@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
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { defineWriteHandler, type HandlerContext } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { InternalError, RateLimitError } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
|
+
import type { TenantId } from "@cosmicdrift/kumiko-types/identifiers";
|
|
4
|
+
import { whatsappMessageAggregateId, whatsappStatusAggregateId } from "./aggregate-id.ts";
|
|
5
|
+
import {
|
|
6
|
+
type MessageReceivedPayload,
|
|
7
|
+
receiveMessageInputSchema,
|
|
8
|
+
recordStatusInputSchema,
|
|
9
|
+
type StatusUpdatedPayload,
|
|
10
|
+
type ThrottledPayload,
|
|
11
|
+
WHATSAPP_MESSAGE_AGGREGATE_TYPE,
|
|
12
|
+
WHATSAPP_MESSAGE_RECEIVED_EVENT_QN,
|
|
13
|
+
WHATSAPP_STATUS_AGGREGATE_TYPE,
|
|
14
|
+
WHATSAPP_STATUS_UPDATED_EVENT_QN,
|
|
15
|
+
WHATSAPP_THROTTLED_EVENT_QN,
|
|
16
|
+
} from "./events.ts";
|
|
17
|
+
import type { ResolvedWhatsappOptions } from "./options.ts";
|
|
18
|
+
import { encryptWhatsappPii, WhatsappPiiFields } from "./pii.ts";
|
|
19
|
+
|
|
20
|
+
export type InboundOutcome = "stored" | "duplicate" | "throttled";
|
|
21
|
+
|
|
22
|
+
type InboundResult = {
|
|
23
|
+
readonly isSuccess: true;
|
|
24
|
+
readonly data: { readonly outcome: InboundOutcome };
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const OUTCOME_STORED: InboundResult = { isSuccess: true, data: { outcome: "stored" } };
|
|
28
|
+
const OUTCOME_DUPLICATE: InboundResult = { isSuccess: true, data: { outcome: "duplicate" } };
|
|
29
|
+
const OUTCOME_THROTTLED: InboundResult = { isSuccess: true, data: { outcome: "throttled" } };
|
|
30
|
+
|
|
31
|
+
type LimitContext = Pick<HandlerContext, "services" | "rateLimitDigest">;
|
|
32
|
+
|
|
33
|
+
// Counts one message against every per-sender window. Only a RateLimitError means "throttled";
|
|
34
|
+
// anything else (Redis down, bad config) propagates so the webhook answers 5xx and Meta redelivers.
|
|
35
|
+
async function chargeSender(
|
|
36
|
+
ctx: LimitContext,
|
|
37
|
+
options: ResolvedWhatsappOptions,
|
|
38
|
+
tenantId: TenantId,
|
|
39
|
+
from: string,
|
|
40
|
+
): Promise<RateLimitError | null> {
|
|
41
|
+
if (options.senderRateLimits.length === 0) return null;
|
|
42
|
+
const { rateLimit } = ctx.services;
|
|
43
|
+
const digest = ctx.rateLimitDigest;
|
|
44
|
+
if (!rateLimit || !digest) {
|
|
45
|
+
throw new InternalError({
|
|
46
|
+
message: "channel-whatsapp: the per-sender limit needs a rate limiter and a digest key",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const senderKey = `whatsapp-inbound:${tenantId}:${digest(from)}`;
|
|
50
|
+
try {
|
|
51
|
+
await rateLimit.enforceAll(
|
|
52
|
+
options.senderRateLimits.map(({ limit, windowSeconds }) => ({
|
|
53
|
+
bucket: `${senderKey}:${windowSeconds}s`,
|
|
54
|
+
config: { limit, windowSeconds },
|
|
55
|
+
})),
|
|
56
|
+
);
|
|
57
|
+
return null;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (error instanceof RateLimitError) return error;
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function createReceiveMessageHandler(options: ResolvedWhatsappOptions) {
|
|
65
|
+
return defineWriteHandler({
|
|
66
|
+
name: "receive-message",
|
|
67
|
+
schema: receiveMessageInputSchema,
|
|
68
|
+
access: { roles: ["SystemAdmin"] },
|
|
69
|
+
rateLimit: options.rateLimit,
|
|
70
|
+
agent: { expose: false },
|
|
71
|
+
description:
|
|
72
|
+
"Stores one inbound WhatsApp message verified by the webhook route as a message-received event; a redelivered wamid is a duplicate, a sender over its limit becomes a throttled event.",
|
|
73
|
+
handler: async (event, ctx) => {
|
|
74
|
+
const input = event.payload;
|
|
75
|
+
const tenantId = event.user.tenantId;
|
|
76
|
+
const aggregateId = whatsappMessageAggregateId(tenantId, input.wamid);
|
|
77
|
+
|
|
78
|
+
// Dedupe before the limit: Meta's redeliveries must not use up the sender's budget.
|
|
79
|
+
if ((await ctx.events.load(aggregateId)).length > 0) return OUTCOME_DUPLICATE;
|
|
80
|
+
|
|
81
|
+
const throttle = await chargeSender(ctx, options, tenantId, input.from);
|
|
82
|
+
const requestId = `channel-whatsapp:receive-message:${aggregateId}`;
|
|
83
|
+
const from = await encryptWhatsappPii(
|
|
84
|
+
tenantId,
|
|
85
|
+
throttle ? WhatsappPiiFields.throttledFrom : WhatsappPiiFields.receivedFrom,
|
|
86
|
+
input.from,
|
|
87
|
+
requestId,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
if (throttle) {
|
|
91
|
+
const payload: ThrottledPayload = {
|
|
92
|
+
phoneNumberId: input.phoneNumberId,
|
|
93
|
+
wamid: input.wamid,
|
|
94
|
+
from,
|
|
95
|
+
timestampIso: input.timestampIso,
|
|
96
|
+
retryAfterSeconds: throttle.details.retryAfterSeconds,
|
|
97
|
+
};
|
|
98
|
+
const appended = await ctx.events.tryAppend({
|
|
99
|
+
aggregateId,
|
|
100
|
+
aggregateType: WHATSAPP_MESSAGE_AGGREGATE_TYPE,
|
|
101
|
+
type: WHATSAPP_THROTTLED_EVENT_QN,
|
|
102
|
+
payload,
|
|
103
|
+
});
|
|
104
|
+
return appended.ok ? OUTCOME_THROTTLED : OUTCOME_DUPLICATE;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const payload: MessageReceivedPayload = {
|
|
108
|
+
phoneNumberId: input.phoneNumberId,
|
|
109
|
+
wamid: input.wamid,
|
|
110
|
+
from,
|
|
111
|
+
timestampIso: input.timestampIso,
|
|
112
|
+
messageType: input.messageType,
|
|
113
|
+
text:
|
|
114
|
+
input.text === null
|
|
115
|
+
? null
|
|
116
|
+
: await encryptWhatsappPii(
|
|
117
|
+
tenantId,
|
|
118
|
+
WhatsappPiiFields.receivedText,
|
|
119
|
+
input.text,
|
|
120
|
+
requestId,
|
|
121
|
+
),
|
|
122
|
+
buttonPayload:
|
|
123
|
+
input.buttonPayload === null
|
|
124
|
+
? null
|
|
125
|
+
: await encryptWhatsappPii(
|
|
126
|
+
tenantId,
|
|
127
|
+
WhatsappPiiFields.receivedButtonPayload,
|
|
128
|
+
input.buttonPayload,
|
|
129
|
+
requestId,
|
|
130
|
+
),
|
|
131
|
+
contextWamid: input.contextWamid,
|
|
132
|
+
mediaId: input.mediaId,
|
|
133
|
+
mimeType: input.mimeType,
|
|
134
|
+
};
|
|
135
|
+
// A concurrent delivery of the same wamid that won the race counts as a duplicate.
|
|
136
|
+
const appended = await ctx.events.tryAppend({
|
|
137
|
+
aggregateId,
|
|
138
|
+
aggregateType: WHATSAPP_MESSAGE_AGGREGATE_TYPE,
|
|
139
|
+
type: WHATSAPP_MESSAGE_RECEIVED_EVENT_QN,
|
|
140
|
+
payload,
|
|
141
|
+
});
|
|
142
|
+
return appended.ok ? OUTCOME_STORED : OUTCOME_DUPLICATE;
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function createRecordStatusHandler(options: ResolvedWhatsappOptions) {
|
|
148
|
+
return defineWriteHandler({
|
|
149
|
+
name: "record-status",
|
|
150
|
+
schema: recordStatusInputSchema,
|
|
151
|
+
access: { roles: ["SystemAdmin"] },
|
|
152
|
+
rateLimit: options.rateLimit,
|
|
153
|
+
agent: { expose: false },
|
|
154
|
+
description:
|
|
155
|
+
"Stores one delivery status (sent, delivered, read, failed) of an outbound WhatsApp message as a status-updated event; a repeated status of the same wamid is a duplicate.",
|
|
156
|
+
handler: async (event, ctx) => {
|
|
157
|
+
const input = event.payload;
|
|
158
|
+
const tenantId = event.user.tenantId;
|
|
159
|
+
const aggregateId = whatsappStatusAggregateId(
|
|
160
|
+
tenantId,
|
|
161
|
+
input.wamid,
|
|
162
|
+
input.status,
|
|
163
|
+
input.rawStatus,
|
|
164
|
+
);
|
|
165
|
+
if ((await ctx.events.load(aggregateId)).length > 0) return OUTCOME_DUPLICATE;
|
|
166
|
+
|
|
167
|
+
const payload: StatusUpdatedPayload = {
|
|
168
|
+
phoneNumberId: input.phoneNumberId,
|
|
169
|
+
wamid: input.wamid,
|
|
170
|
+
status: input.status,
|
|
171
|
+
timestampIso: input.timestampIso,
|
|
172
|
+
recipient: await encryptWhatsappPii(
|
|
173
|
+
tenantId,
|
|
174
|
+
WhatsappPiiFields.statusRecipient,
|
|
175
|
+
input.recipient,
|
|
176
|
+
`channel-whatsapp:record-status:${aggregateId}`,
|
|
177
|
+
),
|
|
178
|
+
errorCode: input.errorCode,
|
|
179
|
+
};
|
|
180
|
+
const appended = await ctx.events.tryAppend({
|
|
181
|
+
aggregateId,
|
|
182
|
+
aggregateType: WHATSAPP_STATUS_AGGREGATE_TYPE,
|
|
183
|
+
type: WHATSAPP_STATUS_UPDATED_EVENT_QN,
|
|
184
|
+
payload,
|
|
185
|
+
});
|
|
186
|
+
return appended.ok ? OUTCOME_STORED : OUTCOME_DUPLICATE;
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export { whatsappMessageAggregateId, whatsappStatusAggregateId } from "./aggregate-id.ts";
|
|
2
|
+
export {
|
|
3
|
+
CHANNEL_WHATSAPP_FEATURE,
|
|
4
|
+
WHATSAPP_DEFAULT_ALLOWED_HOSTS,
|
|
5
|
+
WHATSAPP_DEFAULT_API_BASE_URL,
|
|
6
|
+
WHATSAPP_DEFAULT_WEBHOOK_PATH,
|
|
7
|
+
WHATSAPP_OUTSIDE_WINDOW_ERROR_CODE,
|
|
8
|
+
WHATSAPP_SECRET_KEYS,
|
|
9
|
+
type WhatsappMessageType,
|
|
10
|
+
type WhatsappStatusKind,
|
|
11
|
+
} from "./constants.ts";
|
|
12
|
+
export {
|
|
13
|
+
type MessageReceivedPayload,
|
|
14
|
+
type StatusUpdatedPayload,
|
|
15
|
+
type ThrottledPayload,
|
|
16
|
+
WHATSAPP_MESSAGE_RECEIVED_EVENT_QN,
|
|
17
|
+
WHATSAPP_STATUS_UPDATED_EVENT_QN,
|
|
18
|
+
WHATSAPP_THROTTLED_EVENT_QN,
|
|
19
|
+
} from "./events.ts";
|
|
20
|
+
export { createChannelWhatsappFeature } from "./feature.ts";
|
|
21
|
+
export {
|
|
22
|
+
buildWhatsappClient,
|
|
23
|
+
createWhatsappClient,
|
|
24
|
+
type WhatsappButtonsInput,
|
|
25
|
+
type WhatsappCallContext,
|
|
26
|
+
type WhatsappClient,
|
|
27
|
+
type WhatsappMediaFailure,
|
|
28
|
+
type WhatsappMediaInput,
|
|
29
|
+
type WhatsappMediaResult,
|
|
30
|
+
type WhatsappReplyButton,
|
|
31
|
+
type WhatsappSendFailure,
|
|
32
|
+
type WhatsappSendResult,
|
|
33
|
+
type WhatsappTemplateInput,
|
|
34
|
+
type WhatsappTextInput,
|
|
35
|
+
} from "./graph-client.ts";
|
|
36
|
+
export {
|
|
37
|
+
createInMemoryMeta,
|
|
38
|
+
deliverMetaWebhook,
|
|
39
|
+
type InMemoryMeta,
|
|
40
|
+
type InMemoryMetaRejection,
|
|
41
|
+
type InMemoryMetaRequest,
|
|
42
|
+
type InMemoryMetaSentMessage,
|
|
43
|
+
metaButtonReplyMessage,
|
|
44
|
+
metaMediaMessage,
|
|
45
|
+
metaStatus,
|
|
46
|
+
metaTextMessage,
|
|
47
|
+
metaWebhookPayload,
|
|
48
|
+
requestMetaVerification,
|
|
49
|
+
} from "./in-memory-meta.ts";
|
|
50
|
+
export { signMetaBody } from "./meta-signature.ts";
|
|
51
|
+
export {
|
|
52
|
+
type ChannelWhatsappOptions,
|
|
53
|
+
DEFAULT_WHATSAPP_INBOUND_RATE_LIMIT,
|
|
54
|
+
DEFAULT_WHATSAPP_SENDER_RATE_LIMITS,
|
|
55
|
+
type WhatsappSenderRateLimit,
|
|
56
|
+
type WhatsappTransport,
|
|
57
|
+
} from "./options.ts";
|
|
58
|
+
export {
|
|
59
|
+
type DecryptedWhatsappMessage,
|
|
60
|
+
type DecryptedWhatsappStatus,
|
|
61
|
+
type DecryptedWhatsappThrottled,
|
|
62
|
+
readWhatsappMessagePii,
|
|
63
|
+
readWhatsappStatusPii,
|
|
64
|
+
readWhatsappThrottledPii,
|
|
65
|
+
} from "./pii.ts";
|
|
66
|
+
export { createWhatsappWebhookRoutes, type WhatsappWebhookRouteOptions } from "./webhook-routes.ts";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
const SIGNATURE_HEADER_PATTERN = /^sha256=([0-9a-f]{64})$/i;
|
|
4
|
+
|
|
5
|
+
/** Meta's `X-Hub-Signature-256` value for a raw body: `sha256=<hex HMAC with the app secret>`. */
|
|
6
|
+
export function signMetaBody(appSecret: string, rawBody: string): string {
|
|
7
|
+
return `sha256=${createHmac("sha256", appSecret).update(rawBody, "utf8").digest("hex")}`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function isValidMetaSignature(
|
|
11
|
+
appSecret: string,
|
|
12
|
+
rawBody: string,
|
|
13
|
+
header: string | undefined,
|
|
14
|
+
): boolean {
|
|
15
|
+
const match = header === undefined ? null : SIGNATURE_HEADER_PATTERN.exec(header.trim());
|
|
16
|
+
if (match === null) return false;
|
|
17
|
+
const received = Buffer.from((match[1] ?? "").toLowerCase(), "hex");
|
|
18
|
+
const expected = createHmac("sha256", appSecret).update(rawBody, "utf8").digest();
|
|
19
|
+
return received.length === expected.length && timingSafeEqual(received, expected);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Hashing first gives both sides one length, so the comparison leaks nothing about the secret's length. */
|
|
23
|
+
export function secretsMatch(candidate: string, secret: string): boolean {
|
|
24
|
+
const digestOf = (value: string) => createHash("sha256").update(value, "utf8").digest();
|
|
25
|
+
return timingSafeEqual(digestOf(candidate), digestOf(secret));
|
|
26
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { isRateLimitDisabled, type RateLimitDeclaration } from "@cosmicdrift/kumiko-types/handlers";
|
|
2
|
+
import { checkChatWebhookTarget } from "../delivery/index.ts";
|
|
3
|
+
import {
|
|
4
|
+
WHATSAPP_DEFAULT_ALLOWED_HOSTS,
|
|
5
|
+
WHATSAPP_DEFAULT_API_BASE_URL,
|
|
6
|
+
WHATSAPP_DEFAULT_API_VERSION,
|
|
7
|
+
WHATSAPP_DEFAULT_MEDIA_MAX_BYTES,
|
|
8
|
+
WHATSAPP_DEFAULT_TIMEOUT_MS,
|
|
9
|
+
} from "./constants.ts";
|
|
10
|
+
|
|
11
|
+
export type WhatsappTransport = (url: string, init: RequestInit) => Promise<Response>;
|
|
12
|
+
|
|
13
|
+
/** Limit on messages per sender number, counted inside the inbound write handler. */
|
|
14
|
+
export type WhatsappSenderRateLimit = {
|
|
15
|
+
readonly limit: number;
|
|
16
|
+
readonly windowSeconds: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type ChannelWhatsappOptions = {
|
|
20
|
+
// App-level override (tests, proxies); never tenant config. Its host must be in `allowedHosts`.
|
|
21
|
+
readonly apiBaseUrl?: string;
|
|
22
|
+
readonly apiVersion?: string;
|
|
23
|
+
// Replaces the default allowlist; applies to the Graph host AND to the media URL Meta returns.
|
|
24
|
+
readonly allowedHosts?: readonly string[];
|
|
25
|
+
// Default true; `false` only for local http servers.
|
|
26
|
+
readonly requireHttps?: boolean;
|
|
27
|
+
readonly timeoutMs?: number;
|
|
28
|
+
readonly mediaMaxBytes?: number;
|
|
29
|
+
// Replaces the network call (the in-memory Meta); host and https checks still run before it.
|
|
30
|
+
readonly transport?: WhatsappTransport;
|
|
31
|
+
// Per sender number and tenant; an empty list switches the per-sender limit off.
|
|
32
|
+
readonly senderRateLimits?: readonly WhatsappSenderRateLimit[];
|
|
33
|
+
// Coarse flood guard of the inbound write handlers (per tenant and handler).
|
|
34
|
+
readonly rateLimit?: RateLimitDeclaration;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type ResolvedWhatsappOptions = {
|
|
38
|
+
readonly apiBaseUrl: string;
|
|
39
|
+
readonly apiVersion: string;
|
|
40
|
+
readonly allowedHosts: readonly string[];
|
|
41
|
+
readonly requireHttps: boolean;
|
|
42
|
+
readonly timeoutMs: number;
|
|
43
|
+
readonly mediaMaxBytes: number;
|
|
44
|
+
readonly transport: WhatsappTransport | undefined;
|
|
45
|
+
readonly senderRateLimits: readonly WhatsappSenderRateLimit[];
|
|
46
|
+
readonly rateLimit: RateLimitDeclaration;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const DEFAULT_WHATSAPP_SENDER_RATE_LIMITS: readonly WhatsappSenderRateLimit[] = [
|
|
50
|
+
{ limit: 30, windowSeconds: 60 * 60 },
|
|
51
|
+
{ limit: 200, windowSeconds: 24 * 60 * 60 },
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
export const DEFAULT_WHATSAPP_INBOUND_RATE_LIMIT: RateLimitDeclaration = {
|
|
55
|
+
per: "tenant+handler",
|
|
56
|
+
limit: 12_000,
|
|
57
|
+
windowSeconds: 60,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const API_VERSION_PATTERN = /^v\d+\.\d+$/;
|
|
61
|
+
|
|
62
|
+
function isPositiveInteger(value: number): boolean {
|
|
63
|
+
return Number.isInteger(value) && value > 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Fail at boot: a misconfigured base URL must not surface as per-send failures.
|
|
67
|
+
function assertApiBaseUrl(
|
|
68
|
+
apiBaseUrl: string,
|
|
69
|
+
allowedHosts: readonly string[],
|
|
70
|
+
requireHttps: boolean,
|
|
71
|
+
): void {
|
|
72
|
+
let parsedBase: URL;
|
|
73
|
+
try {
|
|
74
|
+
parsedBase = new URL(apiBaseUrl);
|
|
75
|
+
} catch {
|
|
76
|
+
throw new Error("channel-whatsapp: apiBaseUrl is not a valid URL");
|
|
77
|
+
}
|
|
78
|
+
// The same check the sends run at runtime, so boot and runtime cannot disagree.
|
|
79
|
+
if (checkChatWebhookTarget({ allowedHosts, requireHttps }, apiBaseUrl) !== undefined) return;
|
|
80
|
+
if (requireHttps && parsedBase.protocol !== "https:") {
|
|
81
|
+
throw new Error(
|
|
82
|
+
"channel-whatsapp: apiBaseUrl must use https (set requireHttps: false to opt out)",
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
if (requireHttps && parsedBase.port !== "") {
|
|
86
|
+
throw new Error("channel-whatsapp: apiBaseUrl must not carry a port while requireHttps is set");
|
|
87
|
+
}
|
|
88
|
+
if (parsedBase.username !== "" || parsedBase.password !== "") {
|
|
89
|
+
throw new Error("channel-whatsapp: apiBaseUrl must not carry credentials");
|
|
90
|
+
}
|
|
91
|
+
throw new Error(
|
|
92
|
+
`channel-whatsapp: apiBaseUrl host "${parsedBase.hostname}" is not in allowedHosts`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function assertRateLimits(
|
|
97
|
+
senderRateLimits: readonly WhatsappSenderRateLimit[],
|
|
98
|
+
rateLimit: RateLimitDeclaration,
|
|
99
|
+
): void {
|
|
100
|
+
for (const { limit, windowSeconds } of senderRateLimits) {
|
|
101
|
+
if (!isPositiveInteger(limit) || !isPositiveInteger(windowSeconds)) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
"channel-whatsapp: senderRateLimits entries need a positive integer limit and windowSeconds",
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// A disabled flood guard would leave the handler without a declared limit and the
|
|
108
|
+
// per-sender counting without the resolver the declaration makes the engine build.
|
|
109
|
+
if (isRateLimitDisabled(rateLimit) && senderRateLimits.length > 0) {
|
|
110
|
+
throw new Error(
|
|
111
|
+
"channel-whatsapp: rateLimit cannot be disabled while senderRateLimits is set (pass senderRateLimits: [] to switch both off)",
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function resolveWhatsappOptions(options: ChannelWhatsappOptions): ResolvedWhatsappOptions {
|
|
117
|
+
const apiBaseUrl = (options.apiBaseUrl ?? WHATSAPP_DEFAULT_API_BASE_URL).replace(/\/+$/, "");
|
|
118
|
+
const apiVersion = options.apiVersion ?? WHATSAPP_DEFAULT_API_VERSION;
|
|
119
|
+
const allowedHosts = options.allowedHosts ?? WHATSAPP_DEFAULT_ALLOWED_HOSTS;
|
|
120
|
+
const requireHttps = options.requireHttps ?? true;
|
|
121
|
+
const senderRateLimits = options.senderRateLimits ?? DEFAULT_WHATSAPP_SENDER_RATE_LIMITS;
|
|
122
|
+
const rateLimit = options.rateLimit ?? DEFAULT_WHATSAPP_INBOUND_RATE_LIMIT;
|
|
123
|
+
|
|
124
|
+
assertApiBaseUrl(apiBaseUrl, allowedHosts, requireHttps);
|
|
125
|
+
if (!API_VERSION_PATTERN.test(apiVersion)) {
|
|
126
|
+
throw new Error('channel-whatsapp: apiVersion must look like "v21.0"');
|
|
127
|
+
}
|
|
128
|
+
assertRateLimits(senderRateLimits, rateLimit);
|
|
129
|
+
const timeoutMs = options.timeoutMs ?? WHATSAPP_DEFAULT_TIMEOUT_MS;
|
|
130
|
+
const mediaMaxBytes = options.mediaMaxBytes ?? WHATSAPP_DEFAULT_MEDIA_MAX_BYTES;
|
|
131
|
+
if (!isPositiveInteger(timeoutMs)) {
|
|
132
|
+
throw new Error("channel-whatsapp: timeoutMs must be a positive integer");
|
|
133
|
+
}
|
|
134
|
+
if (!isPositiveInteger(mediaMaxBytes)) {
|
|
135
|
+
throw new Error("channel-whatsapp: mediaMaxBytes must be a positive integer");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
apiBaseUrl,
|
|
140
|
+
apiVersion,
|
|
141
|
+
allowedHosts,
|
|
142
|
+
requireHttps,
|
|
143
|
+
timeoutMs,
|
|
144
|
+
mediaMaxBytes,
|
|
145
|
+
transport: options.transport,
|
|
146
|
+
senderRateLimits,
|
|
147
|
+
rateLimit,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
configuredPiiSubjectKms,
|
|
3
|
+
decryptPiiValueForSubject,
|
|
4
|
+
encryptPiiValueForSubject,
|
|
5
|
+
} from "@cosmicdrift/kumiko-framework/crypto";
|
|
6
|
+
import type { TenantId } from "@cosmicdrift/kumiko-types/identifiers";
|
|
7
|
+
import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
8
|
+
|
|
9
|
+
// The sender has no user account, so the tenant key is the subject (as for inbound mail):
|
|
10
|
+
// destroying the tenant shreds the key and every stored number, text and payload with it.
|
|
11
|
+
// The field name is part of the ciphertext's AAD and must match between encrypt and decrypt.
|
|
12
|
+
export const WhatsappPiiFields = {
|
|
13
|
+
receivedFrom: "channel-whatsapp.message-received.from",
|
|
14
|
+
receivedText: "channel-whatsapp.message-received.text",
|
|
15
|
+
receivedButtonPayload: "channel-whatsapp.message-received.buttonPayload",
|
|
16
|
+
statusRecipient: "channel-whatsapp.status-updated.recipient",
|
|
17
|
+
throttledFrom: "channel-whatsapp.throttled.from",
|
|
18
|
+
} as const;
|
|
19
|
+
|
|
20
|
+
export type WhatsappPiiField = (typeof WhatsappPiiFields)[keyof typeof WhatsappPiiFields];
|
|
21
|
+
|
|
22
|
+
/** Without a configured PII KMS the value passes through, like every other event-sourced inbound path. */
|
|
23
|
+
export async function encryptWhatsappPii(
|
|
24
|
+
tenantId: TenantId,
|
|
25
|
+
field: WhatsappPiiField,
|
|
26
|
+
value: string,
|
|
27
|
+
requestId: string,
|
|
28
|
+
): Promise<string> {
|
|
29
|
+
const kms = configuredPiiSubjectKms();
|
|
30
|
+
if (!kms) return value;
|
|
31
|
+
return encryptPiiValueForSubject(
|
|
32
|
+
kms,
|
|
33
|
+
{ kind: "tenant", tenantId },
|
|
34
|
+
value,
|
|
35
|
+
{ requestId, tenantId },
|
|
36
|
+
field,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function decryptWhatsappPii(
|
|
41
|
+
tenantId: TenantId,
|
|
42
|
+
field: WhatsappPiiField,
|
|
43
|
+
value: string,
|
|
44
|
+
): Promise<string> {
|
|
45
|
+
const kms = configuredPiiSubjectKms();
|
|
46
|
+
if (!kms) return value;
|
|
47
|
+
return decryptPiiValueForSubject(
|
|
48
|
+
kms,
|
|
49
|
+
value,
|
|
50
|
+
{ requestId: `channel-whatsapp:decrypt:${field}`, tenantId },
|
|
51
|
+
field,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type DecryptedWhatsappMessage = {
|
|
56
|
+
readonly from: string;
|
|
57
|
+
readonly text: string | null;
|
|
58
|
+
readonly buttonPayload: string | null;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type DecryptedWhatsappStatus = { readonly recipient: string };
|
|
62
|
+
export type DecryptedWhatsappThrottled = { readonly from: string };
|
|
63
|
+
|
|
64
|
+
/** Plaintext recipient of a `status-updated` event payload. */
|
|
65
|
+
export async function readWhatsappStatusPii(
|
|
66
|
+
tenantId: TenantId,
|
|
67
|
+
payload: unknown,
|
|
68
|
+
): Promise<DecryptedWhatsappStatus> {
|
|
69
|
+
const recipient = propertyOf(payload, "recipient");
|
|
70
|
+
if (typeof recipient !== "string") throw new Error("channel-whatsapp: payload has no recipient");
|
|
71
|
+
return {
|
|
72
|
+
recipient: await decryptWhatsappPii(tenantId, WhatsappPiiFields.statusRecipient, recipient),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Plaintext sender of a `throttled` event payload. */
|
|
77
|
+
export async function readWhatsappThrottledPii(
|
|
78
|
+
tenantId: TenantId,
|
|
79
|
+
payload: unknown,
|
|
80
|
+
): Promise<DecryptedWhatsappThrottled> {
|
|
81
|
+
const from = propertyOf(payload, "from");
|
|
82
|
+
if (typeof from !== "string") throw new Error("channel-whatsapp: payload has no sender");
|
|
83
|
+
return { from: await decryptWhatsappPii(tenantId, WhatsappPiiFields.throttledFrom, from) };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Plaintext of the PII fields of a `message-received` event payload, for the consumer.
|
|
88
|
+
* A tenant that was destroyed yields the erased sentinel instead of the value.
|
|
89
|
+
*/
|
|
90
|
+
export async function readWhatsappMessagePii(
|
|
91
|
+
tenantId: TenantId,
|
|
92
|
+
payload: unknown,
|
|
93
|
+
): Promise<DecryptedWhatsappMessage> {
|
|
94
|
+
const from = propertyOf(payload, "from");
|
|
95
|
+
const text = propertyOf(payload, "text");
|
|
96
|
+
const buttonPayload = propertyOf(payload, "buttonPayload");
|
|
97
|
+
if (typeof from !== "string") throw new Error("channel-whatsapp: payload has no sender");
|
|
98
|
+
return {
|
|
99
|
+
from: await decryptWhatsappPii(tenantId, WhatsappPiiFields.receivedFrom, from),
|
|
100
|
+
text:
|
|
101
|
+
typeof text === "string"
|
|
102
|
+
? await decryptWhatsappPii(tenantId, WhatsappPiiFields.receivedText, text)
|
|
103
|
+
: null,
|
|
104
|
+
buttonPayload:
|
|
105
|
+
typeof buttonPayload === "string"
|
|
106
|
+
? await decryptWhatsappPii(tenantId, WhatsappPiiFields.receivedButtonPayload, buttonPayload)
|
|
107
|
+
: null,
|
|
108
|
+
};
|
|
109
|
+
}
|