@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,57 @@
|
|
|
1
|
+
// While the takeover window of the checkout-ledger backfill is open, a Paddle event of a legacy
|
|
2
|
+
// checkout (custom_data still has the tenantBinding) that billing-foundation ignored as
|
|
3
|
+
// "not in the ledger" may only be waiting for the next sweep. Answering it with a retryable
|
|
4
|
+
// 5xx makes Paddle deliver it again once the sweep has ledgered the checkout.
|
|
5
|
+
|
|
6
|
+
import type { SignatureExtraRouteDeps } from "@cosmicdrift/kumiko-framework/api";
|
|
7
|
+
import { SYSTEM_TENANT_ID } from "@cosmicdrift/kumiko-framework/engine";
|
|
8
|
+
import type { FrameworkErrorCode } from "@cosmicdrift/kumiko-framework/errors";
|
|
9
|
+
import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
|
|
10
|
+
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
11
|
+
import { isOneOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
12
|
+
import { isTakeoverWindowOver } from "./backfill-checkout-ledger.ts";
|
|
13
|
+
import {
|
|
14
|
+
LEDGER_BACKFILL_MARKER_HANDLER_QN,
|
|
15
|
+
type LedgerBackfillMarkerResult,
|
|
16
|
+
} from "./ledger-backfill-marker.ts";
|
|
17
|
+
import { hasLegacyTenantBinding } from "./webhook-events.ts";
|
|
18
|
+
|
|
19
|
+
const log = createFallbackLogger("subscription-paddle");
|
|
20
|
+
|
|
21
|
+
// A retry cannot fix these: the marker handler is missing, disabled or not permitted.
|
|
22
|
+
const MARKER_CONFIGURATION_ERROR_CODES = [
|
|
23
|
+
"access_denied",
|
|
24
|
+
"not_found",
|
|
25
|
+
"feature_disabled",
|
|
26
|
+
] as const satisfies readonly FrameworkErrorCode[];
|
|
27
|
+
|
|
28
|
+
type IgnoredEvent = Parameters<typeof hasLegacyTenantBinding>[0];
|
|
29
|
+
|
|
30
|
+
export async function shouldRedeliverLegacyCheckout(args: {
|
|
31
|
+
readonly event: IgnoredEvent;
|
|
32
|
+
readonly reason: string;
|
|
33
|
+
readonly deps: SignatureExtraRouteDeps;
|
|
34
|
+
readonly now?: () => Temporal.Instant;
|
|
35
|
+
}): Promise<boolean> {
|
|
36
|
+
if (!hasLegacyTenantBinding(args.event)) return false;
|
|
37
|
+
const marker = await args.deps.dispatchWriteAs({
|
|
38
|
+
handlerQn: LEDGER_BACKFILL_MARKER_HANDLER_QN,
|
|
39
|
+
tenantId: SYSTEM_TENANT_ID,
|
|
40
|
+
roles: [],
|
|
41
|
+
payload: { markCompleted: false },
|
|
42
|
+
});
|
|
43
|
+
if (!marker.isSuccess) {
|
|
44
|
+
// tenantBinding is client-settable, so a permanent failure must not turn into endless 503s.
|
|
45
|
+
if (isOneOf(MARKER_CONFIGURATION_ERROR_CODES, marker.error.code)) {
|
|
46
|
+
log.warn("ledger backfill marker not readable, not redelivering", {
|
|
47
|
+
errorCode: marker.error.code,
|
|
48
|
+
});
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
// Transient or internal: Paddle redelivers only a bounded number of times, so retrying is safe.
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
const { completedAt } = marker.data as LedgerBackfillMarkerResult; // @cast-boundary engine-payload
|
|
55
|
+
if (completedAt === null) return true;
|
|
56
|
+
return !isTakeoverWindowOver(completedAt, (args.now ?? Temporal.Now.instant)());
|
|
57
|
+
}
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
20
20
|
import { UnconfiguredError } from "@cosmicdrift/kumiko-framework/errors";
|
|
21
21
|
import type { SecretsContext } from "@cosmicdrift/kumiko-framework/secrets";
|
|
22
|
-
import { assertBillingLive } from "../shared/index.ts";
|
|
22
|
+
import { assertBillingLive, isBillingLive } from "../shared/index.ts";
|
|
23
23
|
import { createPaddleHttp, type PaddleRequest, type PaddleSend } from "./client.ts";
|
|
24
24
|
import {
|
|
25
25
|
PADDLE_BASE_URLS,
|
|
@@ -35,14 +35,12 @@ export type PaddlePluginMethod<TName extends keyof SubscriptionProviderPlugin> =
|
|
|
35
35
|
export type PaddleFallbacks = {
|
|
36
36
|
readonly apiKey?: string;
|
|
37
37
|
readonly webhookSecret?: string;
|
|
38
|
-
readonly tenantBindingKey?: string;
|
|
39
38
|
readonly clientToken?: string;
|
|
40
39
|
};
|
|
41
40
|
|
|
42
41
|
export type PaddleRuntimeDeps = {
|
|
43
42
|
readonly apiKeyHandle: ConfigKeyHandle<"text">;
|
|
44
43
|
readonly webhookSecretHandle: ConfigKeyHandle<"text">;
|
|
45
|
-
readonly tenantBindingKeyHandle: ConfigKeyHandle<"text">;
|
|
46
44
|
readonly clientTokenHandle: ConfigKeyHandle<"text">;
|
|
47
45
|
readonly billingLiveHandle: ConfigKeyHandle<"boolean">;
|
|
48
46
|
readonly environmentHandle: ConfigKeyHandle<"select">;
|
|
@@ -54,16 +52,19 @@ function hintFor(shortName: string): string {
|
|
|
54
52
|
return `Set it via config:write:set on \`${SUBSCRIPTION_PADDLE_FEATURE}:config:${shortName}\` (or seed it from the matching PADDLE_* variable during the env bridge).`;
|
|
55
53
|
}
|
|
56
54
|
|
|
55
|
+
// The slice of HandlerContext and JobContext the Paddle calls need, so the
|
|
56
|
+
// backfill job reaches Paddle through the same key and environment resolution.
|
|
57
|
+
export type PaddleCallSource = Pick<HandlerContext, "config" | "services" | "user">;
|
|
58
|
+
|
|
57
59
|
export type PaddleCtxRuntime = {
|
|
58
|
-
readonly call: (ctx:
|
|
60
|
+
readonly call: (ctx: PaddleCallSource, request: PaddleRequest) => Promise<unknown>;
|
|
61
|
+
readonly hasApiKey: (ctx: PaddleCallSource) => Promise<boolean>;
|
|
59
62
|
readonly assertBillingLive: (ctx: HandlerContext, handlerName?: string) => Promise<void>;
|
|
60
63
|
readonly isBillingEnabled: (ctx: HandlerContext) => Promise<boolean>;
|
|
61
|
-
readonly tenantBindingKey: (ctx: HandlerContext) => Promise<string>;
|
|
62
64
|
};
|
|
63
65
|
|
|
64
66
|
export type PaddleWebhookRuntime = {
|
|
65
67
|
readonly resolveWebhookSecret: (systemSecrets?: SecretsContext) => Promise<string>;
|
|
66
|
-
readonly resolveTenantBindingKey: (systemSecrets?: SecretsContext) => Promise<string>;
|
|
67
68
|
};
|
|
68
69
|
|
|
69
70
|
export type PaddleCheckoutConfig = {
|
|
@@ -87,7 +88,7 @@ export function createPaddleRuntimes(deps: PaddleRuntimeDeps): PaddleRuntimes {
|
|
|
87
88
|
const http = createPaddleHttp(deps.send);
|
|
88
89
|
|
|
89
90
|
async function ctxSecret(
|
|
90
|
-
ctx:
|
|
91
|
+
ctx: PaddleCallSource,
|
|
91
92
|
handle: ConfigKeyHandle<"text">,
|
|
92
93
|
fallback: string | undefined,
|
|
93
94
|
shortName: string,
|
|
@@ -129,7 +130,7 @@ export function createPaddleRuntimes(deps: PaddleRuntimeDeps): PaddleRuntimes {
|
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
async function hasSecret(
|
|
132
|
-
ctx:
|
|
133
|
+
ctx: PaddleCallSource,
|
|
133
134
|
handle: ConfigKeyHandle<"text">,
|
|
134
135
|
fallback: string | undefined,
|
|
135
136
|
): Promise<boolean> {
|
|
@@ -140,7 +141,7 @@ export function createPaddleRuntimes(deps: PaddleRuntimeDeps): PaddleRuntimes {
|
|
|
140
141
|
: false;
|
|
141
142
|
}
|
|
142
143
|
|
|
143
|
-
async function baseUrlFor(ctx:
|
|
144
|
+
async function baseUrlFor(ctx: PaddleCallSource): Promise<string> {
|
|
144
145
|
const environment = ctx.config ? await ctx.config(deps.environmentHandle) : undefined;
|
|
145
146
|
return PADDLE_BASE_URLS[environmentOf(environment)];
|
|
146
147
|
}
|
|
@@ -155,29 +156,17 @@ export function createPaddleRuntimes(deps: PaddleRuntimeDeps): PaddleRuntimes {
|
|
|
155
156
|
},
|
|
156
157
|
request,
|
|
157
158
|
),
|
|
159
|
+
hasApiKey: (ctx) => hasSecret(ctx, deps.apiKeyHandle, deps.fallback.apiKey),
|
|
158
160
|
assertBillingLive: (ctx, handlerName = "create-checkout-session") =>
|
|
159
161
|
assertBillingLive(ctx, deps.billingLiveHandle, SUBSCRIPTION_PADDLE_FEATURE, handlerName),
|
|
160
162
|
isBillingEnabled: async (ctx) => {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return (
|
|
164
|
-
(await hasSecret(ctx, deps.apiKeyHandle, deps.fallback.apiKey)) &&
|
|
165
|
-
(await hasSecret(ctx, deps.tenantBindingKeyHandle, deps.fallback.tenantBindingKey))
|
|
166
|
-
);
|
|
163
|
+
if (!(await isBillingLive(ctx, deps.billingLiveHandle))) return false;
|
|
164
|
+
return hasSecret(ctx, deps.apiKeyHandle, deps.fallback.apiKey);
|
|
167
165
|
},
|
|
168
|
-
tenantBindingKey: (ctx) =>
|
|
169
|
-
ctxSecret(
|
|
170
|
-
ctx,
|
|
171
|
-
deps.tenantBindingKeyHandle,
|
|
172
|
-
deps.fallback.tenantBindingKey,
|
|
173
|
-
"tenant-binding-key",
|
|
174
|
-
),
|
|
175
166
|
},
|
|
176
167
|
webhook: {
|
|
177
168
|
resolveWebhookSecret: (systemSecrets) =>
|
|
178
169
|
webhookSecret(systemSecrets, deps.webhookSecretHandle, deps.fallback.webhookSecret),
|
|
179
|
-
resolveTenantBindingKey: (systemSecrets) =>
|
|
180
|
-
webhookSecret(systemSecrets, deps.tenantBindingKeyHandle, deps.fallback.tenantBindingKey),
|
|
181
170
|
},
|
|
182
171
|
readCheckoutConfig: async (ctx) => {
|
|
183
172
|
const stored = ctx.config ? await ctx.config(deps.clientTokenHandle) : undefined;
|
|
@@ -25,6 +25,7 @@ export const paddleSubscriptionSchema = z.object({
|
|
|
25
25
|
id: z.string().min(1),
|
|
26
26
|
status: z.string(),
|
|
27
27
|
customer_id: z.string().min(1),
|
|
28
|
+
transaction_id: z.string().min(1).nullish(),
|
|
28
29
|
items: z.array(
|
|
29
30
|
z.object({
|
|
30
31
|
price: z.object({ id: z.string().min(1) }),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Paddle webhook: signature check, then mapping of Paddle's event envelope onto
|
|
2
|
-
// the foundation's normalized events.
|
|
3
|
-
//
|
|
2
|
+
// the foundation's normalized events. `custom_data.tenantId` only locates the
|
|
3
|
+
// tenant's stream; Paddle.js can open checkouts with any customData, so
|
|
4
|
+
// billing-foundation accepts an event only for a checkout in its own ledger.
|
|
4
5
|
|
|
5
6
|
import {
|
|
6
7
|
BillingEventKinds,
|
|
@@ -13,6 +14,7 @@ import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
|
|
|
13
14
|
import type { SecretsContext } from "@cosmicdrift/kumiko-framework/secrets";
|
|
14
15
|
import { parseJsonOrThrow } from "@cosmicdrift/kumiko-framework/utils";
|
|
15
16
|
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
17
|
+
import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
16
18
|
import * as z from "zod";
|
|
17
19
|
import { PADDLE_PROVIDER_NAME } from "./constants.ts";
|
|
18
20
|
import type { PaddleWebhookRuntime } from "./runtime.ts";
|
|
@@ -21,7 +23,6 @@ import {
|
|
|
21
23
|
paddleCustomDataSchema,
|
|
22
24
|
paddleSubscriptionSchema,
|
|
23
25
|
} from "./subscription-state.ts";
|
|
24
|
-
import { boundTenantOf } from "./tenant-binding.ts";
|
|
25
26
|
import { verifyPaddleSignature } from "./verify-webhook.ts";
|
|
26
27
|
|
|
27
28
|
const PADDLE_SUBSCRIPTION_EVENT_TYPES: Readonly<Record<string, SubscriptionEventType>> = {
|
|
@@ -59,6 +60,8 @@ const paddleTransactionSchema = z.object({
|
|
|
59
60
|
|
|
60
61
|
export type PaddleWebhookOptions = {
|
|
61
62
|
readonly priceToTier: Readonly<Record<string, string>>;
|
|
63
|
+
/** Prices a one-off payment may credit; Paddle.js lets a browser open checkouts with any customData. */
|
|
64
|
+
readonly oneOffPriceIds: readonly string[];
|
|
62
65
|
/** Test seam: Unix seconds. Defaults to the wall clock. */
|
|
63
66
|
readonly nowSeconds?: () => number;
|
|
64
67
|
};
|
|
@@ -67,10 +70,17 @@ function currentUnixSeconds(): number {
|
|
|
67
70
|
return Math.floor(Temporal.Now.instant().epochMilliseconds / 1000);
|
|
68
71
|
}
|
|
69
72
|
|
|
73
|
+
export function tenantIdOf(
|
|
74
|
+
customData: Readonly<Record<string, unknown>> | null | undefined,
|
|
75
|
+
): string | undefined {
|
|
76
|
+
const tenantId = customData?.["tenantId"];
|
|
77
|
+
return typeof tenantId === "string" && tenantId.length > 0 ? tenantId : undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
70
80
|
function parsePaymentEvent(
|
|
71
81
|
providerEventId: string,
|
|
72
82
|
data: unknown,
|
|
73
|
-
|
|
83
|
+
oneOffPriceIds: readonly string[],
|
|
74
84
|
): PaymentEvent | null {
|
|
75
85
|
const parsed = paddleTransactionSchema.safeParse(data);
|
|
76
86
|
if (!parsed.success) return null;
|
|
@@ -79,14 +89,20 @@ function parsePaymentEvent(
|
|
|
79
89
|
if (transaction.subscription_id) return null;
|
|
80
90
|
const priceId = transaction.items[0]?.price.id;
|
|
81
91
|
const quantity = transaction.items[0]?.quantity ?? 1;
|
|
82
|
-
const
|
|
83
|
-
if (!
|
|
92
|
+
const tenantId = tenantIdOf(transaction.custom_data);
|
|
93
|
+
if (!tenantId || !priceId || !transaction.customer_id) return null;
|
|
94
|
+
if (!oneOffPriceIds.includes(priceId)) {
|
|
95
|
+
createFallbackLogger("subscription-paddle").warn(
|
|
96
|
+
"paddle one-off transaction dropped: price is not an allowed one-off price",
|
|
97
|
+
{ providerEventId, priceId },
|
|
98
|
+
);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
84
101
|
return {
|
|
85
102
|
kind: BillingEventKinds.payment,
|
|
86
103
|
providerEventId,
|
|
87
104
|
providerName: PADDLE_PROVIDER_NAME,
|
|
88
|
-
tenantId
|
|
89
|
-
...(bound.consentId !== undefined && { consentId: bound.consentId }),
|
|
105
|
+
tenantId,
|
|
90
106
|
providerCheckoutId: transaction.id,
|
|
91
107
|
providerCustomerId: transaction.customer_id,
|
|
92
108
|
priceId,
|
|
@@ -115,21 +131,21 @@ function parseSubscriptionEvent(
|
|
|
115
131
|
type: SubscriptionEventType,
|
|
116
132
|
providerEventAt: string,
|
|
117
133
|
data: unknown,
|
|
118
|
-
|
|
134
|
+
priceToTier: Readonly<Record<string, string>>,
|
|
119
135
|
): SubscriptionEvent | null {
|
|
120
136
|
const parsed = paddleSubscriptionSchema.safeParse(data);
|
|
121
137
|
if (!parsed.success) return null;
|
|
122
138
|
const sub = parsed.data;
|
|
123
|
-
const
|
|
124
|
-
const state = mapPaddleSubscriptionState(sub,
|
|
125
|
-
if (!
|
|
139
|
+
const tenantId = tenantIdOf(sub.custom_data);
|
|
140
|
+
const state = mapPaddleSubscriptionState(sub, priceToTier);
|
|
141
|
+
if (!tenantId || !state) return null;
|
|
126
142
|
warnOnUnexpectedQuantity(providerEventId, sub.items);
|
|
127
143
|
return {
|
|
128
144
|
providerEventId,
|
|
129
145
|
providerName: PADDLE_PROVIDER_NAME,
|
|
130
146
|
type,
|
|
131
|
-
tenantId
|
|
132
|
-
...(
|
|
147
|
+
tenantId,
|
|
148
|
+
...(sub.transaction_id && { providerCheckoutId: sub.transaction_id }),
|
|
133
149
|
providerCustomerId: sub.customer_id,
|
|
134
150
|
providerSubscriptionId: sub.id,
|
|
135
151
|
providerEventAt,
|
|
@@ -137,6 +153,28 @@ function parseSubscriptionEvent(
|
|
|
137
153
|
};
|
|
138
154
|
}
|
|
139
155
|
|
|
156
|
+
// Events whose custom_data still carries the pre-ledger tenantBinding: they belong to a checkout
|
|
157
|
+
// the backfill sweep may not have ledgered yet. Kept beside the event, not on it, because
|
|
158
|
+
// billing-foundation must not know about the legacy binding.
|
|
159
|
+
const legacyBindingEvents = new WeakSet<object>();
|
|
160
|
+
|
|
161
|
+
export function hasLegacyTenantBinding(event: SubscriptionEvent | PaymentEvent): boolean {
|
|
162
|
+
return legacyBindingEvents.has(event);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function markLegacyBinding<T extends SubscriptionEvent | PaymentEvent | null>(
|
|
166
|
+
event: T,
|
|
167
|
+
data: unknown,
|
|
168
|
+
): T {
|
|
169
|
+
if (
|
|
170
|
+
event !== null &&
|
|
171
|
+
typeof propertyOf(propertyOf(data, "custom_data"), "tenantBinding") === "string"
|
|
172
|
+
) {
|
|
173
|
+
legacyBindingEvents.add(event);
|
|
174
|
+
}
|
|
175
|
+
return event;
|
|
176
|
+
}
|
|
177
|
+
|
|
140
178
|
export function verifyAndParsePaddleWebhook(
|
|
141
179
|
runtime: PaddleWebhookRuntime,
|
|
142
180
|
options: PaddleWebhookOptions,
|
|
@@ -149,8 +187,6 @@ export function verifyAndParsePaddleWebhook(
|
|
|
149
187
|
return async (rawBody, headers, systemSecrets) => {
|
|
150
188
|
const secret = await runtime.resolveWebhookSecret(systemSecrets);
|
|
151
189
|
verifyPaddleSignature(rawBody, headers, secret, nowSeconds());
|
|
152
|
-
// After verification only: an unauthenticated request must not trigger a second secret read.
|
|
153
|
-
const bindingKey = await runtime.resolveTenantBindingKey(systemSecrets);
|
|
154
190
|
|
|
155
191
|
// Past verification the body is trusted to be Paddle's; a malformed shape is
|
|
156
192
|
// schema drift, so it is dropped (200 ignored) instead of answered with a 401.
|
|
@@ -160,13 +196,24 @@ export function verifyAndParsePaddleWebhook(
|
|
|
160
196
|
if (!envelope.success) return null;
|
|
161
197
|
|
|
162
198
|
const { event_id: providerEventId, event_type: type, occurred_at, data } = envelope.data;
|
|
163
|
-
if (type === TRANSACTION_COMPLETED)
|
|
199
|
+
if (type === TRANSACTION_COMPLETED) {
|
|
200
|
+
return markLegacyBinding(
|
|
201
|
+
parsePaymentEvent(providerEventId, data, options.oneOffPriceIds),
|
|
202
|
+
data,
|
|
203
|
+
);
|
|
204
|
+
}
|
|
164
205
|
if (!Object.hasOwn(PADDLE_SUBSCRIPTION_EVENT_TYPES, type)) return null;
|
|
165
206
|
const normalizedType = PADDLE_SUBSCRIPTION_EVENT_TYPES[type];
|
|
166
207
|
if (!normalizedType) return null;
|
|
167
|
-
return
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
208
|
+
return markLegacyBinding(
|
|
209
|
+
parseSubscriptionEvent(
|
|
210
|
+
providerEventId,
|
|
211
|
+
normalizedType,
|
|
212
|
+
occurred_at,
|
|
213
|
+
data,
|
|
214
|
+
options.priceToTier,
|
|
215
|
+
),
|
|
216
|
+
data,
|
|
217
|
+
);
|
|
171
218
|
};
|
|
172
219
|
}
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.415.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "customer.subscription.created without a linked checkout session is redelivered while young",
|
|
6
|
+
"detail": "An empty checkout session list for a created event younger than ten minutes answers 503 so Stripe redelivers, instead of dropping the subscription as not in the ledger."
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"version": "0.414.0",
|
|
10
|
+
"type": "breaking",
|
|
11
|
+
"title": "Stripe checkouts are matched by session id, consentId metadata is gone",
|
|
12
|
+
"detail": "`createCheckoutSession` returns the Checkout Session id as `providerCheckoutId`, and `customer.subscription.created` looks up the session of the subscription (`checkout.sessions.list`) to carry that id; if the Stripe API call fails, the webhook replies 503 so Stripe retries; a successful empty list yields a created event without checkout id that is ignored as not in the ledger. Session metadata carries only the tenantId. The new option `clientConfig` passes Stripe SDK client settings, for tests against a local fixture API.",
|
|
13
|
+
"migration": "Open Checkout Sessions from before the upgrade are not in the ledger and their `customer.subscription.created` and payment events are ignored; let them expire or finish first. The API key of the Stripe plugin needs read access to Checkout Sessions."
|
|
14
|
+
},
|
|
2
15
|
{
|
|
3
16
|
"version": "0.388.0",
|
|
4
17
|
"type": "improvement",
|
|
@@ -43,6 +43,7 @@ import {
|
|
|
43
43
|
type FeatureDefinition,
|
|
44
44
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
45
45
|
import { type FeatureWithEnvSchema, featureWithEnvSchema } from "@cosmicdrift/kumiko-framework/env";
|
|
46
|
+
import type Stripe from "stripe";
|
|
46
47
|
import * as z from "zod";
|
|
47
48
|
import { priceEnvSchema } from "../shared/index.ts";
|
|
48
49
|
import {
|
|
@@ -137,6 +138,9 @@ export type SubscriptionStripeOptions = {
|
|
|
137
138
|
* explicit allowlist every one-off checkout is closed, the same
|
|
138
139
|
* fail-closed default `priceToTier` has for mode:"subscription". */
|
|
139
140
|
readonly oneOffPriceIds?: readonly string[];
|
|
141
|
+
/** Stripe SDK client config (host, protocol, retries) — lets tests point the
|
|
142
|
+
* client at a local fixture API. */
|
|
143
|
+
readonly clientConfig?: Stripe.StripeConfig;
|
|
140
144
|
};
|
|
141
145
|
|
|
142
146
|
/**
|
|
@@ -222,6 +226,7 @@ export function createSubscriptionStripeFeature(
|
|
|
222
226
|
...(options.apiKey !== undefined && { apiKey: options.apiKey }),
|
|
223
227
|
...(options.webhookSecret !== undefined && { webhookSecret: options.webhookSecret }),
|
|
224
228
|
},
|
|
229
|
+
...(options.clientConfig !== undefined && { clientConfig: options.clientConfig }),
|
|
225
230
|
});
|
|
226
231
|
|
|
227
232
|
const priceCache = createStripePriceCache();
|
|
@@ -116,7 +116,10 @@ export function createStripeCheckoutSession(
|
|
|
116
116
|
runtime: StripeCtxRuntime,
|
|
117
117
|
{ paymentInvoiceCreation = true }: StripeCheckoutSessionRuntimeOptions = {},
|
|
118
118
|
) {
|
|
119
|
-
return async (
|
|
119
|
+
return async (
|
|
120
|
+
ctx: HandlerContext,
|
|
121
|
+
options: StripeCheckoutOptions,
|
|
122
|
+
): Promise<{ url: string; providerCheckoutId: string }> => {
|
|
120
123
|
// Invariant: without billing-live, no Stripe session may be created
|
|
121
124
|
// (sk_test_-keys in production would otherwise create a test-mode checkout).
|
|
122
125
|
// Throw before every Stripe call. The guard used to be provided by the
|
|
@@ -125,10 +128,7 @@ export function createStripeCheckoutSession(
|
|
|
125
128
|
await runtime.assertBillingLive(ctx);
|
|
126
129
|
const stripe = await runtime.clientForCtx(ctx);
|
|
127
130
|
const mode = options.mode ?? "subscription";
|
|
128
|
-
const metadata = {
|
|
129
|
-
tenantId: options.tenantId,
|
|
130
|
-
...(options.consentId && { consentId: options.consentId }),
|
|
131
|
-
};
|
|
131
|
+
const metadata = { tenantId: options.tenantId };
|
|
132
132
|
|
|
133
133
|
const sessionParams = (
|
|
134
134
|
providerCustomerId: string | undefined,
|
|
@@ -182,7 +182,7 @@ export function createStripeCheckoutSession(
|
|
|
182
182
|
// guards against future API drift.
|
|
183
183
|
throw new Error("subscription-stripe: checkout.sessions.create returned no url");
|
|
184
184
|
}
|
|
185
|
-
return { url: session.url };
|
|
185
|
+
return { url: session.url, providerCheckoutId: session.id };
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
188
|
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
import { UnconfiguredError } from "@cosmicdrift/kumiko-framework/errors";
|
|
36
36
|
import type { SecretsContext } from "@cosmicdrift/kumiko-framework/secrets";
|
|
37
37
|
import Stripe from "stripe";
|
|
38
|
-
import { assertBillingLive } from "../shared/index.ts";
|
|
38
|
+
import { assertBillingLive, isBillingLive } from "../shared/index.ts";
|
|
39
39
|
import { SUBSCRIPTION_STRIPE_FEATURE } from "./constants.ts";
|
|
40
40
|
|
|
41
41
|
const API_KEY_HINT =
|
|
@@ -44,14 +44,16 @@ const API_KEY_HINT =
|
|
|
44
44
|
/** Memoize Stripe clients by api-key string — a fresh client is built only
|
|
45
45
|
* when the key actually changes (rotation), so steady-state calls reuse one
|
|
46
46
|
* connection-pooled instance per key. */
|
|
47
|
-
export function createStripeClientCache(
|
|
47
|
+
export function createStripeClientCache(
|
|
48
|
+
clientConfig?: Stripe.StripeConfig,
|
|
49
|
+
): (apiKey: string) => Stripe {
|
|
48
50
|
const cache = new Map<string, Stripe>();
|
|
49
51
|
return (apiKey) => {
|
|
50
52
|
const cached = cache.get(apiKey);
|
|
51
53
|
if (cached) return cached;
|
|
52
54
|
// No apiVersion pin — a string literal breaks consumers' typecheck on newer
|
|
53
55
|
// stripe SDKs; the SDK's own default keeps wire-version and types aligned.
|
|
54
|
-
const client = new Stripe(apiKey);
|
|
56
|
+
const client = new Stripe(apiKey, clientConfig);
|
|
55
57
|
cache.set(apiKey, client);
|
|
56
58
|
return client;
|
|
57
59
|
};
|
|
@@ -62,6 +64,7 @@ export type StripeRuntimeDeps = {
|
|
|
62
64
|
readonly webhookSecretHandle: ConfigKeyHandle<"text">;
|
|
63
65
|
readonly billingLiveHandle: ConfigKeyHandle<"boolean">;
|
|
64
66
|
readonly fallback: { readonly apiKey?: string; readonly webhookSecret?: string };
|
|
67
|
+
readonly clientConfig?: Stripe.StripeConfig;
|
|
65
68
|
};
|
|
66
69
|
|
|
67
70
|
/** Post-tenant runtime: used by checkout/portal/cancel which carry a full
|
|
@@ -95,7 +98,7 @@ export type StripeRuntimes = {
|
|
|
95
98
|
};
|
|
96
99
|
|
|
97
100
|
export function createStripeRuntimes(deps: StripeRuntimeDeps): StripeRuntimes {
|
|
98
|
-
const clientFor = createStripeClientCache();
|
|
101
|
+
const clientFor = createStripeClientCache(deps.clientConfig);
|
|
99
102
|
|
|
100
103
|
async function ctxApiKey(ctx: HandlerContext): Promise<string> {
|
|
101
104
|
let key: string | undefined;
|
|
@@ -136,13 +139,11 @@ export function createStripeRuntimes(deps: StripeRuntimeDeps): StripeRuntimes {
|
|
|
136
139
|
|
|
137
140
|
return {
|
|
138
141
|
ctx: {
|
|
139
|
-
// @wrapper-known semantic-alias
|
|
140
142
|
clientForCtx: async (ctx) => clientFor(await ctxApiKey(ctx)),
|
|
141
143
|
assertBillingLive: (ctx, handlerName = "create-checkout-session") =>
|
|
142
144
|
assertBillingLive(ctx, deps.billingLiveHandle, SUBSCRIPTION_STRIPE_FEATURE, handlerName),
|
|
143
145
|
isBillingEnabled: async (ctx) => {
|
|
144
|
-
|
|
145
|
-
if (live !== true) return false;
|
|
146
|
+
if (!(await isBillingLive(ctx, deps.billingLiveHandle))) return false;
|
|
146
147
|
const hasFallbackKey =
|
|
147
148
|
deps.fallback.apiKey !== undefined && deps.fallback.apiKey.length > 0;
|
|
148
149
|
if (hasFallbackKey) return true;
|
|
@@ -37,7 +37,6 @@ import type {
|
|
|
37
37
|
} from "@cosmicdrift/kumiko-bundled-features/billing-foundation";
|
|
38
38
|
import {
|
|
39
39
|
BillingEventKinds,
|
|
40
|
-
parseProviderConsentId,
|
|
41
40
|
type SubscriptionEventType,
|
|
42
41
|
SubscriptionEventTypes,
|
|
43
42
|
type SubscriptionStatus,
|
|
@@ -165,13 +164,17 @@ export function verifyAndParseStripeWebhook(
|
|
|
165
164
|
return null;
|
|
166
165
|
}
|
|
167
166
|
|
|
168
|
-
|
|
167
|
+
// Only the checkout ledger can vouch for a new subscription, so `created` must name its session.
|
|
168
|
+
const providerCheckoutId =
|
|
169
|
+
normalizedType === SubscriptionEventTypes.created
|
|
170
|
+
? await findCheckoutSessionId(stripe, sub.id, event.created)
|
|
171
|
+
: undefined;
|
|
169
172
|
return {
|
|
170
173
|
providerEventId: event.id,
|
|
171
174
|
providerName: STRIPE_PROVIDER_NAME,
|
|
172
175
|
type: normalizedType,
|
|
173
176
|
tenantId,
|
|
174
|
-
...(
|
|
177
|
+
...(providerCheckoutId !== undefined && { providerCheckoutId }),
|
|
175
178
|
providerCustomerId: typeof sub.customer === "string" ? sub.customer : sub.customer.id,
|
|
176
179
|
providerSubscriptionId: sub.id,
|
|
177
180
|
providerEventAt: Temporal.Instant.fromEpochMilliseconds(event.created * 1000).toString(),
|
|
@@ -180,6 +183,38 @@ export function verifyAndParseStripeWebhook(
|
|
|
180
183
|
};
|
|
181
184
|
}
|
|
182
185
|
|
|
186
|
+
// Stripe may emit `customer.subscription.created` before the session is linked to the subscription.
|
|
187
|
+
const SESSION_LINK_GRACE_SECONDS = 600;
|
|
188
|
+
|
|
189
|
+
// A failing Stripe API call, or an empty list for a young event, is answered with 503 so Stripe
|
|
190
|
+
// redelivers. An empty list for an older event means the subscription has no checkout session: the
|
|
191
|
+
// created event then carries no checkout id and the foundation ignores it as not in the ledger.
|
|
192
|
+
async function findCheckoutSessionId(
|
|
193
|
+
stripe: Stripe,
|
|
194
|
+
subscriptionId: string,
|
|
195
|
+
eventCreatedSeconds: number,
|
|
196
|
+
): Promise<string | undefined> {
|
|
197
|
+
let sessionId: string | undefined;
|
|
198
|
+
try {
|
|
199
|
+
const sessions = await stripe.checkout.sessions.list({
|
|
200
|
+
subscription: subscriptionId,
|
|
201
|
+
limit: 1,
|
|
202
|
+
});
|
|
203
|
+
sessionId = sessions.data[0]?.id;
|
|
204
|
+
} catch (error) {
|
|
205
|
+
throw transientProviderRejection(error);
|
|
206
|
+
}
|
|
207
|
+
if (sessionId === undefined) {
|
|
208
|
+
const ageSeconds = Temporal.Now.instant().epochMilliseconds / 1000 - eventCreatedSeconds;
|
|
209
|
+
if (ageSeconds < SESSION_LINK_GRACE_SECONDS) {
|
|
210
|
+
throw transientProviderRejection(
|
|
211
|
+
new Error(`no checkout session linked to ${subscriptionId} yet`),
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return sessionId;
|
|
216
|
+
}
|
|
217
|
+
|
|
183
218
|
// =============================================================================
|
|
184
219
|
// Shared subscription-state mapping (webhook + retrieveSubscription)
|
|
185
220
|
// =============================================================================
|
|
@@ -294,7 +329,6 @@ export function mapStripeStatus(stripeStatus: Stripe.Subscription.Status): Subsc
|
|
|
294
329
|
/** Gets the subscription from the event. Subscription events include it
|
|
295
330
|
* directly in data.object; invoice events include only the subscription ID
|
|
296
331
|
* and require a lazy fetch via stripe.subscriptions.retrieve. */
|
|
297
|
-
// @wrapper-known semantic-alias
|
|
298
332
|
async function extractSubscriptionFromEvent(
|
|
299
333
|
event: Stripe.Event,
|
|
300
334
|
stripe: Stripe,
|
|
@@ -423,13 +457,11 @@ async function parsePaymentEvent(
|
|
|
423
457
|
return dropPaidSession(event, session, "missing_customer");
|
|
424
458
|
}
|
|
425
459
|
|
|
426
|
-
const consentId = parseProviderConsentId(paymentIntent.metadata?.["consentId"]);
|
|
427
460
|
return {
|
|
428
461
|
kind: BillingEventKinds.payment,
|
|
429
462
|
providerEventId: event.id,
|
|
430
463
|
providerName: STRIPE_PROVIDER_NAME,
|
|
431
464
|
tenantId,
|
|
432
|
-
...(consentId !== undefined && { consentId }),
|
|
433
465
|
providerCheckoutId: session.id,
|
|
434
466
|
providerCustomerId,
|
|
435
467
|
priceId,
|
|
@@ -12,7 +12,6 @@ const TAG_ASSIGNMENT_NAMESPACE = "a7f3c9d2-1b4e-4c8a-9f6d-2e5b8a1c3f7d";
|
|
|
12
12
|
* stream → version_conflict instead of a duplicate row. The assign handler
|
|
13
13
|
* pre-checks existence to keep re-assign idempotent (TX-safe).
|
|
14
14
|
*/
|
|
15
|
-
// @wrapper-known uuid-domain
|
|
16
15
|
export function tagAssignmentAggregateId(
|
|
17
16
|
tenantId: string,
|
|
18
17
|
tagId: string,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// styles (pattern from config-source-badge.tsx) so it renders the same in the
|
|
6
6
|
// picker, on cards and in screenshots without depending on Tailwind tokens.
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type { ReactNode } from "react";
|
|
9
9
|
|
|
10
10
|
// YIQ perceived brightness → black text on light backgrounds, white on dark.
|
|
11
11
|
// Returns null for anything that isn't a #rgb/#rrggbb hex so the caller can use
|
|
@@ -33,8 +33,7 @@ function hexToRgb(color: string): { r: number; g: number; b: number } | null {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
const BASE_STYLE: CSSProperties = {
|
|
36
|
+
const BASE_STYLE = {
|
|
38
37
|
display: "inline-flex",
|
|
39
38
|
alignItems: "center",
|
|
40
39
|
padding: "0 8px",
|
|
@@ -43,7 +42,7 @@ const BASE_STYLE: CSSProperties = {
|
|
|
43
42
|
lineHeight: "20px",
|
|
44
43
|
borderRadius: "9999px",
|
|
45
44
|
whiteSpace: "nowrap",
|
|
46
|
-
};
|
|
45
|
+
} as const;
|
|
47
46
|
|
|
48
47
|
const NEUTRAL = { backgroundColor: "#e5e7eb", color: "#374151" } as const;
|
|
49
48
|
|
|
@@ -71,7 +70,7 @@ export function TagChip({
|
|
|
71
70
|
const fg = color != null && color !== "" ? contrastText(color) : null;
|
|
72
71
|
const palette = fg !== null && color != null ? { backgroundColor: color, color: fg } : NEUTRAL;
|
|
73
72
|
return (
|
|
74
|
-
//
|
|
73
|
+
// biome-ignore lint/style/noInlineStyles: Tag color is user-defined (hex from the DB), no finite token palette possible
|
|
75
74
|
<span data-testid="tag-chip" style={{ ...BASE_STYLE, ...palette }}>
|
|
76
75
|
{name}
|
|
77
76
|
</span>
|
|
@@ -64,13 +64,14 @@ function ColorPicker({
|
|
|
64
64
|
<div className="flex items-center gap-2">
|
|
65
65
|
<div className="flex flex-wrap gap-1">
|
|
66
66
|
{PRESET_COLORS.map((c) => (
|
|
67
|
-
//
|
|
67
|
+
// biome-ignore lint/plugin: color swatch needs a raw colored button — Button is variant-styled.
|
|
68
68
|
<button
|
|
69
69
|
key={c}
|
|
70
70
|
type="button"
|
|
71
71
|
aria-label={c}
|
|
72
72
|
data-testid={`${idPrefix}-swatch-${c}`}
|
|
73
73
|
onClick={() => onChange(c)}
|
|
74
|
+
// biome-ignore lint/style/noInlineStyles: Preset swatch color is user-defined (hex), no finite token palette possible
|
|
74
75
|
style={{
|
|
75
76
|
width: 22,
|
|
76
77
|
height: 22,
|