@reventlessdev/reventless-core 3.0.0-alpha.333 → 3.0.0-alpha.335

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 (38) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/package.json +6 -6
  3. package/src/CommandSent.res +10 -0
  4. package/src/CommandSent.res.mjs +8 -0
  5. package/src/components/Aggregate/Aggregate_Callback.res +3 -0
  6. package/src/components/Aggregate/Aggregate_Callback.res.mjs +3 -3
  7. package/src/components/AutomationSlice/AutomationSlice.res +3 -0
  8. package/src/components/AutomationSlice/AutomationSlice_Builder.res +24 -8
  9. package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +109 -102
  10. package/src/components/AutomationSlice/AutomationSlice_Callback.res +75 -8
  11. package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +58 -7
  12. package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +1 -1
  13. package/src/components/CommandTopic/CommandTopic.res.mjs +9 -0
  14. package/src/components/CommandTopic/CommandTopic_Helpers.res +118 -33
  15. package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +137 -22
  16. package/src/components/Dcb/Dcb_Builder.res +16 -0
  17. package/src/components/Dcb/Dcb_Builder.res.mjs +6 -3
  18. package/src/components/InboundTranslationSlice/InboundTranslationSlice.res +3 -0
  19. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res +17 -6
  20. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res.mjs +46 -41
  21. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res +37 -8
  22. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +33 -13
  23. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res +3 -0
  24. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res.mjs +14 -2
  25. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice.res +3 -0
  26. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res +30 -9
  27. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +10 -5
  28. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +40 -2
  29. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +57 -11
  30. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +20 -2
  31. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +12 -6
  32. package/tests/commandtopic/CommandOutcomeLineTest.res.mjs +3 -3
  33. package/tests/commandtopic/CommandTopicHelpersRejectionTest.res +102 -0
  34. package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +101 -3
  35. package/tests/dcb/DcbReadsNothingTest.res +111 -0
  36. package/tests/dcb/DcbReadsNothingTest.res.mjs +234 -0
  37. package/tests/plugin/PluginStructureAccessTest.res +6 -1
  38. package/tests/plugin/PluginStructureAccessTest.res.mjs +1 -1
@@ -467,6 +467,11 @@ module Make = (
467
467
  dcbCommandTopic
468
468
  ->Component.operations
469
469
  ->Pulumi.Output.apply(ops => ops.publishJsons)
470
+ // Lets an automation or a translation hear a sync slice's refusal.
471
+ let publishJsonsAndWait =
472
+ dcbCommandTopic
473
+ ->Component.operations
474
+ ->Pulumi.Output.apply(ops => ops.publishJsonsAndWait)
470
475
 
471
476
  // Create FIFO CommandTopic for async StateChangeSlices (only if any are configured)
472
477
  module DcbCommandTopicSpecAsync = {
@@ -713,6 +718,7 @@ module Make = (
713
718
  let as_ = AutoSlice.make(
714
719
  ~allEventTopics,
715
720
  ~publishJsons,
721
+ ~publishJsonsAndWait,
716
722
  ~context,
717
723
  ~runtime=?componentRuntime->Dict.get(AutoSlice.Spec.name),
718
724
  ~opts,
@@ -733,6 +739,14 @@ module Make = (
733
739
  OTS.Spec.targetName
734
740
  ->Option.flatMap(target => publishToAggregates->Dict.get(target))
735
741
  ->Option.getOr(publishJsons)
742
+ // An aggregate's topic offers no waiting publish here, so only the DCB
743
+ // topic's outcomes are heard.
744
+ let targetPublishJsonsAndWait = switch OTS.Spec.targetName->Option.flatMap(target =>
745
+ publishToAggregates->Dict.get(target)
746
+ ) {
747
+ | Some(_) => Pulumi.Output.make(None)
748
+ | None => publishJsonsAndWait
749
+ }
736
750
 
737
751
  let ots = OTS.make(
738
752
  ~dcbEventLog,
@@ -740,6 +754,7 @@ module Make = (
740
754
  // name an Aggregate source by its Spec.name.
741
755
  ~allEventTopics,
742
756
  ~publishJsons=targetPublishJsons,
757
+ ~publishJsonsAndWait=targetPublishJsonsAndWait,
743
758
  ~runtime=?componentRuntime->Dict.get(OTS.Spec.name),
744
759
  ~opts,
745
760
  )
@@ -752,6 +767,7 @@ module Make = (
752
767
  inboundTranslationSlices->Array.map((module(ITS: InboundTranslationSlice.T)) => {
753
768
  let its = ITS.make(
754
769
  ~publishJsons,
770
+ ~publishJsonsAndWait,
755
771
  ~runtime=?componentRuntime->Dict.get(ITS.Spec.name),
756
772
  ~opts,
757
773
  )
@@ -258,6 +258,7 @@ function Make(DcbEventLogStorage) {
258
258
  }, opts);
259
259
  Stdlib_Option.forEach(HooksConfig.hooks.onDcbCommandTopicCreated, hook => hook(dcbCommandTopic));
260
260
  let publishJsons = Component$ReventlessCore.operations(dcbCommandTopic).apply(ops => ops.publishJsons);
261
+ let publishJsonsAndWait = Component$ReventlessCore.operations(dcbCommandTopic).apply(ops => ops.publishJsonsAndWait);
261
262
  let name$1 = childName + "Async";
262
263
  let commandSchema$1 = Sury.json;
263
264
  let DcbAsyncCommandTopic = CommandTopic_Builder$ReventlessCore.Make({
@@ -387,7 +388,7 @@ function Make(DcbEventLogStorage) {
387
388
  pluginName: name,
388
389
  sliceName: context_sliceName
389
390
  };
390
- let as_ = AutoSlice.make(allEventTopics, publishJsons, context, componentRuntime[AutoSlice.Spec.name], opts);
391
+ let as_ = AutoSlice.make(allEventTopics, publishJsons, publishJsonsAndWait, context, componentRuntime[AutoSlice.Spec.name], opts);
391
392
  return [
392
393
  AutoSlice.Spec.name,
393
394
  Component$ReventlessCore.outputs(as_)
@@ -395,14 +396,16 @@ function Make(DcbEventLogStorage) {
395
396
  }));
396
397
  let outboundTranslationSlicesOutputs = Object.fromEntries(outboundTranslationSlices.map(OTS => {
397
398
  let targetPublishJsons = Stdlib_Option.getOr(Stdlib_Option.flatMap(OTS.Spec.targetName, target => publishToAggregates[target]), publishJsons);
398
- let ots = OTS.make(dcbEventLog, allEventTopics, targetPublishJsons, componentRuntime[OTS.Spec.name], opts);
399
+ let match = Stdlib_Option.flatMap(OTS.Spec.targetName, target => publishToAggregates[target]);
400
+ let targetPublishJsonsAndWait = match !== undefined ? Pulumi.output(undefined) : publishJsonsAndWait;
401
+ let ots = OTS.make(dcbEventLog, allEventTopics, targetPublishJsons, targetPublishJsonsAndWait, componentRuntime[OTS.Spec.name], opts);
399
402
  return [
400
403
  OTS.Spec.name,
401
404
  Component$ReventlessCore.outputs(ots)
402
405
  ];
403
406
  }));
404
407
  let inboundTranslationSliceData = inboundTranslationSlices.map(ITS => {
405
- let its = ITS.make(publishJsons, componentRuntime[ITS.Spec.name], opts);
408
+ let its = ITS.make(publishJsons, publishJsonsAndWait, componentRuntime[ITS.Spec.name], opts);
406
409
  let fieldName = Api_Naming$ReventlessCore.sliceMutationField(name, ITS.Spec.name);
407
410
  let exposed = InboundTranslationSlice_Callback$ReventlessCore.exposesMutation(ITS.Spec.externalInputSchema);
408
411
  InboundTranslationSlice_Callback$ReventlessCore.checkReachable(name, ITS.Spec.name, exposed, Stdlib_Option.isSome(ITS.Spec.endpoint));
@@ -31,6 +31,9 @@ module type T = {
31
31
 
32
32
  let make: (
33
33
  ~publishJsons: Pulumi.Output.t<CommandTopic.publishJsons>,
34
+ /** The target's publish that waits for each command's outcome, where its topic
35
+ offers one; the caller then hears the target's refusal. */
36
+ ~publishJsonsAndWait: Pulumi.Output.t<option<CommandTopic.publishJsonsAndWait>>=?,
34
37
  ~runtime: ReventlessInfra.RuntimeHints.t=?,
35
38
  ~opts: Pulumi.ComponentResource.options=?,
36
39
  ) => component
@@ -67,7 +67,12 @@ module Make = (
67
67
  | None => ()
68
68
  }
69
69
 
70
- let construct = (~publishJsons, self, _name) => {
70
+ let construct = (
71
+ ~publishJsons,
72
+ ~publishJsonsAndWait: Pulumi.Output.t<option<CommandTopic.publishJsonsAndWait>>,
73
+ self,
74
+ _name,
75
+ ) => {
71
76
  let opts = {Pulumi.ComponentResource.parent: self->Component.toPulumiResource}
72
77
 
73
78
  let queryDb = SpecificQueryDb.make(
@@ -84,15 +89,16 @@ module Make = (
84
89
  })
85
90
 
86
91
  self->Component.setOperations(
87
- (queryDb->Component.operations, publishJsons)
88
- ->Pulumi.Output.all2
89
- ->Pulumi.Output.apply(((queryDbOps, publishJsonsFn)) => {
92
+ (queryDb->Component.operations, publishJsons, publishJsonsAndWait)
93
+ ->Pulumi.Output.all3
94
+ ->Pulumi.Output.apply(((queryDbOps, publishJsonsFn, publishJsonsAndWait)) => {
90
95
  let ops: InboundTranslationSlice.operations = {
91
96
  receive: async (inputJson, ~caller=?, ~door=?) => {
92
97
  let result = await Callback.receive(
93
98
  publishJsonsFn,
94
99
  inputJson,
95
100
  ~capabilities=Capabilities.capabilities(),
101
+ ~publishJsonsAndWait?,
96
102
  ~caller?,
97
103
  ~door?,
98
104
  )
@@ -119,11 +125,16 @@ module Make = (
119
125
  // InboundTranslationSlice publishes commands + syncs its QueryDb inline; it
120
126
  // provisions no per-slice runtime environment, so the runtime hint is accepted
121
127
  // (for composition-surface parity) and discarded.
122
- let make = (~publishJsons, ~runtime as _=?, ~opts=?): InboundTranslationSlice.component =>
128
+ let make = (
129
+ ~publishJsons,
130
+ ~publishJsonsAndWait=Pulumi.Output.make(None),
131
+ ~runtime as _=?,
132
+ ~opts=?,
133
+ ): InboundTranslationSlice.component =>
123
134
  Component.make(
124
135
  ~componentType=InboundTranslationSlice.componentType->ComponentType.toString,
125
136
  ~name=Spec.name,
126
- ~construct=construct(~publishJsons, ...),
137
+ ~construct=construct(~publishJsons, ~publishJsonsAndWait, ...),
127
138
  ~opts,
128
139
  )
129
140
  }
@@ -35,48 +35,53 @@ function Make(QueryDbStorage) {
35
35
  return;
36
36
  }
37
37
  };
38
- let make = (publishJsons, param, opts) => Component$ReventlessCore.make(ComponentType$ReventlessCore.toString(InboundTranslationSlice$ReventlessCore.componentType), Spec.name, (extra, extra$1) => {
39
- let opts_parent = Component$ReventlessCore.toPulumiResource(extra);
40
- let opts = {
41
- parent: opts_parent
42
- };
43
- let queryDb = SpecificQueryDb.make(Api.api(), Api.apiRole(), undefined, {
44
- kind: "InboundTranslationSlice",
45
- name: Spec.name
46
- }, opts);
47
- let publishJsonsRef = {
48
- contents: undefined
49
- };
50
- publishJsons.apply(pj => {
51
- publishJsonsRef.contents = pj;
52
- });
53
- Component$ReventlessCore.setOperations(extra, Pulumi.all([
54
- Component$ReventlessCore.operations(queryDb),
55
- publishJsons
56
- ]).apply(param => {
57
- let publishJsonsFn = param[1];
58
- let queryDbOps = param[0];
59
- return {
60
- receive: async (inputJson, caller, door) => {
61
- let result = await Callback.receive(publishJsonsFn, inputJson, Capabilities.capabilities(), caller, door);
62
- await syncToQueryDb(queryDbOps, InboundTranslationSlice_Callback$ReventlessCore.requestIdOf(result));
63
- return result;
64
- },
65
- refuse: async (body, errorCode, error) => {
66
- let result = Callback.refuse(body, errorCode, error);
67
- await syncToQueryDb(queryDbOps, InboundTranslationSlice_Callback$ReventlessCore.requestIdOf(result));
68
- return result;
69
- }
38
+ let make = (publishJsons, publishJsonsAndWaitOpt, param, opts) => {
39
+ let publishJsonsAndWait = publishJsonsAndWaitOpt !== undefined ? publishJsonsAndWaitOpt : Pulumi.output(undefined);
40
+ return Component$ReventlessCore.make(ComponentType$ReventlessCore.toString(InboundTranslationSlice$ReventlessCore.componentType), Spec.name, (extra, extra$1) => {
41
+ let opts_parent = Component$ReventlessCore.toPulumiResource(extra);
42
+ let opts = {
43
+ parent: opts_parent
44
+ };
45
+ let queryDb = SpecificQueryDb.make(Api.api(), Api.apiRole(), undefined, {
46
+ kind: "InboundTranslationSlice",
47
+ name: Spec.name
48
+ }, opts);
49
+ let publishJsonsRef = {
50
+ contents: undefined
51
+ };
52
+ publishJsons.apply(pj => {
53
+ publishJsonsRef.contents = pj;
54
+ });
55
+ Component$ReventlessCore.setOperations(extra, Pulumi.all([
56
+ Component$ReventlessCore.operations(queryDb),
57
+ publishJsons,
58
+ publishJsonsAndWait
59
+ ]).apply(param => {
60
+ let publishJsonsAndWait = param[2];
61
+ let publishJsonsFn = param[1];
62
+ let queryDbOps = param[0];
63
+ return {
64
+ receive: async (inputJson, caller, door) => {
65
+ let result = await Callback.receive(publishJsonsFn, inputJson, Capabilities.capabilities(), publishJsonsAndWait, caller, door);
66
+ await syncToQueryDb(queryDbOps, InboundTranslationSlice_Callback$ReventlessCore.requestIdOf(result));
67
+ return result;
68
+ },
69
+ refuse: async (body, errorCode, error) => {
70
+ let result = Callback.refuse(body, errorCode, error);
71
+ await syncToQueryDb(queryDbOps, InboundTranslationSlice_Callback$ReventlessCore.requestIdOf(result));
72
+ return result;
73
+ }
74
+ };
75
+ }));
76
+ let outputs_resources = [];
77
+ let outputs_queryDb = Component$ReventlessCore.outputs(queryDb);
78
+ let outputs = {
79
+ resources: outputs_resources,
80
+ queryDb: outputs_queryDb
70
81
  };
71
- }));
72
- let outputs_resources = [];
73
- let outputs_queryDb = Component$ReventlessCore.outputs(queryDb);
74
- let outputs = {
75
- resources: outputs_resources,
76
- queryDb: outputs_queryDb
77
- };
78
- return Component$ReventlessCore.setOutputs(extra, outputs);
79
- }, opts);
82
+ return Component$ReventlessCore.setOutputs(extra, outputs);
83
+ }, opts);
84
+ };
80
85
  return {
81
86
  Spec: Spec,
82
87
  Translation: Translation,
@@ -45,13 +45,13 @@ let receiveResultToOutcome = (
45
45
  | Some(entityId) => Accepted({msgId: requestId, entityId, eventCount: commandCount})
46
46
  | None => Accepted({msgId: requestId, eventCount: commandCount})
47
47
  }
48
- | Error({requestId, error, ?errorCode}) =>
48
+ | Error({requestId, error, ?errorCode, ?cause}) =>
49
49
  let errorCode = errorCode->Option.getOr(Reventless.CommandOutcome.code(TranslationFailed))
50
50
  Rejected({
51
51
  msgId: requestId,
52
52
  errorCode,
53
53
  errorDetail: Some(error),
54
- cause: rejectionCauseOf(errorCode),
54
+ cause: cause->Option.getOr(rejectionCauseOf(errorCode)),
55
55
  })
56
56
  }
57
57
 
@@ -153,11 +153,14 @@ module type T = {
153
153
  /** The audit log -- maps request ID to audit row. */
154
154
  let auditLog: Dict.t<auditRow>
155
155
 
156
- /** Receive external input, translate it, and publish commands. */
156
+ /** Receive external input, translate it, and publish commands. With
157
+ `~publishJsonsAndWait`, the caller hears the first command the target
158
+ refused instead of an acceptance. */
157
159
  let receive: (
158
160
  ReventlessInfra.CommandTopic.publishJsons,
159
161
  JSON.t,
160
162
  ~capabilities: Reventless.Capabilities.t,
163
+ ~publishJsonsAndWait: CommandTopic_Helpers.publishJsonsAndWait=?,
161
164
  ~caller: Reventless.Identity.t=?,
162
165
  ~door: ReventlessInfra.InboundTranslationSlice.door=?,
163
166
  ) => promise<ReventlessInfra.InboundTranslationSlice.receiveResult>
@@ -194,9 +197,9 @@ module Make = (
194
197
  exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr(fallback)
195
198
 
196
199
  // One audit row per request, whatever the outcome.
197
- let failWith = (~requestId, ~input, ~door, ~caller=?, ~errorCode=?, error) => {
200
+ let failWith = (~requestId, ~input, ~door, ~caller=?, ~errorCode=?, ~cause=?, error) => {
198
201
  auditLog->Dict.set(requestId, {input, status: Failure, error, receivedAt: now(), door, ?caller})
199
- Error({ReventlessInfra.InboundTranslationSlice.requestId, error, ?errorCode})
202
+ Error({ReventlessInfra.InboundTranslationSlice.requestId, error, ?errorCode, ?cause})
200
203
  }
201
204
 
202
205
  let succeed = (~requestId, ~inputJson, ~door, ~caller=?, targetIds) => {
@@ -238,6 +241,7 @@ module Make = (
238
241
  publishJsons: ReventlessInfra.CommandTopic.publishJsons,
239
242
  inputJson: JSON.t,
240
243
  ~capabilities: Reventless.Capabilities.t,
244
+ ~publishJsonsAndWait: option<CommandTopic_Helpers.publishJsonsAndWait>=?,
241
245
  ~caller: option<Reventless.Identity.t>=?,
242
246
  ~door: ReventlessInfra.InboundTranslationSlice.door=Mutation,
243
247
  ): ReventlessInfra.InboundTranslationSlice.receiveResult => {
@@ -245,15 +249,20 @@ module Make = (
245
249
  ~comp=`InboundTranslationSlice(${Spec.name})`,
246
250
  publishJsons,
247
251
  )
252
+ let publishJsonsAndWait =
253
+ publishJsonsAndWait->Option.map(wait =>
254
+ CommandSent.announcingAndWaiting(~comp=`InboundTranslationSlice(${Spec.name})`, wait)
255
+ )
248
256
  let requestId = Uuid.v4()
249
257
  let callerId = caller->Option.map(identity => identity.userId)
250
- let fail = (~errorCode=?, error) =>
258
+ let fail = (~errorCode=?, ~cause=?, error) =>
251
259
  failWith(
252
260
  ~requestId,
253
261
  ~input=inputJson->redactInput(~sensitive)->JSON.stringify,
254
262
  ~door,
255
263
  ~caller=?callerId,
256
264
  ~errorCode?,
265
+ ~cause?,
257
266
  error,
258
267
  )
259
268
  let succeed = succeed(~requestId, ~inputJson, ~door, ~caller=?callerId, ...)
@@ -298,8 +307,28 @@ module Make = (
298
307
  | Ok([]) => succeed([])
299
308
  | Ok(msgs) =>
300
309
  try {
301
- await publishJsons(msgs)
302
- succeed(pairs->Array.map(((targetId, _)) => targetId))
310
+ let refusal = switch publishJsonsAndWait {
311
+ | Some(wait) =>
312
+ (await wait(msgs))->Array.findMap(outcome =>
313
+ switch outcome {
314
+ | Rejected({errorCode, errorDetail, cause}) =>
315
+ Some((
316
+ errorCode,
317
+ cause,
318
+ CommandTopic_Helpers.describeRefusal(~errorCode, ~errorDetail),
319
+ ))
320
+ | Accepted(_) | Pending(_) => None
321
+ }
322
+ )
323
+ | None =>
324
+ await publishJsons(msgs)
325
+ None
326
+ }
327
+ switch refusal {
328
+ // The first refusal answers; any other is in its own log line.
329
+ | Some((errorCode, cause, error)) => fail(~errorCode, ~cause, error)
330
+ | None => succeed(pairs->Array.map(((targetId, _)) => targetId))
331
+ }
303
332
  } catch {
304
333
  | exn =>
305
334
  fail(
@@ -22,6 +22,7 @@ import * as CommandOutcome$Reventless from "@reventlessdev/reventless-spec/src/c
22
22
  import * as CommandSent$ReventlessCore from "../../CommandSent.res.mjs";
23
23
  import * as EffectLogger$ReventlessCore from "../../util/EffectLogger.res.mjs";
24
24
  import * as ApiNoApiHelpers$ReventlessCore from "../Api/ApiNoApiHelpers.res.mjs";
25
+ import * as CommandTopic_Helpers$ReventlessCore from "../CommandTopic/CommandTopic_Helpers.res.mjs";
25
26
  import * as InboundTranslationSlice$ReventlessInfra from "@reventlessdev/reventless-infra/src/components/InboundTranslationSlice.res.mjs";
26
27
  import * as InboundTranslationSlice_Webhook$ReventlessCore from "./InboundTranslationSlice_Webhook.res.mjs";
27
28
 
@@ -79,7 +80,7 @@ function receiveResultToOutcome(result) {
79
80
  msgId: match$1.requestId,
80
81
  errorCode: errorCode,
81
82
  errorDetail: match$1.error,
82
- cause: rejectionCauseOf(errorCode)
83
+ cause: Stdlib_Option.getOr(match$1.cause, rejectionCauseOf(errorCode))
83
84
  };
84
85
  }
85
86
 
@@ -154,7 +155,7 @@ function Make(Spec) {
154
155
  let sensitive = Sensitive$Reventless.fieldNames(Spec.externalInputSchema);
155
156
  let makeMeta = () => Message$ReventlessCore.generateMeta(Spec.targetName, undefined, undefined, undefined, undefined, undefined, undefined);
156
157
  let messageOf = (exn, fallback) => Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), fallback);
157
- let failWith = (requestId, input, door, caller, errorCode, error) => {
158
+ let failWith = (requestId, input, door, caller, errorCode, cause, error) => {
158
159
  auditLog[requestId] = {
159
160
  input: input,
160
161
  status: "Failure",
@@ -168,7 +169,8 @@ function Make(Spec) {
168
169
  _0: {
169
170
  requestId: requestId,
170
171
  error: error,
171
- errorCode: errorCode
172
+ errorCode: errorCode,
173
+ cause: cause
172
174
  }
173
175
  };
174
176
  };
@@ -191,12 +193,13 @@ function Make(Spec) {
191
193
  };
192
194
  }
193
195
  };
194
- let receive = async (publishJsons, inputJson, capabilities, caller, doorOpt) => {
196
+ let receive = async (publishJsons, inputJson, capabilities, publishJsonsAndWait, caller, doorOpt) => {
195
197
  let door = doorOpt !== undefined ? doorOpt : "Mutation";
196
198
  let publishJsons$1 = CommandSent$ReventlessCore.announcing(`InboundTranslationSlice(` + Spec.name + `)`, publishJsons);
199
+ let publishJsonsAndWait$1 = Stdlib_Option.map(publishJsonsAndWait, wait => CommandSent$ReventlessCore.announcingAndWaiting(`InboundTranslationSlice(` + Spec.name + `)`, wait));
197
200
  let requestId = Uuid.v4();
198
201
  let callerId = Stdlib_Option.map(caller, identity => identity.userId);
199
- let fail = (errorCode, error) => failWith(requestId, JSON.stringify(redactInput(inputJson, sensitive)), door, callerId, errorCode, error);
202
+ let fail = (errorCode, cause, error) => failWith(requestId, JSON.stringify(redactInput(inputJson, sensitive)), door, callerId, errorCode, cause, error);
200
203
  let succeed = extra => {
201
204
  let commandCount = extra.length;
202
205
  auditLog[requestId] = {
@@ -231,7 +234,7 @@ function Make(Spec) {
231
234
  };
232
235
  }
233
236
  if (parsed.TAG !== "Ok") {
234
- return fail(undefined, parsed._0);
237
+ return fail(undefined, undefined, parsed._0);
235
238
  }
236
239
  let msg;
237
240
  try {
@@ -244,7 +247,7 @@ function Make(Spec) {
244
247
  };
245
248
  }
246
249
  if (msg.TAG !== "Ok") {
247
- return fail(undefined, msg._0);
250
+ return fail(undefined, undefined, msg._0);
248
251
  }
249
252
  let pairs = msg._0;
250
253
  let msg$1 = Stdlib_Array.reduce(pairs, {
@@ -269,24 +272,41 @@ function Make(Spec) {
269
272
  }
270
273
  });
271
274
  if (msg$1.TAG !== "Ok") {
272
- return fail(undefined, msg$1._0);
275
+ return fail(undefined, undefined, msg$1._0);
273
276
  }
274
277
  let msgs = msg$1._0;
275
278
  if (msgs.some(param => !callerAdmits(Authorization$Reventless.named(Spec.authorizationOf(Message$Reventless.variantNameOfJson(param.commandJson))), caller))) {
276
- return fail(CommandOutcome$Reventless.code("Forbidden"), Spec.name + `: the caller is not authorized for every command this input translates into`);
279
+ return fail(CommandOutcome$Reventless.code("Forbidden"), undefined, Spec.name + `: the caller is not authorized for every command this input translates into`);
277
280
  }
278
281
  if (msgs.length === 0) {
279
282
  return succeed([]);
280
283
  }
281
284
  try {
282
- await publishJsons$1(msgs);
283
- return succeed(pairs.map(param => param[0]));
285
+ let refusal = publishJsonsAndWait$1 !== undefined ? Stdlib_Array.findMap(await publishJsonsAndWait$1(msgs), outcome => {
286
+ switch (outcome.TAG) {
287
+ case "Rejected" :
288
+ let errorCode = outcome.errorCode;
289
+ return [
290
+ errorCode,
291
+ outcome.cause,
292
+ CommandTopic_Helpers$ReventlessCore.describeRefusal(errorCode, outcome.errorDetail)
293
+ ];
294
+ case "Accepted" :
295
+ case "Pending" :
296
+ return;
297
+ }
298
+ }) : (await publishJsons$1(msgs), undefined);
299
+ if (refusal !== undefined) {
300
+ return fail(refusal[0], refusal[1], refusal[2]);
301
+ } else {
302
+ return succeed(pairs.map(param => param[0]));
303
+ }
284
304
  } catch (raw_exn$2) {
285
305
  let exn$2 = Primitive_exceptions.internalToException(raw_exn$2);
286
- return fail(CommandOutcome$Reventless.code("PublishFailed"), messageOf(exn$2, "publish failed"));
306
+ return fail(CommandOutcome$Reventless.code("PublishFailed"), undefined, messageOf(exn$2, "publish failed"));
287
307
  }
288
308
  };
289
- let refuse = (body, errorCode, error) => failWith(Uuid.v4(), redactBody(body, sensitive), "Webhook", undefined, errorCode, error);
309
+ let refuse = (body, errorCode, error) => failWith(Uuid.v4(), redactBody(body, sensitive), "Webhook", undefined, errorCode, undefined, error);
290
310
  let webhook = Stdlib_Option.map(Spec.endpoint, endpoint => InboundTranslationSlice_Webhook$ReventlessCore.routeOf(Spec.name, endpoint));
291
311
  return {
292
312
  Spec: Spec,
@@ -151,6 +151,9 @@ let statusOf = (result: ReventlessInfra.InboundTranslationSlice.receiveResult):
151
151
  | Error({errorCode: "InvalidBody"}) => 400
152
152
  | Error({errorCode: "Forbidden"}) => 403
153
153
  | Error({errorCode: "PublishFailed"}) => 503
154
+ // The target's own refusal: its platform failing is worth sending again.
155
+ | Error({cause: InfrastructureFailure}) => 503
156
+ | Error({cause: AccessRefusal}) => 403
154
157
  | Error(_) => 422
155
158
  }
156
159
 
@@ -169,7 +169,8 @@ function statusOf(result) {
169
169
  if (result.TAG === "Ok") {
170
170
  return 200;
171
171
  }
172
- switch (result._0.errorCode) {
172
+ let match = result._0;
173
+ switch (match.errorCode) {
173
174
  case "Forbidden" :
174
175
  return 403;
175
176
  case "InvalidBody" :
@@ -179,7 +180,18 @@ function statusOf(result) {
179
180
  case "Unsigned" :
180
181
  return 401;
181
182
  default:
182
- return 422;
183
+ let match$1 = match.cause;
184
+ if (match$1 === undefined) {
185
+ return 422;
186
+ }
187
+ switch (match$1) {
188
+ case "DomainRejection" :
189
+ return 422;
190
+ case "InfrastructureFailure" :
191
+ return 503;
192
+ case "AccessRefusal" :
193
+ return 403;
194
+ }
183
195
  }
184
196
  }
185
197
 
@@ -31,6 +31,9 @@ module type T = {
31
31
  ~dcbEventLog: DcbEventLog.component,
32
32
  ~allEventTopics: EventTopic.allOutputs=?,
33
33
  ~publishJsons: Pulumi.Output.t<CommandTopic.publishJsons>,
34
+ /** The target's publish that waits for each command's outcome, where its topic
35
+ offers one; a refusal is then recorded on the row instead of `Completed`. */
36
+ ~publishJsonsAndWait: Pulumi.Output.t<option<CommandTopic.publishJsonsAndWait>>=?,
34
37
  ~runtime: ReventlessInfra.RuntimeHints.t=?,
35
38
  ~opts: Pulumi.ComponentResource.options=?,
36
39
  ) => component
@@ -81,6 +81,7 @@ module Make = (
81
81
  ~dcbEventLog: DcbEventLog.component,
82
82
  ~allEventTopics: EventTopic.allOutputs,
83
83
  ~publishJsons,
84
+ ~publishJsonsAndWait: Pulumi.Output.t<option<CommandTopic.publishJsonsAndWait>>,
84
85
  ~runtime,
85
86
  self,
86
87
  _name,
@@ -143,9 +144,9 @@ module Make = (
143
144
  // side-effect-only `publishJsons.apply` against the first event arrival
144
145
  // (which silently dropped Phase 2 in the AutomationSlice's previous shape).
145
146
  let eventCollector =
146
- (queryDb->Component.operations, publishJsons)
147
- ->Pulumi.Output.all2
148
- ->Pulumi.Output.apply(((queryDbOps, publishJsonsFn)) => {
147
+ (queryDb->Component.operations, publishJsons, publishJsonsAndWait)
148
+ ->Pulumi.Output.all3
149
+ ->Pulumi.Output.apply(((queryDbOps, publishJsonsFn, publishJsonsAndWait)) => {
149
150
  let ec = SpecificEventCollector.make(
150
151
  ~name=Spec.name,
151
152
  ~eventTopics,
@@ -202,7 +203,11 @@ module Make = (
202
203
  // same topic, awaiting would self-deadlock the bus — same
203
204
  // shape as AutomationSlice. Detach it; errors are logged.
204
205
  let _ =
205
- Callback.phase2(publishJsonsFn, ~capabilities=Capabilities.capabilities())
206
+ Callback.phase2(
207
+ publishJsonsFn,
208
+ ~capabilities=Capabilities.capabilities(),
209
+ ~publishJsonsAndWait?,
210
+ )
206
211
  ->Promise.then(() => syncToQueryDb(queryDbOps))
207
212
  ->Promise.catch(
208
213
  exn => {
@@ -235,13 +240,21 @@ module Make = (
235
240
  })
236
241
 
237
242
  self->Component.setOperations(
238
- (eventCollector->Pulumi.Output.flatMap(ec => ec->Component.operations), publishJsons)
239
- ->Pulumi.Output.all2
240
- ->Pulumi.Output.apply(((ecOps, publishJsonsFn)) => {
243
+ (
244
+ eventCollector->Pulumi.Output.flatMap(ec => ec->Component.operations),
245
+ publishJsons,
246
+ publishJsonsAndWait,
247
+ )
248
+ ->Pulumi.Output.all3
249
+ ->Pulumi.Output.apply(((ecOps, publishJsonsFn, publishJsonsAndWait)) => {
241
250
  let ops: OutboundTranslationSlice.operations = {
242
251
  enqueueEvent: ecOps.enqueueEvent,
243
252
  translatePending: async () =>
244
- await Callback.phase2(publishJsonsFn, ~capabilities=Capabilities.capabilities()),
253
+ await Callback.phase2(
254
+ publishJsonsFn,
255
+ ~capabilities=Capabilities.capabilities(),
256
+ ~publishJsonsAndWait?,
257
+ ),
245
258
  }
246
259
  ops
247
260
  }),
@@ -265,13 +278,21 @@ module Make = (
265
278
  // DCB log, which `construct` adds regardless.
266
279
  ~allEventTopics=Dict.make(),
267
280
  ~publishJsons,
281
+ ~publishJsonsAndWait=Pulumi.Output.make(None),
268
282
  ~runtime=?,
269
283
  ~opts=?,
270
284
  ): OutboundTranslationSlice.component =>
271
285
  Component.make(
272
286
  ~componentType=OutboundTranslationSlice.componentType->ComponentType.toString,
273
287
  ~name=Spec.name,
274
- ~construct=construct(~dcbEventLog, ~allEventTopics, ~publishJsons, ~runtime, ...),
288
+ ~construct=construct(
289
+ ~dcbEventLog,
290
+ ~allEventTopics,
291
+ ~publishJsons,
292
+ ~publishJsonsAndWait,
293
+ ~runtime,
294
+ ...
295
+ ),
275
296
  ~opts,
276
297
  )
277
298
  }
@@ -57,8 +57,9 @@ function Make(RuntimeEnvironment) {
57
57
  await queryDbOps.save(Id$Reventless.$$String.makeFromString(param[0]), param[1], "Overwrite", undefined);
58
58
  });
59
59
  };
60
- let make = (dcbEventLog, allEventTopicsOpt, publishJsons, runtime, opts) => {
60
+ let make = (dcbEventLog, allEventTopicsOpt, publishJsons, publishJsonsAndWaitOpt, runtime, opts) => {
61
61
  let allEventTopics = allEventTopicsOpt !== undefined ? allEventTopicsOpt : ({});
62
+ let publishJsonsAndWait = publishJsonsAndWaitOpt !== undefined ? publishJsonsAndWaitOpt : Pulumi.output(undefined);
62
63
  return Component$ReventlessCore.make(ComponentType$ReventlessCore.toString(OutboundTranslationSlice$ReventlessCore.componentType), Spec.name, (extra, extra$1) => {
63
64
  let opts_parent = Component$ReventlessCore.toPulumiResource(extra);
64
65
  let opts = {
@@ -86,8 +87,10 @@ function Make(RuntimeEnvironment) {
86
87
  let eventTopics = EventTopic$ReventlessCore.filter(availableTopics, Belt_SetString.fromArray(sourceNames));
87
88
  let eventCollector = Pulumi.all([
88
89
  Component$ReventlessCore.operations(queryDb),
89
- publishJsons
90
+ publishJsons,
91
+ publishJsonsAndWait
90
92
  ]).apply(param => {
93
+ let publishJsonsAndWait = param[2];
91
94
  let publishJsonsFn = param[1];
92
95
  let queryDbOps = param[0];
93
96
  let ec = SpecificEventCollector.make(Spec.name, eventTopics, {
@@ -115,7 +118,7 @@ function Make(RuntimeEnvironment) {
115
118
  param[1]
116
119
  ]), eventsArr.map(param => param[2]), Capabilities.capabilities());
117
120
  await syncToQueryDb(queryDbOps);
118
- Stdlib_Promise.$$catch(Callback.phase2(publishJsonsFn, Capabilities.capabilities()).then(() => syncToQueryDb(queryDbOps)), exn => {
121
+ Stdlib_Promise.$$catch(Callback.phase2(publishJsonsFn, Capabilities.capabilities(), publishJsonsAndWait).then(() => syncToQueryDb(queryDbOps)), exn => {
119
122
  let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown");
120
123
  Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, undefined, `detached phase 2 error: ` + errMsg));
121
124
  return Promise.resolve();
@@ -128,12 +131,14 @@ function Make(RuntimeEnvironment) {
128
131
  });
129
132
  Component$ReventlessCore.setOperations(extra, Pulumi.all([
130
133
  Output$Pulumi.flatMap(eventCollector, Component$ReventlessCore.operations),
131
- publishJsons
134
+ publishJsons,
135
+ publishJsonsAndWait
132
136
  ]).apply(param => {
137
+ let publishJsonsAndWait = param[2];
133
138
  let publishJsonsFn = param[1];
134
139
  return {
135
140
  enqueueEvent: param[0].enqueueEvent,
136
- translatePending: async () => await Callback.phase2(publishJsonsFn, Capabilities.capabilities())
141
+ translatePending: async () => await Callback.phase2(publishJsonsFn, Capabilities.capabilities(), publishJsonsAndWait)
137
142
  };
138
143
  }));
139
144
  let aggregatedResources = Object.values(eventTopics).flatMap(t => t.resources);