@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
@@ -22,7 +22,6 @@ const MAIL_THREAD_NAMESPACE = "b48d1e72-5c9a-4f36-8e0d-6a3f9b2c7e15";
22
22
  * the same tenant can receive the same email (CC'd to both inboxes); these
23
23
  * are two distinct inbound messages.
24
24
  */
25
- // @wrapper-known uuid-domain
26
25
  export function inboundMessageAggregateId(accountId: string, providerMessageId: string): string {
27
26
  return uuidv5(`${accountId}:${providerMessageId}`, INBOUND_MESSAGE_NAMESPACE);
28
27
  }
@@ -34,7 +33,6 @@ export function inboundMessageAggregateId(accountId: string, providerMessageId:
34
33
  * normalized by the provider (References/In-Reply-To chain or provider
35
34
  * thread ID).
36
35
  */
37
- // @wrapper-known uuid-domain
38
36
  export function mailThreadAggregateId(tenantId: string, threadKey: string): string {
39
37
  return uuidv5(`${tenantId}:${threadKey}`, MAIL_THREAD_NAMESPACE);
40
38
  }
@@ -1,4 +1,58 @@
1
1
  [
2
+ {
3
+ "version": "0.415.0",
4
+ "type": "fix",
5
+ "title": "to/cc lists fit the ciphertext limit, forget-message needs file storage",
6
+ "detail": "normalizeRawInboundMessage drops addresses from the end of to/cc until the serialized list fits INBOUND_ADDRESS_LIST_JSON_MAX_CHARS, and ingestMessageSchema rejects longer lists, so a mail to a large distribution list no longer fails the event append. Entity and event limits derive from shared constants. forget-message fails before archiving when a stored original exists but no file storage is configured. The content-refetch scan marker belongs to one poller instead of the module."
7
+ },
8
+ {
9
+ "version": "0.414.0",
10
+ "type": "fix",
11
+ "title": "hanging-account test recovers without the artificial 150ms deadline",
12
+ "detail": "The recovery poll of `watch-supervisor-hanging-account.integration.test.ts` ran with the 150ms deadline meant for the hung fetches, so a slow CI run abandoned the real sync (status degraded, nothing imported). Recovery now uses a supervisor with the default deadline, and the test also asserts a fresh fetch per tick, so a skipped tick fails it."
13
+ },
14
+ {
15
+ "version": "0.414.0",
16
+ "type": "fix",
17
+ "title": "PII ciphertext limits on inbound-mail entities and the mail-account event",
18
+ "detail": "The `inbound-message`, `mail-thread` and `mail-account` read-model fields for from, to, cc, subject, snippet, address, bodyText and bodyHtml, and the `address`, `bodyText` and `bodyHtml` of the event payloads, capped at plaintext or rough limits although they hold PII ciphertext (envelope plus Base64). A sender, subject, snippet or 320-character address at its plaintext limit failed validation once a PII KMS was configured. Their limits now come from `piiCiphertextMaxLengthFor` in `@cosmicdrift/kumiko-framework/crypto`."
19
+ },
20
+ {
21
+ "version": "0.414.0",
22
+ "type": "fix",
23
+ "title": "ingest-message no longer rejects mails whose encrypted fields reach the plaintext limit",
24
+ "detail": "The `inbound-message-received` and `mail-thread-updated` payload schemas capped from, to, cc, subject and snippet at the plaintext limits, but the payload holds PII ciphertext (envelope plus Base64), so a 4000-character subject or snippet failed with \"Validation failed\" once a PII KMS was configured. The limits now come from the new `piiCiphertextMaxLengthFor` in `@cosmicdrift/kumiko-framework/crypto`."
25
+ },
26
+ {
27
+ "version": "0.414.0",
28
+ "type": "fix",
29
+ "title": "review round 2 inbound mail fixes (connect race, quarantine lookups, storeBody, system search index)",
30
+ "detail": "`connect-account` takes an advisory lock per tenant and normalized address before the duplicate check, so a double submit or the OAuth callback racing the IMAP form cannot create two accounts for one address. `quarantinedMessageIds`, `hasOpenQuarantine` and `quarantineMessage` filter on `tenantId` and use the unique index. The supervisor no longer hands the storeBody hook an original that is above the raw MIME limit. `reindexTenantsSearch` also configures the system tenant index when a searchable entity lives on the system stream, so those documents get the searchable and ranking fields instead of the wildcard fallback; with the system tenant added, `failedConfigures` can count one more tenant."
31
+ },
32
+ {
33
+ "version": "0.414.0",
34
+ "type": "fix",
35
+ "title": "inbound mail content reload, IMAP download budget, abandoned syncs, mail retry, consumer audit",
36
+ "detail": "The snippet-only content reload remembers per account where its scan stopped, so mails behind the newest 1000 anchors are reloaded over later ticks. The IMAP provider reads message sizes first, reports mails above the 50 MB limit as rejected without downloading them, and cuts each download at 100 MB (the rest follows in the next round via hasMore). A sync abandoned at its deadline stops ingesting before the next message. A mail adapter that throws ECONNREFUSED, ENOTFOUND, EAI_AGAIN, EHOSTUNREACH or ENETUNREACH is retried, since nothing was accepted. The jobs consumer-restart, -skip, -disable and -enable writes append a `jobs:event:consumer-state-changed` event (action, consumer, skipped event id, actor) that the audit log shows; locale packages gain the label `audit.log.event.consumer-state-changed`. `sendMailFromAccount` documents that it cannot be rolled back."
37
+ },
38
+ {
39
+ "version": "0.414.0",
40
+ "type": "fix",
41
+ "title": "Shared mailbox on an address of a disconnected personal mailbox",
42
+ "detail": "An admin can connect a shared mailbox on an address held by a member's disconnected personal mailbox. The IMAP sent-folder copy is appended detached, and the docs say to call `sendMailFromAccount` from `beforeTransaction`. With several disconnected mailboxes on one address, the one of the wanted owner kind (shared or personal) is chosen, then the smallest id."
43
+ },
44
+ {
45
+ "version": "0.414.0",
46
+ "type": "improvement",
47
+ "title": "forget-message permanently removes one imported mail",
48
+ "detail": "The new write `forget-message` archives the stream of one mail, deletes its read row, the stored original and the attachment files, and keeps the seen anchor so the intake does not import the mail again. The owner of a personal mailbox or, for a shared one, an admin may call it (agent risk high); a mail of another tenant or of someone else's personal mailbox is reported as not found. The retention sweep shares the purge logic."
49
+ },
50
+ {
51
+ "version": "0.414.0",
52
+ "type": "fix",
53
+ "title": "partial recipient refusal and sender-check id on reconnect",
54
+ "detail": "`sendMailFromAccount` returns `rejectedRecipients` when the outgoing server accepts the mail for some recipients and refuses others; before, nodemailer's partial refusal was dropped and the send counted as fully delivered. `reconnect-mailbox` only writes the sender-check id when the payload carries the field, so an admin reconnecting a mailbox through the \"My mail accounts\" form keeps the stored id; the admin form clears it by sending an empty string."
55
+ },
2
56
  {
3
57
  "version": "0.412.0",
4
58
  "type": "fix",
@@ -33,6 +33,8 @@ export const InboundMailFoundationHandlers = {
33
33
  retryQuarantinedMessage: "inbound-mail-foundation:write:retry-quarantined-message",
34
34
  /** Marks all open quarantine entries of a mailbox as acknowledged. */
35
35
  acknowledgeQuarantine: "inbound-mail-foundation:write:acknowledge-quarantine",
36
+ /** Permanently removes one imported mail with its original and attachments. */
37
+ forgetMessage: "inbound-mail-foundation:write:forget-message",
36
38
  /** Supervisor-only: stores the content of an already imported snippet mail. */
37
39
  attachMessageContent: "inbound-mail-foundation:write:attach-message-content",
38
40
  /** OAuth callback only: the refresh token is stored now, so an active account can sync. */
@@ -88,6 +90,10 @@ export const InboundMailConnectErrors = {
88
90
  reason: "address_disconnected",
89
91
  i18nKey: "inboundMail.accounts.errors.addressDisconnected",
90
92
  },
93
+ personalAddressNotOwn: {
94
+ reason: "personal_address_not_own",
95
+ i18nKey: "inboundMail.accounts.errors.personalAddressNotOwn",
96
+ },
91
97
  credentialRequired: {
92
98
  reason: "credential_required",
93
99
  i18nKey: "inboundMail.accounts.errors.credentialRequired",
@@ -17,6 +17,12 @@ import type { InboundMailContext, InboundMailProviderPlugin, MailAccountRecord }
17
17
  export const CONTENT_REFETCH_BUDGET_PER_TICK = 50;
18
18
  const SEEN_PAGE_SIZE = 250;
19
19
  const SEEN_MAX_PAGES = 4;
20
+ export const CONTENT_REFETCH_SCAN_ROWS_PER_TICK = SEEN_PAGE_SIZE * SEEN_MAX_PAGES;
21
+
22
+ // Where the previous tick stopped scanning, per account. Without it every tick re-reads the newest
23
+ // rows and snippet-only mails further back would never be reached. Owned by one poller, so stacks
24
+ // never share it; lost on restart, which only means the scan starts at the newest mail again.
25
+ export type ScanResumePoints = Map<string, Temporal.Instant>;
20
26
 
21
27
  type SeenRow = { readonly providerMessageId: string; readonly seenAt: Temporal.Instant };
22
28
  type MessageRow = {
@@ -32,12 +38,14 @@ function needsContent(row: MessageRow): boolean {
32
38
 
33
39
  async function findSnippetOnlyMessageIds(
34
40
  db: DbConnection,
41
+ scanResumePoint: ScanResumePoints,
35
42
  account: MailAccountRecord,
36
43
  windowDays: number,
37
44
  ): Promise<string[]> {
38
45
  const cutoff = Temporal.Now.instant().subtract({ hours: windowDays * 24 });
39
46
  const found: string[] = [];
40
- let before: Temporal.Instant | undefined;
47
+ let before = scanResumePoint.get(account.id);
48
+ scanResumePoint.delete(account.id);
41
49
  for (
42
50
  let page = 0;
43
51
  page < SEEN_MAX_PAGES && found.length < CONTENT_REFETCH_BUDGET_PER_TICK;
@@ -58,6 +66,7 @@ async function findSnippetOnlyMessageIds(
58
66
  },
59
67
  );
60
68
  if (seen.length === 0) break;
69
+ const pageStart = before;
61
70
  const aggregateToProvider = new Map(
62
71
  seen.map((row) => [
63
72
  inboundMessageAggregateId(account.id, row.providerMessageId),
@@ -76,13 +85,20 @@ async function findSnippetOnlyMessageIds(
76
85
  }
77
86
  const oldest = seen[seen.length - 1];
78
87
  if (seen.length < SEEN_PAGE_SIZE || !oldest) break;
88
+ if (found.length >= CONTENT_REFETCH_BUDGET_PER_TICK) {
89
+ // Reloaded mails stop being candidates, so the page can be read again without looping.
90
+ if (pageStart) scanResumePoint.set(account.id, pageStart);
91
+ break;
92
+ }
79
93
  before = oldest.seenAt;
94
+ scanResumePoint.set(account.id, before);
80
95
  }
81
96
  return found.slice(0, CONTENT_REFETCH_BUDGET_PER_TICK);
82
97
  }
83
98
 
84
99
  export async function refetchSnippetOnlyMessages(args: {
85
100
  readonly db: DbConnection;
101
+ readonly scanResumePoint: ScanResumePoints;
86
102
  readonly dispatchWrite: DispatchWrite;
87
103
  readonly providerCtx: InboundMailContext;
88
104
  readonly account: MailAccountRecord;
@@ -94,7 +110,12 @@ export async function refetchSnippetOnlyMessages(args: {
94
110
  const { account, plugin, dispatchWrite } = args;
95
111
  // skip: the provider cannot reload content.
96
112
  if (!plugin.fetchContent) return;
97
- const ids = await findSnippetOnlyMessageIds(args.db, account, args.windowDays);
113
+ const ids = await findSnippetOnlyMessageIds(
114
+ args.db,
115
+ args.scanResumePoint,
116
+ account,
117
+ args.windowDays,
118
+ );
98
119
  // skip: no snippet-only mail to reload.
99
120
  if (ids.length === 0) return;
100
121
  const result = await plugin.fetchContent(
@@ -1,5 +1,12 @@
1
- import { collectPiiSubjectFields } from "@cosmicdrift/kumiko-framework/crypto";
2
- import { deriveEntityTableMeta, physicalColumnName } from "@cosmicdrift/kumiko-framework/db";
1
+ import {
2
+ collectPiiSubjectFields,
3
+ piiCiphertextMaxLengthFor,
4
+ } from "@cosmicdrift/kumiko-framework/crypto";
5
+ import {
6
+ deriveEntityTableMeta,
7
+ isSchemaTable,
8
+ physicalColumnName,
9
+ } from "@cosmicdrift/kumiko-framework/db";
3
10
  import {
4
11
  access,
5
12
  createBooleanField,
@@ -12,6 +19,15 @@ import {
12
19
  } from "@cosmicdrift/kumiko-framework/engine";
13
20
  import type { OwnershipMap, OwnershipRule } from "@cosmicdrift/kumiko-types/ownership";
14
21
  import { DEFAULT_INBOUND_MAIL_ADMIN_ROLES, DEFAULT_INBOUND_MAIL_USER_ROLES } from "./mail-roles.ts";
22
+ import {
23
+ INBOUND_ADDRESS_LIST_JSON_MAX_CHARS,
24
+ INBOUND_BODY_HTML_MAX_BYTES,
25
+ INBOUND_BODY_TEXT_MAX_CHARS,
26
+ INBOUND_FROM_MAX_CHARS,
27
+ INBOUND_MAIL_ADDRESS_MAX_CHARS,
28
+ INBOUND_SNIPPET_MAX_CHARS,
29
+ INBOUND_SUBJECT_MAX_CHARS,
30
+ } from "./normalize-inbound-message.ts";
15
31
 
16
32
  // ============================================================================
17
33
  // Read models for the three event-sourced aggregates
@@ -25,8 +41,8 @@ import { DEFAULT_INBOUND_MAIL_ADMIN_ROLES, DEFAULT_INBOUND_MAIL_USER_ROLES } fro
25
41
  // **PII convention:** `personal: "tenant"` (not `encrypted`): fields must
26
42
  // be crypto-shredded when eraseSubjectKeys deletes the tenant subject key on
27
43
  // tenant destruction (pattern from billing-foundation).
28
- // maxLength is budgeted for ciphertext (`kumiko-pii:v1:<subject>:
29
- // <blob>` — Plaintext×~2.3 + envelope overhead).
44
+ // The projection holds ciphertext, so these fields' maxLength comes from
45
+ // piiCiphertextMaxLengthFor(<plaintext limit>).
30
46
  //
31
47
  // **Design decision:** The PII subject of an inbound mail is currently the
32
48
  // TENANT (mailbox owner), not the external sender. A sender-forget flow would
@@ -62,7 +78,12 @@ export const mailAccountEntity = createEntity({
62
78
  reason: "tenant_config_not_personal",
63
79
  }),
64
80
  // Mailbox address — tenant PII.
65
- address: createTextField({ required: true, maxLength: 1000, personal: "tenant", find: "none" }),
81
+ address: createTextField({
82
+ required: true,
83
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_MAIL_ADDRESS_MAX_CHARS),
84
+ personal: "tenant",
85
+ find: "none",
86
+ }),
66
87
  status: createTextField({
67
88
  required: true,
68
89
  maxLength: 30,
@@ -89,6 +110,9 @@ function ownMailboxOrSharedRead(memberRoles: readonly string[]): OwnershipMap {
89
110
  const rule: OwnershipRule = {
90
111
  kind: "where",
91
112
  where: (user, ctx) => {
113
+ if (!isSchemaTable(ctx.table)) {
114
+ throw new Error(`${ctx.tableName}: ownership rule received a table not built by table()`);
115
+ }
92
116
  const owner = `"${ctx.tableName}"."${physicalColumnName(ctx.table, "ownerUserId")}"`;
93
117
  return {
94
118
  sqlText: `(${owner} IS NULL OR ${owner} = '' OR ${owner} = $${ctx.paramStart})`,
@@ -128,21 +152,51 @@ export function createInboundMessageEntity(memberRoles: readonly string[]) {
128
152
  personal: false,
129
153
  reason: "technical_reference",
130
154
  }),
131
- from: createTextField({ required: true, maxLength: 2000, personal: "tenant", find: "none" }),
155
+ from: createTextField({
156
+ required: true,
157
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_FROM_MAX_CHARS),
158
+ personal: "tenant",
159
+ find: "none",
160
+ }),
132
161
  // JSON-stringified string[] — als Ganzes encrypted.
133
- to: createTextField({ maxLength: 8000, personal: "tenant", find: "none" }),
134
- cc: createTextField({ maxLength: 8000, personal: "tenant", find: "none" }),
135
- subject: createTextField({ maxLength: 4000, personal: "tenant", find: "none" }),
136
- snippet: createTextField({ maxLength: 4000, personal: "tenant", find: "none" }),
162
+ to: createTextField({
163
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_ADDRESS_LIST_JSON_MAX_CHARS),
164
+ personal: "tenant",
165
+ find: "none",
166
+ }),
167
+ cc: createTextField({
168
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_ADDRESS_LIST_JSON_MAX_CHARS),
169
+ personal: "tenant",
170
+ find: "none",
171
+ }),
172
+ subject: createTextField({
173
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_SUBJECT_MAX_CHARS),
174
+ personal: "tenant",
175
+ find: "none",
176
+ }),
177
+ snippet: createTextField({
178
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_SNIPPET_MAX_CHARS),
179
+ personal: "tenant",
180
+ find: "none",
181
+ }),
137
182
  receivedAt: createTimestampField({ required: true }),
138
183
  bodyRef: createTextField({ maxLength: 500, personal: false, reason: "technical_reference" }),
139
184
  scope: createTextField({ maxLength: 200, personal: false, reason: "technical_reference" }),
140
- // Full plaintext, capped at 32_000 characters before encryption (ciphertext is ~2.3x plus envelope).
141
185
  // Null on rows from before the column; list-messages never selects it.
142
- bodyText: createLongTextField({ maxLength: 200_000, personal: "tenant", find: "none" }),
186
+ // Plaintext is clipped to INBOUND_BODY_TEXT_MAX_CHARS (32_000) before encryption.
187
+ bodyText: createLongTextField({
188
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_BODY_TEXT_MAX_CHARS),
189
+ personal: "tenant",
190
+ find: "none",
191
+ }),
143
192
  bodyTextTruncated: createBooleanField(),
144
- // Sanitized HTML of the mail (sanitizeInboundHtml), null when the mail has none or it was too large.
145
- bodyHtml: createLongTextField({ maxLength: 500_000, personal: "tenant", find: "none" }),
193
+ // Sanitized HTML of the mail, null when the mail has none or it was too large: sanitizeInboundHtml
194
+ // drops anything over 500_000 bytes after sanitizing, before encryption.
195
+ bodyHtml: createLongTextField({
196
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_BODY_HTML_MAX_BYTES),
197
+ personal: "tenant",
198
+ find: "none",
199
+ }),
146
200
  // Bound to the message (entityType = the aggregate type), so the file guard answers with the
147
201
  // mail's visibility. The fileRefs are bound at ingest, the projection copies the ids.
148
202
  attachmentFileIds: createFilesField({ personal: false, reason: "technical_reference" }),
@@ -193,7 +247,11 @@ export const mailThreadEntity = createEntity({
193
247
  personal: false,
194
248
  reason: "technical_reference",
195
249
  }),
196
- subject: createTextField({ maxLength: 4000, personal: "tenant", find: "none" }),
250
+ subject: createTextField({
251
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_SUBJECT_MAX_CHARS),
252
+ personal: "tenant",
253
+ find: "none",
254
+ }),
197
255
  lastMessageAt: createTimestampField({ required: true }),
198
256
  messageCount: createNumberField({ required: true, integer: true }),
199
257
  },
@@ -20,8 +20,18 @@
20
20
  // eraseSubjectKeys makes both the event log and projection unreadable
21
21
  // (crypto-shredding, the billing-foundation pattern).
22
22
 
23
+ import { piiCiphertextMaxLengthFor } from "@cosmicdrift/kumiko-framework/crypto";
23
24
  import * as z from "zod";
24
25
  import { INBOUND_MAIL_FOUNDATION_FEATURE, InboundMailAccountStatuses } from "./constants.ts";
26
+ import {
27
+ INBOUND_ADDRESS_LIST_JSON_MAX_CHARS,
28
+ INBOUND_BODY_HTML_MAX_BYTES,
29
+ INBOUND_BODY_TEXT_MAX_CHARS,
30
+ INBOUND_FROM_MAX_CHARS,
31
+ INBOUND_MAIL_ADDRESS_MAX_CHARS,
32
+ INBOUND_SNIPPET_MAX_CHARS,
33
+ INBOUND_SUBJECT_MAX_CHARS,
34
+ } from "./normalize-inbound-message.ts";
25
35
  import { senderAuthenticationFieldSchema } from "./sender-auth.ts";
26
36
 
27
37
  // Aggregate types for the event store.
@@ -64,9 +74,7 @@ const accountStatusEnum = z.enum([
64
74
  // ============================================================================
65
75
  //
66
76
  // One stream per mailbox (aggregateId = accountId, random UUID on connect).
67
- // address is PII, so maxLength is 1000 to allow for ciphertext expansion
68
- // (a 200-character plaintext becomes ~460+ characters in a JSON envelope;
69
- // see billing-foundation events.ts).
77
+ // address is PII ciphertext; its plaintext is capped at 320 characters by connect-account.write.ts.
70
78
  export const mailAccountEventPayloadSchema = z.object({
71
79
  provider: z.string().min(1).max(50),
72
80
  /** "password" | "xoauth2" | "oauth" (InboundMailAuthMethods) — deliberately
@@ -76,7 +84,7 @@ export const mailAccountEventPayloadSchema = z.object({
76
84
  /** null = shared by the tenant; otherwise, this user's personal mailbox. */
77
85
  ownerUserId: z.string().max(36).nullable(),
78
86
  displayName: z.string().max(200),
79
- address: z.string().min(1).max(1000),
87
+ address: z.string().min(1).max(piiCiphertextMaxLengthFor(INBOUND_MAIL_ADDRESS_MAX_CHARS)),
80
88
  status: accountStatusEnum,
81
89
  /** Provider-agnostic watch state ("idle", "watching", "backoff:3", ...)
82
90
  * — an operational signal only, not PII. */
@@ -114,12 +122,12 @@ export const skippedAttachmentSchema = z.object({
114
122
  });
115
123
 
116
124
  // Shared by inbound-message-received (v2+) and inbound-message-content-fetched.
117
- // bodyText is ciphertext: 32_000 characters become roughly 75 KB, hence the generous max.
125
+ // bodyText is ciphertext of at most INBOUND_BODY_TEXT_MAX_CHARS (32_000) characters.
118
126
  const inboundMessageContentShape = {
119
- bodyText: z.string().max(200_000),
127
+ bodyText: z.string().max(piiCiphertextMaxLengthFor(INBOUND_BODY_TEXT_MAX_CHARS)),
120
128
  bodyTextTruncated: z.boolean(),
121
- /** Sanitized HTML body, PII ciphertext (500_000 characters become roughly 1.2 MB). Null: none or too large. */
122
- bodyHtml: z.string().max(1_500_000).nullable(),
129
+ /** Sanitized HTML body as PII ciphertext. sanitizeInboundHtml drops anything over 500_000 bytes after sanitizing. Null: none or too large. */
130
+ bodyHtml: z.string().max(piiCiphertextMaxLengthFor(INBOUND_BODY_HTML_MAX_BYTES)).nullable(),
123
131
  /** file-foundation FileRef ids (plaintext uuids). Attachments outlive the mail: apps turn them
124
132
  * into documents, so the retention sweep never deletes them. */
125
133
  attachmentFileIds: z.array(z.uuid()).max(50),
@@ -135,8 +143,8 @@ const inboundMessageContentShape = {
135
143
  // aggregateId = inboundMessageAggregateId(accountId, providerMessageId)
136
144
  // → deterministic, so provider replays collide on the same stream.
137
145
  //
138
- // PII fields (from/to/cc/subject/snippet): ciphertext with generous
139
- // maximum lengths. to/cc are JSON-stringified string[] BEFORE encryption;
146
+ // PII fields (from/to/cc/subject/snippet): the maxima are the ciphertext
147
+ // size of the plaintext limits in ingest-message-schema.ts. to/cc are JSON-stringified string[] BEFORE encryption;
140
148
  // the payload contains the ciphertext string, not the array (primitives only,
141
149
  // upcaster-safe).
142
150
  export const inboundMessageEventPayloadSchema = z.object({
@@ -149,13 +157,13 @@ export const inboundMessageEventPayloadSchema = z.object({
149
157
  /** Normalized thread key (References-chain root or provider thread ID,
150
158
  * prefixed by the provider). */
151
159
  threadKey: z.string().min(1).max(500),
152
- from: z.string().min(1).max(2000),
160
+ from: z.string().min(1).max(piiCiphertextMaxLengthFor(INBOUND_FROM_MAX_CHARS)),
153
161
  /** JSON-stringified string[], dann PII-encrypted. */
154
- to: z.string().max(8000),
162
+ to: z.string().max(piiCiphertextMaxLengthFor(INBOUND_ADDRESS_LIST_JSON_MAX_CHARS)),
155
163
  /** JSON-stringified string[], dann PII-encrypted. */
156
- cc: z.string().max(8000),
157
- subject: z.string().max(4000),
158
- snippet: z.string().max(4000),
164
+ cc: z.string().max(piiCiphertextMaxLengthFor(INBOUND_ADDRESS_LIST_JSON_MAX_CHARS)),
165
+ subject: z.string().max(piiCiphertextMaxLengthFor(INBOUND_SUBJECT_MAX_CHARS)),
166
+ snippet: z.string().max(piiCiphertextMaxLengthFor(INBOUND_SNIPPET_MAX_CHARS)),
159
167
  /** ISO instant — receipt time reported by the provider (INTERNALDATE or
160
168
  * receivedDateTime), not ingest time. */
161
169
  receivedAtIso: z.string().min(1),
@@ -193,7 +201,7 @@ export type InboundMessageContentFetchedEventPayload = z.infer<
193
201
  // ============================================================================
194
202
  export const mailThreadEventPayloadSchema = z.object({
195
203
  threadKey: z.string().min(1).max(500),
196
- subject: z.string().max(4000),
204
+ subject: z.string().max(piiCiphertextMaxLengthFor(INBOUND_SUBJECT_MAX_CHARS)),
197
205
  lastMessageAtIso: z.string().min(1),
198
206
  messageCount: z.number().int().min(1),
199
207
  });
@@ -55,6 +55,7 @@ import { createAcknowledgeQuarantineHandler } from "./handlers/acknowledge-quara
55
55
  import { attachMessageContentHandler } from "./handlers/attach-message-content.write.ts";
56
56
  import { createConnectAccountHandler } from "./handlers/connect-account.write.ts";
57
57
  import { createDisconnectAccountHandler } from "./handlers/disconnect-account.write.ts";
58
+ import { createForgetMessageHandler } from "./handlers/forget-message.write.ts";
58
59
  import { ingestMessageHandler } from "./handlers/ingest-message.write.ts";
59
60
  import { createListAccountsQuery } from "./handlers/list-accounts.query.ts";
60
61
  import { createListMessagesQuery } from "./handlers/list-messages.query.ts";
@@ -104,7 +105,7 @@ export function createInboundMailFoundationFeature(options: InboundMailRoleOptio
104
105
  (r) => {
105
106
  r.adoptsBundledLists();
106
107
  r.describe(
107
- "Plugin host for inbound e-mail (inbox federation) — provider plugins (inbound-provider-imap, later M365 Graph / Gmail REST) register at the `inboundMailProvider` extension point with verify/fetch and optional oauth/watch (live push) and send. `sendMailFromAccount(ctx, { accountId, message })` sends from a connected mailbox through its provider (From = the mailbox address, no fallback to the app sender) and answers typed failures (not configured, login rejected, server unreachable, rejected, invalid message); app write handlers call it, it is no endpoint of its own. The foundation owns three event-sourced streams (mail-account lifecycle, inbound-message with exactly-once ingest via deterministic aggregate ids, mail-thread rollup) and their projections `read_mail_accounts`/`read_inbound_messages`/`read_mail_threads`; PII fields are envelope-encrypted per tenant subject key before every append (crypto-shredding on tenant destroy). Wire `createInboundMailConnectRoutes` (OAuth connect + anonymous callback outside /api) and `createInboundMailSupervisor` (IDLE watch with backoff + reconciliation poll) in bin/server.ts. Consume `inbound-mail-foundation:event:inbound-message-received` from app features to attach business processes.",
108
+ "Plugin host for inbound e-mail (inbox federation) — provider plugins (inbound-provider-imap, later M365 Graph / Gmail REST) register at the `inboundMailProvider` extension point with verify/fetch and optional oauth/watch (live push) and send. `sendMailFromAccount(ctx, { accountId, message })` sends from a connected mailbox through its provider (From = the mailbox address, no fallback to the app sender) and answers typed failures (not configured, login rejected, server unreachable, rejected, invalid message); app write handlers call it from `beforeTransaction` (it sends at once and a rollback cannot recall the mail), it is no endpoint of its own. The foundation owns three event-sourced streams (mail-account lifecycle, inbound-message with exactly-once ingest via deterministic aggregate ids, mail-thread rollup) and their projections `read_mail_accounts`/`read_inbound_messages`/`read_mail_threads`; PII fields are envelope-encrypted per tenant subject key before every append (crypto-shredding on tenant destroy). Wire `createInboundMailConnectRoutes` (OAuth connect + anonymous callback outside /api) and `createInboundMailSupervisor` (IDLE watch with backoff + reconciliation poll) in bin/server.ts. Consume `inbound-mail-foundation:event:inbound-message-received` from app features to attach business processes.",
108
109
  );
109
110
  r.uiHints({
110
111
  displayLabel: "Inbound Mail · Foundation",
@@ -256,6 +257,7 @@ export function createInboundMailFoundationFeature(options: InboundMailRoleOptio
256
257
  r.writeHandler(createReactivateAccountHandler(roles));
257
258
  r.writeHandler(createSetTrustedAuthservIdHandler(roles));
258
259
  r.writeHandler(createAcknowledgeQuarantineHandler(roles));
260
+ r.writeHandler(createForgetMessageHandler(roles));
259
261
  r.writeHandler(createRetryQuarantinedMessageHandler(roles));
260
262
  r.writeHandler(attachMessageContentHandler);
261
263
  r.writeHandler(markCredentialStoredHandler);
@@ -27,10 +27,13 @@ function textOf(value: unknown): string {
27
27
  }
28
28
 
29
29
  // A live mailbox wins over a disconnected one: connecting next to a live mailbox is always a duplicate.
30
+ // Among equals the mailbox of the wanted owner kind (shared or personal) wins, then the smallest id,
31
+ // so the outcome does not depend on projection row order.
30
32
  export async function findMailboxByAddress(
31
33
  ctx: Pick<HandlerContext, "db">,
32
34
  tenantId: string,
33
35
  address: string,
36
+ wantedOwnerUserId: string | null,
34
37
  ): Promise<AddressMatch | undefined> {
35
38
  const wanted = normalizeMailAddress(address);
36
39
  const rows = await ctx.db.selectMany(mailAccountsProjectionTable, { tenantId });
@@ -51,10 +54,17 @@ export async function findMailboxByAddress(
51
54
  status: textOf(row["status"]),
52
55
  });
53
56
  }
54
- return matches.find((m) => m.status !== InboundMailAccountStatuses.disconnected) ?? matches[0];
57
+ const rank = (m: AddressMatch): number =>
58
+ (m.status === InboundMailAccountStatuses.disconnected ? 2 : 0) +
59
+ ((m.ownerUserId === null) === (wantedOwnerUserId === null) ? 0 : 1);
60
+ return [...matches].sort((a, b) => rank(a) - rank(b) || a.id.localeCompare(b.id))[0];
55
61
  }
56
62
 
57
- export type ConnectConflict = "already_connected" | "address_disconnected" | "reopen_in_place";
63
+ export type ConnectConflict =
64
+ | "already_connected"
65
+ | "address_disconnected"
66
+ | "reopen_in_place"
67
+ | "replace_disconnected_personal";
58
68
 
59
69
  // A disconnected or sign-in-failed OAuth mailbox of the same provider and owner is reopened (the
60
70
  // callback writes the new token into the same slot); everything else must not silently create a second stream for one address.
@@ -70,6 +80,10 @@ export function connectConflictOf(
70
80
  // A sign-in error of an OAuth mailbox is healed by signing in again, so it reopens like a disconnect.
71
81
  const signInFailed = existing.status === InboundMailAccountStatuses.authError;
72
82
  if (!disconnected && !signInFailed) return "already_connected";
83
+ // A member's disconnected personal mailbox must not lock the address for the team's shared one.
84
+ if (disconnected && wanted.ownerUserId === null && existing.ownerUserId !== null) {
85
+ return "replace_disconnected_personal";
86
+ }
73
87
  const bothOauth =
74
88
  wanted.authMethod === InboundMailAuthMethods.oauth &&
75
89
  existing.authMethod === InboundMailAuthMethods.oauth &&
@@ -57,10 +57,14 @@ function hasContentAlready(events: readonly { type: string; payload: unknown }[]
57
57
 
58
58
  const receivedOwnerSchema = z.object({ ownerUserId: z.string().nullable() });
59
59
 
60
- function ownerUserIdOfStream(events: readonly { type: string; payload: unknown }[]): string | null {
60
+ // `null` inside the result means a shared mailbox; an unreadable stream has no result at all, so a
61
+ // personal mail can never fall through to the shared routing.
62
+ function ownerOfStream(
63
+ events: readonly { type: string; payload: unknown }[],
64
+ ): { readonly ownerUserId: string | null } | undefined {
61
65
  const received = events.find((e) => e.type === INBOUND_MESSAGE_RECEIVED_EVENT_QN);
62
66
  const parsed = receivedOwnerSchema.safeParse(received?.payload);
63
- return parsed.success ? parsed.data.ownerUserId : null;
67
+ return parsed.success ? { ownerUserId: parsed.data.ownerUserId } : undefined;
64
68
  }
65
69
 
66
70
  // Read before the transaction, so it can only skip work: a row that already shows attached content
@@ -160,6 +164,9 @@ export const attachMessageContentHandler = defineWriteHandler({
160
164
  return { isSuccess: true as const, data: { duplicate: true as const } };
161
165
  }
162
166
 
167
+ const owner = ownerOfStream(events);
168
+ if (owner === undefined) return failNotFound("inbound-message-received-event", messageAggId);
169
+
163
170
  const content =
164
171
  payload.outcome !== "fetched"
165
172
  ? undefined
@@ -171,7 +178,7 @@ export const attachMessageContentHandler = defineWriteHandler({
171
178
  content,
172
179
  tenantId,
173
180
  messageAggId,
174
- ownerUserIdOfStream(events),
181
+ owner.ownerUserId,
175
182
  );
176
183
  const appended = await ctx.events.tryAppend({
177
184
  aggregateId: messageAggId,
@@ -12,7 +12,7 @@
12
12
  // stays fast and offline-capable (the test result arrives asynchronously
13
13
  // as a status transition).
14
14
  // - No second account for one address: a live or disconnected address is
15
- // refused (409 reasons in InboundMailConnectErrors); only a disconnected or
15
+ // refused (a disconnected personal mailbox gives way to a shared one) (409 reasons in InboundMailConnectErrors); only a disconnected or
16
16
  // sign-in-failed OAuth mailbox is reopened in place, keeping its account id and cursor.
17
17
  // The reopen returns the existing id and changes nothing yet; the callback re-arms it.
18
18
 
@@ -41,7 +41,15 @@ import {
41
41
  type MailAccountEventPayload,
42
42
  } from "../events.ts";
43
43
  import { accessRolesOf, type InboundMailRoles } from "../mail-roles.ts";
44
- import { connectConflictOf, findMailboxByAddress } from "./account-address.ts";
44
+ import { INBOUND_MAIL_ADDRESS_MAX_CHARS } from "../normalize-inbound-message.ts";
45
+ import {
46
+ connectConflictOf,
47
+ findMailboxByAddress,
48
+ normalizeMailAddress,
49
+ } from "./account-address.ts";
50
+
51
+ // 'inma': serializes the duplicate-address check and the append per tenant and address (the lock key is tenant-scoped).
52
+ const CONNECT_ADDRESS_LOCK_NAMESPACE = 0x696e6d61;
45
53
 
46
54
  export const connectAccountSchema = z
47
55
  .object({
@@ -55,7 +63,7 @@ export const connectAccountSchema = z
55
63
  ]),
56
64
  displayName: z.string().trim().max(200),
57
65
  /** Mailbox address in plaintext; it is encrypted here. */
58
- address: z.string().min(1).max(320),
66
+ address: z.string().min(1).max(INBOUND_MAIL_ADDRESS_MAX_CHARS),
59
67
  /** "shared" = shared across the tenant (info@) · "user" = the caller's
60
68
  * personal mailbox (ownerUserId is taken from the session, never from
61
69
  * the payload—preventing claims on another user's mailbox). */
@@ -96,7 +104,11 @@ export function createConnectAccountHandler({ adminRoles }: InboundMailRoles): W
96
104
  ? event.user.id
97
105
  : null;
98
106
 
99
- const existing = await findMailboxByAddress(ctx, tenantId, payload.address);
107
+ await ctx.db.advisoryXactLock(
108
+ CONNECT_ADDRESS_LOCK_NAMESPACE,
109
+ normalizeMailAddress(payload.address),
110
+ );
111
+ const existing = await findMailboxByAddress(ctx, tenantId, payload.address, ownerUserId);
100
112
  if (existing) {
101
113
  const matched = connectConflictOf(existing, {
102
114
  authMethod: payload.authMethod,
@@ -117,11 +129,13 @@ export function createConnectAccountHandler({ adminRoles }: InboundMailRoles): W
117
129
  data: { accountId: existing.id, reconnected: true as const },
118
130
  };
119
131
  }
120
- const { reason, i18nKey } =
121
- conflict === "address_disconnected"
122
- ? InboundMailConnectErrors.addressDisconnected
123
- : InboundMailConnectErrors.addressAlreadyConnected;
124
- return writeFailure(new UnprocessableError(reason, { i18nKey }));
132
+ if (conflict !== "replace_disconnected_personal") {
133
+ const { reason, i18nKey } =
134
+ conflict === "address_disconnected"
135
+ ? InboundMailConnectErrors.addressDisconnected
136
+ : InboundMailConnectErrors.addressAlreadyConnected;
137
+ return writeFailure(new UnprocessableError(reason, { i18nKey }));
138
+ }
125
139
  }
126
140
 
127
141
  // PII-encrypt the address before the append. This is the only write path to