@cosmicdrift/kumiko-bundled-features 0.405.0 → 0.409.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/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/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/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 +130 -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 +186 -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 +464 -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/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/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/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/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-tenant.query.js +3 -1
- 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 +48 -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/constants.d.ts +1 -0
- package/dist/tenant-lifecycle/constants.js +5 -0
- package/dist/tenant-lifecycle/events.d.ts +2 -0
- package/dist/tenant-lifecycle/events.js +2 -0
- package/dist/tenant-lifecycle/feature.js +18 -3
- package/dist/tenant-lifecycle/handlers/request-destruction.write.js +11 -67
- package/dist/tenant-lifecycle/index.d.ts +2 -1
- package/dist/tenant-lifecycle/index.js +2 -1
- 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 +5 -0
- package/dist/tenant-lifecycle/run-tenant-destroy.js +85 -12
- package/dist/tenant-lifecycle/stages.d.ts +3 -0
- package/dist/tenant-lifecycle/stages.js +27 -3
- 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/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/kumiko-es-tables.json +12 -0
- package/package.json +46 -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 +27 -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 +30 -0
- package/src/tier-engine/changes.json +6 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { addDurationSpec, } from "@cosmicdrift/kumiko-framework/compliance";
|
|
2
|
+
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
3
|
+
const EPOCH = Temporal.Instant.fromEpochMilliseconds(0);
|
|
4
|
+
export function addRetentionSpec(from, spec) {
|
|
5
|
+
if ("months" in spec) {
|
|
6
|
+
return from.toZonedDateTimeISO("UTC").add({ months: spec.months }).toInstant();
|
|
7
|
+
}
|
|
8
|
+
if ("years" in spec) {
|
|
9
|
+
return from.toZonedDateTimeISO("UTC").add({ years: spec.years }).toInstant();
|
|
10
|
+
}
|
|
11
|
+
return addDurationSpec(from, spec);
|
|
12
|
+
}
|
|
13
|
+
function leadMs(spec) {
|
|
14
|
+
return addDurationSpec(EPOCH, spec).epochMilliseconds;
|
|
15
|
+
}
|
|
16
|
+
// Longest lead first, so index 0 is the earliest warning.
|
|
17
|
+
export function sortedWarnings(rule) {
|
|
18
|
+
return [...rule.warnings].sort((a, b) => leadMs(b) - leadMs(a));
|
|
19
|
+
}
|
|
20
|
+
function laterOf(instants) {
|
|
21
|
+
let latest = null;
|
|
22
|
+
for (const instant of instants) {
|
|
23
|
+
if (instant !== null && (latest === null || Temporal.Instant.compare(instant, latest) > 0)) {
|
|
24
|
+
latest = instant;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return latest;
|
|
28
|
+
}
|
|
29
|
+
export function activityBase(state) {
|
|
30
|
+
return (laterOf([state.firstSeenAt, state.lastActivityAt, state.lastExemptAt]) ?? state.firstSeenAt);
|
|
31
|
+
}
|
|
32
|
+
// Activity after the last warning starts a new cycle.
|
|
33
|
+
export function isNewCycle(state) {
|
|
34
|
+
return (state.warningsSent > 0 &&
|
|
35
|
+
state.lastWarnedAt !== null &&
|
|
36
|
+
Temporal.Instant.compare(activityBase(state), state.lastWarnedAt) > 0);
|
|
37
|
+
}
|
|
38
|
+
export function resetWarnings(state) {
|
|
39
|
+
return { ...state, warningsSent: 0, lastWarnedAt: null, postponedDueAt: null };
|
|
40
|
+
}
|
|
41
|
+
export function dueAt(state, rule) {
|
|
42
|
+
const regular = addRetentionSpec(activityBase(state), rule.after);
|
|
43
|
+
return laterOf([regular, state.postponedDueAt]) ?? regular;
|
|
44
|
+
}
|
|
45
|
+
// Expects a state that already went through the new-cycle reset.
|
|
46
|
+
export function planNextStep(state, rule) {
|
|
47
|
+
const due = dueAt(state, rule);
|
|
48
|
+
const warnings = sortedWarnings(rule);
|
|
49
|
+
const nextWarning = warnings[state.warningsSent];
|
|
50
|
+
if (nextWarning === undefined)
|
|
51
|
+
return { step: "destructionRequest", at: due };
|
|
52
|
+
const warnAt = Temporal.Instant.fromEpochMilliseconds(due.epochMilliseconds - leadMs(nextWarning));
|
|
53
|
+
return { step: "warning", at: warnAt };
|
|
54
|
+
}
|
|
55
|
+
// At most one warning per run: the latest one that is due. A deadline that passed with warnings
|
|
56
|
+
// missing sends the final warning late and moves the deletion request behind it.
|
|
57
|
+
export function decideInactivityAction(state, rule, now) {
|
|
58
|
+
const due = dueAt(state, rule);
|
|
59
|
+
const warnings = sortedWarnings(rule);
|
|
60
|
+
const total = warnings.length;
|
|
61
|
+
if (state.warningsSent >= total) {
|
|
62
|
+
return Temporal.Instant.compare(now, due) >= 0 ? { kind: "destroy" } : { kind: "none" };
|
|
63
|
+
}
|
|
64
|
+
const finalLead = warnings[total - 1];
|
|
65
|
+
if (finalLead !== undefined && Temporal.Instant.compare(now, due) >= 0) {
|
|
66
|
+
const postponedDueAt = addDurationSpec(now, finalLead);
|
|
67
|
+
return {
|
|
68
|
+
kind: "warn",
|
|
69
|
+
warningsSentAfter: total,
|
|
70
|
+
deadline: postponedDueAt,
|
|
71
|
+
postponedDueAt,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
let lastDue = -1;
|
|
75
|
+
for (let index = state.warningsSent; index < total; index++) {
|
|
76
|
+
const lead = warnings[index];
|
|
77
|
+
if (lead !== undefined && now.epochMilliseconds >= due.epochMilliseconds - leadMs(lead)) {
|
|
78
|
+
lastDue = index;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (lastDue < 0)
|
|
82
|
+
return { kind: "none" };
|
|
83
|
+
return { kind: "warn", warningsSentAfter: lastDue + 1, deadline: due, postponedDueAt: null };
|
|
84
|
+
}
|
|
85
|
+
// Raises lastActivityAt to the newest known activity; activity after the last warning starts a
|
|
86
|
+
// new cycle, which also drops a postponed deadline.
|
|
87
|
+
export function foldActivity(state, newest) {
|
|
88
|
+
const lastActivityAt = laterOf([state.lastActivityAt, newest]);
|
|
89
|
+
const raised = { ...state, lastActivityAt };
|
|
90
|
+
if (!isNewCycle(raised))
|
|
91
|
+
return { state: raised, newCycle: false };
|
|
92
|
+
return { state: resetWarnings(raised), newCycle: true };
|
|
93
|
+
}
|
|
94
|
+
// Shared by the daily job and the state query so both name the same next step.
|
|
95
|
+
export function describeOutlook(state, rule) {
|
|
96
|
+
if (rule === null || state === null) {
|
|
97
|
+
return {
|
|
98
|
+
exempt: rule === null,
|
|
99
|
+
lastActivityAt: state?.lastActivityAt ?? null,
|
|
100
|
+
warningsSent: state?.warningsSent ?? 0,
|
|
101
|
+
nextStep: null,
|
|
102
|
+
nextStepAt: null,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const plan = planNextStep(state, rule);
|
|
106
|
+
return {
|
|
107
|
+
exempt: false,
|
|
108
|
+
lastActivityAt: state.lastActivityAt,
|
|
109
|
+
warningsSent: state.warningsSent,
|
|
110
|
+
nextStep: plan.step,
|
|
111
|
+
nextStepAt: plan.at,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { TenantInactivityHandlers, TenantInactivityJobs } from "./constants.ts";
|
|
2
|
+
export { createTenantInactivityFeature } from "./feature.ts";
|
|
3
|
+
export type { InactivityRule } from "./inactivity-plan.ts";
|
|
4
|
+
export type { TenantActivitySource, TenantInactivityOptions } from "./options.ts";
|
|
5
|
+
export { fetchRemoteAppLastActivity } from "./remote-activity.ts";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
2
|
+
import { type RowBoundGrantResult } from "../shared/index.ts";
|
|
3
|
+
export declare function signKeepAccountToken(args: {
|
|
4
|
+
readonly tenantId: string;
|
|
5
|
+
readonly cycleId: string;
|
|
6
|
+
readonly ttlMinutes: number;
|
|
7
|
+
readonly secret: string;
|
|
8
|
+
readonly now: Temporal.Instant;
|
|
9
|
+
}): string;
|
|
10
|
+
export declare function redeemKeepAccountToken(args: {
|
|
11
|
+
readonly token: string;
|
|
12
|
+
readonly secret: string | undefined;
|
|
13
|
+
readonly loadCycleId: (tenantId: string) => Promise<string | null>;
|
|
14
|
+
readonly commitKeep: (tenantId: string, cycleId: string) => Promise<boolean>;
|
|
15
|
+
readonly now: Temporal.Instant;
|
|
16
|
+
}): Promise<RowBoundGrantResult>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { redeemRowBoundGrant, signRowBoundGrant, } from "../shared/index.js";
|
|
2
|
+
const KEEP_ACCOUNT_PURPOSE = "keep-account";
|
|
3
|
+
// Subject is the tenant, anchor the state row's cycleId: any activity or a redeemed link rotates
|
|
4
|
+
// the cycleId, so every earlier link stops verifying.
|
|
5
|
+
export function signKeepAccountToken(args) {
|
|
6
|
+
return signRowBoundGrant({
|
|
7
|
+
subject: args.tenantId,
|
|
8
|
+
purpose: KEEP_ACCOUNT_PURPOSE,
|
|
9
|
+
anchor: args.cycleId,
|
|
10
|
+
ttlMinutes: args.ttlMinutes,
|
|
11
|
+
secret: args.secret,
|
|
12
|
+
now: args.now,
|
|
13
|
+
}).token;
|
|
14
|
+
}
|
|
15
|
+
export function redeemKeepAccountToken(args) {
|
|
16
|
+
return redeemRowBoundGrant({
|
|
17
|
+
token: args.token,
|
|
18
|
+
purpose: KEEP_ACCOUNT_PURPOSE,
|
|
19
|
+
secret: args.secret,
|
|
20
|
+
loadAnchor: args.loadCycleId,
|
|
21
|
+
commitAnchor: args.commitKeep,
|
|
22
|
+
now: args.now,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type FeatureRegistrar } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
export declare const InactivityWarningNotificationType: string;
|
|
3
|
+
export declare const inactivityMailTemplateLocale: (notificationType: string, requestedLocale: string) => string;
|
|
4
|
+
export declare function registerInactivityMails(r: FeatureRegistrar): void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { QnTypes, qn, templateVariable, } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { mailT } from "@cosmicdrift/kumiko-framework/i18n";
|
|
3
|
+
import { escapeHtml } from "@cosmicdrift/kumiko-renderer/headless";
|
|
4
|
+
import { createMailLocaleTemplates, mailParagraph } from "../shared/index.js";
|
|
5
|
+
import { TENANT_INACTIVITY_FEATURE } from "./constants.js";
|
|
6
|
+
const WARNING_MAIL_NAME = "warning";
|
|
7
|
+
export const InactivityWarningNotificationType = qn(TENANT_INACTIVITY_FEATURE, QnTypes.notify, WARNING_MAIL_NAME);
|
|
8
|
+
const WARNING_SUBJECT_KEY = "inactivity.mail.warning.subject";
|
|
9
|
+
// Translation placeholder -> template variable.
|
|
10
|
+
// The translation slot is named account because locale-de rejects the word tenant in values.
|
|
11
|
+
const SLOTS = { app: "{app}", account: "{tenant}", when: "{when}" };
|
|
12
|
+
const SUBJECT_SLOTS = { app: "{{app}}", account: "{{tenant}}", when: "{{when}}" };
|
|
13
|
+
const WARNING_VARIABLES = {
|
|
14
|
+
app: templateVariable.text({ required: true }),
|
|
15
|
+
tenant: templateVariable.text({ required: true }),
|
|
16
|
+
when: templateVariable.text({ required: true }),
|
|
17
|
+
keepUrl: templateVariable.link({ required: true }),
|
|
18
|
+
};
|
|
19
|
+
function warningBody(locale) {
|
|
20
|
+
const paragraph = (part) => mailParagraph(mailT(locale, `inactivity.mail.warning.${part}`, SLOTS));
|
|
21
|
+
return [
|
|
22
|
+
mailParagraph(mailT(locale, "gdpr.mail.greeting")),
|
|
23
|
+
paragraph("intro"),
|
|
24
|
+
paragraph("keep"),
|
|
25
|
+
`<p><a data-button href="{{keepUrl}}">${escapeHtml(mailT(locale, "inactivity.mail.warning.button"))}</a></p>`,
|
|
26
|
+
paragraph("after"),
|
|
27
|
+
].join("");
|
|
28
|
+
}
|
|
29
|
+
const mailLocaleTemplates = createMailLocaleTemplates({
|
|
30
|
+
kinds: [WARNING_MAIL_NAME],
|
|
31
|
+
notificationTypes: { [WARNING_MAIL_NAME]: InactivityWarningNotificationType },
|
|
32
|
+
subjectKey: () => WARNING_SUBJECT_KEY,
|
|
33
|
+
bodyFor: (_kind, locale) => warningBody(locale),
|
|
34
|
+
subjectSlots: () => SUBJECT_SLOTS,
|
|
35
|
+
});
|
|
36
|
+
export const inactivityMailTemplateLocale = mailLocaleTemplates.templateLocale;
|
|
37
|
+
export function registerInactivityMails(r) {
|
|
38
|
+
r.notification(WARNING_MAIL_NAME, {
|
|
39
|
+
variables: WARNING_VARIABLES,
|
|
40
|
+
localizedTemplate: mailLocaleTemplates.localizedTemplate(WARNING_MAIL_NAME),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
/** Newest activity an app knows outside this app's sessions (for example a sibling app); null when none. */
|
|
6
|
+
export type TenantActivitySource = (args: {
|
|
7
|
+
readonly tenantId: TenantId;
|
|
8
|
+
readonly now: Temporal.Instant;
|
|
9
|
+
}) => Promise<Temporal.Instant | null>;
|
|
10
|
+
type SharedOptions = {
|
|
11
|
+
/** HMAC key of the keep-account links. Unset: mails link to keepAccountUrl without a token. */
|
|
12
|
+
readonly keepAccountTokenSecret?: string;
|
|
13
|
+
/** App page that reads the `#token=` fragment and calls the keep-account handler. */
|
|
14
|
+
readonly keepAccountUrl: string;
|
|
15
|
+
/** Name shown in the mails; defaults to a generic word per locale. */
|
|
16
|
+
readonly appName?: string;
|
|
17
|
+
readonly activitySources?: readonly TenantActivitySource[];
|
|
18
|
+
};
|
|
19
|
+
export type TenantInactivityOptions<TTier extends string = string> = SharedOptions & ({
|
|
20
|
+
readonly rule: InactivityRule;
|
|
21
|
+
} | {
|
|
22
|
+
readonly resolveTier: (db: TenantDb) => Promise<TTier>;
|
|
23
|
+
/** null exempts the tier (paid plans). */
|
|
24
|
+
readonly rulesByTier: Readonly<Record<TTier, InactivityRule | null>>;
|
|
25
|
+
});
|
|
26
|
+
export declare function resolveInactivityRule<TTier extends string>(options: TenantInactivityOptions<TTier>, db: TenantDb): Promise<InactivityRule | null>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
2
|
+
type SendRequest = (url: string, init: RequestInit) => Promise<Response>;
|
|
3
|
+
/**
|
|
4
|
+
* Asks a sibling app for its newest session activity (the sessions `lastActivityProbeSecret`
|
|
5
|
+
* route). Use it inside a `TenantActivitySource` so a user active in the other app keeps the
|
|
6
|
+
* account alive. Fails closed: any error throws, and the job then sends no mail and files no
|
|
7
|
+
* deletion request for that run. `send` exists for tests; production uses the internal egress
|
|
8
|
+
* pinned to the origin of `url`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function fetchRemoteAppLastActivity(args: {
|
|
11
|
+
readonly url: string;
|
|
12
|
+
readonly secret: string;
|
|
13
|
+
readonly send?: SendRequest;
|
|
14
|
+
}): Promise<Temporal.Instant | null>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { egress } from "@cosmicdrift/kumiko-framework/http";
|
|
2
|
+
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
const probeResponseSchema = z.object({ lastActivityAt: z.string().nullable() });
|
|
5
|
+
/**
|
|
6
|
+
* Asks a sibling app for its newest session activity (the sessions `lastActivityProbeSecret`
|
|
7
|
+
* route). Use it inside a `TenantActivitySource` so a user active in the other app keeps the
|
|
8
|
+
* account alive. Fails closed: any error throws, and the job then sends no mail and files no
|
|
9
|
+
* deletion request for that run. `send` exists for tests; production uses the internal egress
|
|
10
|
+
* pinned to the origin of `url`.
|
|
11
|
+
*/
|
|
12
|
+
export async function fetchRemoteAppLastActivity(args) {
|
|
13
|
+
// Sibling apps sit in the same cluster on private addresses, which the external policy blocks.
|
|
14
|
+
const send = args.send ?? egress({ kind: "internal", allowOrigins: [new URL(args.url).origin] });
|
|
15
|
+
const response = await send(args.url, {
|
|
16
|
+
method: "GET",
|
|
17
|
+
headers: { authorization: `Bearer ${args.secret}` },
|
|
18
|
+
});
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
throw new Error(`remote activity probe answered ${response.status}`);
|
|
21
|
+
}
|
|
22
|
+
const body = probeResponseSchema.parse(await response.json());
|
|
23
|
+
return body.lastActivityAt === null ? null : Temporal.Instant.from(body.lastActivityAt);
|
|
24
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
3
|
+
import type { InactivityState } from "./inactivity-plan.ts";
|
|
4
|
+
export type StoredInactivityState = InactivityState & {
|
|
5
|
+
readonly cycleId: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function loadInactivityState(db: TenantDb): Promise<StoredInactivityState | null>;
|
|
8
|
+
export declare function isSameInactivityState(a: StoredInactivityState | null, b: StoredInactivityState): boolean;
|
|
9
|
+
export declare function saveInactivityState(db: TenantDb, previous: StoredInactivityState | null, next: StoredInactivityState): Promise<void>;
|
|
10
|
+
export declare function loadNewestSessionActivity(db: TenantDb): Promise<Temporal.Instant | null>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
2
|
+
import { userSessionTable } from "../sessions/index.js";
|
|
3
|
+
import { tenantInactivityStateTable } from "./state-table.js";
|
|
4
|
+
const EPOCH = Temporal.Instant.fromEpochMilliseconds(0);
|
|
5
|
+
export async function loadInactivityState(db) {
|
|
6
|
+
const row = await db.fetchOne(tenantInactivityStateTable, { tenantId: db.tenantId });
|
|
7
|
+
if (!row)
|
|
8
|
+
return null;
|
|
9
|
+
return {
|
|
10
|
+
cycleId: row.cycleId,
|
|
11
|
+
firstSeenAt: row.firstSeenAt,
|
|
12
|
+
lastActivityAt: row.lastActivityAt,
|
|
13
|
+
lastExemptAt: row.lastExemptAt,
|
|
14
|
+
lastWarnedAt: row.lastWarnedAt,
|
|
15
|
+
postponedDueAt: row.postponedDueAt,
|
|
16
|
+
warningsSent: row.warningsSent,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function sameInstant(a, b) {
|
|
20
|
+
if (a === null || b === null)
|
|
21
|
+
return a === b;
|
|
22
|
+
return a.epochMilliseconds === b.epochMilliseconds;
|
|
23
|
+
}
|
|
24
|
+
export function isSameInactivityState(a, b) {
|
|
25
|
+
return (a !== null &&
|
|
26
|
+
a.cycleId === b.cycleId &&
|
|
27
|
+
a.warningsSent === b.warningsSent &&
|
|
28
|
+
sameInstant(a.firstSeenAt, b.firstSeenAt) &&
|
|
29
|
+
sameInstant(a.lastActivityAt, b.lastActivityAt) &&
|
|
30
|
+
sameInstant(a.lastExemptAt, b.lastExemptAt) &&
|
|
31
|
+
sameInstant(a.lastWarnedAt, b.lastWarnedAt) &&
|
|
32
|
+
sameInstant(a.postponedDueAt, b.postponedDueAt));
|
|
33
|
+
}
|
|
34
|
+
// Writes only when something changed, so a run that decides nothing stays read-only.
|
|
35
|
+
export async function saveInactivityState(db, previous, next) {
|
|
36
|
+
// skip: nothing changed, so the run stays read-only
|
|
37
|
+
if (isSameInactivityState(previous, next))
|
|
38
|
+
return;
|
|
39
|
+
if (previous === null) {
|
|
40
|
+
await db.insertOne(tenantInactivityStateTable, { tenantId: db.tenantId, ...next });
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
await db.updateMany(tenantInactivityStateTable, next, { tenantId: db.tenantId });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// The sessions table keeps the activity marker; reading it here avoids a write per request.
|
|
47
|
+
export async function loadNewestSessionActivity(db) {
|
|
48
|
+
const [newest] = await db.selectMany(userSessionTable, { tenantId: db.tenantId, lastSeenAt: { gte: EPOCH } }, { limit: 1, orderBy: { col: "lastSeenAt", direction: "desc" } });
|
|
49
|
+
return newest?.lastSeenAt ?? null;
|
|
50
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export declare const tenantInactivityStateEntity: import("@cosmicdrift/kumiko-types/fields").EntityDefinition<{
|
|
2
|
+
readonly tenantId: import("@cosmicdrift/kumiko-types/fields").EntityTextFieldDef & {
|
|
3
|
+
required: true;
|
|
4
|
+
};
|
|
5
|
+
readonly cycleId: import("@cosmicdrift/kumiko-types/fields").EntityTextFieldDef & {
|
|
6
|
+
required: true;
|
|
7
|
+
};
|
|
8
|
+
readonly firstSeenAt: {
|
|
9
|
+
readonly type: "timestamp";
|
|
10
|
+
readonly description?: string;
|
|
11
|
+
readonly required?: boolean;
|
|
12
|
+
readonly sortable?: boolean;
|
|
13
|
+
readonly sortNulls?: import("@cosmicdrift/kumiko-types/fields").SortNulls;
|
|
14
|
+
readonly filterable?: boolean;
|
|
15
|
+
readonly sensitive?: boolean;
|
|
16
|
+
readonly access?: import("@cosmicdrift/kumiko-types/fields").FieldAccess;
|
|
17
|
+
readonly locatedBy?: string;
|
|
18
|
+
readonly min?: string;
|
|
19
|
+
readonly max?: string;
|
|
20
|
+
readonly locale?: string;
|
|
21
|
+
} & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
|
|
22
|
+
required: true;
|
|
23
|
+
};
|
|
24
|
+
readonly lastActivityAt: {
|
|
25
|
+
readonly type: "timestamp";
|
|
26
|
+
readonly description?: string;
|
|
27
|
+
readonly required?: boolean;
|
|
28
|
+
readonly sortable?: boolean;
|
|
29
|
+
readonly sortNulls?: import("@cosmicdrift/kumiko-types/fields").SortNulls;
|
|
30
|
+
readonly filterable?: boolean;
|
|
31
|
+
readonly sensitive?: boolean;
|
|
32
|
+
readonly access?: import("@cosmicdrift/kumiko-types/fields").FieldAccess;
|
|
33
|
+
readonly locatedBy?: string;
|
|
34
|
+
readonly min?: string;
|
|
35
|
+
readonly max?: string;
|
|
36
|
+
readonly locale?: string;
|
|
37
|
+
} & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
|
|
38
|
+
required: false;
|
|
39
|
+
};
|
|
40
|
+
readonly lastExemptAt: {
|
|
41
|
+
readonly type: "timestamp";
|
|
42
|
+
readonly description?: string;
|
|
43
|
+
readonly required?: boolean;
|
|
44
|
+
readonly sortable?: boolean;
|
|
45
|
+
readonly sortNulls?: import("@cosmicdrift/kumiko-types/fields").SortNulls;
|
|
46
|
+
readonly filterable?: boolean;
|
|
47
|
+
readonly sensitive?: boolean;
|
|
48
|
+
readonly access?: import("@cosmicdrift/kumiko-types/fields").FieldAccess;
|
|
49
|
+
readonly locatedBy?: string;
|
|
50
|
+
readonly min?: string;
|
|
51
|
+
readonly max?: string;
|
|
52
|
+
readonly locale?: string;
|
|
53
|
+
} & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
|
|
54
|
+
required: false;
|
|
55
|
+
};
|
|
56
|
+
readonly lastWarnedAt: {
|
|
57
|
+
readonly type: "timestamp";
|
|
58
|
+
readonly description?: string;
|
|
59
|
+
readonly required?: boolean;
|
|
60
|
+
readonly sortable?: boolean;
|
|
61
|
+
readonly sortNulls?: import("@cosmicdrift/kumiko-types/fields").SortNulls;
|
|
62
|
+
readonly filterable?: boolean;
|
|
63
|
+
readonly sensitive?: boolean;
|
|
64
|
+
readonly access?: import("@cosmicdrift/kumiko-types/fields").FieldAccess;
|
|
65
|
+
readonly locatedBy?: string;
|
|
66
|
+
readonly min?: string;
|
|
67
|
+
readonly max?: string;
|
|
68
|
+
readonly locale?: string;
|
|
69
|
+
} & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
|
|
70
|
+
required: false;
|
|
71
|
+
};
|
|
72
|
+
readonly postponedDueAt: {
|
|
73
|
+
readonly type: "timestamp";
|
|
74
|
+
readonly description?: string;
|
|
75
|
+
readonly required?: boolean;
|
|
76
|
+
readonly sortable?: boolean;
|
|
77
|
+
readonly sortNulls?: import("@cosmicdrift/kumiko-types/fields").SortNulls;
|
|
78
|
+
readonly filterable?: boolean;
|
|
79
|
+
readonly sensitive?: boolean;
|
|
80
|
+
readonly access?: import("@cosmicdrift/kumiko-types/fields").FieldAccess;
|
|
81
|
+
readonly locatedBy?: string;
|
|
82
|
+
readonly min?: string;
|
|
83
|
+
readonly max?: string;
|
|
84
|
+
readonly locale?: string;
|
|
85
|
+
} & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
|
|
86
|
+
required: false;
|
|
87
|
+
};
|
|
88
|
+
readonly warningsSent: {
|
|
89
|
+
readonly type: "number";
|
|
90
|
+
readonly description?: string;
|
|
91
|
+
readonly required?: boolean;
|
|
92
|
+
readonly sortable?: boolean;
|
|
93
|
+
readonly sortNulls?: import("@cosmicdrift/kumiko-types/fields").SortNulls;
|
|
94
|
+
readonly filterable?: boolean;
|
|
95
|
+
readonly sensitive?: boolean;
|
|
96
|
+
readonly default?: number;
|
|
97
|
+
readonly access?: import("@cosmicdrift/kumiko-types/fields").FieldAccess;
|
|
98
|
+
readonly min?: number;
|
|
99
|
+
readonly max?: number;
|
|
100
|
+
readonly integer?: boolean;
|
|
101
|
+
readonly unit?: string | {
|
|
102
|
+
readonly field: string;
|
|
103
|
+
};
|
|
104
|
+
readonly grouping?: boolean;
|
|
105
|
+
} & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
|
|
106
|
+
required: true;
|
|
107
|
+
};
|
|
108
|
+
}, "tenant">;
|
|
109
|
+
export declare const tenantInactivityStateTable: import("@cosmicdrift/kumiko-types/entity-table-meta-types").EntityTableMeta & import("@cosmicdrift/kumiko-types/executor-brand").Writable;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { deriveEntityTableMeta } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import { access, createEntity, createNumberField, createTextField, createTimestampField, } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
import { TENANT_INACTIVITY_STATE_ENTITY } from "./constants.js";
|
|
4
|
+
// One row per tenant. Direct-write store: the daily job and the keep-account handler mutate
|
|
5
|
+
// columns, there is no aggregate or event stream behind it.
|
|
6
|
+
export const tenantInactivityStateEntity = createEntity({
|
|
7
|
+
table: "store_tenant_inactivity_state",
|
|
8
|
+
softDelete: false,
|
|
9
|
+
fields: {
|
|
10
|
+
tenantId: createTextField({
|
|
11
|
+
required: true,
|
|
12
|
+
maxLength: 36,
|
|
13
|
+
access: { write: access.privileged },
|
|
14
|
+
personal: false,
|
|
15
|
+
reason: "pseudonymous_fk",
|
|
16
|
+
}),
|
|
17
|
+
cycleId: createTextField({
|
|
18
|
+
required: true,
|
|
19
|
+
maxLength: 36,
|
|
20
|
+
access: { write: access.privileged },
|
|
21
|
+
personal: false,
|
|
22
|
+
reason: "technical_reference",
|
|
23
|
+
}),
|
|
24
|
+
firstSeenAt: createTimestampField({ required: true, access: { write: access.privileged } }),
|
|
25
|
+
lastActivityAt: createTimestampField({ access: { write: access.privileged } }),
|
|
26
|
+
lastExemptAt: createTimestampField({ access: { write: access.privileged } }),
|
|
27
|
+
lastWarnedAt: createTimestampField({ access: { write: access.privileged } }),
|
|
28
|
+
postponedDueAt: createTimestampField({ access: { write: access.privileged } }),
|
|
29
|
+
warningsSent: createNumberField({
|
|
30
|
+
required: true,
|
|
31
|
+
integer: true,
|
|
32
|
+
min: 0,
|
|
33
|
+
access: { write: access.privileged },
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
indexes: [{ unique: true, columns: ["tenantId"], name: "store_tenant_inactivity_state_tenant" }],
|
|
37
|
+
});
|
|
38
|
+
export const tenantInactivityStateTable = deriveEntityTableMeta(TENANT_INACTIVITY_STATE_ENTITY, tenantInactivityStateEntity, { source: "unmanaged" });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { EXT_EXTERNAL_RESOURCE, EXT_INFRA_RESOURCE, EXT_SEARCH_ADAPTER, EXT_STORAGE_PROVIDER, EXT_TENANT_DATA, isTenantDataExtensionHooks, isTenantResourceExtensionHooks, } from "@cosmicdrift/kumiko-framework/engine";
|
|
1
|
+
import { bootRuleError, EXT_EXTERNAL_RESOURCE, EXT_INFRA_RESOURCE, EXT_SEARCH_ADAPTER, EXT_STORAGE_PROVIDER, EXT_TENANT_DATA, isTenantDataExtensionHooks, isTenantResourceExtensionHooks, } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
|
|
3
3
|
import { entitiesOf } from "../shared/index.js";
|
|
4
|
+
import { TENANT_LIFECYCLE_BOOT_RULES } from "./boot-rules.js";
|
|
4
5
|
const log = createFallbackLogger("kumiko:boot");
|
|
5
6
|
// V4: tenantOwned-entity-without-hook gate. Mirrors user-data-rights' V3
|
|
6
7
|
// (validateGdprPiiHookCoverage) but for EXT_TENANT_DATA. Registered as this
|
|
@@ -32,7 +33,9 @@ export function validateTenantDataHookCoverage(features) {
|
|
|
32
33
|
.map(([name]) => name);
|
|
33
34
|
if (tenantSubjectFields.length === 0)
|
|
34
35
|
continue;
|
|
35
|
-
throw
|
|
36
|
+
throw bootRuleError(TENANT_LIFECYCLE_BOOT_RULES.tenantSubjectWithoutDestroyHook, {
|
|
37
|
+
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.`,
|
|
38
|
+
});
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
}
|
|
@@ -58,7 +61,9 @@ export function validateTenantDestroyHookShapes(features) {
|
|
|
58
61
|
if (isValid)
|
|
59
62
|
continue;
|
|
60
63
|
const requiredFn = isTenantData ? "destroy" : "destroyTenant";
|
|
61
|
-
throw
|
|
64
|
+
throw bootRuleError(TENANT_LIFECYCLE_BOOT_RULES.destroyFunctionMissing, {
|
|
65
|
+
message: `[kumiko:boot] ${usage.extensionName} registration for "${usage.entityName}" (feature "${feature.name}") has no ${requiredFn} function — tenant destroy would fail at this stage.`,
|
|
66
|
+
});
|
|
62
67
|
}
|
|
63
68
|
}
|
|
64
69
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const TENANT_LIFECYCLE_BOOT_RULES: {
|
|
2
|
+
readonly tenantSubjectWithoutDestroyHook: {
|
|
3
|
+
readonly id: "tenant-lifecycle/tenant-subject-without-destroy-hook";
|
|
4
|
+
readonly summary: "An entity with tenant-subject fields has an EXT_TENANT_DATA destroy hook, so tenant destroy erases its data.";
|
|
5
|
+
readonly fix: 'Register r.useExtension(EXT_TENANT_DATA, "<entity>", { destroy }) or a documented no-op if crypto-shredding covers it.';
|
|
6
|
+
};
|
|
7
|
+
readonly destroyFunctionMissing: {
|
|
8
|
+
readonly id: "tenant-lifecycle/destroy-function-missing";
|
|
9
|
+
readonly summary: "A tenant data or tenant resource extension registration provides its destroy function, otherwise tenant destroy fails at that stage.";
|
|
10
|
+
readonly fix: "Provide destroy (EXT_TENANT_DATA) or destroyTenant (tenant resource extensions) in the registration options.";
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const TENANT_LIFECYCLE_BOOT_RULES = {
|
|
2
|
+
tenantSubjectWithoutDestroyHook: {
|
|
3
|
+
id: "tenant-lifecycle/tenant-subject-without-destroy-hook",
|
|
4
|
+
summary: "An entity with tenant-subject fields has an EXT_TENANT_DATA destroy hook, so tenant destroy erases its data.",
|
|
5
|
+
fix: 'Register r.useExtension(EXT_TENANT_DATA, "<entity>", { destroy }) or a documented no-op if crypto-shredding covers it.',
|
|
6
|
+
},
|
|
7
|
+
destroyFunctionMissing: {
|
|
8
|
+
id: "tenant-lifecycle/destroy-function-missing",
|
|
9
|
+
summary: "A tenant data or tenant resource extension registration provides its destroy function, otherwise tenant destroy fails at that stage.",
|
|
10
|
+
fix: "Provide destroy (EXT_TENANT_DATA) or destroyTenant (tenant resource extensions) in the registration options.",
|
|
11
|
+
},
|
|
12
|
+
};
|
|
@@ -28,3 +28,4 @@ export declare const TENANT_DESTRUCTION_STAGES: readonly ["external-resources",
|
|
|
28
28
|
export type TenantDestructionStageName = (typeof TENANT_DESTRUCTION_STAGES)[number];
|
|
29
29
|
export declare const DESTRUCTION_STAGE_TICK_BUDGET_MS = 30000;
|
|
30
30
|
export declare const DESTRUCTION_STAGE_MIN_SLICE_MS = 2000;
|
|
31
|
+
export declare const DESTRUCTION_STAGE_MAX_PENDING_MS: number;
|
|
@@ -42,3 +42,8 @@ export const DESTRUCTION_STAGE_TICK_BUDGET_MS = 30_000;
|
|
|
42
42
|
// without a guaranteed first batch processes nothing, and a no-progress stage
|
|
43
43
|
// counts as a failed attempt, which would abandon the pipeline under load.
|
|
44
44
|
export const DESTRUCTION_STAGE_MIN_SLICE_MS = 2_000;
|
|
45
|
+
// How long one stage attempt may report pending (a hook waiting on an external
|
|
46
|
+
// operation) after its stage-started event before the wait counts as a failed attempt.
|
|
47
|
+
// Sized for a queued app teardown (pod drain up to 330 s, database drop up to 180 s,
|
|
48
|
+
// two teardowns in parallel) with headroom for several apps per tenant.
|
|
49
|
+
export const DESTRUCTION_STAGE_MAX_PENDING_MS = 60 * 60_000;
|
|
@@ -12,6 +12,7 @@ export declare const tenantDestructionStartedSchema: z.ZodObject<{
|
|
|
12
12
|
export declare const tenantDestructionStageStartedSchema: z.ZodObject<{
|
|
13
13
|
stage: z.ZodString;
|
|
14
14
|
attempts: z.ZodNumber;
|
|
15
|
+
startedAt: z.ZodOptional<z.ZodString>;
|
|
15
16
|
}, z.core.$strip>;
|
|
16
17
|
export declare const tenantDestructionStageSucceededSchema: z.ZodObject<{
|
|
17
18
|
stage: z.ZodString;
|
|
@@ -21,6 +22,7 @@ export declare const tenantDestructionStageProgressedSchema: z.ZodObject<{
|
|
|
21
22
|
stage: z.ZodString;
|
|
22
23
|
attempts: z.ZodNumber;
|
|
23
24
|
processed: z.ZodNumber;
|
|
25
|
+
pending: z.ZodOptional<z.ZodBoolean>;
|
|
24
26
|
}, z.core.$strip>;
|
|
25
27
|
export declare const tenantDestructionStageFailedSchema: z.ZodObject<{
|
|
26
28
|
stage: z.ZodString;
|
|
@@ -12,6 +12,7 @@ export const tenantDestructionStartedSchema = z.object({
|
|
|
12
12
|
export const tenantDestructionStageStartedSchema = z.object({
|
|
13
13
|
stage: z.string().min(1),
|
|
14
14
|
attempts: z.number().int().positive(),
|
|
15
|
+
startedAt: z.string().datetime().optional(),
|
|
15
16
|
});
|
|
16
17
|
export const tenantDestructionStageSucceededSchema = z.object({
|
|
17
18
|
stage: z.string().min(1),
|
|
@@ -21,6 +22,7 @@ export const tenantDestructionStageProgressedSchema = z.object({
|
|
|
21
22
|
stage: z.string().min(1),
|
|
22
23
|
attempts: z.number().int().positive(),
|
|
23
24
|
processed: z.number().int().nonnegative(),
|
|
25
|
+
pending: z.boolean().optional(),
|
|
24
26
|
});
|
|
25
27
|
export const tenantDestructionStageFailedSchema = z.object({
|
|
26
28
|
stage: z.string().min(1),
|