@reventlessdev/reventless-core 3.0.0-alpha.312 → 3.0.0-alpha.313

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 CHANGED
@@ -3,6 +3,22 @@
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.313 (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
+
10
+ ### BREAKING CHANGES
11
+
12
+ * the ledger's events carry `address: Pii.t<Email.t>`. Pattern-match
13
+ `Value(address)` where the address is read.
14
+
15
+ The published per-platform PPX binary does not know `@pii` until it is republished.
16
+
17
+ Step PD2 of docs/plans/a-personal-field-is-marked-redacted-and-encrypted-at-the-seam.md.
18
+ Claude-Session: https://claude.ai/code/session_01HiQfdxVEsHwLHRoHSUcus1
19
+
20
+
21
+
6
22
  # 3.0.0-alpha.312 (2026-10-29)
7
23
 
8
24
  * 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.312",
3
+ "version": "3.0.0-alpha.313",
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",
33
32
  "@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
34
33
  "@reventlessdev/rescript-node": "2.0.0-alpha.23",
34
+ "@reventlessdev/rescript-fast-csv": "2.0.0-alpha.23",
35
35
  "@reventlessdev/rescript-jest": "1.0.0-alpha.13",
36
- "@reventlessdev/rescript-ssh2": "2.0.0-alpha.24",
37
36
  "@reventlessdev/rescript-pulumi-pulumi": "3.0.0-alpha.0",
37
+ "@reventlessdev/rescript-ssh2": "2.0.0-alpha.24",
38
38
  "@reventlessdev/rescript-uuid": "2.0.0-alpha.1",
39
- "@reventlessdev/reventless-infra": "3.0.0-alpha.209",
39
+ "@reventlessdev/reventless-infra": "3.0.0-alpha.210",
40
40
  "@reventlessdev/reventless-interop": "3.0.0-alpha.42",
41
- "@reventlessdev/reventless-spec": "3.0.0-alpha.180"
41
+ "@reventlessdev/reventless-spec": "3.0.0-alpha.181"
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->JSON.stringifyAny->Option.getOr("")->JSON.Encode.string,
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
@@ -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), ""), str);
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
- props[fieldName] = withAnnotations$2;
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
- let commandStr = json->JSON.stringify
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 meta of ${json->JSON.stringify}: ${Reventless.Util_Sury.exnMessage(
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 meta of ` + JSON.stringify(json) + `: ` + Util_Sury$Reventless.exnMessage(exn, undefined));
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) => {
@@ -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, metaStr, eventStr) = j->Message.idMetaEventOfEvent'Json
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
- if (typeof json !== "object" || json === null || Array.isArray(json)) {
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(json).filter(param => param[0] !== "TAG"), param => {
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
- return `{"event":` + match[2] + `,"meta":` + match[1] + `,"id":"` + match[0] + `"}`;
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,
@@ -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
- ->Array.concat(detail->Option.mapOr([], d => [("detail", truncateDetail(d))]))
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 = data->Option.map(d => ` ${d->JSON.stringify}`)->Option.getOr("")
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
  {
@@ -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
- let metaStr = meta->Message.encode(Message.metaSchema)->JSON.stringify
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
- let metaStr = meta->Message.encode(Message.metaSchema)->JSON.stringify
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","ip":"testIp","user":"testUser"},"id":"testId"}`
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
  },
@@ -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,151 @@
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 PiiMember$ReventlessCore from "./PiiMember.res.mjs";
9
+ import * as SuryToJsonSchema$ReventlessCore from "../../src/components/Api/SuryToJsonSchema.res.mjs";
10
+
11
+ function encode(e) {
12
+ return Util_Sury$Reventless.toJson(e, PiiMember$ReventlessCore.eventSchema);
13
+ }
14
+
15
+ function decode(json) {
16
+ return Util_Sury$Reventless.fromJson(json, PiiMember$ReventlessCore.eventSchema);
17
+ }
18
+
19
+ let joined_1 = {
20
+ TAG: "Value",
21
+ _0: "Ada"
22
+ };
23
+
24
+ let joined_2 = {
25
+ TAG: "Value",
26
+ _0: "mathematician"
27
+ };
28
+
29
+ let joined_4 = {
30
+ TAG: "Value",
31
+ _0: "ada@example.com"
32
+ };
33
+
34
+ let joined_5 = {
35
+ TAG: "Value",
36
+ _0: "/photos/m-1/0b1c.jpg"
37
+ };
38
+
39
+ let joined = {
40
+ TAG: "MemberJoined",
41
+ memberId: "m-1",
42
+ name: joined_1,
43
+ bio: joined_2,
44
+ nickname: undefined,
45
+ address: joined_4,
46
+ photo: joined_5
47
+ };
48
+
49
+ globalThis.describe("@pii on an event", () => {
50
+ globalThis.test("a value is stored as the plain value with no provider, and reads back", () => {
51
+ let json = Util_Sury$Reventless.toJson(joined, PiiMember$ReventlessCore.eventSchema);
52
+ globalThis.expect(JSON.stringify(json).includes("\"Ada\"")).toBe(true);
53
+ globalThis.expect(Util_Sury$Reventless.fromJson(json, PiiMember$ReventlessCore.eventSchema)).toEqual(joined);
54
+ });
55
+ globalThis.test("an erased value reads Erased, not a string", () => {
56
+ let erased = {
57
+ TAG: "MemberJoined",
58
+ memberId: "m-1",
59
+ name: "Erased",
60
+ nickname: undefined,
61
+ address: "Erased",
62
+ photo: "Forgotten"
63
+ };
64
+ let json = Util_Sury$Reventless.toJson(erased, PiiMember$ReventlessCore.eventSchema);
65
+ globalThis.expect(Util_Sury$Reventless.fromJson(json, PiiMember$ReventlessCore.eventSchema)).toEqual(erased);
66
+ });
67
+ globalThis.test("the marker names the subject, defaulting to the @owner field", () => {
68
+ let fields = Pii$Reventless.variantFields(PiiMember$ReventlessCore.eventSchema, "MemberJoined");
69
+ globalThis.expect(fields.map(param => {
70
+ let m = param[1];
71
+ return [
72
+ param[0],
73
+ m.subject,
74
+ m.forgettable
75
+ ];
76
+ })).toEqual([
77
+ [
78
+ "name",
79
+ "memberId",
80
+ false
81
+ ],
82
+ [
83
+ "bio",
84
+ "memberId",
85
+ false
86
+ ],
87
+ [
88
+ "nickname",
89
+ "memberId",
90
+ false
91
+ ],
92
+ [
93
+ "address",
94
+ "memberId",
95
+ false
96
+ ],
97
+ [
98
+ "photo",
99
+ "memberId",
100
+ true
101
+ ]
102
+ ]);
103
+ let invited = Pii$Reventless.variantFields(PiiMember$ReventlessCore.eventSchema, "InvitationSent");
104
+ globalThis.expect(invited.map(param => [
105
+ param[0],
106
+ param[1].subject
107
+ ])).toEqual([[
108
+ "invitee",
109
+ "invitationId"
110
+ ]]);
111
+ });
112
+ globalThis.test("@pii implies @sensitive", () => {
113
+ globalThis.expect(Sensitive$Reventless.variantFieldNames(PiiMember$ReventlessCore.eventSchema, "MemberJoined").includes("name")).toBe(true);
114
+ });
115
+ });
116
+
117
+ globalThis.describe("@pii on a command", () => {
118
+ globalThis.test("keeps the plain type and carries the marker", () => {
119
+ let join = {
120
+ TAG: "Join",
121
+ memberId: "m-1",
122
+ name: "Ada",
123
+ address: "ada@example.com"
124
+ };
125
+ let back = Util_Sury$Reventless.fromJson(Util_Sury$Reventless.toJson(join, PiiMember$ReventlessCore.commandSchema), PiiMember$ReventlessCore.commandSchema);
126
+ globalThis.expect(back).toEqual(join);
127
+ let fields = Pii$Reventless.variantFields(PiiMember$ReventlessCore.commandSchema, "Join");
128
+ globalThis.expect(fields.map(param => param[0])).toEqual([
129
+ "name",
130
+ "address"
131
+ ]);
132
+ });
133
+ });
134
+
135
+ globalThis.describe("the JSON schema", () => {
136
+ globalThis.test("lists the marker on the field", () => {
137
+ let fields = Stdlib_Option.getOrThrow(Semantic$Reventless.unionVariant(PiiMember$ReventlessCore.eventSchema, "MemberJoined"), undefined);
138
+ let json = JSON.stringify(SuryToJsonSchema$ReventlessCore.deriveObjectSchema(undefined, undefined, fields));
139
+ globalThis.expect(json.includes("\"x-reventless-pii\":{\"subject\":\"memberId\",\"forgettable\":false}")).toBe(true);
140
+ });
141
+ });
142
+
143
+ let M;
144
+
145
+ export {
146
+ M,
147
+ encode,
148
+ decode,
149
+ joined,
150
+ }
151
+ /* Not a pure module */