@voltro/plugin-deactivation 0.89.2 → 0.91.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.
@@ -0,0 +1,18 @@
1
+ import { privacyRequestsTable as e } from "./privacyRequests.js";
2
+ import { and as t, eq as n, inSet as r, or as i, queryFor as a } from "@voltro/database";
3
+ import { Effect as o } from "effect";
4
+ // src/accountMerge.ts
5
+ var s = class extends Error {
6
+ constructor() {
7
+ super("An erasure of one of the accounts is pending");
8
+ }
9
+ }, c = (c) => o.tryPromise({
10
+ try: async () => {
11
+ let o = c.store;
12
+ if ((await o.query(a(e).where(t(n("tenantId", c.tenantId), i(n("subjectId", c.sourceId), n("subjectId", c.targetId)))).forUpdate().descriptor)).some((e) => e.status === "pending" || e.status === "erasing")) throw new s();
13
+ let l = await o.query(a(e).where(t(n("tenantId", c.tenantId), n("subjectId", c.sourceId), r("status", ["withdrawn", "completed"]))).descriptor);
14
+ for (let t of l) await o.delete(e.tableName, String(t.id));
15
+ },
16
+ catch: (e) => e
17
+ });
18
+ export { s as PrivacyMergeRefused, c as mergePrivacyRequests };
@@ -1,34 +1,34 @@
1
- import { PrivacyCoordinatorFailure as e } from "./privacyContract.js";
2
- import { PrivacyRequestRefused as t, dataStorePrivacyRequests as n } from "./privacyRequests.js";
1
+ import { PrivacyRequestRefused as e, dataStorePrivacyRequests as t } from "./privacyRequests.js";
2
+ import { PrivacyCoordinatorFailure as n } from "./privacyContract.js";
3
3
  import { Effect as r, Result as i } from "effect";
4
4
  import { randomUUID as a } from "node:crypto";
5
5
  // src/privacyCoordinator.ts
6
- var o = (t) => new e({
7
- code: t,
6
+ var o = (e) => new n({
7
+ code: e,
8
8
  completed: [],
9
9
  missing: []
10
- }), s = (e) => r.tryPromise({
11
- try: e,
12
- catch: (e) => o(e instanceof t ? e.code : "request_unavailable")
10
+ }), s = (t) => r.tryPromise({
11
+ try: t,
12
+ catch: (t) => o(t instanceof e ? t.code : "request_unavailable")
13
13
  }), c = (e) => r.suspend(() => e.type !== "user" || !e.id.trim() || !e.tenantId.trim() ? r.fail(o("identity_required")) : r.succeed(Object.freeze({
14
14
  subjectId: e.id,
15
15
  tenantId: e.tenantId,
16
16
  kind: e.kind === "guest" ? "guest" : "user"
17
- }))), l = (t, l, u = {}) => {
18
- let d = n(t, {
17
+ }))), l = (e, l, u = {}) => {
18
+ let d = t(e, {
19
19
  withdrawalMs: u.withdrawalMs ?? 2592e6,
20
20
  ...u.now === void 0 ? {} : { now: u.now }
21
- }), f = (t) => r.suspend(() => {
22
- let n = l.coverage(t);
23
- return n.missing.length !== 0 || n.participants.length === 0 ? r.fail(new e({
21
+ }), f = (e) => r.suspend(() => {
22
+ let t = l.coverage(e);
23
+ return t.missing.length !== 0 || t.participants.length === 0 ? r.fail(new n({
24
24
  code: "coverage_missing",
25
25
  completed: [],
26
- missing: [...n.missing]
26
+ missing: [...t.missing]
27
27
  })) : r.void;
28
- }), p = (t) => new e({
29
- code: t.code === "coverage_missing" ? "coverage_missing" : t.code === "invalid_request" ? "invalid_request" : t.code === "unavailable" ? "request_unavailable" : "hook_failed",
30
- completed: [...t.completed],
31
- missing: [...t.missing]
28
+ }), p = (e) => new n({
29
+ code: e.code === "coverage_missing" ? "coverage_missing" : e.code === "invalid_request" ? "invalid_request" : e.code === "unavailable" ? "request_unavailable" : "hook_failed",
30
+ completed: [...e.completed],
31
+ missing: [...e.missing]
32
32
  });
33
33
  return {
34
34
  requestErasure: (e, t = a()) => r.gen(function* () {
@@ -105,7 +105,7 @@ export declare const privacyRequestsTable: Table<"_voltro_privacy_requests", Fie
105
105
  readonly tenantId: ColumnBuilder<string | null, "text", boolean>;
106
106
  readonly kind: ColumnBuilder<"user" | "guest", "text", boolean>;
107
107
  readonly activeKey: ColumnBuilder<string, "text", boolean>;
108
- readonly status: ColumnBuilder<"completed" | "pending" | "withdrawn" | "erasing", "text", boolean>;
108
+ readonly status: ColumnBuilder<"pending" | "completed" | "withdrawn" | "erasing", "text", boolean>;
109
109
  readonly requestedAt: ColumnBuilder<Date, "timestamp", boolean>;
110
110
  readonly dueAt: ColumnBuilder<Date, "timestamp", boolean>;
111
111
  readonly claimedAt: ColumnBuilder<Date | null, "timestamp", boolean>;
@@ -1,13 +1,15 @@
1
- import { PrivacyCoordinatorFailure as e, PrivacyExportPackageSchema as t, PrivacyRequestReceiptSchema as n, jsonPrivacyExport as r } from "./privacyContract.js";
2
- import { PrivacyRequestRefused as i, dataStorePrivacyRequests as a, privacyRequestsTable as o } from "./privacyRequests.js";
3
- import { dataStorePrivacyCoordinator as s, privacyTargetFromSubject as c } from "./privacyCoordinator.js";
4
- import { PrivacyService as l } from "./privacyService.js";
5
- import { exportSelfDescriptor as u, privacyRpcClientImports as d, requestErasureDescriptor as f, requestStatusDescriptor as p, withdrawErasureDescriptor as m } from "./privacyRpc.js";
6
- import { Effect as h, Layer as g, Schema as _ } from "effect";
7
- import { fileURLToPath as v } from "node:url";
8
- import { definePlugin as y } from "@voltro/protocol";
1
+ import { mergePrivacyRequests as e } from "./accountMerge.js";
2
+ import { PrivacyCoordinatorFailure as t, PrivacyExportPackageSchema as n, PrivacyRequestReceiptSchema as r, jsonPrivacyExport as i } from "./privacyContract.js";
3
+ import { dataStorePrivacyCoordinator as a, privacyTargetFromSubject as o } from "./privacyCoordinator.js";
4
+ import { PrivacyRequestRefused as s, dataStorePrivacyRequests as c, privacyRequestsTable as l } from "./privacyRequests.js";
5
+ import { PrivacyService as u } from "./privacyService.js";
6
+ import { exportSelfDescriptor as d, privacyRpcClientImports as f, requestErasureDescriptor as p, requestStatusDescriptor as m, withdrawErasureDescriptor as h } from "./privacyRpc.js";
7
+ import { Effect as g, Layer as _, Schema as v } from "effect";
8
+ import { decodePrivacyStatus as y } from "@voltro/protocol/inspect";
9
+ import { fileURLToPath as b } from "node:url";
10
+ import { PluginPrivacyFailure as x, definePlugin as S } from "@voltro/protocol";
9
11
  // src/privacyPlugin.ts
10
- var b = {
12
+ var C = {
11
13
  slots: { exportPackage: {
12
14
  defaultExport: "jsonPrivacyExport",
13
15
  fixtureExport: "privacyExportFixture"
@@ -18,121 +20,199 @@ var b = {
18
20
  fixtureExport: "privacyPortFixture"
19
21
  } },
20
22
  events: []
21
- }, x = () => new e({
23
+ }, w = () => new t({
22
24
  code: "request_unavailable",
23
25
  completed: [],
24
26
  missing: []
25
- }), S = (e) => e.requestId, C = (n = {}) => {
26
- let b = n.withdrawalMs ?? 2592e6;
27
- if (!Number.isSafeInteger(b) || b < 0) throw Error("Privacy withdrawal window must be a non-negative safe integer");
28
- let C = n.exportPackage ?? r, w, T, E, D, O = (e) => h.suspend(() => w === void 0 ? h.fail(x()) : e(w)), k = {
29
- requestErasure: (e, t) => c(e).pipe(h.flatMap(() => O((n) => n.requestErasure(e, t)))),
30
- readSelf: (e, t) => c(e).pipe(h.flatMap(() => O((n) => n.readSelf(e, t)))),
31
- withdraw: (e, t) => c(e).pipe(h.flatMap(() => O((n) => n.withdraw(e, t)))),
32
- exportSelf: (e, n) => c(e).pipe(h.flatMap(() => O((t) => t.exportSelf(e, n))), h.flatMap((e) => h.try({
33
- try: () => _.decodeUnknownSync(t)(C(e)),
34
- catch: x
35
- }))),
36
- execute: (e) => O((t) => t.execute(e)),
37
- dispatch: (e, t) => O((n) => n.dispatch(e, t))
38
- }, A = [
39
- {
40
- ...f,
41
- execute: (e, t) => k.requestErasure(t.request.subject, S(e))
42
- },
27
+ }), T = (e) => e.requestId, E = (r = {}) => {
28
+ let C = r.withdrawalMs ?? 2592e6;
29
+ if (!Number.isSafeInteger(C) || C < 0) throw Error("Privacy withdrawal window must be a non-negative safe integer");
30
+ let E = r.exportPackage ?? i, D, O, k, A, j = Object.freeze({}), M = (e) => D !== void 0 && j === e, N = (e, t) => g.suspend(() => M(e) ? t() : g.fail(w())).pipe(g.flatMap((t) => M(e) ? g.succeed(t) : g.fail(w())), g.catchDefect(() => g.fail(w()))), P = (e) => {
31
+ let t = D, n = j;
32
+ return N(n, () => t === void 0 ? g.fail(w()) : e(t, n));
33
+ }, F = (e, n) => {
34
+ try {
35
+ let t = structuredClone(e), r = P((e, r) => n(e, t, r));
36
+ return o(t).pipe(g.flatMap(() => r));
37
+ } catch {
38
+ return g.fail(new t({
39
+ code: "identity_required",
40
+ completed: [],
41
+ missing: []
42
+ }));
43
+ }
44
+ }, I = {
45
+ requestErasure: (e, t) => F(e, (e, n) => e.requestErasure(n, t)),
46
+ readSelf: (e, t) => F(e, (e, n) => e.readSelf(n, t)),
47
+ withdraw: (e, t) => F(e, (e, n) => e.withdraw(n, t)),
48
+ exportSelf: (e, t) => F(e, (e, r, i) => e.exportSelf(r, t).pipe(g.flatMap((e) => N(i, () => g.try({
49
+ try: () => v.decodeUnknownSync(n)(E(e)),
50
+ catch: w
51
+ }))))),
52
+ execute: (e) => P((t) => t.execute(e)),
53
+ dispatch: (e, t) => {
54
+ let n = {
55
+ limit: e.limit,
56
+ ...e.after === void 0 ? {} : { after: { ...e.after } }
57
+ };
58
+ return P((e, r) => e.dispatch(n, async (e) => {
59
+ if (!M(r)) throw w();
60
+ let n = await t(e);
61
+ if (!M(r)) throw w();
62
+ return n;
63
+ }));
64
+ }
65
+ }, L = [
43
66
  {
44
67
  ...p,
45
- execute: (e, t) => k.readSelf(t.request.subject, e.requestId)
68
+ execute: (e, t) => I.requestErasure(t.request.subject, T(e))
46
69
  },
47
70
  {
48
71
  ...m,
49
- execute: (e, t) => k.withdraw(t.request.subject, e.requestId)
72
+ execute: (e, t) => I.readSelf(t.request.subject, e.requestId)
73
+ },
74
+ {
75
+ ...h,
76
+ execute: (e, t) => I.withdraw(t.request.subject, e.requestId)
50
77
  },
51
78
  {
52
- ...u,
53
- execute: (e, t) => k.exportSelf(t.request.subject, S(e))
79
+ ...d,
80
+ execute: (e, t) => I.exportSelf(t.request.subject, T(e))
54
81
  }
55
82
  ];
56
- return y({
83
+ return S({
57
84
  name: "@voltro/plugin-deactivation",
58
85
  description: "Durable subject privacy requests, withdrawal and JSON export.",
59
86
  permissions: ["store:write", "inspect:read"],
60
- services: g.succeed(l, k),
61
- routes: A,
62
- rpcClientDescriptors: d,
63
- sources: v(new URL("./privacy-app", "" + import.meta.url)),
64
- extendSchema: { tables: [o] },
87
+ services: _.succeed(u, I),
88
+ routes: L,
89
+ rpcClientDescriptors: f,
90
+ sources: b(new URL("./privacy-app", "" + import.meta.url)),
91
+ extendSchema: { tables: [l] },
92
+ subjectMerge: {
93
+ tables: [l.tableName],
94
+ kinds: ["guest"]
95
+ },
96
+ onMergeAccounts: (t) => e(t),
65
97
  inspectEndpoints: [{
66
98
  method: "GET",
67
99
  path: "/status",
68
100
  scope: "shared-store",
69
101
  description: "Bounded recent privacy receipts and declared subject hook coverage; no subject or tenant identifiers.",
70
- handler: () => h.tryPromise({
71
- try: async () => T === void 0 || D === void 0 ? {
102
+ handler: () => {
103
+ let e = O, t = A, n = j;
104
+ return e === void 0 || t === void 0 ? g.succeed({
72
105
  kind: "json",
73
106
  status: 503,
74
107
  data: { error: "privacy_unavailable" }
75
- } : {
76
- kind: "json",
77
- data: {
78
- ...await T.inspectRecent(),
79
- withdrawalMs: b,
80
- limit: 100,
81
- coverage: {
82
- user: D.coverage("user"),
83
- guest: D.coverage("guest")
84
- }
85
- }
86
- },
87
- catch: x
88
- })
108
+ }) : N(n, () => g.tryPromise({
109
+ try: async () => {
110
+ let r = await e.inspectRecent();
111
+ if (!M(n)) throw w();
112
+ let i = y({
113
+ ...r,
114
+ withdrawalMs: C,
115
+ limit: 100,
116
+ coverage: {
117
+ user: t.coverage("user"),
118
+ guest: t.coverage("guest")
119
+ }
120
+ });
121
+ if (!M(n)) throw w();
122
+ return {
123
+ kind: "json",
124
+ data: i
125
+ };
126
+ },
127
+ catch: w
128
+ }));
129
+ }
89
130
  }],
90
131
  subjectPrivacy: {
91
- tables: [o.tableName],
132
+ tables: [l.tableName],
92
133
  kinds: ["user", "guest"],
93
134
  erasePhase: "finalize"
94
135
  },
95
- onExport: (e, t) => h.tryPromise({
96
- try: async () => {
97
- if (T === void 0) throw x();
98
- return T.exportOwned({
99
- subjectId: e,
100
- tenantId: t.tenantId,
101
- kind: t.kind
102
- });
103
- },
104
- catch: x
105
- }),
106
- onErase: (t, n) => h.tryPromise({
107
- try: async () => {
108
- if (T === void 0 || n.completed === void 0) throw x();
109
- (await T.readWorker(n.requestId))?.receipt.status !== "completed" && await T.finish(n.requestId, {
110
- subjectId: t,
111
- tenantId: n.tenantId,
112
- kind: n.kind
113
- }, [...n.completed, "@voltro/plugin-deactivation"]);
114
- },
115
- catch: (t) => new e({
116
- code: t instanceof i ? t.code : "request_unavailable",
117
- completed: [],
118
- missing: []
119
- })
120
- }),
121
- bindDataStore: (e, t) => {
122
- if (t?.privacyRegistry === void 0) throw Error("Privacy orchestration requires the installing app privacy registry");
123
- if (E !== void 0 && E !== e) throw Error("Privacy plugin instance cannot be shared between app stores");
124
- if (D !== void 0 && D !== t.privacyRegistry) throw Error("Privacy plugin instance cannot be shared between app registries");
125
- E = e, D = t.privacyRegistry, T = a(e, {
126
- withdrawalMs: b,
127
- ...n.now === void 0 ? {} : { now: n.now }
128
- }), w = n.operations ?? s(e, t.privacyRegistry, {
129
- withdrawalMs: b,
130
- ...n.now === void 0 ? {} : { now: n.now }
136
+ onExport: (e, t) => {
137
+ let n = O, r = j, i = {
138
+ subjectId: e,
139
+ tenantId: t.tenantId,
140
+ kind: t.kind
141
+ };
142
+ return N(r, () => g.tryPromise({
143
+ try: async () => {
144
+ if (n === void 0) throw w();
145
+ return n.exportOwned(i);
146
+ },
147
+ catch: w
148
+ }));
149
+ },
150
+ onErase: (e, n) => {
151
+ let r = O, i = j, a = n.requestId, o = n.completed === void 0 ? void 0 : [...n.completed], c = {
152
+ subjectId: e,
153
+ tenantId: n.tenantId,
154
+ kind: n.kind
155
+ };
156
+ return N(i, () => g.tryPromise({
157
+ try: async () => {
158
+ if (r === void 0 || o === void 0) throw w();
159
+ let e = await r.readWorker(a);
160
+ if (!M(i)) throw w();
161
+ e?.receipt.status !== "completed" && await r.finish(a, c, [...o, "@voltro/plugin-deactivation"]);
162
+ },
163
+ catch: (e) => new t({
164
+ code: e instanceof s ? e.code : "request_unavailable",
165
+ completed: [],
166
+ missing: []
167
+ })
168
+ }));
169
+ },
170
+ bindDataStore: (e, n) => {
171
+ if (n?.privacyRegistry === void 0) throw Error("Privacy orchestration requires the installing app privacy registry");
172
+ if (k !== void 0 && k !== e) throw Error("Privacy plugin instance cannot be shared between app stores");
173
+ if (A !== void 0 && A !== n.privacyRegistry) throw Error("Privacy plugin instance cannot be shared between app registries");
174
+ k = e, A = n.privacyRegistry, j = Object.freeze({}), D = void 0, O = void 0;
175
+ let i = A, o = j, s = (e) => {
176
+ let t = e.assertCurrent;
177
+ return {
178
+ ...e,
179
+ assertCurrent: () => {
180
+ if (!M(o) || t?.() !== void 0) throw w();
181
+ }
182
+ };
183
+ }, l = {
184
+ coverage: (e) => {
185
+ if (!M(o)) throw w();
186
+ return i.coverage(e);
187
+ },
188
+ exportSubject: (e) => N(o, () => i.exportSubject(s(e))).pipe(g.mapError((n) => n instanceof t ? new x({
189
+ code: "unavailable",
190
+ operation: "export",
191
+ requestId: e.requestId,
192
+ plugin: null,
193
+ completed: [],
194
+ missing: []
195
+ }) : n)),
196
+ eraseSubject: (e) => N(o, () => i.eraseSubject(s(e))).pipe(g.mapError((n) => n instanceof t ? new x({
197
+ code: "unavailable",
198
+ operation: "erase",
199
+ requestId: e.requestId,
200
+ plugin: null,
201
+ completed: [],
202
+ missing: []
203
+ }) : n))
204
+ };
205
+ O = c(e, {
206
+ withdrawalMs: C,
207
+ ...r.now === void 0 ? {} : { now: r.now }
208
+ }), D = r.operations ?? a(e, l, {
209
+ withdrawalMs: C,
210
+ ...r.now === void 0 ? {} : { now: r.now }
131
211
  });
132
212
  },
133
- onDeactivate: () => h.sync(() => {
134
- w = void 0, T = void 0, E = void 0, D = void 0;
213
+ onDeactivate: () => g.sync(() => {
214
+ j = Object.freeze({}), D = void 0, O = void 0, k = void 0, A = void 0;
135
215
  })
136
216
  });
137
217
  };
138
- export { e as PrivacyCoordinatorFailure, t as PrivacyExportPackageSchema, n as PrivacyRequestReceiptSchema, l as PrivacyService, r as jsonPrivacyExport, C as privacyPlugin, o as privacyRequestsTable, b as privacySystemContract };
218
+ export { t as PrivacyCoordinatorFailure, n as PrivacyExportPackageSchema, r as PrivacyRequestReceiptSchema, u as PrivacyService, i as jsonPrivacyExport, E as privacyPlugin, l as privacyRequestsTable, C as privacySystemContract };
@@ -1,9 +1,9 @@
1
- import { PrivacyCoordinatorFailure as e, jsonPrivacyExport as t } from "./privacyContract.js";
2
- import { PrivacyService as n } from "./privacyService.js";
1
+ import { PrivacyService as e } from "./privacyService.js";
2
+ import { PrivacyCoordinatorFailure as t, jsonPrivacyExport as n } from "./privacyContract.js";
3
3
  import { Effect as r, Layer as i } from "effect";
4
4
  import { systemPortFixture as a } from "@voltro/testing/system";
5
5
  // src/privacyTesting.ts
6
- var o = () => r.fail(new e({
6
+ var o = () => r.fail(new t({
7
7
  code: "request_unavailable",
8
8
  completed: [],
9
9
  missing: []
@@ -15,10 +15,10 @@ var o = () => r.fail(new e({
15
15
  execute: o,
16
16
  dispatch: o,
17
17
  ...e
18
- }), c = i.succeed(n, s()), l = a({
19
- tag: n,
18
+ }), c = i.succeed(e, s()), l = a({
19
+ tag: e,
20
20
  fakeLayer: c,
21
- read: r.flatMap(n, (e) => e.readSelf({
21
+ read: r.flatMap(e, (e) => e.readSelf({
22
22
  type: "user",
23
23
  id: "fixture",
24
24
  tenantId: "fixture"
@@ -26,9 +26,9 @@ var o = () => r.fail(new e({
26
26
  expected: null
27
27
  }), u = {
28
28
  kind: "slot",
29
- defaultImplementation: t,
29
+ defaultImplementation: n,
30
30
  defaultProbe: {
31
- run: () => r.sync(() => t({
31
+ run: () => r.sync(() => n({
32
32
  requestId: "export",
33
33
  plugins: []
34
34
  })),
@@ -39,7 +39,7 @@ var o = () => r.fail(new e({
39
39
  },
40
40
  overrideProbe: {
41
41
  run: () => r.sync(() => ({
42
- ...t({
42
+ ...n({
43
43
  requestId: "export",
44
44
  plugins: []
45
45
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voltro/plugin-deactivation",
3
- "version": "0.89.2",
3
+ "version": "0.91.0",
4
4
  "description": "Deactivation plugin — ships the `deactivation()` schema mixin (deactivatedAt + deactivatedBy → Actor). A deactivated subject can't log in but its data stays VISIBLE (distinct from soft-delete, which hides + anonymises). Pure schema mixin, like audit().",
5
5
  "keywords": [
6
6
  "voltro",
@@ -68,16 +68,16 @@
68
68
  "node": ">=24.0.0"
69
69
  },
70
70
  "dependencies": {
71
- "@voltro/database": "0.89.2",
72
- "@voltro/plugin-audit": "0.89.2",
73
- "@voltro/protocol": "0.89.2",
74
- "@voltro/workflow": "0.89.2",
75
- "@voltro/runtime": "0.89.2"
71
+ "@voltro/database": "0.91.0",
72
+ "@voltro/plugin-audit": "0.91.0",
73
+ "@voltro/protocol": "0.91.0",
74
+ "@voltro/workflow": "0.91.0",
75
+ "@voltro/runtime": "0.91.0"
76
76
  },
77
77
  "peerDependencies": {
78
- "@voltro/plugin-auth": "0.89.2",
79
- "effect": "4.1.2",
80
- "@voltro/testing": "0.89.2"
78
+ "@voltro/plugin-auth": "0.91.0",
79
+ "effect": "4.1.4",
80
+ "@voltro/testing": "0.91.0"
81
81
  },
82
82
  "peerDependenciesMeta": {
83
83
  "@voltro/plugin-auth": {