@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.
- package/package.json +1 -1
- package/packages/bundled-features/package.json +16 -1
- package/packages/bundled-features/src/admin-shell/changes.json +6 -0
- package/packages/bundled-features/src/admin-shell/feature.ts +8 -7
- package/packages/bundled-features/src/agent-tools/agent-doc-lint.ts +5 -1
- package/packages/bundled-features/src/agent-tools/agent-manifest.ts +36 -27
- package/packages/bundled-features/src/agent-tools/api-docs/collect-events.ts +8 -1
- package/packages/bundled-features/src/agent-tools/api-docs/collect.ts +3 -2
- package/packages/bundled-features/src/agent-tools/api-docs/generate.ts +6 -0
- package/packages/bundled-features/src/agent-tools/api-docs/index.ts +1 -0
- package/packages/bundled-features/src/agent-tools/api-docs/problems.ts +38 -1
- package/packages/bundled-features/src/agent-tools/api-docs/render-openapi.ts +1 -0
- package/packages/bundled-features/src/agent-tools/api-docs/resolve-config.ts +17 -0
- package/packages/bundled-features/src/agent-tools/api-docs/scope-slug-collisions.ts +17 -0
- package/packages/bundled-features/src/agent-tools/api-docs/translation-gaps.ts +42 -0
- package/packages/bundled-features/src/agent-tools/api-docs/webhook-example-problems.ts +30 -0
- package/packages/bundled-features/src/agent-tools/changes.json +12 -0
- package/packages/bundled-features/src/agent-tools/index.ts +1 -0
- package/packages/bundled-features/src/agent-tools/labels.ts +19 -6
- package/packages/bundled-features/src/agent-tools/tool-catalog.ts +18 -7
- package/packages/bundled-features/src/agent-tools/tool-dispatch.ts +14 -1
- package/packages/bundled-features/src/agent-tools/types.ts +4 -0
- package/packages/bundled-features/src/audit/event-classification.ts +6 -0
- package/packages/bundled-features/src/audit/web/i18n.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/changes.json +18 -0
- package/packages/bundled-features/src/auth-email-password/errors.ts +0 -13
- package/packages/bundled-features/src/auth-email-password/handlers/invite-signup-complete.write.ts +147 -121
- package/packages/bundled-features/src/auth-email-password/handlers/login-options.query.ts +1 -1
- package/packages/bundled-features/src/auth-email-password/handlers/request-account-unlock.write.ts +1 -1
- package/packages/bundled-features/src/auth-email-password/handlers/request-email-verification.write.ts +0 -1
- package/packages/bundled-features/src/auth-email-password/handlers/request-password-reset.write.ts +0 -1
- package/packages/bundled-features/src/auth-email-password/handlers/self-registration-status.query.ts +1 -1
- package/packages/bundled-features/src/auth-email-password/reset-token.ts +0 -2
- package/packages/bundled-features/src/auth-email-password/seeding.ts +39 -7
- package/packages/bundled-features/src/auth-email-password/signup-token-store.ts +2 -3
- package/packages/bundled-features/src/auth-email-password/unlock-token.ts +0 -2
- package/packages/bundled-features/src/auth-email-password/verification-token.ts +0 -2
- package/packages/bundled-features/src/auth-email-password/web/auth-form-primitives.tsx +2 -2
- package/packages/bundled-features/src/auth-email-password/web/auth-gate.tsx +2 -2
- package/packages/bundled-features/src/auth-email-password/web/auth-redirect.ts +5 -0
- package/packages/bundled-features/src/auth-email-password/web/forgot-password-screen.tsx +1 -6
- package/packages/bundled-features/src/auth-email-password/web/invite-accept-screen.tsx +1 -1
- package/packages/bundled-features/src/auth-email-password/web/return-path.ts +2 -1
- package/packages/bundled-features/src/auth-email-password/web/session.tsx +12 -13
- package/packages/bundled-features/src/auth-email-password/web/signup-screen.tsx +1 -6
- package/packages/bundled-features/src/auth-email-password/web/static-account.ts +6 -1
- package/packages/bundled-features/src/auth-email-password/web/tenant-switcher.tsx +1 -1
- package/packages/bundled-features/src/auth-email-password/web/token-confirm-screen.tsx +4 -5
- package/packages/bundled-features/src/auth-email-password/web/user-menu.tsx +1 -1
- package/packages/bundled-features/src/auth-mfa/changes.json +6 -0
- package/packages/bundled-features/src/auth-mfa/web/mfa-code-or-recovery-field.tsx +17 -1
- package/packages/bundled-features/src/auth-mfa/web/mfa-disable-dialog.tsx +1 -1
- package/packages/bundled-features/src/auth-mfa/web/mfa-regenerate-recovery-dialog.tsx +1 -1
- package/packages/bundled-features/src/auth-mfa/web/mfa-setup-preauth-screen.tsx +1 -1
- package/packages/bundled-features/src/auth-mfa/web/mfa-verify-screen.tsx +16 -47
- package/packages/bundled-features/src/auth-mfa-user-data/index.ts +5 -6
- package/packages/bundled-features/src/billing-foundation/aggregate-id.ts +0 -4
- package/packages/bundled-features/src/billing-foundation/changes.json +61 -0
- package/packages/bundled-features/src/billing-foundation/checkout-core.ts +19 -1
- package/packages/bundled-features/src/billing-foundation/checkout-ledger.ts +67 -0
- package/packages/bundled-features/src/billing-foundation/consumer-protection/consent-gate.ts +2 -1
- package/packages/bundled-features/src/billing-foundation/consumer-protection/consent-text.ts +49 -2
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-open-cancels.ts +5 -0
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-provider-timeout.ts +23 -0
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-record.ts +12 -7
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-revoke.ts +1 -1
- package/packages/bundled-features/src/billing-foundation/events.ts +51 -10
- package/packages/bundled-features/src/billing-foundation/feature.ts +15 -1
- package/packages/bundled-features/src/billing-foundation/handlers/billing-plans.query.ts +47 -14
- package/packages/bundled-features/src/billing-foundation/handlers/create-checkout-session.write.ts +9 -1
- package/packages/bundled-features/src/billing-foundation/handlers/process-event.write.ts +183 -17
- package/packages/bundled-features/src/billing-foundation/handlers/process-payment-event.write.ts +35 -10
- package/packages/bundled-features/src/billing-foundation/handlers/record-checkout-opened.write.ts +25 -0
- package/packages/bundled-features/src/billing-foundation/handlers/start-plan-checkout.write.ts +9 -1
- package/packages/bundled-features/src/billing-foundation/handlers/switch-plan.write.ts +16 -4
- package/packages/bundled-features/src/billing-foundation/i18n.ts +3 -0
- package/packages/bundled-features/src/billing-foundation/pending-plan-switch.ts +80 -0
- package/packages/bundled-features/src/billing-foundation/scrub-raw-payload-headers.ts +50 -0
- package/packages/bundled-features/src/billing-foundation/types.ts +47 -30
- package/packages/bundled-features/src/billing-foundation/validate-options.ts +18 -0
- package/packages/bundled-features/src/billing-foundation/web/billing-plans-panel.tsx +10 -5
- package/packages/bundled-features/src/billing-foundation/web/cancel-contract-dialog.tsx +1 -1
- package/packages/bundled-features/src/billing-foundation/web/checkout-consent-dialog.tsx +1 -1
- package/packages/bundled-features/src/billing-foundation/web/constants.ts +5 -2
- package/packages/bundled-features/src/billing-foundation/web/plan-switch-confirm-dialog.tsx +1 -1
- package/packages/bundled-features/src/billing-foundation/webhook-handler.ts +65 -17
- package/packages/bundled-features/src/cap-counter/aggregate-id.ts +0 -2
- package/packages/bundled-features/src/cap-counter/changes.json +6 -0
- package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +19 -4
- package/packages/bundled-features/src/cap-overview/changes.json +6 -0
- package/packages/bundled-features/src/cap-overview/handlers/tenant-caps-list.query.ts +22 -6
- package/packages/bundled-features/src/cap-overview/i18n.ts +1 -0
- package/packages/bundled-features/src/cap-overview/index.ts +1 -0
- package/packages/bundled-features/src/cap-overview/types.ts +11 -1
- package/packages/bundled-features/src/cap-overview/web/cap-cards-panel.tsx +6 -2
- package/packages/bundled-features/src/cap-overview/web/cap-usage-bar.tsx +10 -1
- package/packages/bundled-features/src/cap-overview/web/usage-math.ts +5 -0
- package/packages/bundled-features/src/channel-in-app/changes.json +6 -0
- package/packages/bundled-features/src/channel-in-app/handlers/read-state-by-keys.query.ts +2 -2
- package/packages/bundled-features/src/channel-whatsapp/aggregate-id.ts +29 -0
- package/packages/bundled-features/src/channel-whatsapp/changes.json +32 -0
- package/packages/bundled-features/src/channel-whatsapp/constants.ts +46 -0
- package/packages/bundled-features/src/channel-whatsapp/events.ts +94 -0
- package/packages/bundled-features/src/channel-whatsapp/feature.ts +72 -0
- package/packages/bundled-features/src/channel-whatsapp/graph-client.ts +398 -0
- package/packages/bundled-features/src/channel-whatsapp/in-memory-meta.ts +300 -0
- package/packages/bundled-features/src/channel-whatsapp/inbound-handlers.ts +210 -0
- package/packages/bundled-features/src/channel-whatsapp/index.ts +66 -0
- package/packages/bundled-features/src/channel-whatsapp/meta-signature.ts +26 -0
- package/packages/bundled-features/src/channel-whatsapp/options.ts +149 -0
- package/packages/bundled-features/src/channel-whatsapp/pii.ts +109 -0
- package/packages/bundled-features/src/channel-whatsapp/webhook-normalize.ts +247 -0
- package/packages/bundled-features/src/channel-whatsapp/webhook-routes.ts +185 -0
- package/packages/bundled-features/src/compliance-profiles/changes.json +5 -0
- package/packages/bundled-features/src/compliance-profiles/handlers/set-profile.write.ts +2 -0
- package/packages/bundled-features/src/compliance-profiles/handlers/sub-processors.query.ts +1 -1
- package/packages/bundled-features/src/config/changes.json +12 -0
- package/packages/bundled-features/src/config/handlers/set.write.ts +7 -0
- package/packages/bundled-features/src/config/handlers/values.query.ts +8 -1
- package/packages/bundled-features/src/config/index.ts +1 -0
- package/packages/bundled-features/src/config/read-redaction.ts +6 -3
- package/packages/bundled-features/src/config/table.ts +1 -0
- package/packages/bundled-features/src/config/write-helpers.ts +3 -2
- package/packages/bundled-features/src/crypto-shredding/changes.json +18 -0
- package/packages/bundled-features/src/crypto-shredding/constants.ts +2 -0
- package/packages/bundled-features/src/crypto-shredding/handlers/forget-subject.write.ts +38 -18
- package/packages/bundled-features/src/crypto-shredding/index.ts +4 -0
- package/packages/bundled-features/src/crypto-shredding/subject-forget-after-delete-hook.ts +49 -0
- package/packages/bundled-features/src/custom-fields/aggregate-id.ts +0 -1
- package/packages/bundled-features/src/custom-fields/entity.ts +1 -0
- package/packages/bundled-features/src/custom-fields/wire-for-entity.ts +0 -1
- package/packages/bundled-features/src/data-retention/changes.json +12 -0
- package/packages/bundled-features/src/data-retention/erase-notes-of-deleted-row.ts +23 -0
- package/packages/bundled-features/src/data-retention/feature.ts +2 -5
- package/packages/bundled-features/src/data-retention/run-retention-cleanup.ts +38 -18
- package/packages/bundled-features/src/data-retention/tenant-destruction-hold.ts +9 -0
- package/packages/bundled-features/src/delivery/attempt-log-factory.ts +11 -0
- package/packages/bundled-features/src/delivery/attempt-log.ts +3 -3
- package/packages/bundled-features/src/delivery/changes.json +12 -0
- package/packages/bundled-features/src/delivery/channel-context.ts +6 -3
- package/packages/bundled-features/src/delivery/db/queries/preferences.ts +0 -1
- package/packages/bundled-features/src/delivery/delivery-service.ts +3 -0
- package/packages/bundled-features/src/delivery/feature.ts +4 -13
- package/packages/bundled-features/src/delivery/handlers/opted-in-user-ids.query.ts +54 -0
- package/packages/bundled-features/src/delivery/handlers/preferences.query.ts +2 -20
- package/packages/bundled-features/src/delivery/handlers/resubscribe-user.write.ts +2 -25
- package/packages/bundled-features/src/delivery/handlers/unsubscribe-page-chrome.query.ts +2 -0
- package/packages/bundled-features/src/delivery/handlers/unsubscribe-user.write.ts +2 -27
- package/packages/bundled-features/src/delivery/index.ts +3 -1
- package/packages/bundled-features/src/delivery/options.ts +11 -0
- package/packages/bundled-features/src/delivery/preference-rows.ts +33 -0
- package/packages/bundled-features/src/delivery/set-preference-enabled.ts +40 -0
- package/packages/bundled-features/src/delivery/testing.ts +3 -1
- package/packages/bundled-features/src/delivery/types.ts +1 -0
- package/packages/bundled-features/src/delivery/unsubscribe-page.ts +7 -1
- package/packages/bundled-features/src/delivery/upsert-preference.ts +0 -1
- package/packages/bundled-features/src/delivery/web/public-names.ts +1 -0
- package/packages/bundled-features/src/derivatives-sharp/render.ts +9 -9
- package/packages/bundled-features/src/document-ingest-foundation/aggregate-id.ts +0 -1
- package/packages/bundled-features/src/document-ingest-foundation/append-missing-extract-event.ts +37 -25
- package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
- package/packages/bundled-features/src/document-ingest-foundation/feature.ts +1 -0
- package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +34 -14
- package/packages/bundled-features/src/documents/aggregate-id.ts +0 -2
- package/packages/bundled-features/src/documents/changes.json +24 -0
- package/packages/bundled-features/src/documents/constants.ts +10 -2
- package/packages/bundled-features/src/documents/ensure-link.ts +3 -4
- package/packages/bundled-features/src/documents/feature.ts +33 -6
- package/packages/bundled-features/src/documents/handlers/import.write.ts +2 -2
- package/packages/bundled-features/src/documents/queries/expiry-overview.query.ts +2 -1
- package/packages/bundled-features/src/documents/queries/for-record.query.ts +3 -4
- package/packages/bundled-features/src/documents/queries/list-page.ts +11 -3
- package/packages/bundled-features/src/documents/queries/overview.query.ts +2 -2
- package/packages/bundled-features/src/documents/screens.ts +8 -3
- package/packages/bundled-features/src/documents/tab.ts +1 -1
- package/packages/bundled-features/src/feature-toggles/toggle-sync-signal.ts +6 -3
- package/packages/bundled-features/src/file-derivatives/handlers/public-variant-by-file-ref.query.ts +1 -1
- package/packages/bundled-features/src/file-derivatives/handlers/public-variant.query.ts +1 -1
- package/packages/bundled-features/src/file-foundation/probe.ts +9 -3
- package/packages/bundled-features/src/file-foundation/read-file-ref-content.ts +24 -11
- package/packages/bundled-features/src/file-provider-inmemory/feature.ts +1 -1
- package/packages/bundled-features/src/file-provider-s3/changes.json +14 -0
- package/packages/bundled-features/src/file-provider-s3/env-feature.ts +1 -1
- package/packages/bundled-features/src/file-provider-s3/env-named-feature.ts +1 -1
- package/packages/bundled-features/src/file-provider-s3/env-schema.ts +24 -7
- package/packages/bundled-features/src/file-provider-s3/feature.ts +1 -1
- package/packages/bundled-features/src/file-provider-s3/index.ts +7 -1
- package/packages/bundled-features/src/file-provider-s3/lib/env-helper.ts +21 -13
- package/packages/bundled-features/src/file-provider-s3/lib/s3-provider.ts +8 -1
- package/packages/bundled-features/src/files/changes.json +7 -0
- package/packages/bundled-features/src/folders/aggregate-id.ts +0 -1
- package/packages/bundled-features/src/folders/web/folder-manager.tsx +6 -6
- package/packages/bundled-features/src/folders-user-data/index.ts +12 -14
- package/packages/bundled-features/src/form-draft/feature.ts +1 -0
- package/packages/bundled-features/src/helpdesk/changes.json +56 -0
- package/packages/bundled-features/src/helpdesk/entity.ts +4 -1
- package/packages/bundled-features/src/helpdesk/feature.ts +42 -0
- package/packages/bundled-features/src/helpdesk/handlers/access.ts +0 -10
- package/packages/bundled-features/src/helpdesk/handlers/attempts.ts +7 -14
- package/packages/bundled-features/src/helpdesk/handlers/challenge.query.ts +1 -2
- package/packages/bundled-features/src/helpdesk/handlers/reply.write.ts +5 -12
- package/packages/bundled-features/src/helpdesk/handlers/report.write.ts +4 -10
- package/packages/bundled-features/src/helpdesk/handlers/submit.write.ts +5 -12
- package/packages/bundled-features/src/helpdesk/index.ts +1 -0
- package/packages/bundled-features/src/helpdesk/legacy-contact-config.ts +61 -0
- package/packages/bundled-features/src/helpdesk/legacy-contact-erasure.ts +45 -0
- package/packages/bundled-features/src/helpdesk/legacy-contact-retention.ts +65 -0
- package/packages/bundled-features/src/helpdesk/legacy-contact-streams.ts +187 -0
- package/packages/bundled-features/src/helpdesk/legacy-contact-user-data.ts +84 -0
- package/packages/bundled-features/src/helpdesk/lib.ts +55 -37
- package/packages/bundled-features/src/helpdesk/user-data-hooks.ts +89 -48
- package/packages/bundled-features/src/helpdesk/web/constants.ts +0 -1
- package/packages/bundled-features/src/inbound-mail-foundation/account-health.ts +1 -1
- package/packages/bundled-features/src/inbound-mail-foundation/account-poll.ts +9 -2
- package/packages/bundled-features/src/inbound-mail-foundation/aggregate-id.ts +0 -2
- package/packages/bundled-features/src/inbound-mail-foundation/changes.json +54 -0
- package/packages/bundled-features/src/inbound-mail-foundation/constants.ts +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/content-refetch.ts +23 -2
- package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +73 -15
- package/packages/bundled-features/src/inbound-mail-foundation/events.ts +24 -16
- package/packages/bundled-features/src/inbound-mail-foundation/feature.ts +3 -1
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/account-address.ts +16 -2
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/attach-message-content.write.ts +10 -3
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/connect-account.write.ts +23 -9
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/forget-message.write.ts +79 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message-schema.ts +18 -5
- package/packages/bundled-features/src/inbound-mail-foundation/i18n.ts +3 -0
- package/packages/bundled-features/src/inbound-mail-foundation/index.ts +1 -0
- package/packages/bundled-features/src/inbound-mail-foundation/normalize-inbound-message.ts +22 -8
- package/packages/bundled-features/src/inbound-mail-foundation/oauth-access-token.ts +1 -1
- package/packages/bundled-features/src/inbound-mail-foundation/outbound-mail.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/personal-address.ts +20 -0
- package/packages/bundled-features/src/inbound-mail-foundation/purge-messages.ts +54 -0
- package/packages/bundled-features/src/inbound-mail-foundation/quarantine.ts +15 -5
- package/packages/bundled-features/src/inbound-mail-foundation/retention-job.ts +1 -5
- package/packages/bundled-features/src/inbound-mail-foundation/retention-sweep.ts +21 -34
- package/packages/bundled-features/src/inbound-mail-foundation/sanitize-inbound-html.ts +2 -5
- package/packages/bundled-features/src/inbound-mail-foundation/send-from-account.ts +9 -1
- package/packages/bundled-features/src/inbound-mail-foundation/supervisor-ingest.ts +7 -1
- package/packages/bundled-features/src/inbound-mail-foundation/sync-account-now.ts +1 -1
- package/packages/bundled-features/src/inbound-mail-foundation/tenant-destroy-hook.ts +14 -17
- package/packages/bundled-features/src/inbound-mail-foundation/watch-supervisor.ts +1 -1
- package/packages/bundled-features/src/inbound-provider-imap/byte-budget.ts +80 -0
- package/packages/bundled-features/src/inbound-provider-imap/changes.json +13 -0
- package/packages/bundled-features/src/inbound-provider-imap/connect-mailbox.ts +8 -4
- package/packages/bundled-features/src/inbound-provider-imap/connect-my-mailbox.ts +23 -6
- package/packages/bundled-features/src/inbound-provider-imap/connect-target-rate-limit.ts +46 -0
- package/packages/bundled-features/src/inbound-provider-imap/download-batch.ts +47 -10
- package/packages/bundled-features/src/inbound-provider-imap/feature.ts +7 -4
- package/packages/bundled-features/src/inbound-provider-imap/fetch-content.ts +43 -29
- package/packages/bundled-features/src/inbound-provider-imap/i18n.ts +2 -2
- package/packages/bundled-features/src/inbound-provider-imap/parse-message.ts +14 -0
- package/packages/bundled-features/src/inbound-provider-imap/reconnect-mailbox.ts +5 -4
- package/packages/bundled-features/src/inbound-provider-imap/send-mail.ts +39 -7
- package/packages/bundled-features/src/inbound-provider-imap/smtp-client.ts +19 -4
- package/packages/bundled-features/src/inbound-provider-imap/watch-mailbox.ts +8 -23
- package/packages/bundled-features/src/inbound-provider-inmemory/feature.ts +1 -1
- package/packages/bundled-features/src/jobs/events.ts +10 -0
- package/packages/bundled-features/src/jobs/feature.ts +2 -0
- package/packages/bundled-features/src/jobs/handlers/consumer.write.ts +41 -16
- package/packages/bundled-features/src/jobs/web/constants.ts +4 -0
- package/packages/bundled-features/src/mail-foundation/changes.json +6 -0
- package/packages/bundled-features/src/mail-transport-inmemory/feature.ts +1 -1
- package/packages/bundled-features/src/mail-transport-smtp/feature.ts +3 -2
- package/packages/bundled-features/src/managed-pages/changes.json +12 -0
- package/packages/bundled-features/src/managed-pages/handlers/branding.query.ts +1 -1
- package/packages/bundled-features/src/managed-pages/handlers/by-slug.query.ts +1 -1
- package/packages/bundled-features/src/managed-pages/handlers/by-tenant-published.query.ts +1 -1
- package/packages/bundled-features/src/managed-pages/render-page-body.ts +18 -10
- package/packages/bundled-features/src/managed-pages/screens/page-screens.ts +18 -38
- package/packages/bundled-features/src/managed-pages/table.ts +1 -0
- package/packages/bundled-features/src/managed-pages/web/client-plugin.tsx +8 -6
- package/packages/bundled-features/src/managed-pages/web/constants.ts +8 -1
- package/packages/bundled-features/src/managed-pages/web/i18n.ts +11 -3
- package/packages/bundled-features/src/managed-pages/web/markdown-to-document.ts +1 -1
- package/packages/bundled-features/src/managed-pages/web/page-edit-draft.ts +108 -0
- package/packages/bundled-features/src/managed-pages/web/page-edit-screen.tsx +204 -0
- package/packages/bundled-features/src/managed-pages/web/page-settings-rail.tsx +117 -0
- package/packages/bundled-features/src/notes-history-user-data/index.ts +8 -14
- package/packages/bundled-features/src/personal-access-tokens/boot-rules.ts +5 -0
- package/packages/bundled-features/src/personal-access-tokens/handlers/create.write.ts +0 -1
- package/packages/bundled-features/src/personal-access-tokens/scope-events-check.ts +31 -5
- package/packages/bundled-features/src/presence/changes.json +6 -0
- package/packages/bundled-features/src/presence/handlers/list.query.ts +28 -11
- package/packages/bundled-features/src/presence/room.ts +21 -7
- package/packages/bundled-features/src/presence/store.ts +79 -21
- package/packages/bundled-features/src/readiness/changes.json +25 -0
- package/packages/bundled-features/src/readiness/handlers/latest-summary.query.ts +11 -6
- package/packages/bundled-features/src/readiness/handlers/run-probes.write.ts +35 -5
- package/packages/bundled-features/src/readiness/handlers/run-tone.ts +3 -2
- package/packages/bundled-features/src/readiness/handlers/status.query.ts +15 -1
- package/packages/bundled-features/src/readiness/probe-context.ts +11 -10
- package/packages/bundled-features/src/readiness/screens.ts +4 -4
- package/packages/bundled-features/src/readiness/visible-results.ts +5 -3
- package/packages/bundled-features/src/renderer-foundation/api.ts +6 -13
- package/packages/bundled-features/src/renderer-foundation/types.ts +2 -2
- package/packages/bundled-features/src/secrets/changes.json +7 -0
- package/packages/bundled-features/src/secrets/db/queries/read.ts +18 -4
- package/packages/bundled-features/src/secrets/handlers/list.query.ts +8 -2
- package/packages/bundled-features/src/secrets/secret-scope.ts +2 -3
- package/packages/bundled-features/src/secrets/secrets-context.ts +6 -4
- package/packages/bundled-features/src/secrets/write-gate.ts +4 -2
- package/packages/bundled-features/src/seo/handlers/seo-config.query.ts +1 -1
- package/packages/bundled-features/src/shared/acknowledged-system-db.ts +20 -0
- package/packages/bundled-features/src/shared/assert-billing-live.ts +9 -2
- package/packages/bundled-features/src/shared/changes.json +12 -0
- package/packages/bundled-features/src/shared/hmac-signature.ts +4 -2
- package/packages/bundled-features/src/shared/index.ts +7 -1
- package/packages/bundled-features/src/shared/normalize-email.ts +3 -0
- package/packages/bundled-features/src/shared/parent-visibility.ts +25 -1
- package/packages/bundled-features/src/shared/password-hashing.ts +0 -1
- package/packages/bundled-features/src/shared/price-env-shape.ts +1 -4
- package/packages/bundled-features/src/shared/register-user-data-hooks.ts +29 -0
- package/packages/bundled-features/src/shared/require-bootstrap-extension.ts +26 -0
- package/packages/bundled-features/src/shared/send-best-effort.ts +29 -0
- package/packages/bundled-features/src/shared/stream-tenant-backfill.ts +22 -1
- package/packages/bundled-features/src/shared/stream-tenant-derived-state.ts +31 -1
- package/packages/bundled-features/src/step-dispatcher/changes.json +18 -0
- package/packages/bundled-features/src/step-dispatcher/constants.ts +13 -0
- package/packages/bundled-features/src/step-dispatcher/deliver-dispatch-request.ts +50 -2
- package/packages/bundled-features/src/step-dispatcher/feature.ts +42 -1
- package/packages/bundled-features/src/step-dispatcher/mail-runner.ts +0 -1
- package/packages/bundled-features/src/step-dispatcher/sweep-abandoned.ts +61 -0
- package/packages/bundled-features/src/subscription-mollie/changes.json +7 -0
- package/packages/bundled-features/src/subscription-mollie/plugin-methods.ts +5 -3
- package/packages/bundled-features/src/subscription-mollie/verify-webhook.ts +5 -5
- package/packages/bundled-features/src/subscription-paddle/backfill-checkout-ledger.ts +161 -0
- package/packages/bundled-features/src/subscription-paddle/changes.json +19 -0
- package/packages/bundled-features/src/subscription-paddle/checkout-config.query.ts +1 -1
- package/packages/bundled-features/src/subscription-paddle/checkout-methods.ts +2 -8
- package/packages/bundled-features/src/subscription-paddle/constants.ts +1 -2
- package/packages/bundled-features/src/subscription-paddle/feature.ts +26 -24
- package/packages/bundled-features/src/subscription-paddle/ledger-backfill-marker.ts +70 -0
- package/packages/bundled-features/src/subscription-paddle/plan-switch-methods.ts +2 -8
- package/packages/bundled-features/src/subscription-paddle/redeliver-legacy-checkout.ts +57 -0
- package/packages/bundled-features/src/subscription-paddle/runtime.ts +13 -24
- package/packages/bundled-features/src/subscription-paddle/subscription-state.ts +1 -0
- package/packages/bundled-features/src/subscription-paddle/webhook-events.ts +68 -21
- package/packages/bundled-features/src/subscription-stripe/changes.json +13 -0
- package/packages/bundled-features/src/subscription-stripe/feature.ts +5 -0
- package/packages/bundled-features/src/subscription-stripe/plugin-methods.ts +6 -6
- package/packages/bundled-features/src/subscription-stripe/runtime.ts +8 -7
- package/packages/bundled-features/src/subscription-stripe/verify-webhook.ts +38 -6
- package/packages/bundled-features/src/tags/aggregate-id.ts +0 -1
- package/packages/bundled-features/src/tags/web/tag-chip.tsx +4 -5
- package/packages/bundled-features/src/tags/web/tag-manager.tsx +2 -1
- package/packages/bundled-features/src/template-resolver/api.ts +6 -13
- package/packages/bundled-features/src/template-resolver/changes.json +48 -0
- package/packages/bundled-features/src/template-resolver/document-sanitizer.ts +25 -0
- package/packages/bundled-features/src/template-resolver/feature.ts +2 -0
- package/packages/bundled-features/src/template-resolver/handlers/body-preview.query.ts +41 -0
- package/packages/bundled-features/src/template-resolver/handlers/by-slug.query.ts +1 -1
- package/packages/bundled-features/src/template-resolver/handlers/by-tenant.query.ts +1 -1
- package/packages/bundled-features/src/template-resolver/handlers/collection-shared.ts +5 -11
- package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +3 -2
- package/packages/bundled-features/src/template-resolver/handlers/send-test.write.ts +37 -8
- package/packages/bundled-features/src/template-resolver/linked-resources.ts +2 -5
- package/packages/bundled-features/src/template-resolver/seeding.ts +107 -0
- package/packages/bundled-features/src/template-resolver/table.ts +1 -0
- package/packages/bundled-features/src/template-resolver/template-draft.ts +2 -1
- package/packages/bundled-features/src/template-resolver/template-preview.ts +14 -3
- package/packages/bundled-features/src/template-resolver/testing.ts +0 -2
- package/packages/bundled-features/src/template-resolver/web/client-plugin.tsx +3 -0
- package/packages/bundled-features/src/template-resolver/web/collection-entry-create-form.tsx +33 -33
- package/packages/bundled-features/src/template-resolver/web/constants.ts +7 -0
- package/packages/bundled-features/src/template-resolver/web/content-tree-provider.ts +0 -1
- package/packages/bundled-features/src/template-resolver/web/content-workbench.tsx +142 -0
- package/packages/bundled-features/src/template-resolver/web/document-insert-model.ts +3 -8
- package/packages/bundled-features/src/template-resolver/web/document-link-policy.ts +58 -0
- package/packages/bundled-features/src/template-resolver/web/document-schema.ts +11 -57
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-bubble.tsx +2 -4
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-context.ts +4 -5
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-editor.tsx +2 -2
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-helpers.ts +6 -3
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar-groups.tsx +2 -3
- package/packages/bundled-features/src/template-resolver/web/editor-handle.ts +1 -0
- package/packages/bundled-features/src/template-resolver/web/fill-document-variables.ts +24 -0
- package/packages/bundled-features/src/template-resolver/web/i18n.ts +14 -0
- package/packages/bundled-features/src/template-resolver/web/index.ts +3 -0
- package/packages/bundled-features/src/template-resolver/web/preview-targets.ts +25 -0
- package/packages/bundled-features/src/template-resolver/web/qualified-names.ts +1 -0
- package/packages/bundled-features/src/template-resolver/web/snippet-preview-renderer.tsx +24 -0
- package/packages/bundled-features/src/template-resolver/web/string-values.ts +7 -0
- package/packages/bundled-features/src/template-resolver/web/text-block-editor.tsx +38 -50
- package/packages/bundled-features/src/template-resolver/web/use-collection-entry-create.ts +7 -0
- package/packages/bundled-features/src/template-resolver/web/use-content-write.ts +1 -3
- package/packages/bundled-features/src/template-resolver/web/use-document-tiptap-model.ts +1 -2
- package/packages/bundled-features/src/template-resolver/web/use-text-block-editor.ts +28 -7
- package/packages/bundled-features/src/template-resolver/web/web-preview-renderer.tsx +132 -0
- package/packages/bundled-features/src/template-resolver-user-data/index.ts +11 -10
- package/packages/bundled-features/src/tenant/changes.json +6 -0
- package/packages/bundled-features/src/tenant/handlers/create.write.ts +7 -8
- package/packages/bundled-features/src/tenant/handlers/list.query.ts +7 -9
- package/packages/bundled-features/src/tenant/handlers/member-directory.query.ts +10 -4
- package/packages/bundled-features/src/tenant/handlers/toggle-enabled.write.ts +1 -1
- package/packages/bundled-features/src/tenant/invited-membership.ts +10 -1
- package/packages/bundled-features/src/tenant/seeding.ts +4 -2
- package/packages/bundled-features/src/tenant/stream-tenant-backfill.ts +5 -1
- package/packages/bundled-features/src/tenant/testing.ts +1 -1
- package/packages/bundled-features/src/tenant-inactivity/changes.json +6 -0
- package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +36 -17
- package/packages/bundled-features/src/tenant-inactivity/constants.ts +1 -2
- package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +7 -2
- package/packages/bundled-features/src/tenant-inactivity/state-store.ts +22 -2
- package/packages/bundled-features/src/tenant-lifecycle/changes.json +24 -0
- package/packages/bundled-features/src/tenant-lifecycle/constants.ts +4 -0
- package/packages/bundled-features/src/tenant-lifecycle/feature.ts +1 -0
- package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +43 -6
- package/packages/bundled-features/src/tenant-lifecycle/stages.ts +15 -2
- package/packages/bundled-features/src/tier-engine/aggregate-id.ts +0 -1
- package/packages/bundled-features/src/tier-engine/changes.json +6 -0
- package/packages/bundled-features/src/tier-engine/feature.ts +8 -2
- package/packages/bundled-features/src/user/changes.json +6 -0
- package/packages/bundled-features/src/user/db/queries/stream-tenant-backfill.ts +2 -1
- package/packages/bundled-features/src/user/handlers/me.query.ts +3 -1
- package/packages/bundled-features/src/user/index.ts +1 -0
- package/packages/bundled-features/src/user/resolve-verified-user-email.ts +17 -0
- package/packages/bundled-features/src/user-data-rights/db/queries/export-jobs.ts +0 -1
- package/packages/bundled-features/src/user-data-rights/feature.ts +1 -0
- package/packages/bundled-features/src/user-data-rights/handlers/confirm-deletion-by-token.write.ts +1 -1
- package/packages/bundled-features/src/user-data-rights/handlers/download-by-token.query.ts +1 -1
- package/packages/bundled-features/src/user-data-rights/handlers/request-deletion-by-email.write.ts +1 -1
- package/packages/bundled-features/src/user-data-rights/run-export-jobs.ts +0 -2
- package/packages/bundled-features/src/user-data-rights/run-forget-cleanup.ts +3 -3
- package/packages/bundled-features/src/user-data-rights/schema/download-attempt.ts +3 -2
- package/packages/bundled-features/src/user-data-rights/web/confirm-deletion-screen.tsx +1 -1
- package/packages/bundled-features/src/user-data-rights/web/privacy-center-screen.tsx +1 -1
- package/packages/bundled-features/src/user-data-rights/web/request-deletion-screen.tsx +1 -1
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/api-token.userdata-hook.ts +5 -5
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/hard-delete-own-rows-hook.ts +17 -0
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/in-app-message.userdata-hook.ts +5 -5
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/job-run.userdata-hook.ts +2 -1
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/user-session.userdata-hook.ts +5 -5
- package/packages/bundled-features/src/user-profile/handlers/change-email.write.ts +0 -1
- package/packages/bundled-features/src/waitlist/changes.json +6 -0
- package/packages/bundled-features/src/waitlist/handlers/reject.write.ts +1 -1
- package/packages/bundled-features/src/waitlist/handlers/submit.write.ts +5 -29
- package/packages/bundled-features/src/waitlist/import.ts +2 -1
- package/packages/bundled-features/src/waitlist/lib.ts +2 -11
- package/packages/bundled-features/src/waitlist/link-on-signup.ts +2 -2
- package/packages/bundled-features/src/waitlist/user-data-hooks.ts +6 -19
- package/packages/bundled-features/src/workflow-runner/aggregate-id.ts +0 -1
- package/packages/bundled-features/src/workflow-runner/changes.json +6 -0
- package/packages/bundled-features/src/workflow-runner/event-trigger.ts +6 -2
- package/packages/bundled-features/src/workflow-runner/feature.ts +1 -5
- package/packages/bundled-features/src/workflow-runner/handlers/resume-run.write.ts +7 -4
- package/packages/bundled-features/src/workflow-runner/runner.ts +2 -0
- package/samples/apps/admin-console/src/app/shell.tsx +1 -0
- package/samples/apps/showcase/src/features/demos/web/pages/dialog.tsx +0 -1
- package/samples/apps/showcase/src/features/demos/web/pages/layout.tsx +1 -1
- package/samples/apps/showcase/src/features/demos/web/pages/sidebar-panel.tsx +0 -1
- package/samples/apps/styleguide/src/features/gallery/web/Gallery.tsx +1 -4
- package/samples/apps/ui-walkthrough/src/features/subscription-plans/feature.ts +6 -2
- package/samples/apps/use-all-bundled/e2e-billing-gallery/gallery-features.ts +12 -14
- package/samples/apps/use-all-bundled/feature-manifest.json +60 -29
- package/samples/apps/use-all-bundled/playwright.billing-docs.config.ts +1 -1
- package/samples/apps/use-all-bundled/playwright.config.ts +1 -0
- package/samples/apps/use-all-bundled/src/app/seed.ts +1 -1
- package/samples/apps/use-all-bundled/src/run-config.ts +2 -1
- package/samples/recipes/auth-mfa/src/web/confirmation-code-step.tsx +32 -10
- package/samples/recipes/chat-channels/README.md +2 -0
- package/samples/recipes/crypto-shredding-hr/README.md +11 -0
- package/samples/recipes/crypto-shredding-hr/src/feature.ts +27 -0
- package/samples/recipes/currencies-global/src/entities/currency.ts +1 -0
- package/samples/recipes/managed-pages/README.md +5 -1
- package/samples/recipes/managed-pages/package.json +3 -2
- package/samples/recipes/managed-pages/src/web/branded-preview.tsx +21 -0
- package/samples/recipes/managed-pages/tsconfig.json +8 -0
- package/samples/recipes/pwa-shell/README.md +52 -0
- package/samples/recipes/pwa-shell/bin/server.ts +12 -0
- package/samples/recipes/pwa-shell/package.json +13 -0
- package/samples/recipes/pwa-shell/src/app.ts +34 -0
- package/samples/recipes/rate-limiting/README.md +3 -3
- package/samples/recipes/record-detail-layout/README.md +33 -0
- package/samples/recipes/record-detail-layout/src/feature.ts +556 -44
- package/samples/recipes/record-detail-layout/src/order-board.ts +529 -0
- package/packages/bundled-features/src/managed-pages/web/page-body-section.tsx +0 -72
- package/packages/bundled-features/src/subscription-paddle/tenant-binding.ts +0 -34
- package/packages/bundled-features/src/template-resolver/web/content-field.tsx +0 -61
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { DbRunner } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import {
|
|
3
|
+
type Registry,
|
|
4
|
+
STEP_DISPATCH_AGGREGATE_TYPE,
|
|
5
|
+
STEP_DISPATCH_FAILED_TYPE,
|
|
6
|
+
STEP_DISPATCH_REQUESTED_TYPE,
|
|
7
|
+
STEP_DISPATCHED_TYPE,
|
|
8
|
+
} from "@cosmicdrift/kumiko-framework/engine";
|
|
9
|
+
import { selectOpenStreamsStartedBefore } from "@cosmicdrift/kumiko-framework/event-store";
|
|
10
|
+
import { createMultiStreamApplyContext } from "@cosmicdrift/kumiko-framework/pipeline";
|
|
11
|
+
import { SYSTEM_USER_ID } from "@cosmicdrift/kumiko-types/identifiers";
|
|
12
|
+
import { STEP_DISPATCHER_FEATURE, SWEEP_ABANDONED_BATCH_SIZE } from "./constants.ts";
|
|
13
|
+
import { closeAbandonedDispatch } from "./deliver-dispatch-request.ts";
|
|
14
|
+
|
|
15
|
+
export type SweepAbandonedArgs = {
|
|
16
|
+
readonly db: DbRunner;
|
|
17
|
+
readonly registry: Registry;
|
|
18
|
+
readonly startedBeforeIso: string;
|
|
19
|
+
// A stream whose deliver job is still queued or running is alive, not abandoned.
|
|
20
|
+
readonly isDeliverJobPending: (aggregateId: string) => Promise<boolean>;
|
|
21
|
+
readonly onCloseFailure: (aggregateId: string, errorName: string) => void;
|
|
22
|
+
readonly batchSize?: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Pages by id until a short page: a stream that fails permanently stays open and would otherwise
|
|
26
|
+
// occupy the front of every run, starving the streams behind it.
|
|
27
|
+
export async function sweepAbandonedDispatches(args: SweepAbandonedArgs): Promise<void> {
|
|
28
|
+
const batchSize = args.batchSize ?? SWEEP_ABANDONED_BATCH_SIZE;
|
|
29
|
+
let afterId: string | undefined;
|
|
30
|
+
for (;;) {
|
|
31
|
+
const page = await selectOpenStreamsStartedBefore(args.db, {
|
|
32
|
+
aggregateType: STEP_DISPATCH_AGGREGATE_TYPE,
|
|
33
|
+
startedType: STEP_DISPATCH_REQUESTED_TYPE,
|
|
34
|
+
closingTypes: [STEP_DISPATCHED_TYPE, STEP_DISPATCH_FAILED_TYPE],
|
|
35
|
+
startedBeforeIso: args.startedBeforeIso,
|
|
36
|
+
limit: batchSize,
|
|
37
|
+
...(afterId !== undefined && { afterId }),
|
|
38
|
+
});
|
|
39
|
+
for (const { tenantId, aggregateId } of page) {
|
|
40
|
+
const applyContext = createMultiStreamApplyContext({
|
|
41
|
+
registry: args.registry,
|
|
42
|
+
db: args.db,
|
|
43
|
+
tenantId,
|
|
44
|
+
userId: SYSTEM_USER_ID,
|
|
45
|
+
callerFeature: STEP_DISPATCHER_FEATURE,
|
|
46
|
+
});
|
|
47
|
+
try {
|
|
48
|
+
// skip: the next run checks the stream again
|
|
49
|
+
if (await args.isDeliverJobPending(aggregateId)) continue;
|
|
50
|
+
await closeAbandonedDispatch(applyContext, aggregateId);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
// One broken stream must not keep the others open; the next run retries it.
|
|
53
|
+
args.onCloseFailure(aggregateId, err instanceof Error ? err.name : "unknown");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const last = page.at(-1);
|
|
57
|
+
// skip: a short page is the last one
|
|
58
|
+
if (page.length < batchSize || last === undefined) return;
|
|
59
|
+
afterId = last.id;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.414.0",
|
|
4
|
+
"type": "breaking",
|
|
5
|
+
"title": "Mollie first payments are matched by payment id, consentId metadata is gone",
|
|
6
|
+
"detail": "`createCheckoutSession` returns the first payment's id as `providerCheckoutId`; the created event of the subscription made from that mandate payment carries it. Payment and subscription metadata no longer hold a consentId.",
|
|
7
|
+
"migration": "First payments created before the upgrade are not in the ledger and their webhook is ignored; let open mandate checkouts finish first."
|
|
8
|
+
},
|
|
2
9
|
{
|
|
3
10
|
"version": "0.338.0",
|
|
4
11
|
"type": "improvement",
|
|
@@ -40,7 +40,10 @@ export function createMollieCheckoutSession(
|
|
|
40
40
|
priceToConfig: Readonly<Record<string, MolliePriceConfig>>,
|
|
41
41
|
appWebhookUrl: string,
|
|
42
42
|
) {
|
|
43
|
-
return async (
|
|
43
|
+
return async (
|
|
44
|
+
_ctx: HandlerContext,
|
|
45
|
+
options: MollieCheckoutOptions,
|
|
46
|
+
): Promise<{ url: string; providerCheckoutId: string }> => {
|
|
44
47
|
const priceCfg = priceToConfig[options.priceId];
|
|
45
48
|
if (!priceCfg) {
|
|
46
49
|
throw new Error(`subscription-mollie: priceId "${options.priceId}" not in priceToConfig-Map`);
|
|
@@ -81,7 +84,6 @@ export function createMollieCheckoutSession(
|
|
|
81
84
|
metadata: {
|
|
82
85
|
tenantId: options.tenantId,
|
|
83
86
|
priceId: options.priceId,
|
|
84
|
-
...(options.consentId && { consentId: options.consentId }),
|
|
85
87
|
},
|
|
86
88
|
}) as Promise<Payment>)) satisfies Payment; // @cast-boundary engine-bridge
|
|
87
89
|
|
|
@@ -93,6 +95,6 @@ export function createMollieCheckoutSession(
|
|
|
93
95
|
`subscription-mollie: payment.getCheckoutUrl() returned null (sequenceType=${sequenceType})${mandateHint}`,
|
|
94
96
|
);
|
|
95
97
|
}
|
|
96
|
-
return { url: checkoutHref };
|
|
98
|
+
return { url: checkoutHref, providerCheckoutId: payment.id };
|
|
97
99
|
};
|
|
98
100
|
}
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
// with a subscription id.
|
|
16
16
|
|
|
17
17
|
import {
|
|
18
|
-
parseProviderConsentId,
|
|
19
18
|
type SubscriptionEvent,
|
|
20
19
|
type SubscriptionEventType,
|
|
21
20
|
SubscriptionEventTypes,
|
|
@@ -129,13 +128,15 @@ export function verifyAndParseMollieWebhook(
|
|
|
129
128
|
}
|
|
130
129
|
const currentPeriodEnd = mollieDateStringToInstantIso(periodEndSource);
|
|
131
130
|
|
|
132
|
-
|
|
131
|
+
// The first payment is the checkout the foundation ledgered at createCheckoutSession.
|
|
132
|
+
const providerCheckoutId =
|
|
133
|
+
triggerPayment?.sequenceType === "first" ? triggerPayment.id : undefined;
|
|
133
134
|
return {
|
|
134
135
|
providerEventId: id,
|
|
135
136
|
providerName: MOLLIE_PROVIDER_NAME,
|
|
136
137
|
type,
|
|
137
138
|
tenantId,
|
|
138
|
-
...(
|
|
139
|
+
...(providerCheckoutId !== undefined && { providerCheckoutId }),
|
|
139
140
|
providerCustomerId: subscription.customerId,
|
|
140
141
|
providerSubscriptionId: subscription.id,
|
|
141
142
|
status,
|
|
@@ -162,7 +163,6 @@ async function ensureSubscriptionForMandate(
|
|
|
162
163
|
const paymentMetadata = (payment.metadata as Record<string, string> | null) ?? {}; // @cast-boundary engine-bridge
|
|
163
164
|
const tenantId = paymentMetadata["tenantId"];
|
|
164
165
|
const priceId = paymentMetadata["priceId"];
|
|
165
|
-
const consentId = parseProviderConsentId(paymentMetadata["consentId"]);
|
|
166
166
|
if (!tenantId || !priceId) return null;
|
|
167
167
|
const priceCfg = options.priceToConfig[priceId];
|
|
168
168
|
if (!priceCfg) return null;
|
|
@@ -183,7 +183,7 @@ async function ensureSubscriptionForMandate(
|
|
|
183
183
|
amount: { currency: priceCfg.amountCurrency, value: priceCfg.amountValue },
|
|
184
184
|
interval: priceCfg.interval,
|
|
185
185
|
description: priceCfg.description,
|
|
186
|
-
metadata: { tenantId, priceId
|
|
186
|
+
metadata: { tenantId, priceId },
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
189
|
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Takes over Paddle checkouts that were opened before the checkout ledger
|
|
2
|
+
// existed: their custom_data still carries the old tenantBinding. Once the
|
|
3
|
+
// first sweep is done the job keeps sweeping for an hour (checkouts opened by
|
|
4
|
+
// the previous release can still be paid), then does nothing.
|
|
5
|
+
// The tenant in custom_data is unverified: the key that signed the binding no longer exists.
|
|
6
|
+
// Only origin "api" and the one hour window bound that; losing a paid checkout would be worse.
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
parseProviderConsentId,
|
|
10
|
+
SubscriptionFoundationHandlers,
|
|
11
|
+
} from "@cosmicdrift/kumiko-bundled-features/billing-foundation";
|
|
12
|
+
import {
|
|
13
|
+
createSystemUser,
|
|
14
|
+
type JobContext,
|
|
15
|
+
parseTenantId,
|
|
16
|
+
} from "@cosmicdrift/kumiko-framework/engine";
|
|
17
|
+
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
18
|
+
import * as z from "zod";
|
|
19
|
+
import { PADDLE_PROVIDER_NAME } from "./constants.ts";
|
|
20
|
+
import {
|
|
21
|
+
LEDGER_BACKFILL_MARKER_HANDLER_QN,
|
|
22
|
+
type LedgerBackfillMarkerResult,
|
|
23
|
+
} from "./ledger-backfill-marker.ts";
|
|
24
|
+
import type { PaddleCallSource, PaddleCtxRuntime } from "./runtime.ts";
|
|
25
|
+
import { tenantIdOf } from "./webhook-events.ts";
|
|
26
|
+
|
|
27
|
+
const TAKEOVER_WINDOW_MS = 60 * 60 * 1000;
|
|
28
|
+
const PAGE_SIZE = "200";
|
|
29
|
+
const MAX_PAGES = 100;
|
|
30
|
+
// A checkout that completed between the deploy and the first sweep is no longer draft/ready,
|
|
31
|
+
// but its webhook is still pending, so completed ones are listed too, for a week back.
|
|
32
|
+
const LISTED_STATUSES = "draft,ready,billed,paid,completed";
|
|
33
|
+
const LOOKBACK_DAYS = 7;
|
|
34
|
+
|
|
35
|
+
const transactionListSchema = z.object({
|
|
36
|
+
data: z.array(
|
|
37
|
+
z.object({
|
|
38
|
+
id: z.string().min(1),
|
|
39
|
+
custom_data: z.record(z.string(), z.unknown()).nullish(),
|
|
40
|
+
items: z.array(z.object({ price: z.object({ id: z.string().min(1) }) })),
|
|
41
|
+
}),
|
|
42
|
+
),
|
|
43
|
+
meta: z
|
|
44
|
+
.object({ pagination: z.object({ has_more: z.boolean().optional() }).optional() })
|
|
45
|
+
.optional(),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
type ListedTransaction = z.infer<typeof transactionListSchema>["data"][number];
|
|
49
|
+
|
|
50
|
+
export type BackfillDeps = {
|
|
51
|
+
readonly runtime: PaddleCtxRuntime;
|
|
52
|
+
readonly priceToTier: Readonly<Record<string, string>>;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function isLegacyCheckout(transaction: ListedTransaction): boolean {
|
|
56
|
+
return typeof transaction.custom_data?.["tenantBinding"] === "string";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function paddleCallSourceOf(ctx: JobContext): PaddleCallSource {
|
|
60
|
+
return {
|
|
61
|
+
services: ctx.services,
|
|
62
|
+
user: ctx.systemUser,
|
|
63
|
+
...(ctx.config && { config: ctx.config }),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function readMarker(
|
|
68
|
+
ctx: JobContext,
|
|
69
|
+
markCompleted: boolean,
|
|
70
|
+
): Promise<LedgerBackfillMarkerResult> {
|
|
71
|
+
const result = await ctx.dispatch.write(LEDGER_BACKFILL_MARKER_HANDLER_QN, { markCompleted });
|
|
72
|
+
if (!result.isSuccess) {
|
|
73
|
+
throw new Error(`backfill-checkout-ledger: marker handler failed (${result.error.code})`);
|
|
74
|
+
}
|
|
75
|
+
return result.data as LedgerBackfillMarkerResult; // @cast-boundary engine-payload
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function isTakeoverWindowOver(completedAt: string, now: Temporal.Instant): boolean {
|
|
79
|
+
const elapsed = now.epochMilliseconds - Temporal.Instant.from(completedAt).epochMilliseconds;
|
|
80
|
+
return elapsed >= TAKEOVER_WINDOW_MS;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function listOpenApiTransactions(
|
|
84
|
+
ctx: JobContext,
|
|
85
|
+
runtime: PaddleCtxRuntime,
|
|
86
|
+
after: string | undefined,
|
|
87
|
+
createdSince: string,
|
|
88
|
+
) {
|
|
89
|
+
const raw = await runtime.call(paddleCallSourceOf(ctx), {
|
|
90
|
+
method: "GET",
|
|
91
|
+
path: "/transactions",
|
|
92
|
+
query: {
|
|
93
|
+
status: LISTED_STATUSES,
|
|
94
|
+
origin: "api",
|
|
95
|
+
"created_at[GTE]": createdSince,
|
|
96
|
+
order_by: "id[ASC]",
|
|
97
|
+
per_page: PAGE_SIZE,
|
|
98
|
+
...(after !== undefined && { after }),
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
return transactionListSchema.parse(raw);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function ledgerTransaction(
|
|
105
|
+
ctx: JobContext,
|
|
106
|
+
priceToTier: BackfillDeps["priceToTier"],
|
|
107
|
+
transaction: ListedTransaction,
|
|
108
|
+
): Promise<void> {
|
|
109
|
+
const tenantId = parseTenantId(tenantIdOf(transaction.custom_data));
|
|
110
|
+
const priceId = transaction.items[0]?.price.id;
|
|
111
|
+
// skip: a transaction without tenant or price cannot be ledgered
|
|
112
|
+
if (tenantId === null || !priceId) return;
|
|
113
|
+
const consentId = parseProviderConsentId(transaction.custom_data?.["consentId"]);
|
|
114
|
+
const result = await ctx.dispatch.writeAs(
|
|
115
|
+
createSystemUser(tenantId, ["SystemAdmin"]),
|
|
116
|
+
SubscriptionFoundationHandlers.recordCheckoutOpened,
|
|
117
|
+
{
|
|
118
|
+
providerName: PADDLE_PROVIDER_NAME,
|
|
119
|
+
providerCheckoutId: transaction.id,
|
|
120
|
+
priceId,
|
|
121
|
+
mode: priceId in priceToTier ? "subscription" : "payment",
|
|
122
|
+
...(consentId !== undefined && { consentId }),
|
|
123
|
+
},
|
|
124
|
+
);
|
|
125
|
+
if (!result.isSuccess) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
`backfill-checkout-ledger: ledgering ${transaction.id} failed (${result.error.code})`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export async function runBackfillCheckoutLedger(
|
|
133
|
+
ctx: JobContext,
|
|
134
|
+
deps: BackfillDeps,
|
|
135
|
+
): Promise<void> {
|
|
136
|
+
// skip: without an API key there is no Paddle account to sweep
|
|
137
|
+
if (!(await deps.runtime.hasApiKey(paddleCallSourceOf(ctx)))) return;
|
|
138
|
+
const marker = await readMarker(ctx, false);
|
|
139
|
+
if (marker.completedAt !== null && isTakeoverWindowOver(marker.completedAt, ctx.tz.now())) {
|
|
140
|
+
// skip: the takeover window is over
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const createdSince = ctx.tz
|
|
145
|
+
.now()
|
|
146
|
+
.subtract({ hours: LOOKBACK_DAYS * 24 })
|
|
147
|
+
.toString();
|
|
148
|
+
let after: string | undefined;
|
|
149
|
+
for (let page = 0; page < MAX_PAGES; page++) {
|
|
150
|
+
const listed = await listOpenApiTransactions(ctx, deps.runtime, after, createdSince);
|
|
151
|
+
for (const transaction of listed.data) {
|
|
152
|
+
if (isLegacyCheckout(transaction))
|
|
153
|
+
await ledgerTransaction(ctx, deps.priceToTier, transaction);
|
|
154
|
+
}
|
|
155
|
+
const last = listed.data.at(-1);
|
|
156
|
+
if (listed.meta?.pagination?.has_more !== true || last === undefined) break;
|
|
157
|
+
after = last.id;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (marker.completedAt === null) await readMarker(ctx, true);
|
|
161
|
+
}
|
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.415.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "unreadable ledger backfill marker no longer causes endless 503",
|
|
6
|
+
"detail": "shouldRedeliverLegacyCheckout answers 200 and logs when the marker dispatch fails, because custom_data.tenantBinding is client-settable."
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"version": "0.414.0",
|
|
10
|
+
"type": "breaking",
|
|
11
|
+
"title": "Paddle checkouts are bound by the checkout ledger, the tenant binding key is gone",
|
|
12
|
+
"detail": "The HMAC `tenantBinding` in custom_data and the PADDLE_TENANT_BINDING_KEY / `tenant-binding-key` setting are removed; a webhook is accepted when its transaction id is in the checkout ledger. The new job `backfill-checkout-ledger` (cron every 5 minutes, no-op without an API key) lists open Paddle transactions created through the API, ledgers the ones that still carry a `tenantBinding`, keeps sweeping for one hour after its first completed sweep and then does nothing. The sweep also lists billed, paid and completed transactions of the last 7 days, and while the takeover window is open (no completed sweep yet, or one younger than an hour) a webhook of a legacy checkout (custom_data still has `tenantBinding`) that is not in the ledger yet answers 503, so Paddle redelivers it after the sweep ledgered the checkout.",
|
|
13
|
+
"migration": "Remove PADDLE_TENANT_BINDING_KEY from the environment and the `subscription-paddle:config:tenant-binding-key` value from the secrets; nothing reads them any more. Checkouts that customers opened before the upgrade are taken over by the `backfill-checkout-ledger` job within about five minutes, so no manual step is needed. The job needs a worker that runs the system-identity jobs."
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"version": "0.414.0",
|
|
17
|
+
"type": "fix",
|
|
18
|
+
"title": "paddle webhook drops one-off payments for prices outside oneOffPriceIds",
|
|
19
|
+
"detail": "`transaction.completed` became a payment event for any price with a valid tenant binding. Paddle.js can open a checkout in the browser with arbitrary customData and price, so the server-side `oneOffPriceIds` / `authorizeOneOffCheckout` gate was bypassable. `PaddleWebhookOptions` now takes `oneOffPriceIds` (the feature passes `options.oneOffPriceIds ?? []`) and an event for any other price is dropped with a warning carrying only the provider event id and price id. Apps selling one-off credits must list those prices in `oneOffPriceIds`."
|
|
20
|
+
},
|
|
2
21
|
{
|
|
3
22
|
"version": "0.394.0",
|
|
4
23
|
"type": "improvement",
|
|
@@ -8,7 +8,7 @@ export function makeCheckoutConfigQuery(readCheckoutConfig: PaddleRuntimes["read
|
|
|
8
8
|
return defineQueryHandler({
|
|
9
9
|
name: "checkout-config",
|
|
10
10
|
schema: z.object({}),
|
|
11
|
-
access: { roles: ["anonymous"
|
|
11
|
+
access: { roles: ["anonymous"], anySignedIn: true },
|
|
12
12
|
rateLimit: { per: "ip+handler", limit: 60, windowSeconds: 60 },
|
|
13
13
|
description:
|
|
14
14
|
"Answers the public Paddle.js client token and the Paddle environment for the checkout page; the client token is public by design and no other config leaves this handler.",
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import { SubscriptionCancelTimings } from "@cosmicdrift/kumiko-bundled-features/billing-foundation";
|
|
5
5
|
import * as z from "zod";
|
|
6
6
|
import type { PaddleCtxRuntime, PaddlePluginMethod } from "./runtime.ts";
|
|
7
|
-
import { signTenantBinding } from "./tenant-binding.ts";
|
|
8
7
|
|
|
9
8
|
export function paddleSubscriptionPath(providerSubscriptionId: string): string {
|
|
10
9
|
return `/subscriptions/${encodeURIComponent(providerSubscriptionId)}`;
|
|
@@ -28,7 +27,6 @@ export function createPaddleCheckoutSession(
|
|
|
28
27
|
return async (ctx, options) => {
|
|
29
28
|
// No Paddle transaction may be created while billing is not live.
|
|
30
29
|
await runtime.assertBillingLive(ctx);
|
|
31
|
-
const bindingKey = await runtime.tenantBindingKey(ctx);
|
|
32
30
|
// No `checkout.url` in the body: Paddle rejects unapproved domains and otherwise
|
|
33
31
|
// answers with the dashboard's Default Payment Link plus `?_ptxn=`.
|
|
34
32
|
const { data } = checkoutResponseSchema.parse(
|
|
@@ -38,11 +36,7 @@ export function createPaddleCheckoutSession(
|
|
|
38
36
|
body: {
|
|
39
37
|
items: [{ price_id: options.priceId, quantity: 1 }],
|
|
40
38
|
...(options.providerCustomerId && { customer_id: options.providerCustomerId }),
|
|
41
|
-
custom_data: {
|
|
42
|
-
tenantId: options.tenantId,
|
|
43
|
-
tenantBinding: signTenantBinding(bindingKey, options.tenantId),
|
|
44
|
-
...(options.consentId && { consentId: options.consentId }),
|
|
45
|
-
},
|
|
39
|
+
custom_data: { tenantId: options.tenantId },
|
|
46
40
|
},
|
|
47
41
|
}),
|
|
48
42
|
);
|
|
@@ -53,7 +47,7 @@ export function createPaddleCheckoutSession(
|
|
|
53
47
|
url.searchParams.set("success", relativeTarget(options.successUrl));
|
|
54
48
|
url.searchParams.set("cancel", relativeTarget(options.cancelUrl));
|
|
55
49
|
if (options.locale) url.searchParams.set("locale", options.locale);
|
|
56
|
-
return { url: url.href };
|
|
50
|
+
return { url: url.href, providerCheckoutId: data.id };
|
|
57
51
|
};
|
|
58
52
|
}
|
|
59
53
|
|
|
@@ -8,10 +8,9 @@ export const PADDLE_PROVIDER_NAME = "paddle" as const;
|
|
|
8
8
|
export const PADDLE_CHECKOUT_PATH = "/billing/paddle-checkout" as const;
|
|
9
9
|
|
|
10
10
|
// Config-key short-names, qualified to `subscription-paddle:config:<name>` at
|
|
11
|
-
// registry-build. api-key
|
|
11
|
+
// registry-build. api-key and webhook-secret are backing:"secrets".
|
|
12
12
|
export const PADDLE_API_KEY_CONFIG = "api-key" as const;
|
|
13
13
|
export const PADDLE_WEBHOOK_SECRET_CONFIG = "webhook-secret" as const;
|
|
14
|
-
export const PADDLE_TENANT_BINDING_KEY_CONFIG = "tenant-binding-key" as const;
|
|
15
14
|
export const PADDLE_CLIENT_TOKEN_CONFIG = "client-token" as const;
|
|
16
15
|
export const PADDLE_ENVIRONMENT_CONFIG = "environment" as const;
|
|
17
16
|
export const PADDLE_BILLING_LIVE_CONFIG = "billingLive" as const;
|
|
@@ -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` /
|
|
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
|
|
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
|
|
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
|
};
|