@biglogic/rgs 2.7.0

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.
Files changed (39) hide show
  1. package/dist/CODEOWNERS +1 -0
  2. package/dist/CONTRIBUTING.md +65 -0
  3. package/dist/COPYRIGHT.md +4 -0
  4. package/dist/LICENSE +9 -0
  5. package/dist/README.md +267 -0
  6. package/dist/SECURITY.md +3 -0
  7. package/dist/advanced.d.ts +9 -0
  8. package/dist/advanced.js +1 -0
  9. package/dist/core/advanced.d.ts +5 -0
  10. package/dist/core/async.d.ts +8 -0
  11. package/dist/core/hooks.d.ts +8 -0
  12. package/dist/core/security.d.ts +54 -0
  13. package/dist/core/store.d.ts +7 -0
  14. package/dist/core/types.d.ts +134 -0
  15. package/dist/index.d.ts +37 -0
  16. package/dist/index.js +1 -0
  17. package/dist/markdown/SUMMARY.md +55 -0
  18. package/dist/markdown/api.md +342 -0
  19. package/dist/markdown/chapters/01-philosophy.md +54 -0
  20. package/dist/markdown/chapters/02-getting-started.md +68 -0
  21. package/dist/markdown/chapters/03-the-magnetar-way.md +62 -0
  22. package/dist/markdown/chapters/04-persistence-and-safety.md +84 -0
  23. package/dist/markdown/chapters/05-plugin-sdk.md +290 -0
  24. package/dist/markdown/chapters/05-plugins-and-extensibility.md +174 -0
  25. package/dist/markdown/chapters/06-case-studies.md +69 -0
  26. package/dist/markdown/chapters/07-faq.md +53 -0
  27. package/dist/markdown/chapters/08-migration-guide.md +206 -0
  28. package/dist/package.json +81 -0
  29. package/dist/plugins/index.d.ts +13 -0
  30. package/dist/plugins/official/analytics.plugin.d.ts +9 -0
  31. package/dist/plugins/official/debug.plugin.d.ts +2 -0
  32. package/dist/plugins/official/devtools.plugin.d.ts +4 -0
  33. package/dist/plugins/official/guard.plugin.d.ts +2 -0
  34. package/dist/plugins/official/immer.plugin.d.ts +2 -0
  35. package/dist/plugins/official/schema.plugin.d.ts +2 -0
  36. package/dist/plugins/official/snapshot.plugin.d.ts +2 -0
  37. package/dist/plugins/official/sync.plugin.d.ts +4 -0
  38. package/dist/plugins/official/undo-redo.plugin.d.ts +4 -0
  39. package/package.json +81 -0
@@ -0,0 +1,206 @@
1
+ # 🔄 Migration Guide
2
+
3
+ ## Upgrading from Previous Versions
4
+
5
+ ### Security: `secure` → `encoded`
6
+
7
+ **IMPORTANT:** The `secure` option has been deprecated in favor of `encoded` to clarify that it only applies **base64 encoding**, not encryption.
8
+
9
+ #### ❌ Old Code (Deprecated)
10
+
11
+ ```typescript
12
+ store.set('apiKey', 'secret123', {
13
+ persist: true,
14
+ secure: true // ⚠️ DEPRECATED: This is NOT encryption!
15
+ })
16
+ ```
17
+
18
+ #### ✅ New Code (Recommended)
19
+
20
+ ```typescript
21
+ store.set('apiKey', 'secret123', {
22
+ persist: true,
23
+ encoded: true // ✅ Clear: This is base64 encoding
24
+ })
25
+ ```
26
+
27
+ #### Backward Compatibility
28
+
29
+ Your old code will **still work**, but you'll see a deprecation warning in TypeScript:
30
+
31
+ ```typescript
32
+ /** @deprecated Use 'encoded' instead. 'secure' only applies base64 encoding, not encryption. */
33
+ secure?: boolean
34
+ ```
35
+
36
+ #### Why This Change?
37
+
38
+ Base64 encoding is **NOT encryption**. It's trivial to decode:
39
+
40
+ ```javascript
41
+ // Anyone can decode base64
42
+ const encoded = btoa(JSON.stringify({ secret: 'password123' }))
43
+ const decoded = JSON.parse(atob(encoded)) // { secret: 'password123' }
44
+ ```
45
+
46
+ **For real security**, use proper encryption libraries like:
47
+
48
+ - `crypto-js` (AES encryption)
49
+ - `tweetnacl` (NaCl encryption)
50
+ - Web Crypto API (`crypto.subtle`)
51
+
52
+ ---
53
+
54
+ ### Error Handling: `onError` Callback
55
+
56
+ **NEW:** You can now catch and handle errors from plugins, hydration, and other operations.
57
+
58
+ #### Example: Custom Error Logging
59
+
60
+ ```typescript
61
+ import { initState } from 'argis'
62
+
63
+ const store = initState({
64
+ namespace: 'myapp',
65
+ onError: (error, context) => {
66
+ // Send to your error tracking service
67
+ console.error(`[gState Error] ${context.operation}:`, error)
68
+
69
+ if (context.operation === 'hydration') {
70
+ // Handle corrupted localStorage
71
+ localStorage.clear()
72
+ alert('Storage corrupted, resetting...')
73
+ }
74
+
75
+ if (context.operation.startsWith('plugin:')) {
76
+ // Handle plugin crashes
77
+ Sentry.captureException(error, { tags: { plugin: context.operation } })
78
+ }
79
+ }
80
+ })
81
+ ```
82
+
83
+ #### Error Context
84
+
85
+ ```typescript
86
+ interface ErrorContext {
87
+ operation: string // 'hydration', 'plugin:name:hook', 'set'
88
+ key?: string // State key (if applicable)
89
+ }
90
+ ```
91
+
92
+ ---
93
+
94
+ ### Performance: `maxObjectSize` Warning
95
+
96
+ **NEW:** Get warned when storing objects larger than a configurable limit (default: 5MB).
97
+
98
+ #### Example: Custom Size Limit
99
+
100
+ ```typescript
101
+ import { createStore } from 'argis'
102
+
103
+ const store = createStore({
104
+ maxObjectSize: 10 * 1024 * 1024, // 10MB limit
105
+ onError: (error, context) => {
106
+ if (context.operation === 'set') {
107
+ console.warn(`Large object detected in key: ${context.key}`)
108
+ }
109
+ }
110
+ })
111
+
112
+ // This will trigger a warning if > 10MB
113
+ store.set('bigData', hugeArray)
114
+ ```
115
+
116
+ #### Disable Size Checking
117
+
118
+ ```typescript
119
+ const store = createStore({
120
+ maxObjectSize: 0 // Disable size warnings
121
+ })
122
+ ```
123
+
124
+ ---
125
+
126
+ ## Upgrading to Latest Version (The Enterprise Update)
127
+
128
+ **IMPORTANT:** This release introduces a fundamental shift towards **Multi-Store Isolation**. Security rules and GDPR consents are now instance-bound rather than global.
129
+
130
+ ### 1. Security: Global → Instance-Specific
131
+
132
+ In previous versions, security rules were shared globally. Now, each store instance maintains its own rules for better isolation in micro-frontend environments.
133
+
134
+ #### ❌ Deprecated Global Methods
135
+
136
+ ```typescript
137
+ import { addAccessRule, recordConsent } from 'argis'
138
+
139
+ // ⚠️ DEPRECATED: These affect the 'default' store only and are less isolated
140
+ addAccessRule('user_*', ['read', 'write'])
141
+ ```
142
+
143
+ #### ✅ Recommended Instance Methods
144
+
145
+ ```typescript
146
+ const store = createStore({ namespace: 'my-isolated-app' })
147
+
148
+ // ✅ Use the instance methods
149
+ store.addAccessRule('user_*', ['read', 'write'])
150
+ store.recordConsent('user123', 'marketing', true)
151
+ ```
152
+
153
+ ### 2. Operational Resilience: Ghost Stores
154
+
155
+ **NEW:** If you access a store that hasn't finished its initialization (e.g., during slow hydration), RGS now returns a **Ghost Store Proxy**.
156
+
157
+ - **Behavior:** It prevents application crashes by providing a safe fallback.
158
+ - **Developer Warning:** It logs a detailed warning in the console so you can fix the initialization sequence.
159
+
160
+ ### 3. Performance: Regex Caching
161
+
162
+ **NEW:** Permission checks now use an internal **Regex Cache** per instance.
163
+
164
+ - **Why?** Avoids the overhead of re-compiling regex strings on every `.get()` or `.set()` call.
165
+ - **Impact:** Significant performance boost for applications with high-frequency state updates and complex RBAC rules.
166
+
167
+ ### 4. Advanced Plugin Typing
168
+
169
+ **NEW:** Introducing `GStatePlugins` for Module Augmentation.
170
+
171
+ - You can now define types for your custom plugins to get full IDE autocomplete.
172
+
173
+ ---
174
+
175
+ ## Breaking Changes
176
+
177
+ ### 🔒 Security Isolation
178
+
179
+ If you relied on `addAccessRule()` from the global export to affect a `createStore()` instance, you must now call `store.addAccessRule()` on that specific instance.
180
+
181
+ ---
182
+
183
+ ## Recommended Actions
184
+
185
+ ### 1. Migrate Security Calls to Store Instances
186
+
187
+ **Priority:** High (if using multiple stores)
188
+
189
+ **Effort:** Low
190
+
191
+ ### 2. Implement `GStatePlugins` for Custom Plugins
192
+
193
+ **Priority:** Medium (Developer Experience)
194
+
195
+ **Effort:** Low
196
+
197
+ ---
198
+
199
+ ## Need Help?
200
+
201
+ - **Issues:** [GitHub Issues](https://github.com/dpassariello/rgs/issues)
202
+ - **Docs:** [Galaxy Documentation](../SUMMARY.md)
203
+
204
+ ---
205
+
206
+ ## Last updated: 2026-02-15
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@biglogic/rgs",
3
+ "version": "2.7.0",
4
+ "description": "Argis (RGS) - React Globo State: A react state everywhere made easy",
5
+ "keywords": [
6
+ "rgs",
7
+ "gstate",
8
+ "state-management",
9
+ "react",
10
+ "enterprise",
11
+ "hooks",
12
+ "global-state",
13
+ "immer",
14
+ "biglogic",
15
+ "persistence",
16
+ "react-globo-state",
17
+ "argis"
18
+ ],
19
+ "license": "MIT",
20
+ "author": "Dario Passariello",
21
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ },
27
+ "./advanced": {
28
+ "types": "./dist/advanced.d.ts",
29
+ "default": "./dist/advanced.js"
30
+ },
31
+ "./package.json": "./package.json"
32
+ },
33
+ "main": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "scripts": {
39
+ "build": "tsc --emitDeclarationOnly --outDir dist && node ./esbuild.config.mjs",
40
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config ./tests/jest/jest.config.ts",
41
+ "test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config ./tests/jest/jest.config.ts --watch",
42
+ "test:e2e": "playwright test --config ./tests/playwright/playwright.config.ts",
43
+ "type-check": "tsc --noEmit",
44
+ "npm:publish": "npm run build && npm publish --access=public",
45
+ "lint": "eslint . --ext .ts,.tsx --config tests/eslint/eslint.config.mjs"
46
+ },
47
+ "dependencies": {
48
+ "immer": "^11.1.4"
49
+ },
50
+ "peerDependencies": {
51
+ "react": ">=16.8.0",
52
+ "react-dom": ">=16.8.0"
53
+ },
54
+ "devDependencies": {
55
+ "@eslint/js": "10.0.1",
56
+ "@playwright/test": "1.58.2",
57
+ "@testing-library/dom": "10.4.1",
58
+ "@testing-library/jest-dom": "6.9.1",
59
+ "@testing-library/react": "16.3.2",
60
+ "@types/jest": "30.0.0",
61
+ "@types/node": "25.2.3",
62
+ "@types/react": "19.2.14",
63
+ "@types/react-dom": "19.2.3",
64
+ "@typescript-eslint/eslint-plugin": "^8.55.0",
65
+ "@typescript-eslint/parser": "^8.55.0",
66
+ "dphelper": "2.6.3",
67
+ "esbuild": "0.27.3",
68
+ "esbuild-plugin-copy": "2.1.1",
69
+ "eslint": "^10.0.0",
70
+ "eslint-plugin-react": "7.37.5",
71
+ "eslint-plugin-react-hooks": "7.0.1",
72
+ "jest": "30.2.0",
73
+ "jest-environment-jsdom": "30.2.0",
74
+ "react": "19.2.4",
75
+ "react-dom": "19.2.4",
76
+ "ts-jest": "29.4.6",
77
+ "tslib": "^2.8.1",
78
+ "typescript": "^5.9.3",
79
+ "typescript-eslint": "8.55.0"
80
+ }
81
+ }
@@ -0,0 +1,13 @@
1
+ export { immerPlugin } from "./official/immer.plugin";
2
+ export { undoRedoPlugin } from "./official/undo-redo.plugin";
3
+ export { schemaPlugin } from "./official/schema.plugin";
4
+ export { devToolsPlugin } from "./official/devtools.plugin";
5
+ export { snapshotPlugin } from "./official/snapshot.plugin";
6
+ export { guardPlugin } from "./official/guard.plugin";
7
+ export { analyticsPlugin } from "./official/analytics.plugin";
8
+ export { syncPlugin } from "./official/sync.plugin";
9
+ export { debugPlugin } from "./official/debug.plugin";
10
+ import type { IPlugin } from "../core/types";
11
+ export declare const loggerPlugin: (options?: {
12
+ collapsed?: boolean;
13
+ }) => IPlugin;
@@ -0,0 +1,9 @@
1
+ import type { IPlugin } from '../../core/types';
2
+ export declare const analyticsPlugin: (options: {
3
+ provider: (event: {
4
+ key: string;
5
+ value: unknown;
6
+ action: string;
7
+ }) => void;
8
+ keys?: string[];
9
+ }) => IPlugin;
@@ -0,0 +1,2 @@
1
+ import type { IPlugin } from '../../core/types';
2
+ export declare const debugPlugin: () => IPlugin;
@@ -0,0 +1,4 @@
1
+ import type { IPlugin } from '../../core/types';
2
+ export declare const devToolsPlugin: (options?: {
3
+ name?: string;
4
+ }) => IPlugin;
@@ -0,0 +1,2 @@
1
+ import type { IPlugin } from '../../core/types';
2
+ export declare const guardPlugin: (guards: Record<string, (val: unknown) => unknown>) => IPlugin;
@@ -0,0 +1,2 @@
1
+ import type { IPlugin } from '../../core/types';
2
+ export declare const immerPlugin: () => IPlugin;
@@ -0,0 +1,2 @@
1
+ import type { IPlugin } from '../../core/types';
2
+ export declare const schemaPlugin: (schemas: Record<string, (val: unknown) => boolean | string>) => IPlugin;
@@ -0,0 +1,2 @@
1
+ import type { IPlugin } from '../../core/types';
2
+ export declare const snapshotPlugin: () => IPlugin;
@@ -0,0 +1,4 @@
1
+ import type { IPlugin } from '../../core/types';
2
+ export declare const syncPlugin: (options?: {
3
+ channelName?: string;
4
+ }) => IPlugin;
@@ -0,0 +1,4 @@
1
+ import type { IPlugin } from '../../core/types';
2
+ export declare const undoRedoPlugin: (options?: {
3
+ limit?: number;
4
+ }) => IPlugin;
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@biglogic/rgs",
3
+ "version": "2.7.0",
4
+ "description": "Argis (RGS) - React Globo State: A react state everywhere made easy",
5
+ "keywords": [
6
+ "rgs",
7
+ "gstate",
8
+ "state-management",
9
+ "react",
10
+ "enterprise",
11
+ "hooks",
12
+ "global-state",
13
+ "immer",
14
+ "biglogic",
15
+ "persistence",
16
+ "react-globo-state",
17
+ "argis"
18
+ ],
19
+ "license": "MIT",
20
+ "author": "Dario Passariello",
21
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ },
27
+ "./advanced": {
28
+ "types": "./dist/advanced.d.ts",
29
+ "default": "./dist/advanced.js"
30
+ },
31
+ "./package.json": "./package.json"
32
+ },
33
+ "main": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "scripts": {
39
+ "build": "tsc --emitDeclarationOnly --outDir dist && node ./esbuild.config.mjs",
40
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config ./tests/jest/jest.config.ts",
41
+ "test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config ./tests/jest/jest.config.ts --watch",
42
+ "test:e2e": "playwright test --config ./tests/playwright/playwright.config.ts",
43
+ "type-check": "tsc --noEmit",
44
+ "npm:publish": "npm run build && npm publish --access=public",
45
+ "lint": "eslint . --ext .ts,.tsx --config tests/eslint/eslint.config.mjs"
46
+ },
47
+ "dependencies": {
48
+ "immer": "^11.1.4"
49
+ },
50
+ "peerDependencies": {
51
+ "react": ">=16.8.0",
52
+ "react-dom": ">=16.8.0"
53
+ },
54
+ "devDependencies": {
55
+ "@eslint/js": "10.0.1",
56
+ "@playwright/test": "1.58.2",
57
+ "@testing-library/dom": "10.4.1",
58
+ "@testing-library/jest-dom": "6.9.1",
59
+ "@testing-library/react": "16.3.2",
60
+ "@types/jest": "30.0.0",
61
+ "@types/node": "25.2.3",
62
+ "@types/react": "19.2.14",
63
+ "@types/react-dom": "19.2.3",
64
+ "@typescript-eslint/eslint-plugin": "^8.55.0",
65
+ "@typescript-eslint/parser": "^8.55.0",
66
+ "dphelper": "2.6.3",
67
+ "esbuild": "0.27.3",
68
+ "esbuild-plugin-copy": "2.1.1",
69
+ "eslint": "^10.0.0",
70
+ "eslint-plugin-react": "7.37.5",
71
+ "eslint-plugin-react-hooks": "7.0.1",
72
+ "jest": "30.2.0",
73
+ "jest-environment-jsdom": "30.2.0",
74
+ "react": "19.2.4",
75
+ "react-dom": "19.2.4",
76
+ "ts-jest": "29.4.6",
77
+ "tslib": "^2.8.1",
78
+ "typescript": "^5.9.3",
79
+ "typescript-eslint": "8.55.0"
80
+ }
81
+ }