@cosmicdrift/kumiko-bundled-features 0.405.0 → 0.409.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 (337) hide show
  1. package/dist/account-security/feature.js +9 -1
  2. package/dist/admin-shell/feature.d.ts +3 -0
  3. package/dist/admin-shell/feature.js +1 -1
  4. package/dist/agent-tools/agent-manifest.js +1 -0
  5. package/dist/agent-tools/tool-catalog.js +1 -0
  6. package/dist/agent-tools/types.d.ts +4 -1
  7. package/dist/audit/event-classification.js +1 -0
  8. package/dist/auth-email-password/bootstrap.js +1 -0
  9. package/dist/auth-email-password/errors.js +16 -41
  10. package/dist/auth-email-password/web/auth-client.d.ts +8 -32
  11. package/dist/auth-email-password/web/auth-client.js +18 -52
  12. package/dist/auth-email-password/web/auth-redirect.js +2 -2
  13. package/dist/auth-email-password/web/confirm-account-unlock-screen.d.ts +2 -2
  14. package/dist/auth-email-password/web/confirm-account-unlock-screen.js +14 -35
  15. package/dist/auth-email-password/web/index.d.ts +1 -0
  16. package/dist/auth-email-password/web/index.js +1 -0
  17. package/dist/auth-email-password/web/read-path-param.d.ts +1 -0
  18. package/dist/auth-email-password/web/read-path-param.js +4 -0
  19. package/dist/auth-email-password/web/return-path.js +2 -2
  20. package/dist/auth-email-password/web/token-confirm-screen.d.ts +20 -0
  21. package/dist/auth-email-password/web/token-confirm-screen.js +38 -0
  22. package/dist/auth-email-password/web/verify-email-screen.d.ts +2 -2
  23. package/dist/auth-email-password/web/verify-email-screen.js +14 -37
  24. package/dist/auth-foundation/boot-checks.js +24 -12
  25. package/dist/auth-foundation/boot-rules.d.ts +27 -0
  26. package/dist/auth-foundation/boot-rules.js +27 -0
  27. package/dist/auth-mfa/errors.d.ts +1 -1
  28. package/dist/auth-mfa/errors.js +11 -24
  29. package/dist/auth-mfa/feature-exports.js +6 -45
  30. package/dist/auth-mfa/feature.js +7 -18
  31. package/dist/auth-mfa/web/mfa-client.js +11 -25
  32. package/dist/billing-foundation/consumer-protection/termination-notify.js +1 -0
  33. package/dist/billing-foundation/web/plan-price.js +7 -8
  34. package/dist/cap-counter/stock-cap-guard.js +1 -0
  35. package/dist/channel-in-app/constants.d.ts +1 -0
  36. package/dist/channel-in-app/feature.js +2 -0
  37. package/dist/channel-in-app/handlers/read-state-by-keys.query.d.ts +9 -0
  38. package/dist/channel-in-app/handlers/read-state-by-keys.query.js +21 -0
  39. package/dist/channel-in-app/in-app-channel.js +1 -0
  40. package/dist/channel-in-app/tables.js +5 -1
  41. package/dist/contact/challenge.d.ts +14 -0
  42. package/dist/contact/challenge.js +30 -0
  43. package/dist/contact/client/contact-client-source.d.ts +1 -0
  44. package/dist/contact/client/contact-client-source.js +203 -0
  45. package/dist/contact/entity.d.ts +777 -0
  46. package/dist/contact/entity.js +145 -0
  47. package/dist/contact/feature.d.ts +3 -0
  48. package/dist/contact/feature.js +130 -0
  49. package/dist/contact/handlers/access.d.ts +7 -0
  50. package/dist/contact/handlers/access.js +9 -0
  51. package/dist/contact/handlers/attempts.d.ts +14 -0
  52. package/dist/contact/handlers/attempts.js +54 -0
  53. package/dist/contact/handlers/challenge.query.d.ts +9 -0
  54. package/dist/contact/handlers/challenge.query.js +35 -0
  55. package/dist/contact/handlers/forward-request.write.d.ts +9 -0
  56. package/dist/contact/handlers/forward-request.write.js +61 -0
  57. package/dist/contact/handlers/mark-done.write.d.ts +7 -0
  58. package/dist/contact/handlers/mark-done.write.js +30 -0
  59. package/dist/contact/handlers/notify-reporter-in-app.write.d.ts +10 -0
  60. package/dist/contact/handlers/notify-reporter-in-app.write.js +36 -0
  61. package/dist/contact/handlers/open-count.d.ts +2 -0
  62. package/dist/contact/handlers/open-count.js +11 -0
  63. package/dist/contact/handlers/open-count.query.d.ts +3 -0
  64. package/dist/contact/handlers/open-count.query.js +13 -0
  65. package/dist/contact/handlers/replies.query.d.ts +11 -0
  66. package/dist/contact/handlers/replies.query.js +28 -0
  67. package/dist/contact/handlers/reply.write.d.ts +12 -0
  68. package/dist/contact/handlers/reply.write.js +118 -0
  69. package/dist/contact/handlers/report.write.d.ts +16 -0
  70. package/dist/contact/handlers/report.write.js +90 -0
  71. package/dist/contact/handlers/request-delivery.query.d.ts +16 -0
  72. package/dist/contact/handlers/request-delivery.query.js +85 -0
  73. package/dist/contact/handlers/request-detail.query.d.ts +41 -0
  74. package/dist/contact/handlers/request-detail.query.js +32 -0
  75. package/dist/contact/handlers/request-list.query.d.ts +2 -0
  76. package/dist/contact/handlers/request-list.query.js +9 -0
  77. package/dist/contact/handlers/send-reply-mail.write.d.ts +8 -0
  78. package/dist/contact/handlers/send-reply-mail.write.js +82 -0
  79. package/dist/contact/handlers/send-test.write.d.ts +5 -0
  80. package/dist/contact/handlers/send-test.write.js +36 -0
  81. package/dist/contact/handlers/submit.write.d.ts +20 -0
  82. package/dist/contact/handlers/submit.write.js +137 -0
  83. package/dist/contact/handlers/take-over-uploads.d.ts +9 -0
  84. package/dist/contact/handlers/take-over-uploads.js +33 -0
  85. package/dist/contact/i18n.d.ts +6 -0
  86. package/dist/contact/i18n.js +186 -0
  87. package/dist/contact/index.d.ts +5 -0
  88. package/dist/contact/index.js +4 -0
  89. package/dist/contact/lib.d.ts +101 -0
  90. package/dist/contact/lib.js +109 -0
  91. package/dist/contact/mail.d.ts +91 -0
  92. package/dist/contact/mail.js +279 -0
  93. package/dist/contact/options.d.ts +51 -0
  94. package/dist/contact/options.js +32 -0
  95. package/dist/contact/panels.d.ts +2 -0
  96. package/dist/contact/panels.js +21 -0
  97. package/dist/contact/payloads.d.ts +56 -0
  98. package/dist/contact/payloads.js +82 -0
  99. package/dist/contact/pow.d.ts +6 -0
  100. package/dist/contact/pow.js +19 -0
  101. package/dist/contact/screens.d.ts +5 -0
  102. package/dist/contact/screens.js +464 -0
  103. package/dist/contact/subject.d.ts +1 -0
  104. package/dist/contact/subject.js +13 -0
  105. package/dist/contact/user-agent.d.ts +1 -0
  106. package/dist/contact/user-agent.js +35 -0
  107. package/dist/contact/user-data-hooks.d.ts +3 -0
  108. package/dist/contact/user-data-hooks.js +129 -0
  109. package/dist/contact/web/constants.d.ts +127 -0
  110. package/dist/contact/web/constants.js +126 -0
  111. package/dist/contact/web/index.d.ts +1 -0
  112. package/dist/contact/web/index.js +1 -0
  113. package/dist/crypto-shredding/handlers/forget-subject.write.js +5 -13
  114. package/dist/data-retention/feature.js +16 -2
  115. package/dist/data-retention/index.d.ts +1 -0
  116. package/dist/data-retention/index.js +1 -0
  117. package/dist/data-retention/run-retention-cleanup.d.ts +14 -2
  118. package/dist/data-retention/run-retention-cleanup.js +102 -36
  119. package/dist/data-retention/tenant-destruction-hold.d.ts +23 -0
  120. package/dist/data-retention/tenant-destruction-hold.js +132 -0
  121. package/dist/delivery/address-opt-out.js +1 -0
  122. package/dist/delivery/channel-context.d.ts +1 -1
  123. package/dist/delivery/channel-context.js +2 -1
  124. package/dist/delivery/delivery-service.js +18 -8
  125. package/dist/delivery/events.d.ts +1 -0
  126. package/dist/delivery/events.js +2 -0
  127. package/dist/delivery/feature.js +3 -0
  128. package/dist/delivery/handlers/attempts-by-keys.query.d.ts +15 -0
  129. package/dist/delivery/handlers/attempts-by-keys.query.js +35 -0
  130. package/dist/delivery/handlers/log.query.d.ts +1 -0
  131. package/dist/delivery/handlers/log.query.js +1 -1
  132. package/dist/delivery/jobs.js +5 -2
  133. package/dist/delivery/tables.js +12 -2
  134. package/dist/delivery/types.d.ts +2 -0
  135. package/dist/delivery/unsubscribe-page.js +2 -0
  136. package/dist/delivery/web/delivery-channel-cell.js +1 -1
  137. package/dist/delivery/web/delivery-error-cell.js +1 -1
  138. package/dist/delivery/web/delivery-status-cell.js +1 -1
  139. package/dist/delivery/web/delivery-time-cell.js +3 -2
  140. package/dist/delivery/web/delivery-type-cell.js +1 -1
  141. package/dist/delivery/web/public-names.d.ts +1 -0
  142. package/dist/delivery/web/public-names.js +1 -0
  143. package/dist/document-ingest-foundation/boot-checks.js +19 -11
  144. package/dist/document-ingest-foundation/boot-rules.d.ts +17 -0
  145. package/dist/document-ingest-foundation/boot-rules.js +17 -0
  146. package/dist/document-ingest-foundation/events.d.ts +8 -0
  147. package/dist/document-ingest-foundation/events.js +12 -0
  148. package/dist/document-ingest-foundation/feature.js +30 -2
  149. package/dist/document-ingest-foundation/index.d.ts +3 -1
  150. package/dist/document-ingest-foundation/index.js +3 -1
  151. package/dist/document-ingest-foundation/report-ingest-progress.d.ts +14 -0
  152. package/dist/document-ingest-foundation/report-ingest-progress.js +20 -0
  153. package/dist/document-ingest-foundation/tables.d.ts +3 -0
  154. package/dist/document-ingest-foundation/tables.js +26 -0
  155. package/dist/files-tenant-data/hooks.js +4 -1
  156. package/dist/folders/web/folder-manager.js +3 -10
  157. package/dist/folders/web/folder-section.js +1 -1
  158. package/dist/form-draft-user-data/index.js +4 -1
  159. package/dist/inbound-mail-foundation/entities.d.ts +3 -0
  160. package/dist/inbound-mail-foundation/entities.js +2 -0
  161. package/dist/inbound-mail-foundation/events.d.ts +2 -0
  162. package/dist/inbound-mail-foundation/events.js +2 -0
  163. package/dist/inbound-mail-foundation/feature.js +6 -6
  164. package/dist/inbound-mail-foundation/handlers/attach-message-content.write.js +3 -1
  165. package/dist/inbound-mail-foundation/handlers/ingest-message.write.js +5 -0
  166. package/dist/inbound-mail-foundation/handlers/list-messages.query.js +4 -2
  167. package/dist/inbound-mail-foundation/handlers/message-content.d.ts +1 -0
  168. package/dist/inbound-mail-foundation/handlers/message-content.js +8 -0
  169. package/dist/inbound-mail-foundation/handlers/message-content.query.d.ts +2 -0
  170. package/dist/inbound-mail-foundation/handlers/message-content.query.js +1 -0
  171. package/dist/inbound-mail-foundation/projection.d.ts +3 -0
  172. package/dist/inbound-mail-foundation/projection.js +2 -0
  173. package/dist/inbound-mail-foundation/sanitize-inbound-html.d.ts +2 -0
  174. package/dist/inbound-mail-foundation/sanitize-inbound-html.js +135 -0
  175. package/dist/inbound-mail-foundation/types.js +1 -0
  176. package/dist/jobs/job-run-logger.js +16 -20
  177. package/dist/ledger/handlers/reports.query.js +25 -27
  178. package/dist/ledger/recurring.js +1 -0
  179. package/dist/notes-history/web/notes-section.js +3 -2
  180. package/dist/personal-access-tokens/feature.js +5 -18
  181. package/dist/personal-access-tokens/handlers/create.write.js +2 -5
  182. package/dist/secrets/handlers/delete.write.d.ts +4 -0
  183. package/dist/secrets/handlers/delete.write.js +9 -4
  184. package/dist/secrets/handlers/list.query.d.ts +6 -1
  185. package/dist/secrets/handlers/list.query.js +7 -3
  186. package/dist/secrets/handlers/set.write.d.ts +4 -0
  187. package/dist/secrets/handlers/set.write.js +10 -4
  188. package/dist/secrets/secret-scope.d.ts +17 -0
  189. package/dist/secrets/secret-scope.js +18 -0
  190. package/dist/sessions/feature.d.ts +3 -0
  191. package/dist/sessions/feature.js +13 -19
  192. package/dist/sessions/handlers/last-activity-probe.query.d.ts +7 -0
  193. package/dist/sessions/handlers/last-activity-probe.query.js +40 -0
  194. package/dist/sessions/handlers/last-activity-probe.route.d.ts +2 -0
  195. package/dist/sessions/handlers/last-activity-probe.route.js +30 -0
  196. package/dist/sessions/screens.js +1 -0
  197. package/dist/sessions/session-callbacks.d.ts +2 -0
  198. package/dist/sessions/session-callbacks.js +9 -7
  199. package/dist/sessions/web/i18n.js +4 -1
  200. package/dist/shared/assert-billing-live.d.ts +2 -0
  201. package/dist/shared/assert-billing-live.js +7 -0
  202. package/dist/shared/collect-extension-options.d.ts +1 -0
  203. package/dist/shared/collect-extension-options.js +8 -0
  204. package/dist/shared/index.d.ts +7 -1
  205. package/dist/shared/index.js +7 -1
  206. package/dist/shared/late-bound-slot.d.ts +5 -0
  207. package/dist/shared/late-bound-slot.js +13 -0
  208. package/dist/shared/mail-locale-templates.d.ts +1 -0
  209. package/dist/shared/mail-locale-templates.js +1 -1
  210. package/dist/shared/price-env-shape.d.ts +11 -0
  211. package/dist/shared/price-env-shape.js +15 -0
  212. package/dist/shared/purge-row-file-refs.d.ts +1 -0
  213. package/dist/shared/purge-row-file-refs.js +1 -1
  214. package/dist/shared/read-feature-export-fn.d.ts +2 -0
  215. package/dist/shared/read-feature-export-fn.js +11 -0
  216. package/dist/shared/signup-handover.js +3 -5
  217. package/dist/shared/tenant-destruction-hold.d.ts +23 -0
  218. package/dist/shared/tenant-destruction-hold.js +15 -0
  219. package/dist/shared/unprocessable.d.ts +4 -0
  220. package/dist/shared/unprocessable.js +4 -0
  221. package/dist/shared/web/index.d.ts +3 -0
  222. package/dist/shared/web/index.js +3 -0
  223. package/dist/subscription-paddle/feature.d.ts +1 -5
  224. package/dist/subscription-paddle/feature.js +7 -9
  225. package/dist/subscription-paddle/runtime.js +3 -7
  226. package/dist/subscription-stripe/feature.d.ts +1 -5
  227. package/dist/subscription-stripe/feature.js +7 -9
  228. package/dist/subscription-stripe/runtime.js +3 -7
  229. package/dist/tags/entity.js +1 -0
  230. package/dist/tags/web/tag-chip.d.ts +7 -0
  231. package/dist/tags/web/tag-chip.js +4 -0
  232. package/dist/tags/web/tag-filter.js +2 -5
  233. package/dist/tags/web/tag-manager.js +1 -1
  234. package/dist/tags/web/tag-section.js +3 -6
  235. package/dist/tags/web/tags-cell.js +2 -5
  236. package/dist/template-resolver/compile-document-body.js +12 -17
  237. package/dist/template-resolver/handlers/by-tenant.query.js +3 -1
  238. package/dist/template-resolver/handlers/discard-draft.write.js +1 -0
  239. package/dist/template-resolver/handlers/overview.query.js +3 -1
  240. package/dist/template-resolver/handlers/send-test.write.js +2 -4
  241. package/dist/template-resolver/handlers/toggle-status.write.js +3 -0
  242. package/dist/template-resolver/linked-resources.js +6 -5
  243. package/dist/template-resolver/store-template-resource.js +5 -10
  244. package/dist/template-resolver/web/document-images.js +6 -6
  245. package/dist/template-resolver/web/document-insert-fields.js +22 -4
  246. package/dist/template-resolver/web/document-schema.js +11 -12
  247. package/dist/template-resolver/web/tiptap-attribute-parse-rule.d.ts +15 -0
  248. package/dist/template-resolver/web/tiptap-attribute-parse-rule.js +11 -0
  249. package/dist/tenant/i18n.js +3 -0
  250. package/dist/tenant/schema/tenant.d.ts +9 -7
  251. package/dist/tenant/schema/tenant.js +1 -0
  252. package/dist/tenant/web/member-roles-cell.js +1 -1
  253. package/dist/tenant/web/member-status-cell.js +1 -1
  254. package/dist/tenant-inactivity/check-inactive-tenants.d.ts +3 -0
  255. package/dist/tenant-inactivity/check-inactive-tenants.js +184 -0
  256. package/dist/tenant-inactivity/constants.d.ts +10 -0
  257. package/dist/tenant-inactivity/constants.js +10 -0
  258. package/dist/tenant-inactivity/email-templates.d.ts +3 -0
  259. package/dist/tenant-inactivity/email-templates.js +16 -0
  260. package/dist/tenant-inactivity/feature.d.ts +8 -0
  261. package/dist/tenant-inactivity/feature.js +45 -0
  262. package/dist/tenant-inactivity/handlers/inactivity-state.query.d.ts +11 -0
  263. package/dist/tenant-inactivity/handlers/inactivity-state.query.js +45 -0
  264. package/dist/tenant-inactivity/handlers/keep-account.write.d.ts +8 -0
  265. package/dist/tenant-inactivity/handlers/keep-account.write.js +48 -0
  266. package/dist/tenant-inactivity/inactivity-plan.d.ts +51 -0
  267. package/dist/tenant-inactivity/inactivity-plan.js +113 -0
  268. package/dist/tenant-inactivity/index.d.ts +5 -0
  269. package/dist/tenant-inactivity/index.js +3 -0
  270. package/dist/tenant-inactivity/keep-token.d.ts +16 -0
  271. package/dist/tenant-inactivity/keep-token.js +24 -0
  272. package/dist/tenant-inactivity/mail-notifications.d.ts +4 -0
  273. package/dist/tenant-inactivity/mail-notifications.js +42 -0
  274. package/dist/tenant-inactivity/options.d.ts +27 -0
  275. package/dist/tenant-inactivity/options.js +5 -0
  276. package/dist/tenant-inactivity/remote-activity.d.ts +15 -0
  277. package/dist/tenant-inactivity/remote-activity.js +24 -0
  278. package/dist/tenant-inactivity/state-store.d.ts +10 -0
  279. package/dist/tenant-inactivity/state-store.js +50 -0
  280. package/dist/tenant-inactivity/state-table.d.ts +109 -0
  281. package/dist/tenant-inactivity/state-table.js +38 -0
  282. package/dist/tenant-lifecycle/boot-checks.js +8 -3
  283. package/dist/tenant-lifecycle/boot-rules.d.ts +12 -0
  284. package/dist/tenant-lifecycle/boot-rules.js +12 -0
  285. package/dist/tenant-lifecycle/constants.d.ts +1 -0
  286. package/dist/tenant-lifecycle/constants.js +5 -0
  287. package/dist/tenant-lifecycle/events.d.ts +2 -0
  288. package/dist/tenant-lifecycle/events.js +2 -0
  289. package/dist/tenant-lifecycle/feature.js +18 -3
  290. package/dist/tenant-lifecycle/handlers/request-destruction.write.js +11 -67
  291. package/dist/tenant-lifecycle/index.d.ts +2 -1
  292. package/dist/tenant-lifecycle/index.js +2 -1
  293. package/dist/tenant-lifecycle/request-tenant-destruction.d.ts +20 -0
  294. package/dist/tenant-lifecycle/request-tenant-destruction.js +66 -0
  295. package/dist/tenant-lifecycle/retention-config-destroy-hooks.d.ts +5 -0
  296. package/dist/tenant-lifecycle/retention-config-destroy-hooks.js +29 -0
  297. package/dist/tenant-lifecycle/run-tenant-destroy.d.ts +5 -0
  298. package/dist/tenant-lifecycle/run-tenant-destroy.js +85 -12
  299. package/dist/tenant-lifecycle/stages.d.ts +3 -0
  300. package/dist/tenant-lifecycle/stages.js +27 -3
  301. package/dist/tenant-lifecycle/testing.js +1 -1
  302. package/dist/tier-engine/caps-for-tier-from-map.d.ts +5 -0
  303. package/dist/tier-engine/caps-for-tier-from-map.js +12 -0
  304. package/dist/tier-engine/compose-app.d.ts +0 -22
  305. package/dist/tier-engine/compose-app.js +9 -16
  306. package/dist/tier-engine/index.d.ts +1 -0
  307. package/dist/tier-engine/index.js +1 -0
  308. package/dist/user/handlers/detail.query.d.ts +1 -1
  309. package/dist/user-data-rights/feature.js +2 -0
  310. package/dist/user-data-rights/run-forget-cleanup.js +2 -0
  311. package/dist/user-data-rights/web/privacy-center-screen.js +1 -1
  312. package/dist/user-data-rights/zip-path.js +1 -0
  313. package/dist/user-data-rights-defaults/hooks/config-value.userdata-hook.d.ts +1 -1
  314. package/dist/user-data-rights-defaults/hooks/config-value.userdata-hook.js +7 -20
  315. package/dist/user-data-rights-defaults/hooks/delivery-attempt.userdata-hook.js +3 -1
  316. package/dist/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.d.ts +10 -0
  317. package/dist/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.js +26 -0
  318. package/dist/user-data-rights-defaults/hooks/notification-preference.userdata-hook.d.ts +1 -1
  319. package/dist/user-data-rights-defaults/hooks/notification-preference.userdata-hook.js +7 -20
  320. package/dist/user-profile/handlers/change-email.write.js +2 -4
  321. package/dist/user-profile/web/profile-screen.js +2 -3
  322. package/kumiko-es-tables.json +12 -0
  323. package/package.json +46 -12
  324. package/src/admin-shell/changes.json +6 -0
  325. package/src/agent-tools/changes.json +6 -0
  326. package/src/channel-in-app/changes.json +7 -0
  327. package/src/contact/changes.json +27 -0
  328. package/src/data-retention/changes.json +6 -0
  329. package/src/delivery/changes.json +7 -0
  330. package/src/document-ingest-foundation/changes.json +6 -0
  331. package/src/files-tenant-data/changes.json +6 -0
  332. package/src/inbound-mail-foundation/changes.json +13 -0
  333. package/src/secrets/changes.json +6 -0
  334. package/src/sessions/changes.json +6 -0
  335. package/src/tenant-inactivity/changes.json +8 -0
  336. package/src/tenant-lifecycle/changes.json +30 -0
  337. package/src/tier-engine/changes.json +6 -0
@@ -1,44 +1,21 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  // VerifyEmailScreen — reads `?token=...` from the URL and automatically sends it to
3
3
  // /api/auth/verify-email on mount, then shows success/error. The server-side
4
4
  // operation is idempotent (repeating it sets emailVerified=true again), so
5
5
  // retries are safe.
6
- //
7
- // The empty-deps effect and once guard prevent React Strict Mode from firing
8
- // the verification call twice (Strict Mode dispatches useEffect twice in dev).
9
- // The token roundtrip is single-use server-side, but this avoids showing an
10
- // invalid-token banner after the first valid mount call.
11
- import { usePrimitives, useTranslation } from "@cosmicdrift/kumiko-renderer";
12
- import { useEffect, useRef, useState } from "react";
6
+ import { useTranslation } from "@cosmicdrift/kumiko-renderer";
13
7
  import { verifyEmail } from "./auth-client.js";
14
- import { AuthCard, useUrlToken } from "./auth-form-primitives.js";
15
- export function VerifyEmailScreen({ title, token: tokenProp, loginHref = "/login", }) {
8
+ import { TokenConfirmScreen } from "./token-confirm-screen.js";
9
+ // guard:dup-ok TokenConfirmScreen holds the logic; each screen only supplies its own literal label keys
10
+ export function VerifyEmailScreen({ title, token, loginHref = "/login", }) {
16
11
  const t = useTranslation();
17
- const { Link } = usePrimitives();
18
- const token = useUrlToken(tokenProp);
19
- const [status, setStatus] = useState(token === "" ? "missing-token" : "verifying");
20
- const startedRef = useRef(false);
21
- // kumiko-lint-ignore no-raw-hooks not yet converted to the framework hook set
22
- useEffect(() => {
23
- if (status !== "verifying")
24
- return;
25
- if (startedRef.current)
26
- return;
27
- startedRef.current = true;
28
- void (async () => {
29
- const res = await verifyEmail(token);
30
- setStatus(res.ok ? "success" : "error");
31
- })();
32
- }, [status, token]);
33
- if (status === "missing-token") {
34
- return (_jsxs(AuthCard, { title: title ?? t("auth.verifyEmail.errorTitle"), children: [_jsx("p", { className: "text-sm text-muted-foreground", children: t("auth.verifyEmail.missingToken") }), _jsx(Link, { href: loginHref, variant: "muted", children: t("auth.verifyEmail.goToLogin") })] }));
35
- }
36
- if (status === "verifying") {
37
- return (_jsx(AuthCard, { children: _jsx("div", { className: "p-6", children: _jsx("p", { className: "text-sm text-muted-foreground", role: "status", children: t("auth.verifyEmail.verifying") }) }) }));
38
- }
39
- if (status === "success") {
40
- return (_jsxs(AuthCard, { title: title ?? t("auth.verifyEmail.successTitle"), children: [_jsx("p", { className: "text-sm text-muted-foreground", children: t("auth.verifyEmail.successBody") }), _jsx(Link, { href: loginHref, variant: "button", children: t("auth.verifyEmail.goToLogin") })] }));
41
- }
42
- // status === "error"
43
- return (_jsxs(AuthCard, { title: title ?? t("auth.verifyEmail.errorTitle"), children: [_jsx("p", { className: "text-sm text-muted-foreground", children: t("auth.verifyEmail.errorBody") }), _jsx(Link, { href: loginHref, variant: "muted", children: t("auth.verifyEmail.goToLogin") })] }));
12
+ return (_jsx(TokenConfirmScreen, { title: title, token: token, loginHref: loginHref, confirm: verifyEmail, labels: {
13
+ errorTitle: t("auth.verifyEmail.errorTitle"),
14
+ missingToken: t("auth.verifyEmail.missingToken"),
15
+ goToLogin: t("auth.verifyEmail.goToLogin"),
16
+ verifying: t("auth.verifyEmail.verifying"),
17
+ successTitle: t("auth.verifyEmail.successTitle"),
18
+ successBody: t("auth.verifyEmail.successBody"),
19
+ errorBody: t("auth.verifyEmail.errorBody"),
20
+ } }));
44
21
  }
@@ -11,6 +11,8 @@
11
11
  // (their provider is picked from tenant config, which doesn't exist at
12
12
  // boot; auth-foundation's providers are static per-deployment, so boot is
13
13
  // the right time to catch it).
14
+ import { bootRuleError } from "@cosmicdrift/kumiko-framework/engine";
15
+ import { AUTH_FOUNDATION_BOOT_RULES } from "./boot-rules.js";
14
16
  import { EXT_SESSION_STORE, EXT_TENANT_EXISTENCE, EXT_TENANT_RESOLVER, EXT_TOKEN_VERIFIER, isAuthProviderPlugin, isSessionStoreProvider, isTenantExistenceProvider, isTenantResolverProvider, tokenShapeKey, } from "./types.js";
15
17
  export function validateTokenVerifierMultiplicity(features) {
16
18
  const namesByShape = new Map();
@@ -19,8 +21,10 @@ export function validateTokenVerifierMultiplicity(features) {
19
21
  if (usage.extensionName !== EXT_TOKEN_VERIFIER)
20
22
  continue;
21
23
  if (!isAuthProviderPlugin(usage.options)) {
22
- throw new Error(`[auth-foundation] tokenVerifier provider "${usage.entityName}" (feature "${feature.name}") ` +
23
- `registered without a valid AuthProviderPlugin — options must have a { shape, build } shape.`);
24
+ throw bootRuleError(AUTH_FOUNDATION_BOOT_RULES.tokenVerifierInvalidPlugin, {
25
+ message: `[auth-foundation] tokenVerifier provider "${usage.entityName}" (feature "${feature.name}") ` +
26
+ `registered without a valid AuthProviderPlugin — options must have a { shape, build } shape.`,
27
+ });
24
28
  }
25
29
  const key = tokenShapeKey(usage.options.shape);
26
30
  const names = namesByShape.get(key) ?? [];
@@ -38,15 +42,19 @@ export function validateTokenVerifierMultiplicity(features) {
38
42
  return;
39
43
  }
40
44
  }
41
- throw new Error("[auth-foundation] no tokenVerifier providers and no sessionStore registered — mount " +
42
- "at least one auth-provider-* feature (e.g. auth-provider-jwt / personal-access-tokens) " +
43
- "or a sessionStore (e.g. sessions) alongside auth-foundation.");
45
+ throw bootRuleError(AUTH_FOUNDATION_BOOT_RULES.noTokenVerifierOrSessionStore, {
46
+ message: "[auth-foundation] no tokenVerifier providers and no sessionStore registered — mount " +
47
+ "at least one auth-provider-* feature (e.g. auth-provider-jwt / personal-access-tokens) " +
48
+ "or a sessionStore (e.g. sessions) alongside auth-foundation.",
49
+ });
44
50
  }
45
51
  for (const [key, names] of namesByShape) {
46
52
  if (names.length >= 2) {
47
- throw new Error(`[auth-foundation] ${names.length} tokenVerifier providers claim the same shape "${key}" ` +
48
- `(${names.join(", ")}) — resolveTokenVerifier can't route between them unambiguously. ` +
49
- `Give each provider a distinct shape.`);
53
+ throw bootRuleError(AUTH_FOUNDATION_BOOT_RULES.tokenVerifierShapeCollision, {
54
+ message: `[auth-foundation] ${names.length} tokenVerifier providers claim the same shape "${key}" ` +
55
+ `(${names.join(", ")}) — resolveTokenVerifier can't route between them unambiguously. ` +
56
+ `Give each provider a distinct shape.`,
57
+ });
50
58
  }
51
59
  }
52
60
  }
@@ -68,15 +76,19 @@ function validateSingleProvider(features, opts) {
68
76
  if (usage.extensionName !== ext)
69
77
  continue;
70
78
  if (!guard(usage.options)) {
71
- throw new Error(`[auth-foundation] ${label} provider "${usage.entityName}" (feature "${feature.name}") ` +
72
- `registered without a valid ${shapeHint}.`);
79
+ throw bootRuleError(AUTH_FOUNDATION_BOOT_RULES.singleProviderInvalidShape, {
80
+ message: `[auth-foundation] ${label} provider "${usage.entityName}" (feature "${feature.name}") ` +
81
+ `registered without a valid ${shapeHint}.`,
82
+ });
73
83
  }
74
84
  names.push(usage.entityName);
75
85
  }
76
86
  }
77
87
  if (names.length >= 2) {
78
- throw new Error(`[auth-foundation] ${names.length} ${label} providers registered (${names.join(", ")}) — ` +
79
- `only one ${label} provider may be mounted at a time.`);
88
+ throw bootRuleError(AUTH_FOUNDATION_BOOT_RULES.singleProviderMultiple, {
89
+ message: `[auth-foundation] ${names.length} ${label} providers registered (${names.join(", ")}) — ` +
90
+ `only one ${label} provider may be mounted at a time.`,
91
+ });
80
92
  }
81
93
  }
82
94
  // Multiplicity boot-check for the `sessionStore` extension point.
@@ -0,0 +1,27 @@
1
+ export declare const AUTH_FOUNDATION_BOOT_RULES: {
2
+ readonly tokenVerifierInvalidPlugin: {
3
+ readonly id: "auth-foundation/token-verifier-invalid-plugin";
4
+ readonly summary: "A tokenVerifier provider registers a valid AuthProviderPlugin with a { shape, build } options shape.";
5
+ readonly fix: "Register the provider with options of shape { shape, build }.";
6
+ };
7
+ readonly noTokenVerifierOrSessionStore: {
8
+ readonly id: "auth-foundation/no-token-verifier-or-session-store";
9
+ readonly summary: "At least one tokenVerifier provider or a sessionStore is registered alongside auth-foundation.";
10
+ readonly fix: "Mount an auth-provider-* feature (e.g. auth-provider-jwt / personal-access-tokens) or a sessionStore (e.g. sessions).";
11
+ };
12
+ readonly tokenVerifierShapeCollision: {
13
+ readonly id: "auth-foundation/token-verifier-shape-collision";
14
+ readonly summary: "No two tokenVerifier providers claim the same token shape, so resolveTokenVerifier can route unambiguously.";
15
+ readonly fix: "Give each provider a distinct shape.";
16
+ };
17
+ readonly singleProviderInvalidShape: {
18
+ readonly id: "auth-foundation/single-provider-invalid-shape";
19
+ readonly summary: "A single-provider extension registration carries the options shape its provider type requires.";
20
+ readonly fix: "Register the provider with the options shape named in the error message.";
21
+ };
22
+ readonly singleProviderMultiple: {
23
+ readonly id: "auth-foundation/single-provider-multiple";
24
+ readonly summary: "At most one provider of a single-provider extension is mounted at a time.";
25
+ readonly fix: "Unmount all but one provider.";
26
+ };
27
+ };
@@ -0,0 +1,27 @@
1
+ export const AUTH_FOUNDATION_BOOT_RULES = {
2
+ tokenVerifierInvalidPlugin: {
3
+ id: "auth-foundation/token-verifier-invalid-plugin",
4
+ summary: "A tokenVerifier provider registers a valid AuthProviderPlugin with a { shape, build } options shape.",
5
+ fix: "Register the provider with options of shape { shape, build }.",
6
+ },
7
+ noTokenVerifierOrSessionStore: {
8
+ id: "auth-foundation/no-token-verifier-or-session-store",
9
+ summary: "At least one tokenVerifier provider or a sessionStore is registered alongside auth-foundation.",
10
+ fix: "Mount an auth-provider-* feature (e.g. auth-provider-jwt / personal-access-tokens) or a sessionStore (e.g. sessions).",
11
+ },
12
+ tokenVerifierShapeCollision: {
13
+ id: "auth-foundation/token-verifier-shape-collision",
14
+ summary: "No two tokenVerifier providers claim the same token shape, so resolveTokenVerifier can route unambiguously.",
15
+ fix: "Give each provider a distinct shape.",
16
+ },
17
+ singleProviderInvalidShape: {
18
+ id: "auth-foundation/single-provider-invalid-shape",
19
+ summary: "A single-provider extension registration carries the options shape its provider type requires.",
20
+ fix: "Register the provider with the options shape named in the error message.",
21
+ },
22
+ singleProviderMultiple: {
23
+ id: "auth-foundation/single-provider-multiple",
24
+ summary: "At most one provider of a single-provider extension is mounted at a time.",
25
+ fix: "Unmount all but one provider.",
26
+ },
27
+ };
@@ -1,4 +1,4 @@
1
- import { type WriteFailure } from "@cosmicdrift/kumiko-framework/errors";
1
+ import type { WriteFailure } from "@cosmicdrift/kumiko-framework/errors";
2
2
  export { AuthMfaErrorCodes as AuthMfaErrors } from "./web/constants.ts";
3
3
  export declare function mfaAlreadyEnabled(): WriteFailure;
4
4
  export declare function mfaNotEnabled(): WriteFailure;
@@ -1,40 +1,27 @@
1
- import { UnprocessableError, writeFailure, } from "@cosmicdrift/kumiko-framework/errors";
2
- import { AuthMfaErrorCodes } from "./web/constants.js";
1
+ import { unprocessable } from "../shared/index.js";
2
+ import { AuthMfaErrorCodes as Code } from "./web/constants.js";
3
3
  export { AuthMfaErrorCodes as AuthMfaErrors } from "./web/constants.js";
4
4
  export function mfaAlreadyEnabled() {
5
- return writeFailure(new UnprocessableError(AuthMfaErrorCodes.mfaAlreadyEnabled, {
6
- i18nKey: "auth.mfa.errors.mfaAlreadyEnabled",
7
- }));
5
+ return unprocessable(Code.mfaAlreadyEnabled, "auth.mfa.errors.mfaAlreadyEnabled");
8
6
  }
9
7
  export function mfaNotEnabled() {
10
- return writeFailure(new UnprocessableError(AuthMfaErrorCodes.mfaNotEnabled, {
11
- i18nKey: "auth.mfa.errors.mfaNotEnabled",
12
- }));
8
+ return unprocessable(Code.mfaNotEnabled, "auth.mfa.errors.mfaNotEnabled");
13
9
  }
14
10
  export function invalidSetupToken() {
15
- return writeFailure(new UnprocessableError(AuthMfaErrorCodes.invalidSetupToken, {
16
- i18nKey: "auth.mfa.errors.invalidSetupToken",
17
- }));
11
+ return unprocessable(Code.invalidSetupToken, "auth.mfa.errors.invalidSetupToken");
18
12
  }
19
13
  export function invalidTotpCode() {
20
- return writeFailure(new UnprocessableError(AuthMfaErrorCodes.invalidTotpCode, {
21
- i18nKey: "auth.mfa.errors.invalidTotpCode",
22
- }));
14
+ return unprocessable(Code.invalidTotpCode, "auth.mfa.errors.invalidTotpCode");
23
15
  }
24
16
  export function invalidRecoveryCode() {
25
- return writeFailure(new UnprocessableError(AuthMfaErrorCodes.invalidRecoveryCode, {
26
- i18nKey: "auth.mfa.errors.invalidRecoveryCode",
27
- }));
17
+ return unprocessable(Code.invalidRecoveryCode, "auth.mfa.errors.invalidRecoveryCode");
28
18
  }
29
19
  export function invalidChallengeToken() {
30
- return writeFailure(new UnprocessableError(AuthMfaErrorCodes.invalidChallengeToken, {
31
- i18nKey: "auth.mfa.errors.invalidChallengeToken",
32
- }));
20
+ return unprocessable(Code.invalidChallengeToken, "auth.mfa.errors.invalidChallengeToken");
33
21
  }
34
22
  // retryAfterSeconds drives the login UI countdown — must stay > 0.
35
23
  export function tooManyAttempts(retryAfterSeconds) {
36
- return writeFailure(new UnprocessableError(AuthMfaErrorCodes.tooManyAttempts, {
37
- i18nKey: "auth.mfa.errors.tooManyAttempts",
38
- details: { retryAfterSeconds },
39
- }));
24
+ return unprocessable(Code.tooManyAttempts, "auth.mfa.errors.tooManyAttempts", {
25
+ retryAfterSeconds,
26
+ });
40
27
  }
@@ -1,72 +1,33 @@
1
+ import { readFeatureExportFn } from "../shared/index.js";
1
2
  // Reads the late-bind setter off a mounted auth-mfa feature's exports —
2
3
  // mirrors sessions' own bindAutoRevokeFromFeature. run{Prod,Dev}App call
3
4
  // this once the sessions feature (if mounted) has produced a concrete
4
5
  // sessionRevokeAllOthers callback.
5
6
  export function bindMfaRevokeAllOtherSessionsFromFeature(feature) {
6
- const exports = feature.exports;
7
- if (exports && typeof exports === "object" && "bindRevokeAllOtherSessions" in exports) {
8
- const { bindRevokeAllOtherSessions } = exports;
9
- if (typeof bindRevokeAllOtherSessions === "function") {
10
- // @cast-boundary feature-exports — feature.exports is untyped by design
11
- return bindRevokeAllOtherSessions;
12
- }
13
- }
14
- return undefined;
7
+ return readFeatureExportFn(feature, "bindRevokeAllOtherSessions");
15
8
  }
16
9
  // Reads the eagerly-built `checkMfaStatus` off a mounted auth-mfa feature's
17
10
  // exports — no bind-setter needed (see the comment where it's built).
18
11
  export function mfaStatusCheckerFromFeature(feature) {
19
- const exports = feature.exports;
20
- if (exports && typeof exports === "object" && "checkMfaStatus" in exports) {
21
- const { checkMfaStatus } = exports;
22
- if (typeof checkMfaStatus === "function") {
23
- // @cast-boundary feature-exports — feature.exports is untyped by design
24
- return checkMfaStatus;
25
- }
26
- }
27
- return undefined;
12
+ return readFeatureExportFn(feature, "checkMfaStatus");
28
13
  }
29
14
  // Reads the eagerly-built `verifyMfaCode` off a mounted auth-mfa feature's
30
15
  // exports — personal-access-tokens wires this in as its optional
31
16
  // mfaVerifier (re-auth gate for minting a token). Same no-bind-setter
32
17
  // reasoning as checkMfaStatus above.
33
18
  export function mfaVerifierFromFeature(feature) {
34
- const exports = feature.exports;
35
- if (exports && typeof exports === "object" && "verifyMfaCode" in exports) {
36
- const { verifyMfaCode } = exports;
37
- if (typeof verifyMfaCode === "function") {
38
- // @cast-boundary feature-exports — feature.exports is untyped by design
39
- return verifyMfaCode;
40
- }
41
- }
42
- return undefined;
19
+ return readFeatureExportFn(feature, "verifyMfaCode");
43
20
  }
44
21
  // Reads the token-secret binder off a mounted auth-mfa feature's exports.
45
22
  // run{Prod,Dev}App and setupTestStack call it with the JWT secret once the
46
23
  // env is validated, so a dry run never needs the master secret.
47
24
  export function bindMfaTokenSecretsFromFeature(feature) {
48
- const exports = feature.exports;
49
- if (exports && typeof exports === "object" && "bindTokenSecrets" in exports) {
50
- const { bindTokenSecrets } = exports;
51
- if (typeof bindTokenSecrets === "function") {
52
- // @cast-boundary feature-exports — feature.exports is untyped by design
53
- return bindTokenSecrets;
54
- }
55
- }
56
- return undefined;
25
+ return readFeatureExportFn(feature, "bindTokenSecrets");
57
26
  }
58
27
  // Reads the late-bind setter off a mounted auth-mfa feature's exports —
59
28
  // run{Prod,Dev}App call this once the personal-access-tokens feature (if
60
29
  // mounted) has produced a concrete revoker, same wiring shape as
61
30
  // bindMfaRevokeAllOtherSessionsFromFeature.
62
31
  export function bindRevokeAllPatTokensFromFeature(feature) {
63
- const exports = feature.exports;
64
- if (exports && typeof exports === "object" && "bindRevokeAllPatTokens" in exports) {
65
- const { bindRevokeAllPatTokens } = exports;
66
- if (typeof bindRevokeAllPatTokens === "function") {
67
- // @cast-boundary feature-exports — feature.exports is untyped by design
68
- return bindRevokeAllPatTokens;
69
- }
70
- }
71
- return undefined;
32
+ return readFeatureExportFn(feature, "bindRevokeAllPatTokens");
72
33
  }
@@ -1,5 +1,6 @@
1
1
  import { defineFeature } from "@cosmicdrift/kumiko-framework/engine";
2
2
  import { featureWithEnvSchema } from "@cosmicdrift/kumiko-framework/env";
3
+ import { createLateBoundSlot } from "../shared/index.js";
3
4
  import { mfaRequiredConfigKey } from "./config.js";
4
5
  import { authMfaEnvSchema } from "./env.js";
5
6
  import { createDisableHandler } from "./handlers/disable.write.js";
@@ -65,14 +66,14 @@ export function createAuthMfaFeature(opts) {
65
66
  // sessions' own bindAutoRevokeOnPasswordChange. Shared by every handler
66
67
  // that changes MFA state (enable/disable/regenerate), so each one's
67
68
  // "log out every other session" behavior tracks the same wiring.
68
- let revokeAllOtherSessions;
69
- const sharedRevoker = (userId, currentSid) => revokeAllOtherSessions?.(userId, currentSid) ?? Promise.resolve(0);
69
+ const otherSessionsRevokerSlot = createLateBoundSlot();
70
+ const sharedRevoker = (userId, currentSid) => otherSessionsRevokerSlot.current()?.(userId, currentSid) ?? Promise.resolve(0);
70
71
  // Same late-bind shape as sharedRevoker above, for the personal-access-
71
72
  // tokens feature (if mounted). Wired to enable-confirm(-preauth)/disable
72
73
  // only — regenerate-recovery doesn't change enrollment state, so it's
73
74
  // out of scope for the "MFA-enable/disable" finding this mirrors.
74
- let revokeAllPatTokens;
75
- const sharedPatRevoker = (userId) => revokeAllPatTokens?.(userId) ?? Promise.resolve(0);
75
+ const patTokensRevokerSlot = createLateBoundSlot();
76
+ const sharedPatRevoker = (userId) => patTokensRevokerSlot.current()?.(userId) ?? Promise.resolve(0);
76
77
  // Handlers and the status checker read the secrets through these getters
77
78
  // on each call, so the boot can bind them after env validation. Never
78
79
  // spread these objects: a spread would read the getter eagerly.
@@ -145,20 +146,8 @@ export function createAuthMfaFeature(opts) {
145
146
  // No late-bind needed — same reasoning as checkMfaStatus: only needs the
146
147
  // HandlerContext the caller already has.
147
148
  const verifyMfaCode = createMfaCodeVerifier();
148
- const bindRevokeAllOtherSessions = (revoker) => {
149
- revokeAllOtherSessions = revoker;
150
- return () => {
151
- if (revokeAllOtherSessions === revoker)
152
- revokeAllOtherSessions = undefined;
153
- };
154
- };
155
- const bindRevokeAllPatTokens = (revoker) => {
156
- revokeAllPatTokens = revoker;
157
- return () => {
158
- if (revokeAllPatTokens === revoker)
159
- revokeAllPatTokens = undefined;
160
- };
161
- };
149
+ const bindRevokeAllOtherSessions = otherSessionsRevokerSlot.bind;
150
+ const bindRevokeAllPatTokens = patTokensRevokerSlot.bind;
162
151
  return {
163
152
  handlers,
164
153
  queries,
@@ -7,12 +7,14 @@
7
7
  // routes.
8
8
  // kumiko-lint-ignore cross-feature-import client-only types, the feature's server barrel has no web/ re-export
9
9
  import { failureFromErrorField, toLoginResponse, } from "../../auth-email-password/web/index.js";
10
- export async function verifyMfaChallenge(challengeToken, code) {
11
- const res = await fetch("/api/auth/mfa/verify", {
10
+ const VERIFY_PATH = "/api/auth/mfa/verify";
11
+ const PREAUTH_CONFIRM_PATH = "/api/auth/mfa/preauth-confirm";
12
+ async function postMfaLogin(path, payload, fallbackReason) {
13
+ const res = await fetch(path, {
12
14
  method: "POST",
13
15
  credentials: "same-origin",
14
16
  headers: { "Content-Type": "application/json" },
15
- body: JSON.stringify({ challengeToken, code }),
17
+ body: JSON.stringify(payload),
16
18
  });
17
19
  if (res.status === 429) {
18
20
  return { kind: "failure", error: { reason: "rate_limited" } };
@@ -25,7 +27,10 @@ export async function verifyMfaChallenge(challengeToken, code) {
25
27
  data: toLoginResponse(body.token, body.user, body.landingPath),
26
28
  };
27
29
  }
28
- return { kind: "failure", error: failureFromErrorField(body.error, "mfa_verify_failed") };
30
+ return { kind: "failure", error: failureFromErrorField(body.error, fallbackReason) };
31
+ }
32
+ export async function verifyMfaChallenge(challengeToken, code) {
33
+ return postMfaLogin(VERIFY_PATH, { challengeToken, code }, "mfa_verify_failed");
29
34
  }
30
35
  // Browser side of POST /api/auth/mfa/preauth-enable-start — lets a user
31
36
  // blocked at login by MFA enforcement generate a TOTP secret/QR without a
@@ -63,26 +68,7 @@ export async function startMfaSetupPreauth(preauthSetupToken, accountLabel) {
63
68
  // Browser side of POST /api/auth/mfa/preauth-confirm — completes both the
64
69
  // enrollment started by startMfaSetupPreauth and the login
65
70
  // mfa-setup-required block. Its response mirrors /auth/mfa/verify's and is
66
- // minted via the same mintSessionAndRespond(). It remains a separate function
67
- // so this file's two already-tested request shapes stay independently
68
- // editable.
71
+ // minted via the same mintSessionAndRespond(), so both share postMfaLogin.
69
72
  export async function confirmMfaSetupPreauth(setupToken, code) {
70
- const res = await fetch("/api/auth/mfa/preauth-confirm", {
71
- method: "POST",
72
- credentials: "same-origin",
73
- headers: { "Content-Type": "application/json" },
74
- body: JSON.stringify({ setupToken, code }),
75
- });
76
- if (res.status === 429) {
77
- return { kind: "failure", error: { reason: "rate_limited" } };
78
- }
79
- // @cast-boundary engine-payload — HTTP-API contract, server-side schema-validated
80
- const body = (await res.json().catch(() => ({})));
81
- if (body.isSuccess === true && body.token !== undefined && body.user !== undefined) {
82
- return {
83
- kind: "success",
84
- data: toLoginResponse(body.token, body.user, body.landingPath),
85
- };
86
- }
87
- return { kind: "failure", error: failureFromErrorField(body.error, "mfa_setup_confirm_failed") };
73
+ return postMfaLogin(PREAUTH_CONFIRM_PATH, { setupToken, code }, "mfa_setup_confirm_failed");
88
74
  }
@@ -1,6 +1,7 @@
1
1
  import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
2
2
  import { CONTRACT_TERMINATION_OPERATOR_NOTIFICATION_TYPE } from "../web/constants.js";
3
3
  import { operatorNoticeVariables } from "./termination-mail.js";
4
+ // guard:dup-ok narrows one optional ctx member with this feature's own mount hint
4
5
  export function requireNotify(ctx) {
5
6
  if (!ctx.notify) {
6
7
  throw new InternalError({
@@ -1,16 +1,15 @@
1
- export function intervalKey(price) {
1
+ function recurrenceKey(price, everyPrefix, singlePrefix) {
2
2
  if (price === null || price.interval === null)
3
3
  return undefined;
4
4
  return price.intervalCount !== null && price.intervalCount > 1
5
- ? `billing-foundation.plans.everyInterval.${price.interval}`
6
- : `billing-foundation.plans.perInterval.${price.interval}`;
5
+ ? `${everyPrefix}.${price.interval}`
6
+ : `${singlePrefix}.${price.interval}`;
7
+ }
8
+ export function intervalKey(price) {
9
+ return recurrenceKey(price, "billing-foundation.plans.everyInterval", "billing-foundation.plans.perInterval");
7
10
  }
8
11
  export function renewalKey(price) {
9
- if (price === null || price.interval === null)
10
- return undefined;
11
- return price.intervalCount !== null && price.intervalCount > 1
12
- ? `billing-foundation.consent.renewsEvery.${price.interval}`
13
- : `billing-foundation.consent.renews.${price.interval}`;
12
+ return recurrenceKey(price, "billing-foundation.consent.renewsEvery", "billing-foundation.consent.renews");
14
13
  }
15
14
  export function pricesDiffer(prices) {
16
15
  const [first, ...rest] = prices;
@@ -9,6 +9,7 @@ import { enforceStockCap } from "./enforce-cap.js";
9
9
  const STOCK_CAP_LOCK_NAMESPACE = 0x73636170;
10
10
  // Lock on the counted set, not on `code`: two handlers capping the same rows under
11
11
  // different codes must still serialize against each other.
12
+ // guard:dup-ok lock key of one counted set; only the sorted-entries shape matches other key builders
12
13
  function countedSetKey(spec) {
13
14
  const where = Object.entries(spec.where ?? {}).sort(([a], [b]) => a.localeCompare(b));
14
15
  return `${spec.table.tableName}:${JSON.stringify(where)}`;
@@ -6,4 +6,5 @@ export declare const InAppHandlers: {
6
6
  export declare const InAppQueries: {
7
7
  readonly inbox: "channel-in-app:query:inbox";
8
8
  readonly unreadCount: "channel-in-app:query:unread-count";
9
+ readonly readStateByKeys: "channel-in-app:query:read-state-by-keys";
9
10
  };
@@ -3,6 +3,7 @@ import { defineFeature } from "@cosmicdrift/kumiko-framework/engine";
3
3
  import { inboxQuery } from "./handlers/inbox.query.js";
4
4
  import { markAllReadWrite } from "./handlers/mark-all-read.write.js";
5
5
  import { markReadWrite } from "./handlers/mark-read.write.js";
6
+ import { readStateByKeysQuery } from "./handlers/read-state-by-keys.query.js";
6
7
  import { unreadCountQuery } from "./handlers/unread-count.query.js";
7
8
  import { inAppChannel } from "./in-app-channel.js";
8
9
  import { inAppMessagesTableMeta } from "./tables.js";
@@ -32,6 +33,7 @@ export function createChannelInAppFeature() {
32
33
  const queries = {
33
34
  inbox: r.queryHandler(inboxQuery),
34
35
  unreadCount: r.queryHandler(unreadCountQuery),
36
+ readStateByKeys: r.queryHandler(readStateByKeysQuery),
35
37
  };
36
38
  return { handlers, queries };
37
39
  });
@@ -0,0 +1,9 @@
1
+ import * as z from "zod";
2
+ export declare const readStateByKeysQuery: import("@cosmicdrift/kumiko-types/define-handler").QueryHandlerDefinition<"readStateByKeys", z.ZodObject<{
3
+ keys: z.ZodArray<z.ZodString>;
4
+ }, z.core.$strict>, {
5
+ rows: {
6
+ key: string;
7
+ readAt: globalThis.Temporal.Instant | null;
8
+ }[];
9
+ }, import("@cosmicdrift/kumiko-types/event-type-map").KumikoEventTypeMap>;
@@ -0,0 +1,21 @@
1
+ import { selectMany } from "@cosmicdrift/kumiko-framework/db";
2
+ import { access, defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
3
+ import * as z from "zod";
4
+ import { inAppMessagesTable } from "../tables.js";
5
+ const MAX_KEYS = 50;
6
+ export const readStateByKeysQuery = defineQueryHandler({
7
+ name: "readStateByKeys",
8
+ schema: z.object({ keys: z.array(z.string().min(1).max(256)).min(1).max(MAX_KEYS) }).strict(),
9
+ access: { roles: access.systemAdmin },
10
+ description: "Returns when the in-app message sent under each given notify() idempotency key was read (null while unread), within the caller's tenant and without any message content; a SystemAdmin queries the recipient's tenant by acting as a system user of it. Use it to show whether a recipient has seen a notification a feature sent under a known key.",
11
+ handler: async (query, ctx) => {
12
+ const rows = await selectMany(ctx.db, inAppMessagesTable, { idempotencyKey: { in: query.payload.keys } }, { orderBy: [{ col: "createdAt", direction: "asc" }] });
13
+ const states = new Map();
14
+ for (const row of rows) {
15
+ if (row.idempotencyKey !== null && !states.has(row.idempotencyKey)) {
16
+ states.set(row.idempotencyKey, row.readAt);
17
+ }
18
+ }
19
+ return { rows: [...states].map(([key, readAt]) => ({ key, readAt })) };
20
+ },
21
+ });
@@ -25,6 +25,7 @@ export const inAppChannel = {
25
25
  title: message.title,
26
26
  body: message.body ?? null,
27
27
  data: storedData,
28
+ idempotencyKey: ctx.idempotencyKey ?? null,
28
29
  });
29
30
  if (ctx.sseBroker) {
30
31
  // The row is stored, so a failing push (e.g. Redis down) must not turn the delivery into
@@ -9,10 +9,14 @@ export const inAppMessagesTable = pgTable("in_app_messages", {
9
9
  data: text("data"), // JSON string for action, screen, etc.
10
10
  isRead: boolean("is_read").default(false).notNull(),
11
11
  readAt: instant("read_at"),
12
+ idempotencyKey: text("idempotency_key"),
12
13
  createdAt: instant("created_at").default(sql `now()`).notNull(),
13
14
  },
14
15
  // Every inbox, unread-count, mark-all-read and userData export/delete read filters by tenant + user.
15
- (t) => [index("in_app_messages_tenant_user_created_idx").on(t.tenantId, t.userId, t.createdAt)]);
16
+ (t) => [
17
+ index("in_app_messages_tenant_user_created_idx").on(t.tenantId, t.userId, t.createdAt),
18
+ index("in_app_messages_idempotency_key_idx").on(t.idempotencyKey),
19
+ ]);
16
20
  // Derived from inAppMessagesTable (table() attaches the meta as a Symbol) so
17
21
  // the two can't drift, instead of hand-duplicating the column list.
18
22
  export const inAppMessagesTableMeta = requireEntityTableMeta(inAppMessagesTable, "inAppMessagesTable");
@@ -0,0 +1,14 @@
1
+ import type { Redis } from "ioredis";
2
+ import * as z from "zod";
3
+ declare const StoredChallengeSchema: z.ZodObject<{
4
+ issuedAtMs: z.ZodNumber;
5
+ bits: z.ZodNumber;
6
+ }, z.core.$strip>;
7
+ export type StoredChallenge = z.infer<typeof StoredChallengeSchema>;
8
+ export declare function issueChallenge(redis: Redis, args: {
9
+ readonly bits: number;
10
+ readonly ttlSeconds: number;
11
+ readonly nowMs: number;
12
+ }): Promise<string>;
13
+ export declare function consumeChallenge(redis: Redis, challenge: string): Promise<StoredChallenge | null>;
14
+ export {};
@@ -0,0 +1,30 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import * as z from "zod";
3
+ import { CONTACT_CHALLENGE_REDIS_PREFIX } from "./web/constants.js";
4
+ const CHALLENGE_BYTES = 16;
5
+ const StoredChallengeSchema = z.object({
6
+ issuedAtMs: z.number().int().nonnegative(),
7
+ bits: z.number().int().positive(),
8
+ });
9
+ const challengeKey = (challenge) => `${CONTACT_CHALLENGE_REDIS_PREFIX}${challenge}`;
10
+ export async function issueChallenge(redis, args) {
11
+ const challenge = randomBytes(CHALLENGE_BYTES).toString("base64url");
12
+ const stored = { issuedAtMs: args.nowMs, bits: args.bits };
13
+ await redis.set(challengeKey(challenge), JSON.stringify(stored), "EX", args.ttlSeconds);
14
+ return challenge;
15
+ }
16
+ // GETDEL makes the challenge single-use even when the submit is rejected afterwards.
17
+ export async function consumeChallenge(redis, challenge) {
18
+ const raw = await redis.getdel(challengeKey(challenge));
19
+ if (raw === null)
20
+ return null;
21
+ let json;
22
+ try {
23
+ json = JSON.parse(raw);
24
+ }
25
+ catch {
26
+ return null;
27
+ }
28
+ const parsed = StoredChallengeSchema.safeParse(json);
29
+ return parsed.success ? parsed.data : null;
30
+ }