@eifi1/ui-kit 0.43.0 → 0.45.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.
Files changed (134) hide show
  1. package/README.md +11 -7
  2. package/dist/admin/admin-action-log-labels.js +9 -0
  3. package/dist/admin/admin-action-log-labels.js.map +1 -1
  4. package/dist/admin/admin-action-log.d.ts +18 -1
  5. package/dist/admin/admin-action-log.js +25 -16
  6. package/dist/admin/admin-action-log.js.map +1 -1
  7. package/dist/admin/admin-area-labels.d.ts +6 -0
  8. package/dist/admin/admin-area-labels.js +1 -0
  9. package/dist/admin/admin-area-labels.js.map +1 -1
  10. package/dist/admin/mail-test-card-labels.d.ts +3 -0
  11. package/dist/admin/mail-test-card-labels.js +17 -0
  12. package/dist/admin/mail-test-card-labels.js.map +1 -0
  13. package/dist/admin/mail-test-card.d.ts +74 -0
  14. package/dist/admin/mail-test-card.js +80 -0
  15. package/dist/admin/mail-test-card.js.map +1 -0
  16. package/dist/billing/provider-page.d.ts +9 -0
  17. package/dist/billing/provider-page.js.map +1 -1
  18. package/dist/components/data-table-mobile.js +17 -2
  19. package/dist/components/data-table-mobile.js.map +1 -1
  20. package/dist/components/data-table-shared.d.ts +2 -0
  21. package/dist/components/data-table-shared.js +8 -0
  22. package/dist/components/data-table-shared.js.map +1 -1
  23. package/dist/components/data-table.js +1 -6
  24. package/dist/components/data-table.js.map +1 -1
  25. package/dist/eslint/index.js +1 -1
  26. package/dist/i18n/defaults.js +9 -1
  27. package/dist/i18n/defaults.js.map +1 -1
  28. package/dist/i18n/german.js +42 -2
  29. package/dist/i18n/german.js.map +1 -1
  30. package/dist/i18n/kit-labels.d.ts +13 -0
  31. package/dist/i18n/kit-labels.js.map +1 -1
  32. package/dist/i18n/locales/en.js +60 -4
  33. package/dist/i18n/locales/en.js.map +3 -3
  34. package/dist/i18n/locales/es.js +40 -0
  35. package/dist/i18n/locales/es.js.map +1 -1
  36. package/dist/i18n/locales/fr.js +42 -2
  37. package/dist/i18n/locales/fr.js.map +1 -1
  38. package/dist/i18n/locales/hu.js +40 -0
  39. package/dist/i18n/locales/hu.js.map +1 -1
  40. package/dist/i18n/locales/it.js +41 -1
  41. package/dist/i18n/locales/it.js.map +1 -1
  42. package/dist/i18n/locales/zh.js +40 -0
  43. package/dist/i18n/locales/zh.js.map +1 -1
  44. package/dist/i18n/review.js +13 -1
  45. package/dist/i18n/review.js.map +1 -1
  46. package/dist/index.d.ts +2 -0
  47. package/dist/index.js +5 -0
  48. package/dist/index.js.map +1 -1
  49. package/dist/lib/format.d.ts +2 -1
  50. package/dist/lib/format.js +6 -1
  51. package/dist/lib/format.js.map +1 -1
  52. package/dist/offline/pwa-update-prompt-labels.d.ts +2 -0
  53. package/dist/offline/pwa-update-prompt-labels.js +9 -0
  54. package/dist/offline/pwa-update-prompt-labels.js.map +1 -0
  55. package/dist/offline/pwa-update-prompt.d.ts +32 -0
  56. package/dist/offline/pwa-update-prompt.js +36 -0
  57. package/dist/offline/pwa-update-prompt.js.map +1 -0
  58. package/dist/offline/query-persistence.d.ts +100 -0
  59. package/dist/offline/query-persistence.js +179 -0
  60. package/dist/offline/query-persistence.js.map +1 -0
  61. package/dist/offline/shared-computer-labels.d.ts +2 -0
  62. package/dist/offline/shared-computer-labels.js +9 -0
  63. package/dist/offline/shared-computer-labels.js.map +1 -0
  64. package/dist/offline/shared-computer.d.ts +44 -0
  65. package/dist/offline/shared-computer.js +51 -0
  66. package/dist/offline/shared-computer.js.map +1 -0
  67. package/dist/offline/sign-out-pending-dialog-labels.d.ts +2 -0
  68. package/dist/offline/sign-out-pending-dialog-labels.js +14 -0
  69. package/dist/offline/sign-out-pending-dialog-labels.js.map +1 -0
  70. package/dist/offline/sign-out-pending-dialog.d.ts +58 -0
  71. package/dist/offline/sign-out-pending-dialog.js +66 -0
  72. package/dist/offline/sign-out-pending-dialog.js.map +1 -0
  73. package/dist/offline.d.ts +8 -0
  74. package/dist/offline.js +24 -0
  75. package/dist/offline.js.map +1 -0
  76. package/dist/shell/admin-menu.d.ts +24 -0
  77. package/dist/shell/admin-menu.js +12 -3
  78. package/dist/shell/admin-menu.js.map +1 -1
  79. package/dist/shell.d.ts +2 -0
  80. package/dist/shell.js +2 -0
  81. package/dist/shell.js.map +1 -1
  82. package/dist/tour/tour-catalogue-labels.js +2 -2
  83. package/dist/tour/tour-catalogue-labels.js.map +1 -1
  84. package/dist/tour/tour-catalogue.d.ts +7 -1
  85. package/dist/tour/tour-catalogue.js.map +1 -1
  86. package/dist/tour/tour-info.d.ts +2 -2
  87. package/dist/tour/tour-info.js.map +1 -1
  88. package/dist/tour/tour.d.ts +38 -2
  89. package/dist/tour/tour.js +42 -3
  90. package/dist/tour/tour.js.map +1 -1
  91. package/dist/tour/use-tour-progress.d.ts +165 -12
  92. package/dist/tour/use-tour-progress.js +271 -25
  93. package/dist/tour/use-tour-progress.js.map +1 -1
  94. package/dist/tour.d.ts +3 -1
  95. package/dist/tour.js +4 -1
  96. package/dist/tour.js.map +1 -1
  97. package/package.json +25 -1
  98. package/src/admin/admin-action-log-labels.ts +9 -0
  99. package/src/admin/admin-action-log.tsx +41 -5
  100. package/src/admin/admin-area-labels.ts +7 -0
  101. package/src/admin/mail-test-card-labels.ts +19 -0
  102. package/src/admin/mail-test-card.tsx +186 -0
  103. package/src/billing/provider-page.ts +9 -0
  104. package/src/components/data-table-mobile.tsx +26 -3
  105. package/src/components/data-table-shared.tsx +18 -1
  106. package/src/components/data-table.tsx +1 -15
  107. package/src/i18n/defaults.ts +8 -0
  108. package/src/i18n/german.ts +48 -2
  109. package/src/i18n/kit-labels.tsx +13 -0
  110. package/src/i18n/locales/en.ts +13 -1
  111. package/src/i18n/locales/es.ts +46 -0
  112. package/src/i18n/locales/fr.ts +48 -2
  113. package/src/i18n/locales/hu.ts +42 -0
  114. package/src/i18n/locales/it.ts +47 -1
  115. package/src/i18n/locales/zh.ts +40 -0
  116. package/src/i18n/review.ts +12 -0
  117. package/src/index.ts +3 -0
  118. package/src/lib/format.ts +13 -2
  119. package/src/offline/pwa-update-prompt-labels.ts +9 -0
  120. package/src/offline/pwa-update-prompt.tsx +72 -0
  121. package/src/offline/query-persistence.ts +323 -0
  122. package/src/offline/shared-computer-labels.ts +8 -0
  123. package/src/offline/shared-computer.tsx +87 -0
  124. package/src/offline/sign-out-pending-dialog-labels.ts +21 -0
  125. package/src/offline/sign-out-pending-dialog.tsx +135 -0
  126. package/src/offline.ts +26 -0
  127. package/src/shell/admin-menu.tsx +40 -3
  128. package/src/shell.ts +4 -0
  129. package/src/tour/tour-catalogue-labels.ts +2 -2
  130. package/src/tour/tour-catalogue.tsx +7 -1
  131. package/src/tour/tour-info.ts +2 -2
  132. package/src/tour/tour.tsx +87 -3
  133. package/src/tour/use-tour-progress.ts +501 -34
  134. package/src/tour.ts +5 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/tour/use-tour-progress.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useSyncExternalStore } from \"react\";\nimport { readStored, removeStored, writeStored } from \"../lib/safe-storage\";\nimport { isTourDone, type TourCompletions } from \"./tour-info\";\n\n/**\n * Which tours this device has completed (docs/tours-harmonization.md §2.6, §6.2) —\n * keksdose's `tour-progress-store` and kastlan's `completions.ts`, as one hook.\n *\n * - **Device storage, the app's key.** `storageKey` is always the app's: an app on shared\n * devices scopes it per account (KS, bench PCs), and an app that lists its keys\n * (KS `storage-keys.ts`) spells it there. Every access is guarded: a blocked or full\n * storage keeps the marks for this page's life instead of throwing.\n * - **One store, every reader.** A change notifies every hook on the same key in this tab\n * (an in-tab emitter) and in other tabs (the `storage` event), so the tours page and\n * `TourMenu` agree without a reload (ka F3).\n * - **`migrate(raw)`** reads an older shape, so nobody loses their done marks at adoption:\n * it gets the stored JSON (or the raw text, if it is no JSON) and returns the record for\n * a shape it recognises, `undefined` for any other — the kit's own shape included,\n * which it then reads itself. keksdose: zustand's `{state: {completed}, version: 1}`;\n * kastlan: an array of ids, completed without a date (`null`). It runs only on a stored\n * text that is not the kit's shape already, once per text and key, whichever reader\n * reads it first; its identity is ignored. **Define `migrate` once, at module level**,\n * and hand every reader of the key the same one: readers of one key share one snapshot.\n * - **Resetting the device** (settings §11): register the key with `reset: () =>\n * resetTourProgress(storageKey)`, which clears storage and the page's memory and tells\n * every reader in this tab.\n *\n * The kit's own shape is the record itself, `{ [id]: ISO | null }`; an empty string reads\n * as `null` (kastlan's record of 0.42).\n */\nexport interface UseTourProgressOptions {\n storageKey: string;\n migrate?: (raw: unknown) => Record<string, string | null> | undefined;\n}\n\nexport interface TourProgress {\n /** Tour id → the completion's ISO timestamp, or `null` when recorded without a date. */\n completed: TourCompletions;\n /**\n * Record a completion. Keeps the FIRST completion's date, so a replay changes nothing —\n * unless the tour was reset by an update since (§8): pass the tour (`{id, updated}`) and\n * a completion from before `updated.date` is replaced by today's.\n *\n * Returns `true` when this counts as a new completion — the moment to award the tour's\n * points and show the app's toast (§6.1) — and `false` for a replay.\n */\n complete: (tour: string | { id: string; updated?: { date: string } | null }) => boolean;\n /** \"Mark as not done\": forget the completion. */\n reset: (id: string) => void;\n}\n\n/* ── The store: one per key, shared by every hook ───────────────────────────── */\n\nconst EMPTY: TourCompletions = Object.freeze({});\n/** In-tab listeners per key. */\nconst listeners = new Map<string, Set<() => void>>();\n/** What this page wrote where storage refused to keep it (blocked, full): per key. */\nconst memory = new Map<string, string>();\n/**\n * The last raw text read per key and what it parsed to, so a snapshot keeps its identity:\n * the same text gives the same object, whichever reader asks and whatever `migrate` it\n * holds. Several readers of one key with inline `migrate` arrows used to evict each other\n * here and loop (kastlan B1, 0.43).\n */\nconst cache = new Map<string, { raw: string | null; value: TourCompletions }>();\n\nfunction emit(key: string) {\n listeners.get(key)?.forEach((listener) => listener());\n}\n\nfunction rawOf(key: string): string | null {\n return memory.get(key) ?? readStored(key);\n}\n\n/** Is this the kit's own shape already: a record whose every value is a string or null? */\nfunction isKitShape(value: unknown): boolean {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n return Object.values(value as Record<string, unknown>).every((at) => at === null || typeof at === \"string\");\n}\n\n/** The kit's own shape: a record of string or null; anything else is dropped. */\nfunction fromRecord(value: unknown): TourCompletions | undefined {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n const out: Record<string, string | null> = {};\n for (const [id, at] of Object.entries(value as Record<string, unknown>)) {\n if (at === null || at === \"\") out[id] = null;\n else if (typeof at === \"string\") out[id] = at;\n }\n return out;\n}\n\nfunction parse(raw: string | null, migrate: UseTourProgressOptions[\"migrate\"]): TourCompletions {\n if (raw === null) return EMPTY;\n let value: unknown = raw;\n try {\n value = JSON.parse(raw);\n } catch {\n // Not JSON: `migrate` still sees the text.\n }\n if (migrate && !isKitShape(value)) {\n try {\n const migrated = migrate(value);\n if (migrated !== undefined) return fromRecord(migrated) ?? EMPTY;\n } catch {\n // A migrate that throws reads as \"not a shape it knows\".\n }\n }\n return fromRecord(value) ?? EMPTY;\n}\n\nfunction snapshot(key: string, migrate: UseTourProgressOptions[\"migrate\"]): TourCompletions {\n const raw = rawOf(key);\n const hit = cache.get(key);\n if (hit && hit.raw === raw) return hit.value;\n const value = parse(raw, migrate);\n cache.set(key, { raw, value });\n return value;\n}\n\nfunction write(key: string, record: TourCompletions) {\n const raw = JSON.stringify(record);\n writeStored(key, raw);\n // Storage refused it (blocked, full): keep it for this page's life instead.\n if (readStored(key) === raw) memory.delete(key);\n else memory.set(key, raw);\n emit(key);\n}\n\nfunction subscribe(key: string, listener: () => void): () => void {\n let set = listeners.get(key);\n if (!set) listeners.set(key, (set = new Set()));\n set.add(listener);\n // Another tab wrote (or cleared all storage: `key` null).\n const onStorage = (event: StorageEvent) => {\n if (event.key !== null && event.key !== key) return;\n memory.delete(key);\n listener();\n };\n if (typeof window !== \"undefined\") window.addEventListener(\"storage\", onStorage);\n return () => {\n set.delete(listener);\n if (typeof window !== \"undefined\") window.removeEventListener(\"storage\", onStorage);\n };\n}\n\n/**\n * Forget every tour completion under `storageKey` on this device: the stored key, what the\n * page kept in memory where storage refused it, and every reader in this tab moves at\n * once. For \"Reset this device's settings\" (settings §11):\n *\n * registerDeviceSetting({ key: TOUR_KEY, kind: \"view\", reset: () => resetTourProgress(TOUR_KEY) });\n */\nexport function resetTourProgress(storageKey: string): void {\n removeStored(storageKey);\n memory.delete(storageKey);\n cache.delete(storageKey);\n emit(storageKey);\n}\n\n/** The device's tour completions under `storageKey`; see {@link UseTourProgressOptions}. */\nexport function useTourProgress({ storageKey, migrate }: UseTourProgressOptions): TourProgress {\n // Held, not depended on: an inline arrow is a new function every render, and neither the\n // snapshot nor the callbacks may change with it.\n const migrateRef = useRef(migrate);\n useEffect(() => {\n migrateRef.current = migrate;\n });\n const completed = useSyncExternalStore(\n useCallback((listener: () => void) => subscribe(storageKey, listener), [storageKey]),\n () => snapshot(storageKey, migrateRef.current),\n () => EMPTY,\n );\n\n const complete = useCallback(\n (tour: string | { id: string; updated?: { date: string } | null }) => {\n const subject = typeof tour === \"string\" ? { id: tour } : tour;\n // Read now rather than from the render: two completions in one handler both count.\n const current = snapshot(storageKey, migrateRef.current);\n if (isTourDone(subject, current[subject.id])) return false;\n write(storageKey, { ...current, [subject.id]: new Date().toISOString() });\n return true;\n },\n [storageKey],\n );\n\n const reset = useCallback(\n (id: string) => {\n const current = snapshot(storageKey, migrateRef.current);\n if (current[id] === undefined) return;\n const next = { ...current };\n delete next[id];\n write(storageKey, next);\n },\n [storageKey],\n );\n\n return useMemo(() => ({ completed, complete, reset }), [completed, complete, reset]);\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,SAAS,QAAQ,4BAA4B;AAC9E,SAAS,YAAY,cAAc,mBAAmB;AACtD,SAAS,kBAAwC;AAmDjD,MAAM,QAAyB,OAAO,OAAO,CAAC,CAAC;AAE/C,MAAM,YAAY,oBAAI,IAA6B;AAEnD,MAAM,SAAS,oBAAI,IAAoB;AAOvC,MAAM,QAAQ,oBAAI,IAA4D;AAE9E,SAAS,KAAK,KAAa;AACz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AAI;AAE1D,YAAM,UAAU,SAAS,YAAY,WAAW,OAAO;AACvD,UAAI,WAAW,SAAS,QAAQ,QAAQ,EAAE,CAAC,EAAG,QAAO;AACrD,YAAM,YAAY,EAAE,GAAG,SAAS,CAAC,QAAQ,EAAE,IAAG,oBAAI,KAAK,GAAE,YAAY,EAAE,CAAC;AACxE,aAAO;AAAA,IACT;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AAEA,QAAM,QAAQ;AAAA,IACZ,CAAC,OAAe;AACd,YAAM,UAAU,SAAS,YAAY,WAAW,OAAO;AACvD,UAAI,QAAQ,EAAE,MAAM,OAAW;AAC/B,YAAM,OAAO,EAAE,GAAG,QAAQ;AAC1B,aAAO,KAAK,EAAE;AACd,YAAM,YAAY,IAAI;AAAA,IACxB;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AAEA,SAAO,QAAQ,OAAO,EAAE,WAAW,UAAU,MAAM,IAAI,CAAC,WAAW,UAAU,KAAK,CAAC;AACrF;","names":[]}
1
+ {"version":3,"sources":["../../src/tour/use-tour-progress.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useSyncExternalStore } from \"react\";\nimport { readStored, removeStored, writeStored } from \"../lib/safe-storage\";\nimport { httpStatusOf } from \"../auth/auth-errors\";\nimport { isTourDone, type TourCompletions } from \"./tour-info\";\n\n/**\n * Which tours this device has completed (docs/tours-harmonization.md §2.6, §6.2) —\n * keksdose's `tour-progress-store` and kastlan's `completions.ts`, as one hook.\n *\n * - **Device storage, the app's key.** `storageKey` is always the app's: an app on shared\n * devices scopes it per account (KS, bench PCs), and an app that lists its keys\n * (KS `storage-keys.ts`) spells it there. Every access is guarded: a blocked or full\n * storage keeps the marks for this page's life instead of throwing.\n * - **One store, every reader.** A change notifies every hook on the same key in this tab\n * (an in-tab emitter) and in other tabs (the `storage` event), so the tours page and\n * `TourMenu` agree without a reload (ka F3).\n * - **`migrate(raw)`** reads an older shape, so nobody loses their done marks at adoption:\n * it gets the stored JSON (or the raw text, if it is no JSON) and returns the record for\n * a shape it recognises, `undefined` for any other — the kit's own shape included,\n * which it then reads itself. keksdose: zustand's `{state: {completed}, version: 1}`;\n * kastlan: an array of ids, completed without a date (`null`). It runs only on a stored\n * text that is not the kit's shape already, once per text and key. The FIRST `migrate`\n * any reader, `TourProvider` or {@link completeTour} passes for a key is remembered for\n * that key (later identities are ignored), so a reader without one, mounted first, no\n * longer hides the old marks from the rest (keksdose B-2). **Still, define the options\n * once, at module level, and hand the provider and every reader the same object.**\n * - **Never overwritten unread** (keksdose B-1): a write (`complete`, the provider's,\n * `completeTour`) on a stored text that is neither empty nor the kit's shape, and that no\n * known `migrate` reads, THROWS instead of replacing the old marks.\n * - **Resetting the device** (settings §11): register the key with `reset: () =>\n * resetTourProgress(storageKey)`, which clears storage and the page's memory and tells\n * every reader in this tab.\n *\n * **The stored shape** (§9.3, §9.6.6), for an app's tests and seeds: the JSON record\n * `{ [id]: ISO instant | \"\" }` under `storageKey`, where `\"\"` is a completion without a\n * date (a migrated record: kastlan's id list). That is the one written form; the hooks\n * and callbacks (`completed`, `TourCompletions`) give `null` for `\"\"`. A `null` read from\n * storage (or returned by `migrate`) is accepted as the same thing and written back as\n * `\"\"`. To write a completion from outside a page, use {@link completeTour}.\n *\n * **On the account** (0.45, §10.2–§10.3): with `account`, the device key becomes the\n * account's CACHE — see {@link TourProgressAccount}. Without it, nothing changes from 0.44.\n */\nexport interface UseTourProgressOptions {\n storageKey: string;\n migrate?: (raw: unknown) => Record<string, string | null> | undefined;\n /**\n * 0.45: the account's record behind the device key (§10.2.4). Remembered per key like\n * `migrate` (the FIRST one any reader or the provider passes wins). With it,\n * `storageKey` must be per account (a prefix plus the user id), so build the options per\n * account and keep ONE stable object per key — memoise them in a `Map` by user id — and\n * let `load`/`save` read the current token when they run, never capture one:\n *\n * const byUser = new Map<string, UseTourProgressOptions>();\n * function tourProgressFor(user: { id: string; isDemo: boolean } | null) {\n * if (!user || user.isDemo) return { storageKey: \"app.tours.completions\" }; // no account\n * let options = byUser.get(user.id);\n * if (!options) byUser.set(user.id, (options = { storageKey: `app.tours.completions:${user.id}`, account }));\n * return options;\n * }\n *\n * Signed out, and in a demo, pass none (and a fixed key): the device record works as in\n * 0.44, and a demo neither PATCHes into a 403 nor leaves an orphan key per demo id.\n */\n account?: TourProgressAccount;\n}\n\n/** The record on the wire (§10.2.2): tour id → ISO instant, or `\"\"` (done, no date). */\ntype TourProgressWire = Record<string, string>;\n\n/** The `PATCH /tours/progress` body (§10.2.2): what to mark done, and what to forget.\n * An id is never in both. Either may be left out. */\nexport interface TourProgressBody {\n completed?: TourProgressWire;\n forget?: string[];\n}\n\n/**\n * Taking over a device-wide record from before the account (§10.2.5), on the FIRST load\n * of the account key on this page:\n * - `{storageKey, discard: true}` (kastlan): removes the old key and uploads nothing — a\n * shared PC must not hand one person another's marks. Removing an absent key is a no-op.\n * - `{storageKey, migrate?}`: reads the old key once (through `migrate` for an older\n * shape), uploads it to the first account that signs in on this device, then removes it.\n */\nexport type TourProgressAdopt =\n | { storageKey: string; discard: true; migrate?: never }\n | { storageKey: string; discard?: false; migrate?: UseTourProgressOptions[\"migrate\"] };\n\n/**\n * The app's account record (§10.3): `load()` is its `GET /tours/progress`, `save(body)`\n * its `PATCH`, each resolving to the parsed answer, `{completed}` — the whole record.\n *\n * - The page paints from the device key at once (and offline); the account is loaded on\n * the first reader of the key on this page, on `online`, and after each save, and its\n * answer replaces the cache.\n * - A write (`complete`, the provider's finish, `reset`) goes to the cache at once and to\n * a PENDING record beside it, `<storageKey>:pending` (`{synced, completed, forget}`),\n * sent as one PATCH and cleared by its answer. A failure with no answer (offline, 5xx,\n * 401) keeps it for the next load or `online`; a 402 (a lapsed plan) keeps it but sends it\n * no more on this page (the next session or page load tries again); a 403 or 422 drops\n * it and logs.\n * - `awarded` stays the device's answer against the cache (§10.2.4).\n * - The pending record is NOT the app's outbox: leave it out of any \"N waiting\" count\n * and any sign-out guard (losing a tour mark is acceptable).\n * - A device record never synced (no `:pending` with `synced: true`) is uploaded whole on\n * its first load, by the server's merge rule (later completion wins).\n * - On every end of a session call {@link signOutTourProgress}.\n */\nexport interface TourProgressAccount {\n load: () => Promise<{ completed: TourProgressWire }>;\n save: (body: TourProgressBody) => Promise<{ completed: TourProgressWire }>;\n adopt?: TourProgressAdopt;\n}\n\n/** What `complete` takes: a tour id, or the tour (`{id, updated}`, a `TourInfo` fits). */\ntype CompletedTour = string | { id: string; updated?: { date: string } | null };\n\nexport interface TourProgress {\n /** Tour id → the completion's ISO timestamp, or `null` when recorded without a date. */\n completed: TourCompletions;\n /**\n * Record a completion. Keeps the FIRST completion's date, so a replay changes nothing —\n * unless the tour was reset by an update since (§8): pass the tour (`{id, updated}`) and\n * a completion from before `updated.date` is replaced by today's.\n *\n * Returns `true` when this counts as a new completion — the moment to award the tour's\n * points and show the app's toast (§6.1) — and `false` for a replay.\n *\n * A tour started with `start(steps, {tour})` under a `TourProvider` that has `progress`\n * is recorded by the provider (§9.6.2): do not call this from that start's `onFinish`\n * too, or the second write answers `false`.\n */\n complete: (tour: CompletedTour) => boolean;\n /** \"Mark as not done\": forget the completion. */\n reset: (id: string) => void;\n}\n\n/* ── The store: one per key, shared by every hook ───────────────────────────── */\n\nconst EMPTY: TourCompletions = Object.freeze({});\n/** In-tab listeners per key. */\nconst listeners = new Map<string, Set<() => void>>();\n/** What this page wrote where storage refused to keep it (blocked, full): per key. */\nconst memory = new Map<string, string>();\n/**\n * The last raw text read per key and what it parsed to, so a snapshot keeps its identity:\n * the same text gives the same object, whichever reader asks and whatever `migrate` it\n * holds. Several readers of one key with inline `migrate` arrows used to evict each other\n * here and loop (kastlan B1, 0.43).\n */\nconst cache = new Map<string, { raw: string | null; value: TourCompletions; readable: boolean }>();\ntype Migrate = NonNullable<UseTourProgressOptions[\"migrate\"]>;\n/** Each key's migrate: the first one any reader, the provider or `completeTour` passes (B-2). */\nconst migrates = new Map<string, Migrate>();\n\n/**\n * Remember `migrate` for `key` if it is the first one, and return the key's migrate. A\n * snapshot parsed before the key had one is dropped and re-parsed, and the key's readers\n * hear of it after this render (never from inside one).\n * @internal Not part of the barrel; `TourProvider` registers its `progress` with it.\n */\nexport function rememberMigrate(key: string, migrate: UseTourProgressOptions[\"migrate\"]): Migrate | undefined {\n if (migrate && !migrates.has(key)) {\n migrates.set(key, migrate);\n if (cache.delete(key)) queueMicrotask(() => emit(key));\n }\n return migrates.get(key);\n}\n\nfunction emit(key: string) {\n listeners.get(key)?.forEach((listener) => listener());\n}\n\nfunction rawOf(key: string): string | null {\n return memory.get(key) ?? readStored(key);\n}\n\n/** Is this the kit's own shape already: a record whose every value is a string or null? */\nfunction isKitShape(value: unknown): boolean {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n return Object.values(value as Record<string, unknown>).every((at) => at === null || typeof at === \"string\");\n}\n\n/** The kit's own shape: a record of string or null; anything else is dropped. */\nfunction fromRecord(value: unknown): TourCompletions | undefined {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n const out: Record<string, string | null> = {};\n for (const [id, at] of Object.entries(value as Record<string, unknown>)) {\n if (at === null || at === \"\") out[id] = null;\n else if (typeof at === \"string\") out[id] = at;\n }\n return out;\n}\n\n/**\n * The record, and whether the text was READ (empty, the kit's shape, or a shape `migrate`\n * knows) rather than dropped: a write over an unread text would lose it (B-1).\n */\nfunction parse(raw: string | null, migrate: UseTourProgressOptions[\"migrate\"]): { value: TourCompletions; readable: boolean } {\n if (raw === null || raw.trim() === \"\") return { value: EMPTY, readable: true };\n let value: unknown = raw;\n try {\n value = JSON.parse(raw);\n } catch {\n // Not JSON: `migrate` still sees the text.\n }\n if (migrate && !isKitShape(value)) {\n try {\n const migrated = fromRecord(migrate(value));\n if (migrated !== undefined) return { value: migrated, readable: true };\n } catch {\n // A migrate that throws reads as \"not a shape it knows\".\n }\n }\n return { value: fromRecord(value) ?? EMPTY, readable: isKitShape(value) };\n}\n\nfunction snapshot(key: string, migrate: UseTourProgressOptions[\"migrate\"]): TourCompletions {\n const known = rememberMigrate(key, migrate);\n const raw = rawOf(key);\n const hit = cache.get(key);\n if (hit && hit.raw === raw) return hit.value;\n const parsed = parse(raw, known);\n cache.set(key, { raw, ...parsed });\n return parsed.value;\n}\n\n/** The record a write builds on; throws rather than overwrite a text nobody could read (B-1). */\nfunction readForWrite(key: string, migrate: UseTourProgressOptions[\"migrate\"], own = false): TourCompletions {\n // `own`: this migrate, even where the key registered another (completeTour's `{migrate}`).\n const known = rememberMigrate(key, migrate);\n const { value, readable } =\n own && migrate && known !== migrate\n ? parse(rawOf(key), migrate)\n : { value: snapshot(key, migrate), readable: cache.get(key)?.readable };\n if (!readable) {\n throw new Error(\n `[ui-kit] tour progress: the text stored under \"${key}\" is not the kit's shape and no migrate reads it; ` +\n \"refusing to overwrite it. Pass the key's migrate (the shared useTourProgress / TourProvider options, \" +\n \"or completeTour's {migrate}).\",\n );\n }\n return value;\n}\n\n/** The one written form (§9.6.6): a completion without a date is stored as `\"\"`, never `null`. */\nfunction write(key: string, record: TourCompletions) {\n const stored: Record<string, string> = {};\n for (const [id, at] of Object.entries(record)) stored[id] = at ?? \"\";\n const raw = JSON.stringify(stored);\n writeStored(key, raw);\n // Storage refused it (blocked, full): keep it for this page's life instead.\n if (readStored(key) === raw) memory.delete(key);\n else memory.set(key, raw);\n emit(key);\n}\n\n/* ── The account behind the device key (0.45, §10.2.4–§10.2.8) ─────────────── */\n\n/** The key's account: the first one any reader or the provider passes (as `migrate`). */\nconst accounts = new Map<string, TourProgressAccount>();\n/** Keys whose account was loaded (or is loading) on this page: the first reader loads. */\nconst loaded = new Set<string>();\n/** Keys with a sync running, and those asked for another while it ran. */\nconst running = new Set<string>();\nconst rerun = new Set<string>();\n/** Keys with a sync queued for the end of this task: two writes in one handler, one PATCH. */\nconst queued = new Set<string>();\n/** Bumped by a sign-out: an answer that comes back after it never refills the cache. */\nconst epochs = new Map<string, number>();\n/** Keys whose PATCH got a 402 (a lapsed plan): the pending record is kept but not sent\n * again on this page; the next session (or page load) tries once more. */\nconst parked = new Set<string>();\n/** The pending record where storage refused to keep it. */\nconst pendingMemory = new Map<string, string>();\nlet onlineListening = false;\n\n/** The pending record (§10.2.4): what waits to be sent, and whether the device key was\n * ever synced. */\ninterface PendingRecord {\n synced: boolean;\n completed: TourProgressWire;\n forget: string[];\n}\n\nconst pendingKey = (key: string) => `${key}:pending`;\n\nfunction devWarn(message: string) {\n if (import.meta.env?.DEV) console.warn(message);\n}\n\n/**\n * Remember `account` for `key` if it is the first one, and return the key's account.\n * @internal Not part of the barrel; `TourProvider` registers its `progress` with it.\n */\nexport function rememberAccount(key: string, account: TourProgressAccount | undefined): TourProgressAccount | undefined {\n if (account && !accounts.has(key)) {\n accounts.set(key, account);\n if (account.adopt && account.adopt.storageKey === key) {\n devWarn(\n `[ui-kit] tour progress: the account key \"${key}\" is the key \\`adopt\\` takes over. ` +\n \"With an account the key must be per account (a prefix plus the user id), apart from the old device-wide key.\",\n );\n }\n if (!onlineListening && typeof window !== \"undefined\") {\n onlineListening = true;\n window.addEventListener(\"online\", () => {\n for (const known of loaded) void sync(known);\n });\n }\n }\n return accounts.get(key);\n}\n\nfunction readPending(key: string): PendingRecord | null {\n const raw = pendingMemory.get(key) ?? readStored(pendingKey(key));\n if (raw === null) return null;\n try {\n const value = JSON.parse(raw) as Partial<PendingRecord> | null;\n if (!value || typeof value !== \"object\") return null;\n const completed: TourProgressWire = {};\n for (const [id, at] of Object.entries(value.completed ?? {})) {\n if (typeof at === \"string\") completed[id] = at;\n else if (at === null) completed[id] = \"\";\n }\n const forget = Array.isArray(value.forget) ? value.forget.filter((id): id is string => typeof id === \"string\") : [];\n return { synced: value.synced === true, completed, forget };\n } catch {\n return null;\n }\n}\n\nfunction writePending(key: string, record: PendingRecord) {\n const raw = JSON.stringify(record);\n writeStored(pendingKey(key), raw);\n if (readStored(pendingKey(key)) === raw) pendingMemory.delete(key);\n else pendingMemory.set(key, raw);\n}\n\nconst hasWork = (record: PendingRecord) => Object.keys(record.completed).length > 0 || record.forget.length > 0;\n\n/** \"Later completion wins\" (§10.2.3), as the server merges: an instant beats `\"\"`, `\"\"`\n * beats nothing, and between two instants the later is kept. */\nfunction later(a: string | undefined, b: string): string {\n if (a === undefined || a === \"\") return b;\n if (b === \"\") return a;\n return Date.parse(b) > Date.parse(a) ? b : a;\n}\n\n/** Note a completion (or, with `forget`, its removal) in the key's pending record. */\nfunction markPending(key: string, id: string, at: string | null | undefined, forget = false) {\n const record = readPending(key) ?? { synced: false, completed: {}, forget: [] };\n if (forget) {\n delete record.completed[id];\n if (!record.forget.includes(id)) record.forget.push(id);\n } else {\n record.completed[id] = at ?? \"\";\n record.forget = record.forget.filter((other) => other !== id);\n }\n writePending(key, record);\n}\n\n/** After an answer (or a 403/422): take what was sent out of the pending record, keeping\n * what was written while the request ran. */\nfunction clearSent(key: string, sent: TourProgressBody, synced: boolean) {\n const record = readPending(key) ?? { synced: false, completed: {}, forget: [] };\n for (const [id, at] of Object.entries(sent.completed ?? {})) {\n if (record.completed[id] === at) delete record.completed[id];\n }\n const forgotten = new Set(sent.forget ?? []);\n record.forget = record.forget.filter((id) => !forgotten.has(id));\n record.synced = record.synced || synced;\n writePending(key, record);\n}\n\n/** The account's answer as the cache, with what still waits to be sent laid over it. */\nfunction refill(key: string, answer: { completed: TourProgressWire } | null | undefined) {\n const next: Record<string, string> = {};\n for (const [id, at] of Object.entries(fromRecord(answer?.completed) ?? {})) next[id] = at ?? \"\";\n const waiting = readPending(key);\n if (waiting) {\n for (const [id, at] of Object.entries(waiting.completed)) next[id] = later(next[id], at);\n for (const id of waiting.forget) delete next[id];\n }\n const record: Record<string, string | null> = {};\n for (const [id, at] of Object.entries(next)) record[id] = at === \"\" ? null : at;\n write(key, record);\n}\n\n/** The first load of an account key on this page takes over the old device-wide key\n * (§10.2.5). */\nfunction adoptOldRecord(key: string, account: TourProgressAccount) {\n const adopt = account.adopt;\n if (!adopt || adopt.storageKey === key) return;\n const old = adopt.storageKey;\n if (!adopt.discard) {\n const { value } = parse(rawOf(old), adopt.migrate ?? migrates.get(old));\n const entries = Object.entries(value);\n if (entries.length > 0) {\n const record = readPending(key) ?? { synced: false, completed: {}, forget: [] };\n for (const [id, at] of entries) record.completed[id] = later(record.completed[id], at ?? \"\");\n writePending(key, record);\n }\n }\n // Removed either way, at once: no second account on this device gets it.\n removeStored(old);\n memory.delete(old);\n cache.delete(old);\n emit(old);\n}\n\n/** A device record never synced is uploaded whole on its first load (§10.2.5). */\nfunction uploadUnsynced(key: string) {\n const record = readPending(key);\n if (record?.synced) return;\n const device = snapshot(key, migrates.get(key));\n const entries = Object.entries(device);\n const next = record ?? { synced: false, completed: {}, forget: [] };\n if (entries.length === 0 && record) return;\n for (const [id, at] of entries) {\n if (!next.forget.includes(id)) next.completed[id] = later(next.completed[id], at ?? \"\");\n }\n writePending(key, next);\n}\n\n/** The key's first sync on this page: take over the old record, upload a never-synced one. */\nfunction prepare(key: string) {\n loaded.add(key);\n adoptOldRecord(key, accounts.get(key)!);\n uploadUnsynced(key);\n}\n\n/** Queue a sync for the end of this task, so a handler's writes go as one PATCH. */\nfunction queueSync(key: string) {\n if (!loaded.has(key)) prepare(key);\n if (queued.has(key)) return;\n queued.add(key);\n queueMicrotask(() => {\n queued.delete(key);\n void sync(key);\n });\n}\n\n/** The first reader of an account key on this page loads it. */\nfunction ensureLoaded(key: string) {\n if (!accounts.has(key) || loaded.has(key)) return;\n prepare(key);\n void sync(key);\n}\n\n/**\n * Send what waits (one PATCH) or, with nothing waiting, load; the answer replaces the\n * cache. One at a time per key; a request asked for while one runs follows it.\n */\nasync function sync(key: string): Promise<void> {\n const account = accounts.get(key);\n if (!account || !loaded.has(key)) return;\n if (running.has(key)) {\n rerun.add(key);\n return;\n }\n if (typeof navigator !== \"undefined\" && navigator.onLine === false) return;\n running.add(key);\n const epoch = epochs.get(key) ?? 0;\n try {\n const waiting = readPending(key);\n if (waiting && hasWork(waiting)) {\n if (parked.has(key)) return;\n const body: TourProgressBody = {};\n if (Object.keys(waiting.completed).length > 0) body.completed = { ...waiting.completed };\n if (waiting.forget.length > 0) body.forget = [...waiting.forget];\n let answer: { completed: TourProgressWire };\n try {\n answer = await account.save(body);\n } catch (error) {\n const status = httpStatusOf(error);\n if (status === 403 || status === 422) {\n // Refused for good (a demo, a malformed or full record): dropped, not retried.\n if ((epochs.get(key) ?? 0) === epoch) clearSent(key, body, false);\n console.warn(`[ui-kit] tour progress: the account refused the pending record (${status}); dropped.`, error);\n } else if (status === 402) {\n // A lapsed plan refuses every write: kept, but not re-sent after each finish\n // and each `online` — the next session or page load tries again.\n parked.add(key);\n }\n // No answer (offline, 5xx, 401): it stays for the next load or `online`.\n return;\n }\n if ((epochs.get(key) ?? 0) !== epoch) return;\n clearSent(key, body, true);\n refill(key, answer);\n } else {\n const answer = await account.load();\n if ((epochs.get(key) ?? 0) !== epoch) return;\n if (waiting && !waiting.synced) writePending(key, { ...waiting, synced: true });\n else if (!waiting) writePending(key, { synced: true, completed: {}, forget: [] });\n refill(key, answer);\n }\n } catch {\n // A load that failed keeps the cache as it is.\n } finally {\n running.delete(key);\n if (rerun.delete(key)) void sync(key);\n }\n}\n\n/**\n * The end of a session (§10.2.6) — sign-out, a 401 nothing could renew, the account's\n * deletion, every path: removes the CACHE only (the device key and the page's snapshot;\n * every reader in this tab moves), synchronously and with no request, and KEEPS\n * `<storageKey>:pending`. That record sits under this person's own key, holds tour ids and\n * dates only, and goes out on their next sign-in. An answer still on its way is ignored.\n *\n * function logout() { …; signOutTourProgress(`app.tours:${user.id}`); }\n */\nexport function signOutTourProgress(storageKey: string): void {\n epochs.set(storageKey, (epochs.get(storageKey) ?? 0) + 1);\n loaded.delete(storageKey);\n rerun.delete(storageKey);\n parked.delete(storageKey);\n removeStored(storageKey);\n memory.delete(storageKey);\n cache.delete(storageKey);\n emit(storageKey);\n}\n\nfunction subscribe(key: string, listener: () => void): () => void {\n let set = listeners.get(key);\n if (!set) listeners.set(key, (set = new Set()));\n set.add(listener);\n // Another tab wrote (or cleared all storage: `key` null).\n const onStorage = (event: StorageEvent) => {\n if (event.key !== null && event.key !== key) return;\n memory.delete(key);\n listener();\n };\n if (typeof window !== \"undefined\") window.addEventListener(\"storage\", onStorage);\n return () => {\n set.delete(listener);\n if (typeof window !== \"undefined\") window.removeEventListener(\"storage\", onStorage);\n };\n}\n\n/**\n * Forget every tour completion under `storageKey` on this device: the stored key, what the\n * page kept in memory where storage refused it, and every reader in this tab moves at\n * once. For \"Reset this device's settings\" (settings §11):\n *\n * registerDeviceSetting({ key: TOUR_KEY, kind: \"view\", reset: () => resetTourProgress(TOUR_KEY) });\n *\n * With an account (0.45) it clears the cache only: the account is never written, the\n * pending record stays (\"anything waiting to be sent\", settings §11.2.2) and the next load\n * refills the cache. Tour progress is never registered with the device reset (§10.2.8).\n */\nexport function resetTourProgress(storageKey: string): void {\n if (accounts.has(storageKey)) loaded.delete(storageKey);\n removeStored(storageKey);\n memory.delete(storageKey);\n cache.delete(storageKey);\n emit(storageKey);\n}\n\n/**\n * Record a completion under `storageKey`, as {@link TourProgress.complete} does: through\n * the one shared store and snapshot (never a copy), so every reader of the key moves.\n * Returns `true` when it counts anew. `TourProvider` calls this on a tour's last step.\n * @internal Not part of the barrel.\n */\nexport function completeStored(\n storageKey: string,\n migrate: UseTourProgressOptions[\"migrate\"],\n tour: CompletedTour,\n): boolean {\n const subject = typeof tour === \"string\" ? { id: tour } : tour;\n // Read now rather than from a render: two completions in one handler both count.\n const current = readForWrite(storageKey, migrate);\n if (isTourDone(subject, current[subject.id])) return false;\n const at = new Date().toISOString();\n write(storageKey, { ...current, [subject.id]: at });\n if (accounts.has(storageKey)) {\n markPending(storageKey, subject.id, at);\n queueSync(storageKey);\n }\n return true;\n}\n\n/** \"Mark as not done\" (§10.2.8): off the cache, and `forget` to the account. @internal */\nfunction resetStored(storageKey: string, migrate: UseTourProgressOptions[\"migrate\"], id: string) {\n const current = snapshot(storageKey, migrate);\n if (current[id] === undefined) return;\n const next = { ...current };\n delete next[id];\n write(storageKey, next);\n if (accounts.has(storageKey)) {\n markPending(storageKey, id, undefined, true);\n queueSync(storageKey);\n }\n}\n\n/**\n * Write a completion from outside a page (§9.2): for an app's tests, seeds and scripts,\n * beside {@link resetTourProgress}. It writes the kit's stored shape (`{[id]: ISO | \"\"}`)\n * under `storageKey`, keeps the other tours' marks, and notifies every reader of the key\n * in this tab directly (the `storage` event reaches only OTHER tabs), so a mounted\n * `useTourProgress` or `TourCatalogue` moves at once.\n *\n * Unlike `complete`, it always writes (over a readable text; see below): `at` is the\n * completion's instant (an ISO string or a `Date`, default now), `null` a completion\n * without a date (stored as `\"\"`, read back as `null`).\n *\n * completeTour(TOUR_KEY, \"budget\", \"2026-09-01T10:00:00Z\");\n *\n * A stored text in an app's older shape is read through `opts.migrate`, or else the\n * migrate a reader or the provider registered for the key. If the text is neither empty\n * nor the kit's shape and no migrate reads it, this THROWS and writes nothing (B-1):\n *\n * completeTour(TOUR_KEY, \"budget\", undefined, { migrate: fromZustand });\n *\n * With an account on the key (0.45) it stays a device write — no request — and is marked\n * pending, so the next load sends it.\n */\nexport function completeTour(\n storageKey: string,\n tour: string | { id: string },\n at?: string | Date | null,\n opts?: { migrate?: UseTourProgressOptions[\"migrate\"] },\n): void {\n const id = typeof tour === \"string\" ? tour : tour.id;\n const when = at === null ? null : at instanceof Date ? at.toISOString() : (at ?? new Date().toISOString());\n write(storageKey, { ...readForWrite(storageKey, opts?.migrate, true), [id]: when });\n if (accounts.has(storageKey)) markPending(storageKey, id, when);\n}\n\n/** The device's tour completions under `storageKey`; see {@link UseTourProgressOptions}. */\nexport function useTourProgress({ storageKey, migrate, account }: UseTourProgressOptions): TourProgress {\n // Held, not depended on: an inline arrow is a new function every render, and neither the\n // snapshot nor the callbacks may change with it.\n const migrateRef = useRef(migrate);\n useEffect(() => {\n migrateRef.current = migrate;\n });\n // The first account for the key wins (as `migrate`); its first reader on the page loads.\n const accountRef = useRef(account);\n useEffect(() => {\n accountRef.current = account;\n });\n useEffect(() => {\n if (rememberAccount(storageKey, accountRef.current)) ensureLoaded(storageKey);\n }, [storageKey]);\n const completed = useSyncExternalStore(\n useCallback((listener: () => void) => subscribe(storageKey, listener), [storageKey]),\n () => snapshot(storageKey, migrateRef.current),\n () => EMPTY,\n );\n\n const complete = useCallback(\n (tour: CompletedTour) => completeStored(storageKey, migrateRef.current, tour),\n [storageKey],\n );\n\n const reset = useCallback((id: string) => resetStored(storageKey, migrateRef.current, id), [storageKey]);\n\n return useMemo(() => ({ completed, complete, reset }), [completed, complete, reset]);\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,SAAS,QAAQ,4BAA4B;AAC9E,SAAS,YAAY,cAAc,mBAAmB;AACtD,SAAS,oBAAoB;AAC7B,SAAS,kBAAwC;AAyIjD,MAAM,QAAyB,OAAO,OAAO,CAAC,CAAC;AAE/C,MAAM,YAAY,oBAAI,IAA6B;AAEnD,MAAM,SAAS,oBAAI,IAAoB;AAOvC,MAAM,QAAQ,oBAAI,IAA+E;AAGjG,MAAM,WAAW,oBAAI,IAAqB;AAQnC,SAAS,gBAAgB,KAAa,SAAiE;AAC5G,MAAI,WAAW,CAAC,SAAS,IAAI,GAAG,GAAG;AACjC,aAAS,IAAI,KAAK,OAAO;AACzB,QAAI,MAAM,OAAO,GAAG,EAAG,gBAAe,MAAM,KAAK,GAAG,CAAC;AAAA,EACvD;AACA,SAAO,SAAS,IAAI,GAAG;AACzB;AAEA,SAAS,KAAK,KAAa;AACzB,YAAU,IAAI,GAAG,GAAG,QAAQ,CAAC,aAAa,SAAS,CAAC;AACtD;AAEA,SAAS,MAAM,KAA4B;AACzC,SAAO,OAAO,IAAI,GAAG,KAAK,WAAW,GAAG;AAC1C;AAGA,SAAS,WAAW,OAAyB;AAC3C,MAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,EAAG,QAAO;AACxE,SAAO,OAAO,OAAO,KAAgC,EAAE,MAAM,CAAC,OAAO,OAAO,QAAQ,OAAO,OAAO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,QAAQ,OAAO,EAAE,WAAW,UAAU,MAAM,IAAI,CAAC,WAAW,UAAU,KAAK,CAAC;AACrF;","names":[]}
package/dist/tour.d.ts CHANGED
@@ -3,7 +3,9 @@ export { TourCatalogue, TourCatalogueCard, DEFAULT_TOUR_CATALOGUE_LABELS } from
3
3
  export type { TourCatalogueProps, TourCatalogueCardProps, TourCatalogueLabels } from "./tour/tour-catalogue.js";
4
4
  export { isTourNew, isTourReset, isTourDone, doneCount, earnedPoints } from "./tour/tour-info.js";
5
5
  export type { TourInfo, TourGroup, TourUpdate, TourCompletions } from "./tour/tour-info.js";
6
- export { useTourProgress, resetTourProgress } from "./tour/use-tour-progress.js";
6
+ export { useTourProgress, resetTourProgress, completeTour } from "./tour/use-tour-progress.js";
7
7
  export type { UseTourProgressOptions, TourProgress } from "./tour/use-tour-progress.js";
8
+ export { signOutTourProgress } from "./tour/use-tour-progress.js";
9
+ export type { TourProgressAccount, TourProgressAdopt, TourProgressBody } from "./tour/use-tour-progress.js";
8
10
  export { useTourUrlSync, useTourCatalogueUrlState } from "./tour/use-tour-url-sync.js";
9
11
  export type { UseTourUrlSyncOptions, TourCatalogueFilter, TourStateFilter } from "./tour/use-tour-url-sync.js";
package/dist/tour.js CHANGED
@@ -2,18 +2,21 @@
2
2
  export * from "./tour/tour.js";
3
3
  import { TourCatalogue, TourCatalogueCard, DEFAULT_TOUR_CATALOGUE_LABELS } from "./tour/tour-catalogue.js";
4
4
  import { isTourNew, isTourReset, isTourDone, doneCount, earnedPoints } from "./tour/tour-info.js";
5
- import { useTourProgress, resetTourProgress } from "./tour/use-tour-progress.js";
5
+ import { useTourProgress, resetTourProgress, completeTour } from "./tour/use-tour-progress.js";
6
+ import { signOutTourProgress } from "./tour/use-tour-progress.js";
6
7
  import { useTourUrlSync, useTourCatalogueUrlState } from "./tour/use-tour-url-sync.js";
7
8
  export {
8
9
  DEFAULT_TOUR_CATALOGUE_LABELS,
9
10
  TourCatalogue,
10
11
  TourCatalogueCard,
12
+ completeTour,
11
13
  doneCount,
12
14
  earnedPoints,
13
15
  isTourDone,
14
16
  isTourNew,
15
17
  isTourReset,
16
18
  resetTourProgress,
19
+ signOutTourProgress,
17
20
  useTourCatalogueUrlState,
18
21
  useTourProgress,
19
22
  useTourUrlSync
package/dist/tour.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/tour.ts"],"sourcesContent":["// `@eifi1/ui-kit/tour` — guided tours.\n// A re-slicing of the main barrel, not a new API.\nexport * from \"./tour/tour\";\n// 0.43.0: the tours page (docs/tours-harmonization.md §3, §8) — keksdose's catalogue, its\n// card, the NEW and reset rules, device progress and the URL. `useTourUrlSync` and\n// `useTourCatalogueUrlState` need react-router (a peer already, for /shell).\nexport { TourCatalogue, TourCatalogueCard, DEFAULT_TOUR_CATALOGUE_LABELS } from \"./tour/tour-catalogue\";\nexport type { TourCatalogueProps, TourCatalogueCardProps, TourCatalogueLabels } from \"./tour/tour-catalogue\";\nexport { isTourNew, isTourReset, isTourDone, doneCount, earnedPoints } from \"./tour/tour-info\";\nexport type { TourInfo, TourGroup, TourUpdate, TourCompletions } from \"./tour/tour-info\";\nexport { useTourProgress, resetTourProgress } from \"./tour/use-tour-progress\";\nexport type { UseTourProgressOptions, TourProgress } from \"./tour/use-tour-progress\";\nexport { useTourUrlSync, useTourCatalogueUrlState } from \"./tour/use-tour-url-sync\";\nexport type { UseTourUrlSyncOptions, TourCatalogueFilter, TourStateFilter } from \"./tour/use-tour-url-sync\";\n"],"mappings":";AAEA,cAAc;AAId,SAAS,eAAe,mBAAmB,qCAAqC;AAEhF,SAAS,WAAW,aAAa,YAAY,WAAW,oBAAoB;AAE5E,SAAS,iBAAiB,yBAAyB;AAEnD,SAAS,gBAAgB,gCAAgC;","names":[]}
1
+ {"version":3,"sources":["../src/tour.ts"],"sourcesContent":["// `@eifi1/ui-kit/tour` — guided tours.\n// A re-slicing of the main barrel, not a new API.\nexport * from \"./tour/tour\";\n// 0.43.0: the tours page (docs/tours-harmonization.md §3, §8) — keksdose's catalogue, its\n// card, the NEW and reset rules, device progress and the URL. `useTourUrlSync` and\n// `useTourCatalogueUrlState` need react-router (a peer already, for /shell).\nexport { TourCatalogue, TourCatalogueCard, DEFAULT_TOUR_CATALOGUE_LABELS } from \"./tour/tour-catalogue\";\nexport type { TourCatalogueProps, TourCatalogueCardProps, TourCatalogueLabels } from \"./tour/tour-catalogue\";\nexport { isTourNew, isTourReset, isTourDone, doneCount, earnedPoints } from \"./tour/tour-info\";\nexport type { TourInfo, TourGroup, TourUpdate, TourCompletions } from \"./tour/tour-info\";\n// 0.44.0: the writer outside a page (§9.2).\nexport { useTourProgress, resetTourProgress, completeTour } from \"./tour/use-tour-progress\";\nexport type { UseTourProgressOptions, TourProgress } from \"./tour/use-tour-progress\";\n// 0.45.0: progress on the account (§10.2–§10.3) and the end of a session.\nexport { signOutTourProgress } from \"./tour/use-tour-progress\";\nexport type { TourProgressAccount, TourProgressAdopt, TourProgressBody } from \"./tour/use-tour-progress\";\nexport { useTourUrlSync, useTourCatalogueUrlState } from \"./tour/use-tour-url-sync\";\nexport type { UseTourUrlSyncOptions, TourCatalogueFilter, TourStateFilter } from \"./tour/use-tour-url-sync\";\n"],"mappings":";AAEA,cAAc;AAId,SAAS,eAAe,mBAAmB,qCAAqC;AAEhF,SAAS,WAAW,aAAa,YAAY,WAAW,oBAAoB;AAG5E,SAAS,iBAAiB,mBAAmB,oBAAoB;AAGjE,SAAS,2BAA2B;AAEpC,SAAS,gBAAgB,gCAAgC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eifi1/ui-kit",
3
- "version": "0.43.0",
3
+ "version": "0.45.0",
4
4
  "type": "module",
5
5
  "description": "App-agnostic shared design system: domain-free React components, theme and tokens.",
6
6
  "_sideEffects": "The barrel (src/index.ts) re-exports EVERY component, including components/chart, which statically imports recharts. Without this field a bundler must assume each of those modules has side effects, so it cannot drop the unused ones: importing a Button from '@eifi1/ui-kit' dragged all 433KB of recharts into the consumer's ENTRY chunk, and Keksdose was preloading it on every page load, login included. Nothing in src/ imports for side effects (no bare imports, no CSS imports from JS, no module-level global writes) — the token stylesheet is its own './tokens.css' export — so this is safe. CSS is still listed so any future stylesheet survives. Re-checked when `flag-icons` left `dependencies` and tsup started emitting a `\"use client\"` banner: neither touches this. The flag stylesheet was never imported from JS in the first place (that was the finding), and a directive prologue is a string literal every bundler lifts out before it decides whether a module is inert.",
@@ -64,6 +64,10 @@
64
64
  "types": "./dist/rhf.d.ts",
65
65
  "import": "./dist/rhf.js"
66
66
  },
67
+ "./offline": {
68
+ "types": "./dist/offline.d.ts",
69
+ "import": "./dist/offline.js"
70
+ },
67
71
  "./i18n/*": {
68
72
  "types": "./dist/i18n/locales/*.d.ts",
69
73
  "import": "./dist/i18n/locales/*.js"
@@ -112,6 +116,10 @@
112
116
  "deps:outdated": "npm outdated || true"
113
117
  },
114
118
  "peerDependencies": {
119
+ "@tanstack/query-async-storage-persister": "^5",
120
+ "@tanstack/react-query": "^5",
121
+ "@tanstack/react-query-persist-client": "^5",
122
+ "idb-keyval": "^6",
115
123
  "lucide-react": ">=0.400.0 <2",
116
124
  "modern-screenshot": "^4.7.0",
117
125
  "react": ">=19.2",
@@ -122,6 +130,18 @@
122
130
  "sonner": ">=2"
123
131
  },
124
132
  "peerDependenciesMeta": {
133
+ "@tanstack/query-async-storage-persister": {
134
+ "optional": true
135
+ },
136
+ "@tanstack/react-query": {
137
+ "optional": true
138
+ },
139
+ "@tanstack/react-query-persist-client": {
140
+ "optional": true
141
+ },
142
+ "idb-keyval": {
143
+ "optional": true
144
+ },
125
145
  "modern-screenshot": {
126
146
  "optional": true
127
147
  },
@@ -141,6 +161,9 @@
141
161
  "devDependencies": {
142
162
  "@eslint/js": "^10.0.1",
143
163
  "@tailwindcss/vite": "^4.3.3",
164
+ "@tanstack/query-async-storage-persister": "^5.104.1",
165
+ "@tanstack/react-query": "^5.104.1",
166
+ "@tanstack/react-query-persist-client": "^5.104.1",
144
167
  "@testing-library/jest-dom": "^7.0.1",
145
168
  "@testing-library/react": "^16.3.0",
146
169
  "@testing-library/user-event": "^14.6.7",
@@ -159,6 +182,7 @@
159
182
  "flag-icons": "^7.5.0",
160
183
  "globals": "^17.12.0",
161
184
  "husky": "^9.1.7",
185
+ "idb-keyval": "^6.2.6",
162
186
  "jsdom": "^30.0.1",
163
187
  "lucide-react": "^1.47.0",
164
188
  "modern-screenshot": "^4.7.0",
@@ -33,11 +33,14 @@ export const DEFAULT_ADMIN_ACTION_LOG_LABELS: AdminActionLogLabels = {
33
33
  erase: "Account erased",
34
34
  plan: "Plan changed",
35
35
  },
36
+ renamedFromTo: (from, to) => `from ${from} to ${to}`,
36
37
  groupActions: {
37
38
  group: {
38
39
  group_create: "Group created",
39
40
  group_rename: "Group renamed",
40
41
  group_delete: "Group deleted",
42
+ group_deactivate: "Group deactivated",
43
+ group_reactivate: "Group reactivated",
41
44
  membership_add: "Added to the group",
42
45
  membership_role: "Role in the group changed",
43
46
  membership_remove: "Removed from the group",
@@ -47,6 +50,8 @@ export const DEFAULT_ADMIN_ACTION_LOG_LABELS: AdminActionLogLabels = {
47
50
  group_create: "Team created",
48
51
  group_rename: "Team renamed",
49
52
  group_delete: "Team deleted",
53
+ group_deactivate: "Team deactivated",
54
+ group_reactivate: "Team reactivated",
50
55
  membership_add: "Added to the team",
51
56
  membership_role: "Role in the team changed",
52
57
  membership_remove: "Removed from the team",
@@ -56,6 +61,8 @@ export const DEFAULT_ADMIN_ACTION_LOG_LABELS: AdminActionLogLabels = {
56
61
  group_create: "Company created",
57
62
  group_rename: "Company renamed",
58
63
  group_delete: "Company deleted",
64
+ group_deactivate: "Company deactivated",
65
+ group_reactivate: "Company reactivated",
59
66
  membership_add: "Added to the company",
60
67
  membership_role: "Role in the company changed",
61
68
  membership_remove: "Removed from the company",
@@ -65,6 +72,8 @@ export const DEFAULT_ADMIN_ACTION_LOG_LABELS: AdminActionLogLabels = {
65
72
  group_create: "Budget created",
66
73
  group_rename: "Budget renamed",
67
74
  group_delete: "Budget deleted",
75
+ group_deactivate: "Budget deactivated",
76
+ group_reactivate: "Budget reactivated",
68
77
  membership_add: "Added to the budget",
69
78
  membership_role: "Role in the budget changed",
70
79
  membership_remove: "Removed from the budget",
@@ -72,7 +72,11 @@ export type AdminActionKind =
72
72
  | "group_rename"
73
73
  | "group_delete"
74
74
  | "membership_add"
75
- | "membership_role";
75
+ | "membership_role"
76
+ // 0.45 (admin §9.1.3): a group switched off or on again — kastlan's company PATCH
77
+ // (`is_active`). server-kit 0.15's `AdminAction.GROUP_DEACTIVATE` / `GROUP_REACTIVATE`.
78
+ | "group_deactivate"
79
+ | "group_reactivate";
76
80
 
77
81
  /** Every {@link AdminActionKind}, in the contract's order. */
78
82
  export const ADMIN_ACTION_KINDS: readonly AdminActionKind[] = [
@@ -98,6 +102,8 @@ export const ADMIN_ACTION_KINDS: readonly AdminActionKind[] = [
98
102
  "group_delete",
99
103
  "membership_add",
100
104
  "membership_role",
105
+ "group_deactivate",
106
+ "group_reactivate",
101
107
  ];
102
108
 
103
109
  /** The app's word for its groups (§11.5): Kurvenschmiede's teams, kastlan's companies,
@@ -105,11 +111,14 @@ export const ADMIN_ACTION_KINDS: readonly AdminActionKind[] = [
105
111
  * actions are said in. */
106
112
  export type AdminGroupNoun = "group" | "team" | "company" | "budget";
107
113
 
108
- /** The kinds said in the noun's words: the five of 0.34, and `membership_remove`. */
114
+ /** The kinds said in the noun's words: the five of 0.34, `membership_remove`, and 0.45's
115
+ * `group_deactivate` / `group_reactivate`. */
109
116
  type AdminGroupActionKind =
110
117
  | "group_create"
111
118
  | "group_rename"
112
119
  | "group_delete"
120
+ | "group_deactivate"
121
+ | "group_reactivate"
113
122
  | "membership_add"
114
123
  | "membership_role"
115
124
  | "membership_remove";
@@ -118,6 +127,8 @@ const GROUP_ACTION_KINDS: ReadonlySet<string> = new Set<AdminGroupActionKind>([
118
127
  "group_create",
119
128
  "group_rename",
120
129
  "group_delete",
130
+ "group_deactivate",
131
+ "group_reactivate",
121
132
  "membership_add",
122
133
  "membership_role",
123
134
  "membership_remove",
@@ -184,6 +195,13 @@ export interface AdminActionLogEntry {
184
195
  group?: AdminGroupTarget | null;
185
196
  /** The `detail` in the app's words — "Member → Admin", "12 items to Ben Example". */
186
197
  detail?: ReactNode;
198
+ /**
199
+ * 0.45 (admin §9.4, Marcel 2026-10-19): a `group_rename` row's `detail.{from, to}` —
200
+ * kastlan's company rename logs both names. With both, the row reads "Company renamed
201
+ * from A to B" (`renamedFromTo`) in place of the target. A rename that logs `{}` (KS's
202
+ * team rename: never a name) leaves it out and reads "Team renamed" and the group.
203
+ */
204
+ renamed?: { from?: string | null; to?: string | null } | null;
187
205
  }
188
206
 
189
207
  /** The `adminActionLog` namespace. */
@@ -206,6 +224,8 @@ export interface AdminActionLogLabels {
206
224
  showAll: string;
207
225
  /** A target name as a filter button — "Show only the actions on Ada Example". */
208
226
  filterBy: (target: string) => string;
227
+ /** 0.45: after "Company renamed" when the row carries both names — "from A to B". */
228
+ renamedFromTo: (from: string, to: string) => string;
209
229
  /** What each action is called, past tense, keyed by the vocabulary. An app adds its
210
230
  * own here (`labels={{ actions: { plan: "Plan changed" } }}`). A word given here
211
231
  * outranks the noun's in `groupActions` — so no catalogue holds the group kinds
@@ -223,6 +243,11 @@ interface AdminGroupActionLabels {
223
243
  group_rename: string;
224
244
  /** "Team deleted". */
225
245
  group_delete: string;
246
+ /** "Company deactivated" (0.45, admin §9.1.3): the group switched off — its people
247
+ * locked out — not a person's `deactivate`. */
248
+ group_deactivate: string;
249
+ /** "Company reactivated" (0.45). */
250
+ group_reactivate: string;
226
251
  /** "Added to the team" — said of the person, so it agrees with the account where a
227
252
  * language agrees (es "Añadida", fr "Ajouté"). */
228
253
  membership_add: string;
@@ -384,12 +409,22 @@ export function AdminActionLog({
384
409
  aria-busy={loading || undefined}
385
410
  className={cn("divide-y divide-subtle", loading && "opacity-60")}
386
411
  >
387
- {entries.map((entry) => (
412
+ {entries.map((entry) => {
413
+ const from = (entry.renamed?.from ?? "").trim();
414
+ const to = (entry.renamed?.to ?? "").trim();
415
+ const renamed = entry.action === "group_rename" && from !== "" && to !== "";
416
+ return (
388
417
  <li key={entry.id} data-action={entry.action} className="space-y-0.5 py-2 first:pt-0 last:pb-0">
389
418
  <div className="flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5">
390
419
  <div className="flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5 text-sm">
391
420
  <span className="font-medium text-primary">{actionText(entry.action)}</span>
392
- {entry.target !== undefined && <span className="min-w-0 break-words">{targetNode(entry)}</span>}
421
+ {renamed ? (
422
+ <span data-private data-renamed className="min-w-0 break-words text-primary">
423
+ {labels.renamedFromTo(from, to)}
424
+ </span>
425
+ ) : (
426
+ entry.target !== undefined && <span className="min-w-0 break-words">{targetNode(entry)}</span>
427
+ )}
393
428
  {entry.group && (
394
429
  <span data-group className="min-w-0 break-words text-xs text-muted">
395
430
  {groupText(entry.group)}
@@ -410,7 +445,8 @@ export function AdminActionLog({
410
445
  )}
411
446
  </div>
412
447
  </li>
413
- ))}
448
+ );
449
+ })}
414
450
  </ol>
415
451
  )}
416
452
  {paging && paging.total > 0 && (
@@ -32,6 +32,12 @@ export interface AdminAreaLabels {
32
32
  /** The row's waiting count, for a reader ("Administration, 3 waiting"); the eye sees
33
33
  * the number in the badge. */
34
34
  waiting: (count: number) => string;
35
+ /**
36
+ * 0.45 (admin §9.3.4): a button's whole name with its count — "Platform, 2 waiting" —
37
+ * for an `IconButton` whose `badge` is an `AdminWaitingBadge`: the badge is decorative
38
+ * there, so the name carries the count. `label` is the button's own name.
39
+ */
40
+ waitingLabel: (label: string, count: number) => string;
35
41
  /** The 403 page's heading (§2.2 decision 8). */
36
42
  forbiddenTitle: string;
37
43
  /**
@@ -59,6 +65,7 @@ export interface AdminAreaLabels {
59
65
  export const DEFAULT_ADMIN_AREA_LABELS: AdminAreaLabels = {
60
66
  title: "Administration",
61
67
  waiting: (count) => `${count} waiting`,
68
+ waitingLabel: (label, count) => `${label}, ${count} waiting`,
62
69
  forbiddenTitle: "Only for administrators",
63
70
  forbiddenBody: (appName) => `This is where administrators run ${appName}. Your account cannot open this page.`,
64
71
  forbiddenHome: "Go to the start page",
@@ -0,0 +1,19 @@
1
+ // The English words of ./mail-test-card, in a module with no component code: the English
2
+ // catalogue (src/i18n/defaults.ts) imports them without the component, so `en` loads as one
3
+ // chunk like the other languages (0.34, KS U8). ./mail-test-card re-exports them.
4
+
5
+ import { englishRateLimited } from "../auth/auth-errors";
6
+ import type { MailTestCardLabels } from "./mail-test-card";
7
+
8
+ /** docs/admin-harmonization.md §9.2.4, word for word. */
9
+ export const DEFAULT_MAIL_TEST_CARD_LABELS: MailTestCardLabels = {
10
+ title: "Test mail",
11
+ description: "Sends one mail to your own address, through the transport this installation sends all its mail with.",
12
+ transport: (backend) => `Transport: ${backend}`,
13
+ action: "Send a test mail to me",
14
+ sent: (address) => `Sent to ${address}. Check the inbox.`,
15
+ console: "The console transport only logs mail; nothing was sent.",
16
+ failed: "Could not send. The server log has the provider’s answer.",
17
+ rateLimited: englishRateLimited,
18
+ keywords: "test mail email e-mail transport smtp resend console send deliver",
19
+ };
@@ -0,0 +1,186 @@
1
+ import { useState } from "react";
2
+ import type { ReactNode } from "react";
3
+ import { Send } from "lucide-react";
4
+
5
+ import { useKitLabels, type LabelOverride } from "../i18n/kit-labels";
6
+ import { isRateLimited, retryAfterSeconds } from "../auth/auth-errors";
7
+ import { AlertBanner } from "../components/alert-banner";
8
+ import { Button } from "../components/button";
9
+ import { Chip } from "../components/chip";
10
+ import { SettingsSection, type SettingsSectionProps } from "../settings/settings-section";
11
+ import { DEFAULT_MAIL_TEST_CARD_LABELS } from "./mail-test-card-labels";
12
+
13
+ /* ── Labels ──────────────────────────────────────────────────────────────── */
14
+
15
+ /** Every string {@link MailTestCard} renders — the `mailTestCard` namespace of
16
+ * `<UiKitProvider labels>`, overridable per instance through `labels`
17
+ * (docs/admin-harmonization.md §9.2.4). */
18
+ export interface MailTestCardLabels {
19
+ /** The card's title, and the app's catalogue entry's. */
20
+ title: string;
21
+ /** The sentence under it. */
22
+ description: string;
23
+ /** The transport's chip: "Transport: resend". `backend` is the server's `mail_backend`. */
24
+ transport: (backend: string) => string;
25
+ /** The button. */
26
+ action: string;
27
+ /** The answer said "sent" through a real transport. `address` is masked ("a…@example.com"). */
28
+ sent: (address: string) => string;
29
+ /** `mail_backend` is `console`: said whatever `sent` is — a console answers `true`. */
30
+ console: string;
31
+ /** Not sent, or the request failed. The provider's error stays in the server log. */
32
+ failed: string;
33
+ /** HTTP 429 — the app's limiter (server-kit's `MAIL_TEST_LIMIT`, 3 per 10 minutes);
34
+ * `seconds` from `Retry-After` when the response has one. */
35
+ rateLimited: (seconds?: number) => string;
36
+ /** For the app's catalogue entry (`keywords`); the card never reads it. */
37
+ keywords: string;
38
+ }
39
+
40
+ // Defined in ./mail-test-card-labels, which holds no component code.
41
+ export { DEFAULT_MAIL_TEST_CARD_LABELS };
42
+
43
+ /* ── The card ────────────────────────────────────────────────────────────── */
44
+
45
+ /** The answer of `POST /admin/mail/test` — server-kit 0.15's `MailTestResult`. */
46
+ export interface MailTestAnswer {
47
+ sent: boolean;
48
+ /** The transport that took it: `console`, `resend`, `smtp`, … */
49
+ mail_backend: string;
50
+ }
51
+
52
+ /** The card's default DOM id: its catalogue entry's `anchor`, the `?focus=` target. */
53
+ export const MAIL_TEST_ANCHOR = "admin-mail-test";
54
+
55
+ export interface MailTestCardProps
56
+ extends Omit<SettingsSectionProps, "anchor" | "title" | "description" | "children"> {
57
+ /** The installation's transport, as the admin page has it (`mail_backend`): the chip
58
+ * before a send. After one, the answer's. */
59
+ mailBackend: string;
60
+ /** The app's `POST /admin/mail/test` (kastlan `/platform/mail/test`), no body: it
61
+ * awaits the app's own send and answers `{sent, mail_backend}`. A rejection is read
62
+ * for a 429 (the limiter); anything else is "could not send". */
63
+ send: () => Promise<MailTestAnswer>;
64
+ /** The signed-in admin's own address — where the mail goes. Shown masked. */
65
+ address: string;
66
+ /** Default {@link MAIL_TEST_ANCHOR}; the app's catalogue entry names the same. */
67
+ anchor?: string;
68
+ /** The app's sentence after the kit's description. */
69
+ description?: ReactNode;
70
+ labels?: LabelOverride<MailTestCardLabels>;
71
+ }
72
+
73
+ /**
74
+ * An address with its local part masked to its first character: "ada@example.com" →
75
+ * "a…@example.com". The domain stays, so the admin sees which mailbox to open.
76
+ */
77
+ export function maskMailAddress(address: string): string {
78
+ const text = address.trim();
79
+ const at = text.lastIndexOf("@");
80
+ if (at <= 0) return text === "" ? "" : `${Array.from(text)[0]}…`;
81
+ return `${Array.from(text.slice(0, at))[0]}…${text.slice(at)}`;
82
+ }
83
+
84
+ type Outcome =
85
+ | { kind: "sent"; backend: string }
86
+ | { kind: "console"; backend: string }
87
+ | { kind: "failed"; backend?: string }
88
+ | { kind: "limited"; seconds?: number };
89
+
90
+ /**
91
+ * "Send a test mail to me" (docs/admin-harmonization.md §9.2): a `SettingsSection` with a
92
+ * sentence, the transport as a chip, the button and the result line. One mail goes to the
93
+ * signed-in admin's own address, never another, through the app's own send.
94
+ *
95
+ * **The result line reads `mail_backend` first**: with `console` it says "nothing was sent"
96
+ * whatever `sent` is, since every console path answers `true` (§9.2 Today). Otherwise
97
+ * `sent` says "Sent to a…@example.com. Check the inbox." or "Could not send." — the
98
+ * provider's error stays in the server log (§9.2.7). A 429 says the limiter's line. The
99
+ * button is busy while the request runs; the line is a live region.
100
+ *
101
+ * Not a commit: the test writes nothing, so it is not under the write lock (a demo never
102
+ * reaches the admin area, and the server refuses it anyway). The app adds the catalogue
103
+ * entry `{ id, anchor: MAIL_TEST_ANCHOR, title, keywords }` from these labels.
104
+ */
105
+ export function MailTestCard({
106
+ mailBackend,
107
+ send,
108
+ address,
109
+ anchor = MAIL_TEST_ANCHOR,
110
+ description,
111
+ labels: labelsProp,
112
+ ...rest
113
+ }: MailTestCardProps) {
114
+ const labels = useKitLabels("mailTestCard", DEFAULT_MAIL_TEST_CARD_LABELS, labelsProp);
115
+ const [busy, setBusy] = useState(false);
116
+ const [outcome, setOutcome] = useState<Outcome | null>(null);
117
+
118
+ const run = async () => {
119
+ if (busy) return;
120
+ setBusy(true);
121
+ setOutcome(null);
122
+ try {
123
+ const answer = await send();
124
+ const backend = answer.mail_backend;
125
+ if (backend === "console") setOutcome({ kind: "console", backend });
126
+ else setOutcome(answer.sent ? { kind: "sent", backend } : { kind: "failed", backend });
127
+ } catch (error) {
128
+ setOutcome(isRateLimited(error) ? { kind: "limited", seconds: retryAfterSeconds(error) } : { kind: "failed" });
129
+ } finally {
130
+ setBusy(false);
131
+ }
132
+ };
133
+
134
+ const backend = outcome && "backend" in outcome && outcome.backend ? outcome.backend : mailBackend;
135
+
136
+ return (
137
+ <SettingsSection
138
+ {...rest}
139
+ anchor={anchor}
140
+ title={labels.title}
141
+ description={
142
+ description != null ? (
143
+ <>
144
+ {labels.description} {description}
145
+ </>
146
+ ) : (
147
+ labels.description
148
+ )
149
+ }
150
+ >
151
+ <div className="space-y-2">
152
+ <div className="flex flex-wrap items-center gap-2">
153
+ <Button variant="secondary" pending={busy} onClick={() => void run()}>
154
+ <Send className="size-4" aria-hidden />
155
+ {labels.action}
156
+ </Button>
157
+ {backend && (
158
+ <Chip size="sm" data-slot="mail-backend">
159
+ {labels.transport(backend)}
160
+ </Chip>
161
+ )}
162
+ </div>
163
+ {outcome?.kind === "sent" && (
164
+ <AlertBanner variant="inline" block tone="success">
165
+ <span data-private>{labels.sent(maskMailAddress(address))}</span>
166
+ </AlertBanner>
167
+ )}
168
+ {outcome?.kind === "console" && (
169
+ <AlertBanner variant="inline" block tone="info">
170
+ {labels.console}
171
+ </AlertBanner>
172
+ )}
173
+ {outcome?.kind === "failed" && (
174
+ <AlertBanner variant="inline" block tone="danger">
175
+ {labels.failed}
176
+ </AlertBanner>
177
+ )}
178
+ {outcome?.kind === "limited" && (
179
+ <AlertBanner variant="inline" block tone="warning">
180
+ {labels.rateLimited(outcome.seconds)}
181
+ </AlertBanner>
182
+ )}
183
+ </div>
184
+ </SettingsSection>
185
+ );
186
+ }
@@ -39,6 +39,15 @@ export interface OpenProviderPageOptions {
39
39
  * />
40
40
  *
41
41
  * Resolves with the way it went.
42
+ *
43
+ * **The test seam is `options.window`** (docs/tours-harmonization.md §9.5, kk 7): an app's
44
+ * test passes a stub with `open` (returning a fake tab, or `null` for a blocked pop-up)
45
+ * and `location.assign`, instead of patching the global `window`:
46
+ *
47
+ * const tab = { opener: {}, closed: false, location: { href: "" }, close: vi.fn() };
48
+ * const win = { open: vi.fn(() => tab), location: { assign: vi.fn() } } as unknown as Window;
49
+ * await openProviderPage(async () => "https://pay.example/portal", { window: win });
50
+ * expect(tab.location.href).toBe("https://pay.example/portal");
42
51
  */
43
52
  export async function openProviderPage(
44
53
  fetchUrl: () => Promise<string>,