@cosmicdrift/kumiko-bundled-features 0.406.0 → 0.410.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/account-security/feature.js +9 -1
- package/dist/admin-shell/feature.d.ts +3 -0
- package/dist/admin-shell/feature.js +1 -1
- package/dist/agent-tools/agent-manifest.js +1 -0
- package/dist/agent-tools/tool-catalog.js +1 -0
- package/dist/agent-tools/types.d.ts +4 -1
- package/dist/audit/event-classification.js +1 -0
- package/dist/auth-email-password/bootstrap.js +1 -0
- package/dist/auth-email-password/errors.js +16 -41
- package/dist/auth-email-password/handlers/login-options.query.js +1 -1
- package/dist/auth-email-password/handlers/self-registration-status.query.js +1 -1
- package/dist/auth-email-password/web/auth-client.d.ts +8 -32
- package/dist/auth-email-password/web/auth-client.js +18 -52
- package/dist/auth-email-password/web/auth-redirect.js +2 -2
- package/dist/auth-email-password/web/confirm-account-unlock-screen.d.ts +2 -2
- package/dist/auth-email-password/web/confirm-account-unlock-screen.js +14 -35
- package/dist/auth-email-password/web/index.d.ts +1 -0
- package/dist/auth-email-password/web/index.js +1 -0
- package/dist/auth-email-password/web/read-path-param.d.ts +1 -0
- package/dist/auth-email-password/web/read-path-param.js +4 -0
- package/dist/auth-email-password/web/return-path.js +2 -2
- package/dist/auth-email-password/web/token-confirm-screen.d.ts +20 -0
- package/dist/auth-email-password/web/token-confirm-screen.js +38 -0
- package/dist/auth-email-password/web/verify-email-screen.d.ts +2 -2
- package/dist/auth-email-password/web/verify-email-screen.js +14 -37
- package/dist/auth-foundation/boot-checks.js +24 -12
- package/dist/auth-foundation/boot-rules.d.ts +27 -0
- package/dist/auth-foundation/boot-rules.js +27 -0
- package/dist/auth-mfa/errors.d.ts +1 -1
- package/dist/auth-mfa/errors.js +11 -24
- package/dist/auth-mfa/feature-exports.js +6 -45
- package/dist/auth-mfa/feature.js +7 -18
- package/dist/auth-mfa/web/mfa-client.js +11 -25
- package/dist/billing-foundation/consumer-protection/termination-notify.js +1 -0
- package/dist/billing-foundation/web/plan-price.js +7 -8
- package/dist/cap-counter/stock-cap-guard.js +1 -0
- package/dist/channel-in-app/constants.d.ts +1 -0
- package/dist/channel-in-app/feature.js +2 -0
- package/dist/channel-in-app/handlers/read-state-by-keys.query.d.ts +9 -0
- package/dist/channel-in-app/handlers/read-state-by-keys.query.js +21 -0
- package/dist/channel-in-app/in-app-channel.js +1 -0
- package/dist/channel-in-app/tables.js +5 -1
- package/dist/compliance-profiles/handlers/sub-processors.query.js +4 -1
- package/dist/contact/challenge.d.ts +14 -0
- package/dist/contact/challenge.js +30 -0
- package/dist/contact/client/contact-client-source.d.ts +1 -0
- package/dist/contact/client/contact-client-source.js +203 -0
- package/dist/contact/client/contact-website-client.d.ts +26 -0
- package/dist/contact/client/contact-website-client.js +1 -0
- package/dist/contact/client/index.d.ts +2 -0
- package/dist/contact/client/index.js +1 -0
- package/dist/contact/entity.d.ts +777 -0
- package/dist/contact/entity.js +145 -0
- package/dist/contact/feature.d.ts +3 -0
- package/dist/contact/feature.js +134 -0
- package/dist/contact/handlers/access.d.ts +7 -0
- package/dist/contact/handlers/access.js +9 -0
- package/dist/contact/handlers/attempts.d.ts +14 -0
- package/dist/contact/handlers/attempts.js +54 -0
- package/dist/contact/handlers/challenge.query.d.ts +9 -0
- package/dist/contact/handlers/challenge.query.js +35 -0
- package/dist/contact/handlers/forward-request.write.d.ts +9 -0
- package/dist/contact/handlers/forward-request.write.js +61 -0
- package/dist/contact/handlers/mark-done.write.d.ts +7 -0
- package/dist/contact/handlers/mark-done.write.js +30 -0
- package/dist/contact/handlers/notify-reporter-in-app.write.d.ts +10 -0
- package/dist/contact/handlers/notify-reporter-in-app.write.js +36 -0
- package/dist/contact/handlers/open-count.d.ts +2 -0
- package/dist/contact/handlers/open-count.js +11 -0
- package/dist/contact/handlers/open-count.query.d.ts +3 -0
- package/dist/contact/handlers/open-count.query.js +13 -0
- package/dist/contact/handlers/replies.query.d.ts +11 -0
- package/dist/contact/handlers/replies.query.js +28 -0
- package/dist/contact/handlers/reply.write.d.ts +12 -0
- package/dist/contact/handlers/reply.write.js +118 -0
- package/dist/contact/handlers/report.write.d.ts +16 -0
- package/dist/contact/handlers/report.write.js +90 -0
- package/dist/contact/handlers/request-delivery.query.d.ts +16 -0
- package/dist/contact/handlers/request-delivery.query.js +85 -0
- package/dist/contact/handlers/request-detail.query.d.ts +41 -0
- package/dist/contact/handlers/request-detail.query.js +32 -0
- package/dist/contact/handlers/request-list.query.d.ts +2 -0
- package/dist/contact/handlers/request-list.query.js +9 -0
- package/dist/contact/handlers/send-reply-mail.write.d.ts +8 -0
- package/dist/contact/handlers/send-reply-mail.write.js +82 -0
- package/dist/contact/handlers/send-test.write.d.ts +5 -0
- package/dist/contact/handlers/send-test.write.js +36 -0
- package/dist/contact/handlers/submit.write.d.ts +20 -0
- package/dist/contact/handlers/submit.write.js +137 -0
- package/dist/contact/handlers/take-over-uploads.d.ts +9 -0
- package/dist/contact/handlers/take-over-uploads.js +33 -0
- package/dist/contact/i18n.d.ts +6 -0
- package/dist/contact/i18n.js +189 -0
- package/dist/contact/index.d.ts +5 -0
- package/dist/contact/index.js +4 -0
- package/dist/contact/lib.d.ts +101 -0
- package/dist/contact/lib.js +109 -0
- package/dist/contact/mail.d.ts +91 -0
- package/dist/contact/mail.js +279 -0
- package/dist/contact/options.d.ts +51 -0
- package/dist/contact/options.js +32 -0
- package/dist/contact/panels.d.ts +2 -0
- package/dist/contact/panels.js +21 -0
- package/dist/contact/payloads.d.ts +56 -0
- package/dist/contact/payloads.js +82 -0
- package/dist/contact/pow.d.ts +6 -0
- package/dist/contact/pow.js +19 -0
- package/dist/contact/screens.d.ts +5 -0
- package/dist/contact/screens.js +465 -0
- package/dist/contact/subject.d.ts +1 -0
- package/dist/contact/subject.js +13 -0
- package/dist/contact/user-agent.d.ts +1 -0
- package/dist/contact/user-agent.js +35 -0
- package/dist/contact/user-data-hooks.d.ts +3 -0
- package/dist/contact/user-data-hooks.js +129 -0
- package/dist/contact/web/constants.d.ts +127 -0
- package/dist/contact/web/constants.js +126 -0
- package/dist/contact/web/index.d.ts +1 -0
- package/dist/contact/web/index.js +1 -0
- package/dist/crypto-shredding/handlers/forget-subject.write.js +5 -13
- package/dist/data-retention/feature.js +16 -2
- package/dist/data-retention/index.d.ts +1 -0
- package/dist/data-retention/index.js +1 -0
- package/dist/data-retention/run-retention-cleanup.d.ts +14 -2
- package/dist/data-retention/run-retention-cleanup.js +102 -36
- package/dist/data-retention/tenant-destruction-hold.d.ts +23 -0
- package/dist/data-retention/tenant-destruction-hold.js +132 -0
- package/dist/delivery/address-opt-out.js +1 -0
- package/dist/delivery/channel-context.d.ts +1 -1
- package/dist/delivery/channel-context.js +2 -1
- package/dist/delivery/delivery-service.js +18 -8
- package/dist/delivery/events.d.ts +1 -0
- package/dist/delivery/events.js +2 -0
- package/dist/delivery/feature.js +3 -0
- package/dist/delivery/handlers/attempts-by-keys.query.d.ts +15 -0
- package/dist/delivery/handlers/attempts-by-keys.query.js +35 -0
- package/dist/delivery/handlers/log.query.d.ts +1 -0
- package/dist/delivery/handlers/log.query.js +1 -1
- package/dist/delivery/jobs.js +5 -2
- package/dist/delivery/tables.js +12 -2
- package/dist/delivery/types.d.ts +2 -0
- package/dist/delivery/unsubscribe-page.js +2 -0
- package/dist/delivery/web/delivery-channel-cell.js +1 -1
- package/dist/delivery/web/delivery-error-cell.js +1 -1
- package/dist/delivery/web/delivery-status-cell.js +1 -1
- package/dist/delivery/web/delivery-time-cell.js +3 -2
- package/dist/delivery/web/delivery-type-cell.js +1 -1
- package/dist/delivery/web/public-names.d.ts +1 -0
- package/dist/delivery/web/public-names.js +1 -0
- package/dist/document-ingest-foundation/boot-checks.js +19 -11
- package/dist/document-ingest-foundation/boot-rules.d.ts +17 -0
- package/dist/document-ingest-foundation/boot-rules.js +17 -0
- package/dist/document-ingest-foundation/events.d.ts +8 -0
- package/dist/document-ingest-foundation/events.js +12 -0
- package/dist/document-ingest-foundation/feature.js +30 -2
- package/dist/document-ingest-foundation/index.d.ts +3 -1
- package/dist/document-ingest-foundation/index.js +3 -1
- package/dist/document-ingest-foundation/report-ingest-progress.d.ts +14 -0
- package/dist/document-ingest-foundation/report-ingest-progress.js +20 -0
- package/dist/document-ingest-foundation/tables.d.ts +3 -0
- package/dist/document-ingest-foundation/tables.js +26 -0
- 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/files-tenant-data/hooks.js +4 -1
- package/dist/folders/web/folder-manager.js +3 -10
- package/dist/folders/web/folder-section.js +1 -1
- package/dist/form-draft-user-data/index.js +4 -1
- package/dist/inbound-mail-foundation/entities.d.ts +3 -0
- package/dist/inbound-mail-foundation/entities.js +2 -0
- package/dist/inbound-mail-foundation/events.d.ts +2 -0
- package/dist/inbound-mail-foundation/events.js +2 -0
- package/dist/inbound-mail-foundation/feature.js +6 -6
- package/dist/inbound-mail-foundation/handlers/attach-message-content.write.js +3 -1
- package/dist/inbound-mail-foundation/handlers/ingest-message.write.js +5 -0
- package/dist/inbound-mail-foundation/handlers/list-messages.query.js +4 -2
- package/dist/inbound-mail-foundation/handlers/message-content.d.ts +1 -0
- package/dist/inbound-mail-foundation/handlers/message-content.js +8 -0
- package/dist/inbound-mail-foundation/handlers/message-content.query.d.ts +2 -0
- package/dist/inbound-mail-foundation/handlers/message-content.query.js +1 -0
- package/dist/inbound-mail-foundation/projection.d.ts +3 -0
- package/dist/inbound-mail-foundation/projection.js +2 -0
- package/dist/inbound-mail-foundation/sanitize-inbound-html.d.ts +2 -0
- package/dist/inbound-mail-foundation/sanitize-inbound-html.js +135 -0
- package/dist/inbound-mail-foundation/types.js +1 -0
- package/dist/jobs/job-run-logger.js +16 -20
- package/dist/ledger/handlers/reports.query.js +25 -27
- package/dist/ledger/recurring.js +1 -0
- 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/notes-history/web/notes-section.js +3 -2
- package/dist/personal-access-tokens/feature.js +5 -18
- package/dist/personal-access-tokens/handlers/create.write.js +2 -5
- package/dist/secrets/handlers/delete.write.d.ts +4 -0
- package/dist/secrets/handlers/delete.write.js +9 -4
- package/dist/secrets/handlers/list.query.d.ts +6 -1
- package/dist/secrets/handlers/list.query.js +7 -3
- package/dist/secrets/handlers/set.write.d.ts +4 -0
- package/dist/secrets/handlers/set.write.js +10 -4
- package/dist/secrets/secret-scope.d.ts +17 -0
- package/dist/secrets/secret-scope.js +18 -0
- package/dist/seo/handlers/seo-config.query.js +1 -1
- package/dist/sessions/feature.d.ts +3 -0
- package/dist/sessions/feature.js +13 -19
- package/dist/sessions/handlers/last-activity-probe.query.d.ts +7 -0
- package/dist/sessions/handlers/last-activity-probe.query.js +40 -0
- package/dist/sessions/handlers/last-activity-probe.route.d.ts +2 -0
- package/dist/sessions/handlers/last-activity-probe.route.js +30 -0
- package/dist/sessions/screens.js +1 -0
- package/dist/sessions/session-callbacks.d.ts +2 -0
- package/dist/sessions/session-callbacks.js +9 -7
- package/dist/sessions/web/i18n.js +4 -1
- package/dist/shared/assert-billing-live.d.ts +2 -0
- package/dist/shared/assert-billing-live.js +7 -0
- package/dist/shared/collect-extension-options.d.ts +1 -0
- package/dist/shared/collect-extension-options.js +8 -0
- package/dist/shared/index.d.ts +7 -1
- package/dist/shared/index.js +7 -1
- package/dist/shared/late-bound-slot.d.ts +5 -0
- package/dist/shared/late-bound-slot.js +13 -0
- package/dist/shared/mail-locale-templates.d.ts +1 -0
- package/dist/shared/mail-locale-templates.js +1 -1
- package/dist/shared/price-env-shape.d.ts +11 -0
- package/dist/shared/price-env-shape.js +15 -0
- package/dist/shared/purge-row-file-refs.d.ts +1 -0
- package/dist/shared/purge-row-file-refs.js +1 -1
- package/dist/shared/read-feature-export-fn.d.ts +2 -0
- package/dist/shared/read-feature-export-fn.js +11 -0
- package/dist/shared/signup-handover.js +3 -5
- package/dist/shared/tenant-destruction-hold.d.ts +23 -0
- package/dist/shared/tenant-destruction-hold.js +15 -0
- package/dist/shared/unprocessable.d.ts +4 -0
- package/dist/shared/unprocessable.js +4 -0
- package/dist/shared/web/index.d.ts +3 -0
- package/dist/shared/web/index.js +3 -0
- package/dist/subscription-paddle/checkout-config.query.js +1 -1
- package/dist/subscription-paddle/feature.d.ts +1 -5
- package/dist/subscription-paddle/feature.js +7 -9
- package/dist/subscription-paddle/runtime.js +3 -7
- package/dist/subscription-stripe/feature.d.ts +1 -5
- package/dist/subscription-stripe/feature.js +7 -9
- package/dist/subscription-stripe/runtime.js +3 -7
- package/dist/tags/entity.js +1 -0
- package/dist/tags/web/tag-chip.d.ts +7 -0
- package/dist/tags/web/tag-chip.js +4 -0
- package/dist/tags/web/tag-filter.js +2 -5
- package/dist/tags/web/tag-manager.js +1 -1
- package/dist/tags/web/tag-section.js +3 -6
- package/dist/tags/web/tags-cell.js +2 -5
- package/dist/template-resolver/compile-document-body.js +12 -17
- package/dist/template-resolver/handlers/by-slug.query.js +1 -1
- package/dist/template-resolver/handlers/by-tenant.query.js +4 -2
- package/dist/template-resolver/handlers/discard-draft.write.js +1 -0
- package/dist/template-resolver/handlers/overview.query.js +3 -1
- package/dist/template-resolver/handlers/send-test.write.js +2 -4
- package/dist/template-resolver/handlers/toggle-status.write.js +3 -0
- package/dist/template-resolver/linked-resources.js +6 -5
- package/dist/template-resolver/store-template-resource.js +5 -10
- package/dist/template-resolver/web/document-images.js +6 -6
- package/dist/template-resolver/web/document-insert-fields.js +22 -4
- package/dist/template-resolver/web/document-schema.js +11 -12
- package/dist/template-resolver/web/tiptap-attribute-parse-rule.d.ts +15 -0
- package/dist/template-resolver/web/tiptap-attribute-parse-rule.js +11 -0
- package/dist/tenant/i18n.js +3 -0
- package/dist/tenant/schema/tenant.d.ts +9 -7
- package/dist/tenant/schema/tenant.js +1 -0
- package/dist/tenant/web/member-roles-cell.js +1 -1
- package/dist/tenant/web/member-status-cell.js +1 -1
- package/dist/tenant-inactivity/check-inactive-tenants.d.ts +3 -0
- package/dist/tenant-inactivity/check-inactive-tenants.js +184 -0
- package/dist/tenant-inactivity/constants.d.ts +10 -0
- package/dist/tenant-inactivity/constants.js +10 -0
- package/dist/tenant-inactivity/email-templates.d.ts +3 -0
- package/dist/tenant-inactivity/email-templates.js +16 -0
- package/dist/tenant-inactivity/feature.d.ts +8 -0
- package/dist/tenant-inactivity/feature.js +45 -0
- package/dist/tenant-inactivity/handlers/inactivity-state.query.d.ts +11 -0
- package/dist/tenant-inactivity/handlers/inactivity-state.query.js +45 -0
- package/dist/tenant-inactivity/handlers/keep-account.write.d.ts +8 -0
- package/dist/tenant-inactivity/handlers/keep-account.write.js +51 -0
- package/dist/tenant-inactivity/inactivity-plan.d.ts +51 -0
- package/dist/tenant-inactivity/inactivity-plan.js +113 -0
- package/dist/tenant-inactivity/index.d.ts +5 -0
- package/dist/tenant-inactivity/index.js +3 -0
- package/dist/tenant-inactivity/keep-token.d.ts +16 -0
- package/dist/tenant-inactivity/keep-token.js +24 -0
- package/dist/tenant-inactivity/mail-notifications.d.ts +4 -0
- package/dist/tenant-inactivity/mail-notifications.js +42 -0
- package/dist/tenant-inactivity/options.d.ts +27 -0
- package/dist/tenant-inactivity/options.js +5 -0
- package/dist/tenant-inactivity/remote-activity.d.ts +15 -0
- package/dist/tenant-inactivity/remote-activity.js +24 -0
- package/dist/tenant-inactivity/state-store.d.ts +10 -0
- package/dist/tenant-inactivity/state-store.js +50 -0
- package/dist/tenant-inactivity/state-table.d.ts +109 -0
- package/dist/tenant-inactivity/state-table.js +38 -0
- package/dist/tenant-lifecycle/boot-checks.js +8 -3
- package/dist/tenant-lifecycle/boot-rules.d.ts +12 -0
- package/dist/tenant-lifecycle/boot-rules.js +12 -0
- package/dist/tenant-lifecycle/feature.js +17 -2
- package/dist/tenant-lifecycle/handlers/request-destruction.write.js +11 -67
- package/dist/tenant-lifecycle/index.d.ts +1 -0
- package/dist/tenant-lifecycle/index.js +1 -0
- package/dist/tenant-lifecycle/request-tenant-destruction.d.ts +20 -0
- package/dist/tenant-lifecycle/request-tenant-destruction.js +66 -0
- package/dist/tenant-lifecycle/retention-config-destroy-hooks.d.ts +5 -0
- package/dist/tenant-lifecycle/retention-config-destroy-hooks.js +29 -0
- package/dist/tenant-lifecycle/run-tenant-destroy.d.ts +3 -0
- package/dist/tenant-lifecycle/run-tenant-destroy.js +43 -5
- package/dist/tenant-lifecycle/stages.d.ts +2 -0
- package/dist/tenant-lifecycle/stages.js +23 -2
- package/dist/tenant-lifecycle/testing.js +1 -1
- package/dist/tier-engine/caps-for-tier-from-map.d.ts +5 -0
- package/dist/tier-engine/caps-for-tier-from-map.js +12 -0
- package/dist/tier-engine/compose-app.d.ts +0 -22
- package/dist/tier-engine/compose-app.js +9 -16
- package/dist/tier-engine/index.d.ts +1 -0
- package/dist/tier-engine/index.js +1 -0
- package/dist/user/handlers/detail.query.d.ts +1 -1
- package/dist/user-data-rights/feature.js +2 -0
- package/dist/user-data-rights/handlers/confirm-deletion-by-token.write.js +4 -1
- package/dist/user-data-rights/handlers/download-by-token.query.js +1 -0
- package/dist/user-data-rights/handlers/request-deletion-by-email.write.js +4 -1
- package/dist/user-data-rights/run-forget-cleanup.js +2 -0
- package/dist/user-data-rights/web/privacy-center-screen.js +1 -1
- package/dist/user-data-rights/zip-path.js +1 -0
- package/dist/user-data-rights-defaults/hooks/config-value.userdata-hook.d.ts +1 -1
- package/dist/user-data-rights-defaults/hooks/config-value.userdata-hook.js +7 -20
- package/dist/user-data-rights-defaults/hooks/delivery-attempt.userdata-hook.js +3 -1
- package/dist/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.d.ts +10 -0
- package/dist/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.js +26 -0
- package/dist/user-data-rights-defaults/hooks/notification-preference.userdata-hook.d.ts +1 -1
- package/dist/user-data-rights-defaults/hooks/notification-preference.userdata-hook.js +7 -20
- package/dist/user-profile/handlers/change-email.write.js +2 -4
- package/dist/user-profile/web/profile-screen.js +2 -3
- package/dist/waitlist/handlers/submit.write.js +1 -2
- package/kumiko-es-tables.json +12 -0
- package/package.json +54 -12
- package/src/admin-shell/changes.json +6 -0
- package/src/agent-tools/changes.json +6 -0
- package/src/channel-in-app/changes.json +7 -0
- package/src/contact/changes.json +33 -0
- package/src/data-retention/changes.json +6 -0
- package/src/delivery/changes.json +7 -0
- package/src/document-ingest-foundation/changes.json +6 -0
- package/src/files-tenant-data/changes.json +6 -0
- package/src/inbound-mail-foundation/changes.json +13 -0
- package/src/secrets/changes.json +6 -0
- package/src/sessions/changes.json +6 -0
- package/src/tenant-inactivity/changes.json +8 -0
- package/src/tenant-lifecycle/changes.json +18 -0
- package/src/tier-engine/changes.json +6 -0
- package/src/waitlist/changes.json +6 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// blockDelete rows of a tenant under destruction: the mandatory retention period outlives the account.
|
|
2
|
+
// The tenant-lifecycle destroy pipeline keeps those rows (anonymized) and parks the tenant until the
|
|
3
|
+
// retention cleanup has removed them.
|
|
4
|
+
import { createEventStoreExecutor, createTenantDb, selectMany, WritePurposes, } from "@cosmicdrift/kumiko-framework/db";
|
|
5
|
+
import { createSystemUser, } from "@cosmicdrift/kumiko-framework/engine";
|
|
6
|
+
import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
7
|
+
import { collectFileRefIds, planFileFields } from "../shared/index.js";
|
|
8
|
+
import { computeCutoff } from "./keep-for.js";
|
|
9
|
+
import { resolveRetentionPolicyForTenant } from "./resolve-for-tenant.js";
|
|
10
|
+
import { resolveTenantRetentionPreset } from "./resolve-tenant-preset.js";
|
|
11
|
+
import { anonymizeMatchingRows, DEFAULT_REFERENCE_FIELD, FRAMEWORK_REFERENCE_ALIAS, loadOverrideByEntity, resolveAnonymizeTargets, } from "./run-retention-cleanup.js";
|
|
12
|
+
const ANONYMIZE_PAGE_SIZE = 1000;
|
|
13
|
+
async function collectBlockDeleteEntities(args) {
|
|
14
|
+
const { db, registry, tenantId, now } = args;
|
|
15
|
+
const preloadedTenantPreset = await resolveTenantRetentionPreset({ db, registry, tenantId });
|
|
16
|
+
const overrideByEntity = await loadOverrideByEntity(db, tenantId);
|
|
17
|
+
const found = [];
|
|
18
|
+
for (const proj of registry.getAllProjections().values()) {
|
|
19
|
+
if (proj.isImplicit !== true || typeof proj.source !== "string" || !proj.table)
|
|
20
|
+
continue;
|
|
21
|
+
const entityName = proj.source;
|
|
22
|
+
const entity = registry.getEntity(entityName);
|
|
23
|
+
if (!entity)
|
|
24
|
+
continue;
|
|
25
|
+
const { policy } = await resolveRetentionPolicyForTenant({
|
|
26
|
+
db,
|
|
27
|
+
registry,
|
|
28
|
+
tenantId,
|
|
29
|
+
entityName,
|
|
30
|
+
preloadedTenantPreset,
|
|
31
|
+
preloadedOverride: overrideByEntity.get(entityName) ?? null,
|
|
32
|
+
});
|
|
33
|
+
if (policy?.strategy !== "blockDelete")
|
|
34
|
+
continue;
|
|
35
|
+
// Rows of an entity without tenantId column cannot be attributed to this tenant.
|
|
36
|
+
if (propertyOf(proj.table, "tenantId") === undefined)
|
|
37
|
+
continue;
|
|
38
|
+
const declaredReference = policy.reference ?? DEFAULT_REFERENCE_FIELD;
|
|
39
|
+
const referenceField = FRAMEWORK_REFERENCE_ALIAS[declaredReference] ?? declaredReference;
|
|
40
|
+
if (propertyOf(proj.table, referenceField) === undefined)
|
|
41
|
+
continue;
|
|
42
|
+
found.push({
|
|
43
|
+
entityName,
|
|
44
|
+
entity,
|
|
45
|
+
table: proj.table,
|
|
46
|
+
referenceField,
|
|
47
|
+
cutoff: computeCutoff(policy.keepFor, now),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return found;
|
|
51
|
+
}
|
|
52
|
+
async function hasAnyRow(db, table, where) {
|
|
53
|
+
return (await selectMany(db, table, where, { limit: 1 })).length > 0;
|
|
54
|
+
}
|
|
55
|
+
/** True while the tenant still owns rows in an entity whose resolved policy is blockDelete. */
|
|
56
|
+
export async function tenantHasBlockDeleteRows(args) {
|
|
57
|
+
for (const held of await collectBlockDeleteEntities(args)) {
|
|
58
|
+
if (await hasAnyRow(args.db, held.table, { tenantId: args.tenantId }))
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
async function collectHeldRowFileRefIds(args, held, into) {
|
|
64
|
+
const plan = planFileFields(held.entity.fields);
|
|
65
|
+
// skip: an entity without file fields cannot point at a fileRef
|
|
66
|
+
if (plan.singleFields.length === 0 && plan.multiFields.length === 0)
|
|
67
|
+
return;
|
|
68
|
+
let cursor;
|
|
69
|
+
for (;;) {
|
|
70
|
+
const where = cursor === undefined
|
|
71
|
+
? { tenantId: args.tenantId }
|
|
72
|
+
: { tenantId: args.tenantId, id: { gt: cursor } };
|
|
73
|
+
const rows = await selectMany(args.db, held.table, where, {
|
|
74
|
+
limit: ANONYMIZE_PAGE_SIZE,
|
|
75
|
+
orderBy: { col: "id" },
|
|
76
|
+
});
|
|
77
|
+
// skip: the cursor walked past the last held row
|
|
78
|
+
if (rows.length === 0)
|
|
79
|
+
return;
|
|
80
|
+
for (const row of rows) {
|
|
81
|
+
for (const id of await collectFileRefIds(args.db, args.tenantId, held.entityName, row, plan)) {
|
|
82
|
+
into.add(id);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
cursor = String(rows[rows.length - 1]?.["id"]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Entities of the tenant with at least one blockDelete row still inside keepFor. All tenant rows of
|
|
90
|
+
* those entities get their personal fields anonymized (idempotent: already anonymized rows emit no
|
|
91
|
+
* event) and stay; the caller must not delete them, nor the fileRefs they point at.
|
|
92
|
+
*/
|
|
93
|
+
export async function holdBlockDeleteRowsForDestruction(args) {
|
|
94
|
+
const heldEntityNames = new Set();
|
|
95
|
+
const heldFileRefIds = new Set();
|
|
96
|
+
const systemUser = createSystemUser(args.tenantId);
|
|
97
|
+
const tdb = createTenantDb({
|
|
98
|
+
db: args.db,
|
|
99
|
+
tenantId: args.tenantId,
|
|
100
|
+
mode: "system",
|
|
101
|
+
reason: "tenant destruction anonymizes retention-held rows of the tenant being destroyed",
|
|
102
|
+
});
|
|
103
|
+
for (const candidate of await collectBlockDeleteEntities(args)) {
|
|
104
|
+
const { entityName, entity, table } = candidate;
|
|
105
|
+
const stillInsideKeepFor = await hasAnyRow(args.db, table, {
|
|
106
|
+
tenantId: args.tenantId,
|
|
107
|
+
[candidate.referenceField]: { gte: candidate.cutoff },
|
|
108
|
+
});
|
|
109
|
+
if (!stillInsideKeepFor)
|
|
110
|
+
continue;
|
|
111
|
+
heldEntityNames.add(entityName);
|
|
112
|
+
await collectHeldRowFileRefIds(args, candidate, heldFileRefIds);
|
|
113
|
+
const targets = await resolveAnonymizeTargets(entity.fields);
|
|
114
|
+
if (!targets)
|
|
115
|
+
continue;
|
|
116
|
+
const executor = createEventStoreExecutor(table, entity, { entityName });
|
|
117
|
+
let updated = ANONYMIZE_PAGE_SIZE;
|
|
118
|
+
while (updated === ANONYMIZE_PAGE_SIZE) {
|
|
119
|
+
updated = await anonymizeMatchingRows(args.db, table, { tenantId: args.tenantId }, ANONYMIZE_PAGE_SIZE, targets, async (id, changes) => {
|
|
120
|
+
const result = await executor.update({ id, changes }, systemUser, tdb, {
|
|
121
|
+
skipOptimisticLock: true,
|
|
122
|
+
writePurpose: WritePurposes.retention,
|
|
123
|
+
});
|
|
124
|
+
if (!result.isSuccess) {
|
|
125
|
+
throw new Error(`data-retention: failed to anonymize held ${entityName} row ${String(id)}: ${result.error.message}`);
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return { entityNames: heldEntityNames, fileRefIds: heldFileRefIds };
|
|
132
|
+
}
|
|
@@ -15,6 +15,7 @@ export function hashUnsubscribeAddress(address) {
|
|
|
15
15
|
return undefined;
|
|
16
16
|
return computeBlindIndex(key, address.trim().toLowerCase());
|
|
17
17
|
}
|
|
18
|
+
// guard:dup-ok fetchOne over this table's own business key; the preference lookup reads another table
|
|
18
19
|
async function lookup(db, tenantId, addressHash, notificationType, channel) {
|
|
19
20
|
return fetchOne(db, notificationAddressOptOutsTable, {
|
|
20
21
|
tenantId,
|
|
@@ -7,4 +7,4 @@ import { type MailPayload } from "../renderer-foundation/index.ts";
|
|
|
7
7
|
import type { ChannelContext, RenderedMail } from "./types.ts";
|
|
8
8
|
export declare function createTemplateMailRenderer(db: DbConnection | TenantDb, registry: Registry, tenantId: TenantId, config: ConfigAccessor | undefined): (payload: MailPayload) => Promise<RenderedMail>;
|
|
9
9
|
export declare function createEmailAttachmentReader(db: DbConnection | TenantDb, registry: Registry, tenantId: TenantId, config: ConfigAccessor | undefined, filesForTenant: (tenantId: string) => FileContext | undefined): NonNullable<ChannelContext["readAttachment"]>;
|
|
10
|
-
export declare function buildChannelContext(db: DbConnection, registry: Registry, sseBroker: SseBroker | undefined, tenantId: TenantId, secrets?: SecretsContext, tenantConfig?: ConfigAccessor, filesForTenant?: (tenantId: string) => FileContext | undefined): ChannelContext;
|
|
10
|
+
export declare function buildChannelContext(db: DbConnection, registry: Registry, sseBroker: SseBroker | undefined, tenantId: TenantId, secrets?: SecretsContext, tenantConfig?: ConfigAccessor, filesForTenant?: (tenantId: string) => FileContext | undefined, idempotencyKey?: string): ChannelContext;
|
|
@@ -88,7 +88,7 @@ export function createEmailAttachmentReader(db, registry, tenantId, config, file
|
|
|
88
88
|
// Shared by the synchronous delivery-service path and the async job handlers
|
|
89
89
|
// (which pass sseBroker=undefined — only the inline inApp channel uses SSE,
|
|
90
90
|
// and it never runs through a job).
|
|
91
|
-
export function buildChannelContext(db, registry, sseBroker, tenantId, secrets, tenantConfig, filesForTenant) {
|
|
91
|
+
export function buildChannelContext(db, registry, sseBroker, tenantId, secrets, tenantConfig, filesForTenant, idempotencyKey) {
|
|
92
92
|
return {
|
|
93
93
|
db: createTenantDb({ db, tenantId }),
|
|
94
94
|
registry,
|
|
@@ -96,6 +96,7 @@ export function buildChannelContext(db, registry, sseBroker, tenantId, secrets,
|
|
|
96
96
|
tenantId,
|
|
97
97
|
secrets,
|
|
98
98
|
config: tenantConfig,
|
|
99
|
+
...(idempotencyKey !== undefined && { idempotencyKey }),
|
|
99
100
|
renderMail: createTemplateMailRenderer(db, registry, tenantId, tenantConfig),
|
|
100
101
|
...(filesForTenant !== undefined && {
|
|
101
102
|
readAttachment: createEmailAttachmentReader(db, registry, tenantId, tenantConfig, filesForTenant),
|
|
@@ -168,9 +168,15 @@ export function createDeliveryService(options) {
|
|
|
168
168
|
// Single-shot terminal log (inline channels, skips, idempotency dups). Async
|
|
169
169
|
// attempts instead append a queued event up front and a terminal event from
|
|
170
170
|
// the send job — see deliverViaChannel + jobs.ts.
|
|
171
|
+
function withIdempotencyKey(run, entry) {
|
|
172
|
+
return run.idempotencyKey === undefined
|
|
173
|
+
? entry
|
|
174
|
+
: { ...entry, idempotencyKey: run.idempotencyKey };
|
|
175
|
+
}
|
|
171
176
|
async function logDelivery(run, entry) {
|
|
172
|
-
const
|
|
173
|
-
|
|
177
|
+
const stamped = withIdempotencyKey(run, entry);
|
|
178
|
+
const attemptId = await logAttempt(run.db, registry, stamped);
|
|
179
|
+
recordDelivery(run, stamped, attemptId);
|
|
174
180
|
}
|
|
175
181
|
// The stored/returned error is only the code; the redacted message goes to the log.
|
|
176
182
|
async function logInlineFailure(run, args, code, err) {
|
|
@@ -211,7 +217,7 @@ export function createDeliveryService(options) {
|
|
|
211
217
|
error: null,
|
|
212
218
|
priority,
|
|
213
219
|
};
|
|
214
|
-
await appendAttemptEvent(run.db, registry, deliveryAttemptId, queuedEntry);
|
|
220
|
+
await appendAttemptEvent(run.db, registry, deliveryAttemptId, withIdempotencyKey(run, queuedEntry));
|
|
215
221
|
await run.jobDispatcher.dispatch(channel.render ? DeliveryJobs.render : DeliveryJobs.send, {
|
|
216
222
|
channelName: channel.name,
|
|
217
223
|
...(await sealRecipientAddress(address, tenantId, addressCipher)),
|
|
@@ -222,6 +228,7 @@ export function createDeliveryService(options) {
|
|
|
222
228
|
priority,
|
|
223
229
|
message,
|
|
224
230
|
...(run.jobIdempotencyKey !== undefined && { idempotencyKey: run.jobIdempotencyKey }),
|
|
231
|
+
...(run.idempotencyKey !== undefined && { notifyIdempotencyKey: run.idempotencyKey }),
|
|
225
232
|
}, { priority: deliveryPriorityRank[priority] });
|
|
226
233
|
recordDelivery(run, queuedEntry, deliveryAttemptId);
|
|
227
234
|
}
|
|
@@ -345,6 +352,7 @@ export function createDeliveryService(options) {
|
|
|
345
352
|
return addressHash !== undefined && suppressed.has(addressOptOutKey(addressHash, channelName));
|
|
346
353
|
}
|
|
347
354
|
const recipientChannelKey = (userId, channelName) => `${userId}|${channelName}`;
|
|
355
|
+
const isChannelSelected = (run, channelName) => run.channelNames === undefined || run.channelNames.has(channelName);
|
|
348
356
|
// Kill switch, then the user's preference, then the rate limit — the order deliverToUser reports
|
|
349
357
|
// skips in. The rate limit consumes a token, so each recipient/channel pair is evaluated once.
|
|
350
358
|
async function evaluateChannelGate(run, userId, tenantId, notificationType, channelName, priority) {
|
|
@@ -370,10 +378,10 @@ export function createDeliveryService(options) {
|
|
|
370
378
|
async function prefetchRecipients(run, userIds, tenantId, notificationType, priority) {
|
|
371
379
|
const addresses = new Map();
|
|
372
380
|
const gates = new Map();
|
|
373
|
-
const channelCtx = buildChannelContext(run.db, registry, sseBroker, tenantId, secrets, tenantConfigFor?.(tenantId), run.filesForTenant);
|
|
381
|
+
const channelCtx = buildChannelContext(run.db, registry, sseBroker, tenantId, secrets, tenantConfigFor?.(tenantId), run.filesForTenant, run.idempotencyKey);
|
|
374
382
|
for (const userId of userIds) {
|
|
375
383
|
for (const channel of channels) {
|
|
376
|
-
if (!channel.resolve)
|
|
384
|
+
if (!channel.resolve || !isChannelSelected(run, channel.name))
|
|
377
385
|
continue;
|
|
378
386
|
const key = recipientChannelKey(userId, channel.name);
|
|
379
387
|
try {
|
|
@@ -423,10 +431,10 @@ export function createDeliveryService(options) {
|
|
|
423
431
|
return !prefs.some((p) => p.enabled === false);
|
|
424
432
|
}
|
|
425
433
|
async function deliverToUser(userId, notificationType, data, tenantId, priority, run, prefetched, suppressed) {
|
|
426
|
-
const channelCtx = buildChannelContext(run.db, registry, sseBroker, tenantId, secrets, tenantConfigFor?.(tenantId), run.filesForTenant);
|
|
434
|
+
const channelCtx = buildChannelContext(run.db, registry, sseBroker, tenantId, secrets, tenantConfigFor?.(tenantId), run.filesForTenant, run.idempotencyKey);
|
|
427
435
|
for (const channel of channels) {
|
|
428
436
|
// Route-only channel (no per-user address): not a user-notification target.
|
|
429
|
-
if (!channel.resolve)
|
|
437
|
+
if (!channel.resolve || !isChannelSelected(run, channel.name))
|
|
430
438
|
continue;
|
|
431
439
|
const message = buildMessage(notificationType, data, channel.name, run.locale);
|
|
432
440
|
const prefetchKey = recipientChannelKey(userId, channel.name);
|
|
@@ -512,7 +520,7 @@ export function createDeliveryService(options) {
|
|
|
512
520
|
}
|
|
513
521
|
}
|
|
514
522
|
async function deliverDirect(route, notificationType, data, tenantId, priority, recipientId, run) {
|
|
515
|
-
const channelCtx = buildChannelContext(run.db, registry, sseBroker, tenantId, secrets, tenantConfigFor?.(tenantId), run.filesForTenant);
|
|
523
|
+
const channelCtx = buildChannelContext(run.db, registry, sseBroker, tenantId, secrets, tenantConfigFor?.(tenantId), run.filesForTenant, run.idempotencyKey);
|
|
516
524
|
const suppressed = await loadSuppressedAddresses(run, tenantId, notificationType, priority, Object.values(route));
|
|
517
525
|
// Direct routing skips preferences (no user account) but NOT rate limit
|
|
518
526
|
// — direct sends can still be abused (webhook replays, test harnesses).
|
|
@@ -625,7 +633,9 @@ export function createDeliveryService(options) {
|
|
|
625
633
|
deliveries: [],
|
|
626
634
|
jobDispatcher: options.immediate ? undefined : (jobDispatcher ?? jobRunner),
|
|
627
635
|
locale: options.locale,
|
|
636
|
+
channelNames: options.channels === undefined ? undefined : new Set(options.channels),
|
|
628
637
|
jobIdempotencyKey: jobIdempotencyKeyFor(idempotencyKey, route),
|
|
638
|
+
idempotencyKey,
|
|
629
639
|
filesForTenant: fileProviderResolver === undefined
|
|
630
640
|
? filesForTenant
|
|
631
641
|
: (fileTenantId) => fileContextFromResolver(fileProviderResolver, fileTenantId),
|
|
@@ -34,6 +34,7 @@ export declare const deliveryAttemptSchema: z.ZodObject<{
|
|
|
34
34
|
normal: "normal";
|
|
35
35
|
}>;
|
|
36
36
|
confirmed: z.ZodOptional<z.ZodLiteral<false>>;
|
|
37
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
37
38
|
}, z.core.$strip>;
|
|
38
39
|
export type DeliveryAttemptPayload = z.infer<typeof deliveryAttemptSchema>;
|
|
39
40
|
export declare const deliveryAttemptAddressErasedSchema: z.ZodObject<{}, z.core.$strip>;
|
package/dist/delivery/events.js
CHANGED
|
@@ -27,6 +27,8 @@ export const deliveryAttemptSchema = z.object({
|
|
|
27
27
|
priority: z.enum(["critical", "normal", "low"]),
|
|
28
28
|
// Provider accepted the request but does not confirm delivery (e.g. Teams 202).
|
|
29
29
|
confirmed: z.literal(false).optional(),
|
|
30
|
+
// The notify() idempotencyKey, so callers can find their attempts again; set on the first event of an attempt only.
|
|
31
|
+
idempotencyKey: z.string().optional(),
|
|
30
32
|
});
|
|
31
33
|
// No payload: the event only marks the attempt row's address as erased.
|
|
32
34
|
export const deliveryAttemptAddressErasedSchema = z.object({});
|
package/dist/delivery/feature.js
CHANGED
|
@@ -5,6 +5,7 @@ import { projectedAttemptAddress, rememberConnectionNameChannel } from "./attemp
|
|
|
5
5
|
import { resolveAttemptLogRetentionDays, runAttemptLogRetention } from "./attempt-log-retention.js";
|
|
6
6
|
import { DELIVERY_ATTEMPT_ADDRESS_ERASED_EVENT, DELIVERY_ATTEMPT_EVENT, DELIVERY_CHANNEL_CELL_COMPONENT, DELIVERY_CHANNEL_EXTENSION, DELIVERY_ERROR_CELL_COMPONENT, DELIVERY_LOG_SCREEN_ID, DELIVERY_STATUS_CELL_COMPONENT, DELIVERY_TIME_CELL_COMPONENT, DELIVERY_TYPE_CELL_COMPONENT, DeliveryJobNames, DeliveryQueries, } from "./constants.js";
|
|
7
7
|
import { deliveryAttemptAddressErasedSchema, deliveryAttemptSchema } from "./events.js";
|
|
8
|
+
import { attemptsByKeysQuery } from "./handlers/attempts-by-keys.query.js";
|
|
8
9
|
import { logQuery } from "./handlers/log.query.js";
|
|
9
10
|
import { preferencesQuery } from "./handlers/preferences.query.js";
|
|
10
11
|
import { resubscribeAddressWrite } from "./handlers/resubscribe-address.write.js";
|
|
@@ -100,6 +101,7 @@ export function createDeliveryFeature(options) {
|
|
|
100
101
|
error: p.error,
|
|
101
102
|
priority: p.priority,
|
|
102
103
|
confirmed: p.confirmed ?? null,
|
|
104
|
+
idempotencyKey: p.idempotencyKey ?? null,
|
|
103
105
|
}, {
|
|
104
106
|
status: p.status,
|
|
105
107
|
error: p.error,
|
|
@@ -156,6 +158,7 @@ export function createDeliveryFeature(options) {
|
|
|
156
158
|
const queries = {
|
|
157
159
|
log: r.queryHandler({ ...logQuery, access: { roles: resolvedAccess } }),
|
|
158
160
|
preferences: r.queryHandler(preferencesQuery),
|
|
161
|
+
attemptsByKeys: r.queryHandler(attemptsByKeysQuery),
|
|
159
162
|
unsubscribePageChrome: r.queryHandler(unsubscribePageChromeQuery),
|
|
160
163
|
};
|
|
161
164
|
r.screen({
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
export declare const attemptsByKeysQuery: import("@cosmicdrift/kumiko-types/define-handler").QueryHandlerDefinition<"attempts-by-keys", z.ZodObject<{
|
|
3
|
+
keys: z.ZodArray<z.ZodString>;
|
|
4
|
+
}, z.core.$strict>, {
|
|
5
|
+
rows: {
|
|
6
|
+
id: string;
|
|
7
|
+
key: string | null;
|
|
8
|
+
notificationType: string;
|
|
9
|
+
channel: string;
|
|
10
|
+
recipientId: string | null;
|
|
11
|
+
status: string;
|
|
12
|
+
error: import("@cosmicdrift/kumiko-types/handlers").DeliveryErrorCode | null;
|
|
13
|
+
createdAt: globalThis.Temporal.Instant;
|
|
14
|
+
}[];
|
|
15
|
+
}, import("@cosmicdrift/kumiko-types/event-type-map").KumikoEventTypeMap>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { selectMany } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import { access, defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
import { deliveryAttemptsTable } from "../tables.js";
|
|
6
|
+
import { toClientError } from "./log.query.js";
|
|
7
|
+
const MAX_KEYS = 50;
|
|
8
|
+
export const attemptsByKeysQuery = defineQueryHandler({
|
|
9
|
+
name: "attempts-by-keys",
|
|
10
|
+
schema: z.object({ keys: z.array(z.string().min(1).max(256)).min(1).max(MAX_KEYS) }).strict(),
|
|
11
|
+
access: { roles: access.systemAdmin },
|
|
12
|
+
description: "Returns the delivery attempts (channel, status, error code, time, recipient id, never an address) recorded for notify() calls made with one of the given idempotency keys, across all tenants; use it to show whether a notification a feature sent under a known key arrived.",
|
|
13
|
+
handler: async (query, ctx) => {
|
|
14
|
+
if (!ctx.systemDb) {
|
|
15
|
+
throw new InternalError({ message: "attempts-by-keys requires ctx.systemDb" });
|
|
16
|
+
}
|
|
17
|
+
const db = ctx.systemDb.acknowledgeCrossTenant("SystemAdmin reads delivery attempts of a notification across tenants");
|
|
18
|
+
const rows = await selectMany(db, deliveryAttemptsTable, { idempotencyKey: { in: query.payload.keys } }, { orderBy: [{ col: "createdAt", direction: "asc" }] });
|
|
19
|
+
return {
|
|
20
|
+
rows: rows
|
|
21
|
+
// "*" rows only record that a duplicate key was skipped.
|
|
22
|
+
.filter((row) => row.channel !== "*")
|
|
23
|
+
.map((row) => ({
|
|
24
|
+
id: row.id,
|
|
25
|
+
key: row.idempotencyKey,
|
|
26
|
+
notificationType: row.notificationType,
|
|
27
|
+
channel: row.channel,
|
|
28
|
+
recipientId: row.recipientId,
|
|
29
|
+
status: row.status,
|
|
30
|
+
error: toClientError(row.error),
|
|
31
|
+
createdAt: row.createdAt,
|
|
32
|
+
})),
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type DeliveryErrorCode, type NotifyPriority } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import * as z from "zod";
|
|
3
3
|
import type { DeliveryStatusValue } from "../constants.ts";
|
|
4
|
+
export declare function toClientError(stored: string | null): DeliveryErrorCode | null;
|
|
4
5
|
export declare const logQuery: import("@cosmicdrift/kumiko-framework/engine").PagedQueryHandlerDefinition<"log", z.ZodObject<{
|
|
5
6
|
cursor: z.ZodOptional<z.ZodString>;
|
|
6
7
|
limit: z.ZodDefault<z.ZodNumber>;
|
|
@@ -6,7 +6,7 @@ import * as z from "zod";
|
|
|
6
6
|
import { decryptStoredPii } from "../../shared/index.js";
|
|
7
7
|
import { resolveUserDisplayNames, USER_FEATURE } from "../../user/index.js";
|
|
8
8
|
import { deliveryAttemptsTable } from "../tables.js";
|
|
9
|
-
function toClientError(stored) {
|
|
9
|
+
export function toClientError(stored) {
|
|
10
10
|
if (stored === null)
|
|
11
11
|
return null;
|
|
12
12
|
return isDeliveryErrorCode(stored) ? stored : "channel_error";
|
package/dist/delivery/jobs.js
CHANGED
|
@@ -29,6 +29,8 @@ const renderJobBaseSchema = z.object({
|
|
|
29
29
|
priority: z.enum(["critical", "normal", "low"]),
|
|
30
30
|
message: channelMessageSchema,
|
|
31
31
|
idempotencyKey: z.string().optional(),
|
|
32
|
+
// The notify() key as given, for the channel context; idempotencyKey above is only the release key.
|
|
33
|
+
notifyIdempotencyKey: z.string().optional(),
|
|
32
34
|
});
|
|
33
35
|
const renderJobPayloadSchema = renderJobBaseSchema.and(recipientAddressFieldSchema);
|
|
34
36
|
const sendJobPayloadSchema = renderJobBaseSchema
|
|
@@ -177,7 +179,7 @@ async function renderStep(p, ctx) {
|
|
|
177
179
|
const tenantId = p.tenantId; // @cast-boundary engine-payload — stream tenant
|
|
178
180
|
const { db, registry } = requireTenantScopedDeps(ctx, tenantId);
|
|
179
181
|
const channel = resolveChannel(registry, p.channelName);
|
|
180
|
-
const channelCtx = buildChannelContext(db, registry, undefined, tenantId, ctx.services.secrets, ctx.config, (fileTenantId) => fileContextForTenant(ctx, ctx.systemUser.tenantId, fileTenantId));
|
|
182
|
+
const channelCtx = buildChannelContext(db, registry, undefined, tenantId, ctx.services.secrets, ctx.config, (fileTenantId) => fileContextForTenant(ctx, ctx.systemUser.tenantId, fileTenantId), p.notifyIdempotencyKey);
|
|
181
183
|
let rendered;
|
|
182
184
|
try {
|
|
183
185
|
if (!channel.render) {
|
|
@@ -199,6 +201,7 @@ async function renderStep(p, ctx) {
|
|
|
199
201
|
// Deliver via the channel using the rendered payload (if any). On failure:
|
|
200
202
|
// record the terminal failed event and rethrow so BullMQ retries the send with
|
|
201
203
|
// the same already-rendered HTML — no re-render needed.
|
|
204
|
+
// guard:dup-ok one job entry point per step; payload schema and step differ from deliveryRenderJob
|
|
202
205
|
export const deliverySendJob = async (payload, ctx) => {
|
|
203
206
|
const p = sendJobPayloadSchema.parse(payload);
|
|
204
207
|
return releasingKeyOnTerminalFailure(ctx, p, () => sendStep(p, ctx));
|
|
@@ -207,7 +210,7 @@ async function sendStep(p, ctx) {
|
|
|
207
210
|
const tenantId = p.tenantId; // @cast-boundary engine-payload — stream tenant
|
|
208
211
|
const { db, registry } = requireTenantScopedDeps(ctx, tenantId);
|
|
209
212
|
const channel = resolveChannel(registry, p.channelName);
|
|
210
|
-
const channelCtx = buildChannelContext(db, registry, undefined, tenantId, ctx.services.secrets, ctx.config, (fileTenantId) => fileContextForTenant(ctx, ctx.systemUser.tenantId, fileTenantId));
|
|
213
|
+
const channelCtx = buildChannelContext(db, registry, undefined, tenantId, ctx.services.secrets, ctx.config, (fileTenantId) => fileContextForTenant(ctx, ctx.systemUser.tenantId, fileTenantId), p.notifyIdempotencyKey);
|
|
211
214
|
try {
|
|
212
215
|
const address = await openRecipientAddress(p, tenantId, ctx.services.configEncryption);
|
|
213
216
|
const result = await channel.send(address, toMessage(p), channelCtx, p.rendered);
|
package/dist/delivery/tables.js
CHANGED
|
@@ -13,6 +13,7 @@ import { createBooleanField, createEntity, createTextField, } from "@cosmicdrift
|
|
|
13
13
|
// its event stream 1:1 — same convention as jobRunsTable + tenantSecretsTable.
|
|
14
14
|
// Event replays stay idempotent (primary-key conflict instead of duplicate rows).
|
|
15
15
|
const DELIVERY_ATTEMPTS_TENANT_CREATED_INDEX = "store_delivery_attempts_tenant_id_created_at_idx";
|
|
16
|
+
const DELIVERY_ATTEMPTS_TENANT_IDEMPOTENCY_INDEX = "store_delivery_attempts_tenant_id_idempotency_key_idx";
|
|
16
17
|
export const deliveryAttemptsTable = pgTable("store_delivery_attempts", {
|
|
17
18
|
id: uuid("id").primaryKey(),
|
|
18
19
|
tenantId: uuid("tenant_id").notNull(),
|
|
@@ -29,7 +30,12 @@ export const deliveryAttemptsTable = pgTable("store_delivery_attempts", {
|
|
|
29
30
|
// notify() priority from the event payload.
|
|
30
31
|
priority: text("priority").notNull().default("normal").$type(),
|
|
31
32
|
createdAt: instant("created_at").default(sql `now()`).notNull(),
|
|
32
|
-
|
|
33
|
+
// Null for attempts of notify() calls without an idempotencyKey and for rows that predate the column.
|
|
34
|
+
idempotencyKey: text("idempotency_key"),
|
|
35
|
+
}, (t) => [
|
|
36
|
+
index(DELIVERY_ATTEMPTS_TENANT_CREATED_INDEX).on(t.tenantId, t.createdAt),
|
|
37
|
+
index(DELIVERY_ATTEMPTS_TENANT_IDEMPOTENCY_INDEX).on(t.tenantId, t.idempotencyKey),
|
|
38
|
+
]);
|
|
33
39
|
// **Unmanaged table** — deliberately has no createEntity because:
|
|
34
40
|
// - id comes from the aggregate stream (no gen_random_uuid()-DEFAULT)
|
|
35
41
|
// - no version/inserted_by/modified_by/modified_at: no in-place edits or
|
|
@@ -41,7 +47,10 @@ export const deliveryAttemptsTable = pgTable("store_delivery_attempts", {
|
|
|
41
47
|
// from this metadata.
|
|
42
48
|
export const deliveryAttemptsTableMeta = defineUnmanagedTable({
|
|
43
49
|
tableName: "store_delivery_attempts",
|
|
44
|
-
indexes: [
|
|
50
|
+
indexes: [
|
|
51
|
+
{ name: DELIVERY_ATTEMPTS_TENANT_CREATED_INDEX, columns: ["tenant_id", "created_at"] },
|
|
52
|
+
{ name: DELIVERY_ATTEMPTS_TENANT_IDEMPOTENCY_INDEX, columns: ["tenant_id", "idempotency_key"] },
|
|
53
|
+
],
|
|
45
54
|
columns: [
|
|
46
55
|
{ name: "id", pgType: "uuid", notNull: true, primaryKey: true },
|
|
47
56
|
{ name: "tenant_id", pgType: "uuid", notNull: true },
|
|
@@ -54,6 +63,7 @@ export const deliveryAttemptsTableMeta = defineUnmanagedTable({
|
|
|
54
63
|
{ name: "confirmed", pgType: "boolean", notNull: false },
|
|
55
64
|
{ name: "priority", pgType: "text", notNull: true, defaultSql: "'normal'" },
|
|
56
65
|
{ name: "created_at", pgType: "timestamptz", notNull: true, defaultSql: "now()" },
|
|
66
|
+
{ name: "idempotency_key", pgType: "text", notNull: false },
|
|
57
67
|
],
|
|
58
68
|
});
|
|
59
69
|
// User-scoped opt-in/opt-out for (notificationType, channel) pairs. Post-ES
|
package/dist/delivery/types.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export type ChannelContext = {
|
|
|
24
24
|
readonly tenantId: TenantId;
|
|
25
25
|
readonly secrets?: SecretsContext | undefined;
|
|
26
26
|
readonly config?: ConfigAccessor | undefined;
|
|
27
|
+
readonly idempotencyKey?: string | undefined;
|
|
27
28
|
readonly renderMail?: (payload: MailPayload) => Promise<RenderedMail>;
|
|
28
29
|
readonly readAttachment?: (ref: EmailAttachmentRef, origin?: AttachmentOrigin) => Promise<{
|
|
29
30
|
readonly content: Uint8Array;
|
|
@@ -72,6 +73,7 @@ export type DeliveryLogEntry = {
|
|
|
72
73
|
readonly error: DeliveryErrorCode | null;
|
|
73
74
|
readonly priority: NotifyPriority;
|
|
74
75
|
readonly confirmed?: false;
|
|
76
|
+
readonly idempotencyKey?: string;
|
|
75
77
|
};
|
|
76
78
|
export type DeliveryService = {
|
|
77
79
|
notify(notificationType: string, options: NotifyOptions, user: SessionUser, tenantId: TenantId, jobDispatcher?: NotifyJobDispatcher, deliveryDb?: DbConnection, fileProviderResolver?: FileProviderResolver): Promise<NotifyDispatched>;
|
|
@@ -40,6 +40,7 @@ function linkHtml(link) {
|
|
|
40
40
|
}
|
|
41
41
|
// The style block is static apart from the validated hex accent and the markup carries
|
|
42
42
|
// no style attributes, so the CSP admits exactly this block by its hash.
|
|
43
|
+
// guard:dup-ok one template-literal stylesheet; only the shape matches unrelated string builders
|
|
43
44
|
function pageStyle(accent) {
|
|
44
45
|
return `@font-face{font-family:"IBM Plex Sans";font-style:normal;font-weight:400;font-display:swap;src:url("${FONT_URL_PREFIX}400.woff2") format("woff2")}
|
|
45
46
|
@font-face{font-family:"IBM Plex Sans";font-style:normal;font-weight:600;font-display:swap;src:url("${FONT_URL_PREFIX}600.woff2") format("woff2")}
|
|
@@ -101,6 +102,7 @@ function footerHtml(chrome) {
|
|
|
101
102
|
const linesHtml = lineHtmls.join("<br>");
|
|
102
103
|
return linesHtml === "" ? "" : `<footer class="footer">${linesHtml}</footer>`;
|
|
103
104
|
}
|
|
105
|
+
// guard:dup-ok one escaped template-literal form; only the shape matches other HTML snippets
|
|
104
106
|
function tokenForm(action, token, label, variant) {
|
|
105
107
|
return `<form method="post" action="${escapeHtmlAttr(action)}">
|
|
106
108
|
<input type="hidden" name="token" value="${escapeHtmlAttr(token)}">
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Channel column: the label comes from `delivery.channel.<name>`, registered by each
|
|
2
2
|
// channel feature; unknown channels show their raw name.
|
|
3
3
|
import { useTranslation } from "@cosmicdrift/kumiko-renderer";
|
|
4
|
-
import { translateOrRaw } from "../../shared/web/
|
|
4
|
+
import { translateOrRaw } from "../../shared/web/index.js";
|
|
5
5
|
export function DeliveryChannelCell({ row }) {
|
|
6
6
|
const t = useTranslation();
|
|
7
7
|
const channel = typeof row["channel"] === "string" ? row["channel"] : "";
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// takes the status as a parameter, anything unknown shows as the raw value.
|
|
3
3
|
import { useTranslation } from "@cosmicdrift/kumiko-renderer";
|
|
4
4
|
import { HTTP_ERROR_CODE_PATTERN } from "@cosmicdrift/kumiko-types/handlers";
|
|
5
|
-
import { translateOrRaw } from "../../shared/web/
|
|
5
|
+
import { translateOrRaw } from "../../shared/web/index.js";
|
|
6
6
|
export function DeliveryErrorCell({ row }) {
|
|
7
7
|
const t = useTranslation();
|
|
8
8
|
const error = row["error"];
|
|
@@ -5,7 +5,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
5
5
|
// projectionList renderer — only this one cell stays TSX.
|
|
6
6
|
import { useTranslation } from "@cosmicdrift/kumiko-renderer";
|
|
7
7
|
import { StatusBadge } from "@cosmicdrift/kumiko-renderer/web";
|
|
8
|
-
import { translateOrRaw } from "../../shared/web/
|
|
8
|
+
import { translateOrRaw } from "../../shared/web/index.js";
|
|
9
9
|
import { DeliveryStatus } from "./public-names.js";
|
|
10
10
|
const STATUS_TONE = {
|
|
11
11
|
[DeliveryStatus.sent]: "ok",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { formatWhen } from "@cosmicdrift/kumiko-renderer";
|
|
1
|
+
import { formatWhen, useLocale } from "@cosmicdrift/kumiko-renderer";
|
|
2
2
|
export function DeliveryTimeCell({ row }) {
|
|
3
|
+
const locale = useLocale().locale();
|
|
3
4
|
const createdAt = row["createdAt"];
|
|
4
|
-
return typeof createdAt === "string" ? formatWhen(createdAt) : "";
|
|
5
|
+
return typeof createdAt === "string" ? formatWhen(createdAt, locale) : "";
|
|
5
6
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// owns the notification (bundled features register none). Falls back to the short
|
|
4
4
|
// name, or to the raw value for any other format.
|
|
5
5
|
import { useTranslation } from "@cosmicdrift/kumiko-renderer";
|
|
6
|
-
import { translateOrRaw } from "../../shared/web/
|
|
6
|
+
import { translateOrRaw } from "../../shared/web/index.js";
|
|
7
7
|
const NOTIFICATION_QN_PATTERN = /^([^:]+):notify:(.+)$/;
|
|
8
8
|
export function DeliveryTypeCell({ row }) {
|
|
9
9
|
const t = useTranslation();
|
|
@@ -11,6 +11,7 @@ export declare const DELIVERY_RESUBSCRIBE_PATH: "/api/delivery/resubscribe";
|
|
|
11
11
|
export declare const DeliveryQueries: {
|
|
12
12
|
readonly log: "delivery:query:log";
|
|
13
13
|
readonly preferences: "delivery:query:preferences";
|
|
14
|
+
readonly attemptsByKeys: "delivery:query:attempts-by-keys";
|
|
14
15
|
readonly unsubscribePageChrome: "delivery:query:unsubscribe-page-chrome";
|
|
15
16
|
};
|
|
16
17
|
export declare const DELIVERY_LOG_SCREEN_ID: "delivery-log";
|
|
@@ -19,6 +19,7 @@ export const DELIVERY_RESUBSCRIBE_PATH = "/api/delivery/resubscribe";
|
|
|
19
19
|
export const DeliveryQueries = {
|
|
20
20
|
log: "delivery:query:log",
|
|
21
21
|
preferences: "delivery:query:preferences",
|
|
22
|
+
attemptsByKeys: "delivery:query:attempts-by-keys",
|
|
22
23
|
unsubscribePageChrome: "delivery:query:unsubscribe-page-chrome",
|
|
23
24
|
};
|
|
24
25
|
export const DELIVERY_LOG_SCREEN_ID = "delivery-log";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Every job triggered on documentIngest.requested must filter to exactly one
|
|
2
2
|
// registered provider, and every registered provider must have a job wired
|
|
3
3
|
// to it — otherwise requested ingests for that provider never get picked up.
|
|
4
|
+
import { bootRuleError } from "@cosmicdrift/kumiko-framework/engine";
|
|
5
|
+
import { DOCUMENT_INGEST_BOOT_RULES } from "./boot-rules.js";
|
|
4
6
|
import { DOCUMENT_INGEST_REQUESTED_EVENT_QN } from "./events.js";
|
|
5
7
|
import { resolveDocumentIngestProviders } from "./providers.js";
|
|
6
8
|
// undefined = job isn't triggered on documentIngest.requested at all (not our
|
|
@@ -26,16 +28,20 @@ export function validateDocumentIngestProviderWiring(features) {
|
|
|
26
28
|
if (provider === undefined)
|
|
27
29
|
continue;
|
|
28
30
|
if (provider === "") {
|
|
29
|
-
throw
|
|
30
|
-
`
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
throw bootRuleError(DOCUMENT_INGEST_BOOT_RULES.jobWithoutProviderFilter, {
|
|
32
|
+
message: `[kumiko:boot] Job "${jobDef.name}" (feature "${feature.name}") triggers on ` +
|
|
33
|
+
`document-ingest-foundation's documentIngest.requested without a provider filter — every job on ` +
|
|
34
|
+
`this event must route through documentIngestProviderTrigger("<name>"), or it fires for every ` +
|
|
35
|
+
`provider's uploads. Use: trigger: documentIngestProviderTrigger("<name>").`,
|
|
36
|
+
});
|
|
33
37
|
}
|
|
34
38
|
if (!registeredProviderNames.has(provider)) {
|
|
35
|
-
throw
|
|
36
|
-
`
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
throw bootRuleError(DOCUMENT_INGEST_BOOT_RULES.jobUnknownProvider, {
|
|
40
|
+
message: `[kumiko:boot] Job "${jobDef.name}" (feature "${feature.name}") filters documentIngest.requested to ` +
|
|
41
|
+
`provider "${provider}", but no feature registers that provider via ` +
|
|
42
|
+
`r.useExtension(EXT_DOCUMENT_INGEST_PROVIDER, "${provider}", ...). Known: ` +
|
|
43
|
+
`${[...registeredProviderNames].join(", ") || "<none>"}.`,
|
|
44
|
+
});
|
|
39
45
|
}
|
|
40
46
|
wiredProviderNames.add(provider);
|
|
41
47
|
}
|
|
@@ -43,8 +49,10 @@ export function validateDocumentIngestProviderWiring(features) {
|
|
|
43
49
|
for (const name of registeredProviderNames) {
|
|
44
50
|
if (wiredProviderNames.has(name))
|
|
45
51
|
continue;
|
|
46
|
-
throw
|
|
47
|
-
`
|
|
48
|
-
|
|
52
|
+
throw bootRuleError(DOCUMENT_INGEST_BOOT_RULES.providerWithoutJob, {
|
|
53
|
+
message: `[kumiko:boot] Provider "${name}" is registered via EXT_DOCUMENT_INGEST_PROVIDER but no job triggers on ` +
|
|
54
|
+
`documentIngestProviderTrigger("${name}") — files matching its mimeTypes would be requested for ingest ` +
|
|
55
|
+
`and never processed. Add an r.job with that trigger, or unmount the provider.`,
|
|
56
|
+
});
|
|
49
57
|
}
|
|
50
58
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const DOCUMENT_INGEST_BOOT_RULES: {
|
|
2
|
+
readonly jobWithoutProviderFilter: {
|
|
3
|
+
readonly id: "document-ingest-foundation/job-without-provider-filter";
|
|
4
|
+
readonly summary: "A job triggered by documentIngest.requested filters to one provider, so it does not fire for every provider's uploads.";
|
|
5
|
+
readonly fix: 'Use trigger: documentIngestProviderTrigger("<name>").';
|
|
6
|
+
};
|
|
7
|
+
readonly jobUnknownProvider: {
|
|
8
|
+
readonly id: "document-ingest-foundation/job-unknown-provider";
|
|
9
|
+
readonly summary: "A documentIngest.requested job filters to a provider that some feature registers via EXT_DOCUMENT_INGEST_PROVIDER.";
|
|
10
|
+
readonly fix: 'Register the provider via r.useExtension(EXT_DOCUMENT_INGEST_PROVIDER, "<name>", ...) or fix the provider name.';
|
|
11
|
+
};
|
|
12
|
+
readonly providerWithoutJob: {
|
|
13
|
+
readonly id: "document-ingest-foundation/provider-without-job";
|
|
14
|
+
readonly summary: "A registered document-ingest provider has a job triggered by documentIngestProviderTrigger, otherwise requested files are never processed.";
|
|
15
|
+
readonly fix: "Add an r.job with that trigger, or unmount the provider.";
|
|
16
|
+
};
|
|
17
|
+
};
|