@reventlessdev/reventless-core 3.0.0-alpha.306 → 3.0.0-alpha.308

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/package.json +5 -5
  3. package/src/Projection.res +4 -4
  4. package/src/Projection.res.mjs +11 -9
  5. package/src/ResourceAttribution.res +3 -3
  6. package/src/ResourceAttribution.res.mjs +1 -4
  7. package/src/adapter/Auth/Auth_ActiveRole.res +13 -18
  8. package/src/adapter/Auth/Auth_ActiveRole.res.mjs +4 -9
  9. package/src/adapter/Auth/Auth_UserId.res +24 -0
  10. package/src/adapter/Auth/Auth_UserId.res.mjs +23 -0
  11. package/src/adapter/EventLogProvisioning/EventLogProvisioning.res +1 -1
  12. package/src/adapter/Monitoring/Monitoring.res +5 -5
  13. package/src/adapter/Stash/Stash_Memory_Backend.res +35 -0
  14. package/src/adapter/Stash/Stash_Memory_Backend.res.mjs +44 -0
  15. package/src/adapter/Throttle/AnonymousLimiter.res +37 -0
  16. package/src/adapter/Throttle/AnonymousLimiter.res.mjs +43 -0
  17. package/src/admin/Platform_Admin.res +2 -2
  18. package/src/admin/Platform_Admin_Structure.res +0 -9
  19. package/src/admin/Platform_Admin_Structure.res.mjs +3 -12
  20. package/src/admin/Platform_BakedManifest.res +6 -6
  21. package/src/admin/Platform_BakedManifest.res.mjs +11 -26
  22. package/src/admin/Platform_PluginStructuresApi.res +36 -2
  23. package/src/admin/Platform_PluginStructuresApi.res.mjs +43 -1
  24. package/src/admin/Platform_SelfRegistration.res +54 -0
  25. package/src/admin/Platform_SelfRegistration.res.mjs +77 -0
  26. package/src/components/Api/GraphQL_SchemaInspector.res +3 -3
  27. package/src/components/Api/SuryToJsonSchema.res +3 -3
  28. package/src/components/Dcb/Dcb_Builder.res +6 -9
  29. package/src/components/Dcb/Dcb_Builder.res.mjs +0 -3
  30. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res +14 -1
  31. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res.mjs +3 -3
  32. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res +73 -8
  33. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +60 -12
  34. package/src/plugin/component/Plugin.res +2 -0
  35. package/src/plugin/component/Plugin_Builder.res +9 -8
  36. package/src/plugin/component/Plugin_Builder.res.mjs +6 -10
  37. package/src/plugin/component/Plugin_Helpers.res +4 -4
  38. package/src/plugin/component/Plugin_Structure.res +179 -115
  39. package/src/plugin/component/Plugin_Structure.res.mjs +83 -17
  40. package/src/plugin/lifecycle/PluginsProjection.res +10 -6
  41. package/src/plugin/lifecycle/PluginsReadModelSpec.res +8 -8
  42. package/src/util/FTPHandler.res +3 -3
  43. package/src/util/ScheduleTime.res +5 -8
  44. package/src/util/ScheduleTime.res.mjs +0 -3
  45. package/src/util/Util_Promise.res +1 -1
  46. package/tests/AnonymousLimiterTest.res +66 -0
  47. package/tests/AnonymousLimiterTest.res.mjs +89 -0
  48. package/tests/Auth_UserIdTest.res +24 -0
  49. package/tests/Auth_UserIdTest.res.mjs +23 -0
  50. package/tests/ResourceAttributionTest.res +1 -1
  51. package/tests/ResourceAttributionTest.res.mjs +1 -4
  52. package/tests/Stash_Memory_BackendTest.res +63 -0
  53. package/tests/Stash_Memory_BackendTest.res.mjs +98 -0
  54. package/tests/admin/AdminApiSchemaDriftTest.res +72 -44
  55. package/tests/admin/AdminApiSchemaDriftTest.res.mjs +41 -3
  56. package/tests/admin/Platform_Admin_StructureTest.res +1 -1
  57. package/tests/admin/Platform_Admin_StructureTest.res.mjs +4 -22
  58. package/tests/admin/Platform_BakedManifestTest.res +11 -29
  59. package/tests/admin/Platform_BakedManifestTest.res.mjs +8 -39
  60. package/tests/admin/Platform_ComponentDefinitionsApiTest.res +24 -84
  61. package/tests/admin/Platform_ComponentDefinitionsApiTest.res.mjs +36 -169
  62. package/tests/admin/Platform_PluginStructuresApiTest.res +46 -31
  63. package/tests/admin/Platform_PluginStructuresApiTest.res.mjs +37 -34
  64. package/tests/admin/Platform_SelfRegistrationTest.res +70 -0
  65. package/tests/admin/Platform_SelfRegistrationTest.res.mjs +98 -0
  66. package/tests/admin/Platform_UIFragmentsApiTest.res +1 -4
  67. package/tests/admin/Platform_UIFragmentsApiTest.res.mjs +1 -4
  68. package/tests/api/GeocodingTest.res +1 -1
  69. package/tests/logger/LogFormatTest.res +0 -2
  70. package/tests/logger/LogFormatTest.res.mjs +0 -2
  71. package/tests/message/MessageTest.res +0 -13
  72. package/tests/message/MessageTest.res.mjs +2 -15
  73. package/tests/plugin/ManifestVisibilityTest.res.mjs +1 -1
  74. package/tests/plugin/PluginStructureAccessTest.res +6 -1
  75. package/tests/plugin/PluginStructureAccessTest.res.mjs +9 -5
  76. package/tests/plugin/PluginStructureTest.res +99 -23
  77. package/tests/plugin/PluginStructureTest.res.mjs +123 -79
  78. package/tests/plugin/pluginDefinitionRequiredScalars.txt +10 -0
@@ -102,17 +102,11 @@ function referencedEntities(pluginName, kept) {
102
102
  function curateStructure(pluginId, def, sel) {
103
103
  return Stdlib_Result.map(validate(def, sel), () => {
104
104
  let pluginName = Plugin$ReventlessCore.name(pluginId);
105
- let keepCommands = ws => ws.map(w => ({
106
- name: w.name,
107
- commands: w.commands.filter(c => isSelected(sel.commands, c.name)),
108
- producedEventTypes: w.producedEventTypes,
109
- consumedEventTypes: w.consumedEventTypes,
110
- linkedViews: w.linkedViews,
111
- consistencyRead: w.consistencyRead,
112
- events: w.events,
113
- errors: w.errors,
114
- chapter: w.chapter
115
- })).filter(w => w.commands.length !== 0);
105
+ let keepCommands = ws => ws.map(w => {
106
+ let newrecord = {...w};
107
+ newrecord.commands = w.commands.filter(c => isSelected(sel.commands, c.name));
108
+ return newrecord;
109
+ }).filter(w => w.commands.length !== 0);
116
110
  let stateChangeSlices = keepCommands(def.stateChangeSlices);
117
111
  let aggregates = keepCommands(def.aggregates);
118
112
  let referenced = referencedEntities(pluginName, stateChangeSlices.concat(aggregates));
@@ -123,21 +117,12 @@ function curateStructure(pluginId, def, sel) {
123
117
  return referenced.includes(q.name);
124
118
  }
125
119
  });
126
- return {
127
- readModels: keepViews(def.readModels),
128
- stateViewSlices: keepViews(def.stateViewSlices),
129
- stateChangeSlices: stateChangeSlices,
130
- aggregates: aggregates,
131
- automationSlices: def.automationSlices,
132
- outboundTranslationSlices: def.outboundTranslationSlices,
133
- inboundTranslationSlices: def.inboundTranslationSlices,
134
- extensions: def.extensions,
135
- extensionPoints: def.extensionPoints,
136
- requiredStores: def.requiredStores,
137
- requiredStoreDeclarations: def.requiredStoreDeclarations,
138
- requiredCapabilities: def.requiredCapabilities,
139
- traitDeclarations: def.traitDeclarations
140
- };
120
+ let newrecord = {...def};
121
+ newrecord.aggregates = aggregates;
122
+ newrecord.stateChangeSlices = stateChangeSlices;
123
+ newrecord.stateViewSlices = keepViews(def.stateViewSlices);
124
+ newrecord.readModels = keepViews(def.readModels);
125
+ return newrecord;
141
126
  });
142
127
  }
143
128
 
@@ -46,13 +46,19 @@ let sdlTypes: array<string> = [
46
46
  // It records ORIGIN, never behavior — a grafted file is the host's to edit
47
47
  // afterwards — so a reader must not paint a declared graft as a verified one.
48
48
  `type Platform_TraitDeclaration {\n trait: String!\n version: String!\n posture: String!\n component: String!\n}`,
49
+ // How a person comes to hold a role, per role the plugin declares. `strategy` is a
50
+ // String for the reason `posture` is; `invitedBy` is null unless it is `Invitation`.
51
+ `type Platform_AdmissionDef {\n role: String!\n strategy: String!\n invitedBy: [String!]\n}`,
52
+ // A door into the admission flow, and which part of it the door serves.
53
+ `type Platform_AdmissionDoorDef {\n component: String!\n part: String!\n}`,
49
54
  // `extensionPoints` / `requiredStores` / `requiredStoreDeclarations` /
50
- // `requiredCapabilities` / `traitDeclarations` are nullable lists, not `[T!]!`: all five are optional on
55
+ // `requiredCapabilities` / `traitDeclarations` / `admission` / `admissionDoors` are
56
+ // nullable lists, not `[T!]!`: all seven are optional on
51
57
  // `pluginStructure` so that plugin definitions persisted before the field existed
52
58
  // still decode. A structure written by an older deploy sends null, and null is the
53
59
  // honest answer — an empty list would claim the plugin has no extension points when
54
60
  // the truth is that the deployment cannot say.
55
- `type Platform_PluginStructureEntry {\n pluginId: String!\n readModels: [Platform_ReadSideDef!]!\n stateViewSlices: [Platform_ReadSideDef!]!\n stateChangeSlices: [Platform_WriteSideDef!]!\n aggregates: [Platform_WriteSideDef!]!\n automationSlices: [Platform_AutomationSliceDef!]!\n outboundTranslationSlices: [Platform_OutboundTranslationSliceDef!]!\n inboundTranslationSlices: [Platform_InboundTranslationSliceDef!]!\n extensions: [Platform_ExtensionDef!]!\n extensionPoints: [Platform_ExtensionPointDef!]\n requiredStores: [String!]\n requiredStoreDeclarations: [Platform_RequiredStoreDeclaration!]\n requiredCapabilities: [Platform_RequiredCapabilityDeclaration!]\n traitDeclarations: [Platform_TraitDeclaration!]\n}`,
61
+ `type Platform_PluginStructureEntry {\n pluginId: String!\n readModels: [Platform_ReadSideDef!]!\n stateViewSlices: [Platform_ReadSideDef!]!\n stateChangeSlices: [Platform_WriteSideDef!]!\n aggregates: [Platform_WriteSideDef!]!\n automationSlices: [Platform_AutomationSliceDef!]!\n outboundTranslationSlices: [Platform_OutboundTranslationSliceDef!]!\n inboundTranslationSlices: [Platform_InboundTranslationSliceDef!]!\n extensions: [Platform_ExtensionDef!]!\n extensionPoints: [Platform_ExtensionPointDef!]\n requiredStores: [String!]\n requiredStoreDeclarations: [Platform_RequiredStoreDeclaration!]\n requiredCapabilities: [Platform_RequiredCapabilityDeclaration!]\n traitDeclarations: [Platform_TraitDeclaration!]\n admission: [Platform_AdmissionDef!]\n admissionDoors: [Platform_AdmissionDoorDef!]\n}`,
56
62
  ]
57
63
 
58
64
  let sdlQueryField: string = ` Platform_PluginStructures: [Platform_PluginStructureEntry!]!`
@@ -65,6 +71,22 @@ let encodeTraitDeclaration = (d: traitDeclaration): JSON.t =>
65
71
  ("component", JSON.Encode.string(d.component)),
66
72
  ])->JSON.Encode.object
67
73
 
74
+ let encodeAdmissionDef = (d: Reventless.Admission.def): JSON.t =>
75
+ Dict.fromArray([
76
+ ("role", JSON.Encode.string(d.role)),
77
+ ("strategy", JSON.Encode.string(d.strategy)),
78
+ (
79
+ "invitedBy",
80
+ d.invitedBy->Option.mapOr(JSON.Encode.null, Platform_ComponentDefinitionsApi.encodeStrings),
81
+ ),
82
+ ])->JSON.Encode.object
83
+
84
+ let encodeAdmissionDoorDef = (d: Reventless.Admission.doorDef): JSON.t =>
85
+ Dict.fromArray([
86
+ ("component", JSON.Encode.string(d.component)),
87
+ ("part", JSON.Encode.string(d.part)),
88
+ ])->JSON.Encode.object
89
+
68
90
  let encodeExtensionPointDef = (e: extensionPointDef): JSON.t =>
69
91
  Dict.fromArray([
70
92
  ("name", JSON.Encode.string(e.name)),
@@ -204,4 +226,16 @@ let encodePluginStructureEntry = (~pluginId: string, def: pluginStructure): JSON
204
226
  ds->Array.map(encodeTraitDeclaration)->JSON.Encode.array
205
227
  ),
206
228
  ),
229
+ (
230
+ "admission",
231
+ def.admission->Option.mapOr(JSON.Encode.null, ds =>
232
+ ds->Array.map(encodeAdmissionDef)->JSON.Encode.array
233
+ ),
234
+ ),
235
+ (
236
+ "admissionDoors",
237
+ def.admissionDoors->Option.mapOr(JSON.Encode.null, ds =>
238
+ ds->Array.map(encodeAdmissionDoorDef)->JSON.Encode.array
239
+ ),
240
+ ),
207
241
  ])->JSON.Encode.object
@@ -11,7 +11,9 @@ let sdlTypes = [
11
11
  `type Platform_RequiredStoreDeclaration {\n store: String!\n component: String!\n field: String!\n annotation: String\n}`,
12
12
  `type Platform_RequiredCapabilityDeclaration {\n capability: String!\n component: String!\n}`,
13
13
  `type Platform_TraitDeclaration {\n trait: String!\n version: String!\n posture: String!\n component: String!\n}`,
14
- `type Platform_PluginStructureEntry {\n pluginId: String!\n readModels: [Platform_ReadSideDef!]!\n stateViewSlices: [Platform_ReadSideDef!]!\n stateChangeSlices: [Platform_WriteSideDef!]!\n aggregates: [Platform_WriteSideDef!]!\n automationSlices: [Platform_AutomationSliceDef!]!\n outboundTranslationSlices: [Platform_OutboundTranslationSliceDef!]!\n inboundTranslationSlices: [Platform_InboundTranslationSliceDef!]!\n extensions: [Platform_ExtensionDef!]!\n extensionPoints: [Platform_ExtensionPointDef!]\n requiredStores: [String!]\n requiredStoreDeclarations: [Platform_RequiredStoreDeclaration!]\n requiredCapabilities: [Platform_RequiredCapabilityDeclaration!]\n traitDeclarations: [Platform_TraitDeclaration!]\n}`
14
+ `type Platform_AdmissionDef {\n role: String!\n strategy: String!\n invitedBy: [String!]\n}`,
15
+ `type Platform_AdmissionDoorDef {\n component: String!\n part: String!\n}`,
16
+ `type Platform_PluginStructureEntry {\n pluginId: String!\n readModels: [Platform_ReadSideDef!]!\n stateViewSlices: [Platform_ReadSideDef!]!\n stateChangeSlices: [Platform_WriteSideDef!]!\n aggregates: [Platform_WriteSideDef!]!\n automationSlices: [Platform_AutomationSliceDef!]!\n outboundTranslationSlices: [Platform_OutboundTranslationSliceDef!]!\n inboundTranslationSlices: [Platform_InboundTranslationSliceDef!]!\n extensions: [Platform_ExtensionDef!]!\n extensionPoints: [Platform_ExtensionPointDef!]\n requiredStores: [String!]\n requiredStoreDeclarations: [Platform_RequiredStoreDeclaration!]\n requiredCapabilities: [Platform_RequiredCapabilityDeclaration!]\n traitDeclarations: [Platform_TraitDeclaration!]\n admission: [Platform_AdmissionDef!]\n admissionDoors: [Platform_AdmissionDoorDef!]\n}`
15
17
  ];
16
18
 
17
19
  function encodeTraitDeclaration(d) {
@@ -35,6 +37,36 @@ function encodeTraitDeclaration(d) {
35
37
  ]);
36
38
  }
37
39
 
40
+ function encodeAdmissionDef(d) {
41
+ return Object.fromEntries([
42
+ [
43
+ "role",
44
+ d.role
45
+ ],
46
+ [
47
+ "strategy",
48
+ d.strategy
49
+ ],
50
+ [
51
+ "invitedBy",
52
+ Stdlib_Option.mapOr(d.invitedBy, null, Platform_ComponentDefinitionsApi$ReventlessCore.encodeStrings)
53
+ ]
54
+ ]);
55
+ }
56
+
57
+ function encodeAdmissionDoorDef(d) {
58
+ return Object.fromEntries([
59
+ [
60
+ "component",
61
+ d.component
62
+ ],
63
+ [
64
+ "part",
65
+ d.part
66
+ ]
67
+ ]);
68
+ }
69
+
38
70
  function encodeExtensionPointDef(e) {
39
71
  return Object.fromEntries([
40
72
  [
@@ -173,6 +205,14 @@ function encodePluginStructureEntry(pluginId, def) {
173
205
  [
174
206
  "traitDeclarations",
175
207
  Stdlib_Option.mapOr(def.traitDeclarations, null, ds => ds.map(encodeTraitDeclaration))
208
+ ],
209
+ [
210
+ "admission",
211
+ Stdlib_Option.mapOr(def.admission, null, ds => ds.map(encodeAdmissionDef))
212
+ ],
213
+ [
214
+ "admissionDoors",
215
+ Stdlib_Option.mapOr(def.admissionDoors, null, ds => ds.map(encodeAdmissionDoorDef))
176
216
  ]
177
217
  ]);
178
218
  }
@@ -183,6 +223,8 @@ export {
183
223
  sdlTypes,
184
224
  sdlQueryField,
185
225
  encodeTraitDeclaration,
226
+ encodeAdmissionDef,
227
+ encodeAdmissionDoorDef,
186
228
  encodeExtensionPointDef,
187
229
  encodeRequiredStoreDeclaration,
188
230
  encodeRequiredCapabilityDeclaration,
@@ -0,0 +1,54 @@
1
+ // What the host shell needs to let a visitor create an account, read off the
2
+ // plugin structures rather than written by hand: the mutation that starts a
3
+ // registration, the one that completes it, and the groups a visitor may sign up
4
+ // for. Absent when no plugin marks both doors, so a deployment without
5
+ // self-registration writes the same `config.json` it always did.
6
+
7
+ let configKey = "selfRegistration"
8
+
9
+ type config = {
10
+ start: string,
11
+ complete: string,
12
+ /** The groups of the roles declared self-service, as the deployment maps them. */
13
+ roles: array<string>,
14
+ }
15
+
16
+ let doorField = (
17
+ structures: array<(string, Reventless.Plugin.pluginStructure)>,
18
+ part: Reventless.Admission.door,
19
+ ): option<string> =>
20
+ structures->Array.findMap(((plugin, s)) =>
21
+ s.admissionDoors
22
+ ->Option.getOr([])
23
+ ->Array.find(d => d.part == Reventless.Admission.doorName(part))
24
+ ->Option.map(d => Api_Naming.sliceMutationField(~plugin, ~slice=d.component))
25
+ )
26
+
27
+ let selfServiceGroups = (structures: array<(string, Reventless.Plugin.pluginStructure)>) =>
28
+ structures->Array.flatMap(((_, s)) =>
29
+ switch s.admission->Option.map(Reventless.Admission.fromDefs) {
30
+ | Some(Ok(table)) => table->Reventless.Admission.selfService->Array.map(Reventless.Role.groupOf)
31
+ | Some(Error(_)) | None => []
32
+ }
33
+ )
34
+
35
+ /** The configuration, where a deployment has a door that starts and one that
36
+ completes a registration. */
37
+ let fromStructures = (structures: array<(string, Reventless.Plugin.pluginStructure)>): option<
38
+ config,
39
+ > =>
40
+ switch (doorField(structures, Start), doorField(structures, Complete)) {
41
+ | (Some(start), Some(complete)) => Some({start, complete, roles: selfServiceGroups(structures)})
42
+ | _ => None
43
+ }
44
+
45
+ let toJson = (c: config): JSON.t =>
46
+ JSON.Encode.object(
47
+ Dict.fromArray([
48
+ ("start", JSON.Encode.string(c.start)),
49
+ ("complete", JSON.Encode.string(c.complete)),
50
+ ("roles", c.roles->Array.map(JSON.Encode.string)->JSON.Encode.array),
51
+ ]),
52
+ )
53
+
54
+ let configEntry = (c: config): (string, JSON.t) => (configKey, toJson(c))
@@ -0,0 +1,77 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
4
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
5
+ import * as Role$Reventless from "@reventlessdev/reventless-spec/src/types/Role.res.mjs";
6
+ import * as Admission$Reventless from "@reventlessdev/reventless-spec/src/types/Admission.res.mjs";
7
+ import * as Api_Naming$ReventlessCore from "../components/Api/Api_Naming.res.mjs";
8
+
9
+ let configKey = "selfRegistration";
10
+
11
+ function doorField(structures, part) {
12
+ return Stdlib_Array.findMap(structures, param => {
13
+ let plugin = param[0];
14
+ return Stdlib_Option.map(Stdlib_Option.getOr(param[1].admissionDoors, []).find(d => d.part === Admission$Reventless.doorName(part)), d => Api_Naming$ReventlessCore.sliceMutationField(plugin, d.component));
15
+ });
16
+ }
17
+
18
+ function selfServiceGroups(structures) {
19
+ return structures.flatMap(param => {
20
+ let match = Stdlib_Option.map(param[1].admission, Admission$Reventless.fromDefs);
21
+ if (match !== undefined) {
22
+ if (match.TAG === "Ok") {
23
+ return Admission$Reventless.selfService(match._0).map(Role$Reventless.groupOf);
24
+ } else {
25
+ return [];
26
+ }
27
+ } else {
28
+ return [];
29
+ }
30
+ });
31
+ }
32
+
33
+ function fromStructures(structures) {
34
+ let match = doorField(structures, "Start");
35
+ let match$1 = doorField(structures, "Complete");
36
+ if (match !== undefined && match$1 !== undefined) {
37
+ return {
38
+ start: match,
39
+ complete: match$1,
40
+ roles: selfServiceGroups(structures)
41
+ };
42
+ }
43
+ }
44
+
45
+ function toJson(c) {
46
+ return Object.fromEntries([
47
+ [
48
+ "start",
49
+ c.start
50
+ ],
51
+ [
52
+ "complete",
53
+ c.complete
54
+ ],
55
+ [
56
+ "roles",
57
+ c.roles.map(prim => prim)
58
+ ]
59
+ ]);
60
+ }
61
+
62
+ function configEntry(c) {
63
+ return [
64
+ configKey,
65
+ toJson(c)
66
+ ];
67
+ }
68
+
69
+ export {
70
+ configKey,
71
+ doorField,
72
+ selfServiceGroups,
73
+ fromStructures,
74
+ toJson,
75
+ configEntry,
76
+ }
77
+ /* Role-Reventless Not a pure module */
@@ -59,9 +59,9 @@ let inspectMutationFields = (~fieldPrefix: string, commandSchema: S.t<'a>): arra
59
59
  }
60
60
 
61
61
  type queryFieldInspection = {
62
- typeDef: option<string>,
62
+ typeDef?: string,
63
63
  singleQuery: string,
64
- listQuery: option<string>,
64
+ listQuery?: string,
65
65
  }
66
66
 
67
67
  let inspectQueryFields = (
@@ -83,7 +83,7 @@ let inspectQueryFields = (
83
83
  ~pluralTypeName=pluralName,
84
84
  ),
85
85
  )
86
- {typeDef, singleQuery, listQuery}
86
+ {?typeDef, singleQuery, ?listQuery}
87
87
  }
88
88
 
89
89
  // ── Plugin Level — Fragment Inspector ───────────────────────────────────────
@@ -312,7 +312,7 @@ and withSemantic = (fieldSchema: JSON.t, sem: Reventless.Semantic.t): JSON.t =>
312
312
  obj->Dict.set("x-reventless-semantic-source", str("type"))
313
313
  switch sem.payload {
314
314
  | Plain => ()
315
- | ReferenceTo({entity, plugin, ?identity}) =>
315
+ | ReferenceTo({entity, ?plugin, ?identity}) =>
316
316
  let pairs = withOptionalPlugin([("entity", str(entity))], plugin)
317
317
  let pairs = switch identity {
318
318
  | Some(key) => Array.concat(pairs, [("identity", str(key))])
@@ -321,14 +321,14 @@ and withSemantic = (fieldSchema: JSON.t, sem: Reventless.Semantic.t): JSON.t =>
321
321
  obj->Dict.set("x-reventless-semantic-target", jsonObject(pairs))
322
322
  | IdentityOf({key}) =>
323
323
  obj->Dict.set("x-reventless-semantic-target", jsonObject([("key", str(key))]))
324
- | StoredIn({plugin, store}) =>
324
+ | StoredIn({?plugin, store}) =>
325
325
  // An absent plugin means "this plugin's own store" — omit the key rather
326
326
  // than writing an empty string, so a reader never has to tell those apart.
327
327
  obj->Dict.set(
328
328
  "x-reventless-semantic-target",
329
329
  jsonObject(withOptionalPlugin([("store", str(store))], plugin)),
330
330
  )
331
- | MemberOf({plugin, view, field, content}) =>
331
+ | MemberOf({?plugin, ?view, field, ?content}) =>
332
332
  // Same channel as the two above, and `view` and `content` are omitted on
333
333
  // the same terms as `plugin`: absent means the collection is on the row
334
334
  // this field is already part of, and that the member's kind is the
@@ -47,17 +47,17 @@ let mergedEventSchema = (schemas: array<S.t<unknown>>) =>
47
47
  }
48
48
 
49
49
  type dcbResult = {
50
- dcbEventLogOutputs: option<DcbEventLog.outputs>,
50
+ dcbEventLogOutputs?: DcbEventLog.outputs,
51
51
  stateChangeSlicesOutputs: dict<StateChangeSlice.outputs>,
52
52
  stateViewSlicesOutputs: dict<StateViewSlice.outputs>,
53
53
  automationSlicesOutputs: dict<AutomationSlice.outputs>,
54
54
  outboundTranslationSlicesOutputs: dict<OutboundTranslationSlice.outputs>,
55
55
  inboundTranslationSlicesOutputs: dict<InboundTranslationSlice.outputs>,
56
- dcbRuntimeSetup: option<unit => unit>,
56
+ dcbRuntimeSetup?: unit => unit,
57
57
  // Shared publishJsons for all DCB StateChangeSlices in this plugin (same command topic).
58
58
  // Used by Plugin_Builder to register slice names in publishToAggregates so extensions
59
59
  // can dispatch commands to DCB slices via the same mechanism as regular aggregates.
60
- dcbPublishJsons: option<Pulumi.Output.t<CommandTopic.publishJsons>>,
60
+ dcbPublishJsons?: Pulumi.Output.t<CommandTopic.publishJsons>,
61
61
  // SQS URL of the DCB command topic — shared by all StateChangeSlices in this
62
62
  // plugin. Surfaced so the bundled Plugin EventCollector Lambda can dispatch
63
63
  // PublishStateChangeSliceCommand actions from user extensions to the right
@@ -75,14 +75,11 @@ type dcbResult = {
75
75
  }
76
76
 
77
77
  let emptyResult: dcbResult = {
78
- dcbEventLogOutputs: None,
79
78
  stateChangeSlicesOutputs: Dict.make(),
80
79
  stateViewSlicesOutputs: Dict.make(),
81
80
  automationSlicesOutputs: Dict.make(),
82
81
  outboundTranslationSlicesOutputs: Dict.make(),
83
82
  inboundTranslationSlicesOutputs: Dict.make(),
84
- dcbRuntimeSetup: None,
85
- dcbPublishJsons: None,
86
83
  dcbCommandTopicQueueUrl: Pulumi.Output.make(""),
87
84
  mutationEntries: [],
88
85
  queryEntries: [],
@@ -1267,7 +1264,7 @@ module Make = (
1267
1264
  }
1268
1265
  })
1269
1266
  {
1270
- dcbEventLogOutputs: Some(dcbEventLog->Component.outputs),
1267
+ dcbEventLogOutputs: dcbEventLog->Component.outputs,
1271
1268
  stateChangeSlicesOutputs: Dict.fromArray(
1272
1269
  Array.concat(
1273
1270
  stateChangeSlicesOutputs->Dict.toArray,
@@ -1278,8 +1275,8 @@ module Make = (
1278
1275
  automationSlicesOutputs,
1279
1276
  outboundTranslationSlicesOutputs,
1280
1277
  inboundTranslationSlicesOutputs,
1281
- dcbRuntimeSetup: Some(dcbRuntimeSetup),
1282
- dcbPublishJsons: Some(publishJsons),
1278
+ dcbRuntimeSetup,
1279
+ dcbPublishJsons: publishJsons,
1283
1280
  dcbCommandTopicQueueUrl,
1284
1281
  mutationEntries: Array.concat(mutationEntriesFromSlices, mutationEntriesFromInboundSlices),
1285
1282
  queryEntries: stateViewEntries
@@ -107,14 +107,11 @@ let emptyResult_queryEntries = [];
107
107
  let emptyResult_eventLogEntries = [];
108
108
 
109
109
  let emptyResult = {
110
- dcbEventLogOutputs: undefined,
111
110
  stateChangeSlicesOutputs: emptyResult_stateChangeSlicesOutputs,
112
111
  stateViewSlicesOutputs: emptyResult_stateViewSlicesOutputs,
113
112
  automationSlicesOutputs: emptyResult_automationSlicesOutputs,
114
113
  outboundTranslationSlicesOutputs: emptyResult_outboundTranslationSlicesOutputs,
115
114
  inboundTranslationSlicesOutputs: emptyResult_inboundTranslationSlicesOutputs,
116
- dcbRuntimeSetup: undefined,
117
- dcbPublishJsons: undefined,
118
115
  dcbCommandTopicQueueUrl: emptyResult_dcbCommandTopicQueueUrl,
119
116
  mutationEntries: emptyResult_mutationEntries,
120
117
  queryEntries: emptyResult_queryEntries,
@@ -13,6 +13,13 @@ module Make = (
13
13
  let api: unit => QueryDbStorage.api
14
14
  let apiRole: unit => QueryDbStorage.role
15
15
  },
16
+ // What the platform provisioned, for `translate` to reach — the outbound
17
+ // builder's parameter, for the same reason: a platform that omits it does not
18
+ // compile. Read per request, so a provider registered after this functor is
19
+ // applied is still the one a request meets.
20
+ Capabilities: {
21
+ let capabilities: unit => Reventless.Capabilities.t
22
+ },
16
23
  ) => {
17
24
  module Make = (
18
25
  Spec: Reventless.InboundTranslationSlice.Spec,
@@ -82,7 +89,13 @@ module Make = (
82
89
  ->Pulumi.Output.apply(((queryDbOps, publishJsonsFn)) => {
83
90
  let ops: InboundTranslationSlice.operations = {
84
91
  receive: async (inputJson, ~caller=?, ~door=?) => {
85
- let result = await Callback.receive(publishJsonsFn, inputJson, ~caller?, ~door?)
92
+ let result = await Callback.receive(
93
+ publishJsonsFn,
94
+ inputJson,
95
+ ~capabilities=Capabilities.capabilities(),
96
+ ~caller?,
97
+ ~door?,
98
+ )
86
99
  await syncToQueryDb(queryDbOps, result->InboundTranslationSlice_Callback.requestIdOf)
87
100
  result
88
101
  },
@@ -11,7 +11,7 @@ import * as InboundTranslationSlice$ReventlessCore from "./InboundTranslationSli
11
11
  import * as InboundTranslationSlice_Callback$ReventlessCore from "./InboundTranslationSlice_Callback.res.mjs";
12
12
 
13
13
  function Make(QueryDbStorage) {
14
- return QueryDbResolvers => (Api => {
14
+ return QueryDbResolvers => (Api => (Capabilities => {
15
15
  let Make = Spec => (Translation => {
16
16
  let Callback = InboundTranslationSlice_Callback$ReventlessCore.Make(Spec)(Translation);
17
17
  let queryDbName = Spec.name + "Audit";
@@ -58,7 +58,7 @@ function Make(QueryDbStorage) {
58
58
  let queryDbOps = param[0];
59
59
  return {
60
60
  receive: async (inputJson, caller, door) => {
61
- let result = await Callback.receive(publishJsonsFn, inputJson, caller, door);
61
+ let result = await Callback.receive(publishJsonsFn, inputJson, Capabilities.capabilities(), caller, door);
62
62
  await syncToQueryDb(queryDbOps, InboundTranslationSlice_Callback$ReventlessCore.requestIdOf(result));
63
63
  return result;
64
64
  },
@@ -87,7 +87,7 @@ function Make(QueryDbStorage) {
87
87
  return {
88
88
  Make: Make
89
89
  };
90
- });
90
+ }));
91
91
  }
92
92
 
93
93
  export {
@@ -17,6 +17,10 @@ type auditRow = {
17
17
  receivedAt: string,
18
18
  /** Absent on rows written before the slice had a second door. */
19
19
  door?: ReventlessInfra.InboundTranslationSlice.door,
20
+ /** Who called the door: their `userId`, `anonymous` for a caller who is not
21
+ signed in. Absent where the platform acted for itself, and on rows written
22
+ before doors were handed their caller. */
23
+ caller?: string,
20
24
  }
21
25
 
22
26
  /** A refused caller is access, a failed publish the platform; anything else is
@@ -104,6 +108,44 @@ let checkReachable = (~plugin: string, ~slice: string, ~mutation: bool, ~webhook
104
108
  )
105
109
  }
106
110
 
111
+ /** What an audit row holds in place of a sensitive value. */
112
+ let withheld = JSON.String("[withheld]")
113
+
114
+ /**
115
+ The input as an audit row may hold it: every field `externalInput` marks
116
+ `@sensitive` replaced by [withheld].
117
+
118
+ The row is stored, and readable by operators, so a password a registration door
119
+ receives would otherwise sit there for as long as the row does. Redacted by the
120
+ field names the schema declares rather than by guessing at values, and on the raw
121
+ JSON rather than the decoded input, so a request that failed to decode is
122
+ redacted all the same.
123
+ */
124
+ let redactInput = (inputJson: JSON.t, ~sensitive: array<string>): JSON.t =>
125
+ switch inputJson {
126
+ | Object(fields) if sensitive != [] =>
127
+ fields
128
+ ->Dict.toArray
129
+ ->Array.map(((name, value)) => (name, sensitive->Array.includes(name) ? withheld : value))
130
+ ->Dict.fromArray
131
+ ->JSON.Object
132
+ | other => other
133
+ }
134
+
135
+ /**
136
+ A raw body as an audit row may hold it. A body that does not parse cannot be
137
+ redacted field by field, so a slice with sensitive fields keeps none of it.
138
+ */
139
+ let redactBody = (body: string, ~sensitive: array<string>): string =>
140
+ switch sensitive {
141
+ | [] => body
142
+ | _ =>
143
+ switch JSON.parseOrThrow(body) {
144
+ | json => json->redactInput(~sensitive)->JSON.stringify
145
+ | exception _ => "[withheld: unreadable, and this input carries sensitive fields]"
146
+ }
147
+ }
148
+
107
149
  module type T = {
108
150
  module Spec: Reventless.InboundTranslationSlice.Spec
109
151
  module Translation: Reventless.InboundTranslationSlice.Translation with module Spec := Spec
@@ -115,6 +157,7 @@ module type T = {
115
157
  let receive: (
116
158
  ReventlessInfra.CommandTopic.publishJsons,
117
159
  JSON.t,
160
+ ~capabilities: Reventless.Capabilities.t,
118
161
  ~caller: Reventless.Identity.t=?,
119
162
  ~door: ReventlessInfra.InboundTranslationSlice.door=?,
120
163
  ) => promise<ReventlessInfra.InboundTranslationSlice.receiveResult>
@@ -139,6 +182,8 @@ module Make = (
139
182
 
140
183
  let auditLog: Dict.t<auditRow> = Dict.make()
141
184
 
185
+ let sensitive = Reventless.Sensitive.fieldNames(Spec.externalInputSchema->S.castToUnknown)
186
+
142
187
  let now = () => Date.make()->Date.toISOString
143
188
 
144
189
  // External input has no upstream meta, so each command starts a correlation
@@ -149,22 +194,23 @@ module Make = (
149
194
  exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr(fallback)
150
195
 
151
196
  // One audit row per request, whatever the outcome.
152
- let failWith = (~requestId, ~input, ~door, ~errorCode=?, error) => {
153
- auditLog->Dict.set(requestId, {input, status: Failure, error, receivedAt: now(), door})
197
+ let failWith = (~requestId, ~input, ~door, ~caller=?, ~errorCode=?, error) => {
198
+ auditLog->Dict.set(requestId, {input, status: Failure, error, receivedAt: now(), door, ?caller})
154
199
  Error({ReventlessInfra.InboundTranslationSlice.requestId, error, ?errorCode})
155
200
  }
156
201
 
157
- let succeed = (~requestId, ~inputJson, ~door, targetIds) => {
202
+ let succeed = (~requestId, ~inputJson, ~door, ~caller=?, targetIds) => {
158
203
  let commandCount = targetIds->Array.length
159
204
  auditLog->Dict.set(
160
205
  requestId,
161
206
  {
162
- input: inputJson->JSON.stringify,
207
+ input: inputJson->redactInput(~sensitive)->JSON.stringify,
163
208
  status: Success,
164
209
  targetIds,
165
210
  commandCount,
166
211
  receivedAt: now(),
167
212
  door,
213
+ ?caller,
168
214
  },
169
215
  )
170
216
  Ok({ReventlessInfra.InboundTranslationSlice.requestId, targetIds, commandCount})
@@ -191,13 +237,22 @@ module Make = (
191
237
  let receive = async (
192
238
  publishJsons: ReventlessInfra.CommandTopic.publishJsons,
193
239
  inputJson: JSON.t,
240
+ ~capabilities: Reventless.Capabilities.t,
194
241
  ~caller: option<Reventless.Identity.t>=?,
195
242
  ~door: ReventlessInfra.InboundTranslationSlice.door=Mutation,
196
243
  ): ReventlessInfra.InboundTranslationSlice.receiveResult => {
197
244
  let requestId = Uuid.v4()
245
+ let callerId = caller->Option.map(identity => identity.userId)
198
246
  let fail = (~errorCode=?, error) =>
199
- failWith(~requestId, ~input=inputJson->JSON.stringify, ~door, ~errorCode?, error)
200
- let succeed = succeed(~requestId, ~inputJson, ~door, ...)
247
+ failWith(
248
+ ~requestId,
249
+ ~input=inputJson->redactInput(~sensitive)->JSON.stringify,
250
+ ~door,
251
+ ~caller=?callerId,
252
+ ~errorCode?,
253
+ error,
254
+ )
255
+ let succeed = succeed(~requestId, ~inputJson, ~door, ~caller=?callerId, ...)
201
256
  let parsed = try Ok(inputJson->S.parseOrThrow(~to=Spec.externalInputSchema)) catch {
202
257
  | exn => Error(messageOf(exn, "invalid input"))
203
258
  }
@@ -205,7 +260,11 @@ module Make = (
205
260
  switch parsed {
206
261
  | Error(msg) => fail(msg)
207
262
  | Ok(input) =>
208
- switch Translation.translate(input) {
263
+ // A throw is the translation failing, not the platform: it is the input's
264
+ // answer, recorded like any other refusal.
265
+ switch try await Translation.translate(input, ~capabilities, ~caller) catch {
266
+ | exn => Error(messageOf(exn, "translate failed"))
267
+ } {
209
268
  | Error(msg) => fail(msg)
210
269
  | Ok(pairs) =>
211
270
  switch pairs->Array.reduce(Ok([]), (acc, pair) =>
@@ -250,7 +309,13 @@ module Make = (
250
309
  }
251
310
 
252
311
  let refuse = (~body, ~errorCode, error) =>
253
- failWith(~requestId=Uuid.v4(), ~input=body, ~door=Webhook, ~errorCode, error)
312
+ failWith(
313
+ ~requestId=Uuid.v4(),
314
+ ~input=body->redactBody(~sensitive),
315
+ ~door=Webhook,
316
+ ~errorCode,
317
+ error,
318
+ )
254
319
 
255
320
  let webhook =
256
321
  Spec.endpoint->Option.map(endpoint =>