@cosmicdrift/kumiko-framework 0.215.1 → 0.215.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmicdrift/kumiko-framework",
3
- "version": "0.215.1",
3
+ "version": "0.215.2",
4
4
  "description": "Framework core — engine, pipeline, API, DB, and every other bit that makes Kumiko go.",
5
5
  "license": "BUSL-1.1",
6
6
  "author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
@@ -194,7 +194,7 @@
194
194
  "./package.json": "./package.json"
195
195
  },
196
196
  "dependencies": {
197
- "@cosmicdrift/kumiko-types": "0.215.1",
197
+ "@cosmicdrift/kumiko-types": "0.215.2",
198
198
  "bullmq": "^5.76.7",
199
199
  "bun-types": "^1.3.13",
200
200
  "hono": "^4.13.1",
@@ -210,7 +210,7 @@
210
210
  "zod": "^4.4.3"
211
211
  },
212
212
  "devDependencies": {
213
- "@cosmicdrift/kumiko-dispatcher-live": "0.215.1",
213
+ "@cosmicdrift/kumiko-dispatcher-live": "0.215.2",
214
214
  "bun-types": "^1.3.13",
215
215
  "pino-pretty": "^13.1.3"
216
216
  },
@@ -44,3 +44,41 @@ export async function nullBlindIndexesForSubject(
44
44
  }
45
45
  }
46
46
  }
47
+
48
+ // Tenant-scope oracle for crypto-shredding's forget-subject (mh#349): a
49
+ // "user"-kind subject id is often not a real user (share-token recipient,
50
+ // email subscriber, ...) — those entities self-own their PII (`personal:
51
+ // "self"`, i.e. their own row id IS the subject) and carry a real tenant_id,
52
+ // unlike read_users (systemStream, tenant_id always SYSTEM_TENANT_ID). This
53
+ // checks whether the subject row lives in the given tenant, so a tenant-
54
+ // scoped DPO can still forget subjects it truly owns without needing a
55
+ // tenant-membership row (which only exists for real users).
56
+ export async function subjectRowExistsInTenant(
57
+ db: DbRunner,
58
+ features: ReadonlyMap<string, FeatureDefinition>,
59
+ subjectId: string,
60
+ tenantId: string,
61
+ ): Promise<boolean> {
62
+ for (const feature of features.values()) {
63
+ for (const [entityName, entity] of Object.entries(feature.entities ?? {})) {
64
+ const hasSelfPiiField = Object.values(entity.fields).some(
65
+ (field) => "pii" in field && field.pii === true,
66
+ );
67
+ if (!hasSelfPiiField) continue;
68
+ const tableName = resolveTableName(entityName, entity, undefined);
69
+ try {
70
+ const rows = await executeRawQuery(
71
+ db,
72
+ `SELECT 1 FROM ${quoteIdent(tableName)} WHERE id = $1 AND tenant_id = $2 LIMIT 1`,
73
+ [subjectId, tenantId],
74
+ );
75
+ if (rows.length > 0) return true;
76
+ } catch {
77
+ // Table missing, id-type mismatch, ... — not evidence the subject is
78
+ // owned here. Fail-closed must come from an honest "not found" across
79
+ // every entity, never from a query blowing up on one of them.
80
+ }
81
+ }
82
+ }
83
+ return false;
84
+ }
package/src/db/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { assertExistsIn } from "./assert-exists-in";
2
- export { nullBlindIndexesForSubject } from "./blind-index-cleanup";
2
+ export { nullBlindIndexesForSubject, subjectRowExistsInTenant } from "./blind-index-cleanup";
3
3
  export { collectTableMetas } from "./collect-table-metas";
4
4
  export { flattenCompoundTypes, rehydrateCompoundTypes } from "./compound-types";
5
5
  export { seedConfigValues } from "./config-seed";