@nodii/dsar 0.20.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 +127 -13
- package/dist/bind-pattern-a.d.ts.map +1 -1
- package/dist/bind-pattern-a.js +553 -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/retention.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
// Retention policy helpers.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// Retention policy helpers.
|
|
2
|
+
//
|
|
3
|
+
// v0.1.0 shipped the types + a pure `applyRetention` matcher over
|
|
4
|
+
// `retention_policies` rows (`retention_days` from `created_at`).
|
|
5
|
+
//
|
|
6
|
+
// D720 adds the SCHEDULE layer on top of it, without disturbing it:
|
|
7
|
+
// - `RetentionSchedule` — the effective-dated, jurisdictional row of the
|
|
8
|
+
// platform-global `retention_schedules` table.
|
|
9
|
+
// - `applyRetentionSchedules` — the schedules-aware overload: resolve the
|
|
10
|
+
// governing schedule for a (jurisdiction, document_class, entity_kind)
|
|
11
|
+
// tuple at a point in time, then compute the expiry from the record's
|
|
12
|
+
// ANCHOR timestamp.
|
|
13
|
+
// - `createRetentionSchedulesTable` — the idempotent DDL.
|
|
14
|
+
//
|
|
15
|
+
// SCHEDULE CONTENT IS DATA. This module ships the mechanism; the periods are
|
|
16
|
+
// operator/counsel-owned rows. Nothing here hard-codes a jurisdiction's window,
|
|
17
|
+
// and the tests seed their own.
|
|
18
|
+
import { isRetentionAnchor } from "./types.js";
|
|
4
19
|
/**
|
|
5
20
|
* Match a DSAR row against a list of retention policies. Returns the most
|
|
6
21
|
* conservative policy that matches the row's `(data_class, subject_kind)`
|
|
@@ -29,4 +44,202 @@ export function applyRetention(policies, dsarRow, dataClass) {
|
|
|
29
44
|
retainUntil: retainUntilDate.toISOString(),
|
|
30
45
|
};
|
|
31
46
|
}
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// D720 — ISO-8601 duration arithmetic.
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
const ISO_DURATION_RE = /^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/;
|
|
51
|
+
/**
|
|
52
|
+
* Parse an ISO-8601 duration (`P8Y`, `P10Y`, `P1Y6M`, `P90D`, `PT12H`).
|
|
53
|
+
*
|
|
54
|
+
* Throws on anything unparseable — a retention period is a legal obligation,
|
|
55
|
+
* and silently treating `"8Y"` (missing the `P`) as zero would purge a record
|
|
56
|
+
* eight years early. Negative durations are rejected for the same reason.
|
|
57
|
+
*/
|
|
58
|
+
export function parseIsoDuration(period) {
|
|
59
|
+
if (typeof period !== "string" || period.length < 2) {
|
|
60
|
+
throw new Error(`parseIsoDuration: ${JSON.stringify(period)} is not an ISO-8601 duration (expected e.g. "P8Y", "P1Y6M", "P90D").`);
|
|
61
|
+
}
|
|
62
|
+
const m = ISO_DURATION_RE.exec(period);
|
|
63
|
+
if (!m || period === "P" || period.endsWith("T")) {
|
|
64
|
+
throw new Error(`parseIsoDuration: ${JSON.stringify(period)} is not a valid ISO-8601 duration. A retention window is a legal obligation — the library will not guess at a malformed one (a silently-zero period purges the record immediately).`);
|
|
65
|
+
}
|
|
66
|
+
const n = (v) => (v ? Number.parseInt(v, 10) : 0);
|
|
67
|
+
return {
|
|
68
|
+
years: n(m[1]),
|
|
69
|
+
months: n(m[2]),
|
|
70
|
+
weeks: n(m[3]),
|
|
71
|
+
days: n(m[4]),
|
|
72
|
+
hours: n(m[5]),
|
|
73
|
+
minutes: n(m[6]),
|
|
74
|
+
seconds: n(m[7]),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Add an ISO-8601 duration to an instant, calendar-correctly.
|
|
79
|
+
*
|
|
80
|
+
* Years and months go through the CALENDAR (UTC), not a fixed day count:
|
|
81
|
+
* "8 years from 2024-02-29" must land on 2032-02-29, and approximating a year
|
|
82
|
+
* as 365 days drifts two days over an 8-year statutory window — enough to purge
|
|
83
|
+
* on the wrong side of a filing deadline. Weeks/days/time are exact offsets.
|
|
84
|
+
*/
|
|
85
|
+
export function addIsoDuration(at, period) {
|
|
86
|
+
const d = parseIsoDuration(period);
|
|
87
|
+
const out = new Date(at.getTime());
|
|
88
|
+
if (d.years || d.months) {
|
|
89
|
+
// Clamp day-of-month the way the calendar does (Jan 31 + 1M → Feb 28/29),
|
|
90
|
+
// by letting Date normalise the overflow only after the day is capped.
|
|
91
|
+
const targetYear = out.getUTCFullYear() + d.years;
|
|
92
|
+
const targetMonth = out.getUTCMonth() + d.months;
|
|
93
|
+
const day = out.getUTCDate();
|
|
94
|
+
const normYear = targetYear + Math.floor(targetMonth / 12);
|
|
95
|
+
const normMonth = ((targetMonth % 12) + 12) % 12;
|
|
96
|
+
const lastDay = new Date(Date.UTC(normYear, normMonth + 1, 0)).getUTCDate();
|
|
97
|
+
out.setUTCFullYear(normYear, normMonth, Math.min(day, lastDay));
|
|
98
|
+
}
|
|
99
|
+
const ms = (d.weeks * 7 + d.days) * 86_400_000 +
|
|
100
|
+
d.hours * 3_600_000 +
|
|
101
|
+
d.minutes * 60_000 +
|
|
102
|
+
d.seconds * 1000;
|
|
103
|
+
return new Date(out.getTime() + ms);
|
|
104
|
+
}
|
|
105
|
+
function toDate(v, label) {
|
|
106
|
+
const d = v instanceof Date ? v : new Date(v);
|
|
107
|
+
if (Number.isNaN(d.getTime())) {
|
|
108
|
+
throw new Error(`applyRetentionSchedules: ${label} ${JSON.stringify(String(v))} is not a valid date.`);
|
|
109
|
+
}
|
|
110
|
+
return d;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* D720 — resolve the governing retention schedule for a record and compute its
|
|
114
|
+
* hard-delete date.
|
|
115
|
+
*
|
|
116
|
+
* SELECTION, in order:
|
|
117
|
+
* 1. rows matching `(jurisdiction, document_class, entity_kind)` exactly;
|
|
118
|
+
* 2. narrowed to those IN FORCE at `at` (`effective_from <= at` and
|
|
119
|
+
* `effective_to` null or `> at`);
|
|
120
|
+
* 3. of those, the one with the LATEST `effective_from` — the most recent
|
|
121
|
+
* amendment wins, which is what "effective-dated" means;
|
|
122
|
+
* 4. ties (two rows with the same `effective_from`, e.g. a mid-migration
|
|
123
|
+
* double-insert) break toward the LONGER period. Retention floors are
|
|
124
|
+
* floors: when the registry is ambiguous the safe reading is the one that
|
|
125
|
+
* keeps the record, since a wrong purge is irreversible and a wrong keep
|
|
126
|
+
* is a row we delete next sweep.
|
|
127
|
+
*
|
|
128
|
+
* Returns `null` when nothing matches — the caller decides what that means. The
|
|
129
|
+
* sweeper treats it as "no schedule, no purge": absence of a rule is never a
|
|
130
|
+
* licence to delete.
|
|
131
|
+
*/
|
|
132
|
+
export function applyRetentionSchedules(schedules, query) {
|
|
133
|
+
const at = toDate(query.at ?? new Date(), "at");
|
|
134
|
+
const anchorAt = toDate(query.anchorAt, "anchorAt");
|
|
135
|
+
const candidates = schedules.filter((s) => {
|
|
136
|
+
if (s.jurisdiction !== query.jurisdiction ||
|
|
137
|
+
s.document_class !== query.documentClass ||
|
|
138
|
+
s.entity_kind !== query.entityKind) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
const from = toDate(s.effective_from, "effective_from");
|
|
142
|
+
if (from.getTime() > at.getTime())
|
|
143
|
+
return false;
|
|
144
|
+
if (s.effective_to !== undefined && s.effective_to !== null) {
|
|
145
|
+
const to = toDate(s.effective_to, "effective_to");
|
|
146
|
+
if (to.getTime() <= at.getTime())
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
});
|
|
151
|
+
if (candidates.length === 0)
|
|
152
|
+
return null;
|
|
153
|
+
candidates.sort((a, b) => {
|
|
154
|
+
const delta = toDate(b.effective_from, "effective_from").getTime() -
|
|
155
|
+
toDate(a.effective_from, "effective_from").getTime();
|
|
156
|
+
if (delta !== 0)
|
|
157
|
+
return delta;
|
|
158
|
+
// Same effective_from → keep the LONGER window (see docstring).
|
|
159
|
+
const aUntil = addIsoDuration(anchorAt, a.retention_period).getTime();
|
|
160
|
+
const bUntil = addIsoDuration(anchorAt, b.retention_period).getTime();
|
|
161
|
+
return bUntil - aUntil;
|
|
162
|
+
});
|
|
163
|
+
const winner = candidates[0];
|
|
164
|
+
if (!winner)
|
|
165
|
+
return null;
|
|
166
|
+
if (!isRetentionAnchor(winner.anchor)) {
|
|
167
|
+
throw new Error(`applyRetentionSchedules: schedule (${winner.jurisdiction}/${winner.document_class}/${winner.entity_kind}) declares anchor ${JSON.stringify(winner.anchor)}, which is not one of creation | last_activity | relationship_end | filing (D720). Picking the wrong anchor moves a hard-delete date by years; the library will not guess.`);
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
schedule: winner,
|
|
171
|
+
retainUntil: addIsoDuration(anchorAt, winner.retention_period).toISOString(),
|
|
172
|
+
extendedByProceeding: winner.extended_by_proceeding === true,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
// ---------------------------------------------------------------------------
|
|
176
|
+
// D720 — `retention_schedules` DDL.
|
|
177
|
+
// ---------------------------------------------------------------------------
|
|
178
|
+
/** The canonical platform-global schedules table name. */
|
|
179
|
+
export const RETENTION_SCHEDULES_TABLE = "retention_schedules";
|
|
180
|
+
/**
|
|
181
|
+
* D720 — the platform-global `retention_schedules` table.
|
|
182
|
+
*
|
|
183
|
+
* PLATFORM-GLOBAL, not per-service: it sits beside `retention_policies` and
|
|
184
|
+
* `data_residency_holds` in the orchestrator's schema, with no `<svc>_` prefix,
|
|
185
|
+
* because a jurisdiction's statutory period is a property of the LAW, not of
|
|
186
|
+
* whichever service happens to hold the record. `applyDsarMigrations` creates
|
|
187
|
+
* it; this function is for consumers running their own migration tool.
|
|
188
|
+
*
|
|
189
|
+
* The rows are DATA (operator/counsel-owned jurisdiction packs). This emits the
|
|
190
|
+
* shape only — no seed rows, no invented periods.
|
|
191
|
+
*/
|
|
192
|
+
export function createRetentionSchedulesTable(tableName = RETENTION_SCHEDULES_TABLE) {
|
|
193
|
+
if (!/^[a-z][a-z0-9_]*$/.test(tableName)) {
|
|
194
|
+
throw new Error(`createRetentionSchedulesTable: ${JSON.stringify(tableName)} is not a valid SQL identifier (must match /^[a-z][a-z0-9_]*$/).`);
|
|
195
|
+
}
|
|
196
|
+
return { tableName, ddl: retentionSchedulesDdl(tableName) };
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The idempotent DDL body. Kept as a standalone function so the dsar migration
|
|
200
|
+
* template and `createRetentionSchedulesTable` emit BYTE-IDENTICAL SQL — one
|
|
201
|
+
* source of truth, no drift between the runner and the artifact.
|
|
202
|
+
*/
|
|
203
|
+
export function retentionSchedulesDdl(tableName = RETENTION_SCHEDULES_TABLE) {
|
|
204
|
+
return `CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
205
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
206
|
+
jurisdiction TEXT NOT NULL,
|
|
207
|
+
document_class TEXT NOT NULL,
|
|
208
|
+
entity_kind TEXT NOT NULL,
|
|
209
|
+
retention_period TEXT NOT NULL,
|
|
210
|
+
anchor TEXT NOT NULL,
|
|
211
|
+
extended_by_proceeding BOOLEAN NOT NULL DEFAULT false,
|
|
212
|
+
statute_citation TEXT,
|
|
213
|
+
effective_from TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
214
|
+
effective_to TIMESTAMPTZ,
|
|
215
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
216
|
+
);
|
|
217
|
+
ALTER TABLE ${tableName} ADD COLUMN IF NOT EXISTS statute_citation TEXT;
|
|
218
|
+
ALTER TABLE ${tableName} ADD COLUMN IF NOT EXISTS effective_to TIMESTAMPTZ;
|
|
219
|
+
DO $retention_schedules_anchor$
|
|
220
|
+
BEGIN
|
|
221
|
+
IF NOT EXISTS (
|
|
222
|
+
SELECT 1 FROM pg_constraint WHERE conname = '${tableName}_anchor_valid'
|
|
223
|
+
) THEN
|
|
224
|
+
ALTER TABLE ${tableName} ADD CONSTRAINT ${tableName}_anchor_valid
|
|
225
|
+
CHECK (anchor IN ('creation', 'last_activity', 'relationship_end', 'filing'));
|
|
226
|
+
END IF;
|
|
227
|
+
END
|
|
228
|
+
$retention_schedules_anchor$;
|
|
229
|
+
DO $retention_schedules_window$
|
|
230
|
+
BEGIN
|
|
231
|
+
IF NOT EXISTS (
|
|
232
|
+
SELECT 1 FROM pg_constraint WHERE conname = '${tableName}_window_valid'
|
|
233
|
+
) THEN
|
|
234
|
+
ALTER TABLE ${tableName} ADD CONSTRAINT ${tableName}_window_valid
|
|
235
|
+
CHECK (effective_to IS NULL OR effective_to > effective_from);
|
|
236
|
+
END IF;
|
|
237
|
+
END
|
|
238
|
+
$retention_schedules_window$;
|
|
239
|
+
CREATE UNIQUE INDEX IF NOT EXISTS uq_${tableName}_effective
|
|
240
|
+
ON ${tableName} (jurisdiction, document_class, entity_kind, effective_from);
|
|
241
|
+
CREATE INDEX IF NOT EXISTS idx_${tableName}_lookup
|
|
242
|
+
ON ${tableName} (jurisdiction, document_class, entity_kind)
|
|
243
|
+
WHERE effective_to IS NULL;`;
|
|
244
|
+
}
|
|
32
245
|
//# sourceMappingURL=retention.js.map
|
package/dist/retention.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retention.js","sourceRoot":"","sources":["../src/retention.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"retention.js","source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AW,qBAAqB,IAAI,CAAC,SAAS,CACzI,MAAM,CAAC,MAAM,CACd,4KAA4K,CAC9K,CAAC;IACJ,CAAC;IACD,OAAO;QACL,QAAQ,EAAE,MAAM;QAChB,WAAW,EAAE,cAAc,CACzB,QAAQ,EACR,MAAM,CAAC,gBAAgB,CACxB,CAAC,WAAW,EAAE;QACf,oBAAoB,EAAE,MAAM,CAAC,sBAAsB,KAAK,IAAI;KAC7D,CAAC;AACJ,CAAC;AASD,8EAA8E;AAC9E,oCAAoC;AACpC,8EAA8E;AAE9E,0DAA0D;AAC1D,MAAM,CAAC,MAAM,yBAAyB,GAAG,qBAAqB,CAAC;AAQ/D;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,6BAA6B,CAC3C,YAAoB,yBAAyB;IAE7C,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CACb,kCAAkC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,kEAAkE,CAC9H,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,qBAAqB,CAAC,SAAS,CAAC,EAAE,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CACnC,YAAoB,yBAAyB;IAE7C,OAAO,8BAA8B,SAAS;;;;;;;;;;;;;cAalC,SAAS;cACT,SAAS;;;;mDAI4B,SAAS;;kBAE1C,SAAS,mBAAmB,SAAS;;;;;;;;mDAQJ,SAAS;;kBAE1C,SAAS,mBAAmB,SAAS;;;;;uCAKhB,SAAS;OACzC,SAAS;iCACiB,SAAS;OACnC,SAAS;8BACc,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { DsarError } from "./types.js";
|
|
2
|
+
import type { LifecycleResponse } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The closed data-subject vocabulary, wire (lowercase) form. Order is stable
|
|
5
|
+
* and is the order the parity fixtures assert across ts / python / go.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SUBJECT_KINDS: readonly ["user", "employee", "customer", "vendor", "third_party", "tenant"];
|
|
8
|
+
/** One of the six D719 data-subject kinds. */
|
|
9
|
+
export type SubjectKind = (typeof SUBJECT_KINDS)[number];
|
|
10
|
+
/**
|
|
11
|
+
* Raised whenever a value that must be a D719 data-subject kind is not one.
|
|
12
|
+
*
|
|
13
|
+
* Fail-loud by construction: there is no "unknown kind" fallback, no coercion,
|
|
14
|
+
* and no silent drop. A `DsarError` subclass so existing
|
|
15
|
+
* `catch (e) { e instanceof DsarError }` handlers keep classifying it as a
|
|
16
|
+
* DSAR-domain failure.
|
|
17
|
+
*/
|
|
18
|
+
export declare class UnknownSubjectKindError extends DsarError {
|
|
19
|
+
readonly code = "UNKNOWN_SUBJECT_KIND";
|
|
20
|
+
/** The rejected value, verbatim (already stringified). */
|
|
21
|
+
readonly subjectKind: string;
|
|
22
|
+
/** Where the rejection happened, e.g. `registerWithOrchestrator(...)`. */
|
|
23
|
+
readonly context: string;
|
|
24
|
+
constructor(subjectKind: unknown, context: string);
|
|
25
|
+
}
|
|
26
|
+
/** Type guard — `true` iff `value` is one of the six D719 kinds. */
|
|
27
|
+
export declare function isSubjectKind(value: unknown): value is SubjectKind;
|
|
28
|
+
/**
|
|
29
|
+
* Narrow `value` to a {@link SubjectKind} or throw
|
|
30
|
+
* {@link UnknownSubjectKindError}.
|
|
31
|
+
*
|
|
32
|
+
* `context` is a short human string naming the call site — it lands verbatim
|
|
33
|
+
* in the thrown message so a boot-time rejection says WHICH registration /
|
|
34
|
+
* request carried the bad kind.
|
|
35
|
+
*/
|
|
36
|
+
export declare function assertSubjectKind(value: unknown, context: string): SubjectKind;
|
|
37
|
+
/**
|
|
38
|
+
* Stable refusal reason a PARTICIPANT returns when an inbound RPC carries a
|
|
39
|
+
* subject_kind outside the closed vocabulary.
|
|
40
|
+
*
|
|
41
|
+
* Machine-readable on purpose: the orchestrator records this verbatim in
|
|
42
|
+
* `platform_lifecycle_requests.per_sibling_state[<sibling>].reason`, so an
|
|
43
|
+
* operator (or a consumer classifying a refusal) can tell "this sibling
|
|
44
|
+
* rejected the request as malformed" from "this sibling failed" WITHOUT
|
|
45
|
+
* string-matching a prose message. Same posture as the hold-gate refusal
|
|
46
|
+
* vocabulary in `hold-failure-mode.ts`.
|
|
47
|
+
*/
|
|
48
|
+
export declare const UNKNOWN_SUBJECT_KIND_REASON = "invalid_argument_unknown_subject_kind";
|
|
49
|
+
/**
|
|
50
|
+
* Build the participant-side refusal for an unroutable subject_kind.
|
|
51
|
+
*
|
|
52
|
+
* WHY A `FAILED` RESPONSE RATHER THAN A THROW: the participant bindings are
|
|
53
|
+
* the server side of a per-host `DataLifecycleService`. A throw becomes a
|
|
54
|
+
* transport-level error whose shape depends on the host's gRPC wiring; a
|
|
55
|
+
* `FAILED` `LifecycleResponse` is the binding's own contract and lands in the
|
|
56
|
+
* orchestrator's `per_sibling_state` as durable, queryable evidence that this
|
|
57
|
+
* sibling refused and why. The request is malformed (gRPC `INVALID_ARGUMENT`
|
|
58
|
+
* in spirit), and the one outcome that must NOT happen is a silent success.
|
|
59
|
+
*
|
|
60
|
+
* WHY IT MUST PRECEDE PERSISTENCE: `withLifecycleIdempotency` memoizes on
|
|
61
|
+
* `(request_id, rpc_method)`. Writing a `lifecycle_requests` row for a request
|
|
62
|
+
* that can never be routed would cache the malformed request's outcome, so a
|
|
63
|
+
* corrected retry with the SAME request_id would replay the cached refusal
|
|
64
|
+
* instead of running. Refuse before the store is touched.
|
|
65
|
+
*
|
|
66
|
+
* The response carries the token in `reason` and NOTHING else. It deliberately
|
|
67
|
+
* does NOT borrow `hold_gate_error`, which is documented as the diagnostic for
|
|
68
|
+
* the two hold-gate infrastructure corners and absent on every other outcome —
|
|
69
|
+
* a subject-kind refusal appearing there would make that field ambiguous. The
|
|
70
|
+
* full diagnostic is reconstructible from the token plus the request's own
|
|
71
|
+
* `subject_kind`, and the binder emits it on the refusal audit row.
|
|
72
|
+
*/
|
|
73
|
+
export declare function unknownSubjectKindRefusal(requestId: string): LifecycleResponse;
|
|
74
|
+
//# sourceMappingURL=subject-kinds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subject-kinds.d.ts","sourceRoot":"","sources":["../src/subject-kinds.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;GAGG;AACH,eAAO,MAAM,aAAa,8EAOhB,CAAC;AAEX,8CAA8C;AAC9C,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAIzD;;;;;;;GAOG;AACH,qBAAa,uBAAwB,SAAQ,SAAS;IACpD,QAAQ,CAAC,IAAI,0BAA0B;IACvC,0DAA0D;IAC1D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM;CAuBlD;AAED,oEAAoE;AACpE,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,MAAM,GACd,WAAW,CAKb;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,2BAA2B,0CACC,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,MAAM,GAChB,iBAAiB,CAMnB"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// D719 — the CLOSED data-subject vocabulary (LOCKED 2026-08-13).
|
|
2
|
+
//
|
|
3
|
+
// SUPERSEDES the D341 enum. Before this, every port carried its own slightly
|
|
4
|
+
// different list (`ts/dsar` had 4 kinds in `DsarSubjectKind` and 5 in
|
|
5
|
+
// `SubjectKindStr`; python + go had their own twins) and NOTHING validated an
|
|
6
|
+
// inbound `subject_kind` — so a service could register a data-class under a
|
|
7
|
+
// typo, an internal key-scope label, or a retired kind, and the orchestrator's
|
|
8
|
+
// D486 subject_kind-only fan-out (`SELECT DISTINCT service_id FROM
|
|
9
|
+
// retention_policies WHERE subject_kind = $1`) would simply never match it.
|
|
10
|
+
// The registration succeeded, the erase silently skipped that service, and no
|
|
11
|
+
// gate anywhere went red.
|
|
12
|
+
//
|
|
13
|
+
// THE CLOSED SET (wire / lowercase form — what crosses the RPC boundary and
|
|
14
|
+
// what `retention_policies.subject_kind` stores):
|
|
15
|
+
//
|
|
16
|
+
// user · employee · customer · vendor · third_party · tenant
|
|
17
|
+
//
|
|
18
|
+
// `platform_admin` is REMOVED as a data-subject kind. It survives only as an
|
|
19
|
+
// audit ACTOR kind, which is a different axis and is not modelled here. The
|
|
20
|
+
// proto enum value 4 it used to occupy is RESERVED — see
|
|
21
|
+
// `subjectKindFromProto` in `src/grpc/dsar-service.ts`.
|
|
22
|
+
//
|
|
23
|
+
// EVERYTHING ELSE IS NOT A SUBJECT KIND. In particular the per-record /
|
|
24
|
+
// per-credential DEK envelope SCOPES some services mint keys under
|
|
25
|
+
// (`TICKET_REQUESTER`, `EXTERNAL_INTEGRATION_CREDENTIAL`, `OUTBOUND_WEBHOOK`,
|
|
26
|
+
// `STATUS_SUBSCRIBER`, `GEO_RESOLVE_SUBJECT`, service synthetic-`TENANT`
|
|
27
|
+
// usages) are LEGAL for a `@nodii/pii` DEK mint but are NEVER routable and
|
|
28
|
+
// NEVER registrable here. A key scope in `retention_policies` is an
|
|
29
|
+
// erase-completeness hole wearing a valid-looking label. Declare those to
|
|
30
|
+
// `@nodii/pii` via `initPii({ keyScopes })` instead.
|
|
31
|
+
import { DsarError } from "./types.js";
|
|
32
|
+
/**
|
|
33
|
+
* The closed data-subject vocabulary, wire (lowercase) form. Order is stable
|
|
34
|
+
* and is the order the parity fixtures assert across ts / python / go.
|
|
35
|
+
*/
|
|
36
|
+
export const SUBJECT_KINDS = [
|
|
37
|
+
"user",
|
|
38
|
+
"employee",
|
|
39
|
+
"customer",
|
|
40
|
+
"vendor",
|
|
41
|
+
"third_party",
|
|
42
|
+
"tenant",
|
|
43
|
+
];
|
|
44
|
+
const SUBJECT_KIND_SET = new Set(SUBJECT_KINDS);
|
|
45
|
+
/**
|
|
46
|
+
* Raised whenever a value that must be a D719 data-subject kind is not one.
|
|
47
|
+
*
|
|
48
|
+
* Fail-loud by construction: there is no "unknown kind" fallback, no coercion,
|
|
49
|
+
* and no silent drop. A `DsarError` subclass so existing
|
|
50
|
+
* `catch (e) { e instanceof DsarError }` handlers keep classifying it as a
|
|
51
|
+
* DSAR-domain failure.
|
|
52
|
+
*/
|
|
53
|
+
export class UnknownSubjectKindError extends DsarError {
|
|
54
|
+
code = "UNKNOWN_SUBJECT_KIND";
|
|
55
|
+
/** The rejected value, verbatim (already stringified). */
|
|
56
|
+
subjectKind;
|
|
57
|
+
/** Where the rejection happened, e.g. `registerWithOrchestrator(...)`. */
|
|
58
|
+
context;
|
|
59
|
+
constructor(subjectKind, context) {
|
|
60
|
+
const got = typeof subjectKind === "string"
|
|
61
|
+
? JSON.stringify(subjectKind)
|
|
62
|
+
: String(subjectKind);
|
|
63
|
+
// Joined from parts rather than `+`-concatenated (biome useTemplate) — the
|
|
64
|
+
// alternative that satisfies the rule is one ~600-char line, and this
|
|
65
|
+
// message is the whole diagnostic a boot crash prints.
|
|
66
|
+
super([
|
|
67
|
+
`unknown_subject_kind: ${got} is not a D719 data-subject kind (${context}).`,
|
|
68
|
+
`The closed set is [${SUBJECT_KINDS.join(", ")}].`,
|
|
69
|
+
"`platform_admin` was removed by D719 (it is an audit ACTOR kind, not a subject kind).",
|
|
70
|
+
"Per-record / per-credential DEK envelope SCOPES (TICKET_REQUESTER,",
|
|
71
|
+
"EXTERNAL_INTEGRATION_CREDENTIAL, OUTBOUND_WEBHOOK, STATUS_SUBSCRIBER,",
|
|
72
|
+
"GEO_RESOLVE_SUBJECT, …) are legal for a @nodii/pii DEK mint — declare them via",
|
|
73
|
+
"initPii({ keyScopes }) — but they are NEVER routable or registrable as a subject kind.",
|
|
74
|
+
].join(" "));
|
|
75
|
+
this.name = "UnknownSubjectKindError";
|
|
76
|
+
this.subjectKind = got;
|
|
77
|
+
this.context = context;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Type guard — `true` iff `value` is one of the six D719 kinds. */
|
|
81
|
+
export function isSubjectKind(value) {
|
|
82
|
+
return typeof value === "string" && SUBJECT_KIND_SET.has(value);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Narrow `value` to a {@link SubjectKind} or throw
|
|
86
|
+
* {@link UnknownSubjectKindError}.
|
|
87
|
+
*
|
|
88
|
+
* `context` is a short human string naming the call site — it lands verbatim
|
|
89
|
+
* in the thrown message so a boot-time rejection says WHICH registration /
|
|
90
|
+
* request carried the bad kind.
|
|
91
|
+
*/
|
|
92
|
+
export function assertSubjectKind(value, context) {
|
|
93
|
+
if (!isSubjectKind(value)) {
|
|
94
|
+
throw new UnknownSubjectKindError(value, context);
|
|
95
|
+
}
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Stable refusal reason a PARTICIPANT returns when an inbound RPC carries a
|
|
100
|
+
* subject_kind outside the closed vocabulary.
|
|
101
|
+
*
|
|
102
|
+
* Machine-readable on purpose: the orchestrator records this verbatim in
|
|
103
|
+
* `platform_lifecycle_requests.per_sibling_state[<sibling>].reason`, so an
|
|
104
|
+
* operator (or a consumer classifying a refusal) can tell "this sibling
|
|
105
|
+
* rejected the request as malformed" from "this sibling failed" WITHOUT
|
|
106
|
+
* string-matching a prose message. Same posture as the hold-gate refusal
|
|
107
|
+
* vocabulary in `hold-failure-mode.ts`.
|
|
108
|
+
*/
|
|
109
|
+
export const UNKNOWN_SUBJECT_KIND_REASON = "invalid_argument_unknown_subject_kind";
|
|
110
|
+
/**
|
|
111
|
+
* Build the participant-side refusal for an unroutable subject_kind.
|
|
112
|
+
*
|
|
113
|
+
* WHY A `FAILED` RESPONSE RATHER THAN A THROW: the participant bindings are
|
|
114
|
+
* the server side of a per-host `DataLifecycleService`. A throw becomes a
|
|
115
|
+
* transport-level error whose shape depends on the host's gRPC wiring; a
|
|
116
|
+
* `FAILED` `LifecycleResponse` is the binding's own contract and lands in the
|
|
117
|
+
* orchestrator's `per_sibling_state` as durable, queryable evidence that this
|
|
118
|
+
* sibling refused and why. The request is malformed (gRPC `INVALID_ARGUMENT`
|
|
119
|
+
* in spirit), and the one outcome that must NOT happen is a silent success.
|
|
120
|
+
*
|
|
121
|
+
* WHY IT MUST PRECEDE PERSISTENCE: `withLifecycleIdempotency` memoizes on
|
|
122
|
+
* `(request_id, rpc_method)`. Writing a `lifecycle_requests` row for a request
|
|
123
|
+
* that can never be routed would cache the malformed request's outcome, so a
|
|
124
|
+
* corrected retry with the SAME request_id would replay the cached refusal
|
|
125
|
+
* instead of running. Refuse before the store is touched.
|
|
126
|
+
*
|
|
127
|
+
* The response carries the token in `reason` and NOTHING else. It deliberately
|
|
128
|
+
* does NOT borrow `hold_gate_error`, which is documented as the diagnostic for
|
|
129
|
+
* the two hold-gate infrastructure corners and absent on every other outcome —
|
|
130
|
+
* a subject-kind refusal appearing there would make that field ambiguous. The
|
|
131
|
+
* full diagnostic is reconstructible from the token plus the request's own
|
|
132
|
+
* `subject_kind`, and the binder emits it on the refusal audit row.
|
|
133
|
+
*/
|
|
134
|
+
export function unknownSubjectKindRefusal(requestId) {
|
|
135
|
+
return {
|
|
136
|
+
request_id: requestId,
|
|
137
|
+
status: "FAILED",
|
|
138
|
+
reason: UNKNOWN_SUBJECT_KIND_REASON,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=subject-k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