@cosmicdrift/kumiko-samples 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/package.json +1 -1
- package/packages/bundled-features/package.json +31 -4
- package/packages/bundled-features/src/account-security/feature.ts +9 -1
- package/packages/bundled-features/src/admin-shell/changes.json +6 -0
- package/packages/bundled-features/src/admin-shell/feature.ts +4 -1
- package/packages/bundled-features/src/agent-tools/agent-manifest.ts +1 -0
- package/packages/bundled-features/src/agent-tools/changes.json +6 -0
- package/packages/bundled-features/src/agent-tools/tool-catalog.ts +1 -0
- package/packages/bundled-features/src/agent-tools/types.ts +4 -0
- package/packages/bundled-features/src/audit/event-classification.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/bootstrap.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/errors.ts +18 -66
- package/packages/bundled-features/src/auth-email-password/handlers/login-options.query.ts +1 -1
- package/packages/bundled-features/src/auth-email-password/handlers/self-registration-status.query.ts +1 -1
- package/packages/bundled-features/src/auth-email-password/web/auth-client.ts +30 -64
- package/packages/bundled-features/src/auth-email-password/web/auth-redirect.ts +2 -2
- package/packages/bundled-features/src/auth-email-password/web/confirm-account-unlock-screen.tsx +20 -66
- package/packages/bundled-features/src/auth-email-password/web/index.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/web/read-path-param.ts +8 -0
- package/packages/bundled-features/src/auth-email-password/web/return-path.ts +3 -2
- package/packages/bundled-features/src/auth-email-password/web/token-confirm-screen.tsx +97 -0
- package/packages/bundled-features/src/auth-email-password/web/verify-email-screen.tsx +20 -68
- package/packages/bundled-features/src/auth-foundation/boot-checks.ts +22 -15
- package/packages/bundled-features/src/auth-foundation/boot-rules.ts +33 -0
- package/packages/bundled-features/src/auth-mfa/errors.ts +12 -42
- package/packages/bundled-features/src/auth-mfa/feature-exports.ts +6 -45
- package/packages/bundled-features/src/auth-mfa/feature.ts +8 -19
- package/packages/bundled-features/src/auth-mfa/web/mfa-client.ts +19 -33
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-notify.ts +1 -0
- package/packages/bundled-features/src/billing-foundation/web/plan-price.ts +20 -7
- package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +1 -0
- package/packages/bundled-features/src/channel-in-app/changes.json +7 -0
- package/packages/bundled-features/src/channel-in-app/feature.ts +2 -0
- package/packages/bundled-features/src/channel-in-app/handlers/read-state-by-keys.query.ts +35 -0
- package/packages/bundled-features/src/channel-in-app/in-app-channel.ts +1 -0
- package/packages/bundled-features/src/channel-in-app/tables.ts +5 -1
- package/packages/bundled-features/src/compliance-profiles/handlers/sub-processors.query.ts +4 -1
- package/packages/bundled-features/src/contact/challenge.ts +41 -0
- package/packages/bundled-features/src/contact/changes.json +33 -0
- package/packages/bundled-features/src/contact/client/contact-client-source.ts +203 -0
- package/packages/bundled-features/src/contact/client/contact-website-client.ts +29 -0
- package/packages/bundled-features/src/contact/client/index.ts +9 -0
- package/packages/bundled-features/src/contact/entity.ts +168 -0
- package/packages/bundled-features/src/contact/feature.ts +174 -0
- package/packages/bundled-features/src/contact/handlers/access.ts +17 -0
- package/packages/bundled-features/src/contact/handlers/attempts.ts +76 -0
- package/packages/bundled-features/src/contact/handlers/challenge.query.ts +44 -0
- package/packages/bundled-features/src/contact/handlers/forward-request.write.ts +98 -0
- package/packages/bundled-features/src/contact/handlers/mark-done.write.ts +40 -0
- package/packages/bundled-features/src/contact/handlers/notify-reporter-in-app.write.ts +48 -0
- package/packages/bundled-features/src/contact/handlers/open-count.query.ts +15 -0
- package/packages/bundled-features/src/contact/handlers/open-count.ts +17 -0
- package/packages/bundled-features/src/contact/handlers/replies.query.ts +29 -0
- package/packages/bundled-features/src/contact/handlers/reply.write.ts +197 -0
- package/packages/bundled-features/src/contact/handlers/report.write.ts +126 -0
- package/packages/bundled-features/src/contact/handlers/request-delivery.query.ts +143 -0
- package/packages/bundled-features/src/contact/handlers/request-detail.query.ts +50 -0
- package/packages/bundled-features/src/contact/handlers/request-list.query.ts +14 -0
- package/packages/bundled-features/src/contact/handlers/send-reply-mail.write.ts +124 -0
- package/packages/bundled-features/src/contact/handlers/send-test.write.ts +45 -0
- package/packages/bundled-features/src/contact/handlers/submit.write.ts +194 -0
- package/packages/bundled-features/src/contact/handlers/take-over-uploads.ts +47 -0
- package/packages/bundled-features/src/contact/i18n.ts +192 -0
- package/packages/bundled-features/src/contact/index.ts +29 -0
- package/packages/bundled-features/src/contact/lib.ts +176 -0
- package/packages/bundled-features/src/contact/mail.ts +401 -0
- package/packages/bundled-features/src/contact/options.ts +95 -0
- package/packages/bundled-features/src/contact/panels.ts +28 -0
- package/packages/bundled-features/src/contact/payloads.ts +106 -0
- package/packages/bundled-features/src/contact/pow.ts +22 -0
- package/packages/bundled-features/src/contact/screens.ts +507 -0
- package/packages/bundled-features/src/contact/subject.ts +13 -0
- package/packages/bundled-features/src/contact/user-agent.ts +39 -0
- package/packages/bundled-features/src/contact/user-data-hooks.ts +180 -0
- package/packages/bundled-features/src/contact/web/constants.ts +160 -0
- package/packages/bundled-features/src/contact/web/index.ts +29 -0
- package/packages/bundled-features/src/crypto-shredding/handlers/forget-subject.write.ts +5 -16
- package/packages/bundled-features/src/data-retention/changes.json +6 -0
- package/packages/bundled-features/src/data-retention/feature.ts +16 -2
- package/packages/bundled-features/src/data-retention/index.ts +5 -0
- package/packages/bundled-features/src/data-retention/run-retention-cleanup.ts +138 -41
- package/packages/bundled-features/src/data-retention/tenant-destruction-hold.ts +196 -0
- package/packages/bundled-features/src/delivery/address-opt-out.ts +1 -0
- package/packages/bundled-features/src/delivery/changes.json +7 -0
- package/packages/bundled-features/src/delivery/channel-context.ts +2 -0
- package/packages/bundled-features/src/delivery/delivery-service.ts +29 -5
- package/packages/bundled-features/src/delivery/events.ts +2 -0
- package/packages/bundled-features/src/delivery/feature.ts +3 -2
- package/packages/bundled-features/src/delivery/handlers/attempts-by-keys.query.ts +55 -0
- package/packages/bundled-features/src/delivery/handlers/log.query.ts +1 -1
- package/packages/bundled-features/src/delivery/jobs.ts +5 -0
- package/packages/bundled-features/src/delivery/tables.ts +13 -2
- package/packages/bundled-features/src/delivery/types.ts +3 -0
- package/packages/bundled-features/src/delivery/unsubscribe-page.ts +2 -0
- package/packages/bundled-features/src/delivery/web/delivery-channel-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-error-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-status-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-time-cell.tsx +3 -2
- package/packages/bundled-features/src/delivery/web/delivery-type-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/public-names.ts +1 -0
- package/packages/bundled-features/src/document-ingest-foundation/boot-checks.ts +14 -9
- package/packages/bundled-features/src/document-ingest-foundation/boot-rules.ts +22 -0
- package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
- package/packages/bundled-features/src/document-ingest-foundation/events.ts +17 -0
- package/packages/bundled-features/src/document-ingest-foundation/feature.ts +39 -1
- package/packages/bundled-features/src/document-ingest-foundation/index.ts +10 -0
- package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +43 -0
- package/packages/bundled-features/src/document-ingest-foundation/tables.ts +43 -0
- package/packages/bundled-features/src/file-derivatives/handlers/public-variant-by-file-ref.query.ts +1 -1
- package/packages/bundled-features/src/file-derivatives/handlers/public-variant.query.ts +1 -1
- package/packages/bundled-features/src/files-tenant-data/changes.json +6 -0
- package/packages/bundled-features/src/files-tenant-data/hooks.ts +4 -1
- package/packages/bundled-features/src/folders/web/folder-manager.tsx +8 -9
- package/packages/bundled-features/src/folders/web/folder-section.tsx +1 -1
- package/packages/bundled-features/src/form-draft-user-data/index.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/changes.json +13 -0
- package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/events.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/feature.ts +6 -6
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/attach-message-content.write.ts +7 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message.write.ts +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/list-messages.query.ts +6 -2
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.query.ts +3 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.ts +19 -0
- package/packages/bundled-features/src/inbound-mail-foundation/projection.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/sanitize-inbound-html.ts +150 -0
- package/packages/bundled-features/src/inbound-mail-foundation/types.ts +1 -0
- package/packages/bundled-features/src/jobs/job-run-logger.ts +24 -25
- package/packages/bundled-features/src/ledger/handlers/reports.query.ts +46 -31
- package/packages/bundled-features/src/ledger/recurring.ts +1 -0
- package/packages/bundled-features/src/managed-pages/handlers/branding.query.ts +1 -1
- package/packages/bundled-features/src/managed-pages/handlers/by-slug.query.ts +1 -1
- package/packages/bundled-features/src/managed-pages/handlers/by-tenant-published.query.ts +1 -1
- package/packages/bundled-features/src/notes-history/web/notes-section.tsx +3 -1
- package/packages/bundled-features/src/personal-access-tokens/feature.ts +9 -17
- package/packages/bundled-features/src/personal-access-tokens/handlers/create.write.ts +2 -7
- package/packages/bundled-features/src/secrets/changes.json +6 -0
- package/packages/bundled-features/src/secrets/handlers/delete.write.ts +8 -4
- package/packages/bundled-features/src/secrets/handlers/list.query.ts +6 -3
- package/packages/bundled-features/src/secrets/handlers/set.write.ts +9 -4
- package/packages/bundled-features/src/secrets/secret-scope.ts +33 -0
- package/packages/bundled-features/src/seo/handlers/seo-config.query.ts +1 -1
- package/packages/bundled-features/src/sessions/changes.json +6 -0
- package/packages/bundled-features/src/sessions/feature.ts +21 -18
- package/packages/bundled-features/src/sessions/handlers/last-activity-probe.query.ts +53 -0
- package/packages/bundled-features/src/sessions/handlers/last-activity-probe.route.ts +39 -0
- package/packages/bundled-features/src/sessions/screens.ts +1 -0
- package/packages/bundled-features/src/sessions/session-callbacks.ts +13 -12
- package/packages/bundled-features/src/sessions/web/i18n.ts +4 -1
- package/packages/bundled-features/src/shared/assert-billing-live.ts +14 -0
- package/packages/bundled-features/src/shared/collect-extension-options.ts +12 -0
- package/packages/bundled-features/src/shared/index.ts +16 -0
- package/packages/bundled-features/src/shared/late-bound-slot.ts +19 -0
- package/packages/bundled-features/src/shared/mail-locale-templates.ts +7 -1
- package/packages/bundled-features/src/shared/price-env-shape.ts +44 -0
- package/packages/bundled-features/src/shared/purge-row-file-refs.ts +1 -1
- package/packages/bundled-features/src/shared/read-feature-export-fn.ts +16 -0
- package/packages/bundled-features/src/shared/signup-handover.ts +3 -4
- package/packages/bundled-features/src/shared/tenant-destruction-hold.ts +49 -0
- package/packages/bundled-features/src/shared/unprocessable.ts +19 -0
- package/packages/bundled-features/src/shared/web/index.ts +3 -0
- package/packages/bundled-features/src/subscription-paddle/checkout-config.query.ts +1 -1
- package/packages/bundled-features/src/subscription-paddle/feature.ts +7 -15
- package/packages/bundled-features/src/subscription-paddle/runtime.ts +4 -7
- package/packages/bundled-features/src/subscription-stripe/feature.ts +7 -15
- package/packages/bundled-features/src/subscription-stripe/runtime.ts +4 -7
- package/packages/bundled-features/src/tags/entity.ts +1 -0
- package/packages/bundled-features/src/tags/web/tag-chip.tsx +14 -0
- package/packages/bundled-features/src/tags/web/tag-filter.tsx +4 -5
- package/packages/bundled-features/src/tags/web/tag-manager.tsx +1 -1
- package/packages/bundled-features/src/tags/web/tag-section.tsx +3 -6
- package/packages/bundled-features/src/tags/web/tags-cell.tsx +4 -5
- package/packages/bundled-features/src/template-resolver/compile-document-body.ts +27 -15
- package/packages/bundled-features/src/template-resolver/handlers/by-slug.query.ts +1 -1
- package/packages/bundled-features/src/template-resolver/handlers/by-tenant.query.ts +12 -9
- package/packages/bundled-features/src/template-resolver/handlers/discard-draft.write.ts +1 -0
- package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +1 -0
- package/packages/bundled-features/src/template-resolver/handlers/send-test.write.ts +5 -5
- package/packages/bundled-features/src/template-resolver/handlers/toggle-status.write.ts +3 -0
- package/packages/bundled-features/src/template-resolver/linked-resources.ts +11 -6
- package/packages/bundled-features/src/template-resolver/store-template-resource.ts +15 -12
- package/packages/bundled-features/src/template-resolver/web/document-images.ts +6 -6
- package/packages/bundled-features/src/template-resolver/web/document-insert-fields.tsx +41 -36
- package/packages/bundled-features/src/template-resolver/web/document-schema.ts +11 -12
- package/packages/bundled-features/src/template-resolver/web/tiptap-attribute-parse-rule.ts +19 -0
- package/packages/bundled-features/src/tenant/i18n.ts +3 -0
- package/packages/bundled-features/src/tenant/schema/tenant.ts +1 -0
- package/packages/bundled-features/src/tenant/web/member-roles-cell.tsx +1 -1
- package/packages/bundled-features/src/tenant/web/member-status-cell.tsx +1 -1
- package/packages/bundled-features/src/tenant-inactivity/changes.json +8 -0
- package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +260 -0
- package/packages/bundled-features/src/tenant-inactivity/constants.ts +12 -0
- package/packages/bundled-features/src/tenant-inactivity/email-templates.ts +24 -0
- package/packages/bundled-features/src/tenant-inactivity/feature.ts +66 -0
- package/packages/bundled-features/src/tenant-inactivity/handlers/inactivity-state.query.ts +49 -0
- package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +59 -0
- package/packages/bundled-features/src/tenant-inactivity/inactivity-plan.ts +187 -0
- package/packages/bundled-features/src/tenant-inactivity/index.ts +5 -0
- package/packages/bundled-features/src/tenant-inactivity/keep-token.ts +44 -0
- package/packages/bundled-features/src/tenant-inactivity/mail-notifications.ts +62 -0
- package/packages/bundled-features/src/tenant-inactivity/options.ts +38 -0
- package/packages/bundled-features/src/tenant-inactivity/remote-activity.ts +32 -0
- package/packages/bundled-features/src/tenant-inactivity/state-store.ts +71 -0
- package/packages/bundled-features/src/tenant-inactivity/state-table.ts +50 -0
- package/packages/bundled-features/src/tenant-lifecycle/boot-checks.ts +8 -6
- package/packages/bundled-features/src/tenant-lifecycle/boot-rules.ts +16 -0
- package/packages/bundled-features/src/tenant-lifecycle/changes.json +18 -0
- package/packages/bundled-features/src/tenant-lifecycle/feature.ts +24 -1
- package/packages/bundled-features/src/tenant-lifecycle/handlers/request-destruction.write.ts +12 -87
- package/packages/bundled-features/src/tenant-lifecycle/index.ts +4 -0
- package/packages/bundled-features/src/tenant-lifecycle/request-tenant-destruction.ts +108 -0
- package/packages/bundled-features/src/tenant-lifecycle/retention-config-destroy-hooks.ts +62 -0
- package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +58 -5
- package/packages/bundled-features/src/tenant-lifecycle/stages.ts +31 -2
- package/packages/bundled-features/src/tenant-lifecycle/testing.ts +1 -1
- package/packages/bundled-features/src/tier-engine/caps-for-tier-from-map.ts +16 -0
- package/packages/bundled-features/src/tier-engine/changes.json +6 -0
- package/packages/bundled-features/src/tier-engine/compose-app.ts +21 -20
- package/packages/bundled-features/src/tier-engine/index.ts +1 -0
- package/packages/bundled-features/src/user-data-rights/feature.ts +2 -0
- package/packages/bundled-features/src/user-data-rights/handlers/confirm-deletion-by-token.write.ts +4 -1
- package/packages/bundled-features/src/user-data-rights/handlers/download-by-token.query.ts +1 -0
- package/packages/bundled-features/src/user-data-rights/handlers/request-deletion-by-email.write.ts +4 -1
- package/packages/bundled-features/src/user-data-rights/run-forget-cleanup.ts +2 -0
- package/packages/bundled-features/src/user-data-rights/web/privacy-center-screen.tsx +1 -1
- package/packages/bundled-features/src/user-data-rights/zip-path.ts +1 -0
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/config-value.userdata-hook.ts +8 -27
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/delivery-attempt.userdata-hook.ts +11 -8
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.ts +42 -0
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/notification-preference.userdata-hook.ts +8 -27
- package/packages/bundled-features/src/user-profile/handlers/change-email.write.ts +2 -6
- package/packages/bundled-features/src/user-profile/web/profile-screen.tsx +2 -3
- package/packages/bundled-features/src/waitlist/changes.json +6 -0
- package/packages/bundled-features/src/waitlist/handlers/submit.write.ts +1 -2
- package/samples/apps/styleguide/src/features/widgets/i18n.ts +6 -0
- package/samples/apps/styleguide/src/features/widgets/web/InboxReaderExamples.tsx +158 -0
- package/samples/apps/styleguide/src/features/widgets/web/Widgets.tsx +2 -0
- package/samples/apps/styleguide/src/features/widgets/web/sample-pdf.ts +28 -0
- package/samples/apps/use-all-bundled/feature-manifest.json +113 -2
- package/samples/apps/use-all-bundled/kumiko/migrations/0063_contact.rebuild.json +4 -0
- package/samples/apps/use-all-bundled/package.json +1 -0
- package/samples/apps/use-all-bundled/src/app/client.tsx +3 -0
- package/samples/apps/use-all-bundled/src/app/screens-feature.ts +46 -2
- package/samples/apps/use-all-bundled/src/run-config.ts +23 -1
- package/samples/recipes/anonymous-access/README.md +2 -0
- package/samples/recipes/anonymous-access/src/feature.ts +7 -1
- package/samples/recipes/contact/README.md +52 -0
- package/samples/recipes/contact/package.json +12 -0
- package/samples/recipes/contact/src/feature.ts +27 -0
- package/samples/recipes/delivery-notifications/src/feature.ts +3 -0
- package/samples/recipes/record-detail-layout/src/feature.ts +9 -1
- package/samples/recipes/search/README.md +2 -0
- package/samples/recipes/search/src/feature.ts +27 -2
- package/samples/recipes/secrets-demo/README.md +1 -0
- package/samples/recipes/secrets-demo/src/feature.ts +56 -0
- package/samples/recipes/tenant-inactivity/README.md +21 -0
- package/samples/recipes/tenant-inactivity/package.json +12 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
2
|
+
import {
|
|
3
|
+
type RowBoundGrantResult,
|
|
4
|
+
redeemRowBoundGrant,
|
|
5
|
+
signRowBoundGrant,
|
|
6
|
+
} from "../shared/index.ts";
|
|
7
|
+
|
|
8
|
+
const KEEP_ACCOUNT_PURPOSE = "keep-account";
|
|
9
|
+
|
|
10
|
+
// Subject is the tenant, anchor the state row's cycleId: any activity or a redeemed link rotates
|
|
11
|
+
// the cycleId, so every earlier link stops verifying.
|
|
12
|
+
export function signKeepAccountToken(args: {
|
|
13
|
+
readonly tenantId: string;
|
|
14
|
+
readonly cycleId: string;
|
|
15
|
+
readonly ttlMinutes: number;
|
|
16
|
+
readonly secret: string;
|
|
17
|
+
readonly now: Temporal.Instant;
|
|
18
|
+
}): string {
|
|
19
|
+
return signRowBoundGrant({
|
|
20
|
+
subject: args.tenantId,
|
|
21
|
+
purpose: KEEP_ACCOUNT_PURPOSE,
|
|
22
|
+
anchor: args.cycleId,
|
|
23
|
+
ttlMinutes: args.ttlMinutes,
|
|
24
|
+
secret: args.secret,
|
|
25
|
+
now: args.now,
|
|
26
|
+
}).token;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function redeemKeepAccountToken(args: {
|
|
30
|
+
readonly token: string;
|
|
31
|
+
readonly secret: string | undefined;
|
|
32
|
+
readonly loadCycleId: (tenantId: string) => Promise<string | null>;
|
|
33
|
+
readonly commitKeep: (tenantId: string, cycleId: string) => Promise<boolean>;
|
|
34
|
+
readonly now: Temporal.Instant;
|
|
35
|
+
}): Promise<RowBoundGrantResult> {
|
|
36
|
+
return redeemRowBoundGrant({
|
|
37
|
+
token: args.token,
|
|
38
|
+
purpose: KEEP_ACCOUNT_PURPOSE,
|
|
39
|
+
secret: args.secret,
|
|
40
|
+
loadAnchor: args.loadCycleId,
|
|
41
|
+
commitAnchor: args.commitKeep,
|
|
42
|
+
now: args.now,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type FeatureRegistrar,
|
|
3
|
+
QnTypes,
|
|
4
|
+
qn,
|
|
5
|
+
type TemplateVariables,
|
|
6
|
+
templateVariable,
|
|
7
|
+
} from "@cosmicdrift/kumiko-framework/engine";
|
|
8
|
+
import { mailT } from "@cosmicdrift/kumiko-framework/i18n";
|
|
9
|
+
import { escapeHtml } from "@cosmicdrift/kumiko-renderer/headless";
|
|
10
|
+
import { createMailLocaleTemplates, mailParagraph } from "../shared/index.ts";
|
|
11
|
+
import { TENANT_INACTIVITY_FEATURE } from "./constants.ts";
|
|
12
|
+
|
|
13
|
+
const WARNING_MAIL_NAME = "warning";
|
|
14
|
+
|
|
15
|
+
export const InactivityWarningNotificationType = qn(
|
|
16
|
+
TENANT_INACTIVITY_FEATURE,
|
|
17
|
+
QnTypes.notify,
|
|
18
|
+
WARNING_MAIL_NAME,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const WARNING_SUBJECT_KEY = "inactivity.mail.warning.subject";
|
|
22
|
+
|
|
23
|
+
// Translation placeholder -> template variable.
|
|
24
|
+
// The translation slot is named account because locale-de rejects the word tenant in values.
|
|
25
|
+
const SLOTS = { app: "{app}", account: "{tenant}", when: "{when}" } as const;
|
|
26
|
+
const SUBJECT_SLOTS = { app: "{{app}}", account: "{{tenant}}", when: "{{when}}" } as const;
|
|
27
|
+
|
|
28
|
+
const WARNING_VARIABLES: TemplateVariables = {
|
|
29
|
+
app: templateVariable.text({ required: true }),
|
|
30
|
+
tenant: templateVariable.text({ required: true }),
|
|
31
|
+
when: templateVariable.text({ required: true }),
|
|
32
|
+
keepUrl: templateVariable.link({ required: true }),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function warningBody(locale: string): string {
|
|
36
|
+
const paragraph = (part: string) =>
|
|
37
|
+
mailParagraph(mailT(locale, `inactivity.mail.warning.${part}`, SLOTS));
|
|
38
|
+
return [
|
|
39
|
+
mailParagraph(mailT(locale, "gdpr.mail.greeting")),
|
|
40
|
+
paragraph("intro"),
|
|
41
|
+
paragraph("keep"),
|
|
42
|
+
`<p><a data-button href="{{keepUrl}}">${escapeHtml(mailT(locale, "inactivity.mail.warning.button"))}</a></p>`,
|
|
43
|
+
paragraph("after"),
|
|
44
|
+
].join("");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const mailLocaleTemplates = createMailLocaleTemplates({
|
|
48
|
+
kinds: [WARNING_MAIL_NAME],
|
|
49
|
+
notificationTypes: { [WARNING_MAIL_NAME]: InactivityWarningNotificationType },
|
|
50
|
+
subjectKey: () => WARNING_SUBJECT_KEY,
|
|
51
|
+
bodyFor: (_kind, locale) => warningBody(locale),
|
|
52
|
+
subjectSlots: () => SUBJECT_SLOTS,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const inactivityMailTemplateLocale = mailLocaleTemplates.templateLocale;
|
|
56
|
+
|
|
57
|
+
export function registerInactivityMails(r: FeatureRegistrar): void {
|
|
58
|
+
r.notification(WARNING_MAIL_NAME, {
|
|
59
|
+
variables: WARNING_VARIABLES,
|
|
60
|
+
localizedTemplate: mailLocaleTemplates.localizedTemplate(WARNING_MAIL_NAME),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { TenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import type { TenantId } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
import type { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
4
|
+
import type { InactivityRule } from "./inactivity-plan.ts";
|
|
5
|
+
|
|
6
|
+
/** Newest activity an app knows outside this app's sessions (for example a sibling app); null when none. */
|
|
7
|
+
export type TenantActivitySource = (args: {
|
|
8
|
+
readonly tenantId: TenantId;
|
|
9
|
+
readonly now: Temporal.Instant;
|
|
10
|
+
}) => Promise<Temporal.Instant | null>;
|
|
11
|
+
|
|
12
|
+
type SharedOptions = {
|
|
13
|
+
/** HMAC key of the keep-account links. Unset: mails link to keepAccountUrl without a token. */
|
|
14
|
+
readonly keepAccountTokenSecret?: string;
|
|
15
|
+
/** App page that reads the `#token=` fragment and calls the keep-account handler. */
|
|
16
|
+
readonly keepAccountUrl: string;
|
|
17
|
+
/** Name shown in the mails; defaults to a generic word per locale. */
|
|
18
|
+
readonly appName?: string;
|
|
19
|
+
readonly activitySources?: readonly TenantActivitySource[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type TenantInactivityOptions<TTier extends string = string> = SharedOptions &
|
|
23
|
+
(
|
|
24
|
+
| { readonly rule: InactivityRule }
|
|
25
|
+
| {
|
|
26
|
+
readonly resolveTier: (db: TenantDb) => Promise<TTier>;
|
|
27
|
+
/** null exempts the tier (paid plans). */
|
|
28
|
+
readonly rulesByTier: Readonly<Record<TTier, InactivityRule | null>>;
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export async function resolveInactivityRule<TTier extends string>(
|
|
33
|
+
options: TenantInactivityOptions<TTier>,
|
|
34
|
+
db: TenantDb,
|
|
35
|
+
): Promise<InactivityRule | null> {
|
|
36
|
+
if ("rule" in options) return options.rule;
|
|
37
|
+
return options.rulesByTier[await options.resolveTier(db)];
|
|
38
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { egress } from "@cosmicdrift/kumiko-framework/http";
|
|
2
|
+
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
|
|
5
|
+
const probeResponseSchema = z.object({ lastActivityAt: z.string().nullable() });
|
|
6
|
+
|
|
7
|
+
type SendRequest = (url: string, init: RequestInit) => Promise<Response>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Asks a sibling app for its newest session activity (the sessions `lastActivityProbeSecret`
|
|
11
|
+
* route). Use it inside a `TenantActivitySource` so a user active in the other app keeps the
|
|
12
|
+
* account alive. Fails closed: any error throws, and the job then sends no mail and files no
|
|
13
|
+
* deletion request for that run. `send` exists for tests; production uses the internal egress
|
|
14
|
+
* pinned to the origin of `url`.
|
|
15
|
+
*/
|
|
16
|
+
export async function fetchRemoteAppLastActivity(args: {
|
|
17
|
+
readonly url: string;
|
|
18
|
+
readonly secret: string;
|
|
19
|
+
readonly send?: SendRequest;
|
|
20
|
+
}): Promise<Temporal.Instant | null> {
|
|
21
|
+
// Sibling apps sit in the same cluster on private addresses, which the external policy blocks.
|
|
22
|
+
const send = args.send ?? egress({ kind: "internal", allowOrigins: [new URL(args.url).origin] });
|
|
23
|
+
const response = await send(args.url, {
|
|
24
|
+
method: "GET",
|
|
25
|
+
headers: { authorization: `Bearer ${args.secret}` },
|
|
26
|
+
});
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
throw new Error(`remote activity probe answered ${response.status}`);
|
|
29
|
+
}
|
|
30
|
+
const body = probeResponseSchema.parse(await response.json());
|
|
31
|
+
return body.lastActivityAt === null ? null : Temporal.Instant.from(body.lastActivityAt);
|
|
32
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { TenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
3
|
+
import { userSessionTable } from "../sessions/index.ts";
|
|
4
|
+
import type { InactivityState } from "./inactivity-plan.ts";
|
|
5
|
+
import { tenantInactivityStateTable } from "./state-table.ts";
|
|
6
|
+
|
|
7
|
+
export type StoredInactivityState = InactivityState & { readonly cycleId: string };
|
|
8
|
+
|
|
9
|
+
type StateRow = StoredInactivityState & { readonly id: string };
|
|
10
|
+
|
|
11
|
+
const EPOCH = Temporal.Instant.fromEpochMilliseconds(0);
|
|
12
|
+
|
|
13
|
+
export async function loadInactivityState(db: TenantDb): Promise<StoredInactivityState | null> {
|
|
14
|
+
const row = await db.fetchOne<StateRow>(tenantInactivityStateTable, { tenantId: db.tenantId });
|
|
15
|
+
if (!row) return null;
|
|
16
|
+
return {
|
|
17
|
+
cycleId: row.cycleId,
|
|
18
|
+
firstSeenAt: row.firstSeenAt,
|
|
19
|
+
lastActivityAt: row.lastActivityAt,
|
|
20
|
+
lastExemptAt: row.lastExemptAt,
|
|
21
|
+
lastWarnedAt: row.lastWarnedAt,
|
|
22
|
+
postponedDueAt: row.postponedDueAt,
|
|
23
|
+
warningsSent: row.warningsSent,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function sameInstant(a: Temporal.Instant | null, b: Temporal.Instant | null): boolean {
|
|
28
|
+
if (a === null || b === null) return a === b;
|
|
29
|
+
return a.epochMilliseconds === b.epochMilliseconds;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function isSameInactivityState(
|
|
33
|
+
a: StoredInactivityState | null,
|
|
34
|
+
b: StoredInactivityState,
|
|
35
|
+
): boolean {
|
|
36
|
+
return (
|
|
37
|
+
a !== null &&
|
|
38
|
+
a.cycleId === b.cycleId &&
|
|
39
|
+
a.warningsSent === b.warningsSent &&
|
|
40
|
+
sameInstant(a.firstSeenAt, b.firstSeenAt) &&
|
|
41
|
+
sameInstant(a.lastActivityAt, b.lastActivityAt) &&
|
|
42
|
+
sameInstant(a.lastExemptAt, b.lastExemptAt) &&
|
|
43
|
+
sameInstant(a.lastWarnedAt, b.lastWarnedAt) &&
|
|
44
|
+
sameInstant(a.postponedDueAt, b.postponedDueAt)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Writes only when something changed, so a run that decides nothing stays read-only.
|
|
49
|
+
export async function saveInactivityState(
|
|
50
|
+
db: TenantDb,
|
|
51
|
+
previous: StoredInactivityState | null,
|
|
52
|
+
next: StoredInactivityState,
|
|
53
|
+
): Promise<void> {
|
|
54
|
+
// skip: nothing changed, so the run stays read-only
|
|
55
|
+
if (isSameInactivityState(previous, next)) return;
|
|
56
|
+
if (previous === null) {
|
|
57
|
+
await db.insertOne(tenantInactivityStateTable, { tenantId: db.tenantId, ...next });
|
|
58
|
+
} else {
|
|
59
|
+
await db.updateMany(tenantInactivityStateTable, next, { tenantId: db.tenantId });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// The sessions table keeps the activity marker; reading it here avoids a write per request.
|
|
64
|
+
export async function loadNewestSessionActivity(db: TenantDb): Promise<Temporal.Instant | null> {
|
|
65
|
+
const [newest] = await db.selectMany<{ lastSeenAt: Temporal.Instant | null }>(
|
|
66
|
+
userSessionTable,
|
|
67
|
+
{ tenantId: db.tenantId, lastSeenAt: { gte: EPOCH } },
|
|
68
|
+
{ limit: 1, orderBy: { col: "lastSeenAt", direction: "desc" } },
|
|
69
|
+
);
|
|
70
|
+
return newest?.lastSeenAt ?? null;
|
|
71
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { deriveEntityTableMeta } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import {
|
|
3
|
+
access,
|
|
4
|
+
createEntity,
|
|
5
|
+
createNumberField,
|
|
6
|
+
createTextField,
|
|
7
|
+
createTimestampField,
|
|
8
|
+
} from "@cosmicdrift/kumiko-framework/engine";
|
|
9
|
+
import { TENANT_INACTIVITY_STATE_ENTITY } from "./constants.ts";
|
|
10
|
+
|
|
11
|
+
// One row per tenant. Direct-write store: the daily job and the keep-account handler mutate
|
|
12
|
+
// columns, there is no aggregate or event stream behind it.
|
|
13
|
+
export const tenantInactivityStateEntity = createEntity({
|
|
14
|
+
table: "store_tenant_inactivity_state",
|
|
15
|
+
softDelete: false,
|
|
16
|
+
fields: {
|
|
17
|
+
tenantId: createTextField({
|
|
18
|
+
required: true,
|
|
19
|
+
maxLength: 36,
|
|
20
|
+
access: { write: access.privileged },
|
|
21
|
+
personal: false,
|
|
22
|
+
reason: "pseudonymous_fk",
|
|
23
|
+
}),
|
|
24
|
+
cycleId: createTextField({
|
|
25
|
+
required: true,
|
|
26
|
+
maxLength: 36,
|
|
27
|
+
access: { write: access.privileged },
|
|
28
|
+
personal: false,
|
|
29
|
+
reason: "technical_reference",
|
|
30
|
+
}),
|
|
31
|
+
firstSeenAt: createTimestampField({ required: true, access: { write: access.privileged } }),
|
|
32
|
+
lastActivityAt: createTimestampField({ access: { write: access.privileged } }),
|
|
33
|
+
lastExemptAt: createTimestampField({ access: { write: access.privileged } }),
|
|
34
|
+
lastWarnedAt: createTimestampField({ access: { write: access.privileged } }),
|
|
35
|
+
postponedDueAt: createTimestampField({ access: { write: access.privileged } }),
|
|
36
|
+
warningsSent: createNumberField({
|
|
37
|
+
required: true,
|
|
38
|
+
integer: true,
|
|
39
|
+
min: 0,
|
|
40
|
+
access: { write: access.privileged },
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
43
|
+
indexes: [{ unique: true, columns: ["tenantId"], name: "store_tenant_inactivity_state_tenant" }],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const tenantInactivityStateTable = deriveEntityTableMeta(
|
|
47
|
+
TENANT_INACTIVITY_STATE_ENTITY,
|
|
48
|
+
tenantInactivityStateEntity,
|
|
49
|
+
{ source: "unmanaged" },
|
|
50
|
+
);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
bootRuleError,
|
|
2
3
|
EXT_EXTERNAL_RESOURCE,
|
|
3
4
|
EXT_INFRA_RESOURCE,
|
|
4
5
|
EXT_SEARCH_ADAPTER,
|
|
@@ -11,6 +12,7 @@ import {
|
|
|
11
12
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
12
13
|
import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
|
|
13
14
|
import { entitiesOf } from "../shared/index.ts";
|
|
15
|
+
import { TENANT_LIFECYCLE_BOOT_RULES } from "./boot-rules.ts";
|
|
14
16
|
|
|
15
17
|
const log = createFallbackLogger("kumiko:boot");
|
|
16
18
|
|
|
@@ -46,9 +48,9 @@ export function validateTenantDataHookCoverage(features: readonly FeatureDefinit
|
|
|
46
48
|
.filter(([, field]) => hasTenantOwned(field))
|
|
47
49
|
.map(([name]) => name);
|
|
48
50
|
if (tenantSubjectFields.length === 0) continue;
|
|
49
|
-
throw
|
|
50
|
-
`[kumiko:boot] Entity "${entityName}" (feature "${feature.name}") has tenant-subject fields (${tenantSubjectFields.join(", ")}) but no feature registers an EXT_TENANT_DATA destroy hook for it — tenant destroy never erases this data. Register r.useExtension(EXT_TENANT_DATA, "${entityName}", { destroy }) or a documented no-op if crypto-shredding covers it.`,
|
|
51
|
-
);
|
|
51
|
+
throw bootRuleError(TENANT_LIFECYCLE_BOOT_RULES.tenantSubjectWithoutDestroyHook, {
|
|
52
|
+
message: `[kumiko:boot] Entity "${entityName}" (feature "${feature.name}") has tenant-subject fields (${tenantSubjectFields.join(", ")}) but no feature registers an EXT_TENANT_DATA destroy hook for it — tenant destroy never erases this data. Register r.useExtension(EXT_TENANT_DATA, "${entityName}", { destroy }) or a documented no-op if crypto-shredding covers it.`,
|
|
53
|
+
});
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
}
|
|
@@ -74,9 +76,9 @@ export function validateTenantDestroyHookShapes(features: readonly FeatureDefini
|
|
|
74
76
|
: isTenantResourceExtensionHooks(usage.options);
|
|
75
77
|
if (isValid) continue;
|
|
76
78
|
const requiredFn = isTenantData ? "destroy" : "destroyTenant";
|
|
77
|
-
throw
|
|
78
|
-
`[kumiko:boot] ${usage.extensionName} registration for "${usage.entityName}" (feature "${feature.name}") has no ${requiredFn} function — tenant destroy would fail at this stage.`,
|
|
79
|
-
);
|
|
79
|
+
throw bootRuleError(TENANT_LIFECYCLE_BOOT_RULES.destroyFunctionMissing, {
|
|
80
|
+
message: `[kumiko:boot] ${usage.extensionName} registration for "${usage.entityName}" (feature "${feature.name}") has no ${requiredFn} function — tenant destroy would fail at this stage.`,
|
|
81
|
+
});
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
84
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BootRuleTable } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
|
|
3
|
+
export const TENANT_LIFECYCLE_BOOT_RULES = {
|
|
4
|
+
tenantSubjectWithoutDestroyHook: {
|
|
5
|
+
id: "tenant-lifecycle/tenant-subject-without-destroy-hook",
|
|
6
|
+
summary:
|
|
7
|
+
"An entity with tenant-subject fields has an EXT_TENANT_DATA destroy hook, so tenant destroy erases its data.",
|
|
8
|
+
fix: 'Register r.useExtension(EXT_TENANT_DATA, "<entity>", { destroy }) or a documented no-op if crypto-shredding covers it.',
|
|
9
|
+
},
|
|
10
|
+
destroyFunctionMissing: {
|
|
11
|
+
id: "tenant-lifecycle/destroy-function-missing",
|
|
12
|
+
summary:
|
|
13
|
+
"A tenant data or tenant resource extension registration provides its destroy function, otherwise tenant destroy fails at that stage.",
|
|
14
|
+
fix: "Provide destroy (EXT_TENANT_DATA) or destroyTenant (tenant resource extensions) in the registration options.",
|
|
15
|
+
},
|
|
16
|
+
} as const satisfies BootRuleTable;
|
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.408.0",
|
|
4
|
+
"type": "improvement",
|
|
5
|
+
"title": "Shared lookup for single-provider extension points",
|
|
6
|
+
"detail": "findSignupHandoverProvider and findTenantDestructionHoldProvider now go through one internal helper that returns the first registered usage whose options match the provider shape. Usages with other options are still skipped, and the result is undefined when none matches."
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"version": "0.407.0",
|
|
10
|
+
"type": "improvement",
|
|
11
|
+
"title": "Tenants with blockDelete rows park in destroyHeld",
|
|
12
|
+
"detail": "When a destroying tenant owns rows of an entity with strategy blockDelete (entity default, preset, profile or per-tenant override), the destruction pauses before the tenant row in the new tenant status destroyHeld instead of deleting those rows. The sweep ignores destroyHeld tenants and hasTenantDestructionWork does not count them. The daily data-retention cleanup hard-deletes the held rows once their keepFor has passed, including their files, and then moves the tenant back to destroying in the same run. Code that switches exhaustively over the tenant status must handle destroyHeld; it is a transient state between destroying and destroyed and never the final one. The tenant's compliance profile and retention overrides are erased in the tenant-row phase through EXT_TENANT_DATA hooks, so they survive while the tenant is held."
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"version": "0.407.0",
|
|
16
|
+
"type": "improvement",
|
|
17
|
+
"title": "requestTenantDestruction extracted",
|
|
18
|
+
"detail": "The core of the request-destruction handler is exported as requestTenantDestruction({ tenantId, actor, now, db, runner, registry, revokeSessions }) so other features, such as tenant-inactivity, file the same deletion request. The handler behavior is unchanged."
|
|
19
|
+
},
|
|
2
20
|
{
|
|
3
21
|
"version": "0.406.0",
|
|
4
22
|
"type": "improvement",
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type FeatureDefinition,
|
|
10
10
|
type TenantLifecycleStatusPlugin,
|
|
11
11
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
12
|
+
import { EXT_TENANT_DESTRUCTION_HOLD } from "../shared/index.ts";
|
|
12
13
|
import {
|
|
13
14
|
validateTenantDataHookCoverage,
|
|
14
15
|
validateTenantDestroyHookShapes,
|
|
@@ -40,10 +41,17 @@ import {
|
|
|
40
41
|
} from "./events.ts";
|
|
41
42
|
import { cancelDestructionWrite } from "./handlers/cancel-destruction.write.ts";
|
|
42
43
|
import { requestDestructionWrite } from "./handlers/request-destruction.write.ts";
|
|
44
|
+
import {
|
|
45
|
+
COMPLIANCE_PROFILE_ENTITY_NAME,
|
|
46
|
+
complianceProfileTenantDestroyHook,
|
|
47
|
+
RETENTION_OVERRIDE_ENTITY_NAME,
|
|
48
|
+
retentionOverrideTenantDestroyHook,
|
|
49
|
+
} from "./retention-config-destroy-hooks.ts";
|
|
43
50
|
import {
|
|
44
51
|
hasTenantDestructionWork,
|
|
45
52
|
resolveTenantLifecycleGate,
|
|
46
53
|
runTenantDestructionSweep,
|
|
54
|
+
tenantDestructionHoldProvider,
|
|
47
55
|
} from "./run-tenant-destroy.ts";
|
|
48
56
|
|
|
49
57
|
const tenantLifecycleStatusPlugin: TenantLifecycleStatusPlugin = {
|
|
@@ -64,7 +72,7 @@ export function createTenantLifecycleFeature(): FeatureDefinition {
|
|
|
64
72
|
recommended: false,
|
|
65
73
|
});
|
|
66
74
|
r.requires({ features: ["tenant", "compliance-profiles"] });
|
|
67
|
-
r.optionalRequires("sessions");
|
|
75
|
+
r.optionalRequires("sessions", "data-retention");
|
|
68
76
|
r.usesApi("compliance.forTenant");
|
|
69
77
|
|
|
70
78
|
r.extendsRegistrar(EXT_TENANT_DATA, {});
|
|
@@ -73,6 +81,21 @@ export function createTenantLifecycleFeature(): FeatureDefinition {
|
|
|
73
81
|
r.extendsRegistrar(EXT_STORAGE_PROVIDER, {});
|
|
74
82
|
r.extendsRegistrar(EXT_INFRA_RESOURCE, {});
|
|
75
83
|
|
|
84
|
+
// Self-extension: data-retention hands a parked tenant back through this, see shared/tenant-destruction-hold.ts.
|
|
85
|
+
r.extendsRegistrar(EXT_TENANT_DESTRUCTION_HOLD, {});
|
|
86
|
+
r.useExtension(EXT_TENANT_DESTRUCTION_HOLD, "tenant-lifecycle", tenantDestructionHoldProvider);
|
|
87
|
+
|
|
88
|
+
// Registered here because the hosts of these entities cannot require tenant-lifecycle (cycle,
|
|
89
|
+
// resp. standalone use); the override hook no-ops without data-retention.
|
|
90
|
+
r.useExtension(EXT_TENANT_DATA, COMPLIANCE_PROFILE_ENTITY_NAME, {
|
|
91
|
+
destroy: complianceProfileTenantDestroyHook,
|
|
92
|
+
phase: "tenant-row",
|
|
93
|
+
});
|
|
94
|
+
r.useExtension(EXT_TENANT_DATA, RETENTION_OVERRIDE_ENTITY_NAME, {
|
|
95
|
+
destroy: retentionOverrideTenantDestroyHook,
|
|
96
|
+
phase: "tenant-row",
|
|
97
|
+
});
|
|
98
|
+
|
|
76
99
|
// Self-extension, same pattern as `user`/EXT_PRINCIPAL_STATUS — declares
|
|
77
100
|
// AND fulfils tenantLifecycleStatus so teardown state is visible with no per-app wiring.
|
|
78
101
|
r.extendsRegistrar(EXT_TENANT_LIFECYCLE_STATUS, {});
|
package/packages/bundled-features/src/tenant-lifecycle/handlers/request-destruction.write.ts
CHANGED
|
@@ -1,22 +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 { type TenantLifecycleStatus, tenantEntity, tenantTable } from "../../tenant/index.ts";
|
|
10
|
-
import { DESTRUCTION_REQUESTED_EVENT_QN, TENANT_LIFECYCLE_FEATURE } from "../constants.ts";
|
|
11
|
-
import { revokeTenantSessions } from "../lib/revoke-tenant-sessions.ts";
|
|
12
|
-
import { invalidateTenantLifecycleGate } from "../lifecycle-gate.ts";
|
|
13
|
-
|
|
14
|
-
const crud = createEventStoreExecutor(tenantTable, tenantEntity, { entityName: "tenant" });
|
|
15
|
-
|
|
16
|
-
type TenantLifecycleRow = {
|
|
17
|
-
status: TenantLifecycleStatus;
|
|
18
|
-
gracePeriodEnd: Temporal.Instant | null;
|
|
19
|
-
};
|
|
3
|
+
import { requestTenantDestruction } from "../request-tenant-destruction.ts";
|
|
20
4
|
|
|
21
5
|
const REQUEST_DESTRUCTION_TENANT_ROW_REASON =
|
|
22
6
|
"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";
|
|
@@ -32,73 +16,14 @@ export const requestDestructionWrite = defineWriteHandler({
|
|
|
32
16
|
grants: ["unsafeRaw"],
|
|
33
17
|
reason: REQUEST_DESTRUCTION_TENANT_ROW_REASON,
|
|
34
18
|
},
|
|
35
|
-
handler: async (event, ctx) =>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
details: { status: row.status },
|
|
46
|
-
}),
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const { profile } = await resolveProfileForTenant({ db: runner, tenantId });
|
|
51
|
-
const T = getTemporal();
|
|
52
|
-
const gracePeriodEnd = addDurationSpec(T.Now.instant(), profile.tenantDestroyGracePeriod);
|
|
53
|
-
|
|
54
|
-
const update = await crud.update(
|
|
55
|
-
{
|
|
56
|
-
id: tenantId,
|
|
57
|
-
changes: {
|
|
58
|
-
status: "destroyRequested",
|
|
59
|
-
destroyRequestedAt: T.Now.instant(),
|
|
60
|
-
destroyRequestedBy: event.user.id,
|
|
61
|
-
gracePeriodEnd,
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
event.user,
|
|
65
|
-
ctx.db,
|
|
66
|
-
{ skipOptimisticLock: true },
|
|
67
|
-
);
|
|
68
|
-
if (!update.isSuccess) return update;
|
|
69
|
-
invalidateTenantLifecycleGate(tenantId);
|
|
70
|
-
|
|
71
|
-
await appendDomainEventCore(
|
|
72
|
-
{
|
|
73
|
-
registry: ctx.registry,
|
|
74
|
-
db: runner,
|
|
75
|
-
tenantId: SYSTEM_TENANT_ID,
|
|
76
|
-
userId: String(event.user.id),
|
|
77
|
-
callSiteLabel: "tenant-lifecycle request-destruction",
|
|
78
|
-
callerFeature: TENANT_LIFECYCLE_FEATURE,
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
aggregateId: tenantId,
|
|
82
|
-
aggregateType: "tenant",
|
|
83
|
-
type: DESTRUCTION_REQUESTED_EVENT_QN,
|
|
84
|
-
payload: {
|
|
85
|
-
requestedBy: event.user.id,
|
|
86
|
-
gracePeriodEnd: gracePeriodEnd.toString(),
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
if (await ctx.hasFeature("sessions")) {
|
|
92
|
-
await revokeTenantSessions(runner, tenantId);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
isSuccess: true as const,
|
|
97
|
-
data: {
|
|
98
|
-
tenantId,
|
|
99
|
-
status: "destroyRequested" as const,
|
|
100
|
-
gracePeriodEnd: gracePeriodEnd.toString(),
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
},
|
|
19
|
+
handler: async (event, ctx) =>
|
|
20
|
+
requestTenantDestruction({
|
|
21
|
+
tenantId: event.user.tenantId,
|
|
22
|
+
actor: event.user,
|
|
23
|
+
now: ctx.tz.now(),
|
|
24
|
+
db: ctx.db,
|
|
25
|
+
runner: ctx.db.unsafeRaw(),
|
|
26
|
+
registry: ctx.registry,
|
|
27
|
+
revokeSessions: await ctx.hasFeature("sessions"),
|
|
28
|
+
}),
|
|
104
29
|
});
|
|
@@ -11,4 +11,8 @@ export {
|
|
|
11
11
|
TenantLifecycleHandlers,
|
|
12
12
|
} from "./constants.ts";
|
|
13
13
|
export { createTenantLifecycleFeature } from "./feature.ts";
|
|
14
|
+
export {
|
|
15
|
+
type RequestTenantDestructionArgs,
|
|
16
|
+
requestTenantDestruction,
|
|
17
|
+
} from "./request-tenant-destruction.ts";
|
|
14
18
|
export { resolveTenantLifecycleGate } from "./run-tenant-destroy.ts";
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { addDurationSpec } from "@cosmicdrift/kumiko-framework/compliance";
|
|
2
|
+
import {
|
|
3
|
+
createEventStoreExecutor,
|
|
4
|
+
type DbRunner,
|
|
5
|
+
fetchOne,
|
|
6
|
+
type TenantDb,
|
|
7
|
+
} from "@cosmicdrift/kumiko-framework/db";
|
|
8
|
+
import {
|
|
9
|
+
type Registry,
|
|
10
|
+
type SessionUser,
|
|
11
|
+
SYSTEM_TENANT_ID,
|
|
12
|
+
type TenantId,
|
|
13
|
+
} from "@cosmicdrift/kumiko-framework/engine";
|
|
14
|
+
import { UnprocessableError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
15
|
+
import { appendDomainEventCore } from "@cosmicdrift/kumiko-framework/pipeline";
|
|
16
|
+
import type { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
17
|
+
import { resolveProfileForTenant } from "../compliance-profiles/index.ts";
|
|
18
|
+
import { type TenantLifecycleStatus, tenantEntity, tenantTable } from "../tenant/index.ts";
|
|
19
|
+
import { DESTRUCTION_REQUESTED_EVENT_QN, TENANT_LIFECYCLE_FEATURE } from "./constants.ts";
|
|
20
|
+
import { revokeTenantSessions } from "./lib/revoke-tenant-sessions.ts";
|
|
21
|
+
import { invalidateTenantLifecycleGate } from "./lifecycle-gate.ts";
|
|
22
|
+
|
|
23
|
+
const crud = createEventStoreExecutor(tenantTable, tenantEntity, { entityName: "tenant" });
|
|
24
|
+
|
|
25
|
+
type TenantLifecycleRow = {
|
|
26
|
+
status: TenantLifecycleStatus;
|
|
27
|
+
gracePeriodEnd: Temporal.Instant | null;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type RequestTenantDestructionArgs = {
|
|
31
|
+
readonly tenantId: TenantId;
|
|
32
|
+
readonly actor: SessionUser;
|
|
33
|
+
readonly now: Temporal.Instant;
|
|
34
|
+
readonly db: TenantDb;
|
|
35
|
+
readonly runner: DbRunner;
|
|
36
|
+
readonly registry: Registry;
|
|
37
|
+
readonly revokeSessions: boolean;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Shared by the owner-facing request-destruction handler and by system callers such as
|
|
41
|
+
// tenant-inactivity, so both start the same compliance-profile grace period.
|
|
42
|
+
export async function requestTenantDestruction(args: RequestTenantDestructionArgs) {
|
|
43
|
+
const { tenantId, actor, now, db, runner, registry } = args;
|
|
44
|
+
const row = await fetchOne<TenantLifecycleRow>(runner, tenantTable, { id: tenantId });
|
|
45
|
+
if (!row) {
|
|
46
|
+
return writeFailure(new UnprocessableError("tenant_not_found", { details: { tenantId } }));
|
|
47
|
+
}
|
|
48
|
+
if (row.status !== "active") {
|
|
49
|
+
return writeFailure(
|
|
50
|
+
new UnprocessableError("tenant_not_active", {
|
|
51
|
+
details: { status: row.status },
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const { profile } = await resolveProfileForTenant({ db: runner, tenantId });
|
|
57
|
+
const gracePeriodEnd = addDurationSpec(now, profile.tenantDestroyGracePeriod);
|
|
58
|
+
|
|
59
|
+
const update = await crud.update(
|
|
60
|
+
{
|
|
61
|
+
id: tenantId,
|
|
62
|
+
changes: {
|
|
63
|
+
status: "destroyRequested",
|
|
64
|
+
destroyRequestedAt: now,
|
|
65
|
+
destroyRequestedBy: actor.id,
|
|
66
|
+
gracePeriodEnd,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
actor,
|
|
70
|
+
db,
|
|
71
|
+
{ skipOptimisticLock: true },
|
|
72
|
+
);
|
|
73
|
+
if (!update.isSuccess) return update;
|
|
74
|
+
invalidateTenantLifecycleGate(tenantId);
|
|
75
|
+
|
|
76
|
+
await appendDomainEventCore(
|
|
77
|
+
{
|
|
78
|
+
registry,
|
|
79
|
+
db: runner,
|
|
80
|
+
tenantId: SYSTEM_TENANT_ID,
|
|
81
|
+
userId: String(actor.id),
|
|
82
|
+
callSiteLabel: "tenant-lifecycle request-destruction",
|
|
83
|
+
callerFeature: TENANT_LIFECYCLE_FEATURE,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
aggregateId: tenantId,
|
|
87
|
+
aggregateType: "tenant",
|
|
88
|
+
type: DESTRUCTION_REQUESTED_EVENT_QN,
|
|
89
|
+
payload: {
|
|
90
|
+
requestedBy: actor.id,
|
|
91
|
+
gracePeriodEnd: gracePeriodEnd.toString(),
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
if (args.revokeSessions) {
|
|
97
|
+
await revokeTenantSessions(runner, tenantId);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
isSuccess: true as const,
|
|
102
|
+
data: {
|
|
103
|
+
tenantId,
|
|
104
|
+
status: "destroyRequested" as const,
|
|
105
|
+
gracePeriodEnd: gracePeriodEnd.toString(),
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|