@plitzi/sdk-interactions 0.37.2 → 0.37.4

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.
@@ -1,9 +1,18 @@
1
1
  import { ElementInteraction } from '@plitzi/sdk-shared';
2
- declare const flowTrigger: (triggerNode: ElementInteraction, nodes?: {}, callbacksAvailables?: {}, flowParams?: Record<string, unknown>, globalParams?: {},
2
+ /**
3
+ * The page's sources, as a step reads them.
4
+ *
5
+ * A function rather than a value because it is called before EVERY step: a step sees what the steps before it wrote,
6
+ * and whatever else changed while the flow waited — a `delay`, a request, a person clicking. Read once when the
7
+ * trigger fired, every step saw the page as it was then: a condition after a `delay` could not tell that the reader
8
+ * had moved on, and a step after `setState` read the value from before it.
9
+ */
10
+ export type ReadGlobals = () => Record<string, unknown>;
11
+ declare const flowTrigger: (triggerNode: ElementInteraction, nodes?: {}, callbacksAvailables?: {}, flowParams?: Record<string, unknown>, readGlobals?: ReadGlobals,
3
12
  /** The id of the element this fired on, carried through purely so the log can name it. */
4
13
  hostElementId?: string, postCallbacksTotal?: never[]) => Promise<void>;
5
14
  export { flowTrigger };
6
15
  declare const InteractionsHelper: {
7
- flowTrigger: (triggerNode: ElementInteraction, nodes?: {}, callbacksAvailables?: {}, flowParams?: Record<string, unknown>, globalParams?: {}, hostElementId?: string, postCallbacksTotal?: never[]) => Promise<void>;
16
+ flowTrigger: (triggerNode: ElementInteraction, nodes?: {}, callbacksAvailables?: {}, flowParams?: Record<string, unknown>, readGlobals?: ReadGlobals, hostElementId?: string, postCallbacksTotal?: never[]) => Promise<void>;
8
17
  };
9
18
  export default InteractionsHelper;
@@ -2,157 +2,153 @@ import e from "./utility/index.mjs";
2
2
  import { get as t, omit as n } from "@plitzi/plitzi-ui/helpers";
3
3
  import { QueryBuilderEvaluator as r } from "@plitzi/plitzi-ui/QueryBuilder";
4
4
  import { pConsole as i } from "@plitzi/sdk-shared/devTools/utils/PlitziConsole";
5
- import { hasTemplateSyntax as a, hasValidToken as o, processTwig as s } from "@plitzi/sdk-shared/helpers/twigWrapper";
6
- import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
5
+ import { MAX_PARAM_PASSES as a, resolveStepParam as o } from "@plitzi/sdk-shared/helpers/twigWrapper";
6
+ import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
7
7
  //#region src/InteractionsHelper.tsx
8
- var d = 5, f = 5, p = (e, t, n, r, c) => {
9
- if (e === "utility" && c === "twigTemplate") return t;
10
- let p = {
8
+ var u = 5, d = (e, t, n, r, s) => {
9
+ if (e === "utility" && s === "twigTemplate") return t;
10
+ let d = {
11
11
  ...n,
12
12
  ...r
13
- }, m = (e, t, n) => {
13
+ }, f = (e, t, n) => {
14
14
  if (typeof e == "string") {
15
- let n = e, r = d;
16
- for (a(n) && !o(n) && (n = s(n, p, !1, !0), r--); typeof n == "string" && o(n) && r > 0;) n = s(n, p, !1, !0), r--;
17
- return typeof n == "string" && o(n) && i.warning("interactions", /* @__PURE__ */ u("span", { children: [
15
+ let { value: n, unresolved: r } = o(e, d);
16
+ return r && i.warning("interactions", /* @__PURE__ */ l("span", { children: [
18
17
  "Twig token resolution exceeded ",
19
- d,
18
+ a,
20
19
  " passes for ",
21
- /* @__PURE__ */ l("b", { children: t }),
20
+ /* @__PURE__ */ c("b", { children: t }),
22
21
  ", leaving unresolved tokens"
23
22
  ] }), {
24
23
  param: t,
25
24
  value: n
26
25
  }), n;
27
26
  }
28
- return n >= f || typeof e != "object" || !e ? e : Array.isArray(e) ? e.map((e) => m(e, t, n + 1)) : Object.fromEntries(Object.entries(e).map(([e, r]) => [e, m(r, t, n + 1)]));
27
+ return n >= u || typeof e != "object" || !e ? e : Array.isArray(e) ? e.map((e) => f(e, t, n + 1)) : Object.fromEntries(Object.entries(e).map(([e, r]) => [e, f(r, t, n + 1)]));
29
28
  };
30
29
  return Object.keys(t).reduce((n, r) => {
31
- let i = e === "trigger" ? t[r] : m(t[r], r, 0);
30
+ let i = e === "trigger" ? t[r] : f(t[r], r, 0);
32
31
  return {
33
32
  ...n,
34
33
  [r]: i
35
34
  };
36
35
  }, {});
37
- }, m = async (n, a = {}, o = {}, s = {}, c = {}) => {
38
- let d = {}, f = [], { id: m, action: h, enabled: g, params: _, elementId: v, type: y, when: b } = n;
39
- if (!h || !g) return {
36
+ }, f = (e) => typeof e != "function" && typeof e != "symbol" && typeof e != "bigint", p = (e) => Object.fromEntries(Object.entries(e).filter((e) => f(e[1]))), m = (e) => typeof e == "object" && !!e && "then" in e && typeof e.then == "function", h = (n, a = {}, o = {}, s = {}, u = {}) => {
37
+ let f = [], { id: h, action: g, enabled: _, params: v, elementId: y, type: b, when: x } = n;
38
+ if (!g || !_) return {
40
39
  status: "disabled",
41
- result: d,
40
+ result: {},
42
41
  postCallbacks: f
43
42
  };
44
- let x = {
43
+ let S = p({
45
44
  ...s,
46
45
  ...o,
47
- [m]: _
48
- };
49
- if (b && !r(b, x)) return {
46
+ [h]: v
47
+ });
48
+ if (x && !r(x, S)) return {
50
49
  status: "skipped",
51
- result: d,
50
+ result: {},
52
51
  postCallbacks: f,
53
- whenParams: x
54
- };
55
- let S = {
56
- ...o,
57
- ...s,
58
- ...p(y, _, o, s, h)
52
+ whenParams: S
59
53
  };
54
+ let C = (e) => (i.danger("interactions", /* @__PURE__ */ l("span", { children: ["Interaction node failed ", /* @__PURE__ */ c("b", { children: g })] }), {
55
+ error: e instanceof Error ? e.message : String(e),
56
+ node: n
57
+ }), {
58
+ status: "failed",
59
+ result: {},
60
+ postCallbacks: f,
61
+ whenParams: S
62
+ }), w;
63
+ switch (b) {
64
+ case "callback":
65
+ case "globalCallback":
66
+ if (!y) return i.warning("interactions", /* @__PURE__ */ l("span", { children: [
67
+ "Step ",
68
+ /* @__PURE__ */ c("b", { children: g }),
69
+ " names no element, so there is nothing to run it on"
70
+ ] }), { node: n }), {
71
+ status: "failed",
72
+ result: {},
73
+ postCallbacks: f,
74
+ whenParams: S
75
+ };
76
+ if (w = t(a, `${y}.${g}`), !w) return i.warning("interactions", /* @__PURE__ */ l("span", { children: [
77
+ "Nothing is registered as ",
78
+ /* @__PURE__ */ c("b", { children: `${y}.${g}` }),
79
+ ", so this step did nothing"
80
+ ] }), {
81
+ node: n,
82
+ available: Object.keys(t(a, y, {}))
83
+ }), {
84
+ status: "failed",
85
+ result: {},
86
+ postCallbacks: f,
87
+ whenParams: S
88
+ };
89
+ break;
90
+ case "utility":
91
+ w = t(e, g, {});
92
+ break;
93
+ default: return {
94
+ status: "success",
95
+ result: {},
96
+ postCallbacks: f,
97
+ whenParams: S
98
+ };
99
+ }
60
100
  try {
61
- switch (y) {
62
- case "callback":
63
- case "globalCallback": {
64
- if (!v) return i.warning("interactions", /* @__PURE__ */ u("span", { children: [
65
- "Step ",
66
- /* @__PURE__ */ l("b", { children: h }),
67
- " names no element, so there is nothing to run it on"
68
- ] }), { node: n }), {
69
- status: "failed",
70
- result: d,
71
- postCallbacks: f,
72
- whenParams: x
73
- };
74
- let e = t(a, `${v}.${h}`);
75
- if (!e) return i.warning("interactions", /* @__PURE__ */ u("span", { children: [
76
- "Nothing is registered as ",
77
- /* @__PURE__ */ l("b", { children: `${v}.${h}` }),
78
- ", so this step did nothing"
79
- ] }), {
80
- node: n,
81
- available: Object.keys(t(a, v, {}))
82
- }), {
83
- status: "failed",
84
- result: d,
85
- postCallbacks: f,
86
- whenParams: x
87
- };
88
- let { callback: r, postCallback: o } = e;
89
- r && (d = await r(S, c)), o && f.push({
90
- id: m,
91
- callback: o,
92
- params: {
93
- ...S,
94
- [m]: d
95
- }
96
- });
97
- break;
101
+ let e = {
102
+ ...o,
103
+ ...s,
104
+ ...d(b, v, o, s, g)
105
+ }, { callback: t, postCallback: n } = w, r = (t) => (n && f.push({
106
+ id: h,
107
+ callback: n,
108
+ params: {
109
+ ...e,
110
+ [h]: t
98
111
  }
99
- case "utility": {
100
- let { callback: n, postCallback: r } = t(e, h, {});
101
- n && (d = await n(S, c)), r && f.push({
102
- id: m,
103
- callback: r,
104
- params: {
105
- ...S,
106
- [m]: d
107
- }
108
- });
109
- break;
110
- }
111
- }
112
- } catch (e) {
113
- return i.danger("interactions", /* @__PURE__ */ u("span", { children: ["Interaction node failed ", /* @__PURE__ */ l("b", { children: h })] }), {
114
- error: e instanceof Error ? e.message : String(e),
115
- node: n
116
112
  }), {
117
- status: "failed",
118
- result: d,
113
+ status: "success",
114
+ result: t,
119
115
  postCallbacks: f,
120
- whenParams: x
121
- };
116
+ whenParams: S
117
+ }), i = t ? t(e, u) : {};
118
+ return m(i) ? Promise.resolve(i).then(r, C) : r(i);
119
+ } catch (e) {
120
+ return C(e);
122
121
  }
123
- return {
124
- status: "success",
125
- result: d,
126
- postCallbacks: f,
127
- whenParams: x
128
- };
129
- }, h = async (e = []) => {
122
+ }, g = async (e = []) => {
130
123
  let t = {};
131
124
  return await Promise.all(e.reverse().map(async ({ id: e, callback: r, params: i }) => {
132
125
  t[e] = await r?.(n(i, [e]), i[e]);
133
126
  })), t;
134
- }, g = async (e, n = {}, r = {}, a = {}, o = {}, s = [], c = {}, l = {}) => {
135
- if (!e) return c;
136
- let u = t(n, e.afterNode);
137
- if (!u && s.length > 0 && await h(s), !u) return c;
138
- let d = i.getTime().valueOf(), { status: f, result: p, postCallbacks: _, whenParams: v } = await m(u, r, a, o, l);
139
- return c[u.id] = {
140
- node: u,
141
- status: f,
142
- result: p,
143
- postCallbacks: _,
144
- whenParams: v,
145
- startTime: d,
146
- endTime: i.getTime().valueOf()
147
- }, s.push(..._), g(u, n, r, {
148
- ...a,
149
- [u.id]: p
150
- }, o, s, c, l);
151
- }, _ = (e, t, n = {}, r, a) => {
152
- let o = i.getTime().valueOf(), s = r === "skipped" ? "skipped" : "success", d = /* @__PURE__ */ u("span", { children: [
127
+ }, _ = () => ({}), v = async (e, n = {}, r = {}, a = {}, o = _, s = [], c = {}, l = {}) => {
128
+ let u = e, d = a;
129
+ for (; u;) {
130
+ let e = t(n, u.afterNode);
131
+ if (!e) return s.length > 0 && await g(s), c;
132
+ let a = i.getTime().valueOf(), f = h(e, r, d, o(), l), { status: p, result: _, postCallbacks: v, whenParams: y } = m(f) ? await f : f;
133
+ c[e.id] = {
134
+ node: e,
135
+ status: p,
136
+ result: _,
137
+ postCallbacks: v,
138
+ whenParams: y,
139
+ startTime: a,
140
+ endTime: i.getTime().valueOf()
141
+ }, s.push(...v), d = {
142
+ ...d,
143
+ [e.id]: _
144
+ }, u = e;
145
+ }
146
+ return c;
147
+ }, y = (e, t, n = {}, r, a) => {
148
+ let o = i.getTime().valueOf(), u = r === "skipped" ? "skipped" : "success", d = /* @__PURE__ */ l("span", { children: [
153
149
  "Interaction triggered ",
154
- /* @__PURE__ */ l("b", { children: `${e.title} [${e.action}]` }),
155
- a ? /* @__PURE__ */ u(c, { children: [" on ", /* @__PURE__ */ l("b", { children: a })] }) : null
150
+ /* @__PURE__ */ c("b", { children: `${e.title} [${e.action}]` }),
151
+ a ? /* @__PURE__ */ l(s, { children: [" on ", /* @__PURE__ */ c("b", { children: a })] }) : null
156
152
  ] }), f = {
157
153
  status: r,
158
154
  node: e,
@@ -162,7 +158,7 @@ var d = 5, f = 5, p = (e, t, n, r, c) => {
162
158
  ...n,
163
159
  [e.id]: {
164
160
  node: e,
165
- status: s,
161
+ status: u,
166
162
  result: void 0,
167
163
  postCallbacks: [],
168
164
  startTime: t,
@@ -177,17 +173,17 @@ var d = 5, f = 5, p = (e, t, n, r, c) => {
177
173
  return;
178
174
  }
179
175
  i.info("interactions", d, f);
180
- }, v = (e) => Object.values(e).some(({ status: e }) => e === "failed") ? "failed" : "completed", y = async (e, t = {}, n = {}, a = {}, o = {}, s, c = []) => {
176
+ }, b = (e) => Object.values(e).some(({ status: e }) => e === "failed") ? "failed" : "completed", x = async (e, t = {}, n = {}, a = {}, o = _, s, c = []) => {
181
177
  let l = i.getTime().valueOf(), { action: u, enabled: d, when: f } = e;
182
- if (!u || !d || f && !r(f, {
183
- ...o,
178
+ if (!u || !d || f && !r(f, p({
179
+ ...o(),
184
180
  ...a
185
- })) {
186
- _(e, l, {}, "skipped", s);
181
+ }))) {
182
+ y(e, l, {}, "skipped", s);
187
183
  return;
188
184
  }
189
- let p = await g(e, t, n, a, o, c, {}, { hostElementId: s });
190
- _(e, l, p, v(p), s);
191
- }, b = { flowTrigger: y };
185
+ let m = await v(e, t, n, a, o, c, {}, { hostElementId: s });
186
+ y(e, l, m, b(m), s);
187
+ }, S = { flowTrigger: x };
192
188
  //#endregion
193
- export { b as default, y as flowTrigger };
189
+ export { S as default, x as flowTrigger };
@@ -8,12 +8,27 @@ declare class InteractionsManager {
8
8
  interactionsData: Record<string, string | number | boolean>;
9
9
  subscriptors: Record<string, Subscriptor>;
10
10
  callbacksAvailables: Record<string, Record<string, InteractionCallback<any>>>;
11
- interactionsRunning: Record<string, boolean>;
11
+ /**
12
+ * The flows running now, by element and trigger node — what `whileRunning` decides against. Per FLOW rather than per
13
+ * event: two flows on one click are two things, and one still running says nothing about the other.
14
+ */
15
+ private flowsRunning;
12
16
  lastUpdate: number;
13
17
  private listeners;
14
18
  constructor(currentPageId?: string, routeParams?: RouteParams, queryParams?: QueryParams);
15
19
  eventBridgeCallback: (interactions?: Record<string, ElementInteraction>) => (subscriptorId: string, eventName: string, params: Record<string, unknown>) => Promise<void>;
20
+ /** One firing of one flow, as its trigger's `whileRunning` says — see {@link WhileRunning}. */
21
+ private runFlow;
16
22
  subscribe<TParams extends Record<string, unknown> = Record<string, unknown>>(id: string, interactions?: Record<string, ElementInteraction>, triggers?: Record<string, InteractionCallback<TParams>>, callbacks?: Record<string, InteractionCallback<TParams>>, getAdditionalParams?: Subscriptor<TParams>['getAdditionalParams']): boolean;
23
+ /**
24
+ * What a subscribed element wires, replaced — its subscription kept.
25
+ *
26
+ * An element re-renders with new callbacks all the time, often right after firing a trigger (a form marks itself
27
+ * submitted). Its subscription is the same one for as long as it is mounted, so a flow that trigger started still
28
+ * runs: only an element unmounted meanwhile loses it (see `eventBridgeCallback`).
29
+ */
30
+ update<TParams extends Record<string, unknown> = Record<string, unknown>>(id: string, interactions?: Record<string, ElementInteraction>, triggers?: Record<string, InteractionCallback<TParams>>, callbacks?: Record<string, InteractionCallback<TParams>>, getAdditionalParams?: Subscriptor<TParams>['getAdditionalParams']): boolean;
31
+ private wire;
17
32
  unsubscribe(id: string): boolean;
18
33
  getRootManager(): this | undefined;
19
34
  private getSubscriptorInternal;
@@ -1,55 +1,68 @@
1
1
  import { flowTrigger as e } from "./InteractionsHelper.mjs";
2
2
  import { get as t, set as n } from "@plitzi/plitzi-ui/helpers";
3
3
  import r from "@plitzi/sdk-event-bridge";
4
+ import { KEY_TRIGGER as i } from "@plitzi/sdk-shared/helpers/keys";
4
5
  //#region src/InteractionsManager.ts
5
- var i = class i {
6
+ var a = (e, t) => {
7
+ if (e.action !== i) return !0;
8
+ let { shortcuts: n } = t;
9
+ return Array.isArray(n) && n.includes(e.params.keys);
10
+ }, o = class i {
6
11
  eventBridge;
7
12
  parentManager;
8
13
  childManagers;
9
14
  interactionsData;
10
15
  subscriptors;
11
16
  callbacksAvailables;
12
- interactionsRunning;
17
+ flowsRunning = /* @__PURE__ */ new Map();
13
18
  lastUpdate;
14
19
  listeners = /* @__PURE__ */ new Set();
15
20
  constructor(e = "", t = {}, n = {}) {
16
- this.eventBridge = new r(), this.parentManager = void 0, this.childManagers = [], this.subscriptors = {}, this.callbacksAvailables = {}, this.interactionsRunning = {}, this.interactionsData = {
21
+ this.eventBridge = new r(), this.parentManager = void 0, this.childManagers = [], this.subscriptors = {}, this.callbacksAvailables = {}, this.interactionsData = {
17
22
  currentPageId: e,
18
23
  ...t,
19
24
  ...n
20
25
  }, this.lastUpdate = Date.now();
21
26
  }
22
- eventBridgeCallback = (r) => async (i, a, o) => {
23
- if (r && a && i && !t(this.interactionsRunning, `${i}.${a}`)) {
24
- n(this.interactionsRunning, `${i}.${a}`, !0);
25
- try {
26
- let n = t(this.subscriptors, `${i}.getAdditionalParams`, void 0), s;
27
- typeof n == "function" && ({dataSource: s} = n());
28
- let c = Object.values(r).filter((e) => e.type === "trigger" && e.action === a && e.enabled);
29
- await Promise.all(c.map((t) => e(t, r, this.getCallbacksAvailables(), { [t.id]: o }, {
30
- ...this.interactionsData,
31
- ...s
32
- }, i)));
33
- } finally {
34
- n(this.interactionsRunning, `${i}.${a}`, !1);
35
- }
36
- }
27
+ eventBridgeCallback = (n) => async (r, i, o) => {
28
+ if (!n || !i || !r) return;
29
+ let s = this.subscriptors[r];
30
+ if (await Promise.resolve(), !s || this.subscriptors[r] !== s) return;
31
+ let c = t(this.subscriptors, `${r}.getAdditionalParams`, void 0), l = () => ({
32
+ ...this.interactionsData,
33
+ ...typeof c == "function" ? c().dataSource : void 0
34
+ }), u = Object.values(n).filter((e) => e.type === "trigger" && e.action === i && e.enabled && a(e, o));
35
+ await Promise.all(u.map((t) => this.runFlow(`${r}.${t.id}`, t.whileRunning ?? "skip", () => e(t, n, this.getCallbacksAvailables(), { [t.id]: o }, l, r))));
37
36
  };
37
+ runFlow(e, t, n) {
38
+ let r = this.flowsRunning.get(e);
39
+ if (t === "parallel") return n();
40
+ if (r && t === "skip") return Promise.resolve();
41
+ let i = (r ? r.then(n, n) : n()).finally(() => {
42
+ this.flowsRunning.get(e) === i && this.flowsRunning.delete(e);
43
+ });
44
+ return this.flowsRunning.set(e, i), i;
45
+ }
38
46
  subscribe(e, t = {}, r = {}, i = {}, a) {
39
- if (!e || this.subscriptors[e]) return !1;
40
- n(this.subscriptors, e, {
47
+ return !e || this.subscriptors[e] ? !1 : (n(this.subscriptors, e, {
41
48
  id: e,
42
49
  triggers: r,
43
50
  getAdditionalParams: a
44
- });
45
- let o = Object.keys(i);
46
- return o.length > 0 && (this.callbacksAvailables[e] = o.reduce((t, n) => {
47
- let { title: r, callback: a, postCallback: o, params: s, preview: c, type: l } = i[n];
51
+ }), this.wire(e, t, r, i), this.touch(), !0);
52
+ }
53
+ update(e, t = {}, n = {}, r = {}, i) {
54
+ let a = this.subscriptors[e];
55
+ return a ? (a.triggers = n, a.getAdditionalParams = i, this.wire(e, t, n, r), this.touch(), !0) : !1;
56
+ }
57
+ wire(e, t, n, r) {
58
+ let i = Object.keys(r);
59
+ i.length > 0 ? this.callbacksAvailables[e] = i.reduce((t, n) => {
60
+ let { title: i, callback: a, postCallback: o, params: s, preview: c, type: l } = r[n];
48
61
  return typeof a == "function" ? {
49
62
  ...t,
50
63
  [n]: {
51
64
  elementId: e,
52
- title: r,
65
+ title: i,
53
66
  action: n,
54
67
  type: l,
55
68
  callback: a,
@@ -58,7 +71,7 @@ var i = class i {
58
71
  preview: c
59
72
  }
60
73
  } : t;
61
- }, {})), Object.keys(r).length > 0 && this.eventBridge.on("interaction", e, this.eventBridgeCallback(t), { override: !0 }), this.touch(), !0;
74
+ }, {}) : delete this.callbacksAvailables[e], Object.keys(n).length > 0 ? this.eventBridge.on("interaction", e, this.eventBridgeCallback(t), { override: !0 }) : this.eventBridge.off("interaction", e);
62
75
  }
63
76
  unsubscribe(e) {
64
77
  return this.subscriptors[e] ? (this.eventBridge.off("interaction", e), delete this.subscriptors[e], this.callbacksAvailables[e] && delete this.callbacksAvailables[e], this.touch(), !0) : !1;
@@ -112,4 +125,4 @@ var i = class i {
112
125
  }
113
126
  };
114
127
  //#endregion
115
- export { i as default };
128
+ export { o as default };
@@ -4,9 +4,11 @@ import { use as t, useEffect as n } from "react";
4
4
  var r = ({ id: r, interactions: i, triggers: a, callbacks: o, getAdditionalParams: s }) => {
5
5
  let { interactionsManager: c } = t(e);
6
6
  n(() => {
7
- if (r) return c.subscribe(r, i, a, o, s), () => {
7
+ if (r) return c.subscribe(r), () => {
8
8
  c.unsubscribe(r);
9
9
  };
10
+ }, [r, c]), n(() => {
11
+ r && c.update(r, i, a, o, s);
10
12
  }, [
11
13
  r,
12
14
  i,
@@ -237,7 +237,8 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
237
237
  status: "failed",
238
238
  reason: r.reason ?? "failed",
239
239
  runId: "",
240
- output: {}
240
+ output: {},
241
+ ...r.error ? { error: r.error } : {}
241
242
  };
242
243
  }
243
244
  let i = e.headers.get("X-Plitzi-Run-Id") ?? "";
@@ -272,6 +273,7 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
272
273
  T({
273
274
  status: e.data.status === "completed" ? "completed" : "failed",
274
275
  ...e.data.output ? { output: e.data.output } : {},
276
+ ...typeof e.data.error == "string" ? { error: e.data.error } : {},
275
277
  ...r ? { steps: r } : {}
276
278
  }), k(t?.hostElementId, "onFlowEnd", {
277
279
  actionId: n,
@@ -336,12 +338,14 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
336
338
  status: O.status === "completed" ? "completed" : "failed",
337
339
  ...O.runId ? { runId: O.runId } : {},
338
340
  ...O.output ? { output: O.output } : {},
341
+ ...O.error ? { error: O.error } : {},
339
342
  ...O.steps ? { steps: O.steps } : {},
340
343
  ...O.trace ? { trace: O.trace } : {}
341
344
  }), {
342
345
  status: O.status ?? "completed",
343
346
  runId: O.runId ?? "",
344
- output: O.output ?? {}
347
+ output: O.output ?? {},
348
+ ...O.error ? { error: O.error } : {}
345
349
  }) : (w(D.status, O, E), T({
346
350
  status: "failed",
347
351
  ...O.runId ? { runId: O.runId } : {},
@@ -363,7 +367,8 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
363
367
  status: "failed",
364
368
  reason: O.reason ?? "failed",
365
369
  runId: O.runId ?? "",
366
- output: {}
370
+ output: {},
371
+ ...O.error ? { error: O.error } : {}
367
372
  });
368
373
  }, [E, k]), j = r(async (e) => {
369
374
  if (!E || !e.runId) return { cancelled: !1 };
@@ -14,10 +14,9 @@ var t = {
14
14
  label: "Action"
15
15
  },
16
16
  input: {
17
- type: "text",
17
+ type: "json",
18
18
  description: "The values passed to the action, as a JSON object. The server drops every key the action did not declare. Authoring in code, pass a real object rather than a line of JSON text — an interpolated value containing a quote or a newline makes the text unparseable, and unparseable input posts nothing.",
19
19
  default: "{}",
20
- builderType: "codemirror-json",
21
20
  label: "Input"
22
21
  },
23
22
  mode: {
@@ -50,7 +49,9 @@ var t = {
50
49
  preview: {
51
50
  runId: "",
52
51
  status: "",
53
- output: {}
52
+ output: {},
53
+ reason: "",
54
+ error: ""
54
55
  }
55
56
  },
56
57
  cancelServerAction: {
@@ -9,10 +9,15 @@ var e = {
9
9
  type: "select",
10
10
  description: "Credentials to sign in with: a username and password, or a token obtained elsewhere.",
11
11
  default: "normal",
12
- options: ["normal", "token"],
12
+ options: [
13
+ "normal",
14
+ "token",
15
+ "mfa"
16
+ ],
13
17
  optionLabels: {
14
18
  normal: "User and Password",
15
- token: "Token"
19
+ token: "Token",
20
+ mfa: "Second factor"
16
21
  },
17
22
  canBind: !1
18
23
  },
@@ -33,11 +38,24 @@ var e = {
33
38
  description: "A token to exchange for a session.",
34
39
  default: "",
35
40
  when: (e) => e.mode === "token"
41
+ },
42
+ mfaToken: {
43
+ type: "text",
44
+ description: "The challenge a sign-in answered with when it owed a second factor: `{{ login.mfaToken }}`.",
45
+ default: "",
46
+ when: (e) => e.mode === "mfa"
47
+ },
48
+ code: {
49
+ type: "text",
50
+ description: "The code from the authenticator app, or a recovery code.",
51
+ default: "",
52
+ when: (e) => e.mode === "mfa"
36
53
  }
37
54
  },
38
55
  preview: {
39
56
  ok: "",
40
57
  reason: "",
58
+ mfaToken: "",
41
59
  errors: {
42
60
  username: "",
43
61
  password: "",