@picked/client 0.0.38-next.1 → 0.0.38-next.3

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,29 +1,385 @@
1
1
  import { ExperienceInstance } from '../entities/experience-instance/experience-instance';
2
+ /**
3
+ * Defines the scope of storage items.
4
+ * - 'global': Storage is shared across all experiences
5
+ * - 'experience': Storage is scoped to a specific experience instance
6
+ */
2
7
  export type StorageScope = 'global' | 'experience';
8
+ /**
9
+ * Represents a storage item with methods to read, write, and subscribe to changes.
10
+ * Provides type-safe access to browser storage (localStorage or sessionStorage).
11
+ *
12
+ * @template T - The type of the stored value
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const key = createStorageKey('user-preferences')
17
+ * const item = sessionStore.get<UserPrefs>(key)
18
+ *
19
+ * // Check if value exists
20
+ * if (item.isSet()) {
21
+ * const prefs = item.json() // UserPrefs | null
22
+ * }
23
+ *
24
+ * // Set value with expiry
25
+ * item.set({ theme: 'dark' }, 3600000) // Expires in 1 hour
26
+ *
27
+ * // Subscribe to changes
28
+ * const unsubscribe = item.subscribe((updatedItem) => {
29
+ * console.log('Updated:', updatedItem.json())
30
+ * })
31
+ * ```
32
+ */
3
33
  export interface StorageItem<T = unknown> {
34
+ /**
35
+ * Checks if a value is stored for this item.
36
+ *
37
+ * @returns `true` if a value exists, `false` otherwise
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * if (item.isSet()) {
42
+ * console.log('Value exists')
43
+ * }
44
+ * ```
45
+ */
4
46
  isSet: () => boolean;
47
+ /**
48
+ * Gets the stored value as a string.
49
+ *
50
+ * @returns The stored string value, or `null` if not set
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const name = item.text() // "John" or null
55
+ * ```
56
+ */
5
57
  text: () => string | null;
58
+ /**
59
+ * Gets the stored value as a parsed JSON object.
60
+ *
61
+ * @returns The parsed value of type T, or `null` if not set
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const user = item.json<User>() // { name: "John", age: 30 } or null
66
+ * ```
67
+ */
6
68
  json: () => T | null;
69
+ /**
70
+ * Gets the stored value as a boolean.
71
+ *
72
+ * @returns `true` if value is "true", `false` if value is any other string, or `null` if not set
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * const isEnabled = item.boolean() // true, false, or null
77
+ * ```
78
+ */
7
79
  boolean: () => boolean | null;
8
- set: (value: T) => void;
80
+ /**
81
+ * Sets a value in storage with optional expiry time.
82
+ *
83
+ * @param value - The value to store (will be JSON stringified if not a string)
84
+ * @param expiresIn - Optional expiry time in milliseconds from now
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * // Set without expiry
89
+ * item.set({ theme: 'dark' })
90
+ *
91
+ * // Set with 1 hour expiry
92
+ * item.set({ theme: 'dark' }, 60 * 60 * 1000)
93
+ * ```
94
+ */
95
+ set: (value: T, expiresIn?: number) => void;
96
+ /**
97
+ * Removes the item from storage, including any expiry metadata.
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * item.remove()
102
+ * console.log(item.isSet()) // false
103
+ * ```
104
+ */
9
105
  remove: () => void;
106
+ /**
107
+ * Subscribes to storage changes for this item, both in the same tab and across browser tabs/windows.
108
+ * Callbacks are invoked immediately when changes occur via set() or remove() in the same tab,
109
+ * and also when changes are made in other tabs/windows.
110
+ *
111
+ * @param callback - Function called when the storage value changes, receives the updated StorageItem
112
+ * @returns Unsubscribe function to stop listening to changes
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * const unsubscribe = item.subscribe((updatedItem) => {
117
+ * console.log('Value changed:', updatedItem.json())
118
+ * })
119
+ *
120
+ * // Changes in same tab will trigger the callback
121
+ * item.set({ theme: 'dark' }) // callback fires immediately
122
+ *
123
+ * // Changes in other tabs also trigger the callback
124
+ * // (when another tab calls item.set())
125
+ *
126
+ * // Later, stop listening
127
+ * unsubscribe()
128
+ * ```
129
+ */
130
+ subscribe: (callback: (value: StorageItem<T>) => void) => () => void;
10
131
  }
132
+ /**
133
+ * Represents a storage key with encoded identifier and scope metadata.
134
+ */
11
135
  export interface StorageKey {
136
+ /**
137
+ * The encoded storage key string used in browser storage
138
+ */
12
139
  _: string;
140
+ /**
141
+ * The scope of the storage key ('global' or 'experience')
142
+ */
13
143
  scope: StorageScope;
14
144
  }
145
+ /**
146
+ * Creates a storage key with proper prefixing and encoding.
147
+ * Keys are prefixed with 'pckd' and optionally scoped to an experience instance.
148
+ *
149
+ * @param key - The raw key name (e.g., 'user-preferences')
150
+ * @param scope - The storage scope, defaults to 'global'
151
+ * @param experienceInstance - Required when scope is 'experience'
152
+ * @returns A StorageKey object with encoded identifier and scope
153
+ * @throws Error if scope is 'experience' but experienceInstance is not provided
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * // Global scope
158
+ * const globalKey = createStorageKey('theme')
159
+ * // Result: { _: 'pckd:encodedTheme', scope: 'global' }
160
+ *
161
+ * // Experience scope
162
+ * const expKey = createStorageKey('step', 'experience', experienceInstance)
163
+ * // Result: { _: 'pckd:exp123:encodedStep', scope: 'experience' }
164
+ * ```
165
+ */
15
166
  export declare function createStorageKey(key: string, scope?: StorageScope, experienceInstance?: ExperienceInstance): StorageKey;
167
+ /**
168
+ * Subscribes to storage changes for a specific key in both the same tab and across browser tabs/windows.
169
+ * Uses a local subscription registry for same-tab changes and the browser's storage event for cross-tab changes.
170
+ *
171
+ * @template T - The type of the stored value
172
+ * @param key - The storage key to watch
173
+ * @param storage - The storage type ('local' or 'session')
174
+ * @param get - Function to retrieve the current StorageItem
175
+ * @param callback - Function called when storage changes, receives updated StorageItem
176
+ * @returns Unsubscribe function to stop listening to changes
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * const key = createStorageKey('theme')
181
+ * const unsubscribe = subscribe(
182
+ * key,
183
+ * 'local',
184
+ * (k) => localStore.get(k),
185
+ * (item) => console.log('Theme changed:', item.json())
186
+ * )
187
+ *
188
+ * // Later, stop listening
189
+ * unsubscribe()
190
+ * ```
191
+ */
16
192
  export declare function subscribe<T = unknown>(key: StorageKey, storage: 'local' | 'session', get: (key: StorageKey) => StorageItem<T>, callback: (value: StorageItem<T>) => void): () => void;
193
+ /**
194
+ * Session storage wrapper with type-safe access and expiry support.
195
+ * Data persists only for the browser session and is cleared when the tab/window is closed.
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * // Create a key
200
+ * const key = createStorageKey('cart-items')
201
+ *
202
+ * // Get a storage item
203
+ * const cart = sessionStore.get<CartItem[]>(key)
204
+ *
205
+ * // Set value with 30-minute expiry
206
+ * sessionStore.set(key, [{ id: 1, name: 'Product' }], 30 * 60 * 1000)
207
+ *
208
+ * // Subscribe to changes
209
+ * const unsubscribe = sessionStore.subscribe(key, (item) => {
210
+ * console.log('Cart updated:', item.json())
211
+ * })
212
+ *
213
+ * // Remove value
214
+ * sessionStore.remove(key)
215
+ * ```
216
+ */
17
217
  export declare const sessionStore: {
218
+ /**
219
+ * Retrieves a storage item from sessionStorage.
220
+ *
221
+ * @template T - The type of the stored value
222
+ * @param key - The storage key
223
+ * @returns A StorageItem with methods to interact with the value
224
+ *
225
+ * @example
226
+ * ```typescript
227
+ * const key = createStorageKey('user')
228
+ * const item = sessionStore.get<User>(key)
229
+ * const user = item.json() // User | null
230
+ * ```
231
+ */
18
232
  get<T = unknown>(key: StorageKey): StorageItem<T>;
233
+ /**
234
+ * Sets a value in sessionStorage with optional expiry.
235
+ *
236
+ * @param key - The storage key
237
+ * @param value - The value to store
238
+ * @param expiresIn - Optional expiry time in milliseconds from now
239
+ *
240
+ * @example
241
+ * ```typescript
242
+ * const key = createStorageKey('theme')
243
+ * // Set without expiry
244
+ * sessionStore.set(key, 'dark')
245
+ * // Set with 1 hour expiry
246
+ * sessionStore.set(key, 'dark', 60 * 60 * 1000)
247
+ * ```
248
+ */
19
249
  set(key: StorageKey, value: unknown, expiresIn?: number): void;
250
+ /**
251
+ * Removes a value from sessionStorage, including expiry metadata.
252
+ *
253
+ * @param key - The storage key
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * const key = createStorageKey('temp-data')
258
+ * sessionStore.remove(key)
259
+ * ```
260
+ */
20
261
  remove(key: StorageKey): void;
262
+ /**
263
+ * Subscribes to storage changes for a key, both in the same tab and across browser tabs/windows.
264
+ * Callbacks are invoked when changes occur via sessionStore.set() or sessionStore.remove() in the same tab,
265
+ * and also when changes are made in other tabs/windows.
266
+ *
267
+ * @template T - The type of the stored value
268
+ * @param key - The storage key to watch
269
+ * @param callback - Function called when storage changes
270
+ * @returns Unsubscribe function to stop listening
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * const key = createStorageKey('notifications')
275
+ * const unsubscribe = sessionStore.subscribe<Notification[]>(key, (item) => {
276
+ * const notifications = item.json()
277
+ * console.log('Notifications updated:', notifications)
278
+ * })
279
+ *
280
+ * // Changes in same tab trigger callback
281
+ * sessionStore.set(key, [{ id: 1, message: 'New notification' }])
282
+ *
283
+ * // Later, stop listening
284
+ * unsubscribe()
285
+ * ```
286
+ */
21
287
  subscribe<T = unknown>(key: StorageKey, callback: (value: StorageItem<T>) => void): () => void;
22
288
  };
289
+ /**
290
+ * Local storage wrapper with type-safe access and expiry support.
291
+ * Data persists across browser sessions until explicitly removed or expired.
292
+ *
293
+ * @example
294
+ * ```typescript
295
+ * // Create a key
296
+ * const key = createStorageKey('user-preferences')
297
+ *
298
+ * // Get a storage item
299
+ * const prefs = localStore.get<UserPrefs>(key)
300
+ *
301
+ * // Set value with 7-day expiry
302
+ * localStore.set(key, { theme: 'dark' }, 7 * 24 * 60 * 60 * 1000)
303
+ *
304
+ * // Subscribe to changes
305
+ * const unsubscribe = localStore.subscribe(key, (item) => {
306
+ * console.log('Preferences updated:', item.json())
307
+ * })
308
+ *
309
+ * // Remove value
310
+ * localStore.remove(key)
311
+ * ```
312
+ */
23
313
  export declare const localStore: {
314
+ /**
315
+ * Retrieves a storage item from localStorage.
316
+ *
317
+ * @template T - The type of the stored value
318
+ * @param key - The storage key
319
+ * @returns A StorageItem with methods to interact with the value
320
+ *
321
+ * @example
322
+ * ```typescript
323
+ * const key = createStorageKey('settings')
324
+ * const item = localStore.get<Settings>(key)
325
+ * const settings = item.json() // Settings | null
326
+ * ```
327
+ */
24
328
  get<T = unknown>(key: StorageKey): StorageItem<T>;
329
+ /**
330
+ * Sets a value in localStorage with optional expiry.
331
+ *
332
+ * @param key - The storage key
333
+ * @param value - The value to store
334
+ * @param expiresIn - Optional expiry time in milliseconds from now
335
+ *
336
+ * @example
337
+ * ```typescript
338
+ * const key = createStorageKey('auth-token')
339
+ * // Set without expiry
340
+ * localStore.set(key, 'token123')
341
+ * // Set with 24 hour expiry
342
+ * localStore.set(key, 'token123', 24 * 60 * 60 * 1000)
343
+ * ```
344
+ */
25
345
  set(key: StorageKey, value: unknown, expiresIn?: number): void;
346
+ /**
347
+ * Removes a value from localStorage, including expiry metadata.
348
+ *
349
+ * @param key - The storage key
350
+ *
351
+ * @example
352
+ * ```typescript
353
+ * const key = createStorageKey('cached-data')
354
+ * localStore.remove(key)
355
+ * ```
356
+ */
26
357
  remove(key: StorageKey): void;
358
+ /**
359
+ * Subscribes to storage changes for a key, both in the same tab and across browser tabs/windows.
360
+ * Callbacks are invoked when changes occur via localStore.set() or localStore.remove() in the same tab,
361
+ * and also when changes are made in other tabs/windows.
362
+ *
363
+ * @template T - The type of the stored value
364
+ * @param key - The storage key to watch
365
+ * @param callback - Function called when storage changes
366
+ * @returns Unsubscribe function to stop listening
367
+ *
368
+ * @example
369
+ * ```typescript
370
+ * const key = createStorageKey('user-status')
371
+ * const unsubscribe = localStore.subscribe<UserStatus>(key, (item) => {
372
+ * const status = item.json()
373
+ * console.log('User status changed:', status)
374
+ * })
375
+ *
376
+ * // Changes in same tab trigger callback
377
+ * localStore.set(key, { online: true })
378
+ *
379
+ * // Later, stop listening
380
+ * unsubscribe()
381
+ * ```
382
+ */
27
383
  subscribe<T = unknown>(key: StorageKey, callback: (value: StorageItem<T>) => void): () => void;
28
384
  };
29
385
  //# sourceMappingURL=storage.d.ts.map
@@ -1 +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-next.3",
4
4
  "dependencies": {
5
5
  "@withease/factories": "^1.0.5"
6
6
  },
@@ -1,94 +0,0 @@
1
- const f = (e) => btoa([...e].map((t) => String.fromCharCode(t.charCodeAt(0) ^ 7)).join("")).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
2
- function m(e, t = "global", r) {
3
- let o = "pckd";
4
- if (t === "experience") {
5
- if (!r)
6
- throw new Error("Experience instance is required to scope storage to an experience");
7
- o = `${o}:${r.experienceId}`;
8
- }
9
- return { _: `${o}:${f(e)}`, scope: t };
10
- }
11
- function l(e, t, r, o) {
12
- const n = r === "local" ? localStorage : sessionStorage, s = typeof t != "string" ? JSON.stringify(t) : t;
13
- if (n.setItem(e._, s), typeof o == "number") {
14
- const a = new Date(Date.now() + o).toISOString();
15
- n.setItem(`${e._}:expires-at`, a);
16
- }
17
- }
18
- function c(e, t) {
19
- const r = t === "local" ? localStorage : sessionStorage;
20
- r.removeItem(e._), r.removeItem(`${e._}:expires-at`);
21
- }
22
- function u(e, t, r, o) {
23
- const n = t === "local" ? localStorage : sessionStorage;
24
- function s(i) {
25
- i.storageArea === n && i.key === e._ && o(r(e));
26
- }
27
- return window.addEventListener("storage", s), function() {
28
- window.removeEventListener("storage", s);
29
- };
30
- }
31
- function g(e, t) {
32
- const r = t === "local" ? localStorage : sessionStorage, o = r.getItem(e._), n = r.getItem(`${e._}:expires-at`), s = (a) => l(e, a, t), i = () => c(e, t);
33
- if (n) {
34
- const a = /* @__PURE__ */ new Date(), S = new Date(n);
35
- if (a > S)
36
- return c(e, t), {
37
- isSet: () => !1,
38
- text: () => null,
39
- json: () => null,
40
- boolean: () => null,
41
- set: s,
42
- remove: i
43
- };
44
- }
45
- return {
46
- isSet() {
47
- return o !== null;
48
- },
49
- text() {
50
- return o;
51
- },
52
- json() {
53
- return o ? JSON.parse(o) : null;
54
- },
55
- boolean() {
56
- return o ? o === "true" : null;
57
- },
58
- set: s,
59
- remove: i
60
- };
61
- }
62
- const p = {
63
- get(e) {
64
- return g(e, "session");
65
- },
66
- set(e, t, r) {
67
- l(e, t, "session", r);
68
- },
69
- remove(e) {
70
- c(e, "session");
71
- },
72
- subscribe(e, t) {
73
- return u(e, "session", this.get, t);
74
- }
75
- }, b = {
76
- get(e) {
77
- return g(e, "local");
78
- },
79
- set(e, t, r) {
80
- l(e, t, "local", r);
81
- },
82
- remove(e) {
83
- c(e, "local");
84
- },
85
- subscribe(e, t) {
86
- return u(e, "local", this.get, t);
87
- }
88
- };
89
- export {
90
- u as a,
91
- m as c,
92
- b as l,
93
- p as s
94
- };
@@ -1 +0,0 @@
1
- "use strict";const f=e=>btoa([...e].map(t=>String.fromCharCode(t.charCodeAt(0)^7)).join("")).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");function m(e,t="global",r){let o="pckd";if(t==="experience"){if(!r)throw new Error("Experience instance is required to scope storage to an experience");o=`${o}:${r.experienceId}`}return{_:`${o}:${f(e)}`,scope:t}}function l(e,t,r,o){const n=r==="local"?localStorage:sessionStorage,s=typeof t!="string"?JSON.stringify(t):t;if(n.setItem(e._,s),typeof o=="number"){const c=new Date(Date.now()+o).toISOString();n.setItem(`${e._}:expires-at`,c)}}function a(e,t){const r=t==="local"?localStorage:sessionStorage;r.removeItem(e._),r.removeItem(`${e._}:expires-at`)}function u(e,t,r,o){const n=t==="local"?localStorage:sessionStorage;function s(i){i.storageArea===n&&i.key===e._&&o(r(e))}return window.addEventListener("storage",s),function(){window.removeEventListener("storage",s)}}function g(e,t){const r=t==="local"?localStorage:sessionStorage,o=r.getItem(e._),n=r.getItem(`${e._}:expires-at`),s=c=>l(e,c,t),i=()=>a(e,t);if(n){const c=new Date,S=new Date(n);if(c>S)return a(e,t),{isSet:()=>!1,text:()=>null,json:()=>null,boolean:()=>null,set:s,remove:i}}return{isSet(){return o!==null},text(){return o},json(){return o?JSON.parse(o):null},boolean(){return o?o==="true":null},set:s,remove:i}}const b={get(e){return g(e,"session")},set(e,t,r){l(e,t,"session",r)},remove(e){a(e,"session")},subscribe(e,t){return u(e,"session",this.get,t)}},p={get(e){return g(e,"local")},set(e,t,r){l(e,t,"local",r)},remove(e){a(e,"local")},subscribe(e,t){return u(e,"local",this.get,t)}};exports.createStorageKey=m;exports.localStore=p;exports.sessionStore=b;exports.subscribe=u;