@cosmicdrift/kumiko-bundled-features 0.404.1 → 0.406.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/auth-email-password/mail-notifications.d.ts +3 -3
- package/dist/auth-email-password/mail-notifications.js +10 -34
- package/dist/auth-email-password/web/default-topbar-actions.d.ts +6 -1
- package/dist/auth-email-password/web/default-topbar-actions.js +2 -2
- package/dist/auth-email-password/web/index.d.ts +2 -0
- package/dist/auth-email-password/web/index.js +1 -0
- package/dist/auth-email-password/web/invite-accept-screen.js +6 -41
- package/dist/auth-email-password/web/tenant-label.d.ts +2 -0
- package/dist/auth-email-password/web/tenant-label.js +10 -0
- package/dist/auth-email-password/web/tenant-menu-items.js +2 -7
- package/dist/auth-email-password/web/tenant-switcher.js +5 -12
- package/dist/auth-email-password/web/use-redirect-authed-from-login.d.ts +7 -0
- package/dist/auth-email-password/web/use-redirect-authed-from-login.js +30 -0
- package/dist/auth-foundation/feature.js +8 -21
- package/dist/auth-mfa/handlers/reencrypt.job.js +7 -15
- package/dist/auth-mfa/hmac-token-codec.d.ts +6 -1
- package/dist/auth-mfa/hmac-token-codec.js +8 -10
- package/dist/auth-mfa/mfa-challenge-token.js +2 -8
- package/dist/auth-mfa/mfa-preauth-setup-token.js +2 -8
- package/dist/auth-mfa/mfa-setup-token.d.ts +2 -8
- package/dist/auth-mfa/mfa-setup-token.js +8 -45
- package/dist/billing-foundation/consumer-protection/termination-revoke.js +3 -11
- package/dist/billing-foundation/feature.js +1 -5
- package/dist/billing-foundation/handlers/process-event.write.js +2 -6
- package/dist/billing-foundation/handlers/process-payment-event.write.js +2 -6
- package/dist/billing-foundation/index.d.ts +2 -0
- package/dist/billing-foundation/index.js +2 -0
- package/dist/billing-foundation/projection.js +12 -21
- package/dist/billing-foundation/provider-event-seen.d.ts +5 -0
- package/dist/billing-foundation/provider-event-seen.js +7 -0
- package/dist/billing-foundation/provider-shared.d.ts +11 -0
- package/dist/billing-foundation/provider-shared.js +44 -0
- package/dist/billing-foundation/tenant-destroy-hook.js +5 -4
- package/dist/channel-email/feature.js +1 -1
- package/dist/config/handlers/reencrypt.job.js +7 -15
- package/dist/delivery/delivery-service.js +2 -8
- package/dist/file-derivatives/feature.js +9 -21
- package/dist/file-foundation/feature.js +2 -6
- package/dist/files-tenant-data/hooks.js +1 -6
- package/dist/folders/feature.js +2 -9
- package/dist/folders/web/folder-manager.js +7 -26
- package/dist/folders/web/folder-section.js +5 -24
- package/dist/form-draft/handlers/save.write.d.ts +9 -0
- package/dist/form-draft/handlers/save.write.js +3 -7
- package/dist/inbound-mail-foundation/feature.js +2 -6
- package/dist/inbound-mail-foundation/oauth-state.js +5 -13
- package/dist/inbound-mail-foundation/tenant-destroy-hook.d.ts +1 -1
- package/dist/inbound-mail-foundation/tenant-destroy-hook.js +3 -18
- package/dist/jobs/handlers/tenant-failures.query.js +1 -15
- package/dist/jobs/handlers/tenant-runs.query.js +1 -14
- package/dist/jobs/job-run-logger.js +19 -23
- package/dist/jobs/parse-subject.d.ts +1 -0
- package/dist/jobs/parse-subject.js +15 -0
- package/dist/ledger/feature.js +2 -8
- package/dist/mail-foundation/feature.js +3 -7
- package/dist/managed-pages/render-page-body.js +4 -12
- package/dist/notes-history/feature.js +2 -9
- package/dist/personal-access-tokens/handlers/list.query.js +1 -9
- package/dist/personal-access-tokens/hash.js +2 -2
- package/dist/personal-access-tokens/parse-scope-names.d.ts +1 -0
- package/dist/personal-access-tokens/parse-scope-names.js +10 -0
- package/dist/personal-access-tokens/resolver.js +1 -9
- package/dist/renderer-foundation/feature.js +3 -14
- package/dist/secrets/handlers/rotate.job.js +7 -18
- package/dist/shared/collect-extension-options.d.ts +4 -0
- package/dist/shared/collect-extension-options.js +8 -0
- package/dist/shared/hmac-signature.d.ts +2 -0
- package/dist/shared/hmac-signature.js +10 -0
- package/dist/shared/index.d.ts +6 -0
- package/dist/shared/index.js +6 -0
- package/dist/shared/is-unique-constraint-failure.d.ts +2 -0
- package/dist/shared/is-unique-constraint-failure.js +7 -0
- package/dist/shared/mail-locale-templates.d.ts +12 -0
- package/dist/shared/mail-locale-templates.js +36 -0
- package/dist/shared/resolve-feature-access.d.ts +7 -0
- package/dist/shared/resolve-feature-access.js +8 -0
- package/dist/shared/signed-token.js +4 -14
- package/dist/shared/single-use-token-store.js +2 -2
- package/dist/shared/stream-tenant-derived-state.js +1 -5
- package/dist/shared/tenant-db-cache.d.ts +3 -0
- package/dist/shared/tenant-db-cache.js +14 -0
- package/dist/shared/web/status-banner.d.ts +15 -0
- package/dist/shared/web/status-banner.js +13 -0
- package/dist/shared/web/use-dispatched-writes.d.ts +8 -0
- package/dist/shared/web/use-dispatched-writes.js +29 -0
- package/dist/subscription-paddle/feature.js +2 -15
- package/dist/subscription-paddle/price-methods.d.ts +2 -5
- package/dist/subscription-paddle/price-methods.js +5 -26
- package/dist/subscription-paddle/runtime.d.ts +1 -1
- package/dist/subscription-paddle/runtime.js +3 -16
- package/dist/subscription-stripe/feature.js +2 -17
- package/dist/subscription-stripe/plugin-methods.d.ts +2 -5
- package/dist/subscription-stripe/plugin-methods.js +3 -18
- package/dist/subscription-stripe/runtime.js +3 -19
- package/dist/tags/feature.js +2 -9
- package/dist/tags/web/tag-manager.js +5 -24
- package/dist/tags/web/tag-section.js +3 -12
- package/dist/template-resolver/handlers/tenant-overrides.query.js +3 -9
- package/dist/tenant/handlers/decrypt-member-users.d.ts +10 -0
- package/dist/tenant/handlers/decrypt-member-users.js +17 -0
- package/dist/tenant/handlers/members.query.js +2 -17
- package/dist/tenant/handlers/team-list.query.js +4 -17
- package/dist/tenant-lifecycle/archive-and-delete-tenant-rows.d.ts +5 -0
- package/dist/tenant-lifecycle/archive-and-delete-tenant-rows.js +20 -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 +1 -1
- package/dist/tenant-lifecycle/index.d.ts +2 -1
- package/dist/tenant-lifecycle/index.js +2 -1
- package/dist/tenant-lifecycle/run-tenant-destroy.d.ts +2 -0
- package/dist/tenant-lifecycle/run-tenant-destroy.js +42 -7
- package/dist/tenant-lifecycle/stages.d.ts +1 -0
- package/dist/tenant-lifecycle/stages.js +4 -1
- package/dist/tier-engine/feature.js +1 -1
- package/dist/user-data-rights/build-hook-db.d.ts +11 -0
- package/dist/user-data-rights/build-hook-db.js +22 -0
- package/dist/user-data-rights/handlers/request-export.write.js +2 -12
- package/dist/user-data-rights/mail-notifications.d.ts +3 -3
- package/dist/user-data-rights/mail-notifications.js +10 -34
- package/dist/user-data-rights/run-forget-cleanup.d.ts +1 -1
- package/dist/user-data-rights/run-forget-cleanup.js +2 -21
- package/dist/user-data-rights/run-user-export.d.ts +1 -1
- package/dist/user-data-rights/run-user-export.js +2 -21
- package/dist/user-data-rights/token-helpers.js +2 -14
- package/dist/user-data-rights/web/privacy-center-screen.js +1 -11
- package/dist/user-profile/web/profile-screen.js +1 -11
- package/package.json +20 -20
- package/src/auth-email-password/changes.json +6 -0
- package/src/auth-mfa/changes.json +6 -0
- package/src/billing-foundation/changes.json +6 -0
- package/src/shared/changes.json +6 -0
- package/src/tenant-lifecycle/changes.json +18 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type MemberUserRow = {
|
|
2
|
+
readonly id: unknown;
|
|
3
|
+
readonly email?: unknown;
|
|
4
|
+
readonly displayName?: unknown;
|
|
5
|
+
};
|
|
6
|
+
export declare const KMS_POOL_CONCURRENCY = 4;
|
|
7
|
+
export declare function decryptMemberUsers(users: readonly MemberUserRow[], reason: string): Promise<Map<string, {
|
|
8
|
+
readonly email: string | null;
|
|
9
|
+
readonly displayName: string | null;
|
|
10
|
+
}>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { decryptStoredPii, mapWithConcurrency } from "../../shared/index.js";
|
|
2
|
+
// Bounded, not Promise.all/sequential: each decrypt hits the KMS adapter's
|
|
3
|
+
// own small dedicated pool (PgKmsAdapter default max: 4). Promise.all fires
|
|
4
|
+
// one call per user unbounded and exhausts the pool once membership counts
|
|
5
|
+
// exceed a handful, surfacing as "the connection was closed"; a strict
|
|
6
|
+
// sequential loop caps concurrency at 1 and leaves 3 pool slots idle.
|
|
7
|
+
export const KMS_POOL_CONCURRENCY = 4;
|
|
8
|
+
export async function decryptMemberUsers(users, reason) {
|
|
9
|
+
const decrypted = await mapWithConcurrency(users, KMS_POOL_CONCURRENCY, async (user) => {
|
|
10
|
+
const email = typeof user.email === "string" ? await decryptStoredPii(user.email, "email", reason) : null;
|
|
11
|
+
const displayName = typeof user.displayName === "string"
|
|
12
|
+
? await decryptStoredPii(user.displayName, "displayName", reason)
|
|
13
|
+
: null;
|
|
14
|
+
return { userId: String(user.id), email, displayName };
|
|
15
|
+
});
|
|
16
|
+
return new Map(decrypted.map((d) => [d.userId, d]));
|
|
17
|
+
}
|
|
@@ -3,15 +3,9 @@ import { access, defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine
|
|
|
3
3
|
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
4
4
|
import { parseRoles } from "@cosmicdrift/kumiko-framework/utils";
|
|
5
5
|
import * as z from "zod";
|
|
6
|
-
import { decryptStoredPii, mapWithConcurrency } from "../../shared/index.js";
|
|
7
6
|
import { userTable } from "../../user/index.js";
|
|
8
7
|
import { tenantMembershipsTable } from "../membership-table.js";
|
|
9
|
-
|
|
10
|
-
// own small dedicated pool (PgKmsAdapter default max: 4). Promise.all fires
|
|
11
|
-
// one call per user unbounded and exhausts the pool once membership counts
|
|
12
|
-
// exceed a handful, surfacing as "the connection was closed"; a strict
|
|
13
|
-
// sequential loop caps concurrency at 1 and leaves 3 pool slots idle.
|
|
14
|
-
const KMS_POOL_CONCURRENCY = 4;
|
|
8
|
+
import { decryptMemberUsers } from "./decrypt-member-users.js";
|
|
15
9
|
export const membersQuery = defineQueryHandler({
|
|
16
10
|
name: "members",
|
|
17
11
|
schema: z.object({
|
|
@@ -37,16 +31,7 @@ export const membersQuery = defineQueryHandler({
|
|
|
37
31
|
const userIds = [...new Set(rows.map((row) => row["userId"]))];
|
|
38
32
|
const users = userIds.length > 0 ? await selectMany(db, userTable, { id: userIds }) : [];
|
|
39
33
|
const userById = new Map(users.map((u) => [String(u.id), u]));
|
|
40
|
-
const
|
|
41
|
-
const email = typeof user.email === "string"
|
|
42
|
-
? await decryptStoredPii(user.email, "email", "tenant:members")
|
|
43
|
-
: null;
|
|
44
|
-
const displayName = typeof user.displayName === "string"
|
|
45
|
-
? await decryptStoredPii(user.displayName, "displayName", "tenant:members")
|
|
46
|
-
: null;
|
|
47
|
-
return { userId: String(user.id), email, displayName };
|
|
48
|
-
});
|
|
49
|
-
const decryptedByUserId = new Map(decrypted.map((d) => [d.userId, d]));
|
|
34
|
+
const decryptedByUserId = await decryptMemberUsers(users, "tenant:members");
|
|
50
35
|
return rows.map((row) => {
|
|
51
36
|
const user = userById.get(String(row["userId"]));
|
|
52
37
|
const decrypted = user ? decryptedByUserId.get(String(user.id)) : undefined;
|
|
@@ -10,7 +10,7 @@ import { decryptStoredPii, mapWithConcurrency } from "../../shared/index.js";
|
|
|
10
10
|
import { userTable } from "../../user/index.js";
|
|
11
11
|
import { INVITATION_STATUS, tenantInvitationsTable } from "../invitation-table.js";
|
|
12
12
|
import { tenantMembershipsTable } from "../membership-table.js";
|
|
13
|
-
|
|
13
|
+
import { decryptMemberUsers, KMS_POOL_CONCURRENCY, } from "./decrypt-member-users.js";
|
|
14
14
|
// The /members screen exposes one column per field above under the SAME
|
|
15
15
|
// name — unlike delivery-log there is no display-alias to map, `sort` on
|
|
16
16
|
// the wire already names a TeamRow field directly.
|
|
@@ -86,11 +86,7 @@ export const teamListQuery = definePagedQueryHandler({
|
|
|
86
86
|
const tenantId = query.user.tenantId;
|
|
87
87
|
const membershipRows = await selectMany(db, tenantMembershipsTable, { tenantId });
|
|
88
88
|
const userIds = [...new Set(membershipRows.map((row) => String(row["userId"])))];
|
|
89
|
-
const users = userIds.length > 0
|
|
90
|
-
? await selectMany(db, userTable, {
|
|
91
|
-
id: userIds,
|
|
92
|
-
})
|
|
93
|
-
: [];
|
|
89
|
+
const users = userIds.length > 0 ? await selectMany(db, userTable, { id: userIds }) : [];
|
|
94
90
|
const lastSeenByUserId = new Map();
|
|
95
91
|
if (userIds.length > 0) {
|
|
96
92
|
try {
|
|
@@ -115,19 +111,10 @@ export const teamListQuery = definePagedQueryHandler({
|
|
|
115
111
|
}
|
|
116
112
|
}
|
|
117
113
|
// Bounded, not Promise.all/sequential-per-item: shares the KMS
|
|
118
|
-
// adapter's small dedicated pool (max 4, see
|
|
114
|
+
// adapter's small dedicated pool (max 4, see decrypt-member-users.ts) with the
|
|
119
115
|
// invitations decrypt below — the two passes run one after the other
|
|
120
116
|
// (await, not Promise.all), so combined concurrency never exceeds 4.
|
|
121
|
-
const
|
|
122
|
-
const email = typeof user.email === "string"
|
|
123
|
-
? await decryptStoredPii(user.email, "email", "tenant:team-list")
|
|
124
|
-
: null;
|
|
125
|
-
const displayName = typeof user.displayName === "string"
|
|
126
|
-
? await decryptStoredPii(user.displayName, "displayName", "tenant:team-list")
|
|
127
|
-
: null;
|
|
128
|
-
return { userId: String(user.id), email, displayName };
|
|
129
|
-
});
|
|
130
|
-
const decryptedByUserId = new Map(decryptedUsers.map((d) => [d.userId, d]));
|
|
117
|
+
const decryptedByUserId = await decryptMemberUsers(users, "tenant:team-list");
|
|
131
118
|
const memberRows = membershipRows.map((row) => {
|
|
132
119
|
const userId = String(row["userId"]);
|
|
133
120
|
const decrypted = decryptedByUserId.get(userId);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { EntityTableMeta } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import { type TenantDataHookCtx } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
export declare const TENANT_DESTROY_ARCHIVED_BY = "tenant-lifecycle:destroy";
|
|
4
|
+
export declare const TENANT_DESTROY_ARCHIVE_REASON = "tenant_destroy";
|
|
5
|
+
export declare function archiveAndDeleteTenantRows(ctx: TenantDataHookCtx, table: EntityTableMeta, aggregateType: string, escapeHatchReason: string): Promise<readonly string[]>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { declareEscapeHatch } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { archiveStream } from "@cosmicdrift/kumiko-framework/event-store";
|
|
3
|
+
export const TENANT_DESTROY_ARCHIVED_BY = "tenant-lifecycle:destroy";
|
|
4
|
+
export const TENANT_DESTROY_ARCHIVE_REASON = "tenant_destroy";
|
|
5
|
+
// Archiving first means a later projection rebuild cannot resurrect the deleted rows.
|
|
6
|
+
export async function archiveAndDeleteTenantRows(ctx, table, aggregateType, escapeHatchReason) {
|
|
7
|
+
declareEscapeHatch({ reason: escapeHatchReason });
|
|
8
|
+
const rows = await ctx.db.selectMany(table, { tenantId: ctx.tenantId });
|
|
9
|
+
for (const row of rows) {
|
|
10
|
+
await archiveStream(ctx.db.unsafeRaw(), {
|
|
11
|
+
tenantId: ctx.tenantId,
|
|
12
|
+
aggregateId: row.id,
|
|
13
|
+
aggregateType,
|
|
14
|
+
archivedBy: TENANT_DESTROY_ARCHIVED_BY,
|
|
15
|
+
reason: TENANT_DESTROY_ARCHIVE_REASON,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
await ctx.db.deleteMany(table, { tenantId: ctx.tenantId });
|
|
19
|
+
return rows.map((row) => row.id);
|
|
20
|
+
}
|
|
@@ -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),
|
|
@@ -67,7 +67,7 @@ export function createTenantLifecycleFeature() {
|
|
|
67
67
|
const RUN_TENANT_DESTRUCTION_REASON = "sweeps tenant destruction across every tenant";
|
|
68
68
|
r.job({
|
|
69
69
|
name: "run-tenant-destruction",
|
|
70
|
-
trigger: { cron: "0 * * * * *" },
|
|
70
|
+
trigger: { cron: "0 * * * * *", wakesSleepingApp: false },
|
|
71
71
|
concurrency: "skip",
|
|
72
72
|
escapeHatch: { reason: RUN_TENANT_DESTRUCTION_REASON },
|
|
73
73
|
handler: async (_payload, ctx) => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { archiveAndDeleteTenantRows, TENANT_DESTROY_ARCHIVE_REASON, TENANT_DESTROY_ARCHIVED_BY, } from "./archive-and-delete-tenant-rows.ts";
|
|
2
|
+
export { TENANT_DESTRUCTION_STAGE_FAILED_EVENT_QN, TENANT_DESTRUCTION_STAGE_PROGRESSED_EVENT_QN, TENANT_DESTRUCTION_STAGES, TENANT_LIFECYCLE_FEATURE, TenantLifecycleHandlers, } from "./constants.ts";
|
|
2
3
|
export { createTenantLifecycleFeature } from "./feature.ts";
|
|
3
4
|
export { resolveTenantLifecycleGate } from "./run-tenant-destroy.ts";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { archiveAndDeleteTenantRows, TENANT_DESTROY_ARCHIVE_REASON, TENANT_DESTROY_ARCHIVED_BY, } from "./archive-and-delete-tenant-rows.js";
|
|
2
|
+
export { TENANT_DESTRUCTION_STAGE_FAILED_EVENT_QN, TENANT_DESTRUCTION_STAGE_PROGRESSED_EVENT_QN, TENANT_DESTRUCTION_STAGES, TENANT_LIFECYCLE_FEATURE, TenantLifecycleHandlers, } from "./constants.js";
|
|
2
3
|
export { createTenantLifecycleFeature } from "./feature.js";
|
|
3
4
|
export { resolveTenantLifecycleGate } from "./run-tenant-destroy.js";
|
|
@@ -9,6 +9,7 @@ type StageTickResult = {
|
|
|
9
9
|
readonly error?: string;
|
|
10
10
|
readonly halted?: boolean;
|
|
11
11
|
readonly progressed?: boolean;
|
|
12
|
+
readonly pending?: boolean;
|
|
12
13
|
};
|
|
13
14
|
export declare function runNextDestructionStage(args: {
|
|
14
15
|
readonly db: DbRunner;
|
|
@@ -21,6 +22,7 @@ export declare function runNextDestructionStage(args: {
|
|
|
21
22
|
readonly escapeHatchAuditLog?: Logger;
|
|
22
23
|
readonly actor?: string;
|
|
23
24
|
readonly deadlineAt?: number;
|
|
25
|
+
readonly now?: Temporal.Instant;
|
|
24
26
|
}): Promise<StageTickResult>;
|
|
25
27
|
export declare function hasTenantDestructionWork(reads: Pick<TenantDb, "count">, now: Temporal.Instant): Promise<boolean>;
|
|
26
28
|
/** Cron entry: start destruction for tenants past grace, then advance stages. */
|
|
@@ -3,7 +3,7 @@ import { createSystemUser, SYSTEM_TENANT_ID, } from "@cosmicdrift/kumiko-framewo
|
|
|
3
3
|
import { append, loadAggregate, VersionConflictError, } from "@cosmicdrift/kumiko-framework/event-store";
|
|
4
4
|
import { getTemporal } from "@cosmicdrift/kumiko-framework/time";
|
|
5
5
|
import { tenantEntity, tenantTable } from "../tenant/index.js";
|
|
6
|
-
import { DESTRUCTION_STAGE_MIN_SLICE_MS, DESTRUCTION_STAGE_TICK_BUDGET_MS, TENANT_AGGREGATE_TYPE, TENANT_DESTRUCTION_COMPLETED_EVENT_QN, TENANT_DESTRUCTION_FAILED_EVENT_QN, TENANT_DESTRUCTION_STAGE_ABANDONED_EVENT_SHORT, TENANT_DESTRUCTION_STAGE_FAILED_EVENT_SHORT, TENANT_DESTRUCTION_STAGE_PROGRESSED_EVENT_SHORT, TENANT_DESTRUCTION_STAGE_STARTED_EVENT_SHORT, TENANT_DESTRUCTION_STAGE_SUCCEEDED_EVENT_SHORT, TENANT_DESTRUCTION_STARTED_EVENT_SHORT, } from "./constants.js";
|
|
6
|
+
import { DESTRUCTION_STAGE_MAX_PENDING_MS, DESTRUCTION_STAGE_MIN_SLICE_MS, DESTRUCTION_STAGE_TICK_BUDGET_MS, TENANT_AGGREGATE_TYPE, TENANT_DESTRUCTION_COMPLETED_EVENT_QN, TENANT_DESTRUCTION_FAILED_EVENT_QN, TENANT_DESTRUCTION_STAGE_ABANDONED_EVENT_SHORT, TENANT_DESTRUCTION_STAGE_FAILED_EVENT_SHORT, TENANT_DESTRUCTION_STAGE_PROGRESSED_EVENT_SHORT, TENANT_DESTRUCTION_STAGE_STARTED_EVENT_SHORT, TENANT_DESTRUCTION_STAGE_SUCCEEDED_EVENT_SHORT, TENANT_DESTRUCTION_STARTED_EVENT_SHORT, } from "./constants.js";
|
|
7
7
|
import { invalidateTenantLifecycleGate, TEARDOWN_GATE_SETTLE_MS } from "./lifecycle-gate.js";
|
|
8
8
|
import { isDestructionPipelineComplete, pickNextStage, } from "./stages.js";
|
|
9
9
|
const tenantCrud = createEventStoreExecutor(tenantTable, tenantEntity, { entityName: "tenant" });
|
|
@@ -44,6 +44,20 @@ function isStageContinuation(events, stageName) {
|
|
|
44
44
|
const lastStageEvent = events.findLast((event) => stageEventTypes.has(event.type) && event.payload["stage"] === stageName);
|
|
45
45
|
return lastStageEvent?.type === qualified(TENANT_DESTRUCTION_STAGE_PROGRESSED_EVENT_SHORT);
|
|
46
46
|
}
|
|
47
|
+
// Stage-started events written before startedAt existed fall back to their append time.
|
|
48
|
+
function currentAttemptStartedAt(events, stageName) {
|
|
49
|
+
const started = events.findLast((event) => event.type === qualified(TENANT_DESTRUCTION_STAGE_STARTED_EVENT_SHORT) &&
|
|
50
|
+
event.payload["stage"] === stageName);
|
|
51
|
+
if (!started)
|
|
52
|
+
return undefined;
|
|
53
|
+
const startedAt = started.payload["startedAt"];
|
|
54
|
+
return typeof startedAt === "string" ? getTemporal().Instant.from(startedAt) : started.createdAt;
|
|
55
|
+
}
|
|
56
|
+
function isPendingWindowOpen(events, stageName, now) {
|
|
57
|
+
const startedAt = currentAttemptStartedAt(events, stageName);
|
|
58
|
+
return (startedAt !== undefined &&
|
|
59
|
+
now.epochMilliseconds - startedAt.epochMilliseconds <= DESTRUCTION_STAGE_MAX_PENDING_MS);
|
|
60
|
+
}
|
|
47
61
|
function lastEventVersion(events) {
|
|
48
62
|
const last = events.at(-1);
|
|
49
63
|
return last?.version ?? 0;
|
|
@@ -144,7 +158,28 @@ async function recordFailedStageAttempt(args) {
|
|
|
144
158
|
await appendTenantStageEvent(args.db, args.tenantId, qualified(TENANT_DESTRUCTION_STAGE_FAILED_EVENT_SHORT), { stage: args.stage.name, attempts: args.attempt, error: args.error }, args.version);
|
|
145
159
|
return { done: false, error: args.error };
|
|
146
160
|
}
|
|
161
|
+
// A tick that neither finishes nor processes anything would otherwise loop forever,
|
|
162
|
+
// because progressed events do not count as attempts. A pending tick still appends a
|
|
163
|
+
// progressed event: without it the next tick would open a new stage-started and the
|
|
164
|
+
// pending window would never close.
|
|
165
|
+
async function recordIdleStageTick(args) {
|
|
166
|
+
if (args.pending && isPendingWindowOpen(args.events, args.stage.name, args.now)) {
|
|
167
|
+
await appendTenantStageEvent(args.db, args.tenantId, qualified(TENANT_DESTRUCTION_STAGE_PROGRESSED_EVENT_SHORT), { stage: args.stage.name, attempts: args.attempt, processed: 0, pending: true }, lastEventVersion(args.events));
|
|
168
|
+
return { done: false, pending: true };
|
|
169
|
+
}
|
|
170
|
+
return await recordFailedStageAttempt({
|
|
171
|
+
db: args.db,
|
|
172
|
+
tenantId: args.tenantId,
|
|
173
|
+
stage: args.stage,
|
|
174
|
+
attempt: args.attempt,
|
|
175
|
+
error: args.pending
|
|
176
|
+
? `stage "${args.stage.name}" still pending after ${DESTRUCTION_STAGE_MAX_PENDING_MS / 60_000} min`
|
|
177
|
+
: `stage "${args.stage.name}" made no progress`,
|
|
178
|
+
version: lastEventVersion(args.events),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
147
181
|
export async function runNextDestructionStage(args) {
|
|
182
|
+
const now = args.now ?? getTemporal().Now.instant();
|
|
148
183
|
const events = await loadAggregate(args.db, args.tenantId, SYSTEM_TENANT_ID);
|
|
149
184
|
const { completed, abandoned, attemptsByStage } = replayStageState(events);
|
|
150
185
|
if (abandoned.size > 0) {
|
|
@@ -171,7 +206,7 @@ export async function runNextDestructionStage(args) {
|
|
|
171
206
|
};
|
|
172
207
|
let version = lastEventVersion(events);
|
|
173
208
|
if (!isStageContinuation(events, next.name)) {
|
|
174
|
-
version = await appendTenantStageEventIdempotent(args.db, args.tenantId, qualified(TENANT_DESTRUCTION_STAGE_STARTED_EVENT_SHORT), { stage: next.name, attempts: attempt }, version, stageOutcomeRecorded(events, next.name, TENANT_DESTRUCTION_STAGE_SUCCEEDED_EVENT_SHORT));
|
|
209
|
+
version = await appendTenantStageEventIdempotent(args.db, args.tenantId, qualified(TENANT_DESTRUCTION_STAGE_STARTED_EVENT_SHORT), { stage: next.name, attempts: attempt, startedAt: now.toString() }, version, stageOutcomeRecorded(events, next.name, TENANT_DESTRUCTION_STAGE_SUCCEEDED_EVENT_SHORT));
|
|
175
210
|
}
|
|
176
211
|
try {
|
|
177
212
|
const outcome = await next.run(ctx);
|
|
@@ -180,16 +215,15 @@ export async function runNextDestructionStage(args) {
|
|
|
180
215
|
// the version fresh instead of trusting the pre-run `version`, or this
|
|
181
216
|
// append throws VersionConflictError on every stage whose run() writes.
|
|
182
217
|
const eventsAfterRun = await loadAggregate(args.db, args.tenantId, SYSTEM_TENANT_ID);
|
|
183
|
-
// A tick that neither finishes nor processes anything would otherwise loop
|
|
184
|
-
// forever, because progressed events do not count as attempts.
|
|
185
218
|
if (!outcome.done && outcome.processed === 0) {
|
|
186
|
-
return await
|
|
219
|
+
return await recordIdleStageTick({
|
|
187
220
|
db: args.db,
|
|
188
221
|
tenantId: args.tenantId,
|
|
189
222
|
stage: next,
|
|
190
223
|
attempt,
|
|
191
|
-
|
|
192
|
-
|
|
224
|
+
pending: outcome.pending === true,
|
|
225
|
+
events: eventsAfterRun,
|
|
226
|
+
now,
|
|
193
227
|
});
|
|
194
228
|
}
|
|
195
229
|
if (!outcome.done) {
|
|
@@ -267,6 +301,7 @@ export async function runTenantDestructionSweep(args) {
|
|
|
267
301
|
try {
|
|
268
302
|
const result = await runNextDestructionStage({
|
|
269
303
|
deadlineAt: tenantDeadlineAt,
|
|
304
|
+
now,
|
|
270
305
|
db: args.db,
|
|
271
306
|
registry: args.registry,
|
|
272
307
|
tenantId: row.id,
|
|
@@ -17,14 +17,17 @@ const tenantMembershipCrud = createEventStoreExecutor(tenantMembershipsTable, te
|
|
|
17
17
|
// hooks time out with nothing processed until it finishes.
|
|
18
18
|
function newOutcomeAccumulator() {
|
|
19
19
|
let allDone = true;
|
|
20
|
+
let pending = false;
|
|
20
21
|
let processed = 0;
|
|
21
22
|
return {
|
|
22
23
|
add: (result) => {
|
|
23
24
|
if (result?.done === false)
|
|
24
25
|
allDone = false;
|
|
26
|
+
if (result?.done === false && result.pending === true)
|
|
27
|
+
pending = true;
|
|
25
28
|
processed += result?.processed ?? 0;
|
|
26
29
|
},
|
|
27
|
-
outcome: () => ({ done: allDone, processed }),
|
|
30
|
+
outcome: () => ({ done: allDone, processed, pending }),
|
|
28
31
|
};
|
|
29
32
|
}
|
|
30
33
|
async function runExtensionDestroyHooks(registry, extensionName, ctx) {
|
|
@@ -380,7 +380,7 @@ export function createTierEngineFeature(opts = {}) {
|
|
|
380
380
|
// point AND registers itself as the default plugin. Other features could
|
|
381
381
|
// register there later (e.g. a future toggle-only resolver), but only one
|
|
382
382
|
// plugin wins — see the "single-plugin" comment on findTierResolverUsage.
|
|
383
|
-
r.extendsRegistrar(TENANT_TIER_RESOLVER_EXT, {
|
|
383
|
+
r.extendsRegistrar(TENANT_TIER_RESOLVER_EXT, {});
|
|
384
384
|
// Plugin-registration: framework's runDevApp/runProdApp picks this up
|
|
385
385
|
// post-stack-setup, calls build(deps), wires effectiveFeatures.
|
|
386
386
|
const plugin = {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type DbRunner } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import { type EscapeHatchAuditSink, type TenantId } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
import { type Logger } from "@cosmicdrift/kumiko-framework/logging";
|
|
4
|
+
export declare function buildHookDb(db: DbRunner, tenantId: TenantId, entry: {
|
|
5
|
+
readonly entityName: string;
|
|
6
|
+
readonly escapeHatchReason: string | undefined;
|
|
7
|
+
}, args: {
|
|
8
|
+
readonly escapeHatchAuditSink?: EscapeHatchAuditSink;
|
|
9
|
+
readonly escapeHatchAuditLog?: Logger;
|
|
10
|
+
readonly actor?: string;
|
|
11
|
+
}): import("@cosmicdrift/kumiko-types/tenant-db-types").TenantDb;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createTenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import { EXT_USER_DATA, } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
|
|
4
|
+
import { createEscapeHatchReporter, UNATTRIBUTED_ACTOR, } from "@cosmicdrift/kumiko-framework/pipeline";
|
|
5
|
+
export function buildHookDb(db, tenantId, entry, args) {
|
|
6
|
+
const report = createEscapeHatchReporter({
|
|
7
|
+
handler: `${EXT_USER_DATA}:${entry.entityName}`,
|
|
8
|
+
tenantId,
|
|
9
|
+
actor: args.actor ?? UNATTRIBUTED_ACTOR,
|
|
10
|
+
sink: args.escapeHatchAuditSink,
|
|
11
|
+
log: args.escapeHatchAuditLog ?? createFallbackLogger("user-data-rights"),
|
|
12
|
+
});
|
|
13
|
+
return createTenantDb({
|
|
14
|
+
db,
|
|
15
|
+
tenantId,
|
|
16
|
+
mode: "tenant",
|
|
17
|
+
grants: {
|
|
18
|
+
unsafeRaw: entry.escapeHatchReason !== undefined ? { reason: entry.escapeHatchReason } : undefined,
|
|
19
|
+
report,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -24,22 +24,12 @@ import { createEventStoreExecutor, fetchOne } from "@cosmicdrift/kumiko-framewor
|
|
|
24
24
|
import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
25
25
|
import { getTemporal } from "@cosmicdrift/kumiko-framework/time";
|
|
26
26
|
import * as z from "zod";
|
|
27
|
+
import { isUniqueConstraintFailure } from "../../shared/index.js";
|
|
27
28
|
import { ACTIVE_JOB_CONSTRAINT, EXPORT_JOB_STATUS, exportJobEntity, exportJobsTable, } from "../schema/export-job.js";
|
|
28
29
|
const crud = createEventStoreExecutor(exportJobsTable, exportJobEntity, {
|
|
29
30
|
entityName: "export-job",
|
|
30
31
|
});
|
|
31
32
|
const REQUEST_EXPORT_REASON = "export jobs are keyed by userId across all of the user's tenant memberships, not the caller's current tenant";
|
|
32
|
-
/**
|
|
33
|
-
* `createEventStoreExecutor.create` catches 23505 internally and returns
|
|
34
|
-
* `WriteFailure(UniqueViolationError)` rather than throwing. Check the
|
|
35
|
-
* failure code and constraintName to distinguish the app-side and race
|
|
36
|
-
* paths; propagate other failures (validation, version conflicts, ...)
|
|
37
|
-
* unchanged.
|
|
38
|
-
*/
|
|
39
|
-
function isActiveJobConflict(failure) {
|
|
40
|
-
const error = failure.error; // @cast-boundary error-details
|
|
41
|
-
return (error.code === "unique_violation" && error.details?.constraintName === ACTIVE_JOB_CONSTRAINT);
|
|
42
|
-
}
|
|
43
33
|
export const requestExportWrite = defineWriteHandler({
|
|
44
34
|
name: "request-export",
|
|
45
35
|
schema: z.object({}),
|
|
@@ -89,7 +79,7 @@ export const requestExportWrite = defineWriteHandler({
|
|
|
89
79
|
// crud.create, causing UniqueViolationError for our constraint. Re-fetch
|
|
90
80
|
// and return the existing job with isExisting=true. Propagate other
|
|
91
81
|
// failures (validation, version conflicts, ...) unchanged.
|
|
92
|
-
if (
|
|
82
|
+
if (isUniqueConstraintFailure(result, ACTIVE_JOB_CONSTRAINT)) {
|
|
93
83
|
const winner = await findActiveJob(exportJobRunner, userId);
|
|
94
84
|
if (!winner) {
|
|
95
85
|
// This should be impossible: a constraint violation without an existing
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FeatureRegistrar, type
|
|
1
|
+
import { type FeatureRegistrar, type TemplateVariables } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
declare const ALL_GDPR_MAIL_KINDS: readonly ["exportReady", "exportFailed", "deletionRequested", "deletionExecuted"];
|
|
3
3
|
export type GdprMailKind = (typeof ALL_GDPR_MAIL_KINDS)[number];
|
|
4
4
|
export declare const GDPR_MAIL_KINDS: Readonly<Record<GdprMailKind, {
|
|
@@ -6,8 +6,8 @@ export declare const GDPR_MAIL_KINDS: Readonly<Record<GdprMailKind, {
|
|
|
6
6
|
readonly translationKey: string;
|
|
7
7
|
}>>;
|
|
8
8
|
export declare const GdprMailNotificationTypes: Readonly<Record<GdprMailKind, string>>;
|
|
9
|
-
export declare
|
|
9
|
+
export declare const gdprMailTemplateLocale: (notificationType: string, requestedLocale: string) => string;
|
|
10
10
|
export declare const GDPR_MAIL_VARIABLES: Readonly<Record<GdprMailKind, TemplateVariables>>;
|
|
11
|
-
export declare
|
|
11
|
+
export declare const gdprMailLocalizedTemplate: (kind: "deletionExecuted" | "deletionRequested" | "exportFailed" | "exportReady") => () => import("@cosmicdrift/kumiko-types/config").NotificationLocalizedTemplate;
|
|
12
12
|
export declare function registerGdprMails(r: FeatureRegistrar): void;
|
|
13
13
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { QnTypes, qn, templateVariable, } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
-
import {
|
|
2
|
+
import { mailT } from "@cosmicdrift/kumiko-framework/i18n";
|
|
3
3
|
import { escapeHtml } from "@cosmicdrift/kumiko-renderer/headless";
|
|
4
|
-
import { mailParagraph } from "../shared/index.js";
|
|
4
|
+
import { createMailLocaleTemplates, mailParagraph } from "../shared/index.js";
|
|
5
5
|
import { USER_DATA_RIGHTS_FEATURE } from "./web/constants.js";
|
|
6
6
|
const ALL_GDPR_MAIL_KINDS = [
|
|
7
7
|
"exportReady",
|
|
@@ -27,15 +27,13 @@ function gdprMailType(kind) {
|
|
|
27
27
|
function subjectKey(kind) {
|
|
28
28
|
return `gdpr.mail.${GDPR_MAIL_KINDS[kind].translationKey}.subject`;
|
|
29
29
|
}
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return key !== undefined && hasMailTranslationKey(locale, key) ? locale : "en";
|
|
38
|
-
}
|
|
30
|
+
const mailLocaleTemplates = createMailLocaleTemplates({
|
|
31
|
+
kinds: ALL_GDPR_MAIL_KINDS,
|
|
32
|
+
notificationTypes: GdprMailNotificationTypes,
|
|
33
|
+
subjectKey,
|
|
34
|
+
bodyFor: (kind, locale) => mailBody(kind, locale),
|
|
35
|
+
});
|
|
36
|
+
export const gdprMailTemplateLocale = mailLocaleTemplates.templateLocale;
|
|
39
37
|
const appName = () => templateVariable.text({ required: true });
|
|
40
38
|
export const GDPR_MAIL_VARIABLES = {
|
|
41
39
|
exportReady: {
|
|
@@ -85,29 +83,7 @@ function mailBody(kind, locale) {
|
|
|
85
83
|
return [greeting(locale), paragraph(kind, locale, "intro")].join("");
|
|
86
84
|
}
|
|
87
85
|
}
|
|
88
|
-
|
|
89
|
-
// registered its mail translations. English always ships; another locale only
|
|
90
|
-
// gets a template when it has its own subject, so a missing translation never
|
|
91
|
-
// silently becomes an English mail in that locale's slot.
|
|
92
|
-
export function gdprMailLocalizedTemplate(kind) {
|
|
93
|
-
const kindSubjectKey = subjectKey(kind);
|
|
94
|
-
return () => {
|
|
95
|
-
const locales = [
|
|
96
|
-
"en",
|
|
97
|
-
...listMailLocales().filter((locale) => locale !== "en" && hasMailTranslationKey(locale, kindSubjectKey)),
|
|
98
|
-
];
|
|
99
|
-
return Object.fromEntries(locales.map((locale) => [
|
|
100
|
-
locale,
|
|
101
|
-
{
|
|
102
|
-
body: mailBody(kind, locale),
|
|
103
|
-
meta: {
|
|
104
|
-
subject: mailT(locale, kindSubjectKey, { app: "{{appName}}" }),
|
|
105
|
-
category: "transactional",
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
]));
|
|
109
|
-
};
|
|
110
|
-
}
|
|
86
|
+
export const gdprMailLocalizedTemplate = mailLocaleTemplates.localizedTemplate;
|
|
111
87
|
export function registerGdprMails(r) {
|
|
112
88
|
for (const kind of ALL_GDPR_MAIL_KINDS) {
|
|
113
89
|
r.notification(GDPR_MAIL_KINDS[kind].name, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Logger } from "@cosmicdrift/kumiko-framework/logging";
|
|
2
2
|
import { type KmsAdapter } from "@cosmicdrift/kumiko-framework/crypto";
|
|
3
3
|
import { type DbRunner } from "@cosmicdrift/kumiko-framework/db";
|
|
4
4
|
import { type EscapeHatchAuditSink, type Registry, type TenantId, type TenantUserModel, type UserDataDeleteStrategy, type UserDataStorageProvider } from "@cosmicdrift/kumiko-framework/engine";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
|
|
2
1
|
// Forget-cleanup runner — pure-function pipeline.
|
|
3
2
|
//
|
|
4
3
|
// After the grace period, this runner processes users in DeletionRequested
|
|
@@ -28,36 +27,18 @@ import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
|
|
|
28
27
|
// collected and returned for operator visibility, while a user with failed
|
|
29
28
|
// hooks remains in DeletionRequested for automatic retry.
|
|
30
29
|
import { configuredPiiSubjectKms, subjectIdToKey, } from "@cosmicdrift/kumiko-framework/crypto";
|
|
31
|
-
import {
|
|
30
|
+
import { entityEventName, executeRawQuery, fetchOne, nullBlindIndexesForSubject, selectMany, WritePurposes, } from "@cosmicdrift/kumiko-framework/db";
|
|
32
31
|
import { deleteStoredFileAndDerivatives } from "@cosmicdrift/kumiko-framework/derivatives";
|
|
33
32
|
import { EXT_USER_DATA, EXT_USER_DATA_ORDER, extensionUsageEscapeHatchReason, } from "@cosmicdrift/kumiko-framework/engine";
|
|
34
33
|
import { runInSystemRowLevelSecurityScope } from "@cosmicdrift/kumiko-framework/internal/row-level-security";
|
|
35
|
-
import { createEscapeHatchReporter, UNATTRIBUTED_ACTOR, } from "@cosmicdrift/kumiko-framework/pipeline";
|
|
36
34
|
import { purgeSearchDocumentsForSubject, } from "@cosmicdrift/kumiko-framework/search";
|
|
37
35
|
import { resolveRetentionPolicyForTenant, resolveTenantRetentionPreset, } from "../data-retention/index.js";
|
|
38
36
|
import { decryptStoredPii, purgeFilesReachingSubject, runInSubTransaction, } from "../shared/index.js";
|
|
39
37
|
import { tenantMembershipsTable } from "../tenant/index.js";
|
|
40
38
|
import { USER_STATUS, userTable } from "../user/index.js";
|
|
39
|
+
import { buildHookDb } from "./build-hook-db.js";
|
|
41
40
|
import { selectUsersDueForForgetCleanup } from "./db/queries/forget-cleanup.js";
|
|
42
41
|
import { updateUserLifecycle } from "./lib/update-user-lifecycle.js";
|
|
43
|
-
function buildHookDb(db, tenantId, entry, args) {
|
|
44
|
-
const report = createEscapeHatchReporter({
|
|
45
|
-
handler: `${EXT_USER_DATA}:${entry.entityName}`,
|
|
46
|
-
tenantId,
|
|
47
|
-
actor: args.actor ?? UNATTRIBUTED_ACTOR,
|
|
48
|
-
sink: args.escapeHatchAuditSink,
|
|
49
|
-
log: args.escapeHatchAuditLog ?? createFallbackLogger("user-data-rights"),
|
|
50
|
-
});
|
|
51
|
-
return createTenantDb({
|
|
52
|
-
db,
|
|
53
|
-
tenantId,
|
|
54
|
-
mode: "tenant",
|
|
55
|
-
grants: {
|
|
56
|
-
unsafeRaw: entry.escapeHatchReason !== undefined ? { reason: entry.escapeHatchReason } : undefined,
|
|
57
|
-
report,
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
42
|
// EXT_USER_DATA delete-hooks default here; a hook that redacts data keyed on an
|
|
62
43
|
// owner column it doesn't own must register a lower order so it runs BEFORE any
|
|
63
44
|
// hook that nulls that column. See custom-fields wire-user-data-rights.ts.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Logger } from "@cosmicdrift/kumiko-framework/logging";
|
|
2
2
|
import type { DbRunner } from "@cosmicdrift/kumiko-framework/db";
|
|
3
3
|
import { type EscapeHatchAuditSink, type Registry, type TenantId, type UserDataExportSnippet } from "@cosmicdrift/kumiko-framework/engine";
|
|
4
4
|
import type { getTemporal } from "@cosmicdrift/kumiko-framework/time";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
|
|
2
1
|
// User data export pipeline — GDPR Art. 15 (access) +
|
|
3
2
|
// Art. 20 (data portability).
|
|
4
3
|
//
|
|
@@ -20,30 +19,12 @@ import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
|
|
|
20
19
|
// user-data-rights-defaults/hooks/user.userdata-hook explicitly exposes
|
|
21
20
|
// neither passwordHash nor roles (privileged columns).
|
|
22
21
|
import { configuredPiiSubjectKms, decryptPiiFieldValues, isPiiCiphertext, } from "@cosmicdrift/kumiko-framework/crypto";
|
|
23
|
-
import { collectEncryptedFieldNames, configuredEntityFieldEncryption,
|
|
22
|
+
import { collectEncryptedFieldNames, configuredEntityFieldEncryption, decryptEntityFieldValues, selectMany, } from "@cosmicdrift/kumiko-framework/db";
|
|
24
23
|
import { EXT_USER_DATA, extensionUsageEscapeHatchReason, maskWriteOnlyFields, } from "@cosmicdrift/kumiko-framework/engine";
|
|
25
24
|
import { runInSystemRowLevelSecurityScope } from "@cosmicdrift/kumiko-framework/internal/row-level-security";
|
|
26
|
-
import { createEscapeHatchReporter, UNATTRIBUTED_ACTOR, } from "@cosmicdrift/kumiko-framework/pipeline";
|
|
27
25
|
import { tenantMembershipsTable } from "../tenant/index.js";
|
|
26
|
+
import { buildHookDb } from "./build-hook-db.js";
|
|
28
27
|
import { buildFileRefZipPath } from "./zip-path.js";
|
|
29
|
-
function buildHookDb(db, tenantId, entry, args) {
|
|
30
|
-
const report = createEscapeHatchReporter({
|
|
31
|
-
handler: `${EXT_USER_DATA}:${entry.entityName}`,
|
|
32
|
-
tenantId,
|
|
33
|
-
actor: args.actor ?? UNATTRIBUTED_ACTOR,
|
|
34
|
-
sink: args.escapeHatchAuditSink,
|
|
35
|
-
log: args.escapeHatchAuditLog ?? createFallbackLogger("user-data-rights"),
|
|
36
|
-
});
|
|
37
|
-
return createTenantDb({
|
|
38
|
-
db,
|
|
39
|
-
tenantId,
|
|
40
|
-
mode: "tenant",
|
|
41
|
-
grants: {
|
|
42
|
-
unsafeRaw: entry.escapeHatchReason !== undefined ? { reason: entry.escapeHatchReason } : undefined,
|
|
43
|
-
report,
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
28
|
/**
|
|
48
29
|
* Pure function: invokes all EXT_USER_DATA hooks for each tenant
|
|
49
30
|
* membership and collects snippets into a UserExportBundle.
|