@cosmicdrift/kumiko-bundled-features 0.277.0 → 0.280.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -9
- package/src/auth-email-password/__tests__/invite-flow-kms.integration.test.ts +8 -2
- package/src/auth-mfa-user-data/__tests__/hooks.integration.test.ts +6 -6
- package/src/auth-mfa-user-data/hooks.ts +4 -6
- package/src/cap-counter/__tests__/enforce-cap.test.ts +7 -10
- package/src/cap-counter/__tests__/stock-cap-guard.integration.test.ts +123 -6
- package/src/cap-counter/__tests__/with-cap-enforcement.integration.test.ts +135 -1
- package/src/cap-counter/book-cap-usage.ts +158 -0
- package/src/cap-counter/changes.json +16 -1
- package/src/cap-counter/enforce-cap.ts +5 -37
- package/src/cap-counter/handlers/increment.write.ts +7 -47
- package/src/cap-counter/handlers/mark-soft-warned.write.ts +6 -33
- package/src/cap-counter/index.ts +8 -0
- package/src/cap-counter/stock-cap-guard.ts +14 -19
- package/src/cap-counter/with-cap-enforcement.ts +9 -11
- package/src/custom-fields/__tests__/user-data-rights.integration.test.ts +10 -3
- package/src/custom-fields/wire-user-data-rights.ts +40 -24
- package/src/data-retention/resolve-for-tenant.ts +18 -6
- package/src/delivery/db/queries/preferences.ts +1 -0
- package/src/files-tenant-data/hooks.ts +3 -5
- package/src/folders/__tests__/folders.integration.test.ts +4 -3
- package/src/folders-user-data/__tests__/hooks.integration.test.ts +2 -1
- package/src/folders-user-data/hooks.ts +5 -10
- package/src/form-draft-user-data/__tests__/hooks-delete-failure.integration.test.ts +7 -1
- package/src/form-draft-user-data/__tests__/hooks.integration.test.ts +16 -5
- package/src/form-draft-user-data/hooks.ts +3 -6
- package/src/notes-history-user-data/__tests__/hooks.integration.test.ts +9 -3
- package/src/notes-history-user-data/hooks.ts +3 -4
- package/src/personal-access-tokens/handlers/create.write.ts +1 -0
- package/src/template-resolver-user-data/hooks.ts +1 -2
- package/src/tenant-lifecycle/feature.ts +2 -0
- package/src/tenant-lifecycle/run-tenant-destroy.ts +9 -0
- package/src/tenant-lifecycle/stages.ts +26 -2
- package/src/tier-engine/__tests__/tier-resolver.integration.test.ts +138 -0
- package/src/tier-engine/changes.json +7 -0
- package/src/tier-engine/tier-resolver.ts +7 -6
- package/src/user-data-rights/__tests__/cross-data-matrix.integration.test.ts +5 -14
- package/src/user-data-rights/__tests__/escape-hatch-audit.integration.test.ts +133 -0
- package/src/user-data-rights/__tests__/escape-hatch-declaration.integration.test.ts +198 -0
- package/src/user-data-rights/__tests__/forget-cleanup-hook-ordering.integration.test.ts +15 -3
- package/src/user-data-rights/__tests__/forget-cleanup-search-purge-ordering.integration.test.ts +10 -2
- package/src/user-data-rights/__tests__/mail-default-bridge.integration.test.ts +3 -1
- package/src/user-data-rights/__tests__/run-export-jobs-cron-context.integration.test.ts +8 -3
- package/src/user-data-rights/__tests__/run-forget-cleanup.integration.test.ts +8 -2
- package/src/user-data-rights/__tests__/run-user-export.integration.test.ts +8 -4
- package/src/user-data-rights/__tests__/tenant-model-erasure.integration.test.ts +15 -5
- package/src/user-data-rights/feature.ts +4 -0
- package/src/user-data-rights/run-export-jobs.ts +16 -1
- package/src/user-data-rights/run-forget-cleanup.ts +44 -2
- package/src/user-data-rights/run-user-export.ts +43 -3
- package/src/user-data-rights-defaults/__tests__/bundled-entities.userdata-hooks.integration.test.ts +7 -6
- package/src/user-data-rights-defaults/__tests__/user-data-rights-defaults.integration.test.ts +64 -18
- package/src/user-data-rights-defaults/hooks/api-token.userdata-hook.ts +2 -3
- package/src/user-data-rights-defaults/hooks/config-value.userdata-hook.ts +4 -6
- package/src/user-data-rights-defaults/hooks/delivery-attempt.userdata-hook.ts +1 -2
- package/src/user-data-rights-defaults/hooks/file-ref.userdata-hook.ts +5 -11
- package/src/user-data-rights-defaults/hooks/in-app-message.userdata-hook.ts +2 -3
- package/src/user-data-rights-defaults/hooks/job-run.userdata-hook.ts +1 -2
- package/src/user-data-rights-defaults/hooks/notification-preference.userdata-hook.ts +4 -6
- package/src/user-data-rights-defaults/hooks/tenant-invitation.userdata-hook.ts +8 -10
- package/src/user-data-rights-defaults/hooks/user-session.userdata-hook.ts +2 -3
- package/src/user-data-rights-defaults/hooks/user.userdata-hook.ts +9 -10
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createEventStoreExecutor, createTenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
1
|
+
import { createEventStoreExecutor } from "@cosmicdrift/kumiko-framework/db";
|
|
3
2
|
import {
|
|
4
3
|
createSystemUser,
|
|
5
4
|
type UserDataDeleteHook,
|
|
@@ -23,7 +22,7 @@ const crud = createEventStoreExecutor(notificationPreferencesTable, notification
|
|
|
23
22
|
|
|
24
23
|
export const notificationPreferenceExportHook: UserDataExportHook = async (ctx) => {
|
|
25
24
|
if (!featureMounted(ctx, "delivery")) return null;
|
|
26
|
-
const rows = await selectMany<Record<string, unknown>>(
|
|
25
|
+
const rows = await ctx.db.selectMany<Record<string, unknown>>(notificationPreferencesTable, {
|
|
27
26
|
tenantId: ctx.tenantId,
|
|
28
27
|
userId: ctx.userId,
|
|
29
28
|
});
|
|
@@ -42,14 +41,13 @@ export const notificationPreferenceDeleteHook: UserDataDeleteHook = async (ctx)
|
|
|
42
41
|
// skip: delivery not mounted — its table doesn't exist, nothing to erase.
|
|
43
42
|
if (!featureMounted(ctx, "delivery")) return;
|
|
44
43
|
const systemUser = createSystemUser(ctx.tenantId);
|
|
45
|
-
const
|
|
46
|
-
const rows = await selectMany<Record<string, unknown>>(ctx.db, notificationPreferencesTable, {
|
|
44
|
+
const rows = await ctx.db.selectMany<Record<string, unknown>>(notificationPreferencesTable, {
|
|
47
45
|
tenantId: ctx.tenantId,
|
|
48
46
|
userId: ctx.userId,
|
|
49
47
|
});
|
|
50
48
|
for (const row of rows) {
|
|
51
49
|
const id = row["id"]; // @cast-boundary db-row
|
|
52
50
|
if (typeof id !== "string") continue;
|
|
53
|
-
assertErased(await crud.forget({ id }, systemUser,
|
|
51
|
+
assertErased(await crud.forget({ id }, systemUser, ctx.db), "notification-preference", id);
|
|
54
52
|
}
|
|
55
53
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createEventStoreExecutor, createTenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
1
|
+
import { createEventStoreExecutor } from "@cosmicdrift/kumiko-framework/db";
|
|
3
2
|
import {
|
|
4
3
|
createSystemUser,
|
|
5
4
|
type UserDataDeleteHook,
|
|
@@ -41,7 +40,7 @@ const KMS_POOL_CONCURRENCY = 4;
|
|
|
41
40
|
|
|
42
41
|
async function resolveUserEmail(ctx: UserDataHookCtx): Promise<string | null> {
|
|
43
42
|
if (ctx.userEmailBeforeDelete) return ctx.userEmailBeforeDelete.toLowerCase();
|
|
44
|
-
const row = (await
|
|
43
|
+
const row = (await ctx.db.fetchOne(userTable, { id: ctx.userId })) as {
|
|
45
44
|
email: string;
|
|
46
45
|
} | null; // @cast-boundary db-runner
|
|
47
46
|
if (!row) return null;
|
|
@@ -57,7 +56,7 @@ export const tenantInvitationExportHook: UserDataExportHook = async (ctx) => {
|
|
|
57
56
|
if (!email) return null;
|
|
58
57
|
// Invitation emails are lowercase-normalized on insert, so an exact match
|
|
59
58
|
// is a case-insensitive match.
|
|
60
|
-
const rows = await selectMany<Record<string, unknown>>(
|
|
59
|
+
const rows = await ctx.db.selectMany<Record<string, unknown>>(tenantInvitationsTable, {
|
|
61
60
|
tenantId: ctx.tenantId,
|
|
62
61
|
email,
|
|
63
62
|
});
|
|
@@ -88,11 +87,10 @@ export const tenantInvitationDeleteHook: UserDataDeleteHook = async (ctx, strate
|
|
|
88
87
|
// skip: tenant not mounted — its table doesn't exist, nothing to erase.
|
|
89
88
|
if (!featureMounted(ctx, "tenant")) return;
|
|
90
89
|
const systemUser = createSystemUser(ctx.tenantId);
|
|
91
|
-
const tdb = createTenantDb(ctx.db, ctx.tenantId, "system");
|
|
92
90
|
|
|
93
91
|
const email = await resolveUserEmail(ctx);
|
|
94
92
|
if (email) {
|
|
95
|
-
const inviteeRows = await selectMany<Record<string, unknown>>(
|
|
93
|
+
const inviteeRows = await ctx.db.selectMany<Record<string, unknown>>(tenantInvitationsTable, {
|
|
96
94
|
tenantId: ctx.tenantId,
|
|
97
95
|
email,
|
|
98
96
|
});
|
|
@@ -100,14 +98,14 @@ export const tenantInvitationDeleteHook: UserDataDeleteHook = async (ctx, strate
|
|
|
100
98
|
const id = row["id"]; // @cast-boundary db-row
|
|
101
99
|
if (typeof id !== "string") continue;
|
|
102
100
|
if (strategy === "delete") {
|
|
103
|
-
assertErased(await crud.forget({ id }, systemUser,
|
|
101
|
+
assertErased(await crud.forget({ id }, systemUser, ctx.db), "tenant-invitation", id);
|
|
104
102
|
} else {
|
|
105
103
|
// Row-id in the pseudonym keeps the (tenantId, email) unique index
|
|
106
104
|
// collision-free when a user has invitations in several states.
|
|
107
105
|
await crud.update(
|
|
108
106
|
{ id, changes: { email: `forgotten-${id}@anonymized.invalid` } },
|
|
109
107
|
systemUser,
|
|
110
|
-
|
|
108
|
+
ctx.db,
|
|
111
109
|
{ skipOptimisticLock: true },
|
|
112
110
|
);
|
|
113
111
|
}
|
|
@@ -120,14 +118,14 @@ export const tenantInvitationDeleteHook: UserDataDeleteHook = async (ctx, strate
|
|
|
120
118
|
// without loading + decrypting every invitation in the tenant. See
|
|
121
119
|
// tenant/handlers/invitations.query.ts for the same lookupable-filter
|
|
122
120
|
// pattern on `email`.
|
|
123
|
-
const inviterRows = await selectMany<Record<string, unknown>>(
|
|
121
|
+
const inviterRows = await ctx.db.selectMany<Record<string, unknown>>(tenantInvitationsTable, {
|
|
124
122
|
tenantId: ctx.tenantId,
|
|
125
123
|
invitedBy: ctx.userId,
|
|
126
124
|
});
|
|
127
125
|
for (const row of inviterRows) {
|
|
128
126
|
const id = row["id"]; // @cast-boundary db-row
|
|
129
127
|
if (typeof id !== "string") continue;
|
|
130
|
-
await crud.update({ id, changes: { invitedBy: INVITED_BY_ANONYMIZED } }, systemUser,
|
|
128
|
+
await crud.update({ id, changes: { invitedBy: INVITED_BY_ANONYMIZED } }, systemUser, ctx.db, {
|
|
131
129
|
skipOptimisticLock: true,
|
|
132
130
|
});
|
|
133
131
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { deleteMany, selectMany } from "@cosmicdrift/kumiko-framework/bun-db";
|
|
2
1
|
import type { UserDataDeleteHook, UserDataExportHook } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
2
|
import { userSessionTable } from "../../sessions";
|
|
4
3
|
import { featureMounted } from "./feature-mounted";
|
|
@@ -16,7 +15,7 @@ import { featureMounted } from "./feature-mounted";
|
|
|
16
15
|
|
|
17
16
|
export const userSessionExportHook: UserDataExportHook = async (ctx) => {
|
|
18
17
|
if (!featureMounted(ctx, "sessions")) return null;
|
|
19
|
-
const rows = await
|
|
18
|
+
const rows = await ctx.db.selectMany(userSessionTable, {
|
|
20
19
|
userId: ctx.userId,
|
|
21
20
|
tenantId: ctx.tenantId,
|
|
22
21
|
});
|
|
@@ -38,5 +37,5 @@ export const userSessionExportHook: UserDataExportHook = async (ctx) => {
|
|
|
38
37
|
export const userSessionDeleteHook: UserDataDeleteHook = async (ctx) => {
|
|
39
38
|
// skip: sessions not mounted — its table doesn't exist, nothing to erase.
|
|
40
39
|
if (!featureMounted(ctx, "sessions")) return;
|
|
41
|
-
await
|
|
40
|
+
await ctx.db.deleteMany(userSessionTable, { userId: ctx.userId, tenantId: ctx.tenantId });
|
|
42
41
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createEventStoreExecutor, createTenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
1
|
+
import { createEventStoreExecutor } from "@cosmicdrift/kumiko-framework/db";
|
|
3
2
|
import {
|
|
4
3
|
createSystemUser,
|
|
5
4
|
type UserDataDeleteHook,
|
|
@@ -42,13 +41,13 @@ const crud = createEventStoreExecutor(userTable, userEntity, { entityName: "user
|
|
|
42
41
|
// Frist auf einer FK-target-Entity)
|
|
43
42
|
|
|
44
43
|
export const userExportHook: UserDataExportHook = async (ctx) => {
|
|
45
|
-
const row =
|
|
44
|
+
const row = await ctx.db.fetchOne<{
|
|
46
45
|
id: string;
|
|
47
46
|
email: string;
|
|
48
47
|
displayName: string;
|
|
49
48
|
locale: string | null;
|
|
50
49
|
emailVerified: boolean;
|
|
51
|
-
}
|
|
50
|
+
}>(userTable, { id: ctx.userId });
|
|
52
51
|
|
|
53
52
|
if (!row) return null;
|
|
54
53
|
|
|
@@ -75,11 +74,11 @@ export const userDeleteHook: UserDataDeleteHook = async (ctx, strategy) => {
|
|
|
75
74
|
|
|
76
75
|
// System actor + skipOptimisticLock: the forget pipeline has no read
|
|
77
76
|
// version and writes privileged identity columns ("system" is privileged).
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
//
|
|
77
|
+
// crud.update extracts the raw connection from ctx.db via tenantDbRunner
|
|
78
|
+
// and enforces global-entity tenancy itself (isForeignTenantOnGlobalEntity),
|
|
79
|
+
// so it reaches the row by id regardless of which tenant pass triggered it —
|
|
80
|
+
// TenantDb's own tenant-scoping narrowing never applies to executor writes.
|
|
81
81
|
const systemUser = createSystemUser(ctx.tenantId);
|
|
82
|
-
const tdb = createTenantDb(ctx.db, ctx.tenantId, "system");
|
|
83
82
|
|
|
84
83
|
if (strategy === "delete") {
|
|
85
84
|
// PII raus + status=deleted (Login geblockt) via Event → Rebuild spielt den
|
|
@@ -102,7 +101,7 @@ export const userDeleteHook: UserDataDeleteHook = async (ctx, strategy) => {
|
|
|
102
101
|
},
|
|
103
102
|
},
|
|
104
103
|
systemUser,
|
|
105
|
-
|
|
104
|
+
ctx.db,
|
|
106
105
|
{ skipOptimisticLock: true },
|
|
107
106
|
);
|
|
108
107
|
} else {
|
|
@@ -120,7 +119,7 @@ export const userDeleteHook: UserDataDeleteHook = async (ctx, strategy) => {
|
|
|
120
119
|
},
|
|
121
120
|
},
|
|
122
121
|
systemUser,
|
|
123
|
-
|
|
122
|
+
ctx.db,
|
|
124
123
|
{ skipOptimisticLock: true },
|
|
125
124
|
);
|
|
126
125
|
}
|