@telperion/reactive-storage 1.2.0 → 1.3.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.
Files changed (55) hide show
  1. package/.build-manifest.json +86 -0
  2. package/README.md +6 -6
  3. package/fesm/reactive-storage.mjs +639 -0
  4. package/fesm/reactive-storage.mjs.map +1 -0
  5. package/index.cjs +17 -8
  6. package/index.cjs.map +1 -0
  7. package/index.d.cts +6 -0
  8. package/index.d.ts +6 -5
  9. package/index.js +5 -6
  10. package/index.js.map +1 -1
  11. package/json-parse.cjs +5 -3
  12. package/json-parse.cjs.map +1 -0
  13. package/json-parse.d.cts +8 -0
  14. package/json-parse.d.ts +3 -1
  15. package/json-parse.js +2 -1
  16. package/json-parse.js.map +1 -1
  17. package/package.json +60 -31
  18. package/reactive-cookie-storage.cjs +69 -50
  19. package/reactive-cookie-storage.cjs.map +1 -0
  20. package/reactive-cookie-storage.d.cts +77 -0
  21. package/reactive-cookie-storage.d.ts +48 -40
  22. package/reactive-cookie-storage.js +60 -41
  23. package/reactive-cookie-storage.js.map +1 -1
  24. package/reactive-storage.cjs +168 -83
  25. package/reactive-storage.cjs.map +1 -0
  26. package/reactive-storage.d.cts +165 -0
  27. package/reactive-storage.d.ts +118 -37
  28. package/reactive-storage.js +128 -43
  29. package/reactive-storage.js.map +1 -1
  30. package/reactive-web-local-storage.cjs +30 -8
  31. package/reactive-web-local-storage.cjs.map +1 -0
  32. package/reactive-web-local-storage.d.cts +37 -0
  33. package/reactive-web-local-storage.d.ts +30 -5
  34. package/reactive-web-local-storage.js +27 -5
  35. package/reactive-web-local-storage.js.map +1 -1
  36. package/reactive-web-session-storage.cjs +24 -8
  37. package/reactive-web-session-storage.cjs.map +1 -0
  38. package/reactive-web-session-storage.d.cts +31 -0
  39. package/reactive-web-session-storage.d.ts +24 -5
  40. package/reactive-web-session-storage.js +21 -5
  41. package/reactive-web-session-storage.js.map +1 -1
  42. package/reactive-web-storage.cjs +42 -27
  43. package/reactive-web-storage.cjs.map +1 -0
  44. package/reactive-web-storage.d.cts +47 -0
  45. package/reactive-web-storage.d.ts +28 -10
  46. package/reactive-web-storage.js +33 -18
  47. package/reactive-web-storage.js.map +1 -1
  48. package/async-iterator.polyfill.cjs +0 -87
  49. package/async-iterator.polyfill.d.ts +0 -2
  50. package/async-iterator.polyfill.js +0 -86
  51. package/async-iterator.polyfill.js.map +0 -1
  52. package/regex-parser.cjs +0 -29
  53. package/regex-parser.d.ts +0 -11
  54. package/regex-parser.js +0 -27
  55. package/regex-parser.js.map +0 -1
@@ -1,69 +1,77 @@
1
- import { ReactiveStorage } from './reactive-storage';
1
+ import { ReactiveStorage, ReactiveStorageChangeEvent } from './reactive-storage.js';
2
+ import 'rxjs';
3
+
2
4
  /**
3
- * Options for configuring cookie behavior in ReactiveCookieStorage.
5
+ * Attributes written with every cookie of a {@link ReactiveCookieStorage}. Unset attributes are
6
+ * left out of the cookie, so the browser applies its own defaults.
4
7
  */
5
- export interface ReactiveCookieStorageOptions {
6
- /** URL path where the cookie is valid. Default: '/' */
8
+ interface ReactiveCookieStorageOptions {
9
+ /** URL path the cookie is sent for, e.g. `'/'` for the whole site. Unset: the path of the current page */
7
10
  path?: string;
8
- /** Domain where the cookie is valid. Default: current domain */
11
+ /** Domain the cookie is sent to, e.g. `'example.com'` to include subdomains. Unset: the current host only */
9
12
  domain?: string;
10
- /** Cookie lifetime in seconds. Default: undefined (session cookie) */
13
+ /** Lifetime in seconds. With neither `maxAge` nor `expires`, it is a session cookie */
11
14
  maxAge?: number;
12
- /** Absolute expiration date. Default: undefined */
15
+ /** Absolute expiry date. With neither `maxAge` nor `expires`, it is a session cookie */
13
16
  expires?: Date;
14
- /** HTTPS only flag. Default: false */
17
+ /** Send the cookie over HTTPS only */
15
18
  secure?: boolean;
16
- /** CSRF protection level. Default: 'lax' */
19
+ /** Cross-site sending policy. Unset: the browser default, `lax` in current browsers */
17
20
  sameSite?: 'strict' | 'lax' | 'none';
18
21
  }
19
22
  /**
20
- * Reactive wrapper for browser cookies.
21
- * Provides RxJS-based reactive API for cookie storage with automatic change detection.
23
+ * Reactive storage on `document.cookie`: for small values the server should see too, or that must expire.
22
24
  *
23
- * **Important Limitations:**
24
- * - Cookies have a ~4KB size limit per cookie
25
- * - No native change events - use linker to sync multiple instances
26
- * - Cannot access httpOnly cookies set by the server
25
+ * Each store is one cookie named `<appName>_<storeName>`, holding the store as URI-encoded JSON.
26
+ * Characters a cookie name cannot hold are percent-encoded in both parts (`user.settings` stays,
27
+ * `user settings` becomes `user%20settings`). Every cookie is written with the attributes given in `options`.
27
28
  *
28
- * **Cross-Instance Synchronization:**
29
- * Link multiple instances using any shared value (symbol, string, object, etc.) to automatically sync changes between them.
29
+ * - A cookie is limited to 4000 bytes; a larger write is rejected with an error.
30
+ * - Browsers have no change event for cookies, so only writes made through this instance are observed.
31
+ * Pass the same `linker` to several instances to have each one notified of the others' writes.
32
+ * - `httpOnly` cookies set by the server cannot be read or written from JavaScript.
30
33
  *
31
- * @template S - Storage store name type
34
+ * Example usage:
35
+ * ```ts
36
+ * import { ReactiveCookieStorage } from '@telperion/reactive-storage/reactive-cookie-storage';
32
37
  *
33
- * @example
34
- * ```typescript
35
- * // Single instance
36
- * const storage = new ReactiveCookieStorage('my-app', {
37
- * path: '/',
38
- * maxAge: 86400,
39
- * secure: true,
40
- * sameSite: 'strict'
41
- * });
38
+ * const storage = new ReactiveCookieStorage('my-app', { path: '/', maxAge: 60 * 60 * 24, sameSite: 'strict' });
42
39
  *
43
- * // Multiple linked instances using a symbol
44
- * const linker = Symbol('cookie-sync');
45
- * const storageOne = new ReactiveCookieStorage('my-app', { secure: true }, linker);
46
- * const storageTwo = new ReactiveCookieStorage('my-app', { secure: false }, linker);
47
- * // Changes in storageOne will notify storageTwo and vice versa
40
+ * await storage.set('consent', 'analytics', true); // cookie my-app_consent, valid for a day
41
+ * ```
42
+ *
43
+ * Linked instances:
44
+ * ```ts
45
+ * const linker = Symbol('cookies');
46
+ * const header = new ReactiveCookieStorage('my-app', { path: '/' }, linker);
47
+ * const settings = new ReactiveCookieStorage('my-app', { path: '/' }, linker);
48
48
  *
49
- * // Or use any other value type
50
- * const storageA = new ReactiveCookieStorage('my-app', { secure: true }, 'my-linker');
51
- * const storageB = new ReactiveCookieStorage('my-app', { secure: false }, 'my-linker');
49
+ * header.get('prefs', 'theme').subscribe(console.log);
50
+ * await settings.set('prefs', 'theme', 'dark'); // header logs "dark"
52
51
  * ```
52
+ *
53
+ * @template S - Store name type: a union of string literals restricts the store names you can use
53
54
  */
54
- export declare class ReactiveCookieStorage<S extends string = string> extends ReactiveStorage<S> {
55
+ declare class ReactiveCookieStorage<S extends string = string> extends ReactiveStorage<S> {
55
56
  #private;
56
57
  readonly appName: string;
57
58
  private readonly options;
59
+ /**
60
+ * @param appName - Prefix of this app's cookie names: each store is saved as `<appName>_<storeName>`. Defaults to `'app'`
61
+ * @param options - Attributes written with every cookie
62
+ * @param linker - Any truthy value, e.g. a symbol: instances created with the same linker are notified of each other's writes
63
+ */
58
64
  constructor(appName?: string, options?: ReactiveCookieStorageOptions, linker?: any);
59
65
  /**
60
- * Destroy the storage instance and cleanup resources.
61
- * Unregisters from linker group and completes the changes subject.
62
- * Call this when you're done using the storage to prevent memory leaks.
66
+ * Releases the instance: unlinks it from its linker group and stops its change stream.
67
+ * Call it when the storage is no longer used, so linked instances do not keep it alive.
63
68
  */
64
69
  destroy(): void;
65
70
  protected [ReactiveStorage.Props.GET_ALL](): Promise<any>;
66
- protected [ReactiveStorage.Props.CHANGES]: any;
71
+ protected [ReactiveStorage.Props.CHANGES]: AsyncGenerator<ReactiveStorageChangeEvent<S>>;
67
72
  protected [ReactiveStorage.Props.SET](storeName: S, value: unknown): Promise<void>;
68
73
  protected [ReactiveStorage.Props.REMOVE](storeName: S): Promise<void>;
69
74
  }
75
+
76
+ export { ReactiveCookieStorage };
77
+ export type { ReactiveCookieStorageOptions };
@@ -1,44 +1,43 @@
1
- var _a;
2
1
  import { Subject } from 'rxjs';
3
- import { ReactiveStorage } from './reactive-storage';
4
- import { toAsyncIterator } from './async-iterator.polyfill';
5
- import { jsonParse } from './json-parse';
2
+ import { makeAsyncIterator } from '@telperion/rx-utils/to-async-iteratable';
3
+ import { ReactiveStorage } from './reactive-storage.js';
4
+ import { jsonParse } from './json-parse.js';
5
+
6
+ var _a;
6
7
  /**
7
- * Reactive wrapper for browser cookies.
8
- * Provides RxJS-based reactive API for cookie storage with automatic change detection.
8
+ * Reactive storage on `document.cookie`: for small values the server should see too, or that must expire.
9
9
  *
10
- * **Important Limitations:**
11
- * - Cookies have a ~4KB size limit per cookie
12
- * - No native change events - use linker to sync multiple instances
13
- * - Cannot access httpOnly cookies set by the server
10
+ * Each store is one cookie named `<appName>_<storeName>`, holding the store as URI-encoded JSON.
11
+ * Characters a cookie name cannot hold are percent-encoded in both parts (`user.settings` stays,
12
+ * `user settings` becomes `user%20settings`). Every cookie is written with the attributes given in `options`.
14
13
  *
15
- * **Cross-Instance Synchronization:**
16
- * Link multiple instances using any shared value (symbol, string, object, etc.) to automatically sync changes between them.
14
+ * - A cookie is limited to 4000 bytes; a larger write is rejected with an error.
15
+ * - Browsers have no change event for cookies, so only writes made through this instance are observed.
16
+ * Pass the same `linker` to several instances to have each one notified of the others' writes.
17
+ * - `httpOnly` cookies set by the server cannot be read or written from JavaScript.
17
18
  *
18
- * @template S - Storage store name type
19
+ * Example usage:
20
+ * ```ts
21
+ * import { ReactiveCookieStorage } from '@telperion/reactive-storage/reactive-cookie-storage';
19
22
  *
20
- * @example
21
- * ```typescript
22
- * // Single instance
23
- * const storage = new ReactiveCookieStorage('my-app', {
24
- * path: '/',
25
- * maxAge: 86400,
26
- * secure: true,
27
- * sameSite: 'strict'
28
- * });
23
+ * const storage = new ReactiveCookieStorage('my-app', { path: '/', maxAge: 60 * 60 * 24, sameSite: 'strict' });
29
24
  *
30
- * // Multiple linked instances using a symbol
31
- * const linker = Symbol('cookie-sync');
32
- * const storageOne = new ReactiveCookieStorage('my-app', { secure: true }, linker);
33
- * const storageTwo = new ReactiveCookieStorage('my-app', { secure: false }, linker);
34
- * // Changes in storageOne will notify storageTwo and vice versa
25
+ * await storage.set('consent', 'analytics', true); // cookie my-app_consent, valid for a day
26
+ * ```
27
+ *
28
+ * Linked instances:
29
+ * ```ts
30
+ * const linker = Symbol('cookies');
31
+ * const header = new ReactiveCookieStorage('my-app', { path: '/' }, linker);
32
+ * const settings = new ReactiveCookieStorage('my-app', { path: '/' }, linker);
35
33
  *
36
- * // Or use any other value type
37
- * const storageA = new ReactiveCookieStorage('my-app', { secure: true }, 'my-linker');
38
- * const storageB = new ReactiveCookieStorage('my-app', { secure: false }, 'my-linker');
34
+ * header.get('prefs', 'theme').subscribe(console.log);
35
+ * await settings.set('prefs', 'theme', 'dark'); // header logs "dark"
39
36
  * ```
37
+ *
38
+ * @template S - Store name type: a union of string literals restricts the store names you can use
40
39
  */
41
- export class ReactiveCookieStorage extends ReactiveStorage {
40
+ class ReactiveCookieStorage extends ReactiveStorage {
42
41
  appName;
43
42
  options;
44
43
  static #MAX_COOKIE_SIZE = 4000; // Conservative 4KB limit
@@ -52,6 +51,11 @@ export class ReactiveCookieStorage extends ReactiveStorage {
52
51
  }
53
52
  #changes$ = new Subject();
54
53
  #linker;
54
+ /**
55
+ * @param appName - Prefix of this app's cookie names: each store is saved as `<appName>_<storeName>`. Defaults to `'app'`
56
+ * @param options - Attributes written with every cookie
57
+ * @param linker - Any truthy value, e.g. a symbol: instances created with the same linker are notified of each other's writes
58
+ */
55
59
  constructor(appName = 'app', options = {}, linker) {
56
60
  super();
57
61
  this.appName = appName;
@@ -66,9 +70,8 @@ export class ReactiveCookieStorage extends ReactiveStorage {
66
70
  }
67
71
  }
68
72
  /**
69
- * Destroy the storage instance and cleanup resources.
70
- * Unregisters from linker group and completes the changes subject.
71
- * Call this when you're done using the storage to prevent memory leaks.
73
+ * Releases the instance: unlinks it from its linker group and stops its change stream.
74
+ * Call it when the storage is no longer used, so linked instances do not keep it alive.
72
75
  */
73
76
  destroy() {
74
77
  // Unregister from linker group
@@ -87,8 +90,9 @@ export class ReactiveCookieStorage extends ReactiveStorage {
87
90
  const cookies = this.#getAppCookies();
88
91
  return Object.fromEntries(Object.entries(cookies).map(([storeName, value]) => [storeName, _a.#parse(value)]));
89
92
  }
93
+ // Prefer an Observable's own async iterator (rxjs 8, or `@telperion/rx-utils/static/async-iterator`)
90
94
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
- [ReactiveStorage.Props.CHANGES] = this.#changes$[Symbol.asyncIterator] ?? toAsyncIterator(this.#changes$);
95
+ [ReactiveStorage.Props.CHANGES] = this.#changes$[Symbol.asyncIterator]?.() ?? makeAsyncIterator(this.#changes$);
92
96
  async [ReactiveStorage.Props.SET](storeName, value) {
93
97
  const serialized = JSON.stringify(value);
94
98
  const cookieName = this.#getCookieName(storeName);
@@ -109,11 +113,18 @@ export class ReactiveCookieStorage extends ReactiveStorage {
109
113
  this.#notifyLinkedInstances(event);
110
114
  }
111
115
  /**
112
- * Convert store name to cookie name by prefixing with app name.
113
- * Sanitizes to only allow alphanumeric, underscore, and hyphen.
116
+ * Cookie-name-safe form of an app or store name that decodes back to it: URI encoding, plus
117
+ * `(` and `)`, which it leaves but cookie names forbid. Letters, digits, `_` and `-` stay as they are.
114
118
  */
119
+ static #encodeName(name) {
120
+ return encodeURIComponent(name).replace(/[()]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);
121
+ }
122
+ /** `<appName>_<storeName>`, each part encoded with {@link ReactiveCookieStorage.#encodeName} */
115
123
  #getCookieName(storeName) {
116
- return `${this.appName}_${storeName}`.replace(/[^a-zA-Z0-9_-]/g, '_');
124
+ return `${this.#cookiePrefix}${_a.#encodeName(storeName)}`;
125
+ }
126
+ get #cookiePrefix() {
127
+ return `${_a.#encodeName(this.appName)}_`;
117
128
  }
118
129
  /**
119
130
  * Parse document.cookie string into key-value object.
@@ -147,11 +158,18 @@ export class ReactiveCookieStorage extends ReactiveStorage {
147
158
  */
148
159
  #getAppCookies() {
149
160
  const allCookies = this.#parseCookies();
150
- const prefix = `${this.appName}_`;
161
+ const prefix = this.#cookiePrefix;
151
162
  const appCookies = {};
152
163
  for (const [cookieName, value] of Object.entries(allCookies)) {
153
- if (cookieName.startsWith(prefix)) {
154
- const storeName = cookieName.slice(prefix.length);
164
+ if (cookieName.startsWith(prefix) && cookieName.length > prefix.length) {
165
+ const encoded = cookieName.slice(prefix.length);
166
+ let storeName;
167
+ try {
168
+ storeName = decodeURIComponent(encoded);
169
+ }
170
+ catch {
171
+ storeName = encoded; // Not written by this library
172
+ }
155
173
  appCookies[storeName] = value;
156
174
  }
157
175
  }
@@ -207,4 +225,5 @@ export class ReactiveCookieStorage extends ReactiveStorage {
207
225
  }
208
226
  _a = ReactiveCookieStorage;
209
227
 
228
+ export { ReactiveCookieStorage };
210
229
  //# sourceMappingURL=reactive-cookie-storage.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../libs/reactive-storage/src/reactive-cookie-storage.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,OAAO,EAAE,eAAe,EAA8B,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAoBzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,OAAO,qBAAiD,SAAQ,eAAkB;IAgBpE;IACC;IAhBnB,MAAM,CAAU,gBAAgB,GAAG,IAAI,CAAC,CAAC,yBAAyB;IAClE,MAAM,CAAU,QAAQ,GAAG,IAAI,GAAG,EAAwC,CAAC;IAE3E;;;OAGG;IACH,MAAM,CAAC,MAAM,CAAC,KAAa;QACzB,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAEQ,SAAS,GAAG,IAAI,OAAO,EAA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AG,MAAM,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,aAAa,CAAC,YAAoB;QAChC,IAAI,YAAY,CAAC,MAAM,GAAG,EAAqB,CAAC,gBAAgB,EAAE,CAAC;YACjE,MAAM,IAAI,KAAK,CACb,gBAAgB,YAAY,CAAC,MAAM,mBAAmB,EAAqB,CAAC,gBAAgB,eAAe;gBACzG,kFAAkF,CACrF,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,sBAAsB,CAAC,KAAoC;QACzD,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO;QAE1B,MAAM,eAAe,GAAG,EAAqB,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzE,IAAI,CAAC,eAAe;YAAE,OAAO;QAE7B,KAAK,MAAM,QAAQ,IAAI,eAAe,EAAE,CAAC;YACvC,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;gBACtB,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;IACH,CAAC","file":"reactive-cookie-storage.js","sourcesContent":["import { Subject } from 'rxjs';\r\n\r\nimport { ReactiveStorage, ReactiveStorageChangeEvent } from './reactive-storage';\r\nimport { toAsyncIterator } from './async-iterator.polyfill';\r\nimport { jsonParse } from './json-parse';\r\n\r\n/**\r\n * Options for configuring cookie behavior in ReactiveCookieStorage.\r\n */\r\nexport interface ReactiveCookieStorageOptions {\r\n /** URL path where the cookie is valid. Default: '/' */\r\n path?: string;\r\n /** Domain where the cookie is valid. Default: current domain */\r\n domain?: string;\r\n /** Cookie lifetime in seconds. Default: undefined (session cookie) */\r\n maxAge?: number;\r\n /** Absolute expiration date. Default: undefined */\r\n expires?: Date;\r\n /** HTTPS only flag. Default: false */\r\n secure?: boolean;\r\n /** CSRF protection level. Default: 'lax' */\r\n sameSite?: 'strict' | 'lax' | 'none';\r\n}\r\n\r\n/**\r\n * Reactive wrapper for browser cookies.\r\n * Provides RxJS-based reactive API for cookie storage with automatic change detection.\r\n *\r\n * **Important Limitations:**\r\n * - Cookies have a ~4KB size limit per cookie\r\n * - No native change events - use linker to sync multiple instances\r\n * - Cannot access httpOnly cookies set by the server\r\n *\r\n * **Cross-Instance Synchronization:**\r\n * Link multiple instances using any shared value (symbol, string, object, etc.) to automatically sync changes between them.\r\n *\r\n * @template S - Storage store name type\r\n *\r\n * @example\r\n * ```typescript\r\n * // Single instance\r\n * const storage = new ReactiveCookieStorage('my-app', {\r\n * path: '/',\r\n * maxAge: 86400,\r\n * secure: true,\r\n * sameSite: 'strict'\r\n * });\r\n *\r\n * // Multiple linked instances using a symbol\r\n * const linker = Symbol('cookie-sync');\r\n * const storageOne = new ReactiveCookieStorage('my-app', { secure: true }, linker);\r\n * const storageTwo = new ReactiveCookieStorage('my-app', { secure: false }, linker);\r\n * // Changes in storageOne will notify storageTwo and vice versa\r\n *\r\n * // Or use any other value type\r\n * const storageA = new ReactiveCookieStorage('my-app', { secure: true }, 'my-linker');\r\n * const storageB = new ReactiveCookieStorage('my-app', { secure: false }, 'my-linker');\r\n * ```\r\n */\r\nexport class ReactiveCookieStorage<S extends string = string> extends ReactiveStorage<S> {\r\n static readonly #MAX_COOKIE_SIZE = 4000; // Conservative 4KB limit\r\n static readonly #LINKERS = new Map<any, Set<ReactiveCookieStorage<any>>>();\r\n\r\n /**\r\n * Safely parse JSON with error handling.\r\n * Returns undefined if parsing fails.\r\n */\r\n static #parse(value: string): any {\r\n return jsonParse(value);\r\n }\r\n\r\n readonly #changes$ = new Subject<ReactiveStorageChangeEvent<S>>();\r\n readonly #linker?: any;\r\n\r\n constructor(\r\n public readonly appName: string = 'app',\r\n private readonly options: ReactiveCookieStorageOptions = {},\r\n linker?: any\r\n ) {\r\n super();\r\n\r\n // Register to linker group if provided\r\n if (linker) {\r\n this.#linker = linker;\r\n if (!ReactiveCookieStorage.#LINKERS.has(linker)) {\r\n ReactiveCookieStorage.#LINKERS.set(linker, new Set());\r\n }\r\n ReactiveCookieStorage.#LINKERS.get(linker)!.add(this);\r\n }\r\n }\r\n\r\n /**\r\n * Destroy the storage instance and cleanup resources.\r\n * Unregisters from linker group and completes the changes subject.\r\n * Call this when you're done using the storage to prevent memory leaks.\r\n */\r\n destroy(): void {\r\n // Unregister from linker group\r\n if (this.#linker) {\r\n const linkedInstances = ReactiveCookieStorage.#LINKERS.get(this.#linker);\r\n if (linkedInstances) {\r\n linkedInstances.delete(this);\r\n if (linkedInstances.size === 0) {\r\n ReactiveCookieStorage.#LINKERS.delete(this.#linker);\r\n }\r\n }\r\n }\r\n\r\n this.#changes$.complete();\r\n }\r\n\r\n protected async [ReactiveStorage.Props.GET_ALL](): Promise<any> {\r\n const cookies = this.#getAppCookies();\r\n\r\n return Object.fromEntries(\r\n Object.entries(cookies).map(([storeName, value]) => [storeName, ReactiveCookieStorage.#parse(value)])\r\n );\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n protected [ReactiveStorage.Props.CHANGES] = (this.#changes$ as any)[Symbol.asyncIterator] ?? toAsyncIterator(this.#changes$);\r\n\r\n protected async [ReactiveStorage.Props.SET](storeName: S, value: unknown): Promise<void> {\r\n const serialized = JSON.stringify(value);\r\n const cookieName = this.#getCookieName(storeName);\r\n\r\n // Validate size before setting\r\n const cookieString = `${cookieName}=${encodeURIComponent(serialized)}`;\r\n this.#validateSize(cookieString);\r\n\r\n this.#setCookie(cookieName, serialized); // Uses instance options\r\n\r\n const event = { storeName, value };\r\n this.#changes$.next(event);\r\n this.#notifyLinkedInstances(event);\r\n }\r\n\r\n protected async [ReactiveStorage.Props.REMOVE](storeName: S): Promise<void> {\r\n const cookieName = this.#getCookieName(storeName);\r\n\r\n // Delete cookie by setting max-age to 0\r\n this.#setCookie(cookieName, '', { maxAge: 0 });\r\n\r\n const event = { storeName, value: undefined };\r\n this.#changes$.next(event);\r\n this.#notifyLinkedInstances(event);\r\n }\r\n\r\n /**\r\n * Convert store name to cookie name by prefixing with app name.\r\n * Sanitizes to only allow alphanumeric, underscore, and hyphen.\r\n */\r\n #getCookieName(storeName: S): string {\r\n return `${this.appName}_${storeName}`.replace(/[^a-zA-Z0-9_-]/g, '_');\r\n }\r\n\r\n /**\r\n * Parse document.cookie string into key-value object.\r\n * Handles decoding of cookie values.\r\n */\r\n #parseCookies(): Record<string, string> {\r\n if (!document.cookie) {\r\n return {};\r\n }\r\n\r\n return Object.fromEntries(\r\n document.cookie\r\n .split('; ')\r\n .filter(Boolean)\r\n .map((cookie) => {\r\n const separatorIndex = cookie.indexOf('=');\r\n if (separatorIndex === -1) {\r\n return [cookie, ''];\r\n }\r\n const name = cookie.slice(0, separatorIndex);\r\n const value = cookie.slice(separatorIndex + 1);\r\n try {\r\n return [name, decodeURIComponent(value)];\r\n } catch {\r\n return [name, value]; // Return raw value if decode fails\r\n }\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * Get all cookies that belong to this app (matching appName prefix).\r\n * Returns object with storeName -> encoded value.\r\n */\r\n #getAppCookies(): Record<string, string> {\r\n const allCookies = this.#parseCookies();\r\n const prefix = `${this.appName}_`;\r\n const appCookies: Record<string, string> = {};\r\n\r\n for (const [cookieName, value] of Object.entries(allCookies)) {\r\n if (cookieName.startsWith(prefix)) {\r\n const storeName = cookieName.slice(prefix.length);\r\n appCookies[storeName] = value;\r\n }\r\n }\r\n\r\n return appCookies;\r\n }\r\n\r\n /**\r\n * Build and set a cookie with the instance's configured options.\r\n * Pass options parameter to override specific settings (e.g., maxAge: 0 to delete).\r\n */\r\n #setCookie(name: string, value: string, overrides: Partial<ReactiveCookieStorageOptions> = {}): void {\r\n const opts = { ...this.options, ...overrides };\r\n let cookie = `${name}=${encodeURIComponent(value)}`;\r\n\r\n if (opts.path !== undefined) cookie += `; path=${opts.path}`;\r\n if (opts.domain) cookie += `; domain=${opts.domain}`;\r\n if (opts.maxAge !== undefined) cookie += `; max-age=${opts.maxAge}`;\r\n if (opts.expires) cookie += `; expires=${opts.expires.toUTCString()}`;\r\n if (opts.secure) cookie += '; secure';\r\n if (opts.sameSite) cookie += `; samesite=${opts.sameSite}`;\r\n\r\n document.cookie = cookie;\r\n }\r\n\r\n /**\r\n * Validate that a cookie string doesn't exceed size limits.\r\n * Throws an error if the cookie is too large.\r\n */\r\n #validateSize(cookieString: string): void {\r\n if (cookieString.length > ReactiveCookieStorage.#MAX_COOKIE_SIZE) {\r\n throw new Error(\r\n `Cookie size (${cookieString.length} bytes) exceeds ${ReactiveCookieStorage.#MAX_COOKIE_SIZE} byte limit. ` +\r\n `Consider using localStorage for larger data or splitting across multiple stores.`\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Notify all other linked storage instances about a change.\r\n * This instance will not be notified (to prevent infinite loops).\r\n */\r\n #notifyLinkedInstances(event: ReactiveStorageChangeEvent<S>): void {\r\n if (!this.#linker) return;\r\n\r\n const linkedInstances = ReactiveCookieStorage.#LINKERS.get(this.#linker);\r\n if (!linkedInstances) return;\r\n\r\n for (const instance of linkedInstances) {\r\n if (instance !== this) {\r\n instance.#changes$.next(event);\r\n }\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"reactive-cookie-storage.js","sources":["../../../libs/reactive-storage/src/reactive-cookie-storage.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAyBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCG;AACG,MAAO,qBAAiD,SAAQ,eAAkB,CAAA;AAqBpE,IAAA,OAAA;AACC,IAAA,OAAA;AArBnB,IAAA,OAAgB,gBAAgB,GAAG,IAAI,CAAC;AACxC,IAAA,OAAgB,QAAQ,GAAG,IAAI,GAAG,EAAwC;AAE1E;;;AAGG;IACH,OAAO,MAAM,CAAC,KAAa,EAAA;AACzB,QAAA,OAAO,SAAS,CAAC,KAAK,CAAC;IACzB;AAES,IAAA,SAAS,GAAG,IAAI,OAAO,EAAiC;AACxD,IAAA,OAAO;AAEhB;;;;AAIG;AACH,IAAA,WAAA,CACkB,UA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