tempest-react-sdk 0.82.0 → 0.84.0
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 +7 -6
- package/bin/lib/openapi/generate.hostile.test.mjs +91 -0
- package/bin/lib/openapi/generate.mjs +42 -3
- package/dist/auth/create-tempest-auth.cjs +1 -1
- package/dist/auth/create-tempest-auth.cjs.map +1 -1
- package/dist/auth/create-tempest-auth.js +201 -153
- package/dist/auth/create-tempest-auth.js.map +1 -1
- package/dist/http/resumable-upload.cjs +1 -1
- package/dist/http/resumable-upload.cjs.map +1 -1
- package/dist/http/resumable-upload.js +124 -75
- package/dist/http/resumable-upload.js.map +1 -1
- package/dist/http/upload-with-progress.cjs +1 -1
- package/dist/http/upload-with-progress.cjs.map +1 -1
- package/dist/http/upload-with-progress.js +108 -44
- package/dist/http/upload-with-progress.js.map +1 -1
- package/dist/payments/PixCheckout.cjs +2 -0
- package/dist/payments/PixCheckout.cjs.map +1 -0
- package/dist/payments/PixCheckout.js +171 -0
- package/dist/payments/PixCheckout.js.map +1 -0
- package/dist/payments/PixCheckout.module.cjs +3 -0
- package/dist/payments/PixCheckout.module.cjs.map +1 -0
- package/dist/payments/PixCheckout.module.js +22 -0
- package/dist/payments/PixCheckout.module.js.map +1 -0
- package/dist/payments/format.cjs +2 -0
- package/dist/payments/format.cjs.map +1 -0
- package/dist/payments/format.js +9 -0
- package/dist/payments/format.js.map +1 -0
- package/dist/payments/mercado-pago.cjs +2 -0
- package/dist/payments/mercado-pago.cjs.map +1 -0
- package/dist/payments/mercado-pago.js +27 -0
- package/dist/payments/mercado-pago.js.map +1 -0
- package/dist/payments/outcome.cjs +2 -0
- package/dist/payments/outcome.cjs.map +1 -0
- package/dist/payments/outcome.js +108 -0
- package/dist/payments/outcome.js.map +1 -0
- package/dist/payments/types.cjs +2 -0
- package/dist/payments/types.cjs.map +1 -0
- package/dist/payments/types.js +16 -0
- package/dist/payments/types.js.map +1 -0
- package/dist/payments/use-mercado-pago-card.cjs +2 -0
- package/dist/payments/use-mercado-pago-card.cjs.map +1 -0
- package/dist/payments/use-mercado-pago-card.js +120 -0
- package/dist/payments/use-mercado-pago-card.js.map +1 -0
- package/dist/payments/use-pix-charge.cjs +2 -0
- package/dist/payments/use-pix-charge.cjs.map +1 -0
- package/dist/payments/use-pix-charge.js +63 -0
- package/dist/payments/use-pix-charge.js.map +1 -0
- package/dist/query/offline-persistence.cjs +1 -1
- package/dist/query/offline-persistence.cjs.map +1 -1
- package/dist/query/offline-persistence.js +57 -44
- package/dist/query/offline-persistence.js.map +1 -1
- package/dist/styles/PixCheckout.css +2 -0
- package/dist/styles/component/PixCheckout.css +18 -0
- package/dist/styles/manifest.json +6 -0
- package/dist/styles/payments.css +18 -0
- package/dist/styles.css +1 -1
- package/dist/sw/cache.cjs +1 -1
- package/dist/sw/cache.cjs.map +1 -1
- package/dist/sw/cache.js +82 -32
- package/dist/sw/cache.js.map +1 -1
- package/dist/sw.d.ts +21 -1
- package/dist/tempest-react-sdk.cjs +1 -1
- package/dist/tempest-react-sdk.d.ts +748 -10
- package/dist/tempest-react-sdk.js +104 -97
- package/dist/vite/base-url.cjs +1 -1
- package/dist/vite/base-url.cjs.map +1 -1
- package/dist/vite/base-url.js +5 -1
- package/dist/vite/base-url.js.map +1 -1
- package/dist/vite/tempest-pwa-dev-sw.cjs +1 -1
- package/dist/vite/tempest-pwa-dev-sw.cjs.map +1 -1
- package/dist/vite/tempest-pwa-dev-sw.js +96 -31
- package/dist/vite/tempest-pwa-dev-sw.js.map +1 -1
- package/dist/vite/tempest-pwa-manifest.cjs +2 -2
- package/dist/vite/tempest-pwa-manifest.cjs.map +1 -1
- package/dist/vite/tempest-pwa-manifest.js +32 -16
- package/dist/vite/tempest-pwa-manifest.js.map +1 -1
- package/dist/vite.cjs +1 -1
- package/dist/vite.d.ts +63 -12
- package/dist/vite.js +4 -4
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"offline-persistence.cjs","names":["ownerFingerprint","createOfflineStore","isDevBuild","dehydrate","require_dev_mode","require_owner_fingerprint","require_create_offline_store","_tanstack_react_query","pendingClears","currentOwner","getPrincipal","persistQueryClientOffline","options","key","databaseName","store","slot","ended","warnedEnded","timer","inFlight","afterPendingClear","pending","warnEnded","save","snapshot","queryClient","write","cancelTimer","schedule","throttleMs","onCacheEvent","event","unsubscribeCache","endSession","resetClient","previous","run","clearOptions","settled"],"sources":["../../src/query/offline-persistence.ts"],"sourcesContent":["import {\n dehydrate,\n hydrate,\n type QueryCacheNotifyEvent,\n type QueryClient,\n} from \"@tanstack/react-query\";\nimport { createOfflineStore } from \"../offline/create-offline-store\";\nimport { isDevBuild } from \"../utils/dev-mode\";\nimport { ownerFingerprint } from \"../utils/owner-fingerprint\";\n\n/**\n * Clears still running, per `databaseName` + `key` slot, across every handle.\n *\n * A handle's `clear()` deletes by key with no ordering against other handles,\n * so a new handle created on login while the previous one is still clearing\n * could `restore()` the previous user's snapshot before the delete lands, or\n * have its first write deleted by it. Every handle's `restore()` and writes\n * wait for the slot's pending clear first; the entry is dropped once settled.\n */\nconst pendingClears = new Map<string, Promise<unknown>>();\n\n/** Options for {@link persistQueryClientOffline}. */\nexport interface OfflineQueryPersistenceOptions {\n /** The `QueryClient` to snapshot and restore. */\n queryClient: QueryClient;\n /** IndexedDB database name for the snapshot. Default `\"TempestQueryCache\"`. */\n databaseName?: string;\n /** Row key under which the snapshot is stored. Default `\"tanstack-query\"`. */\n key?: string;\n /**\n * Minimum gap between snapshot writes, in ms — cache churn is coalesced into\n * one trailing write per window. Default `1000`.\n */\n throttleMs?: number;\n /**\n * Who is signed in right now — a stable, non-secret id such as the user id;\n * `null`/`undefined` when nobody is. Read on every write, which stamps the\n * snapshot with a one-way fingerprint of it (never the id itself), and on\n * `restore()`, which hydrates only a snapshot stamped with the same\n * fingerprint.\n *\n * `clear()` on logout already deletes the snapshot; this covers the session\n * that ends without it — a token that expired, a crash, a tab closed while\n * signed in. Without it, the next account to boot on the browser is shown\n * the previous account's cached responses (#531). A snapshot written before\n * this option was set carries no stamp and is not restored either; it is a\n * cache, so the cost is one cold start.\n *\n * A foreign snapshot is skipped, not deleted: a cookie app that only learns\n * the principal after a `/me` round trip would otherwise wipe its own cache\n * on every cold start. The next write replaces it.\n *\n * Read synchronously. A non-string, non-number value (the `Promise` of an\n * `async` getter) or a getter that throws reads as nobody. Omit it to restore\n * every snapshot, as before 0.82.0.\n */\n getPrincipal?: () => string | number | null | undefined;\n}\n\n/** Options for {@link OfflineQueryPersistence.clear}. */\nexport interface OfflineQueryClearOptions {\n /**\n * Also clear the in-memory `QueryClient` (`queryClient.clear()`) once\n * persistence has stopped and the snapshot is deleted — the one-call logout.\n * Default `false`: the client belongs to the app, which may want to keep\n * public queries (a catalog, feature flags) across sessions and drop only\n * the user-scoped keys with `removeQueries`.\n */\n resetClient?: boolean;\n}\n\n/** Handle returned by {@link persistQueryClientOffline}. */\nexport interface OfflineQueryPersistence {\n /**\n * Load the persisted snapshot into the `QueryClient`. Call once on boot,\n * before rendering queries, so cached data is available offline. A no-op\n * once {@link OfflineQueryPersistence.clear} has been called, and — with\n * `getPrincipal` — for a snapshot written under another principal.\n */\n restore: () => Promise<void>;\n /**\n * Write the current cache snapshot immediately (bypassing the throttle). A\n * no-op once {@link OfflineQueryPersistence.clear} has been called.\n */\n flush: () => Promise<void>;\n /** Stop persisting and drop the pending write. Idempotent. */\n unsubscribe: () => void;\n /**\n * End the persisted session (e.g. on logout) and delete the snapshot.\n *\n * Terminal for this handle: it cancels the pending throttled write, stops\n * persisting cache changes, waits for any write already in flight and only\n * then deletes the row — so neither a write pending in the last throttle\n * window nor cache activity after logout (the next user's first query) can\n * re-persist the previous user's responses. Afterwards `restore`/`flush`\n * are no-ops; to persist a new session, call\n * {@link persistQueryClientOffline} again after login. In a dev build\n * (`isDevBuild()`), the first `restore`, `flush` or added/updated query on\n * an ended handle logs one `console.warn` saying so, because a handle kept\n * at module scope would otherwise stop persisting in silence.\n *\n * Ordered against other handles on the same `databaseName` + `key`: until\n * this clear settles, a new handle's `restore()` and writes wait for it, so\n * a handle created on login without awaiting the logout neither hydrates\n * the previous snapshot nor has its first write deleted.\n *\n * If the delete rejects, `resetClient` still clears the client and the\n * rejection reaches the caller.\n *\n * The in-memory `QueryClient` is cleared only with `resetClient: true`, and\n * then only after persistence has stopped, so the reset itself cannot\n * trigger a write. It is opt-in because the app owns the client and the\n * shape of its logout: it may keep public queries and drop only the\n * user-scoped keys with `removeQueries`. Because persistence is already\n * off, that manual call can come before or after this one.\n *\n * Idempotent and safe to call concurrently; every call deletes the row\n * again.\n *\n * @param options - `resetClient` also clears the in-memory `QueryClient`.\n */\n clear: (options?: OfflineQueryClearOptions) => Promise<void>;\n}\n\ninterface Snapshot {\n id: string;\n state: ReturnType<typeof dehydrate>;\n /** Owner fingerprint when `getPrincipal` was set at write time; absent otherwise. */\n owner?: string | null;\n}\n\n/**\n * Fingerprint whoever `getPrincipal` says is signed in.\n *\n * @param getPrincipal - The app's principal getter.\n * @returns The fingerprint, or `null` for nobody, a non-identity value or a throw.\n */\nfunction currentOwner(getPrincipal: () => unknown): string | null {\n try {\n return ownerFingerprint(\"p\", getPrincipal());\n } catch {\n return null;\n }\n}\n\n/**\n * Persist a TanStack `QueryClient` cache to IndexedDB (via\n * {@link createOfflineStore}) and restore it on boot — so a reload or a cold\n * offline start shows the last-known data instead of empty screens.\n *\n * Self-contained: uses `dehydrate`/`hydrate` from `@tanstack/react-query`\n * directly, so no `@tanstack/react-query-persist-client` dependency is needed.\n * Writes are throttled and subscribe to the query cache; call `unsubscribe` on\n * teardown. Dexie is a peer dependency of the offline store — install it.\n *\n * @param options - The client plus storage/throttle configuration.\n * @returns A handle with `restore`, `flush`, `clear` and `unsubscribe`.\n *\n * `clear()` is terminal for the handle (see {@link OfflineQueryPersistence.clear}):\n * a logout that only deleted the row used to be undone by the pending write or\n * by the next cache event, restoring the previous user's data on the next boot\n * (#440).\n *\n * @example\n * const persistence = persistQueryClientOffline({ queryClient });\n * await persistence.restore();\n *\n * async function logout(): Promise<void> {\n * await persistence.clear({ resetClient: true });\n * }\n */\nexport function persistQueryClientOffline(\n options: OfflineQueryPersistenceOptions,\n): OfflineQueryPersistence {\n const { queryClient, throttleMs = 1000, getPrincipal } = options;\n const key = options.key ?? \"tanstack-query\";\n const databaseName = options.databaseName ?? \"TempestQueryCache\";\n const store = createOfflineStore<Snapshot, string>({\n databaseName,\n version: 1,\n tableName: \"cache\",\n indexes: \"&id\",\n keyPath: \"id\",\n });\n\n const slot = `${databaseName}\\u0000${key}`;\n let ended = false;\n let warnedEnded = false;\n let timer: ReturnType<typeof setTimeout> | null = null;\n const inFlight = new Set<Promise<unknown>>();\n\n async function afterPendingClear(): Promise<void> {\n const pending = pendingClears.get(slot);\n if (pending) await pending;\n }\n\n function warnEnded(): void {\n if (warnedEnded || !isDevBuild()) return;\n warnedEnded = true;\n console.warn(\n \"[tempest-react-sdk] persistQueryClientOffline: handle ended by clear(); \" +\n \"create a new one after login to keep persisting.\",\n );\n }\n\n async function save(): Promise<void> {\n if (ended) return;\n await afterPendingClear();\n if (ended) return;\n const snapshot: Snapshot = { id: key, state: dehydrate(queryClient) };\n if (getPrincipal) snapshot.owner = currentOwner(getPrincipal);\n const write = store.put(snapshot);\n inFlight.add(write);\n try {\n await write;\n } finally {\n inFlight.delete(write);\n }\n }\n\n function cancelTimer(): void {\n if (timer) {\n clearTimeout(timer);\n timer = null;\n }\n }\n\n function schedule(): void {\n if (timer || ended) return;\n timer = setTimeout(() => {\n timer = null;\n void save();\n }, throttleMs);\n }\n\n function onCacheEvent(event: QueryCacheNotifyEvent): void {\n if (!ended) {\n schedule();\n return;\n }\n if (event.type !== \"added\" && event.type !== \"updated\") return;\n unsubscribeCache();\n warnEnded();\n }\n\n const unsubscribeCache = queryClient.getQueryCache().subscribe(onCacheEvent);\n\n async function endSession(resetClient: boolean): Promise<void> {\n try {\n await Promise.allSettled([...inFlight]);\n await store.delete(key);\n } finally {\n if (resetClient) queryClient.clear();\n }\n }\n\n return {\n async restore() {\n if (ended) {\n warnEnded();\n return;\n }\n await afterPendingClear();\n if (ended) return;\n const snapshot = await store.get(key);\n if (!snapshot || ended) return;\n if (getPrincipal && snapshot.owner !== currentOwner(getPrincipal)) return;\n hydrate(queryClient, snapshot.state);\n },\n async flush() {\n if (ended) {\n warnEnded();\n return;\n }\n cancelTimer();\n await save();\n },\n unsubscribe() {\n cancelTimer();\n unsubscribeCache();\n },\n async clear(clearOptions = {}) {\n ended = true;\n cancelTimer();\n const previous = pendingClears.get(slot);\n const run = endSession(clearOptions.resetClient ?? false);\n const settled = Promise.allSettled([previous, run]);\n pendingClears.set(slot, settled);\n void settled.then(() => {\n if (pendingClears.get(slot) === settled) pendingClears.delete(slot);\n });\n await run;\n },\n };\n}\n"],"mappings":"A,6KAmBA,IAAMQ,EAAgB,IAAI,IAsH1B,SAASC,EAAa,EAA4C,CAC9D,GAAI,CACA,OAAOT,EAAAA,iBAAiB,IAAKU,EAAa,CAAC,CAC/C,MAAQ,CACJ,OAAO,IACX,CACJ,CA4BA,SAAgBC,EACZ,EACuB,CACvB,GAAM,CAAE,cAAa,aAAa,IAAM,gBAAiBC,EACnDC,EAAMD,EAAQ,KAAO,iBACrBE,EAAeF,EAAQ,cAAgB,oBACvCG,EAAQd,EAAAA,mBAAqC,CAC/C,eACA,QAAS,EACT,UAAW,QACX,QAAS,MACT,QAAS,IACb,CAAC,EAEKe,EAAO,GAAGF,EAAa,QAAQD,IACjCI,EAAQ,GACRC,EAAc,GACdC,EAA8C,KAC5CC,EAAW,IAAI,IAErB,eAAeC,GAAmC,CAC9C,IAAMC,EAAUd,EAAc,IAAIQ,CAAI,EAClCM,GAAS,MAAMA,CACvB,CAEA,SAASC,GAAkB,CACnB,IAAgBrB,EAAAA,WAAW,IAC/B,EAAc,GACd,QAAQ,KACJ,0HAEJ,EACJ,CAEA,eAAesB,GAAsB,CAGjC,GAFIP,IACJ,MAA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EAAG,CAC3B,EAAQ,GACRL,EAAY,EACZ,IAAMQ,EAAW5B,EAAc,IAAIQ,CAAI,EACjCqB,EAAMH,EAAWI,EAAa,aAAe,EAAK,EAClDC,EAAU,QAAQ,WAAW,CAACH,EAAUC,CAAG,CAAC,EAClD7B,EAAc,IAAIQ,EAAMuB,CAAO,EAC/BA,EAAa,SAAW,CAChB/B,EAAc,IAAIQ,CAAI,IAAMuB,GAAS/B,EAAc,OAAOQ,CAAI,CACtE,CAAC,EACD,MAAMqB,CACV,CACJ,CACJ,C"}
|
|
1
|
+
{"version":3,"file":"offline-persistence.cjs","names":["ownerFingerprint","createOfflineStore","isDevBuild","dehydrate","require_dev_mode","require_owner_fingerprint","require_create_offline_store","_tanstack_react_query","pendingClears","ANONYMOUS_SNAPSHOT_OWNER","currentOwner","getPrincipal","persistQueryClientOffline","options","key","databaseName","store","slot","ended","warnedEnded","warnedRebound","boundOwner","timer","inFlight","afterPendingClear","pending","warnEnded","warnRebound","save","snapshot","queryClient","foreign","owner","write","cancelTimer","schedule","throttleMs","onCacheEvent","event","unsubscribeCache","endSession","resetClient","previous","run","clearOptions","settled"],"sources":["../../src/query/offline-persistence.ts"],"sourcesContent":["import {\n dehydrate,\n hydrate,\n type QueryCacheNotifyEvent,\n type QueryClient,\n} from \"@tanstack/react-query\";\nimport { createOfflineStore } from \"../offline/create-offline-store\";\nimport { isDevBuild } from \"../utils/dev-mode\";\nimport { ownerFingerprint } from \"../utils/owner-fingerprint\";\n\n/**\n * Clears still running, per `databaseName` + `key` slot, across every handle.\n *\n * A handle's `clear()` deletes by key with no ordering against other handles,\n * so a new handle created on login while the previous one is still clearing\n * could `restore()` the previous user's snapshot before the delete lands, or\n * have its first write deleted by it. Every handle's `restore()` and writes\n * wait for the slot's pending clear first; the entry is dropped once settled.\n */\nconst pendingClears = new Map<string, Promise<unknown>>();\n\n/** Options for {@link persistQueryClientOffline}. */\nexport interface OfflineQueryPersistenceOptions {\n /** The `QueryClient` to snapshot and restore. */\n queryClient: QueryClient;\n /** IndexedDB database name for the snapshot. Default `\"TempestQueryCache\"`. */\n databaseName?: string;\n /** Row key under which the snapshot is stored. Default `\"tanstack-query\"`. */\n key?: string;\n /**\n * Minimum gap between snapshot writes, in ms — cache churn is coalesced into\n * one trailing write per window. Default `1000`.\n */\n throttleMs?: number;\n /**\n * Who is signed in right now — a stable, non-secret id such as the user id;\n * `null`/`undefined` when nobody is. Read on every write, which stamps the\n * snapshot with a one-way fingerprint of it (never the id itself), on\n * `restore()`, which hydrates only a snapshot stamped with the same\n * fingerprint, and on cache changes until the handle is bound.\n *\n * `clear()` on logout already deletes the snapshot; this covers the session\n * that ends without it — a token that expired, a crash, a tab closed while\n * signed in. Without it, the next account to boot on the browser is shown\n * the previous account's cached responses (#531). A snapshot written before\n * this option was set carries no stamp and is not restored either; it is a\n * cache, so the cost is one cold start.\n *\n * A foreign snapshot is skipped, not deleted: a cookie app that only learns\n * the principal after a `/me` round trip would otherwise wipe its own cache\n * on every cold start. The next write replaces it.\n *\n * The handle is bound to the first signed-in owner it sees on a cache\n * change, a write or a restore — the cache change is what pins the owner of\n * data that a throttled write would otherwise stamp with whoever is signed\n * in a second later (#580). Once bound, a write under another owner —\n * nobody, because the token expired without `clear()`, or a second account\n * on the same tab — deletes the snapshot instead of stamping the bound\n * owner's cached responses with the new owner (#563); the same owner coming\n * back writes again. Writes\n * before anyone signs in stay anonymous and are restored while nobody is,\n * so an app that persists logged-out data keeps doing so. An anonymous\n * snapshot written by 0.82.0 is not restored (it may hold an expired\n * session's cache): one cold start, once.\n *\n * Read synchronously. A non-string, non-number value (the `Promise` of an\n * `async` getter) or a getter that throws reads as nobody. Omit it to restore\n * every snapshot, as before 0.82.0.\n */\n getPrincipal?: () => string | number | null | undefined;\n}\n\n/** Options for {@link OfflineQueryPersistence.clear}. */\nexport interface OfflineQueryClearOptions {\n /**\n * Also clear the in-memory `QueryClient` (`queryClient.clear()`) once\n * persistence has stopped and the snapshot is deleted — the one-call logout.\n * Default `false`: the client belongs to the app, which may want to keep\n * public queries (a catalog, feature flags) across sessions and drop only\n * the user-scoped keys with `removeQueries`.\n */\n resetClient?: boolean;\n}\n\n/** Handle returned by {@link persistQueryClientOffline}. */\nexport interface OfflineQueryPersistence {\n /**\n * Load the persisted snapshot into the `QueryClient`. Call once on boot,\n * before rendering queries, so cached data is available offline. A no-op\n * once {@link OfflineQueryPersistence.clear} has been called, and — with\n * `getPrincipal` — for a snapshot written under another principal.\n */\n restore: () => Promise<void>;\n /**\n * Write the current cache snapshot immediately (bypassing the throttle). A\n * no-op once {@link OfflineQueryPersistence.clear} has been called.\n */\n flush: () => Promise<void>;\n /** Stop persisting and drop the pending write. Idempotent. */\n unsubscribe: () => void;\n /**\n * End the persisted session (e.g. on logout) and delete the snapshot.\n *\n * Terminal for this handle: it cancels the pending throttled write, stops\n * persisting cache changes, waits for any write already in flight and only\n * then deletes the row — so neither a write pending in the last throttle\n * window nor cache activity after logout (the next user's first query) can\n * re-persist the previous user's responses. Afterwards `restore`/`flush`\n * are no-ops; to persist a new session, call\n * {@link persistQueryClientOffline} again after login. In a dev build\n * (`isDevBuild()`), the first `restore`, `flush` or added/updated query on\n * an ended handle logs one `console.warn` saying so, because a handle kept\n * at module scope would otherwise stop persisting in silence.\n *\n * Ordered against other handles on the same `databaseName` + `key`: until\n * this clear settles, a new handle's `restore()` and writes wait for it, so\n * a handle created on login without awaiting the logout neither hydrates\n * the previous snapshot nor has its first write deleted.\n *\n * If the delete rejects, `resetClient` still clears the client and the\n * rejection reaches the caller.\n *\n * The in-memory `QueryClient` is cleared only with `resetClient: true`, and\n * then only after persistence has stopped, so the reset itself cannot\n * trigger a write. It is opt-in because the app owns the client and the\n * shape of its logout: it may keep public queries and drop only the\n * user-scoped keys with `removeQueries`. Because persistence is already\n * off, that manual call can come before or after this one.\n *\n * Idempotent and safe to call concurrently; every call deletes the row\n * again.\n *\n * @param options - `resetClient` also clears the in-memory `QueryClient`.\n */\n clear: (options?: OfflineQueryClearOptions) => Promise<void>;\n}\n\n/**\n * Owner stamp of a snapshot written while nobody was signed in.\n *\n * Not a fingerprint (`ownerFingerprint` only yields `p:` + 16 hex characters),\n * so it never matches a signed-in owner. It replaces the `null` stamp of 0.82.0\n * on purpose: a `null` row from 0.82.0 may hold the cache of a session that\n * expired before the write (#563), and nothing in it tells that row apart from\n * genuinely anonymous data, so `restore()` skips it — one cold start, once.\n */\nconst ANONYMOUS_SNAPSHOT_OWNER = \"p:anonymous\";\n\ninterface Snapshot {\n id: string;\n state: ReturnType<typeof dehydrate>;\n /**\n * Owner fingerprint, or {@link ANONYMOUS_SNAPSHOT_OWNER}, when `getPrincipal`\n * was set at write time; absent otherwise.\n */\n owner?: string | null;\n}\n\n/**\n * Fingerprint whoever `getPrincipal` says is signed in.\n *\n * @param getPrincipal - The app's principal getter.\n * @returns The fingerprint, or `null` for nobody, a non-identity value or a throw.\n */\nfunction currentOwner(getPrincipal: () => unknown): string | null {\n try {\n return ownerFingerprint(\"p\", getPrincipal());\n } catch {\n return null;\n }\n}\n\n/**\n * Persist a TanStack `QueryClient` cache to IndexedDB (via\n * {@link createOfflineStore}) and restore it on boot — so a reload or a cold\n * offline start shows the last-known data instead of empty screens.\n *\n * Self-contained: uses `dehydrate`/`hydrate` from `@tanstack/react-query`\n * directly, so no `@tanstack/react-query-persist-client` dependency is needed.\n * Writes are throttled and subscribe to the query cache; call `unsubscribe` on\n * teardown. Dexie is a peer dependency of the offline store — install it.\n *\n * @param options - The client plus storage/throttle configuration.\n * @returns A handle with `restore`, `flush`, `clear` and `unsubscribe`.\n *\n * `clear()` is terminal for the handle (see {@link OfflineQueryPersistence.clear}):\n * a logout that only deleted the row used to be undone by the pending write or\n * by the next cache event, restoring the previous user's data on the next boot\n * (#440).\n *\n * @example\n * const persistence = persistQueryClientOffline({ queryClient });\n * await persistence.restore();\n *\n * async function logout(): Promise<void> {\n * await persistence.clear({ resetClient: true });\n * }\n */\nexport function persistQueryClientOffline(\n options: OfflineQueryPersistenceOptions,\n): OfflineQueryPersistence {\n const { queryClient, throttleMs = 1000, getPrincipal } = options;\n const key = options.key ?? \"tanstack-query\";\n const databaseName = options.databaseName ?? \"TempestQueryCache\";\n const store = createOfflineStore<Snapshot, string>({\n databaseName,\n version: 1,\n tableName: \"cache\",\n indexes: \"&id\",\n keyPath: \"id\",\n });\n\n const slot = `${databaseName}\\u0000${key}`;\n let ended = false;\n let warnedEnded = false;\n let warnedRebound = false;\n let boundOwner: string | null = null;\n let timer: ReturnType<typeof setTimeout> | null = null;\n const inFlight = new Set<Promise<unknown>>();\n\n async function afterPendingClear(): Promise<void> {\n const pending = pendingClears.get(slot);\n if (pending) await pending;\n }\n\n function warnEnded(): void {\n if (warnedEnded || !isDevBuild()) return;\n warnedEnded = true;\n console.warn(\n \"[tempest-react-sdk] persistQueryClientOffline: handle ended by clear(); \" +\n \"create a new one after login to keep persisting.\",\n );\n }\n\n function warnRebound(): void {\n if (warnedRebound || !isDevBuild()) return;\n warnedRebound = true;\n console.warn(\n \"[tempest-react-sdk] persistQueryClientOffline: another account signed in on a \" +\n \"handle bound to the previous one; its snapshot is deleted instead of written. \" +\n \"Create a new handle after login to keep persisting.\",\n );\n }\n\n /**\n * Write the snapshot, or delete the row when the session it holds is over.\n *\n * With `getPrincipal`, the handle is bound to the first signed-in owner it\n * sees on a cache change, a write or a restore. A write under any other owner — nobody, after a token\n * expired, or a second account signing in on the same tab — deletes the row\n * instead of stamping it: the in-memory cache still holds the bound owner's\n * responses, and stamping them with the new owner is what handed them to the\n * next account (#563). The same owner coming back writes again.\n *\n * A second account (not an expiry) means the app kept the handle across a\n * login, which stops persistence for that account in silence; a dev build\n * logs one `console.warn` saying so, as for a handle ended by `clear()`.\n */\n async function save(): Promise<void> {\n if (ended) return;\n await afterPendingClear();\n if (ended) return;\n const snapshot: Snapshot = { id: key, state: dehydrate(queryClient) };\n let foreign = false;\n if (getPrincipal) {\n const owner = currentOwner(getPrincipal);\n foreign = boundOwner !== null && owner !== boundOwner;\n if (foreign && owner !== null) warnRebound();\n boundOwner ??= owner;\n snapshot.owner = owner ?? ANONYMOUS_SNAPSHOT_OWNER;\n }\n const write = foreign ? store.delete(key) : store.put(snapshot);\n inFlight.add(write);\n try {\n await write;\n } finally {\n inFlight.delete(write);\n }\n }\n\n function cancelTimer(): void {\n if (timer) {\n clearTimeout(timer);\n timer = null;\n }\n }\n\n function schedule(): void {\n if (timer || ended) return;\n timer = setTimeout(() => {\n timer = null;\n void save();\n }, throttleMs);\n }\n\n /**\n * Schedule a write for cache activity, or detach once the handle has ended.\n *\n * With `getPrincipal`, an unbound handle is bound here, to whoever is\n * signed in when the cache changes — not only by a write or a restore. The\n * write is throttled, so the principal it reads can already be someone\n * else's: a session that expired inside the first window used to stamp the\n * previous user's responses `p:anonymous`, which the next logged-out boot\n * hydrated and the next account re-stamped as its own; an account that\n * signed in inside it got them stamped as its own directly (#580). Binding\n * at event time pins the owner of the data, so that write deletes instead.\n * An event while nobody is signed in leaves the handle unbound, which keeps\n * the cookie app whose principal arrives after `/me` persisting.\n */\n function onCacheEvent(event: QueryCacheNotifyEvent): void {\n if (!ended) {\n if (getPrincipal) boundOwner ??= currentOwner(getPrincipal);\n schedule();\n return;\n }\n if (event.type !== \"added\" && event.type !== \"updated\") return;\n unsubscribeCache();\n warnEnded();\n }\n\n const unsubscribeCache = queryClient.getQueryCache().subscribe(onCacheEvent);\n\n async function endSession(resetClient: boolean): Promise<void> {\n try {\n await Promise.allSettled([...inFlight]);\n await store.delete(key);\n } finally {\n if (resetClient) queryClient.clear();\n }\n }\n\n return {\n async restore() {\n if (ended) {\n warnEnded();\n return;\n }\n await afterPendingClear();\n if (ended) return;\n const snapshot = await store.get(key);\n if (!snapshot || ended) return;\n if (getPrincipal) {\n const owner = currentOwner(getPrincipal);\n if (snapshot.owner !== (owner ?? ANONYMOUS_SNAPSHOT_OWNER)) return;\n boundOwner ??= owner;\n }\n hydrate(queryClient, snapshot.state);\n },\n async flush() {\n if (ended) {\n warnEnded();\n return;\n }\n cancelTimer();\n await save();\n },\n unsubscribe() {\n cancelTimer();\n unsubscribeCache();\n },\n async clear(clearOptions = {}) {\n ended = true;\n cancelTimer();\n const previous = pendingClears.get(slot);\n const run = endSession(clearOptions.resetClient ?? false);\n const settled = Promise.allSettled([previous, run]);\n pendingClears.set(slot, settled);\n void settled.then(() => {\n if (pendingClears.get(slot) === settled) pendingClears.delete(slot);\n });\n await run;\n },\n };\n}\n"],"mappings":"A,6KAmBA,IAAMQ,EAAgB,IAAI,IA+HpBC,EAA2B,cAkBjC,SAASC,EAAa,EAA4C,CAC9D,GAAI,CACA,OAAOV,EAAAA,iBAAiB,IAAKW,EAAa,CAAC,CAC/C,MAAQ,CACJ,OAAO,IACX,CACJ,CA4BA,SAAgBC,EACZ,EACuB,CACvB,GAAM,CAAE,cAAa,aAAa,IAAM,gBAAiBC,EACnDC,EAAMD,EAAQ,KAAO,iBACrBE,EAAeF,EAAQ,cAAgB,oBACvCG,EAAQf,EAAAA,mBAAqC,CAC/C,eACA,QAAS,EACT,UAAW,QACX,QAAS,MACT,QAAS,IACb,CAAC,EAEKgB,EAAO,GAAGF,EAAa,QAAQD,IACjCI,EAAQ,GACRC,EAAc,GACdC,EAAgB,GAChBC,EAA4B,KAC5BC,EAA8C,KAC5CC,EAAW,IAAI,IAErB,eAAeC,GAAmC,CAC9C,IAAMC,EAAUjB,EAAc,IAAIS,CAAI,EAClCQ,GAAS,MAAMA,CACvB,CAEA,SAASC,GAAkB,CACnB,IAAgBxB,EAAAA,WAAW,IAC/B,EAAc,GACd,QAAQ,KACJ,0HAEJ,EACJ,CAEA,SAASyB,GAAoB,CACrB,IAAkBzB,EAAAA,WAAW,IACjC,EAAgB,GAChB,QAAQ,KACJ,iNAGJ,EACJ,CAgBA,eAAe0B,GAAsB,CAGjC,GAFIV,IACJ,MAAMM,EAAkB,EACpBN,GAAO,OACX,IAAMW,EAAqB,CAAE,GAAIf,EAAK,OAAA,EAAOX,EAAAA,UAAAA,CAAU2B,C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zB,EAAA,QAAA,CAAQuB,EAAaD,EAAS,KAAK,CADnC,CAEJ,EACA,MAAM,OAAQ,CACNX,EACAQ,EAAU,GAGdQ,EAAY,EACZ,MAAMN,EAAK,EACf,EACA,aAAc,CACVM,EAAY,EACZK,EAAiB,CACrB,EACA,MAAM,MAAM,EAAe,CAAC,EAAG,CAC3B,EAAQ,GACRL,EAAY,EACZ,IAAMQ,EAAWlC,EAAc,IAAIS,CAAI,EACjC0B,EAAMH,EAAWI,EAAa,aAAe,EAAK,EAClDC,EAAU,QAAQ,WAAW,CAACH,EAAUC,CAAG,CAAC,EAClDnC,EAAc,IAAIS,EAAM4B,CAAO,EAC/BA,EAAa,SAAW,CAChBrC,EAAc,IAAIS,CAAI,IAAM4B,GAASrC,EAAc,OAAOS,CAAI,CACtE,CAAC,EACD,MAAM0B,CACV,CACJ,CACJ,C"}
|
|
@@ -3,89 +3,102 @@ import { ownerFingerprint as t } from "../utils/owner-fingerprint.js";
|
|
|
3
3
|
import { createOfflineStore as n } from "../offline/create-offline-store.js";
|
|
4
4
|
import { dehydrate as r, hydrate as i } from "@tanstack/react-query";
|
|
5
5
|
//#region src/query/offline-persistence.ts
|
|
6
|
-
var a = /* @__PURE__ */ new Map();
|
|
7
|
-
function
|
|
6
|
+
var a = /* @__PURE__ */ new Map(), o = "p:anonymous";
|
|
7
|
+
function s(e) {
|
|
8
8
|
try {
|
|
9
9
|
return t("p", e());
|
|
10
10
|
} catch {
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
let { queryClient:
|
|
16
|
-
databaseName:
|
|
14
|
+
function c(t) {
|
|
15
|
+
let { queryClient: c, throttleMs: l = 1e3, getPrincipal: u } = t, d = t.key ?? "tanstack-query", f = t.databaseName ?? "TempestQueryCache", p = n({
|
|
16
|
+
databaseName: f,
|
|
17
17
|
version: 1,
|
|
18
18
|
tableName: "cache",
|
|
19
19
|
indexes: "&id",
|
|
20
20
|
keyPath: "id"
|
|
21
|
-
}),
|
|
22
|
-
async function
|
|
23
|
-
let e = a.get(
|
|
21
|
+
}), m = `${f}\u0000${d}`, h = !1, g = !1, _ = !1, v = null, y = null, b = /* @__PURE__ */ new Set();
|
|
22
|
+
async function x() {
|
|
23
|
+
let e = a.get(m);
|
|
24
24
|
e && await e;
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
!
|
|
26
|
+
function S() {
|
|
27
|
+
!g && e() && (g = !0, console.warn("[tempest-react-sdk] persistQueryClientOffline: handle ended by clear(); create a new one after login to keep persisting."));
|
|
28
|
+
}
|
|
29
|
+
function C() {
|
|
30
|
+
!_ && e() && (_ = !0, console.warn("[tempest-react-sdk] persistQueryClientOffline: another account signed in on a handle bound to the previous one; its snapshot is deleted instead of written. Create a new handle after login to keep persisting."));
|
|
28
31
|
}
|
|
29
|
-
async function
|
|
30
|
-
if (
|
|
32
|
+
async function w() {
|
|
33
|
+
if (h || (await x(), h)) return;
|
|
31
34
|
let e = {
|
|
32
|
-
id:
|
|
33
|
-
state: r(
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
id: d,
|
|
36
|
+
state: r(c)
|
|
37
|
+
}, t = !1;
|
|
38
|
+
if (u) {
|
|
39
|
+
let n = s(u);
|
|
40
|
+
t = v !== null && n !== v, t && n !== null && C(), v ??= n, e.owner = n ?? o;
|
|
41
|
+
}
|
|
42
|
+
let n = t ? p.delete(d) : p.put(e);
|
|
43
|
+
b.add(n);
|
|
38
44
|
try {
|
|
39
|
-
await
|
|
45
|
+
await n;
|
|
40
46
|
} finally {
|
|
41
|
-
|
|
47
|
+
b.delete(n);
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
50
|
+
function T() {
|
|
51
|
+
y &&= (clearTimeout(y), null);
|
|
46
52
|
}
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
},
|
|
53
|
+
function E() {
|
|
54
|
+
y || h || (y = setTimeout(() => {
|
|
55
|
+
y = null, w();
|
|
56
|
+
}, l));
|
|
51
57
|
}
|
|
52
|
-
function
|
|
53
|
-
|
|
58
|
+
function D(e) {
|
|
59
|
+
h ? (e.type === "added" || e.type === "updated") && (O(), S()) : (u && (v ??= s(u)), E());
|
|
54
60
|
}
|
|
55
|
-
let
|
|
56
|
-
async function
|
|
61
|
+
let O = c.getQueryCache().subscribe(D);
|
|
62
|
+
async function k(e) {
|
|
57
63
|
try {
|
|
58
|
-
await Promise.allSettled([...
|
|
64
|
+
await Promise.allSettled([...b]), await p.delete(d);
|
|
59
65
|
} finally {
|
|
60
|
-
e &&
|
|
66
|
+
e && c.clear();
|
|
61
67
|
}
|
|
62
68
|
}
|
|
63
69
|
return {
|
|
64
70
|
async restore() {
|
|
65
|
-
if (
|
|
66
|
-
|
|
71
|
+
if (h) {
|
|
72
|
+
S();
|
|
67
73
|
return;
|
|
68
74
|
}
|
|
69
|
-
if (await
|
|
70
|
-
let e = await
|
|
71
|
-
e && !
|
|
75
|
+
if (await x(), h) return;
|
|
76
|
+
let e = await p.get(d);
|
|
77
|
+
if (e && !h) {
|
|
78
|
+
if (u) {
|
|
79
|
+
let t = s(u);
|
|
80
|
+
if (e.owner !== (t ?? o)) return;
|
|
81
|
+
v ??= t;
|
|
82
|
+
}
|
|
83
|
+
i(c, e.state);
|
|
84
|
+
}
|
|
72
85
|
},
|
|
73
86
|
async flush() {
|
|
74
|
-
|
|
87
|
+
h ? S() : (T(), await w());
|
|
75
88
|
},
|
|
76
89
|
unsubscribe() {
|
|
77
|
-
|
|
90
|
+
T(), O();
|
|
78
91
|
},
|
|
79
92
|
async clear(e = {}) {
|
|
80
|
-
|
|
81
|
-
let t = a.get(
|
|
82
|
-
a.set(
|
|
83
|
-
a.get(
|
|
93
|
+
h = !0, T();
|
|
94
|
+
let t = a.get(m), n = k(e.resetClient ?? !1), r = Promise.allSettled([t, n]);
|
|
95
|
+
a.set(m, r), r.then(() => {
|
|
96
|
+
a.get(m) === r && a.delete(m);
|
|
84
97
|
}), await n;
|
|
85
98
|
}
|
|
86
99
|
};
|
|
87
100
|
}
|
|
88
101
|
//#endregion
|
|
89
|
-
export {
|
|
102
|
+
export { c as persistQueryClientOffline };
|
|
90
103
|
|
|
91
104
|
//# sourceMappingURL=offline-persistence.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"offline-persistence.js","names":["pendingClears","currentOwner","ownerFingerprint","getPrincipal","persistQueryClientOffline","options","key","databaseName","store","createOfflineStore","slot","ended","warnedEnded","timer","inFlight","afterPendingClear","pending","warnEnded","isDevBuild","save","snapshot","dehydrate","queryClient","write","cancelTimer","schedule","throttleMs","onCacheEvent","event","unsubscribeCache","endSession","resetClient","hydrate","previous","run","clearOptions","settled"],"sources":["../../src/query/offline-persistence.ts"],"sourcesContent":["import {\n dehydrate,\n hydrate,\n type QueryCacheNotifyEvent,\n type QueryClient,\n} from \"@tanstack/react-query\";\nimport { createOfflineStore } from \"../offline/create-offline-store\";\nimport { isDevBuild } from \"../utils/dev-mode\";\nimport { ownerFingerprint } from \"../utils/owner-fingerprint\";\n\n/**\n * Clears still running, per `databaseName` + `key` slot, across every handle.\n *\n * A handle's `clear()` deletes by key with no ordering against other handles,\n * so a new handle created on login while the previous one is still clearing\n * could `restore()` the previous user's snapshot before the delete lands, or\n * have its first write deleted by it. Every handle's `restore()` and writes\n * wait for the slot's pending clear first; the entry is dropped once settled.\n */\nconst pendingClears = new Map<string, Promise<unknown>>();\n\n/** Options for {@link persistQueryClientOffline}. */\nexport interface OfflineQueryPersistenceOptions {\n /** The `QueryClient` to snapshot and restore. */\n queryClient: QueryClient;\n /** IndexedDB database name for the snapshot. Default `\"TempestQueryCache\"`. */\n databaseName?: string;\n /** Row key under which the snapshot is stored. Default `\"tanstack-query\"`. */\n key?: string;\n /**\n * Minimum gap between snapshot writes, in ms — cache churn is coalesced into\n * one trailing write per window. Default `1000`.\n */\n throttleMs?: number;\n /**\n * Who is signed in right now — a stable, non-secret id such as the user id;\n * `null`/`undefined` when nobody is. Read on every write, which stamps the\n * snapshot with a one-way fingerprint of it (never the id itself), and on\n * `restore()`, which hydrates only a snapshot stamped with the same\n * fingerprint.\n *\n * `clear()` on logout already deletes the snapshot; this covers the session\n * that ends without it — a token that expired, a crash, a tab closed while\n * signed in. Without it, the next account to boot on the browser is shown\n * the previous account's cached responses (#531). A snapshot written before\n * this option was set carries no stamp and is not restored either; it is a\n * cache, so the cost is one cold start.\n *\n * A foreign snapshot is skipped, not deleted: a cookie app that only learns\n * the principal after a `/me` round trip would otherwise wipe its own cache\n * on every cold start. The next write replaces it.\n *\n * Read synchronously. A non-string, non-number value (the `Promise` of an\n * `async` getter) or a getter that throws reads as nobody. Omit it to restore\n * every snapshot, as before 0.82.0.\n */\n getPrincipal?: () => string | number | null | undefined;\n}\n\n/** Options for {@link OfflineQueryPersistence.clear}. */\nexport interface OfflineQueryClearOptions {\n /**\n * Also clear the in-memory `QueryClient` (`queryClient.clear()`) once\n * persistence has stopped and the snapshot is deleted — the one-call logout.\n * Default `false`: the client belongs to the app, which may want to keep\n * public queries (a catalog, feature flags) across sessions and drop only\n * the user-scoped keys with `removeQueries`.\n */\n resetClient?: boolean;\n}\n\n/** Handle returned by {@link persistQueryClientOffline}. */\nexport interface OfflineQueryPersistence {\n /**\n * Load the persisted snapshot into the `QueryClient`. Call once on boot,\n * before rendering queries, so cached data is available offline. A no-op\n * once {@link OfflineQueryPersistence.clear} has been called, and — with\n * `getPrincipal` — for a snapshot written under another principal.\n */\n restore: () => Promise<void>;\n /**\n * Write the current cache snapshot immediately (bypassing the throttle). A\n * no-op once {@link OfflineQueryPersistence.clear} has been called.\n */\n flush: () => Promise<void>;\n /** Stop persisting and drop the pending write. Idempotent. */\n unsubscribe: () => void;\n /**\n * End the persisted session (e.g. on logout) and delete the snapshot.\n *\n * Terminal for this handle: it cancels the pending throttled write, stops\n * persisting cache changes, waits for any write already in flight and only\n * then deletes the row — so neither a write pending in the last throttle\n * window nor cache activity after logout (the next user's first query) can\n * re-persist the previous user's responses. Afterwards `restore`/`flush`\n * are no-ops; to persist a new session, call\n * {@link persistQueryClientOffline} again after login. In a dev build\n * (`isDevBuild()`), the first `restore`, `flush` or added/updated query on\n * an ended handle logs one `console.warn` saying so, because a handle kept\n * at module scope would otherwise stop persisting in silence.\n *\n * Ordered against other handles on the same `databaseName` + `key`: until\n * this clear settles, a new handle's `restore()` and writes wait for it, so\n * a handle created on login without awaiting the logout neither hydrates\n * the previous snapshot nor has its first write deleted.\n *\n * If the delete rejects, `resetClient` still clears the client and the\n * rejection reaches the caller.\n *\n * The in-memory `QueryClient` is cleared only with `resetClient: true`, and\n * then only after persistence has stopped, so the reset itself cannot\n * trigger a write. It is opt-in because the app owns the client and the\n * shape of its logout: it may keep public queries and drop only the\n * user-scoped keys with `removeQueries`. Because persistence is already\n * off, that manual call can come before or after this one.\n *\n * Idempotent and safe to call concurrently; every call deletes the row\n * again.\n *\n * @param options - `resetClient` also clears the in-memory `QueryClient`.\n */\n clear: (options?: OfflineQueryClearOptions) => Promise<void>;\n}\n\ninterface Snapshot {\n id: string;\n state: ReturnType<typeof dehydrate>;\n /** Owner fingerprint when `getPrincipal` was set at write time; absent otherwise. */\n owner?: string | null;\n}\n\n/**\n * Fingerprint whoever `getPrincipal` says is signed in.\n *\n * @param getPrincipal - The app's principal getter.\n * @returns The fingerprint, or `null` for nobody, a non-identity value or a throw.\n */\nfunction currentOwner(getPrincipal: () => unknown): string | null {\n try {\n return ownerFingerprint(\"p\", getPrincipal());\n } catch {\n return null;\n }\n}\n\n/**\n * Persist a TanStack `QueryClient` cache to IndexedDB (via\n * {@link createOfflineStore}) and restore it on boot — so a reload or a cold\n * offline start shows the last-known data instead of empty screens.\n *\n * Self-contained: uses `dehydrate`/`hydrate` from `@tanstack/react-query`\n * directly, so no `@tanstack/react-query-persist-client` dependency is needed.\n * Writes are throttled and subscribe to the query cache; call `unsubscribe` on\n * teardown. Dexie is a peer dependency of the offline store — install it.\n *\n * @param options - The client plus storage/throttle configuration.\n * @returns A handle with `restore`, `flush`, `clear` and `unsubscribe`.\n *\n * `clear()` is terminal for the handle (see {@link OfflineQueryPersistence.clear}):\n * a logout that only deleted the row used to be undone by the pending write or\n * by the next cache event, restoring the previous user's data on the next boot\n * (#440).\n *\n * @example\n * const persistence = persistQueryClientOffline({ queryClient });\n * await persistence.restore();\n *\n * async function logout(): Promise<void> {\n * await persistence.clear({ resetClient: true });\n * }\n */\nexport function persistQueryClientOffline(\n options: OfflineQueryPersistenceOptions,\n): OfflineQueryPersistence {\n const { queryClient, throttleMs = 1000, getPrincipal } = options;\n const key = options.key ?? \"tanstack-query\";\n const databaseName = options.databaseName ?? \"TempestQueryCache\";\n const store = createOfflineStore<Snapshot, string>({\n databaseName,\n version: 1,\n tableName: \"cache\",\n indexes: \"&id\",\n keyPath: \"id\",\n });\n\n const slot = `${databaseName}\\u0000${key}`;\n let ended = false;\n let warnedEnded = false;\n let timer: ReturnType<typeof setTimeout> | null = null;\n const inFlight = new Set<Promise<unknown>>();\n\n async function afterPendingClear(): Promise<void> {\n const pending = pendingClears.get(slot);\n if (pending) await pending;\n }\n\n function warnEnded(): void {\n if (warnedEnded || !isDevBuild()) return;\n warnedEnded = true;\n console.warn(\n \"[tempest-react-sdk] persistQueryClientOffline: handle ended by clear(); \" +\n \"create a new one after login to keep persisting.\",\n );\n }\n\n async function save(): Promise<void> {\n if (ended) return;\n await afterPendingClear();\n if (ended) return;\n const snapshot: Snapshot = { id: key, state: dehydrate(queryClient) };\n if (getPrincipal) snapshot.owner = currentOwner(getPrincipal);\n const write = store.put(snapshot);\n inFlight.add(write);\n try {\n await write;\n } finally {\n inFlight.delete(write);\n }\n }\n\n function cancelTimer(): void {\n if (timer) {\n clearTimeout(timer);\n timer = null;\n }\n }\n\n function schedule(): void {\n if (timer || ended) return;\n timer = setTimeout(() => {\n timer = null;\n void save();\n }, throttleMs);\n }\n\n function onCacheEvent(event: QueryCacheNotifyEvent): void {\n if (!ended) {\n schedule();\n return;\n }\n if (event.type !== \"added\" && event.type !== \"updated\") return;\n unsubscribeCache();\n warnEnded();\n }\n\n const unsubscribeCache = queryClient.getQueryCache().subscribe(onCacheEvent);\n\n async function endSession(resetClient: boolean): Promise<void> {\n try {\n await Promise.allSettled([...inFlight]);\n await store.delete(key);\n } finally {\n if (resetClient) queryClient.clear();\n }\n }\n\n return {\n async restore() {\n if (ended) {\n warnEnded();\n return;\n }\n await afterPendingClear();\n if (ended) return;\n const snapshot = await store.get(key);\n if (!snapshot || ended) return;\n if (getPrincipal && snapshot.owner !== currentOwner(getPrincipal)) return;\n hydrate(queryClient, snapshot.state);\n },\n async flush() {\n if (ended) {\n warnEnded();\n return;\n }\n cancelTimer();\n await save();\n },\n unsubscribe() {\n cancelTimer();\n unsubscribeCache();\n },\n async clear(clearOptions = {}) {\n ended = true;\n cancelTimer();\n const previous = pendingClears.get(slot);\n const run = endSession(clearOptions.resetClient ?? false);\n const settled = Promise.allSettled([previous, run]);\n pendingClears.set(slot, settled);\n void settled.then(() => {\n if (pendingClears.get(slot) === settled) pendingClears.delete(slot);\n });\n await run;\n },\n };\n}\n"],"mappings":";;;;;AAmBA,IAAMA,oBAAgB,IAAI,IAA8B;AAsHxD,SAASC,EAAa,GAA4C;CAC9D,IAAI;EACA,OAAOC,EAAiB,KAAKC,EAAa,CAAC;CAC/C,QAAQ;EACJ,OAAO;CACX;AACJ;AA4BA,SAAgBC,EACZ,GACuB;CACvB,IAAM,EAAE,gBAAa,gBAAa,KAAM,oBAAiBC,GACnDC,IAAMD,EAAQ,OAAO,kBACrBE,IAAeF,EAAQ,gBAAgB,qBACvCG,IAAQC,EAAqC;EAC/C;EACA,SAAS;EACT,WAAW;EACX,SAAS;EACT,SAAS;CACb,CAAC,GAEKC,IAAO,GAAGH,EAAa,QAAQD,KACjCK,IAAQ,IACRC,IAAc,IACdC,IAA8C,MAC5CC,oBAAW,IAAI,IAAsB;CAE3C,eAAeC,IAAmC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,EAAS,UAAUnB,EAAaE,CAAY,KAChE6B,EAAQV,GAAaF,EAAS,KAAK;EACvC;EACA,MAAM,QAAQ;GACV,AAAIT,IACAM,EAAU,KAGdO,EAAY,GACZ,MAAML,EAAK;EACf;EACA,cAAc;GAEV,AADAK,EAAY,GACZK,EAAiB;EACrB;EACA,MAAM,MAAM,IAAe,CAAC,GAAG;GAE3B,AADA,IAAQ,IACRL,EAAY;GACZ,IAAMS,IAAWjC,EAAc,IAAIU,CAAI,GACjCwB,IAAMJ,EAAWK,EAAa,eAAe,EAAK,GAClDC,IAAU,QAAQ,WAAW,CAACH,GAAUC,CAAG,CAAC;GAKlD,AAJAlC,EAAc,IAAIU,GAAM0B,CAAO,GAC/BA,EAAa,WAAW;IACpB,AAAIpC,EAAc,IAAIU,CAAI,MAAM0B,KAASpC,EAAc,OAAOU,CAAI;GACtE,CAAC,GACD,MAAMwB;EACV;CACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"offline-persistence.js","names":["pendingClears","ANONYMOUS_SNAPSHOT_OWNER","currentOwner","ownerFingerprint","getPrincipal","persistQueryClientOffline","options","key","databaseName","store","createOfflineStore","slot","ended","warnedEnded","warnedRebound","boundOwner","timer","inFlight","afterPendingClear","pending","warnEnded","isDevBuild","warnRebound","save","snapshot","dehydrate","queryClient","foreign","owner","write","cancelTimer","schedule","throttleMs","onCacheEvent","event","unsubscribeCache","endSession","resetClient","previous","run","clearOptions","settled"],"sources":["../../src/query/offline-persistence.ts"],"sourcesContent":["import {\n dehydrate,\n hydrate,\n type QueryCacheNotifyEvent,\n type QueryClient,\n} from \"@tanstack/react-query\";\nimport { createOfflineStore } from \"../offline/create-offline-store\";\nimport { isDevBuild } from \"../utils/dev-mode\";\nimport { ownerFingerprint } from \"../utils/owner-fingerprint\";\n\n/**\n * Clears still running, per `databaseName` + `key` slot, across every handle.\n *\n * A handle's `clear()` deletes by key with no ordering against other handles,\n * so a new handle created on login while the previous one is still clearing\n * could `restore()` the previous user's snapshot before the delete lands, or\n * have its first write deleted by it. Every handle's `restore()` and writes\n * wait for the slot's pending clear first; the entry is dropped once settled.\n */\nconst pendingClears = new Map<string, Promise<unknown>>();\n\n/** Options for {@link persistQueryClientOffline}. */\nexport interface OfflineQueryPersistenceOptions {\n /** The `QueryClient` to snapshot and restore. */\n queryClient: QueryClient;\n /** IndexedDB database name for the snapshot. Default `\"TempestQueryCache\"`. */\n databaseName?: string;\n /** Row key under which the snapshot is stored. Default `\"tanstack-query\"`. */\n key?: string;\n /**\n * Minimum gap between snapshot writes, in ms — cache churn is coalesced into\n * one trailing write per window. Default `1000`.\n */\n throttleMs?: number;\n /**\n * Who is signed in right now — a stable, non-secret id such as the user id;\n * `null`/`undefined` when nobody is. Read on every write, which stamps the\n * snapshot with a one-way fingerprint of it (never the id itself), on\n * `restore()`, which hydrates only a snapshot stamped with the same\n * fingerprint, and on cache changes until the handle is bound.\n *\n * `clear()` on logout already deletes the snapshot; this covers the session\n * that ends without it — a token that expired, a crash, a tab closed while\n * signed in. Without it, the next account to boot on the browser is shown\n * the previous account's cached responses (#531). A snapshot written before\n * this option was set carries no stamp and is not restored either; it is a\n * cache, so the cost is one cold start.\n *\n * A foreign snapshot is skipped, not deleted: a cookie app that only learns\n * the principal after a `/me` round trip would otherwise wipe its own cache\n * on every cold start. The next write replaces it.\n *\n * The handle is bound to the first signed-in owner it sees on a cache\n * change, a write or a restore — the cache change is what pins the owner of\n * data that a throttled write would otherwise stamp with whoever is signed\n * in a second later (#580). Once bound, a write under another owner —\n * nobody, because the token expired without `clear()`, or a second account\n * on the same tab — deletes the snapshot instead of stamping the bound\n * owner's cached responses with the new owner (#563); the same owner coming\n * back writes again. Writes\n * before anyone signs in stay anonymous and are restored while nobody is,\n * so an app that persists logged-out data keeps doing so. An anonymous\n * snapshot written by 0.82.0 is not restored (it may hold an expired\n * session's cache): one cold start, once.\n *\n * Read synchronously. A non-string, non-number value (the `Promise` of an\n * `async` getter) or a getter that throws reads as nobody. Omit it to restore\n * every snapshot, as before 0.82.0.\n */\n getPrincipal?: () => string | number | null | undefined;\n}\n\n/** Options for {@link OfflineQueryPersistence.clear}. */\nexport interface OfflineQueryClearOptions {\n /**\n * Also clear the in-memory `QueryClient` (`queryClient.clear()`) once\n * persistence has stopped and the snapshot is deleted — the one-call logout.\n * Default `false`: the client belongs to the app, which may want to keep\n * public queries (a catalog, feature flags) across sessions and drop only\n * the user-scoped keys with `removeQueries`.\n */\n resetClient?: boolean;\n}\n\n/** Handle returned by {@link persistQueryClientOffline}. */\nexport interface OfflineQueryPersistence {\n /**\n * Load the persisted snapshot into the `QueryClient`. Call once on boot,\n * before rendering queries, so cached data is available offline. A no-op\n * once {@link OfflineQueryPersistence.clear} has been called, and — with\n * `getPrincipal` — for a snapshot written under another principal.\n */\n restore: () => Promise<void>;\n /**\n * Write the current cache snapshot immediately (bypassing the throttle). A\n * no-op once {@link OfflineQueryPersistence.clear} has been called.\n */\n flush: () => Promise<void>;\n /** Stop persisting and drop the pending write. Idempotent. */\n unsubscribe: () => void;\n /**\n * End the persisted session (e.g. on logout) and delete the snapshot.\n *\n * Terminal for this handle: it cancels the pending throttled write, stops\n * persisting cache changes, waits for any write already in flight and only\n * then deletes the row — so neither a write pending in the last throttle\n * window nor cache activity after logout (the next user's first query) can\n * re-persist the previous user's responses. Afterwards `restore`/`flush`\n * are no-ops; to persist a new session, call\n * {@link persistQueryClientOffline} again after login. In a dev build\n * (`isDevBuild()`), the first `restore`, `flush` or added/updated query on\n * an ended handle logs one `console.warn` saying so, because a handle kept\n * at module scope would otherwise stop persisting in silence.\n *\n * Ordered against other handles on the same `databaseName` + `key`: until\n * this clear settles, a new handle's `restore()` and writes wait for it, so\n * a handle created on login without awaiting the logout neither hydrates\n * the previous snapshot nor has its first write deleted.\n *\n * If the delete rejects, `resetClient` still clears the client and the\n * rejection reaches the caller.\n *\n * The in-memory `QueryClient` is cleared only with `resetClient: true`, and\n * then only after persistence has stopped, so the reset itself cannot\n * trigger a write. It is opt-in because the app owns the client and the\n * shape of its logout: it may keep public queries and drop only the\n * user-scoped keys with `removeQueries`. Because persistence is already\n * off, that manual call can come before or after this one.\n *\n * Idempotent and safe to call concurrently; every call deletes the row\n * again.\n *\n * @param options - `resetClient` also clears the in-memory `QueryClient`.\n */\n clear: (options?: OfflineQueryClearOptions) => Promise<void>;\n}\n\n/**\n * Owner stamp of a snapshot written while nobody was signed in.\n *\n * Not a fingerprint (`ownerFingerprint` only yields `p:` + 16 hex characters),\n * so it never matches a signed-in owner. It replaces the `null` stamp of 0.82.0\n * on purpose: a `null` row from 0.82.0 may hold the cache of a session that\n * expired before the write (#563), and nothing in it tells that row apart from\n * genuinely anonymous data, so `restore()` skips it — one cold start, once.\n */\nconst ANONYMOUS_SNAPSHOT_OWNER = \"p:anonymous\";\n\ninterface Snapshot {\n id: string;\n state: ReturnType<typeof dehydrate>;\n /**\n * Owner fingerprint, or {@link ANONYMOUS_SNAPSHOT_OWNER}, when `getPrincipal`\n * was set at write time; absent otherwise.\n */\n owner?: string | null;\n}\n\n/**\n * Fingerprint whoever `getPrincipal` says is signed in.\n *\n * @param getPrincipal - The app's principal getter.\n * @returns The fingerprint, or `null` for nobody, a non-identity value or a throw.\n */\nfunction currentOwner(getPrincipal: () => unknown): string | null {\n try {\n return ownerFingerprint(\"p\", getPrincipal());\n } catch {\n return null;\n }\n}\n\n/**\n * Persist a TanStack `QueryClient` cache to IndexedDB (via\n * {@link createOfflineStore}) and restore it on boot — so a reload or a cold\n * offline start shows the last-known data instead of empty screens.\n *\n * Self-contained: uses `dehydrate`/`hydrate` from `@tanstack/react-query`\n * directly, so no `@tanstack/react-query-persist-client` dependency is needed.\n * Writes are throttled and subscribe to the query cache; call `unsubscribe` on\n * teardown. Dexie is a peer dependency of the offline store — install it.\n *\n * @param options - The client plus storage/throttle configuration.\n * @returns A handle with `restore`, `flush`, `clear` and `unsubscribe`.\n *\n * `clear()` is terminal for the handle (see {@link OfflineQueryPersistence.clear}):\n * a logout that only deleted the row used to be undone by the pending write or\n * by the next cache event, restoring the previous user's data on the next boot\n * (#440).\n *\n * @example\n * const persistence = persistQueryClientOffline({ queryClient });\n * await persistence.restore();\n *\n * async function logout(): Promise<void> {\n * await persistence.clear({ resetClient: true });\n * }\n */\nexport function persistQueryClientOffline(\n options: OfflineQueryPersistenceOptions,\n): OfflineQueryPersistence {\n const { queryClient, throttleMs = 1000, getPrincipal } = options;\n const key = options.key ?? \"tanstack-query\";\n const databaseName = options.databaseName ?? \"TempestQueryCache\";\n const store = createOfflineStore<Snapshot, string>({\n databaseName,\n version: 1,\n tableName: \"cache\",\n indexes: \"&id\",\n keyPath: \"id\",\n });\n\n const slot = `${databaseName}\\u0000${key}`;\n let ended = false;\n let warnedEnded = false;\n let warnedRebound = false;\n let boundOwner: string | null = null;\n let timer: ReturnType<typeof setTimeout> | null = null;\n const inFlight = new Set<Promise<unknown>>();\n\n async function afterPendingClear(): Promise<void> {\n const pending = pendingClears.get(slot);\n if (pending) await pending;\n }\n\n function warnEnded(): void {\n if (warnedEnded || !isDevBuild()) return;\n warnedEnded = true;\n console.warn(\n \"[tempest-react-sdk] persistQueryClientOffline: handle ended by clear(); \" +\n \"create a new one after login to keep persisting.\",\n );\n }\n\n function warnRebound(): void {\n if (warnedRebound || !isDevBuild()) return;\n warnedRebound = true;\n console.warn(\n \"[tempest-react-sdk] persistQueryClientOffline: another account signed in on a \" +\n \"handle bound to the previous one; its snapshot is deleted instead of written. \" +\n \"Create a new handle after login to keep persisting.\",\n );\n }\n\n /**\n * Write the snapshot, or delete the row when the session it holds is over.\n *\n * With `getPrincipal`, the handle is bound to the first signed-in owner it\n * sees on a cache change, a write or a restore. A write under any other owner — nobody, after a token\n * expired, or a second account signing in on the same tab — deletes the row\n * instead of stamping it: the in-memory cache still holds the bound owner's\n * responses, and stamping them with the new owner is what handed them to the\n * next account (#563). The same owner coming back writes again.\n *\n * A second account (not an expiry) means the app kept the handle across a\n * login, which stops persistence for that account in silence; a dev build\n * logs one `console.warn` saying so, as for a handle ended by `clear()`.\n */\n async function save(): Promise<void> {\n if (ended) return;\n await afterPendingClear();\n if (ended) return;\n const snapshot: Snapshot = { id: key, state: dehydrate(queryClient) };\n let foreign = false;\n if (getPrincipal) {\n const owner = currentOwner(getPrincipal);\n foreign = boundOwner !== null && owner !== boundOwner;\n if (foreign && owner !== null) warnRebound();\n boundOwner ??= owner;\n snapshot.owner = owner ?? ANONYMOUS_SNAPSHOT_OWNER;\n }\n const write = foreign ? store.delete(key) : store.put(snapshot);\n inFlight.add(write);\n try {\n await write;\n } finally {\n inFlight.delete(write);\n }\n }\n\n function cancelTimer(): void {\n if (timer) {\n clearTimeout(timer);\n timer = null;\n }\n }\n\n function schedule(): void {\n if (timer || ended) return;\n timer = setTimeout(() => {\n timer = null;\n void save();\n }, throttleMs);\n }\n\n /**\n * Schedule a write for cache activity, or detach once the handle has ended.\n *\n * With `getPrincipal`, an unbound handle is bound here, to whoever is\n * signed in when the cache changes — not only by a write or a restore. The\n * write is throttled, so the principal it reads can already be someone\n * else's: a session that expired inside the first window used to stamp the\n * previous user's responses `p:anonymous`, which the next logged-out boot\n * hydrated and the next account re-stamped as its own; an account that\n * signed in inside it got them stamped as its own directly (#580). Binding\n * at event time pins the owner of the data, so that write deletes instead.\n * An event while nobody is signed in leaves the handle unbound, which keeps\n * the cookie app whose principal arrives after `/me` persisting.\n */\n function onCacheEvent(event: QueryCacheNotifyEvent): void {\n if (!ended) {\n if (getPrincipal) boundOwner ??= currentOwner(getPrincipal);\n schedule();\n return;\n }\n if (event.type !== \"added\" && event.type !== \"updated\") return;\n unsubscribeCache();\n warnEnded();\n }\n\n const unsubscribeCache = queryClient.getQueryCache().subscribe(onCacheEvent);\n\n async function endSession(resetClient: boolean): Promise<void> {\n try {\n await Promise.allSettled([...inFlight]);\n await store.delete(key);\n } finally {\n if (resetClient) queryClient.clear();\n }\n }\n\n return {\n async restore() {\n if (ended) {\n warnEnded();\n return;\n }\n await afterPendingClear();\n if (ended) return;\n const snapshot = await store.get(key);\n if (!snapshot || ended) return;\n if (getPrincipal) {\n const owner = currentOwner(getPrincipal);\n if (snapshot.owner !== (owner ?? ANONYMOUS_SNAPSHOT_OWNER)) return;\n boundOwner ??= owner;\n }\n hydrate(queryClient, snapshot.state);\n },\n async flush() {\n if (ended) {\n warnEnded();\n return;\n }\n cancelTimer();\n await save();\n },\n unsubscribe() {\n cancelTimer();\n unsubscribeCache();\n },\n async clear(clearOptions = {}) {\n ended = true;\n cancelTimer();\n const previous = pendingClears.get(slot);\n const run = endSession(clearOptions.resetClient ?? false);\n const settled = Promise.allSettled([previous, run]);\n pendingClears.set(slot, settled);\n void settled.then(() => {\n if (pendingClears.get(slot) === settled) pendingClears.delete(slot);\n });\n await run;\n },\n };\n}\n"],"mappings":";;;;;AAmBA,IAAMA,oBAAgB,IAAI,IAA8B,GA+HlDC,IAA2B;AAkBjC,SAASC,EAAa,GAA4C;CAC9D,IAAI;EACA,OAAOC,EAAiB,KAAKC,EAAa,CAAC;CAC/C,QAAQ;EACJ,OAAO;CACX;AACJ;AA4BA,SAAgBC,EACZ,GACuB;CACvB,IAAM,EAAE,gBAAa,gBAAa,KAAM,oBAAiBC,GACnDC,IAAMD,EAAQ,OAAO,kBACrBE,IAAeF,EAAQ,gBAAgB,qBACvCG,IAAQC,EAAqC;EAC/C;EACA,SAAS;EACT,WAAW;EACX,SAAS;EACT,SAAS;CACb,CAAC,GAEKC,IAAO,GAAGH,EAAa,QAAQD,KACjCK,IAAQ,IACRC,IAAc,IACdC,IAAgB,IAChBC,IAA4B,MAC5BC,IAA8C,MAC5CC,oBAAW,IAAI,IAAsB;CAE3C,eAAeC,IAAmC;EAC9C,IAAMC,IAAUnB,EAAc,IAAIW,CAAI;EACtC,AAAIQ,KAAS,MAAMA;CACvB;CAEA,SAASC,IAAkB;EACvB,AAAI,MAAgBC,EAAW,MAC/B,IAAc,IACd,QAAQ,KACJ,0HAEJ;CACJ;CAEA,SAASC,IAAoB;EACzB,AAAI,MAAkBD,EAAW,MACj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BN,GAAO;GACX,IAAMY,IAAW,MAAMf,EAAM,IAAIF,CAAG;GACpC,IAAKiB,KAAY,IACjB;QAAIpB,GAAc;KACd,IAAMwB,IAAQ1B,EAAaE,CAAY;KACvC,IAAIoB,EAAS,WAAWI,KAAS3B,IAA2B;KAC5D,MAAe2B;IACnB;IACA,EAAQF,GAAaF,EAAS,KAAK;GADnC;EAEJ;EACA,MAAM,QAAQ;GACV,AAAIZ,IACAQ,EAAU,KAGdU,EAAY,GACZ,MAAMP,EAAK;EACf;EACA,cAAc;GAEV,AADAO,EAAY,GACZK,EAAiB;EACrB;EACA,MAAM,MAAM,IAAe,CAAC,GAAG;GAE3B,AADA,IAAQ,IACRL,EAAY;GACZ,IAAMQ,IAAWtC,EAAc,IAAIW,CAAI,GACjC4B,IAAMH,EAAWI,EAAa,eAAe,EAAK,GAClDC,IAAU,QAAQ,WAAW,CAACH,GAAUC,CAAG,CAAC;GAKlD,AAJAvC,EAAc,IAAIW,GAAM8B,CAAO,GAC/BA,EAAa,WAAW;IACpB,AAAIzC,EAAc,IAAIW,CAAI,MAAM8B,KAASzC,EAAc,OAAOW,CAAI;GACtE,CAAC,GACD,MAAM4B;EACV;CACJ;AACJ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* Generated by scripts/split-css.mjs — do not edit. */
|
|
2
|
+
.tempest_checkout_KESha{align-items:center;gap:var(--tempest-space-3);width:100%;max-width:360px;font-family:var(--tempest-font-sans);color:var(--tempest-text);text-align:center;flex-direction:column;margin-inline:auto;display:flex}
|
|
3
|
+
.tempest_amount_7xCfs{font-size:var(--tempest-text-2xl);font-weight:var(--tempest-weight-semibold);font-variant-numeric:tabular-nums}
|
|
4
|
+
.tempest_state_I4M-g{text-align:start;width:100%}
|
|
5
|
+
div.tempest_state_I4M-g[role=status]{text-align:center}
|
|
6
|
+
.tempest_title_wcrWG{font-size:var(--tempest-text-lg);font-weight:var(--tempest-weight-semibold);margin:0}
|
|
7
|
+
.tempest_description_6tRir{margin:var(--tempest-space-1) 0 0;color:var(--tempest-text-muted);font-size:var(--tempest-text-sm);line-height:var(--tempest-leading-snug)}
|
|
8
|
+
.tempest_timer_KaP5v{color:var(--tempest-text-muted);font-size:var(--tempest-text-sm);margin:0}
|
|
9
|
+
.tempest_timer_KaP5v strong{color:var(--tempest-text);font-variant-numeric:tabular-nums}
|
|
10
|
+
.tempest_symbol_860pD{padding:var(--tempest-space-2);border:1px solid var(--tempest-border);border-radius:var(--tempest-radius-md);background:#fff;display:inline-flex}
|
|
11
|
+
.tempest_image_wTRUA{max-width:100%;height:auto;image-rendering:pixelated;display:block}
|
|
12
|
+
.tempest_hint_vdsWp{color:var(--tempest-text-muted);font-size:var(--tempest-text-sm);margin:0}
|
|
13
|
+
.tempest_copy_7GUOj{align-items:center;gap:var(--tempest-space-2);width:100%;display:flex}
|
|
14
|
+
.tempest_copy_7GUOj>button{white-space:nowrap;flex:none}
|
|
15
|
+
.tempest_code_KJufe{min-width:0;padding:var(--tempest-space-1) var(--tempest-space-2);background:var(--tempest-surface-2);border:1px solid var(--tempest-border);border-radius:var(--tempest-radius-sm);color:var(--tempest-text-muted);font-family:var(--tempest-font-mono);font-size:var(--tempest-text-xs);line-height:var(--tempest-leading-snug);text-align:start;text-overflow:ellipsis;white-space:nowrap;flex:auto;overflow:hidden}
|
|
16
|
+
.tempest_copyDone_MBlRT,.tempest_copy_7GUOj button[data-copied] .tempest_copyIdle_MW0LU{display:none}
|
|
17
|
+
.tempest_copy_7GUOj button[data-copied] .tempest_copyDone_MBlRT{display:inline}
|
|
18
|
+
.tempest_footer_YnAyb{width:100%}
|
|
@@ -365,6 +365,12 @@
|
|
|
365
365
|
"PinInput": [
|
|
366
366
|
"component/PinInput.css"
|
|
367
367
|
],
|
|
368
|
+
"PixCheckout": [
|
|
369
|
+
"component/Alert.css",
|
|
370
|
+
"component/CopyButton.css",
|
|
371
|
+
"component/PixCheckout.css",
|
|
372
|
+
"component/QRCode.css"
|
|
373
|
+
],
|
|
368
374
|
"Popover": [
|
|
369
375
|
"component/Popover.css"
|
|
370
376
|
],
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* Generated by scripts/split-css.mjs — do not edit. */
|
|
2
|
+
.tempest_checkout_KESha{align-items:center;gap:var(--tempest-space-3);width:100%;max-width:360px;font-family:var(--tempest-font-sans);color:var(--tempest-text);text-align:center;flex-direction:column;margin-inline:auto;display:flex}
|
|
3
|
+
.tempest_amount_7xCfs{font-size:var(--tempest-text-2xl);font-weight:var(--tempest-weight-semibold);font-variant-numeric:tabular-nums}
|
|
4
|
+
.tempest_state_I4M-g{text-align:start;width:100%}
|
|
5
|
+
div.tempest_state_I4M-g[role=status]{text-align:center}
|
|
6
|
+
.tempest_title_wcrWG{font-size:var(--tempest-text-lg);font-weight:var(--tempest-weight-semibold);margin:0}
|
|
7
|
+
.tempest_description_6tRir{margin:var(--tempest-space-1) 0 0;color:var(--tempest-text-muted);font-size:var(--tempest-text-sm);line-height:var(--tempest-leading-snug)}
|
|
8
|
+
.tempest_timer_KaP5v{color:var(--tempest-text-muted);font-size:var(--tempest-text-sm);margin:0}
|
|
9
|
+
.tempest_timer_KaP5v strong{color:var(--tempest-text);font-variant-numeric:tabular-nums}
|
|
10
|
+
.tempest_symbol_860pD{padding:var(--tempest-space-2);border:1px solid var(--tempest-border);border-radius:var(--tempest-radius-md);background:#fff;display:inline-flex}
|
|
11
|
+
.tempest_image_wTRUA{max-width:100%;height:auto;image-rendering:pixelated;display:block}
|
|
12
|
+
.tempest_hint_vdsWp{color:var(--tempest-text-muted);font-size:var(--tempest-text-sm);margin:0}
|
|
13
|
+
.tempest_copy_7GUOj{align-items:center;gap:var(--tempest-space-2);width:100%;display:flex}
|
|
14
|
+
.tempest_copy_7GUOj>button{white-space:nowrap;flex:none}
|
|
15
|
+
.tempest_code_KJufe{min-width:0;padding:var(--tempest-space-1) var(--tempest-space-2);background:var(--tempest-surface-2);border:1px solid var(--tempest-border);border-radius:var(--tempest-radius-sm);color:var(--tempest-text-muted);font-family:var(--tempest-font-mono);font-size:var(--tempest-text-xs);line-height:var(--tempest-leading-snug);text-align:start;text-overflow:ellipsis;white-space:nowrap;flex:auto;overflow:hidden}
|
|
16
|
+
.tempest_copyDone_MBlRT,.tempest_copy_7GUOj button[data-copied] .tempest_copyIdle_MW0LU{display:none}
|
|
17
|
+
.tempest_copy_7GUOj button[data-copied] .tempest_copyDone_MBlRT{display:inline}
|
|
18
|
+
.tempest_footer_YnAyb{width:100%}
|