@cosmicdrift/kumiko-bundled-features 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/dist/admin-shell/feature.js +2 -2
- package/dist/agent-tools/agent-doc-lint.js +2 -1
- package/dist/agent-tools/agent-manifest.js +33 -25
- package/dist/agent-tools/api-docs/collect-events.js +4 -1
- package/dist/agent-tools/api-docs/collect.js +3 -3
- package/dist/agent-tools/api-docs/generate.js +4 -1
- package/dist/agent-tools/api-docs/index.d.ts +1 -0
- package/dist/agent-tools/api-docs/index.js +1 -0
- package/dist/agent-tools/api-docs/problems.d.ts +21 -0
- package/dist/agent-tools/api-docs/problems.js +11 -1
- package/dist/agent-tools/api-docs/render-openapi.js +2 -0
- package/dist/agent-tools/api-docs/resolve-config.d.ts +9 -0
- package/dist/agent-tools/api-docs/resolve-config.js +11 -0
- package/dist/agent-tools/api-docs/scope-slug-collisions.d.ts +4 -0
- package/dist/agent-tools/api-docs/scope-slug-collisions.js +10 -0
- package/dist/agent-tools/api-docs/translation-gaps.d.ts +4 -0
- package/dist/agent-tools/api-docs/translation-gaps.js +29 -0
- package/dist/agent-tools/api-docs/webhook-example-problems.d.ts +6 -0
- package/dist/agent-tools/api-docs/webhook-example-problems.js +25 -0
- package/dist/agent-tools/index.d.ts +1 -1
- package/dist/agent-tools/index.js +1 -1
- package/dist/agent-tools/labels.d.ts +3 -2
- package/dist/agent-tools/labels.js +21 -4
- package/dist/agent-tools/tool-catalog.d.ts +5 -5
- package/dist/agent-tools/tool-catalog.js +12 -10
- package/dist/agent-tools/tool-dispatch.js +11 -1
- package/dist/agent-tools/types.d.ts +4 -0
- package/dist/audit/event-classification.js +6 -0
- package/dist/audit/web/i18n.js +1 -0
- package/dist/auth-email-password/errors.js +0 -13
- package/dist/auth-email-password/handlers/invite-signup-complete.write.js +101 -84
- package/dist/auth-email-password/handlers/login-options.query.js +1 -1
- package/dist/auth-email-password/handlers/request-account-unlock.write.js +1 -1
- package/dist/auth-email-password/handlers/request-email-verification.write.js +0 -1
- package/dist/auth-email-password/handlers/request-password-reset.write.js +0 -1
- package/dist/auth-email-password/handlers/self-registration-status.query.js +1 -1
- package/dist/auth-email-password/reset-token.js +0 -2
- package/dist/auth-email-password/seeding.js +34 -8
- package/dist/auth-email-password/signup-token-store.d.ts +2 -2
- package/dist/auth-email-password/signup-token-store.js +2 -4
- package/dist/auth-email-password/unlock-token.js +0 -2
- package/dist/auth-email-password/verification-token.js +0 -2
- package/dist/auth-email-password/web/auth-form-primitives.js +2 -2
- package/dist/auth-email-password/web/auth-gate.js +2 -2
- package/dist/auth-email-password/web/auth-redirect.d.ts +1 -0
- package/dist/auth-email-password/web/auth-redirect.js +4 -0
- package/dist/auth-email-password/web/forgot-password-screen.js +1 -5
- package/dist/auth-email-password/web/invite-accept-screen.js +1 -1
- package/dist/auth-email-password/web/return-path.d.ts +2 -1
- package/dist/auth-email-password/web/return-path.js +2 -1
- package/dist/auth-email-password/web/session.js +13 -13
- package/dist/auth-email-password/web/signup-screen.js +1 -5
- package/dist/auth-email-password/web/static-account.js +6 -2
- package/dist/auth-email-password/web/token-confirm-screen.js +4 -5
- package/dist/auth-mfa/web/mfa-code-or-recovery-field.d.ts +6 -1
- package/dist/auth-mfa/web/mfa-code-or-recovery-field.js +4 -2
- package/dist/auth-mfa/web/mfa-disable-dialog.js +1 -1
- package/dist/auth-mfa/web/mfa-regenerate-recovery-dialog.js +1 -1
- package/dist/auth-mfa/web/mfa-setup-preauth-screen.js +1 -1
- package/dist/auth-mfa/web/mfa-verify-screen.js +7 -11
- package/dist/auth-mfa-user-data/index.js +5 -6
- package/dist/billing-foundation/aggregate-id.js +0 -4
- package/dist/billing-foundation/checkout-core.d.ts +2 -0
- package/dist/billing-foundation/checkout-core.js +17 -1
- package/dist/billing-foundation/checkout-ledger.d.ts +22 -0
- package/dist/billing-foundation/checkout-ledger.js +38 -0
- package/dist/billing-foundation/consumer-protection/consent-gate.d.ts +1 -1
- package/dist/billing-foundation/consumer-protection/consent-gate.js +2 -2
- package/dist/billing-foundation/consumer-protection/consent-text.d.ts +6 -2
- package/dist/billing-foundation/consumer-protection/consent-text.js +29 -3
- package/dist/billing-foundation/consumer-protection/termination-open-cancels.d.ts +2 -1
- package/dist/billing-foundation/consumer-protection/termination-open-cancels.js +5 -1
- package/dist/billing-foundation/consumer-protection/termination-provider-timeout.d.ts +2 -0
- package/dist/billing-foundation/consumer-protection/termination-provider-timeout.js +17 -0
- package/dist/billing-foundation/consumer-protection/termination-record.js +5 -4
- package/dist/billing-foundation/consumer-protection/termination-revoke.js +1 -1
- package/dist/billing-foundation/events.d.ts +23 -0
- package/dist/billing-foundation/events.js +39 -10
- package/dist/billing-foundation/feature.js +12 -1
- package/dist/billing-foundation/handlers/billing-plans.query.js +25 -15
- package/dist/billing-foundation/handlers/create-checkout-session.write.js +3 -2
- package/dist/billing-foundation/handlers/process-event.write.d.ts +4 -2
- package/dist/billing-foundation/handlers/process-event.write.js +132 -25
- package/dist/billing-foundation/handlers/process-payment-event.write.d.ts +1 -2
- package/dist/billing-foundation/handlers/process-payment-event.write.js +31 -11
- package/dist/billing-foundation/handlers/record-checkout-opened.write.d.ts +2 -0
- package/dist/billing-foundation/handlers/record-checkout-opened.write.js +22 -0
- package/dist/billing-foundation/handlers/start-plan-checkout.write.js +3 -2
- package/dist/billing-foundation/handlers/switch-plan.write.js +10 -4
- package/dist/billing-foundation/i18n.js +3 -0
- package/dist/billing-foundation/pending-plan-switch.d.ts +12 -0
- package/dist/billing-foundation/pending-plan-switch.js +57 -0
- package/dist/billing-foundation/scrub-raw-payload-headers.d.ts +4 -0
- package/dist/billing-foundation/scrub-raw-payload-headers.js +33 -0
- package/dist/billing-foundation/types.d.ts +40 -24
- package/dist/billing-foundation/validate-options.js +14 -0
- package/dist/billing-foundation/web/billing-plans-panel.js +8 -3
- package/dist/billing-foundation/web/cancel-contract-dialog.js +1 -1
- package/dist/billing-foundation/web/checkout-consent-dialog.js +1 -1
- package/dist/billing-foundation/web/constants.d.ts +3 -0
- package/dist/billing-foundation/web/constants.js +5 -2
- package/dist/billing-foundation/web/plan-switch-confirm-dialog.js +1 -1
- package/dist/billing-foundation/webhook-handler.js +53 -11
- package/dist/cap-counter/aggregate-id.js +0 -2
- package/dist/cap-counter/stock-cap-guard.d.ts +1 -0
- package/dist/cap-counter/stock-cap-guard.js +18 -4
- package/dist/cap-overview/handlers/tenant-caps-list.query.js +18 -4
- package/dist/cap-overview/i18n.js +1 -0
- package/dist/cap-overview/index.d.ts +1 -1
- package/dist/cap-overview/types.d.ts +4 -0
- package/dist/cap-overview/web/cap-cards-panel.js +6 -2
- package/dist/cap-overview/web/cap-usage-bar.js +6 -1
- package/dist/cap-overview/web/usage-math.d.ts +1 -0
- package/dist/cap-overview/web/usage-math.js +4 -0
- package/dist/channel-in-app/handlers/read-state-by-keys.query.js +2 -2
- package/dist/channel-whatsapp/aggregate-id.d.ts +8 -0
- package/dist/channel-whatsapp/aggregate-id.js +18 -0
- package/dist/channel-whatsapp/constants.d.ts +25 -0
- package/dist/channel-whatsapp/constants.js +36 -0
- package/dist/channel-whatsapp/events.d.ts +90 -0
- package/dist/channel-whatsapp/events.js +71 -0
- package/dist/channel-whatsapp/feature.d.ts +3 -0
- package/dist/channel-whatsapp/feature.js +56 -0
- package/dist/channel-whatsapp/graph-client.d.ts +85 -0
- package/dist/channel-whatsapp/graph-client.js +272 -0
- package/dist/channel-whatsapp/in-memory-meta.d.ts +83 -0
- package/dist/channel-whatsapp/in-memory-meta.js +181 -0
- package/dist/channel-whatsapp/inbound-handlers.d.ts +39 -0
- package/dist/channel-whatsapp/inbound-handlers.js +148 -0
- package/dist/channel-whatsapp/index.d.ts +10 -0
- package/dist/channel-whatsapp/index.js +10 -0
- package/dist/channel-whatsapp/meta-signature.d.ts +5 -0
- package/dist/channel-whatsapp/meta-signature.js +19 -0
- package/dist/channel-whatsapp/options.d.ts +32 -0
- package/dist/channel-whatsapp/options.js +83 -0
- package/dist/channel-whatsapp/pii.d.ts +32 -0
- package/dist/channel-whatsapp/pii.js +61 -0
- package/dist/channel-whatsapp/webhook-normalize.d.ts +7 -0
- package/dist/channel-whatsapp/webhook-normalize.js +200 -0
- package/dist/channel-whatsapp/webhook-routes.d.ts +10 -0
- package/dist/channel-whatsapp/webhook-routes.js +118 -0
- package/dist/compliance-profiles/handlers/set-profile.write.js +2 -0
- package/dist/compliance-profiles/handlers/sub-processors.query.js +1 -1
- package/dist/config/handlers/set.write.js +7 -0
- package/dist/config/handlers/values.query.js +8 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/read-redaction.d.ts +1 -0
- package/dist/config/read-redaction.js +5 -2
- package/dist/config/table.js +1 -0
- package/dist/config/write-helpers.js +3 -2
- package/dist/crypto-shredding/constants.d.ts +1 -0
- package/dist/crypto-shredding/constants.js +1 -0
- package/dist/crypto-shredding/handlers/forget-subject.write.js +34 -13
- package/dist/crypto-shredding/index.d.ts +1 -0
- package/dist/crypto-shredding/index.js +1 -0
- package/dist/crypto-shredding/subject-forget-after-delete-hook.d.ts +12 -0
- package/dist/crypto-shredding/subject-forget-after-delete-hook.js +38 -0
- package/dist/custom-fields/aggregate-id.js +0 -1
- package/dist/custom-fields/entity.js +1 -0
- package/dist/custom-fields/wire-for-entity.js +0 -1
- package/dist/data-retention/erase-notes-of-deleted-row.d.ts +9 -0
- package/dist/data-retention/erase-notes-of-deleted-row.js +15 -0
- package/dist/data-retention/feature.js +2 -5
- package/dist/data-retention/run-retention-cleanup.d.ts +1 -0
- package/dist/data-retention/run-retention-cleanup.js +39 -19
- package/dist/data-retention/tenant-destruction-hold.js +7 -0
- package/dist/delivery/attempt-log-factory.d.ts +3 -0
- package/dist/delivery/attempt-log-factory.js +5 -0
- package/dist/delivery/attempt-log.d.ts +2 -2
- package/dist/delivery/channel-context.d.ts +1 -1
- package/dist/delivery/channel-context.js +5 -2
- package/dist/delivery/db/queries/preferences.js +0 -1
- package/dist/delivery/delivery-service.js +3 -0
- package/dist/delivery/feature.d.ts +1 -4
- package/dist/delivery/feature.js +3 -1
- package/dist/delivery/handlers/attempts-by-keys.query.d.ts +1 -1
- package/dist/delivery/handlers/opted-in-user-ids.query.d.ts +7 -0
- package/dist/delivery/handlers/opted-in-user-ids.query.js +50 -0
- package/dist/delivery/handlers/preferences.query.js +2 -20
- package/dist/delivery/handlers/resubscribe-user.write.d.ts +2 -2
- package/dist/delivery/handlers/resubscribe-user.write.js +2 -24
- package/dist/delivery/handlers/unsubscribe-page-chrome.query.js +2 -0
- package/dist/delivery/handlers/unsubscribe-user.write.d.ts +2 -2
- package/dist/delivery/handlers/unsubscribe-user.write.js +2 -26
- package/dist/delivery/index.d.ts +3 -1
- package/dist/delivery/index.js +1 -0
- package/dist/delivery/options.d.ts +4 -0
- package/dist/delivery/options.js +1 -0
- package/dist/delivery/preference-rows.d.ts +9 -0
- package/dist/delivery/preference-rows.js +22 -0
- package/dist/delivery/set-preference-enabled.d.ts +17 -0
- package/dist/delivery/set-preference-enabled.js +26 -0
- package/dist/delivery/tables.d.ts +2 -2
- package/dist/delivery/testing.d.ts +1 -1
- package/dist/delivery/testing.js +3 -1
- package/dist/delivery/types.d.ts +1 -0
- package/dist/delivery/unsubscribe-page.js +5 -1
- package/dist/delivery/upsert-preference.js +0 -1
- package/dist/delivery/web/public-names.d.ts +1 -0
- package/dist/delivery/web/public-names.js +1 -0
- package/dist/derivatives-sharp/render.js +9 -9
- package/dist/document-ingest-foundation/aggregate-id.js +0 -1
- package/dist/document-ingest-foundation/append-missing-extract-event.d.ts +0 -1
- package/dist/document-ingest-foundation/append-missing-extract-event.js +32 -21
- package/dist/document-ingest-foundation/feature.js +1 -0
- package/dist/document-ingest-foundation/report-ingest-progress.d.ts +1 -1
- package/dist/document-ingest-foundation/report-ingest-progress.js +32 -13
- package/dist/documents/aggregate-id.js +0 -2
- package/dist/documents/constants.d.ts +6 -0
- package/dist/documents/constants.js +8 -2
- package/dist/documents/ensure-link.d.ts +5 -8
- package/dist/documents/ensure-link.js +4 -2
- package/dist/documents/feature.d.ts +3 -1
- package/dist/documents/feature.js +29 -5
- package/dist/documents/handlers/import.write.js +2 -2
- package/dist/documents/queries/expiry-overview.query.js +2 -1
- package/dist/documents/queries/for-record.query.js +3 -4
- package/dist/documents/queries/list-page.js +11 -3
- package/dist/documents/queries/overview.query.js +2 -2
- package/dist/documents/screens.js +3 -3
- package/dist/documents/tab.js +1 -1
- package/dist/feature-toggles/toggle-sync-signal.d.ts +2 -2
- package/dist/feature-toggles/toggle-sync-signal.js +3 -2
- package/dist/file-derivatives/handlers/public-variant-by-file-ref.query.js +1 -1
- package/dist/file-derivatives/handlers/public-variant.query.js +1 -1
- package/dist/file-foundation/probe.js +9 -3
- package/dist/file-foundation/read-file-ref-content.js +23 -11
- package/dist/file-provider-inmemory/feature.js +1 -1
- package/dist/file-provider-s3/env-feature.js +1 -1
- package/dist/file-provider-s3/env-named-feature.js +1 -1
- package/dist/file-provider-s3/env-schema.d.ts +10 -1
- package/dist/file-provider-s3/env-schema.js +20 -7
- package/dist/file-provider-s3/feature.js +1 -1
- package/dist/file-provider-s3/index.d.ts +1 -1
- package/dist/file-provider-s3/index.js +1 -1
- package/dist/file-provider-s3/lib/env-helper.d.ts +3 -2
- package/dist/file-provider-s3/lib/env-helper.js +13 -12
- package/dist/file-provider-s3/lib/s3-provider.js +10 -2
- package/dist/folders/aggregate-id.js +0 -1
- package/dist/folders/web/folder-manager.js +1 -1
- package/dist/folders-user-data/index.js +12 -14
- package/dist/form-draft/feature.js +1 -0
- package/dist/helpdesk/entity.js +4 -1
- package/dist/helpdesk/feature.js +37 -0
- package/dist/helpdesk/handlers/access.d.ts +0 -1
- package/dist/helpdesk/handlers/access.js +0 -3
- package/dist/helpdesk/handlers/attempts.js +7 -13
- package/dist/helpdesk/handlers/challenge.query.js +1 -2
- package/dist/helpdesk/handlers/reply.write.js +7 -8
- package/dist/helpdesk/handlers/report.write.js +4 -7
- package/dist/helpdesk/handlers/submit.write.js +5 -9
- package/dist/helpdesk/index.d.ts +1 -1
- package/dist/helpdesk/index.js +1 -1
- package/dist/helpdesk/legacy-contact-config.d.ts +3 -0
- package/dist/helpdesk/legacy-contact-config.js +57 -0
- package/dist/helpdesk/legacy-contact-erasure.d.ts +9 -0
- package/dist/helpdesk/legacy-contact-erasure.js +19 -0
- package/dist/helpdesk/legacy-contact-retention.d.ts +2 -0
- package/dist/helpdesk/legacy-contact-retention.js +53 -0
- package/dist/helpdesk/legacy-contact-streams.d.ts +20 -0
- package/dist/helpdesk/legacy-contact-streams.js +124 -0
- package/dist/helpdesk/legacy-contact-user-data.d.ts +5 -0
- package/dist/helpdesk/legacy-contact-user-data.js +62 -0
- package/dist/helpdesk/lib.d.ts +8 -2
- package/dist/helpdesk/lib.js +32 -32
- package/dist/helpdesk/user-data-hooks.d.ts +10 -1
- package/dist/helpdesk/user-data-hooks.js +47 -36
- package/dist/helpdesk/web/constants.d.ts +0 -1
- package/dist/helpdesk/web/constants.js +0 -1
- package/dist/inbound-mail-foundation/account-health.js +1 -1
- package/dist/inbound-mail-foundation/account-poll.js +3 -1
- package/dist/inbound-mail-foundation/aggregate-id.js +0 -2
- package/dist/inbound-mail-foundation/constants.d.ts +6 -0
- package/dist/inbound-mail-foundation/constants.js +6 -0
- package/dist/inbound-mail-foundation/content-refetch.d.ts +4 -0
- package/dist/inbound-mail-foundation/content-refetch.js +13 -3
- package/dist/inbound-mail-foundation/entities.js +58 -15
- package/dist/inbound-mail-foundation/events.js +16 -16
- package/dist/inbound-mail-foundation/feature.js +3 -1
- package/dist/inbound-mail-foundation/handlers/account-address.d.ts +2 -2
- package/dist/inbound-mail-foundation/handlers/account-address.js +10 -2
- package/dist/inbound-mail-foundation/handlers/attach-message-content.write.js +8 -3
- package/dist/inbound-mail-foundation/handlers/connect-account.write.js +14 -8
- package/dist/inbound-mail-foundation/handlers/forget-message.write.d.ts +7 -0
- package/dist/inbound-mail-foundation/handlers/forget-message.write.js +58 -0
- package/dist/inbound-mail-foundation/handlers/ingest-message-schema.js +12 -5
- package/dist/inbound-mail-foundation/i18n.js +3 -0
- package/dist/inbound-mail-foundation/index.d.ts +1 -0
- package/dist/inbound-mail-foundation/index.js +1 -0
- package/dist/inbound-mail-foundation/normalize-inbound-message.d.ts +6 -0
- package/dist/inbound-mail-foundation/normalize-inbound-message.js +21 -8
- package/dist/inbound-mail-foundation/oauth-access-token.js +1 -1
- package/dist/inbound-mail-foundation/outbound-mail.d.ts +2 -0
- package/dist/inbound-mail-foundation/personal-address.d.ts +1 -0
- package/dist/inbound-mail-foundation/personal-address.js +16 -0
- package/dist/inbound-mail-foundation/purge-messages.d.ts +20 -0
- package/dist/inbound-mail-foundation/purge-messages.js +33 -0
- package/dist/inbound-mail-foundation/quarantine.d.ts +3 -2
- package/dist/inbound-mail-foundation/quarantine.js +9 -5
- package/dist/inbound-mail-foundation/retention-job.js +1 -5
- package/dist/inbound-mail-foundation/retention-sweep.js +17 -28
- package/dist/inbound-mail-foundation/sanitize-inbound-html.d.ts +0 -1
- package/dist/inbound-mail-foundation/sanitize-inbound-html.js +2 -4
- package/dist/inbound-mail-foundation/send-from-account.js +9 -1
- package/dist/inbound-mail-foundation/supervisor-ingest.js +4 -1
- package/dist/inbound-mail-foundation/sync-account-now.js +1 -1
- package/dist/inbound-mail-foundation/tenant-destroy-hook.js +3 -6
- package/dist/inbound-mail-foundation/watch-supervisor.js +1 -1
- package/dist/inbound-provider-imap/byte-budget.d.ts +14 -0
- package/dist/inbound-provider-imap/byte-budget.js +53 -0
- package/dist/inbound-provider-imap/connect-mailbox.d.ts +2 -4
- package/dist/inbound-provider-imap/connect-mailbox.js +8 -3
- package/dist/inbound-provider-imap/connect-my-mailbox.d.ts +1 -1
- package/dist/inbound-provider-imap/connect-my-mailbox.js +15 -4
- package/dist/inbound-provider-imap/connect-target-rate-limit.d.ts +3 -0
- package/dist/inbound-provider-imap/connect-target-rate-limit.js +37 -0
- package/dist/inbound-provider-imap/download-batch.d.ts +10 -0
- package/dist/inbound-provider-imap/download-batch.js +21 -6
- package/dist/inbound-provider-imap/feature.js +7 -4
- package/dist/inbound-provider-imap/fetch-content.js +35 -30
- package/dist/inbound-provider-imap/i18n.js +2 -2
- package/dist/inbound-provider-imap/parse-message.d.ts +7 -0
- package/dist/inbound-provider-imap/parse-message.js +8 -0
- package/dist/inbound-provider-imap/reconnect-mailbox.js +5 -4
- package/dist/inbound-provider-imap/send-mail.d.ts +2 -0
- package/dist/inbound-provider-imap/send-mail.js +32 -6
- package/dist/inbound-provider-imap/smtp-client.d.ts +9 -2
- package/dist/inbound-provider-imap/smtp-client.js +15 -3
- package/dist/inbound-provider-imap/watch-mailbox.js +3 -24
- package/dist/inbound-provider-inmemory/feature.js +1 -1
- package/dist/jobs/events.d.ts +13 -0
- package/dist/jobs/events.js +8 -0
- package/dist/jobs/feature.js +2 -0
- package/dist/jobs/handlers/consumer.write.js +31 -20
- package/dist/jobs/web/constants.d.ts +3 -0
- package/dist/jobs/web/constants.js +3 -0
- package/dist/mail-transport-inmemory/feature.js +1 -1
- package/dist/mail-transport-smtp/feature.js +3 -2
- package/dist/managed-pages/handlers/branding.query.js +1 -1
- package/dist/managed-pages/handlers/by-slug.query.js +1 -1
- package/dist/managed-pages/handlers/by-tenant-published.query.js +1 -1
- package/dist/managed-pages/render-page-body.d.ts +2 -0
- package/dist/managed-pages/render-page-body.js +12 -8
- package/dist/managed-pages/screens/page-screens.d.ts +3 -2
- package/dist/managed-pages/screens/page-screens.js +14 -33
- package/dist/managed-pages/table.js +1 -0
- package/dist/managed-pages/web/client-plugin.js +8 -6
- package/dist/managed-pages/web/constants.d.ts +5 -1
- package/dist/managed-pages/web/constants.js +6 -1
- package/dist/managed-pages/web/i18n.js +11 -3
- package/dist/managed-pages/web/markdown-to-document.js +1 -1
- package/dist/managed-pages/web/page-edit-draft.d.ts +32 -0
- package/dist/managed-pages/web/page-edit-draft.js +76 -0
- package/dist/managed-pages/web/page-edit-screen.d.ts +2 -0
- package/dist/managed-pages/web/page-edit-screen.js +113 -0
- package/dist/managed-pages/web/page-settings-rail.d.ts +11 -0
- package/dist/managed-pages/web/page-settings-rail.js +14 -0
- package/dist/notes-history-user-data/index.js +8 -14
- package/dist/personal-access-tokens/boot-rules.d.ts +5 -0
- package/dist/personal-access-tokens/boot-rules.js +5 -0
- package/dist/personal-access-tokens/handlers/create.write.js +0 -1
- package/dist/personal-access-tokens/scope-events-check.js +26 -6
- package/dist/presence/handlers/list.query.js +18 -8
- package/dist/presence/room.d.ts +2 -0
- package/dist/presence/room.js +8 -5
- package/dist/presence/store.d.ts +2 -0
- package/dist/presence/store.js +62 -26
- package/dist/readiness/handlers/latest-summary.query.js +10 -6
- package/dist/readiness/handlers/run-probes.write.js +24 -4
- package/dist/readiness/handlers/run-tone.js +3 -2
- package/dist/readiness/handlers/status.query.js +11 -3
- package/dist/readiness/probe-context.js +7 -10
- package/dist/readiness/screens.js +4 -4
- package/dist/readiness/visible-results.d.ts +1 -1
- package/dist/readiness/visible-results.js +5 -2
- package/dist/renderer-foundation/api.js +6 -12
- package/dist/renderer-foundation/types.d.ts +2 -2
- package/dist/secrets/db/queries/read.d.ts +2 -1
- package/dist/secrets/db/queries/read.js +10 -1
- package/dist/secrets/handlers/list.query.js +4 -2
- package/dist/secrets/secret-scope.d.ts +0 -1
- package/dist/secrets/secret-scope.js +2 -2
- package/dist/secrets/secrets-context.js +4 -4
- package/dist/secrets/table.d.ts +1 -1
- package/dist/secrets/write-gate.js +4 -2
- package/dist/seo/handlers/seo-config.query.js +1 -1
- package/dist/shared/acknowledged-system-db.d.ts +5 -0
- package/dist/shared/acknowledged-system-db.js +9 -0
- package/dist/shared/assert-billing-live.d.ts +1 -0
- package/dist/shared/assert-billing-live.js +5 -2
- package/dist/shared/hmac-signature.js +4 -2
- package/dist/shared/index.d.ts +7 -2
- package/dist/shared/index.js +7 -2
- package/dist/shared/normalize-email.d.ts +1 -0
- package/dist/shared/normalize-email.js +3 -0
- package/dist/shared/parent-visibility.d.ts +1 -0
- package/dist/shared/parent-visibility.js +16 -1
- package/dist/shared/password-hashing.js +0 -1
- package/dist/shared/price-env-shape.js +1 -1
- package/dist/shared/register-user-data-hooks.d.ts +11 -0
- package/dist/shared/register-user-data-hooks.js +11 -0
- package/dist/shared/require-bootstrap-extension.d.ts +9 -0
- package/dist/shared/require-bootstrap-extension.js +16 -0
- package/dist/shared/send-best-effort.d.ts +3 -0
- package/dist/shared/send-best-effort.js +19 -0
- package/dist/shared/stream-tenant-backfill.d.ts +1 -0
- package/dist/shared/stream-tenant-backfill.js +17 -1
- package/dist/shared/stream-tenant-derived-state.d.ts +5 -1
- package/dist/shared/stream-tenant-derived-state.js +19 -2
- package/dist/step-dispatcher/constants.d.ts +4 -0
- package/dist/step-dispatcher/constants.js +11 -0
- package/dist/step-dispatcher/deliver-dispatch-request.d.ts +1 -0
- package/dist/step-dispatcher/deliver-dispatch-request.js +41 -3
- package/dist/step-dispatcher/feature.js +31 -2
- package/dist/step-dispatcher/mail-runner.js +0 -1
- package/dist/step-dispatcher/sweep-abandoned.d.ts +11 -0
- package/dist/step-dispatcher/sweep-abandoned.js +46 -0
- package/dist/subscription-mollie/plugin-methods.d.ts +1 -0
- package/dist/subscription-mollie/plugin-methods.js +1 -2
- package/dist/subscription-mollie/verify-webhook.js +5 -5
- package/dist/subscription-paddle/backfill-checkout-ledger.d.ts +9 -0
- package/dist/subscription-paddle/backfill-checkout-ledger.js +112 -0
- package/dist/subscription-paddle/checkout-config.query.js +1 -1
- package/dist/subscription-paddle/checkout-methods.js +2 -8
- package/dist/subscription-paddle/constants.d.ts +0 -1
- package/dist/subscription-paddle/constants.js +1 -2
- package/dist/subscription-paddle/feature.d.ts +0 -4
- package/dist/subscription-paddle/feature.js +21 -20
- package/dist/subscription-paddle/ledger-backfill-marker.d.ts +17 -0
- package/dist/subscription-paddle/ledger-backfill-marker.js +53 -0
- package/dist/subscription-paddle/plan-switch-methods.js +2 -8
- package/dist/subscription-paddle/redeliver-legacy-checkout.d.ts +11 -0
- package/dist/subscription-paddle/redeliver-legacy-checkout.js +43 -0
- package/dist/subscription-paddle/runtime.d.ts +3 -5
- package/dist/subscription-paddle/runtime.js +4 -7
- package/dist/subscription-paddle/subscription-state.d.ts +1 -0
- package/dist/subscription-paddle/subscription-state.js +1 -0
- package/dist/subscription-paddle/webhook-events.d.ts +4 -0
- package/dist/subscription-paddle/webhook-events.js +40 -22
- package/dist/subscription-stripe/feature.d.ts +4 -0
- package/dist/subscription-stripe/feature.js +1 -0
- package/dist/subscription-stripe/plugin-methods.d.ts +1 -0
- package/dist/subscription-stripe/plugin-methods.js +2 -5
- package/dist/subscription-stripe/runtime.d.ts +2 -1
- package/dist/subscription-stripe/runtime.js +5 -7
- package/dist/subscription-stripe/verify-webhook.js +31 -6
- package/dist/tags/aggregate-id.js +0 -1
- package/dist/tags/web/tag-chip.js +0 -1
- package/dist/tags/web/tag-manager.js +3 -1
- package/dist/template-resolver/api.js +6 -12
- package/dist/template-resolver/document-sanitizer.d.ts +1 -1
- package/dist/template-resolver/document-sanitizer.js +18 -0
- package/dist/template-resolver/feature.d.ts +1 -0
- package/dist/template-resolver/feature.js +2 -0
- package/dist/template-resolver/handlers/body-preview.query.d.ts +11 -0
- package/dist/template-resolver/handlers/body-preview.query.js +41 -0
- package/dist/template-resolver/handlers/by-slug.query.js +1 -1
- package/dist/template-resolver/handlers/by-tenant.query.js +1 -1
- package/dist/template-resolver/handlers/collection-shared.js +5 -8
- package/dist/template-resolver/handlers/overview.query.d.ts +1 -0
- package/dist/template-resolver/handlers/overview.query.js +2 -1
- package/dist/template-resolver/handlers/send-test.write.js +27 -8
- package/dist/template-resolver/linked-resources.js +2 -6
- package/dist/template-resolver/seeding.js +92 -1
- package/dist/template-resolver/table.js +1 -0
- package/dist/template-resolver/template-draft.js +2 -1
- package/dist/template-resolver/template-preview.js +12 -3
- package/dist/template-resolver/testing.js +0 -2
- package/dist/template-resolver/web/client-plugin.js +3 -0
- package/dist/template-resolver/web/collection-entry-create-form.js +19 -9
- package/dist/template-resolver/web/constants.d.ts +2 -0
- package/dist/template-resolver/web/constants.js +2 -0
- package/dist/template-resolver/web/content-tree-provider.js +0 -1
- package/dist/template-resolver/web/content-workbench.d.ts +22 -0
- package/dist/template-resolver/web/content-workbench.js +32 -0
- package/dist/template-resolver/web/document-insert-model.d.ts +2 -4
- package/dist/template-resolver/web/document-insert-model.js +1 -2
- package/dist/template-resolver/web/document-link-policy.d.ts +3 -0
- package/dist/template-resolver/web/document-link-policy.js +53 -0
- package/dist/template-resolver/web/document-schema.d.ts +2 -4
- package/dist/template-resolver/web/document-schema.js +2 -53
- package/dist/template-resolver/web/document-tiptap-context.d.ts +2 -5
- package/dist/template-resolver/web/document-tiptap-context.js +2 -2
- package/dist/template-resolver/web/document-tiptap-editor.js +2 -2
- package/dist/template-resolver/web/document-tiptap-helpers.d.ts +7 -4
- package/dist/template-resolver/web/document-tiptap-toolbar-groups.js +3 -3
- package/dist/template-resolver/web/editor-handle.js +1 -0
- package/dist/template-resolver/web/fill-document-variables.d.ts +1 -0
- package/dist/template-resolver/web/fill-document-variables.js +22 -0
- package/dist/template-resolver/web/i18n.js +10 -0
- package/dist/template-resolver/web/index.d.ts +3 -0
- package/dist/template-resolver/web/index.js +2 -0
- package/dist/template-resolver/web/preview-targets.d.ts +5 -0
- package/dist/template-resolver/web/preview-targets.js +21 -0
- package/dist/template-resolver/web/qualified-names.d.ts +1 -0
- package/dist/template-resolver/web/qualified-names.js +1 -0
- package/dist/template-resolver/web/snippet-preview-renderer.d.ts +2 -0
- package/dist/template-resolver/web/snippet-preview-renderer.js +15 -0
- package/dist/template-resolver/web/string-values.d.ts +1 -0
- package/dist/template-resolver/web/string-values.js +8 -0
- package/dist/template-resolver/web/text-block-editor.js +18 -11
- package/dist/template-resolver/web/use-collection-entry-create.d.ts +1 -0
- package/dist/template-resolver/web/use-collection-entry-create.js +6 -0
- package/dist/template-resolver/web/use-document-tiptap-model.d.ts +2 -6
- package/dist/template-resolver/web/use-text-block-editor.d.ts +3 -0
- package/dist/template-resolver/web/use-text-block-editor.js +26 -5
- package/dist/template-resolver/web/web-preview-renderer.d.ts +12 -0
- package/dist/template-resolver/web/web-preview-renderer.js +45 -0
- package/dist/template-resolver-user-data/index.js +11 -10
- package/dist/tenant/handlers/create.write.js +3 -7
- package/dist/tenant/handlers/list.query.js +3 -8
- package/dist/tenant/handlers/member-directory.query.js +10 -5
- package/dist/tenant/handlers/toggle-enabled.write.js +1 -1
- package/dist/tenant/invited-membership.js +9 -1
- package/dist/tenant/seeding.d.ts +3 -0
- package/dist/tenant/seeding.js +3 -1
- package/dist/tenant/stream-tenant-backfill.js +5 -1
- package/dist/tenant/testing.js +1 -1
- package/dist/tenant-inactivity/check-inactive-tenants.js +29 -18
- package/dist/tenant-inactivity/constants.js +1 -2
- package/dist/tenant-inactivity/handlers/keep-account.write.js +8 -2
- package/dist/tenant-inactivity/state-store.d.ts +3 -1
- package/dist/tenant-inactivity/state-store.js +16 -1
- package/dist/tenant-lifecycle/constants.d.ts +1 -0
- package/dist/tenant-lifecycle/constants.js +3 -0
- package/dist/tenant-lifecycle/feature.js +1 -0
- package/dist/tenant-lifecycle/run-tenant-destroy.js +38 -5
- package/dist/tenant-lifecycle/stages.js +14 -2
- package/dist/tier-engine/aggregate-id.js +0 -1
- package/dist/tier-engine/feature.js +9 -2
- package/dist/user/db/queries/stream-tenant-backfill.js +2 -1
- package/dist/user/handlers/me.query.js +4 -1
- package/dist/user/index.d.ts +1 -0
- package/dist/user/index.js +1 -0
- package/dist/user/resolve-verified-user-email.d.ts +2 -0
- package/dist/user/resolve-verified-user-email.js +14 -0
- package/dist/user-data-rights/db/queries/export-jobs.js +0 -1
- package/dist/user-data-rights/feature.js +1 -0
- package/dist/user-data-rights/handlers/confirm-deletion-by-token.write.js +1 -1
- package/dist/user-data-rights/handlers/download-by-token.query.js +1 -1
- package/dist/user-data-rights/handlers/request-deletion-by-email.write.js +1 -1
- package/dist/user-data-rights/run-export-jobs.js +0 -2
- package/dist/user-data-rights/run-forget-cleanup.js +2 -2
- package/dist/user-data-rights/schema/download-attempt.js +3 -2
- package/dist/user-data-rights/web/confirm-deletion-screen.js +2 -2
- package/dist/user-data-rights/web/privacy-center-screen.js +1 -1
- package/dist/user-data-rights/web/request-deletion-screen.js +2 -2
- package/dist/user-data-rights-defaults/hooks/api-token.userdata-hook.js +5 -6
- package/dist/user-data-rights-defaults/hooks/hard-delete-own-rows-hook.d.ts +7 -0
- package/dist/user-data-rights-defaults/hooks/hard-delete-own-rows-hook.js +11 -0
- package/dist/user-data-rights-defaults/hooks/in-app-message.userdata-hook.js +5 -6
- package/dist/user-data-rights-defaults/hooks/job-run.userdata-hook.js +2 -1
- package/dist/user-data-rights-defaults/hooks/user-session.userdata-hook.js +5 -6
- package/dist/user-profile/handlers/change-email.write.js +0 -1
- package/dist/waitlist/handlers/reject.write.js +2 -1
- package/dist/waitlist/handlers/submit.write.js +6 -19
- package/dist/waitlist/import.js +2 -1
- package/dist/waitlist/lib.d.ts +0 -1
- package/dist/waitlist/lib.js +2 -10
- package/dist/waitlist/link-on-signup.js +2 -2
- package/dist/waitlist/user-data-hooks.js +6 -20
- package/dist/workflow-runner/aggregate-id.js +0 -1
- package/dist/workflow-runner/event-trigger.js +6 -2
- package/dist/workflow-runner/feature.js +1 -5
- package/dist/workflow-runner/handlers/resume-run.write.js +6 -4
- package/dist/workflow-runner/runner.d.ts +1 -0
- package/package.json +35 -11
- package/src/admin-shell/changes.json +6 -0
- package/src/agent-tools/changes.json +12 -0
- package/src/auth-email-password/changes.json +18 -0
- package/src/auth-mfa/changes.json +6 -0
- package/src/billing-foundation/changes.json +61 -0
- package/src/cap-counter/changes.json +6 -0
- package/src/cap-overview/changes.json +6 -0
- package/src/channel-in-app/changes.json +6 -0
- package/src/channel-whatsapp/changes.json +32 -0
- package/src/compliance-profiles/changes.json +5 -0
- package/src/config/changes.json +12 -0
- package/src/crypto-shredding/changes.json +18 -0
- package/src/data-retention/changes.json +12 -0
- package/src/delivery/changes.json +12 -0
- package/src/document-ingest-foundation/changes.json +6 -0
- package/src/documents/changes.json +24 -0
- package/src/file-provider-s3/changes.json +14 -0
- package/src/files/changes.json +7 -0
- package/src/helpdesk/changes.json +56 -0
- package/src/inbound-mail-foundation/changes.json +54 -0
- package/src/inbound-provider-imap/changes.json +13 -0
- package/src/mail-foundation/changes.json +6 -0
- package/src/managed-pages/changes.json +12 -0
- package/src/presence/changes.json +6 -0
- package/src/readiness/changes.json +25 -0
- package/src/secrets/changes.json +7 -0
- package/src/shared/changes.json +12 -0
- package/src/step-dispatcher/changes.json +18 -0
- package/src/subscription-mollie/changes.json +7 -0
- package/src/subscription-paddle/changes.json +19 -0
- package/src/subscription-stripe/changes.json +13 -0
- package/src/template-resolver/changes.json +48 -0
- package/src/tenant/changes.json +6 -0
- package/src/tenant-inactivity/changes.json +6 -0
- package/src/tenant-lifecycle/changes.json +24 -0
- package/src/tier-engine/changes.json +6 -0
- package/src/user/changes.json +6 -0
- package/src/waitlist/changes.json +6 -0
- package/src/workflow-runner/changes.json +6 -0
- package/dist/managed-pages/web/page-body-section.d.ts +0 -3
- package/dist/managed-pages/web/page-body-section.js +0 -40
- package/dist/subscription-paddle/tenant-binding.d.ts +0 -8
- package/dist/subscription-paddle/tenant-binding.js +0 -26
- package/dist/template-resolver/web/content-field.d.ts +0 -9
- package/dist/template-resolver/web/content-field.js +0 -14
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { ExtraRouteRejection, signatureRoute, } from "@cosmicdrift/kumiko-framework/api";
|
|
2
|
+
import { parseTenantId, SYSTEM_USER_ID } from "@cosmicdrift/kumiko-types/identifiers";
|
|
3
|
+
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
4
|
+
import { CHANNEL_WHATSAPP_FEATURE, WHATSAPP_DEFAULT_WEBHOOK_PATH, WHATSAPP_SECRET_KEYS, WhatsappHandlers, } from "./constants.js";
|
|
5
|
+
import { isValidMetaSignature, secretsMatch } from "./meta-signature.js";
|
|
6
|
+
import { normalizeWhatsappWebhook } from "./webhook-normalize.js";
|
|
7
|
+
const MAX_CHALLENGE_CHARS = 512;
|
|
8
|
+
const AUDIT_HANDLER = `${CHANNEL_WHATSAPP_FEATURE}:webhook`;
|
|
9
|
+
// Every authentication failure is a plain throw: the framework answers all of them with the
|
|
10
|
+
// same 401 body, so a caller cannot tell a bad tenant id, an unknown tenant, a missing secret
|
|
11
|
+
// and a wrong signature apart.
|
|
12
|
+
class WebhookAuthError extends Error {
|
|
13
|
+
}
|
|
14
|
+
async function readTenantSecret(deps, tenantIdParam, key) {
|
|
15
|
+
const tenantId = parseTenantId(tenantIdParam);
|
|
16
|
+
if (tenantId === null)
|
|
17
|
+
throw new WebhookAuthError("invalid tenant id");
|
|
18
|
+
const revealed = await deps.secrets?.get(tenantId, key, {
|
|
19
|
+
userId: SYSTEM_USER_ID,
|
|
20
|
+
handlerName: AUDIT_HANDLER,
|
|
21
|
+
});
|
|
22
|
+
const secret = revealed?.reveal();
|
|
23
|
+
if (secret === undefined || secret === "")
|
|
24
|
+
throw new WebhookAuthError("no secret");
|
|
25
|
+
return { tenantId, secret };
|
|
26
|
+
}
|
|
27
|
+
async function verifyChallenge(deps, params, query) {
|
|
28
|
+
const { secret } = await readTenantSecret(deps, params["tenantId"], WHATSAPP_SECRET_KEYS.verifyToken);
|
|
29
|
+
const challenge = query["hub.challenge"];
|
|
30
|
+
const token = query["hub.verify_token"];
|
|
31
|
+
if (query["hub.mode"] !== "subscribe" ||
|
|
32
|
+
token === undefined ||
|
|
33
|
+
!secretsMatch(token, secret) ||
|
|
34
|
+
challenge === undefined ||
|
|
35
|
+
challenge === "" ||
|
|
36
|
+
challenge.length > MAX_CHALLENGE_CHARS) {
|
|
37
|
+
throw new WebhookAuthError("verification failed");
|
|
38
|
+
}
|
|
39
|
+
return { kind: "challenge", challenge };
|
|
40
|
+
}
|
|
41
|
+
async function verifySignedWebhook(deps, request) {
|
|
42
|
+
const { tenantId, secret } = await readTenantSecret(deps, request.params["tenantId"], WHATSAPP_SECRET_KEYS.appSecret);
|
|
43
|
+
if (!isValidMetaSignature(secret, request.rawBody, request.headers["x-hub-signature-256"])) {
|
|
44
|
+
throw new WebhookAuthError("bad signature");
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
return { kind: "webhook", tenantId, body: JSON.parse(request.rawBody) };
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
throw new ExtraRouteRejection(400, {
|
|
51
|
+
error: { code: "whatsapp_webhook_invalid_json", message: "body is not JSON" },
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function outcomeOf(data) {
|
|
56
|
+
const outcome = data !== null && typeof data === "object" && "outcome" in data ? data.outcome : undefined;
|
|
57
|
+
return outcome === "duplicate" || outcome === "throttled" ? outcome : "stored";
|
|
58
|
+
}
|
|
59
|
+
async function processWebhook(c, verified, deps) {
|
|
60
|
+
const { messages, statuses, skipped } = normalizeWhatsappWebhook(verified.body, Temporal.Now.instant().toString());
|
|
61
|
+
const counts = { stored: 0, duplicate: 0, throttled: 0, failed: 0 };
|
|
62
|
+
const dispatches = [
|
|
63
|
+
...messages.map((payload) => ({ handlerQn: WhatsappHandlers.receiveMessage, payload })),
|
|
64
|
+
...statuses.map((payload) => ({ handlerQn: WhatsappHandlers.recordStatus, payload })),
|
|
65
|
+
];
|
|
66
|
+
// Every item is tried even after a failure: the dedupe makes the redelivery of the
|
|
67
|
+
// already stored ones harmless, and the failed ones get their retry from Meta.
|
|
68
|
+
for (const { handlerQn, payload } of dispatches) {
|
|
69
|
+
const dispatched = await deps.dispatchSystemWrite({
|
|
70
|
+
handlerQn,
|
|
71
|
+
payload,
|
|
72
|
+
tenantId: verified.tenantId,
|
|
73
|
+
});
|
|
74
|
+
if (dispatched.isSuccess)
|
|
75
|
+
counts[outcomeOf(dispatched.data)] += 1;
|
|
76
|
+
else
|
|
77
|
+
counts.failed += 1;
|
|
78
|
+
}
|
|
79
|
+
if (counts.failed > 0) {
|
|
80
|
+
return c.json({
|
|
81
|
+
error: {
|
|
82
|
+
code: "whatsapp_webhook_processing_failed",
|
|
83
|
+
message: "Internal error processing the webhook",
|
|
84
|
+
},
|
|
85
|
+
}, 500);
|
|
86
|
+
}
|
|
87
|
+
return c.json({ ...counts, skipped }, 200);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The two routes Meta needs: GET answers the subscription handshake (`hub.challenge`), POST takes
|
|
91
|
+
* the signed notifications. Mount via `extraRoutes: createWhatsappWebhookRoutes()`.
|
|
92
|
+
*/
|
|
93
|
+
export function createWhatsappWebhookRoutes(options = {}) {
|
|
94
|
+
const path = options.path ?? WHATSAPP_DEFAULT_WEBHOOK_PATH;
|
|
95
|
+
if (!path.includes(":tenantId")) {
|
|
96
|
+
throw new Error(`${CHANNEL_WHATSAPP_FEATURE}: the webhook path must carry a :tenantId segment (the secrets are tenant-scoped)`);
|
|
97
|
+
}
|
|
98
|
+
return [
|
|
99
|
+
signatureRoute({
|
|
100
|
+
method: "GET",
|
|
101
|
+
path,
|
|
102
|
+
entry: "signature",
|
|
103
|
+
verify: ({ params, query }, deps) => verifyChallenge(deps, params, query),
|
|
104
|
+
handler: (c, verified) => verified.kind === "challenge"
|
|
105
|
+
? c.text(verified.challenge, 200)
|
|
106
|
+
: c.json({ error: { code: "whatsapp_webhook_unexpected" } }, 400),
|
|
107
|
+
}),
|
|
108
|
+
signatureRoute({
|
|
109
|
+
method: "POST",
|
|
110
|
+
path,
|
|
111
|
+
entry: "signature",
|
|
112
|
+
verify: (request, deps) => verifySignedWebhook(deps, request),
|
|
113
|
+
handler: (c, verified, deps) => verified.kind === "webhook"
|
|
114
|
+
? processWebhook(c, verified, deps)
|
|
115
|
+
: c.json({ error: { code: "whatsapp_webhook_unexpected" } }, 400),
|
|
116
|
+
}),
|
|
117
|
+
];
|
|
118
|
+
}
|
|
@@ -33,6 +33,8 @@ export const setProfileWrite = defineWriteHandler({
|
|
|
33
33
|
// SystemAdmin can set profiles for customer setup through the platform-
|
|
34
34
|
// operator path; TenantAdmin can set them only for their own tenant.
|
|
35
35
|
access: { roles: access.admin },
|
|
36
|
+
// The profile picks the retention preset, so a change can shorten how long data is kept before the purge.
|
|
37
|
+
agent: { risk: "high" },
|
|
36
38
|
description: "Sets or replaces a tenant's compliance profile key plus an optional JSON override, for onboarding or a later region change; a system admin may target a different tenant through tenantIdOverride.",
|
|
37
39
|
handler: async (event, ctx) => {
|
|
38
40
|
const tenantId = (event.payload.tenantIdOverride ?? event.user.tenantId); // @cast-boundary engine-payload
|
|
@@ -17,7 +17,7 @@ export const subProcessorsQuery = defineQueryHandler({
|
|
|
17
17
|
name: "sub-processors",
|
|
18
18
|
schema: z.object({}),
|
|
19
19
|
access: {
|
|
20
|
-
roles: ["anonymous"
|
|
20
|
+
roles: ["anonymous"],
|
|
21
21
|
anySignedIn: true,
|
|
22
22
|
},
|
|
23
23
|
rateLimit: { per: "ip+handler", limit: 30, windowSeconds: 60 },
|
|
@@ -84,6 +84,13 @@ export const setWrite = defineWriteHandler({
|
|
|
84
84
|
message: `[config:write:set] readCascade: unknown config key "${qualifiedKey}"`,
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
+
// Validators are free to echo values into error details; plaintext of a stored
|
|
88
|
+
// secret or PII key must never reach the writing admin that way.
|
|
89
|
+
if (isEncryptedAtRest(cascadeKeyDef) || cascadeKeyDef.piiEncrypted) {
|
|
90
|
+
throw new InternalError({
|
|
91
|
+
message: `[config:write:set] readCascade: key "${qualifiedKey}" is encrypted and cannot be read by a validator`,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
87
94
|
return requireConfigResolver(ctx, "config:write:set").getCascade(qualifiedKey, cascadeKeyDef, tenantId, event.user.id, validateDb, ctx.services.secrets);
|
|
88
95
|
},
|
|
89
96
|
});
|
|
@@ -28,6 +28,7 @@ export const valuesQuery = defineQueryHandler({
|
|
|
28
28
|
const resolver = requireConfigResolver(ctx, "config:query:values");
|
|
29
29
|
const allKeys = registry.getAllConfigKeys();
|
|
30
30
|
const keyDefs = new Map();
|
|
31
|
+
const declaredScopes = new Map();
|
|
31
32
|
const filteredKeys = [];
|
|
32
33
|
const requestedKeys = query.payload.keys === undefined ? undefined : new Set(query.payload.keys);
|
|
33
34
|
for (const [qualifiedKey, keyDef] of allKeys) {
|
|
@@ -36,6 +37,7 @@ export const valuesQuery = defineQueryHandler({
|
|
|
36
37
|
if (!hasConfigAccess(keyDef.access.read, query.user.roles))
|
|
37
38
|
continue;
|
|
38
39
|
keyDefs.set(qualifiedKey, keyDefAtScope(keyDef, query.payload.scope, query.user.roles));
|
|
40
|
+
declaredScopes.set(qualifiedKey, keyDef.scope);
|
|
39
41
|
filteredKeys.push(qualifiedKey);
|
|
40
42
|
}
|
|
41
43
|
// Resolve through the full cascade (rows → app-override → computed →
|
|
@@ -62,7 +64,12 @@ export const valuesQuery = defineQueryHandler({
|
|
|
62
64
|
else {
|
|
63
65
|
value = cascade.value;
|
|
64
66
|
}
|
|
65
|
-
|
|
67
|
+
// The response scope is the key's declared one: a widened read scope must not turn into a write target.
|
|
68
|
+
result[qualifiedKey] = {
|
|
69
|
+
value,
|
|
70
|
+
scope: declaredScopes.get(qualifiedKey) ?? keyDef.scope,
|
|
71
|
+
source: cascade.source,
|
|
72
|
+
};
|
|
66
73
|
}
|
|
67
74
|
return result;
|
|
68
75
|
},
|
package/dist/config/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { DbConnection } from "@cosmicdrift/kumiko-framework/db";
|
|
|
2
2
|
import type { Registry } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
3
|
import type { EnvelopeCipher } from "@cosmicdrift/kumiko-framework/secrets";
|
|
4
4
|
export type { ConfigContext } from "./feature.ts";
|
|
5
|
-
export { createConfigAccessor, createConfigAccessorFactory, createConfigFeature, } from "./feature.ts";
|
|
5
|
+
export { createConfigAccessor, createConfigAccessorFactory, createConfigFeature, requireConfigResolver, } from "./feature.ts";
|
|
6
6
|
export type { ReadinessMissingKey, RequiredKeyGate } from "./handlers/readiness.query.ts";
|
|
7
7
|
export { buildProviderSelectionGate, collectMissingRequiredConfig, } from "./handlers/readiness.query.ts";
|
|
8
8
|
export type { AppConfigOverrides, ConfigResolver } from "./resolver.ts";
|
package/dist/config/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { seedConfigValues } from "@cosmicdrift/kumiko-framework/db";
|
|
2
2
|
import { configValueEntity, configValuesTable } from "./table.js";
|
|
3
|
-
export { createConfigAccessor, createConfigAccessorFactory, createConfigFeature, } from "./feature.js";
|
|
3
|
+
export { createConfigAccessor, createConfigAccessorFactory, createConfigFeature, requireConfigResolver, } from "./feature.js";
|
|
4
4
|
export { buildProviderSelectionGate, collectMissingRequiredConfig, } from "./handlers/readiness.query.js";
|
|
5
5
|
export { buildEnvConfigOverrides, createConfigResolver, validateAppOverrides } from "./resolver.js";
|
|
6
6
|
export { configValueEntity, configValuesTable } from "./table.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ConfigCascade, ConfigKeyDefinition } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
export declare const MASKED = "\u2022\u2022\u2022\u2022\u2022\u2022";
|
|
3
|
+
export declare function isSystemAdmin(roles: readonly string[]): boolean;
|
|
3
4
|
export declare function mayViewInheritedValue(roles: readonly string[]): boolean;
|
|
4
5
|
export declare function shouldRedactInherited(keyDef: Pick<ConfigKeyDefinition, "inheritedToTenant">, roles: readonly string[]): boolean;
|
|
5
6
|
export declare function redactInheritedCascade(cascade: ConfigCascade): ConfigCascade;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { ROLES } from "@cosmicdrift/kumiko-framework/auth";
|
|
2
2
|
// The viewer's own cascade rungs. Every other rung (system-row, app-override,
|
|
3
3
|
// computed, default) carries a platform-inherited value — for an
|
|
4
4
|
// inheritedToTenant:false key those must stay hidden from a tenant-side viewer.
|
|
@@ -16,8 +16,11 @@ const OWN_SOURCES = new Set(["user-row", "tenant-row"]);
|
|
|
16
16
|
// functioning config. So "nor that it is set" holds for the value queries, not
|
|
17
17
|
// for the functional readiness rollup. See readiness.query.ts.
|
|
18
18
|
export const MASKED = "••••••";
|
|
19
|
+
export function isSystemAdmin(roles) {
|
|
20
|
+
return roles.includes(ROLES.SystemAdmin);
|
|
21
|
+
}
|
|
19
22
|
export function mayViewInheritedValue(roles) {
|
|
20
|
-
return roles
|
|
23
|
+
return isSystemAdmin(roles);
|
|
21
24
|
}
|
|
22
25
|
export function shouldRedactInherited(keyDef, roles) {
|
|
23
26
|
return keyDef.inheritedToTenant === false && !mayViewInheritedValue(roles);
|
package/dist/config/table.js
CHANGED
|
@@ -17,6 +17,7 @@ import { createEntity, createTextField } from "@cosmicdrift/kumiko-framework/eng
|
|
|
17
17
|
// provides handlers (`reset.write.ts` etc.) with a typed Drizzle table ref.
|
|
18
18
|
export const configValueEntity = createEntity({
|
|
19
19
|
table: "read_config_values",
|
|
20
|
+
systemRowsReadable: true,
|
|
20
21
|
fields: {
|
|
21
22
|
key: createTextField({ required: true, personal: false, reason: "system_metadata" }),
|
|
22
23
|
// value is JSON-encoded primitive (or encrypted blob). Nullable so a
|
|
@@ -5,6 +5,7 @@ import { fetchOne } from "@cosmicdrift/kumiko-framework/db";
|
|
|
5
5
|
import { ConfigScopes, extensionSelectorTargets, isEncryptedAtRest, SYSTEM_ROLE, SYSTEM_TENANT_ID, selectablePluginIds, } from "@cosmicdrift/kumiko-framework/engine";
|
|
6
6
|
import { AccessDeniedError, InternalError, NotFoundError, UnprocessableError, ValidationError, writeFailure, } from "@cosmicdrift/kumiko-framework/errors";
|
|
7
7
|
import { assertUnreachable } from "@cosmicdrift/kumiko-framework/utils";
|
|
8
|
+
import { isSystemAdmin } from "./read-redaction.js";
|
|
8
9
|
import { decryptStoredValue } from "./resolver.js";
|
|
9
10
|
import { configValuesTable } from "./table.js";
|
|
10
11
|
import { ConfigErrors } from "./web/constants.js";
|
|
@@ -102,7 +103,7 @@ export function checkScopeWriteAccess(scope, userRoles) {
|
|
|
102
103
|
return null;
|
|
103
104
|
if (userRoles.includes(SYSTEM_ROLE))
|
|
104
105
|
return null;
|
|
105
|
-
if (userRoles
|
|
106
|
+
if (isSystemAdmin(userRoles))
|
|
106
107
|
return null;
|
|
107
108
|
return new AccessDeniedError({
|
|
108
109
|
message: "system-scope config write requires SystemAdmin",
|
|
@@ -128,7 +129,7 @@ const SCOPE_LEVEL = {
|
|
|
128
129
|
// Only a SystemAdmin may widen the read to the platform level; everyone else keeps the normal cascade.
|
|
129
130
|
export function keyDefAtScope(keyDef, readScope, roles) {
|
|
130
131
|
if (readScope === undefined ||
|
|
131
|
-
!roles
|
|
132
|
+
!isSystemAdmin(roles) ||
|
|
132
133
|
SCOPE_LEVEL[readScope] >= SCOPE_LEVEL[keyDef.scope]) {
|
|
133
134
|
return keyDef;
|
|
134
135
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const CRYPTO_SHREDDING_FEATURE_NAME = "crypto-shredding";
|
|
2
|
+
export declare const FORGET_SUBJECT_QUALIFIED_NAME = "crypto-shredding:write:forget-subject";
|
|
2
3
|
export declare const SUBJECT_FORGOTTEN_EVENT_NAME = "crypto-shredding:event:subject-forgotten";
|
|
3
4
|
export declare const SUBJECT_FORGET_DENIED_EVENT_NAME = "crypto-shredding:event:forget-denied";
|
|
4
5
|
export declare const CRYPTO_SHREDDING_AGGREGATE_TYPE = "crypto-shredding-subject";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export const CRYPTO_SHREDDING_FEATURE_NAME = "crypto-shredding";
|
|
2
|
+
export const FORGET_SUBJECT_QUALIFIED_NAME = `${CRYPTO_SHREDDING_FEATURE_NAME}:write:forget-subject`;
|
|
2
3
|
export const SUBJECT_FORGOTTEN_EVENT_NAME = "crypto-shredding:event:subject-forgotten";
|
|
3
4
|
export const SUBJECT_FORGET_DENIED_EVENT_NAME = "crypto-shredding:event:forget-denied";
|
|
4
5
|
export const CRYPTO_SHREDDING_AGGREGATE_TYPE = "crypto-shredding-subject";
|
|
@@ -9,12 +9,13 @@ import { purgeSearchDocumentsForSubject } from "@cosmicdrift/kumiko-framework/se
|
|
|
9
9
|
import { generateId } from "@cosmicdrift/kumiko-framework/utils";
|
|
10
10
|
import * as z from "zod";
|
|
11
11
|
import { resolveRetentionPolicyForTenant } from "../../data-retention/index.js";
|
|
12
|
+
import { NOTES_HISTORY_FEATURE_NAME } from "../../notes-history/index.js";
|
|
12
13
|
import { eraseNoteBodiesReachingSubject } from "../../notes-history-user-data/index.js";
|
|
13
14
|
import { revokeAllPatTokensForUser } from "../../personal-access-tokens/index.js";
|
|
14
15
|
import { purgeFilesReachingSubject } from "../../shared/index.js";
|
|
15
16
|
import { USER_STATUS, userTable } from "../../user/index.js";
|
|
16
17
|
import { denyIfTargetOutsideAdminTenant, isSystemAdminActor, updateUserLifecycle, } from "../../user-data-rights/index.js";
|
|
17
|
-
import { CRYPTO_SHREDDING_AGGREGATE_TYPE, CRYPTO_SHREDDING_FEATURE_NAME, RECORD_ENTITY_NOT_REGISTERED, SUBJECT_FORGET_DENIED_EVENT_NAME, SUBJECT_FORGOTTEN_EVENT_NAME, TARGET_RECORD_NOT_ADMIN_TENANT, TARGET_RECORD_RETENTION_BLOCK_DELETE, TARGET_TENANT_NOT_ADMIN_TENANT, } from "../constants.js";
|
|
18
|
+
import { CRYPTO_SHREDDING_AGGREGATE_TYPE, CRYPTO_SHREDDING_FEATURE_NAME, FORGET_SUBJECT_QUALIFIED_NAME, RECORD_ENTITY_NOT_REGISTERED, SUBJECT_FORGET_DENIED_EVENT_NAME, SUBJECT_FORGOTTEN_EVENT_NAME, TARGET_RECORD_NOT_ADMIN_TENANT, TARGET_RECORD_RETENTION_BLOCK_DELETE, TARGET_TENANT_NOT_ADMIN_TENANT, } from "../constants.js";
|
|
18
19
|
import { resolveFileBytesDeleter } from "../resolve-file-bytes-deleter.js";
|
|
19
20
|
export { subjectIdSchema };
|
|
20
21
|
export const forgetSubjectSchema = z.object({
|
|
@@ -37,6 +38,28 @@ export const subjectForgetDeniedSchema = z.object({
|
|
|
37
38
|
actorTenantId: z.string().min(1),
|
|
38
39
|
denial: z.string().min(1),
|
|
39
40
|
});
|
|
41
|
+
function subjectOfInput(raw) {
|
|
42
|
+
switch (raw.kind) {
|
|
43
|
+
case "user":
|
|
44
|
+
return { kind: "user", userId: raw.userId };
|
|
45
|
+
case "tenant":
|
|
46
|
+
return { kind: "tenant", tenantId: raw.tenantId };
|
|
47
|
+
case "record":
|
|
48
|
+
return { kind: "record", entity: raw.entity, id: raw.id };
|
|
49
|
+
default: {
|
|
50
|
+
const unreachable = raw;
|
|
51
|
+
return unreachable;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Called from another write handler (subjectForgetAfterDeleteHook), the caller's tx holds
|
|
56
|
+
// the uncommitted delete event on the subject's own stream; appending there from outside
|
|
57
|
+
// that tx would wait on it forever, so the event goes onto a fresh stream.
|
|
58
|
+
function forgottenEventAggregateId(raw) {
|
|
59
|
+
const entryHandlerQn = requestContext.get()?.entryHandler?.qn;
|
|
60
|
+
const nestedInCallerTransaction = entryHandlerQn !== undefined && entryHandlerQn !== FORGET_SUBJECT_QUALIFIED_NAME;
|
|
61
|
+
return nestedInCallerTransaction ? generateId() : subjectAggregateId(raw);
|
|
62
|
+
}
|
|
40
63
|
// Exhaustive switch so a 4th subject kind fails to compile instead of
|
|
41
64
|
// silently aggregating under the wrong id.
|
|
42
65
|
function subjectAggregateId(raw) {
|
|
@@ -235,7 +258,7 @@ async function sweepDerivedSubjectData(ctx, subject, subjectKey, crossTenantRunn
|
|
|
235
258
|
await purgeSearchDocumentsForSubject(crossTenantSubjectRunner, ctx.registry.features, ctx.services.searchAdapter, subjectKey, subject);
|
|
236
259
|
}
|
|
237
260
|
// Note bodies are keyed per note, so the subject's own key never reaches them.
|
|
238
|
-
if (ctx.registry.features.has(
|
|
261
|
+
if (ctx.registry.features.has(NOTES_HISTORY_FEATURE_NAME)) {
|
|
239
262
|
await eraseNoteBodiesReachingSubject({
|
|
240
263
|
db: crossTenantSubjectRunner,
|
|
241
264
|
subject,
|
|
@@ -353,11 +376,7 @@ export const forgetSubjectWrite = defineWriteHandler({
|
|
|
353
376
|
}));
|
|
354
377
|
}
|
|
355
378
|
const raw = event.payload.subject;
|
|
356
|
-
const subject = raw
|
|
357
|
-
? { kind: "user", userId: raw.userId }
|
|
358
|
-
: raw.kind === "tenant"
|
|
359
|
-
? { kind: "tenant", tenantId: raw.tenantId }
|
|
360
|
-
: { kind: "record", entity: raw.entity, id: raw.id };
|
|
379
|
+
const subject = subjectOfInput(raw);
|
|
361
380
|
const subjectKey = subjectIdToKey(subject);
|
|
362
381
|
const tenantScopeDenial = await resolveTenantScopeDenial(ctx.db.unsafeRaw(), ctx.registry.features, event.user, raw);
|
|
363
382
|
if (tenantScopeDenial) {
|
|
@@ -397,19 +416,21 @@ export const forgetSubjectWrite = defineWriteHandler({
|
|
|
397
416
|
// crash recovery is safe. User-feature guard: without the user feature
|
|
398
417
|
// read_users doesn't exist (crypto-only stack). Tenant subjects have no
|
|
399
418
|
// credentials.
|
|
400
|
-
//
|
|
401
|
-
//
|
|
402
|
-
//
|
|
419
|
+
// Door close and audit event commit on the outside-transaction db, before the sweep:
|
|
420
|
+
// the key erase above is irreversible, so neither may roll back with the handler tx
|
|
421
|
+
// (sweep failure, a later subject, a later hook, a failed commit). The handler tx holds
|
|
422
|
+
// no lock on this user's read_users row yet (only read gates ran).
|
|
423
|
+
const outsideRunner = ctx.db.outsideTransaction?.unsafeRaw();
|
|
403
424
|
if (raw.kind === "user" && ctx.registry.features.has("user")) {
|
|
404
|
-
await closeUserLoginDoor(ctx, raw.userId,
|
|
425
|
+
await closeUserLoginDoor(ctx, raw.userId, outsideRunner, ctx.db.unsafeRaw());
|
|
405
426
|
}
|
|
406
427
|
const cleanupError = await sweepDerivedSubjectData(ctx, subject, subjectKey, ctx.db.unsafeRaw(), { requestId, erasedBy: event.user.id }, raw);
|
|
407
|
-
await appendSubjectForgotten(ctx, event,
|
|
428
|
+
await appendSubjectForgotten(ctx, event, forgottenEventAggregateId(raw), {
|
|
408
429
|
subjectKey,
|
|
409
430
|
reason: event.payload.reason,
|
|
410
431
|
forgottenBy: event.user.id,
|
|
411
432
|
...(cleanupError !== undefined && { cleanupError }),
|
|
412
|
-
},
|
|
433
|
+
}, outsideRunner);
|
|
413
434
|
if (cleanupError !== undefined) {
|
|
414
435
|
throw new InternalError({
|
|
415
436
|
message: `[crypto-shredding] forget-subject erased the key but a derived-data sweep failed (${cleanupError}); retry to finish the cleanup.`,
|
|
@@ -2,3 +2,4 @@ export { CRYPTO_SHREDDING_AGGREGATE_TYPE, CRYPTO_SHREDDING_FEATURE_NAME, SUBJECT
|
|
|
2
2
|
export { kmsEnvSchema } from "./env/index.ts";
|
|
3
3
|
export { createCryptoShreddingFeature } from "./feature.ts";
|
|
4
4
|
export { forgetSubjectSchema, subjectForgetDeniedSchema, subjectForgottenSchema, subjectIdSchema, } from "./handlers/forget-subject.write.ts";
|
|
5
|
+
export { type SubjectForgetAfterDeleteOptions, subjectForgetAfterDeleteHook, } from "./subject-forget-after-delete-hook.ts";
|
|
@@ -2,3 +2,4 @@ export { CRYPTO_SHREDDING_AGGREGATE_TYPE, CRYPTO_SHREDDING_FEATURE_NAME, SUBJECT
|
|
|
2
2
|
export { kmsEnvSchema } from "./env/index.js";
|
|
3
3
|
export { createCryptoShreddingFeature } from "./feature.js";
|
|
4
4
|
export { forgetSubjectSchema, subjectForgetDeniedSchema, subjectForgottenSchema, subjectIdSchema, } from "./handlers/forget-subject.write.js";
|
|
5
|
+
export { subjectForgetAfterDeleteHook, } from "./subject-forget-after-delete-hook.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SubjectId } from "@cosmicdrift/kumiko-framework/crypto";
|
|
2
|
+
import type { HookDefinition } from "@cosmicdrift/kumiko-types/feature-registrar";
|
|
3
|
+
export type SubjectForgetAfterDeleteOptions = {
|
|
4
|
+
readonly target: Extract<HookDefinition, {
|
|
5
|
+
type: "postDelete";
|
|
6
|
+
}>["target"];
|
|
7
|
+
readonly subjectsOf: (deletedId: string) => readonly SubjectId[];
|
|
8
|
+
readonly reason: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function subjectForgetAfterDeleteHook(options: SubjectForgetAfterDeleteOptions): Extract<HookDefinition, {
|
|
11
|
+
type: "postDelete";
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ROLES } from "@cosmicdrift/kumiko-framework/auth";
|
|
2
|
+
import { createSystemUser, parseTenantId } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
import { InternalError, reraiseAsKumikoError } from "@cosmicdrift/kumiko-framework/errors";
|
|
4
|
+
import { FORGET_SUBJECT_QUALIFIED_NAME } from "./constants.js";
|
|
5
|
+
// A postDelete hook, not a step inside the delete handler: preDelete hooks run after the handler
|
|
6
|
+
// returns, and the key erase cannot be rolled back. Run here, in the delete's own transaction, the
|
|
7
|
+
// erase only happens once every preDelete hook has accepted the delete; a failed forget throws and
|
|
8
|
+
// rolls the delete back. The escalation stays in the tenant of the deleted row's own event.
|
|
9
|
+
// forget-subject is irreversible (assertIrreversibleOperationAllowed), so the consumer's delete
|
|
10
|
+
// handler (the entry handler) must resolve to agent risk "high", otherwise the hook fails.
|
|
11
|
+
export function subjectForgetAfterDeleteHook(options) {
|
|
12
|
+
return {
|
|
13
|
+
type: "postDelete",
|
|
14
|
+
target: options.target,
|
|
15
|
+
phase: "inTransaction",
|
|
16
|
+
escapeHatch: {
|
|
17
|
+
reason: `deleting the row escalates to the system identity to run crypto-shredding:forget-subject (DPO/SystemAdmin-only) for the subjects of the row just deleted in its own tenant: ${options.reason}`,
|
|
18
|
+
grants: ["systemIdentity"],
|
|
19
|
+
},
|
|
20
|
+
handler: async (deleted, ctx) => {
|
|
21
|
+
const tenantId = parseTenantId(deleted.event.tenantId);
|
|
22
|
+
if (tenantId === null) {
|
|
23
|
+
throw new InternalError({
|
|
24
|
+
message: "[crypto-shredding] subjectForgetAfterDeleteHook: deleted row has no tenant",
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
const systemAdmin = createSystemUser(tenantId, [ROLES.SystemAdmin]);
|
|
28
|
+
for (const subject of options.subjectsOf(String(deleted.id))) {
|
|
29
|
+
const forgotten = await ctx.dispatch.writeAs(systemAdmin, FORGET_SUBJECT_QUALIFIED_NAME, {
|
|
30
|
+
subject,
|
|
31
|
+
reason: options.reason,
|
|
32
|
+
});
|
|
33
|
+
if (!forgotten.isSuccess)
|
|
34
|
+
throw reraiseAsKumikoError(forgotten.error);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -21,7 +21,6 @@ const FIELD_DEFINITION_NAMESPACE = "f1d3b2c7-4e5a-4b9c-8d1f-2a3b4c5d6e7f";
|
|
|
21
21
|
* define its own `customer.internalNumber` (422 `fieldKey_conflict`). This
|
|
22
22
|
* prevents ambiguity when resolving the field during reads.
|
|
23
23
|
*/
|
|
24
|
-
// @wrapper-known uuid-domain
|
|
25
24
|
export function fieldDefinitionAggregateId(tenantId, entityName, fieldKey) {
|
|
26
25
|
return uuidv5(`${tenantId}|${entityName}|${fieldKey}`, FIELD_DEFINITION_NAMESPACE);
|
|
27
26
|
}
|
|
@@ -31,6 +31,7 @@ import { createBooleanField, createEntity, createNumberField, createTextField, }
|
|
|
31
31
|
// columns and events.
|
|
32
32
|
export const fieldDefinitionEntity = createEntity({
|
|
33
33
|
table: "read_custom_field_definitions",
|
|
34
|
+
systemRowsReadable: true,
|
|
34
35
|
description: "One custom-field definition: the host entity it extends, the field key, its type and required/searchable flags, a display order, and the serialized field builder that carries the type options, default value and labels. Rows owned by the system tenant apply to every tenant; all others belong to the tenant that defined them.",
|
|
35
36
|
// softDelete is required, NOT cosmetic: the aggregate-id is deterministic
|
|
36
37
|
// (uuidv5(tenantId|entityName|fieldKey)), so deleting a definition leaves a
|
|
@@ -14,7 +14,6 @@ import { CUSTOM_FIELDS_EXTENSION, FIELD_DEFINITION_AGGREGATE_TYPE } from "./web/
|
|
|
14
14
|
//
|
|
15
15
|
// `customFields` follows the same contract as regular fields: default `{}` and
|
|
16
16
|
// NOT NULL, like embedded columns.
|
|
17
|
-
// @wrapper-known semantic-alias
|
|
18
17
|
export function customFieldsField() {
|
|
19
18
|
return createJsonbField();
|
|
20
19
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DbRunner } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import type { Registry } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
export declare function eraseNotesOfDeletedRow(args: {
|
|
4
|
+
readonly registry: Registry;
|
|
5
|
+
readonly tx: DbRunner;
|
|
6
|
+
readonly entityName: string;
|
|
7
|
+
readonly rowId: string;
|
|
8
|
+
readonly erasedBy: string;
|
|
9
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NOTES_HISTORY_FEATURE_NAME } from "../notes-history/index.js";
|
|
2
|
+
import { eraseNoteBodiesReachingSubject } from "../notes-history-user-data/index.js";
|
|
3
|
+
// Note bodies are keyed per note, so a hardDeleted parent's own key never reaches them. The runner
|
|
4
|
+
// is the retention job's unfiltered one: notes of a global parent sit in whichever tenant wrote them.
|
|
5
|
+
export async function eraseNotesOfDeletedRow(args) {
|
|
6
|
+
// skip: without notes-history there are no notes hanging on the row
|
|
7
|
+
if (!args.registry.features.has(NOTES_HISTORY_FEATURE_NAME))
|
|
8
|
+
return;
|
|
9
|
+
await eraseNoteBodiesReachingSubject({
|
|
10
|
+
db: args.tx,
|
|
11
|
+
subject: { kind: "record", entity: args.entityName, id: args.rowId },
|
|
12
|
+
erasedBy: args.erasedBy,
|
|
13
|
+
requestId: `data-retention:hardDelete:${args.entityName}:${args.rowId}`,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -43,6 +43,7 @@ export function createDataRetentionFeature() {
|
|
|
43
43
|
r.job({
|
|
44
44
|
name: "retention-cleanup",
|
|
45
45
|
trigger: { maintenance: true },
|
|
46
|
+
irreversibleWithoutEntryHandler: "high-risk-or-cron-pipeline",
|
|
46
47
|
perTenant: true,
|
|
47
48
|
includeSystemTenant: true,
|
|
48
49
|
concurrency: "skip",
|
|
@@ -53,11 +54,7 @@ export function createDataRetentionFeature() {
|
|
|
53
54
|
if (!ctx.registry) {
|
|
54
55
|
throw new Error("retention-cleanup: ctx.registry required (JobContext incomplete)");
|
|
55
56
|
}
|
|
56
|
-
const tenantId = ctx.systemUser
|
|
57
|
-
if (tenantId === undefined) {
|
|
58
|
-
// skip: cron fired without a perTenant fan-out tenant — nothing scoped
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
57
|
+
const tenantId = ctx.systemUser.tenantId;
|
|
61
58
|
const cleanupDb = ctx.db.unsafeRaw(); // @cast-boundary db-operator — jobs never run inside a DbTx
|
|
62
59
|
const tenantPreset = await resolveTenantRetentionPreset({
|
|
63
60
|
db: cleanupDb,
|
|
@@ -47,6 +47,7 @@ export interface RunRetentionCleanupResult {
|
|
|
47
47
|
readonly skipped: readonly RetentionCleanupSkip[];
|
|
48
48
|
}
|
|
49
49
|
export declare function resolveAnonymizeTargets(fields: Readonly<Record<string, unknown>>): Promise<Record<string, unknown> | null>;
|
|
50
|
+
export declare function sameAnonymizedValue(current: unknown, target: unknown): boolean;
|
|
50
51
|
export declare function anonymizeMatchingRows(db: DbRunner, table: Parameters<typeof selectMany>[1], where: WhereObject, batchLimit: number, targets: Record<string, unknown>, op: (id: EntityId, changes: Record<string, unknown>) => Promise<{
|
|
51
52
|
readonly isSuccess: boolean;
|
|
52
53
|
}>): Promise<number>;
|
|
@@ -39,12 +39,13 @@
|
|
|
39
39
|
import { collectPiiSubjectFields, configuredPiiSubjectKms, isPiiCiphertext, isRecordKeyedField, isSelfPiiField, PII_ERASED_SENTINEL, resolveSubjectForField, subjectIdToKey, } from "@cosmicdrift/kumiko-framework/crypto";
|
|
40
40
|
import { createEventStoreExecutor, createTenantDb, nullBlindIndexesForSubject, selectMany, WritePurposes, } from "@cosmicdrift/kumiko-framework/db";
|
|
41
41
|
import { deleteFileRefBytes } from "@cosmicdrift/kumiko-framework/derivatives";
|
|
42
|
-
import { createSystemUser, entityHasAnonymizableSubjectField, } from "@cosmicdrift/kumiko-framework/engine";
|
|
42
|
+
import { createSystemUser, entityHasAnonymizableSubjectField, isUnchangedValue, } from "@cosmicdrift/kumiko-framework/engine";
|
|
43
43
|
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
44
44
|
import { fileRefEntity, fileRefsTable, } from "@cosmicdrift/kumiko-framework/files";
|
|
45
45
|
import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
|
|
46
46
|
import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
47
47
|
import { collectSingleFileHolders, decryptStoredPii, planFileFields, purgeRowFileRefs, runInSubTransaction, } from "../shared/index.js";
|
|
48
|
+
import { eraseNotesOfDeletedRow } from "./erase-notes-of-deleted-row.js";
|
|
48
49
|
import { computeCutoff } from "./keep-for.js";
|
|
49
50
|
import { resolveRetentionPolicyForTenant } from "./resolve-for-tenant.js";
|
|
50
51
|
import { tenantRetentionOverrideTable } from "./schema/tenant-retention-override.js";
|
|
@@ -156,6 +157,13 @@ async function forgetRowAndEraseKeys(args) {
|
|
|
156
157
|
tenantId: args.tenantId,
|
|
157
158
|
row: args.row,
|
|
158
159
|
});
|
|
160
|
+
await eraseNotesOfDeletedRow({
|
|
161
|
+
registry: args.registry,
|
|
162
|
+
tx: sp,
|
|
163
|
+
entityName: args.entityName,
|
|
164
|
+
rowId: String(args.rowId),
|
|
165
|
+
erasedBy: args.systemUser.id,
|
|
166
|
+
});
|
|
159
167
|
return { isSuccess: true };
|
|
160
168
|
});
|
|
161
169
|
}
|
|
@@ -299,11 +307,20 @@ async function rowNeedsAnonymize(row, targets) {
|
|
|
299
307
|
const current = isPiiCiphertext(stored)
|
|
300
308
|
? await decryptStoredPii(stored, field, "retention-anonymize")
|
|
301
309
|
: stored;
|
|
302
|
-
if (current !== PII_ERASED_SENTINEL && current
|
|
310
|
+
if (current !== PII_ERASED_SENTINEL && !sameAnonymizedValue(current, target))
|
|
303
311
|
return true;
|
|
304
312
|
}
|
|
305
313
|
return false;
|
|
306
314
|
}
|
|
315
|
+
// Objects and arrays (JSON fields) are never identical by reference, so they compare by content;
|
|
316
|
+
// jsonb returns keys in its own order, so the comparison must not depend on key order.
|
|
317
|
+
export function sameAnonymizedValue(current, target) {
|
|
318
|
+
if (current === target)
|
|
319
|
+
return true;
|
|
320
|
+
if (typeof target !== "object" || target === null)
|
|
321
|
+
return false;
|
|
322
|
+
return isUnchangedValue(current, target);
|
|
323
|
+
}
|
|
307
324
|
// Anonymize every matching row via the executor (event → rebuild-safe).
|
|
308
325
|
// id-Cursor-paged because the where keeps matching already-anonymized rows;
|
|
309
326
|
// the diff-check keeps the daily re-run event-free. batchLimit bounds the
|
|
@@ -485,23 +502,26 @@ export async function runRetentionCleanup(args) {
|
|
|
485
502
|
// A tenant held in destroyHeld has its expired blockDelete rows removed for good;
|
|
486
503
|
// anonymizing them would keep the account's data stored for nothing.
|
|
487
504
|
if (policy.strategy === "blockDelete" && args.purgeExpiredBlockDelete === true) {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
+
// A row whose reference was never set has no running keepFor, so it would block the release forever.
|
|
506
|
+
for (const expired of [where, { ...where, [referenceField]: null }]) {
|
|
507
|
+
hardDeleted += await hardDeleteMatchingRows({
|
|
508
|
+
db,
|
|
509
|
+
table: proj.table,
|
|
510
|
+
where: expired,
|
|
511
|
+
batchLimit,
|
|
512
|
+
tenantId,
|
|
513
|
+
entityName,
|
|
514
|
+
entity,
|
|
515
|
+
files: args.files,
|
|
516
|
+
systemUser,
|
|
517
|
+
tdb,
|
|
518
|
+
kms,
|
|
519
|
+
registry,
|
|
520
|
+
fileHolders,
|
|
521
|
+
deleteWithoutFileStorage: true,
|
|
522
|
+
skipped,
|
|
523
|
+
});
|
|
524
|
+
}
|
|
505
525
|
break;
|
|
506
526
|
}
|
|
507
527
|
const targets = await resolveAnonymizeTargets(entity.fields);
|