@firedesktop/react-base 2.1.25 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +162 -0
- package/README.md +174 -94
- package/dist/components/AppIcon.d.ts +20 -20
- package/dist/components/AppIcon.js +53 -64
- package/dist/components/AppIcon.js.map +1 -1
- package/dist/components/AppInput.d.ts +20 -20
- package/dist/components/AppInput.js +7 -18
- package/dist/components/AppInput.js.map +1 -1
- package/dist/components/AppPagination.d.ts +11 -11
- package/dist/components/AppPagination.js +63 -74
- package/dist/components/AppPagination.js.map +1 -1
- package/dist/components/Spin.d.ts +6 -6
- package/dist/components/Spin.js +21 -17
- package/dist/components/Spin.js.map +1 -1
- package/dist/components/Toaster/Toaster.d.ts +7 -7
- package/dist/components/Toaster/Toaster.js +41 -29
- package/dist/components/Toaster/Toaster.js.map +1 -1
- package/dist/components/Toaster/Types.d.ts +6 -6
- package/dist/components/Toaster/Types.js +1 -1
- package/dist/components/index.d.ts +7 -7
- package/dist/components/index.js +7 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/utils/CurrencyUtiles.d.ts +4 -4
- package/dist/utils/CurrencyUtiles.js +35 -30
- package/dist/utils/CurrencyUtiles.js.map +1 -1
- package/dist/utils/DateUtils.d.ts +7 -7
- package/dist/utils/DateUtils.js +111 -100
- package/dist/utils/DateUtils.js.map +1 -1
- package/dist/utils/FileUtils.d.ts +5 -5
- package/dist/utils/FileUtils.js +73 -73
- package/dist/utils/FileUtils.js.map +1 -1
- package/dist/utils/Logger.d.ts +13 -0
- package/dist/utils/Logger.js +44 -0
- package/dist/utils/Logger.js.map +1 -0
- package/dist/utils/RegExValidation.d.ts +4 -4
- package/dist/utils/RegExValidation.js +19 -19
- package/dist/utils/UrlUtils.d.ts +4 -4
- package/dist/utils/UrlUtils.js +15 -15
- package/dist/utils/UrlUtils.js.map +1 -1
- package/dist/utils/configuration/ConfigurationLoader.d.ts +6 -6
- package/dist/utils/configuration/ConfigurationLoader.js +76 -75
- package/dist/utils/configuration/ConfigurationLoader.js.map +1 -1
- package/dist/utils/configuration/ConfigurationManager.d.ts +5 -5
- package/dist/utils/configuration/ConfigurationManager.js +96 -89
- package/dist/utils/configuration/ConfigurationManager.js.map +1 -1
- package/dist/utils/configuration/ConfigurationReturner.d.ts +9 -9
- package/dist/utils/configuration/ConfigurationReturner.js +70 -69
- package/dist/utils/configuration/ConfigurationReturner.js.map +1 -1
- package/dist/utils/configuration/index.d.ts +4 -4
- package/dist/utils/configuration/index.js +4 -4
- package/dist/utils/fetch/Types.d.ts +10 -10
- package/dist/utils/fetch/Types.js +1 -1
- package/dist/utils/fetch/fetchWrapper.d.ts +14 -14
- package/dist/utils/fetch/fetchWrapper.js +268 -233
- package/dist/utils/fetch/fetchWrapper.js.map +1 -1
- package/dist/utils/fetch/index.d.ts +3 -3
- package/dist/utils/fetch/index.js +3 -3
- package/dist/utils/index.d.ts +10 -9
- package/dist/utils/index.js +10 -9
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/labels/LanguageLoader.d.ts +7 -7
- package/dist/utils/labels/LanguageLoader.js +130 -100
- package/dist/utils/labels/LanguageLoader.js.map +1 -1
- package/dist/utils/labels/LanguageManager.d.ts +6 -6
- package/dist/utils/labels/LanguageManager.js +118 -110
- package/dist/utils/labels/LanguageManager.js.map +1 -1
- package/dist/utils/labels/LanguageReturner.d.ts +10 -10
- package/dist/utils/labels/LanguageReturner.js +70 -69
- package/dist/utils/labels/LanguageReturner.js.map +1 -1
- package/dist/utils/labels/index.d.ts +4 -4
- package/dist/utils/labels/index.js +4 -4
- package/docs/APP_ICON.md +82 -0
- package/docs/APP_INPUT.md +81 -0
- package/docs/APP_PAGINATION.md +61 -0
- package/docs/CONFIGURATION.md +105 -0
- package/docs/FETCH_WRAPPER.md +163 -0
- package/docs/LABELS.md +148 -0
- package/docs/LOGGER.md +112 -0
- package/docs/SECURITY_AUDIT_2026-02-05.md +468 -0
- package/docs/SPIN.md +45 -0
- package/docs/TOASTER.md +75 -0
- package/docs/UTILITIES.md +177 -0
- package/package.json +28 -38
- package/src/App.css +0 -12
- package/src/lib/components/AppIcon.tsx +0 -784
- package/src/lib/components/AppInput.tsx +0 -66
- package/src/lib/components/AppPagination.tsx +0 -124
- package/src/lib/components/Spin.tsx +0 -31
- package/src/lib/components/Toaster/Toaster.tsx +0 -50
- package/src/lib/components/Toaster/Types.ts +0 -11
- package/src/lib/components/index.ts +0 -8
- package/src/lib/index.ts +0 -15
- package/src/lib/styles/base.css +0 -392
- package/src/lib/styles/syncfusion_bootstrap4.css +0 -10
- package/src/lib/styles/toaster.css +0 -50
- package/src/lib/utils/CurrencyUtiles.ts +0 -48
- package/src/lib/utils/DateUtils.ts +0 -135
- package/src/lib/utils/FileUtils.ts +0 -40
- package/src/lib/utils/RegExValidation.ts +0 -49
- package/src/lib/utils/UrlUtils.ts +0 -17
- package/src/lib/utils/configuration/ConfigurationLoader.tsx +0 -43
- package/src/lib/utils/configuration/ConfigurationManager.ts +0 -38
- package/src/lib/utils/configuration/ConfigurationReturner.tsx +0 -39
- package/src/lib/utils/configuration/index.ts +0 -9
- package/src/lib/utils/fetch/Types.ts +0 -11
- package/src/lib/utils/fetch/fetchWrapper.ts +0 -174
- package/src/lib/utils/fetch/index.ts +0 -4
- package/src/lib/utils/index.ts +0 -11
- package/src/lib/utils/labels/LanguageLoader.tsx +0 -69
- package/src/lib/utils/labels/LanguageManager.ts +0 -61
- package/src/lib/utils/labels/LanguageReturner.tsx +0 -41
- package/src/lib/utils/labels/index.ts +0 -9
package/docs/LABELS.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Labels (i18n)
|
|
2
|
+
|
|
3
|
+
Runtime internationalization system that loads locale JSON files and provides dot-notation label access.
|
|
4
|
+
|
|
5
|
+
## Components
|
|
6
|
+
|
|
7
|
+
### LanguageLoader (Redux)
|
|
8
|
+
|
|
9
|
+
Headless component that loads labels on mount and dispatches to Redux.
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
import { LanguageLoader } from '@firedesktop/react-base';
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
#### Props
|
|
16
|
+
|
|
17
|
+
| Prop | Type | Required | Default | Description |
|
|
18
|
+
|------|------|----------|---------|-------------|
|
|
19
|
+
| `updateAppState` | `(name: string, value: object) => any` | Yes | -- | Redux action creator |
|
|
20
|
+
| `language` | `string` | Yes | -- | Locale code (e.g., `'it-IT'`, `'en'`) |
|
|
21
|
+
| `path` | `string` | No | -- | Custom labels directory path |
|
|
22
|
+
|
|
23
|
+
#### Usage
|
|
24
|
+
|
|
25
|
+
```jsx
|
|
26
|
+
import { LanguageLoader } from '@firedesktop/react-base';
|
|
27
|
+
import { Provider } from 'react-redux';
|
|
28
|
+
|
|
29
|
+
<Provider store={store}>
|
|
30
|
+
<LanguageLoader updateAppState={updateAppState} language="it-IT" />
|
|
31
|
+
<App />
|
|
32
|
+
</Provider>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
With base + custom labels:
|
|
36
|
+
|
|
37
|
+
```jsx
|
|
38
|
+
<LanguageLoader
|
|
39
|
+
updateAppState={updateAppState}
|
|
40
|
+
language="it-IT"
|
|
41
|
+
path="labels/custom"
|
|
42
|
+
/>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
When `path` is provided, the loader fetches both `./labels/{language}.json` (base) and `./{path}/{language}.json` (custom), then deep-merges custom labels on top of base labels.
|
|
46
|
+
|
|
47
|
+
### LanguageReturner (Callback)
|
|
48
|
+
|
|
49
|
+
For applications not using Redux. Loads labels and calls a callback.
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
import { LanguageReturner } from '@firedesktop/react-base';
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### Props
|
|
56
|
+
|
|
57
|
+
| Prop | Type | Required | Description |
|
|
58
|
+
|------|------|----------|-------------|
|
|
59
|
+
| `labels` | `{ language: string }` | No | Current labels state (prevents re-loading) |
|
|
60
|
+
| `language` | `string` | Yes | Locale code |
|
|
61
|
+
| `onLanguageLoad` | `(labels?) => void` | Yes | Callback receiving loaded labels |
|
|
62
|
+
| `path` | `string` | Yes | Path to the labels directory |
|
|
63
|
+
|
|
64
|
+
## Label File Format
|
|
65
|
+
|
|
66
|
+
Place locale files in `public/labels/`:
|
|
67
|
+
|
|
68
|
+
**`it-IT.json`**
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"language": "it-IT",
|
|
72
|
+
"common": {
|
|
73
|
+
"save": "Salva",
|
|
74
|
+
"cancel": "Annulla",
|
|
75
|
+
"delete": "Elimina"
|
|
76
|
+
},
|
|
77
|
+
"errors": {
|
|
78
|
+
"required": "Campo obbligatorio",
|
|
79
|
+
"invalid_email": "Email non valida"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**`en.json`**
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"language": "en",
|
|
88
|
+
"common": {
|
|
89
|
+
"save": "Save",
|
|
90
|
+
"cancel": "Cancel",
|
|
91
|
+
"delete": "Delete"
|
|
92
|
+
},
|
|
93
|
+
"errors": {
|
|
94
|
+
"required": "Required field",
|
|
95
|
+
"invalid_email": "Invalid email"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The response must be a plain JSON object (not an array or primitive).
|
|
101
|
+
|
|
102
|
+
## Reading Labels
|
|
103
|
+
|
|
104
|
+
### LanguageManager
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
import { Utils } from '@firedesktop/react-base';
|
|
108
|
+
const { getLabel } = Utils.Labels();
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### `getLabel(labels, id, defaultValue?)`
|
|
112
|
+
|
|
113
|
+
| Parameter | Type | Description |
|
|
114
|
+
|-----------|------|-------------|
|
|
115
|
+
| `labels` | `object` | Labels object from Redux state |
|
|
116
|
+
| `id` | `string` | Dot-notation path to the label (e.g., `'common.save'`) |
|
|
117
|
+
| `defaultValue` | `string` | Fallback if the label is not found (defaults to `id`) |
|
|
118
|
+
|
|
119
|
+
### Usage in components
|
|
120
|
+
|
|
121
|
+
```jsx
|
|
122
|
+
import { useSelector } from 'react-redux';
|
|
123
|
+
import { Utils } from '@firedesktop/react-base';
|
|
124
|
+
|
|
125
|
+
const { getLabel } = Utils.Labels();
|
|
126
|
+
|
|
127
|
+
function MyComponent() {
|
|
128
|
+
const { labels } = useSelector(state => state);
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<div>
|
|
132
|
+
<button>{getLabel(labels, 'common.save', 'Save')}</button>
|
|
133
|
+
<button>{getLabel(labels, 'common.cancel', 'Cancel')}</button>
|
|
134
|
+
</div>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Behavior
|
|
140
|
+
|
|
141
|
+
- Fetches with cache-busting timestamp query parameter
|
|
142
|
+
- Sets `Cache-Control`, `pragma`, `Expires` headers
|
|
143
|
+
- Validates HTTP status (`res.ok`) before parsing
|
|
144
|
+
- Validates the response is a plain object
|
|
145
|
+
- Re-loads when the `language` prop changes
|
|
146
|
+
- Deep merge uses a safe merge function that blocks prototype pollution keys (`__proto__`, `constructor`, `prototype`)
|
|
147
|
+
- Dispatches as `updateAppState('labels', mergedLabels)` (Redux variant)
|
|
148
|
+
- Errors are logged via [Logger](LOGGER.md) (silent by default)
|
package/docs/LOGGER.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Logger
|
|
2
|
+
|
|
3
|
+
`@firedesktop/react-base` includes a built-in Logger utility that controls all internal diagnostic output. It is **disabled by default**, meaning the library produces zero console output in production unless explicitly enabled by the consumer application.
|
|
4
|
+
|
|
5
|
+
## Why
|
|
6
|
+
|
|
7
|
+
Previous versions of this library logged configuration paths, label data, fetch URLs, and error objects directly to `console.log/warn/error` in all environments. This caused:
|
|
8
|
+
|
|
9
|
+
- Sensitive configuration data visible in production browser consoles
|
|
10
|
+
- Internal file paths exposed to end users
|
|
11
|
+
- Noisy console output that obscured application-level logs
|
|
12
|
+
- No way for consumers to suppress library logging
|
|
13
|
+
|
|
14
|
+
The Logger centralizes all internal logging behind a single opt-in flag, resolving these issues.
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
```javascript
|
|
19
|
+
import { Logger } from '@firedesktop/react-base';
|
|
20
|
+
|
|
21
|
+
// Enable debug logging (typically in your app entry point)
|
|
22
|
+
Logger.enableDebug(process.env.NODE_ENV === 'development');
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
All internal library logs will now appear in the browser console, prefixed with `[react-base]`.
|
|
26
|
+
|
|
27
|
+
## API Reference
|
|
28
|
+
|
|
29
|
+
### `Logger.enableDebug(enabled: boolean): void`
|
|
30
|
+
|
|
31
|
+
Turns debug logging on or off globally. Affects all `Logger.debug`, `Logger.warn`, and `Logger.error` calls across the library.
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
// Enable
|
|
35
|
+
Logger.enableDebug(true);
|
|
36
|
+
|
|
37
|
+
// Disable (default state)
|
|
38
|
+
Logger.enableDebug(false);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### `Logger.isEnabled(): boolean`
|
|
42
|
+
|
|
43
|
+
Returns the current debug state. Useful for conditional logic in consumer code.
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
if (Logger.isEnabled()) {
|
|
47
|
+
// additional app-level debugging
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### `Logger.debug(message: string, ...args: any[]): void`
|
|
52
|
+
|
|
53
|
+
Logs an informational message via `console.log` when debug is enabled. Used internally for loading progress (e.g., "Loading Configuration...", "Loaded Labels...").
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
Logger.debug('Custom message', { someData: 123 });
|
|
57
|
+
// Output when enabled: [react-base] Custom message { someData: 123 }
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### `Logger.warn(message: string, ...args: any[]): void`
|
|
61
|
+
|
|
62
|
+
Logs a warning via `console.warn` when debug is enabled. Used internally for non-critical failures (e.g., labels file not found, fetch errors).
|
|
63
|
+
|
|
64
|
+
### `Logger.error(message: string, ...args: any[]): void`
|
|
65
|
+
|
|
66
|
+
Logs an error via `console.error` when debug is enabled. Used internally for loading failures (e.g., configuration load error, label parse error).
|
|
67
|
+
|
|
68
|
+
## Usage Patterns
|
|
69
|
+
|
|
70
|
+
### Development only
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
Logger.enableDebug(process.env.NODE_ENV === 'development');
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Feature flag controlled
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
Logger.enableDebug(window.__DEBUG_REACT_BASE__ === true);
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Conditional at runtime
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
// Enable from browser DevTools at any time:
|
|
86
|
+
// window.__REACT_BASE_DEBUG = true
|
|
87
|
+
|
|
88
|
+
Logger.enableDebug(window.__REACT_BASE_DEBUG === true);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Disable completely (default)
|
|
92
|
+
|
|
93
|
+
No action needed. The Logger is off by default. If you never call `Logger.enableDebug(true)`, zero console output is produced by the library.
|
|
94
|
+
|
|
95
|
+
## Filtering in Browser DevTools
|
|
96
|
+
|
|
97
|
+
When enabled, all messages are prefixed with `[react-base]`. To filter:
|
|
98
|
+
|
|
99
|
+
1. Open browser DevTools > Console
|
|
100
|
+
2. Type `[react-base]` in the filter box
|
|
101
|
+
3. Only library logs are shown
|
|
102
|
+
|
|
103
|
+
## Import Paths
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
// Top-level export (recommended)
|
|
107
|
+
import { Logger } from '@firedesktop/react-base';
|
|
108
|
+
|
|
109
|
+
// Via Utils namespace
|
|
110
|
+
import { Utils } from '@firedesktop/react-base';
|
|
111
|
+
Utils.Logger.enableDebug(true);
|
|
112
|
+
```
|