@nodii/dsar 0.19.0 → 0.22.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/bind-pattern-a.d.ts +139 -2
- package/dist/bind-pattern-a.d.ts.map +1 -1
- package/dist/bind-pattern-a.js +571 -32
- package/dist/bind-pattern-a.js.map +1 -1
- package/dist/bind-pattern-b.d.ts.map +1 -1
- package/dist/bind-pattern-b.js +58 -3
- package/dist/bind-pattern-b.js.map +1 -1
- package/dist/grpc/dsar-service.d.ts +29 -0
- package/dist/grpc/dsar-service.d.ts.map +1 -1
- package/dist/grpc/dsar-service.js +34 -0
- package/dist/grpc/dsar-service.js.map +1 -1
- package/dist/grpc/proto-path.d.ts +33 -0
- package/dist/grpc/proto-path.d.ts.map +1 -0
- package/dist/grpc/proto-path.js +87 -0
- package/dist/grpc/proto-path.js.map +1 -0
- package/dist/hold-failure-mode.d.ts +24 -0
- package/dist/hold-failure-mode.d.ts.map +1 -1
- package/dist/hold-failure-mode.js +24 -0
- package/dist/hold-failure-mode.js.map +1 -1
- package/dist/hold-gate-probe.d.ts +61 -0
- package/dist/hold-gate-probe.d.ts.map +1 -0
- package/dist/hold-gate-probe.js +146 -0
- package/dist/hold-gate-probe.js.map +1 -0
- package/dist/holds.d.ts +60 -1
- package/dist/holds.d.ts.map +1 -1
- package/dist/holds.js +60 -3
- package/dist/holds.js.map +1 -1
- package/dist/index.d.ts +16 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -5
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +10 -0
- package/dist/migrations/index.js.map +1 -1
- package/dist/orchestrator.d.ts +48 -0
- package/dist/orchestrator.d.ts.map +1 -1
- package/dist/orchestrator.js +297 -20
- package/dist/orchestrator.js.map +1 -1
- package/dist/register.d.ts +35 -1
- package/dist/register.d.ts.map +1 -1
- package/dist/register.js +26 -0
- package/dist/register.js.map +1 -1
- package/dist/retention-sweeper.d.ts +252 -0
- package/dist/retention-sweeper.d.ts.map +1 -0
- package/dist/retention-sweeper.js +356 -0
- package/dist/retention-sweeper.js.map +1 -0
- package/dist/retention.d.ts +109 -1
- package/dist/retention.d.ts.map +1 -1
- package/dist/retention.js +216 -3
- package/dist/retention.js.map +1 -1
- package/dist/subject-kinds.d.ts +74 -0
- package/dist/subject-kinds.d.ts.map +1 -0
- package/dist/subject-kinds.js +141 -0
- package/dist/subject-kinds.js.map +1 -0
- package/dist/types.d.ts +423 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +164 -0
- package/dist/types.js.map +1 -1
- package/package.json +7 -4
- package/proto/nodii/dsar/v1/dsar.proto +202 -0
- package/src/migrations/001-lifecycle-requests.sql +422 -0
package/dist/types.js
CHANGED
|
@@ -21,6 +21,40 @@
|
|
|
21
21
|
// - Multi-format streaming for `PortabilityExport` (jsonl + csv).
|
|
22
22
|
// - Compensation walk + library-spawned child saga for partial-erasure rollback.
|
|
23
23
|
// ----------------------------------------------------------------------------
|
|
24
|
+
// D720 — the three-bucket retention vocabulary.
|
|
25
|
+
//
|
|
26
|
+
// TWIN of `@nodii/pii`'s `PII_BUCKETS` (buckets.ts), redeclared rather than
|
|
27
|
+
// imported: `@nodii/pii` is a PEER dependency of this package, not a runtime
|
|
28
|
+
// one — the whole point of `PiiAdapter` being a structural interface is that a
|
|
29
|
+
// DSAR participant can bind without pulling the crypto library into its import
|
|
30
|
+
// graph. A parity test asserts the two lists stay identical.
|
|
31
|
+
// ----------------------------------------------------------------------------
|
|
32
|
+
/** The closed D720 bucket set. Twin of `@nodii/pii`'s `PII_BUCKETS`. */
|
|
33
|
+
export const PII_BUCKETS = ["statutory", "operational", "free_text"];
|
|
34
|
+
/** The bucket a data class with no explicit declaration lands in. */
|
|
35
|
+
export const DEFAULT_PII_BUCKET = "operational";
|
|
36
|
+
/** Narrowing predicate for {@link PiiBucket}. */
|
|
37
|
+
export function isPiiBucket(value) {
|
|
38
|
+
return (typeof value === "string" &&
|
|
39
|
+
PII_BUCKETS.includes(value));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* D720 — which timestamp a retention window counts from. CLOSED set: an
|
|
43
|
+
* unrecognised anchor cannot be defaulted, because picking the wrong one moves
|
|
44
|
+
* a hard-delete date by years in either direction.
|
|
45
|
+
*/
|
|
46
|
+
export const RETENTION_ANCHORS = [
|
|
47
|
+
"creation",
|
|
48
|
+
"last_activity",
|
|
49
|
+
"relationship_end",
|
|
50
|
+
"filing",
|
|
51
|
+
];
|
|
52
|
+
/** Narrowing predicate for {@link RetentionAnchor}. */
|
|
53
|
+
export function isRetentionAnchor(value) {
|
|
54
|
+
return (typeof value === "string" &&
|
|
55
|
+
RETENTION_ANCHORS.includes(value));
|
|
56
|
+
}
|
|
57
|
+
// ----------------------------------------------------------------------------
|
|
24
58
|
// Typed errors.
|
|
25
59
|
export class DsarError extends Error {
|
|
26
60
|
constructor(message) {
|
|
@@ -188,6 +222,136 @@ export class MissingOutboxEmitterError extends Error {
|
|
|
188
222
|
this.name = "MissingOutboxEmitterError";
|
|
189
223
|
}
|
|
190
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Raised at BIND time when `bindPatternA` is called WITHOUT a `sqlClient`.
|
|
227
|
+
*
|
|
228
|
+
* A Pattern A participant always binds the `erase` + `restrict` handlers (both
|
|
229
|
+
* are REQUIRED members of {@link PatternAHandlers}), and both are gated on the
|
|
230
|
+
* `data_residency_holds` consult. With no SQL client there is no holds table to
|
|
231
|
+
* consult, so the gate cannot run — and per the operator ruling of 2026-07-30
|
|
232
|
+
* ("If holds is inaccessible - we deny the write. ... Fail CLOSED.") every such
|
|
233
|
+
* request must be refused. A service in that shape can serve NOTHING on its two
|
|
234
|
+
* most compliance-sensitive RPCs; it is a boot misconfiguration, not a runtime
|
|
235
|
+
* condition, so it fails at BOOT rather than once per request.
|
|
236
|
+
*
|
|
237
|
+
* HISTORY (libs#612 → this release). `checkHold` used to open with
|
|
238
|
+
* `if (!opts.sqlClient) return null` — PROCEED. That made the fleet's
|
|
239
|
+
* "unconditionally fail-closed" docstrings literally false whenever the pool was
|
|
240
|
+
* absent: a participant bound without `sqlClient` performed crypto-shred erases
|
|
241
|
+
* with NO hold consultation and answered `COMPLETED`. libs#612 closed the
|
|
242
|
+
* data-loss half by routing the absent pool through the branded, audited,
|
|
243
|
+
* non-memoizable refusal path (`hold_consult_failed_fail_closed`), which is
|
|
244
|
+
* correct but SILENT until the first erase — the misconfiguration surfaced as a
|
|
245
|
+
* production DSAR failure rather than a failed deploy. THIS release moves the
|
|
246
|
+
* detection to bind time.
|
|
247
|
+
*
|
|
248
|
+
* NO ESCAPE HATCH — there is no flag, no `allowNoHoldsClient`, no dev mode. A
|
|
249
|
+
* CI / dev boot with no holds table applies the holds migration
|
|
250
|
+
* (`applyDsarMigrations`) against a real pool; it does not bypass the gate.
|
|
251
|
+
*
|
|
252
|
+
* Mirrors {@link MissingOutboxEmitterError}: same bind-time position, same
|
|
253
|
+
* `code`-carrying shape, and the message names the gRPC `serviceName` (wire
|
|
254
|
+
* identity), NEVER the short audit token.
|
|
255
|
+
*
|
|
256
|
+
* Twins: python `MissingSqlClientForHoldGateError`, go
|
|
257
|
+
* `MissingSQLClientForHoldGateError`.
|
|
258
|
+
*/
|
|
259
|
+
export class MissingSqlClientForHoldGateError extends Error {
|
|
260
|
+
code = "MISSING_SQL_CLIENT_FOR_HOLD_GATE";
|
|
261
|
+
constructor(serviceName) {
|
|
262
|
+
const svc = JSON.stringify(serviceName);
|
|
263
|
+
super(`MISSING_SQL_CLIENT_FOR_HOLD_GATE: bindPatternA({ serviceName: ${svc} }) requires a \`sqlClient\` — the EraseData and RestrictProcessing handlers are gated on the \`data_residency_holds\` consult, and with no SQL client that consult can never run. Per the operator ruling of 2026-07-30 the hold gate is UNCONDITIONALLY fail-CLOSED, so every erase/restrict would be refused (\`hold_consult_failed_fail_closed\`) — a service in this shape cannot serve its two most compliance-sensitive RPCs. Wire \`sqlClient\` to the holds database (and run \`applyDsarMigrations\` so \`data_residency_holds\` exists). There is NO opt-out.`);
|
|
264
|
+
this.name = "MissingSqlClientForHoldGateError";
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* D720 — raised when an erase is about to run against a subject whose scope
|
|
269
|
+
* includes a `statutory` data class, but the service cannot prove that class is
|
|
270
|
+
* keyed to the tenant RETENTION DEK.
|
|
271
|
+
*
|
|
272
|
+
* Two ways to get here, both misconfigurations, both silent without this check:
|
|
273
|
+
* 1. the `PiiAdapter` has no `hasRetentionDek` at all — the service declared
|
|
274
|
+
* a statutory class and never adopted the retention-DEK path; or
|
|
275
|
+
* 2. it returned `false` — the tenant has no retention DEK row, so whatever
|
|
276
|
+
* statutory data exists was written under the per-subject DEK.
|
|
277
|
+
*
|
|
278
|
+
* In both cases the statutory records are under the key `erasePerSubject` is
|
|
279
|
+
* about to NULL. The library REFUSES (FAILED) rather than proceeding: an erase
|
|
280
|
+
* that destroys a statutory-bucket record is a defect (D720), and the one thing
|
|
281
|
+
* worse than refusing an erase is performing an irreversible one that the
|
|
282
|
+
* regulator will later ask about. `reason` is the stable
|
|
283
|
+
* `statutory_bucket_not_retention_keyed` token.
|
|
284
|
+
*
|
|
285
|
+
* FIX, not a flag: mint the retention DEK by writing the statutory columns
|
|
286
|
+
* through `bucket: "statutory"` (see `@nodii/pii`), or correct the declaration
|
|
287
|
+
* if the class was never statutory. There is no opt-out.
|
|
288
|
+
*/
|
|
289
|
+
export class StatutoryBucketNotRetentionKeyed extends DsarError {
|
|
290
|
+
code = "STATUTORY_BUCKET_NOT_RETENTION_KEYED";
|
|
291
|
+
dataClasses;
|
|
292
|
+
constructor(serviceName, tenantId, dataClasses, detail) {
|
|
293
|
+
const why = detail === "adapter_missing_probe"
|
|
294
|
+
? "the wired PiiAdapter has no `hasRetentionDek` — the service declared a statutory class but never adopted the retention-DEK path"
|
|
295
|
+
: "the tenant has NO retention DEK row — whatever statutory data exists was written under the per-subject DEK";
|
|
296
|
+
super(`statutory_bucket_not_retention_keyed: ${serviceName} declared statutory data class(es) [${dataClasses.join(", ")}] for tenant ${tenantId}, but ${why}. Those records are under the key this erase is about to NULL, so proceeding would crypto-shred data the law requires the tenant to KEEP (D720). REFUSED. Fix: write the statutory columns through \`bucket: "statutory"\` so the tenant retention DEK is minted, or correct the bucket declaration if the class was never statutory. There is no opt-out.`);
|
|
297
|
+
this.name = "StatutoryBucketNotRetentionKeyed";
|
|
298
|
+
this.dataClasses = [...dataClasses];
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/** Stable `reason` token for a {@link StatutoryBucketNotRetentionKeyed} refusal. */
|
|
302
|
+
export const STATUTORY_NOT_RETENTION_KEYED_REASON = "statutory_bucket_not_retention_keyed";
|
|
303
|
+
/**
|
|
304
|
+
* D720 — stable `reason` token for an erase that completed for the operational
|
|
305
|
+
* + free_text buckets and RETAINED one or more statutory classes. Pairs with
|
|
306
|
+
* `status: "PARTIAL"` + a non-empty `retained_classes`.
|
|
307
|
+
*/
|
|
308
|
+
export const STATUTORY_RETENTION_PARTIAL_REASON = "statutory_retention_partial";
|
|
309
|
+
/**
|
|
310
|
+
* D720 — stable `reason` token for an erase that found the tenant's retention
|
|
311
|
+
* DEK already SHREDDED (D105). Pairs with `status: "COMPLETED"` + a non-empty
|
|
312
|
+
* `statutory_already_erased`: nothing survived, so nothing was retained, and
|
|
313
|
+
* the erase is total.
|
|
314
|
+
*/
|
|
315
|
+
export const STATUTORY_ALREADY_TENANT_SHREDDED_REASON = "statutory_already_tenant_shredded";
|
|
316
|
+
/**
|
|
317
|
+
* D720 — raised when the RESTRICTED marker write affected no row.
|
|
318
|
+
*
|
|
319
|
+
* `restricted_at` is the only durable evidence that a subject was erased as far
|
|
320
|
+
* as the law allows. A `PARTIAL` response that promises retention while its
|
|
321
|
+
* marker silently wrote nothing is exactly the class of lie D720 exists to
|
|
322
|
+
* remove — on the next audit the subject reads as never-erased while the
|
|
323
|
+
* response claims a lawful partial erase.
|
|
324
|
+
*
|
|
325
|
+
* The marker is an UPSERT, so "no row" cannot mean "this subject had no
|
|
326
|
+
* data_subjects row" (a statutory-ONLY subject never gets one: nothing ever
|
|
327
|
+
* minted a subject DEK for it). It means the write did not land, and the erase
|
|
328
|
+
* fails loud rather than reporting a marker that does not exist.
|
|
329
|
+
*/
|
|
330
|
+
export class RestrictedMarkerNotWritten extends DsarError {
|
|
331
|
+
code = "RESTRICTED_MARKER_NOT_WRITTEN";
|
|
332
|
+
constructor(serviceName, tableName, rowsAffected) {
|
|
333
|
+
super(`restricted_marker_not_written: ${serviceName} retained statutory data for this subject, but the RESTRICTED marker UPSERT against ${tableName} affected ${rowsAffected} row(s) (expected exactly 1). \`restricted_at\` is the only durable record that the subject was erased as far as the law allows — without it the next audit reads the subject as never-erased while the response claims a lawful partial erase. Refusing to report a marker that was not written. Check that ${tableName} exists, carries the D720 \`restricted_at\` column (run migrate-gen), and has the UNIQUE (tenant_id, subject_id, subject_kind) constraint the UPSERT targets.`);
|
|
334
|
+
this.name = "RestrictedMarkerNotWritten";
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Raised by {@link liftHold} when the lift scope is AMBIGUOUS — a concrete
|
|
339
|
+
* `subjectId` together with `sweepAllSubjects: true`.
|
|
340
|
+
*
|
|
341
|
+
* Those two say opposite things ("lift this subject's holds" vs "lift every hold
|
|
342
|
+
* in the tenant") and the library will not pick one. Drop `sweepAllSubjects` for
|
|
343
|
+
* a per-subject lift; pass `subjectId: null` with it for the sweep.
|
|
344
|
+
*
|
|
345
|
+
* The commonest way to reach this error is forwarding a lift handler's
|
|
346
|
+
* `tenant_level` flag into `sweepAllSubjects`. They are OPPOSITES — see
|
|
347
|
+
* `RetentionHoldHandlers.lift` — and the message says so.
|
|
348
|
+
*/
|
|
349
|
+
export class AmbiguousLiftScope extends DsarError {
|
|
350
|
+
constructor(subjectId) {
|
|
351
|
+
super(`ambiguous_lift_scope: liftHold received BOTH subjectId=${JSON.stringify(subjectId)} and sweepAllSubjects:true. A per-subject lift and a whole-tenant sweep are different operations and the library will not guess. Pass \`subjectId\` alone to lift ONE subject's holds; pass \`subjectId: null\` alone to lift only the TENANT-LEVEL row (subject_id IS NULL); pass \`subjectId: null\` WITH \`sweepAllSubjects: true\` to lift every hold in the tenant, every subject's included. If you got here by forwarding a lift handler's \`tenant_level\` flag: that flag is the OPPOSITE of \`sweepAllSubjects\` — route it through \`subjectId\` (\`tenant_level ? null : subject_id\`) instead.`);
|
|
352
|
+
this.name = "AmbiguousLiftScope";
|
|
353
|
+
}
|
|
354
|
+
}
|
|
191
355
|
/**
|
|
192
356
|
* D239 Rule 3 — RPC method → compliance-topic verb segment. Distinct from
|
|
193
357
|
* {@link RPC_TO_VERB} (the audit-action verbs): the compliance topic verbs are
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,EAAE;AACF,mEAAmE;AACnE,EAAE;AACF,gCAAgC;AAChC,yDAAyD;AACzD,wEAAwE;AACxE,gFAAgF;AAChF,+CAA+C;AAC/C,+DAA+D;AAC/D,uDAAuD;AACvD,iEAAiE;AACjE,qDAAqD;AACrD,wCAAwC;AACxC,EAAE;AACF,qCAAqC;AACrC,mEAAmE;AACnE,+EAA+E;AAC/E,+EAA+E;AAC/E,iFAAiF;AACjF,oEAAoE;AACpE,mFAAmF;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,EAAE;AACF,mEAAmE;AACnE,EAAE;AACF,gCAAgC;AAChC,yDAAyD;AACzD,wEAAwE;AACxE,gFAAgF;AAChF,+CAA+C;AAC/C,+DAA+D;AAC/D,uDAAuD;AACvD,iEAAiE;AACjE,qDAAqD;AACrD,wCAAwC;AACxC,EAAE;AACF,qCAAq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AS,CAAC,SAAS,CAAC,6kBAA6kB,CACjqB,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAE/B;IACF,UAAU,EAAE,aAAa;IACzB,SAAS,EAAE,YAAY;IACvB,WAAW,EAAE,cAAc;IAC3B,kBAAkB,EAAE,sBAAsB;IAC1C,kBAAkB,EAAE,qBAAqB;IACzC,kBAAkB,EAAE,uBAAuB;IAC3C,iBAAiB,EAAE,uBAAuB;CAC3C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,WAAmB,EACnB,SAA2C;IAE3C,OAAO,GAAG,WAAW,eAAe,sBAAsB,CAAC,SAAS,CAAC,eAAe,CAAC;AACvF,CAAC;AA0GD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAErC;IACC,OAAO;QACL,KAAK,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE;YAC3B,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,mBAAmB,CAAC,EAAE,EAAE,sBAAsB,CAAC,CAAC;YAC5D,CAAC;YACD,MAAM,GAAG,GAAW,EAAE,QAAQ,EAAE,oBAAoB,QAAQ,EAAE,EAAE,CAAC;YACjE,IAAI,IAAI,EAAE,MAAM,KAAK,SAAS;gBAAE,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;YACzD,OAAO,GAAG,CAAC;QACb,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nodii/dsar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "GDPR Data Subject Access Request (DSAR) library for the Nodii microservice stack — 9-RPC DataLifecycleService surface with typed handler registry + DsarStore + retention policy helpers. Polyglot ship: TS + Python + Go in parity. Spec: planning hub docKey=dsar.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
|
-
"
|
|
17
|
+
"proto",
|
|
18
|
+
"README.md",
|
|
19
|
+
"src/migrations/*.sql"
|
|
18
20
|
],
|
|
19
21
|
"publishConfig": {
|
|
20
22
|
"access": "public"
|
|
@@ -30,9 +32,10 @@
|
|
|
30
32
|
"postgres": "^3.4.4"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@nodii/pii": "0.15.0",
|
|
35
|
+
"@grpc/proto-loader": "^0.7.13",
|
|
35
36
|
"@nodii/audit-chain": "0.14.0",
|
|
37
|
+
"@nodii/pii": "0.20.0",
|
|
38
|
+
"@nodii/telemetry": "0.29.0",
|
|
36
39
|
"@types/bun": "^1.3.13",
|
|
37
40
|
"typescript": "^5.9.3"
|
|
38
41
|
},
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
// DataLifecycleService — the DSAR Pattern A/B/C gRPC surface every participant
|
|
4
|
+
// host serves over its OWN data subjects, called by
|
|
5
|
+
// nodii-tenant-service.DsarOrchestratorService (11-dsar § 6 / D109).
|
|
6
|
+
// Wired via `@nodii/dsar`.bindPatternA / bindPatternB / bindPatternC — the
|
|
7
|
+
// library's `DsarServiceImpl` handler map is mounted onto this definition.
|
|
8
|
+
//
|
|
9
|
+
// ── THIS FILE IS A PER-HOST TEMPLATE, NOT A SHARED CONTRACT (D417) ──────────
|
|
10
|
+
//
|
|
11
|
+
// `DataLifecycleService` is served PER HOST under the host's OWN package —
|
|
12
|
+
// `nodii.<host>.v1.DataLifecycleService` (e.g. `nodii.billing.v1`,
|
|
13
|
+
// `nodii.crm.v1`). There is NO shared `nodii.dsar.v1.DataLifecycleService` FQN
|
|
14
|
+
// on any wire; `dataLifecycleServiceFqn(host)` in this package is the pin for
|
|
15
|
+
// that grammar.
|
|
16
|
+
//
|
|
17
|
+
// The `package nodii.dsar.v1;` line below is therefore the TEMPLATE DEFAULT,
|
|
18
|
+
// not an address. Do NOT serve this file verbatim. Materialize it for your host
|
|
19
|
+
// with `dataLifecycleProtoFor("<host>")` (ts), `data_lifecycle_proto_for()`
|
|
20
|
+
// (python) or `DataLifecycleProtoFor()` (go), each of which rewrites exactly
|
|
21
|
+
// that one line and leaves every message, field number and enum value byte-
|
|
22
|
+
// identical. Shipping the shapes ONCE, from the library that implements them, is
|
|
23
|
+
// the point: before this file was packaged, every host hand-transcribed the
|
|
24
|
+
// messages from a peer's repo and the copies drifted (drift `dc5640d1`).
|
|
25
|
+
//
|
|
26
|
+
// ── SubjectKind is the D719 set ─────────────────────────────────────────────
|
|
27
|
+
//
|
|
28
|
+
// PLATFORM_ADMIN (= 4) is REMOVED and its number is `reserved`. VENDOR (= 6) and
|
|
29
|
+
// THIRD_PARTY (= 7) are added. Numbers are NEVER reused or renumbered: a
|
|
30
|
+
// reserved 4 is what stops a future member from silently inheriting the wire
|
|
31
|
+
// meaning of a removed one, which on this enum would mis-route a subject's erase.
|
|
32
|
+
//
|
|
33
|
+
// KNOWN DIVERGENCE, stated rather than hidden: the copy vendored at
|
|
34
|
+
// `ts/grpc-interfaces/proto/nodii/dsar/v1/dsar.proto` (and its python twin)
|
|
35
|
+
// still carries the pre-D719 enum — PLATFORM_ADMIN = 4 present, 6 and 7 absent.
|
|
36
|
+
// The two files are deliberately NOT byte-identical and this one is NOT
|
|
37
|
+
// registered in `scripts/check-proto-copies.sh`'s parity sets. Reconciling
|
|
38
|
+
// grpc-interfaces is a separate change (it is a buf module with a breaking-change
|
|
39
|
+
// gate); until it lands, THIS file is the one that matches D719.
|
|
40
|
+
//
|
|
41
|
+
// Uniform envelope: every request carries (request_id, tenant_id, subject_kind,
|
|
42
|
+
// subject_id, …); the 8 lifecycle RPCs return LifecycleResponse{status, …};
|
|
43
|
+
// ListActiveHolds returns ListActiveHoldsResponse{holds}.
|
|
44
|
+
|
|
45
|
+
package nodii.dsar.v1;
|
|
46
|
+
|
|
47
|
+
import "google/protobuf/timestamp.proto";
|
|
48
|
+
|
|
49
|
+
service DataLifecycleService { // conformance:allow D417 template proto — package re-materialized per HOST (nodii.<svc>.v1); hub serves per-host packages; template namespace never dialed
|
|
50
|
+
// GDPR subject rights.
|
|
51
|
+
rpc AccessData(AccessDataRequest) returns (LifecycleResponse);
|
|
52
|
+
rpc EraseData(EraseDataRequest) returns (LifecycleResponse);
|
|
53
|
+
rpc RectifyData(RectifyDataRequest) returns (LifecycleResponse);
|
|
54
|
+
rpc ExportPortableData(ExportPortableDataRequest) returns (LifecycleResponse);
|
|
55
|
+
rpc RestrictProcessing(RestrictProcessingRequest) returns (LifecycleResponse);
|
|
56
|
+
|
|
57
|
+
// Retention hold pair.
|
|
58
|
+
rpc PlaceRetentionHold(PlaceRetentionHoldRequest) returns (LifecycleResponse);
|
|
59
|
+
rpc LiftRetentionHold(LiftRetentionHoldRequest) returns (LifecycleResponse);
|
|
60
|
+
|
|
61
|
+
// Visibility.
|
|
62
|
+
rpc GetLifecycleRequestStatus(GetLifecycleRequestStatusRequest)
|
|
63
|
+
returns (LifecycleResponse);
|
|
64
|
+
// D108 (drift 7a24d546): ListActiveHolds replaces the legacy Acknowledge.
|
|
65
|
+
rpc ListActiveHolds(ListActiveHoldsRequest) returns (ListActiveHoldsResponse);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// D719 — the canonical subject-kind set.
|
|
69
|
+
enum SubjectKind {
|
|
70
|
+
SUBJECT_KIND_UNSPECIFIED = 0;
|
|
71
|
+
SUBJECT_KIND_USER = 1;
|
|
72
|
+
SUBJECT_KIND_EMPLOYEE = 2;
|
|
73
|
+
SUBJECT_KIND_CUSTOMER = 3;
|
|
74
|
+
// 4 was SUBJECT_KIND_PLATFORM_ADMIN. REMOVED by D719 — never reuse the number.
|
|
75
|
+
reserved 4;
|
|
76
|
+
SUBJECT_KIND_TENANT = 5; // synthetic — tenant-level holds + per-tenant erase
|
|
77
|
+
SUBJECT_KIND_VENDOR = 6;
|
|
78
|
+
SUBJECT_KIND_THIRD_PARTY = 7;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
enum Status {
|
|
82
|
+
STATUS_UNSPECIFIED = 0;
|
|
83
|
+
STATUS_ACCEPTED = 1;
|
|
84
|
+
STATUS_COMPLETED = 2;
|
|
85
|
+
STATUS_NO_DATA = 3;
|
|
86
|
+
STATUS_PARTIAL = 4;
|
|
87
|
+
STATUS_FAILED = 5;
|
|
88
|
+
STATUS_HELD = 6;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ---- Request messages (RPCs 1-8) -------------------------------------------
|
|
92
|
+
|
|
93
|
+
message AccessDataRequest {
|
|
94
|
+
string request_id = 1; // UUIDv7
|
|
95
|
+
string tenant_id = 2;
|
|
96
|
+
SubjectKind subject_kind = 3;
|
|
97
|
+
string subject_id = 4;
|
|
98
|
+
string reason = 5;
|
|
99
|
+
string requested_by = 6;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
message EraseDataRequest {
|
|
103
|
+
string request_id = 1;
|
|
104
|
+
string tenant_id = 2;
|
|
105
|
+
SubjectKind subject_kind = 3;
|
|
106
|
+
string subject_id = 4;
|
|
107
|
+
string reason = 5;
|
|
108
|
+
string requested_by = 6;
|
|
109
|
+
string scope = 7; // "subject" | "tenant"
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
message RectifyDataRequest {
|
|
113
|
+
string request_id = 1;
|
|
114
|
+
string tenant_id = 2;
|
|
115
|
+
SubjectKind subject_kind = 3;
|
|
116
|
+
string subject_id = 4;
|
|
117
|
+
string reason = 5;
|
|
118
|
+
string requested_by = 6;
|
|
119
|
+
map<string, string> patches = 7;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
message ExportPortableDataRequest {
|
|
123
|
+
string request_id = 1;
|
|
124
|
+
string tenant_id = 2;
|
|
125
|
+
SubjectKind subject_kind = 3;
|
|
126
|
+
string subject_id = 4;
|
|
127
|
+
string reason = 5;
|
|
128
|
+
string requested_by = 6;
|
|
129
|
+
string region = 7; // for S3 artifact bucket selection
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
message RestrictProcessingRequest {
|
|
133
|
+
string request_id = 1;
|
|
134
|
+
string tenant_id = 2;
|
|
135
|
+
SubjectKind subject_kind = 3;
|
|
136
|
+
string subject_id = 4;
|
|
137
|
+
string reason = 5;
|
|
138
|
+
string requested_by = 6;
|
|
139
|
+
string restriction_kind = 7; // free-form
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
message PlaceRetentionHoldRequest {
|
|
143
|
+
string request_id = 1;
|
|
144
|
+
string tenant_id = 2;
|
|
145
|
+
SubjectKind subject_kind = 3;
|
|
146
|
+
string subject_id = 4;
|
|
147
|
+
string statute_citation = 5;
|
|
148
|
+
google.protobuf.Timestamp expires_at = 6;
|
|
149
|
+
string requested_by = 7;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
message LiftRetentionHoldRequest {
|
|
153
|
+
string request_id = 1;
|
|
154
|
+
string tenant_id = 2;
|
|
155
|
+
SubjectKind subject_kind = 3;
|
|
156
|
+
string subject_id = 4;
|
|
157
|
+
string justification = 5;
|
|
158
|
+
string requested_by = 6;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
message GetLifecycleRequestStatusRequest {
|
|
162
|
+
string request_id = 1;
|
|
163
|
+
string rpc_method = 2;
|
|
164
|
+
string tenant_id = 3;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ---- ListActiveHolds (D108 9th RPC — replaces Acknowledge) -----------------
|
|
168
|
+
|
|
169
|
+
message ListActiveHoldsRequest {
|
|
170
|
+
string request_id = 1;
|
|
171
|
+
string tenant_id = 2;
|
|
172
|
+
SubjectKind subject_kind = 3; // optional narrowing filter (UNSPECIFIED = any)
|
|
173
|
+
string subject_id = 4; // optional narrowing filter ("" = any)
|
|
174
|
+
string hold_kind = 5; // optional "erase" | "restrict" ("" = any)
|
|
175
|
+
string requested_by = 6;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
message ActiveHold {
|
|
179
|
+
string id = 1;
|
|
180
|
+
string tenant_id = 2;
|
|
181
|
+
string subject_id = 3; // "" / unset for tenant-level holds
|
|
182
|
+
string hold_kind = 4; // "erase" | "restrict"
|
|
183
|
+
string statute_citation = 5;
|
|
184
|
+
string placed_by = 6;
|
|
185
|
+
google.protobuf.Timestamp placed_at = 7;
|
|
186
|
+
google.protobuf.Timestamp expires_at = 8; // unset = no expiry
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
message ListActiveHoldsResponse {
|
|
190
|
+
repeated ActiveHold holds = 1;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ---- Uniform lifecycle response (8 RPCs) -----------------------------------
|
|
194
|
+
|
|
195
|
+
message LifecycleResponse {
|
|
196
|
+
string request_id = 1;
|
|
197
|
+
Status status = 2;
|
|
198
|
+
string reason = 3;
|
|
199
|
+
string result_artifact_uri = 4;
|
|
200
|
+
google.protobuf.Timestamp expires_at = 5;
|
|
201
|
+
string statute_citation = 6;
|
|
202
|
+
}
|