@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
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createEventStoreExecutor, fetchOne } from "@cosmicdrift/kumiko-framework/db";
|
|
3
|
-
import { defineWriteHandler, SYSTEM_TENANT_ID } from "@cosmicdrift/kumiko-framework/engine";
|
|
4
|
-
import { UnprocessableError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
5
|
-
import { appendDomainEventCore } from "@cosmicdrift/kumiko-framework/pipeline";
|
|
6
|
-
import { getTemporal } from "@cosmicdrift/kumiko-framework/time";
|
|
1
|
+
import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
7
2
|
import * as z from "zod";
|
|
8
|
-
import {
|
|
9
|
-
import { tenantEntity, tenantTable } from "../../tenant/index.js";
|
|
10
|
-
import { DESTRUCTION_REQUESTED_EVENT_QN, TENANT_LIFECYCLE_FEATURE } from "../constants.js";
|
|
11
|
-
import { revokeTenantSessions } from "../lib/revoke-tenant-sessions.js";
|
|
12
|
-
import { invalidateTenantLifecycleGate } from "../lifecycle-gate.js";
|
|
13
|
-
const crud = createEventStoreExecutor(tenantTable, tenantEntity, { entityName: "tenant" });
|
|
3
|
+
import { requestTenantDestruction } from "../request-tenant-destruction.js";
|
|
14
4
|
const REQUEST_DESTRUCTION_TENANT_ROW_REASON = "reads the caller's tenant row (a global row on the system tenant), its compliance profile, appends to the tenant stream on the system tenant and revokes its sessions via DbRunner helpers";
|
|
15
5
|
export const requestDestructionWrite = defineWriteHandler({
|
|
16
6
|
name: "request-destruction",
|
|
@@ -22,59 +12,13 @@ export const requestDestructionWrite = defineWriteHandler({
|
|
|
22
12
|
grants: ["unsafeRaw"],
|
|
23
13
|
reason: REQUEST_DESTRUCTION_TENANT_ROW_REASON,
|
|
24
14
|
},
|
|
25
|
-
handler: async (event, ctx) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
details: { status: row.status },
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
const { profile } = await resolveProfileForTenant({ db: runner, tenantId });
|
|
38
|
-
const T = getTemporal();
|
|
39
|
-
const gracePeriodEnd = addDurationSpec(T.Now.instant(), profile.tenantDestroyGracePeriod);
|
|
40
|
-
const update = await crud.update({
|
|
41
|
-
id: tenantId,
|
|
42
|
-
changes: {
|
|
43
|
-
status: "destroyRequested",
|
|
44
|
-
destroyRequestedAt: T.Now.instant(),
|
|
45
|
-
destroyRequestedBy: event.user.id,
|
|
46
|
-
gracePeriodEnd,
|
|
47
|
-
},
|
|
48
|
-
}, event.user, ctx.db, { skipOptimisticLock: true });
|
|
49
|
-
if (!update.isSuccess)
|
|
50
|
-
return update;
|
|
51
|
-
invalidateTenantLifecycleGate(tenantId);
|
|
52
|
-
await appendDomainEventCore({
|
|
53
|
-
registry: ctx.registry,
|
|
54
|
-
db: runner,
|
|
55
|
-
tenantId: SYSTEM_TENANT_ID,
|
|
56
|
-
userId: String(event.user.id),
|
|
57
|
-
callSiteLabel: "tenant-lifecycle request-destruction",
|
|
58
|
-
callerFeature: TENANT_LIFECYCLE_FEATURE,
|
|
59
|
-
}, {
|
|
60
|
-
aggregateId: tenantId,
|
|
61
|
-
aggregateType: "tenant",
|
|
62
|
-
type: DESTRUCTION_REQUESTED_EVENT_QN,
|
|
63
|
-
payload: {
|
|
64
|
-
requestedBy: event.user.id,
|
|
65
|
-
gracePeriodEnd: gracePeriodEnd.toString(),
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
if (await ctx.hasFeature("sessions")) {
|
|
69
|
-
await revokeTenantSessions(runner, tenantId);
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
isSuccess: true,
|
|
73
|
-
data: {
|
|
74
|
-
tenantId,
|
|
75
|
-
status: "destroyRequested",
|
|
76
|
-
gracePeriodEnd: gracePeriodEnd.toString(),
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
},
|
|
15
|
+
handler: async (event, ctx) => requestTenantDestruction({
|
|
16
|
+
tenantId: event.user.tenantId,
|
|
17
|
+
actor: event.user,
|
|
18
|
+
now: ctx.tz.now(),
|
|
19
|
+
db: ctx.db,
|
|
20
|
+
runner: ctx.db.unsafeRaw(),
|
|
21
|
+
registry: ctx.registry,
|
|
22
|
+
revokeSessions: await ctx.hasFeature("sessions"),
|
|
23
|
+
}),
|
|
80
24
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { archiveAndDeleteTenantRows, TENANT_DESTROY_ARCHIVE_REASON, TENANT_DESTROY_ARCHIVED_BY, } from "./archive-and-delete-tenant-rows.ts";
|
|
2
2
|
export { TENANT_DESTRUCTION_STAGE_FAILED_EVENT_QN, TENANT_DESTRUCTION_STAGE_PROGRESSED_EVENT_QN, TENANT_DESTRUCTION_STAGES, TENANT_LIFECYCLE_FEATURE, TenantLifecycleHandlers, } from "./constants.ts";
|
|
3
3
|
export { createTenantLifecycleFeature } from "./feature.ts";
|
|
4
|
+
export { type RequestTenantDestructionArgs, requestTenantDestruction, } from "./request-tenant-destruction.ts";
|
|
4
5
|
export { resolveTenantLifecycleGate } from "./run-tenant-destroy.ts";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { archiveAndDeleteTenantRows, TENANT_DESTROY_ARCHIVE_REASON, TENANT_DESTROY_ARCHIVED_BY, } from "./archive-and-delete-tenant-rows.js";
|
|
2
2
|
export { TENANT_DESTRUCTION_STAGE_FAILED_EVENT_QN, TENANT_DESTRUCTION_STAGE_PROGRESSED_EVENT_QN, TENANT_DESTRUCTION_STAGES, TENANT_LIFECYCLE_FEATURE, TenantLifecycleHandlers, } from "./constants.js";
|
|
3
3
|
export { createTenantLifecycleFeature } from "./feature.js";
|
|
4
|
+
export { requestTenantDestruction, } from "./request-tenant-destruction.js";
|
|
4
5
|
export { resolveTenantLifecycleGate } from "./run-tenant-destroy.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type DbRunner, type TenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import { type Registry, type SessionUser, type TenantId } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
import type { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
4
|
+
export type RequestTenantDestructionArgs = {
|
|
5
|
+
readonly tenantId: TenantId;
|
|
6
|
+
readonly actor: SessionUser;
|
|
7
|
+
readonly now: Temporal.Instant;
|
|
8
|
+
readonly db: TenantDb;
|
|
9
|
+
readonly runner: DbRunner;
|
|
10
|
+
readonly registry: Registry;
|
|
11
|
+
readonly revokeSessions: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare function requestTenantDestruction(args: RequestTenantDestructionArgs): Promise<import("@cosmicdrift/kumiko-types/write-error-info-types").WriteFailure | {
|
|
14
|
+
isSuccess: true;
|
|
15
|
+
data: {
|
|
16
|
+
tenantId: string;
|
|
17
|
+
status: "destroyRequested";
|
|
18
|
+
gracePeriodEnd: string;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { addDurationSpec } from "@cosmicdrift/kumiko-framework/compliance";
|
|
2
|
+
import { createEventStoreExecutor, fetchOne, } from "@cosmicdrift/kumiko-framework/db";
|
|
3
|
+
import { SYSTEM_TENANT_ID, } from "@cosmicdrift/kumiko-framework/engine";
|
|
4
|
+
import { UnprocessableError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
5
|
+
import { appendDomainEventCore } from "@cosmicdrift/kumiko-framework/pipeline";
|
|
6
|
+
import { resolveProfileForTenant } from "../compliance-profiles/index.js";
|
|
7
|
+
import { tenantEntity, tenantTable } from "../tenant/index.js";
|
|
8
|
+
import { DESTRUCTION_REQUESTED_EVENT_QN, TENANT_LIFECYCLE_FEATURE } from "./constants.js";
|
|
9
|
+
import { revokeTenantSessions } from "./lib/revoke-tenant-sessions.js";
|
|
10
|
+
import { invalidateTenantLifecycleGate } from "./lifecycle-gate.js";
|
|
11
|
+
const crud = createEventStoreExecutor(tenantTable, tenantEntity, { entityName: "tenant" });
|
|
12
|
+
// Shared by the owner-facing request-destruction handler and by system callers such as
|
|
13
|
+
// tenant-inactivity, so both start the same compliance-profile grace period.
|
|
14
|
+
export async function requestTenantDestruction(args) {
|
|
15
|
+
const { tenantId, actor, now, db, runner, registry } = args;
|
|
16
|
+
const row = await fetchOne(runner, tenantTable, { id: tenantId });
|
|
17
|
+
if (!row) {
|
|
18
|
+
return writeFailure(new UnprocessableError("tenant_not_found", { details: { tenantId } }));
|
|
19
|
+
}
|
|
20
|
+
if (row.status !== "active") {
|
|
21
|
+
return writeFailure(new UnprocessableError("tenant_not_active", {
|
|
22
|
+
details: { status: row.status },
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
const { profile } = await resolveProfileForTenant({ db: runner, tenantId });
|
|
26
|
+
const gracePeriodEnd = addDurationSpec(now, profile.tenantDestroyGracePeriod);
|
|
27
|
+
const update = await crud.update({
|
|
28
|
+
id: tenantId,
|
|
29
|
+
changes: {
|
|
30
|
+
status: "destroyRequested",
|
|
31
|
+
destroyRequestedAt: now,
|
|
32
|
+
destroyRequestedBy: actor.id,
|
|
33
|
+
gracePeriodEnd,
|
|
34
|
+
},
|
|
35
|
+
}, actor, db, { skipOptimisticLock: true });
|
|
36
|
+
if (!update.isSuccess)
|
|
37
|
+
return update;
|
|
38
|
+
invalidateTenantLifecycleGate(tenantId);
|
|
39
|
+
await appendDomainEventCore({
|
|
40
|
+
registry,
|
|
41
|
+
db: runner,
|
|
42
|
+
tenantId: SYSTEM_TENANT_ID,
|
|
43
|
+
userId: String(actor.id),
|
|
44
|
+
callSiteLabel: "tenant-lifecycle request-destruction",
|
|
45
|
+
callerFeature: TENANT_LIFECYCLE_FEATURE,
|
|
46
|
+
}, {
|
|
47
|
+
aggregateId: tenantId,
|
|
48
|
+
aggregateType: "tenant",
|
|
49
|
+
type: DESTRUCTION_REQUESTED_EVENT_QN,
|
|
50
|
+
payload: {
|
|
51
|
+
requestedBy: actor.id,
|
|
52
|
+
gracePeriodEnd: gracePeriodEnd.toString(),
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
if (args.revokeSessions) {
|
|
56
|
+
await revokeTenantSessions(runner, tenantId);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
isSuccess: true,
|
|
60
|
+
data: {
|
|
61
|
+
tenantId,
|
|
62
|
+
status: "destroyRequested",
|
|
63
|
+
gracePeriodEnd: gracePeriodEnd.toString(),
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type TenantDataHookCtx } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
export declare const COMPLIANCE_PROFILE_ENTITY_NAME = "tenant-compliance-profile";
|
|
3
|
+
export declare const RETENTION_OVERRIDE_ENTITY_NAME = "tenant-retention-override";
|
|
4
|
+
export declare function complianceProfileTenantDestroyHook(ctx: TenantDataHookCtx): Promise<void>;
|
|
5
|
+
export declare function retentionOverrideTenantDestroyHook(ctx: TenantDataHookCtx): Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// The tenant's retention configuration (compliance profile, retention overrides) decides which
|
|
2
|
+
// entities are blockDelete-held. It is erased in the "tenant-row" phase, after the hold check, because
|
|
3
|
+
// deleting it earlier would change the hold predicate while the tenant still waits on held rows.
|
|
4
|
+
import { createEventStoreExecutor } from "@cosmicdrift/kumiko-framework/db";
|
|
5
|
+
import { createSystemUser, } from "@cosmicdrift/kumiko-framework/engine";
|
|
6
|
+
import { tenantComplianceProfileEntity, tenantComplianceProfileTable, } from "../compliance-profiles/index.js";
|
|
7
|
+
import { tenantRetentionOverrideEntity, tenantRetentionOverrideTable, } from "../data-retention/index.js";
|
|
8
|
+
export const COMPLIANCE_PROFILE_ENTITY_NAME = "tenant-compliance-profile";
|
|
9
|
+
export const RETENTION_OVERRIDE_ENTITY_NAME = "tenant-retention-override";
|
|
10
|
+
async function forgetAllTenantRows(ctx, table, entity, entityName) {
|
|
11
|
+
const executor = createEventStoreExecutor(table, entity, { entityName });
|
|
12
|
+
const user = createSystemUser(ctx.tenantId);
|
|
13
|
+
const rows = await ctx.db.selectMany(table, { tenantId: ctx.tenantId });
|
|
14
|
+
for (const row of rows) {
|
|
15
|
+
const forgotten = await executor.forget({ id: row.id }, user, ctx.db);
|
|
16
|
+
if (!forgotten.isSuccess) {
|
|
17
|
+
throw new Error(`tenant-lifecycle: failed to forget ${entityName} ${row.id} for tenant ${ctx.tenantId}: ${forgotten.error.message}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export async function complianceProfileTenantDestroyHook(ctx) {
|
|
22
|
+
await forgetAllTenantRows(ctx, tenantComplianceProfileTable, tenantComplianceProfileEntity, COMPLIANCE_PROFILE_ENTITY_NAME);
|
|
23
|
+
}
|
|
24
|
+
export async function retentionOverrideTenantDestroyHook(ctx) {
|
|
25
|
+
// skip: data-retention is optional, without it the override table does not exist
|
|
26
|
+
if (!ctx.registry.getEntity(RETENTION_OVERRIDE_ENTITY_NAME))
|
|
27
|
+
return;
|
|
28
|
+
await forgetAllTenantRows(ctx, tenantRetentionOverrideTable, tenantRetentionOverrideEntity, RETENTION_OVERRIDE_ENTITY_NAME);
|
|
29
|
+
}
|
|
@@ -4,12 +4,14 @@ import { type EscapeHatchAuditSink, type Registry, type TenantId } from "@cosmic
|
|
|
4
4
|
import type { FileProviderResolver } from "@cosmicdrift/kumiko-framework/files";
|
|
5
5
|
import type { Logger } from "@cosmicdrift/kumiko-framework/logging";
|
|
6
6
|
import type { SearchAdapter } from "@cosmicdrift/kumiko-framework/search";
|
|
7
|
+
import type { TenantDestructionHoldProvider } from "../shared/index.ts";
|
|
7
8
|
type StageTickResult = {
|
|
8
9
|
readonly done: boolean;
|
|
9
10
|
readonly error?: string;
|
|
10
11
|
readonly halted?: boolean;
|
|
11
12
|
readonly progressed?: boolean;
|
|
12
13
|
readonly pending?: boolean;
|
|
14
|
+
readonly held?: boolean;
|
|
13
15
|
};
|
|
14
16
|
export declare function runNextDestructionStage(args: {
|
|
15
17
|
readonly db: DbRunner;
|
|
@@ -25,6 +27,7 @@ export declare function runNextDestructionStage(args: {
|
|
|
25
27
|
readonly now?: Temporal.Instant;
|
|
26
28
|
}): Promise<StageTickResult>;
|
|
27
29
|
export declare function hasTenantDestructionWork(reads: Pick<TenantDb, "count">, now: Temporal.Instant): Promise<boolean>;
|
|
30
|
+
export declare const tenantDestructionHoldProvider: TenantDestructionHoldProvider;
|
|
28
31
|
/** Cron entry: start destruction for tenants past grace, then advance stages. */
|
|
29
32
|
export declare function runTenantDestructionSweep(args: {
|
|
30
33
|
readonly db: DbRunner;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { createEventStoreExecutor, createTenantDb, selectMany, WritePurposes, } from "@cosmicdrift/kumiko-framework/db";
|
|
1
|
+
import { createEventStoreExecutor, createTenantDb, fetchOne, selectMany, WritePurposes, } from "@cosmicdrift/kumiko-framework/db";
|
|
2
2
|
import { createSystemUser, SYSTEM_TENANT_ID, } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
3
|
import { append, loadAggregate, VersionConflictError, } from "@cosmicdrift/kumiko-framework/event-store";
|
|
4
4
|
import { getTemporal } from "@cosmicdrift/kumiko-framework/time";
|
|
5
|
+
import { tenantHasBlockDeleteRows } from "../data-retention/index.js";
|
|
5
6
|
import { tenantEntity, tenantTable } from "../tenant/index.js";
|
|
6
7
|
import { DESTRUCTION_STAGE_MAX_PENDING_MS, DESTRUCTION_STAGE_MIN_SLICE_MS, DESTRUCTION_STAGE_TICK_BUDGET_MS, TENANT_AGGREGATE_TYPE, TENANT_DESTRUCTION_COMPLETED_EVENT_QN, TENANT_DESTRUCTION_FAILED_EVENT_QN, TENANT_DESTRUCTION_STAGE_ABANDONED_EVENT_SHORT, TENANT_DESTRUCTION_STAGE_FAILED_EVENT_SHORT, TENANT_DESTRUCTION_STAGE_PROGRESSED_EVENT_SHORT, TENANT_DESTRUCTION_STAGE_STARTED_EVENT_SHORT, TENANT_DESTRUCTION_STAGE_SUCCEEDED_EVENT_SHORT, TENANT_DESTRUCTION_STARTED_EVENT_SHORT, } from "./constants.js";
|
|
7
8
|
import { invalidateTenantLifecycleGate, TEARDOWN_GATE_SETTLE_MS } from "./lifecycle-gate.js";
|
|
@@ -101,7 +102,7 @@ async function appendTenantStageEventIdempotent(db, tenantId, type, payload, exp
|
|
|
101
102
|
const events = await loadAggregate(db, tenantId, SYSTEM_TENANT_ID);
|
|
102
103
|
return lastEventVersion(events);
|
|
103
104
|
}
|
|
104
|
-
async function
|
|
105
|
+
async function setTenantLifecycleStatus(db, tenantId, status) {
|
|
105
106
|
const user = createSystemUser(tenantId);
|
|
106
107
|
const scopedDb = createTenantDb({
|
|
107
108
|
db,
|
|
@@ -111,10 +112,16 @@ async function markTenantDestroyFailed(db, tenantId) {
|
|
|
111
112
|
});
|
|
112
113
|
await tenantCrud.update({
|
|
113
114
|
id: tenantId,
|
|
114
|
-
changes: { status
|
|
115
|
+
changes: { status },
|
|
115
116
|
}, user, scopedDb, { skipOptimisticLock: true, writePurpose: WritePurposes.erasure });
|
|
116
117
|
invalidateTenantLifecycleGate(tenantId);
|
|
117
118
|
}
|
|
119
|
+
// True while the tenant still owns rows whose blockDelete retention has not run out.
|
|
120
|
+
async function tenantOwnsRetentionHeldRows(args) {
|
|
121
|
+
if (!args.registry.features.has("data-retention"))
|
|
122
|
+
return false;
|
|
123
|
+
return await tenantHasBlockDeleteRows(args);
|
|
124
|
+
}
|
|
118
125
|
async function haltPipelineOnAbandon(args) {
|
|
119
126
|
const T = getTemporal();
|
|
120
127
|
const failedAt = T.Now.instant();
|
|
@@ -127,7 +134,7 @@ async function haltPipelineOnAbandon(args) {
|
|
|
127
134
|
const eventsAfterAbandon = await loadAggregate(args.db, args.tenantId, SYSTEM_TENANT_ID);
|
|
128
135
|
const versionAfterAbandon = lastEventVersion(eventsAfterAbandon);
|
|
129
136
|
await appendTenantStageEvent(args.db, args.tenantId, TENANT_DESTRUCTION_FAILED_EVENT_QN, { stage: args.stage, error: args.error, failedAt: failedAt.toString() }, versionAfterAbandon);
|
|
130
|
-
await
|
|
137
|
+
await setTenantLifecycleStatus(args.db, args.tenantId, "destroyFailed");
|
|
131
138
|
}
|
|
132
139
|
async function maybeAppendDestructionCompleted(db, tenantId, completed) {
|
|
133
140
|
if (!isDestructionPipelineComplete(completed)) {
|
|
@@ -190,6 +197,17 @@ export async function runNextDestructionStage(args) {
|
|
|
190
197
|
await maybeAppendDestructionCompleted(args.db, args.tenantId, completed);
|
|
191
198
|
return { done: isDestructionPipelineComplete(completed) };
|
|
192
199
|
}
|
|
200
|
+
// Parking is no stage attempt: no stage-started event, no attempt count, no failure.
|
|
201
|
+
if (next.name === "tenant-row" &&
|
|
202
|
+
(await tenantOwnsRetentionHeldRows({
|
|
203
|
+
db: args.db,
|
|
204
|
+
registry: args.registry,
|
|
205
|
+
tenantId: args.tenantId,
|
|
206
|
+
now,
|
|
207
|
+
}))) {
|
|
208
|
+
await setTenantLifecycleStatus(args.db, args.tenantId, "destroyHeld");
|
|
209
|
+
return { done: false, held: true };
|
|
210
|
+
}
|
|
193
211
|
const priorAttempts = attemptsByStage.get(next.name) ?? 0;
|
|
194
212
|
const attempt = priorAttempts + 1;
|
|
195
213
|
const ctx = {
|
|
@@ -203,6 +221,7 @@ export async function runNextDestructionStage(args) {
|
|
|
203
221
|
escapeHatchAuditLog: args.escapeHatchAuditLog,
|
|
204
222
|
actor: args.actor,
|
|
205
223
|
deadlineAt: args.deadlineAt ?? Date.now() + DESTRUCTION_STAGE_TICK_BUDGET_MS,
|
|
224
|
+
now,
|
|
206
225
|
};
|
|
207
226
|
let version = lastEventVersion(events);
|
|
208
227
|
if (!isStageContinuation(events, next.name)) {
|
|
@@ -260,6 +279,25 @@ export async function hasTenantDestructionWork(reads, now) {
|
|
|
260
279
|
]);
|
|
261
280
|
return due > 0 || destroying > 0;
|
|
262
281
|
}
|
|
282
|
+
// A destroyHeld tenant is not sweep work: the daily retention run releases it once its last held row
|
|
283
|
+
// is gone, and the sweep then runs tenant-row as a fresh first attempt.
|
|
284
|
+
export const tenantDestructionHoldProvider = {
|
|
285
|
+
async isParked({ db, tenantId }) {
|
|
286
|
+
return (await tenantStatusOf(db, tenantId)) === "destroyHeld";
|
|
287
|
+
},
|
|
288
|
+
async releaseIfFree({ db, registry, tenantId, now }) {
|
|
289
|
+
if ((await tenantStatusOf(db, tenantId)) !== "destroyHeld")
|
|
290
|
+
return false;
|
|
291
|
+
if (await tenantOwnsRetentionHeldRows({ db, registry, tenantId, now }))
|
|
292
|
+
return false;
|
|
293
|
+
await setTenantLifecycleStatus(db, tenantId, "destroying");
|
|
294
|
+
return true;
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
async function tenantStatusOf(db, tenantId) {
|
|
298
|
+
const row = await fetchOne(db, tenantTable, { id: tenantId });
|
|
299
|
+
return row?.status;
|
|
300
|
+
}
|
|
263
301
|
/** Cron entry: start destruction for tenants past grace, then advance stages. */
|
|
264
302
|
export async function runTenantDestructionSweep(args) {
|
|
265
303
|
const T = getTemporal();
|
|
@@ -312,7 +350,7 @@ export async function runTenantDestructionSweep(args) {
|
|
|
312
350
|
escapeHatchAuditLog: args.escapeHatchAuditLog,
|
|
313
351
|
actor: args.actor,
|
|
314
352
|
});
|
|
315
|
-
if (!result.error && !result.halted)
|
|
353
|
+
if (!result.error && !result.halted && !result.held)
|
|
316
354
|
advanced++;
|
|
317
355
|
}
|
|
318
356
|
catch (err) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="temporal-polyfill/global" preserve="true" />
|
|
1
2
|
import { type DbRunner } from "@cosmicdrift/kumiko-framework/db";
|
|
2
3
|
import { type EscapeHatchAuditSink, type Registry, type TenantId } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
4
|
import type { FileProviderResolver } from "@cosmicdrift/kumiko-framework/files";
|
|
@@ -15,6 +16,7 @@ export type DestructionStageCtx = {
|
|
|
15
16
|
readonly escapeHatchAuditLog?: Logger;
|
|
16
17
|
readonly actor?: string;
|
|
17
18
|
readonly deadlineAt: number;
|
|
19
|
+
readonly now: Temporal.Instant;
|
|
18
20
|
};
|
|
19
21
|
export type StageRunOutcome = {
|
|
20
22
|
readonly done: boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="temporal-polyfill/global" preserve="true" />
|
|
1
2
|
import { configuredPiiSubjectKms, subjectIdToKey, } from "@cosmicdrift/kumiko-framework/crypto";
|
|
2
3
|
import { createEventStoreExecutor, createTenantDataDestroyDb, createTenantDb, selectMany, WritePurposes, } from "@cosmicdrift/kumiko-framework/db";
|
|
3
4
|
import { createSystemUser, EXT_EXTERNAL_RESOURCE, EXT_INFRA_RESOURCE, EXT_SEARCH_ADAPTER, EXT_STORAGE_PROVIDER, EXT_TENANT_DATA, extensionUsageEscapeHatchReason, isTenantDataExtensionHooks, isTenantResourceExtensionHooks, } from "@cosmicdrift/kumiko-framework/engine";
|
|
@@ -5,6 +6,7 @@ import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
|
|
|
5
6
|
import { createEscapeHatchReporter, UNATTRIBUTED_ACTOR, } from "@cosmicdrift/kumiko-framework/pipeline";
|
|
6
7
|
import { purgeSearchDocumentsForSubject, } from "@cosmicdrift/kumiko-framework/search";
|
|
7
8
|
import { getTemporal } from "@cosmicdrift/kumiko-framework/time";
|
|
9
|
+
import { holdBlockDeleteRowsForDestruction, } from "../data-retention/index.js";
|
|
8
10
|
import { tenantEntity, tenantMembershipEntity, tenantMembershipsTable, tenantTable, } from "../tenant/index.js";
|
|
9
11
|
import { invalidateTenantLifecycleGate } from "./lifecycle-gate.js";
|
|
10
12
|
const STAGE_DONE = { done: true, processed: 0 };
|
|
@@ -41,13 +43,28 @@ async function runExtensionDestroyHooks(registry, extensionName, ctx) {
|
|
|
41
43
|
}
|
|
42
44
|
return total.outcome();
|
|
43
45
|
}
|
|
44
|
-
|
|
46
|
+
const NOTHING_HELD = { entityNames: new Set(), fileRefIds: new Set() };
|
|
47
|
+
async function runTenantDataHooks(ctx, phase) {
|
|
45
48
|
const usages = ctx.registry.getExtensionUsages(EXT_TENANT_DATA);
|
|
46
49
|
const total = newOutcomeAccumulator();
|
|
50
|
+
// Rows inside a blockDelete keepFor must outlive the account; their hook is skipped, the rows are
|
|
51
|
+
// anonymized and the fileRefs they point at are handed to the other hooks. Recomputed every tick.
|
|
52
|
+
const hold = phase === "app-data" && ctx.registry.features.has("data-retention")
|
|
53
|
+
? await holdBlockDeleteRowsForDestruction({
|
|
54
|
+
db: ctx.db,
|
|
55
|
+
registry: ctx.registry,
|
|
56
|
+
tenantId: ctx.tenantId,
|
|
57
|
+
now: ctx.now,
|
|
58
|
+
})
|
|
59
|
+
: NOTHING_HELD;
|
|
47
60
|
for (const usage of usages) {
|
|
48
61
|
if (!isTenantDataExtensionHooks(usage.options)) {
|
|
49
62
|
throw new Error(`${EXT_TENANT_DATA} registration for "${usage.entityName}" has no destroy function`);
|
|
50
63
|
}
|
|
64
|
+
if ((usage.options["phase"] ?? "app-data") !== phase)
|
|
65
|
+
continue;
|
|
66
|
+
if (hold.entityNames.has(usage.entityName))
|
|
67
|
+
continue;
|
|
51
68
|
const destroy = usage.options.destroy;
|
|
52
69
|
const reason = extensionUsageEscapeHatchReason(usage);
|
|
53
70
|
const report = createEscapeHatchReporter({
|
|
@@ -70,6 +87,7 @@ async function runTenantDataHooks(ctx) {
|
|
|
70
87
|
tenantId: ctx.tenantId,
|
|
71
88
|
deadlineAt: ctx.deadlineAt,
|
|
72
89
|
fileProviderResolver: ctx.fileProviderResolver,
|
|
90
|
+
heldFileRefIds: hold.fileRefIds,
|
|
73
91
|
log: ctx.log,
|
|
74
92
|
};
|
|
75
93
|
total.add(await destroy(hookCtx));
|
|
@@ -131,6 +149,9 @@ async function purgeTenantCache(ctx) {
|
|
|
131
149
|
return STAGE_DONE;
|
|
132
150
|
}
|
|
133
151
|
async function tombstoneTenantRow(ctx) {
|
|
152
|
+
const lateHooks = await runTenantDataHooks(ctx, "tenant-row");
|
|
153
|
+
if (!lateHooks.done)
|
|
154
|
+
return lateHooks;
|
|
134
155
|
const now = getTemporal().Now.instant();
|
|
135
156
|
const user = createSystemUser(ctx.tenantId);
|
|
136
157
|
const db = createTenantDb({
|
|
@@ -191,7 +212,7 @@ export const DESTRUCTION_STAGES = [
|
|
|
191
212
|
{
|
|
192
213
|
name: "app-data",
|
|
193
214
|
maxAttempts: 3,
|
|
194
|
-
run: runTenantDataHooks,
|
|
215
|
+
run: (ctx) => runTenantDataHooks(ctx, "app-data"),
|
|
195
216
|
},
|
|
196
217
|
{
|
|
197
218
|
name: "subject-keys",
|
|
@@ -35,7 +35,7 @@ export async function driveDestructionToCompletion(stack, db, tenantId, searchAd
|
|
|
35
35
|
});
|
|
36
36
|
const rows = await selectMany(db, tenantTable, { id: tenantId });
|
|
37
37
|
status = String(rows[0]?.["status"]);
|
|
38
|
-
if (status === "destroyed" || status === "destroyFailed")
|
|
38
|
+
if (status === "destroyed" || status === "destroyFailed" || status === "destroyHeld")
|
|
39
39
|
break;
|
|
40
40
|
}
|
|
41
41
|
return status;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Caps lookup for `TierResolverDeps.capsForTier`: an unknown tier name falls back to the default
|
|
2
|
+
* tier (least-privileged by convention), a name missing from the map is a wiring bug and throws. */
|
|
3
|
+
export declare function capsForTierFromMap<TTier extends string, TCaps>(tierMap: Readonly<Record<TTier, {
|
|
4
|
+
readonly caps: TCaps;
|
|
5
|
+
}>>, isTierName: (value: string) => value is TTier, defaultTier: TTier): (tier: string) => TCaps;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Caps lookup for `TierResolverDeps.capsForTier`: an unknown tier name falls back to the default
|
|
2
|
+
* tier (least-privileged by convention), a name missing from the map is a wiring bug and throws. */
|
|
3
|
+
export function capsForTierFromMap(tierMap, isTierName, defaultTier) {
|
|
4
|
+
return (tier) => {
|
|
5
|
+
const name = isTierName(tier) ? tier : defaultTier;
|
|
6
|
+
const def = tierMap[name];
|
|
7
|
+
if (!def) {
|
|
8
|
+
throw new Error(`tier-map: tier "${name}" not in tier map`);
|
|
9
|
+
}
|
|
10
|
+
return def.caps;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -56,26 +56,4 @@ export type ComposedApp<TCaps extends Readonly<Record<string, unknown>>> = {
|
|
|
56
56
|
/** Effective caps after tier + add-on overrides — same shape as input.tierMap[*].caps. */
|
|
57
57
|
readonly caps: TCaps;
|
|
58
58
|
};
|
|
59
|
-
/**
|
|
60
|
-
* composeApp — compute the feature-set + caps for a platform-tenant.
|
|
61
|
-
*
|
|
62
|
-
* **Contract:**
|
|
63
|
-
* 1. base features always mount (the Tier-Engine itself is part of them)
|
|
64
|
-
* 2. plus tier-specific features (from tierMap[tier].features)
|
|
65
|
-
* 3. plus add-on features (from addOnMap[addOn].features for each active add-on)
|
|
66
|
-
* 4. caps = tier.caps ⊕ add-on.capOverrides (later add-ons override earlier)
|
|
67
|
-
*
|
|
68
|
-
* **Failure modes:**
|
|
69
|
-
* - tier not in tierMap → throws (config error, app must register valid tiers)
|
|
70
|
-
* - addOn not in addOnMap → throws (same)
|
|
71
|
-
* - feature-name not in featureRegistry → throws (same)
|
|
72
|
-
*
|
|
73
|
-
* **Why throw vs silently ignore:** unknown tier/add-on means a Stripe-webhook
|
|
74
|
-
* delivered something the platform doesn't understand. Failing loud at boot
|
|
75
|
-
* is safer than silently mounting the wrong feature-set and hoping nobody
|
|
76
|
-
* notices when "Pro" turns out to mean "Free".
|
|
77
|
-
*
|
|
78
|
-
* **No production callers, and that is not rot** — see
|
|
79
|
-
* docs/reference/tier-composition-boot-vs-runtime.md for why.
|
|
80
|
-
*/
|
|
81
59
|
export declare function composeApp<TCaps extends Readonly<Record<string, unknown>>>(input: ComposeAppInput<TCaps>): ComposedApp<TCaps>;
|
|
@@ -20,31 +20,24 @@
|
|
|
20
20
|
* **No production callers, and that is not rot** — see
|
|
21
21
|
* docs/reference/tier-composition-boot-vs-runtime.md for why.
|
|
22
22
|
*/
|
|
23
|
+
function lookupOrThrow(map, name, kind, knownLabel) {
|
|
24
|
+
const value = map[name];
|
|
25
|
+
if (!value) {
|
|
26
|
+
throw new Error(`composeApp: unknown ${kind} "${name}". ${knownLabel}: ${Object.keys(map).join(", ")}`);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
23
30
|
export function composeApp(input) {
|
|
24
31
|
const tierDef = input.tierMap[input.tier];
|
|
25
32
|
if (!tierDef) {
|
|
26
33
|
throw new Error(`composeApp: unknown tier "${input.tier}". Known tiers: ` +
|
|
27
34
|
`${Object.keys(input.tierMap).join(", ")}`);
|
|
28
35
|
}
|
|
29
|
-
const addOnDefs = input.addOns.map((name) =>
|
|
30
|
-
const def = input.addOnMap[name];
|
|
31
|
-
if (!def) {
|
|
32
|
-
throw new Error(`composeApp: unknown add-on "${name}". Known add-ons: ` +
|
|
33
|
-
`${Object.keys(input.addOnMap).join(", ")}`);
|
|
34
|
-
}
|
|
35
|
-
return def;
|
|
36
|
-
});
|
|
36
|
+
const addOnDefs = input.addOns.map((name) => lookupOrThrow(input.addOnMap, name, "add-on", "Known add-ons"));
|
|
37
37
|
const tierFeatureNames = tierDef.features;
|
|
38
38
|
const addOnFeatureNames = addOnDefs.flatMap((d) => d.features);
|
|
39
39
|
const allFeatureNames = [...tierFeatureNames, ...addOnFeatureNames];
|
|
40
|
-
const additionalFeatures = allFeatureNames.map((name) =>
|
|
41
|
-
const feature = input.featureRegistry[name];
|
|
42
|
-
if (!feature) {
|
|
43
|
-
throw new Error(`composeApp: unknown feature "${name}". Registered features: ` +
|
|
44
|
-
`${Object.keys(input.featureRegistry).join(", ")}`);
|
|
45
|
-
}
|
|
46
|
-
return feature;
|
|
47
|
-
});
|
|
40
|
+
const additionalFeatures = allFeatureNames.map((name) => lookupOrThrow(input.featureRegistry, name, "feature", "Registered features"));
|
|
48
41
|
// Dedupe — a feature listed in both the tier and an add-on should only
|
|
49
42
|
// mount once. Order-preserving: first occurrence wins.
|
|
50
43
|
const seen = new Set();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { tierAssignmentAggregateId } from "./aggregate-id.ts";
|
|
2
|
+
export { capsForTierFromMap } from "./caps-for-tier-from-map.ts";
|
|
2
3
|
export { type AddOnDefinition, type AddOnMap, type ComposeAppInput, type ComposedApp, composeApp, type TierDefinition, type TierMap, } from "./compose-app.ts";
|
|
3
4
|
export { tierAssignmentEntity } from "./entity.ts";
|
|
4
5
|
export { type CreateTierEngineOptions, createTierEngineFeature, } from "./feature.ts";
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// - `tierAssignmentEntity` — for migrations + drizzle-schema-generation
|
|
8
8
|
// - `TierEngineHandlers` / `TierEngineQueries` — qualified handler names
|
|
9
9
|
export { tierAssignmentAggregateId } from "./aggregate-id.js";
|
|
10
|
+
export { capsForTierFromMap } from "./caps-for-tier-from-map.js";
|
|
10
11
|
export { composeApp, } from "./compose-app.js";
|
|
11
12
|
export { tierAssignmentEntity } from "./entity.js";
|
|
12
13
|
export { createTierEngineFeature, } from "./feature.js";
|
|
@@ -6,7 +6,7 @@ export declare const detailQuery: {
|
|
|
6
6
|
__kumikoEntityConventionQuery?: true;
|
|
7
7
|
access: import("@cosmicdrift/kumiko-types/handlers").AccessRule;
|
|
8
8
|
description?: string;
|
|
9
|
-
agent?: import("@cosmicdrift/kumiko-
|
|
9
|
+
agent?: import("@cosmicdrift/kumiko-framework/engine").AgentHandlerHints;
|
|
10
10
|
rateLimit?: import("@cosmicdrift/kumiko-types/handlers").RateLimitDeclaration;
|
|
11
11
|
outputSchema?: import("zod").ZodType;
|
|
12
12
|
liveEntities?: readonly string[];
|
|
@@ -333,6 +333,7 @@ export function createUserDataRightsFeature(opts = {}) {
|
|
|
333
333
|
// Entry point of the emailed download link; cheap static page, but
|
|
334
334
|
// anonymous and token-bearing, so bound per-IP probing.
|
|
335
335
|
rateLimit: { per: "ip+handler", limit: 30, windowSeconds: 60 },
|
|
336
|
+
// guard:dup-ok the few-shot corpus extractor reads httpRoute handlers only when they are inline
|
|
336
337
|
handler: async (c) => {
|
|
337
338
|
return c.body(TOKEN_EXCHANGE_PAGE_HTML, 200, {
|
|
338
339
|
"content-type": "text/html; charset=utf-8",
|
|
@@ -347,6 +348,7 @@ export function createUserDataRightsFeature(opts = {}) {
|
|
|
347
348
|
method: "GET",
|
|
348
349
|
path: "/user-export/by-token.js",
|
|
349
350
|
anonymous: true,
|
|
351
|
+
// guard:dup-ok the few-shot corpus extractor reads httpRoute handlers only when they are inline
|
|
350
352
|
handler: async (c) => {
|
|
351
353
|
return c.body(TOKEN_EXCHANGE_PAGE_JS, 200, {
|
|
352
354
|
"content-type": "application/javascript; charset=utf-8",
|
|
@@ -47,7 +47,10 @@ export function createConfirmDeletionByTokenHandler(opts = {}) {
|
|
|
47
47
|
return defineWriteHandler({
|
|
48
48
|
name: "confirm-deletion-by-token",
|
|
49
49
|
schema: z.object({ token: z.string().min(1) }),
|
|
50
|
-
access: {
|
|
50
|
+
access: {
|
|
51
|
+
roles: ["anonymous", "Member", "User", "TenantAdmin", "SystemAdmin"],
|
|
52
|
+
anySignedIn: true,
|
|
53
|
+
},
|
|
51
54
|
escapeHatch: {
|
|
52
55
|
reason: "resolveGracePeriod reads the tenant compliance profile via ctx.dispatch.queryAs(SYSTEM, " +
|
|
53
56
|
"...) to compute the grace period end — the anonymous token holder has no read access " +
|
|
@@ -51,6 +51,7 @@ export const downloadByTokenQuery = defineQueryHandler({
|
|
|
51
51
|
access: {
|
|
52
52
|
roles: ["anonymous", "Member", "User", "TenantAdmin", "SystemAdmin"],
|
|
53
53
|
personalData: "public-intake",
|
|
54
|
+
anySignedIn: true,
|
|
54
55
|
},
|
|
55
56
|
agent: { expose: false },
|
|
56
57
|
// Brute-force protection for token-hash probing. This anonymous endpoint uses a
|
|
@@ -29,7 +29,10 @@ export function createRequestDeletionByEmailHandler(opts = {}) {
|
|
|
29
29
|
return defineWriteHandler({
|
|
30
30
|
name: "request-deletion-by-email",
|
|
31
31
|
schema: z.object({ email: z.email() }),
|
|
32
|
-
access: {
|
|
32
|
+
access: {
|
|
33
|
+
roles: ["anonymous", "Member", "User", "TenantAdmin", "SystemAdmin"],
|
|
34
|
+
anySignedIn: true,
|
|
35
|
+
},
|
|
33
36
|
description: "Mails an account-deletion verification link to the given address, for a user who wants to be erased but can no longer log in; it answers identically whether or not the address belongs to an active account and never returns the link.",
|
|
34
37
|
// Mails a deletion link to any address the caller names.
|
|
35
38
|
agent: { risk: "high" },
|
|
@@ -55,6 +55,7 @@ export function sanitizeReasonForLog(reason) {
|
|
|
55
55
|
}
|
|
56
56
|
// Cross-tenant by design: the due-user and membership reads on the given runner and raw hook
|
|
57
57
|
// statements must see every tenant, whatever RLS scope the caller (job, operator handler) runs in.
|
|
58
|
+
// guard:dup-ok the single runInSystemRowLevelSecurityScope call with this entry point's own reason
|
|
58
59
|
export function runForgetCleanup(args) {
|
|
59
60
|
return runInSystemRowLevelSecurityScope("forget cleanup anonymizes users across all tenants", () => forgetDueUsers(args));
|
|
60
61
|
}
|
|
@@ -204,6 +205,7 @@ async function processUser(args) {
|
|
|
204
205
|
resolveDeleteBytes: resolveForgetFileBytesDeleter(buildStorageProvider),
|
|
205
206
|
missingStorage: {
|
|
206
207
|
mode: "skip",
|
|
208
|
+
// guard:dup-ok a one-message log callback; only the shape matches other log callbacks
|
|
207
209
|
warn: (tenantId) =>
|
|
208
210
|
// biome-ignore lint/suspicious/noConsole: misconfiguration visibility, same as the fileRef delete hook
|
|
209
211
|
console.warn(`[user-data-rights:run-forget-cleanup] no file provider resolvable for tenantId=${tenantId} - file binaries of userId=${userId} are NOT deleted (rows kept). Mount file-foundation + a file-provider-* feature so erasure can reach the binaries.`),
|