@reventlessdev/reventless-core 3.0.0-alpha.312 → 3.0.0-alpha.314
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 +35 -0
- package/package.json +6 -6
- package/src/Message.res +8 -1
- package/src/Message.res.mjs +7 -1
- package/src/components/Api/SuryToJsonSchema.res +19 -0
- package/src/components/Api/SuryToJsonSchema.res.mjs +26 -5
- package/src/components/CommandTopic/CommandTopic_Callback.res +3 -1
- package/src/components/CommandTopic/CommandTopic_Callback.res.mjs +2 -1
- package/src/components/EventLog/EventLog_Operations.res +1 -1
- package/src/components/EventLog/EventLog_Operations.res.mjs +1 -1
- package/src/util/LogFormat.res +22 -4
- package/src/util/LogFormat.res.mjs +26 -5
- package/src/util/Logger.res +11 -2
- package/src/util/Logger.res.mjs +3 -2
- package/tests/logger/LogFormatTest.res +5 -3
- package/tests/logger/LogFormatTest.res.mjs +3 -3
- package/tests/pii/AesGcmTest.res +40 -0
- package/tests/pii/PiiMember.res +18 -0
- package/tests/pii/PiiMember.res.mjs +59 -0
- package/tests/pii/PiiPpxTest.res +128 -0
- package/tests/pii/PiiPpxTest.res.mjs +196 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,41 @@
|
|
|
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.314 (2026-10-29)
|
|
7
|
+
|
|
8
|
+
* feat(ppx)!: `@pii` marks a value about a person, and an event reads it as `Pii.t` ([37174c1](https://github.com/ReventlessDev/reventless-core/commit/37174c10eb80e9e3adbb93a52ad7a9ef5def7100))
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **core:** no log line prints a personal value ([af03709](https://github.com/ReventlessDev/reventless-core/commit/af037090770992c254e5dc69ab71ef251bad2db9))
|
|
12
|
+
|
|
13
|
+
### BREAKING CHANGES
|
|
14
|
+
|
|
15
|
+
* the ledger's events carry `address: Pii.t<Email.t>`. Pattern-match
|
|
16
|
+
`Value(address)` where the address is read.
|
|
17
|
+
|
|
18
|
+
The published per-platform PPX binary does not know `@pii` until it is republished.
|
|
19
|
+
|
|
20
|
+
Step PD2 of docs/plans/a-personal-field-is-marked-redacted-and-encrypted-at-the-seam.md.
|
|
21
|
+
Claude-Session: https://claude.ai/code/session_01HiQfdxVEsHwLHRoHSUcus1
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# 3.0.0-alpha.313 (2026-10-29)
|
|
26
|
+
|
|
27
|
+
* feat(ppx)!: `@pii` marks a value about a person, and an event reads it as `Pii.t` ([37174c1](https://github.com/ReventlessDev/reventless-core/commit/37174c10eb80e9e3adbb93a52ad7a9ef5def7100))
|
|
28
|
+
|
|
29
|
+
### BREAKING CHANGES
|
|
30
|
+
|
|
31
|
+
* the ledger's events carry `address: Pii.t<Email.t>`. Pattern-match
|
|
32
|
+
`Value(address)` where the address is read.
|
|
33
|
+
|
|
34
|
+
The published per-platform PPX binary does not know `@pii` until it is republished.
|
|
35
|
+
|
|
36
|
+
Step PD2 of docs/plans/a-personal-field-is-marked-redacted-and-encrypted-at-the-seam.md.
|
|
37
|
+
Claude-Session: https://claude.ai/code/session_01HiQfdxVEsHwLHRoHSUcus1
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
6
41
|
# 3.0.0-alpha.312 (2026-10-29)
|
|
7
42
|
|
|
8
43
|
* feat(registration)!: the ledger tags an address by its keyed fingerprint ([ccafddf](https://github.com/ReventlessDev/reventless-core/commit/ccafddfc7eb8039687afc62a483ce34b8e7081dd))
|
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.314",
|
|
4
4
|
"description": "Core package for Reventless framework",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"jest": {
|
|
@@ -28,17 +28,17 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"sury": "11.0.0",
|
|
30
30
|
"uuid": "^13.0.0",
|
|
31
|
-
"@reventlessdev/rescript-fast-csv": "2.0.0-alpha.23",
|
|
32
31
|
"@reventlessdev/rescript-effect": "1.0.0-alpha.1",
|
|
32
|
+
"@reventlessdev/rescript-fast-csv": "2.0.0-alpha.23",
|
|
33
33
|
"@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
|
|
34
|
-
"@reventlessdev/rescript-node": "2.0.0-alpha.23",
|
|
35
34
|
"@reventlessdev/rescript-jest": "1.0.0-alpha.13",
|
|
36
|
-
"@reventlessdev/rescript-
|
|
35
|
+
"@reventlessdev/rescript-node": "2.0.0-alpha.23",
|
|
37
36
|
"@reventlessdev/rescript-pulumi-pulumi": "3.0.0-alpha.0",
|
|
37
|
+
"@reventlessdev/rescript-ssh2": "2.0.0-alpha.24",
|
|
38
|
+
"@reventlessdev/reventless-infra": "3.0.0-alpha.211",
|
|
38
39
|
"@reventlessdev/rescript-uuid": "2.0.0-alpha.1",
|
|
39
|
-
"@reventlessdev/reventless-infra": "3.0.0-alpha.209",
|
|
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.182"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"rescript": "12.3.1",
|
package/src/Message.res
CHANGED
|
@@ -85,7 +85,14 @@ let uuid = Uuid.v4
|
|
|
85
85
|
let log: ('a, string) => 'a = (value, str) => {
|
|
86
86
|
logger.debug(
|
|
87
87
|
~comp="Message",
|
|
88
|
-
~data=value
|
|
88
|
+
~data=value
|
|
89
|
+
->JSON.stringifyAny
|
|
90
|
+
->Option.flatMap(s =>
|
|
91
|
+
try Some(JSON.parseOrThrow(s)) catch {
|
|
92
|
+
| _ => None
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
->Option.getOr(JSON.Encode.null),
|
|
89
96
|
str,
|
|
90
97
|
)
|
|
91
98
|
value
|
package/src/Message.res.mjs
CHANGED
|
@@ -66,7 +66,13 @@ function uuid(prim) {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
function log(value, str) {
|
|
69
|
-
logger.debug("Message", Stdlib_Option.getOr(JSON.stringify(value),
|
|
69
|
+
logger.debug("Message", Stdlib_Option.getOr(Stdlib_Option.flatMap(JSON.stringify(value), s => {
|
|
70
|
+
try {
|
|
71
|
+
return JSON.parse(s);
|
|
72
|
+
} catch (exn) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
}), null), str);
|
|
70
76
|
return value;
|
|
71
77
|
}
|
|
72
78
|
|
|
@@ -380,6 +380,7 @@ and objectRefToJsonSchema = (
|
|
|
380
380
|
~optional: array<string>=[],
|
|
381
381
|
~owners: array<string>=[],
|
|
382
382
|
~sensitive: array<string>=[],
|
|
383
|
+
~pii: array<(string, Reventless.Pii.marker)>=[],
|
|
383
384
|
~inputNames: bool=false,
|
|
384
385
|
fields: dict<SchemaType.schemaType>,
|
|
385
386
|
): JSON.t => {
|
|
@@ -431,6 +432,23 @@ and objectRefToJsonSchema = (
|
|
|
431
432
|
JSON.Encode.object(obj)
|
|
432
433
|
| None => withAnnotations
|
|
433
434
|
}
|
|
435
|
+
// `@pii`: whose data the field holds, so a tool can list the personal data an
|
|
436
|
+
// app keeps and a reader can route it without decoding it.
|
|
437
|
+
let withAnnotations = switch (
|
|
438
|
+
pii->Array.find(((name, _)) => name == fieldName),
|
|
439
|
+
withAnnotations->JSON.Decode.object,
|
|
440
|
+
) {
|
|
441
|
+
| (Some((_, {subject, forgettable})), Some(obj)) =>
|
|
442
|
+
obj->Dict.set(
|
|
443
|
+
"x-reventless-pii",
|
|
444
|
+
Dict.fromArray([
|
|
445
|
+
("subject", JSON.Encode.string(subject)),
|
|
446
|
+
("forgettable", JSON.Encode.bool(forgettable)),
|
|
447
|
+
])->JSON.Encode.object,
|
|
448
|
+
)
|
|
449
|
+
JSON.Encode.object(obj)
|
|
450
|
+
| _ => withAnnotations
|
|
451
|
+
}
|
|
434
452
|
props->Dict.set(fieldName, withAnnotations)
|
|
435
453
|
|
|
436
454
|
// Optional two ways, because neither source answers alone. `optional` is
|
|
@@ -475,6 +493,7 @@ let deriveObjectSchema = (
|
|
|
475
493
|
~optional=SchemaType.optionalFieldNames(schema),
|
|
476
494
|
~owners=Reventless.Owner.fieldNames(schema),
|
|
477
495
|
~sensitive=Reventless.Sensitive.fieldNames(schema),
|
|
496
|
+
~pii=Reventless.Pii.fieldsOf(schema),
|
|
478
497
|
~inputNames,
|
|
479
498
|
fields,
|
|
480
499
|
)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
|
|
4
4
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
5
|
+
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
5
6
|
import * as Owner$Reventless from "@reventlessdev/reventless-spec/src/components/Owner.res.mjs";
|
|
6
7
|
import * as Sensitive$Reventless from "@reventlessdev/reventless-spec/src/components/Sensitive.res.mjs";
|
|
7
8
|
import * as Logger$ReventlessCore from "../../util/Logger.res.mjs";
|
|
@@ -249,7 +250,7 @@ function fromSchemaType(_inputNamesOpt, _st) {
|
|
|
249
250
|
]
|
|
250
251
|
]);
|
|
251
252
|
case "ObjectRef" :
|
|
252
|
-
let base = objectRefToJsonSchema(undefined, undefined, undefined, undefined, inputNames, st._1);
|
|
253
|
+
let base = objectRefToJsonSchema(undefined, undefined, undefined, undefined, undefined, inputNames, st._1);
|
|
253
254
|
if (inputNames) {
|
|
254
255
|
return withGraphqlInput(base, st._0);
|
|
255
256
|
} else {
|
|
@@ -308,7 +309,7 @@ function armToJsonSchema(inputNamesOpt, tag, armType) {
|
|
|
308
309
|
if (armType.TAG !== "ObjectRef") {
|
|
309
310
|
return fromSchemaType(inputNames, armType);
|
|
310
311
|
}
|
|
311
|
-
let base = objectRefToJsonSchema(undefined, undefined, undefined, undefined, inputNames, armType._1);
|
|
312
|
+
let base = objectRefToJsonSchema(undefined, undefined, undefined, undefined, undefined, inputNames, armType._1);
|
|
312
313
|
let obj = Stdlib_JSON.Decode.object(base);
|
|
313
314
|
if (obj === undefined) {
|
|
314
315
|
return base;
|
|
@@ -391,10 +392,11 @@ function withSemantic(fieldSchema, sem) {
|
|
|
391
392
|
return obj;
|
|
392
393
|
}
|
|
393
394
|
|
|
394
|
-
function objectRefToJsonSchema(annotations, optionalOpt, ownersOpt, sensitiveOpt, inputNamesOpt, fields) {
|
|
395
|
+
function objectRefToJsonSchema(annotations, optionalOpt, ownersOpt, sensitiveOpt, piiOpt, inputNamesOpt, fields) {
|
|
395
396
|
let optional = optionalOpt !== undefined ? optionalOpt : [];
|
|
396
397
|
let owners = ownersOpt !== undefined ? ownersOpt : [];
|
|
397
398
|
let sensitive = sensitiveOpt !== undefined ? sensitiveOpt : [];
|
|
399
|
+
let pii = piiOpt !== undefined ? piiOpt : [];
|
|
398
400
|
let inputNames = inputNamesOpt !== undefined ? inputNamesOpt : false;
|
|
399
401
|
let props = {};
|
|
400
402
|
let required = [];
|
|
@@ -427,7 +429,26 @@ function objectRefToJsonSchema(annotations, optionalOpt, ownersOpt, sensitiveOpt
|
|
|
427
429
|
} else {
|
|
428
430
|
withAnnotations$2 = withAnnotations$1;
|
|
429
431
|
}
|
|
430
|
-
|
|
432
|
+
let match = pii.find(param => param[0] === fieldName);
|
|
433
|
+
let match$1 = Stdlib_JSON.Decode.object(withAnnotations$2);
|
|
434
|
+
let withAnnotations$3;
|
|
435
|
+
if (match !== undefined && match$1 !== undefined) {
|
|
436
|
+
let match$2 = match[1];
|
|
437
|
+
match$1["x-reventless-pii"] = Object.fromEntries([
|
|
438
|
+
[
|
|
439
|
+
"subject",
|
|
440
|
+
match$2.subject
|
|
441
|
+
],
|
|
442
|
+
[
|
|
443
|
+
"forgettable",
|
|
444
|
+
match$2.forgettable
|
|
445
|
+
]
|
|
446
|
+
]);
|
|
447
|
+
withAnnotations$3 = match$1;
|
|
448
|
+
} else {
|
|
449
|
+
withAnnotations$3 = withAnnotations$2;
|
|
450
|
+
}
|
|
451
|
+
props[fieldName] = withAnnotations$3;
|
|
431
452
|
if (!optional.includes(fieldName) && !isNullableType(fieldType)) {
|
|
432
453
|
required.push(fieldName);
|
|
433
454
|
return;
|
|
@@ -463,7 +484,7 @@ function deriveObjectSchema(inputNamesOpt, typeNameOpt, schema) {
|
|
|
463
484
|
]]);
|
|
464
485
|
}
|
|
465
486
|
let annotations = StateAnnotations$Reventless.getSpec(schema);
|
|
466
|
-
let objSchema = objectRefToJsonSchema(annotations, SchemaType$ReventlessCore.optionalFieldNames(schema), Owner$Reventless.fieldNames(schema), Sensitive$Reventless.fieldNames(schema), inputNames, fields);
|
|
487
|
+
let objSchema = objectRefToJsonSchema(annotations, SchemaType$ReventlessCore.optionalFieldNames(schema), Owner$Reventless.fieldNames(schema), Sensitive$Reventless.fieldNames(schema), Pii$Reventless.fieldsOf(schema), inputNames, fields);
|
|
467
488
|
if (annotations === undefined) {
|
|
468
489
|
return objSchema;
|
|
469
490
|
}
|
|
@@ -17,7 +17,9 @@ module Make = (Spec: ReventlessInfra.CommandTopic.T, Ops: Ops with module Spec =
|
|
|
17
17
|
switch json->Message.decodeCommand'(Spec.Id.schema, Spec.commandSchema) {
|
|
18
18
|
| command' => Some({ReventlessInfra.CommandTopic.reference, command: command'})
|
|
19
19
|
| exception err =>
|
|
20
|
-
|
|
20
|
+
// The command as it may be logged: a command that failed to decode is
|
|
21
|
+
// exactly one whose fields the schema could not vouch for.
|
|
22
|
+
let commandStr = json->Reventless.LogRedaction.redactJson->JSON.stringify
|
|
21
23
|
let errMsg = err->Reventless.Util_Sury.exnMessage
|
|
22
24
|
EffectLogger.logError(~comp, `decode failed: ${commandStr} err=${errMsg}`)->Effect.runSync
|
|
23
25
|
None
|
|
@@ -5,6 +5,7 @@ import * as Stream from "effect/Stream";
|
|
|
5
5
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
6
6
|
import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
|
|
7
7
|
import * as Message$ReventlessCore from "../../Message.res.mjs";
|
|
8
|
+
import * as LogRedaction$Reventless from "@reventlessdev/reventless-spec/src/util/LogRedaction.res.mjs";
|
|
8
9
|
import * as EffectLogger$ReventlessCore from "../../util/EffectLogger.res.mjs";
|
|
9
10
|
|
|
10
11
|
function Make(Spec) {
|
|
@@ -19,7 +20,7 @@ function Make(Spec) {
|
|
|
19
20
|
command$p = Message$ReventlessCore.decodeCommand$p(json, Spec.Id.schema, Spec.commandSchema);
|
|
20
21
|
} catch (raw_err) {
|
|
21
22
|
let err = Primitive_exceptions.internalToException(raw_err);
|
|
22
|
-
let commandStr = JSON.stringify(json);
|
|
23
|
+
let commandStr = JSON.stringify(LogRedaction$Reventless.redactJson(json));
|
|
23
24
|
let errMsg = Util_Sury$Reventless.exnMessage(err, undefined);
|
|
24
25
|
Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, `decode failed: ` + commandStr + ` err=` + errMsg));
|
|
25
26
|
return;
|
|
@@ -212,7 +212,7 @@ module Make = (Spec: ReventlessInfra.EventLog.T, Ops: Ops with module Spec = Spe
|
|
|
212
212
|
} catch {
|
|
213
213
|
| exn =>
|
|
214
214
|
JsError.throwWithMessage(
|
|
215
|
-
`EventLog.replay: Error: id:${id}: Couldn't decode
|
|
215
|
+
`EventLog.replay: Error: id:${id}: Couldn't decode the event's meta: ${Reventless.Util_Sury.exnMessage(
|
|
216
216
|
exn,
|
|
217
217
|
)}`,
|
|
218
218
|
)
|
|
@@ -193,7 +193,7 @@ function Make(Spec) {
|
|
|
193
193
|
return Util_Sury$Reventless.fromJson(Message$ReventlessCore.composeMeta(Stdlib_Option.getOrThrow(Stdlib_JSON.Decode.object(json), undefined)), Message$ReventlessCore.metaSchema);
|
|
194
194
|
} catch (raw_exn) {
|
|
195
195
|
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
196
|
-
return Stdlib_JsError.throwWithMessage(`EventLog.replay: Error: id:` + id + `: Couldn't decode
|
|
196
|
+
return Stdlib_JsError.throwWithMessage(`EventLog.replay: Error: id:` + id + `: Couldn't decode the event's meta: ` + Util_Sury$Reventless.exnMessage(exn, undefined));
|
|
197
197
|
}
|
|
198
198
|
};
|
|
199
199
|
let replayStream$p = (id, fromSeq) => {
|
package/src/util/LogFormat.res
CHANGED
|
@@ -93,7 +93,7 @@ external stringifiedOrAbsent: string => Nullable.t<string> = "%identity"
|
|
|
93
93
|
// {"TAG":"Add","name":"Cat 1"} → {name:"Cat 1"}
|
|
94
94
|
// "Add" (bare string variant) → ""
|
|
95
95
|
let variantFields = (json: JSON.t): string =>
|
|
96
|
-
switch json {
|
|
96
|
+
switch json->Reventless.LogRedaction.redactJson {
|
|
97
97
|
| Object(dict) =>
|
|
98
98
|
let fields =
|
|
99
99
|
dict
|
|
@@ -135,9 +135,23 @@ let cmdLabelOfJson = (json: JSON.t): string => {
|
|
|
135
135
|
let cmdDetailNoId = (msg: Message.commandJson): string => msg.commandJson->cmdLabelOfJson
|
|
136
136
|
|
|
137
137
|
// "{\"command\":{...},\"meta\":{...},\"id\":\"1\"}" (full envelope with meta, no summary prefix)
|
|
138
|
+
/** The envelope as a log line prints it: without the caller's address, which is
|
|
139
|
+
personal data, and without the header bag, which holds whatever a caller put
|
|
140
|
+
in it. */
|
|
141
|
+
let metaForLog = (meta: JSON.t): JSON.t =>
|
|
142
|
+
switch meta {
|
|
143
|
+
| Object(obj) =>
|
|
144
|
+
obj
|
|
145
|
+
->Dict.toArray
|
|
146
|
+
->Array.filter(((k, _)) => k != "ip" && k != "headers")
|
|
147
|
+
->Dict.fromArray
|
|
148
|
+
->JSON.Encode.object
|
|
149
|
+
| other => other
|
|
150
|
+
}
|
|
151
|
+
|
|
138
152
|
let cmdFull = (msg: Message.commandJson): string => {
|
|
139
|
-
let commandStr = msg.commandJson->JSON.stringify
|
|
140
|
-
let metaStr = msg.meta->Message.encode(Message.metaSchema)->JSON.stringify
|
|
153
|
+
let commandStr = msg.commandJson->Reventless.LogRedaction.redactJson->JSON.stringify
|
|
154
|
+
let metaStr = msg.meta->Message.encode(Message.metaSchema)->metaForLog->JSON.stringify
|
|
141
155
|
`{"command":${commandStr},"meta":${metaStr},"id":"${msg.id}"}`
|
|
142
156
|
}
|
|
143
157
|
|
|
@@ -178,7 +192,11 @@ let eventDetails = (events: array<JSON.t>): string =>
|
|
|
178
192
|
|
|
179
193
|
// "{\"event\":{...},\"meta\":{...},\"id\":\"1\"}" (full envelope with meta, no summary prefix)
|
|
180
194
|
let eventFull = (j: JSON.t): string => {
|
|
181
|
-
let (id,
|
|
195
|
+
let (id, _, _) = j->Message.idMetaEventOfEvent'Json
|
|
196
|
+
let part = key =>
|
|
197
|
+
j->JSON.Decode.object->Option.flatMap(d => d->Dict.get(key))->Option.getOr(JSON.Encode.null)
|
|
198
|
+
let eventStr = part("event")->Reventless.LogRedaction.redactJson->JSON.stringify
|
|
199
|
+
let metaStr = part("meta")->metaForLog->JSON.stringify
|
|
182
200
|
`{"event":${eventStr},"meta":${metaStr},"id":"${id}"}`
|
|
183
201
|
}
|
|
184
202
|
|
|
@@ -8,6 +8,7 @@ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js
|
|
|
8
8
|
import * as AnsiStyle$Reventless from "@reventlessdev/reventless-spec/src/AnsiStyle.res.mjs";
|
|
9
9
|
import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
|
|
10
10
|
import * as Message$ReventlessCore from "../Message.res.mjs";
|
|
11
|
+
import * as LogRedaction$Reventless from "@reventlessdev/reventless-spec/src/util/LogRedaction.res.mjs";
|
|
11
12
|
|
|
12
13
|
let maxValueChars = Stdlib_Option.getOr(Stdlib_Option.flatMap(process.env["REVENTLESS_LOG_MAX_VALUE"], v => Stdlib_Int.fromString(v, undefined)), 512);
|
|
13
14
|
|
|
@@ -37,10 +38,11 @@ function cmdSummaries(msgs) {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
function variantFields(json) {
|
|
40
|
-
|
|
41
|
+
let dict = LogRedaction$Reventless.redactJson(json);
|
|
42
|
+
if (typeof dict !== "object" || dict === null || Array.isArray(dict)) {
|
|
41
43
|
return "";
|
|
42
44
|
}
|
|
43
|
-
let fields = Stdlib_Array.filterMap(Object.entries(
|
|
45
|
+
let fields = Stdlib_Array.filterMap(Object.entries(dict).filter(param => param[0] !== "TAG"), param => {
|
|
44
46
|
let k = param[0];
|
|
45
47
|
return Stdlib_Option.map(Primitive_option.fromNullable(JSON.stringify(param[1])), s => k + `:` + truncate(s));
|
|
46
48
|
}).join(",");
|
|
@@ -69,9 +71,24 @@ function cmdDetailNoId(msg) {
|
|
|
69
71
|
return cmdLabelOfJson(msg.commandJson);
|
|
70
72
|
}
|
|
71
73
|
|
|
74
|
+
function metaForLog(meta) {
|
|
75
|
+
if (typeof meta === "object" && meta !== null && !Array.isArray(meta)) {
|
|
76
|
+
return Object.fromEntries(Object.entries(meta).filter(param => {
|
|
77
|
+
let k = param[0];
|
|
78
|
+
if (k !== "ip") {
|
|
79
|
+
return k !== "headers";
|
|
80
|
+
} else {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
84
|
+
} else {
|
|
85
|
+
return meta;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
72
89
|
function cmdFull(msg) {
|
|
73
|
-
let commandStr = JSON.stringify(msg.commandJson);
|
|
74
|
-
let metaStr = JSON.stringify(Message$ReventlessCore.encode(msg.meta, Message$ReventlessCore.metaSchema));
|
|
90
|
+
let commandStr = JSON.stringify(LogRedaction$Reventless.redactJson(msg.commandJson));
|
|
91
|
+
let metaStr = JSON.stringify(metaForLog(Message$ReventlessCore.encode(msg.meta, Message$ReventlessCore.metaSchema)));
|
|
75
92
|
return `{"command":` + commandStr + `,"meta":` + metaStr + `,"id":"` + msg.id + `"}`;
|
|
76
93
|
}
|
|
77
94
|
|
|
@@ -108,7 +125,10 @@ function eventDetails(events) {
|
|
|
108
125
|
|
|
109
126
|
function eventFull(j) {
|
|
110
127
|
let match = Message$ReventlessCore.idMetaEventOfEvent$pJson(j);
|
|
111
|
-
|
|
128
|
+
let part = key => Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JSON.Decode.object(j), d => d[key]), null);
|
|
129
|
+
let eventStr = JSON.stringify(LogRedaction$Reventless.redactJson(part("event")));
|
|
130
|
+
let metaStr = JSON.stringify(metaForLog(part("meta")));
|
|
131
|
+
return `{"event":` + eventStr + `,"meta":` + metaStr + `,"id":"` + match[0] + `"}`;
|
|
112
132
|
}
|
|
113
133
|
|
|
114
134
|
function eventFulls(events) {
|
|
@@ -248,6 +268,7 @@ export {
|
|
|
248
268
|
cmdDetails,
|
|
249
269
|
cmdLabelOfJson,
|
|
250
270
|
cmdDetailNoId,
|
|
271
|
+
metaForLog,
|
|
251
272
|
cmdFull,
|
|
252
273
|
cmdFulls,
|
|
253
274
|
eventName,
|
package/src/util/Logger.res
CHANGED
|
@@ -148,7 +148,13 @@ let emit = (
|
|
|
148
148
|
->Array.concat(pluginField->Option.mapOr([], p => [("plugin", JSON.Encode.string(p))]))
|
|
149
149
|
->Array.concat(comp->Option.mapOr([], c => [("comp", JSON.Encode.string(c))]))
|
|
150
150
|
->Array.concat(annotationFields)
|
|
151
|
-
|
|
151
|
+
// Redacted before anything else: a personal value must not reach a log
|
|
152
|
+
// group, which cannot be swept for one person (`LogRedaction`).
|
|
153
|
+
->Array.concat(
|
|
154
|
+
detail->Option.mapOr([], d => [
|
|
155
|
+
("detail", d->Reventless.LogRedaction.redactJson->truncateDetail),
|
|
156
|
+
]),
|
|
157
|
+
)
|
|
152
158
|
Console.log(fields->Dict.fromArray->JSON.Encode.object->JSON.stringify)
|
|
153
159
|
} else {
|
|
154
160
|
// Terminal — colored, human-readable, no detail
|
|
@@ -179,7 +185,10 @@ let setDefaultMinLevel = (l: level) => defaultMinLevel := l
|
|
|
179
185
|
let makeLoggerWith = (shouldLog: level => bool): t => {
|
|
180
186
|
let log = (level, ~comp=?, ~data=?, msg) =>
|
|
181
187
|
if shouldLog(level) {
|
|
182
|
-
let dataStr =
|
|
188
|
+
let dataStr =
|
|
189
|
+
data
|
|
190
|
+
->Option.map(d => ` ${d->Reventless.LogRedaction.redactJson->JSON.stringify}`)
|
|
191
|
+
->Option.getOr("")
|
|
183
192
|
emit(~level, ~comp?, `${msg}${dataStr}`)
|
|
184
193
|
}
|
|
185
194
|
{
|
package/src/util/Logger.res.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.js";
|
|
|
4
4
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
5
5
|
import * as AnsiStyle$Reventless from "@reventlessdev/reventless-spec/src/AnsiStyle.res.mjs";
|
|
6
6
|
import * as LogPrefix$Reventless from "@reventlessdev/reventless-spec/src/LogPrefix.res.mjs";
|
|
7
|
+
import * as LogRedaction$Reventless from "@reventlessdev/reventless-spec/src/util/LogRedaction.res.mjs";
|
|
7
8
|
|
|
8
9
|
function serviceName() {
|
|
9
10
|
let s = process.env.REVENTLESS_SERVICE;
|
|
@@ -119,7 +120,7 @@ function emit(level, comp, plugin, detail, annotations, msg) {
|
|
|
119
120
|
c
|
|
120
121
|
]])).concat(annotationFields).concat(Stdlib_Option.mapOr(detail, [], d => [[
|
|
121
122
|
"detail",
|
|
122
|
-
truncateDetail(d)
|
|
123
|
+
truncateDetail(LogRedaction$Reventless.redactJson(d))
|
|
123
124
|
]]));
|
|
124
125
|
console.log(JSON.stringify(Object.fromEntries(fields)));
|
|
125
126
|
return;
|
|
@@ -155,7 +156,7 @@ function makeLoggerWith(shouldLog) {
|
|
|
155
156
|
if (!shouldLog(level)) {
|
|
156
157
|
return;
|
|
157
158
|
}
|
|
158
|
-
let dataStr = Stdlib_Option.getOr(Stdlib_Option.map(data, d => ` ` + JSON.stringify(d)), "");
|
|
159
|
+
let dataStr = Stdlib_Option.getOr(Stdlib_Option.map(data, d => ` ` + JSON.stringify(LogRedaction$Reventless.redactJson(d))), "");
|
|
159
160
|
emit(level, comp, undefined, undefined, undefined, msg + dataStr);
|
|
160
161
|
};
|
|
161
162
|
return {
|
|
@@ -29,7 +29,8 @@ describe("LogFormat", () => {
|
|
|
29
29
|
msgId: "testMsgId",
|
|
30
30
|
correlationId: "testCorrelationId",
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
// Printed without the caller's address and the header bag.
|
|
33
|
+
let metaStr = meta->Message.encode(Message.metaSchema)->LogFormat.metaForLog->JSON.stringify
|
|
33
34
|
let arr: array<Message.commandJson> = commands->Array.mapWithIndex(
|
|
34
35
|
(command, idx) => {
|
|
35
36
|
{
|
|
@@ -80,7 +81,8 @@ describe("LogFormat", () => {
|
|
|
80
81
|
msgId: "testMsgId",
|
|
81
82
|
correlationId: "testCorrelationId",
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
+
// Printed without the caller's address and the header bag.
|
|
85
|
+
let metaStr = meta->Message.encode(Message.metaSchema)->LogFormat.metaForLog->JSON.stringify
|
|
84
86
|
let arr: array<Message.commandJson> = commands->Array.mapWithIndex(
|
|
85
87
|
(command, idx) => {
|
|
86
88
|
{
|
|
@@ -118,7 +120,7 @@ describe("LogFormat", () => {
|
|
|
118
120
|
|
|
119
121
|
// sury 11 (alpha.8) serialises meta keys in a different order than alpha.4
|
|
120
122
|
// (msgId/correlationId before ip/user) — same data, JSON-equivalent.
|
|
121
|
-
let expected = `\x1b[1mVersionDetected\x1b[0m(testId): {"event":{"TAG":"VersionDetected","_0":"0.0.0"},"meta":{"service":"testService","time":"testTime","msgId":"testMsgId","correlationId":"testCorrelationId","
|
|
123
|
+
let expected = `\x1b[1mVersionDetected\x1b[0m(testId): {"event":{"TAG":"VersionDetected","_0":"0.0.0"},"meta":{"service":"testService","time":"testTime","msgId":"testMsgId","correlationId":"testCorrelationId","user":"testUser"},"id":"testId"}`
|
|
122
124
|
|
|
123
125
|
expect(msg)->toEqual(expected)
|
|
124
126
|
},
|
|
@@ -38,7 +38,7 @@ globalThis.describe("LogFormat", () => {
|
|
|
38
38
|
msgId: "testMsgId",
|
|
39
39
|
correlationId: "testCorrelationId"
|
|
40
40
|
};
|
|
41
|
-
let metaStr = JSON.stringify(Message$ReventlessCore.encode(meta, Message$ReventlessCore.metaSchema));
|
|
41
|
+
let metaStr = JSON.stringify(LogFormat$ReventlessCore.metaForLog(Message$ReventlessCore.encode(meta, Message$ReventlessCore.metaSchema)));
|
|
42
42
|
let arr = commands.map((command, idx) => ({
|
|
43
43
|
id: idx.toString(),
|
|
44
44
|
meta: meta,
|
|
@@ -84,7 +84,7 @@ globalThis.describe("LogFormat", () => {
|
|
|
84
84
|
msgId: "testMsgId",
|
|
85
85
|
correlationId: "testCorrelationId"
|
|
86
86
|
};
|
|
87
|
-
let metaStr = JSON.stringify(Message$ReventlessCore.encode(meta, Message$ReventlessCore.metaSchema));
|
|
87
|
+
let metaStr = JSON.stringify(LogFormat$ReventlessCore.metaForLog(Message$ReventlessCore.encode(meta, Message$ReventlessCore.metaSchema)));
|
|
88
88
|
let arr = commands.map((command, idx) => ({
|
|
89
89
|
id: idx.toString(),
|
|
90
90
|
meta: meta,
|
|
@@ -116,7 +116,7 @@ globalThis.describe("LogFormat", () => {
|
|
|
116
116
|
}
|
|
117
117
|
}, Sury.string, PluginSpec$ReventlessCore.eventSchema);
|
|
118
118
|
let msg = LogFormat$ReventlessCore.event$pJsonToLogMessage(eventJson$p);
|
|
119
|
-
globalThis.expect(msg).toEqual(`\x1b[1mVersionDetected\x1b[0m(testId): {"event":{"TAG":"VersionDetected","_0":"0.0.0"},"meta":{"service":"testService","time":"testTime","msgId":"testMsgId","correlationId":"testCorrelationId","
|
|
119
|
+
globalThis.expect(msg).toEqual(`\x1b[1mVersionDetected\x1b[0m(testId): {"event":{"TAG":"VersionDetected","_0":"0.0.0"},"meta":{"service":"testService","time":"testTime","msgId":"testMsgId","correlationId":"testCorrelationId","user":"testUser"},"id":"testId"}`);
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
122
|
globalThis.describe("variantFields", () => {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// The AES-256-GCM binding an encrypting provider seals values with.
|
|
2
|
+
|
|
3
|
+
open JestGlobals
|
|
4
|
+
|
|
5
|
+
let key = NodeCrypto.aesKey()
|
|
6
|
+
|
|
7
|
+
describe("NodeCrypto AES-256-GCM", () => {
|
|
8
|
+
testSync("round-trips, and never repeats a ciphertext", () => {
|
|
9
|
+
let a = NodeCrypto.aesGcmEncrypt(~key, "Ada Lovelace")
|
|
10
|
+
let b = NodeCrypto.aesGcmEncrypt(~key, "Ada Lovelace")
|
|
11
|
+
expect(a == b)->toBe(false)
|
|
12
|
+
expect(NodeCrypto.aesGcmDecrypt(~key, a))->toEqual(Ok("Ada Lovelace"))
|
|
13
|
+
expect(a->String.includes("Ada"))->toBe(false)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
testSync("a tampered value does not open", () => {
|
|
17
|
+
let sealed = NodeCrypto.aesGcmEncrypt(~key, "Ada Lovelace")
|
|
18
|
+
let flipped = sealed->String.charAt(20) == "A" ? "B" : "A"
|
|
19
|
+
let tampered =
|
|
20
|
+
sealed->String.slice(~start=0, ~end=20) ++ flipped ++ sealed->String.slice(~start=21)
|
|
21
|
+
expect(NodeCrypto.aesGcmDecrypt(~key, tampered)->Result.isError)->toBe(true)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
testSync("another key, or another aad, does not open it", () => {
|
|
25
|
+
let sealed = NodeCrypto.aesGcmEncrypt(~key, ~aad="member-1/name", "Ada")
|
|
26
|
+
expect(
|
|
27
|
+
NodeCrypto.aesGcmDecrypt(
|
|
28
|
+
~key=NodeCrypto.aesKey(),
|
|
29
|
+
~aad="member-1/name",
|
|
30
|
+
sealed,
|
|
31
|
+
)->Result.isError,
|
|
32
|
+
)->toBe(true)
|
|
33
|
+
expect(NodeCrypto.aesGcmDecrypt(~key, ~aad="member-2/name", sealed)->Result.isError)->toBe(true)
|
|
34
|
+
expect(NodeCrypto.aesGcmDecrypt(~key, ~aad="member-1/name", sealed))->toEqual(Ok("Ada"))
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
testSync("a value too short to hold a nonce and a tag is refused", () =>
|
|
38
|
+
expect(NodeCrypto.aesGcmDecrypt(~key, "AAAA")->Result.isError)->toBe(true)
|
|
39
|
+
)
|
|
40
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Fixture: a spec whose event and command mark personal fields with `@pii`.
|
|
2
|
+
|
|
3
|
+
@@reventless.spec("PiiMember")
|
|
4
|
+
|
|
5
|
+
@schema
|
|
6
|
+
type event =
|
|
7
|
+
| MemberJoined({
|
|
8
|
+
@owner memberId: string,
|
|
9
|
+
@pii name: string,
|
|
10
|
+
@pii bio?: string,
|
|
11
|
+
@pii nickname: option<string>,
|
|
12
|
+
@pii address: Reventless.Email.t,
|
|
13
|
+
@pii({subject: "memberId"}) @storageRef("photos") photo: string,
|
|
14
|
+
})
|
|
15
|
+
| InvitationSent({invitationId: string, @pii("invitationId") invitee: Reventless.Email.t})
|
|
16
|
+
|
|
17
|
+
@schema
|
|
18
|
+
type command = Join({@owner memberId: string, @pii name: string, @pii address: Reventless.Email.t})
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
import * as Owner$Reventless from "@reventlessdev/reventless-spec/src/components/Owner.res.mjs";
|
|
7
|
+
import * as StorageRef$Reventless from "@reventlessdev/reventless-spec/src/semantic/StorageRef.res.mjs";
|
|
8
|
+
|
|
9
|
+
let eventSchema = Sury.union([
|
|
10
|
+
Sury.$schema(s => ({
|
|
11
|
+
TAG: "MemberJoined",
|
|
12
|
+
memberId: s.m(Owner$Reventless.string),
|
|
13
|
+
name: s.m(Pii$Reventless.marked("memberId", undefined, Sury.string)),
|
|
14
|
+
bio: s.m(Sury.$option(Pii$Reventless.marked("memberId", undefined, Sury.string))),
|
|
15
|
+
nickname: s.m(Sury.$option(Pii$Reventless.marked("memberId", undefined, Sury.string))),
|
|
16
|
+
address: s.m(Pii$Reventless.marked("memberId", undefined, Email$Reventless.schema)),
|
|
17
|
+
photo: s.m(Pii$Reventless.marked("memberId", true, StorageRef$Reventless.forStore(undefined, "photos")))
|
|
18
|
+
})),
|
|
19
|
+
Sury.$schema(s => ({
|
|
20
|
+
TAG: "InvitationSent",
|
|
21
|
+
invitationId: s.m(Sury.string),
|
|
22
|
+
invitee: s.m(Pii$Reventless.marked("invitationId", undefined, Email$Reventless.schema))
|
|
23
|
+
}))
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
let commandSchema = Sury.$schema(s => ({
|
|
27
|
+
TAG: "Join",
|
|
28
|
+
memberId: s.m(Owner$Reventless.string),
|
|
29
|
+
name: s.m(Pii$Reventless.mark("memberId", undefined, Sury.string)),
|
|
30
|
+
address: s.m(Pii$Reventless.mark("memberId", undefined, Email$Reventless.schema))
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
function authorizationOf(param) {
|
|
34
|
+
return "AllowAuthenticated";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function commandTransition(param) {
|
|
38
|
+
return "Undeclared";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let traits = [];
|
|
42
|
+
|
|
43
|
+
let name = "PiiMember";
|
|
44
|
+
|
|
45
|
+
let Id;
|
|
46
|
+
|
|
47
|
+
let moduleUrl = "@reventlessdev/reventless-core/tests/pii/PiiMember.res.mjs";
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
name,
|
|
51
|
+
Id,
|
|
52
|
+
eventSchema,
|
|
53
|
+
commandSchema,
|
|
54
|
+
moduleUrl,
|
|
55
|
+
authorizationOf,
|
|
56
|
+
commandTransition,
|
|
57
|
+
traits,
|
|
58
|
+
}
|
|
59
|
+
/* eventSchema Not a pure module */
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// `@pii` as the PPX expands it: on an event the field reads `Pii.t`, and on a
|
|
2
|
+
// command it keeps its type; on both the schema carries the marker and
|
|
3
|
+
// `@sensitive`, and the JSON schema lists it.
|
|
4
|
+
|
|
5
|
+
open JestGlobals
|
|
6
|
+
|
|
7
|
+
module M = PiiMember
|
|
8
|
+
|
|
9
|
+
let encode = e => e->Reventless.Util_Sury.toJson(M.eventSchema)
|
|
10
|
+
let decode = json => json->Reventless.Util_Sury.fromJson(M.eventSchema)
|
|
11
|
+
|
|
12
|
+
let joined: M.event = MemberJoined({
|
|
13
|
+
memberId: "m-1",
|
|
14
|
+
name: Value("Ada"),
|
|
15
|
+
bio: Value("mathematician"),
|
|
16
|
+
nickname: None,
|
|
17
|
+
address: Value(Reventless.Email.unsafe("ada@example.com")),
|
|
18
|
+
photo: Value("/photos/m-1/0b1c.jpg"),
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
describe("@pii on an event", () => {
|
|
22
|
+
testSync("a value is stored as the plain value with no provider, and reads back", () => {
|
|
23
|
+
let json = encode(joined)
|
|
24
|
+
expect(json->JSON.stringify->String.includes("\"Ada\""))->toBe(true)
|
|
25
|
+
expect(decode(json))->toEqual(joined)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
testSync("an erased value reads Erased, not a string", () => {
|
|
29
|
+
let erased: M.event = MemberJoined({
|
|
30
|
+
memberId: "m-1",
|
|
31
|
+
name: Erased,
|
|
32
|
+
nickname: None,
|
|
33
|
+
address: Erased,
|
|
34
|
+
photo: Forgotten,
|
|
35
|
+
})
|
|
36
|
+
expect(decode(encode(erased)))->toEqual(erased)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
testSync("the marker names the subject, defaulting to the @owner field", () => {
|
|
40
|
+
let fields =
|
|
41
|
+
M.eventSchema->S.castToUnknown->Reventless.Pii.variantFields(~variant="MemberJoined")
|
|
42
|
+
expect(fields->Array.map(((name, m)) => (name, m.subject, m.forgettable)))->toEqual([
|
|
43
|
+
("name", "memberId", false),
|
|
44
|
+
("bio", "memberId", false),
|
|
45
|
+
("nickname", "memberId", false),
|
|
46
|
+
("address", "memberId", false),
|
|
47
|
+
("photo", "memberId", true),
|
|
48
|
+
])
|
|
49
|
+
let invited =
|
|
50
|
+
M.eventSchema->S.castToUnknown->Reventless.Pii.variantFields(~variant="InvitationSent")
|
|
51
|
+
expect(invited->Array.map(((name, m)) => (name, m.subject)))->toEqual([
|
|
52
|
+
("invitee", "invitationId"),
|
|
53
|
+
])
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
testSync("@pii implies @sensitive", () =>
|
|
57
|
+
expect(
|
|
58
|
+
M.eventSchema
|
|
59
|
+
->S.castToUnknown
|
|
60
|
+
->Reventless.Sensitive.variantFieldNames(~variant="MemberJoined")
|
|
61
|
+
->Array.includes("name"),
|
|
62
|
+
)->toBe(true)
|
|
63
|
+
)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
describe("@pii on a command", () => {
|
|
67
|
+
testSync("keeps the plain type and carries the marker", () => {
|
|
68
|
+
let join: M.command = Join({
|
|
69
|
+
memberId: "m-1",
|
|
70
|
+
name: "Ada",
|
|
71
|
+
address: Reventless.Email.unsafe("ada@example.com"),
|
|
72
|
+
})
|
|
73
|
+
let back =
|
|
74
|
+
join
|
|
75
|
+
->Reventless.Util_Sury.toJson(M.commandSchema)
|
|
76
|
+
->Reventless.Util_Sury.fromJson(M.commandSchema)
|
|
77
|
+
expect(back)->toEqual(join)
|
|
78
|
+
let fields = M.commandSchema->S.castToUnknown->Reventless.Pii.variantFields(~variant="Join")
|
|
79
|
+
expect(fields->Array.map(((name, _)) => name))->toEqual(["name", "address"])
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
describe("the JSON schema", () => {
|
|
84
|
+
testSync("lists the marker on the field", () => {
|
|
85
|
+
let fields =
|
|
86
|
+
M.eventSchema
|
|
87
|
+
->S.castToUnknown
|
|
88
|
+
->Reventless.Semantic.unionVariant(~variant="MemberJoined")
|
|
89
|
+
->Option.getOrThrow
|
|
90
|
+
let json = SuryToJsonSchema.deriveObjectSchema(fields)->JSON.stringify
|
|
91
|
+
expect(
|
|
92
|
+
json->String.includes(
|
|
93
|
+
"\"x-reventless-pii\":{\"subject\":\"memberId\",\"forgettable\":false}",
|
|
94
|
+
),
|
|
95
|
+
)->toBe(true)
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
describe("a log line of a @pii event or command", () => {
|
|
100
|
+
testSync("holds no personal value, whichever formatter prints it", () => {
|
|
101
|
+
let eventJson = encode(joined)
|
|
102
|
+
let envelope =
|
|
103
|
+
Dict.fromArray([
|
|
104
|
+
("id", JSON.Encode.string("m-1")),
|
|
105
|
+
("meta", Dict.fromArray([("ip", JSON.Encode.string("10.0.0.1"))])->JSON.Encode.object),
|
|
106
|
+
("event", eventJson),
|
|
107
|
+
])->JSON.Encode.object
|
|
108
|
+
let lines = [LogFormat.eventDetail(envelope), LogFormat.eventFull(envelope)]
|
|
109
|
+
lines->Array.forEach(
|
|
110
|
+
line => {
|
|
111
|
+
expect(line->String.includes("Ada"))->toBe(false)
|
|
112
|
+
expect(line->String.includes("ada@example.com"))->toBe(false)
|
|
113
|
+
expect(line->String.includes("mathematician"))->toBe(false)
|
|
114
|
+
expect(line->String.includes("10.0.0.1"))->toBe(false)
|
|
115
|
+
expect(line->String.includes("m-1"))->toBe(true)
|
|
116
|
+
},
|
|
117
|
+
)
|
|
118
|
+
let join: M.command = Join({
|
|
119
|
+
memberId: "m-1",
|
|
120
|
+
name: "Ada",
|
|
121
|
+
address: Reventless.Email.unsafe("ada@example.com"),
|
|
122
|
+
})
|
|
123
|
+
let commandJson = join->Reventless.Util_Sury.toJson(M.commandSchema)
|
|
124
|
+
let label = LogFormat.cmdLabelOfJson(commandJson)
|
|
125
|
+
expect(label->String.includes("Ada"))->toBe(false)
|
|
126
|
+
expect(label->String.includes("m-1"))->toBe(true)
|
|
127
|
+
})
|
|
128
|
+
})
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
4
|
+
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
5
|
+
import * as Semantic$Reventless from "@reventlessdev/reventless-spec/src/semantic/Semantic.res.mjs";
|
|
6
|
+
import * as Sensitive$Reventless from "@reventlessdev/reventless-spec/src/components/Sensitive.res.mjs";
|
|
7
|
+
import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
|
|
8
|
+
import * as LogFormat$ReventlessCore from "../../src/util/LogFormat.res.mjs";
|
|
9
|
+
import * as PiiMember$ReventlessCore from "./PiiMember.res.mjs";
|
|
10
|
+
import * as SuryToJsonSchema$ReventlessCore from "../../src/components/Api/SuryToJsonSchema.res.mjs";
|
|
11
|
+
|
|
12
|
+
function encode(e) {
|
|
13
|
+
return Util_Sury$Reventless.toJson(e, PiiMember$ReventlessCore.eventSchema);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function decode(json) {
|
|
17
|
+
return Util_Sury$Reventless.fromJson(json, PiiMember$ReventlessCore.eventSchema);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let joined_1 = {
|
|
21
|
+
TAG: "Value",
|
|
22
|
+
_0: "Ada"
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
let joined_2 = {
|
|
26
|
+
TAG: "Value",
|
|
27
|
+
_0: "mathematician"
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
let joined_4 = {
|
|
31
|
+
TAG: "Value",
|
|
32
|
+
_0: "ada@example.com"
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
let joined_5 = {
|
|
36
|
+
TAG: "Value",
|
|
37
|
+
_0: "/photos/m-1/0b1c.jpg"
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
let joined = {
|
|
41
|
+
TAG: "MemberJoined",
|
|
42
|
+
memberId: "m-1",
|
|
43
|
+
name: joined_1,
|
|
44
|
+
bio: joined_2,
|
|
45
|
+
nickname: undefined,
|
|
46
|
+
address: joined_4,
|
|
47
|
+
photo: joined_5
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
globalThis.describe("@pii on an event", () => {
|
|
51
|
+
globalThis.test("a value is stored as the plain value with no provider, and reads back", () => {
|
|
52
|
+
let json = Util_Sury$Reventless.toJson(joined, PiiMember$ReventlessCore.eventSchema);
|
|
53
|
+
globalThis.expect(JSON.stringify(json).includes("\"Ada\"")).toBe(true);
|
|
54
|
+
globalThis.expect(Util_Sury$Reventless.fromJson(json, PiiMember$ReventlessCore.eventSchema)).toEqual(joined);
|
|
55
|
+
});
|
|
56
|
+
globalThis.test("an erased value reads Erased, not a string", () => {
|
|
57
|
+
let erased = {
|
|
58
|
+
TAG: "MemberJoined",
|
|
59
|
+
memberId: "m-1",
|
|
60
|
+
name: "Erased",
|
|
61
|
+
nickname: undefined,
|
|
62
|
+
address: "Erased",
|
|
63
|
+
photo: "Forgotten"
|
|
64
|
+
};
|
|
65
|
+
let json = Util_Sury$Reventless.toJson(erased, PiiMember$ReventlessCore.eventSchema);
|
|
66
|
+
globalThis.expect(Util_Sury$Reventless.fromJson(json, PiiMember$ReventlessCore.eventSchema)).toEqual(erased);
|
|
67
|
+
});
|
|
68
|
+
globalThis.test("the marker names the subject, defaulting to the @owner field", () => {
|
|
69
|
+
let fields = Pii$Reventless.variantFields(PiiMember$ReventlessCore.eventSchema, "MemberJoined");
|
|
70
|
+
globalThis.expect(fields.map(param => {
|
|
71
|
+
let m = param[1];
|
|
72
|
+
return [
|
|
73
|
+
param[0],
|
|
74
|
+
m.subject,
|
|
75
|
+
m.forgettable
|
|
76
|
+
];
|
|
77
|
+
})).toEqual([
|
|
78
|
+
[
|
|
79
|
+
"name",
|
|
80
|
+
"memberId",
|
|
81
|
+
false
|
|
82
|
+
],
|
|
83
|
+
[
|
|
84
|
+
"bio",
|
|
85
|
+
"memberId",
|
|
86
|
+
false
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
"nickname",
|
|
90
|
+
"memberId",
|
|
91
|
+
false
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
"address",
|
|
95
|
+
"memberId",
|
|
96
|
+
false
|
|
97
|
+
],
|
|
98
|
+
[
|
|
99
|
+
"photo",
|
|
100
|
+
"memberId",
|
|
101
|
+
true
|
|
102
|
+
]
|
|
103
|
+
]);
|
|
104
|
+
let invited = Pii$Reventless.variantFields(PiiMember$ReventlessCore.eventSchema, "InvitationSent");
|
|
105
|
+
globalThis.expect(invited.map(param => [
|
|
106
|
+
param[0],
|
|
107
|
+
param[1].subject
|
|
108
|
+
])).toEqual([[
|
|
109
|
+
"invitee",
|
|
110
|
+
"invitationId"
|
|
111
|
+
]]);
|
|
112
|
+
});
|
|
113
|
+
globalThis.test("@pii implies @sensitive", () => {
|
|
114
|
+
globalThis.expect(Sensitive$Reventless.variantFieldNames(PiiMember$ReventlessCore.eventSchema, "MemberJoined").includes("name")).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
globalThis.describe("@pii on a command", () => {
|
|
119
|
+
globalThis.test("keeps the plain type and carries the marker", () => {
|
|
120
|
+
let join = {
|
|
121
|
+
TAG: "Join",
|
|
122
|
+
memberId: "m-1",
|
|
123
|
+
name: "Ada",
|
|
124
|
+
address: "ada@example.com"
|
|
125
|
+
};
|
|
126
|
+
let back = Util_Sury$Reventless.fromJson(Util_Sury$Reventless.toJson(join, PiiMember$ReventlessCore.commandSchema), PiiMember$ReventlessCore.commandSchema);
|
|
127
|
+
globalThis.expect(back).toEqual(join);
|
|
128
|
+
let fields = Pii$Reventless.variantFields(PiiMember$ReventlessCore.commandSchema, "Join");
|
|
129
|
+
globalThis.expect(fields.map(param => param[0])).toEqual([
|
|
130
|
+
"name",
|
|
131
|
+
"address"
|
|
132
|
+
]);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
globalThis.describe("the JSON schema", () => {
|
|
137
|
+
globalThis.test("lists the marker on the field", () => {
|
|
138
|
+
let fields = Stdlib_Option.getOrThrow(Semantic$Reventless.unionVariant(PiiMember$ReventlessCore.eventSchema, "MemberJoined"), undefined);
|
|
139
|
+
let json = JSON.stringify(SuryToJsonSchema$ReventlessCore.deriveObjectSchema(undefined, undefined, fields));
|
|
140
|
+
globalThis.expect(json.includes("\"x-reventless-pii\":{\"subject\":\"memberId\",\"forgettable\":false}")).toBe(true);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
globalThis.describe("a log line of a @pii event or command", () => {
|
|
145
|
+
globalThis.test("holds no personal value, whichever formatter prints it", () => {
|
|
146
|
+
let eventJson = Util_Sury$Reventless.toJson(joined, PiiMember$ReventlessCore.eventSchema);
|
|
147
|
+
let envelope = Object.fromEntries([
|
|
148
|
+
[
|
|
149
|
+
"id",
|
|
150
|
+
"m-1"
|
|
151
|
+
],
|
|
152
|
+
[
|
|
153
|
+
"meta",
|
|
154
|
+
Object.fromEntries([[
|
|
155
|
+
"ip",
|
|
156
|
+
"10.0.0.1"
|
|
157
|
+
]])
|
|
158
|
+
],
|
|
159
|
+
[
|
|
160
|
+
"event",
|
|
161
|
+
eventJson
|
|
162
|
+
]
|
|
163
|
+
]);
|
|
164
|
+
let lines = [
|
|
165
|
+
LogFormat$ReventlessCore.eventDetail(envelope),
|
|
166
|
+
LogFormat$ReventlessCore.eventFull(envelope)
|
|
167
|
+
];
|
|
168
|
+
lines.forEach(line => {
|
|
169
|
+
globalThis.expect(line.includes("Ada")).toBe(false);
|
|
170
|
+
globalThis.expect(line.includes("ada@example.com")).toBe(false);
|
|
171
|
+
globalThis.expect(line.includes("mathematician")).toBe(false);
|
|
172
|
+
globalThis.expect(line.includes("10.0.0.1")).toBe(false);
|
|
173
|
+
globalThis.expect(line.includes("m-1")).toBe(true);
|
|
174
|
+
});
|
|
175
|
+
let join = {
|
|
176
|
+
TAG: "Join",
|
|
177
|
+
memberId: "m-1",
|
|
178
|
+
name: "Ada",
|
|
179
|
+
address: "ada@example.com"
|
|
180
|
+
};
|
|
181
|
+
let commandJson = Util_Sury$Reventless.toJson(join, PiiMember$ReventlessCore.commandSchema);
|
|
182
|
+
let label = LogFormat$ReventlessCore.cmdLabelOfJson(commandJson);
|
|
183
|
+
globalThis.expect(label.includes("Ada")).toBe(false);
|
|
184
|
+
globalThis.expect(label.includes("m-1")).toBe(true);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
let M;
|
|
189
|
+
|
|
190
|
+
export {
|
|
191
|
+
M,
|
|
192
|
+
encode,
|
|
193
|
+
decode,
|
|
194
|
+
joined,
|
|
195
|
+
}
|
|
196
|
+
/* Not a pure module */
|