@cosmicdrift/kumiko-samples 0.413.1 → 0.415.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 (479) hide show
  1. package/package.json +1 -1
  2. package/packages/bundled-features/package.json +16 -1
  3. package/packages/bundled-features/src/admin-shell/changes.json +6 -0
  4. package/packages/bundled-features/src/admin-shell/feature.ts +8 -7
  5. package/packages/bundled-features/src/agent-tools/agent-doc-lint.ts +5 -1
  6. package/packages/bundled-features/src/agent-tools/agent-manifest.ts +36 -27
  7. package/packages/bundled-features/src/agent-tools/api-docs/collect-events.ts +8 -1
  8. package/packages/bundled-features/src/agent-tools/api-docs/collect.ts +3 -2
  9. package/packages/bundled-features/src/agent-tools/api-docs/generate.ts +6 -0
  10. package/packages/bundled-features/src/agent-tools/api-docs/index.ts +1 -0
  11. package/packages/bundled-features/src/agent-tools/api-docs/problems.ts +38 -1
  12. package/packages/bundled-features/src/agent-tools/api-docs/render-openapi.ts +1 -0
  13. package/packages/bundled-features/src/agent-tools/api-docs/resolve-config.ts +17 -0
  14. package/packages/bundled-features/src/agent-tools/api-docs/scope-slug-collisions.ts +17 -0
  15. package/packages/bundled-features/src/agent-tools/api-docs/translation-gaps.ts +42 -0
  16. package/packages/bundled-features/src/agent-tools/api-docs/webhook-example-problems.ts +30 -0
  17. package/packages/bundled-features/src/agent-tools/changes.json +12 -0
  18. package/packages/bundled-features/src/agent-tools/index.ts +1 -0
  19. package/packages/bundled-features/src/agent-tools/labels.ts +19 -6
  20. package/packages/bundled-features/src/agent-tools/tool-catalog.ts +18 -7
  21. package/packages/bundled-features/src/agent-tools/tool-dispatch.ts +14 -1
  22. package/packages/bundled-features/src/agent-tools/types.ts +4 -0
  23. package/packages/bundled-features/src/audit/event-classification.ts +6 -0
  24. package/packages/bundled-features/src/audit/web/i18n.ts +1 -0
  25. package/packages/bundled-features/src/auth-email-password/changes.json +18 -0
  26. package/packages/bundled-features/src/auth-email-password/errors.ts +0 -13
  27. package/packages/bundled-features/src/auth-email-password/handlers/invite-signup-complete.write.ts +147 -121
  28. package/packages/bundled-features/src/auth-email-password/handlers/login-options.query.ts +1 -1
  29. package/packages/bundled-features/src/auth-email-password/handlers/request-account-unlock.write.ts +1 -1
  30. package/packages/bundled-features/src/auth-email-password/handlers/request-email-verification.write.ts +0 -1
  31. package/packages/bundled-features/src/auth-email-password/handlers/request-password-reset.write.ts +0 -1
  32. package/packages/bundled-features/src/auth-email-password/handlers/self-registration-status.query.ts +1 -1
  33. package/packages/bundled-features/src/auth-email-password/reset-token.ts +0 -2
  34. package/packages/bundled-features/src/auth-email-password/seeding.ts +39 -7
  35. package/packages/bundled-features/src/auth-email-password/signup-token-store.ts +2 -3
  36. package/packages/bundled-features/src/auth-email-password/unlock-token.ts +0 -2
  37. package/packages/bundled-features/src/auth-email-password/verification-token.ts +0 -2
  38. package/packages/bundled-features/src/auth-email-password/web/auth-form-primitives.tsx +2 -2
  39. package/packages/bundled-features/src/auth-email-password/web/auth-gate.tsx +2 -2
  40. package/packages/bundled-features/src/auth-email-password/web/auth-redirect.ts +5 -0
  41. package/packages/bundled-features/src/auth-email-password/web/forgot-password-screen.tsx +1 -6
  42. package/packages/bundled-features/src/auth-email-password/web/invite-accept-screen.tsx +1 -1
  43. package/packages/bundled-features/src/auth-email-password/web/return-path.ts +2 -1
  44. package/packages/bundled-features/src/auth-email-password/web/session.tsx +12 -13
  45. package/packages/bundled-features/src/auth-email-password/web/signup-screen.tsx +1 -6
  46. package/packages/bundled-features/src/auth-email-password/web/static-account.ts +6 -1
  47. package/packages/bundled-features/src/auth-email-password/web/tenant-switcher.tsx +1 -1
  48. package/packages/bundled-features/src/auth-email-password/web/token-confirm-screen.tsx +4 -5
  49. package/packages/bundled-features/src/auth-email-password/web/user-menu.tsx +1 -1
  50. package/packages/bundled-features/src/auth-mfa/changes.json +6 -0
  51. package/packages/bundled-features/src/auth-mfa/web/mfa-code-or-recovery-field.tsx +17 -1
  52. package/packages/bundled-features/src/auth-mfa/web/mfa-disable-dialog.tsx +1 -1
  53. package/packages/bundled-features/src/auth-mfa/web/mfa-regenerate-recovery-dialog.tsx +1 -1
  54. package/packages/bundled-features/src/auth-mfa/web/mfa-setup-preauth-screen.tsx +1 -1
  55. package/packages/bundled-features/src/auth-mfa/web/mfa-verify-screen.tsx +16 -47
  56. package/packages/bundled-features/src/auth-mfa-user-data/index.ts +5 -6
  57. package/packages/bundled-features/src/billing-foundation/aggregate-id.ts +0 -4
  58. package/packages/bundled-features/src/billing-foundation/changes.json +61 -0
  59. package/packages/bundled-features/src/billing-foundation/checkout-core.ts +19 -1
  60. package/packages/bundled-features/src/billing-foundation/checkout-ledger.ts +67 -0
  61. package/packages/bundled-features/src/billing-foundation/consumer-protection/consent-gate.ts +2 -1
  62. package/packages/bundled-features/src/billing-foundation/consumer-protection/consent-text.ts +49 -2
  63. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-open-cancels.ts +5 -0
  64. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-provider-timeout.ts +23 -0
  65. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-record.ts +12 -7
  66. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-revoke.ts +1 -1
  67. package/packages/bundled-features/src/billing-foundation/events.ts +51 -10
  68. package/packages/bundled-features/src/billing-foundation/feature.ts +15 -1
  69. package/packages/bundled-features/src/billing-foundation/handlers/billing-plans.query.ts +47 -14
  70. package/packages/bundled-features/src/billing-foundation/handlers/create-checkout-session.write.ts +9 -1
  71. package/packages/bundled-features/src/billing-foundation/handlers/process-event.write.ts +183 -17
  72. package/packages/bundled-features/src/billing-foundation/handlers/process-payment-event.write.ts +35 -10
  73. package/packages/bundled-features/src/billing-foundation/handlers/record-checkout-opened.write.ts +25 -0
  74. package/packages/bundled-features/src/billing-foundation/handlers/start-plan-checkout.write.ts +9 -1
  75. package/packages/bundled-features/src/billing-foundation/handlers/switch-plan.write.ts +16 -4
  76. package/packages/bundled-features/src/billing-foundation/i18n.ts +3 -0
  77. package/packages/bundled-features/src/billing-foundation/pending-plan-switch.ts +80 -0
  78. package/packages/bundled-features/src/billing-foundation/scrub-raw-payload-headers.ts +50 -0
  79. package/packages/bundled-features/src/billing-foundation/types.ts +47 -30
  80. package/packages/bundled-features/src/billing-foundation/validate-options.ts +18 -0
  81. package/packages/bundled-features/src/billing-foundation/web/billing-plans-panel.tsx +10 -5
  82. package/packages/bundled-features/src/billing-foundation/web/cancel-contract-dialog.tsx +1 -1
  83. package/packages/bundled-features/src/billing-foundation/web/checkout-consent-dialog.tsx +1 -1
  84. package/packages/bundled-features/src/billing-foundation/web/constants.ts +5 -2
  85. package/packages/bundled-features/src/billing-foundation/web/plan-switch-confirm-dialog.tsx +1 -1
  86. package/packages/bundled-features/src/billing-foundation/webhook-handler.ts +65 -17
  87. package/packages/bundled-features/src/cap-counter/aggregate-id.ts +0 -2
  88. package/packages/bundled-features/src/cap-counter/changes.json +6 -0
  89. package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +19 -4
  90. package/packages/bundled-features/src/cap-overview/changes.json +6 -0
  91. package/packages/bundled-features/src/cap-overview/handlers/tenant-caps-list.query.ts +22 -6
  92. package/packages/bundled-features/src/cap-overview/i18n.ts +1 -0
  93. package/packages/bundled-features/src/cap-overview/index.ts +1 -0
  94. package/packages/bundled-features/src/cap-overview/types.ts +11 -1
  95. package/packages/bundled-features/src/cap-overview/web/cap-cards-panel.tsx +6 -2
  96. package/packages/bundled-features/src/cap-overview/web/cap-usage-bar.tsx +10 -1
  97. package/packages/bundled-features/src/cap-overview/web/usage-math.ts +5 -0
  98. package/packages/bundled-features/src/channel-in-app/changes.json +6 -0
  99. package/packages/bundled-features/src/channel-in-app/handlers/read-state-by-keys.query.ts +2 -2
  100. package/packages/bundled-features/src/channel-whatsapp/aggregate-id.ts +29 -0
  101. package/packages/bundled-features/src/channel-whatsapp/changes.json +32 -0
  102. package/packages/bundled-features/src/channel-whatsapp/constants.ts +46 -0
  103. package/packages/bundled-features/src/channel-whatsapp/events.ts +94 -0
  104. package/packages/bundled-features/src/channel-whatsapp/feature.ts +72 -0
  105. package/packages/bundled-features/src/channel-whatsapp/graph-client.ts +398 -0
  106. package/packages/bundled-features/src/channel-whatsapp/in-memory-meta.ts +300 -0
  107. package/packages/bundled-features/src/channel-whatsapp/inbound-handlers.ts +210 -0
  108. package/packages/bundled-features/src/channel-whatsapp/index.ts +66 -0
  109. package/packages/bundled-features/src/channel-whatsapp/meta-signature.ts +26 -0
  110. package/packages/bundled-features/src/channel-whatsapp/options.ts +149 -0
  111. package/packages/bundled-features/src/channel-whatsapp/pii.ts +109 -0
  112. package/packages/bundled-features/src/channel-whatsapp/webhook-normalize.ts +247 -0
  113. package/packages/bundled-features/src/channel-whatsapp/webhook-routes.ts +185 -0
  114. package/packages/bundled-features/src/compliance-profiles/changes.json +5 -0
  115. package/packages/bundled-features/src/compliance-profiles/handlers/set-profile.write.ts +2 -0
  116. package/packages/bundled-features/src/compliance-profiles/handlers/sub-processors.query.ts +1 -1
  117. package/packages/bundled-features/src/config/changes.json +12 -0
  118. package/packages/bundled-features/src/config/handlers/set.write.ts +7 -0
  119. package/packages/bundled-features/src/config/handlers/values.query.ts +8 -1
  120. package/packages/bundled-features/src/config/index.ts +1 -0
  121. package/packages/bundled-features/src/config/read-redaction.ts +6 -3
  122. package/packages/bundled-features/src/config/table.ts +1 -0
  123. package/packages/bundled-features/src/config/write-helpers.ts +3 -2
  124. package/packages/bundled-features/src/crypto-shredding/changes.json +18 -0
  125. package/packages/bundled-features/src/crypto-shredding/constants.ts +2 -0
  126. package/packages/bundled-features/src/crypto-shredding/handlers/forget-subject.write.ts +38 -18
  127. package/packages/bundled-features/src/crypto-shredding/index.ts +4 -0
  128. package/packages/bundled-features/src/crypto-shredding/subject-forget-after-delete-hook.ts +49 -0
  129. package/packages/bundled-features/src/custom-fields/aggregate-id.ts +0 -1
  130. package/packages/bundled-features/src/custom-fields/entity.ts +1 -0
  131. package/packages/bundled-features/src/custom-fields/wire-for-entity.ts +0 -1
  132. package/packages/bundled-features/src/data-retention/changes.json +12 -0
  133. package/packages/bundled-features/src/data-retention/erase-notes-of-deleted-row.ts +23 -0
  134. package/packages/bundled-features/src/data-retention/feature.ts +2 -5
  135. package/packages/bundled-features/src/data-retention/run-retention-cleanup.ts +38 -18
  136. package/packages/bundled-features/src/data-retention/tenant-destruction-hold.ts +9 -0
  137. package/packages/bundled-features/src/delivery/attempt-log-factory.ts +11 -0
  138. package/packages/bundled-features/src/delivery/attempt-log.ts +3 -3
  139. package/packages/bundled-features/src/delivery/changes.json +12 -0
  140. package/packages/bundled-features/src/delivery/channel-context.ts +6 -3
  141. package/packages/bundled-features/src/delivery/db/queries/preferences.ts +0 -1
  142. package/packages/bundled-features/src/delivery/delivery-service.ts +3 -0
  143. package/packages/bundled-features/src/delivery/feature.ts +4 -13
  144. package/packages/bundled-features/src/delivery/handlers/opted-in-user-ids.query.ts +54 -0
  145. package/packages/bundled-features/src/delivery/handlers/preferences.query.ts +2 -20
  146. package/packages/bundled-features/src/delivery/handlers/resubscribe-user.write.ts +2 -25
  147. package/packages/bundled-features/src/delivery/handlers/unsubscribe-page-chrome.query.ts +2 -0
  148. package/packages/bundled-features/src/delivery/handlers/unsubscribe-user.write.ts +2 -27
  149. package/packages/bundled-features/src/delivery/index.ts +3 -1
  150. package/packages/bundled-features/src/delivery/options.ts +11 -0
  151. package/packages/bundled-features/src/delivery/preference-rows.ts +33 -0
  152. package/packages/bundled-features/src/delivery/set-preference-enabled.ts +40 -0
  153. package/packages/bundled-features/src/delivery/testing.ts +3 -1
  154. package/packages/bundled-features/src/delivery/types.ts +1 -0
  155. package/packages/bundled-features/src/delivery/unsubscribe-page.ts +7 -1
  156. package/packages/bundled-features/src/delivery/upsert-preference.ts +0 -1
  157. package/packages/bundled-features/src/delivery/web/public-names.ts +1 -0
  158. package/packages/bundled-features/src/derivatives-sharp/render.ts +9 -9
  159. package/packages/bundled-features/src/document-ingest-foundation/aggregate-id.ts +0 -1
  160. package/packages/bundled-features/src/document-ingest-foundation/append-missing-extract-event.ts +37 -25
  161. package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
  162. package/packages/bundled-features/src/document-ingest-foundation/feature.ts +1 -0
  163. package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +34 -14
  164. package/packages/bundled-features/src/documents/aggregate-id.ts +0 -2
  165. package/packages/bundled-features/src/documents/changes.json +24 -0
  166. package/packages/bundled-features/src/documents/constants.ts +10 -2
  167. package/packages/bundled-features/src/documents/ensure-link.ts +3 -4
  168. package/packages/bundled-features/src/documents/feature.ts +33 -6
  169. package/packages/bundled-features/src/documents/handlers/import.write.ts +2 -2
  170. package/packages/bundled-features/src/documents/queries/expiry-overview.query.ts +2 -1
  171. package/packages/bundled-features/src/documents/queries/for-record.query.ts +3 -4
  172. package/packages/bundled-features/src/documents/queries/list-page.ts +11 -3
  173. package/packages/bundled-features/src/documents/queries/overview.query.ts +2 -2
  174. package/packages/bundled-features/src/documents/screens.ts +8 -3
  175. package/packages/bundled-features/src/documents/tab.ts +1 -1
  176. package/packages/bundled-features/src/feature-toggles/toggle-sync-signal.ts +6 -3
  177. package/packages/bundled-features/src/file-derivatives/handlers/public-variant-by-file-ref.query.ts +1 -1
  178. package/packages/bundled-features/src/file-derivatives/handlers/public-variant.query.ts +1 -1
  179. package/packages/bundled-features/src/file-foundation/probe.ts +9 -3
  180. package/packages/bundled-features/src/file-foundation/read-file-ref-content.ts +24 -11
  181. package/packages/bundled-features/src/file-provider-inmemory/feature.ts +1 -1
  182. package/packages/bundled-features/src/file-provider-s3/changes.json +14 -0
  183. package/packages/bundled-features/src/file-provider-s3/env-feature.ts +1 -1
  184. package/packages/bundled-features/src/file-provider-s3/env-named-feature.ts +1 -1
  185. package/packages/bundled-features/src/file-provider-s3/env-schema.ts +24 -7
  186. package/packages/bundled-features/src/file-provider-s3/feature.ts +1 -1
  187. package/packages/bundled-features/src/file-provider-s3/index.ts +7 -1
  188. package/packages/bundled-features/src/file-provider-s3/lib/env-helper.ts +21 -13
  189. package/packages/bundled-features/src/file-provider-s3/lib/s3-provider.ts +8 -1
  190. package/packages/bundled-features/src/files/changes.json +7 -0
  191. package/packages/bundled-features/src/folders/aggregate-id.ts +0 -1
  192. package/packages/bundled-features/src/folders/web/folder-manager.tsx +6 -6
  193. package/packages/bundled-features/src/folders-user-data/index.ts +12 -14
  194. package/packages/bundled-features/src/form-draft/feature.ts +1 -0
  195. package/packages/bundled-features/src/helpdesk/changes.json +56 -0
  196. package/packages/bundled-features/src/helpdesk/entity.ts +4 -1
  197. package/packages/bundled-features/src/helpdesk/feature.ts +42 -0
  198. package/packages/bundled-features/src/helpdesk/handlers/access.ts +0 -10
  199. package/packages/bundled-features/src/helpdesk/handlers/attempts.ts +7 -14
  200. package/packages/bundled-features/src/helpdesk/handlers/challenge.query.ts +1 -2
  201. package/packages/bundled-features/src/helpdesk/handlers/reply.write.ts +5 -12
  202. package/packages/bundled-features/src/helpdesk/handlers/report.write.ts +4 -10
  203. package/packages/bundled-features/src/helpdesk/handlers/submit.write.ts +5 -12
  204. package/packages/bundled-features/src/helpdesk/index.ts +1 -0
  205. package/packages/bundled-features/src/helpdesk/legacy-contact-config.ts +61 -0
  206. package/packages/bundled-features/src/helpdesk/legacy-contact-erasure.ts +45 -0
  207. package/packages/bundled-features/src/helpdesk/legacy-contact-retention.ts +65 -0
  208. package/packages/bundled-features/src/helpdesk/legacy-contact-streams.ts +187 -0
  209. package/packages/bundled-features/src/helpdesk/legacy-contact-user-data.ts +84 -0
  210. package/packages/bundled-features/src/helpdesk/lib.ts +55 -37
  211. package/packages/bundled-features/src/helpdesk/user-data-hooks.ts +89 -48
  212. package/packages/bundled-features/src/helpdesk/web/constants.ts +0 -1
  213. package/packages/bundled-features/src/inbound-mail-foundation/account-health.ts +1 -1
  214. package/packages/bundled-features/src/inbound-mail-foundation/account-poll.ts +9 -2
  215. package/packages/bundled-features/src/inbound-mail-foundation/aggregate-id.ts +0 -2
  216. package/packages/bundled-features/src/inbound-mail-foundation/changes.json +54 -0
  217. package/packages/bundled-features/src/inbound-mail-foundation/constants.ts +6 -0
  218. package/packages/bundled-features/src/inbound-mail-foundation/content-refetch.ts +23 -2
  219. package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +73 -15
  220. package/packages/bundled-features/src/inbound-mail-foundation/events.ts +24 -16
  221. package/packages/bundled-features/src/inbound-mail-foundation/feature.ts +3 -1
  222. package/packages/bundled-features/src/inbound-mail-foundation/handlers/account-address.ts +16 -2
  223. package/packages/bundled-features/src/inbound-mail-foundation/handlers/attach-message-content.write.ts +10 -3
  224. package/packages/bundled-features/src/inbound-mail-foundation/handlers/connect-account.write.ts +23 -9
  225. package/packages/bundled-features/src/inbound-mail-foundation/handlers/forget-message.write.ts +79 -0
  226. package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message-schema.ts +18 -5
  227. package/packages/bundled-features/src/inbound-mail-foundation/i18n.ts +3 -0
  228. package/packages/bundled-features/src/inbound-mail-foundation/index.ts +1 -0
  229. package/packages/bundled-features/src/inbound-mail-foundation/normalize-inbound-message.ts +22 -8
  230. package/packages/bundled-features/src/inbound-mail-foundation/oauth-access-token.ts +1 -1
  231. package/packages/bundled-features/src/inbound-mail-foundation/outbound-mail.ts +2 -0
  232. package/packages/bundled-features/src/inbound-mail-foundation/personal-address.ts +20 -0
  233. package/packages/bundled-features/src/inbound-mail-foundation/purge-messages.ts +54 -0
  234. package/packages/bundled-features/src/inbound-mail-foundation/quarantine.ts +15 -5
  235. package/packages/bundled-features/src/inbound-mail-foundation/retention-job.ts +1 -5
  236. package/packages/bundled-features/src/inbound-mail-foundation/retention-sweep.ts +21 -34
  237. package/packages/bundled-features/src/inbound-mail-foundation/sanitize-inbound-html.ts +2 -5
  238. package/packages/bundled-features/src/inbound-mail-foundation/send-from-account.ts +9 -1
  239. package/packages/bundled-features/src/inbound-mail-foundation/supervisor-ingest.ts +7 -1
  240. package/packages/bundled-features/src/inbound-mail-foundation/sync-account-now.ts +1 -1
  241. package/packages/bundled-features/src/inbound-mail-foundation/tenant-destroy-hook.ts +14 -17
  242. package/packages/bundled-features/src/inbound-mail-foundation/watch-supervisor.ts +1 -1
  243. package/packages/bundled-features/src/inbound-provider-imap/byte-budget.ts +80 -0
  244. package/packages/bundled-features/src/inbound-provider-imap/changes.json +13 -0
  245. package/packages/bundled-features/src/inbound-provider-imap/connect-mailbox.ts +8 -4
  246. package/packages/bundled-features/src/inbound-provider-imap/connect-my-mailbox.ts +23 -6
  247. package/packages/bundled-features/src/inbound-provider-imap/connect-target-rate-limit.ts +46 -0
  248. package/packages/bundled-features/src/inbound-provider-imap/download-batch.ts +47 -10
  249. package/packages/bundled-features/src/inbound-provider-imap/feature.ts +7 -4
  250. package/packages/bundled-features/src/inbound-provider-imap/fetch-content.ts +43 -29
  251. package/packages/bundled-features/src/inbound-provider-imap/i18n.ts +2 -2
  252. package/packages/bundled-features/src/inbound-provider-imap/parse-message.ts +14 -0
  253. package/packages/bundled-features/src/inbound-provider-imap/reconnect-mailbox.ts +5 -4
  254. package/packages/bundled-features/src/inbound-provider-imap/send-mail.ts +39 -7
  255. package/packages/bundled-features/src/inbound-provider-imap/smtp-client.ts +19 -4
  256. package/packages/bundled-features/src/inbound-provider-imap/watch-mailbox.ts +8 -23
  257. package/packages/bundled-features/src/inbound-provider-inmemory/feature.ts +1 -1
  258. package/packages/bundled-features/src/jobs/events.ts +10 -0
  259. package/packages/bundled-features/src/jobs/feature.ts +2 -0
  260. package/packages/bundled-features/src/jobs/handlers/consumer.write.ts +41 -16
  261. package/packages/bundled-features/src/jobs/web/constants.ts +4 -0
  262. package/packages/bundled-features/src/mail-foundation/changes.json +6 -0
  263. package/packages/bundled-features/src/mail-transport-inmemory/feature.ts +1 -1
  264. package/packages/bundled-features/src/mail-transport-smtp/feature.ts +3 -2
  265. package/packages/bundled-features/src/managed-pages/changes.json +12 -0
  266. package/packages/bundled-features/src/managed-pages/handlers/branding.query.ts +1 -1
  267. package/packages/bundled-features/src/managed-pages/handlers/by-slug.query.ts +1 -1
  268. package/packages/bundled-features/src/managed-pages/handlers/by-tenant-published.query.ts +1 -1
  269. package/packages/bundled-features/src/managed-pages/render-page-body.ts +18 -10
  270. package/packages/bundled-features/src/managed-pages/screens/page-screens.ts +18 -38
  271. package/packages/bundled-features/src/managed-pages/table.ts +1 -0
  272. package/packages/bundled-features/src/managed-pages/web/client-plugin.tsx +8 -6
  273. package/packages/bundled-features/src/managed-pages/web/constants.ts +8 -1
  274. package/packages/bundled-features/src/managed-pages/web/i18n.ts +11 -3
  275. package/packages/bundled-features/src/managed-pages/web/markdown-to-document.ts +1 -1
  276. package/packages/bundled-features/src/managed-pages/web/page-edit-draft.ts +108 -0
  277. package/packages/bundled-features/src/managed-pages/web/page-edit-screen.tsx +204 -0
  278. package/packages/bundled-features/src/managed-pages/web/page-settings-rail.tsx +117 -0
  279. package/packages/bundled-features/src/notes-history-user-data/index.ts +8 -14
  280. package/packages/bundled-features/src/personal-access-tokens/boot-rules.ts +5 -0
  281. package/packages/bundled-features/src/personal-access-tokens/handlers/create.write.ts +0 -1
  282. package/packages/bundled-features/src/personal-access-tokens/scope-events-check.ts +31 -5
  283. package/packages/bundled-features/src/presence/changes.json +6 -0
  284. package/packages/bundled-features/src/presence/handlers/list.query.ts +28 -11
  285. package/packages/bundled-features/src/presence/room.ts +21 -7
  286. package/packages/bundled-features/src/presence/store.ts +79 -21
  287. package/packages/bundled-features/src/readiness/changes.json +25 -0
  288. package/packages/bundled-features/src/readiness/handlers/latest-summary.query.ts +11 -6
  289. package/packages/bundled-features/src/readiness/handlers/run-probes.write.ts +35 -5
  290. package/packages/bundled-features/src/readiness/handlers/run-tone.ts +3 -2
  291. package/packages/bundled-features/src/readiness/handlers/status.query.ts +15 -1
  292. package/packages/bundled-features/src/readiness/probe-context.ts +11 -10
  293. package/packages/bundled-features/src/readiness/screens.ts +4 -4
  294. package/packages/bundled-features/src/readiness/visible-results.ts +5 -3
  295. package/packages/bundled-features/src/renderer-foundation/api.ts +6 -13
  296. package/packages/bundled-features/src/renderer-foundation/types.ts +2 -2
  297. package/packages/bundled-features/src/secrets/changes.json +7 -0
  298. package/packages/bundled-features/src/secrets/db/queries/read.ts +18 -4
  299. package/packages/bundled-features/src/secrets/handlers/list.query.ts +8 -2
  300. package/packages/bundled-features/src/secrets/secret-scope.ts +2 -3
  301. package/packages/bundled-features/src/secrets/secrets-context.ts +6 -4
  302. package/packages/bundled-features/src/secrets/write-gate.ts +4 -2
  303. package/packages/bundled-features/src/seo/handlers/seo-config.query.ts +1 -1
  304. package/packages/bundled-features/src/shared/acknowledged-system-db.ts +20 -0
  305. package/packages/bundled-features/src/shared/assert-billing-live.ts +9 -2
  306. package/packages/bundled-features/src/shared/changes.json +12 -0
  307. package/packages/bundled-features/src/shared/hmac-signature.ts +4 -2
  308. package/packages/bundled-features/src/shared/index.ts +7 -1
  309. package/packages/bundled-features/src/shared/normalize-email.ts +3 -0
  310. package/packages/bundled-features/src/shared/parent-visibility.ts +25 -1
  311. package/packages/bundled-features/src/shared/password-hashing.ts +0 -1
  312. package/packages/bundled-features/src/shared/price-env-shape.ts +1 -4
  313. package/packages/bundled-features/src/shared/register-user-data-hooks.ts +29 -0
  314. package/packages/bundled-features/src/shared/require-bootstrap-extension.ts +26 -0
  315. package/packages/bundled-features/src/shared/send-best-effort.ts +29 -0
  316. package/packages/bundled-features/src/shared/stream-tenant-backfill.ts +22 -1
  317. package/packages/bundled-features/src/shared/stream-tenant-derived-state.ts +31 -1
  318. package/packages/bundled-features/src/step-dispatcher/changes.json +18 -0
  319. package/packages/bundled-features/src/step-dispatcher/constants.ts +13 -0
  320. package/packages/bundled-features/src/step-dispatcher/deliver-dispatch-request.ts +50 -2
  321. package/packages/bundled-features/src/step-dispatcher/feature.ts +42 -1
  322. package/packages/bundled-features/src/step-dispatcher/mail-runner.ts +0 -1
  323. package/packages/bundled-features/src/step-dispatcher/sweep-abandoned.ts +61 -0
  324. package/packages/bundled-features/src/subscription-mollie/changes.json +7 -0
  325. package/packages/bundled-features/src/subscription-mollie/plugin-methods.ts +5 -3
  326. package/packages/bundled-features/src/subscription-mollie/verify-webhook.ts +5 -5
  327. package/packages/bundled-features/src/subscription-paddle/backfill-checkout-ledger.ts +161 -0
  328. package/packages/bundled-features/src/subscription-paddle/changes.json +19 -0
  329. package/packages/bundled-features/src/subscription-paddle/checkout-config.query.ts +1 -1
  330. package/packages/bundled-features/src/subscription-paddle/checkout-methods.ts +2 -8
  331. package/packages/bundled-features/src/subscription-paddle/constants.ts +1 -2
  332. package/packages/bundled-features/src/subscription-paddle/feature.ts +26 -24
  333. package/packages/bundled-features/src/subscription-paddle/ledger-backfill-marker.ts +70 -0
  334. package/packages/bundled-features/src/subscription-paddle/plan-switch-methods.ts +2 -8
  335. package/packages/bundled-features/src/subscription-paddle/redeliver-legacy-checkout.ts +57 -0
  336. package/packages/bundled-features/src/subscription-paddle/runtime.ts +13 -24
  337. package/packages/bundled-features/src/subscription-paddle/subscription-state.ts +1 -0
  338. package/packages/bundled-features/src/subscription-paddle/webhook-events.ts +68 -21
  339. package/packages/bundled-features/src/subscription-stripe/changes.json +13 -0
  340. package/packages/bundled-features/src/subscription-stripe/feature.ts +5 -0
  341. package/packages/bundled-features/src/subscription-stripe/plugin-methods.ts +6 -6
  342. package/packages/bundled-features/src/subscription-stripe/runtime.ts +8 -7
  343. package/packages/bundled-features/src/subscription-stripe/verify-webhook.ts +38 -6
  344. package/packages/bundled-features/src/tags/aggregate-id.ts +0 -1
  345. package/packages/bundled-features/src/tags/web/tag-chip.tsx +4 -5
  346. package/packages/bundled-features/src/tags/web/tag-manager.tsx +2 -1
  347. package/packages/bundled-features/src/template-resolver/api.ts +6 -13
  348. package/packages/bundled-features/src/template-resolver/changes.json +48 -0
  349. package/packages/bundled-features/src/template-resolver/document-sanitizer.ts +25 -0
  350. package/packages/bundled-features/src/template-resolver/feature.ts +2 -0
  351. package/packages/bundled-features/src/template-resolver/handlers/body-preview.query.ts +41 -0
  352. package/packages/bundled-features/src/template-resolver/handlers/by-slug.query.ts +1 -1
  353. package/packages/bundled-features/src/template-resolver/handlers/by-tenant.query.ts +1 -1
  354. package/packages/bundled-features/src/template-resolver/handlers/collection-shared.ts +5 -11
  355. package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +3 -2
  356. package/packages/bundled-features/src/template-resolver/handlers/send-test.write.ts +37 -8
  357. package/packages/bundled-features/src/template-resolver/linked-resources.ts +2 -5
  358. package/packages/bundled-features/src/template-resolver/seeding.ts +107 -0
  359. package/packages/bundled-features/src/template-resolver/table.ts +1 -0
  360. package/packages/bundled-features/src/template-resolver/template-draft.ts +2 -1
  361. package/packages/bundled-features/src/template-resolver/template-preview.ts +14 -3
  362. package/packages/bundled-features/src/template-resolver/testing.ts +0 -2
  363. package/packages/bundled-features/src/template-resolver/web/client-plugin.tsx +3 -0
  364. package/packages/bundled-features/src/template-resolver/web/collection-entry-create-form.tsx +33 -33
  365. package/packages/bundled-features/src/template-resolver/web/constants.ts +7 -0
  366. package/packages/bundled-features/src/template-resolver/web/content-tree-provider.ts +0 -1
  367. package/packages/bundled-features/src/template-resolver/web/content-workbench.tsx +142 -0
  368. package/packages/bundled-features/src/template-resolver/web/document-insert-model.ts +3 -8
  369. package/packages/bundled-features/src/template-resolver/web/document-link-policy.ts +58 -0
  370. package/packages/bundled-features/src/template-resolver/web/document-schema.ts +11 -57
  371. package/packages/bundled-features/src/template-resolver/web/document-tiptap-bubble.tsx +2 -4
  372. package/packages/bundled-features/src/template-resolver/web/document-tiptap-context.ts +4 -5
  373. package/packages/bundled-features/src/template-resolver/web/document-tiptap-editor.tsx +2 -2
  374. package/packages/bundled-features/src/template-resolver/web/document-tiptap-helpers.ts +6 -3
  375. package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar-groups.tsx +2 -3
  376. package/packages/bundled-features/src/template-resolver/web/editor-handle.ts +1 -0
  377. package/packages/bundled-features/src/template-resolver/web/fill-document-variables.ts +24 -0
  378. package/packages/bundled-features/src/template-resolver/web/i18n.ts +14 -0
  379. package/packages/bundled-features/src/template-resolver/web/index.ts +3 -0
  380. package/packages/bundled-features/src/template-resolver/web/preview-targets.ts +25 -0
  381. package/packages/bundled-features/src/template-resolver/web/qualified-names.ts +1 -0
  382. package/packages/bundled-features/src/template-resolver/web/snippet-preview-renderer.tsx +24 -0
  383. package/packages/bundled-features/src/template-resolver/web/string-values.ts +7 -0
  384. package/packages/bundled-features/src/template-resolver/web/text-block-editor.tsx +38 -50
  385. package/packages/bundled-features/src/template-resolver/web/use-collection-entry-create.ts +7 -0
  386. package/packages/bundled-features/src/template-resolver/web/use-content-write.ts +1 -3
  387. package/packages/bundled-features/src/template-resolver/web/use-document-tiptap-model.ts +1 -2
  388. package/packages/bundled-features/src/template-resolver/web/use-text-block-editor.ts +28 -7
  389. package/packages/bundled-features/src/template-resolver/web/web-preview-renderer.tsx +132 -0
  390. package/packages/bundled-features/src/template-resolver-user-data/index.ts +11 -10
  391. package/packages/bundled-features/src/tenant/changes.json +6 -0
  392. package/packages/bundled-features/src/tenant/handlers/create.write.ts +7 -8
  393. package/packages/bundled-features/src/tenant/handlers/list.query.ts +7 -9
  394. package/packages/bundled-features/src/tenant/handlers/member-directory.query.ts +10 -4
  395. package/packages/bundled-features/src/tenant/handlers/toggle-enabled.write.ts +1 -1
  396. package/packages/bundled-features/src/tenant/invited-membership.ts +10 -1
  397. package/packages/bundled-features/src/tenant/seeding.ts +4 -2
  398. package/packages/bundled-features/src/tenant/stream-tenant-backfill.ts +5 -1
  399. package/packages/bundled-features/src/tenant/testing.ts +1 -1
  400. package/packages/bundled-features/src/tenant-inactivity/changes.json +6 -0
  401. package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +36 -17
  402. package/packages/bundled-features/src/tenant-inactivity/constants.ts +1 -2
  403. package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +7 -2
  404. package/packages/bundled-features/src/tenant-inactivity/state-store.ts +22 -2
  405. package/packages/bundled-features/src/tenant-lifecycle/changes.json +24 -0
  406. package/packages/bundled-features/src/tenant-lifecycle/constants.ts +4 -0
  407. package/packages/bundled-features/src/tenant-lifecycle/feature.ts +1 -0
  408. package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +43 -6
  409. package/packages/bundled-features/src/tenant-lifecycle/stages.ts +15 -2
  410. package/packages/bundled-features/src/tier-engine/aggregate-id.ts +0 -1
  411. package/packages/bundled-features/src/tier-engine/changes.json +6 -0
  412. package/packages/bundled-features/src/tier-engine/feature.ts +8 -2
  413. package/packages/bundled-features/src/user/changes.json +6 -0
  414. package/packages/bundled-features/src/user/db/queries/stream-tenant-backfill.ts +2 -1
  415. package/packages/bundled-features/src/user/handlers/me.query.ts +3 -1
  416. package/packages/bundled-features/src/user/index.ts +1 -0
  417. package/packages/bundled-features/src/user/resolve-verified-user-email.ts +17 -0
  418. package/packages/bundled-features/src/user-data-rights/db/queries/export-jobs.ts +0 -1
  419. package/packages/bundled-features/src/user-data-rights/feature.ts +1 -0
  420. package/packages/bundled-features/src/user-data-rights/handlers/confirm-deletion-by-token.write.ts +1 -1
  421. package/packages/bundled-features/src/user-data-rights/handlers/download-by-token.query.ts +1 -1
  422. package/packages/bundled-features/src/user-data-rights/handlers/request-deletion-by-email.write.ts +1 -1
  423. package/packages/bundled-features/src/user-data-rights/run-export-jobs.ts +0 -2
  424. package/packages/bundled-features/src/user-data-rights/run-forget-cleanup.ts +3 -3
  425. package/packages/bundled-features/src/user-data-rights/schema/download-attempt.ts +3 -2
  426. package/packages/bundled-features/src/user-data-rights/web/confirm-deletion-screen.tsx +1 -1
  427. package/packages/bundled-features/src/user-data-rights/web/privacy-center-screen.tsx +1 -1
  428. package/packages/bundled-features/src/user-data-rights/web/request-deletion-screen.tsx +1 -1
  429. package/packages/bundled-features/src/user-data-rights-defaults/hooks/api-token.userdata-hook.ts +5 -5
  430. package/packages/bundled-features/src/user-data-rights-defaults/hooks/hard-delete-own-rows-hook.ts +17 -0
  431. package/packages/bundled-features/src/user-data-rights-defaults/hooks/in-app-message.userdata-hook.ts +5 -5
  432. package/packages/bundled-features/src/user-data-rights-defaults/hooks/job-run.userdata-hook.ts +2 -1
  433. package/packages/bundled-features/src/user-data-rights-defaults/hooks/user-session.userdata-hook.ts +5 -5
  434. package/packages/bundled-features/src/user-profile/handlers/change-email.write.ts +0 -1
  435. package/packages/bundled-features/src/waitlist/changes.json +6 -0
  436. package/packages/bundled-features/src/waitlist/handlers/reject.write.ts +1 -1
  437. package/packages/bundled-features/src/waitlist/handlers/submit.write.ts +5 -29
  438. package/packages/bundled-features/src/waitlist/import.ts +2 -1
  439. package/packages/bundled-features/src/waitlist/lib.ts +2 -11
  440. package/packages/bundled-features/src/waitlist/link-on-signup.ts +2 -2
  441. package/packages/bundled-features/src/waitlist/user-data-hooks.ts +6 -19
  442. package/packages/bundled-features/src/workflow-runner/aggregate-id.ts +0 -1
  443. package/packages/bundled-features/src/workflow-runner/changes.json +6 -0
  444. package/packages/bundled-features/src/workflow-runner/event-trigger.ts +6 -2
  445. package/packages/bundled-features/src/workflow-runner/feature.ts +1 -5
  446. package/packages/bundled-features/src/workflow-runner/handlers/resume-run.write.ts +7 -4
  447. package/packages/bundled-features/src/workflow-runner/runner.ts +2 -0
  448. package/samples/apps/admin-console/src/app/shell.tsx +1 -0
  449. package/samples/apps/showcase/src/features/demos/web/pages/dialog.tsx +0 -1
  450. package/samples/apps/showcase/src/features/demos/web/pages/layout.tsx +1 -1
  451. package/samples/apps/showcase/src/features/demos/web/pages/sidebar-panel.tsx +0 -1
  452. package/samples/apps/styleguide/src/features/gallery/web/Gallery.tsx +1 -4
  453. package/samples/apps/ui-walkthrough/src/features/subscription-plans/feature.ts +6 -2
  454. package/samples/apps/use-all-bundled/e2e-billing-gallery/gallery-features.ts +12 -14
  455. package/samples/apps/use-all-bundled/feature-manifest.json +60 -29
  456. package/samples/apps/use-all-bundled/playwright.billing-docs.config.ts +1 -1
  457. package/samples/apps/use-all-bundled/playwright.config.ts +1 -0
  458. package/samples/apps/use-all-bundled/src/app/seed.ts +1 -1
  459. package/samples/apps/use-all-bundled/src/run-config.ts +2 -1
  460. package/samples/recipes/auth-mfa/src/web/confirmation-code-step.tsx +32 -10
  461. package/samples/recipes/chat-channels/README.md +2 -0
  462. package/samples/recipes/crypto-shredding-hr/README.md +11 -0
  463. package/samples/recipes/crypto-shredding-hr/src/feature.ts +27 -0
  464. package/samples/recipes/currencies-global/src/entities/currency.ts +1 -0
  465. package/samples/recipes/managed-pages/README.md +5 -1
  466. package/samples/recipes/managed-pages/package.json +3 -2
  467. package/samples/recipes/managed-pages/src/web/branded-preview.tsx +21 -0
  468. package/samples/recipes/managed-pages/tsconfig.json +8 -0
  469. package/samples/recipes/pwa-shell/README.md +52 -0
  470. package/samples/recipes/pwa-shell/bin/server.ts +12 -0
  471. package/samples/recipes/pwa-shell/package.json +13 -0
  472. package/samples/recipes/pwa-shell/src/app.ts +34 -0
  473. package/samples/recipes/rate-limiting/README.md +3 -3
  474. package/samples/recipes/record-detail-layout/README.md +33 -0
  475. package/samples/recipes/record-detail-layout/src/feature.ts +556 -44
  476. package/samples/recipes/record-detail-layout/src/order-board.ts +529 -0
  477. package/packages/bundled-features/src/managed-pages/web/page-body-section.tsx +0 -72
  478. package/packages/bundled-features/src/subscription-paddle/tenant-binding.ts +0 -34
  479. package/packages/bundled-features/src/template-resolver/web/content-field.tsx +0 -61
@@ -104,10 +104,24 @@ function isDetailHandlerQn(qn: string, entityName: string): boolean {
104
104
  * `resolveAgentExposure` never runs for them. Only an EXPLICIT opt-out may hide one here —
105
105
  * the resolver's own default is fail-closed on a missing `description`, and CRUD-generated
106
106
  * handlers never carry one, so reusing it would delete every entity tool in every app. */
107
- export function isExplicitlyAgentHidden(def: QueryHandlerDef): boolean {
107
+ function isExplicitlyAgentHidden(def: QueryHandlerDef): boolean {
108
108
  return def.agent?.expose === false;
109
109
  }
110
110
 
111
+ /** The entity a query handler serves to this role as a registry-derived tool, if any. The
112
+ * manifest and the catalog both decide entity reachability through this one rule. */
113
+ export function reachableQueryEntity(
114
+ registry: Pick<RegistrySearchView, "getHandlerEntity">,
115
+ qn: string,
116
+ def: QueryHandlerDef,
117
+ roleFilter: { roles: readonly string[] },
118
+ denyQns: ReadonlySet<string>,
119
+ ): string | undefined {
120
+ const entityName = registry.getHandlerEntity(qn);
121
+ if (entityName === undefined || denyQns.has(qn) || isExplicitlyAgentHidden(def)) return undefined;
122
+ return hasAccess(roleFilter, def.access) ? entityName : undefined;
123
+ }
124
+
111
125
  /** The model's filters feed the WHERE clause, and only the output is field-filtered — a field
112
126
  * whose read access is role- or row-restricted would leak through `totalCount` and hit/miss
113
127
  * probing. Only fields every one of these roles may read without a row condition are offered. */
@@ -431,10 +445,8 @@ function addRegistrySearchTools(
431
445
  sink: CatalogSink,
432
446
  ): void {
433
447
  for (const [qn, def] of registry.getAllQueryHandlers()) {
434
- const entityName = registry.getHandlerEntity(qn);
448
+ const entityName = reachableQueryEntity(registry, qn, def, roleFilter, denyQns);
435
449
  if (!entityName || !isListHandlerQn(qn, entityName)) continue;
436
- if (denyQns.has(qn) || isExplicitlyAgentHidden(def)) continue;
437
- if (!hasAccess(roleFilter, def.access)) continue;
438
450
 
439
451
  const entity = registry.getEntity(entityName);
440
452
  if (!entity) continue;
@@ -466,9 +478,8 @@ function collectEntityHandlerQns(
466
478
  if (isListHandlerQn(qn, entityName)) entityListDetailQns.add(qn);
467
479
  }
468
480
  for (const [qn, def] of registry.getAllQueryHandlers()) {
469
- const entityName = registry.getHandlerEntity(qn);
470
- if (!entityName || !hasAccess(roleFilter, def.access)) continue;
471
- if (denyQns.has(qn) || isExplicitlyAgentHidden(def)) continue;
481
+ const entityName = reachableQueryEntity(registry, qn, def, roleFilter, denyQns);
482
+ if (!entityName) continue;
472
483
  if (isDetailHandlerQn(qn, entityName)) detailQnByEntity.set(entityName, qn);
473
484
  if (isListHandlerQn(qn, entityName)) listQnByEntity.set(entityName, qn);
474
485
  }
@@ -303,7 +303,16 @@ async function dispatchServerWrite(
303
303
  return invalidToolCall(`This tool requires a non-empty string "id" argument`);
304
304
  }
305
305
  if (!descriptor.detailQn) {
306
- return invalidToolCall("Tool is misconfigured: no detail handler to read version from");
306
+ const message = `Tool ${descriptor.qn} injects a version but has no detail handler to read it from`;
307
+ return classifyFailure(
308
+ {
309
+ code: "internal_error",
310
+ httpStatus: HTTP_SERVER_ERROR,
311
+ message,
312
+ retryAfterSeconds: undefined,
313
+ },
314
+ new Error(message),
315
+ );
307
316
  }
308
317
  const current = await dispatcher.query(descriptor.detailQn, { id }, user);
309
318
  const version =
@@ -423,6 +432,10 @@ function dispatchClient(
423
432
  return dispatchClientOpenForm(descriptor, input);
424
433
  case "ask_user":
425
434
  return dispatchClientAskUser(input);
435
+ default: {
436
+ const exhaustiveCheck: never = descriptor;
437
+ return exhaustiveCheck;
438
+ }
426
439
  }
427
440
  }
428
441
 
@@ -221,6 +221,10 @@ export type RegistryManifestView = {
221
221
  getAllQueryHandlers(): ReadonlyMap<string, QueryHandlerDef>;
222
222
  getAllWriteHandlers(): ReadonlyMap<string, WriteHandlerDef>;
223
223
  getHandlerEntity(qualifiedHandler: string): string | undefined;
224
+ getHandlerFeature(qualifiedHandler: string): string | undefined;
225
+ getScreenFeature(qualifiedName: string): string | undefined;
226
+ getNavFeature(qualifiedName: string): string | undefined;
227
+ getWorkspaceFeature(qualifiedName: string): string | undefined;
224
228
  getSearchableFields(entityName: string): readonly string[];
225
229
  getAllTranslations(): TranslationKeys;
226
230
  getAllScreens(): ReadonlyMap<string, ScreenDefinition>;
@@ -20,6 +20,9 @@ export const AUDIT_EVENT_STANCES: Readonly<Record<string, AuditEventStance>> = {
20
20
  "inbound-mail-foundation:event:inbound-message-received": TECHNICAL_EVENT,
21
21
  "inbound-mail-foundation:event:inbound-message-content-fetched": TECHNICAL_EVENT,
22
22
  "inbound-mail-foundation:event:mail-thread-updated": TECHNICAL_EVENT,
23
+ "channel-whatsapp:event:message-received": TECHNICAL_EVENT,
24
+ "channel-whatsapp:event:status-updated": TECHNICAL_EVENT,
25
+ "channel-whatsapp:event:throttled": TECHNICAL_EVENT,
23
26
  "document-ingest-foundation:event:document-ingest-progress": TECHNICAL_EVENT,
24
27
  "document-ingest-foundation:event:document-ingest-requested": TECHNICAL_EVENT,
25
28
  "document-ingest-foundation:event:document-ingest-skipped": TECHNICAL_EVENT,
@@ -47,6 +50,8 @@ export const AUDIT_EVENT_STANCES: Readonly<Record<string, AuditEventStance>> = {
47
50
  "billing-foundation:event:invoice-payment-failed": label("invoice-payment-failed"),
48
51
  "billing-foundation:event:payment-received": label("payment-received"),
49
52
  "billing-foundation:event:checkout-consent-recorded": label("checkout-consent-recorded"),
53
+ "billing-foundation:event:checkout-opened": TECHNICAL_EVENT,
54
+ "subscription-paddle:event:ledger-backfill-sweep-completed": TECHNICAL_EVENT,
50
55
  "billing-foundation:event:contract-confirmation-issued": label("contract-confirmation-issued"),
51
56
  "billing-foundation:event:contract-termination-requested": label(
52
57
  "contract-termination-requested",
@@ -65,6 +70,7 @@ export const AUDIT_EVENT_STANCES: Readonly<Record<string, AuditEventStance>> = {
65
70
  "waitlist:event:exported": label("waitlist-exported"),
66
71
  "waitlist:event:purged": label("waitlist-purged"),
67
72
  "feature-toggles:event:toggle-set": label("feature-toggle-set"),
73
+ "jobs:event:consumer-state-changed": label("consumer-state-changed"),
68
74
  };
69
75
 
70
76
  // Streams whose payload holds rows that only a SystemAdmin or a single owner may read: a
@@ -62,6 +62,7 @@ export const AUDIT_I18N: Readonly<Record<string, LocalizedString>> = {
62
62
  "audit.log.event.waitlist-exported": { en: "Waitlist exported" },
63
63
  "audit.log.event.waitlist-purged": { en: "Waitlist purged" },
64
64
  "audit.log.event.feature-toggle-set": { en: "Feature toggle changed" },
65
+ "audit.log.event.consumer-state-changed": { en: "Event consumer state changed" },
65
66
  "audit.log.event.contract-termination-requested": { en: "Contract termination requested" },
66
67
  "audit.log.event.contract-termination-declared": { en: "Contract termination declared" },
67
68
  "audit.log.event.contract-termination-unmatched": { en: "Contract termination not matched" },
@@ -1,4 +1,22 @@
1
1
  [
2
+ {
3
+ "version": "0.414.0",
4
+ "type": "fix",
5
+ "title": "Foreign-member check with one limited query",
6
+ "detail": "auth-email-password checks for foreign members with one limited query."
7
+ },
8
+ {
9
+ "version": "0.414.0",
10
+ "type": "fix",
11
+ "title": "Logout navigates once and no longer races a login redirect",
12
+ "detail": "In the browser `logout()` leaves the session state untouched and either assigns `postLogoutUrl` or reloads the page. Before, the reload path first flipped the state to unauthenticated, which let an `AuthGate` with `loginUrl` start its own redirect against the reload (aborted navigation, flaky e2e). Without `window` (native, SSR) the state is still set to unauthenticated."
13
+ },
14
+ {
15
+ "version": "0.414.0",
16
+ "type": "fix",
17
+ "title": "boot admin seed ignores unverified accounts that squat the seed email",
18
+ "detail": "`seedAdminGuarded` (demoAdmin, sysadmin, auth.admin boot seeds) reconciled `emailVerified` and added memberships for any existing account with the seed email, so a self-registered, unverified account with a foreign password became the admin on the next boot. For an existing row it now requires `emailVerified === true` or a seed password that verifies against the stored hash; otherwise it logs a warning and returns the id untouched. An explicit caller guard (`seedBootstrapAdmin`, passwordless own account) still replaces this check."
19
+ },
2
20
  {
3
21
  "version": "0.411.0",
4
22
  "type": "improvement",
@@ -1,47 +1,38 @@
1
1
  import { unprocessable } from "../shared/index.ts";
2
2
  import { AuthErrors } from "./web/constants.ts";
3
3
 
4
- // @wrapper-known error-helper
5
4
  export function invalidCredentials() {
6
5
  return unprocessable(AuthErrors.invalidCredentials, "auth.errors.invalidCredentials");
7
6
  }
8
7
 
9
- // @wrapper-known error-helper
10
8
  export function invalidInviteToken() {
11
9
  return unprocessable(AuthErrors.invalidInviteToken, "auth.errors.invalidInviteToken");
12
10
  }
13
11
 
14
- // @wrapper-known error-helper
15
12
  export function inviteEmailMismatch() {
16
13
  return unprocessable(AuthErrors.inviteEmailMismatch, "auth.errors.inviteEmailMismatch");
17
14
  }
18
15
 
19
- // @wrapper-known error-helper
20
16
  export function inviteAlreadyAccepted() {
21
17
  return unprocessable(AuthErrors.inviteAlreadyAccepted, "auth.errors.inviteAlreadyAccepted");
22
18
  }
23
19
 
24
- // @wrapper-known error-helper
25
20
  export function invalidResetToken() {
26
21
  return unprocessable(AuthErrors.invalidResetToken, "auth.errors.invalidResetToken");
27
22
  }
28
23
 
29
- // @wrapper-known error-helper
30
24
  export function invalidUnlockToken() {
31
25
  return unprocessable(AuthErrors.invalidUnlockToken, "auth.errors.invalidUnlockToken");
32
26
  }
33
27
 
34
- // @wrapper-known error-helper
35
28
  export function invalidVerificationToken() {
36
29
  return unprocessable(AuthErrors.invalidVerificationToken, "auth.errors.invalidVerificationToken");
37
30
  }
38
31
 
39
- // @wrapper-known error-helper
40
32
  export function invalidSignupToken() {
41
33
  return unprocessable(AuthErrors.invalidSignupToken, "auth.errors.invalidSignupToken");
42
34
  }
43
35
 
44
- // @wrapper-known error-helper
45
36
  export function signupEmailAlreadyRegistered() {
46
37
  return unprocessable(
47
38
  AuthErrors.signupEmailAlreadyRegistered,
@@ -49,25 +40,21 @@ export function signupEmailAlreadyRegistered() {
49
40
  );
50
41
  }
51
42
 
52
- // @wrapper-known error-helper
53
43
  export function noMembership() {
54
44
  return unprocessable(AuthErrors.noMembership, "auth.errors.noMembership");
55
45
  }
56
46
 
57
- // @wrapper-known error-helper
58
47
  export function emailNotVerified() {
59
48
  return unprocessable(AuthErrors.emailNotVerified, "auth.errors.emailNotVerified");
60
49
  }
61
50
 
62
51
  // retryAfterSeconds drives the login/signup UI countdown — must stay > 0.
63
- // @wrapper-known error-helper
64
52
  export function accountLocked(retryAfterSeconds: number) {
65
53
  return unprocessable(AuthErrors.accountLocked, "auth.errors.accountLocked", {
66
54
  retryAfterSeconds,
67
55
  });
68
56
  }
69
57
 
70
- // @wrapper-known error-helper
71
58
  export function accountRestricted() {
72
59
  return unprocessable(AuthErrors.accountRestricted, "auth.errors.accountRestricted");
73
60
  }
@@ -27,8 +27,10 @@ import {
27
27
  buildSessionRoles,
28
28
  createSystemUser,
29
29
  defineWriteHandler,
30
+ type HandlerContext,
30
31
  type SessionUser,
31
32
  type TenantId,
33
+ type WriteResult,
32
34
  } from "@cosmicdrift/kumiko-framework/engine";
33
35
  import { InternalError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
34
36
  import * as z from "zod";
@@ -115,131 +117,16 @@ export function createInviteSignupCompleteHandler(opts: InviteSignupCompleteOpti
115
117
  const burn = await burnInviteToken(ctx.services.redis, event.payload.token);
116
118
  if (burn === "already-used") return invalidInviteToken();
117
119
 
118
- type InvitationRow = {
119
- readonly status: string;
120
- readonly tenantId: TenantId;
121
- readonly email: string;
122
- readonly role: string;
123
- readonly globalRoles: unknown;
124
- readonly version: number;
125
- };
126
-
127
120
  let committed = false;
128
121
  try {
129
- const invitation = await fetchOne<InvitationRow>(
130
- ctx.db.unsafeRaw(),
131
- tenantInvitationsTable,
132
- { id: invitationId },
133
- );
134
- if (!invitation || invitation.status !== INVITATION_STATUS.pending)
135
- return invalidInviteToken();
136
-
137
- const invitationTenantId = invitation.tenantId;
138
- const invitationEmail = await decryptStoredPii(
139
- invitation.email,
140
- "email",
141
- "auth:invite-signup-complete",
142
- );
143
- const invitationRole = invitation.role;
144
- const invitationGlobalRoles = parseInvitedGlobalRoles(invitation.globalRoles);
145
- const invitationVersion = invitation.version;
146
-
147
- // If the email is already registered, the user must use Branch 2
148
- // (acceptWithLogin). This flow explicitly requires a new email;
149
- // otherwise there would be two ways to set a password for the same user.
150
- // Email uniqueness is partial on live rows — without this filter,
151
- // the lookup can resolve a soft-deleted row.
152
- const existingUser = await ctx.db.global(userTable).fetchOne({
153
- email: invitationEmail,
154
- isDeleted: false,
155
- });
156
- if (existingUser) return invalidInviteToken();
157
-
158
- // Create the user through seedUserWithPassword so the magic-link flow
159
- // records emailVerified=true.
160
- // @cast-boundary db-runner — helpers use only the query API that
161
- // DbConnection and DbTx share.
162
- const dbConn = ctx.db.unsafeRaw() as DbConnection;
163
- const registrationLocale = registrationLocaleFromRequest();
164
- const { id: userId } = await seedUserWithPassword(dbConn, {
165
- email: invitationEmail,
122
+ const result = await acceptInvitationAndCreateUser(ctx, opts, {
123
+ redis: ctx.services.redis,
124
+ invitationId,
125
+ token: event.payload.token,
166
126
  password: event.payload.password,
167
- displayName: invitationEmail.split("@")[0] ?? invitationEmail,
168
- emailVerified: true,
169
- ...registrationLocale,
170
- ...(invitationGlobalRoles.length > 0 && { roles: invitationGlobalRoles }),
171
- });
172
-
173
- // The seed helper bypasses addMember's access check because
174
- // createSystemUser does not match ["SystemAdmin"].
175
- const forbiddenInviteRole = findForbiddenMembershipRole([invitationRole]);
176
- if (forbiddenInviteRole !== undefined) {
177
- return writeFailure(reservedMembershipRoleError(forbiddenInviteRole));
178
- }
179
- await seedTenantMembership(dbConn, {
180
- userId,
181
- tenantId: invitationTenantId,
182
- roles: [invitationRole],
183
127
  });
184
-
185
- // Update the invitation in the invited tenant's database context.
186
- const invitationTdb = createTenantDb({
187
- db: dbConn,
188
- tenantId: invitationTenantId,
189
- mode: "system",
190
- reason:
191
- "invitation tenant differs from the caller's tenant, the accept step updates the invitation row there",
192
- });
193
- const updateResult = await invitationExecutor.update(
194
- {
195
- id: invitationId,
196
- version: invitationVersion,
197
- changes: { status: INVITATION_STATUS.accepted },
198
- },
199
- createSystemUser(invitationTenantId),
200
- invitationTdb,
201
- );
202
- if (!updateResult.isSuccess) return updateResult;
203
-
204
- // buildSessionRoles calls stripForbiddenMembershipRoles internally —
205
- // a reserved role on the invitation itself must never reach the session.
206
- const mergedRoles = buildSessionRoles(invitationGlobalRoles, [invitationRole]);
207
-
208
- // Same gate as invite-accept-with-login: the account exists after this
209
- // call, but an MFA-gated role gets the MFA step instead of a session.
210
- // It runs before the token is deleted so a throwing check leaves the link retryable.
211
- const mfaGate = await gateEnforceMfa(
212
- ctx,
213
- { mfaStatusChecker: opts.mfaStatusChecker },
214
- userId,
215
- invitationTenantId,
216
- mergedRoles,
217
- );
218
-
219
- await deleteInviteToken(ctx.services.redis, { invitationId, token: event.payload.token });
220
-
221
- if (mfaGate !== undefined) {
222
- committed = true;
223
- return { isSuccess: true, data: mfaGate };
224
- }
225
-
226
- const session: SessionUser = {
227
- id: userId,
228
- tenantId: invitationTenantId,
229
- roles: mergedRoles,
230
- ...registrationLocale,
231
- };
232
-
233
- committed = true;
234
- return {
235
- isSuccess: true,
236
- data: {
237
- kind: "auth-session",
238
- session,
239
- tenantId: invitationTenantId,
240
- role: invitationRole,
241
- },
242
- };
128
+ committed = result.isSuccess;
129
+ return result;
243
130
  } finally {
244
131
  if (!committed && ctx.services.redis) {
245
132
  await unburnInviteToken(ctx.services.redis, event.payload.token);
@@ -248,3 +135,142 @@ export function createInviteSignupCompleteHandler(opts: InviteSignupCompleteOpti
248
135
  },
249
136
  });
250
137
  }
138
+
139
+ type InvitationRow = {
140
+ readonly status: string;
141
+ readonly tenantId: TenantId;
142
+ readonly email: string;
143
+ readonly role: string;
144
+ readonly globalRoles: unknown;
145
+ readonly version: number;
146
+ };
147
+
148
+ type AcceptInvitationInput = {
149
+ readonly redis: NonNullable<HandlerContext["services"]["redis"]>;
150
+ readonly invitationId: string;
151
+ readonly token: string;
152
+ readonly password: string;
153
+ };
154
+
155
+ async function acceptInvitationAndCreateUser(
156
+ ctx: HandlerContext,
157
+ opts: InviteSignupCompleteOptions,
158
+ input: AcceptInvitationInput,
159
+ ): Promise<WriteResult<InviteSignupCompleteData>> {
160
+ const { redis, invitationId, token, password } = input;
161
+ const invitation = await fetchOne<InvitationRow>(ctx.db.unsafeRaw(), tenantInvitationsTable, {
162
+ id: invitationId,
163
+ });
164
+ if (!invitation || invitation.status !== INVITATION_STATUS.pending) return invalidInviteToken();
165
+
166
+ const invitationTenantId = invitation.tenantId;
167
+ const invitationEmail = await decryptStoredPii(
168
+ invitation.email,
169
+ "email",
170
+ "auth:invite-signup-complete",
171
+ );
172
+ const invitationRole = invitation.role;
173
+ const invitationGlobalRoles = parseInvitedGlobalRoles(invitation.globalRoles);
174
+ const invitationVersion = invitation.version;
175
+
176
+ // If the email is already registered, the user must use Branch 2
177
+ // (acceptWithLogin). This flow explicitly requires a new email;
178
+ // otherwise there would be two ways to set a password for the same user.
179
+ // Email uniqueness is partial on live rows — without this filter,
180
+ // the lookup can resolve a soft-deleted row.
181
+ const existingUser = await ctx.db.global(userTable).fetchOne({
182
+ email: invitationEmail,
183
+ isDeleted: false,
184
+ });
185
+ if (existingUser) return invalidInviteToken();
186
+
187
+ // Create the user through seedUserWithPassword so the magic-link flow
188
+ // records emailVerified=true.
189
+ // @cast-boundary db-runner — helpers use only the query API that
190
+ // DbConnection and DbTx share.
191
+ const dbConn = ctx.db.unsafeRaw() as DbConnection;
192
+ const registrationLocale = registrationLocaleFromRequest();
193
+ const { id: userId } = await seedUserWithPassword(dbConn, {
194
+ email: invitationEmail,
195
+ password: password,
196
+ displayName: invitationEmail.split("@")[0] ?? invitationEmail,
197
+ emailVerified: true,
198
+ ...registrationLocale,
199
+ ...(invitationGlobalRoles.length > 0 && { roles: invitationGlobalRoles }),
200
+ });
201
+
202
+ // The seed helper bypasses addMember's access check because
203
+ // createSystemUser does not match ["SystemAdmin"].
204
+ const forbiddenInviteRole = findForbiddenMembershipRole([invitationRole]);
205
+ if (forbiddenInviteRole !== undefined) {
206
+ return writeFailure(reservedMembershipRoleError(forbiddenInviteRole));
207
+ }
208
+ const membership = await seedTenantMembership(dbConn, {
209
+ userId,
210
+ tenantId: invitationTenantId,
211
+ roles: [invitationRole],
212
+ });
213
+ if (membership.rowMissing) {
214
+ ctx.obs.log.warn("invite signup: membership stream exists but its row is missing", {
215
+ tenantId: invitationTenantId,
216
+ userId,
217
+ });
218
+ }
219
+
220
+ // Update the invitation in the invited tenant's database context.
221
+ const invitationTdb = createTenantDb({
222
+ db: dbConn,
223
+ tenantId: invitationTenantId,
224
+ mode: "system",
225
+ reason:
226
+ "invitation tenant differs from the caller's tenant, the accept step updates the invitation row there",
227
+ });
228
+ const updateResult = await invitationExecutor.update(
229
+ {
230
+ id: invitationId,
231
+ version: invitationVersion,
232
+ changes: { status: INVITATION_STATUS.accepted },
233
+ },
234
+ createSystemUser(invitationTenantId),
235
+ invitationTdb,
236
+ );
237
+ if (!updateResult.isSuccess) return updateResult;
238
+
239
+ // buildSessionRoles calls stripForbiddenMembershipRoles internally —
240
+ // a reserved role on the invitation itself must never reach the session.
241
+ const mergedRoles = buildSessionRoles(invitationGlobalRoles, [invitationRole]);
242
+
243
+ // Same gate as invite-accept-with-login: the account exists after this
244
+ // call, but an MFA-gated role gets the MFA step instead of a session.
245
+ // It runs before the token is deleted so a throwing check leaves the link retryable.
246
+ const mfaGate = await gateEnforceMfa(
247
+ ctx,
248
+ { mfaStatusChecker: opts.mfaStatusChecker },
249
+ userId,
250
+ invitationTenantId,
251
+ mergedRoles,
252
+ );
253
+
254
+ await deleteInviteToken(redis, { invitationId, token: token });
255
+
256
+ if (mfaGate !== undefined) {
257
+ return { isSuccess: true, data: mfaGate };
258
+ }
259
+
260
+ const session: SessionUser = {
261
+ id: userId,
262
+ tenantId: invitationTenantId,
263
+ roles: mergedRoles,
264
+ ...registrationLocale,
265
+ };
266
+
267
+ return {
268
+ isSuccess: true,
269
+ data: {
270
+ kind: "auth-session",
271
+ session,
272
+ tenantId: invitationTenantId,
273
+ role: invitationRole,
274
+ },
275
+ };
276
+ }
@@ -8,7 +8,7 @@ import { AuthHandlers } from "../web/constants.ts";
8
8
  export const loginOptionsQuery = defineQueryHandler({
9
9
  name: "login-options",
10
10
  schema: z.object({}),
11
- access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"], anySignedIn: true },
11
+ access: { roles: ["anonymous"], anySignedIn: true },
12
12
  rateLimit: { per: "ip+handler", limit: 30, windowSeconds: 60 },
13
13
  description:
14
14
  "Reports which optional login-page flows (password reset, account unlock) are available, readable without signing in, so the login screen links only to flows that exist.",
@@ -13,7 +13,7 @@ export type RequestAccountUnlockOptions = TokenRequestOptions;
13
13
  // the dispatcher (bypassing the framework's auth-routes).
14
14
  export type RequestUnlockData = TokenRequestData<"unlock-requested">;
15
15
 
16
- // @wrapper-known semantic-alias
16
+ // guard:dup-ok thin config wrapper over createTokenRequestHandler; only the per-flow config literals match request-password-reset
17
17
  export function createRequestAccountUnlockHandler(opts: RequestAccountUnlockOptions) {
18
18
  return createTokenRequestHandler(
19
19
  {
@@ -11,7 +11,6 @@ export type RequestEmailVerificationOptions = TokenRequestOptions;
11
11
 
12
12
  export type RequestVerificationData = TokenRequestData<"verification-requested">;
13
13
 
14
- // @wrapper-known semantic-alias
15
14
  export function createRequestEmailVerificationHandler(opts: RequestEmailVerificationOptions) {
16
15
  return createTokenRequestHandler(
17
16
  {
@@ -13,7 +13,6 @@ export type RequestPasswordResetOptions = TokenRequestOptions;
13
13
  // the dispatcher (bypassing the framework's auth-routes).
14
14
  export type RequestResetData = TokenRequestData<"reset-requested">;
15
15
 
16
- // @wrapper-known semantic-alias
17
16
  export function createRequestPasswordResetHandler(opts: RequestPasswordResetOptions) {
18
17
  return createTokenRequestHandler(
19
18
  {
@@ -13,7 +13,7 @@ import { AUTH_SELF_REGISTRATION_FEATURE } from "../self-registration-toggle.ts";
13
13
  export const selfRegistrationStatusQuery = defineQueryHandler({
14
14
  name: "signup-registration-status",
15
15
  schema: z.object({}),
16
- access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"], anySignedIn: true },
16
+ access: { roles: ["anonymous"], anySignedIn: true },
17
17
  rateLimit: { per: "ip+handler", limit: 30, windowSeconds: 60 },
18
18
  description:
19
19
  "Reports whether self-registration is currently switched on, readable without signing in, so a signup page can hide its own form instead of collecting an address that would be silently ignored.",
@@ -10,7 +10,6 @@ export type VerifyResult =
10
10
  | { readonly ok: true; readonly userId: string; readonly expiresAtMs: number }
11
11
  | { readonly ok: false; readonly reason: "malformed" | "bad_signature" | "expired" };
12
12
 
13
- // @wrapper-known semantic-alias
14
13
  export function signResetToken(
15
14
  userId: string,
16
15
  ttlMinutes: number,
@@ -20,7 +19,6 @@ export function signResetToken(
20
19
  return signToken(userId, TokenPurpose.passwordReset, ttlMinutes, secret, now);
21
20
  }
22
21
 
23
- // @wrapper-known semantic-alias
24
22
  export function verifyResetToken(
25
23
  token: string,
26
24
  secret: string,
@@ -28,7 +28,7 @@ import {
28
28
  } from "@cosmicdrift/kumiko-framework/engine";
29
29
  import { ConflictError } from "@cosmicdrift/kumiko-framework/errors";
30
30
  import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
31
- import { hashPassword } from "../shared/index.ts";
31
+ import { hashPassword, verifyPassword } from "../shared/index.ts";
32
32
  // kumiko-lint-ignore cross-feature-import bootstrap admin seed checks whether the tenant already has members
33
33
  import { tenantMembershipsTable } from "../tenant/membership-table.ts";
34
34
  // kumiko-lint-ignore cross-feature-import auth-tests need user+tenant seed-helpers
@@ -350,14 +350,39 @@ async function findExistingUserIdForEmail(
350
350
  return matches.length === 0 ? undefined : pickCanonicalUserId(matches);
351
351
  }
352
352
 
353
+ // A self-registered, unverified account may squat the seed email before the
354
+ // first boot. Granting roles to it (or marking it verified) would hand the
355
+ // attacker the admin. An explicit caller guard (bootstrap seed: passwordless
356
+ // own account) replaces the built-in proof because it cannot satisfy it.
357
+ async function mayGrantToExistingAccount(
358
+ row: Record<string, unknown>,
359
+ options: SeedAdminOptions,
360
+ callerGuard: ((row: Record<string, unknown>) => boolean) | undefined,
361
+ ): Promise<boolean> {
362
+ if (callerGuard) return callerGuard(row);
363
+ if (row["emailVerified"] === true) return true;
364
+ const storedHash = row["passwordHash"];
365
+ if (options.password === undefined || typeof storedHash !== "string" || storedHash === "") {
366
+ return false;
367
+ }
368
+ return verifyPassword(storedHash, options.password);
369
+ }
370
+
371
+ function warnSeedSkippedForUnprovenAccount(): void {
372
+ log.warn(
373
+ "seedAdminGuarded: an existing unverified account holds the seed email and does not match the seed password, grants skipped",
374
+ );
375
+ }
376
+
353
377
  async function seedAdminPlaintext(
354
378
  db: DbConnection,
355
379
  options: SeedAdminOptions,
356
380
  mayGrantToExisting: ((row: Record<string, unknown>) => boolean) | undefined,
357
381
  ): Promise<{ id: string }> {
358
- if (mayGrantToExisting) {
359
- const row = await fetchOne(db, userTable, { email: options.email, isDeleted: false });
360
- if (row && !mayGrantToExisting(row)) return { id: String(row["id"]) };
382
+ const row = await fetchOne(db, userTable, { email: options.email, isDeleted: false });
383
+ if (row && !(await mayGrantToExistingAccount(row, options, mayGrantToExisting))) {
384
+ if (!mayGrantToExisting) warnSeedSkippedForUnprovenAccount();
385
+ return { id: String(row["id"]) };
361
386
  }
362
387
  return seedAdmin(db, options);
363
388
  }
@@ -403,7 +428,10 @@ export async function seedAdminGuarded(
403
428
  // stays unfindable for login and every boot re-scans the whole table.
404
429
  await rewriteSeededUserEmail(db, existingRow, options.email, by);
405
430
  const refreshed = (await fetchOne(db, userTable, { id: existingId })) ?? existingRow;
406
- if (mayGrantToExisting && !mayGrantToExisting(refreshed)) return { id: existingId };
431
+ if (!(await mayGrantToExistingAccount(refreshed, options, mayGrantToExisting))) {
432
+ if (!mayGrantToExisting) warnSeedSkippedForUnprovenAccount();
433
+ return { id: existingId };
434
+ }
407
435
  if (options.emailVerified === true) {
408
436
  await reconcileSeededUserEmailVerified(db, refreshed, by);
409
437
  }
@@ -437,8 +465,12 @@ async function tenantHasForeignMember(
437
465
  tenantId: TenantId,
438
466
  ownUserId: string | undefined,
439
467
  ): Promise<boolean> {
440
- const members = await selectMany(db, tenantMembershipsTable, { tenantId });
441
- return members.some((member) => member["userId"] !== ownUserId);
468
+ const where = ownUserId === undefined ? { tenantId } : { tenantId, userId: { ne: ownUserId } };
469
+ const [foreignMember] = await selectMany(db, tenantMembershipsTable, where, {
470
+ fields: ["id"],
471
+ limit: 1,
472
+ });
473
+ return foreignMember !== undefined;
442
474
  }
443
475
 
444
476
  /**