@nodii/dsar 0.31.0 → 0.32.1

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.
Files changed (60) hide show
  1. package/dist/bind-pattern-a.d.ts +54 -2
  2. package/dist/bind-pattern-a.d.ts.map +1 -1
  3. package/dist/bind-pattern-a.js +502 -100
  4. package/dist/bind-pattern-a.js.map +1 -1
  5. package/dist/generated/embedded-proto-source.d.ts +1 -1
  6. package/dist/generated/embedded-proto-source.d.ts.map +1 -1
  7. package/dist/generated/embedded-proto-source.js +1 -1
  8. package/dist/generated/embedded-proto-source.js.map +1 -1
  9. package/dist/generated/package-version.d.ts +1 -1
  10. package/dist/generated/package-version.js +1 -1
  11. package/dist/grpc/dsar-service.d.ts +15 -5
  12. package/dist/grpc/dsar-service.d.ts.map +1 -1
  13. package/dist/grpc/dsar-service.js +9 -3
  14. package/dist/grpc/dsar-service.js.map +1 -1
  15. package/dist/handler-status.d.ts +24 -0
  16. package/dist/handler-status.d.ts.map +1 -0
  17. package/dist/handler-status.js +37 -0
  18. package/dist/handler-status.js.map +1 -0
  19. package/dist/hold-failure-mode.d.ts +6 -0
  20. package/dist/hold-failure-mode.d.ts.map +1 -1
  21. package/dist/hold-failure-mode.js +31 -1
  22. package/dist/hold-failure-mode.js.map +1 -1
  23. package/dist/identity.d.ts +278 -0
  24. package/dist/identity.d.ts.map +1 -0
  25. package/dist/identity.js +876 -0
  26. package/dist/identity.js.map +1 -0
  27. package/dist/index.d.ts +15 -3
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +15 -3
  30. package/dist/index.js.map +1 -1
  31. package/dist/migrations/index.d.ts +9 -0
  32. package/dist/migrations/index.d.ts.map +1 -1
  33. package/dist/migrations/index.js +57 -0
  34. package/dist/migrations/index.js.map +1 -1
  35. package/dist/orchestrator.d.ts +11 -3
  36. package/dist/orchestrator.d.ts.map +1 -1
  37. package/dist/orchestrator.js +97 -20
  38. package/dist/orchestrator.js.map +1 -1
  39. package/dist/rectify.d.ts +87 -0
  40. package/dist/rectify.d.ts.map +1 -0
  41. package/dist/rectify.js +194 -0
  42. package/dist/rectify.js.map +1 -0
  43. package/dist/register.d.ts.map +1 -1
  44. package/dist/register.js +15 -2
  45. package/dist/register.js.map +1 -1
  46. package/dist/retention.d.ts.map +1 -1
  47. package/dist/retention.js +6 -2
  48. package/dist/retention.js.map +1 -1
  49. package/dist/s3-artifact.d.ts +30 -1
  50. package/dist/s3-artifact.d.ts.map +1 -1
  51. package/dist/s3-artifact.js +34 -0
  52. package/dist/s3-artifact.js.map +1 -1
  53. package/dist/types.d.ts +57 -1
  54. package/dist/types.d.ts.map +1 -1
  55. package/dist/types.js +47 -1
  56. package/dist/types.js.map +1 -1
  57. package/package.json +3 -3
  58. package/proto/nodii/dsar/v1/dsar.proto +158 -9
  59. package/src/migrations/001-lifecycle-requests.sql +81 -2
  60. package/src/migrations/002-retention-schedules-own-table-checks.sql +56 -0
@@ -21,12 +21,16 @@ import { actionName } from "./audit-actions.js";
21
21
  import { eraseShreddedCount, mergeEraseRetention, readEraseEvidence, } from "./erase-evidence.js";
22
22
  import { holdKindFromProto, subjectKindFromProto, } from "./grpc/dsar-service.js";
23
23
  import { UNKNOWN_SUBJECT_KIND_REASON, isSubjectKind, unknownSubjectKindRefusal, } from "./subject-kinds.js";
24
- import { brandHoldGateRefusal, carryHoldGateRefusalBrand, HOLD_CONSULT_FAILED_REASON, HOLD_GATE_NO_SQL_CLIENT_DETAIL, holdGateRefusalAuditPayload, resolveFailClosedHolds, } from "./hold-failure-mode.js";
24
+ import { ARTIFACT_INFRA_REFUSAL_REASONS, brandHoldGateRefusal, carryHoldGateRefusalBrand, HOLD_CONSULT_FAILED_REASON, HOLD_GATE_NO_SQL_CLIENT_DETAIL, holdGateRefusalAuditPayload, resolveFailClosedHolds, } from "./hold-failure-mode.js";
25
25
  import { HOLD_GATE_PROBE_TIMEOUT_MS, HoldGateUnreachableError, probeHoldGate, } from "./hold-gate-probe.js";
26
+ import { HANDLER_REPORTED_FAILED_REASON, mapHandlerStatus, NOT_IMPLEMENTED_REASON, } from "./handler-status.js";
26
27
  import { isHeld, isHeldInTenant, listActiveHolds } from "./holds.js";
28
+ import { bindIdentityRpcs } from "./identity.js";
29
+ import { MissingSubjectEventEmitterError, SUBJECT_RECTIFIED_EVENT_TYPE, subjectRectifiedTopic, validateRectifyPatches, } from "./rectify.js";
30
+ import { assertArtifactStore, createArtifact, PARTICIPANT_ARTIFACT_EXPIRY_SECONDS, } from "./s3-artifact.js";
27
31
  import { safeReason } from "./safe-reason.js";
28
32
  import { PostgresLifecycleRequestsStore, withLifecycleIdempotency, } from "./state-store/postgres-lifecycle.js";
29
- import { DEFAULT_ERASE_BLOCKING_HOLD_KINDS, INVALID_ERASE_SCOPE_REASON, isHoldScope, DEFAULT_PII_BUCKET, MissingOutboxEmitterError, MissingSqlClientForHoldGateError, RPC_TO_COMPLIANCE_VERB, RestrictedMarkerNotWritten, STATUTORY_ALREADY_TENANT_SHREDDED_REASON, STATUTORY_NOT_RETENTION_KEYED_REASON, STATUTORY_REKEY_IN_FLIGHT_REASON, STATUTORY_RETENTION_PARTIAL_REASON, StatutoryBucketNotRetentionKeyed, StatutoryRekeyInFlight, isPiiBucket, } from "./types.js";
33
+ import { assertStatutoryCitations, DEFAULT_ERASE_BLOCKING_HOLD_KINDS, INVALID_ERASE_SCOPE_REASON, isHoldScope, DEFAULT_PII_BUCKET, MissingOutboxEmitterError, MissingSqlClientForHoldGateError, RPC_TO_COMPLIANCE_VERB, RestrictedMarkerNotWritten, STATUTORY_ALREADY_TENANT_SHREDDED_REASON, STATUTORY_NOT_RETENTION_KEYED_REASON, STATUTORY_REKEY_IN_FLIGHT_REASON, STATUTORY_REKEY_PROBE_FAILED_REASON, STATUTORY_RETENTION_PARTIAL_REASON, StatutoryBucketNotRetentionKeyed, StatutoryRekeyInFlight, isPiiBucket, } from "./types.js";
30
34
  /**
31
35
  * Map a `LifecycleResponse.status` to the D239 compliance status.
32
36
  * COMPLETED / PARTIAL / NO_DATA → 'completed'
@@ -68,11 +72,73 @@ export function complianceStatusFor(status) {
68
72
  return "held";
69
73
  return "failed";
70
74
  }
75
+ /** An inline access/export answer, but no `artifacts` store to stage it in. */
76
+ export const ARTIFACT_STORE_NOT_CONFIGURED_REASON = "artifact_store_not_configured";
77
+ /** The tenant's CMK could not be resolved for the staged artifact. */
78
+ export const CMK_UNAVAILABLE_REASON = "cmk_unavailable";
79
+ /** The staged artifact could not be written. */
80
+ export const ARTIFACT_WRITE_FAILED_REASON = "artifact_write_failed";
81
+ /** The handler returned neither an artifact locator nor any data. */
82
+ export const NO_ARTIFACT_REASON = "no_artifact";
83
+ /** An erase the handler reported as partial, with nothing kept under statute. */
84
+ export const ERASE_PARTIAL_REASON = "erase_partial";
85
+ /** A rectify the handler reported as partial. */
86
+ export const RECTIFY_PARTIAL_REASON = "rectify_partial";
71
87
  /**
72
88
  * Bind a Pattern A service implementation.
73
89
  */
90
+ /**
91
+ * Whether a decrypted bundle's data carries anything. Not data: null, an
92
+ * empty object, map or array, an empty string. Anything else is data. The same
93
+ * rule in every port; an empty bundle is nothing to hand over (DSAR-FIX-2).
94
+ */
95
+ /**
96
+ * A handler's inline `payload` as keys: a plain object's own keys, or a Map's
97
+ * string keys. An array, typed array, class instance, string or other value
98
+ * carries no keys, the same as in Go (string-keyed maps only) and Python
99
+ * (Mapping, string keys only).
100
+ */
101
+ export function handlerPayload(v) {
102
+ if (v instanceof Map) {
103
+ const out = {};
104
+ for (const [k, val] of v)
105
+ if (typeof k === "string")
106
+ out[k] = val;
107
+ return out;
108
+ }
109
+ if (v === null || typeof v !== "object")
110
+ return {};
111
+ const proto = Object.getPrototypeOf(v);
112
+ if (proto !== Object.prototype && proto !== null)
113
+ return {};
114
+ return { ...v };
115
+ }
116
+ /**
117
+ * The `outcome` on the erase audit row of a re-key wait (ACCEPTED, retried):
118
+ * the row names the classes (D722) but is not the erase's final failure.
119
+ */
120
+ export const REKEY_WAIT_OUTCOME = "accepted_retry";
121
+ /** Whether a decrypt completed and its data holds anything (holdsData). */
122
+ function bundleHoldsData(bundle) {
123
+ return bundle?.status === "completed" && holdsData(bundle.data);
124
+ }
125
+ export function holdsData(v) {
126
+ if (v === null || v === undefined)
127
+ return false;
128
+ if (typeof v === "string")
129
+ return v.length > 0;
130
+ if (v instanceof Map)
131
+ return v.size > 0;
132
+ if (typeof v === "object")
133
+ return Object.keys(v).length > 0;
134
+ return true;
135
+ }
74
136
  export function bindPatternA(opts) {
75
- const { serviceName, handlers } = opts;
137
+ const { serviceName } = opts;
138
+ // A handler may be missing (a JS caller, or one this release added): that
139
+ // RPC then answers FAILED `not_implemented` at call time instead of
140
+ // throwing a TypeError, and the bind still succeeds (DSAR-FIX-3).
141
+ const handlers = opts.handlers ?? {};
76
142
  // B4 (request `4240382e` / drift `c117fdab`) — the SHORT service audit
77
143
  // token used ONLY for the `<svc>.dsar.<verb>_<phase>` audit-action family
78
144
  // (06-dsar § 5/§9 + 02-audit § 5). Defaults to the gRPC `serviceName` for
@@ -103,6 +169,24 @@ export function bindPatternA(opts) {
103
169
  throw new MissingSqlClientForHoldGateError(serviceName);
104
170
  }
105
171
  const sqlClient = opts.sqlClient;
172
+ // Each applied correction is announced to the services that keep copies, in
173
+ // the same transaction as the lifecycle row (DSAR-FIX-5). Same bind-time
174
+ // position and shape as the outbox check.
175
+ if (typeof opts.subjectEventEmitter !== "function") {
176
+ throw new MissingSubjectEventEmitterError(serviceName);
177
+ }
178
+ const subjectEventEmitter = opts.subjectEventEmitter;
179
+ // An artifact store that is given must be usable: a bad deployEnv would
180
+ // stage the person's data in another environment's bucket.
181
+ if (opts.artifacts !== undefined) {
182
+ assertArtifactStore(`bindPatternA(${serviceName})`, opts.artifacts);
183
+ }
184
+ const artifactStore = opts.artifacts;
185
+ // MatchSubject / VerifySubjectFactors / SendSubjectCode (DSAR-FIX-4).
186
+ const identityRpcs = bindIdentityRpcs({
187
+ sqlClient,
188
+ ...(opts.identity !== undefined ? { identity: opts.identity } : {}),
189
+ });
106
190
  // …AND IT MUST BE ABLE TO REACH THE HOLDS TABLE.
107
191
  //
108
192
  // The check above is STRUCTURAL — it proves an object with an `unsafe` method
@@ -150,12 +234,14 @@ export function bindPatternA(opts) {
150
234
  // `failClosedHolds: false` loudly here (boot), where it is visible, rather
151
235
  // than silently at request time.
152
236
  resolveFailClosedHolds(`bindPatternA(${serviceName})`, opts);
153
- const lifecycleStore = opts.sqlClient
154
- ? new PostgresLifecycleRequestsStore({
155
- sql: opts.sqlClient,
156
- tableName: opts.lifecycleTableName,
157
- })
158
- : null;
237
+ // Always present: the bind refused a missing sqlClient above
238
+ // (MissingSqlClientForHoldGateError), so every RPC runs through the
239
+ // lifecycle transaction, and a completed rectify always announces
240
+ // subject.rectified.v1 inside it (DSAR-FIX-5), as in Python and Go.
241
+ const lifecycleStore = new PostgresLifecycleRequestsStore({
242
+ sql: sqlClient,
243
+ tableName: opts.lifecycleTableName,
244
+ });
159
245
  /** See {@link complianceStatusFor} (hoisted to module scope to be testable). */
160
246
  const complianceStatus = complianceStatusFor;
161
247
  /**
@@ -164,7 +250,7 @@ export function bindPatternA(opts) {
164
250
  * verb (RPC_TO_COMPLIANCE_VERB). The proto subject-kind string is upper-cased
165
251
  * to the canonical `USER` / `CUSTOMER` / … form for the event.
166
252
  */
167
- const buildComplianceEvent = (rpcMethod, env, response, dataClasses) => {
253
+ const buildComplianceEvent = (rpcMethod, env, response, dataClasses, restrictionKind) => {
168
254
  const status = complianceStatus(response.status);
169
255
  const event = {
170
256
  rpcMethod,
@@ -196,6 +282,9 @@ export function bindPatternA(opts) {
196
282
  }
197
283
  if (response.shredded_count !== undefined)
198
284
  event.shreddedCount = response.shredded_count;
285
+ if (restrictionKind !== undefined && restrictionKind !== "") {
286
+ event.restrictionKind = restrictionKind;
287
+ }
199
288
  return event;
200
289
  };
201
290
  /**
@@ -217,7 +306,7 @@ export function bindPatternA(opts) {
217
306
  * (harmless — the assertions use `toContain`); tx-aware emitters should
218
307
  * treat the `tx`-carrying call as the durable terminal row.
219
308
  */
220
- const makeInTxHook = (rpcMethod, env, dataClasses) => async (tx, response) => {
309
+ const makeInTxHook = (rpcMethod, env, dataClasses, extra) => async (tx, response) => {
221
310
  // D720 — the RESTRICTED marker joins the SAME tx as the lifecycle row,
222
311
  // the compliance event and the terminal audit. A retained-statutory erase
223
312
  // whose marker was lost to a partial commit reads, on the next audit, as
@@ -227,8 +316,26 @@ export function bindPatternA(opts) {
227
316
  response.retained_classes.length > 0) {
228
317
  await markRestricted(tx, env);
229
318
  }
230
- const event = buildComplianceEvent(rpcMethod, env, response, dataClasses);
319
+ const event = buildComplianceEvent(rpcMethod, env, response, dataClasses, extra?.restrictionKind);
231
320
  await outboxEmitter(tx, event);
321
+ // DSAR-FIX-5 — an applied correction is announced in the same tx. Field
322
+ // names only; the values never leave the handler.
323
+ if (rpcMethod === "RectifyData" &&
324
+ extra?.rectifiedFields !== undefined &&
325
+ (response.status === "COMPLETED" || response.status === "PARTIAL")) {
326
+ await subjectEventEmitter(tx, {
327
+ eventType: SUBJECT_RECTIFIED_EVENT_TYPE,
328
+ topic: subjectRectifiedTopic(serviceName),
329
+ requestId: env.request_id,
330
+ tenantId: env.tenant_id,
331
+ subjectKind: String(env.subject_kind).toUpperCase(),
332
+ subjectId: env.subject_id,
333
+ // The corrected fields; for a PARTIAL, the requested ones (the
334
+ // handler does not say which landed), so replica owners refetch them.
335
+ fields: [...extra.rectifiedFields],
336
+ rectifiedAt: new Date().toISOString(),
337
+ });
338
+ }
232
339
  await emitTerminalAudit(tx, rpcMethod, env, response);
233
340
  };
234
341
  const emitAudit = async (rpcMethod, phase, tenantId, subjectId, payload) => {
@@ -271,10 +378,6 @@ export function bindPatternA(opts) {
271
378
  const tenantId = String(request.tenant_id ?? "");
272
379
  const subjectKind = subjectKindFromProto(request.subject_kind);
273
380
  const subjectId = String(request.subject_id ?? "");
274
- if (!lifecycleStore) {
275
- // No persistence; just run handler.
276
- return handler();
277
- }
278
381
  return withLifecycleIdempotency(lifecycleStore, {
279
382
  request_id: requestId,
280
383
  rpc_method: rpcMethod,
@@ -315,6 +418,9 @@ export function bindPatternA(opts) {
315
418
  !opts.retention?.dataSubjectsTableName) {
316
419
  throw new Error(`bindPatternA({ serviceName: ${JSON.stringify(serviceName)} }): retention.dataClasses declares statutory class(es) [${declaredStatutoryClasses.join(", ")}] but no \`retention.dataSubjectsTableName\`. D720 requires the RESTRICTED marker (\`restricted_at\`) to be stamped on <svc>_data_subjects in the same tx as the erase — a statutory retention with no marker leaves no durable record that the subject was erased as far as the law allows.`);
317
420
  }
421
+ // DSAR-FIX-6 — a statutory class must name the law it is kept under: the
422
+ // held-erasure notice quotes it to the person.
423
+ assertStatutoryCitations("bindPatternA", serviceName, opts.retention?.dataClasses ?? []);
318
424
  const dataSubjectsTableName = opts.retention?.dataSubjectsTableName;
319
425
  if (dataSubjectsTableName !== undefined &&
320
426
  !/^[a-z_][a-z0-9_]*$/.test(dataSubjectsTableName)) {
@@ -509,28 +615,32 @@ export function bindPatternA(opts) {
509
615
  // Fail-CLOSED, for the same reason the hold gate and the keying gate do:
510
616
  // we cannot show the statutory data is safe, and the operation is
511
617
  // irreversible.
618
+ // FAILED with its own reason, not the ACCEPTED re-key wait: a broken
619
+ // probe is a fault to see, not work in progress. The brand keeps the
620
+ // lifecycle wrap from memoizing it, so a retry after the fix re-runs.
512
621
  return {
513
622
  kind: "refuse",
514
623
  classes: declaredStatutoryClasses,
515
- response: {
624
+ response: brandHoldGateRefusal({
516
625
  request_id: env.request_id,
517
626
  status: "FAILED",
518
- reason: STATUTORY_REKEY_IN_FLIGHT_REASON,
627
+ reason: STATUTORY_REKEY_PROBE_FAILED_REASON,
519
628
  retention_gate_error: err instanceof Error ? err.message : String(err),
520
- },
629
+ }),
521
630
  };
522
631
  }
523
632
  if (inFlight.length === 0)
524
633
  return { kind: "retain" };
634
+ // ACCEPTED + branded: a wait, not an answer (see above).
525
635
  return {
526
636
  kind: "refuse",
527
637
  classes: inFlight,
528
- response: {
638
+ response: brandHoldGateRefusal({
529
639
  request_id: env.request_id,
530
- status: "FAILED",
640
+ status: "ACCEPTED",
531
641
  reason: STATUTORY_REKEY_IN_FLIGHT_REASON,
532
642
  retention_gate_error: new StatutoryRekeyInFlight(serviceName, env.tenant_id, inFlight).message,
533
- },
643
+ }),
534
644
  };
535
645
  };
536
646
  /**
@@ -686,9 +796,174 @@ export function bindPatternA(opts) {
686
796
  reason: String(request.reason ?? ""),
687
797
  requested_by: String(request.requested_by ?? ""),
688
798
  });
799
+ /**
800
+ * FAILED `not_implemented` for an RPC whose handler was not bound. Nothing
801
+ * is persisted (a retry after the handler is deployed runs normally); the
802
+ * refusal leaves a best-effort failed audit row.
803
+ */
804
+ const notImplemented = async (rpcMethod, env) => {
805
+ try {
806
+ await emitAudit(rpcMethod, "failed", env.tenant_id, env.subject_id, {
807
+ refusal_reason: NOT_IMPLEMENTED_REASON,
808
+ });
809
+ }
810
+ catch {
811
+ // Audit is evidence of the refusal, not the refusal itself.
812
+ }
813
+ return {
814
+ request_id: env.request_id,
815
+ status: "FAILED",
816
+ reason: NOT_IMPLEMENTED_REASON,
817
+ };
818
+ };
819
+ /**
820
+ * DSAR-FIX-2 — turn an access / portability answer into an artifact
821
+ * locator, or a refusal token. Never COMPLETED without an artifact:
822
+ * 1. the handler's own `result_artifact_uri` wins;
823
+ * 2. else a non-empty inline payload is staged through `artifacts`
824
+ * (`s3://<staging bucket>/{tenant}/{request_id}/<kind>.json`, tenant
825
+ * CMK, one-day expiry);
826
+ * 3. else `no_artifact`.
827
+ */
828
+ const resolveArtifact = async (kind, env, region, handlerUri, payload) => {
829
+ if (typeof handlerUri === "string" && handlerUri !== "") {
830
+ return { ok: true, uri: handlerUri };
831
+ }
832
+ if (Object.keys(payload).length === 0) {
833
+ return { ok: false, reason: NO_ARTIFACT_REASON };
834
+ }
835
+ if (!artifactStore) {
836
+ return { ok: false, reason: ARTIFACT_STORE_NOT_CONFIGURED_REASON };
837
+ }
838
+ // A lookup that throws, even synchronously, is no CMK.
839
+ const kmsKeyId = await Promise.resolve()
840
+ .then(() => artifactStore.cmkLookup.resolveCmk({ tenantId: env.tenant_id }))
841
+ .then((ref) => (typeof ref?.kmsKeyId === "string" ? ref.kmsKeyId : ""), () => "");
842
+ if (kmsKeyId === "")
843
+ return { ok: false, reason: CMK_UNAVAILABLE_REASON };
844
+ try {
845
+ const artifact = await createArtifact({
846
+ s3Client: artifactStore.s3Client,
847
+ tenantId: env.tenant_id,
848
+ subjectId: env.subject_id,
849
+ subjectKind: env.subject_kind,
850
+ kind,
851
+ payload,
852
+ region,
853
+ requestId: env.request_id,
854
+ // The service in the key: every sibling stages under the same
855
+ // tenant and request_id in one shared staging bucket, so without it
856
+ // the last writer would overwrite the others.
857
+ filename: `${serviceName}/${kind}`,
858
+ kmsKeyId,
859
+ staging: true,
860
+ deployEnv: artifactStore.deployEnv,
861
+ expirySeconds: PARTICIPANT_ARTIFACT_EXPIRY_SECONDS,
862
+ presignDownload: false,
863
+ ...(artifactStore.bucketName !== undefined
864
+ ? { bucketName: artifactStore.bucketName }
865
+ : {}),
866
+ ...(artifactStore.serializer !== undefined
867
+ ? { serializer: artifactStore.serializer }
868
+ : {}),
869
+ ...(artifactStore.objectLock !== undefined
870
+ ? { objectLock: artifactStore.objectLock }
871
+ : {}),
872
+ });
873
+ // An s3://bucket/key pointer the orchestrator can read (DSAR-FIX-71);
874
+ // never a presigned URL.
875
+ return {
876
+ ok: true,
877
+ uri: `s3://${artifact.bucket}/${artifact.key}`,
878
+ expiresAt: artifact.expiresAt,
879
+ };
880
+ }
881
+ catch {
882
+ return { ok: false, reason: ARTIFACT_WRITE_FAILED_REASON };
883
+ }
884
+ };
885
+ /**
886
+ * The shared tail of access + portability: map the handler's status, then
887
+ * resolve the artifact for a COMPLETED / PARTIAL answer.
888
+ */
889
+ const finishExport = async (rpcMethod, kind, env, region, result, payload, auditExtra,
890
+ // Whether the library's own decrypted pii bundle holds the subject's
891
+ // fields. Decided from the bundle, never from `payload`, where a handler
892
+ // may have put a `decrypted` key of its own.
893
+ libraryHolds) => {
894
+ const mapped = mapHandlerStatus(result?.status);
895
+ if (mapped.wire === "FAILED") {
896
+ await emitAudit(rpcMethod, "failed", env.tenant_id, env.subject_id, {
897
+ refusal_reason: mapped.reason,
898
+ });
899
+ return {
900
+ request_id: env.request_id,
901
+ status: "FAILED",
902
+ reason: mapped.reason,
903
+ };
904
+ }
905
+ // The library's own encrypted fields for the subject (the decrypted pii
906
+ // bundle) are data to hand over, whatever the handler holds itself.
907
+ if (mapped.wire === "NO_DATA" && !libraryHolds) {
908
+ await emitAudit(rpcMethod, "completed", env.tenant_id, env.subject_id, {
909
+ ...auditExtra,
910
+ has_artifact: false,
911
+ no_data: true,
912
+ });
913
+ return { request_id: env.request_id, status: "NO_DATA", reason: "" };
914
+ }
915
+ // A handler that returns its own locator owns the export: it was handed
916
+ // the decrypted bundle (one decrypt, drift 0b480ce1) and built its file
917
+ // from it, so that locator is the answer and nothing more is staged.
918
+ const handlerUri = typeof result?.result_artifact_uri === "string"
919
+ ? result.result_artifact_uri
920
+ : undefined;
921
+ const artifact = await resolveArtifact(kind, env, region, handlerUri, payload);
922
+ if (!artifact.ok) {
923
+ const infra = ARTIFACT_INFRA_REFUSAL_REASONS.includes(artifact.reason);
924
+ try {
925
+ await emitAudit(rpcMethod, "failed", env.tenant_id, env.subject_id, {
926
+ refusal_reason: artifact.reason,
927
+ });
928
+ }
929
+ catch (err) {
930
+ // On a store / CMK fault the audit row is evidence of the refusal, not
931
+ // the refusal itself: a failed audit must not turn the retryable
932
+ // refusal into a memoized FAILED. Any other refusal still fails loud.
933
+ if (!infra)
934
+ throw err;
935
+ }
936
+ const refusal = {
937
+ request_id: env.request_id,
938
+ status: "FAILED",
939
+ reason: artifact.reason,
940
+ };
941
+ // A store / CMK fault is not the answer: branded so the lifecycle wrap
942
+ // does not memoize it and the retry runs again (no_artifact stays).
943
+ return infra ? brandHoldGateRefusal(refusal) : refusal;
944
+ }
945
+ // The locator (a staging key or URL) is NEVER audited (doctrine § 7.5) —
946
+ // only the fact that one was produced.
947
+ await emitAudit(rpcMethod, "completed", env.tenant_id, env.subject_id, {
948
+ ...auditExtra,
949
+ has_artifact: true,
950
+ });
951
+ return {
952
+ request_id: env.request_id,
953
+ status: mapped.wire === "NO_DATA" ? "COMPLETED" : mapped.wire,
954
+ reason: mapped.reason,
955
+ result_artifact_uri: artifact.uri,
956
+ ...(artifact.expiresAt !== undefined
957
+ ? { expires_at: artifact.expiresAt }
958
+ : {}),
959
+ };
960
+ };
689
961
  // ---- 5 GDPR-right handlers ----
690
962
  const accessHandler = async (request) => {
691
963
  const env = envelope(request);
964
+ const access = handlers.access;
965
+ if (typeof access !== "function")
966
+ return notImplemented("AccessData", env);
692
967
  // bc646e4e gap 3 — Access carries a region (per-region staging bucket is
693
968
  // mandated for BOTH Access and Portability per billing spec 505b8c66 [6]).
694
969
  // Resolved from tenant residency by the orchestrator / consumer;
@@ -697,14 +972,11 @@ export function bindPatternA(opts) {
697
972
  return runWithIdempotency("AccessData", request, async () => {
698
973
  await emitAudit("AccessData", "requested", env.tenant_id, env.subject_id);
699
974
  try {
700
- // pii integration: pre-decrypt for export when adapter present. The
701
- // bytes are materialized into the S3 artifact (createArtifact) by the
702
- // consumer handler; the LifecycleResponse carries only the locator.
703
- // SINGLE decrypt (drift 0b480ce1): decrypt once HERE + hand the bundle
704
- // to the handler so it materializes the disclosure WITHOUT a second
705
- // decryptForExport (which would double-bill KMS + write a duplicate
706
- // Pattern-C decrypt-audit row). bundle is undefined when no pii adapter
707
- // is wired — the handler then sources the data itself (back-compat).
975
+ // SINGLE decrypt (drift 0b480ce1): decrypt once HERE + hand the
976
+ // bundle to the handler so it materializes the disclosure WITHOUT a
977
+ // second decryptForExport (which would double-bill KMS + write a
978
+ // duplicate Pattern-C decrypt-audit row). bundle is undefined when no
979
+ // pii adapter is wired — the handler then sources the data itself.
708
980
  let bundle;
709
981
  if (opts.pii) {
710
982
  bundle = await opts.pii.decryptForExport({
@@ -713,23 +985,20 @@ export function bindPatternA(opts) {
713
985
  subjectKind: env.subject_kind,
714
986
  });
715
987
  }
716
- const result = await handlers.access({ ...env, region, bundle });
717
- await emitAudit("AccessData", "completed", env.tenant_id, env.subject_id,
718
- // result_artifact_uri (a presigned URL / staging key) is NEVER
719
- // audited per doctrine § 7.5 — only the fact that one was produced.
720
- { has_artifact: result.result_artifact_uri !== undefined });
721
- // bc646e4e gap 1 — propagate the handler's artifact locator onto the
722
- // LifecycleResponse (mirrors how eraseHandler reads result.artifactId).
723
- // The old binding discarded the return + hard-coded an empty URI,
724
- // silently producing disclosure-without-locator.
725
- return {
726
- request_id: env.request_id,
727
- status: "COMPLETED",
728
- reason: "",
729
- ...(result.result_artifact_uri !== undefined
730
- ? { result_artifact_uri: result.result_artifact_uri }
731
- : {}),
988
+ const result = await access.call(handlers, {
989
+ ...env,
990
+ region,
991
+ bundle,
992
+ });
993
+ // The inline answer: whatever the handler returned plus the decrypted
994
+ // bundle, applied LAST so a handler key cannot replace the subject's
995
+ // library-held fields. Staged when the handler gave no locator.
996
+ const libraryHolds = bundleHoldsData(bundle);
997
+ const payload = {
998
+ ...handlerPayload(result?.payload),
999
+ ...(libraryHolds ? { decrypted: bundle?.data } : {}),
732
1000
  };
1001
+ return await finishExport("AccessData", "access", env, region, result, payload, {}, libraryHolds);
733
1002
  }
734
1003
  catch (err) {
735
1004
  await emitAudit("AccessData", "failed", env.tenant_id, env.subject_id, {
@@ -745,6 +1014,9 @@ export function bindPatternA(opts) {
745
1014
  };
746
1015
  const eraseHandler = async (request) => {
747
1016
  const env = envelope(request);
1017
+ const erase = handlers.erase;
1018
+ if (typeof erase !== "function")
1019
+ return notImplemented("EraseData", env);
748
1020
  // An absent scope is one person's erase. Any other value is refused, so a
749
1021
  // misspelt "tenant" cannot quietly run as a subject erase.
750
1022
  const requestedScope = request.scope ?? "";
@@ -829,9 +1101,15 @@ export function bindPatternA(opts) {
829
1101
  verdict = await checkRekeyInFlight(env);
830
1102
  }
831
1103
  if (verdict.kind === "refuse") {
1104
+ // D722 keeps a row naming the classes. A re-key in flight answers
1105
+ // ACCEPTED and is retried, so its row says so (`outcome`): it is a
1106
+ // wait, not this erase's final failure.
832
1107
  await emitAudit("EraseData", "failed", env.tenant_id, env.subject_id, {
833
1108
  error: verdict.response.retention_gate_error,
834
1109
  statutory_classes: verdict.classes ?? retained,
1110
+ ...(verdict.response.status === "ACCEPTED"
1111
+ ? { outcome: REKEY_WAIT_OUTCOME }
1112
+ : {}),
835
1113
  });
836
1114
  return verdict.response;
837
1115
  }
@@ -868,13 +1146,46 @@ export function bindPatternA(opts) {
868
1146
  : [];
869
1147
  const handlerDestroy = scope === "tenant" ? [...destroyed, ...retained] : destroyed;
870
1148
  const classSelection = dataClasses.length > 0 ? "explicit" : "all";
871
- const result = await handlers.erase({
1149
+ const result = await erase.call(handlers, {
872
1150
  ...env,
873
1151
  scope,
874
1152
  data_classes: handlerDestroy,
875
1153
  retained_classes: handlerRetained,
876
1154
  class_selection: classSelection,
877
1155
  });
1156
+ // DSAR-FIX-3 — the handler's own word decides the status. A
1157
+ // reported failure is FAILED, whatever was shredded before it.
1158
+ const mapped = mapHandlerStatus(result?.status);
1159
+ if (mapped.wire === "FAILED") {
1160
+ // A failed erase may already have destroyed data: the audit row
1161
+ // records what the handler reports it shredded, so the record is
1162
+ // whole even though the request failed.
1163
+ const failedEvidence = {
1164
+ artifactId: result
1165
+ ?.artifactId,
1166
+ ...readEraseEvidence(result),
1167
+ };
1168
+ const failedShredded = eraseShreddedCount(failedEvidence.shreddedCount);
1169
+ await emitAudit("EraseData", "failed", env.tenant_id, env.subject_id, {
1170
+ refusal_reason: mapped.reason,
1171
+ scope,
1172
+ artifactId: failedEvidence.artifactId,
1173
+ // What it was told to destroy; shredded_count is the evidence
1174
+ // of what it did.
1175
+ requested_classes: handlerDestroy,
1176
+ ...(failedShredded !== undefined
1177
+ ? { shredded_count: failedShredded }
1178
+ : {}),
1179
+ });
1180
+ return {
1181
+ request_id: env.request_id,
1182
+ status: "FAILED",
1183
+ reason: mapped.reason,
1184
+ ...(failedShredded !== undefined
1185
+ ? { shredded_count: failedShredded }
1186
+ : {}),
1187
+ };
1188
+ }
878
1189
  // What the SUBJECT is told. Diverges from what the HANDLER is told in
879
1190
  // the already-shredded case: the handler must still not delete those
880
1191
  // rows, but promising the subject they "survive under statute" when
@@ -902,13 +1213,22 @@ export function bindPatternA(opts) {
902
1213
  await emitAudit("EraseData", "completed", env.tenant_id, env.subject_id, {
903
1214
  scope,
904
1215
  artifactId: evidence.artifactId,
905
- destroyed_classes: handlerDestroy,
1216
+ // A handler that said partial or no_data did not destroy all it
1217
+ // was told to: record what it was told, not "destroyed".
1218
+ ...(mapped.wire === "PARTIAL" || mapped.wire === "NO_DATA"
1219
+ ? { requested_classes: handlerDestroy }
1220
+ : { destroyed_classes: handlerDestroy }),
906
1221
  ...(retainedClasses.length > 0
907
1222
  ? { retained_classes: retainedClasses }
908
1223
  : {}),
909
1224
  ...(alreadyErasedClasses.length > 0
910
1225
  ? { statutory_already_erased: alreadyErasedClasses }
911
1226
  : {}),
1227
+ // DSAR-FIX-3 — what the handler said, so a partial or no-data
1228
+ // erase is not recorded as a whole one.
1229
+ ...(mapped.wire === "PARTIAL" || mapped.wire === "NO_DATA"
1230
+ ? { handler_status: mapped.wire.toLowerCase() }
1231
+ : {}),
912
1232
  });
913
1233
  if (retainedClasses.length > 0) {
914
1234
  // A reasoned PARTIAL refusal: the operational + free_text buckets
@@ -916,14 +1236,52 @@ export function bindPatternA(opts) {
916
1236
  // classifies as `completed` in the D239 compliance vocabulary
917
1237
  // (complianceStatusFor) — the participant discharged the obligation
918
1238
  // as far as the law permits, which is what it is obliged to do.
1239
+ // If the handler itself says partial, it did not destroy all it
1240
+ // was told to: erase_partial, not "only the statutory ones survive".
919
1241
  return {
920
1242
  request_id: env.request_id,
921
1243
  ...(shreddedCount === undefined
922
1244
  ? {}
923
1245
  : { shredded_count: shreddedCount }),
924
1246
  status: "PARTIAL",
925
- reason: STATUTORY_RETENTION_PARTIAL_REASON,
1247
+ reason: mapped.wire === "PARTIAL"
1248
+ ? ERASE_PARTIAL_REASON
1249
+ : STATUTORY_RETENTION_PARTIAL_REASON,
926
1250
  retained_classes: retainedClasses,
1251
+ ...(alreadyErasedClasses.length > 0
1252
+ ? { statutory_already_erased: alreadyErasedClasses }
1253
+ : {}),
1254
+ };
1255
+ }
1256
+ if (mapped.wire === "PARTIAL") {
1257
+ return {
1258
+ request_id: env.request_id,
1259
+ ...(shreddedCount === undefined
1260
+ ? {}
1261
+ : { shredded_count: shreddedCount }),
1262
+ status: "PARTIAL",
1263
+ reason: ERASE_PARTIAL_REASON,
1264
+ ...(alreadyErasedClasses.length > 0
1265
+ ? { statutory_already_erased: alreadyErasedClasses }
1266
+ : {}),
1267
+ };
1268
+ }
1269
+ // A tenant-wide erase with `pii` wired always destroyed the tenant
1270
+ // key, so a handler's no_data is not "nothing to erase" there (the
1271
+ // audit row keeps handler_status: "no_data"). A per-subject shred
1272
+ // reports nothing about whether a key existed, so it stays NO_DATA.
1273
+ if (mapped.wire === "NO_DATA" && !(opts.pii && scope === "tenant")) {
1274
+ // The handler held nothing to erase, and nothing was kept.
1275
+ return {
1276
+ request_id: env.request_id,
1277
+ ...(shreddedCount === undefined
1278
+ ? {}
1279
+ : { shredded_count: shreddedCount }),
1280
+ status: "NO_DATA",
1281
+ reason: "",
1282
+ ...(alreadyErasedClasses.length > 0
1283
+ ? { statutory_already_erased: alreadyErasedClasses }
1284
+ : {}),
927
1285
  };
928
1286
  }
929
1287
  if (alreadyErasedClasses.length > 0) {
@@ -964,29 +1322,68 @@ export function bindPatternA(opts) {
964
1322
  };
965
1323
  const rectifyHandler = async (request) => {
966
1324
  const env = envelope(request);
967
- const patches = (request.patches ?? {});
1325
+ const rectify = handlers.rectify;
1326
+ if (typeof rectify !== "function")
1327
+ return notImplemented("RectifyData", env);
1328
+ // DSAR-FIX-5 — the fixed field list is checked BEFORE the idempotency wrap
1329
+ // and the handler, the way erase checks `scope`: an unknown field or an
1330
+ // empty request is refused, audited, and never reaches the handler.
1331
+ const checked = validateRectifyPatches(request.patches);
1332
+ if (checked.outcome === "failed") {
1333
+ try {
1334
+ await emitAudit("RectifyData", "failed", env.tenant_id, env.subject_id, {
1335
+ refusal_reason: checked.reason,
1336
+ });
1337
+ }
1338
+ catch {
1339
+ // Audit is evidence of the refusal, not the refusal itself.
1340
+ }
1341
+ return {
1342
+ request_id: env.request_id,
1343
+ status: "FAILED",
1344
+ reason: checked.reason,
1345
+ };
1346
+ }
1347
+ const { fields, patches } = checked;
968
1348
  return runWithIdempotency("RectifyData", request, async () => {
969
1349
  await emitAudit("RectifyData", "requested", env.tenant_id, env.subject_id);
970
1350
  try {
971
- const result = await handlers.rectify({ ...env, patches });
972
- // bc646e4e gap 4 — surface the handler's return. A handler that could
973
- // only partially apply corrections (e.g. PGW unreachable mid-rectify)
974
- // reports `status:'partial'`; we map it to the PARTIAL wire status so
975
- // the orchestrator records partial completion rather than a fake
976
- // success. `corrections_applied` reaches the wire either way (billing
977
- // spec 505b8c66 § RectifyData [4]).
978
- const isPartial = result.status?.toLowerCase() === "partial";
979
- await emitAudit(isPartial ? "RectifyData" : "RectifyData", isPartial ? "failed" : "completed", env.tenant_id, env.subject_id, {
980
- corrections_applied: result.corrections_applied ?? 0,
981
- partial: isPartial,
1351
+ const result = await rectify.call(handlers, { ...env, patches });
1352
+ // bc646e4e gap 4 + DSAR-FIX-3 — the handler's status decides the
1353
+ // wire status. An explicit `corrections_applied: 0` means nothing
1354
+ // was changed: NO_DATA, never a fake COMPLETED.
1355
+ const mapped = mapHandlerStatus(result?.status);
1356
+ const applied = result?.corrections_applied;
1357
+ let status = mapped.wire;
1358
+ let reason = mapped.reason;
1359
+ // Only a COMPLETED answer: a `partial` with nothing applied is a
1360
+ // correction that failed, not "nothing to correct".
1361
+ if (status === "COMPLETED" && applied === 0) {
1362
+ status = "NO_DATA";
1363
+ reason = "";
1364
+ }
1365
+ // A partial that applied nothing failed: no subject.rectified.v1 for
1366
+ // fields that never changed.
1367
+ if (status === "PARTIAL" && applied === 0) {
1368
+ status = "FAILED";
1369
+ reason = HANDLER_REPORTED_FAILED_REASON;
1370
+ }
1371
+ if (status === "PARTIAL")
1372
+ reason = RECTIFY_PARTIAL_REASON;
1373
+ await emitAudit("RectifyData", status === "COMPLETED" || status === "NO_DATA"
1374
+ ? "completed"
1375
+ : "failed", env.tenant_id, env.subject_id, {
1376
+ corrections_applied: applied ?? 0,
1377
+ partial: status === "PARTIAL",
1378
+ // Field names only, never values.
1379
+ fields,
1380
+ ...(status === "FAILED" ? { refusal_reason: reason } : {}),
982
1381
  });
983
1382
  return {
984
1383
  request_id: env.request_id,
985
- status: isPartial ? "PARTIAL" : "COMPLETED",
986
- reason: isPartial ? "rectify_partial" : "",
987
- ...(result.corrections_applied !== undefined
988
- ? { corrections_applied: result.corrections_applied }
989
- : {}),
1384
+ status,
1385
+ reason,
1386
+ ...(applied !== undefined ? { corrections_applied: applied } : {}),
990
1387
  };
991
1388
  }
992
1389
  catch (err) {
@@ -997,10 +1394,14 @@ export function bindPatternA(opts) {
997
1394
  reason: safeReason(err),
998
1395
  };
999
1396
  }
1000
- }, makeInTxHook("RectifyData", env, undefined));
1397
+ }, makeInTxHook("RectifyData", env, undefined, { rectifiedFields: fields }));
1001
1398
  };
1002
1399
  const portabilityHandler = async (request) => {
1003
1400
  const env = envelope(request);
1401
+ const portability = handlers.portability;
1402
+ if (typeof portability !== "function") {
1403
+ return notImplemented("ExportPortableData", env);
1404
+ }
1004
1405
  const region = String(request.region ?? process.env.AWS_REGION ?? "us-east-1");
1005
1406
  return runWithIdempotency("ExportPortableData", request, async () => {
1006
1407
  await emitAudit("ExportPortableData", "started", env.tenant_id, env.subject_id);
@@ -1016,29 +1417,22 @@ export function bindPatternA(opts) {
1016
1417
  subjectId: env.subject_id,
1017
1418
  subjectKind: env.subject_kind,
1018
1419
  });
1019
- if (bundle.status === "completed") {
1420
+ if (bundleHoldsData(bundle)) {
1020
1421
  payload = { decrypted: bundle.data };
1021
1422
  }
1022
1423
  }
1023
- const result = await handlers.portability({ ...env, region, bundle });
1424
+ const result = await portability.call(handlers, {
1425
+ ...env,
1426
+ region,
1427
+ bundle,
1428
+ });
1429
+ // The library's decrypted bundle (in `payload`) is applied LAST so a
1430
+ // handler key cannot replace the subject's library-held fields.
1024
1431
  const finalPayload = {
1432
+ ...handlerPayload(result?.payload),
1025
1433
  ...(payload ?? {}),
1026
- ...(result.payload ?? {}),
1027
- };
1028
- await emitAudit("ExportPortableData", "completed", env.tenant_id, env.subject_id, {
1029
- size: JSON.stringify(finalPayload).length,
1030
- // presigned URL / staging key NEVER audited (doctrine § 7.5).
1031
- has_artifact: result.result_artifact_uri !== undefined,
1032
- });
1033
- // bc646e4e gap 1 — propagate the export locator onto LifecycleResponse.
1034
- return {
1035
- request_id: env.request_id,
1036
- status: "COMPLETED",
1037
- reason: "",
1038
- ...(result.result_artifact_uri !== undefined
1039
- ? { result_artifact_uri: result.result_artifact_uri }
1040
- : {}),
1041
1434
  };
1435
+ return await finishExport("ExportPortableData", "portability", env, region, result, finalPayload, { size: JSON.stringify(finalPayload).length }, bundleHoldsData(bundle));
1042
1436
  }
1043
1437
  catch (err) {
1044
1438
  await emitAudit("ExportPortableData", "failed", env.tenant_id, env.subject_id, { error: err instanceof Error ? err.message : String(err) });
@@ -1052,6 +1446,12 @@ export function bindPatternA(opts) {
1052
1446
  };
1053
1447
  const restrictHandler = async (request) => {
1054
1448
  const env = envelope(request);
1449
+ const restrict = handlers.restrict;
1450
+ if (typeof restrict !== "function") {
1451
+ return notImplemented("RestrictProcessing", env);
1452
+ }
1453
+ // Passed through unchanged: "consent_withdrawn" is the one fixed value
1454
+ // (RESTRICTION_KIND_CONSENT_WITHDRAWN); any other is a general restriction.
1055
1455
  const restrictionKind = String(request.restriction_kind ?? "");
1056
1456
  return runWithIdempotency("RestrictProcessing", request, async () => {
1057
1457
  const held = await checkHold(env.tenant_id, env.subject_id, "restrict", undefined);
@@ -1079,15 +1479,21 @@ export function bindPatternA(opts) {
1079
1479
  });
1080
1480
  }
1081
1481
  try {
1082
- await handlers.restrict({
1482
+ const result = await restrict.call(handlers, {
1083
1483
  ...env,
1084
1484
  restriction_kind: restrictionKind,
1085
1485
  });
1086
- await emitAudit("RestrictProcessing", "completed", env.tenant_id, env.subject_id, { restriction_kind: restrictionKind });
1486
+ const mapped = mapHandlerStatus(result?.status);
1487
+ await emitAudit("RestrictProcessing", mapped.wire === "FAILED" ? "failed" : "completed", env.tenant_id, env.subject_id, {
1488
+ restriction_kind: restrictionKind,
1489
+ ...(mapped.wire === "FAILED"
1490
+ ? { refusal_reason: mapped.reason }
1491
+ : {}),
1492
+ });
1087
1493
  return {
1088
1494
  request_id: env.request_id,
1089
- status: "COMPLETED",
1090
- reason: "",
1495
+ status: mapped.wire,
1496
+ reason: mapped.reason,
1091
1497
  };
1092
1498
  }
1093
1499
  catch (err) {
@@ -1097,7 +1503,7 @@ export function bindPatternA(opts) {
1097
1503
  reason: safeReason(err),
1098
1504
  };
1099
1505
  }
1100
- }, makeInTxHook("RestrictProcessing", env, undefined));
1506
+ }, makeInTxHook("RestrictProcessing", env, undefined, { restrictionKind }));
1101
1507
  };
1102
1508
  // ---- retention holds ----
1103
1509
  const placeHoldHandler = async (request) => {
@@ -1238,13 +1644,6 @@ export function bindPatternA(opts) {
1238
1644
  const statusHandler = async (request) => {
1239
1645
  const requestId = String(request.request_id ?? "");
1240
1646
  const rpcMethod = String(request.rpc_method ?? "");
1241
- if (!lifecycleStore) {
1242
- return {
1243
- request_id: requestId,
1244
- status: "UNSPECIFIED",
1245
- reason: "no_store_configured",
1246
- };
1247
- }
1248
1647
  const existing = await lifecycleStore.fetchExisting(requestId, rpcMethod);
1249
1648
  if (!existing) {
1250
1649
  return {
@@ -1394,9 +1793,12 @@ export function bindPatternA(opts) {
1394
1793
  // exactly the rows an operator is trying to find while cleaning up.
1395
1794
  GetLifecycleRequestStatus: statusHandler,
1396
1795
  ListActiveHolds: listActiveHoldsHandler,
1796
+ // DSAR-FIX-4 — the identity RPCs guard the subject kind themselves (their
1797
+ // refusal is their own response shape) and write no audit rows.
1798
+ ...identityRpcs,
1397
1799
  };
1398
- // NON-ENUMERABLE so the impl still presents EXACTLY the 9 RPC keys to
1399
- // `Object.keys` / spread / `server.addService` — a 10th enumerable key would
1800
+ // NON-ENUMERABLE so the impl still presents EXACTLY the 12 RPC keys to
1801
+ // `Object.keys` / spread / `server.addService` — a 13th enumerable key would
1400
1802
  // reach every consumer that iterates the descriptor to mount handlers, and
1401
1803
  // would be registered as an RPC that does not exist on the wire.
1402
1804
  Object.defineProperty(impl, "holdGateReady", {
@@ -1432,8 +1834,8 @@ export async function bindPatternAAndVerify(opts) {
1432
1834
  * The hold-gate probe promise attached to a `bindPatternA` impl.
1433
1835
  *
1434
1836
  * Exposed as a function rather than a typed field because `DsarServiceImpl` is
1435
- * the WIRE descriptor — the 9 RPCs and nothing else — and widening it would
1436
- * declare a 10th method on a shape consumers hand to `server.addService`.
1837
+ * the WIRE descriptor — the 12 RPCs and nothing else — and widening it would
1838
+ * declare a 13th method on a shape consumers hand to `server.addService`.
1437
1839
  * Returns an already-resolved promise for impls that carry no probe (Pattern B /
1438
1840
  * Pattern C, which have no hold gate to verify), so a caller can await it
1439
1841
  * unconditionally.