@plitzi/sdk-interactions 0.38.3 → 0.38.5
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 +535 -0
- package/dist/InteractionsHelper.d.ts +4 -2
- package/dist/InteractionsHelper.mjs +93 -88
- package/dist/InteractionsManager.d.ts +2 -0
- package/dist/InteractionsManager.mjs +10 -2
- package/dist/helpers/coerceDeclaredParams.d.ts +11 -0
- package/dist/helpers/coerceDeclaredParams.mjs +18 -0
- package/dist/sources/ActionsSource/ActionInteractions.mjs +42 -40
- package/dist/utility/delayTime.d.ts +7 -0
- package/dist/utility/delayTime.mjs +11 -3
- package/dist/utility/webHook.mjs +22 -21
- package/package.json +13 -8
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
import e from "./
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { coerceDeclaredParams as e } from "./helpers/coerceDeclaredParams.mjs";
|
|
2
|
+
import t from "./utility/index.mjs";
|
|
3
|
+
import { get as n, omit as r } from "@plitzi/plitzi-ui/helpers";
|
|
4
|
+
import { QueryBuilderEvaluator as i } from "@plitzi/plitzi-ui/QueryBuilder";
|
|
5
|
+
import { pConsole as a } from "@plitzi/sdk-shared/devTools/utils/PlitziConsole";
|
|
6
|
+
import { MAX_PARAM_PASSES as o, resolveStepParam as s } from "@plitzi/sdk-shared/helpers/twigWrapper";
|
|
7
|
+
import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
7
8
|
//#region src/InteractionsHelper.tsx
|
|
8
|
-
var
|
|
9
|
-
if (e === "utility" &&
|
|
10
|
-
let
|
|
9
|
+
var d = 5, f = (e, t, n, r, i) => {
|
|
10
|
+
if (e === "utility" && i === "twigTemplate") return t;
|
|
11
|
+
let c = {
|
|
11
12
|
...n,
|
|
12
13
|
...r
|
|
13
14
|
}, f = (e, t, n) => {
|
|
14
15
|
if (typeof e == "string") {
|
|
15
|
-
let { value: n, unresolved: r } =
|
|
16
|
-
return r &&
|
|
16
|
+
let { value: n, unresolved: r } = s(e, c);
|
|
17
|
+
return r && a.warning("interactions", /* @__PURE__ */ u("span", { children: [
|
|
17
18
|
"Twig token resolution exceeded ",
|
|
18
|
-
|
|
19
|
+
o,
|
|
19
20
|
" passes for ",
|
|
20
|
-
/* @__PURE__ */
|
|
21
|
+
/* @__PURE__ */ l("b", { children: t }),
|
|
21
22
|
", leaving unresolved tokens"
|
|
22
23
|
] }), {
|
|
23
24
|
param: t,
|
|
24
25
|
value: n
|
|
25
26
|
}), n;
|
|
26
27
|
}
|
|
27
|
-
return n >=
|
|
28
|
+
return n >= d || 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)]));
|
|
28
29
|
};
|
|
29
30
|
return Object.keys(t).reduce((n, r) => {
|
|
30
31
|
let i = e === "trigger" ? t[r] : f(t[r], r, 0);
|
|
@@ -33,132 +34,133 @@ var u = 5, d = (e, t, n, r, s) => {
|
|
|
33
34
|
[r]: i
|
|
34
35
|
};
|
|
35
36
|
}, {});
|
|
36
|
-
},
|
|
37
|
-
let
|
|
38
|
-
if (!
|
|
37
|
+
}, p = (e) => typeof e != "function" && typeof e != "symbol" && typeof e != "bigint", m = (e) => Object.fromEntries(Object.entries(e).filter((e) => p(e[1]))), h = (e) => typeof e == "object" && !!e && "then" in e && typeof e.then == "function", g = (r, o = {}, s = {}, c = {}, d = {}) => {
|
|
38
|
+
let p = [], { id: g, action: _, enabled: v, params: y, elementId: b, type: x, when: S } = r;
|
|
39
|
+
if (!_ || !v) return {
|
|
39
40
|
status: "disabled",
|
|
40
41
|
result: {},
|
|
41
|
-
postCallbacks:
|
|
42
|
+
postCallbacks: p
|
|
42
43
|
};
|
|
43
|
-
let
|
|
44
|
+
let C = m({
|
|
45
|
+
...c,
|
|
44
46
|
...s,
|
|
45
|
-
|
|
46
|
-
[h]: v
|
|
47
|
+
[g]: y
|
|
47
48
|
});
|
|
48
|
-
if (
|
|
49
|
+
if (S && !i(S, C)) return {
|
|
49
50
|
status: "skipped",
|
|
50
51
|
result: {},
|
|
51
|
-
postCallbacks:
|
|
52
|
-
whenParams:
|
|
52
|
+
postCallbacks: p,
|
|
53
|
+
whenParams: C
|
|
53
54
|
};
|
|
54
|
-
let
|
|
55
|
+
let w = (e) => (a.danger("interactions", /* @__PURE__ */ u("span", { children: ["Interaction node failed ", /* @__PURE__ */ l("b", { children: _ })] }), {
|
|
55
56
|
error: e instanceof Error ? e.message : String(e),
|
|
56
|
-
node:
|
|
57
|
+
node: r
|
|
57
58
|
}), {
|
|
58
59
|
status: "failed",
|
|
59
60
|
result: {},
|
|
60
|
-
postCallbacks:
|
|
61
|
-
whenParams:
|
|
62
|
-
}),
|
|
63
|
-
switch (
|
|
61
|
+
postCallbacks: p,
|
|
62
|
+
whenParams: C
|
|
63
|
+
}), T;
|
|
64
|
+
switch (x) {
|
|
64
65
|
case "callback":
|
|
65
66
|
case "globalCallback":
|
|
66
|
-
if (!
|
|
67
|
+
if (!b) return a.warning("interactions", /* @__PURE__ */ u("span", { children: [
|
|
67
68
|
"Step ",
|
|
68
|
-
/* @__PURE__ */
|
|
69
|
+
/* @__PURE__ */ l("b", { children: _ }),
|
|
69
70
|
" names no element, so there is nothing to run it on"
|
|
70
|
-
] }), { node:
|
|
71
|
+
] }), { node: r }), {
|
|
71
72
|
status: "failed",
|
|
72
73
|
result: {},
|
|
73
|
-
postCallbacks:
|
|
74
|
-
whenParams:
|
|
74
|
+
postCallbacks: p,
|
|
75
|
+
whenParams: C
|
|
75
76
|
};
|
|
76
|
-
if (
|
|
77
|
+
if (T = n(o, `${b}.${_}`), !T) return a.warning("interactions", /* @__PURE__ */ u("span", { children: [
|
|
77
78
|
"Nothing is registered as ",
|
|
78
|
-
/* @__PURE__ */
|
|
79
|
+
/* @__PURE__ */ l("b", { children: `${b}.${_}` }),
|
|
79
80
|
", so this step did nothing"
|
|
80
81
|
] }), {
|
|
81
|
-
node:
|
|
82
|
-
available: Object.keys(
|
|
82
|
+
node: r,
|
|
83
|
+
available: Object.keys(n(o, b, {}))
|
|
83
84
|
}), {
|
|
84
85
|
status: "failed",
|
|
85
86
|
result: {},
|
|
86
|
-
postCallbacks:
|
|
87
|
-
whenParams:
|
|
87
|
+
postCallbacks: p,
|
|
88
|
+
whenParams: C
|
|
88
89
|
};
|
|
89
90
|
break;
|
|
90
91
|
case "utility":
|
|
91
|
-
|
|
92
|
+
T = n(t, _, {});
|
|
92
93
|
break;
|
|
93
94
|
default: return {
|
|
94
95
|
status: "success",
|
|
95
96
|
result: {},
|
|
96
|
-
postCallbacks:
|
|
97
|
-
whenParams:
|
|
97
|
+
postCallbacks: p,
|
|
98
|
+
whenParams: C
|
|
98
99
|
};
|
|
99
100
|
}
|
|
100
101
|
try {
|
|
101
|
-
let
|
|
102
|
-
...o,
|
|
102
|
+
let t = {
|
|
103
103
|
...s,
|
|
104
|
-
...
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
...c,
|
|
105
|
+
...e(T.params, f(x, y, s, c, _))
|
|
106
|
+
}, { callback: n, postCallback: r } = T, i = (e) => (r && p.push({
|
|
107
|
+
id: g,
|
|
108
|
+
callback: r,
|
|
108
109
|
params: {
|
|
109
|
-
...
|
|
110
|
-
[
|
|
110
|
+
...t,
|
|
111
|
+
[g]: e
|
|
111
112
|
}
|
|
112
113
|
}), {
|
|
113
114
|
status: "success",
|
|
114
|
-
result:
|
|
115
|
-
postCallbacks:
|
|
116
|
-
whenParams:
|
|
117
|
-
}),
|
|
118
|
-
return
|
|
115
|
+
result: e,
|
|
116
|
+
postCallbacks: p,
|
|
117
|
+
whenParams: C
|
|
118
|
+
}), a = n ? n(t, d) : {};
|
|
119
|
+
return h(a) ? Promise.resolve(a).then(i, w) : i(a);
|
|
119
120
|
} catch (e) {
|
|
120
|
-
return
|
|
121
|
+
return w(e);
|
|
121
122
|
}
|
|
122
|
-
},
|
|
123
|
+
}, _ = async (e = []) => {
|
|
123
124
|
let t = {};
|
|
124
|
-
return await Promise.all(e.reverse().map(async ({ id: e, callback:
|
|
125
|
-
t[e] = await
|
|
125
|
+
return await Promise.all(e.reverse().map(async ({ id: e, callback: n, params: i }) => {
|
|
126
|
+
t[e] = await n?.(r(i, [e]), i[e]);
|
|
126
127
|
})), t;
|
|
127
|
-
},
|
|
128
|
-
let u = e, d =
|
|
128
|
+
}, v = () => ({}), y = async (e, t = {}, r = {}, i = {}, o = v, s = [], c = {}, l = {}) => {
|
|
129
|
+
let u = e, d = i;
|
|
129
130
|
for (; u;) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
if (l.signal?.aborted) return c;
|
|
132
|
+
let e = n(t, u.afterNode);
|
|
133
|
+
if (!e) return s.length > 0 && await _(s), c;
|
|
134
|
+
let i = a.getTime().valueOf(), f = g(e, r, d, o(), l), p = h(f) ? await f : f, { result: m, postCallbacks: v, whenParams: y } = p, b = p.status === "failed" && l.signal?.aborted ? "skipped" : p.status;
|
|
133
135
|
c[e.id] = {
|
|
134
136
|
node: e,
|
|
135
|
-
status:
|
|
136
|
-
result:
|
|
137
|
+
status: b,
|
|
138
|
+
result: m,
|
|
137
139
|
postCallbacks: v,
|
|
138
140
|
whenParams: y,
|
|
139
|
-
startTime:
|
|
140
|
-
endTime:
|
|
141
|
+
startTime: i,
|
|
142
|
+
endTime: a.getTime().valueOf()
|
|
141
143
|
}, s.push(...v), d = {
|
|
142
144
|
...d,
|
|
143
|
-
[e.id]:
|
|
145
|
+
[e.id]: m
|
|
144
146
|
}, u = e;
|
|
145
147
|
}
|
|
146
148
|
return c;
|
|
147
|
-
},
|
|
148
|
-
let o =
|
|
149
|
+
}, b = (e, t, n = {}, r, i) => {
|
|
150
|
+
let o = a.getTime().valueOf(), s = r === "skipped" ? "skipped" : "success", d = /* @__PURE__ */ u("span", { children: [
|
|
149
151
|
"Interaction triggered ",
|
|
150
|
-
/* @__PURE__ */
|
|
151
|
-
|
|
152
|
+
/* @__PURE__ */ l("b", { children: `${e.title} [${e.action}]` }),
|
|
153
|
+
i ? /* @__PURE__ */ u(c, { children: [" on ", /* @__PURE__ */ l("b", { children: i })] }) : null
|
|
152
154
|
] }), f = {
|
|
153
155
|
status: r,
|
|
154
156
|
node: e,
|
|
155
157
|
elementId: e.elementId,
|
|
156
|
-
hostElementId:
|
|
158
|
+
hostElementId: i,
|
|
157
159
|
nodes: {
|
|
158
160
|
...n,
|
|
159
161
|
[e.id]: {
|
|
160
162
|
node: e,
|
|
161
|
-
status:
|
|
163
|
+
status: s,
|
|
162
164
|
result: void 0,
|
|
163
165
|
postCallbacks: [],
|
|
164
166
|
startTime: t,
|
|
@@ -169,21 +171,24 @@ var u = 5, d = (e, t, n, r, s) => {
|
|
|
169
171
|
endTime: o
|
|
170
172
|
};
|
|
171
173
|
if (r === "failed") {
|
|
172
|
-
|
|
174
|
+
a.danger("interactions", d, f);
|
|
173
175
|
return;
|
|
174
176
|
}
|
|
175
|
-
|
|
176
|
-
},
|
|
177
|
-
let
|
|
178
|
-
if (!
|
|
177
|
+
a.info("interactions", d, f);
|
|
178
|
+
}, x = (e) => Object.values(e).some(({ status: e }) => e === "failed") ? "failed" : "completed", S = async (e, t = {}, n = {}, r = {}, o = v, s, c, l = []) => {
|
|
179
|
+
let u = a.getTime().valueOf(), { action: d, enabled: f, when: p } = e;
|
|
180
|
+
if (!d || !f || p && !i(p, m({
|
|
179
181
|
...o(),
|
|
180
|
-
...
|
|
182
|
+
...r
|
|
181
183
|
}))) {
|
|
182
|
-
|
|
184
|
+
b(e, u, {}, "skipped", s);
|
|
183
185
|
return;
|
|
184
186
|
}
|
|
185
|
-
let
|
|
186
|
-
|
|
187
|
-
|
|
187
|
+
let h = await y(e, t, n, r, o, l, {}, {
|
|
188
|
+
hostElementId: s,
|
|
189
|
+
...c ? { signal: c } : {}
|
|
190
|
+
});
|
|
191
|
+
b(e, u, h, x(h), s);
|
|
192
|
+
}, C = { flowTrigger: S };
|
|
188
193
|
//#endregion
|
|
189
|
-
export {
|
|
194
|
+
export { C as default, S as flowTrigger };
|
|
@@ -13,6 +13,8 @@ declare class InteractionsManager {
|
|
|
13
13
|
* event: two flows on one click are two things, and one still running says nothing about the other.
|
|
14
14
|
*/
|
|
15
15
|
private flowsRunning;
|
|
16
|
+
/** The run a `latest` flow is on now, by the same key: what the next firing stops. */
|
|
17
|
+
private latestRuns;
|
|
16
18
|
lastUpdate: number;
|
|
17
19
|
private listeners;
|
|
18
20
|
constructor(currentPageId?: string, routeParams?: RouteParams, queryParams?: QueryParams);
|
|
@@ -18,6 +18,7 @@ var s = (e, t) => {
|
|
|
18
18
|
subscriptors;
|
|
19
19
|
callbacksAvailables;
|
|
20
20
|
flowsRunning = /* @__PURE__ */ new Map();
|
|
21
|
+
latestRuns = /* @__PURE__ */ new Map();
|
|
21
22
|
lastUpdate;
|
|
22
23
|
listeners = /* @__PURE__ */ new Set();
|
|
23
24
|
constructor(e = "", t = {}, n = {}) {
|
|
@@ -35,13 +36,20 @@ var s = (e, t) => {
|
|
|
35
36
|
...this.interactionsData,
|
|
36
37
|
...typeof c == "function" ? c().dataSource : void 0
|
|
37
38
|
}), u = Object.values(n).filter((e) => e.type === "trigger" && e.action === i && e.enabled && s(e, a));
|
|
38
|
-
await Promise.all(u.map((t) => this.runFlow(`${r}.${t.id}`, t.whileRunning ?? "skip", () => e(t, n, this.getCallbacksAvailables(), { [t.id]: a }, l, r))));
|
|
39
|
+
await Promise.all(u.map((t) => this.runFlow(`${r}.${t.id}`, t.whileRunning ?? "skip", (i) => e(t, n, this.getCallbacksAvailables(), { [t.id]: a }, l, r, i))));
|
|
39
40
|
};
|
|
40
41
|
runFlow(e, t, n) {
|
|
42
|
+
if (t === "latest") {
|
|
43
|
+
this.latestRuns.get(e)?.abort();
|
|
44
|
+
let t = new AbortController();
|
|
45
|
+
return this.latestRuns.set(e, t), n(t.signal).finally(() => {
|
|
46
|
+
this.latestRuns.get(e) === t && this.latestRuns.delete(e);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
41
49
|
let r = this.flowsRunning.get(e);
|
|
42
50
|
if (t === "parallel") return n();
|
|
43
51
|
if (r && t === "skip") return Promise.resolve();
|
|
44
|
-
let i = (r ? r.then(n, n) : n()).finally(() => {
|
|
52
|
+
let i = (r ? r.then(() => n(), () => n()) : n()).finally(() => {
|
|
45
53
|
this.flowsRunning.get(e) === i && this.flowsRunning.delete(e);
|
|
46
54
|
});
|
|
47
55
|
return this.flowsRunning.set(e, i), i;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { InteractionCallback } from '@plitzi/sdk-shared';
|
|
2
|
+
/**
|
|
3
|
+
* A step's params, each as the type its callback DECLARES: a `number` param written `5000` — or bound to text that
|
|
4
|
+
* says it — arrives as the number, a `boolean` one written `'true'` as `true`, an empty number as nothing at all (so the
|
|
5
|
+
* component's default applies). Everything else arrives as written.
|
|
6
|
+
*
|
|
7
|
+
* The callback declares the type, so the conversion happens once, here, for every action — a plugin's above all, whose
|
|
8
|
+
* author otherwise wrote `Number(params.interval)` in every callback. Only the step's own params: what the flow and
|
|
9
|
+
* the page hand along beside them is theirs.
|
|
10
|
+
*/
|
|
11
|
+
export declare const coerceDeclaredParams: (declared: InteractionCallback["params"] | undefined, params: Record<string, unknown>) => Record<string, unknown>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/helpers/coerceDeclaredParams.ts
|
|
2
|
+
var e = (e, t) => typeof e.type == "function" ? e.type(t) : e.type, t = (e, t) => {
|
|
3
|
+
if (typeof t != "string") return t;
|
|
4
|
+
if (e === "number") {
|
|
5
|
+
let e = t.trim();
|
|
6
|
+
if (e === "") return;
|
|
7
|
+
let n = Number(e);
|
|
8
|
+
return Number.isFinite(n) ? n : t;
|
|
9
|
+
}
|
|
10
|
+
return e === "boolean" && (t === "true" || t === "false") ? t === "true" : t;
|
|
11
|
+
}, n = (n, r) => {
|
|
12
|
+
if (!n) return r;
|
|
13
|
+
let i = typeof n == "function" ? n(r) : n, a = { ...r };
|
|
14
|
+
for (let [n, o] of Object.entries(i)) Object.hasOwn(r, n) && (a[n] = t(e(o, r), r[n]));
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { n as coerceDeclaredParams };
|
|
@@ -85,8 +85,7 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
|
|
|
85
85
|
actionId: n,
|
|
86
86
|
mode: r,
|
|
87
87
|
input: o
|
|
88
|
-
}), _ = new AbortController(), v = ""
|
|
89
|
-
p(g, () => {
|
|
88
|
+
}), _ = new AbortController(), v = "", T = () => {
|
|
90
89
|
_.abort(), h(g, {
|
|
91
90
|
status: "aborted",
|
|
92
91
|
endedAt: Date.now(),
|
|
@@ -95,9 +94,12 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
|
|
|
95
94
|
method: "DELETE",
|
|
96
95
|
credentials: "same-origin"
|
|
97
96
|
}).catch(() => void 0);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
};
|
|
98
|
+
p(g, T);
|
|
99
|
+
let D = t?.signal;
|
|
100
|
+
D?.addEventListener("abort", T, { once: !0 });
|
|
101
|
+
let O = (t) => {
|
|
102
|
+
D?.removeEventListener("abort", T), m(g), h(g, {
|
|
101
103
|
endedAt: Date.now(),
|
|
102
104
|
cancellable: !1,
|
|
103
105
|
...t
|
|
@@ -125,7 +127,7 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
|
|
|
125
127
|
}).then(async (e) => {
|
|
126
128
|
let i = await e.json().catch(() => ({}));
|
|
127
129
|
if (!e.ok) {
|
|
128
|
-
w(e.status, i, E),
|
|
130
|
+
w(e.status, i, E), O({
|
|
129
131
|
status: "failed",
|
|
130
132
|
...i.runId ? { runId: i.runId } : {},
|
|
131
133
|
...i.reason ? { reason: i.reason } : {},
|
|
@@ -139,7 +141,7 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
|
|
|
139
141
|
});
|
|
140
142
|
return;
|
|
141
143
|
}
|
|
142
|
-
|
|
144
|
+
O({
|
|
143
145
|
status: i.status === "completed" ? "completed" : "accepted",
|
|
144
146
|
...i.runId ? { runId: i.runId } : {},
|
|
145
147
|
...i.output ? { output: i.output } : {},
|
|
@@ -162,7 +164,7 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
|
|
|
162
164
|
output: i.output ?? {}
|
|
163
165
|
});
|
|
164
166
|
}).catch((e) => {
|
|
165
|
-
|
|
167
|
+
O(C(_, e)), a.warning("actions", /* @__PURE__ */ u("span", { children: [
|
|
166
168
|
"Server action ",
|
|
167
169
|
/* @__PURE__ */ l("b", { children: n }),
|
|
168
170
|
" could not be sent"
|
|
@@ -205,7 +207,7 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
|
|
|
205
207
|
body: s
|
|
206
208
|
});
|
|
207
209
|
} catch (e) {
|
|
208
|
-
return
|
|
210
|
+
return O(C(_, e)), a.warning("actions", /* @__PURE__ */ u("span", { children: [
|
|
209
211
|
"Server action ",
|
|
210
212
|
/* @__PURE__ */ l("b", { children: n }),
|
|
211
213
|
" could not be reached"
|
|
@@ -222,7 +224,7 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
|
|
|
222
224
|
}
|
|
223
225
|
if (!e.ok || !e.body) {
|
|
224
226
|
let r = await e.json().catch(() => ({}));
|
|
225
|
-
return w(e.status, r, E),
|
|
227
|
+
return w(e.status, r, E), O({
|
|
226
228
|
status: "failed",
|
|
227
229
|
...r.runId ? { runId: r.runId } : {},
|
|
228
230
|
...r.reason ? { reason: r.reason } : {},
|
|
@@ -256,7 +258,7 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
|
|
|
256
258
|
}
|
|
257
259
|
if (e.event === "error") {
|
|
258
260
|
let r = y(e.data.steps);
|
|
259
|
-
|
|
261
|
+
O({
|
|
260
262
|
status: "failed",
|
|
261
263
|
...typeof e.data.reason == "string" ? { reason: e.data.reason } : {},
|
|
262
264
|
...typeof e.data.error == "string" ? { error: e.data.error } : {},
|
|
@@ -270,7 +272,7 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
|
|
|
270
272
|
}
|
|
271
273
|
if (e.event === "done") {
|
|
272
274
|
let r = y(e.data.steps);
|
|
273
|
-
|
|
275
|
+
O({
|
|
274
276
|
status: e.data.status === "completed" ? "completed" : "failed",
|
|
275
277
|
...e.data.output ? { output: e.data.output } : {},
|
|
276
278
|
...typeof e.data.error == "string" ? { error: e.data.error } : {},
|
|
@@ -284,7 +286,7 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
|
|
|
284
286
|
}).catch((e) => {
|
|
285
287
|
if (_.signal.aborted) return;
|
|
286
288
|
let o = e instanceof Error ? e.message : String(e);
|
|
287
|
-
|
|
289
|
+
O({
|
|
288
290
|
status: "failed",
|
|
289
291
|
error: o
|
|
290
292
|
}), a.warning("actions", /* @__PURE__ */ u("span", { children: [
|
|
@@ -309,9 +311,9 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
|
|
|
309
311
|
output: {}
|
|
310
312
|
};
|
|
311
313
|
}
|
|
312
|
-
let
|
|
314
|
+
let A;
|
|
313
315
|
try {
|
|
314
|
-
|
|
316
|
+
A = await fetch(E, {
|
|
315
317
|
method: "POST",
|
|
316
318
|
headers: { "Content-Type": "application/json" },
|
|
317
319
|
credentials: "same-origin",
|
|
@@ -319,7 +321,7 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
|
|
|
319
321
|
body: s
|
|
320
322
|
});
|
|
321
323
|
} catch (e) {
|
|
322
|
-
return
|
|
324
|
+
return O(C(_, e)), a.warning("interactions", /* @__PURE__ */ u("span", { children: [
|
|
323
325
|
"Server action ",
|
|
324
326
|
/* @__PURE__ */ l("b", { children: n }),
|
|
325
327
|
" could not be reached"
|
|
@@ -333,25 +335,25 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
|
|
|
333
335
|
reason: "failed"
|
|
334
336
|
}), S;
|
|
335
337
|
}
|
|
336
|
-
let
|
|
337
|
-
return
|
|
338
|
-
status:
|
|
339
|
-
...
|
|
340
|
-
...
|
|
341
|
-
...
|
|
342
|
-
...
|
|
343
|
-
...
|
|
338
|
+
let j = await A.json().catch(() => ({}));
|
|
339
|
+
return A.ok ? (O({
|
|
340
|
+
status: j.status === "completed" ? "completed" : "failed",
|
|
341
|
+
...j.runId ? { runId: j.runId } : {},
|
|
342
|
+
...j.output ? { output: j.output } : {},
|
|
343
|
+
...j.error ? { error: j.error } : {},
|
|
344
|
+
...j.steps ? { steps: j.steps } : {},
|
|
345
|
+
...j.trace ? { trace: j.trace } : {}
|
|
344
346
|
}), {
|
|
345
|
-
status:
|
|
346
|
-
runId:
|
|
347
|
-
output:
|
|
348
|
-
...
|
|
349
|
-
}) : (w(
|
|
347
|
+
status: j.status ?? "completed",
|
|
348
|
+
runId: j.runId ?? "",
|
|
349
|
+
output: j.output ?? {},
|
|
350
|
+
...j.error ? { error: j.error } : {}
|
|
351
|
+
}) : (w(A.status, j, E), O({
|
|
350
352
|
status: "failed",
|
|
351
|
-
...
|
|
352
|
-
...
|
|
353
|
-
...
|
|
354
|
-
...
|
|
353
|
+
...j.runId ? { runId: j.runId } : {},
|
|
354
|
+
...j.reason ? { reason: j.reason } : {},
|
|
355
|
+
...j.error ? { error: j.error } : {},
|
|
356
|
+
...j.steps ? { steps: j.steps } : {}
|
|
355
357
|
}), a.warning("actions", /* @__PURE__ */ u("span", { children: [
|
|
356
358
|
"Server action ",
|
|
357
359
|
/* @__PURE__ */ l("b", { children: n }),
|
|
@@ -359,16 +361,16 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
|
|
|
359
361
|
] }), {
|
|
360
362
|
actionId: n,
|
|
361
363
|
mode: r,
|
|
362
|
-
runId:
|
|
363
|
-
reason:
|
|
364
|
-
error:
|
|
365
|
-
status: String(
|
|
364
|
+
runId: j.runId,
|
|
365
|
+
reason: j.reason,
|
|
366
|
+
error: j.error,
|
|
367
|
+
status: String(A.status)
|
|
366
368
|
}), {
|
|
367
369
|
status: "failed",
|
|
368
|
-
reason:
|
|
369
|
-
runId:
|
|
370
|
+
reason: j.reason ?? "failed",
|
|
371
|
+
runId: j.runId ?? "",
|
|
370
372
|
output: {},
|
|
371
|
-
...
|
|
373
|
+
...j.error ? { error: j.error } : {}
|
|
372
374
|
});
|
|
373
375
|
}, [E, k]), j = r(async (e) => {
|
|
374
376
|
if (!E || !e.runId) return { cancelled: !1 };
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { InteractionCallback } from '@plitzi/sdk-shared';
|
|
2
|
+
/**
|
|
3
|
+
* Waits `time` milliseconds before the next step.
|
|
4
|
+
*
|
|
5
|
+
* The wait ends early when the flow is superseded (`whileRunning: 'latest'`): the run is over, and holding a timer
|
|
6
|
+
* for it only keeps it alive for nothing. That pair is how a flow is debounced — `whileRunning('latest')` and a
|
|
7
|
+
* `delay(450)` first: every new firing stops the one still waiting, and only the last gets past the wait.
|
|
8
|
+
*/
|
|
2
9
|
declare const delayTime: InteractionCallback<{
|
|
3
10
|
time: number;
|
|
4
11
|
}>;
|
|
@@ -5,11 +5,19 @@ var e = {
|
|
|
5
5
|
type: "utility",
|
|
6
6
|
params: { time: {
|
|
7
7
|
label: "Time (Milliseconds)",
|
|
8
|
-
type: "
|
|
8
|
+
type: "number"
|
|
9
9
|
} },
|
|
10
10
|
preview: {},
|
|
11
|
-
callback: ({ time: e }) => new Promise((
|
|
12
|
-
|
|
11
|
+
callback: ({ time: e }, t) => new Promise((n) => {
|
|
12
|
+
let r = t?.signal;
|
|
13
|
+
if (r?.aborted) {
|
|
14
|
+
n(void 0);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
let i = () => {
|
|
18
|
+
clearTimeout(a), r?.removeEventListener("abort", i), n(void 0);
|
|
19
|
+
}, a = setTimeout(i, e);
|
|
20
|
+
r?.addEventListener("abort", i, { once: !0 });
|
|
13
21
|
})
|
|
14
22
|
};
|
|
15
23
|
//#endregion
|
package/dist/utility/webHook.mjs
CHANGED
|
@@ -9,41 +9,42 @@ var a = /* @__PURE__ */ new Set(["GET", "HEAD"]), o = /* @__PURE__ */ new Set([
|
|
|
9
9
|
]), s = (t) => {
|
|
10
10
|
let n = Number(t);
|
|
11
11
|
return (Number.isFinite(n) && n >= 0 ? n : Number(e.params.staleTime.default)) * 1e3;
|
|
12
|
-
}, c = (e) => e ? { Authorization: `Bearer ${e}` } : {}, l = (e) => typeof e == "object" && e ? e : {}, u = /* @__PURE__ */ new Set(["authorization", "content-type"]), d = (e) => typeof e == "object" && e ? Object.fromEntries(Object.entries(e).flatMap(([e, t]) => (typeof t == "string" || typeof t == "number") && t !== "" && !u.has(e.toLowerCase()) ? [[e, String(t)]] : [])) : {}, f = async ({ url: e, authorizationToken: t, headers: n, body: r, credentials: i }, a) => {
|
|
13
|
-
let
|
|
12
|
+
}, c = (e) => e ? { Authorization: `Bearer ${e}` } : {}, l = (e) => typeof e == "object" && e ? e : {}, u = /* @__PURE__ */ new Set(["authorization", "content-type"]), d = (e) => typeof e == "object" && e ? Object.fromEntries(Object.entries(e).flatMap(([e, t]) => (typeof t == "string" || typeof t == "number") && t !== "" && !u.has(e.toLowerCase()) ? [[e, String(t)]] : [])) : {}, f = async ({ url: e, authorizationToken: t, headers: n, body: r, credentials: i }, a, s) => {
|
|
13
|
+
let u = l(r), f = Object.values(u).some((e) => e instanceof Blob), p = {
|
|
14
14
|
method: a,
|
|
15
15
|
headers: {
|
|
16
16
|
...d(n),
|
|
17
|
-
...
|
|
17
|
+
...f ? {} : { "Content-Type": "application/json" },
|
|
18
18
|
...c(t)
|
|
19
19
|
},
|
|
20
|
-
credentials: i
|
|
20
|
+
credentials: i,
|
|
21
|
+
...s ? { signal: s } : {}
|
|
21
22
|
};
|
|
22
23
|
if (!o.has(a)) {
|
|
23
|
-
if (!
|
|
24
|
+
if (!f) p.body = JSON.stringify(u);
|
|
24
25
|
else {
|
|
25
26
|
let e = new FormData();
|
|
26
|
-
Object.entries(
|
|
27
|
+
Object.entries(u).forEach(([t, n]) => {
|
|
27
28
|
e.append(t, n);
|
|
28
|
-
}),
|
|
29
|
+
}), p.body = e;
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
let
|
|
32
|
+
let m = await fetch(e, p).catch((t) => {
|
|
32
33
|
throw Error(`${a} ${e} got no answer: ${t instanceof Error ? t.message : String(t)}`);
|
|
33
|
-
}),
|
|
34
|
+
}), h = "";
|
|
34
35
|
try {
|
|
35
|
-
|
|
36
|
+
h = await m.json();
|
|
36
37
|
} catch {}
|
|
37
38
|
return {
|
|
38
|
-
status:
|
|
39
|
-
data:
|
|
39
|
+
status: m.status,
|
|
40
|
+
data: h
|
|
40
41
|
};
|
|
41
|
-
}, p = t("webHook", e, async (e) => {
|
|
42
|
-
let
|
|
43
|
-
if (a.has(
|
|
44
|
-
if (e.cache !== !0 && e.cache !== "true") return { response: await f(e, t) };
|
|
42
|
+
}, p = t("webHook", e, async (e, t) => {
|
|
43
|
+
let o = (e.method || "get").toUpperCase();
|
|
44
|
+
if (a.has(o)) {
|
|
45
|
+
if (e.cache !== !0 && e.cache !== "true") return { response: await f(e, o, t?.signal) };
|
|
45
46
|
let n = i({
|
|
46
|
-
method:
|
|
47
|
+
method: o,
|
|
47
48
|
url: e.url,
|
|
48
49
|
credentials: e.credentials,
|
|
49
50
|
headers: {
|
|
@@ -53,18 +54,18 @@ var a = /* @__PURE__ */ new Set(["GET", "HEAD"]), o = /* @__PURE__ */ new Set([
|
|
|
53
54
|
});
|
|
54
55
|
return { response: await r.fetchQuery(n, {
|
|
55
56
|
meta: { url: e.url },
|
|
56
|
-
fetcher: () => f(e,
|
|
57
|
+
fetcher: () => f(e, o),
|
|
57
58
|
staleTime: s(e.staleTime),
|
|
58
59
|
isCacheable: (e) => e.status < 400
|
|
59
60
|
}) };
|
|
60
61
|
}
|
|
61
|
-
let
|
|
62
|
-
return
|
|
62
|
+
let l = await f(e, o, t?.signal);
|
|
63
|
+
return l.status >= 200 && l.status < 300 && n({
|
|
63
64
|
mode: e.invalidateQueries,
|
|
64
65
|
fallback: "origin",
|
|
65
66
|
elements: e.invalidateElements,
|
|
66
67
|
url: e.url
|
|
67
|
-
}), { response:
|
|
68
|
+
}), { response: l };
|
|
68
69
|
});
|
|
69
70
|
//#endregion
|
|
70
71
|
export { p as default };
|