@telperion/ng-pack 1.3.2 → 1.4.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.
@@ -1 +1 @@
1
- {"version":3,"file":"telperion-ng-pack-storage-signals.mjs","sources":["../../storage-signals/src/storage.ts","../../storage-signals/src/local-storage.ts","../../storage-signals/src/session-storage.ts","../../storage-signals/src/telperion-ng-pack-storage-signals.ts"],"sourcesContent":["import { WritableSignal } from \"@angular/core\";\r\nimport { toSignal } from \"@angular/core/rxjs-interop\";\r\nimport { ReactiveStorage } from '@thalesrc/reactive-storage';\r\n\r\nexport interface StorageSignal<T> extends WritableSignal<T | null | undefined> {\r\n delete(): void;\r\n}\r\n\r\nexport function storageSignal<T>(storage: ReactiveStorage, store: string, key: string): StorageSignal<T> {\r\n const source = toSignal(storage.get<T>(store, key));\r\n\r\n function setter(value: T | null | undefined) {\r\n storage.set(store, key, value);\r\n }\r\n\r\n function updater(updaterFn: (value: T | null | undefined) => T | null | undefined) {\r\n const currentValue = source();\r\n const newValue = updaterFn(currentValue);\r\n\r\n storage.set(store, key, newValue);\r\n }\r\n\r\n function deleter() {\r\n storage.delete(store, key);\r\n }\r\n\r\n return new Proxy(source as StorageSignal<T>, {\r\n apply() {\r\n return source();\r\n },\r\n get(target, prop, receiver) {\r\n switch (prop) {\r\n case 'set':\r\n return setter;\r\n case 'update':\r\n return updater;\r\n case 'delete':\r\n return deleter;\r\n default:\r\n return Reflect.get(target, prop, receiver);\r\n }\r\n }\r\n })\r\n}\r\n","import { inject, InjectionToken, Provider } from \"@angular/core\";\r\nimport { ReactiveWebLocalStorage } from '@thalesrc/reactive-storage';\r\n\r\nimport { StorageSignal, storageSignal } from \"./storage\";\r\n\r\nconst LOCAL_STORAGE = new InjectionToken<ReactiveWebLocalStorage>('Telperion Local Storage');\r\n\r\nexport function provideLocalStorage(appName?: string): Provider {\r\n return {\r\n provide: LOCAL_STORAGE,\r\n useValue: new ReactiveWebLocalStorage(appName)\r\n };\r\n}\r\n\r\nexport function localStorageSignal<T>(store: string, key: string): StorageSignal<T> {\r\n const storage = inject(LOCAL_STORAGE);\r\n\r\n return storageSignal(storage, store, key);\r\n}\r\n","import { inject, InjectionToken, Provider } from \"@angular/core\";\r\nimport { ReactiveWebSessionStorage } from '@thalesrc/reactive-storage';\r\n\r\nimport { StorageSignal, storageSignal } from \"./storage\";\r\n\r\nconst SESSION_STORAGE = new InjectionToken<ReactiveWebSessionStorage>('Telperion Session Storage');\r\n\r\nexport function provideSessionStorage(appName?: string): Provider {\r\n return {\r\n provide: SESSION_STORAGE,\r\n useValue: new ReactiveWebSessionStorage(appName)\r\n };\r\n}\r\n\r\nexport function sessionStorageSignal<T>(store: string, key: string): StorageSignal<T> {\r\n const storage = inject(SESSION_STORAGE);\r\n\r\n return storageSignal(storage, store, key);\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;SAQgB,aAAa,CAAI,OAAwB,EAAE,KAAa,EAAE,GAAW,EAAA;AACnF,IAAA,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAI,KAAK,EAAE,GAAG,CAAC,CAAC;IAEnD,SAAS,MAAM,CAAC,KAA2B,EAAA;QACzC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC;IAChC;IAEA,SAAS,OAAO,CAAC,SAAgE,EAAA;AAC/E,QAAA,MAAM,YAAY,GAAG,MAAM,EAAE;AAC7B,QAAA,MAAM,QAAQ,GAAG,SAAS,CAAC,YAAY,CAAC;QAExC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC;IACnC;AAEA,IAAA,SAAS,OAAO,GAAA;AACd,QAAA,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC;IAC5B;AAEA,IAAA,OAAO,IAAI,KAAK,CAAC,MAA0B,EAAE;QAC3C,KAAK,GAA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als/src/local-storage.ts","../../storage-signals/src/session-storage.ts","../../storage-signals/src/cookie-storage.ts","../../storage-signals/src/telperion-ng-pack-storage-signals.ts"],"sourcesContent":["import { toSignal } from \"@angular/core/rxjs-interop\";\r\nimport { ReactiveStorage } from '@telperion/reactive-storage';\r\nimport { StorageSignal } from \"./storage-signal\";\r\n\r\n/**\r\n * Creates a StorageSignal from a ReactiveStorage instance.\r\n *\r\n * @template T - The type of value stored\r\n * @param storage - The ReactiveStorage instance (localStorage, sessionStorage, or cookie storage)\r\n * @param store - The storage namespace/store name\r\n * @param key - The key within the store\r\n * @returns A StorageSignal that provides reactive access to the stored value\r\n *\r\n * @remarks\r\n * This is a low-level factory function that bridges Angular signals with ReactiveStorage.\r\n * Most applications should use the higher-level functions:\r\n * - {@link localStorageSignal} for localStorage\r\n * - {@link sessionStorageSignal} for sessionStorage\r\n * - {@link cookieStorageSignal} for cookies\r\n *\r\n * The function:\r\n * 1. Converts the ReactiveStorage Observable into an Angular signal using `toSignal`\r\n * 2. Creates a Proxy that intercepts calls to add `set`, `update`, and `delete` methods\r\n * 3. Ensures all storage operations propagate to both the underlying storage and the signal\r\n *\r\n * **Proxy Pattern:**\r\n * The returned signal is a Proxy that:\r\n * - Delegates reading to the underlying signal\r\n * - Provides `set()` to write values\r\n * - Provides `update()` for functional updates\r\n * - Provides `delete()` to remove the value\r\n *\r\n * @example\r\n * ```typescript\r\n * // Typically used internally by specialized signal creators\r\n * import { ReactiveWebLocalStorage } from '@telperion/reactive-storage';\r\n *\r\n * const storage = new ReactiveWebLocalStorage('my-app');\r\n * const userSignal = storageSignal<User>(storage, 'users', 'current');\r\n *\r\n * userSignal.set({ id: 1, name: 'Alice' });\r\n * console.log(userSignal()); // { id: 1, name: 'Alice' }\r\n *\r\n * userSignal.update(user => ({ ...user, name: 'Bob' }));\r\n * userSignal.delete();\r\n * ```\r\n *\r\n * @internal This is primarily for internal use. Use the specialized signal creators instead.\r\n */\r\nexport function storageSignal<T>(storage: ReactiveStorage, store: string, key: string): StorageSignal<T> {\r\n const source = toSignal(storage.get<T>(store, key));\r\n\r\n function setter(value: T | null | undefined) {\r\n storage.set(store, key, value);\r\n }\r\n\r\n function updater(updaterFn: (value: T | null | undefined) => T | null | undefined) {\r\n const currentValue = source();\r\n const newValue = updaterFn(currentValue);\r\n\r\n storage.set(store, key, newValue);\r\n }\r\n\r\n function deleter() {\r\n storage.delete(store, key);\r\n }\r\n\r\n return new Proxy(source as StorageSignal<T>, {\r\n apply() {\r\n return source();\r\n },\r\n get(target, prop, receiver) {\r\n switch (prop) {\r\n case 'set':\r\n return setter;\r\n case 'update':\r\n return updater;\r\n case 'delete':\r\n return deleter;\r\n default:\r\n return Reflect.get(target, prop, receiver);\r\n }\r\n }\r\n })\r\n}\r\n","import { inject, InjectionToken, Provider } from \"@angular/core\";\r\nimport { ReactiveWebLocalStorage } from '@telperion/reactive-storage';\r\n\r\nimport { storageSignal } from \"./storage\";\r\nimport { StorageSignal } from \"./storage-signal\";\r\n\r\n/**\r\n * Injection token for the ReactiveWebLocalStorage singleton.\r\n * @internal\r\n */\r\nconst LOCAL_STORAGE = new InjectionToken<ReactiveWebLocalStorage>('Telperion Local Storage');\r\n\r\n/**\r\n * Provides a ReactiveWebLocalStorage instance for dependency injection.\r\n *\r\n * @param appName - Optional application name for namespacing localStorage keys\r\n * @returns An Angular provider configuration\r\n *\r\n * @remarks\r\n * This provider creates a singleton ReactiveWebLocalStorage instance that can be injected\r\n * throughout your application. All `localStorageSignal` calls will use this shared instance,\r\n * ensuring consistent storage access and change detection.\r\n *\r\n * **Namespacing:**\r\n * The `appName` parameter prefixes all localStorage keys to prevent conflicts:\r\n * - With appName: `my-app:store:key`\r\n * - Without appName: `store:key`\r\n *\r\n * **Singleton Pattern:**\r\n * Only one instance is created per application, ensuring:\r\n * - Consistent storage access across components\r\n * - Efficient memory usage\r\n * - Reliable cross-component synchronization\r\n *\r\n * @example\r\n * ```typescript\r\n * // app.config.ts\r\n * import { ApplicationConfig } from '@angular/core';\r\n * import { provideLocalStorage } from '@telperion/ng-pack/storage-signals';\r\n *\r\n * export const appConfig: ApplicationConfig = {\r\n * providers: [\r\n * provideLocalStorage('my-app'),\r\n * // ... other providers\r\n * ]\r\n * };\r\n * ```\r\n *\r\n * @example\r\n * ```typescript\r\n * // Without namespace (keys are not prefixed)\r\n * export const appConfig: ApplicationConfig = {\r\n * providers: [\r\n * provideLocalStorage(),\r\n * ]\r\n * };\r\n * ```\r\n *\r\n * @public\r\n */\r\nexport function provideLocalStorage(appName?: string): Provider {\r\n return {\r\n provide: LOCAL_STORAGE,\r\n useValue: new ReactiveWebLocalStorage(appName)\r\n };\r\n}\r\n\r\n/**\r\n * Creates a reactive signal connected to browser's localStorage.\r\n *\r\n * @template T - The type of value stored\r\n * @param store - The storage namespace/store name\r\n * @param key - The key within the store\r\n * @returns A StorageSignal that reactively tracks the localStorage value\r\n *\r\n * @remarks\r\n * This function creates an Angular signal that automatically syncs with localStorage.\r\n * Any changes to the value (via `set`, `update`, or `delete`) are immediately persisted\r\n * to localStorage and propagate to all components using the same signal.\r\n *\r\n * **Requirements:**\r\n * Must call {@link provideLocalStorage} in application config before using this function.\r\n *\r\n * **Storage Key:**\r\n * The actual localStorage key is formed as:\r\n * - With app name: `appName:store:key`\r\n * - Without app name: `store:key`\r\n *\r\n * **Type Safety:**\r\n * Values are automatically serialized/deserialized as JSON:\r\n * - Objects and arrays are preserved\r\n * - Primitives (string, number, boolean) work correctly\r\n * - Functions and undefined values are not supported\r\n *\r\n * **Cross-Component Sync:**\r\n * All components using the same `store` and `key` share the same signal state.\r\n * Changes in one component immediately reflect in others.\r\n *\r\n * @example\r\n * ```typescript\r\n * import { Component } from '@angular/core';\r\n * import { localStorageSignal } from '@telperion/ng-pack/storage-signals';\r\n *\r\n * @Component({\r\n * selector: 'app-settings',\r\n * template: `\r\n * <div>\r\n * <p>Theme: {{ theme() }}</p>\r\n * <button (click)=\"theme.set('dark')\">Dark</button>\r\n * <button (click)=\"theme.set('light')\">Light</button>\r\n * <button (click)=\"theme.delete()\">Reset</button>\r\n * </div>\r\n * `\r\n * })\r\n * export class SettingsComponent {\r\n * theme = localStorageSignal<string>('settings', 'theme');\r\n * }\r\n * ```\r\n *\r\n * @example\r\n * ```typescript\r\n * // Complex types\r\n * interface UserPreferences {\r\n * theme: 'light' | 'dark';\r\n * fontSize: number;\r\n * notifications: boolean;\r\n * }\r\n *\r\n * const prefs = localStorageSignal<UserPreferences>('user', 'preferences');\r\n *\r\n * // Set entire object\r\n * prefs.set({ theme: 'dark', fontSize: 14, notifications: true });\r\n *\r\n * // Update specific property\r\n * prefs.update(current => ({\r\n * ...current,\r\n * theme: current?.theme === 'dark' ? 'light' : 'dark'\r\n * }));\r\n * ```\r\n *\r\n * @throws Error if {@link provideLocalStorage} was not called in application config\r\n *\r\n * @public\r\n */\r\nexport function localStorageSignal<T>(store: string, key: string): StorageSignal<T> {\r\n const storage = inject(LOCAL_STORAGE);\r\n\r\n return storageSignal(storage, store, key);\r\n}\r\n","import { inject, InjectionToken, Provider } from \"@angular/core\";\r\nimport { ReactiveWebSessionStorage } from '@telperion/reactive-storage';\r\n\r\nimport { storageSignal } from \"./storage\";\r\nimport { StorageSignal } from \"./storage-signal\";\r\n\r\n/**\r\n * Injection token for the ReactiveWebSessionStorage singleton.\r\n * @internal\r\n */\r\nconst SESSION_STORAGE = new InjectionToken<ReactiveWebSessionStorage>('Telperion Session Storage');\r\n\r\n/**\r\n * Provides a ReactiveWebSessionStorage instance for dependency injection.\r\n *\r\n * @param appName - Optional application name for namespacing sessionStorage keys\r\n * @returns An Angular provider configuration\r\n *\r\n * @remarks\r\n * This provider creates a singleton ReactiveWebSessionStorage instance that can be injected\r\n * throughout your application. All `sessionStorageSignal` calls will use this shared instance,\r\n * ensuring consistent storage access and change detection.\r\n *\r\n * **SessionStorage vs LocalStorage:**\r\n * - **sessionStorage**: Data persists only for the browser tab/window session (cleared on close)\r\n * - **localStorage**: Data persists indefinitely until explicitly cleared\r\n *\r\n * **Use Cases for sessionStorage:**\r\n * - Multi-step form wizards\r\n * - Temporary authentication tokens\r\n * - Per-session user preferences\r\n * - Shopping cart for current session\r\n * - Tab-specific state isolation\r\n *\r\n * **Namespacing:**\r\n * The `appName` parameter prefixes all sessionStorage keys to prevent conflicts:\r\n * - With appName: `my-app:store:key`\r\n * - Without appName: `store:key`\r\n *\r\n * **Singleton Pattern:**\r\n * Only one instance is created per application, ensuring:\r\n * - Consistent storage access across components\r\n * - Efficient memory usage\r\n * - Reliable cross-component synchronization\r\n *\r\n * @example\r\n * ```typescript\r\n * // app.config.ts\r\n * import { ApplicationConfig } from '@angular/core';\r\n * import { provideSessionStorage } from '@telperion/ng-pack/storage-signals';\r\n *\r\n * export const appConfig: ApplicationConfig = {\r\n * providers: [\r\n * provideSessionStorage('my-app'),\r\n * // ... other providers\r\n * ]\r\n * };\r\n * ```\r\n *\r\n * @example\r\n * ```typescript\r\n * // Without namespace\r\n * export const appConfig: ApplicationConfig = {\r\n * providers: [\r\n * provideSessionStorage(),\r\n * ]\r\n * };\r\n * ```\r\n *\r\n * @public\r\n */\r\nexport function provideSessionStorage(appName?: string): Provider {\r\n return {\r\n provide: SESSION_STORAGE,\r\n useValue: new ReactiveWebSessionStorage(appName)\r\n };\r\n}\r\n\r\n/**\r\n * Creates a reactive signal connected to browser's sessionStorage.\r\n *\r\n * @template T - The type of value stored\r\n * @param store - The storage namespace/store name\r\n * @param key - The key within the store\r\n * @returns A StorageSignal that reactively tracks the sessionStorage value\r\n *\r\n * @remarks\r\n * This function creates an Angular signal that automatically syncs with sessionStorage.\r\n * Any changes to the value (via `set`, `update`, or `delete`) are immediately persisted\r\n * to sessionStorage and propagate to all components using the same signal.\r\n *\r\n * **Session Lifecycle:**\r\n * - Data is cleared when the browser tab/window is closed\r\n * - Each tab has its own independent sessionStorage\r\n * - Opening a page in a new tab creates fresh sessionStorage (even for same URL)\r\n * - Refreshing the page preserves sessionStorage data\r\n *\r\n * **Requirements:**\r\n * Must call {@link provideSessionStorage} in application config before using this function.\r\n *\r\n * **Storage Key:**\r\n * The actual sessionStorage key is formed as:\r\n * - With app name: `appName:store:key`\r\n * - Without app name: `store:key`\r\n *\r\n * **Type Safety:**\r\n * Values are automatically serialized/deserialized as JSON:\r\n * - Objects and arrays are preserved\r\n * - Primitives (string, number, boolean) work correctly\r\n * - Functions and undefined values are not supported\r\n *\r\n * **Cross-Component Sync:**\r\n * All components in the same tab using the same `store` and `key` share the same signal state.\r\n * Changes in one component immediately reflect in others within the same tab.\r\n * Different tabs do NOT share sessionStorage.\r\n *\r\n * @example\r\n * ```typescript\r\n * import { Component } from '@angular/core';\r\n * import { sessionStorageSignal } from '@telperion/ng-pack/storage-signals';\r\n *\r\n * @Component({\r\n * selector: 'app-wizard',\r\n * template: `\r\n * <div>\r\n * <p>Current Step: {{ currentStep() }}</p>\r\n * <button (click)=\"nextStep()\">Next</button>\r\n * <button (click)=\"currentStep.delete()\">Reset</button>\r\n * </div>\r\n * `\r\n * })\r\n * export class WizardComponent {\r\n * currentStep = sessionStorageSignal<number>('wizard', 'step');\r\n *\r\n * nextStep() {\r\n * this.currentStep.update(step => (step ?? 0) + 1);\r\n * }\r\n * }\r\n * ```\r\n *\r\n * @example\r\n * ```typescript\r\n * // Form data that shouldn't persist across sessions\r\n * interface FormData {\r\n * email: string;\r\n * message: string;\r\n * }\r\n *\r\n * const formData = sessionStorageSignal<FormData>('contact', 'draft');\r\n *\r\n * // Auto-save form data (cleared when tab closes)\r\n * formData.set({ email: 'user@example.com', message: 'Hello!' });\r\n *\r\n * // Update specific field\r\n * formData.update(current => ({\r\n * ...current,\r\n * message: 'Updated message'\r\n * }));\r\n * ```\r\n *\r\n * @throws Error if {@link provideSessionStorage} was not called in application config\r\n *\r\n * @public\r\n */\r\nexport function sessionStorageSignal<T>(store: string, key: string): StorageSignal<T> {\r\n const storage = inject(SESSION_STORAGE);\r\n\r\n return storageSignal(storage, store, key);\r\n}\r\n","import { inject, Provider } from '@angular/core';\r\nimport { ReactiveCookieStorage, ReactiveCookieStorageOptions } from '@telperion/reactive-storage';\r\nimport { storageSignal } from './storage';\r\n\r\n/**\r\n * Internal provider that manages ReactiveCookieStorage instances with different configurations.\r\n *\r\n * @remarks\r\n * This class implements a registry pattern to ensure that cookie storages with identical\r\n * configurations share the same underlying ReactiveCookieStorage instance. This is critical for:\r\n * - Preventing duplicate cookie writes\r\n * - Ensuring consistent change detection across components\r\n * - Optimizing memory usage\r\n *\r\n * **Linker Pattern:**\r\n * All instances created by this provider share a common linker (Symbol) to enable\r\n * cross-instance synchronization even when using different option combinations.\r\n *\r\n * **Instance Deduplication:**\r\n * Two `cookieStorageSignal` calls with the same options will reuse the same storage instance,\r\n * preventing redundant cookie operations.\r\n *\r\n * @internal This class is not exported publicly\r\n */\r\nclass CookieStorageProvider {\r\n /**\r\n * Valid cookie option keys that can be used to configure cookie storage.\r\n * Filters out any invalid properties from being passed to cookie operations.\r\n */\r\n static #VALID_OPTIONS = ['path', 'domain', 'secure', 'sameSite', 'expires', 'maxAge'] as (keyof ReactiveCookieStorageOptions)[];\r\n\r\n /**\r\n * Shared linker symbol used to synchronize all cookie storage instances\r\n * created by this provider, enabling cross-instance change notifications.\r\n */\r\n #linker = Symbol('ReactiveCookieStorage Linker');\r\n\r\n /**\r\n * Registry of ReactiveCookieStorage instances keyed by their configuration options.\r\n * Ensures instances with identical options are reused.\r\n */\r\n #stores = new Map<ReactiveCookieStorageOptions, ReactiveCookieStorage>();\r\n\r\n /**\r\n * Creates a new CookieStorageProvider with base configuration.\r\n *\r\n * @param appName - Optional application name for namespacing cookie keys\r\n * @param baseOptions - Default cookie options applied to all storage instances\r\n */\r\n constructor(\r\n private appName?: string,\r\n private baseOptions: ReactiveCookieStorageOptions = {}\r\n ) {\r\n const parsedOptions = this.#parseOptions(baseOptions);\r\n\r\n this.#stores.set(parsedOptions, new ReactiveCookieStorage(appName, parsedOptions, this.#linker));\r\n }\r\n\r\n /**\r\n * Gets or creates a ReactiveCookieStorage instance with the specified options.\r\n *\r\n * @param options - Cookie options to override base options\r\n * @returns A ReactiveCookieStorage instance (reused if options match existing instance)\r\n *\r\n * @remarks\r\n * This method implements option merging and instance deduplication:\r\n * 1. Merges provided options with base options (provided options take precedence)\r\n * 2. Checks if an instance with these exact options already exists\r\n * 3. Returns existing instance if found, otherwise creates and caches a new one\r\n *\r\n * All instances share the same linker for cross-instance synchronization.\r\n */\r\n getStore(options: ReactiveCookieStorageOptions = {}): ReactiveCookieStorage {\r\n const parsedOptions = this.#parseOptions({...this.baseOptions, ...options});\r\n let existingKey = this.#getStoredOptions(parsedOptions);\r\n\r\n if (!existingKey) {\r\n this.#stores.set(parsedOptions, new ReactiveCookieStorage(this.appName, parsedOptions, this.#linker));\r\n existingKey = parsedOptions;\r\n }\r\n\r\n return this.#stores.get(existingKey)!;\r\n }\r\n\r\n /**\r\n * Filters cookie options to include only valid properties.\r\n *\r\n * @param options - Raw options object that may contain invalid properties\r\n * @returns Filtered options containing only valid cookie configuration properties\r\n */\r\n #parseOptions(options: ReactiveCookieStorageOptions) {\r\n return Object.fromEntries(\r\n Object.entries(options).filter(([key]) => CookieStorageProvider.#VALID_OPTIONS.includes(key as keyof ReactiveCookieStorageOptions))\r\n ) as ReactiveCookieStorageOptions;\r\n }\r\n\r\n /**\r\n * Searches the registry for an existing options object that matches the provided options.\r\n *\r\n * @param options - Cookie options to search for\r\n * @returns The stored options object if found, undefined otherwise\r\n *\r\n * @remarks\r\n * Two options objects are considered equal if all valid cookie properties have identical values.\r\n */\r\n #getStoredOptions(options: ReactiveCookieStorageOptions): ReactiveCookieStorageOptions | undefined {\r\n const stored = this.#stores.keys();\r\n\r\n return stored.find(storedOpts => {\r\n return CookieStorageProvider.#VALID_OPTIONS.every(key => storedOpts[key] === options[key]);\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * Provides a CookieStorageProvider instance for dependency injection.\r\n *\r\n * @param appName - Optional application name for namespacing cookie keys\r\n * @param options - Default cookie options applied to all cookie storage signals\r\n * @returns An Angular provider configuration\r\n *\r\n * @remarks\r\n * This provider creates a singleton CookieStorageProvider that manages all cookie storage\r\n * instances in your application. All `cookieStorageSignal` calls will use this shared provider.\r\n *\r\n * **Cookie Namespacing:**\r\n * The `appName` parameter prefixes all cookie names to prevent conflicts:\r\n * - With appName: `my-app:store:key`\r\n * - Without appName: `store:key`\r\n *\r\n * **Base Options:**\r\n * The `options` parameter provides default cookie configuration for all signals.\r\n * Individual signals can override these options when created.\r\n *\r\n * **Common Options:**\r\n * - `path` - Cookie path (default: current path)\r\n * - `domain` - Cookie domain (default: current domain)\r\n * - `secure` - Require HTTPS (recommended for production)\r\n * - `sameSite` - CSRF protection ('strict' | 'lax' | 'none')\r\n * - `maxAge` - Expiry time in seconds\r\n * - `expires` - Expiry as Date object\r\n *\r\n * **Instance Management:**\r\n * The provider automatically deduplicates storage instances:\r\n * - Signals with identical options share the same storage instance\r\n * - All instances are linked for cross-instance synchronization\r\n * - Memory-efficient for applications with many cookie signals\r\n *\r\n * @example\r\n * ```typescript\r\n * // app.config.ts\r\n * import { ApplicationConfig } from '@angular/core';\r\n * import { provideCookieStorage } from '@telperion/ng-pack/storage-signals';\r\n *\r\n * export const appConfig: ApplicationConfig = {\r\n * providers: [\r\n * provideCookieStorage('my-app', {\r\n * path: '/',\r\n * secure: true,\r\n * sameSite: 'strict',\r\n * maxAge: 86400 // 24 hours\r\n * }),\r\n * ]\r\n * };\r\n * ```\r\n *\r\n * @example\r\n * ```typescript\r\n * // Minimal configuration\r\n * export const appConfig: ApplicationConfig = {\r\n * providers: [\r\n * provideCookieStorage('my-app'),\r\n * ]\r\n * };\r\n * ```\r\n *\r\n * @public\r\n */\r\nexport function provideCookieStorage(\r\n appName?: string,\r\n options?: ReactiveCookieStorageOptions\r\n): Provider {\r\n return {\r\n provide: CookieStorageProvider,\r\n useValue: new CookieStorageProvider(appName, options)\r\n };\r\n}\r\n\r\n/**\r\n * Creates a reactive signal connected to browser cookies.\r\n *\r\n * @template T - The type of value stored\r\n * @param store - The cookie namespace/store name\r\n * @param key - The cookie key within the store\r\n * @param options - Optional cookie-specific options that override provider defaults\r\n * @returns A StorageSignal that reactively tracks the cookie value\r\n *\r\n * @remarks\r\n * This function creates an Angular signal that automatically syncs with browser cookies.\r\n * Any changes to the value (via `set`, `update`, or `delete`) are immediately written\r\n * to cookies and propagate to all components using the same signal.\r\n *\r\n * **Requirements:**\r\n * Must call {@link provideCookieStorage} in application config before using this function.\r\n *\r\n * **Cookie Name:**\r\n * The actual cookie name is formed as:\r\n * - With app name: `appName:store:key`\r\n * - Without app name: `store:key`\r\n *\r\n * **Size Limitations:**\r\n * Cookies have a ~4KB size limit. The underlying ReactiveCookieStorage enforces a 4000 byte\r\n * limit and throws an error if exceeded. Use localStorage for larger data.\r\n *\r\n * **Options Merging:**\r\n * Cookie options are merged in this order (later overrides earlier):\r\n * 1. Provider base options (from `provideCookieStorage`)\r\n * 2. Signal-specific options (from this function's `options` parameter)\r\n *\r\n * **Instance Deduplication:**\r\n * Signals with identical merged options share the same underlying storage instance:\r\n * ```typescript\r\n * // These share the same storage instance\r\n * const token1 = cookieStorageSignal('auth', 'token', { secure: true });\r\n * const token2 = cookieStorageSignal('auth', 'token', { secure: true });\r\n *\r\n * // These use different instances (different options)\r\n * const temp = cookieStorageSignal('auth', 'token', { maxAge: 300 });\r\n * ```\r\n *\r\n * **Type Safety:**\r\n * Values are automatically serialized/deserialized as JSON:\r\n * - Objects and arrays are preserved\r\n * - Primitives (string, number, boolean) work correctly\r\n * - Functions and undefined values are not supported\r\n *\r\n * **Security Best Practices:**\r\n * - Use `secure: true` in production (HTTPS only)\r\n * - Use `sameSite: 'strict'` for CSRF protection\r\n * - Set appropriate `maxAge` or `expires` for sensitive data\r\n * - Never store sensitive data in cookies without encryption\r\n *\r\n * @example\r\n * ```typescript\r\n * import { Component } from '@angular/core';\r\n * import { cookieStorageSignal } from '@telperion/ng-pack/storage-signals';\r\n *\r\n * @Component({\r\n * selector: 'app-auth',\r\n * template: `\r\n * <div>\r\n * <p>Token: {{ authToken() }}</p>\r\n * <button (click)=\"login()\">Login</button>\r\n * <button (click)=\"logout()\">Logout</button>\r\n * </div>\r\n * `\r\n * })\r\n * export class AuthComponent {\r\n * // Secure cookie with 1 hour expiry\r\n * authToken = cookieStorageSignal<string>('auth', 'token', {\r\n * secure: true,\r\n * sameSite: 'strict',\r\n * maxAge: 3600\r\n * });\r\n *\r\n * login() {\r\n * this.authToken.set('abc123');\r\n * }\r\n *\r\n * logout() {\r\n * this.authToken.delete();\r\n * }\r\n * }\r\n * ```\r\n *\r\n * @example\r\n * ```typescript\r\n * // User preferences with different cookie lifetimes\r\n * const theme = cookieStorageSignal<string>('prefs', 'theme', {\r\n * maxAge: 31536000 // 1 year\r\n * });\r\n *\r\n * const tempSetting = cookieStorageSignal<boolean>('prefs', 'banner-dismissed', {\r\n * maxAge: 86400 // 1 day\r\n * });\r\n *\r\n * theme.set('dark');\r\n * tempSetting.set(true);\r\n * ```\r\n *\r\n * @throws Error if {@link provideCookieStorage} was not called in application config\r\n * @throws Error if the serialized value exceeds 4000 bytes\r\n *\r\n * @public\r\n */\r\nexport function cookieStorageSignal<T>(store: string, key: string, options?: ReactiveCookieStorageOptions) {\r\n const provider = inject(CookieStorageProvider);\r\n const storage = provider.getStore(options);\r\n\r\n return storageSignal(storage, store, key);\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CG;SACa,aAAa,CAAI,OAAwB,EAAE,KAAa,EAAE,GAAW,EAAA;AACnF,IAAA,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAI,KAAK,EAAE,GAAG,CAAC,CAAC;IAEnD,SAAS,MAAM,CAAC,KAA2B,EAAA;QACzC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC;IAChC;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DG;AACG,SAAU,oBAAoB,CAClC,OAAgB,EAChB,OAAsC,EAAA;IAEtC,OAAO;AACL,QAAA,OAAO,EAAE,qBAAqB;AAC9B,QAAA,QAAQ,EAAE,IAAI,qBAAqB,CAAC,OAAO,EAAE,OAAO;KACrD;AACH;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0GG;SACa,mBAAmB,CAAI,KAAa,EAAE,GAAW,EAAE,OAAsC,EAAA;AACvG,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,qBAAqB,CAAC;IAC9C,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC;IAE1C,OAAO,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC;AAC3C;;AC5SA;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@telperion/ng-pack",
3
- "version": "1.3.2",
4
- "description": "Collection of Angular utilities and libraries organized as secondary entry points. Includes signal-based storage (localStorage/sessionStorage), SSE client with HttpClient-inspired interceptors, event modifier plugins, and more. Built with TypeScript, RxJS, and Angular Signals for modern Angular applications.",
3
+ "version": "1.4.1",
4
+ "description": "Collection of Angular utilities and libraries organized as secondary entry points. Includes signal-based storage (localStorage/sessionStorage/cookieStorage), SSE client with HttpClient-inspired interceptors, event modifier plugins, and more. Built with TypeScript, RxJS, and Angular Signals for modern Angular applications.",
5
5
  "keywords": [
6
6
  "angular",
7
7
  "angular-signals",
@@ -11,6 +11,7 @@
11
11
  "eventsource",
12
12
  "localstorage",
13
13
  "sessionstorage",
14
+ "cookie",
14
15
  "storage",
15
16
  "signals",
16
17
  "interceptors",
@@ -33,7 +34,7 @@
33
34
  "dependencies": {
34
35
  "@thalesrc/extra-ts-types": "^1.4.0",
35
36
  "@thalesrc/js-utils": "^3.4.0",
36
- "@thalesrc/reactive-storage": "^1.0.5",
37
+ "@telperion/reactive-storage": "^1.2.0",
37
38
  "tslib": "^2.3.0"
38
39
  },
39
40
  "sideEffects": false,
@@ -1,16 +1,18 @@
1
1
  # @telperion/ng-pack/storage-signals
2
2
 
3
- Angular signals-based wrapper for browser's localStorage and sessionStorage with reactive updates.
3
+ Angular signals-based wrapper for browser's localStorage, sessionStorage, and cookies with reactive updates.
4
4
 
5
5
  ## Features
6
6
 
7
7
  - 🚀 **Signal-based API** - Seamlessly integrate with Angular's signal system
8
8
  - 🔄 **Reactive updates** - Automatically sync changes across components
9
9
  - 🎯 **Type-safe** - Full TypeScript support with generic typing
10
- - 🏪 **Dual storage support** - Works with both localStorage and sessionStorage
10
+ - 🏪 **Triple storage support** - Works with localStorage, sessionStorage, and cookies
11
11
  - 🔑 **Namespaced storage** - Organize storage with app names and store names
12
12
  - 🎯 **Nested property access** - Access deep object properties using dot notation
13
13
  - 🧹 **Simple API** - Signal interface with `set()`, `update()`, and `delete()` methods
14
+ - 🍪 **Cookie configuration** - Full control over cookie options (secure, sameSite, maxAge, etc.)
15
+ - 🔗 **Cross-instance sync** - Cookie signals support instance synchronization
14
16
 
15
17
  ## Installation
16
18
 
@@ -54,6 +56,35 @@ export const appConfig: ApplicationConfig = {
54
56
  };
55
57
  ```
56
58
 
59
+ ### Cookie Storage
60
+
61
+ Configure cookie storage in your application config:
62
+
63
+ ```typescript
64
+ import { ApplicationConfig } from '@angular/core';
65
+ import { provideCookieStorage } from '@telperion/ng-pack/storage-signals';
66
+
67
+ export const appConfig: ApplicationConfig = {
68
+ providers: [
69
+ provideCookieStorage('my-app', {
70
+ path: '/',
71
+ secure: true,
72
+ sameSite: 'strict',
73
+ maxAge: 86400 // 24 hours
74
+ }),
75
+ // ... other providers
76
+ ]
77
+ };
78
+ ```
79
+
80
+ **Cookie Options:**
81
+ - `path` - Cookie path (default: current path)
82
+ - `domain` - Cookie domain (default: current domain)
83
+ - `secure` - Require HTTPS (recommended for production)
84
+ - `sameSite` - CSRF protection: `'strict'` | `'lax'` | `'none'`
85
+ - `maxAge` - Expiry time in seconds
86
+ - `expires` - Expiry as Date object
87
+
57
88
  ## Usage
58
89
 
59
90
  ### Basic Usage
@@ -110,6 +141,45 @@ export class WizardComponent {
110
141
  }
111
142
  ```
112
143
 
144
+ ### Cookie Storage
145
+
146
+ ```typescript
147
+ import { Component } from '@angular/core';
148
+ import { cookieStorageSignal } from '@telperion/ng-pack/storage-signals';
149
+
150
+ @Component({
151
+ selector: 'app-auth',
152
+ template: `
153
+ <div>
154
+ @if (authToken()) {
155
+ <p>Authenticated</p>
156
+ <button (click)="logout()">Logout</button>
157
+ } @else {
158
+ <button (click)="login()">Login</button>
159
+ }
160
+ </div>
161
+ `
162
+ })
163
+ export class AuthComponent {
164
+ // Create a signal connected to cookies with custom options
165
+ authToken = cookieStorageSignal<string>('auth', 'token', {
166
+ secure: true,
167
+ sameSite: 'strict',
168
+ maxAge: 3600 // 1 hour
169
+ });
170
+
171
+ login() {
172
+ this.authToken.set('abc123token');
173
+ }
174
+
175
+ logout() {
176
+ this.authToken.delete();
177
+ }
178
+ }
179
+ ```
180
+
181
+ **Important:** Cookies have a ~4KB size limit. The library enforces a 4000-byte limit and throws an error if exceeded. Use localStorage for larger data.
182
+
113
183
  ### Nested Property Access
114
184
 
115
185
  One of the most powerful features is the ability to access nested object properties using dot notation:
@@ -237,6 +307,47 @@ Creates a signal connected to sessionStorage. Must be called within an injection
237
307
 
238
308
  ---
239
309
 
310
+ ### `provideCookieStorage(appName?: string, options?: ReactiveCookieStorageOptions): Provider`
311
+
312
+ Creates a provider for cookie storage integration.
313
+
314
+ **Parameters:**
315
+ - `appName` (optional) - Namespace prefix for all cookie names
316
+ - `options` (optional) - Default cookie options applied to all signals
317
+ - `path` - Cookie path
318
+ - `domain` - Cookie domain
319
+ - `secure` - Require HTTPS
320
+ - `sameSite` - CSRF protection (`'strict'` | `'lax'` | `'none'`)
321
+ - `maxAge` - Expiry time in seconds
322
+ - `expires` - Expiry as Date object
323
+
324
+ **Returns:** Angular Provider
325
+
326
+ ---
327
+
328
+ ### `cookieStorageSignal<T>(store: string, key: string, options?: ReactiveCookieStorageOptions): StorageSignal<T>`
329
+
330
+ Creates a signal connected to browser cookies. Must be called within an injection context.
331
+
332
+ **Parameters:**
333
+ - `store` - Storage namespace/category (e.g., 'auth', 'preferences')
334
+ - `key` - Unique key within the store
335
+ - `options` (optional) - Cookie-specific options that override provider defaults
336
+
337
+ **Returns:** `StorageSignal<T>`
338
+
339
+ **Limitations:**
340
+ - Maximum ~4KB per cookie (enforced at 4000 bytes)
341
+ - Throws error if value exceeds size limit
342
+
343
+ **Security Best Practices:**
344
+ - Use `secure: true` in production (HTTPS only)
345
+ - Use `sameSite: 'strict'` for CSRF protection
346
+ - Set appropriate `maxAge` for sensitive data
347
+ - Never store unencrypted sensitive data
348
+
349
+ ---
350
+
240
351
  ### `StorageSignal<T>`
241
352
 
242
353
  A signal interface extending Angular's `WritableSignal` with additional storage methods.
@@ -249,7 +360,7 @@ A signal interface extending Angular's `WritableSignal` with additional storage
249
360
 
250
361
  ## Storage Organization
251
362
 
252
- The library uses a hierarchical storage structure:
363
+ The library uses a hierarchical storage structure for all storage types:
253
364
 
254
365
  ```
255
366
  [appName]:[store]:[key] = value
@@ -259,14 +370,35 @@ Example:
259
370
  ```typescript
260
371
  // With provideLocalStorage('my-app')
261
372
  localStorageSignal<string>('settings', 'theme');
262
- // Creates key: "my-app:settings:theme"
373
+ // Creates localStorage key: "my-app:settings:theme"
374
+
375
+ // With provideSessionStorage('my-app')
376
+ sessionStorageSignal<number>('user', 'id');
377
+ // Creates sessionStorage key: "my-app:user:id"
263
378
 
264
- localStorageSignal<number>('user', 'id');
265
- // Creates key: "my-app:user:id"
379
+ // With provideCookieStorage('my-app')
380
+ cookieStorageSignal<string>('auth', 'token');
381
+ // Creates cookie name: "my-app:auth:token"
266
382
  ```
267
383
 
268
384
  This organization helps prevent key collisions and makes storage management cleaner.
269
385
 
386
+ ## Storage Type Comparison
387
+
388
+ | Feature | localStorage | sessionStorage | Cookies |
389
+ |---------|--------------|----------------|---------|
390
+ | **Persistence** | Until explicitly cleared | Until tab/window closes | Until expiry (configurable) |
391
+ | **Capacity** | ~10MB | ~10MB | ~4KB per cookie |
392
+ | **Scope** | All tabs/windows | Single tab/window | All tabs/windows |
393
+ | **Server Access** | No | No | Yes (sent with requests) |
394
+ | **Best For** | Long-term app state | Per-session state | Auth tokens, small settings |
395
+ | **Security** | Client-side only | Client-side only | HttpOnly, Secure, SameSite options |
396
+
397
+ **When to use:**
398
+ - **localStorage**: User preferences, app settings, cached data
399
+ - **sessionStorage**: Multi-step forms, temporary UI state, wizard flows
400
+ - **cookies**: Authentication tokens, session IDs, small persistent preferences
401
+
270
402
  ## TypeScript Support
271
403
 
272
404
  The library is fully typed with TypeScript generics:
@@ -330,6 +462,37 @@ user.set({ id: 1, name: 'Alice' }); // ✓ OK
330
462
  const formDraft = sessionStorageSignal('form', 'draft');
331
463
  ```
332
464
 
465
+ 6. **Use cookies for security-sensitive small data** - Auth tokens with proper options
466
+ ```typescript
467
+ const authToken = cookieStorageSignal<string>('auth', 'token', {
468
+ secure: true, // HTTPS only
469
+ sameSite: 'strict', // CSRF protection
470
+ maxAge: 3600 // 1 hour expiry
471
+ });
472
+ ```
473
+
474
+ 7. **Mind the cookie size limit** - Keep cookie data under 4KB
475
+ ```typescript
476
+ // Good: Small auth token
477
+ cookieStorageSignal<string>('auth', 'token');
478
+
479
+ // Bad: Large data (use localStorage instead)
480
+ // cookieStorageSignal<LargeObject>('data', 'large');
481
+ ```
482
+
483
+ 8. **Override cookie options per signal** - Different cookies need different lifetimes
484
+ ```typescript
485
+ // Long-lived preference
486
+ const theme = cookieStorageSignal<string>('prefs', 'theme', {
487
+ maxAge: 31536000 // 1 year
488
+ });
489
+
490
+ // Short-lived session token
491
+ const token = cookieStorageSignal<string>('auth', 'token', {
492
+ maxAge: 3600 // 1 hour
493
+ });
494
+ ```
495
+
333
496
  ## License
334
497
 
335
498
  This library is part of the Telperion monorepo.