@plitzi/sdk-authoring 0.35.5 → 0.35.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @plitzi/sdk-authoring
2
2
 
3
+ ## 0.35.6
4
+
5
+ ### Patch Changes
6
+
7
+ - A failed server action can give back what it already did.
8
+
9
+ - **`flow.onFailure` ("On Failure") marks where the undo begins.** A run that reaches it has succeeded and ends there.
10
+ A run whose step failed jumps to it and runs the steps after it, in order, each still asking its own `when` — the
11
+ failure may have come before the thing to undo was ever done — with `{{ failure.step }}` and `{{ failure.message }}`
12
+ in scope. The run still ends failed, with the failure it had; an undo step that fails too is added to it.
13
+ - **The undo runs on its own clock and budget:** 5 seconds (or the run's own timeout if shorter) and its own outbound
14
+ request budget, because the run's may be exactly what ran out, and a caller closing the connection does not stop it.
15
+ A run that hit its deadline is undone too.
16
+ - **`defineAction` writes it from `onFailure: [...]`**, after the answer. `validateActionDocument` refuses an output
17
+ step or a second handler after one, warns about a handler with nothing to undo or nothing that undoes, and reserves
18
+ `failure` as a step id. `FAILURE_HANDLER_TASK` is exported from `@plitzi/sdk-shared/actions`.
19
+
3
20
  ## 0.35.5
4
21
 
5
22
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -145,6 +145,14 @@ export declare interface ActionSpec {
145
145
  /** One way in, or several — a flow reachable both from a page and from a webhook answers each on its own terms. */
146
146
  trigger: ActionTriggerSpec | ActionTriggerSpec[];
147
147
  steps: ActionStepSpec[];
148
+ /**
149
+ * What a failed run gives back: steps that run only when one of `steps` fails, written after the answer behind a
150
+ * `flow.onFailure` step. A run that succeeds never reaches them.
151
+ *
152
+ * Give each a `when` naming the step whose work it undoes — the failure may have come before that step ever ran.
153
+ * What failed is in their scope as `{{ failure.step }}` and `{{ failure.message }}`, and the run still ends failed.
154
+ */
155
+ onFailure?: ActionStepSpec[];
148
156
  /**
149
157
  * What leaves the server, as the output step's template. Defaults to the last step's whole result.
150
158
  *
package/dist/index.js CHANGED
@@ -2278,7 +2278,7 @@ var elementsFromManifest = (manifest) => Object.fromEntries(Object.entries(manif
2278
2278
  })]));
2279
2279
  //#endregion
2280
2280
  //#region ../sdk-elements/dist/Element/helpers/elementConstants.mjs
2281
- var e$12 = {
2281
+ var e$13 = {
2282
2282
  onLoad: {
2283
2283
  action: "onLoad",
2284
2284
  title: "On Load",
@@ -2404,7 +2404,7 @@ var e$12 = {
2404
2404
  * the builders useless for exactly the flows that matter most.
2405
2405
  */
2406
2406
  var on = (trigger, params = {}) => {
2407
- const declared = Object.hasOwn(e$12, trigger) ? e$12[trigger] : void 0;
2407
+ const declared = Object.hasOwn(e$13, trigger) ? e$13[trigger] : void 0;
2408
2408
  return {
2409
2409
  type: "trigger",
2410
2410
  action: trigger,
@@ -2493,7 +2493,7 @@ var toggleElement = (params, target) => ({
2493
2493
  });
2494
2494
  //#endregion
2495
2495
  //#region ../sdk-interactions/dist/sources/ActionsSource/callbacks.mjs
2496
- var e$11 = {
2496
+ var e$12 = {
2497
2497
  runServerAction: {
2498
2498
  source: "actions",
2499
2499
  title: "Run Server Action",
@@ -2555,7 +2555,7 @@ var e$11 = {
2555
2555
  };
2556
2556
  //#endregion
2557
2557
  //#region ../sdk-interactions/dist/sources/AuthSource/callbacks.mjs
2558
- var e$10 = {
2558
+ var e$11 = {
2559
2559
  login: {
2560
2560
  source: "auth",
2561
2561
  title: "Auth Login",
@@ -2625,7 +2625,7 @@ var e$10 = {
2625
2625
  };
2626
2626
  //#endregion
2627
2627
  //#region ../sdk-interactions/dist/sources/HostSource/callbacks.mjs
2628
- var e$9 = { hostAction: {
2628
+ var e$10 = { hostAction: {
2629
2629
  source: "host",
2630
2630
  title: "Host Action",
2631
2631
  strictParams: !0,
@@ -2644,7 +2644,7 @@ var e$9 = { hostAction: {
2644
2644
  } };
2645
2645
  //#endregion
2646
2646
  //#region ../sdk-interactions/dist/sources/NavigationSource/callbacks.mjs
2647
- var e$8 = { navigate: {
2647
+ var e$9 = { navigate: {
2648
2648
  source: "navigation",
2649
2649
  title: "Navigate",
2650
2650
  strictParams: !0,
@@ -2673,7 +2673,7 @@ var e$8 = { navigate: {
2673
2673
  } };
2674
2674
  //#endregion
2675
2675
  //#region ../sdk-interactions/dist/sources/StateSource/callbacks.mjs
2676
- var e$7 = {
2676
+ var e$8 = {
2677
2677
  setState: {
2678
2678
  source: "state",
2679
2679
  title: "Set State",
@@ -2823,10 +2823,10 @@ var e$7 = {
2823
2823
  };
2824
2824
  //#endregion
2825
2825
  //#region ../sdk-shared/dist/helpers/twigWrapper/tokens/tokenPatterns.mjs
2826
- var e$6 = "[a-zA-Z_][a-zA-Z0-9_]*(?:-[a-zA-Z0-9_]+)*";
2827
- var t$11 = `(?:${e$6}|\\d+)`;
2828
- var n$10 = `\\[\\s*(?:\\d+|'[^']*'|"[^"]*"|${e$6}(?:\\.${t$11})*)\\s*\\]`;
2829
- var r$9 = `${`${e$6}(?:${n$10})*(?:\\??\\.${t$11}(?:${n$10})*)*`}(?:\\s*\\?\\?\\s*[^|{}]+?)?(?:\\s*\\|\\s*[a-zA-Z_]+(?:\\([^)]*\\))?)*`;
2826
+ var e$7 = "[a-zA-Z_][a-zA-Z0-9_]*(?:-[a-zA-Z0-9_]+)*";
2827
+ var t$11 = `(?:${e$7}|\\d+)`;
2828
+ var n$10 = `\\[\\s*(?:\\d+|'[^']*'|"[^"]*"|${e$7}(?:\\.${t$11})*)\\s*\\]`;
2829
+ var r$9 = `${`${e$7}(?:${n$10})*(?:\\??\\.${t$11}(?:${n$10})*)*`}(?:\\s*\\?\\?\\s*[^|{}]+?)?(?:\\s*\\|\\s*[a-zA-Z_]+(?:\\([^)]*\\))?)*`;
2830
2830
  var i$8 = `\\{\\{\\s*${r$9}\\s*\\}\\}`;
2831
2831
  var a$6 = `(?:${`\\{\\{\\{\\s*${r$9}\\s*\\}\\}\\}`}|${i$8})`;
2832
2832
  var o$5 = new RegExp(a$6, "g");
@@ -2951,11 +2951,11 @@ var e$1 = { addNotification: {
2951
2951
  */
2952
2952
  var BUILTIN_GLOBAL_CALLBACKS = {
2953
2953
  ...e$1,
2954
- ...e$7,
2955
- ...e$9,
2956
2954
  ...e$8,
2957
2955
  ...e$10,
2958
- ...e$11
2956
+ ...e$9,
2957
+ ...e$11,
2958
+ ...e$12
2959
2959
  };
2960
2960
  /** The built-in globalCallback for an action, or undefined when the action is not a known built-in (a plugin
2961
2961
  * callback whose source/schema is not knowable here). */
@@ -3193,6 +3193,9 @@ var applyUtility = (action, params) => {
3193
3193
  };
3194
3194
  };
3195
3195
  //#endregion
3196
+ //#region ../sdk-shared/dist/actions/failureHandler.mjs
3197
+ var e$6 = "flow.onFailure";
3198
+ //#endregion
3196
3199
  //#region ../sdk-schema/dist/helpers/elementId.mjs
3197
3200
  var e$5 = /^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9_])?$/;
3198
3201
  var t$10 = (t) => e$5.test(t);
@@ -3507,30 +3510,39 @@ var defineAction = (spec) => {
3507
3510
  if (spec.steps.length === 0) throw new Error(`Action "${spec.id}" declares no steps.`);
3508
3511
  const triggerIds = triggers.map((trigger) => trigger.id ?? (triggers.length === 1 ? "start" : trigger.type));
3509
3512
  const last = spec.steps[spec.steps.length - 1];
3513
+ const undo = spec.onFailure ?? [];
3510
3514
  assertUniqueIds([
3511
3515
  ...triggerIds,
3512
3516
  ...spec.steps.map((step) => step.id),
3513
- "answer"
3517
+ "answer",
3518
+ ...undo.length > 0 ? ["onFailure", ...undo.map((step) => step.id)] : []
3514
3519
  ], spec.id);
3520
+ const taskStep = (step) => ({
3521
+ id: step.id,
3522
+ type: "task",
3523
+ action: step.task,
3524
+ params: {
3525
+ ...step.params ?? passthroughParams(triggers, spec.id, step.id),
3526
+ ...step.credential ? { credential: step.credential } : {}
3527
+ },
3528
+ ...step.when ? { when: step.when } : {},
3529
+ ...step.enabled === void 0 ? {} : { enabled: step.enabled }
3530
+ });
3515
3531
  const steps = [
3516
3532
  ...triggers.map((trigger, index) => triggerStep(trigger, triggerIds[index])),
3517
- ...spec.steps.map((step) => ({
3518
- id: step.id,
3519
- type: "task",
3520
- action: step.task,
3521
- params: {
3522
- ...step.params ?? passthroughParams(triggers, spec.id, step.id),
3523
- ...step.credential ? { credential: step.credential } : {}
3524
- },
3525
- ...step.when ? { when: step.when } : {},
3526
- ...step.enabled === void 0 ? {} : { enabled: step.enabled }
3527
- })),
3533
+ ...spec.steps.map(taskStep),
3528
3534
  {
3529
3535
  id: "answer",
3530
3536
  type: "task",
3531
3537
  action: "flow.output",
3532
3538
  params: { values: spec.output ?? `{{ ${last.id} }}` }
3533
- }
3539
+ },
3540
+ ...undo.length > 0 ? [{
3541
+ id: "onFailure",
3542
+ type: "task",
3543
+ action: e$6,
3544
+ params: {}
3545
+ }, ...undo.map(taskStep)] : []
3534
3546
  ];
3535
3547
  return {
3536
3548
  id: spec.id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-authoring",
3
- "version": "0.35.5",
3
+ "version": "0.35.6",
4
4
  "license": "AGPL-3.0",
5
5
  "files": [
6
6
  "dist/index.js",
@@ -44,11 +44,11 @@
44
44
  "devDependencies": {
45
45
  "@microsoft/api-extractor": "^7.59.1",
46
46
  "@plitzi/plitzi-ui": "^1.6.21",
47
- "@plitzi/sdk-elements": "0.35.5",
48
- "@plitzi/sdk-interactions": "0.35.5",
49
- "@plitzi/sdk-schema": "0.35.5",
50
- "@plitzi/sdk-shared": "0.35.5",
51
- "@plitzi/sdk-style": "0.35.5",
47
+ "@plitzi/sdk-elements": "0.35.6",
48
+ "@plitzi/sdk-interactions": "0.35.6",
49
+ "@plitzi/sdk-schema": "0.35.6",
50
+ "@plitzi/sdk-shared": "0.35.6",
51
+ "@plitzi/sdk-style": "0.35.6",
52
52
  "@types/react": "^19.3.0",
53
53
  "eslint": "^9.39.5",
54
54
  "typescript": "^6.0.3",