@djangocfg/api 2.1.599 → 2.1.601
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.
- package/README.md +2 -1
- package/dist/OAuthProvidersResponse-QZ566OYR.mjs +25 -0
- package/dist/OAuthProvidersResponse-QZ566OYR.mjs.map +1 -0
- package/dist/auth.cjs +526 -288
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +144 -31
- package/dist/auth.d.ts +144 -31
- package/dist/auth.mjs +409 -213
- package/dist/auth.mjs.map +1 -1
- package/dist/cfg_accounts_oauth_connections_response_200_AutoRef-N532BRPN.mjs +28 -0
- package/dist/cfg_accounts_oauth_connections_response_200_AutoRef-N532BRPN.mjs.map +1 -0
- package/dist/chunk-PCOSFQTH.mjs +10 -0
- package/dist/chunk-PCOSFQTH.mjs.map +1 -0
- package/dist/clients.cjs +34 -3
- package/dist/clients.cjs.map +1 -1
- package/dist/clients.d.cts +135 -14
- package/dist/clients.d.ts +135 -14
- package/dist/clients.mjs +34 -3
- package/dist/clients.mjs.map +1 -1
- package/dist/hooks.cjs +1 -0
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.mjs +1 -0
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.cjs +34 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +169 -17
- package/dist/index.d.ts +169 -17
- package/dist/index.mjs +34 -3
- package/dist/index.mjs.map +1 -1
- package/dist/storage.cjs +1 -0
- package/dist/storage.cjs.map +1 -1
- package/dist/storage.d.cts +1 -0
- package/dist/storage.d.ts +1 -0
- package/dist/storage.mjs +1 -0
- package/dist/storage.mjs.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/noStorageLiterals.test.ts +1 -1
- package/src/_api/generated/_cfg_accounts/hooks/index.ts +2 -0
- package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthGoogleAuthorizeCreate.ts +68 -0
- package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthGoogleCallbackCreate.ts +68 -0
- package/src/_api/generated/_cfg_accounts/openapi.json +263 -19
- package/src/_api/generated/_cfg_accounts/schemas/OAuthCallbackRequestRequest.ts +2 -2
- package/src/_api/generated/_cfg_accounts/schemas/OAuthError.ts +2 -1
- package/src/_api/generated/_cfg_accounts/schemas/OAuthErrorCodeEnum.ts +9 -0
- package/src/_api/generated/_cfg_accounts/schemas/OAuthProviderEnum.ts +1 -1
- package/src/_api/generated/_cfg_accounts/schemas/OAuthProviderInfo.ts +14 -0
- package/src/_api/generated/_cfg_accounts/schemas/OAuthProvidersResponse.ts +2 -1
- package/src/_api/generated/_cfg_accounts/schemas/index.ts +2 -0
- package/src/_api/generated/helpers/keys.ts +1 -0
- package/src/_api/generated/openapi.json +263 -19
- package/src/_api/generated/sdk.gen.ts +36 -4
- package/src/_api/generated/types.gen.ts +136 -11
- package/src/auth/__tests__/oauthErrors.test.ts +23 -0
- package/src/auth/__tests__/passwordLogin.test.tsx +1 -0
- package/src/auth/__tests__/useOAuthLogin.test.tsx +387 -0
- package/src/auth/hooks/index.ts +12 -1
- package/src/auth/hooks/useGithubAuth.ts +15 -225
- package/src/auth/hooks/useOAuthLogin.ts +237 -0
- package/src/auth/hooks/useOAuthProviders.ts +76 -0
- package/src/auth/utils/index.ts +8 -0
- package/src/auth/utils/oauthErrors.ts +45 -0
package/dist/storage.cjs
CHANGED
|
@@ -42,6 +42,7 @@ var CFG_KEYS = {
|
|
|
42
42
|
redirectUrlTs: k("cfg.auth.redirect_url_ts", "session", true),
|
|
43
43
|
oauthState: k("cfg.auth.oauth_state", "session", true),
|
|
44
44
|
oauthProvider: k("cfg.auth.oauth_provider", "session", true),
|
|
45
|
+
oauthProviders: k("cfg.auth.oauth_providers", "session", false),
|
|
45
46
|
profileCache: k("cfg.profile.cache", "local", true),
|
|
46
47
|
monitorSessionId: k("cfg.monitor.session_id", "local", false),
|
|
47
48
|
monitorSessionCookie: k("cfg.monitor.session_id", "cookie", false),
|
package/dist/storage.cjs.map
CHANGED
|
@@ -1 +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;AAAA,EACzC,SAAS,EAAE,qBAAqB,SAAS,KAAK;AAAA,EAC9C,aAAa,EAAE,yBAAyB,WAAW,IAAI;AAAA,EACvD,eAAe,EAAE,4BAA4B,WAAW,IAAI;AAAA,EAC5D,YA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AAC,KAAK,SAAU;AAC5B,kBAAU,KAAK,OAAO,KAAK,GAAG;AAAA,MAChC;AACA,iBAAW,UAAU,UAAU;AAC7B,YAAI,CAAC,OAAO,CAAC,OAAO,SAAU;AAC9B,mBAAW,QAAQ,SAAS,OAAO,OAAO,OAAO,MAAM,EAAG,WAAU,OAAO,OAAO,IAAI;AAAA,MACxF;AACA,UAAI,KAAK;AACP,mBAAW,SAAS,CAAC,SAAS,SAAS,GAAY;AACjD,qBAAW,QAAQ,SAAS,OAAO,MAAM,EAAG,WAAU,OAAO,IAAI;AAAA,QACnE;AACA,mBAAW,QAAQ,YAAY,EAAG,KAAI,KAAK,WAAW,MAAM,EAAG,WAAU,UAAU,IAAI;AAAA,MACzF;AAAA,IACF;AAAA,IACA,SAAS,KAAK,UAAU,QAAQ,SAAS;AACvC,kBAAY,GAAG;AACf,UAAI,CAAC,UAAU,EAAG,QAAO,MAAM;AAAA,MAAC;AAChC,YAAM,UAAU,wBAAC,UAAwB;AACvC,YAAI,MAAM,gBAAgB,cAAc,KAAK,EAAG;AAChD,YAAI,MAAM,QAAQ,QAAQ,MAAM,QAAQ,IAAK,UAAS,MAAM,QAAQ,OAAO,OAAO,MAAM,QAAQ;AAAA,MAClG,GAHgB;AAIhB,aAAO,iBAAiB,WAAW,OAAO;AAC1C,aAAO,MAAM,OAAO,oBAAoB,WAAW,OAAO;AAAA,IAC5D;AAAA,EACF;AACA,SAAO;AACT;AApLgB;AAuLT,IAAM,aAA6B,cAAc,OAAO;AAAA,EAC7D,MAAM;AAAA,EACN,UAAU;AACZ,CAAC;","names":[]}
|
|
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 oauthProviders: k('cfg.auth.oauth_providers', 'session', false),\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;AAAA,EACzC,SAAS,EAAE,qBAAqB,SAAS,KAAK;AAAA,EAC9C,aAAa,EAAE,yBAAyB,WAAW,IAAI;AAAA,EACvD,eAAe,EAAE,4BAA4B,WAAW,IAAI;AAAA,EAC5D,YAAY,EAAE,wBAAwB,WAAW,IAAI;AAAA,EACrD,eAAe,EAAE,2BAA2B,WAAW,IAAI;AAAA,EAC3D,gBAAgB,EAAE,4BAA4B,WAAW,KAAK;AAAA,EAC9D,cAAc,EAAE,qBAAqB,SAAS,IAAI;AAAA,EAClD,kBAAkB,EAAE,0BAA0B,SAAS,KAAK;AAAA,EAC5D,sBAAsB,EAAE,0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U,OAAO,OAAO,IAAI;AAAA,MACxF;AACA,UAAI,KAAK;AACP,mBAAW,SAAS,CAAC,SAAS,SAAS,GAAY;AACjD,qBAAW,QAAQ,SAAS,OAAO,MAAM,EAAG,WAAU,OAAO,IAAI;AAAA,QACnE;AACA,mBAAW,QAAQ,YAAY,EAAG,KAAI,KAAK,WAAW,MAAM,EAAG,WAAU,UAAU,IAAI;AAAA,MACzF;AAAA,IACF;AAAA,IACA,SAAS,KAAK,UAAU,QAAQ,SAAS;AACvC,kBAAY,GAAG;AACf,UAAI,CAAC,UAAU,EAAG,QAAO,MAAM;AAAA,MAAC;AAChC,YAAM,UAAU,wBAAC,UAAwB;AACvC,YAAI,MAAM,gBAAgB,cAAc,KAAK,EAAG;AAChD,YAAI,MAAM,QAAQ,QAAQ,MAAM,QAAQ,IAAK,UAAS,MAAM,QAAQ,OAAO,OAAO,MAAM,QAAQ;AAAA,MAClG,GAHgB;AAIhB,aAAO,iBAAiB,WAAW,OAAO;AAC1C,aAAO,MAAM,OAAO,oBAAoB,WAAW,OAAO;AAAA,IAC5D;AAAA,EACF;AACA,SAAO;AACT;AApLgB;AAuLT,IAAM,aAA6B,cAAc,OAAO;AAAA,EAC7D,MAAM;AAAA,EACN,UAAU;AACZ,CAAC;","names":[]}
|
package/dist/storage.d.cts
CHANGED
|
@@ -23,6 +23,7 @@ declare const CFG_KEYS: {
|
|
|
23
23
|
readonly redirectUrlTs: KeySpec;
|
|
24
24
|
readonly oauthState: KeySpec;
|
|
25
25
|
readonly oauthProvider: KeySpec;
|
|
26
|
+
readonly oauthProviders: KeySpec;
|
|
26
27
|
readonly profileCache: KeySpec;
|
|
27
28
|
readonly monitorSessionId: KeySpec;
|
|
28
29
|
readonly monitorSessionCookie: KeySpec;
|
package/dist/storage.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ declare const CFG_KEYS: {
|
|
|
23
23
|
readonly redirectUrlTs: KeySpec;
|
|
24
24
|
readonly oauthState: KeySpec;
|
|
25
25
|
readonly oauthProvider: KeySpec;
|
|
26
|
+
readonly oauthProviders: KeySpec;
|
|
26
27
|
readonly profileCache: KeySpec;
|
|
27
28
|
readonly monitorSessionId: KeySpec;
|
|
28
29
|
readonly monitorSessionCookie: KeySpec;
|
package/dist/storage.mjs
CHANGED
|
@@ -14,6 +14,7 @@ var CFG_KEYS = {
|
|
|
14
14
|
redirectUrlTs: k("cfg.auth.redirect_url_ts", "session", true),
|
|
15
15
|
oauthState: k("cfg.auth.oauth_state", "session", true),
|
|
16
16
|
oauthProvider: k("cfg.auth.oauth_provider", "session", true),
|
|
17
|
+
oauthProviders: k("cfg.auth.oauth_providers", "session", false),
|
|
17
18
|
profileCache: k("cfg.profile.cache", "local", true),
|
|
18
19
|
monitorSessionId: k("cfg.monitor.session_id", "local", false),
|
|
19
20
|
monitorSessionCookie: k("cfg.monitor.session_id", "cookie", false),
|
package/dist/storage.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/_api/generated/helpers/keys.ts"],"sourcesContent":["// 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":";;;;AA4BA,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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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 oauthProviders: k('cfg.auth.oauth_providers', 'session', false),\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":";;;;AA4BA,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;AAAA,EACzC,SAAS,EAAE,qBAAqB,SAAS,KAAK;AAAA,EAC9C,aAAa,EAAE,yBAAyB,WAAW,IAAI;AAAA,EACvD,eAAe,EAAE,4BAA4B,WAAW,IAAI;AAAA,EAC5D,YAAY,EAAE,wBAAwB,WAAW,IAAI;AAAA,EACrD,eAAe,EAAE,2BAA2B,WAAW,IAAI;AAAA,EAC3D,gBAAgB,EAAE,4BAA4B,WAAW,KAAK;AAAA,EAC9D,cAAc,EAAE,qBAAqB,SAAS,IAAI;AAAA,EAClD,kBAAkB,EAAE,0BAA0B,SAAS,KAAK;AAAA,EAC5D,sBAAsB,EAAE,0BAA0B,UAAU,KAAK;AAAA,EACjE,cAAc,EAAE,qBAAqB,SAAS,KAAK;AAAA,EACnD,SAAS,EAAE,iBAAiB,WAAW,KAAK;AAAA,EAC5C,gBAAgB,EAAE,wBAAwB,WAAW,KAAK;AAAA,EAC1D,SAAS,EAAE,gBAAgB,SAAS,KAAK;AAAA,EACzC,oBAAoB,EAAE,4BAA4B,SAAS,KAAK;AA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MACzF;AAAA,IACF;AAAA,IACA,SAAS,KAAK,UAAU,QAAQ,SAAS;AACvC,kBAAY,GAAG;AACf,UAAI,CAAC,UAAU,EAAG,QAAO,MAAM;AAAA,MAAC;AAChC,YAAM,UAAU,wBAAC,UAAwB;AACvC,YAAI,MAAM,gBAAgB,cAAc,KAAK,EAAG;AAChD,YAAI,MAAM,QAAQ,QAAQ,MAAM,QAAQ,IAAK,UAAS,MAAM,QAAQ,OAAO,OAAO,MAAM,QAAQ;AAAA,MAClG,GAHgB;AAIhB,aAAO,iBAAiB,WAAW,OAAO;AAC1C,aAAO,MAAM,OAAO,oBAAoB,WAAW,OAAO;AAAA,IAC5D;AAAA,EACF;AACA,SAAO;AACT;AApLgB;AAuLT,IAAM,aAA6B,cAAc,OAAO;AAAA,EAC7D,MAAM;AAAA,EACN,UAAU;AACZ,CAAC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/api",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.601",
|
|
4
4
|
"description": "Auto-generated TypeScript API client with React hooks, SWR integration, and Zod validation for Django REST Framework backends",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"django",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"zod": "^4.3.6"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
94
|
+
"@djangocfg/typescript-config": "^2.1.601",
|
|
95
95
|
"@testing-library/react": "^16.3.2",
|
|
96
96
|
"@types/node": "^25.9.5",
|
|
97
97
|
"@types/react": "19.2.15",
|
|
@@ -5,7 +5,7 @@ import { describe, expect, it } from 'vitest';
|
|
|
5
5
|
// Storage keys are defined once, in the registry. A literal anywhere else is a bug.
|
|
6
6
|
const FORBIDDEN = [
|
|
7
7
|
'user_profile_cache', 'auth_email', 'auth_redirect_url', 'fm_session_id', 'oauth_state',
|
|
8
|
-
'oauth_provider', 'cfg.access_token', 'cfg.refresh_token', 'cfg.api_key',
|
|
8
|
+
'oauth_provider', 'oauth_providers', 'cfg.access_token', 'cfg.refresh_token', 'cfg.api_key',
|
|
9
9
|
];
|
|
10
10
|
|
|
11
11
|
function walk(dir: string, out: string[] = []): string[] {
|
|
@@ -9,6 +9,8 @@ export { useCfgAccountsOauthConnectionsList } from "./useCfgAccountsOauthConnect
|
|
|
9
9
|
export { useCfgAccountsOauthDisconnectCreate } from "./useCfgAccountsOauthDisconnectCreate";
|
|
10
10
|
export { useCfgAccountsOauthGithubAuthorizeCreate } from "./useCfgAccountsOauthGithubAuthorizeCreate";
|
|
11
11
|
export { useCfgAccountsOauthGithubCallbackCreate } from "./useCfgAccountsOauthGithubCallbackCreate";
|
|
12
|
+
export { useCfgAccountsOauthGoogleAuthorizeCreate } from "./useCfgAccountsOauthGoogleAuthorizeCreate";
|
|
13
|
+
export { useCfgAccountsOauthGoogleCallbackCreate } from "./useCfgAccountsOauthGoogleCallbackCreate";
|
|
12
14
|
export { useCfgAccountsOauthProvidersRetrieve } from "./useCfgAccountsOauthProvidersRetrieve";
|
|
13
15
|
export { useCfgAccountsOtpConsentPolicyRetrieve } from "./useCfgAccountsOtpConsentPolicyRetrieve";
|
|
14
16
|
export { useCfgAccountsOtpRequestCreate } from "./useCfgAccountsOtpRequestCreate";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// AUTO-GENERATED by openapi_processor / ts.hooks
|
|
4
|
+
// Start Google OAuth
|
|
5
|
+
// DO NOT EDIT — re-run `make gen`.
|
|
6
|
+
|
|
7
|
+
import useSWRMutation from "swr/mutation";
|
|
8
|
+
import type { SWRMutationConfiguration } from "swr/mutation";
|
|
9
|
+
import { CfgAccountsOauth } from "../../sdk.gen";
|
|
10
|
+
import type { CfgAccountsOauthGoogleAuthorizeCreateData, CfgAccountsOauthGoogleAuthorizeCreateResponses } from "../../types.gen";
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
type Args = Omit<CfgAccountsOauthGoogleAuthorizeCreateData, "url">;
|
|
14
|
+
type Result = CfgAccountsOauthGoogleAuthorizeCreateResponses[keyof CfgAccountsOauthGoogleAuthorizeCreateResponses];
|
|
15
|
+
|
|
16
|
+
export function useCfgAccountsOauthGoogleAuthorizeCreate(
|
|
17
|
+
config?: SWRMutationConfiguration<Result, Error, readonly ["cfg_accounts_oauth_google_authorize_create"], Args>,
|
|
18
|
+
) {
|
|
19
|
+
return useSWRMutation<Result, Error, readonly ["cfg_accounts_oauth_google_authorize_create"], Args>(
|
|
20
|
+
["cfg_accounts_oauth_google_authorize_create"] as const,
|
|
21
|
+
async (_key, { arg }: { arg: Args }) => {
|
|
22
|
+
const res = await CfgAccountsOauth.cfgAccountsOauthGoogleAuthorizeCreate({ ...arg, throwOnError: true } as never);
|
|
23
|
+
const data = res.data as Result;
|
|
24
|
+
void import("../schemas/OAuthAuthorizeResponse")
|
|
25
|
+
.then(({ OAuthAuthorizeResponseSchema }) => {
|
|
26
|
+
const parsed = OAuthAuthorizeResponseSchema.safeParse(data);
|
|
27
|
+
if (parsed.success) return;
|
|
28
|
+
// Log first so the failure is always visible, even if the
|
|
29
|
+
// event handler swallows it.
|
|
30
|
+
console.warn(
|
|
31
|
+
"[zod] response did not match schema",
|
|
32
|
+
{
|
|
33
|
+
operation: "cfg_accounts_oauth_google_authorize_create",
|
|
34
|
+
method: "POST",
|
|
35
|
+
path: "/cfg/accounts/oauth/google/authorize/",
|
|
36
|
+
issues: parsed.error.issues,
|
|
37
|
+
data,
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
if (typeof window !== "undefined") {
|
|
41
|
+
try {
|
|
42
|
+
window.dispatchEvent(
|
|
43
|
+
new CustomEvent("zod-validation-error", {
|
|
44
|
+
detail: {
|
|
45
|
+
operation: "cfg_accounts_oauth_google_authorize_create",
|
|
46
|
+
method: "POST",
|
|
47
|
+
path: "/cfg/accounts/oauth/google/authorize/",
|
|
48
|
+
issues: parsed.error.issues,
|
|
49
|
+
data,
|
|
50
|
+
timestamp: new Date(),
|
|
51
|
+
},
|
|
52
|
+
bubbles: true,
|
|
53
|
+
cancelable: false,
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
} catch {
|
|
57
|
+
// Event dispatch is best-effort.
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
.catch(() => {
|
|
62
|
+
// A schema chunk that fails to load is not the caller's problem.
|
|
63
|
+
});
|
|
64
|
+
return data;
|
|
65
|
+
},
|
|
66
|
+
config,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// AUTO-GENERATED by openapi_processor / ts.hooks
|
|
4
|
+
// Complete Google OAuth
|
|
5
|
+
// DO NOT EDIT — re-run `make gen`.
|
|
6
|
+
|
|
7
|
+
import useSWRMutation from "swr/mutation";
|
|
8
|
+
import type { SWRMutationConfiguration } from "swr/mutation";
|
|
9
|
+
import { CfgAccountsOauth } from "../../sdk.gen";
|
|
10
|
+
import type { CfgAccountsOauthGoogleCallbackCreateData, CfgAccountsOauthGoogleCallbackCreateResponses } from "../../types.gen";
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
type Args = Omit<CfgAccountsOauthGoogleCallbackCreateData, "url">;
|
|
14
|
+
type Result = CfgAccountsOauthGoogleCallbackCreateResponses[keyof CfgAccountsOauthGoogleCallbackCreateResponses];
|
|
15
|
+
|
|
16
|
+
export function useCfgAccountsOauthGoogleCallbackCreate(
|
|
17
|
+
config?: SWRMutationConfiguration<Result, Error, readonly ["cfg_accounts_oauth_google_callback_create"], Args>,
|
|
18
|
+
) {
|
|
19
|
+
return useSWRMutation<Result, Error, readonly ["cfg_accounts_oauth_google_callback_create"], Args>(
|
|
20
|
+
["cfg_accounts_oauth_google_callback_create"] as const,
|
|
21
|
+
async (_key, { arg }: { arg: Args }) => {
|
|
22
|
+
const res = await CfgAccountsOauth.cfgAccountsOauthGoogleCallbackCreate({ ...arg, throwOnError: true } as never);
|
|
23
|
+
const data = res.data as Result;
|
|
24
|
+
void import("../schemas/OAuthTokenResponse")
|
|
25
|
+
.then(({ OAuthTokenResponseSchema }) => {
|
|
26
|
+
const parsed = OAuthTokenResponseSchema.safeParse(data);
|
|
27
|
+
if (parsed.success) return;
|
|
28
|
+
// Log first so the failure is always visible, even if the
|
|
29
|
+
// event handler swallows it.
|
|
30
|
+
console.warn(
|
|
31
|
+
"[zod] response did not match schema",
|
|
32
|
+
{
|
|
33
|
+
operation: "cfg_accounts_oauth_google_callback_create",
|
|
34
|
+
method: "POST",
|
|
35
|
+
path: "/cfg/accounts/oauth/google/callback/",
|
|
36
|
+
issues: parsed.error.issues,
|
|
37
|
+
data,
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
if (typeof window !== "undefined") {
|
|
41
|
+
try {
|
|
42
|
+
window.dispatchEvent(
|
|
43
|
+
new CustomEvent("zod-validation-error", {
|
|
44
|
+
detail: {
|
|
45
|
+
operation: "cfg_accounts_oauth_google_callback_create",
|
|
46
|
+
method: "POST",
|
|
47
|
+
path: "/cfg/accounts/oauth/google/callback/",
|
|
48
|
+
issues: parsed.error.issues,
|
|
49
|
+
data,
|
|
50
|
+
timestamp: new Date(),
|
|
51
|
+
},
|
|
52
|
+
bubbles: true,
|
|
53
|
+
cancelable: false,
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
} catch {
|
|
57
|
+
// Event dispatch is best-effort.
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
.catch(() => {
|
|
62
|
+
// A schema chunk that fails to load is not the caller's problem.
|
|
63
|
+
});
|
|
64
|
+
return data;
|
|
65
|
+
},
|
|
66
|
+
config,
|
|
67
|
+
);
|
|
68
|
+
}
|