@djangocfg/api 2.1.582 → 2.1.584

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 (69) hide show
  1. package/README.md +18 -0
  2. package/dist/OAuthTokenResponse-WEDM6IP5.mjs +19 -0
  3. package/dist/OAuthTokenResponse-WEDM6IP5.mjs.map +1 -0
  4. package/dist/OTPVerifyResponse-P5LDNM7H.mjs +20 -0
  5. package/dist/OTPVerifyResponse-P5LDNM7H.mjs.map +1 -0
  6. package/dist/PasswordLoginResponse-33B576NG.mjs +20 -0
  7. package/dist/PasswordLoginResponse-33B576NG.mjs.map +1 -0
  8. package/dist/auth.cjs +279 -103
  9. package/dist/auth.cjs.map +1 -1
  10. package/dist/auth.d.cts +14 -41
  11. package/dist/auth.d.ts +14 -41
  12. package/dist/auth.mjs +279 -101
  13. package/dist/auth.mjs.map +1 -1
  14. package/dist/clients.cjs +242 -54
  15. package/dist/clients.cjs.map +1 -1
  16. package/dist/clients.d.cts +13 -41
  17. package/dist/clients.d.ts +13 -41
  18. package/dist/clients.mjs +242 -54
  19. package/dist/clients.mjs.map +1 -1
  20. package/dist/hooks.cjs +242 -54
  21. package/dist/hooks.cjs.map +1 -1
  22. package/dist/hooks.mjs +242 -54
  23. package/dist/hooks.mjs.map +1 -1
  24. package/dist/index.cjs +247 -54
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +90 -63
  27. package/dist/index.d.ts +90 -63
  28. package/dist/index.mjs +247 -54
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/storage.cjs +268 -0
  31. package/dist/storage.cjs.map +1 -0
  32. package/dist/storage.d.cts +84 -0
  33. package/dist/storage.d.ts +84 -0
  34. package/dist/storage.mjs +247 -0
  35. package/dist/storage.mjs.map +1 -0
  36. package/package.json +8 -2
  37. package/src/__tests__/noStorageLiterals.test.ts +27 -0
  38. package/src/__tests__/storage.test.ts +134 -0
  39. package/src/__tests__/storageSsr.test.ts +14 -0
  40. package/src/_api/generated/_cfg_accounts/openapi.json +1 -28
  41. package/src/_api/generated/_cfg_accounts/schemas/OAuthCallbackRequestRequest.ts +0 -1
  42. package/src/_api/generated/_cfg_accounts/schemas/OAuthTokenResponse.ts +0 -1
  43. package/src/_api/generated/_cfg_accounts/schemas/OTPVerifyRequest.ts +0 -1
  44. package/src/_api/generated/_cfg_accounts/schemas/OTPVerifyResponse.ts +0 -1
  45. package/src/_api/generated/_cfg_accounts/schemas/PasswordLoginRequest.ts +0 -1
  46. package/src/_api/generated/_cfg_accounts/schemas/PasswordLoginResponse.ts +0 -1
  47. package/src/_api/generated/_cfg_totp/openapi.json +0 -5
  48. package/src/_api/generated/_cfg_totp/schemas/VerifyResponse.ts +0 -1
  49. package/src/_api/generated/helpers/auth.ts +28 -65
  50. package/src/_api/generated/helpers/index.ts +12 -0
  51. package/src/_api/generated/helpers/keys.ts +327 -0
  52. package/src/_api/generated/openapi.json +1 -33
  53. package/src/_api/generated/types.gen.ts +4 -59
  54. package/src/auth/__tests__/authRedirect.test.ts +1 -1
  55. package/src/auth/__tests__/passwordLogin.test.tsx +1 -3
  56. package/src/auth/__tests__/profileCache.test.ts +1 -1
  57. package/src/auth/context/AccountsContext.tsx +6 -8
  58. package/src/auth/context/AuthContext.tsx +3 -5
  59. package/src/auth/context/types.ts +1 -1
  60. package/src/auth/hooks/useAuthForm.ts +3 -5
  61. package/src/auth/hooks/useAuthFormState.ts +0 -4
  62. package/src/auth/hooks/useAuthRedirect.ts +3 -2
  63. package/src/auth/hooks/useGithubAuth.ts +14 -16
  64. package/src/auth/hooks/useLocalStorage.ts +7 -7
  65. package/src/auth/hooks/useProfileCache.ts +2 -1
  66. package/src/auth/hooks/useSessionStorage.ts +7 -7
  67. package/src/auth/hooks/useTwoFactorVerify.ts +2 -2
  68. package/src/auth/types/form.ts +0 -5
  69. package/src/storage.ts +21 -0
@@ -0,0 +1,268 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/storage.ts
22
+ var storage_exports = {};
23
+ __export(storage_exports, {
24
+ CFG_FAMILIES: () => CFG_FAMILIES,
25
+ CFG_KEYS: () => CFG_KEYS,
26
+ cfgStorage: () => cfgStorage,
27
+ createStorage: () => createStorage,
28
+ normalizeSegment: () => normalizeSegment
29
+ });
30
+ module.exports = __toCommonJS(storage_exports);
31
+
32
+ // src/_api/generated/helpers/keys.ts
33
+ var k = /* @__PURE__ */ __name((key, store, personal) => ({ key, store, personal }), "k");
34
+ var f = /* @__PURE__ */ __name((prefix, store, personal) => ({ prefix, store, personal }), "f");
35
+ var CFG_KEYS = {
36
+ accessToken: k("cfg.auth.access_token", "local", true),
37
+ refreshToken: k("cfg.auth.refresh_token", "local", true),
38
+ apiKey: k("cfg.auth.api_key", "local", true),
39
+ email: k("cfg.auth.email", "local", false),
40
+ emailTs: k("cfg.auth.email_ts", "local", false),
41
+ redirectUrl: k("cfg.auth.redirect_url", "session", true),
42
+ redirectUrlTs: k("cfg.auth.redirect_url_ts", "session", true),
43
+ oauthState: k("cfg.auth.oauth_state", "session", true),
44
+ oauthProvider: k("cfg.auth.oauth_provider", "session", true),
45
+ profileCache: k("cfg.profile.cache", "local", true),
46
+ monitorSessionId: k("cfg.monitor.session_id", "local", false),
47
+ monitorSessionCookie: k("cfg.monitor.session_id", "cookie", false),
48
+ monitorDebug: k("cfg.monitor.debug", "local", false),
49
+ uiTabId: k("cfg.ui.tab_id", "session", false),
50
+ uiRouterSerial: k("cfg.ui.router_serial", "session", false),
51
+ uiState: k("cfg.ui.state", "local", false),
52
+ chatSpeechLanguage: k("cfg.chat.speech_language", "local", false),
53
+ chatRecentTools: k("cfg.chat.recent_tools", "local", false),
54
+ formsSpeechDebug: k("cfg.forms.speech_debug", "local", false),
55
+ formsSpeechPrefs: k("cfg.forms.speech_prefs", "local", false),
56
+ agentPlaygroundApiKeyId: k("cfg.agent.playground_api_key_id", "session", true),
57
+ agentPlaygroundBearer: k("cfg.agent.playground_bearer", "session", true),
58
+ agentEndpointDoc: k("cfg.agent.endpoint_doc", "session", false)
59
+ };
60
+ var CFG_FAMILIES = {
61
+ chatDraft: f("cfg.chat.draft.", "session", true),
62
+ dataTree: f("cfg.data.tree.", "local", false),
63
+ agentEndpointDraft: f("cfg.agent.endpoint_draft.", "local", false)
64
+ };
65
+ var OWNER_RE = /^[a-z][a-z0-9_]*$/;
66
+ function normalizeSegment(raw) {
67
+ return raw.trim().toLowerCase().replace(/[^a-z0-9_]+/g, "_").replace(/^_+|_+$/g, "");
68
+ }
69
+ __name(normalizeSegment, "normalizeSegment");
70
+ var hasWindow = /* @__PURE__ */ __name(() => typeof window !== "undefined", "hasWindow");
71
+ function nativeStorage(store) {
72
+ if (!hasWindow()) return null;
73
+ try {
74
+ return store === "session" ? window.sessionStorage : window.localStorage;
75
+ } catch {
76
+ return null;
77
+ }
78
+ }
79
+ __name(nativeStorage, "nativeStorage");
80
+ function cookieNames() {
81
+ if (!hasWindow()) return [];
82
+ try {
83
+ return document.cookie.split("; ").map((part) => decodeURIComponent(part.split("=")[0] ?? "")).filter(Boolean);
84
+ } catch {
85
+ return [];
86
+ }
87
+ }
88
+ __name(cookieNames, "cookieNames");
89
+ function createStorage(owner, options = {}) {
90
+ if (!OWNER_RE.test(owner)) {
91
+ throw new TypeError(`createStorage: owner "${owner}" must match ${OWNER_RE}`);
92
+ }
93
+ const prefix = `${owner}.`;
94
+ const pattern = owner === "cfg" ? /^cfg(\.[a-z0-9_]+)+$/ : new RegExp(`^(cfg|${owner})(\\.[a-z0-9_]+)+$`);
95
+ const cookieMaxAge = options.cookieMaxAgeSeconds ?? 60 * 60 * 24 * 30;
96
+ const specs = Object.values(options.keys ?? {});
97
+ const families = Object.values(options.families ?? {});
98
+ const specByKey = /* @__PURE__ */ new Map();
99
+ for (const spec of specs) specByKey.set(spec.key, [...specByKey.get(spec.key) ?? [], spec]);
100
+ const memory = {
101
+ local: /* @__PURE__ */ new Map(),
102
+ session: /* @__PURE__ */ new Map(),
103
+ cookie: /* @__PURE__ */ new Map()
104
+ };
105
+ const isValid = /* @__PURE__ */ __name((key) => pattern.test(key), "isValid");
106
+ const assertValid = /* @__PURE__ */ __name((key) => {
107
+ if (!isValid(key)) throw new TypeError(`storage key "${key}" must match ${pattern}`);
108
+ }, "assertValid");
109
+ const assertOwned = /* @__PURE__ */ __name((key) => {
110
+ assertValid(key);
111
+ if (!key.startsWith(prefix)) throw new TypeError(`storage key "${key}" is not owned by "${owner}"`);
112
+ }, "assertOwned");
113
+ function rawGet(store, key) {
114
+ if (!hasWindow()) return null;
115
+ if (store === "cookie") {
116
+ try {
117
+ const escaped = encodeURIComponent(key).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
118
+ const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${escaped}=([^;]*)`));
119
+ if (match?.[1] !== void 0) return decodeURIComponent(match[1]);
120
+ } catch {
121
+ }
122
+ return memory.cookie.get(key) ?? null;
123
+ }
124
+ try {
125
+ const value = nativeStorage(store)?.getItem(key) ?? null;
126
+ if (value !== null) return value;
127
+ } catch {
128
+ }
129
+ return memory[store].get(key) ?? null;
130
+ }
131
+ __name(rawGet, "rawGet");
132
+ function rawSet(store, key, value) {
133
+ if (!hasWindow()) return false;
134
+ try {
135
+ if (store === "cookie") {
136
+ const secure = window.location.protocol === "https:" ? "; Secure" : "";
137
+ document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)}; Path=/; Max-Age=${cookieMaxAge}; SameSite=Lax${secure}`;
138
+ if (rawGet("cookie", key) === value && !memory.cookie.has(key)) return true;
139
+ memory.cookie.set(key, value);
140
+ return false;
141
+ }
142
+ const native = nativeStorage(store);
143
+ if (!native) throw new Error("storage unavailable");
144
+ native.setItem(key, value);
145
+ memory[store].delete(key);
146
+ return true;
147
+ } catch {
148
+ memory[store].set(key, value);
149
+ return false;
150
+ }
151
+ }
152
+ __name(rawSet, "rawSet");
153
+ function rawRemove(store, key) {
154
+ memory[store].delete(key);
155
+ if (!hasWindow()) return;
156
+ try {
157
+ if (store === "cookie") {
158
+ const secure = window.location.protocol === "https:" ? "; Secure" : "";
159
+ document.cookie = `${encodeURIComponent(key)}=; Path=/; Max-Age=0; SameSite=Lax${secure}`;
160
+ } else {
161
+ nativeStorage(store)?.removeItem(key);
162
+ }
163
+ } catch {
164
+ }
165
+ }
166
+ __name(rawRemove, "rawRemove");
167
+ function resolveStore(key, store) {
168
+ return store ?? specByKey.get(key)?.[0]?.store ?? "local";
169
+ }
170
+ __name(resolveStore, "resolveStore");
171
+ function listKeys(store, startsWith) {
172
+ const out = [];
173
+ try {
174
+ const native = nativeStorage(store);
175
+ if (native) {
176
+ for (let i = 0; i < native.length; i += 1) {
177
+ const name = native.key(i);
178
+ if (name?.startsWith(startsWith)) out.push(name);
179
+ }
180
+ }
181
+ } catch {
182
+ }
183
+ for (const name of memory[store].keys()) if (name.startsWith(startsWith) && !out.includes(name)) out.push(name);
184
+ return out;
185
+ }
186
+ __name(listKeys, "listKeys");
187
+ const familyKey = /* @__PURE__ */ __name((family, id) => {
188
+ const part = normalizeSegment(id);
189
+ if (!part) throw new TypeError("storage family id is empty after normalisation");
190
+ return family.prefix + part;
191
+ }, "familyKey");
192
+ const api = {
193
+ owner,
194
+ key(...parts) {
195
+ const segments = parts.map(normalizeSegment);
196
+ if (segments.length === 0 || segments.some((segment) => !segment)) {
197
+ throw new TypeError(`storage key parts must be non-empty: ${JSON.stringify(parts)}`);
198
+ }
199
+ return `${prefix}${segments.join(".")}`;
200
+ },
201
+ familyKey,
202
+ isValid,
203
+ read(key, store) {
204
+ assertValid(key);
205
+ const target = resolveStore(key, store);
206
+ return rawGet(target, key);
207
+ },
208
+ write(key, value, store) {
209
+ assertOwned(key);
210
+ const target = resolveStore(key, store);
211
+ return rawSet(target, key, value);
212
+ },
213
+ remove(key, store) {
214
+ assertOwned(key);
215
+ const target = resolveStore(key, store);
216
+ rawRemove(target, key);
217
+ },
218
+ readJSON(key, store) {
219
+ const raw = api.read(key, store);
220
+ if (raw === null) return null;
221
+ try {
222
+ return JSON.parse(raw);
223
+ } catch {
224
+ return null;
225
+ }
226
+ },
227
+ writeJSON(key, value, store) {
228
+ return api.write(key, JSON.stringify(value), store);
229
+ },
230
+ keys(store = "local") {
231
+ return listKeys(store, prefix);
232
+ },
233
+ clearAll({ all = false } = {}) {
234
+ for (const spec of specs) {
235
+ if (!all && !spec.personal) continue;
236
+ rawRemove(spec.store, spec.key);
237
+ }
238
+ for (const family of families) {
239
+ if (!all && !family.personal) continue;
240
+ for (const name of listKeys(family.store, family.prefix)) rawRemove(family.store, name);
241
+ }
242
+ if (all) {
243
+ for (const store of ["local", "session"]) {
244
+ for (const name of listKeys(store, prefix)) rawRemove(store, name);
245
+ }
246
+ for (const name of cookieNames()) if (name.startsWith(prefix)) rawRemove("cookie", name);
247
+ }
248
+ },
249
+ onChange(key, listener, store = "local") {
250
+ assertValid(key);
251
+ if (!hasWindow()) return () => {
252
+ };
253
+ const handler = /* @__PURE__ */ __name((event) => {
254
+ if (event.storageArea !== nativeStorage(store)) return;
255
+ if (event.key === null || event.key === key) listener(event.key === null ? null : event.newValue);
256
+ }, "handler");
257
+ window.addEventListener("storage", handler);
258
+ return () => window.removeEventListener("storage", handler);
259
+ }
260
+ };
261
+ return api;
262
+ }
263
+ __name(createStorage, "createStorage");
264
+ var cfgStorage = createStorage("cfg", {
265
+ keys: CFG_KEYS,
266
+ families: CFG_FAMILIES
267
+ });
268
+ //# sourceMappingURL=storage.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/storage.ts","../src/_api/generated/helpers/keys.ts"],"sourcesContent":["/**\n * `@djangocfg/api/storage` — the browser-storage key registry on its own.\n *\n * Zero dependencies and no client: packages that only need a key, a guarded\n * read/write or `createStorage('<owner>')` import this, not the generated SDK.\n * The source is the generated `helpers/keys.ts`.\n */\nexport {\n CFG_FAMILIES,\n CFG_KEYS,\n cfgStorage,\n createStorage,\n normalizeSegment,\n} from './_api/generated/helpers/keys';\nexport type {\n FamilySpec,\n GuardedStorage,\n KeySpec,\n KeyStore,\n StorageOptions,\n} from './_api/generated/helpers/keys';\n","// AUTO-GENERATED by django_generator / ts_extras.wrapper\n// Browser-storage key registry: one scheme, guarded access.\n// DO NOT EDIT — re-run `make gen`.\n//\n// Rules for agents and apps: @docs/STORAGE_KEYS.md in @djangocfg/api.\n//\n// Scheme: `<owner>.<area>.<name>` — lower case, dots between levels,\n// `snake_case` inside a level. The framework's owner is `cfg`; an app picks its\n// own with `createStorage('<owner>')`. Third-party keys (a library's own\n// prefix, `NEXT_LOCALE`) are not ours to rename and stay as they are.\n\nexport type KeyStore = 'local' | 'session' | 'cookie';\n\nexport interface KeySpec {\n /** The canonical key. */\n readonly key: string;\n readonly store: KeyStore;\n /** Removed by `clearAll()` (sign-out). Preferences are kept. */\n readonly personal: boolean;\n}\n\nexport interface FamilySpec {\n /** Canonical prefix ending in a dot; the id is appended in normalised form. */\n readonly prefix: string;\n readonly store: 'local' | 'session';\n readonly personal: boolean;\n}\n\nconst k = (\n key: string,\n store: KeyStore,\n personal: boolean,\n): KeySpec => ({ key, store, personal });\n\nconst f = (\n prefix: string,\n store: 'local' | 'session',\n personal: boolean,\n): FamilySpec => ({ prefix, store, personal });\n\n/** Every key the framework writes. No legacy spellings are read: old keys are simply ignored. */\nexport const CFG_KEYS = {\n accessToken: k('cfg.auth.access_token', 'local', true),\n refreshToken: k('cfg.auth.refresh_token', 'local', true),\n apiKey: k('cfg.auth.api_key', 'local', true),\n email: k('cfg.auth.email', 'local', false),\n emailTs: k('cfg.auth.email_ts', 'local', false),\n redirectUrl: k('cfg.auth.redirect_url', 'session', true),\n redirectUrlTs: k('cfg.auth.redirect_url_ts', 'session', true),\n oauthState: k('cfg.auth.oauth_state', 'session', true),\n oauthProvider: k('cfg.auth.oauth_provider', 'session', true),\n profileCache: k('cfg.profile.cache', 'local', true),\n monitorSessionId: k('cfg.monitor.session_id', 'local', false),\n monitorSessionCookie: k('cfg.monitor.session_id', 'cookie', false),\n monitorDebug: k('cfg.monitor.debug', 'local', false),\n uiTabId: k('cfg.ui.tab_id', 'session', false),\n uiRouterSerial: k('cfg.ui.router_serial', 'session', false),\n uiState: k('cfg.ui.state', 'local', false),\n chatSpeechLanguage: k('cfg.chat.speech_language', 'local', false),\n chatRecentTools: k('cfg.chat.recent_tools', 'local', false),\n formsSpeechDebug: k('cfg.forms.speech_debug', 'local', false),\n formsSpeechPrefs: k('cfg.forms.speech_prefs', 'local', false),\n agentPlaygroundApiKeyId: k('cfg.agent.playground_api_key_id', 'session', true),\n agentPlaygroundBearer: k('cfg.agent.playground_bearer', 'session', true),\n agentEndpointDoc: k('cfg.agent.endpoint_doc', 'session', false),\n} as const satisfies Record<string, KeySpec>;\n\n/** Keys with a caller-supplied id part: one per room, tree, endpoint. */\nexport const CFG_FAMILIES = {\n chatDraft: f('cfg.chat.draft.', 'session', true),\n dataTree: f('cfg.data.tree.', 'local', false),\n agentEndpointDraft: f('cfg.agent.endpoint_draft.', 'local', false),\n} as const satisfies Record<string, FamilySpec>;\n\nconst OWNER_RE = /^[a-z][a-z0-9_]*$/;\n\n/** One segment of a key: lower case, `[a-z0-9_]`, anything else folded to `_`. */\nexport function normalizeSegment(raw: string): string {\n return raw\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9_]+/g, '_')\n .replace(/^_+|_+$/g, '');\n}\n\nexport interface StorageOptions {\n /** Named keys of this owner. */\n readonly keys?: Readonly<Record<string, KeySpec>>;\n readonly families?: Readonly<Record<string, FamilySpec>>;\n /** Cookie lifetime for the `cookie` store. Default 30 days. */\n readonly cookieMaxAgeSeconds?: number;\n}\n\nexport interface GuardedStorage {\n readonly owner: string;\n /** Builds `<owner>.<part>.<part>` from free-form parts; throws if a part is empty. */\n key(...parts: string[]): string;\n /** Builds a family member key: the prefix plus the normalised id. */\n familyKey(family: FamilySpec, id: string): string;\n /** `^(cfg|<owner>)(\\.[a-z0-9_]+)+$`. */\n isValid(key: string): boolean;\n read(key: string, store?: KeyStore): string | null;\n /** True when the value reached the browser's storage; false means it is held in memory for this page only. */\n write(key: string, value: string, store?: KeyStore): boolean;\n /** Removes the key. */\n remove(key: string, store?: KeyStore): void;\n readJSON<T>(key: string, store?: KeyStore): T | null;\n writeJSON(key: string, value: unknown, store?: KeyStore): boolean;\n /** Keys this owner holds in `store`. */\n keys(store?: Exclude<KeyStore, 'cookie'>): string[];\n /** Sign-out: removes the `personal` keys. `{ all: true }` removes everything under this owner. */\n clearAll(options?: { all?: boolean }): void;\n /** Cross-tab: calls `listener` with the new value when ANOTHER tab changes `key`. Cookies fire no events. */\n onChange(key: string, listener: (value: string | null) => void, store?: Exclude<KeyStore, 'cookie'>): () => void;\n}\n\nconst hasWindow = () => typeof window !== 'undefined';\n\nfunction nativeStorage(store: 'local' | 'session'): Storage | null {\n if (!hasWindow()) return null;\n try {\n return store === 'session' ? window.sessionStorage : window.localStorage;\n } catch {\n return null;\n }\n}\n\nfunction cookieNames(): string[] {\n if (!hasWindow()) return [];\n try {\n return document.cookie\n .split('; ')\n .map((part) => decodeURIComponent(part.split('=')[0] ?? ''))\n .filter(Boolean);\n } catch {\n return [];\n }\n}\n\nexport function createStorage(owner: string, options: StorageOptions = {}): GuardedStorage {\n if (!OWNER_RE.test(owner)) {\n throw new TypeError(`createStorage: owner \"${owner}\" must match ${OWNER_RE}`);\n }\n const prefix = `${owner}.`;\n const pattern = owner === 'cfg' ? /^cfg(\\.[a-z0-9_]+)+$/ : new RegExp(`^(cfg|${owner})(\\\\.[a-z0-9_]+)+$`);\n const cookieMaxAge = options.cookieMaxAgeSeconds ?? 60 * 60 * 24 * 30;\n const specs = Object.values(options.keys ?? {});\n const families = Object.values(options.families ?? {});\n const specByKey = new Map<string, KeySpec[]>();\n for (const spec of specs) specByKey.set(spec.key, [...(specByKey.get(spec.key) ?? []), spec]);\n // Held in memory when the browser refuses a write (quota, private mode), so the page still works until reload.\n const memory: Record<KeyStore, Map<string, string>> = {\n local: new Map(),\n session: new Map(),\n cookie: new Map(),\n };\n\n const isValid = (key: string) => pattern.test(key);\n const assertValid = (key: string) => {\n if (!isValid(key)) throw new TypeError(`storage key \"${key}\" must match ${pattern}`);\n };\n const assertOwned = (key: string) => {\n assertValid(key);\n if (!key.startsWith(prefix)) throw new TypeError(`storage key \"${key}\" is not owned by \"${owner}\"`);\n };\n\n function rawGet(store: KeyStore, key: string): string | null {\n if (!hasWindow()) return null;\n if (store === 'cookie') {\n try {\n const escaped = encodeURIComponent(key).replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n const match = document.cookie.match(new RegExp(`(?:^|;\\\\s*)${escaped}=([^;]*)`));\n if (match?.[1] !== undefined) return decodeURIComponent(match[1]);\n } catch {\n /* fall through to memory */\n }\n return memory.cookie.get(key) ?? null;\n }\n try {\n const value = nativeStorage(store)?.getItem(key) ?? null;\n if (value !== null) return value;\n } catch {\n /* fall through to memory */\n }\n return memory[store].get(key) ?? null;\n }\n\n function rawSet(store: KeyStore, key: string, value: string): boolean {\n if (!hasWindow()) return false;\n try {\n if (store === 'cookie') {\n const secure = window.location.protocol === 'https:' ? '; Secure' : '';\n document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)}; Path=/; Max-Age=${cookieMaxAge}; SameSite=Lax${secure}`;\n if (rawGet('cookie', key) === value && !memory.cookie.has(key)) return true;\n memory.cookie.set(key, value);\n return false;\n }\n const native = nativeStorage(store);\n if (!native) throw new Error('storage unavailable');\n native.setItem(key, value);\n memory[store].delete(key);\n return true;\n } catch {\n memory[store].set(key, value);\n return false;\n }\n }\n\n function rawRemove(store: KeyStore, key: string): void {\n memory[store].delete(key);\n if (!hasWindow()) return;\n try {\n if (store === 'cookie') {\n const secure = window.location.protocol === 'https:' ? '; Secure' : '';\n document.cookie = `${encodeURIComponent(key)}=; Path=/; Max-Age=0; SameSite=Lax${secure}`;\n } else {\n nativeStorage(store)?.removeItem(key);\n }\n } catch {\n /* ignore */\n }\n }\n\n function resolveStore(key: string, store?: KeyStore): KeyStore {\n return store ?? specByKey.get(key)?.[0]?.store ?? 'local';\n }\n\n function listKeys(store: 'local' | 'session', startsWith: string): string[] {\n const out: string[] = [];\n try {\n const native = nativeStorage(store);\n if (native) {\n for (let i = 0; i < native.length; i += 1) {\n const name = native.key(i);\n if (name?.startsWith(startsWith)) out.push(name);\n }\n }\n } catch {\n /* ignore */\n }\n for (const name of memory[store].keys()) if (name.startsWith(startsWith) && !out.includes(name)) out.push(name);\n return out;\n }\n\n const familyKey = (family: FamilySpec, id: string) => {\n const part = normalizeSegment(id);\n if (!part) throw new TypeError('storage family id is empty after normalisation');\n return family.prefix + part;\n };\n\n const api: GuardedStorage = {\n owner,\n key(...parts) {\n const segments = parts.map(normalizeSegment);\n if (segments.length === 0 || segments.some((segment) => !segment)) {\n throw new TypeError(`storage key parts must be non-empty: ${JSON.stringify(parts)}`);\n }\n return `${prefix}${segments.join('.')}`;\n },\n familyKey,\n isValid,\n read(key, store) {\n assertValid(key);\n const target = resolveStore(key, store);\n return rawGet(target, key);\n },\n write(key, value, store) {\n assertOwned(key);\n const target = resolveStore(key, store);\n return rawSet(target, key, value);\n },\n remove(key, store) {\n assertOwned(key);\n const target = resolveStore(key, store);\n rawRemove(target, key);\n },\n readJSON<T>(key: string, store?: KeyStore): T | null {\n const raw = api.read(key, store);\n if (raw === null) return null;\n try {\n return JSON.parse(raw) as T;\n } catch {\n return null;\n }\n },\n writeJSON(key, value, store) {\n return api.write(key, JSON.stringify(value), store);\n },\n keys(store = 'local') {\n return listKeys(store, prefix);\n },\n clearAll({ all = false } = {}) {\n for (const spec of specs) {\n if (!all && !spec.personal) continue;\n rawRemove(spec.store, spec.key);\n }\n for (const family of families) {\n if (!all && !family.personal) continue;\n for (const name of listKeys(family.store, family.prefix)) rawRemove(family.store, name);\n }\n if (all) {\n for (const store of ['local', 'session'] as const) {\n for (const name of listKeys(store, prefix)) rawRemove(store, name);\n }\n for (const name of cookieNames()) if (name.startsWith(prefix)) rawRemove('cookie', name);\n }\n },\n onChange(key, listener, store = 'local') {\n assertValid(key);\n if (!hasWindow()) return () => {};\n const handler = (event: StorageEvent) => {\n if (event.storageArea !== nativeStorage(store)) return;\n if (event.key === null || event.key === key) listener(event.key === null ? null : event.newValue);\n };\n window.addEventListener('storage', handler);\n return () => window.removeEventListener('storage', handler);\n },\n };\n return api;\n}\n\n/** The framework's own storage: every `cfg.*` key. */\nexport const cfgStorage: GuardedStorage = createStorage('cfg', {\n keys: CFG_KEYS,\n families: CFG_FAMILIES,\n});\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4BA,IAAM,IAAI,wBACR,KACA,OACA,cACa,EAAE,KAAK,OAAO,SAAS,IAJ5B;AAMV,IAAM,IAAI,wBACR,QACA,OACA,cACgB,EAAE,QAAQ,OAAO,SAAS,IAJlC;AAOH,IAAM,WAAW;AAAA,EACtB,aAAa,EAAE,yBAAyB,SAAS,IAAI;AAAA,EACrD,cAAc,EAAE,0BAA0B,SAAS,IAAI;AAAA,EACvD,QAAQ,EAAE,oBAAoB,SAAS,IAAI;AAAA,EAC3C,OAAO,EAAE,kBAAkB,SAAS,KAAK;AA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;
5
+ readonly store: KeyStore;
6
+ /** Removed by `clearAll()` (sign-out). Preferences are kept. */
7
+ readonly personal: boolean;
8
+ }
9
+ interface FamilySpec {
10
+ /** Canonical prefix ending in a dot; the id is appended in normalised form. */
11
+ readonly prefix: string;
12
+ readonly store: 'local' | 'session';
13
+ readonly personal: boolean;
14
+ }
15
+ /** Every key the framework writes. No legacy spellings are read: old keys are simply ignored. */
16
+ declare const CFG_KEYS: {
17
+ readonly accessToken: KeySpec;
18
+ readonly refreshToken: KeySpec;
19
+ readonly apiKey: KeySpec;
20
+ readonly email: KeySpec;
21
+ readonly emailTs: KeySpec;
22
+ readonly redirectUrl: KeySpec;
23
+ readonly redirectUrlTs: KeySpec;
24
+ readonly oauthState: KeySpec;
25
+ readonly oauthProvider: KeySpec;
26
+ readonly profileCache: KeySpec;
27
+ readonly monitorSessionId: KeySpec;
28
+ readonly monitorSessionCookie: KeySpec;
29
+ readonly monitorDebug: KeySpec;
30
+ readonly uiTabId: KeySpec;
31
+ readonly uiRouterSerial: KeySpec;
32
+ readonly uiState: KeySpec;
33
+ readonly chatSpeechLanguage: KeySpec;
34
+ readonly chatRecentTools: KeySpec;
35
+ readonly formsSpeechDebug: KeySpec;
36
+ readonly formsSpeechPrefs: KeySpec;
37
+ readonly agentPlaygroundApiKeyId: KeySpec;
38
+ readonly agentPlaygroundBearer: KeySpec;
39
+ readonly agentEndpointDoc: KeySpec;
40
+ };
41
+ /** Keys with a caller-supplied id part: one per room, tree, endpoint. */
42
+ declare const CFG_FAMILIES: {
43
+ readonly chatDraft: FamilySpec;
44
+ readonly dataTree: FamilySpec;
45
+ readonly agentEndpointDraft: FamilySpec;
46
+ };
47
+ /** One segment of a key: lower case, `[a-z0-9_]`, anything else folded to `_`. */
48
+ declare function normalizeSegment(raw: string): string;
49
+ interface StorageOptions {
50
+ /** Named keys of this owner. */
51
+ readonly keys?: Readonly<Record<string, KeySpec>>;
52
+ readonly families?: Readonly<Record<string, FamilySpec>>;
53
+ /** Cookie lifetime for the `cookie` store. Default 30 days. */
54
+ readonly cookieMaxAgeSeconds?: number;
55
+ }
56
+ interface GuardedStorage {
57
+ readonly owner: string;
58
+ /** Builds `<owner>.<part>.<part>` from free-form parts; throws if a part is empty. */
59
+ key(...parts: string[]): string;
60
+ /** Builds a family member key: the prefix plus the normalised id. */
61
+ familyKey(family: FamilySpec, id: string): string;
62
+ /** `^(cfg|<owner>)(\.[a-z0-9_]+)+$`. */
63
+ isValid(key: string): boolean;
64
+ read(key: string, store?: KeyStore): string | null;
65
+ /** True when the value reached the browser's storage; false means it is held in memory for this page only. */
66
+ write(key: string, value: string, store?: KeyStore): boolean;
67
+ /** Removes the key. */
68
+ remove(key: string, store?: KeyStore): void;
69
+ readJSON<T>(key: string, store?: KeyStore): T | null;
70
+ writeJSON(key: string, value: unknown, store?: KeyStore): boolean;
71
+ /** Keys this owner holds in `store`. */
72
+ keys(store?: Exclude<KeyStore, 'cookie'>): string[];
73
+ /** Sign-out: removes the `personal` keys. `{ all: true }` removes everything under this owner. */
74
+ clearAll(options?: {
75
+ all?: boolean;
76
+ }): void;
77
+ /** Cross-tab: calls `listener` with the new value when ANOTHER tab changes `key`. Cookies fire no events. */
78
+ onChange(key: string, listener: (value: string | null) => void, store?: Exclude<KeyStore, 'cookie'>): () => void;
79
+ }
80
+ declare function createStorage(owner: string, options?: StorageOptions): GuardedStorage;
81
+ /** The framework's own storage: every `cfg.*` key. */
82
+ declare const cfgStorage: GuardedStorage;
83
+
84
+ export { CFG_FAMILIES, CFG_KEYS, type FamilySpec, type GuardedStorage, type KeySpec, type KeyStore, type StorageOptions, cfgStorage, createStorage, normalizeSegment };
@@ -0,0 +1,84 @@
1
+ type KeyStore = 'local' | 'session' | 'cookie';
2
+ interface KeySpec {
3
+ /** The canonical key. */
4
+ readonly key: string;
5
+ readonly store: KeyStore;
6
+ /** Removed by `clearAll()` (sign-out). Preferences are kept. */
7
+ readonly personal: boolean;
8
+ }
9
+ interface FamilySpec {
10
+ /** Canonical prefix ending in a dot; the id is appended in normalised form. */
11
+ readonly prefix: string;
12
+ readonly store: 'local' | 'session';
13
+ readonly personal: boolean;
14
+ }
15
+ /** Every key the framework writes. No legacy spellings are read: old keys are simply ignored. */
16
+ declare const CFG_KEYS: {
17
+ readonly accessToken: KeySpec;
18
+ readonly refreshToken: KeySpec;
19
+ readonly apiKey: KeySpec;
20
+ readonly email: KeySpec;
21
+ readonly emailTs: KeySpec;
22
+ readonly redirectUrl: KeySpec;
23
+ readonly redirectUrlTs: KeySpec;
24
+ readonly oauthState: KeySpec;
25
+ readonly oauthProvider: KeySpec;
26
+ readonly profileCache: KeySpec;
27
+ readonly monitorSessionId: KeySpec;
28
+ readonly monitorSessionCookie: KeySpec;
29
+ readonly monitorDebug: KeySpec;
30
+ readonly uiTabId: KeySpec;
31
+ readonly uiRouterSerial: KeySpec;
32
+ readonly uiState: KeySpec;
33
+ readonly chatSpeechLanguage: KeySpec;
34
+ readonly chatRecentTools: KeySpec;
35
+ readonly formsSpeechDebug: KeySpec;
36
+ readonly formsSpeechPrefs: KeySpec;
37
+ readonly agentPlaygroundApiKeyId: KeySpec;
38
+ readonly agentPlaygroundBearer: KeySpec;
39
+ readonly agentEndpointDoc: KeySpec;
40
+ };
41
+ /** Keys with a caller-supplied id part: one per room, tree, endpoint. */
42
+ declare const CFG_FAMILIES: {
43
+ readonly chatDraft: FamilySpec;
44
+ readonly dataTree: FamilySpec;
45
+ readonly agentEndpointDraft: FamilySpec;
46
+ };
47
+ /** One segment of a key: lower case, `[a-z0-9_]`, anything else folded to `_`. */
48
+ declare function normalizeSegment(raw: string): string;
49
+ interface StorageOptions {
50
+ /** Named keys of this owner. */
51
+ readonly keys?: Readonly<Record<string, KeySpec>>;
52
+ readonly families?: Readonly<Record<string, FamilySpec>>;
53
+ /** Cookie lifetime for the `cookie` store. Default 30 days. */
54
+ readonly cookieMaxAgeSeconds?: number;
55
+ }
56
+ interface GuardedStorage {
57
+ readonly owner: string;
58
+ /** Builds `<owner>.<part>.<part>` from free-form parts; throws if a part is empty. */
59
+ key(...parts: string[]): string;
60
+ /** Builds a family member key: the prefix plus the normalised id. */
61
+ familyKey(family: FamilySpec, id: string): string;
62
+ /** `^(cfg|<owner>)(\.[a-z0-9_]+)+$`. */
63
+ isValid(key: string): boolean;
64
+ read(key: string, store?: KeyStore): string | null;
65
+ /** True when the value reached the browser's storage; false means it is held in memory for this page only. */
66
+ write(key: string, value: string, store?: KeyStore): boolean;
67
+ /** Removes the key. */
68
+ remove(key: string, store?: KeyStore): void;
69
+ readJSON<T>(key: string, store?: KeyStore): T | null;
70
+ writeJSON(key: string, value: unknown, store?: KeyStore): boolean;
71
+ /** Keys this owner holds in `store`. */
72
+ keys(store?: Exclude<KeyStore, 'cookie'>): string[];
73
+ /** Sign-out: removes the `personal` keys. `{ all: true }` removes everything under this owner. */
74
+ clearAll(options?: {
75
+ all?: boolean;
76
+ }): void;
77
+ /** Cross-tab: calls `listener` with the new value when ANOTHER tab changes `key`. Cookies fire no events. */
78
+ onChange(key: string, listener: (value: string | null) => void, store?: Exclude<KeyStore, 'cookie'>): () => void;
79
+ }
80
+ declare function createStorage(owner: string, options?: StorageOptions): GuardedStorage;
81
+ /** The framework's own storage: every `cfg.*` key. */
82
+ declare const cfgStorage: GuardedStorage;
83
+
84
+ export { CFG_FAMILIES, CFG_KEYS, type FamilySpec, type GuardedStorage, type KeySpec, type KeyStore, type StorageOptions, cfgStorage, createStorage, normalizeSegment };