@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.
- 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/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 +10 -12
- 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/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 +37 -0
- package/packages/bundled-features/src/billing-foundation/checkout-core.ts +8 -1
- package/packages/bundled-features/src/billing-foundation/checkout-ledger.ts +59 -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 +49 -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 +7 -1
- package/packages/bundled-features/src/billing-foundation/handlers/process-event.write.ts +124 -10
- package/packages/bundled-features/src/billing-foundation/handlers/process-payment-event.write.ts +33 -9
- 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 +7 -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 +8 -0
- package/packages/bundled-features/src/channel-whatsapp/constants.ts +46 -0
- package/packages/bundled-features/src/channel-whatsapp/events.ts +93 -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 +189 -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 +226 -0
- package/packages/bundled-features/src/channel-whatsapp/webhook-routes.ts +185 -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 +18 -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 +4 -7
- 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 +6 -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 +45 -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/report-ingest-progress.ts +32 -14
- package/packages/bundled-features/src/documents/aggregate-id.ts +0 -2
- package/packages/bundled-features/src/documents/changes.json +18 -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 +28 -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/helpdesk/changes.json +62 -0
- package/packages/bundled-features/src/helpdesk/entity.ts +4 -1
- package/packages/bundled-features/src/helpdesk/feature.ts +41 -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 +2 -9
- package/packages/bundled-features/src/helpdesk/handlers/report.write.ts +2 -9
- package/packages/bundled-features/src/helpdesk/handlers/submit.write.ts +3 -11
- 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 +185 -0
- package/packages/bundled-features/src/helpdesk/legacy-contact-user-data.ts +84 -0
- package/packages/bundled-features/src/helpdesk/lib.ts +47 -34
- 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 +5 -1
- package/packages/bundled-features/src/inbound-mail-foundation/aggregate-id.ts +0 -2
- package/packages/bundled-features/src/inbound-mail-foundation/changes.json +48 -0
- package/packages/bundled-features/src/inbound-mail-foundation/constants.ts +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/content-refetch.ts +15 -1
- package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +64 -15
- package/packages/bundled-features/src/inbound-mail-foundation/events.ts +15 -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 +21 -8
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/forget-message.write.ts +73 -0
- 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/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/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 +198 -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 +6 -0
- package/packages/bundled-features/src/shared/index.ts +6 -1
- 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 +19 -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 +12 -0
- package/packages/bundled-features/src/step-dispatcher/constants.ts +13 -0
- package/packages/bundled-features/src/step-dispatcher/deliver-dispatch-request.ts +47 -2
- package/packages/bundled-features/src/step-dispatcher/feature.ts +28 -1
- package/packages/bundled-features/src/step-dispatcher/mail-runner.ts +0 -1
- package/packages/bundled-features/src/step-dispatcher/sweep-abandoned.ts +57 -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 +159 -0
- package/packages/bundled-features/src/subscription-paddle/changes.json +13 -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 +36 -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 +7 -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 +24 -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 +36 -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 +77 -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 +126 -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/check-inactive-tenants.ts +4 -3
- package/packages/bundled-features/src/tenant-inactivity/constants.ts +1 -2
- package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +1 -2
- package/packages/bundled-features/src/tenant-inactivity/state-store.ts +10 -1
- package/packages/bundled-features/src/tenant-lifecycle/changes.json +18 -0
- package/packages/bundled-features/src/tenant-lifecycle/constants.ts +4 -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/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/submit.write.ts +4 -28
- package/packages/bundled-features/src/waitlist/lib.ts +2 -7
- 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/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 +5 -4
- package/packages/bundled-features/src/workflow-runner/runner.ts +2 -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/currencies-global/src/entities/currency.ts +1 -0
- package/samples/recipes/helpdesk/README.md +9 -5
- package/samples/recipes/helpdesk/src/feature.ts +6 -3
- 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 +525 -44
- package/samples/recipes/record-detail-layout/src/order-board.ts +521 -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
package/packages/bundled-features/src/billing-foundation/consumer-protection/consent-gate.ts
CHANGED
|
@@ -94,6 +94,7 @@ export async function prepareConsent(
|
|
|
94
94
|
options: ConsumerProtectionOptions,
|
|
95
95
|
consent: ConsentPayload | undefined,
|
|
96
96
|
mode: CheckoutMode,
|
|
97
|
+
providerName?: string,
|
|
97
98
|
): Promise<PreparedConsent> {
|
|
98
99
|
const documentsRequired = options.documentsAcknowledgement === true;
|
|
99
100
|
if (
|
|
@@ -107,7 +108,7 @@ export async function prepareConsent(
|
|
|
107
108
|
});
|
|
108
109
|
}
|
|
109
110
|
const locale = resolveConsentLocale(consent.locale);
|
|
110
|
-
const documentsText = documentsAcknowledgementTextFor(options, locale);
|
|
111
|
+
const documentsText = documentsAcknowledgementTextFor(options, locale, providerName);
|
|
111
112
|
if (consent.consentTextVersion !== consentTextVersion(locale, documentsText)) {
|
|
112
113
|
throw new UnprocessableError("consent_text_outdated", {
|
|
113
114
|
i18nKey: "billing-foundation.errors.consentTextOutdated",
|
package/packages/bundled-features/src/billing-foundation/consumer-protection/consent-text.ts
CHANGED
|
@@ -60,15 +60,62 @@ export function legalLinksPerLocale(
|
|
|
60
60
|
return isLegalLinkSet(legalLinks) ? { de: legalLinks, en: legalLinks } : legalLinks;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
function providerRefundLink(
|
|
64
|
+
options: ConsumerProtectionOptions,
|
|
65
|
+
providerName: string | undefined,
|
|
66
|
+
locale: ConsentLocale,
|
|
67
|
+
): string | undefined {
|
|
68
|
+
const own = providerName === undefined ? undefined : options.providerTexts?.[providerName];
|
|
69
|
+
if (own?.refundLink === undefined) return undefined;
|
|
70
|
+
return typeof own.refundLink === "string" ? own.refundLink : own.refundLink[locale];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function hasProviderRefundLink(
|
|
74
|
+
options: ConsumerProtectionOptions,
|
|
75
|
+
providerName: string | undefined,
|
|
76
|
+
): boolean {
|
|
77
|
+
return (
|
|
78
|
+
providerName !== undefined && options.providerTexts?.[providerName]?.refundLink !== undefined
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The provider's own refund link, else the global `legalLinks.refund`. */
|
|
83
|
+
export function refundLinkFor(
|
|
84
|
+
options: ConsumerProtectionOptions,
|
|
85
|
+
locale: ConsentLocale,
|
|
86
|
+
providerName?: string,
|
|
87
|
+
): string | undefined {
|
|
88
|
+
return (
|
|
89
|
+
providerRefundLink(options, providerName, locale) ??
|
|
90
|
+
legalLinksPerLocale(options.legalLinks)[locale].refund
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function legalLinksFor(
|
|
95
|
+
options: ConsumerProtectionOptions,
|
|
96
|
+
providerName?: string,
|
|
97
|
+
): Readonly<Record<ConsentLocale, LegalLinkSet>> {
|
|
98
|
+
const base = legalLinksPerLocale(options.legalLinks);
|
|
99
|
+
if (!hasProviderRefundLink(options, providerName)) return base;
|
|
100
|
+
const withRefund = (locale: ConsentLocale): LegalLinkSet => ({
|
|
101
|
+
...base[locale],
|
|
102
|
+
...(providerRefundLink(options, providerName, locale) !== undefined && {
|
|
103
|
+
refund: providerRefundLink(options, providerName, locale),
|
|
104
|
+
}),
|
|
105
|
+
});
|
|
106
|
+
return { de: withRefund("de"), en: withRefund("en") };
|
|
107
|
+
}
|
|
108
|
+
|
|
63
109
|
/** The documents checkbox text for a locale, or undefined when the app did not
|
|
64
|
-
* opt in. The variant follows whether
|
|
110
|
+
* opt in. The variant follows whether the provider (or the locale) has a refund link. */
|
|
65
111
|
export function documentsAcknowledgementTextFor(
|
|
66
112
|
options: ConsumerProtectionOptions,
|
|
67
113
|
locale: ConsentLocale,
|
|
114
|
+
providerName?: string,
|
|
68
115
|
): string | undefined {
|
|
69
116
|
if (!options.documentsAcknowledgement) return undefined;
|
|
70
117
|
const texts = DOCUMENTS_ACKNOWLEDGEMENT_TEXTS[locale];
|
|
71
|
-
return
|
|
118
|
+
return refundLinkFor(options, locale, providerName) !== undefined
|
|
72
119
|
? texts.withRefund
|
|
73
120
|
: texts.withoutRefund;
|
|
74
121
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
1
2
|
import {
|
|
2
3
|
CONTRACT_TERMINATION_REQUESTED_EVENT_QN,
|
|
3
4
|
contractTerminationRequestedPayloadSchema,
|
|
@@ -5,9 +6,11 @@ import {
|
|
|
5
6
|
import { hasRevocation } from "./termination-record.ts";
|
|
6
7
|
|
|
7
8
|
// A revoked declaration must not resume a subscription another declaration still cancels at the provider.
|
|
9
|
+
// The stream is per tenant and outlives subscriptions, so a cancel that already took effect belongs to an earlier contract.
|
|
8
10
|
export function hasOtherOpenProviderCancel(
|
|
9
11
|
events: readonly { type: string; payload: unknown }[],
|
|
10
12
|
requestId: string,
|
|
13
|
+
now: Temporal.Instant,
|
|
11
14
|
): boolean {
|
|
12
15
|
return events.some((e) => {
|
|
13
16
|
if (e.type !== CONTRACT_TERMINATION_REQUESTED_EVENT_QN) return false;
|
|
@@ -16,6 +19,8 @@ export function hasOtherOpenProviderCancel(
|
|
|
16
19
|
recorded !== undefined &&
|
|
17
20
|
recorded.requestId !== requestId &&
|
|
18
21
|
recorded.providerCancel !== "none" &&
|
|
22
|
+
(recorded.effectiveAtIso === null ||
|
|
23
|
+
Temporal.Instant.compare(now, Temporal.Instant.from(recorded.effectiveAtIso)) < 0) &&
|
|
19
24
|
!hasRevocation(events, recorded.requestId)
|
|
20
25
|
);
|
|
21
26
|
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// The termination handlers hold the tenant's advisory lock across the provider call; without a
|
|
2
|
+
// bound a hanging provider would pin the transaction, its pool connection and every waiting
|
|
3
|
+
// withdrawal request. The abandoned call may still complete at the provider, so a timeout is
|
|
4
|
+
// reported like any provider error and the operator reconciles by hand.
|
|
5
|
+
export const PROVIDER_CALL_TIMEOUT_MS = 20_000;
|
|
6
|
+
|
|
7
|
+
export async function withProviderCallTimeout<T>(
|
|
8
|
+
call: Promise<T>,
|
|
9
|
+
timeoutMs: number = PROVIDER_CALL_TIMEOUT_MS,
|
|
10
|
+
): Promise<T> {
|
|
11
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
12
|
+
const timeout = new Promise<never>((_, reject) => {
|
|
13
|
+
timer = setTimeout(
|
|
14
|
+
() => reject(new Error(`provider call exceeded ${timeoutMs} ms`)),
|
|
15
|
+
timeoutMs,
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
try {
|
|
19
|
+
return await Promise.race([call, timeout]);
|
|
20
|
+
} finally {
|
|
21
|
+
clearTimeout(timer);
|
|
22
|
+
}
|
|
23
|
+
}
|
package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-record.ts
CHANGED
|
@@ -43,6 +43,7 @@ import {
|
|
|
43
43
|
TERMINATION_PROVIDER_LOCK_KEY,
|
|
44
44
|
TERMINATION_PROVIDER_LOCK_NAMESPACE,
|
|
45
45
|
} from "./termination-provider-lock.ts";
|
|
46
|
+
import { withProviderCallTimeout } from "./termination-provider-timeout.ts";
|
|
46
47
|
import type { OperatorNoticeReason } from "./termination-texts.ts";
|
|
47
48
|
import { isWithinWithdrawalPeriod } from "./withdrawal-period.ts";
|
|
48
49
|
|
|
@@ -140,10 +141,12 @@ async function cancelAtProvider(
|
|
|
140
141
|
return { providerCancel: "none", effectiveAtIso: null, noticeReason: "provider_cannot_cancel" };
|
|
141
142
|
}
|
|
142
143
|
try {
|
|
143
|
-
await
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
await withProviderCallTimeout(
|
|
145
|
+
plugin.cancelSubscription(ctx, {
|
|
146
|
+
providerSubscriptionId: subscription.providerSubscriptionId,
|
|
147
|
+
when,
|
|
148
|
+
}),
|
|
149
|
+
);
|
|
147
150
|
} catch (error) {
|
|
148
151
|
ctx.obs.log?.warn(
|
|
149
152
|
`[billing-foundation:record-contract-termination] provider cancel failed for tenant ${tenantId}: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -344,9 +347,11 @@ export async function resumeAtProvider(
|
|
|
344
347
|
const plugin = findPlugin(ctx, subscription.providerName);
|
|
345
348
|
if (!plugin?.resumeSubscription) return ["revocation_resume_manual"];
|
|
346
349
|
try {
|
|
347
|
-
await
|
|
348
|
-
|
|
349
|
-
|
|
350
|
+
await withProviderCallTimeout(
|
|
351
|
+
plugin.resumeSubscription(ctx, {
|
|
352
|
+
providerSubscriptionId: subscription.providerSubscriptionId,
|
|
353
|
+
}),
|
|
354
|
+
);
|
|
350
355
|
} catch (error) {
|
|
351
356
|
ctx.obs.log?.warn(
|
|
352
357
|
`[billing-foundation:revoke-contract-termination] provider resume failed: ${error instanceof Error ? error.message : String(error)}`,
|
package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-revoke.ts
CHANGED
|
@@ -164,7 +164,7 @@ export function createRecordContractTerminationRevocationHandler(
|
|
|
164
164
|
const reasons: OperatorNoticeReason[] = ["revoked"];
|
|
165
165
|
if (
|
|
166
166
|
requested?.providerCancel === "period-end" &&
|
|
167
|
-
!hasOtherOpenProviderCancel(stream.events, payload.requestId)
|
|
167
|
+
!hasOtherOpenProviderCancel(stream.events, payload.requestId, now)
|
|
168
168
|
) {
|
|
169
169
|
reasons.push(...(await resumeAtProvider(ctx, subscription)));
|
|
170
170
|
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// accounting-export, churn-analytics) listen directly for the event type
|
|
11
11
|
// without a payload discriminator.
|
|
12
12
|
|
|
13
|
+
import { piiCiphertextMaxLengthFor } from "@cosmicdrift/kumiko-framework/crypto";
|
|
13
14
|
import * as z from "zod";
|
|
14
15
|
import { BILLING_FOUNDATION_FEATURE, SubscriptionStatuses } from "./web/constants.ts";
|
|
15
16
|
import { CONSENT_LOCALES } from "./web/consumer-protection/consent-locale.ts";
|
|
@@ -53,12 +54,9 @@ const statusEnum = z.enum([
|
|
|
53
54
|
// PII, and event headers cannot be crypto-shredded.
|
|
54
55
|
export const subscriptionEventPayloadSchema = z.object({
|
|
55
56
|
providerName: z.string().min(1).max(50),
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// provider id. A 200-char plaintext id becomes ~300+ chars of ciphertext.
|
|
60
|
-
providerCustomerId: z.string().min(1).max(1000),
|
|
61
|
-
providerSubscriptionId: z.string().min(1).max(1000),
|
|
57
|
+
// Ciphertext, not the raw id: process-event limits the plaintext id to 200.
|
|
58
|
+
providerCustomerId: z.string().min(1).max(piiCiphertextMaxLengthFor(200)),
|
|
59
|
+
providerSubscriptionId: z.string().min(1).max(piiCiphertextMaxLengthFor(200)),
|
|
62
60
|
status: statusEnum,
|
|
63
61
|
tier: z.string().min(1).max(50),
|
|
64
62
|
currentPeriodEndIso: z.string().min(1),
|
|
@@ -100,10 +98,8 @@ export const PAYMENT_RECEIVED_EVENT_QN =
|
|
|
100
98
|
|
|
101
99
|
export const paymentEventPayloadSchema = z.object({
|
|
102
100
|
providerName: z.string().min(1).max(50),
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
// subscriptionEventPayloadSchema's same rationale.
|
|
106
|
-
providerCustomerId: z.string().min(1).max(1000),
|
|
101
|
+
// Ciphertext, not the raw id (plaintext limit 200).
|
|
102
|
+
providerCustomerId: z.string().min(1).max(piiCiphertextMaxLengthFor(200)),
|
|
107
103
|
priceId: z.string().min(1).max(200),
|
|
108
104
|
// Optional so payloads stored before quantity existed still parse; absent = 1.
|
|
109
105
|
quantity: z.number().int().positive().optional(),
|
|
@@ -117,6 +113,49 @@ export type PaymentEventHeaders = {
|
|
|
117
113
|
readonly providerCheckoutId?: string;
|
|
118
114
|
};
|
|
119
115
|
|
|
116
|
+
// =============================================================================
|
|
117
|
+
// checkout-opened — the server's checkout ledger
|
|
118
|
+
// =============================================================================
|
|
119
|
+
//
|
|
120
|
+
// Appended onto the subscription- or payment-stream (by checkout mode) right
|
|
121
|
+
// after the provider handed out a checkout. Webhooks are only accepted for
|
|
122
|
+
// checkouts listed here, so a checkout opened client-side (public provider
|
|
123
|
+
// tokens) cannot mint payments or subscriptions. No projection applies it.
|
|
124
|
+
|
|
125
|
+
export const CHECKOUT_OPENED_EVENT_SHORT = "checkout-opened" as const;
|
|
126
|
+
export const CHECKOUT_OPENED_EVENT_QN =
|
|
127
|
+
`${BILLING_FOUNDATION_FEATURE}:event:${CHECKOUT_OPENED_EVENT_SHORT}` as const;
|
|
128
|
+
|
|
129
|
+
export const CHECKOUT_MODES = ["subscription", "payment"] as const;
|
|
130
|
+
|
|
131
|
+
export const checkoutOpenedPayloadSchema = z.object({
|
|
132
|
+
providerName: z.string().min(1).max(50),
|
|
133
|
+
providerCheckoutId: z.string().min(1).max(200),
|
|
134
|
+
priceId: z.string().min(1).max(200),
|
|
135
|
+
mode: z.enum(CHECKOUT_MODES),
|
|
136
|
+
consentId: z.string().min(1).max(100).optional(),
|
|
137
|
+
});
|
|
138
|
+
export type CheckoutOpenedPayload = z.infer<typeof checkoutOpenedPayloadSchema>;
|
|
139
|
+
|
|
140
|
+
// =============================================================================
|
|
141
|
+
// plan-switch-requested — in-app plan switch in flight
|
|
142
|
+
// =============================================================================
|
|
143
|
+
//
|
|
144
|
+
// Appended onto the subscription stream when switch-plan applied a switch at the provider; the
|
|
145
|
+
// tier only changes once the provider's webhook arrives. No projection applies it. It blocks a
|
|
146
|
+
// second switch until a state event follows or the window runs out.
|
|
147
|
+
|
|
148
|
+
export const PLAN_SWITCH_REQUESTED_EVENT_SHORT = "plan-switch-requested" as const;
|
|
149
|
+
export const PLAN_SWITCH_REQUESTED_EVENT_QN =
|
|
150
|
+
`${BILLING_FOUNDATION_FEATURE}:event:${PLAN_SWITCH_REQUESTED_EVENT_SHORT}` as const;
|
|
151
|
+
|
|
152
|
+
export const planSwitchRequestedPayloadSchema = z.object({
|
|
153
|
+
tier: z.string().min(1).max(50),
|
|
154
|
+
priceId: z.string().min(1).max(200),
|
|
155
|
+
requestedAtIso: z.iso.datetime(),
|
|
156
|
+
});
|
|
157
|
+
export type PlanSwitchRequestedPayload = z.infer<typeof planSwitchRequestedPayloadSchema>;
|
|
158
|
+
|
|
120
159
|
// =============================================================================
|
|
121
160
|
// checkout-consent-recorded — consumer-protection consent
|
|
122
161
|
// =============================================================================
|
|
@@ -58,6 +58,8 @@ import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
|
58
58
|
import { registerConsumerProtection } from "./consumer-protection/register-consent.ts";
|
|
59
59
|
import { paymentEntity, subscriptionEntity } from "./entities.ts";
|
|
60
60
|
import {
|
|
61
|
+
CHECKOUT_OPENED_EVENT_SHORT,
|
|
62
|
+
checkoutOpenedPayloadSchema,
|
|
61
63
|
INVOICE_PAID_EVENT_QN,
|
|
62
64
|
INVOICE_PAID_EVENT_SHORT,
|
|
63
65
|
INVOICE_PAYMENT_FAILED_EVENT_QN,
|
|
@@ -65,7 +67,9 @@ import {
|
|
|
65
67
|
PAYMENT_AGGREGATE_TYPE,
|
|
66
68
|
PAYMENT_RECEIVED_EVENT_QN,
|
|
67
69
|
PAYMENT_RECEIVED_EVENT_SHORT,
|
|
70
|
+
PLAN_SWITCH_REQUESTED_EVENT_SHORT,
|
|
68
71
|
paymentEventPayloadSchema,
|
|
72
|
+
planSwitchRequestedPayloadSchema,
|
|
69
73
|
SUBSCRIPTION_AGGREGATE_TYPE,
|
|
70
74
|
SUBSCRIPTION_CANCELED_EVENT_QN,
|
|
71
75
|
SUBSCRIPTION_CANCELED_EVENT_SHORT,
|
|
@@ -82,6 +86,7 @@ import { listSubscriptionsQuery } from "./handlers/list-subscriptions.query.ts";
|
|
|
82
86
|
import { createPlanSwitchPreviewQuery } from "./handlers/plan-switch-preview.query.ts";
|
|
83
87
|
import { createProcessEventHandler } from "./handlers/process-event.write.ts";
|
|
84
88
|
import { processPaymentEventHandler } from "./handlers/process-payment-event.write.ts";
|
|
89
|
+
import { recordCheckoutOpenedHandler } from "./handlers/record-checkout-opened.write.ts";
|
|
85
90
|
import { createStartPlanCheckoutHandler } from "./handlers/start-plan-checkout.write.ts";
|
|
86
91
|
import { createSwitchPlanHandler } from "./handlers/switch-plan.write.ts";
|
|
87
92
|
import { syncSubscriptionHandler } from "./handlers/sync-subscription.write.ts";
|
|
@@ -97,6 +102,7 @@ import {
|
|
|
97
102
|
subscriptionsProjectionTable,
|
|
98
103
|
} from "./projection.ts";
|
|
99
104
|
import { createBillingPlansScreen } from "./screens.ts";
|
|
105
|
+
import { registerScrubRawPayloadHeadersJob } from "./scrub-raw-payload-headers.ts";
|
|
100
106
|
import {
|
|
101
107
|
PAYMENT_TENANT_DESTROY_ARCHIVE_REASON,
|
|
102
108
|
paymentTenantDestroyHook,
|
|
@@ -170,6 +176,10 @@ export function createBillingFoundationFeature<TTier extends string = string>(
|
|
|
170
176
|
// state transition. piiFields: "none" for the same reason as the 5 above:
|
|
171
177
|
// providerCustomerId is tenantOwned ciphertext, not plaintext personal data.
|
|
172
178
|
r.defineEvent(PAYMENT_RECEIVED_EVENT_SHORT, paymentEventPayloadSchema, { piiFields: "none" });
|
|
179
|
+
// Checkout ledger: registered unconditionally, webhook acceptance depends on it.
|
|
180
|
+
r.defineEvent(CHECKOUT_OPENED_EVENT_SHORT, checkoutOpenedPayloadSchema, {
|
|
181
|
+
piiFields: "none",
|
|
182
|
+
});
|
|
173
183
|
|
|
174
184
|
// Inline projection: materialized current state in `read_subscriptions`.
|
|
175
185
|
// Apply runs in the same TX as ctx.events.unsafeAppend — read-your-own-
|
|
@@ -214,6 +224,7 @@ export function createBillingFoundationFeature<TTier extends string = string>(
|
|
|
214
224
|
// - process-payment-event: programmatic entry-point from the webhook-
|
|
215
225
|
// handler for one-off-payments; appends onto the payment-aggregate
|
|
216
226
|
r.writeHandler(processPaymentEventHandler);
|
|
227
|
+
r.writeHandler(recordCheckoutOpenedHandler);
|
|
217
228
|
// - sync-subscription: backfill entry-point for the sync-subscriptions
|
|
218
229
|
// job below; pulls the live provider state and appends drift as a
|
|
219
230
|
// subscription.updated event. Registered unconditionally (not
|
|
@@ -238,6 +249,9 @@ export function createBillingFoundationFeature<TTier extends string = string>(
|
|
|
238
249
|
r.queryHandler(createBillingPlansQuery(widened, catalog));
|
|
239
250
|
r.queryHandler(createPlanSwitchPreviewQuery(catalog));
|
|
240
251
|
r.writeHandler(createStartPlanCheckoutHandler(widened, catalog));
|
|
252
|
+
r.defineEvent(PLAN_SWITCH_REQUESTED_EVENT_SHORT, planSwitchRequestedPayloadSchema, {
|
|
253
|
+
piiFields: "none",
|
|
254
|
+
});
|
|
241
255
|
r.writeHandler(createSwitchPlanHandler(widened, catalog));
|
|
242
256
|
r.screen(createBillingPlansScreen(catalog.viewRoles));
|
|
243
257
|
}
|
|
@@ -270,7 +284,7 @@ export function createBillingFoundationFeature<TTier extends string = string>(
|
|
|
270
284
|
);
|
|
271
285
|
},
|
|
272
286
|
});
|
|
273
|
-
|
|
287
|
+
registerScrubRawPayloadHeadersJob(r);
|
|
274
288
|
r.useExtension(EXT_TENANT_DATA, "subscription", {
|
|
275
289
|
destroy: subscriptionTenantDestroyHook,
|
|
276
290
|
escapeHatch: { reason: SUBSCRIPTION_TENANT_DESTROY_ARCHIVE_REASON },
|
|
@@ -14,7 +14,8 @@ import {
|
|
|
14
14
|
CONSENT_TEXTS,
|
|
15
15
|
consentTextVersion,
|
|
16
16
|
documentsAcknowledgementTextFor,
|
|
17
|
-
|
|
17
|
+
hasProviderRefundLink,
|
|
18
|
+
legalLinksFor,
|
|
18
19
|
} from "../consumer-protection/consent-text.ts";
|
|
19
20
|
import {
|
|
20
21
|
type BillingPlansBase,
|
|
@@ -24,6 +25,7 @@ import {
|
|
|
24
25
|
toBillingPlansResult,
|
|
25
26
|
} from "../plan-catalog.ts";
|
|
26
27
|
import type {
|
|
28
|
+
BillingConsumerProtectionView,
|
|
27
29
|
BillingPlanCatalog,
|
|
28
30
|
BillingPlansResult,
|
|
29
31
|
BillingProviderView,
|
|
@@ -50,13 +52,10 @@ export function createBillingPlansQuery(
|
|
|
50
52
|
if (!consumerProtection) return result;
|
|
51
53
|
return {
|
|
52
54
|
...result,
|
|
53
|
-
consumerProtection:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
legalLinks: legalLinksPerLocale(consumerProtection.legalLinks),
|
|
59
|
-
},
|
|
55
|
+
consumerProtection: consumerProtectionView(
|
|
56
|
+
consumerProtection,
|
|
57
|
+
base.blockingSubscription ? base.subscriptionView?.providerName : undefined,
|
|
58
|
+
),
|
|
60
59
|
};
|
|
61
60
|
},
|
|
62
61
|
};
|
|
@@ -87,12 +86,23 @@ async function resolveProviderPlans(
|
|
|
87
86
|
const result = toBillingPlansResult(catalog, base, firstViews);
|
|
88
87
|
|
|
89
88
|
const providerTexts = options.consumerProtection?.providerTexts;
|
|
90
|
-
const
|
|
91
|
-
|
|
89
|
+
const hasProviderSpecifics =
|
|
90
|
+
first !== null &&
|
|
91
|
+
(providerTexts?.[first.name]?.checkoutNote !== undefined ||
|
|
92
|
+
(options.consumerProtection !== undefined &&
|
|
93
|
+
hasProviderRefundLink(options.consumerProtection, first.name)));
|
|
94
|
+
if (offered.length <= 1 && !(offered.length === 1 && hasProviderSpecifics)) return result;
|
|
92
95
|
|
|
93
96
|
const providers = await Promise.all(
|
|
94
97
|
offered.map((provider, index) =>
|
|
95
|
-
providerView(
|
|
98
|
+
providerView(
|
|
99
|
+
ctx,
|
|
100
|
+
catalog,
|
|
101
|
+
base,
|
|
102
|
+
provider,
|
|
103
|
+
options.consumerProtection,
|
|
104
|
+
index === 0 ? firstViews : null,
|
|
105
|
+
),
|
|
96
106
|
),
|
|
97
107
|
);
|
|
98
108
|
return { ...result, providers };
|
|
@@ -103,25 +113,48 @@ async function providerView(
|
|
|
103
113
|
catalog: BillingPlanCatalog,
|
|
104
114
|
base: BillingPlansBase,
|
|
105
115
|
provider: ResolvedProvider,
|
|
106
|
-
|
|
116
|
+
consumerProtection: ConsumerProtectionOptions | undefined,
|
|
107
117
|
known: ProviderPlanViews | null,
|
|
108
118
|
): Promise<BillingProviderView> {
|
|
109
119
|
const views = known ?? (await buildProviderPlanViews(ctx, provider.plugin, catalog, base));
|
|
110
|
-
const note = providerTexts?.[provider.name]?.checkoutNote;
|
|
120
|
+
const note = consumerProtection?.providerTexts?.[provider.name]?.checkoutNote;
|
|
121
|
+
const ownConsumerProtection =
|
|
122
|
+
consumerProtection !== undefined && hasProviderRefundLink(consumerProtection, provider.name)
|
|
123
|
+
? consumerProtectionView(consumerProtection, provider.name)
|
|
124
|
+
: undefined;
|
|
111
125
|
return {
|
|
112
126
|
name: provider.name,
|
|
113
127
|
displayName: provider.plugin.displayName ?? provider.name,
|
|
114
128
|
...(note !== undefined && { note }),
|
|
129
|
+
...(ownConsumerProtection !== undefined && { consumerProtection: ownConsumerProtection }),
|
|
115
130
|
plans: views.plans,
|
|
116
131
|
};
|
|
117
132
|
}
|
|
118
133
|
|
|
134
|
+
function consumerProtectionView(
|
|
135
|
+
consumerProtection: ConsumerProtectionOptions,
|
|
136
|
+
providerName?: string,
|
|
137
|
+
): BillingConsumerProtectionView {
|
|
138
|
+
return {
|
|
139
|
+
consentTexts: {
|
|
140
|
+
de: consentTextView(consumerProtection, "de", providerName),
|
|
141
|
+
en: consentTextView(consumerProtection, "en", providerName),
|
|
142
|
+
},
|
|
143
|
+
legalLinks: legalLinksFor(consumerProtection, providerName),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
119
147
|
function consentTextView(
|
|
120
148
|
consumerProtection: ConsumerProtectionOptions,
|
|
121
149
|
locale: (typeof CONSENT_LOCALES)[number],
|
|
150
|
+
providerName?: string,
|
|
122
151
|
) {
|
|
123
152
|
const { earlyPerformance, withdrawalLoss } = CONSENT_TEXTS[locale];
|
|
124
|
-
const documentsAcknowledgement = documentsAcknowledgementTextFor(
|
|
153
|
+
const documentsAcknowledgement = documentsAcknowledgementTextFor(
|
|
154
|
+
consumerProtection,
|
|
155
|
+
locale,
|
|
156
|
+
providerName,
|
|
157
|
+
);
|
|
125
158
|
return {
|
|
126
159
|
earlyPerformance,
|
|
127
160
|
withdrawalLoss,
|
package/packages/bundled-features/src/billing-foundation/handlers/create-checkout-session.write.ts
CHANGED
|
@@ -119,7 +119,13 @@ export function createCheckoutSessionHandler(
|
|
|
119
119
|
? await consumerProtection.oneOffItemLabel?.(ctx, payload.priceId)
|
|
120
120
|
: undefined;
|
|
121
121
|
assertValidOrderItem(orderItem, payload.priceId);
|
|
122
|
-
const consent = await prepareConsent(
|
|
122
|
+
const consent = await prepareConsent(
|
|
123
|
+
ctx,
|
|
124
|
+
consumerProtection,
|
|
125
|
+
payload.consent,
|
|
126
|
+
mode,
|
|
127
|
+
payload.providerName,
|
|
128
|
+
);
|
|
123
129
|
const result = await startProviderCheckout(ctx, plugin, {
|
|
124
130
|
...checkoutInput,
|
|
125
131
|
...consentCheckoutFields(consent),
|
|
@@ -7,9 +7,12 @@
|
|
|
7
7
|
// already-seen `metadata.providerEventId`. A provider replay
|
|
8
8
|
// (Stripe retry storm) has the same event ID → duplicate=true,
|
|
9
9
|
// with no second append.
|
|
10
|
-
// 2.
|
|
10
|
+
// 2. Admission (handler only, not the shared append): `created` needs a
|
|
11
|
+
// checkout from the server's ledger; every other type needs the tenant's
|
|
12
|
+
// current subscription or a ledgered checkout. Else the event is ignored.
|
|
13
|
+
// 3. Type mapping: SubscriptionEvent.type (= normalized by the plugin)
|
|
11
14
|
// → one of the 5 ES event types.
|
|
12
|
-
//
|
|
15
|
+
// 4. ctx.events.unsafeAppend — the inline projection materializes the
|
|
13
16
|
// `read_subscriptions` row in the same TX.
|
|
14
17
|
|
|
15
18
|
import {
|
|
@@ -21,8 +24,13 @@ import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
|
21
24
|
import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
22
25
|
import * as z from "zod";
|
|
23
26
|
import { subscriptionAggregateId } from "../aggregate-id.ts";
|
|
27
|
+
import { findProviderPlugin } from "../checkout-core.ts";
|
|
28
|
+
import { findCheckoutOpened } from "../checkout-ledger.ts";
|
|
24
29
|
import { SUBSCRIPTION_PII_FIELDS, subscriptionEntity } from "../entities.ts";
|
|
25
30
|
import {
|
|
31
|
+
CHECKOUT_CONSENT_RECORDED_EVENT_QN,
|
|
32
|
+
type CheckoutOpenedPayload,
|
|
33
|
+
checkoutConsentRecordedPayloadSchema,
|
|
26
34
|
INVOICE_PAID_EVENT_QN,
|
|
27
35
|
INVOICE_PAYMENT_FAILED_EVENT_QN,
|
|
28
36
|
SUBSCRIPTION_AGGREGATE_TYPE,
|
|
@@ -75,7 +83,7 @@ export const processEventSchema = z.object({
|
|
|
75
83
|
currentPeriodEndIso: z.string().min(1),
|
|
76
84
|
cancelAtIso: z.string().min(1).nullable().optional(),
|
|
77
85
|
providerEventAtIso: z.iso.datetime().optional(),
|
|
78
|
-
|
|
86
|
+
providerCheckoutId: z.string().min(1).max(200).optional(),
|
|
79
87
|
});
|
|
80
88
|
export type ProcessEventPayload = z.infer<typeof processEventSchema>;
|
|
81
89
|
|
|
@@ -88,6 +96,12 @@ const NORMALIZED_TO_ES_EVENT: Readonly<Record<string, string>> = {
|
|
|
88
96
|
[SubscriptionEventTypes.invoicePaymentFailed]: INVOICE_PAYMENT_FAILED_EVENT_QN,
|
|
89
97
|
} satisfies Readonly<Record<string, string>>;
|
|
90
98
|
|
|
99
|
+
const STATE_EVENT_QNS: ReadonlySet<string> = new Set([
|
|
100
|
+
SUBSCRIPTION_CREATED_EVENT_QN,
|
|
101
|
+
SUBSCRIPTION_UPDATED_EVENT_QN,
|
|
102
|
+
SUBSCRIPTION_CANCELED_EVENT_QN,
|
|
103
|
+
]);
|
|
104
|
+
|
|
91
105
|
const STATE_EVENT_TYPES: ReadonlySet<string> = new Set([
|
|
92
106
|
SubscriptionEventTypes.created,
|
|
93
107
|
SubscriptionEventTypes.updated,
|
|
@@ -152,6 +166,7 @@ export async function appendSubscriptionEvent(
|
|
|
152
166
|
tenantId: string,
|
|
153
167
|
rawPayload: ProcessEventPayload,
|
|
154
168
|
now: Temporal.Instant = Temporal.Now.instant(),
|
|
169
|
+
consentId?: string,
|
|
155
170
|
): Promise<{
|
|
156
171
|
readonly duplicate: boolean;
|
|
157
172
|
readonly stale?: true;
|
|
@@ -245,7 +260,7 @@ export async function appendSubscriptionEvent(
|
|
|
245
260
|
tier: payload.tier,
|
|
246
261
|
currentPeriodEndIso: payload.currentPeriodEndIso,
|
|
247
262
|
...(payload.cancelAtIso !== undefined && { cancelAtIso: payload.cancelAtIso }),
|
|
248
|
-
...(
|
|
263
|
+
...(consentId !== undefined && { consentId }),
|
|
249
264
|
...(payload.providerEventAtIso !== undefined && {
|
|
250
265
|
providerEventAtIso: payload.providerEventAtIso,
|
|
251
266
|
}),
|
|
@@ -294,6 +309,87 @@ function isStaleSubscriptionEvent(
|
|
|
294
309
|
return !supersedesCurrent;
|
|
295
310
|
}
|
|
296
311
|
|
|
312
|
+
type Admission =
|
|
313
|
+
| { readonly admitted: true; readonly consentId?: string }
|
|
314
|
+
| { readonly admitted: false; readonly reason: string; readonly retry?: true };
|
|
315
|
+
|
|
316
|
+
function isBoundToLedgerEntry(
|
|
317
|
+
ctx: HandlerContext,
|
|
318
|
+
entry: CheckoutOpenedPayload,
|
|
319
|
+
payload: ProcessEventPayload,
|
|
320
|
+
): boolean {
|
|
321
|
+
const plugin = findProviderPlugin(ctx, payload.providerName)?.plugin;
|
|
322
|
+
return plugin?.priceToTier?.[entry.priceId] === payload.tier;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// A plan switch has no checkout of its own: its consent is the newest one recorded for the target
|
|
326
|
+
// tier since the last stored state event, as long as no stored subscription event carries it yet.
|
|
327
|
+
function pendingSwitchConsentId(
|
|
328
|
+
storedEvents: readonly { readonly type: string; readonly payload: unknown }[],
|
|
329
|
+
payload: ProcessEventPayload,
|
|
330
|
+
): string | undefined {
|
|
331
|
+
let lastStateIndex = -1;
|
|
332
|
+
const carried = new Set<string>();
|
|
333
|
+
storedEvents.forEach((stored, index) => {
|
|
334
|
+
// skip: only subscription state events can carry a consent
|
|
335
|
+
if (!STATE_EVENT_QNS.has(stored.type)) return;
|
|
336
|
+
lastStateIndex = index;
|
|
337
|
+
const consentId = propertyOf(stored.payload, "consentId");
|
|
338
|
+
if (typeof consentId === "string") carried.add(consentId);
|
|
339
|
+
});
|
|
340
|
+
for (let index = storedEvents.length - 1; index > lastStateIndex; index--) {
|
|
341
|
+
const stored = storedEvents[index];
|
|
342
|
+
if (stored?.type !== CHECKOUT_CONSENT_RECORDED_EVENT_QN) continue;
|
|
343
|
+
const parsed = checkoutConsentRecordedPayloadSchema.safeParse(stored.payload);
|
|
344
|
+
if (!parsed.success) continue;
|
|
345
|
+
const consent = parsed.data;
|
|
346
|
+
if (
|
|
347
|
+
consent.mode === "subscription" &&
|
|
348
|
+
consent.tier === payload.tier &&
|
|
349
|
+
(consent.providerName === undefined || consent.providerName === payload.providerName) &&
|
|
350
|
+
!carried.has(consent.consentId)
|
|
351
|
+
) {
|
|
352
|
+
return consent.consentId;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return undefined;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function admitProviderEvent(
|
|
359
|
+
ctx: HandlerContext,
|
|
360
|
+
storedEvents: readonly { readonly type: string; readonly payload: unknown }[],
|
|
361
|
+
current: SubscriptionView | null,
|
|
362
|
+
payload: ProcessEventPayload,
|
|
363
|
+
): Admission {
|
|
364
|
+
const entry =
|
|
365
|
+
payload.providerCheckoutId === undefined
|
|
366
|
+
? undefined
|
|
367
|
+
: findCheckoutOpened(storedEvents, {
|
|
368
|
+
providerName: payload.providerName,
|
|
369
|
+
providerCheckoutId: payload.providerCheckoutId,
|
|
370
|
+
mode: "subscription",
|
|
371
|
+
});
|
|
372
|
+
if (entry !== undefined && isBoundToLedgerEntry(ctx, entry, payload)) {
|
|
373
|
+
return { admitted: true, ...(entry.consentId !== undefined && { consentId: entry.consentId }) };
|
|
374
|
+
}
|
|
375
|
+
if (payload.type === SubscriptionEventTypes.created) {
|
|
376
|
+
return { admitted: false, reason: "checkout_not_in_ledger" };
|
|
377
|
+
}
|
|
378
|
+
// The provider does not guarantee order: an update that beats the `created` of its
|
|
379
|
+
// subscription must be redelivered, not dropped.
|
|
380
|
+
if (current === null)
|
|
381
|
+
return { admitted: false, reason: "subscription_not_yet_created", retry: true };
|
|
382
|
+
const isCurrentSubscription =
|
|
383
|
+
current.providerName === payload.providerName &&
|
|
384
|
+
current.providerSubscriptionId === payload.providerSubscriptionId;
|
|
385
|
+
if (!isCurrentSubscription) return { admitted: false, reason: "foreign_subscription" };
|
|
386
|
+
const switchConsentId =
|
|
387
|
+
payload.type === SubscriptionEventTypes.updated && current.tier !== payload.tier
|
|
388
|
+
? pendingSwitchConsentId(storedEvents, payload)
|
|
389
|
+
: undefined;
|
|
390
|
+
return { admitted: true, ...(switchConsentId !== undefined && { consentId: switchConsentId }) };
|
|
391
|
+
}
|
|
392
|
+
|
|
297
393
|
export function createProcessEventHandler(now: () => Temporal.Instant): WriteHandlerDef {
|
|
298
394
|
return {
|
|
299
395
|
name: "process-event",
|
|
@@ -303,21 +399,39 @@ export function createProcessEventHandler(now: () => Temporal.Instant): WriteHan
|
|
|
303
399
|
handler: async (event, ctx) => {
|
|
304
400
|
// @cast-boundary engine-payload — dispatcher-zod-validated payload
|
|
305
401
|
const payload = event.payload as ProcessEventPayload;
|
|
402
|
+
const aggId = subscriptionAggregateId(event.user.tenantId);
|
|
306
403
|
const current = await getSubscriptionForTenant(ctx, event.user.tenantId);
|
|
307
|
-
|
|
404
|
+
const admission = admitProviderEvent(ctx, await ctx.events.load(aggId), current, payload);
|
|
405
|
+
if (!admission.admitted) {
|
|
308
406
|
ctx.obs.log?.warn(
|
|
309
|
-
`[billing-foundation:process-event]
|
|
407
|
+
`[billing-foundation:process-event] ignored ${payload.type} ${payload.providerEventId} (${admission.reason}): provider ${payload.providerName}`,
|
|
310
408
|
);
|
|
311
409
|
return {
|
|
312
410
|
isSuccess: true as const,
|
|
313
411
|
data: {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
412
|
+
ignored: true as const,
|
|
413
|
+
reason: admission.reason,
|
|
414
|
+
...(admission.retry === true && { retry: true as const }),
|
|
415
|
+
subscriptionAggregateId: aggId,
|
|
317
416
|
},
|
|
318
417
|
};
|
|
319
418
|
}
|
|
320
|
-
|
|
419
|
+
if (isStaleSubscriptionEvent(current, payload, now())) {
|
|
420
|
+
ctx.obs.log?.warn(
|
|
421
|
+
`[billing-foundation:process-event] dropped stale ${payload.type} ${payload.providerEventId}: tenant already tracks another subscription`,
|
|
422
|
+
);
|
|
423
|
+
return {
|
|
424
|
+
isSuccess: true as const,
|
|
425
|
+
data: { duplicate: false, stale: true, subscriptionAggregateId: aggId },
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
const result = await appendSubscriptionEvent(
|
|
429
|
+
ctx,
|
|
430
|
+
event.user.tenantId,
|
|
431
|
+
payload,
|
|
432
|
+
now(),
|
|
433
|
+
admission.consentId,
|
|
434
|
+
);
|
|
321
435
|
return { isSuccess: true as const, data: result };
|
|
322
436
|
},
|
|
323
437
|
};
|