@cosmicdrift/kumiko-samples 0.413.0 → 0.414.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 (459) 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/unlock-token.ts +0 -2
  36. package/packages/bundled-features/src/auth-email-password/verification-token.ts +0 -2
  37. package/packages/bundled-features/src/auth-email-password/web/auth-form-primitives.tsx +2 -2
  38. package/packages/bundled-features/src/auth-email-password/web/auth-gate.tsx +2 -2
  39. package/packages/bundled-features/src/auth-email-password/web/auth-redirect.ts +5 -0
  40. package/packages/bundled-features/src/auth-email-password/web/forgot-password-screen.tsx +1 -6
  41. package/packages/bundled-features/src/auth-email-password/web/invite-accept-screen.tsx +1 -1
  42. package/packages/bundled-features/src/auth-email-password/web/return-path.ts +2 -1
  43. package/packages/bundled-features/src/auth-email-password/web/session.tsx +10 -12
  44. package/packages/bundled-features/src/auth-email-password/web/signup-screen.tsx +1 -6
  45. package/packages/bundled-features/src/auth-email-password/web/static-account.ts +6 -1
  46. package/packages/bundled-features/src/auth-email-password/web/tenant-switcher.tsx +1 -1
  47. package/packages/bundled-features/src/auth-email-password/web/token-confirm-screen.tsx +4 -5
  48. package/packages/bundled-features/src/auth-email-password/web/user-menu.tsx +1 -1
  49. package/packages/bundled-features/src/auth-mfa/web/mfa-code-or-recovery-field.tsx +17 -1
  50. package/packages/bundled-features/src/auth-mfa/web/mfa-disable-dialog.tsx +1 -1
  51. package/packages/bundled-features/src/auth-mfa/web/mfa-regenerate-recovery-dialog.tsx +1 -1
  52. package/packages/bundled-features/src/auth-mfa/web/mfa-setup-preauth-screen.tsx +1 -1
  53. package/packages/bundled-features/src/auth-mfa/web/mfa-verify-screen.tsx +16 -47
  54. package/packages/bundled-features/src/auth-mfa-user-data/index.ts +5 -6
  55. package/packages/bundled-features/src/billing-foundation/aggregate-id.ts +0 -4
  56. package/packages/bundled-features/src/billing-foundation/changes.json +37 -0
  57. package/packages/bundled-features/src/billing-foundation/checkout-core.ts +8 -1
  58. package/packages/bundled-features/src/billing-foundation/checkout-ledger.ts +59 -0
  59. package/packages/bundled-features/src/billing-foundation/consumer-protection/consent-gate.ts +2 -1
  60. package/packages/bundled-features/src/billing-foundation/consumer-protection/consent-text.ts +49 -2
  61. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-open-cancels.ts +5 -0
  62. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-provider-timeout.ts +23 -0
  63. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-record.ts +12 -7
  64. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-revoke.ts +1 -1
  65. package/packages/bundled-features/src/billing-foundation/events.ts +49 -10
  66. package/packages/bundled-features/src/billing-foundation/feature.ts +15 -1
  67. package/packages/bundled-features/src/billing-foundation/handlers/billing-plans.query.ts +47 -14
  68. package/packages/bundled-features/src/billing-foundation/handlers/create-checkout-session.write.ts +7 -1
  69. package/packages/bundled-features/src/billing-foundation/handlers/process-event.write.ts +124 -10
  70. package/packages/bundled-features/src/billing-foundation/handlers/process-payment-event.write.ts +33 -9
  71. package/packages/bundled-features/src/billing-foundation/handlers/record-checkout-opened.write.ts +25 -0
  72. package/packages/bundled-features/src/billing-foundation/handlers/start-plan-checkout.write.ts +7 -1
  73. package/packages/bundled-features/src/billing-foundation/handlers/switch-plan.write.ts +16 -4
  74. package/packages/bundled-features/src/billing-foundation/i18n.ts +3 -0
  75. package/packages/bundled-features/src/billing-foundation/pending-plan-switch.ts +80 -0
  76. package/packages/bundled-features/src/billing-foundation/scrub-raw-payload-headers.ts +50 -0
  77. package/packages/bundled-features/src/billing-foundation/types.ts +47 -30
  78. package/packages/bundled-features/src/billing-foundation/validate-options.ts +18 -0
  79. package/packages/bundled-features/src/billing-foundation/web/billing-plans-panel.tsx +10 -5
  80. package/packages/bundled-features/src/billing-foundation/web/cancel-contract-dialog.tsx +1 -1
  81. package/packages/bundled-features/src/billing-foundation/web/checkout-consent-dialog.tsx +1 -1
  82. package/packages/bundled-features/src/billing-foundation/web/constants.ts +5 -2
  83. package/packages/bundled-features/src/billing-foundation/web/plan-switch-confirm-dialog.tsx +1 -1
  84. package/packages/bundled-features/src/billing-foundation/webhook-handler.ts +65 -17
  85. package/packages/bundled-features/src/cap-counter/aggregate-id.ts +0 -2
  86. package/packages/bundled-features/src/cap-counter/changes.json +6 -0
  87. package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +19 -4
  88. package/packages/bundled-features/src/cap-overview/changes.json +6 -0
  89. package/packages/bundled-features/src/cap-overview/handlers/tenant-caps-list.query.ts +22 -6
  90. package/packages/bundled-features/src/cap-overview/i18n.ts +1 -0
  91. package/packages/bundled-features/src/cap-overview/index.ts +1 -0
  92. package/packages/bundled-features/src/cap-overview/types.ts +11 -1
  93. package/packages/bundled-features/src/cap-overview/web/cap-cards-panel.tsx +6 -2
  94. package/packages/bundled-features/src/cap-overview/web/cap-usage-bar.tsx +10 -1
  95. package/packages/bundled-features/src/cap-overview/web/usage-math.ts +5 -0
  96. package/packages/bundled-features/src/channel-in-app/changes.json +6 -0
  97. package/packages/bundled-features/src/channel-in-app/handlers/read-state-by-keys.query.ts +2 -2
  98. package/packages/bundled-features/src/channel-whatsapp/aggregate-id.ts +29 -0
  99. package/packages/bundled-features/src/channel-whatsapp/changes.json +8 -0
  100. package/packages/bundled-features/src/channel-whatsapp/constants.ts +46 -0
  101. package/packages/bundled-features/src/channel-whatsapp/events.ts +93 -0
  102. package/packages/bundled-features/src/channel-whatsapp/feature.ts +72 -0
  103. package/packages/bundled-features/src/channel-whatsapp/graph-client.ts +398 -0
  104. package/packages/bundled-features/src/channel-whatsapp/in-memory-meta.ts +300 -0
  105. package/packages/bundled-features/src/channel-whatsapp/inbound-handlers.ts +189 -0
  106. package/packages/bundled-features/src/channel-whatsapp/index.ts +66 -0
  107. package/packages/bundled-features/src/channel-whatsapp/meta-signature.ts +26 -0
  108. package/packages/bundled-features/src/channel-whatsapp/options.ts +149 -0
  109. package/packages/bundled-features/src/channel-whatsapp/pii.ts +109 -0
  110. package/packages/bundled-features/src/channel-whatsapp/webhook-normalize.ts +226 -0
  111. package/packages/bundled-features/src/channel-whatsapp/webhook-routes.ts +185 -0
  112. package/packages/bundled-features/src/compliance-profiles/handlers/sub-processors.query.ts +1 -1
  113. package/packages/bundled-features/src/config/changes.json +12 -0
  114. package/packages/bundled-features/src/config/handlers/set.write.ts +7 -0
  115. package/packages/bundled-features/src/config/handlers/values.query.ts +8 -1
  116. package/packages/bundled-features/src/config/index.ts +1 -0
  117. package/packages/bundled-features/src/config/read-redaction.ts +6 -3
  118. package/packages/bundled-features/src/config/table.ts +1 -0
  119. package/packages/bundled-features/src/config/write-helpers.ts +3 -2
  120. package/packages/bundled-features/src/crypto-shredding/changes.json +18 -0
  121. package/packages/bundled-features/src/crypto-shredding/constants.ts +2 -0
  122. package/packages/bundled-features/src/crypto-shredding/handlers/forget-subject.write.ts +38 -18
  123. package/packages/bundled-features/src/crypto-shredding/index.ts +4 -0
  124. package/packages/bundled-features/src/crypto-shredding/subject-forget-after-delete-hook.ts +49 -0
  125. package/packages/bundled-features/src/custom-fields/aggregate-id.ts +0 -1
  126. package/packages/bundled-features/src/custom-fields/entity.ts +1 -0
  127. package/packages/bundled-features/src/custom-fields/wire-for-entity.ts +0 -1
  128. package/packages/bundled-features/src/data-retention/changes.json +18 -0
  129. package/packages/bundled-features/src/data-retention/erase-notes-of-deleted-row.ts +23 -0
  130. package/packages/bundled-features/src/data-retention/feature.ts +4 -7
  131. package/packages/bundled-features/src/data-retention/run-retention-cleanup.ts +38 -18
  132. package/packages/bundled-features/src/data-retention/tenant-destruction-hold.ts +9 -0
  133. package/packages/bundled-features/src/delivery/attempt-log-factory.ts +11 -0
  134. package/packages/bundled-features/src/delivery/attempt-log.ts +3 -3
  135. package/packages/bundled-features/src/delivery/changes.json +6 -0
  136. package/packages/bundled-features/src/delivery/channel-context.ts +6 -3
  137. package/packages/bundled-features/src/delivery/db/queries/preferences.ts +0 -1
  138. package/packages/bundled-features/src/delivery/delivery-service.ts +3 -0
  139. package/packages/bundled-features/src/delivery/feature.ts +4 -13
  140. package/packages/bundled-features/src/delivery/handlers/opted-in-user-ids.query.ts +45 -0
  141. package/packages/bundled-features/src/delivery/handlers/preferences.query.ts +2 -20
  142. package/packages/bundled-features/src/delivery/handlers/resubscribe-user.write.ts +2 -25
  143. package/packages/bundled-features/src/delivery/handlers/unsubscribe-page-chrome.query.ts +2 -0
  144. package/packages/bundled-features/src/delivery/handlers/unsubscribe-user.write.ts +2 -27
  145. package/packages/bundled-features/src/delivery/index.ts +3 -1
  146. package/packages/bundled-features/src/delivery/options.ts +11 -0
  147. package/packages/bundled-features/src/delivery/preference-rows.ts +33 -0
  148. package/packages/bundled-features/src/delivery/set-preference-enabled.ts +40 -0
  149. package/packages/bundled-features/src/delivery/testing.ts +3 -1
  150. package/packages/bundled-features/src/delivery/types.ts +1 -0
  151. package/packages/bundled-features/src/delivery/unsubscribe-page.ts +7 -1
  152. package/packages/bundled-features/src/delivery/upsert-preference.ts +0 -1
  153. package/packages/bundled-features/src/delivery/web/public-names.ts +1 -0
  154. package/packages/bundled-features/src/derivatives-sharp/render.ts +9 -9
  155. package/packages/bundled-features/src/document-ingest-foundation/aggregate-id.ts +0 -1
  156. package/packages/bundled-features/src/document-ingest-foundation/append-missing-extract-event.ts +37 -25
  157. package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +32 -14
  158. package/packages/bundled-features/src/documents/aggregate-id.ts +0 -2
  159. package/packages/bundled-features/src/documents/changes.json +18 -0
  160. package/packages/bundled-features/src/documents/constants.ts +10 -2
  161. package/packages/bundled-features/src/documents/ensure-link.ts +3 -4
  162. package/packages/bundled-features/src/documents/feature.ts +28 -6
  163. package/packages/bundled-features/src/documents/handlers/import.write.ts +2 -2
  164. package/packages/bundled-features/src/documents/queries/expiry-overview.query.ts +2 -1
  165. package/packages/bundled-features/src/documents/queries/for-record.query.ts +3 -4
  166. package/packages/bundled-features/src/documents/queries/list-page.ts +11 -3
  167. package/packages/bundled-features/src/documents/queries/overview.query.ts +2 -2
  168. package/packages/bundled-features/src/documents/screens.ts +8 -3
  169. package/packages/bundled-features/src/documents/tab.ts +1 -1
  170. package/packages/bundled-features/src/feature-toggles/toggle-sync-signal.ts +6 -3
  171. package/packages/bundled-features/src/file-derivatives/handlers/public-variant-by-file-ref.query.ts +1 -1
  172. package/packages/bundled-features/src/file-derivatives/handlers/public-variant.query.ts +1 -1
  173. package/packages/bundled-features/src/file-foundation/probe.ts +9 -3
  174. package/packages/bundled-features/src/file-foundation/read-file-ref-content.ts +24 -11
  175. package/packages/bundled-features/src/file-provider-inmemory/feature.ts +1 -1
  176. package/packages/bundled-features/src/file-provider-s3/changes.json +14 -0
  177. package/packages/bundled-features/src/file-provider-s3/env-feature.ts +1 -1
  178. package/packages/bundled-features/src/file-provider-s3/env-named-feature.ts +1 -1
  179. package/packages/bundled-features/src/file-provider-s3/env-schema.ts +24 -7
  180. package/packages/bundled-features/src/file-provider-s3/feature.ts +1 -1
  181. package/packages/bundled-features/src/file-provider-s3/index.ts +7 -1
  182. package/packages/bundled-features/src/file-provider-s3/lib/env-helper.ts +21 -13
  183. package/packages/bundled-features/src/file-provider-s3/lib/s3-provider.ts +8 -1
  184. package/packages/bundled-features/src/files/changes.json +7 -0
  185. package/packages/bundled-features/src/folders/aggregate-id.ts +0 -1
  186. package/packages/bundled-features/src/folders/web/folder-manager.tsx +6 -6
  187. package/packages/bundled-features/src/folders-user-data/index.ts +12 -14
  188. package/packages/bundled-features/src/helpdesk/changes.json +62 -0
  189. package/packages/bundled-features/src/helpdesk/entity.ts +4 -1
  190. package/packages/bundled-features/src/helpdesk/feature.ts +41 -0
  191. package/packages/bundled-features/src/helpdesk/handlers/access.ts +0 -10
  192. package/packages/bundled-features/src/helpdesk/handlers/attempts.ts +7 -14
  193. package/packages/bundled-features/src/helpdesk/handlers/challenge.query.ts +1 -2
  194. package/packages/bundled-features/src/helpdesk/handlers/reply.write.ts +2 -9
  195. package/packages/bundled-features/src/helpdesk/handlers/report.write.ts +2 -9
  196. package/packages/bundled-features/src/helpdesk/handlers/submit.write.ts +3 -11
  197. package/packages/bundled-features/src/helpdesk/index.ts +1 -0
  198. package/packages/bundled-features/src/helpdesk/legacy-contact-config.ts +61 -0
  199. package/packages/bundled-features/src/helpdesk/legacy-contact-erasure.ts +45 -0
  200. package/packages/bundled-features/src/helpdesk/legacy-contact-retention.ts +65 -0
  201. package/packages/bundled-features/src/helpdesk/legacy-contact-streams.ts +185 -0
  202. package/packages/bundled-features/src/helpdesk/legacy-contact-user-data.ts +84 -0
  203. package/packages/bundled-features/src/helpdesk/lib.ts +47 -34
  204. package/packages/bundled-features/src/helpdesk/user-data-hooks.ts +89 -48
  205. package/packages/bundled-features/src/helpdesk/web/constants.ts +0 -1
  206. package/packages/bundled-features/src/inbound-mail-foundation/account-health.ts +1 -1
  207. package/packages/bundled-features/src/inbound-mail-foundation/account-poll.ts +5 -1
  208. package/packages/bundled-features/src/inbound-mail-foundation/aggregate-id.ts +0 -2
  209. package/packages/bundled-features/src/inbound-mail-foundation/changes.json +48 -0
  210. package/packages/bundled-features/src/inbound-mail-foundation/constants.ts +6 -0
  211. package/packages/bundled-features/src/inbound-mail-foundation/content-refetch.ts +15 -1
  212. package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +64 -15
  213. package/packages/bundled-features/src/inbound-mail-foundation/events.ts +15 -16
  214. package/packages/bundled-features/src/inbound-mail-foundation/feature.ts +3 -1
  215. package/packages/bundled-features/src/inbound-mail-foundation/handlers/account-address.ts +16 -2
  216. package/packages/bundled-features/src/inbound-mail-foundation/handlers/attach-message-content.write.ts +10 -3
  217. package/packages/bundled-features/src/inbound-mail-foundation/handlers/connect-account.write.ts +21 -8
  218. package/packages/bundled-features/src/inbound-mail-foundation/handlers/forget-message.write.ts +73 -0
  219. package/packages/bundled-features/src/inbound-mail-foundation/i18n.ts +3 -0
  220. package/packages/bundled-features/src/inbound-mail-foundation/index.ts +1 -0
  221. package/packages/bundled-features/src/inbound-mail-foundation/oauth-access-token.ts +1 -1
  222. package/packages/bundled-features/src/inbound-mail-foundation/outbound-mail.ts +2 -0
  223. package/packages/bundled-features/src/inbound-mail-foundation/personal-address.ts +20 -0
  224. package/packages/bundled-features/src/inbound-mail-foundation/purge-messages.ts +54 -0
  225. package/packages/bundled-features/src/inbound-mail-foundation/quarantine.ts +15 -5
  226. package/packages/bundled-features/src/inbound-mail-foundation/retention-job.ts +1 -5
  227. package/packages/bundled-features/src/inbound-mail-foundation/retention-sweep.ts +21 -34
  228. package/packages/bundled-features/src/inbound-mail-foundation/send-from-account.ts +9 -1
  229. package/packages/bundled-features/src/inbound-mail-foundation/supervisor-ingest.ts +7 -1
  230. package/packages/bundled-features/src/inbound-mail-foundation/sync-account-now.ts +1 -1
  231. package/packages/bundled-features/src/inbound-mail-foundation/tenant-destroy-hook.ts +14 -17
  232. package/packages/bundled-features/src/inbound-mail-foundation/watch-supervisor.ts +1 -1
  233. package/packages/bundled-features/src/inbound-provider-imap/byte-budget.ts +80 -0
  234. package/packages/bundled-features/src/inbound-provider-imap/changes.json +13 -0
  235. package/packages/bundled-features/src/inbound-provider-imap/connect-mailbox.ts +8 -4
  236. package/packages/bundled-features/src/inbound-provider-imap/connect-my-mailbox.ts +23 -6
  237. package/packages/bundled-features/src/inbound-provider-imap/connect-target-rate-limit.ts +46 -0
  238. package/packages/bundled-features/src/inbound-provider-imap/download-batch.ts +47 -10
  239. package/packages/bundled-features/src/inbound-provider-imap/feature.ts +7 -4
  240. package/packages/bundled-features/src/inbound-provider-imap/fetch-content.ts +43 -29
  241. package/packages/bundled-features/src/inbound-provider-imap/i18n.ts +2 -2
  242. package/packages/bundled-features/src/inbound-provider-imap/parse-message.ts +14 -0
  243. package/packages/bundled-features/src/inbound-provider-imap/reconnect-mailbox.ts +5 -4
  244. package/packages/bundled-features/src/inbound-provider-imap/send-mail.ts +39 -7
  245. package/packages/bundled-features/src/inbound-provider-imap/smtp-client.ts +19 -4
  246. package/packages/bundled-features/src/inbound-provider-imap/watch-mailbox.ts +8 -23
  247. package/packages/bundled-features/src/inbound-provider-inmemory/feature.ts +1 -1
  248. package/packages/bundled-features/src/jobs/events.ts +10 -0
  249. package/packages/bundled-features/src/jobs/feature.ts +2 -0
  250. package/packages/bundled-features/src/jobs/handlers/consumer.write.ts +41 -16
  251. package/packages/bundled-features/src/jobs/web/constants.ts +4 -0
  252. package/packages/bundled-features/src/mail-foundation/changes.json +6 -0
  253. package/packages/bundled-features/src/mail-transport-inmemory/feature.ts +1 -1
  254. package/packages/bundled-features/src/mail-transport-smtp/feature.ts +3 -2
  255. package/packages/bundled-features/src/managed-pages/changes.json +12 -0
  256. package/packages/bundled-features/src/managed-pages/handlers/branding.query.ts +1 -1
  257. package/packages/bundled-features/src/managed-pages/handlers/by-slug.query.ts +1 -1
  258. package/packages/bundled-features/src/managed-pages/handlers/by-tenant-published.query.ts +1 -1
  259. package/packages/bundled-features/src/managed-pages/render-page-body.ts +18 -10
  260. package/packages/bundled-features/src/managed-pages/screens/page-screens.ts +18 -38
  261. package/packages/bundled-features/src/managed-pages/table.ts +1 -0
  262. package/packages/bundled-features/src/managed-pages/web/client-plugin.tsx +8 -6
  263. package/packages/bundled-features/src/managed-pages/web/constants.ts +8 -1
  264. package/packages/bundled-features/src/managed-pages/web/i18n.ts +11 -3
  265. package/packages/bundled-features/src/managed-pages/web/markdown-to-document.ts +1 -1
  266. package/packages/bundled-features/src/managed-pages/web/page-edit-draft.ts +108 -0
  267. package/packages/bundled-features/src/managed-pages/web/page-edit-screen.tsx +198 -0
  268. package/packages/bundled-features/src/managed-pages/web/page-settings-rail.tsx +117 -0
  269. package/packages/bundled-features/src/notes-history-user-data/index.ts +8 -14
  270. package/packages/bundled-features/src/personal-access-tokens/boot-rules.ts +5 -0
  271. package/packages/bundled-features/src/personal-access-tokens/handlers/create.write.ts +0 -1
  272. package/packages/bundled-features/src/personal-access-tokens/scope-events-check.ts +31 -5
  273. package/packages/bundled-features/src/presence/changes.json +6 -0
  274. package/packages/bundled-features/src/presence/handlers/list.query.ts +28 -11
  275. package/packages/bundled-features/src/presence/room.ts +21 -7
  276. package/packages/bundled-features/src/presence/store.ts +79 -21
  277. package/packages/bundled-features/src/readiness/changes.json +25 -0
  278. package/packages/bundled-features/src/readiness/handlers/latest-summary.query.ts +11 -6
  279. package/packages/bundled-features/src/readiness/handlers/run-probes.write.ts +35 -5
  280. package/packages/bundled-features/src/readiness/handlers/run-tone.ts +3 -2
  281. package/packages/bundled-features/src/readiness/handlers/status.query.ts +15 -1
  282. package/packages/bundled-features/src/readiness/probe-context.ts +11 -10
  283. package/packages/bundled-features/src/readiness/screens.ts +4 -4
  284. package/packages/bundled-features/src/readiness/visible-results.ts +5 -3
  285. package/packages/bundled-features/src/renderer-foundation/api.ts +6 -13
  286. package/packages/bundled-features/src/renderer-foundation/types.ts +2 -2
  287. package/packages/bundled-features/src/secrets/changes.json +7 -0
  288. package/packages/bundled-features/src/secrets/db/queries/read.ts +18 -4
  289. package/packages/bundled-features/src/secrets/handlers/list.query.ts +8 -2
  290. package/packages/bundled-features/src/secrets/secret-scope.ts +2 -3
  291. package/packages/bundled-features/src/secrets/secrets-context.ts +6 -4
  292. package/packages/bundled-features/src/secrets/write-gate.ts +4 -2
  293. package/packages/bundled-features/src/seo/handlers/seo-config.query.ts +1 -1
  294. package/packages/bundled-features/src/shared/acknowledged-system-db.ts +20 -0
  295. package/packages/bundled-features/src/shared/assert-billing-live.ts +9 -2
  296. package/packages/bundled-features/src/shared/changes.json +6 -0
  297. package/packages/bundled-features/src/shared/index.ts +6 -1
  298. package/packages/bundled-features/src/shared/parent-visibility.ts +25 -1
  299. package/packages/bundled-features/src/shared/password-hashing.ts +0 -1
  300. package/packages/bundled-features/src/shared/price-env-shape.ts +1 -4
  301. package/packages/bundled-features/src/shared/register-user-data-hooks.ts +29 -0
  302. package/packages/bundled-features/src/shared/require-bootstrap-extension.ts +26 -0
  303. package/packages/bundled-features/src/shared/send-best-effort.ts +19 -0
  304. package/packages/bundled-features/src/shared/stream-tenant-backfill.ts +22 -1
  305. package/packages/bundled-features/src/shared/stream-tenant-derived-state.ts +31 -1
  306. package/packages/bundled-features/src/step-dispatcher/changes.json +12 -0
  307. package/packages/bundled-features/src/step-dispatcher/constants.ts +13 -0
  308. package/packages/bundled-features/src/step-dispatcher/deliver-dispatch-request.ts +47 -2
  309. package/packages/bundled-features/src/step-dispatcher/feature.ts +28 -1
  310. package/packages/bundled-features/src/step-dispatcher/mail-runner.ts +0 -1
  311. package/packages/bundled-features/src/step-dispatcher/sweep-abandoned.ts +57 -0
  312. package/packages/bundled-features/src/subscription-mollie/changes.json +7 -0
  313. package/packages/bundled-features/src/subscription-mollie/plugin-methods.ts +5 -3
  314. package/packages/bundled-features/src/subscription-mollie/verify-webhook.ts +5 -5
  315. package/packages/bundled-features/src/subscription-paddle/backfill-checkout-ledger.ts +159 -0
  316. package/packages/bundled-features/src/subscription-paddle/changes.json +13 -0
  317. package/packages/bundled-features/src/subscription-paddle/checkout-config.query.ts +1 -1
  318. package/packages/bundled-features/src/subscription-paddle/checkout-methods.ts +2 -8
  319. package/packages/bundled-features/src/subscription-paddle/constants.ts +1 -2
  320. package/packages/bundled-features/src/subscription-paddle/feature.ts +26 -24
  321. package/packages/bundled-features/src/subscription-paddle/ledger-backfill-marker.ts +70 -0
  322. package/packages/bundled-features/src/subscription-paddle/plan-switch-methods.ts +2 -8
  323. package/packages/bundled-features/src/subscription-paddle/redeliver-legacy-checkout.ts +36 -0
  324. package/packages/bundled-features/src/subscription-paddle/runtime.ts +13 -24
  325. package/packages/bundled-features/src/subscription-paddle/subscription-state.ts +1 -0
  326. package/packages/bundled-features/src/subscription-paddle/webhook-events.ts +68 -21
  327. package/packages/bundled-features/src/subscription-stripe/changes.json +7 -0
  328. package/packages/bundled-features/src/subscription-stripe/feature.ts +5 -0
  329. package/packages/bundled-features/src/subscription-stripe/plugin-methods.ts +6 -6
  330. package/packages/bundled-features/src/subscription-stripe/runtime.ts +8 -7
  331. package/packages/bundled-features/src/subscription-stripe/verify-webhook.ts +24 -6
  332. package/packages/bundled-features/src/tags/aggregate-id.ts +0 -1
  333. package/packages/bundled-features/src/tags/web/tag-chip.tsx +4 -5
  334. package/packages/bundled-features/src/tags/web/tag-manager.tsx +2 -1
  335. package/packages/bundled-features/src/template-resolver/api.ts +6 -13
  336. package/packages/bundled-features/src/template-resolver/changes.json +36 -0
  337. package/packages/bundled-features/src/template-resolver/document-sanitizer.ts +25 -0
  338. package/packages/bundled-features/src/template-resolver/feature.ts +2 -0
  339. package/packages/bundled-features/src/template-resolver/handlers/body-preview.query.ts +41 -0
  340. package/packages/bundled-features/src/template-resolver/handlers/by-slug.query.ts +1 -1
  341. package/packages/bundled-features/src/template-resolver/handlers/by-tenant.query.ts +1 -1
  342. package/packages/bundled-features/src/template-resolver/handlers/collection-shared.ts +5 -11
  343. package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +3 -2
  344. package/packages/bundled-features/src/template-resolver/handlers/send-test.write.ts +37 -8
  345. package/packages/bundled-features/src/template-resolver/linked-resources.ts +2 -5
  346. package/packages/bundled-features/src/template-resolver/seeding.ts +77 -0
  347. package/packages/bundled-features/src/template-resolver/table.ts +1 -0
  348. package/packages/bundled-features/src/template-resolver/template-draft.ts +2 -1
  349. package/packages/bundled-features/src/template-resolver/template-preview.ts +14 -3
  350. package/packages/bundled-features/src/template-resolver/testing.ts +0 -2
  351. package/packages/bundled-features/src/template-resolver/web/client-plugin.tsx +3 -0
  352. package/packages/bundled-features/src/template-resolver/web/collection-entry-create-form.tsx +33 -33
  353. package/packages/bundled-features/src/template-resolver/web/constants.ts +7 -0
  354. package/packages/bundled-features/src/template-resolver/web/content-tree-provider.ts +0 -1
  355. package/packages/bundled-features/src/template-resolver/web/content-workbench.tsx +142 -0
  356. package/packages/bundled-features/src/template-resolver/web/document-insert-model.ts +3 -8
  357. package/packages/bundled-features/src/template-resolver/web/document-link-policy.ts +58 -0
  358. package/packages/bundled-features/src/template-resolver/web/document-schema.ts +11 -57
  359. package/packages/bundled-features/src/template-resolver/web/document-tiptap-bubble.tsx +2 -4
  360. package/packages/bundled-features/src/template-resolver/web/document-tiptap-context.ts +4 -5
  361. package/packages/bundled-features/src/template-resolver/web/document-tiptap-editor.tsx +2 -2
  362. package/packages/bundled-features/src/template-resolver/web/document-tiptap-helpers.ts +6 -3
  363. package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar-groups.tsx +2 -3
  364. package/packages/bundled-features/src/template-resolver/web/editor-handle.ts +1 -0
  365. package/packages/bundled-features/src/template-resolver/web/fill-document-variables.ts +24 -0
  366. package/packages/bundled-features/src/template-resolver/web/i18n.ts +14 -0
  367. package/packages/bundled-features/src/template-resolver/web/index.ts +3 -0
  368. package/packages/bundled-features/src/template-resolver/web/preview-targets.ts +25 -0
  369. package/packages/bundled-features/src/template-resolver/web/qualified-names.ts +1 -0
  370. package/packages/bundled-features/src/template-resolver/web/snippet-preview-renderer.tsx +24 -0
  371. package/packages/bundled-features/src/template-resolver/web/string-values.ts +7 -0
  372. package/packages/bundled-features/src/template-resolver/web/text-block-editor.tsx +38 -50
  373. package/packages/bundled-features/src/template-resolver/web/use-collection-entry-create.ts +7 -0
  374. package/packages/bundled-features/src/template-resolver/web/use-content-write.ts +1 -3
  375. package/packages/bundled-features/src/template-resolver/web/use-document-tiptap-model.ts +1 -2
  376. package/packages/bundled-features/src/template-resolver/web/use-text-block-editor.ts +28 -7
  377. package/packages/bundled-features/src/template-resolver/web/web-preview-renderer.tsx +126 -0
  378. package/packages/bundled-features/src/template-resolver-user-data/index.ts +11 -10
  379. package/packages/bundled-features/src/tenant/changes.json +6 -0
  380. package/packages/bundled-features/src/tenant/handlers/create.write.ts +7 -8
  381. package/packages/bundled-features/src/tenant/handlers/list.query.ts +7 -9
  382. package/packages/bundled-features/src/tenant/handlers/member-directory.query.ts +10 -4
  383. package/packages/bundled-features/src/tenant/handlers/toggle-enabled.write.ts +1 -1
  384. package/packages/bundled-features/src/tenant/invited-membership.ts +10 -1
  385. package/packages/bundled-features/src/tenant/seeding.ts +4 -2
  386. package/packages/bundled-features/src/tenant/stream-tenant-backfill.ts +5 -1
  387. package/packages/bundled-features/src/tenant/testing.ts +1 -1
  388. package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +4 -3
  389. package/packages/bundled-features/src/tenant-inactivity/constants.ts +1 -2
  390. package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +1 -2
  391. package/packages/bundled-features/src/tenant-inactivity/state-store.ts +10 -1
  392. package/packages/bundled-features/src/tenant-lifecycle/changes.json +18 -0
  393. package/packages/bundled-features/src/tenant-lifecycle/constants.ts +4 -0
  394. package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +43 -6
  395. package/packages/bundled-features/src/tenant-lifecycle/stages.ts +15 -2
  396. package/packages/bundled-features/src/tier-engine/aggregate-id.ts +0 -1
  397. package/packages/bundled-features/src/tier-engine/changes.json +6 -0
  398. package/packages/bundled-features/src/tier-engine/feature.ts +8 -2
  399. package/packages/bundled-features/src/user/changes.json +6 -0
  400. package/packages/bundled-features/src/user/db/queries/stream-tenant-backfill.ts +2 -1
  401. package/packages/bundled-features/src/user/handlers/me.query.ts +3 -1
  402. package/packages/bundled-features/src/user/index.ts +1 -0
  403. package/packages/bundled-features/src/user/resolve-verified-user-email.ts +17 -0
  404. package/packages/bundled-features/src/user-data-rights/db/queries/export-jobs.ts +0 -1
  405. package/packages/bundled-features/src/user-data-rights/handlers/confirm-deletion-by-token.write.ts +1 -1
  406. package/packages/bundled-features/src/user-data-rights/handlers/download-by-token.query.ts +1 -1
  407. package/packages/bundled-features/src/user-data-rights/handlers/request-deletion-by-email.write.ts +1 -1
  408. package/packages/bundled-features/src/user-data-rights/run-export-jobs.ts +0 -2
  409. package/packages/bundled-features/src/user-data-rights/run-forget-cleanup.ts +3 -3
  410. package/packages/bundled-features/src/user-data-rights/schema/download-attempt.ts +3 -2
  411. package/packages/bundled-features/src/user-data-rights/web/confirm-deletion-screen.tsx +1 -1
  412. package/packages/bundled-features/src/user-data-rights/web/privacy-center-screen.tsx +1 -1
  413. package/packages/bundled-features/src/user-data-rights/web/request-deletion-screen.tsx +1 -1
  414. package/packages/bundled-features/src/user-data-rights-defaults/hooks/api-token.userdata-hook.ts +5 -5
  415. package/packages/bundled-features/src/user-data-rights-defaults/hooks/hard-delete-own-rows-hook.ts +17 -0
  416. package/packages/bundled-features/src/user-data-rights-defaults/hooks/in-app-message.userdata-hook.ts +5 -5
  417. package/packages/bundled-features/src/user-data-rights-defaults/hooks/job-run.userdata-hook.ts +2 -1
  418. package/packages/bundled-features/src/user-data-rights-defaults/hooks/user-session.userdata-hook.ts +5 -5
  419. package/packages/bundled-features/src/user-profile/handlers/change-email.write.ts +0 -1
  420. package/packages/bundled-features/src/waitlist/changes.json +6 -0
  421. package/packages/bundled-features/src/waitlist/handlers/submit.write.ts +4 -28
  422. package/packages/bundled-features/src/waitlist/lib.ts +2 -7
  423. package/packages/bundled-features/src/waitlist/user-data-hooks.ts +6 -19
  424. package/packages/bundled-features/src/workflow-runner/aggregate-id.ts +0 -1
  425. package/packages/bundled-features/src/workflow-runner/event-trigger.ts +6 -2
  426. package/packages/bundled-features/src/workflow-runner/feature.ts +1 -5
  427. package/packages/bundled-features/src/workflow-runner/handlers/resume-run.write.ts +5 -4
  428. package/packages/bundled-features/src/workflow-runner/runner.ts +2 -0
  429. package/samples/apps/showcase/src/features/demos/web/pages/dialog.tsx +0 -1
  430. package/samples/apps/showcase/src/features/demos/web/pages/layout.tsx +1 -1
  431. package/samples/apps/showcase/src/features/demos/web/pages/sidebar-panel.tsx +0 -1
  432. package/samples/apps/styleguide/src/features/gallery/web/Gallery.tsx +1 -4
  433. package/samples/apps/ui-walkthrough/src/features/subscription-plans/feature.ts +6 -2
  434. package/samples/apps/use-all-bundled/e2e-billing-gallery/gallery-features.ts +12 -14
  435. package/samples/apps/use-all-bundled/feature-manifest.json +60 -29
  436. package/samples/apps/use-all-bundled/playwright.billing-docs.config.ts +1 -1
  437. package/samples/apps/use-all-bundled/playwright.config.ts +1 -0
  438. package/samples/apps/use-all-bundled/src/app/seed.ts +1 -1
  439. package/samples/apps/use-all-bundled/src/run-config.ts +2 -1
  440. package/samples/recipes/auth-mfa/src/web/confirmation-code-step.tsx +32 -10
  441. package/samples/recipes/chat-channels/README.md +2 -0
  442. package/samples/recipes/currencies-global/src/entities/currency.ts +1 -0
  443. package/samples/recipes/helpdesk/README.md +9 -5
  444. package/samples/recipes/helpdesk/src/feature.ts +6 -3
  445. package/samples/recipes/managed-pages/README.md +5 -1
  446. package/samples/recipes/managed-pages/package.json +3 -2
  447. package/samples/recipes/managed-pages/src/web/branded-preview.tsx +21 -0
  448. package/samples/recipes/managed-pages/tsconfig.json +8 -0
  449. package/samples/recipes/pwa-shell/README.md +52 -0
  450. package/samples/recipes/pwa-shell/bin/server.ts +12 -0
  451. package/samples/recipes/pwa-shell/package.json +13 -0
  452. package/samples/recipes/pwa-shell/src/app.ts +34 -0
  453. package/samples/recipes/rate-limiting/README.md +3 -3
  454. package/samples/recipes/record-detail-layout/README.md +33 -0
  455. package/samples/recipes/record-detail-layout/src/feature.ts +525 -44
  456. package/samples/recipes/record-detail-layout/src/order-board.ts +521 -0
  457. package/packages/bundled-features/src/managed-pages/web/page-body-section.tsx +0 -72
  458. package/packages/bundled-features/src/subscription-paddle/tenant-binding.ts +0 -34
  459. package/packages/bundled-features/src/template-resolver/web/content-field.tsx +0 -61
@@ -3,7 +3,7 @@
3
3
  // subscription-paddle — Paddle Billing (merchant of record) plugin for the
4
4
  // billing-foundation plugin API. Credentials, the billing-live master switch and
5
5
  // the API environment (sandbox | live) are config keys resolved at call time, like
6
- // subscription-stripe. The `apiKey` / `webhookSecret` / `tenantBindingKey` /
6
+ // subscription-stripe. The `apiKey` / `webhookSecret` /
7
7
  // `clientToken` options are env→config bridge fallbacks.
8
8
 
9
9
  import {
@@ -21,6 +21,7 @@ import { egress } from "@cosmicdrift/kumiko-framework/http";
21
21
  import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
22
22
  import * as z from "zod";
23
23
  import { priceEnvSchema } from "../shared/index.ts";
24
+ import { runBackfillCheckoutLedger } from "./backfill-checkout-ledger.ts";
24
25
  import { makeCheckoutConfigQuery } from "./checkout-config.query.ts";
25
26
  import {
26
27
  createPaddleCancelSubscription,
@@ -36,17 +37,22 @@ import {
36
37
  PADDLE_CLIENT_TOKEN_CONFIG,
37
38
  PADDLE_ENVIRONMENT_CONFIG,
38
39
  PADDLE_PROVIDER_NAME,
39
- PADDLE_TENANT_BINDING_KEY_CONFIG,
40
40
  PADDLE_WEBHOOK_SECRET_CONFIG,
41
41
  PaddleEnvironments,
42
42
  SUBSCRIPTION_PADDLE_FEATURE,
43
43
  } from "./constants.ts";
44
+ import {
45
+ LEDGER_BACKFILL_EVENT_SHORT,
46
+ ledgerBackfillMarkerHandler,
47
+ ledgerBackfillPayloadSchema,
48
+ } from "./ledger-backfill-marker.ts";
44
49
  import {
45
50
  createPaddleApplyPlanSwitch,
46
51
  createPaddlePreviewPlanSwitch,
47
52
  createPaddleRetrieveSubscription,
48
53
  } from "./plan-switch-methods.ts";
49
54
  import { createPaddlePriceCache, createPaddleRetrievePrices } from "./price-methods.ts";
55
+ import { shouldRedeliverLegacyCheckout } from "./redeliver-legacy-checkout.ts";
50
56
  import { createPaddleRuntimes } from "./runtime.ts";
51
57
  import { verifyAndParsePaddleWebhook } from "./webhook-events.ts";
52
58
 
@@ -64,14 +70,6 @@ export const subscriptionPaddleEnvSchema = z.object({
64
70
  .describe("Paddle notification secret (`pdl_ntfset_...`). Bridge-fallback — prefer the secret.")
65
71
  .meta({ kumiko: { pulumi: { secret: true } } })
66
72
  .optional(),
67
- PADDLE_TENANT_BINDING_KEY: z
68
- .string()
69
- .min(1)
70
- .describe(
71
- "Server-only HMAC key binding a Paddle checkout to its tenant. Bridge-fallback — prefer the secret.",
72
- )
73
- .meta({ kumiko: { pulumi: { secret: true } } })
74
- .optional(),
75
73
  PADDLE_CLIENT_TOKEN: z
76
74
  .string()
77
75
  .regex(/^(test|live)_/, "PADDLE_CLIENT_TOKEN must start with 'test_' or 'live_'")
@@ -101,8 +99,6 @@ export type SubscriptionPaddleOptions = {
101
99
  readonly apiKey?: string;
102
100
  /** Bridge-fallback webhook secret; the `webhook-secret` config key wins when set. */
103
101
  readonly webhookSecret?: string;
104
- /** Bridge-fallback tenant binding key; the `tenant-binding-key` config key wins when set. */
105
- readonly tenantBindingKey?: string;
106
102
  /** Bridge-fallback Paddle.js client token; the `client-token` config key wins when set. */
107
103
  readonly clientToken?: string;
108
104
  /** Paddle price id → app tier name. Prices absent here drop the event. */
@@ -124,7 +120,7 @@ export function createSubscriptionPaddleFeature(
124
120
  const now = options.now ?? (() => Temporal.Now.instant().epochMilliseconds);
125
121
  const feature: FeatureDefinition = defineFeature(SUBSCRIPTION_PADDLE_FEATURE, (r) => {
126
122
  r.describe(
127
- 'Paddle Billing provider plugin for `billing-foundation`. Paddle acts as merchant of record: it sells to the customer and issues invoice and VAT, so the consumer-protection texts for this provider come from `consumerProtection.providerTexts`. Reads its API key, webhook secret and tenant binding key from system config keys with `backing:"secrets"` (envelope-encrypted in the secrets store under the system tenant), the public Paddle.js `client-token`, a `billingLive` master switch and an `environment` key (sandbox | live). `environment` is its own key because Paddle serves sandbox and live from different API hosts and a live key must never hit the sandbox host or the other way round; `billingLive` only decides whether checkouts are offered at all. All of them are runtime config, so keys rotate and prod goes live without a redeploy, and the `mask` on each derives the sysadmin settings screen and nav. Mount via `createSubscriptionPaddleFeature({ priceToTier })`; the optional `apiKey`/`webhookSecret`/`tenantBindingKey`/`clientToken` options are env to config bridge fallbacks (`PADDLE_API_KEY`, `PADDLE_WEBHOOK_SECRET`, `PADDLE_TENANT_BINDING_KEY`, `PADDLE_CLIENT_TOKEN`). The plugin always mounts; `createCheckoutSession` throws `feature_disabled` unless `billingLive` is true, and billing counts as enabled only with API key and binding key present. Webhooks arrive at `/webhooks/subscription/paddle` when mounted through the server-runtime `billing.paddle` boot option, or at `/api/subscription/webhook/paddle` when `createSubscriptionWebhookRoute` is mounted by hand and are verified with the `Paddle-Signature` header (HMAC-SHA256 over `ts:rawBody` keyed with the raw secret, any `h1` may match, 5 minute tolerance). Paddle.js can open checkouts with arbitrary `customData` from the browser, so `custom_data.tenantId` is only trusted together with `tenantBinding`, an HMAC of the tenant id under the binding key; events without a valid binding, for prices outside `priceToTier` or without a tenant are dropped. Rotating the binding key makes the webhooks of existing subscriptions fail that check until they are re-bound. Paddle has no hosted checkout page, so the feature serves the Default Payment Link itself at `/billing/paddle-checkout` (the Default Payment Link in the Paddle dashboard must point to `<APP_BASE_URL>/billing/paddle-checkout`; it is the only source, because checkouts are created without a `checkout.url`). Create subscription prices in the Paddle catalog with quantity minimum and maximum 1; for one-off packs set the quantity limits on purpose, because the payment event carries `quantity` and the app has to multiply its credits by it: an anonymous page with its own CSP that loads Paddle.js from cdn.paddle.com, the one external script this framework allows, and opens the overlay for the transaction. Implements checkout, customer portal, cancel and resume, `retrievePrices` (batched, 10-minute TTL cache), `retrieveSubscription` for the sync job, and an in-app plan switch: `previewPlanSwitch` shows the proration before the customer confirms, `applyPlanSwitch` changes the plan without a hosted page and waits for the `subscription.updated` webhook to move the tier.',
123
+ 'Paddle Billing provider plugin for `billing-foundation`. Paddle acts as merchant of record: it sells to the customer and issues invoice and VAT, so the consumer-protection texts for this provider come from `consumerProtection.providerTexts`. Reads its API key and webhook secret from system config keys with `backing:"secrets"` (envelope-encrypted in the secrets store under the system tenant), the public Paddle.js `client-token`, a `billingLive` master switch and an `environment` key (sandbox | live). `environment` is its own key because Paddle serves sandbox and live from different API hosts and a live key must never hit the sandbox host or the other way round; `billingLive` only decides whether checkouts are offered at all. All of them are runtime config, so keys rotate and prod goes live without a redeploy, and the `mask` on each derives the sysadmin settings screen and nav. Mount via `createSubscriptionPaddleFeature({ priceToTier })`; the optional `apiKey`/`webhookSecret`/`clientToken` options are env to config bridge fallbacks (`PADDLE_API_KEY`, `PADDLE_WEBHOOK_SECRET`, `PADDLE_CLIENT_TOKEN`). The plugin always mounts; `createCheckoutSession` throws `feature_disabled` unless `billingLive` is true, and billing counts as enabled only with the API key present. Webhooks arrive at `/webhooks/subscription/paddle` when mounted through the server-runtime `billing.paddle` boot option, or at `/api/subscription/webhook/paddle` when `createSubscriptionWebhookRoute` is mounted by hand and are verified with the `Paddle-Signature` header (HMAC-SHA256 over `ts:rawBody` keyed with the raw secret, any `h1` may match, 5 minute tolerance). Paddle.js can open checkouts with arbitrary `customData` from the browser, so `custom_data.tenantId` only locates the tenant stream: billing-foundation keeps a checkout ledger and accepts a webhook only for a transaction the server opened itself (a `subscription.created` must name it in `transaction_id`), so events for prices outside `priceToTier`, without a tenant or for foreign transactions are dropped. The `backfill-checkout-ledger` job ledgers Paddle checkouts that were open when the ledger was introduced, then goes quiet. Paddle has no hosted checkout page, so the feature serves the Default Payment Link itself at `/billing/paddle-checkout` (the Default Payment Link in the Paddle dashboard must point to `<APP_BASE_URL>/billing/paddle-checkout`; it is the only source, because checkouts are created without a `checkout.url`). Create subscription prices in the Paddle catalog with quantity minimum and maximum 1; for one-off packs set the quantity limits on purpose, because the payment event carries `quantity` and the app has to multiply its credits by it: an anonymous page with its own CSP that loads Paddle.js from cdn.paddle.com, the one external script this framework allows, and opens the overlay for the transaction. Implements checkout, customer portal, cancel and resume, `retrievePrices` (batched, 10-minute TTL cache), `retrieveSubscription` for the sync job, and an in-app plan switch: `previewPlanSwitch` shows the proration before the customer confirms, `applyPlanSwitch` changes the plan without a hosted page and waits for the `subscription.updated` webhook to move the tier.',
128
124
  );
129
125
  r.uiHints({
130
126
  displayLabel: "Billing · Paddle",
@@ -150,12 +146,6 @@ export function createSubscriptionPaddleFeature(
150
146
  read: access.admin,
151
147
  mask: { title: "subscription-paddle.webhook-secret", icon: "shield", order: 2 },
152
148
  }),
153
- [PADDLE_TENANT_BINDING_KEY_CONFIG]: createSystemConfig("text", {
154
- backing: "secrets",
155
- write: access.systemAdmin,
156
- read: access.admin,
157
- mask: { title: "subscription-paddle.tenant-binding-key", icon: "lock", order: 3 },
158
- }),
159
149
  [PADDLE_CLIENT_TOKEN_CONFIG]: createSystemConfig("text", {
160
150
  write: access.systemAdmin,
161
151
  read: access.admin,
@@ -181,7 +171,6 @@ export function createSubscriptionPaddleFeature(
181
171
  keys: {
182
172
  "subscription-paddle.api-key": { en: "Paddle API key" },
183
173
  "subscription-paddle.webhook-secret": { en: "Paddle webhook secret" },
184
- "subscription-paddle.tenant-binding-key": { en: "Paddle tenant binding key" },
185
174
  "subscription-paddle.client-token": { en: "Paddle client-side token" },
186
175
  "subscription-paddle.environment": { en: "Paddle environment" },
187
176
  "subscription-paddle.billing-live": { en: "Live billing" },
@@ -194,7 +183,6 @@ export function createSubscriptionPaddleFeature(
194
183
  const runtimes = createPaddleRuntimes({
195
184
  apiKeyHandle: configKeys[PADDLE_API_KEY_CONFIG],
196
185
  webhookSecretHandle: configKeys[PADDLE_WEBHOOK_SECRET_CONFIG],
197
- tenantBindingKeyHandle: configKeys[PADDLE_TENANT_BINDING_KEY_CONFIG],
198
186
  clientTokenHandle: configKeys[PADDLE_CLIENT_TOKEN_CONFIG],
199
187
  billingLiveHandle: configKeys[PADDLE_BILLING_LIVE_CONFIG],
200
188
  environmentHandle: configKeys[PADDLE_ENVIRONMENT_CONFIG],
@@ -202,14 +190,25 @@ export function createSubscriptionPaddleFeature(
202
190
  fallback: {
203
191
  ...(options.apiKey !== undefined && { apiKey: options.apiKey }),
204
192
  ...(options.webhookSecret !== undefined && { webhookSecret: options.webhookSecret }),
205
- ...(options.tenantBindingKey !== undefined && {
206
- tenantBindingKey: options.tenantBindingKey,
207
- }),
208
193
  ...(options.clientToken !== undefined && { clientToken: options.clientToken }),
209
194
  },
210
195
  });
211
196
 
212
197
  r.queryHandler(makeCheckoutConfigQuery(runtimes.readCheckoutConfig));
198
+ r.defineEvent(LEDGER_BACKFILL_EVENT_SHORT, ledgerBackfillPayloadSchema, { piiFields: "none" });
199
+ r.writeHandler(ledgerBackfillMarkerHandler);
200
+ r.job({
201
+ name: "backfill-checkout-ledger",
202
+ trigger: { cron: "*/5 * * * *" },
203
+ concurrency: "skip",
204
+ // writeAs: ledgers each checkout in the stream of the tenant that opened it.
205
+ escapeHatch: {
206
+ reason: "ledgers open legacy Paddle checkouts in each tenant's stream via writeAs",
207
+ grants: ["systemIdentity"],
208
+ },
209
+ handler: (_payload, ctx) =>
210
+ runBackfillCheckoutLedger(ctx, { runtime: runtimes.ctx, priceToTier }),
211
+ });
213
212
  r.httpRoute({
214
213
  method: "GET",
215
214
  // Literal for the feature-AST extractor; must equal PADDLE_CHECKOUT_PATH (integration test).
@@ -223,8 +222,11 @@ export function createSubscriptionPaddleFeature(
223
222
  displayName: "Paddle",
224
223
  verifyAndParseWebhook: verifyAndParsePaddleWebhook(runtimes.webhook, {
225
224
  priceToTier,
225
+ oneOffPriceIds: options.oneOffPriceIds ?? [],
226
226
  ...(options.nowSeconds && { nowSeconds: options.nowSeconds }),
227
227
  }),
228
+ shouldRedeliverIgnoredEvent: ({ event, reason, deps }) =>
229
+ shouldRedeliverLegacyCheckout({ event, reason, deps }),
228
230
  createCheckoutSession: createPaddleCheckoutSession(runtimes.ctx),
229
231
  createPortalSession: createPaddlePortalSession(runtimes.ctx),
230
232
  cancelSubscription: createPaddleCancelSubscription(runtimes.ctx),
@@ -0,0 +1,70 @@
1
+ // Marker for the one-time checkout-ledger backfill: the first completed sweep is
2
+ // recorded as an event on a fixed system-tenant stream, so every worker and every
3
+ // restart agrees on when the takeover window began.
4
+
5
+ import type { WriteHandlerDef } from "@cosmicdrift/kumiko-framework/engine";
6
+ import { v5 as uuidv5 } from "uuid";
7
+ import * as z from "zod";
8
+ import { SUBSCRIPTION_PADDLE_FEATURE } from "./constants.ts";
9
+
10
+ export const LEDGER_BACKFILL_EVENT_SHORT = "ledger-backfill-sweep-completed" as const;
11
+ export const LEDGER_BACKFILL_EVENT_QN =
12
+ `${SUBSCRIPTION_PADDLE_FEATURE}:event:${LEDGER_BACKFILL_EVENT_SHORT}` as const;
13
+ export const LEDGER_BACKFILL_AGGREGATE_TYPE = "paddle-ledger-backfill" as const;
14
+
15
+ // Set in stone: changing it would orphan the marker and restart the takeover window.
16
+ const LEDGER_BACKFILL_NAMESPACE = "b4c1e7a2-5d38-4f6b-9a0e-2c7d8e1f3a59";
17
+
18
+ export const LEDGER_BACKFILL_AGGREGATE_ID = uuidv5(
19
+ "paddle-ledger-backfill",
20
+ LEDGER_BACKFILL_NAMESPACE,
21
+ );
22
+
23
+ export const ledgerBackfillPayloadSchema = z.object({ completedAt: z.string().min(1) });
24
+
25
+ export const ledgerBackfillMarkerPayloadSchema = z.object({ markCompleted: z.boolean() });
26
+ type LedgerBackfillMarkerPayload = z.infer<typeof ledgerBackfillMarkerPayloadSchema>;
27
+
28
+ export type LedgerBackfillMarkerResult = { readonly completedAt: string | null };
29
+
30
+ export const LEDGER_BACKFILL_MARKER_HANDLER_QN =
31
+ `${SUBSCRIPTION_PADDLE_FEATURE}:write:ledger-backfill-marker` as const;
32
+
33
+ // Reads the marker; with markCompleted it also writes it when absent. One handler
34
+ // for both, so the job never reads an event stream itself.
35
+ export const ledgerBackfillMarkerHandler: WriteHandlerDef = {
36
+ name: "ledger-backfill-marker",
37
+ agent: { expose: false },
38
+ schema: ledgerBackfillMarkerPayloadSchema,
39
+ access: { roles: ["system"] },
40
+ handler: async (event, ctx) => {
41
+ // @cast-boundary engine-payload — dispatcher-zod-validated payload
42
+ const { markCompleted } = event.payload as LedgerBackfillMarkerPayload;
43
+ const stored = await ctx.events.load(LEDGER_BACKFILL_AGGREGATE_ID);
44
+ const marker = stored.find((entry) => entry.type === LEDGER_BACKFILL_EVENT_QN);
45
+ if (marker) {
46
+ const parsed = ledgerBackfillPayloadSchema.parse(marker.payload);
47
+ return {
48
+ isSuccess: true as const,
49
+ data: { completedAt: parsed.completedAt } satisfies LedgerBackfillMarkerResult,
50
+ };
51
+ }
52
+ if (!markCompleted) {
53
+ return {
54
+ isSuccess: true as const,
55
+ data: { completedAt: null } satisfies LedgerBackfillMarkerResult,
56
+ };
57
+ }
58
+ const completedAt = ctx.tz.now().toString();
59
+ await ctx.events.unsafeAppend({
60
+ aggregateId: LEDGER_BACKFILL_AGGREGATE_ID,
61
+ aggregateType: LEDGER_BACKFILL_AGGREGATE_TYPE,
62
+ type: LEDGER_BACKFILL_EVENT_QN,
63
+ payload: { completedAt },
64
+ });
65
+ return {
66
+ isSuccess: true as const,
67
+ data: { completedAt } satisfies LedgerBackfillMarkerResult,
68
+ };
69
+ },
70
+ };
@@ -11,7 +11,6 @@ import { PaddleHttpError } from "./client.ts";
11
11
  import { paddleAmountSchema } from "./price-methods.ts";
12
12
  import type { PaddleCtxRuntime, PaddlePluginMethod } from "./runtime.ts";
13
13
  import { mapPaddleSubscriptionState, paddleSubscriptionSchema } from "./subscription-state.ts";
14
- import { signTenantBinding } from "./tenant-binding.ts";
15
14
 
16
15
  const NOT_FOUND = 404;
17
16
 
@@ -84,23 +83,18 @@ export function createPaddlePreviewPlanSwitch(
84
83
 
85
84
  // The switch itself arrives later as a subscription.updated webhook;
86
85
  // prevent_change keeps the old plan if the immediate charge fails. PATCH
87
- // replaces custom_data as a whole, so the tenant binding is sent again.
86
+ // replaces custom_data as a whole, so the tenant id (the webhook's stream locator) is sent again.
88
87
  export function createPaddleApplyPlanSwitch(
89
88
  runtime: PaddleCtxRuntime,
90
89
  ): PaddlePluginMethod<"applyPlanSwitch"> {
91
90
  return async (ctx, options) => {
92
- const bindingKey = await runtime.tenantBindingKey(ctx);
93
91
  await runtime.call(ctx, {
94
92
  method: "PATCH",
95
93
  path: paddleSubscriptionPath(options.providerSubscriptionId),
96
94
  body: {
97
95
  ...changePlanBody(options.targetPriceId),
98
96
  on_payment_failure: "prevent_change",
99
- custom_data: {
100
- tenantId: options.tenantId,
101
- tenantBinding: signTenantBinding(bindingKey, options.tenantId),
102
- ...(options.consentId && { consentId: options.consentId }),
103
- },
97
+ custom_data: { tenantId: options.tenantId },
104
98
  },
105
99
  });
106
100
  };
@@ -0,0 +1,36 @@
1
+ // While the takeover window of the checkout-ledger backfill is open, a Paddle event of a legacy
2
+ // checkout (custom_data still has the tenantBinding) that billing-foundation ignored as
3
+ // "not in the ledger" may only be waiting for the next sweep. Answering it with a retryable
4
+ // 5xx makes Paddle deliver it again once the sweep has ledgered the checkout.
5
+
6
+ import type { SignatureExtraRouteDeps } from "@cosmicdrift/kumiko-framework/api";
7
+ import { SYSTEM_TENANT_ID } from "@cosmicdrift/kumiko-framework/engine";
8
+ import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
9
+ import { isTakeoverWindowOver } from "./backfill-checkout-ledger.ts";
10
+ import {
11
+ LEDGER_BACKFILL_MARKER_HANDLER_QN,
12
+ type LedgerBackfillMarkerResult,
13
+ } from "./ledger-backfill-marker.ts";
14
+ import { hasLegacyTenantBinding } from "./webhook-events.ts";
15
+
16
+ type IgnoredEvent = Parameters<typeof hasLegacyTenantBinding>[0];
17
+
18
+ export async function shouldRedeliverLegacyCheckout(args: {
19
+ readonly event: IgnoredEvent;
20
+ readonly reason: string;
21
+ readonly deps: SignatureExtraRouteDeps;
22
+ readonly now?: () => Temporal.Instant;
23
+ }): Promise<boolean> {
24
+ if (!hasLegacyTenantBinding(args.event)) return false;
25
+ const marker = await args.deps.dispatchWriteAs({
26
+ handlerQn: LEDGER_BACKFILL_MARKER_HANDLER_QN,
27
+ tenantId: SYSTEM_TENANT_ID,
28
+ roles: [],
29
+ payload: { markCompleted: false },
30
+ });
31
+ // Cannot tell whether the sweep is still open: err towards redelivery, Paddle retries a bounded number of times.
32
+ if (!marker.isSuccess) return true;
33
+ const { completedAt } = marker.data as LedgerBackfillMarkerResult; // @cast-boundary engine-payload
34
+ if (completedAt === null) return true;
35
+ return !isTakeoverWindowOver(completedAt, (args.now ?? Temporal.Now.instant)());
36
+ }
@@ -19,7 +19,7 @@ import {
19
19
  } from "@cosmicdrift/kumiko-framework/engine";
20
20
  import { UnconfiguredError } from "@cosmicdrift/kumiko-framework/errors";
21
21
  import type { SecretsContext } from "@cosmicdrift/kumiko-framework/secrets";
22
- import { assertBillingLive } from "../shared/index.ts";
22
+ import { assertBillingLive, isBillingLive } from "../shared/index.ts";
23
23
  import { createPaddleHttp, type PaddleRequest, type PaddleSend } from "./client.ts";
24
24
  import {
25
25
  PADDLE_BASE_URLS,
@@ -35,14 +35,12 @@ export type PaddlePluginMethod<TName extends keyof SubscriptionProviderPlugin> =
35
35
  export type PaddleFallbacks = {
36
36
  readonly apiKey?: string;
37
37
  readonly webhookSecret?: string;
38
- readonly tenantBindingKey?: string;
39
38
  readonly clientToken?: string;
40
39
  };
41
40
 
42
41
  export type PaddleRuntimeDeps = {
43
42
  readonly apiKeyHandle: ConfigKeyHandle<"text">;
44
43
  readonly webhookSecretHandle: ConfigKeyHandle<"text">;
45
- readonly tenantBindingKeyHandle: ConfigKeyHandle<"text">;
46
44
  readonly clientTokenHandle: ConfigKeyHandle<"text">;
47
45
  readonly billingLiveHandle: ConfigKeyHandle<"boolean">;
48
46
  readonly environmentHandle: ConfigKeyHandle<"select">;
@@ -54,16 +52,19 @@ function hintFor(shortName: string): string {
54
52
  return `Set it via config:write:set on \`${SUBSCRIPTION_PADDLE_FEATURE}:config:${shortName}\` (or seed it from the matching PADDLE_* variable during the env bridge).`;
55
53
  }
56
54
 
55
+ // The slice of HandlerContext and JobContext the Paddle calls need, so the
56
+ // backfill job reaches Paddle through the same key and environment resolution.
57
+ export type PaddleCallSource = Pick<HandlerContext, "config" | "services" | "user">;
58
+
57
59
  export type PaddleCtxRuntime = {
58
- readonly call: (ctx: HandlerContext, request: PaddleRequest) => Promise<unknown>;
60
+ readonly call: (ctx: PaddleCallSource, request: PaddleRequest) => Promise<unknown>;
61
+ readonly hasApiKey: (ctx: PaddleCallSource) => Promise<boolean>;
59
62
  readonly assertBillingLive: (ctx: HandlerContext, handlerName?: string) => Promise<void>;
60
63
  readonly isBillingEnabled: (ctx: HandlerContext) => Promise<boolean>;
61
- readonly tenantBindingKey: (ctx: HandlerContext) => Promise<string>;
62
64
  };
63
65
 
64
66
  export type PaddleWebhookRuntime = {
65
67
  readonly resolveWebhookSecret: (systemSecrets?: SecretsContext) => Promise<string>;
66
- readonly resolveTenantBindingKey: (systemSecrets?: SecretsContext) => Promise<string>;
67
68
  };
68
69
 
69
70
  export type PaddleCheckoutConfig = {
@@ -87,7 +88,7 @@ export function createPaddleRuntimes(deps: PaddleRuntimeDeps): PaddleRuntimes {
87
88
  const http = createPaddleHttp(deps.send);
88
89
 
89
90
  async function ctxSecret(
90
- ctx: HandlerContext,
91
+ ctx: PaddleCallSource,
91
92
  handle: ConfigKeyHandle<"text">,
92
93
  fallback: string | undefined,
93
94
  shortName: string,
@@ -129,7 +130,7 @@ export function createPaddleRuntimes(deps: PaddleRuntimeDeps): PaddleRuntimes {
129
130
  }
130
131
 
131
132
  async function hasSecret(
132
- ctx: HandlerContext,
133
+ ctx: PaddleCallSource,
133
134
  handle: ConfigKeyHandle<"text">,
134
135
  fallback: string | undefined,
135
136
  ): Promise<boolean> {
@@ -140,7 +141,7 @@ export function createPaddleRuntimes(deps: PaddleRuntimeDeps): PaddleRuntimes {
140
141
  : false;
141
142
  }
142
143
 
143
- async function baseUrlFor(ctx: HandlerContext): Promise<string> {
144
+ async function baseUrlFor(ctx: PaddleCallSource): Promise<string> {
144
145
  const environment = ctx.config ? await ctx.config(deps.environmentHandle) : undefined;
145
146
  return PADDLE_BASE_URLS[environmentOf(environment)];
146
147
  }
@@ -155,29 +156,17 @@ export function createPaddleRuntimes(deps: PaddleRuntimeDeps): PaddleRuntimes {
155
156
  },
156
157
  request,
157
158
  ),
159
+ hasApiKey: (ctx) => hasSecret(ctx, deps.apiKeyHandle, deps.fallback.apiKey),
158
160
  assertBillingLive: (ctx, handlerName = "create-checkout-session") =>
159
161
  assertBillingLive(ctx, deps.billingLiveHandle, SUBSCRIPTION_PADDLE_FEATURE, handlerName),
160
162
  isBillingEnabled: async (ctx) => {
161
- const live = ctx.config ? await ctx.config(deps.billingLiveHandle) : undefined;
162
- if (live !== true) return false;
163
- return (
164
- (await hasSecret(ctx, deps.apiKeyHandle, deps.fallback.apiKey)) &&
165
- (await hasSecret(ctx, deps.tenantBindingKeyHandle, deps.fallback.tenantBindingKey))
166
- );
163
+ if (!(await isBillingLive(ctx, deps.billingLiveHandle))) return false;
164
+ return hasSecret(ctx, deps.apiKeyHandle, deps.fallback.apiKey);
167
165
  },
168
- tenantBindingKey: (ctx) =>
169
- ctxSecret(
170
- ctx,
171
- deps.tenantBindingKeyHandle,
172
- deps.fallback.tenantBindingKey,
173
- "tenant-binding-key",
174
- ),
175
166
  },
176
167
  webhook: {
177
168
  resolveWebhookSecret: (systemSecrets) =>
178
169
  webhookSecret(systemSecrets, deps.webhookSecretHandle, deps.fallback.webhookSecret),
179
- resolveTenantBindingKey: (systemSecrets) =>
180
- webhookSecret(systemSecrets, deps.tenantBindingKeyHandle, deps.fallback.tenantBindingKey),
181
170
  },
182
171
  readCheckoutConfig: async (ctx) => {
183
172
  const stored = ctx.config ? await ctx.config(deps.clientTokenHandle) : undefined;
@@ -25,6 +25,7 @@ export const paddleSubscriptionSchema = z.object({
25
25
  id: z.string().min(1),
26
26
  status: z.string(),
27
27
  customer_id: z.string().min(1),
28
+ transaction_id: z.string().min(1).nullish(),
28
29
  items: z.array(
29
30
  z.object({
30
31
  price: z.object({ id: z.string().min(1) }),
@@ -1,6 +1,7 @@
1
1
  // Paddle webhook: signature check, then mapping of Paddle's event envelope onto
2
- // the foundation's normalized events. Events without a valid tenant binding are
3
- // dropped (200 ignored): see tenant-binding.ts.
2
+ // the foundation's normalized events. `custom_data.tenantId` only locates the
3
+ // tenant's stream; Paddle.js can open checkouts with any customData, so
4
+ // billing-foundation accepts an event only for a checkout in its own ledger.
4
5
 
5
6
  import {
6
7
  BillingEventKinds,
@@ -13,6 +14,7 @@ import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
13
14
  import type { SecretsContext } from "@cosmicdrift/kumiko-framework/secrets";
14
15
  import { parseJsonOrThrow } from "@cosmicdrift/kumiko-framework/utils";
15
16
  import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
17
+ import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
16
18
  import * as z from "zod";
17
19
  import { PADDLE_PROVIDER_NAME } from "./constants.ts";
18
20
  import type { PaddleWebhookRuntime } from "./runtime.ts";
@@ -21,7 +23,6 @@ import {
21
23
  paddleCustomDataSchema,
22
24
  paddleSubscriptionSchema,
23
25
  } from "./subscription-state.ts";
24
- import { boundTenantOf } from "./tenant-binding.ts";
25
26
  import { verifyPaddleSignature } from "./verify-webhook.ts";
26
27
 
27
28
  const PADDLE_SUBSCRIPTION_EVENT_TYPES: Readonly<Record<string, SubscriptionEventType>> = {
@@ -59,6 +60,8 @@ const paddleTransactionSchema = z.object({
59
60
 
60
61
  export type PaddleWebhookOptions = {
61
62
  readonly priceToTier: Readonly<Record<string, string>>;
63
+ /** Prices a one-off payment may credit; Paddle.js lets a browser open checkouts with any customData. */
64
+ readonly oneOffPriceIds: readonly string[];
62
65
  /** Test seam: Unix seconds. Defaults to the wall clock. */
63
66
  readonly nowSeconds?: () => number;
64
67
  };
@@ -67,10 +70,17 @@ function currentUnixSeconds(): number {
67
70
  return Math.floor(Temporal.Now.instant().epochMilliseconds / 1000);
68
71
  }
69
72
 
73
+ export function tenantIdOf(
74
+ customData: Readonly<Record<string, unknown>> | null | undefined,
75
+ ): string | undefined {
76
+ const tenantId = customData?.["tenantId"];
77
+ return typeof tenantId === "string" && tenantId.length > 0 ? tenantId : undefined;
78
+ }
79
+
70
80
  function parsePaymentEvent(
71
81
  providerEventId: string,
72
82
  data: unknown,
73
- bindingKey: string,
83
+ oneOffPriceIds: readonly string[],
74
84
  ): PaymentEvent | null {
75
85
  const parsed = paddleTransactionSchema.safeParse(data);
76
86
  if (!parsed.success) return null;
@@ -79,14 +89,20 @@ function parsePaymentEvent(
79
89
  if (transaction.subscription_id) return null;
80
90
  const priceId = transaction.items[0]?.price.id;
81
91
  const quantity = transaction.items[0]?.quantity ?? 1;
82
- const bound = boundTenantOf(transaction.custom_data, bindingKey);
83
- if (!bound || !priceId || !transaction.customer_id) return null;
92
+ const tenantId = tenantIdOf(transaction.custom_data);
93
+ if (!tenantId || !priceId || !transaction.customer_id) return null;
94
+ if (!oneOffPriceIds.includes(priceId)) {
95
+ createFallbackLogger("subscription-paddle").warn(
96
+ "paddle one-off transaction dropped: price is not an allowed one-off price",
97
+ { providerEventId, priceId },
98
+ );
99
+ return null;
100
+ }
84
101
  return {
85
102
  kind: BillingEventKinds.payment,
86
103
  providerEventId,
87
104
  providerName: PADDLE_PROVIDER_NAME,
88
- tenantId: bound.tenantId,
89
- ...(bound.consentId !== undefined && { consentId: bound.consentId }),
105
+ tenantId,
90
106
  providerCheckoutId: transaction.id,
91
107
  providerCustomerId: transaction.customer_id,
92
108
  priceId,
@@ -115,21 +131,21 @@ function parseSubscriptionEvent(
115
131
  type: SubscriptionEventType,
116
132
  providerEventAt: string,
117
133
  data: unknown,
118
- options: { readonly priceToTier: Readonly<Record<string, string>>; readonly bindingKey: string },
134
+ priceToTier: Readonly<Record<string, string>>,
119
135
  ): SubscriptionEvent | null {
120
136
  const parsed = paddleSubscriptionSchema.safeParse(data);
121
137
  if (!parsed.success) return null;
122
138
  const sub = parsed.data;
123
- const bound = boundTenantOf(sub.custom_data, options.bindingKey);
124
- const state = mapPaddleSubscriptionState(sub, options.priceToTier);
125
- if (!bound || !state) return null;
139
+ const tenantId = tenantIdOf(sub.custom_data);
140
+ const state = mapPaddleSubscriptionState(sub, priceToTier);
141
+ if (!tenantId || !state) return null;
126
142
  warnOnUnexpectedQuantity(providerEventId, sub.items);
127
143
  return {
128
144
  providerEventId,
129
145
  providerName: PADDLE_PROVIDER_NAME,
130
146
  type,
131
- tenantId: bound.tenantId,
132
- ...(bound.consentId !== undefined && { consentId: bound.consentId }),
147
+ tenantId,
148
+ ...(sub.transaction_id && { providerCheckoutId: sub.transaction_id }),
133
149
  providerCustomerId: sub.customer_id,
134
150
  providerSubscriptionId: sub.id,
135
151
  providerEventAt,
@@ -137,6 +153,28 @@ function parseSubscriptionEvent(
137
153
  };
138
154
  }
139
155
 
156
+ // Events whose custom_data still carries the pre-ledger tenantBinding: they belong to a checkout
157
+ // the backfill sweep may not have ledgered yet. Kept beside the event, not on it, because
158
+ // billing-foundation must not know about the legacy binding.
159
+ const legacyBindingEvents = new WeakSet<object>();
160
+
161
+ export function hasLegacyTenantBinding(event: SubscriptionEvent | PaymentEvent): boolean {
162
+ return legacyBindingEvents.has(event);
163
+ }
164
+
165
+ function markLegacyBinding<T extends SubscriptionEvent | PaymentEvent | null>(
166
+ event: T,
167
+ data: unknown,
168
+ ): T {
169
+ if (
170
+ event !== null &&
171
+ typeof propertyOf(propertyOf(data, "custom_data"), "tenantBinding") === "string"
172
+ ) {
173
+ legacyBindingEvents.add(event);
174
+ }
175
+ return event;
176
+ }
177
+
140
178
  export function verifyAndParsePaddleWebhook(
141
179
  runtime: PaddleWebhookRuntime,
142
180
  options: PaddleWebhookOptions,
@@ -149,8 +187,6 @@ export function verifyAndParsePaddleWebhook(
149
187
  return async (rawBody, headers, systemSecrets) => {
150
188
  const secret = await runtime.resolveWebhookSecret(systemSecrets);
151
189
  verifyPaddleSignature(rawBody, headers, secret, nowSeconds());
152
- // After verification only: an unauthenticated request must not trigger a second secret read.
153
- const bindingKey = await runtime.resolveTenantBindingKey(systemSecrets);
154
190
 
155
191
  // Past verification the body is trusted to be Paddle's; a malformed shape is
156
192
  // schema drift, so it is dropped (200 ignored) instead of answered with a 401.
@@ -160,13 +196,24 @@ export function verifyAndParsePaddleWebhook(
160
196
  if (!envelope.success) return null;
161
197
 
162
198
  const { event_id: providerEventId, event_type: type, occurred_at, data } = envelope.data;
163
- if (type === TRANSACTION_COMPLETED) return parsePaymentEvent(providerEventId, data, bindingKey);
199
+ if (type === TRANSACTION_COMPLETED) {
200
+ return markLegacyBinding(
201
+ parsePaymentEvent(providerEventId, data, options.oneOffPriceIds),
202
+ data,
203
+ );
204
+ }
164
205
  if (!Object.hasOwn(PADDLE_SUBSCRIPTION_EVENT_TYPES, type)) return null;
165
206
  const normalizedType = PADDLE_SUBSCRIPTION_EVENT_TYPES[type];
166
207
  if (!normalizedType) return null;
167
- return parseSubscriptionEvent(providerEventId, normalizedType, occurred_at, data, {
168
- priceToTier: options.priceToTier,
169
- bindingKey,
170
- });
208
+ return markLegacyBinding(
209
+ parseSubscriptionEvent(
210
+ providerEventId,
211
+ normalizedType,
212
+ occurred_at,
213
+ data,
214
+ options.priceToTier,
215
+ ),
216
+ data,
217
+ );
171
218
  };
172
219
  }
@@ -1,4 +1,11 @@
1
1
  [
2
+ {
3
+ "version": "0.414.0",
4
+ "type": "breaking",
5
+ "title": "Stripe checkouts are matched by session id, consentId metadata is gone",
6
+ "detail": "`createCheckoutSession` returns the Checkout Session id as `providerCheckoutId`, and `customer.subscription.created` looks up the session of the subscription (`checkout.sessions.list`) to carry that id; if the Stripe API call fails, the webhook replies 503 so Stripe retries; a successful empty list yields a created event without checkout id that is ignored as not in the ledger. Session metadata carries only the tenantId. The new option `clientConfig` passes Stripe SDK client settings, for tests against a local fixture API.",
7
+ "migration": "Open Checkout Sessions from before the upgrade are not in the ledger and their `customer.subscription.created` and payment events are ignored; let them expire or finish first. The API key of the Stripe plugin needs read access to Checkout Sessions."
8
+ },
2
9
  {
3
10
  "version": "0.388.0",
4
11
  "type": "improvement",
@@ -43,6 +43,7 @@ import {
43
43
  type FeatureDefinition,
44
44
  } from "@cosmicdrift/kumiko-framework/engine";
45
45
  import { type FeatureWithEnvSchema, featureWithEnvSchema } from "@cosmicdrift/kumiko-framework/env";
46
+ import type Stripe from "stripe";
46
47
  import * as z from "zod";
47
48
  import { priceEnvSchema } from "../shared/index.ts";
48
49
  import {
@@ -137,6 +138,9 @@ export type SubscriptionStripeOptions = {
137
138
  * explicit allowlist every one-off checkout is closed, the same
138
139
  * fail-closed default `priceToTier` has for mode:"subscription". */
139
140
  readonly oneOffPriceIds?: readonly string[];
141
+ /** Stripe SDK client config (host, protocol, retries) — lets tests point the
142
+ * client at a local fixture API. */
143
+ readonly clientConfig?: Stripe.StripeConfig;
140
144
  };
141
145
 
142
146
  /**
@@ -222,6 +226,7 @@ export function createSubscriptionStripeFeature(
222
226
  ...(options.apiKey !== undefined && { apiKey: options.apiKey }),
223
227
  ...(options.webhookSecret !== undefined && { webhookSecret: options.webhookSecret }),
224
228
  },
229
+ ...(options.clientConfig !== undefined && { clientConfig: options.clientConfig }),
225
230
  });
226
231
 
227
232
  const priceCache = createStripePriceCache();
@@ -116,7 +116,10 @@ export function createStripeCheckoutSession(
116
116
  runtime: StripeCtxRuntime,
117
117
  { paymentInvoiceCreation = true }: StripeCheckoutSessionRuntimeOptions = {},
118
118
  ) {
119
- return async (ctx: HandlerContext, options: StripeCheckoutOptions): Promise<{ url: string }> => {
119
+ return async (
120
+ ctx: HandlerContext,
121
+ options: StripeCheckoutOptions,
122
+ ): Promise<{ url: string; providerCheckoutId: string }> => {
120
123
  // Invariant: without billing-live, no Stripe session may be created
121
124
  // (sk_test_-keys in production would otherwise create a test-mode checkout).
122
125
  // Throw before every Stripe call. The guard used to be provided by the
@@ -125,10 +128,7 @@ export function createStripeCheckoutSession(
125
128
  await runtime.assertBillingLive(ctx);
126
129
  const stripe = await runtime.clientForCtx(ctx);
127
130
  const mode = options.mode ?? "subscription";
128
- const metadata = {
129
- tenantId: options.tenantId,
130
- ...(options.consentId && { consentId: options.consentId }),
131
- };
131
+ const metadata = { tenantId: options.tenantId };
132
132
 
133
133
  const sessionParams = (
134
134
  providerCustomerId: string | undefined,
@@ -182,7 +182,7 @@ export function createStripeCheckoutSession(
182
182
  // guards against future API drift.
183
183
  throw new Error("subscription-stripe: checkout.sessions.create returned no url");
184
184
  }
185
- return { url: session.url };
185
+ return { url: session.url, providerCheckoutId: session.id };
186
186
  };
187
187
  }
188
188