@cosmicdrift/kumiko-bundled-features 0.286.0 → 0.288.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 +12 -9
- package/src/auth-email-password/signed-token.ts +4 -86
- package/src/billing-foundation/__tests__/subscription-tier-sync.integration.test.ts +186 -0
- package/src/billing-foundation/changes.json +6 -0
- package/src/billing-foundation/subscription-tier-sync.ts +9 -4
- package/src/derivatives-sharp/__tests__/render.test.ts +246 -1
- package/src/derivatives-sharp/changes.json +8 -1
- package/src/derivatives-sharp/render.ts +172 -5
- package/src/file-derivatives/__tests__/public-variant-route.integration.test.ts +15 -1
- package/src/file-derivatives/changes.json +6 -0
- package/src/file-derivatives/feature.ts +9 -1
- package/src/shared/__tests__/row-bound-grant.integration.test.ts +184 -0
- package/src/shared/changes.json +8 -1
- package/src/shared/index.ts +12 -0
- package/src/shared/row-bound-grant.test.ts +294 -0
- package/src/shared/row-bound-grant.ts +115 -0
- package/src/{auth-email-password/__tests__ → shared}/signed-token.test.ts +1 -1
- package/src/shared/signed-token.ts +101 -0
- package/src/tenant/seeding.ts +4 -0
- package/src/user-data-rights/__tests__/deletion-token-compat.test.ts +35 -0
- package/src/user-data-rights/__tests__/run-export-jobs.integration.test.ts +90 -1
- package/src/user-data-rights/changes.json +12 -0
- package/src/user-data-rights/deletion-token.ts +41 -47
- package/src/user-data-rights/feature.ts +27 -0
- package/src/user-data-rights/handlers/confirm-deletion-by-token.write.ts +10 -20
- package/src/user-data-rights/run-export-jobs.ts +69 -1
- package/src/user-data-rights-defaults/__tests__/user-data-rights-defaults.integration.test.ts +198 -1
- package/src/user-data-rights-defaults/hooks/file-ref.userdata-hook.ts +76 -6
|
@@ -2,6 +2,8 @@ import { createEventStoreExecutor, type TenantDb } from "@cosmicdrift/kumiko-fra
|
|
|
2
2
|
import { derivativeListPrefix, isDerivativeKeyOf } from "@cosmicdrift/kumiko-framework/derivatives";
|
|
3
3
|
import {
|
|
4
4
|
createSystemUser,
|
|
5
|
+
type FieldDefinition,
|
|
6
|
+
type Registry,
|
|
5
7
|
type SessionUser,
|
|
6
8
|
type UserDataDeleteHook,
|
|
7
9
|
type UserDataExportHook,
|
|
@@ -28,10 +30,18 @@ const crud = createEventStoreExecutor(fileRefsTable, fileRefEntity, { entityName
|
|
|
28
30
|
// NICHT direkt — sie werden via signed-Download-URLs separat ins ZIP
|
|
29
31
|
// gepackt (S2.U3 Export-Job-Pipeline orchestriert das).
|
|
30
32
|
//
|
|
31
|
-
// Delete-
|
|
32
|
-
// "delete": storageProvider.delete()
|
|
33
|
-
//
|
|
34
|
-
//
|
|
33
|
+
// Delete-hook removes the fileRef row + binary:
|
|
34
|
+
// "delete": storageProvider.delete() per file + row hard-delete — but
|
|
35
|
+
// ONLY for rows whose field is marked as PII of the person
|
|
36
|
+
// (isPersonalFileRow, #3005). All other rows (business/
|
|
37
|
+
// tenant data, no resolvable field, no annotation) go
|
|
38
|
+
// through severPersonLink instead, even when the entity
|
|
39
|
+
// strategy is "delete" — the uploader axis (insertedById) is
|
|
40
|
+
// not the subject axis.
|
|
41
|
+
// "anonymize": insertedById=null, row + binary survive (FK refs can still
|
|
42
|
+
// point at it; person-link removed) — applies to ALL rows
|
|
43
|
+
// when the entity strategy itself is already anonymize (e.g.
|
|
44
|
+
// blockDelete retention), regardless of the field.
|
|
35
45
|
//
|
|
36
46
|
// **Provider-Resolution:** der Provider kommt zur Lauf-Zeit aus
|
|
37
47
|
// `ctx.buildStorageProvider(ctx.tenantId)` — der Forget-Orchestrator
|
|
@@ -124,6 +134,46 @@ async function resolveProvider(ctx: UserDataHookCtx): Promise<UserDataStoragePro
|
|
|
124
134
|
}
|
|
125
135
|
}
|
|
126
136
|
|
|
137
|
+
// Per-row Art.17 decision (kumiko-framework#3005): whether THIS file's field
|
|
138
|
+
// carries personal data of the forgotten person, or is business/tenant data
|
|
139
|
+
// that merely loses its uploader-attribution. insertedById names who
|
|
140
|
+
// UPLOADED the file, not whose data it is — a dealer's vehicle photo
|
|
141
|
+
// uploaded by an employee is the dealer's business data, not the employee's
|
|
142
|
+
// PII. The field's own personal-annotation decides:
|
|
143
|
+
// - pii / userOwned / recordOwned → the field's content IS personal data
|
|
144
|
+
// of a person (self, owner-referenced, or the record's own subject) →
|
|
145
|
+
// hard-delete path.
|
|
146
|
+
// - anything else (explicit `personal: false`, `tenantOwned`,
|
|
147
|
+
// `subjectRef`, or no annotation at all) → not personal-to-a-person
|
|
148
|
+
// content → sever the uploader link only, keep row + binary.
|
|
149
|
+
function isPersonalPiiField(field: FieldDefinition | undefined): boolean {
|
|
150
|
+
if (!field) return false;
|
|
151
|
+
return (
|
|
152
|
+
("pii" in field && field.pii === true) ||
|
|
153
|
+
("userOwned" in field && field.userOwned !== undefined) ||
|
|
154
|
+
("recordOwned" in field && field.recordOwned === true)
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Three cases the field-lookup itself can't resolve (issue #3005's rule for
|
|
159
|
+
// the non-resolvable cases):
|
|
160
|
+
// 1. Unattached upload (entityType/fieldName both null) → hard-delete: a
|
|
161
|
+
// file with no entity binding belongs to nobody but its uploader.
|
|
162
|
+
// 2. Field exists but carries no PII annotation → anonymize (the
|
|
163
|
+
// conservative path); the boot-validator warns on a PII-typical field
|
|
164
|
+
// name so this stays visible and quiet-fixable via `personal`.
|
|
165
|
+
// 3. Entity or field not resolvable (upload hardening in file-routes.ts
|
|
166
|
+
// should prevent this from ever being written; theoretical remainder
|
|
167
|
+
// only) → anonymize, never a silent hard-delete.
|
|
168
|
+
function isPersonalFileRow(registry: Registry, row: Record<string, unknown>): boolean {
|
|
169
|
+
const entityType = row["entityType"]; // @cast-boundary db-row
|
|
170
|
+
const fieldName = row["fieldName"]; // @cast-boundary db-row
|
|
171
|
+
if (entityType === null && fieldName === null) return true;
|
|
172
|
+
if (typeof entityType !== "string" || typeof fieldName !== "string") return false;
|
|
173
|
+
const fieldDef = registry.getEntity(entityType)?.fields[fieldName];
|
|
174
|
+
return isPersonalPiiField(fieldDef);
|
|
175
|
+
}
|
|
176
|
+
|
|
127
177
|
// Derivatives (thumbnails/resized variants — see derivatives-context.ts) are
|
|
128
178
|
// never tracked anywhere but the storage layer: they're rendered under a
|
|
129
179
|
// deterministic key (deriveKey + variantSuffix) computed from the original's
|
|
@@ -221,14 +271,34 @@ export const fileRefDeleteHook: UserDataDeleteHook = async (ctx, strategy) => {
|
|
|
221
271
|
if (strategy !== "delete") {
|
|
222
272
|
// anonymize: insertedById=null, FileRef + binary bleiben. Use-case: shared
|
|
223
273
|
// chat-Attachment im Multi-User-Channel — Author-ID raus, Datei bleibt sichtbar.
|
|
274
|
+
// Applies to ALL rows — the entity strategy comes from a retention
|
|
275
|
+
// policy (e.g. blockDelete) and overrides the per-field decision below,
|
|
276
|
+
// which only applies for strategy="delete".
|
|
224
277
|
await severPersonLink(ctx.db, systemUser, rows);
|
|
225
278
|
// skip: anonymize is complete — the hard-delete path below runs only for strategy "delete".
|
|
226
279
|
return;
|
|
227
280
|
}
|
|
228
281
|
|
|
282
|
+
// strategy="delete" decides PER ROW based on the field, not uniformly
|
|
283
|
+
// (#3005): only rows whose field is marked as PII of the person (or
|
|
284
|
+
// unattached, see isPersonalFileRow) take the hard path. Everything else
|
|
285
|
+
// only loses the uploader link.
|
|
286
|
+
const personalRows: Record<string, unknown>[] = [];
|
|
287
|
+
const businessRows: Record<string, unknown>[] = [];
|
|
288
|
+
for (const row of rows) {
|
|
289
|
+
(isPersonalFileRow(ctx.registry, row) ? personalRows : businessRows).push(row);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (businessRows.length > 0) {
|
|
293
|
+
await severPersonLink(ctx.db, systemUser, businessRows);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// skip: nothing left to hard-delete — businessRows above already had their person link severed via severPersonLink.
|
|
297
|
+
if (personalRows.length === 0) return;
|
|
298
|
+
|
|
229
299
|
const storageProvider = await resolveProvider(ctx);
|
|
230
300
|
if (storageProvider) {
|
|
231
|
-
const failedKeys = await deleteBinaries(
|
|
301
|
+
const failedKeys = await deleteBinaries(personalRows, storageProvider);
|
|
232
302
|
if (failedKeys.length > 0) {
|
|
233
303
|
throw new Error(
|
|
234
304
|
`[user-data-rights-defaults:fileRef] ${failedKeys.length} binary delete(s) failed — aborting forget so the rows are retried next run (keys: ${failedKeys.join(", ")})`,
|
|
@@ -250,7 +320,7 @@ export const fileRefDeleteHook: UserDataDeleteHook = async (ctx, strategy) => {
|
|
|
250
320
|
// auto-verb, the erasure replays on rebuild (created → forgotten → row gone).
|
|
251
321
|
// The old hard deleteMany was resurrected on rebuild; this closes that Art.17
|
|
252
322
|
// hole without a direct write.
|
|
253
|
-
for (const row of
|
|
323
|
+
for (const row of personalRows) {
|
|
254
324
|
const id = row["id"]; // @cast-boundary db-row
|
|
255
325
|
if (typeof id !== "string") continue;
|
|
256
326
|
assertErased(await crud.forget({ id }, systemUser, ctx.db), "fileRef", id);
|