@reventlessdev/reventless-core 3.0.0-alpha.319 → 3.0.0-alpha.321
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/CHANGELOG.md +15 -0
- package/package.json +5 -5
- package/src/components/EventLog/EventLog_Operations.res +11 -6
- package/src/components/EventLog/EventLog_Operations.res.mjs +5 -3
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res +1 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +1 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +119 -23
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +144 -52
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +1 -1
- package/tests/eventlog/EventLogFixtures.res +5 -0
- package/tests/eventlog/EventLogFixtures.res.mjs +4 -0
- package/tests/eventlog/EventLogPiiTest.res +18 -0
- package/tests/eventlog/EventLogPiiTest.res.mjs +18 -0
- package/tests/pii/Aggregate/PiiCustomer.res +14 -0
- package/tests/pii/Aggregate/PiiCustomer.res.mjs +57 -0
- package/tests/pii/PiiInstallTest.res.mjs +2 -2
- package/tests/pii/PiiMember.res +5 -0
- package/tests/pii/PiiMember.res.mjs +9 -0
- package/tests/pii/PiiPpxTest.res +9 -0
- package/tests/pii/PiiPpxTest.res.mjs +9 -0
- package/tests/pii/PiiStreamSubjectTest.res +69 -0
- package/tests/pii/PiiStreamSubjectTest.res.mjs +106 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,21 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 3.0.0-alpha.321 (2026-10-30)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **outbound:** a work item with personal data is stored like an event ([5588bbe](https://github.com/ReventlessDev/reventless-core/commit/5588bbeaccc5032800d02871243c70147c669ebd))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# 3.0.0-alpha.320 (2026-10-30)
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **pii:** a consumed event's field needs no subject ([e2b71a7](https://github.com/ReventlessDev/reventless-core/commit/e2b71a7f4cc9b5a34db42501e3bb2ee31712a909))
|
|
18
|
+
* **pii:** in an aggregate's spec, a field that names no subject is about the aggregate ([dc77529](https://github.com/ReventlessDev/reventless-core/commit/dc7752955fb97c34fd9512ac79fbd0242f05ce32))
|
|
19
|
+
|
|
20
|
+
|
|
6
21
|
# 3.0.0-alpha.319 (2026-10-30)
|
|
7
22
|
|
|
8
23
|
### Features
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reventlessdev/reventless-core",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.321",
|
|
4
4
|
"description": "Core package for Reventless framework",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"jest": {
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
|
|
34
34
|
"@reventlessdev/rescript-node": "2.0.0-alpha.24",
|
|
35
35
|
"@reventlessdev/rescript-jest": "1.0.0-alpha.13",
|
|
36
|
-
"@reventlessdev/rescript-pulumi-pulumi": "3.0.0-alpha.0",
|
|
37
|
-
"@reventlessdev/rescript-ssh2": "2.0.0-alpha.25",
|
|
38
|
-
"@reventlessdev/reventless-infra": "3.0.0-alpha.216",
|
|
39
36
|
"@reventlessdev/rescript-uuid": "2.0.0-alpha.1",
|
|
37
|
+
"@reventlessdev/rescript-ssh2": "2.0.0-alpha.25",
|
|
38
|
+
"@reventlessdev/rescript-pulumi-pulumi": "3.0.0-alpha.0",
|
|
39
|
+
"@reventlessdev/reventless-infra": "3.0.0-alpha.218",
|
|
40
40
|
"@reventlessdev/reventless-interop": "3.0.0-alpha.42",
|
|
41
|
-
"@reventlessdev/reventless-spec": "3.0.0-alpha.
|
|
41
|
+
"@reventlessdev/reventless-spec": "3.0.0-alpha.189"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"rescript": "12.3.1",
|
|
@@ -72,11 +72,11 @@ module Make = (Spec: ReventlessInfra.EventLog.T, Ops: Ops with module Spec = Spe
|
|
|
72
72
|
let failure = ref(None)
|
|
73
73
|
for i in 0 to events'->Array.length - 1 {
|
|
74
74
|
if failure.contents->Option.isNone {
|
|
75
|
-
let (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
switch await Reventless.Pii.sealData(Spec.eventSchema, ~eventType, data) {
|
|
75
|
+
let event' = events'->Array.getUnsafe(i)
|
|
76
|
+
let (eventType, data) = event'.event->Message.encode(Spec.eventSchema)->Message.splitMessage
|
|
77
|
+
// The aggregate is the subject of a field that names none.
|
|
78
|
+
let streamId = event'.id->Spec.Id.toString
|
|
79
|
+
switch await Reventless.Pii.sealData(Spec.eventSchema, ~eventType, ~streamId, data) {
|
|
80
80
|
| Error(e) => failure := Some(`cannot seal ${eventType}: ${e->Reventless.Pii.errorMessage}`)
|
|
81
81
|
| Ok(sealed) =>
|
|
82
82
|
switch Reventless.Pii.unsealedField(Spec.eventSchema, ~eventType, sealed) {
|
|
@@ -360,7 +360,12 @@ module Make = (Spec: ReventlessInfra.EventLog.T, Ops: Ops with module Spec = Spe
|
|
|
360
360
|
stream->Stream.mapEffect(event =>
|
|
361
361
|
Effect.promise(async () => {
|
|
362
362
|
let (eventType, data) = event->Message.encode(Spec.eventSchema)->Message.splitMessage
|
|
363
|
-
let sealed = switch await Reventless.Pii.sealData(
|
|
363
|
+
let sealed = switch await Reventless.Pii.sealData(
|
|
364
|
+
Spec.eventSchema,
|
|
365
|
+
~eventType,
|
|
366
|
+
~streamId=id->Spec.Id.toString,
|
|
367
|
+
data,
|
|
368
|
+
) {
|
|
364
369
|
| Ok(sealed) => sealed
|
|
365
370
|
| Error(e) =>
|
|
366
371
|
JsError.throwWithMessage(
|
|
@@ -40,9 +40,11 @@ function Make(Spec) {
|
|
|
40
40
|
let failure;
|
|
41
41
|
for (let i = 0, i_finish = events$p.length; i < i_finish; ++i) {
|
|
42
42
|
if (Stdlib_Option.isNone(failure)) {
|
|
43
|
-
let
|
|
43
|
+
let event$p = events$p[i];
|
|
44
|
+
let match = Message$ReventlessCore.splitMessage(Message$ReventlessCore.encode(event$p.event, Spec.eventSchema));
|
|
44
45
|
let eventType = match[0];
|
|
45
|
-
let
|
|
46
|
+
let streamId = Spec.Id.toString(event$p.id);
|
|
47
|
+
let e = await Pii$Reventless.sealData(Spec.eventSchema, eventType, streamId, match[1]);
|
|
46
48
|
if (e.TAG === "Ok") {
|
|
47
49
|
let sealed = e._0;
|
|
48
50
|
let field = Pii$Reventless.unsealedField(Spec.eventSchema, eventType, sealed);
|
|
@@ -316,7 +318,7 @@ function Make(Spec) {
|
|
|
316
318
|
let appendStream = (startingSeqNr, id, stream) => Ops.storage.appendStream(startingSeqNr, Spec.Id.toString(id), Stream.mapEffect(stream, event => Effect$1.promise(async () => {
|
|
317
319
|
let match = Message$ReventlessCore.splitMessage(Message$ReventlessCore.encode(event, Spec.eventSchema));
|
|
318
320
|
let eventType = match[0];
|
|
319
|
-
let sealed = await Pii$Reventless.sealData(Spec.eventSchema, eventType, match[1]);
|
|
321
|
+
let sealed = await Pii$Reventless.sealData(Spec.eventSchema, eventType, Spec.Id.toString(id), match[1]);
|
|
320
322
|
let sealed$1;
|
|
321
323
|
sealed$1 = sealed.TAG === "Ok" ? sealed._0 : Stdlib_JsError.throwWithMessage(`EventLog.appendStream: cannot seal ` + eventType + `: ` + Pii$Reventless.errorMessage(sealed._0));
|
|
322
324
|
return Object.fromEntries([
|
|
@@ -189,7 +189,7 @@ module Make = (
|
|
|
189
189
|
Effect.promise(
|
|
190
190
|
async () => {
|
|
191
191
|
// Phase 1: collect outbound items
|
|
192
|
-
Callback.phase1(eventsArr)
|
|
192
|
+
await Callback.phase1(eventsArr, ~capabilities=Capabilities.capabilities())
|
|
193
193
|
// Sync the post-phase-1 TODO state so consumers awaiting the
|
|
194
194
|
// originating publishEvent observe Pending rows immediately.
|
|
195
195
|
await syncToQueryDb(queryDbOps)
|
|
@@ -108,7 +108,7 @@ function Make(RuntimeEnvironment) {
|
|
|
108
108
|
return [];
|
|
109
109
|
}
|
|
110
110
|
})), events => Stream$1.fromIterable(events))), eventsArr => Effect.promise(async () => {
|
|
111
|
-
Callback.phase1(eventsArr);
|
|
111
|
+
await Callback.phase1(eventsArr, Capabilities.capabilities());
|
|
112
112
|
await syncToQueryDb(queryDbOps);
|
|
113
113
|
Stdlib_Promise.$$catch(Callback.phase2(publishJsonsFn, Capabilities.capabilities()).then(() => syncToQueryDb(queryDbOps)), exn => {
|
|
114
114
|
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown");
|
|
@@ -79,7 +79,10 @@ the AWS entry point kept passing bare events and nothing complained, because its
|
|
|
79
79
|
hand-written copy was internally consistent. The mismatch surfaced only at
|
|
80
80
|
runtime, as `undefined` destructured from a tuple that was never a tuple.
|
|
81
81
|
*/
|
|
82
|
-
type phase1<'event> =
|
|
82
|
+
type phase1<'event> = (
|
|
83
|
+
array<(string, 'event)>,
|
|
84
|
+
~capabilities: Reventless.Capabilities.t,
|
|
85
|
+
) => promise<unit>
|
|
83
86
|
|
|
84
87
|
/** Phase 2: translate all pending items, optionally publishing commands.
|
|
85
88
|
|
|
@@ -109,7 +112,8 @@ module type T = {
|
|
|
109
112
|
|
|
110
113
|
/** Phase 1: update TODO list from a batch of `(sourceId, event)` pairs
|
|
111
114
|
(collect only, no resolve). `sourceId` is the envelope id of the entity the
|
|
112
|
-
event was published for.
|
|
115
|
+
event was published for. `~capabilities` supplies the key a personal item's
|
|
116
|
+
row id is fingerprinted with. */
|
|
113
117
|
let phase1: phase1<Spec.consumedEvent>
|
|
114
118
|
|
|
115
119
|
/** Phase 2: translate all pending items, optionally publishing commands via publishJsons. */
|
|
@@ -201,25 +205,82 @@ module Make = (
|
|
|
201
205
|
)->Effect.runSync
|
|
202
206
|
}
|
|
203
207
|
|
|
204
|
-
|
|
205
|
-
|
|
208
|
+
// A work item that carries personal data is stored the way an event is: its
|
|
209
|
+
// marked fields sealed, and its row keyed by a fingerprint of the key `collect`
|
|
210
|
+
// chose, which may hold the address the work is about. A table key can be
|
|
211
|
+
// neither encrypted nor erased.
|
|
212
|
+
let personalFields = Reventless.Pii.recordFields(Spec.outboundItemSchema)
|
|
213
|
+
let fingerprintPurpose = `outboundWorkItem:${Spec.name}`
|
|
214
|
+
let warnedUnkeyed = ref(false)
|
|
215
|
+
|
|
216
|
+
/** The id a row is stored under, or `None` when it cannot be stored safely. */
|
|
217
|
+
let storedKey = (key, ~capabilities: Reventless.Capabilities.t): option<string> =>
|
|
218
|
+
if personalFields == [] {
|
|
219
|
+
Some(key)
|
|
220
|
+
} else {
|
|
221
|
+
switch capabilities.secrets.fingerprint(~purpose=fingerprintPurpose, key) {
|
|
222
|
+
| Ok(fingerprint) => Some(fingerprint)
|
|
223
|
+
| Error(Unavailable(why)) =>
|
|
224
|
+
if Reventless.Pii.Provider.isRequired() {
|
|
225
|
+
EffectLogger.logError(
|
|
226
|
+
~comp=`OutboundTranslationSlice(${Spec.name})`,
|
|
227
|
+
`a work item was not stored: its row id cannot be fingerprinted (${why})`,
|
|
228
|
+
)->Effect.runSync
|
|
229
|
+
None
|
|
230
|
+
} else {
|
|
231
|
+
if !warnedUnkeyed.contents {
|
|
232
|
+
warnedUnkeyed := true
|
|
233
|
+
EffectLogger.logWarn(
|
|
234
|
+
~comp=`OutboundTranslationSlice(${Spec.name})`,
|
|
235
|
+
`work items carrying personal data are keyed in the clear: no key to fingerprint them with (${why})`,
|
|
236
|
+
)->Effect.runSync
|
|
237
|
+
}
|
|
238
|
+
Some(key)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
let phase1 = async (
|
|
244
|
+
events: array<(string, Spec.consumedEvent)>,
|
|
245
|
+
~capabilities: Reventless.Capabilities.t,
|
|
246
|
+
) =>
|
|
247
|
+
for i in 0 to events->Array.length - 1 {
|
|
248
|
+
let (sourceId, event) = events->Array.getUnsafe(i)
|
|
206
249
|
// Collect new outbound items
|
|
207
|
-
Translation.collect(event, ~sourceId)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
250
|
+
let collected = Translation.collect(event, ~sourceId)
|
|
251
|
+
for j in 0 to collected->Array.length - 1 {
|
|
252
|
+
let (key, item) = collected->Array.getUnsafe(j)
|
|
253
|
+
switch storedKey(key, ~capabilities) {
|
|
254
|
+
| None => ()
|
|
255
|
+
| Some(id) if todoItems->Dict.get(id)->Option.isSome => () // idempotent
|
|
256
|
+
| Some(id) =>
|
|
257
|
+
let json = item->Reventless.Util_Sury.toJson(Spec.outboundItemSchema)
|
|
258
|
+
let stored = switch json {
|
|
259
|
+
| Object(data) if personalFields != [] =>
|
|
260
|
+
(
|
|
261
|
+
await Reventless.Pii.sealRecord(Spec.outboundItemSchema, data)
|
|
262
|
+
)->Result.map(d => JSON.Object(d))
|
|
263
|
+
| other => Ok(other)
|
|
264
|
+
}
|
|
265
|
+
switch stored {
|
|
266
|
+
| Error(e) =>
|
|
267
|
+
EffectLogger.logError(
|
|
268
|
+
~comp=`OutboundTranslationSlice(${Spec.name})`,
|
|
269
|
+
`a work item was not stored: ${e->Reventless.Pii.errorMessage}`,
|
|
270
|
+
)->Effect.runSync
|
|
271
|
+
| Ok(stored) =>
|
|
272
|
+
let row: todoRow = {
|
|
273
|
+
item: stored,
|
|
274
|
+
status: Pending,
|
|
275
|
+
createdAt: now(),
|
|
276
|
+
retryCount: 0,
|
|
277
|
+
maxRetries: Spec.maxRetries,
|
|
278
|
+
}
|
|
279
|
+
todoItems->Dict.set(id, row)
|
|
217
280
|
}
|
|
218
|
-
todoItems->Dict.set(id, row)
|
|
219
281
|
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
223
284
|
|
|
224
285
|
let phase2 = async (
|
|
225
286
|
publishJsons: ReventlessInfra.CommandTopic.publishJsons,
|
|
@@ -253,15 +314,50 @@ module Make = (
|
|
|
253
314
|
let _ = await pending->Array.reduce(Promise.resolve(), async (prev, (id, row)) => {
|
|
254
315
|
let _ = await prev
|
|
255
316
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
317
|
+
// Opened first: a personal field is sealed in the row, and one whose
|
|
318
|
+
// subject was erased since leaves nothing to send.
|
|
319
|
+
let opened = switch row.item {
|
|
320
|
+
| Object(data) if personalFields != [] =>
|
|
321
|
+
switch await Reventless.Pii.openRecord(Spec.outboundItemSchema, data) {
|
|
322
|
+
| Ok(data) =>
|
|
323
|
+
switch Reventless.Pii.goneField(Spec.outboundItemSchema, data) {
|
|
324
|
+
| Some(field) => Error(#Gone(field))
|
|
325
|
+
| None => Ok(JSON.Object(data))
|
|
326
|
+
}
|
|
327
|
+
| Error(e) => Error(#Unopened(e->Reventless.Pii.errorMessage))
|
|
328
|
+
}
|
|
329
|
+
| other => Ok(other)
|
|
330
|
+
}
|
|
331
|
+
let item = switch opened {
|
|
332
|
+
| Error(#Gone(field)) =>
|
|
333
|
+
EffectLogger.logInfo(
|
|
334
|
+
~comp=`OutboundTranslationSlice(${Spec.name})`,
|
|
335
|
+
`${id}: its ${field} was erased; nothing to do`,
|
|
336
|
+
)->Effect.runSync
|
|
337
|
+
todoItems->Dict.set(id, {...row, status: Completed, completedAt: now()})
|
|
338
|
+
None
|
|
339
|
+
| Error(#Unopened(why)) =>
|
|
260
340
|
EffectLogger.logError(
|
|
261
341
|
~comp=`OutboundTranslationSlice(${Spec.name})`,
|
|
262
|
-
|
|
342
|
+
`${id}: its work item does not open: ${why}`,
|
|
263
343
|
)->Effect.runSync
|
|
344
|
+
let updated = row->afterFailedAttempt(~lastError=why)
|
|
345
|
+
todoItems->Dict.set(id, updated)
|
|
346
|
+
if updated.status == Abandoned {
|
|
347
|
+
newlyAbandoned->Array.push(id)
|
|
348
|
+
}
|
|
264
349
|
None
|
|
350
|
+
| Ok(itemJson) =>
|
|
351
|
+
try itemJson->Reventless.Util_Sury.fromJson(Spec.outboundItemSchema)->Some catch {
|
|
352
|
+
| exn =>
|
|
353
|
+
let errMsg =
|
|
354
|
+
exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown")
|
|
355
|
+
EffectLogger.logError(
|
|
356
|
+
~comp=`OutboundTranslationSlice(${Spec.name})`,
|
|
357
|
+
`failed to decode outboundItem: ${errMsg}`,
|
|
358
|
+
)->Effect.runSync
|
|
359
|
+
None
|
|
360
|
+
}
|
|
265
361
|
}
|
|
266
362
|
|
|
267
363
|
switch item {
|
|
@@ -4,7 +4,10 @@ import * as Sury from "sury";
|
|
|
4
4
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
5
5
|
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
6
6
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
7
|
+
import * as Stdlib_Result from "@rescript/runtime/lib/es6/Stdlib_Result.js";
|
|
7
8
|
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
10
|
+
import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
|
|
8
11
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
9
12
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
10
13
|
import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
|
|
@@ -82,27 +85,63 @@ function Make(Spec) {
|
|
|
82
85
|
return Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `retries exhausted for ` + id + `, and the abandonment command could not be published: ` + errMsg));
|
|
83
86
|
}
|
|
84
87
|
};
|
|
85
|
-
let
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
let personalFields = Pii$Reventless.recordFields(Spec.outboundItemSchema);
|
|
89
|
+
let fingerprintPurpose = `outboundWorkItem:` + Spec.name;
|
|
90
|
+
let warnedUnkeyed = {
|
|
91
|
+
contents: false
|
|
92
|
+
};
|
|
93
|
+
let storedKey = (key, capabilities) => {
|
|
94
|
+
if (Primitive_object.equal(personalFields, [])) {
|
|
95
|
+
return key;
|
|
96
|
+
}
|
|
97
|
+
let fingerprint = capabilities.secrets.fingerprint(fingerprintPurpose, key);
|
|
98
|
+
if (fingerprint.TAG === "Ok") {
|
|
99
|
+
return fingerprint._0;
|
|
100
|
+
}
|
|
101
|
+
let why = fingerprint._0._0;
|
|
102
|
+
if (Pii$Reventless.Provider.isRequired()) {
|
|
103
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `a work item was not stored: its row id cannot be fingerprinted (` + why + `)`));
|
|
104
|
+
return;
|
|
105
|
+
} else {
|
|
106
|
+
if (!warnedUnkeyed.contents) {
|
|
107
|
+
warnedUnkeyed.contents = true;
|
|
108
|
+
Effect.runSync(EffectLogger$ReventlessCore.logWarn(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `work items carrying personal data are keyed in the clear: no key to fingerprint them with (` + why + `)`));
|
|
109
|
+
}
|
|
110
|
+
return key;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
let phase1 = async (events, capabilities) => {
|
|
114
|
+
for (let i = 0, i_finish = events.length; i < i_finish; ++i) {
|
|
115
|
+
let match = events[i];
|
|
116
|
+
let collected = Translation.collect(match[1], match[0]);
|
|
117
|
+
for (let j = 0, j_finish = collected.length; j < j_finish; ++j) {
|
|
118
|
+
let match$1 = collected[j];
|
|
119
|
+
let id = storedKey(match$1[0], capabilities);
|
|
120
|
+
if (id !== undefined && !Stdlib_Option.isSome(todoItems[id])) {
|
|
121
|
+
let json = Util_Sury$Reventless.toJson(match$1[1], Spec.outboundItemSchema);
|
|
122
|
+
let stored;
|
|
123
|
+
stored = typeof json === "object" && json !== null && !Array.isArray(json) && Primitive_object.notequal(personalFields, []) ? Stdlib_Result.map(await Pii$Reventless.sealRecord(Spec.outboundItemSchema, json), d => (d)) : ({
|
|
124
|
+
TAG: "Ok",
|
|
125
|
+
_0: json
|
|
126
|
+
});
|
|
127
|
+
if (stored.TAG === "Ok") {
|
|
128
|
+
let row_item = stored._0;
|
|
129
|
+
let row_createdAt = new Date().toISOString();
|
|
130
|
+
let row_maxRetries = Spec.maxRetries;
|
|
131
|
+
let row = {
|
|
132
|
+
item: row_item,
|
|
133
|
+
status: "Pending",
|
|
134
|
+
createdAt: row_createdAt,
|
|
135
|
+
retryCount: 0,
|
|
136
|
+
maxRetries: row_maxRetries
|
|
137
|
+
};
|
|
138
|
+
todoItems[id] = row;
|
|
139
|
+
} else {
|
|
140
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `a work item was not stored: ` + Pii$Reventless.errorMessage(stored._0)));
|
|
141
|
+
}
|
|
92
142
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
let row_maxRetries = Spec.maxRetries;
|
|
96
|
-
let row = {
|
|
97
|
-
item: row_item,
|
|
98
|
-
status: "Pending",
|
|
99
|
-
createdAt: row_createdAt,
|
|
100
|
-
retryCount: 0,
|
|
101
|
-
maxRetries: row_maxRetries
|
|
102
|
-
};
|
|
103
|
-
todoItems[id] = row;
|
|
104
|
-
});
|
|
105
|
-
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
106
145
|
};
|
|
107
146
|
let phase2 = async (publishJsons, capabilities) => {
|
|
108
147
|
let newlyAbandoned = [];
|
|
@@ -131,22 +170,75 @@ function Make(Spec) {
|
|
|
131
170
|
let row = param[1];
|
|
132
171
|
let id = param[0];
|
|
133
172
|
await prev;
|
|
173
|
+
let data = row.item;
|
|
174
|
+
let opened;
|
|
175
|
+
if (typeof data === "object" && data !== null && !Array.isArray(data) && Primitive_object.notequal(personalFields, [])) {
|
|
176
|
+
let data$1 = await Pii$Reventless.openRecord(Spec.outboundItemSchema, data);
|
|
177
|
+
if (data$1.TAG === "Ok") {
|
|
178
|
+
let data$2 = data$1._0;
|
|
179
|
+
let field = Pii$Reventless.goneField(Spec.outboundItemSchema, data$2);
|
|
180
|
+
opened = field !== undefined ? ({
|
|
181
|
+
TAG: "Error",
|
|
182
|
+
_0: {
|
|
183
|
+
NAME: "Gone",
|
|
184
|
+
VAL: field
|
|
185
|
+
}
|
|
186
|
+
}) : ({
|
|
187
|
+
TAG: "Ok",
|
|
188
|
+
_0: data$2
|
|
189
|
+
});
|
|
190
|
+
} else {
|
|
191
|
+
opened = {
|
|
192
|
+
TAG: "Error",
|
|
193
|
+
_0: {
|
|
194
|
+
NAME: "Unopened",
|
|
195
|
+
VAL: Pii$Reventless.errorMessage(data$1._0)
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
opened = {
|
|
201
|
+
TAG: "Ok",
|
|
202
|
+
_0: data
|
|
203
|
+
};
|
|
204
|
+
}
|
|
134
205
|
let item;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
206
|
+
if (opened.TAG === "Ok") {
|
|
207
|
+
try {
|
|
208
|
+
item = Primitive_option.some(Util_Sury$Reventless.fromJson(opened._0, Spec.outboundItemSchema));
|
|
209
|
+
} catch (raw_exn) {
|
|
210
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
211
|
+
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown");
|
|
212
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `failed to decode outboundItem: ` + errMsg));
|
|
213
|
+
item = undefined;
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
let match = opened._0;
|
|
217
|
+
if (match.NAME === "Gone") {
|
|
218
|
+
Effect.runSync(EffectLogger$ReventlessCore.logInfo(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, id + `: its ` + match.VAL + ` was erased; nothing to do`));
|
|
219
|
+
let newrecord = {...row};
|
|
220
|
+
newrecord.completedAt = new Date().toISOString();
|
|
221
|
+
newrecord.status = "Completed";
|
|
222
|
+
todoItems[id] = newrecord;
|
|
223
|
+
item = undefined;
|
|
224
|
+
} else {
|
|
225
|
+
let why = match.VAL;
|
|
226
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, id + `: its work item does not open: ` + why));
|
|
227
|
+
let updated = afterFailedAttempt(row, why);
|
|
228
|
+
todoItems[id] = updated;
|
|
229
|
+
if (updated.status === "Abandoned") {
|
|
230
|
+
newlyAbandoned.push(id);
|
|
231
|
+
}
|
|
232
|
+
item = undefined;
|
|
233
|
+
}
|
|
142
234
|
}
|
|
143
235
|
if (item === undefined) {
|
|
144
236
|
return;
|
|
145
237
|
}
|
|
146
|
-
let newrecord = {...row};
|
|
147
|
-
newrecord.processedAt = new Date().toISOString();
|
|
148
|
-
newrecord.status = "Processing";
|
|
149
|
-
todoItems[id] = newrecord;
|
|
238
|
+
let newrecord$1 = {...row};
|
|
239
|
+
newrecord$1.processedAt = new Date().toISOString();
|
|
240
|
+
newrecord$1.status = "Processing";
|
|
241
|
+
todoItems[id] = newrecord$1;
|
|
150
242
|
let result;
|
|
151
243
|
try {
|
|
152
244
|
result = await Translation.translate(id, Primitive_option.valFromOption(item), capabilities);
|
|
@@ -159,11 +251,11 @@ function Make(Spec) {
|
|
|
159
251
|
};
|
|
160
252
|
}
|
|
161
253
|
if (result.TAG === "Ok") {
|
|
162
|
-
let match = result._0;
|
|
163
|
-
if (match !== undefined) {
|
|
254
|
+
let match$1 = result._0;
|
|
255
|
+
if (match$1 !== undefined) {
|
|
164
256
|
let commandJson;
|
|
165
257
|
try {
|
|
166
|
-
commandJson = Util_Sury$Reventless.toJson(match[1], Spec.inboundCommandSchema);
|
|
258
|
+
commandJson = Util_Sury$Reventless.toJson(match$1[1], Spec.inboundCommandSchema);
|
|
167
259
|
} catch (raw_exn$2) {
|
|
168
260
|
let exn$2 = Primitive_exceptions.internalToException(raw_exn$2);
|
|
169
261
|
let errMsg$1 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$2), Stdlib_JsExn.message), "unknown");
|
|
@@ -172,7 +264,7 @@ function Make(Spec) {
|
|
|
172
264
|
}
|
|
173
265
|
if (commandJson !== undefined) {
|
|
174
266
|
try {
|
|
175
|
-
let msg_id = match[0];
|
|
267
|
+
let msg_id = match$1[0];
|
|
176
268
|
let msg_meta = makeMeta();
|
|
177
269
|
let msg$1 = {
|
|
178
270
|
id: msg_id,
|
|
@@ -180,18 +272,18 @@ function Make(Spec) {
|
|
|
180
272
|
commandJson: commandJson
|
|
181
273
|
};
|
|
182
274
|
await publishJsons([msg$1]);
|
|
183
|
-
let newrecord$
|
|
184
|
-
newrecord$
|
|
185
|
-
newrecord$
|
|
186
|
-
todoItems[id] = newrecord$
|
|
275
|
+
let newrecord$2 = {...row};
|
|
276
|
+
newrecord$2.completedAt = new Date().toISOString();
|
|
277
|
+
newrecord$2.status = "Completed";
|
|
278
|
+
todoItems[id] = newrecord$2;
|
|
187
279
|
return;
|
|
188
280
|
} catch (raw_exn$3) {
|
|
189
281
|
let exn$3 = Primitive_exceptions.internalToException(raw_exn$3);
|
|
190
282
|
let errMsg$2 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$3), Stdlib_JsExn.message), "unknown");
|
|
191
283
|
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `failed to publish command: ` + errMsg$2));
|
|
192
|
-
let updated = afterFailedAttempt(row, errMsg$2);
|
|
193
|
-
todoItems[id] = updated;
|
|
194
|
-
if (updated.status === "Abandoned") {
|
|
284
|
+
let updated$1 = afterFailedAttempt(row, errMsg$2);
|
|
285
|
+
todoItems[id] = updated$1;
|
|
286
|
+
if (updated$1.status === "Abandoned") {
|
|
195
287
|
newlyAbandoned.push(id);
|
|
196
288
|
return;
|
|
197
289
|
} else {
|
|
@@ -199,9 +291,9 @@ function Make(Spec) {
|
|
|
199
291
|
}
|
|
200
292
|
}
|
|
201
293
|
} else {
|
|
202
|
-
let updated$
|
|
203
|
-
todoItems[id] = updated$
|
|
204
|
-
if (updated$
|
|
294
|
+
let updated$2 = afterFailedAttempt(row, undefined);
|
|
295
|
+
todoItems[id] = updated$2;
|
|
296
|
+
if (updated$2.status === "Abandoned") {
|
|
205
297
|
newlyAbandoned.push(id);
|
|
206
298
|
return;
|
|
207
299
|
} else {
|
|
@@ -209,16 +301,16 @@ function Make(Spec) {
|
|
|
209
301
|
}
|
|
210
302
|
}
|
|
211
303
|
} else {
|
|
212
|
-
let newrecord$
|
|
213
|
-
newrecord$
|
|
214
|
-
newrecord$
|
|
215
|
-
todoItems[id] = newrecord$
|
|
304
|
+
let newrecord$3 = {...row};
|
|
305
|
+
newrecord$3.completedAt = new Date().toISOString();
|
|
306
|
+
newrecord$3.status = "Completed";
|
|
307
|
+
todoItems[id] = newrecord$3;
|
|
216
308
|
return;
|
|
217
309
|
}
|
|
218
310
|
} else {
|
|
219
|
-
let updated$
|
|
220
|
-
todoItems[id] = updated$
|
|
221
|
-
if (updated$
|
|
311
|
+
let updated$3 = afterFailedAttempt(row, result._0);
|
|
312
|
+
todoItems[id] = updated$3;
|
|
313
|
+
if (updated$3.status === "Abandoned") {
|
|
222
314
|
newlyAbandoned.push(id);
|
|
223
315
|
return;
|
|
224
316
|
} else {
|
|
@@ -41,7 +41,7 @@ function Make(Spec) {
|
|
|
41
41
|
let match$1 = raw.data;
|
|
42
42
|
if (match === undefined) {
|
|
43
43
|
if (typeof match$1 === "object" && match$1 !== null && !Array.isArray(match$1)) {
|
|
44
|
-
let e = await Pii$Reventless.sealData(Spec.eventSchema, raw.eventType, match$1);
|
|
44
|
+
let e = await Pii$Reventless.sealData(Spec.eventSchema, raw.eventType, undefined, match$1);
|
|
45
45
|
if (e.TAG === "Ok") {
|
|
46
46
|
let sealed = e._0;
|
|
47
47
|
let field = Pii$Reventless.unsealedField(Spec.eventSchema, raw.eventType, sealed);
|
|
@@ -15,6 +15,11 @@ module ItemEventLogSpec = {
|
|
|
15
15
|
name: @s.matches(Reventless.Pii.marked(~subject="personId", S.string))
|
|
16
16
|
Reventless.Pii.t<string>,
|
|
17
17
|
})
|
|
18
|
+
// An aggregate's field that names no subject: the aggregate is it.
|
|
19
|
+
| PersonEmailed({
|
|
20
|
+
email: @s.matches(Reventless.Pii.marked(~subject=Reventless.Pii.streamSubject, S.string))
|
|
21
|
+
Reventless.Pii.t<string>,
|
|
22
|
+
})
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
// ─────────────────────────────────────────────────────────────
|
|
@@ -20,6 +20,10 @@ let eventSchema = Sury.union([
|
|
|
20
20
|
TAG: "PersonNamed",
|
|
21
21
|
personId: s.m(Sury.string),
|
|
22
22
|
name: s.m(Pii$Reventless.marked("personId", undefined, Sury.string))
|
|
23
|
+
})),
|
|
24
|
+
Sury.$schema(s => ({
|
|
25
|
+
TAG: "PersonEmailed",
|
|
26
|
+
email: s.m(Pii$Reventless.marked(Pii$Reventless.streamSubject, undefined, Sury.string))
|
|
23
27
|
}))
|
|
24
28
|
]);
|
|
25
29
|
|
|
@@ -73,6 +73,24 @@ describe("EventLog with a personal-data provider", () => {
|
|
|
73
73
|
expect(replayed)->toEqual([named])
|
|
74
74
|
})
|
|
75
75
|
|
|
76
|
+
testPromise("seals a field that names no subject under the aggregate's id", async () => {
|
|
77
|
+
Reventless.Pii.Provider.install(fakeProvider())
|
|
78
|
+
let emailed: ItemEventLogSpec.event = PersonEmailed({email: Value("ada@example.org")})
|
|
79
|
+
let result = await Log.append(0, "p-9", [makeEvent'("p-9", emailed)])
|
|
80
|
+
expect(result)->toEqual(Ok())
|
|
81
|
+
let stored =
|
|
82
|
+
storedEvents.contents
|
|
83
|
+
->Dict.get("p-9")
|
|
84
|
+
->Option.flatMap(a => a->Array.get(0))
|
|
85
|
+
->Option.flatMap(JSON.Decode.object)
|
|
86
|
+
->Option.flatMap(d => d->Dict.get("data"))
|
|
87
|
+
->Option.flatMap(JSON.Decode.object)
|
|
88
|
+
->Option.flatMap(d => d->Dict.get("email"))
|
|
89
|
+
->Option.flatMap(Reventless.Pii.unwrap)
|
|
90
|
+
expect(stored->Option.mapOr(false, s => s->String.startsWith("enc:v1:p-9:")))->toBe(true)
|
|
91
|
+
expect(await Log.replay("p-9"))->toEqual([emailed])
|
|
92
|
+
})
|
|
93
|
+
|
|
76
94
|
testPromise("refuses an append whose personal field comes out unsealed", async () => {
|
|
77
95
|
Reventless.Pii.Provider.install(fakeProvider(~seals=false))
|
|
78
96
|
let result = await Log.append(0, "p-1", [makeEvent'("p-1", named)])
|
|
@@ -171,6 +171,24 @@ globalThis.describe("EventLog with a personal-data provider", () => {
|
|
|
171
171
|
let replayed = await Log.replay("p-1");
|
|
172
172
|
globalThis.expect(replayed).toEqual([named]);
|
|
173
173
|
});
|
|
174
|
+
globalThis.test("seals a field that names no subject under the aggregate's id", async () => {
|
|
175
|
+
Pii$Reventless.Provider.install(fakeProvider(undefined));
|
|
176
|
+
let emailed = {
|
|
177
|
+
TAG: "PersonEmailed",
|
|
178
|
+
email: {
|
|
179
|
+
TAG: "Value",
|
|
180
|
+
_0: "ada@example.org"
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
let result = await Log.append(0, "p-9", [EventLogFixtures$ReventlessCore.makeEvent$p("p-9", emailed)]);
|
|
184
|
+
globalThis.expect(result).toEqual({
|
|
185
|
+
TAG: "Ok",
|
|
186
|
+
_0: undefined
|
|
187
|
+
});
|
|
188
|
+
let stored = Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_Option.flatMap(EventLogFixtures$ReventlessCore.storedEvents.contents["p-9"], a => a[0]), Stdlib_JSON.Decode.object), d => d["data"]), Stdlib_JSON.Decode.object), d => d["email"]), Pii$Reventless.unwrap);
|
|
189
|
+
globalThis.expect(Stdlib_Option.mapOr(stored, false, s => s.startsWith("enc:v1:p-9:"))).toBe(true);
|
|
190
|
+
globalThis.expect(await Log.replay("p-9")).toEqual([emailed]);
|
|
191
|
+
});
|
|
174
192
|
globalThis.test("refuses an append whose personal field comes out unsealed", async () => {
|
|
175
193
|
Pii$Reventless.Provider.install(fakeProvider(false));
|
|
176
194
|
let result = await Log.append(0, "p-1", [EventLogFixtures$ReventlessCore.makeEvent$p("p-1", named)]);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Fixture: an aggregate's spec, whose events name no subject: the aggregate is it.
|
|
2
|
+
|
|
3
|
+
@@reventless.spec("PiiCustomer")
|
|
4
|
+
|
|
5
|
+
@schema
|
|
6
|
+
type event =
|
|
7
|
+
| Registered({@pii email: Reventless.Email.t, @pii address: string})
|
|
8
|
+
| EmailUpdated({@pii email: Reventless.Email.t})
|
|
9
|
+
// A field about someone else still names them.
|
|
10
|
+
| ReferralSent({friendId: string, @pii("friendId") friendEmail: Reventless.Email.t})
|
|
11
|
+
| Deactivated
|
|
12
|
+
|
|
13
|
+
@schema
|
|
14
|
+
type command = Register({@pii email: Reventless.Email.t, @pii address: string})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Sury from "sury";
|
|
4
|
+
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
5
|
+
import * as Email$Reventless from "@reventlessdev/reventless-spec/src/semantic/Email.res.mjs";
|
|
6
|
+
|
|
7
|
+
let eventSchema = Sury.union([
|
|
8
|
+
Sury.$schema(s => ({
|
|
9
|
+
TAG: "Registered",
|
|
10
|
+
email: s.m(Pii$Reventless.marked("$stream", undefined, Email$Reventless.schema)),
|
|
11
|
+
address: s.m(Pii$Reventless.marked("$stream", undefined, Sury.string))
|
|
12
|
+
})),
|
|
13
|
+
Sury.$schema(s => ({
|
|
14
|
+
TAG: "EmailUpdated",
|
|
15
|
+
email: s.m(Pii$Reventless.marked("$stream", undefined, Email$Reventless.schema))
|
|
16
|
+
})),
|
|
17
|
+
Sury.$schema(s => ({
|
|
18
|
+
TAG: "ReferralSent",
|
|
19
|
+
friendId: s.m(Sury.string),
|
|
20
|
+
friendEmail: s.m(Pii$Reventless.marked("friendId", undefined, Email$Reventless.schema))
|
|
21
|
+
})),
|
|
22
|
+
Sury.literal("Deactivated")
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
let commandSchema = Sury.$schema(s => ({
|
|
26
|
+
TAG: "Register",
|
|
27
|
+
email: s.m(Pii$Reventless.mark("$stream", undefined, Email$Reventless.schema)),
|
|
28
|
+
address: s.m(Pii$Reventless.mark("$stream", undefined, Sury.string))
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
function authorizationOf(param) {
|
|
32
|
+
return "AllowAuthenticated";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function commandTransition(param) {
|
|
36
|
+
return "Undeclared";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let traits = [];
|
|
40
|
+
|
|
41
|
+
let name = "PiiCustomer";
|
|
42
|
+
|
|
43
|
+
let Id;
|
|
44
|
+
|
|
45
|
+
let moduleUrl = "@reventlessdev/reventless-core/tests/pii/Aggregate/PiiCustomer.res.mjs";
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
name,
|
|
49
|
+
Id,
|
|
50
|
+
eventSchema,
|
|
51
|
+
commandSchema,
|
|
52
|
+
moduleUrl,
|
|
53
|
+
authorizationOf,
|
|
54
|
+
commandTransition,
|
|
55
|
+
traits,
|
|
56
|
+
}
|
|
57
|
+
/* eventSchema Not a pure module */
|
|
@@ -59,7 +59,7 @@ function named() {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
function seal(data) {
|
|
62
|
-
return Pii$Reventless.sealData(eventSchema, "MemberNamed", data);
|
|
62
|
+
return Pii$Reventless.sealData(eventSchema, "MemberNamed", undefined, data);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
let variable = "REVENTLESS_PII_REQUIRE_ENCRYPTION";
|
|
@@ -130,7 +130,7 @@ globalThis.describe("Pii.Provider.installWhen", () => {
|
|
|
130
130
|
"memberId",
|
|
131
131
|
"m-1"
|
|
132
132
|
]]);
|
|
133
|
-
globalThis.expect(await Pii$Reventless.sealData(eventSchema, "MemberLeft", data)).toEqual({
|
|
133
|
+
globalThis.expect(await Pii$Reventless.sealData(eventSchema, "MemberLeft", undefined, data)).toEqual({
|
|
134
134
|
TAG: "Ok",
|
|
135
135
|
_0: data
|
|
136
136
|
});
|
package/tests/pii/PiiMember.res
CHANGED
|
@@ -16,3 +16,8 @@ type event =
|
|
|
16
16
|
|
|
17
17
|
@schema
|
|
18
18
|
type command = Join({@owner memberId: string, @pii name: string, @pii address: Reventless.Email.t})
|
|
19
|
+
|
|
20
|
+
// Another slice's view of an aggregate's event, which carries no id of its own:
|
|
21
|
+
// only ever opened, so it needs no subject.
|
|
22
|
+
@schema
|
|
23
|
+
type consumedEvent = CustomerRegistered({@pii email: Reventless.Email.t})
|
|
@@ -30,6 +30,11 @@ let commandSchema = Sury.$schema(s => ({
|
|
|
30
30
|
address: s.m(Pii$Reventless.mark("memberId", undefined, Email$Reventless.schema))
|
|
31
31
|
}));
|
|
32
32
|
|
|
33
|
+
let consumedEventSchema = Sury.$schema(s => ({
|
|
34
|
+
TAG: "CustomerRegistered",
|
|
35
|
+
email: s.m(Pii$Reventless.marked("$stream", undefined, Email$Reventless.schema))
|
|
36
|
+
}));
|
|
37
|
+
|
|
33
38
|
function authorizationOf(param) {
|
|
34
39
|
return "AllowAuthenticated";
|
|
35
40
|
}
|
|
@@ -46,13 +51,17 @@ let Id;
|
|
|
46
51
|
|
|
47
52
|
let moduleUrl = "@reventlessdev/reventless-core/tests/pii/PiiMember.res.mjs";
|
|
48
53
|
|
|
54
|
+
let readConsistency = "EscalateOnRetry";
|
|
55
|
+
|
|
49
56
|
export {
|
|
50
57
|
name,
|
|
51
58
|
Id,
|
|
52
59
|
eventSchema,
|
|
53
60
|
commandSchema,
|
|
61
|
+
consumedEventSchema,
|
|
54
62
|
moduleUrl,
|
|
55
63
|
authorizationOf,
|
|
64
|
+
readConsistency,
|
|
56
65
|
commandTransition,
|
|
57
66
|
traits,
|
|
58
67
|
}
|
package/tests/pii/PiiPpxTest.res
CHANGED
|
@@ -53,6 +53,15 @@ describe("@pii on an event", () => {
|
|
|
53
53
|
])
|
|
54
54
|
})
|
|
55
55
|
|
|
56
|
+
testSync("a consumed field naming no subject is about the aggregate it came from", () =>
|
|
57
|
+
expect(
|
|
58
|
+
M.consumedEventSchema
|
|
59
|
+
->S.castToUnknown
|
|
60
|
+
->Reventless.Pii.variantFields(~variant="CustomerRegistered")
|
|
61
|
+
->Array.map(((name, m)) => (name, m.subject)),
|
|
62
|
+
)->toEqual([("email", Reventless.Pii.streamSubject)])
|
|
63
|
+
)
|
|
64
|
+
|
|
56
65
|
testSync("@pii implies @sensitive", () =>
|
|
57
66
|
expect(
|
|
58
67
|
M.eventSchema
|
|
@@ -110,6 +110,15 @@ globalThis.describe("@pii on an event", () => {
|
|
|
110
110
|
"invitationId"
|
|
111
111
|
]]);
|
|
112
112
|
});
|
|
113
|
+
globalThis.test("a consumed field naming no subject is about the aggregate it came from", () => {
|
|
114
|
+
globalThis.expect(Pii$Reventless.variantFields(PiiMember$ReventlessCore.consumedEventSchema, "CustomerRegistered").map(param => [
|
|
115
|
+
param[0],
|
|
116
|
+
param[1].subject
|
|
117
|
+
])).toEqual([[
|
|
118
|
+
"email",
|
|
119
|
+
Pii$Reventless.streamSubject
|
|
120
|
+
]]);
|
|
121
|
+
});
|
|
113
122
|
globalThis.test("@pii implies @sensitive", () => {
|
|
114
123
|
globalThis.expect(Sensitive$Reventless.variantFieldNames(PiiMember$ReventlessCore.eventSchema, "MemberJoined").includes("name")).toBe(true);
|
|
115
124
|
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// In an aggregate's spec a `@pii` field that names no subject is about the
|
|
2
|
+
// aggregate: the PPX marks it with the stream subject, and the seal pass seals it
|
|
3
|
+
// under the stream id the event log passes.
|
|
4
|
+
|
|
5
|
+
open JestGlobals
|
|
6
|
+
|
|
7
|
+
module C = PiiCustomer
|
|
8
|
+
|
|
9
|
+
let subjects = variant =>
|
|
10
|
+
C.eventSchema
|
|
11
|
+
->S.castToUnknown
|
|
12
|
+
->Reventless.Pii.variantFields(~variant)
|
|
13
|
+
->Array.map(((name, m)) => (name, m.subject))
|
|
14
|
+
|
|
15
|
+
let sealedUnder: ref<array<string>> = ref([])
|
|
16
|
+
let recording: Reventless.Pii.provider = {
|
|
17
|
+
...Reventless.Pii.plain,
|
|
18
|
+
name: "recording",
|
|
19
|
+
encrypts: true,
|
|
20
|
+
seal: async (~subject, ~field as _, ~forgettable as _, _json) => {
|
|
21
|
+
sealedUnder := sealedUnder.contents->Array.concat([subject])
|
|
22
|
+
Ok(Reventless.Pii.wrap(`enc:v1:${subject}:fake:AAAA`))
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let registered = () =>
|
|
27
|
+
Dict.fromArray([
|
|
28
|
+
("email", JSON.Encode.string("ada@example.org")),
|
|
29
|
+
("address", JSON.Encode.string("1 Analytical St")),
|
|
30
|
+
])
|
|
31
|
+
|
|
32
|
+
describe("@pii in an aggregate's spec", () => {
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
Reventless.Pii.Provider.install(Reventless.Pii.plain)
|
|
35
|
+
sealedUnder := []
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
testSync("a field naming no subject is about the aggregate", () =>
|
|
39
|
+
expect(subjects("Registered"))->toEqual([
|
|
40
|
+
("email", Reventless.Pii.streamSubject),
|
|
41
|
+
("address", Reventless.Pii.streamSubject),
|
|
42
|
+
])
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
testSync("a field naming a subject keeps it", () =>
|
|
46
|
+
expect(subjects("ReferralSent"))->toEqual([("friendEmail", "friendId")])
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
testPromise("is sealed under the stream id the event log passes", async () => {
|
|
50
|
+
Reventless.Pii.Provider.install(recording)
|
|
51
|
+
let sealed = await Reventless.Pii.sealData(
|
|
52
|
+
C.eventSchema,
|
|
53
|
+
~eventType="Registered",
|
|
54
|
+
~streamId="c-7",
|
|
55
|
+
registered(),
|
|
56
|
+
)
|
|
57
|
+
expect(sealed->Result.isOk)->toBe(true)
|
|
58
|
+
expect(sealedUnder.contents)->toEqual(["c-7", "c-7"])
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
testPromise("is refused when no stream id is passed", async () => {
|
|
62
|
+
Reventless.Pii.Provider.install(recording)
|
|
63
|
+
switch await Reventless.Pii.sealData(C.eventSchema, ~eventType="Registered", registered()) {
|
|
64
|
+
| Ok(_) => fail("expected a refusal")
|
|
65
|
+
| Error(e) =>
|
|
66
|
+
expect(e->Reventless.Pii.errorMessage->String.includes("no stream id"))->toBe(true)
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
})
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as JestGlobals from "@reventlessdev/rescript-jest/src/JestGlobals.res.mjs";
|
|
4
|
+
import * as Stdlib_Result from "@rescript/runtime/lib/es6/Stdlib_Result.js";
|
|
5
|
+
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
6
|
+
import * as PiiCustomer$ReventlessCore from "./Aggregate/PiiCustomer.res.mjs";
|
|
7
|
+
|
|
8
|
+
function subjects(variant) {
|
|
9
|
+
return Pii$Reventless.variantFields(PiiCustomer$ReventlessCore.eventSchema, variant).map(param => [
|
|
10
|
+
param[0],
|
|
11
|
+
param[1].subject
|
|
12
|
+
]);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let sealedUnder = {
|
|
16
|
+
contents: []
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
async function recording_seal(subject, param, param$1, _json) {
|
|
20
|
+
sealedUnder.contents = sealedUnder.contents.concat([subject]);
|
|
21
|
+
return {
|
|
22
|
+
TAG: "Ok",
|
|
23
|
+
_0: Pii$Reventless.wrap(`enc:v1:` + subject + `:fake:AAAA`)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let recording_prefetch = Pii$Reventless.plain.prefetch;
|
|
28
|
+
|
|
29
|
+
let recording_openNow = Pii$Reventless.plain.openNow;
|
|
30
|
+
|
|
31
|
+
let recording_release = Pii$Reventless.plain.release;
|
|
32
|
+
|
|
33
|
+
let recording = {
|
|
34
|
+
name: "recording",
|
|
35
|
+
encrypts: true,
|
|
36
|
+
seal: recording_seal,
|
|
37
|
+
prefetch: recording_prefetch,
|
|
38
|
+
openNow: recording_openNow,
|
|
39
|
+
release: recording_release
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function registered() {
|
|
43
|
+
return Object.fromEntries([
|
|
44
|
+
[
|
|
45
|
+
"email",
|
|
46
|
+
"ada@example.org"
|
|
47
|
+
],
|
|
48
|
+
[
|
|
49
|
+
"address",
|
|
50
|
+
"1 Analytical St"
|
|
51
|
+
]
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
globalThis.describe("@pii in an aggregate's spec", () => {
|
|
56
|
+
globalThis.afterEach(() => {
|
|
57
|
+
Pii$Reventless.Provider.install(Pii$Reventless.plain);
|
|
58
|
+
sealedUnder.contents = [];
|
|
59
|
+
});
|
|
60
|
+
globalThis.test("a field naming no subject is about the aggregate", () => {
|
|
61
|
+
globalThis.expect(subjects("Registered")).toEqual([
|
|
62
|
+
[
|
|
63
|
+
"email",
|
|
64
|
+
Pii$Reventless.streamSubject
|
|
65
|
+
],
|
|
66
|
+
[
|
|
67
|
+
"address",
|
|
68
|
+
Pii$Reventless.streamSubject
|
|
69
|
+
]
|
|
70
|
+
]);
|
|
71
|
+
});
|
|
72
|
+
globalThis.test("a field naming a subject keeps it", () => {
|
|
73
|
+
globalThis.expect(subjects("ReferralSent")).toEqual([[
|
|
74
|
+
"friendEmail",
|
|
75
|
+
"friendId"
|
|
76
|
+
]]);
|
|
77
|
+
});
|
|
78
|
+
globalThis.test("is sealed under the stream id the event log passes", async () => {
|
|
79
|
+
Pii$Reventless.Provider.install(recording);
|
|
80
|
+
let sealed = await Pii$Reventless.sealData(PiiCustomer$ReventlessCore.eventSchema, "Registered", "c-7", registered());
|
|
81
|
+
globalThis.expect(Stdlib_Result.isOk(sealed)).toBe(true);
|
|
82
|
+
globalThis.expect(sealedUnder.contents).toEqual([
|
|
83
|
+
"c-7",
|
|
84
|
+
"c-7"
|
|
85
|
+
]);
|
|
86
|
+
});
|
|
87
|
+
globalThis.test("is refused when no stream id is passed", async () => {
|
|
88
|
+
Pii$Reventless.Provider.install(recording);
|
|
89
|
+
let e = await Pii$Reventless.sealData(PiiCustomer$ReventlessCore.eventSchema, "Registered", undefined, registered());
|
|
90
|
+
if (e.TAG === "Ok") {
|
|
91
|
+
return JestGlobals.fail("expected a refusal");
|
|
92
|
+
}
|
|
93
|
+
globalThis.expect(Pii$Reventless.errorMessage(e._0).includes("no stream id")).toBe(true);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
let C;
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
C,
|
|
101
|
+
subjects,
|
|
102
|
+
sealedUnder,
|
|
103
|
+
recording,
|
|
104
|
+
registered,
|
|
105
|
+
}
|
|
106
|
+
/* Not a pure module */
|