@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
@@ -25,6 +25,7 @@
25
25
  // proration, multi-currency, coupons, etc. remain provider-specific and
26
26
  // are available through the Customer Portal link.
27
27
 
28
+ import type { SignatureExtraRouteDeps } from "@cosmicdrift/kumiko-framework/api";
28
29
  import type { TenantDb } from "@cosmicdrift/kumiko-framework/db";
29
30
  import type { HandlerContext, TenantId } from "@cosmicdrift/kumiko-framework/engine";
30
31
  import type { SecretsContext } from "@cosmicdrift/kumiko-framework/secrets";
@@ -66,9 +67,11 @@ export type SubscriptionEvent = {
66
67
  /** Platform tenant ID (provider-customer metadata or lookup via
67
68
  * providerCustomerId). The plugin performs the resolution. */
68
69
  readonly tenantId: string;
69
- /** Consent id echoed back from checkout metadata; omitted when absent or
70
- * malformed. */
71
- readonly consentId?: string;
70
+ /** Checkout that created this subscription (Paddle transaction id, Stripe
71
+ * session id, Mollie first-payment id). `created` events are only accepted
72
+ * when the checkout is in the server's checkout ledger; later events of the
73
+ * same subscription do not need it. */
74
+ readonly providerCheckoutId?: string;
72
75
  /** Provider-owned customer ID for later lookup when events lack
73
76
  * metadata. */
74
77
  readonly providerCustomerId: string;
@@ -119,12 +122,10 @@ export type PaymentEvent = {
119
122
  * create time) — never from a freely-choosable payload field, or an
120
123
  * attacker could attribute payments to someone else's tenant. */
121
124
  readonly tenantId: string;
122
- /** Consent id echoed back from checkout metadata; omitted when absent or
123
- * malformed. */
124
- readonly consentId?: string;
125
- /** Provider's checkout/payment object id (Stripe checkout session id) —
126
- * lets consumers key their own grants without the raw provider payload. */
127
- readonly providerCheckoutId?: string;
125
+ /** Provider's checkout/payment object id (Stripe checkout session id,
126
+ * Paddle transaction id). Must name a checkout the server opened itself,
127
+ * otherwise the payment is ignored. */
128
+ readonly providerCheckoutId: string;
128
129
  /** Provider's own customer-id. */
129
130
  readonly providerCustomerId: string;
130
131
  /** Provider's own price/plan-ID of the purchased item. */
@@ -208,15 +209,12 @@ export type SubscriptionProviderPlugin = {
208
209
  * credit top-ups). Optional with default `"subscription"` — existing
209
210
  * callers are unaffected. */
210
211
  readonly mode?: "subscription" | "payment";
211
- /** Id of the consumer-protection consent recorded for this checkout.
212
- * Travels as provider metadata and comes back on the webhook event. */
213
- readonly consentId?: string;
214
212
  /** App locale (BCP-47-ish, e.g. "de", "de-DE") for the hosted page. */
215
213
  readonly locale?: string;
216
214
  /** Text shown next to the submit button on the hosted page. */
217
215
  readonly submitMessage?: string;
218
216
  },
219
- ) => Promise<{ readonly url: string }>;
217
+ ) => Promise<{ readonly url: string; readonly providerCheckoutId: string }>;
220
218
 
221
219
  /**
222
220
  * **Post-tenant-resolution** — called from a write handler with a
@@ -340,7 +338,6 @@ export type SubscriptionProviderPlugin = {
340
338
  readonly providerSubscriptionId: string;
341
339
  readonly targetPriceId: string;
342
340
  readonly tenantId: string;
343
- readonly consentId?: string;
344
341
  },
345
342
  ) => Promise<void>;
346
343
 
@@ -355,6 +352,18 @@ export type SubscriptionProviderPlugin = {
355
352
  * app's config (e.g. Stripe's price-to-tier — same silent-drop the
356
353
  * webhook path already applies to an unmapped price).
357
354
  */
355
+ /**
356
+ * Asked when billing-foundation ignored a verified event because its checkout is not in
357
+ * the ledger. Answering true makes the webhook route reply with a retryable 503 instead
358
+ * of 200, for providers that can still ledger the checkout shortly after (migration
359
+ * sweeps). Absent = never redeliver.
360
+ */
361
+ readonly shouldRedeliverIgnoredEvent?: (args: {
362
+ readonly event: SubscriptionEvent | PaymentEvent;
363
+ readonly reason: string;
364
+ readonly deps: SignatureExtraRouteDeps;
365
+ }) => Promise<boolean>;
366
+
358
367
  readonly retrieveSubscription?: (
359
368
  ctx: HandlerContext,
360
369
  providerSubscriptionId: string,
@@ -484,13 +493,17 @@ export type ConsumerProtectionOptions = {
484
493
  /** Per-provider texts keyed by provider name, e.g. for a merchant-of-record
485
494
  * provider that issues the invoice and VAT itself. `vatNote` here replaces
486
495
  * the global one in that provider's confirmation mail; `checkoutNote` is
487
- * shown under the provider choice. de and en are required for each text. */
496
+ * shown under the provider choice. de and en are required for each text.
497
+ * `refundLink` replaces `legalLinks.refund` for that provider (one link for
498
+ * every locale, or one per consent locale); a provider without it falls back
499
+ * to `legalLinks.refund`. */
488
500
  readonly providerTexts?: Readonly<
489
501
  Record<
490
502
  string,
491
503
  {
492
504
  readonly vatNote?: Readonly<Record<string, string>>;
493
505
  readonly checkoutNote?: Readonly<Record<string, string>>;
506
+ readonly refundLink?: string | Readonly<Record<ConsentLocale, string>>;
494
507
  }
495
508
  >
496
509
  >;
@@ -574,10 +587,28 @@ export type BillingPlanView = {
574
587
  readonly action: BillingPlanAction;
575
588
  };
576
589
 
590
+ export type BillingConsumerProtectionView = {
591
+ readonly consentTexts: Readonly<
592
+ Record<
593
+ "de" | "en",
594
+ {
595
+ readonly earlyPerformance: string;
596
+ readonly withdrawalLoss: string;
597
+ /** Present only when `documentsAcknowledgement` is on. */
598
+ readonly documentsAcknowledgement?: string;
599
+ readonly consentTextVersion: string;
600
+ }
601
+ >
602
+ >;
603
+ readonly legalLinks: Readonly<Record<ConsentLocale, LegalLinkSet>>;
604
+ };
605
+
577
606
  export type BillingProviderView = {
578
607
  readonly name: string;
579
608
  readonly displayName: string;
580
609
  readonly note?: Readonly<Record<string, string>>;
610
+ /** Only set when the provider has its own `providerTexts.refundLink`; replaces the top-level `consumerProtection` while this provider is selected. */
611
+ readonly consumerProtection?: BillingConsumerProtectionView;
581
612
  readonly plans: readonly BillingPlanView[];
582
613
  };
583
614
 
@@ -619,21 +650,7 @@ export type BillingPlansResult = {
619
650
  /** Present only when `catalog.priceNoteKey` is configured. */
620
651
  readonly priceNoteKey?: string;
621
652
  /** Present only when `consumerProtection` is configured. */
622
- readonly consumerProtection?: {
623
- readonly consentTexts: Readonly<
624
- Record<
625
- "de" | "en",
626
- {
627
- readonly earlyPerformance: string;
628
- readonly withdrawalLoss: string;
629
- /** Present only when `documentsAcknowledgement` is on. */
630
- readonly documentsAcknowledgement?: string;
631
- readonly consentTextVersion: string;
632
- }
633
- >
634
- >;
635
- readonly legalLinks: Readonly<Record<ConsentLocale, LegalLinkSet>>;
636
- };
653
+ readonly consumerProtection?: BillingConsumerProtectionView;
637
654
  };
638
655
 
639
656
  // r.useExtension options-shape, co-located since the framework never imports upward.
@@ -30,8 +30,26 @@ function isRootRelativeOrHttpsUrl(link: string): boolean {
30
30
  }
31
31
  }
32
32
 
33
+ function validateProviderRefundLink(
34
+ providerName: string,
35
+ refundLink: string | Readonly<Record<ConsentLocale, string>>,
36
+ ): void {
37
+ const links =
38
+ typeof refundLink === "string"
39
+ ? [["refundLink", refundLink] as const]
40
+ : CONSENT_LOCALES.map((locale) => [`refundLink.${locale}`, refundLink[locale]] as const);
41
+ for (const [path, link] of links) {
42
+ if (typeof link !== "string" || !isRootRelativeOrHttpsUrl(link)) {
43
+ throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.consumerProtectionInvalid, {
44
+ message: `createBillingFoundationFeature: consumerProtection.providerTexts.${providerName}.${path} "${link}" must be a root-relative path ("/..." not "//") or an absolute https URL.`,
45
+ });
46
+ }
47
+ }
48
+ }
49
+
33
50
  function validateProviderTexts(cp: ConsumerProtectionOptions): void {
34
51
  for (const [providerName, texts] of Object.entries(cp.providerTexts ?? {})) {
52
+ if (texts.refundLink !== undefined) validateProviderRefundLink(providerName, texts.refundLink);
35
53
  for (const [textName, text] of [
36
54
  ["vatNote", texts.vatNote],
37
55
  ["checkoutNote", texts.checkoutNote],
@@ -52,7 +52,7 @@ function manageOrReactivateAction(
52
52
  canManage: boolean,
53
53
  subscription: BillingPlansResult["subscription"],
54
54
  t: UseTranslation,
55
- onManage: () => void,
55
+ onManage: () => Promise<void>,
56
56
  redirecting: boolean,
57
57
  ): PlanCardActionSlot | undefined {
58
58
  if (!canManage) return undefined;
@@ -62,7 +62,9 @@ function manageOrReactivateAction(
62
62
  ? "billing-foundation.plans.reactivate"
63
63
  : "billing-foundation.plans.manage",
64
64
  ),
65
- onClick: onManage,
65
+ onClick: () => {
66
+ void onManage();
67
+ },
66
68
  disabled: redirecting,
67
69
  };
68
70
  }
@@ -76,7 +78,7 @@ function planCta(
76
78
  plan: BillingPlanView,
77
79
  result: BillingPlansResult,
78
80
  t: UseTranslation,
79
- onAction: (tier: string, kind: "checkout" | "switch") => void,
81
+ onAction: (tier: string, kind: "checkout" | "switch") => Promise<void>,
80
82
  redirecting: boolean,
81
83
  ): PlanCardActionSlot | undefined {
82
84
  if (plan.action === BillingPlanActions.current) return undefined;
@@ -96,7 +98,9 @@ function planCta(
96
98
  }
97
99
  return {
98
100
  label,
99
- onClick: () => onAction(plan.tier, kind),
101
+ onClick: () => {
102
+ void onAction(plan.tier, kind);
103
+ },
100
104
  disabled: redirecting,
101
105
  };
102
106
  }
@@ -264,6 +268,7 @@ export function BillingPlansPanel(_props: ExtensionSectionProps): ReactNode {
264
268
  const switchPlan =
265
269
  switchTier !== null ? shownPlans.find((plan) => plan.tier === switchTier) : undefined;
266
270
  const consumerProtection = result.consumerProtection;
271
+ const checkoutConsumerProtection = activeProvider?.consumerProtection ?? consumerProtection;
267
272
  const noteLocale = resolveConsentLocale(locale);
268
273
  const noteOf = (provider: { readonly note?: Readonly<Record<string, string>> }) =>
269
274
  provider.note?.[noteLocale] ?? provider.note?.["en"];
@@ -385,7 +390,7 @@ export function BillingPlansPanel(_props: ExtensionSectionProps): ReactNode {
385
390
  renewalKey: renewalKey(consentPlan.price),
386
391
  count: new Intl.NumberFormat(locale).format(consentPlan.price.intervalCount ?? 1),
387
392
  }}
388
- consumerProtection={consumerProtection}
393
+ consumerProtection={checkoutConsumerProtection}
389
394
  providerChoice={providerChoiceFor(consentPlan.tier)}
390
395
  note={singleProviderNote}
391
396
  onOrder={(consent) => orderWithConsent(consentPlan.tier, consent)}
@@ -30,7 +30,7 @@ const DECLARATION_TYPES: readonly ContractTerminationDeclarationType[] = [
30
30
  ];
31
31
  const TERMINATION_KINDS: readonly ContractTerminationKind[] = ["ordinary", "extraordinary"];
32
32
 
33
- // kumiko-lint-ignore no-custom-primitives Uses usePrimitives().Modal internally, name is a billing domain action, not a primitive reimplementation
33
+ // biome-ignore lint/plugin: Uses usePrimitives().Modal internally, name is a billing domain action, not a primitive reimplementation
34
34
  export function CancelContractDialog({
35
35
  open,
36
36
  onOpenChange,
@@ -48,7 +48,7 @@ export type CheckoutConsentDialogProps = {
48
48
  readonly onConsentTextOutdated: () => void;
49
49
  };
50
50
 
51
- // kumiko-lint-ignore no-custom-primitives Uses usePrimitives().Modal internally, name is a billing domain action, not a primitive reimplementation
51
+ // biome-ignore lint/plugin: Uses usePrimitives().Modal internally, name is a billing domain action, not a primitive reimplementation
52
52
  export function CheckoutConsentDialog({
53
53
  open,
54
54
  onOpenChange,
@@ -68,6 +68,9 @@ export const SubscriptionFoundationHandlers = {
68
68
  /** Tenant-Admin terminates or withdraws from the contract of their own
69
69
  * tenant (consumerProtection only). */
70
70
  terminateContract: "billing-foundation:write:terminate-contract",
71
+ /** System-only: puts a checkout the server opened earlier into the checkout
72
+ * ledger (idempotent). Used by provider migration jobs. */
73
+ recordCheckoutOpened: "billing-foundation:write:record-checkout-opened",
71
74
  /** Tenant-Admin/purchase-role picks a plan tier from the catalog with no
72
75
  * existing non-terminal subscription — starts a hosted checkout for the
73
76
  * matching price. Only registered when `createBillingFoundationFeature`
@@ -148,8 +151,8 @@ export const SubscriptionCancelTimings = {
148
151
  export type SubscriptionCancelTiming =
149
152
  (typeof SubscriptionCancelTimings)[keyof typeof SubscriptionCancelTimings];
150
153
 
151
- // consentId is echoed back by the provider (checkout metadata), so it is
152
- // untrusted input: bounded length, id-ish charset only.
154
+ // Only the legacy-checkout migration reads a consentId back from provider
155
+ // metadata; that value is untrusted: bounded length, id-ish charset only.
153
156
  const CONSENT_ID_PATTERN = /^[A-Za-z0-9_-]{1,100}$/;
154
157
 
155
158
  export function parseProviderConsentId(raw: unknown): string | undefined {
@@ -38,7 +38,7 @@ export type PlanSwitchConfirmDialogProps = {
38
38
  readonly onConsentTextOutdated: () => void;
39
39
  };
40
40
 
41
- // kumiko-lint-ignore no-custom-primitives Uses usePrimitives().Modal internally, name is a billing domain action, not a primitive reimplementation
41
+ // biome-ignore lint/plugin: Uses usePrimitives().Modal internally, name is a billing domain action, not a primitive reimplementation
42
42
  export function PlanSwitchConfirmDialog({
43
43
  open,
44
44
  onOpenChange,
@@ -5,7 +5,9 @@
5
5
  // webhook signature in verify() IS the auth, so no c.get("user") here.
6
6
 
7
7
  import { ExtraRouteRejection, signatureRoute } from "@cosmicdrift/kumiko-framework/api";
8
+ import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
8
9
  import type { Context } from "hono";
10
+ import { IgnoredEventReasons } from "./checkout-ledger.ts";
9
11
  import type { PaymentEvent, SubscriptionEvent, SubscriptionProviderPlugin } from "./types.ts";
10
12
  import {
11
13
  BILLING_FOUNDATION_FEATURE,
@@ -106,20 +108,13 @@ export function createSubscriptionWebhookRoute(options: SubscriptionWebhookRoute
106
108
  providerCustomerId: parsed.providerCustomerId,
107
109
  priceId: parsed.priceId,
108
110
  ...(parsed.quantity !== undefined && { quantity: parsed.quantity }),
109
- ...(parsed.consentId !== undefined && { consentId: parsed.consentId }),
110
- ...(parsed.providerCheckoutId !== undefined && {
111
- providerCheckoutId: parsed.providerCheckoutId,
112
- }),
111
+ providerCheckoutId: parsed.providerCheckoutId,
113
112
  },
114
113
  });
115
- return respondFromDispatch(
116
- c,
117
- dispatched.isSuccess && options.afterDispatch
118
- ? await options.afterDispatch(dispatched, tenantId, deps, parsed)
119
- : dispatched,
114
+ return answerWebhook(c, { dispatched, parsed, deps, options }, [
120
115
  "subscription_payment_webhook_processing_failed",
121
116
  "Internal error processing payment event",
122
- );
117
+ ]);
123
118
  }
124
119
  const dispatched = await deps.dispatchSystemWrite({
125
120
  handlerQn: SubscriptionFoundationHandlers.processEvent,
@@ -137,21 +132,73 @@ export function createSubscriptionWebhookRoute(options: SubscriptionWebhookRoute
137
132
  ...(parsed.providerEventAt !== undefined && {
138
133
  providerEventAtIso: parsed.providerEventAt,
139
134
  }),
140
- ...(parsed.consentId !== undefined && { consentId: parsed.consentId }),
135
+ ...(parsed.providerCheckoutId !== undefined && {
136
+ providerCheckoutId: parsed.providerCheckoutId,
137
+ }),
141
138
  },
142
139
  });
143
- return respondFromDispatch(
144
- c,
145
- dispatched.isSuccess && options.afterDispatch
146
- ? await options.afterDispatch(dispatched, tenantId, deps, parsed)
147
- : dispatched,
140
+ return answerWebhook(c, { dispatched, parsed, deps, options }, [
148
141
  "subscription_webhook_processing_failed",
149
142
  "Internal error processing subscription event",
150
- );
143
+ ]);
151
144
  },
152
145
  });
153
146
  }
154
147
 
148
+ type WebhookOutcome = {
149
+ readonly dispatched: import("@cosmicdrift/kumiko-framework/engine").WriteResult;
150
+ readonly parsed: SubscriptionEvent | PaymentEvent;
151
+ readonly deps: import("@cosmicdrift/kumiko-framework/api").SignatureExtraRouteDeps;
152
+ readonly options: SubscriptionWebhookRouteOptions;
153
+ };
154
+
155
+ /** Redelivery (503) when the event may still become admissible, otherwise the afterDispatch
156
+ * side-effect for a processed event and the shared 200/500 mapping. */
157
+ async function answerWebhook(
158
+ c: Context,
159
+ { dispatched, parsed, deps, options }: WebhookOutcome,
160
+ [errorCode, errorMessage]: readonly [string, string],
161
+ ): Promise<Response> {
162
+ const redeliver = await redeliveryReason(dispatched, parsed, deps);
163
+ if (redeliver !== undefined) return retryLater(c, redeliver);
164
+ const settled =
165
+ dispatched.isSuccess && !wasIgnored(dispatched) && options.afterDispatch
166
+ ? await options.afterDispatch(dispatched, parsed.tenantId, deps, parsed)
167
+ : dispatched;
168
+ return respondFromDispatch(c, settled, errorCode, errorMessage);
169
+ }
170
+
171
+ /** Why the provider should send this ignored event again, or undefined when 200 is right: the
172
+ * handler asked for it (the event beat its subscription's `created`), or the provider plugin
173
+ * expects to ledger the checkout shortly (migration sweep). */
174
+ async function redeliveryReason(
175
+ dispatched: import("@cosmicdrift/kumiko-framework/engine").WriteResult,
176
+ event: SubscriptionEvent | PaymentEvent,
177
+ deps: import("@cosmicdrift/kumiko-framework/api").SignatureExtraRouteDeps,
178
+ ): Promise<string | undefined> {
179
+ if (!dispatched.isSuccess || !wasIgnored(dispatched)) return undefined;
180
+ const reason = propertyOf(dispatched.data, "reason");
181
+ if (typeof reason !== "string") return undefined;
182
+ if (propertyOf(dispatched.data, "retry") === true) return reason;
183
+ if (reason !== IgnoredEventReasons.checkoutNotInLedger) return undefined;
184
+ const plugin = resolveProvider(deps.registry, event.providerName);
185
+ const redeliver = await plugin?.shouldRedeliverIgnoredEvent?.({ event, reason, deps });
186
+ return redeliver === true ? reason : undefined;
187
+ }
188
+
189
+ function retryLater(c: Context, reason: string): Response {
190
+ c.header("Retry-After", "60");
191
+ return c.json({ error: { code: "subscription_event_redeliver", reason } }, 503);
192
+ }
193
+
194
+ /** The handler refused the event (not in the checkout ledger, foreign subscription):
195
+ * nothing was stored, so no side-effect (credits, tier sync) may follow. */
196
+ function wasIgnored(
197
+ dispatched: import("@cosmicdrift/kumiko-framework/engine").WriteResult,
198
+ ): boolean {
199
+ return dispatched.isSuccess && propertyOf(dispatched.data, "ignored") === true;
200
+ }
201
+
155
202
  /** Shared 500/200-mapping for both dispatch branches above. Internal error →
156
203
  * provider should retry, hence 500 instead of 401/404 (transient, not a config-bug). */
157
204
  function respondFromDispatch(
@@ -166,5 +213,6 @@ function respondFromDispatch(
166
213
  500,
167
214
  );
168
215
  }
216
+ if (wasIgnored(dispatched)) return c.json({ ignored: true }, 200);
169
217
  return c.json({ processed: true, ...((dispatched.data as object) ?? {}) }, 200); // @cast-boundary engine-bridge
170
218
  }
@@ -18,7 +18,6 @@ const CAP_COUNTER_ROLLING_NAMESPACE = "8b2ad0c6-1f3e-4f7c-9b8a-3c4d5e6f7a8b";
18
18
  * Parallel bookings for the same triple share one stream; the event store's
19
19
  * optimistic lock serializes them and bookCapUsage retries the loser.
20
20
  */
21
- // @wrapper-known uuid-domain
22
21
  export function capCounterAggregateId(
23
22
  tenantId: string,
24
23
  capName: string,
@@ -42,7 +41,6 @@ export function capCounterAggregateId(
42
41
  * this with tenantId + capName and appends increment events to the stream.
43
42
  * Race-free because the event store appends with an auto-incrementing version.
44
43
  */
45
- // @wrapper-known uuid-domain
46
44
  export function rollingCapAggregateId(tenantId: string, capName: string): string {
47
45
  return uuidv5(`${tenantId}|${capName}`, CAP_COUNTER_ROLLING_NAMESPACE);
48
46
  }
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.414.0",
4
+ "type": "fix",
5
+ "title": "Canonical stock-cap lock keys",
6
+ "detail": "The stock-cap lock key sorts where-keys at every depth and serializes Temporal and Date values by their string form, so handlers counting the same rows share one lock."
7
+ },
2
8
  {
3
9
  "version": "0.389.0",
4
10
  "type": "fix",
@@ -42,10 +42,25 @@ export type StockCapSpec<TCaps> = {
42
42
 
43
43
  // Lock on the counted set, not on `code`: two handlers capping the same rows under
44
44
  // different codes must still serialize against each other.
45
- // guard:dup-ok lock key of one counted set; only the sorted-entries shape matches other key builders
46
- function countedSetKey(spec: Pick<StockCapSpec<unknown>, "table" | "where">): string {
47
- const where = Object.entries(spec.where ?? {}).sort(([a], [b]) => a.localeCompare(b));
48
- return `${spec.table.tableName}:${JSON.stringify(where)}`;
45
+ export function countedSetKey(spec: Pick<StockCapSpec<unknown>, "table" | "where">): string {
46
+ return `${spec.table.tableName}:${canonicalWhereJson(spec.where ?? {})}`;
47
+ }
48
+
49
+ // Sorted keys at every depth; toJSON values (Temporal, Date) serialize as their string form
50
+ // instead of being walked as empty objects.
51
+ function canonicalWhereJson(value: unknown): string {
52
+ if (Array.isArray(value)) return `[${value.map(canonicalWhereJson).join(",")}]`;
53
+ if (value === null || typeof value !== "object" || hasToJson(value)) {
54
+ return JSON.stringify(value) ?? "null";
55
+ }
56
+ const entries = Object.entries(value)
57
+ .filter(([, nested]) => nested !== undefined)
58
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
59
+ return `{${entries.map(([key, nested]) => `${JSON.stringify(key)}:${canonicalWhereJson(nested)}`).join(",")}}`;
60
+ }
61
+
62
+ function hasToJson(value: object): boolean {
63
+ return "toJSON" in value && typeof value.toJSON === "function";
49
64
  }
50
65
 
51
66
  export type StockCapGuard<TCaps> = {
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.414.0",
4
+ "type": "fix",
5
+ "title": "Visible overage on not-included caps, batched limits",
6
+ "detail": "A cap with limit 0 and usage above zero shows the used amount with cap-overview.notIncludedButUsed instead of only \"Not included\" (bar, cap cards, tenant list). CapSpec gets an optional limitBatch that tenant-caps:list prefers over one limit() call per tenant and cap, and the limit comment no longer claims it is resolved once per tier."
7
+ },
2
8
  {
3
9
  "version": "0.397.0",
4
10
  "type": "improvement",
@@ -11,7 +11,7 @@ import * as z from "zod";
11
11
  import { subscriptionsProjectionTable } from "../../billing-foundation/index.ts";
12
12
  import { decryptTenantNames, tenantTable } from "../../tenant/index.ts";
13
13
  import { tierAssignmentEntity } from "../../tier-engine/index.ts";
14
- import type { CapSpec, CapSpecLimitContext, CapUsage } from "../types.ts";
14
+ import type { CapSpec, CapSpecLimitContext, CapSpecLimitTenant, CapUsage } from "../types.ts";
15
15
  import { capFieldName } from "../web/constants.ts";
16
16
  import { computeFraction } from "../web/usage-math.ts";
17
17
 
@@ -84,15 +84,31 @@ async function resolveLimitsByTenantAndCap(
84
84
  configFor: ((tenantId: TenantId) => ConfigAccessor) | undefined,
85
85
  db: CapSpecLimitContext["db"],
86
86
  ): Promise<ReadonlyMap<string, number | null>> {
87
+ const limitTenants: readonly CapSpecLimitTenant[] = tenants.map(({ tenantId, tier }) => ({
88
+ config: configFor?.(tenantId),
89
+ tenantId,
90
+ tier,
91
+ }));
87
92
  const entries = await Promise.all(
88
- tenants.flatMap(({ tenantId, tier }) => {
89
- const context: CapSpecLimitContext = { config: configFor?.(tenantId), tenantId, db };
90
- return caps.map(
91
- async (cap) => [tenantCapKey(tenantId, cap.id), await cap.limit(tier, context)] as const,
93
+ caps.map(async (cap) => {
94
+ if (cap.limitBatch) {
95
+ const batch = await cap.limitBatch(limitTenants, db);
96
+ return limitTenants.map(
97
+ ({ tenantId }) => [tenantCapKey(tenantId, cap.id), batch.get(tenantId) ?? null] as const,
98
+ );
99
+ }
100
+ return Promise.all(
101
+ limitTenants.map(async ({ tier, ...tenantContext }) => {
102
+ const context: CapSpecLimitContext = { ...tenantContext, db };
103
+ return [
104
+ tenantCapKey(tenantContext.tenantId, cap.id),
105
+ await cap.limit(tier, context),
106
+ ] as const;
107
+ }),
92
108
  );
93
109
  }),
94
110
  );
95
- return new Map(entries);
111
+ return new Map(entries.flat());
96
112
  }
97
113
 
98
114
  // tier is a plain string with no defined ordering — lt/gt have no meaning
@@ -17,6 +17,7 @@ export const CAP_OVERVIEW_I18N: Readonly<Record<string, LocalizedString>> = {
17
17
  "cap-overview.cards.viewAll": { en: "View all usage" },
18
18
  "cap-overview.notMeasured": { en: "Not measured yet" },
19
19
  "cap-overview.notIncluded": { en: "Not included" },
20
+ "cap-overview.notIncludedButUsed": { en: "{used} · not included" },
20
21
  "cap-overview.unlimited": { en: "{used} · unlimited" },
21
22
  "cap-overview.errors.progressPrimitiveMissing": {
22
23
  en: "Usage bar unavailable — Progress primitive is not registered.",
@@ -10,6 +10,7 @@ export {
10
10
  export type {
11
11
  CapSpec,
12
12
  CapSpecLimitContext,
13
+ CapSpecLimitTenant,
13
14
  CapUsage,
14
15
  CapUsageTone,
15
16
  CapUsageWithMeta,
@@ -17,6 +17,8 @@ export type CapSpecLimitContext = CapLimitContext & {
17
17
  readonly db: TenantDb;
18
18
  };
19
19
 
20
+ export type CapSpecLimitTenant = Omit<CapSpecLimitContext, "db"> & { readonly tier: string };
21
+
20
22
  // Consumer-owned cap definition. `usage`/`usageBatch` receive the SAME
21
23
  // unfiltered system-mode TenantDb the handler itself reads through — the
22
24
  // callback is responsible for scoping its own app-owned tables by tenantId,
@@ -27,11 +29,19 @@ export type CapSpec = {
27
29
  readonly label: string;
28
30
  // `null` = unlimited (a pure usage meter: counted but never capped).
29
31
  // `<= 0` = not part of this tier — existing, unchanged meaning (usage-math.ts).
30
- // Resolved once per (cap, tier) per request, so a config read here is cheap.
32
+ // Resolved per (cap, tenant), so a list of N tenants calls it N times; a limit that reads
33
+ // app rows from `context.db` should also provide `limitBatch` for the list.
31
34
  readonly limit: (
32
35
  tier: string,
33
36
  context: CapSpecLimitContext,
34
37
  ) => number | null | Promise<number | null>;
38
+ // Batched `limit` for the tenant-caps:list screen: called once per cap with the page's
39
+ // tenants. Optional: falls back to per-tenant `limit()`. A tenant absent from the returned
40
+ // map counts as unlimited (`null`).
41
+ readonly limitBatch?: (
42
+ tenants: readonly CapSpecLimitTenant[],
43
+ db: TenantDb,
44
+ ) => Promise<ReadonlyMap<TenantId, number | null>>;
35
45
  // `null` means "no measurement exists yet for this cap" (not "0 used") —
36
46
  // callers that haven't wired up instrumentation return null instead of a
37
47
  // number they don't actually have.
@@ -19,7 +19,7 @@ import type { CapIconKey, CapUnit, CapUsageTone, CapUsageWithMeta } from "../typ
19
19
  import { formatCapAmount, formatCapUsedOfLimit } from "./cap-amount-format.ts";
20
20
  import { CapUsageBar } from "./cap-usage-bar.tsx";
21
21
  import { CapOverviewQueries, MY_CAPS_SCREEN_ID } from "./constants.ts";
22
- import { isCapNotIncluded } from "./usage-math.ts";
22
+ import { isCapNotIncluded, isCapUsedWithoutAllowance } from "./usage-math.ts";
23
23
 
24
24
  type CapsUsageResponse = { readonly rows: readonly CapUsageWithMeta[] };
25
25
 
@@ -133,7 +133,11 @@ function CapUsageStat({
133
133
  label={t(cap.label)}
134
134
  value={
135
135
  notIncluded
136
- ? t("cap-overview.notIncluded")
136
+ ? isCapUsedWithoutAllowance(cap.limit, cap.used)
137
+ ? t("cap-overview.notIncludedButUsed", {
138
+ used: formatCapAmount(cap.used ?? 0, cap.unit, locale),
139
+ })
140
+ : t("cap-overview.notIncluded")
137
141
  : !isMeasured(cap)
138
142
  ? EMPTY_VALUE_PLACEHOLDER
139
143
  : cap.limit === null
@@ -2,7 +2,7 @@ import { useLocale, usePrimitives, useTranslation } from "@cosmicdrift/kumiko-re
2
2
  import type { ReactNode } from "react";
3
3
  import type { CapUsage } from "../types.ts";
4
4
  import { formatCapAmount, formatCapUsedOfLimit } from "./cap-amount-format.ts";
5
- import { computeTone, isCapNotIncluded } from "./usage-math.ts";
5
+ import { computeTone, isCapNotIncluded, isCapUsedWithoutAllowance } from "./usage-math.ts";
6
6
 
7
7
  export function CapUsageBar({
8
8
  usage,
@@ -18,6 +18,15 @@ export function CapUsageBar({
18
18
  const locale = useLocale().locale();
19
19
 
20
20
  if (isCapNotIncluded(usage.limit)) {
21
+ if (isCapUsedWithoutAllowance(usage.limit, usage.used)) {
22
+ return (
23
+ <Text variant="small" testId="cap-usage-not-included-used">
24
+ {t("cap-overview.notIncludedButUsed", {
25
+ used: formatCapAmount(usage.used ?? 0, usage.unit, locale),
26
+ })}
27
+ </Text>
28
+ );
29
+ }
21
30
  return (
22
31
  <Text variant="small" testId="cap-usage-not-included">
23
32
  {t("cap-overview.notIncluded")}
@@ -12,6 +12,11 @@ export function isCapNotIncluded(limit: number | null): boolean {
12
12
  return limit !== null && limit <= 0;
13
13
  }
14
14
 
15
+ // Leftover data after a downgrade: the tier grants nothing, yet usage is above zero.
16
+ export function isCapUsedWithoutAllowance(limit: number | null, used: number | null): boolean {
17
+ return isCapNotIncluded(limit) && used !== null && used > 0;
18
+ }
19
+
15
20
  function rawFraction(used: number, limit: number | null): number {
16
21
  if (limit === null) return 0;
17
22
  if (isCapNotIncluded(limit)) return 0;
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.414.0",
4
+ "type": "improvement",
5
+ "title": "readStateByKeys is readable by a job's system user",
6
+ "detail": "`channel-in-app:query:readStateByKeys` now accepts the `system` role besides SystemAdmin, so a job running as the system user of a tenant reads the read state of its own tenant's messages directly. It still sees only keys of the caller's tenant."
7
+ },
2
8
  {
3
9
  "version": "0.409.0",
4
10
  "type": "improvement",