@reventlessdev/reventless-core 3.0.0-alpha.334 → 3.0.0-alpha.336

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/admin/Platform_I18n.res +112 -0
  6. package/src/admin/Platform_I18n.res.mjs +115 -0
  7. package/src/components/Aggregate/Aggregate_Callback.res +3 -0
  8. package/src/components/Aggregate/Aggregate_Callback.res.mjs +3 -3
  9. package/src/components/AutomationSlice/AutomationSlice.res +3 -0
  10. package/src/components/AutomationSlice/AutomationSlice_Builder.res +24 -8
  11. package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +109 -102
  12. package/src/components/AutomationSlice/AutomationSlice_Callback.res +75 -8
  13. package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +58 -7
  14. package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +1 -1
  15. package/src/components/CommandTopic/CommandTopic.res.mjs +9 -0
  16. package/src/components/CommandTopic/CommandTopic_Helpers.res +118 -33
  17. package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +137 -22
  18. package/src/components/Dcb/Dcb_Builder.res +16 -0
  19. package/src/components/Dcb/Dcb_Builder.res.mjs +6 -3
  20. package/src/components/InboundTranslationSlice/InboundTranslationSlice.res +3 -0
  21. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res +17 -6
  22. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res.mjs +46 -41
  23. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res +37 -8
  24. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +33 -13
  25. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res +3 -0
  26. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res.mjs +14 -2
  27. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice.res +3 -0
  28. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res +30 -9
  29. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +10 -5
  30. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +40 -2
  31. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +57 -11
  32. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +4 -0
  33. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +4 -4
  34. package/tests/commandtopic/CommandOutcomeLineTest.res.mjs +3 -3
  35. package/tests/commandtopic/CommandTopicHelpersRejectionTest.res +102 -0
  36. package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +101 -3
  37. package/tests/plugin/PluginStructureAccessTest.res +6 -1
  38. package/tests/plugin/PluginStructureAccessTest.res.mjs +1 -1
@@ -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);
@@ -98,6 +98,7 @@ type phase1<'event> = (
98
98
  type phase2 = (
99
99
  ReventlessInfra.CommandTopic.publishJsons,
100
100
  ~capabilities: Reventless.Capabilities.t,
101
+ ~publishJsonsAndWait: CommandTopic_Helpers.publishJsonsAndWait=?,
101
102
  ) => promise<unit>
102
103
 
103
104
  /** The whole protocol as a value — what a driver holding a built callback needs,
@@ -176,6 +177,20 @@ module Make = (
176
177
  }
177
178
  }
178
179
 
180
+ /** The row after the target refused the command `translate` produced. Only an
181
+ infrastructure failure is retried: a retry runs `translate` again, and the
182
+ outside service has already acted once. A business or permission refusal
183
+ ends the row, with the target's reason. */
184
+ let afterRefusal = (
185
+ row: todoRow,
186
+ ~cause: CommandTopic_Helpers.refusalCause,
187
+ ~lastError: string,
188
+ ): todoRow =>
189
+ switch cause {
190
+ | InfrastructureFailure => row->afterFailedAttempt(~lastError)
191
+ | DomainRejection | AccessRefusal => {...row->afterFailedAttempt(~lastError), status: Abandoned}
192
+ }
193
+
179
194
  /** Ask the slice whether abandonment is worth telling the domain about, and
180
195
  publish what it says. Failing to publish here cannot mark the row for retry
181
196
  — the budget is what ran out — so the loss is logged and the row stays
@@ -301,11 +316,16 @@ module Make = (
301
316
  let phase2 = async (
302
317
  publishJsons: ReventlessInfra.CommandTopic.publishJsons,
303
318
  ~capabilities: Reventless.Capabilities.t,
319
+ ~publishJsonsAndWait: option<CommandTopic_Helpers.publishJsonsAndWait>=?,
304
320
  ) => {
305
321
  let publishJsons = CommandSent.announcing(
306
322
  ~comp=`OutboundTranslationSlice(${Spec.name})`,
307
323
  publishJsons,
308
324
  )
325
+ let publishJsonsAndWait =
326
+ publishJsonsAndWait->Option.map(wait =>
327
+ CommandSent.announcingAndWaiting(~comp=`OutboundTranslationSlice(${Spec.name})`, wait)
328
+ )
309
329
  // Ids that ran out of budget during this pass, announced once at the end so
310
330
  // one item's abandonment cannot interleave with another's attempt.
311
331
  let newlyAbandoned: array<string> = []
@@ -423,8 +443,26 @@ module Make = (
423
443
  meta: makeMeta(row),
424
444
  commandJson,
425
445
  }
426
- await publishJsons([msg])
427
- todoItems->Dict.set(id, {...row, status: Completed, completedAt: now()})
446
+ let refusal = switch publishJsonsAndWait {
447
+ | Some(wait) =>
448
+ switch (await wait([msg]))->Array.get(0) {
449
+ | Some(Rejected({errorCode, errorDetail, cause})) =>
450
+ Some((cause, CommandTopic_Helpers.describeRefusal(~errorCode, ~errorDetail)))
451
+ | Some(Accepted(_) | Pending(_)) | None => None
452
+ }
453
+ | None =>
454
+ await publishJsons([msg])
455
+ None
456
+ }
457
+ switch refusal {
458
+ | Some((cause, lastError)) =>
459
+ let updated = row->afterRefusal(~cause, ~lastError)
460
+ todoItems->Dict.set(id, updated)
461
+ if updated.status == Abandoned {
462
+ newlyAbandoned->Array.push(id)
463
+ }
464
+ | None => todoItems->Dict.set(id, {...row, status: Completed, completedAt: now()})
465
+ }
428
466
  } catch {
429
467
  | exn =>
430
468
  let errMsg =