@nodii/dsar 0.0.2 → 0.2.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 (78) hide show
  1. package/README.md +57 -1
  2. package/dist/audit-actions.d.ts +13 -0
  3. package/dist/audit-actions.d.ts.map +1 -0
  4. package/dist/audit-actions.js +32 -0
  5. package/dist/audit-actions.js.map +1 -0
  6. package/dist/bind-pattern-a.d.ts +27 -0
  7. package/dist/bind-pattern-a.d.ts.map +1 -0
  8. package/dist/bind-pattern-a.js +387 -0
  9. package/dist/bind-pattern-a.js.map +1 -0
  10. package/dist/bind-pattern-b.d.ts +10 -0
  11. package/dist/bind-pattern-b.d.ts.map +1 -0
  12. package/dist/bind-pattern-b.js +89 -0
  13. package/dist/bind-pattern-b.js.map +1 -0
  14. package/dist/bind-pattern-c.d.ts +6 -0
  15. package/dist/bind-pattern-c.d.ts.map +1 -0
  16. package/dist/bind-pattern-c.js +9 -0
  17. package/dist/bind-pattern-c.js.map +1 -0
  18. package/dist/canonical.d.ts +9 -0
  19. package/dist/canonical.d.ts.map +1 -0
  20. package/dist/canonical.js +57 -0
  21. package/dist/canonical.js.map +1 -0
  22. package/dist/grpc/dsar-service.d.ts +37 -0
  23. package/dist/grpc/dsar-service.d.ts.map +1 -0
  24. package/dist/grpc/dsar-service.js +66 -0
  25. package/dist/grpc/dsar-service.js.map +1 -0
  26. package/dist/handlers.d.ts +102 -0
  27. package/dist/handlers.d.ts.map +1 -0
  28. package/dist/handlers.js +268 -0
  29. package/dist/handlers.js.map +1 -0
  30. package/dist/holds.d.ts +48 -0
  31. package/dist/holds.d.ts.map +1 -0
  32. package/dist/holds.js +79 -0
  33. package/dist/holds.js.map +1 -0
  34. package/dist/index.d.ts +33 -1
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +45 -4
  37. package/dist/index.js.map +1 -1
  38. package/dist/init.d.ts +21 -0
  39. package/dist/init.d.ts.map +1 -0
  40. package/dist/init.js +37 -0
  41. package/dist/init.js.map +1 -0
  42. package/dist/migrations/index.d.ts +15 -0
  43. package/dist/migrations/index.d.ts.map +1 -0
  44. package/dist/migrations/index.js +110 -0
  45. package/dist/migrations/index.js.map +1 -0
  46. package/dist/orchestrator.d.ts +41 -0
  47. package/dist/orchestrator.d.ts.map +1 -0
  48. package/dist/orchestrator.js +205 -0
  49. package/dist/orchestrator.js.map +1 -0
  50. package/dist/register.d.ts +36 -0
  51. package/dist/register.d.ts.map +1 -0
  52. package/dist/register.js +97 -0
  53. package/dist/register.js.map +1 -0
  54. package/dist/registry.d.ts +10 -0
  55. package/dist/registry.d.ts.map +1 -0
  56. package/dist/registry.js +57 -0
  57. package/dist/registry.js.map +1 -0
  58. package/dist/retention.d.ts +17 -0
  59. package/dist/retention.d.ts.map +1 -0
  60. package/dist/retention.js +32 -0
  61. package/dist/retention.js.map +1 -0
  62. package/dist/s3-artifact.d.ts +56 -0
  63. package/dist/s3-artifact.d.ts.map +1 -0
  64. package/dist/s3-artifact.js +121 -0
  65. package/dist/s3-artifact.js.map +1 -0
  66. package/dist/state-store/postgres-lifecycle.d.ts +69 -0
  67. package/dist/state-store/postgres-lifecycle.d.ts.map +1 -0
  68. package/dist/state-store/postgres-lifecycle.js +145 -0
  69. package/dist/state-store/postgres-lifecycle.js.map +1 -0
  70. package/dist/store.d.ts +19 -0
  71. package/dist/store.d.ts.map +1 -0
  72. package/dist/store.js +66 -0
  73. package/dist/store.js.map +1 -0
  74. package/dist/types.d.ts +277 -0
  75. package/dist/types.d.ts.map +1 -0
  76. package/dist/types.js +103 -0
  77. package/dist/types.js.map +1 -0
  78. package/package.json +23 -7
@@ -0,0 +1,277 @@
1
+ /** GDPR request type accepted at BeginDsar. */
2
+ export type DsarRequestType = "access" | "erasure" | "portability" | "rectification";
3
+ /**
4
+ * Subject classification — matches the spec § 5.2 enum minus the synthetic
5
+ * `tenant`. v0.1.0 keeps the lib focused on data-subject flows; tenant-level
6
+ * holds land alongside the orchestrator-side surface in v0.1.x.
7
+ */
8
+ export type DsarSubjectKind = "user" | "employee" | "customer" | "platform_admin";
9
+ /** DSAR state machine — terminal states are `completed`, `rejected_final`. */
10
+ export type DsarStatus = "open" | "in_progress" | "completed" | "rejected" | "under_review";
11
+ /** Format for the portability export. v0.1.0 only handles `json`. */
12
+ export type PortabilityFormat = "json" | "jsonl" | "csv";
13
+ /**
14
+ * Persisted shape of one DSAR row. The store implementation is pluggable;
15
+ * services pass a SQLAlchemy / Drizzle / pgx-backed implementation at boot.
16
+ */
17
+ export interface DsarRow {
18
+ /** UUIDv7 identifier. */
19
+ dsar_id: string;
20
+ tenant_id: string;
21
+ subject_id: string;
22
+ subject_kind: DsarSubjectKind;
23
+ request_type: DsarRequestType;
24
+ status: DsarStatus;
25
+ /** Free-form actor identifier — `tenant_admin`, `nodii_compliance`, ... */
26
+ requested_by: string;
27
+ /** Min 20 chars per the saga-admin justification convention. */
28
+ justification: string;
29
+ /** RFC 3339 / ISO-8601 microsecond timestamp the row was created. */
30
+ created_at: string;
31
+ /** Set when status enters a terminal state. */
32
+ completed_at: string | null;
33
+ /**
34
+ * Append-only compensation log. Each step records the executor that ran
35
+ * + the artifact-id (export key, eraser slug, audit-row hash) for later
36
+ * compensation walk.
37
+ */
38
+ compensation_log: CompensationLogEntry[];
39
+ }
40
+ export interface CompensationLogEntry {
41
+ /** RFC 3339 / ISO-8601 microsecond timestamp. */
42
+ at: string;
43
+ /** Verb that ran — `access` / `erase` / `portability` / `rectify`. */
44
+ verb: string;
45
+ /** Free-form artifact identifier. */
46
+ artifact_id: string;
47
+ /** Free-form additional metadata. */
48
+ metadata: Record<string, string | number | boolean | null>;
49
+ }
50
+ /**
51
+ * Pluggable DsarStore. Implementations live outside this library —
52
+ * services pass a Postgres-backed implementation at boot. The library ships
53
+ * an in-memory test double that synthetic-consumer + unit-test suites use.
54
+ *
55
+ * Implementations MUST be safe under concurrent async access. v0.1.0 callers
56
+ * concurrent-safe via an in-process per-(tenant, subject) async mutex around
57
+ * the BeginDsar create path.
58
+ */
59
+ export interface DsarStore {
60
+ createDsar(row: DsarRow): Promise<void>;
61
+ getDsar(dsarId: string): Promise<DsarRow | null>;
62
+ updateDsarStatus(dsarId: string, status: DsarStatus, completedAt?: string): Promise<void>;
63
+ appendCompensationLog(dsarId: string, entry: CompensationLogEntry): Promise<void>;
64
+ list(filter: {
65
+ tenantId: string;
66
+ subjectKind?: DsarSubjectKind;
67
+ status?: DsarStatus;
68
+ limit: number;
69
+ }): Promise<DsarRow[]>;
70
+ }
71
+ /**
72
+ * Per-subjectKind data-gather callback for AccessData / PortabilityExport.
73
+ * Returns a JSON-serializable bundle that v0.1.0 ships as-is.
74
+ */
75
+ export type ExportGatherFn = (args: {
76
+ tenantId: string;
77
+ subjectId: string;
78
+ subjectKind: DsarSubjectKind;
79
+ dsarId: string;
80
+ }) => Promise<Record<string, unknown>>;
81
+ /**
82
+ * Per-subjectKind erase callback. `scope` is `subject` for per-subject erase
83
+ * (default) and `tenant` for the per-tenant variant. Failure throws
84
+ * `EraseExecutionFailed`.
85
+ */
86
+ export type EraseExecutorFn = (args: {
87
+ tenantId: string;
88
+ subjectId: string;
89
+ subjectKind: DsarSubjectKind;
90
+ dsarId: string;
91
+ scope: "subject" | "tenant";
92
+ }) => Promise<{
93
+ artifactId: string;
94
+ }>;
95
+ /** Per-subjectKind rectification callback. */
96
+ export type RectifyHandlerFn = (args: {
97
+ tenantId: string;
98
+ subjectId: string;
99
+ subjectKind: DsarSubjectKind;
100
+ dsarId: string;
101
+ fieldName: string;
102
+ newValue: string;
103
+ justification: string;
104
+ }) => Promise<{
105
+ artifactId: string;
106
+ }>;
107
+ /**
108
+ * Retention policy shape. Mirrors `retention_policies` rows in
109
+ * nodii-tenant-service per spec § 5.11.5 — the library ships the types +
110
+ * helpers; the orchestrator-side server lands in v0.1.x.
111
+ */
112
+ export interface RetentionPolicy {
113
+ /** Service identifier — `nodii-billing-service`, `obs-interface-service`, ... */
114
+ service_id: string;
115
+ /** Free-form bucket — `PII`, `financial`, `audit`, ... */
116
+ data_class: string;
117
+ subject_kind: DsarSubjectKind | "tenant";
118
+ /** Days the data may be retained after the last legitimate-use timestamp. */
119
+ retention_days: number;
120
+ }
121
+ export declare class DsarError extends Error {
122
+ constructor(message: string);
123
+ }
124
+ export declare class DsarNotInitialized extends DsarError {
125
+ constructor();
126
+ }
127
+ export declare class DsarNotFound extends DsarError {
128
+ readonly dsarId: string;
129
+ constructor(dsarId: string);
130
+ }
131
+ export declare class JustificationRequired extends DsarError {
132
+ readonly minLength: number;
133
+ readonly actualLength: number;
134
+ constructor(actualLength: number);
135
+ }
136
+ export declare class SubjectKindNotRegistered extends DsarError {
137
+ readonly subjectKind: string;
138
+ readonly verb: string;
139
+ constructor(verb: string, subjectKind: string);
140
+ }
141
+ export declare class DsarTerminalStateViolation extends DsarError {
142
+ readonly dsarId: string;
143
+ readonly currentStatus: DsarStatus;
144
+ readonly attemptedTransition: string;
145
+ constructor(dsarId: string, currentStatus: DsarStatus, attemptedTransition: string);
146
+ }
147
+ export declare class ExportGatherFailed extends DsarError {
148
+ readonly cause: unknown;
149
+ constructor(cause: unknown);
150
+ }
151
+ export declare class EraseExecutionFailed extends DsarError {
152
+ readonly cause: unknown;
153
+ constructor(cause: unknown);
154
+ }
155
+ export declare class HandlerAlreadyRegistered extends DsarError {
156
+ readonly subjectKind: string;
157
+ readonly verb: string;
158
+ constructor(verb: string, subjectKind: string);
159
+ }
160
+ /**
161
+ * Canonical LifecycleResponse mirrored from `proto/dsar/v1/dsar.proto`. Used
162
+ * across every bind* and orchestrator path. Wire-serializable JSON.
163
+ */
164
+ export interface LifecycleResponse {
165
+ request_id: string;
166
+ status: "ACCEPTED" | "COMPLETED" | "NO_DATA" | "PARTIAL" | "FAILED" | "HELD" | "UNSPECIFIED";
167
+ reason: string;
168
+ result_artifact_uri?: string;
169
+ expires_at?: string;
170
+ statute_citation?: string;
171
+ }
172
+ /** Five subject kinds matching the proto SubjectKind enum (excluding UNSPECIFIED). */
173
+ export type SubjectKindStr = "user" | "employee" | "customer" | "platform_admin" | "tenant";
174
+ /** Pattern A request envelope passed to consumer handlers. */
175
+ export interface PatternAEnvelope {
176
+ request_id: string;
177
+ tenant_id: string;
178
+ subject_kind: SubjectKindStr;
179
+ subject_id: string;
180
+ reason: string;
181
+ requested_by: string;
182
+ }
183
+ /** Pattern A handler set — five GDPR-right callbacks per spec § 5.1. */
184
+ export interface PatternAHandlers {
185
+ access(env: PatternAEnvelope): Promise<{
186
+ status: string;
187
+ payload?: Record<string, unknown>;
188
+ }>;
189
+ erase(env: PatternAEnvelope & {
190
+ scope: "subject" | "tenant";
191
+ }): Promise<{
192
+ status: string;
193
+ artifactId?: string;
194
+ }>;
195
+ rectify(env: PatternAEnvelope & {
196
+ patches: Record<string, string>;
197
+ }): Promise<{
198
+ status: string;
199
+ artifactId?: string;
200
+ }>;
201
+ portability(env: PatternAEnvelope & {
202
+ region: string;
203
+ }): Promise<{
204
+ status: string;
205
+ payload?: Record<string, unknown>;
206
+ }>;
207
+ restrict(env: PatternAEnvelope & {
208
+ restriction_kind: string;
209
+ }): Promise<{
210
+ status: string;
211
+ artifactId?: string;
212
+ }>;
213
+ }
214
+ export interface RetentionHoldHandlers {
215
+ place(args: {
216
+ request_id: string;
217
+ tenant_id: string;
218
+ subject_kind: SubjectKindStr;
219
+ subject_id: string;
220
+ statute_citation: string;
221
+ expires_at?: string;
222
+ requested_by: string;
223
+ }): Promise<{
224
+ status: string;
225
+ }>;
226
+ lift(args: {
227
+ request_id: string;
228
+ tenant_id: string;
229
+ subject_kind: SubjectKindStr;
230
+ subject_id: string;
231
+ justification: string;
232
+ requested_by: string;
233
+ }): Promise<{
234
+ status: string;
235
+ }>;
236
+ }
237
+ /**
238
+ * Hold consult result returned by `isHeld`. Spec § 5.8.
239
+ */
240
+ export interface HoldConsultResult {
241
+ held: boolean;
242
+ statute_citation?: string;
243
+ expires_at?: string;
244
+ }
245
+ /**
246
+ * Audit emitter — the library calls into this for the 28-action family per
247
+ * spec § 5.6. Consumers either pass `@nodii/audit-chain`'s emit directly or
248
+ * wrap it (e.g. `@nodii/telemetry.audit.emit`).
249
+ */
250
+ export interface AuditEmitter {
251
+ emit(args: {
252
+ action: string;
253
+ target_kind: string;
254
+ target_id: string;
255
+ payload?: Record<string, unknown>;
256
+ tenant_id?: string;
257
+ }): Promise<void>;
258
+ }
259
+ /**
260
+ * pii adapter — the bridge for Pattern A access/portability/erase paths.
261
+ * The library doesn't require @nodii/pii directly; consumers pass an adapter
262
+ * (typically `@nodii/pii`'s real functions).
263
+ */
264
+ export interface PiiAdapter {
265
+ decryptForExport(args: {
266
+ tenantId: string;
267
+ subjectId: string;
268
+ subjectKind: SubjectKindStr;
269
+ }): Promise<{
270
+ status: string;
271
+ data?: unknown;
272
+ reason?: string;
273
+ }>;
274
+ erasePerSubject(tenantId: string, subjectId: string, subjectKind: SubjectKindStr): Promise<void>;
275
+ erasePerTenant(tenantId: string): Promise<void>;
276
+ }
277
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAuBA,+CAA+C;AAC/C,MAAM,MAAM,eAAe,GACvB,QAAQ,GACR,SAAS,GACT,aAAa,GACb,eAAe,CAAC;AAEpB;;;;GAIG;AACH,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,UAAU,GACV,UAAU,GACV,gBAAgB,CAAC;AAErB,8EAA8E;AAC9E,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,aAAa,GACb,WAAW,GACX,UAAU,GACV,cAAc,CAAC;AAEnB,qEAAqE;AACrE,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAEzD;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CA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AW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,gBAAgB,CAAC,IAAI,EAAE;QACrB,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,cAAc,CAAC;KAC7B,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACjE,eAAe,CACb,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjD"}
package/dist/types.js ADDED
@@ -0,0 +1,103 @@
1
+ // Core type surface for @nodii/dsar v0.1.0.
2
+ //
3
+ // Spec: planning hub feature_doc serviceId=nodii-libs docKey=dsar.
4
+ //
5
+ // v0.1.0 ships the foundations:
6
+ // - initDsar bootstrap with pluggable typed DsarStore.
7
+ // - The 9-RPC DataLifecycleService surface as typed handler functions
8
+ // (BeginDsar, GetDsar, ListDsars, AccessData, EraseData, PortabilityExport,
9
+ // Rectify, MarkComplete, AppealRejection).
10
+ // - Per-subjectKind handler registry (registerExportGather /
11
+ // registerEraseExecutor / registerRectifyHandler).
12
+ // - DsarStore typed interface + InMemoryDsarStore test double.
13
+ // - RetentionPolicy shape + applyRetention helper.
14
+ // - Typed errors rooted at DsarError.
15
+ //
16
+ // Deferred (`// TODO dsar-v0.1.x:`):
17
+ // - Real gRPC server wiring + proto codegen for `nodii.dsar.v1`.
18
+ // - Real `@nodii/pii.decryptForExport` integration (callers register stubs).
19
+ // - Real `@nodii/audit-chain.emit` integration for completion/appeal events.
20
+ // - `RetentionPolicyService` separate gRPC server (lib ships types + helpers).
21
+ // - Multi-format streaming for `PortabilityExport` (jsonl + csv).
22
+ // - Compensation walk + library-spawned child saga for partial-erasure rollback.
23
+ // ----------------------------------------------------------------------------
24
+ // Typed errors.
25
+ export class DsarError extends Error {
26
+ constructor(message) {
27
+ super(message);
28
+ this.name = "DsarError";
29
+ }
30
+ }
31
+ export class DsarNotInitialized extends DsarError {
32
+ constructor() {
33
+ super("@nodii/dsar is not initialized — call initDsar({ store }) at process start.");
34
+ this.name = "DsarNotInitialized";
35
+ }
36
+ }
37
+ export class DsarNotFound extends DsarError {
38
+ dsarId;
39
+ constructor(dsarId) {
40
+ super(`dsar_not_found: no DSAR row for dsarId=${dsarId}`);
41
+ this.name = "DsarNotFound";
42
+ this.dsarId = dsarId;
43
+ }
44
+ }
45
+ export class JustificationRequired extends DsarError {
46
+ minLength;
47
+ actualLength;
48
+ constructor(actualLength) {
49
+ super(`justification_required: justification must be at least 20 chars (got ${actualLength}).`);
50
+ this.name = "JustificationRequired";
51
+ this.minLength = 20;
52
+ this.actualLength = actualLength;
53
+ }
54
+ }
55
+ export class SubjectKindNotRegistered extends DsarError {
56
+ subjectKind;
57
+ verb;
58
+ constructor(verb, subjectKind) {
59
+ super(`subject_kind_not_registered: no '${verb}' handler registered for subjectKind=${subjectKind}.`);
60
+ this.name = "SubjectKindNotRegistered";
61
+ this.subjectKind = subjectKind;
62
+ this.verb = verb;
63
+ }
64
+ }
65
+ export class DsarTerminalStateViolation extends DsarError {
66
+ dsarId;
67
+ currentStatus;
68
+ attemptedTransition;
69
+ constructor(dsarId, currentStatus, attemptedTransition) {
70
+ super(`dsar_terminal_state_violation: cannot ${attemptedTransition} DSAR ${dsarId} in status=${currentStatus}.`);
71
+ this.name = "DsarTerminalStateViolation";
72
+ this.dsarId = dsarId;
73
+ this.currentStatus = currentStatus;
74
+ this.attemptedTransition = attemptedTransition;
75
+ }
76
+ }
77
+ export class ExportGatherFailed extends DsarError {
78
+ cause;
79
+ constructor(cause) {
80
+ super(`export_gather_failed: ${cause instanceof Error ? cause.message : String(cause)}`);
81
+ this.name = "ExportGatherFailed";
82
+ this.cause = cause;
83
+ }
84
+ }
85
+ export class EraseExecutionFailed extends DsarError {
86
+ cause;
87
+ constructor(cause) {
88
+ super(`erase_execution_failed: ${cause instanceof Error ? cause.message : String(cause)}`);
89
+ this.name = "EraseExecutionFailed";
90
+ this.cause = cause;
91
+ }
92
+ }
93
+ export class HandlerAlreadyRegistered extends DsarError {
94
+ subjectKind;
95
+ verb;
96
+ constructor(verb, subjectKind) {
97
+ super(`handler_already_registered: '${verb}' handler for subjectKind=${subjectKind} is already registered (first-registration wins).`);
98
+ this.name = "HandlerAlreadyRegistered";
99
+ this.subjectKind = subjectKind;
100
+ this.verb = verb;
101
+ }
102
+ }
103
+ //# sourceMappingURL=types.js.map
@@ -0,0 +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;AA2JnF,+EAA+E;AAC/E,gBAAgB;AAEhB,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AAED,MA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QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;IACjD,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,SAAS;IACtC,KAAK,CAAU;IACxB,YAAY,KAAc;QACxB,KAAK,CACH,yBAAyB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAClF,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IACxC,KAAK,CAAU;IACxB,YAAY,KAAc;QACxB,KAAK,CACH,2BAA2B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACpF,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,SAAS;IAC5C,WAAW,CAAS;IACpB,IAAI,CAAS;IACtB,YAAY,IAAY,EAAE,WAAmB;QAC3C,KAAK,CACH,gCAAgC,IAAI,6BAA6B,WAAW,mDAAmD,CAChI,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nodii/dsar",
3
- "version": "0.0.2",
4
- "description": "Placeholder for @nodii/dsar — implementation lands at v0.1.0",
3
+ "version": "0.2.1",
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",
7
7
  "main": "./dist/index.js",
@@ -12,22 +12,38 @@
12
12
  "default": "./dist/index.js"
13
13
  }
14
14
  },
15
- "files": ["dist"],
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
16
19
  "publishConfig": {
17
- "access": "public",
18
- "provenance": true
20
+ "access": "public"
19
21
  },
20
22
  "scripts": {
21
23
  "build": "tsc",
22
24
  "typecheck": "tsc --noEmit",
23
- "test": "echo 'no tests yet; placeholder package'"
25
+ "test": "bun test"
26
+ },
27
+ "peerDependencies": {
28
+ "@nodii/telemetry": "workspace:*",
29
+ "@nodii/pii": "workspace:*",
30
+ "@nodii/audit-chain": "workspace:*"
31
+ },
32
+ "dependencies": {
33
+ "@aws-sdk/client-s3": "^3.621.0",
34
+ "@aws-sdk/s3-request-presigner": "^3.621.0",
35
+ "postgres": "^3.4.4"
24
36
  },
25
37
  "devDependencies": {
38
+ "@nodii/telemetry": "workspace:*",
39
+ "@nodii/pii": "workspace:*",
40
+ "@nodii/audit-chain": "workspace:*",
41
+ "@types/bun": "^1.3.13",
26
42
  "typescript": "^5.9.3"
27
43
  },
28
44
  "repository": {
29
45
  "type": "git",
30
- "url": "https://github.com/cognion-nucleus/nodii-libs.git",
46
+ "url": "git+https://github.com/cognion-nucleus/nodii-libs.git",
31
47
  "directory": "ts/dsar"
32
48
  }
33
49
  }