@plitzi/sdk-interactions 0.39.15 → 0.39.17
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 +19 -0
- package/dist/InteractionsHelper.mjs +62 -52
- package/dist/sources/ActionsSource/ActionInteractions.mjs +47 -47
- package/dist/utility/webHook.mjs +41 -36
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @plitzi/sdk-interactions
|
|
2
2
|
|
|
3
|
+
## 0.39.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @plitzi/sdk-auth@0.39.17
|
|
8
|
+
- @plitzi/sdk-event-bridge@0.39.17
|
|
9
|
+
- @plitzi/sdk-shared@0.39.17
|
|
10
|
+
|
|
11
|
+
## 0.39.16
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 0389dd0: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
|
|
16
|
+
`@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
|
|
17
|
+
- Updated dependencies [0389dd0]
|
|
18
|
+
- @plitzi/sdk-auth@0.39.16
|
|
19
|
+
- @plitzi/sdk-event-bridge@0.39.16
|
|
20
|
+
- @plitzi/sdk-shared@0.39.16
|
|
21
|
+
|
|
3
22
|
## 0.39.15
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -3,43 +3,44 @@ import t from "./utility/index.mjs";
|
|
|
3
3
|
import { get as n, omit as r } from "@plitzi/plitzi-ui/helpers";
|
|
4
4
|
import { pConsole as i } from "@plitzi/sdk-shared/devTools";
|
|
5
5
|
import { evaluateRuleGroup as a, ruleValuesOf as o } from "@plitzi/sdk-shared/conditions";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { flowStarted as s } from "@plitzi/sdk-shared/devTools/running";
|
|
7
|
+
import { MAX_PARAM_PASSES as c, resolveStepParam as l } from "@plitzi/sdk-shared/helpers/twigWrapper";
|
|
8
|
+
import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
8
9
|
// src/InteractionsHelper.tsx
|
|
9
|
-
var
|
|
10
|
+
var p = 5, m = (e, t, n, r, a) => {
|
|
10
11
|
if (e === "utility" && a === "twigTemplate") return t;
|
|
11
12
|
let o = {
|
|
12
13
|
...n,
|
|
13
14
|
...r
|
|
14
|
-
},
|
|
15
|
+
}, s = (e, t, n) => {
|
|
15
16
|
if (typeof e == "string") {
|
|
16
|
-
let { value: n, unresolved: r } =
|
|
17
|
-
return r && i.warning("interactions", /* @__PURE__ */
|
|
17
|
+
let { value: n, unresolved: r } = l(e, o);
|
|
18
|
+
return r && i.warning("interactions", /* @__PURE__ */ f("span", { children: [
|
|
18
19
|
"Twig token resolution exceeded ",
|
|
19
|
-
|
|
20
|
+
c,
|
|
20
21
|
" passes for ",
|
|
21
|
-
/* @__PURE__ */
|
|
22
|
+
/* @__PURE__ */ d("b", { children: t }),
|
|
22
23
|
", leaving unresolved tokens"
|
|
23
24
|
] }), {
|
|
24
25
|
param: t,
|
|
25
26
|
value: n
|
|
26
27
|
}), n;
|
|
27
28
|
}
|
|
28
|
-
return n >=
|
|
29
|
+
return n >= p || typeof e != "object" || !e ? e : Array.isArray(e) ? e.map((e) => s(e, t, n + 1)) : Object.fromEntries(Object.entries(e).map(([e, r]) => [e, s(r, t, n + 1)]));
|
|
29
30
|
};
|
|
30
31
|
return Object.keys(t).reduce((n, r) => {
|
|
31
|
-
let i = e === "trigger" ? t[r] :
|
|
32
|
+
let i = e === "trigger" ? t[r] : s(t[r], r, 0);
|
|
32
33
|
return {
|
|
33
34
|
...n,
|
|
34
35
|
[r]: i
|
|
35
36
|
};
|
|
36
37
|
}, {});
|
|
37
|
-
},
|
|
38
|
-
let
|
|
38
|
+
}, h = (e) => typeof e == "object" && !!e && "then" in e && typeof e.then == "function", g = (r, s = {}, c = {}, l = {}, u = {}) => {
|
|
39
|
+
let p = [], { id: g, action: _, enabled: v, params: y, elementId: b, type: x, when: S } = r;
|
|
39
40
|
if (!_ || !v) return {
|
|
40
41
|
status: "disabled",
|
|
41
42
|
result: {},
|
|
42
|
-
postCallbacks:
|
|
43
|
+
postCallbacks: p
|
|
43
44
|
};
|
|
44
45
|
let C = o({
|
|
45
46
|
...l,
|
|
@@ -49,34 +50,34 @@ var f = 5, p = (e, t, n, r, a) => {
|
|
|
49
50
|
if (S && !a(S, C)) return {
|
|
50
51
|
status: "skipped",
|
|
51
52
|
result: {},
|
|
52
|
-
postCallbacks:
|
|
53
|
+
postCallbacks: p,
|
|
53
54
|
whenParams: C
|
|
54
55
|
};
|
|
55
|
-
let w = (e) => (i.danger("interactions", /* @__PURE__ */
|
|
56
|
+
let w = (e) => (i.danger("interactions", /* @__PURE__ */ f("span", { children: ["Interaction node failed ", /* @__PURE__ */ d("b", { children: _ })] }), {
|
|
56
57
|
error: e instanceof Error ? e.message : String(e),
|
|
57
58
|
node: r
|
|
58
59
|
}), {
|
|
59
60
|
status: "failed",
|
|
60
61
|
result: {},
|
|
61
|
-
postCallbacks:
|
|
62
|
+
postCallbacks: p,
|
|
62
63
|
whenParams: C
|
|
63
64
|
}), T;
|
|
64
65
|
switch (x) {
|
|
65
66
|
case "callback":
|
|
66
67
|
case "globalCallback":
|
|
67
|
-
if (!b) return i.warning("interactions", /* @__PURE__ */
|
|
68
|
+
if (!b) return i.warning("interactions", /* @__PURE__ */ f("span", { children: [
|
|
68
69
|
"Step ",
|
|
69
|
-
/* @__PURE__ */
|
|
70
|
+
/* @__PURE__ */ d("b", { children: _ }),
|
|
70
71
|
" names no element, so there is nothing to run it on"
|
|
71
72
|
] }), { node: r }), {
|
|
72
73
|
status: "failed",
|
|
73
74
|
result: {},
|
|
74
|
-
postCallbacks:
|
|
75
|
+
postCallbacks: p,
|
|
75
76
|
whenParams: C
|
|
76
77
|
};
|
|
77
|
-
if (T = n(s, `${b}.${_}`), !T) return i.warning("interactions", /* @__PURE__ */
|
|
78
|
+
if (T = n(s, `${b}.${_}`), !T) return i.warning("interactions", /* @__PURE__ */ f("span", { children: [
|
|
78
79
|
"Nothing is registered as ",
|
|
79
|
-
/* @__PURE__ */
|
|
80
|
+
/* @__PURE__ */ d("b", { children: `${b}.${_}` }),
|
|
80
81
|
", so this step did nothing"
|
|
81
82
|
] }), {
|
|
82
83
|
node: r,
|
|
@@ -84,7 +85,7 @@ var f = 5, p = (e, t, n, r, a) => {
|
|
|
84
85
|
}), {
|
|
85
86
|
status: "failed",
|
|
86
87
|
result: {},
|
|
87
|
-
postCallbacks:
|
|
88
|
+
postCallbacks: p,
|
|
88
89
|
whenParams: C
|
|
89
90
|
};
|
|
90
91
|
break;
|
|
@@ -94,7 +95,7 @@ var f = 5, p = (e, t, n, r, a) => {
|
|
|
94
95
|
default: return {
|
|
95
96
|
status: "success",
|
|
96
97
|
result: {},
|
|
97
|
-
postCallbacks:
|
|
98
|
+
postCallbacks: p,
|
|
98
99
|
whenParams: C
|
|
99
100
|
};
|
|
100
101
|
}
|
|
@@ -102,8 +103,8 @@ var f = 5, p = (e, t, n, r, a) => {
|
|
|
102
103
|
let t = {
|
|
103
104
|
...c,
|
|
104
105
|
...l,
|
|
105
|
-
...e(T.params,
|
|
106
|
-
}, { callback: n, postCallback: r } = T, i = (e) => (r &&
|
|
106
|
+
...e(T.params, m(x, y, c, l, _))
|
|
107
|
+
}, { callback: n, postCallback: r } = T, i = (e) => (r && p.push({
|
|
107
108
|
id: g,
|
|
108
109
|
callback: r,
|
|
109
110
|
params: {
|
|
@@ -113,45 +114,45 @@ var f = 5, p = (e, t, n, r, a) => {
|
|
|
113
114
|
}), {
|
|
114
115
|
status: "success",
|
|
115
116
|
result: e,
|
|
116
|
-
postCallbacks:
|
|
117
|
+
postCallbacks: p,
|
|
117
118
|
whenParams: C
|
|
118
|
-
}), a = n ? n(t,
|
|
119
|
-
return
|
|
119
|
+
}), a = n ? n(t, u) : {};
|
|
120
|
+
return h(a) ? Promise.resolve(a).then(i, w) : i(a);
|
|
120
121
|
} catch (e) {
|
|
121
122
|
return w(e);
|
|
122
123
|
}
|
|
123
|
-
},
|
|
124
|
+
}, _ = async (e = []) => {
|
|
124
125
|
let t = {};
|
|
125
126
|
return await Promise.all(e.reverse().map(async ({ id: e, callback: n, params: i }) => {
|
|
126
127
|
t[e] = await n?.(r(i, [e]), i[e]);
|
|
127
128
|
})), t;
|
|
128
|
-
},
|
|
129
|
+
}, v = () => ({}), y = async (e, t = {}, r = {}, a = {}, o = v, s = [], c = {}, l = {}) => {
|
|
129
130
|
let u = e, d = a;
|
|
130
131
|
for (; u;) {
|
|
131
132
|
if (l.signal?.aborted) return c;
|
|
132
133
|
let e = n(t, u.afterNode);
|
|
133
|
-
if (!e) return s.length > 0 && await
|
|
134
|
-
let a = i.getTime().valueOf(), f =
|
|
134
|
+
if (!e) return s.length > 0 && await _(s), c;
|
|
135
|
+
let a = i.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;
|
|
135
136
|
c[e.id] = {
|
|
136
137
|
node: e,
|
|
137
138
|
status: b,
|
|
138
|
-
result:
|
|
139
|
+
result: m,
|
|
139
140
|
postCallbacks: v,
|
|
140
141
|
whenParams: y,
|
|
141
142
|
startTime: a,
|
|
142
143
|
endTime: i.getTime().valueOf()
|
|
143
144
|
}, s.push(...v), d = {
|
|
144
145
|
...d,
|
|
145
|
-
[e.id]:
|
|
146
|
+
[e.id]: m
|
|
146
147
|
}, u = e;
|
|
147
148
|
}
|
|
148
149
|
return c;
|
|
149
|
-
},
|
|
150
|
-
let o = i.getTime().valueOf(), s = r === "skipped" ? "skipped" : "success", c = /* @__PURE__ */
|
|
150
|
+
}, b = (e, t, n = {}, r, a) => {
|
|
151
|
+
let o = i.getTime().valueOf(), s = r === "skipped" ? "skipped" : "success", c = /* @__PURE__ */ f("span", { children: [
|
|
151
152
|
"Interaction triggered ",
|
|
152
|
-
/* @__PURE__ */
|
|
153
|
-
a ? /* @__PURE__ */
|
|
154
|
-
] }),
|
|
153
|
+
/* @__PURE__ */ d("b", { children: `${e.title} [${e.action}]` }),
|
|
154
|
+
a ? /* @__PURE__ */ f(u, { children: [" on ", /* @__PURE__ */ d("b", { children: a })] }) : null
|
|
155
|
+
] }), l = {
|
|
155
156
|
status: r,
|
|
156
157
|
node: e,
|
|
157
158
|
elementId: e.elementId,
|
|
@@ -170,20 +171,29 @@ var f = 5, p = (e, t, n, r, a) => {
|
|
|
170
171
|
startTime: t,
|
|
171
172
|
endTime: o
|
|
172
173
|
};
|
|
173
|
-
r === "failed" ? i.danger("interactions", c,
|
|
174
|
-
},
|
|
175
|
-
let
|
|
176
|
-
if (!
|
|
177
|
-
...
|
|
174
|
+
r === "failed" ? i.danger("interactions", c, l) : i.info("interactions", c, l);
|
|
175
|
+
}, x = (e) => Object.values(e).some(({ status: e }) => e === "failed") ? "failed" : "completed", S = async (e, t = {}, n = {}, r = {}, c = v, l, u, d = []) => {
|
|
176
|
+
let f = i.getTime().valueOf(), { action: p, enabled: m, when: h } = e;
|
|
177
|
+
if (!p || !m || h && !a(h, o({
|
|
178
|
+
...c(),
|
|
178
179
|
...r
|
|
179
180
|
}))) {
|
|
180
|
-
|
|
181
|
+
b(e, f, {}, "skipped", l);
|
|
181
182
|
return;
|
|
182
183
|
}
|
|
183
|
-
let
|
|
184
|
-
|
|
185
|
-
...l ? {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
184
|
+
let g = s({
|
|
185
|
+
trigger: `${e.title} [${e.action}]`,
|
|
186
|
+
...l ? { on: l } : {},
|
|
187
|
+
since: f
|
|
188
|
+
}), _;
|
|
189
|
+
try {
|
|
190
|
+
_ = await y(e, t, n, r, c, d, {}, {
|
|
191
|
+
hostElementId: l,
|
|
192
|
+
...u ? { signal: u } : {}
|
|
193
|
+
});
|
|
194
|
+
} finally {
|
|
195
|
+
g();
|
|
196
|
+
}
|
|
197
|
+
b(e, f, _, x(_), l);
|
|
198
|
+
}, C = { flowTrigger: S };
|
|
199
|
+
export { C as default, S as flowTrigger };
|
|
@@ -5,10 +5,10 @@ import i from "../../InteractionsContext.mjs";
|
|
|
5
5
|
import { use as a, useCallback as o, useMemo as s } from "react";
|
|
6
6
|
import { pConsole as c } from "@plitzi/sdk-shared/devTools";
|
|
7
7
|
import { toBuilderParams as l, toInteractionCallbacks as u } from "@plitzi/sdk-shared/authoring";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
8
|
+
import { authFailureFromResponse as d, reportAuthFailure as f } from "@plitzi/sdk-shared/auth";
|
|
9
|
+
import { invalidateAfterWrite as p } from "@plitzi/sdk-shared/queries";
|
|
10
|
+
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
11
|
+
import { recordActionProgress as g, recordActionRun as _, registerActionCanceller as v, releaseActionCanceller as y, updateActionRun as b, useCommonStore as x } from "@plitzi/sdk-shared/store";
|
|
12
12
|
// src/sources/ActionsSource/ActionInteractions.tsx
|
|
13
13
|
var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
14
14
|
let n = e.getReader(), r = new TextDecoder(), i = "";
|
|
@@ -52,8 +52,8 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
52
52
|
error: t instanceof Error ? t.message : String(t)
|
|
53
53
|
}, D = (e, t, n) => {
|
|
54
54
|
if (e !== 401) return;
|
|
55
|
-
let r =
|
|
56
|
-
r &&
|
|
55
|
+
let r = d(e, t);
|
|
56
|
+
r && f({
|
|
57
57
|
reason: r,
|
|
58
58
|
url: n
|
|
59
59
|
});
|
|
@@ -70,14 +70,14 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
70
70
|
error: t.error ?? "",
|
|
71
71
|
reason: t.reason ?? "failed",
|
|
72
72
|
...t.code ? { code: t.code } : {}
|
|
73
|
-
}), A = ({ children:
|
|
74
|
-
let { useInteractions:
|
|
73
|
+
}), A = ({ children: d }) => {
|
|
74
|
+
let { useInteractions: f, interactionsManager: A } = a(i), [j] = x("actions.endpoint"), [[M, N]] = x(["actions.catalog", "actions.available"]), P = o((e, t, n) => {
|
|
75
75
|
e && A.interactionTrigger(e, t, n);
|
|
76
76
|
}, [A]), F = o(async (e, n) => {
|
|
77
77
|
let { actionId: i, mode: a = "await", idempotencyKey: o } = e;
|
|
78
|
-
if (!j) return c.warning("actions", /* @__PURE__ */
|
|
78
|
+
if (!j) return c.warning("actions", /* @__PURE__ */ h("span", { children: [
|
|
79
79
|
"Server action ",
|
|
80
|
-
/* @__PURE__ */
|
|
80
|
+
/* @__PURE__ */ m("b", { children: i }),
|
|
81
81
|
" was skipped: this page is served without a Plitzi server"
|
|
82
82
|
] }), {
|
|
83
83
|
actionId: i,
|
|
@@ -96,12 +96,12 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
96
96
|
actionId: i,
|
|
97
97
|
input: s,
|
|
98
98
|
...o ? { idempotencyKey: o } : {}
|
|
99
|
-
}, u = JSON.stringify(l),
|
|
99
|
+
}, u = JSON.stringify(l), d = _({
|
|
100
100
|
actionId: i,
|
|
101
101
|
mode: a,
|
|
102
102
|
input: s
|
|
103
|
-
}),
|
|
104
|
-
|
|
103
|
+
}), f = new AbortController(), x = "", A = () => {
|
|
104
|
+
f.abort(), b(d, {
|
|
105
105
|
status: "aborted",
|
|
106
106
|
endedAt: Date.now(),
|
|
107
107
|
cancellable: !1
|
|
@@ -110,23 +110,23 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
110
110
|
credentials: "include"
|
|
111
111
|
}).catch(() => void 0);
|
|
112
112
|
};
|
|
113
|
-
|
|
113
|
+
v(d, A);
|
|
114
114
|
let M = n?.signal;
|
|
115
115
|
M?.addEventListener("abort", A, { once: !0 });
|
|
116
116
|
let N = (t) => {
|
|
117
|
-
M?.removeEventListener("abort", A),
|
|
117
|
+
M?.removeEventListener("abort", A), y(d), b(d, {
|
|
118
118
|
endedAt: Date.now(),
|
|
119
119
|
cancellable: !1,
|
|
120
120
|
...t
|
|
121
|
-
}), t.status === "completed" &&
|
|
121
|
+
}), t.status === "completed" && p({
|
|
122
122
|
mode: e.invalidateQueries,
|
|
123
123
|
fallback: "all",
|
|
124
124
|
elements: e.invalidateElements
|
|
125
125
|
});
|
|
126
126
|
}, F = () => {
|
|
127
|
-
|
|
127
|
+
b(d, { status: "queued" }), c.info("actions", /* @__PURE__ */ h("span", { children: [
|
|
128
128
|
"Server action ",
|
|
129
|
-
/* @__PURE__ */
|
|
129
|
+
/* @__PURE__ */ m("b", { children: i }),
|
|
130
130
|
" is waiting: nothing could run it now, and it runs as soon as something can"
|
|
131
131
|
] }), {
|
|
132
132
|
actionId: i,
|
|
@@ -134,9 +134,9 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
134
134
|
status: "queued"
|
|
135
135
|
});
|
|
136
136
|
};
|
|
137
|
-
if (a === "detached") return c.info("actions", /* @__PURE__ */
|
|
137
|
+
if (a === "detached") return c.info("actions", /* @__PURE__ */ h("span", { children: [
|
|
138
138
|
"Server action ",
|
|
139
|
-
/* @__PURE__ */
|
|
139
|
+
/* @__PURE__ */ m("b", { children: i }),
|
|
140
140
|
" sent"
|
|
141
141
|
] }), {
|
|
142
142
|
actionId: i,
|
|
@@ -145,15 +145,15 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
145
145
|
}), t({
|
|
146
146
|
endpoint: j,
|
|
147
147
|
call: l,
|
|
148
|
-
signal:
|
|
148
|
+
signal: f.signal,
|
|
149
149
|
keepalive: !0,
|
|
150
150
|
onQueued: F
|
|
151
151
|
}).then((e) => {
|
|
152
152
|
if ("unreachable" in e) throw e.unreachable;
|
|
153
153
|
let { status: t, payload: r } = e;
|
|
154
|
-
t < 200 || t >= 300 ? (D(t, r, j), N(O(r)), P(n?.hostElementId, "onFlowError", k(i, r))) : r.status === "failed" ? (N(O(r)), c.warning("actions", /* @__PURE__ */
|
|
154
|
+
t < 200 || t >= 300 ? (D(t, r, j), N(O(r)), P(n?.hostElementId, "onFlowError", k(i, r))) : r.status === "failed" ? (N(O(r)), c.warning("actions", /* @__PURE__ */ h("span", { children: [
|
|
155
155
|
"Server action ",
|
|
156
|
-
/* @__PURE__ */
|
|
156
|
+
/* @__PURE__ */ m("b", { children: i }),
|
|
157
157
|
" failed"
|
|
158
158
|
] }), {
|
|
159
159
|
actionId: i,
|
|
@@ -167,9 +167,9 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
167
167
|
...r.output ? { output: r.output } : {},
|
|
168
168
|
...r.steps ? { steps: r.steps } : {},
|
|
169
169
|
...r.trace ? { trace: r.trace } : {}
|
|
170
|
-
}), c.success("actions", /* @__PURE__ */
|
|
170
|
+
}), c.success("actions", /* @__PURE__ */ h("span", { children: [
|
|
171
171
|
"Server action ",
|
|
172
|
-
/* @__PURE__ */
|
|
172
|
+
/* @__PURE__ */ m("b", { children: i }),
|
|
173
173
|
" finished"
|
|
174
174
|
] }), {
|
|
175
175
|
actionId: i,
|
|
@@ -184,9 +184,9 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
184
184
|
output: r.output ?? {}
|
|
185
185
|
}));
|
|
186
186
|
}).catch((e) => {
|
|
187
|
-
N(E(
|
|
187
|
+
N(E(f, e)), c.warning("actions", /* @__PURE__ */ h("span", { children: [
|
|
188
188
|
"Server action ",
|
|
189
|
-
/* @__PURE__ */
|
|
189
|
+
/* @__PURE__ */ m("b", { children: i }),
|
|
190
190
|
" could not be sent"
|
|
191
191
|
] }), {
|
|
192
192
|
actionId: i,
|
|
@@ -205,9 +205,9 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
205
205
|
output: {}
|
|
206
206
|
};
|
|
207
207
|
if (a === "stream") {
|
|
208
|
-
c.info("actions", /* @__PURE__ */
|
|
208
|
+
c.info("actions", /* @__PURE__ */ h("span", { children: [
|
|
209
209
|
"Server action ",
|
|
210
|
-
/* @__PURE__ */
|
|
210
|
+
/* @__PURE__ */ m("b", { children: i }),
|
|
211
211
|
" streaming"
|
|
212
212
|
] }), {
|
|
213
213
|
actionId: i,
|
|
@@ -223,13 +223,13 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
223
223
|
Accept: "text/event-stream"
|
|
224
224
|
},
|
|
225
225
|
credentials: "include",
|
|
226
|
-
signal:
|
|
226
|
+
signal: f.signal,
|
|
227
227
|
body: u
|
|
228
228
|
});
|
|
229
229
|
} catch (e) {
|
|
230
|
-
return N(E(
|
|
230
|
+
return N(E(f, e)), c.warning("actions", /* @__PURE__ */ h("span", { children: [
|
|
231
231
|
"Server action ",
|
|
232
|
-
/* @__PURE__ */
|
|
232
|
+
/* @__PURE__ */ m("b", { children: i }),
|
|
233
233
|
" could not be reached"
|
|
234
234
|
] }), {
|
|
235
235
|
actionId: i,
|
|
@@ -253,11 +253,11 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
253
253
|
};
|
|
254
254
|
}
|
|
255
255
|
let t = e.headers.get("X-Plitzi-Run-Id") ?? "";
|
|
256
|
-
return x = t,
|
|
256
|
+
return x = t, b(d, {
|
|
257
257
|
status: "streaming",
|
|
258
258
|
...t ? { runId: t } : {}
|
|
259
259
|
}), C(e.body, (e) => {
|
|
260
|
-
if (e.event === "data")
|
|
260
|
+
if (e.event === "data") g(d, e.data.chunk ?? e.data), P(n?.hostElementId, "onFlowProgress", {
|
|
261
261
|
actionId: i,
|
|
262
262
|
runId: t,
|
|
263
263
|
...e.data
|
|
@@ -288,14 +288,14 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
290
|
}).catch((e) => {
|
|
291
|
-
if (
|
|
291
|
+
if (f.signal.aborted) return;
|
|
292
292
|
let r = e instanceof Error ? e.message : String(e);
|
|
293
293
|
N({
|
|
294
294
|
status: "failed",
|
|
295
295
|
error: r
|
|
296
|
-
}), c.warning("actions", /* @__PURE__ */
|
|
296
|
+
}), c.warning("actions", /* @__PURE__ */ h("span", { children: [
|
|
297
297
|
"Server action ",
|
|
298
|
-
/* @__PURE__ */
|
|
298
|
+
/* @__PURE__ */ m("b", { children: i }),
|
|
299
299
|
" stopped mid-stream"
|
|
300
300
|
] }), {
|
|
301
301
|
actionId: i,
|
|
@@ -320,13 +320,13 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
320
320
|
if (I = await t({
|
|
321
321
|
endpoint: j,
|
|
322
322
|
call: l,
|
|
323
|
-
signal:
|
|
323
|
+
signal: f.signal,
|
|
324
324
|
onQueued: F
|
|
325
325
|
}), "unreachable" in I) throw I.unreachable;
|
|
326
326
|
} catch (e) {
|
|
327
|
-
return N(E(
|
|
327
|
+
return N(E(f, e)), c.warning("interactions", /* @__PURE__ */ h("span", { children: [
|
|
328
328
|
"Server action ",
|
|
329
|
-
/* @__PURE__ */
|
|
329
|
+
/* @__PURE__ */ m("b", { children: i }),
|
|
330
330
|
" could not be reached"
|
|
331
331
|
] }), {
|
|
332
332
|
actionId: i,
|
|
@@ -339,9 +339,9 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
339
339
|
}), T;
|
|
340
340
|
}
|
|
341
341
|
let { status: L, payload: R } = I;
|
|
342
|
-
return L < 200 || L >= 300 ? (D(L, R, j), N(O(R)), P(n?.hostElementId, "onFlowError", k(i, R)), c.warning("actions", /* @__PURE__ */
|
|
342
|
+
return L < 200 || L >= 300 ? (D(L, R, j), N(O(R)), P(n?.hostElementId, "onFlowError", k(i, R)), c.warning("actions", /* @__PURE__ */ h("span", { children: [
|
|
343
343
|
"Server action ",
|
|
344
|
-
/* @__PURE__ */
|
|
344
|
+
/* @__PURE__ */ m("b", { children: i }),
|
|
345
345
|
" was refused"
|
|
346
346
|
] }), {
|
|
347
347
|
actionId: i,
|
|
@@ -377,9 +377,9 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
377
377
|
method: "DELETE",
|
|
378
378
|
credentials: "include"
|
|
379
379
|
})).status === 204;
|
|
380
|
-
return c.info("actions", /* @__PURE__ */
|
|
380
|
+
return c.info("actions", /* @__PURE__ */ h("span", { children: [
|
|
381
381
|
"Server action run ",
|
|
382
|
-
/* @__PURE__ */
|
|
382
|
+
/* @__PURE__ */ m("b", { children: e.runId }),
|
|
383
383
|
" ",
|
|
384
384
|
t ? "cancelled" : "was not cancelled"
|
|
385
385
|
] }), {
|
|
@@ -395,7 +395,7 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
395
395
|
label: `${e.name} (${e.identifier})`,
|
|
396
396
|
value: e.identifier
|
|
397
397
|
})), [M]);
|
|
398
|
-
|
|
398
|
+
f({
|
|
399
399
|
id: "actions",
|
|
400
400
|
callbacks: s(() => u(e, {
|
|
401
401
|
cancelServerAction: I,
|
|
@@ -432,9 +432,9 @@ var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
|
432
432
|
idempotencyKey: n,
|
|
433
433
|
invalidateQueries: r
|
|
434
434
|
}), [F]);
|
|
435
|
-
return /* @__PURE__ */
|
|
435
|
+
return /* @__PURE__ */ m(n, {
|
|
436
436
|
value: R,
|
|
437
|
-
children:
|
|
437
|
+
children: d
|
|
438
438
|
});
|
|
439
439
|
};
|
|
440
440
|
export { A as default };
|
package/dist/utility/webHook.mjs
CHANGED
|
@@ -1,71 +1,76 @@
|
|
|
1
1
|
import { webHookSpec as e } from "./webHookSpec.mjs";
|
|
2
2
|
import { toInteractionCallback as t } from "@plitzi/sdk-shared/authoring";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { authFailureFromResponse as n, reportAuthFailure as r } from "@plitzi/sdk-shared/auth";
|
|
4
|
+
import { csrfFetch as i } from "@plitzi/sdk-shared/csrf";
|
|
5
|
+
import { invalidateAfterWrite as a, queryCache as o, requestKey as s } from "@plitzi/sdk-shared/queries";
|
|
5
6
|
// src/utility/webHook.ts
|
|
6
|
-
var
|
|
7
|
+
var c = /* @__PURE__ */ new Set(["GET", "HEAD"]), l = /* @__PURE__ */ new Set([
|
|
7
8
|
"GET",
|
|
8
9
|
"HEAD",
|
|
9
10
|
"DELETE"
|
|
10
|
-
]),
|
|
11
|
+
]), u = (t) => {
|
|
11
12
|
let n = Number(t);
|
|
12
13
|
return (Number.isFinite(n) && n >= 0 ? n : Number(e.params.staleTime.default)) * 1e3;
|
|
13
|
-
},
|
|
14
|
-
let
|
|
15
|
-
method:
|
|
14
|
+
}, d = (e) => e ? { Authorization: `Bearer ${e}` } : {}, f = (e) => typeof e == "object" && e ? e : {}, p = /* @__PURE__ */ new Set(["authorization", "content-type"]), m = (e) => typeof e == "object" && e ? Object.fromEntries(Object.entries(e).flatMap(([e, t]) => (typeof t == "string" || typeof t == "number") && t !== "" && !p.has(e.toLowerCase()) ? [[e, String(t)]] : [])) : {}, h = async (e, t, a, o = !1) => {
|
|
15
|
+
let { url: s, authorizationToken: c, headers: u, body: p, credentials: g } = e, _ = f(p), v = Object.values(_).some((e) => e instanceof Blob), y = {
|
|
16
|
+
method: t,
|
|
16
17
|
headers: {
|
|
17
|
-
...
|
|
18
|
-
...
|
|
19
|
-
...
|
|
18
|
+
...m(u),
|
|
19
|
+
...v ? {} : { "Content-Type": "application/json" },
|
|
20
|
+
...d(c)
|
|
20
21
|
},
|
|
21
|
-
credentials:
|
|
22
|
-
...
|
|
22
|
+
credentials: g,
|
|
23
|
+
...a ? { signal: a } : {}
|
|
23
24
|
};
|
|
24
|
-
if (!
|
|
25
|
-
if (!
|
|
25
|
+
if (!l.has(t)) {
|
|
26
|
+
if (!v) y.body = JSON.stringify(_);
|
|
26
27
|
else {
|
|
27
28
|
let e = new FormData();
|
|
28
|
-
Object.entries(
|
|
29
|
+
Object.entries(_).forEach(([t, n]) => {
|
|
29
30
|
e.append(t, n);
|
|
30
|
-
}),
|
|
31
|
+
}), y.body = e;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
let
|
|
34
|
-
throw Error(`${
|
|
35
|
-
}),
|
|
34
|
+
let b = await i(s, y).catch((e) => {
|
|
35
|
+
throw Error(`${t} ${s} got no answer: ${e instanceof Error ? e.message : String(e)}`);
|
|
36
|
+
}), x = "";
|
|
36
37
|
try {
|
|
37
|
-
|
|
38
|
+
x = await b.json();
|
|
38
39
|
} catch {}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
let S = n(b.status, x);
|
|
41
|
+
return S && await r({
|
|
42
|
+
reason: S,
|
|
43
|
+
url: s
|
|
44
|
+
}) && !o && !c && !a?.aborted ? h(e, t, a, !0) : {
|
|
45
|
+
status: b.status,
|
|
46
|
+
data: x
|
|
42
47
|
};
|
|
43
|
-
},
|
|
48
|
+
}, g = t("webHook", e, async (e, t) => {
|
|
44
49
|
let n = (e.method || "get").toUpperCase();
|
|
45
|
-
if (
|
|
46
|
-
if (e.cache !== !0 && e.cache !== "true") return { response: await
|
|
47
|
-
let r =
|
|
50
|
+
if (c.has(n)) {
|
|
51
|
+
if (e.cache !== !0 && e.cache !== "true") return { response: await h(e, n, t?.signal) };
|
|
52
|
+
let r = s({
|
|
48
53
|
method: n,
|
|
49
54
|
url: e.url,
|
|
50
55
|
credentials: e.credentials,
|
|
51
56
|
headers: {
|
|
52
|
-
...
|
|
53
|
-
...
|
|
57
|
+
...m(e.headers),
|
|
58
|
+
...d(e.authorizationToken)
|
|
54
59
|
}
|
|
55
60
|
});
|
|
56
|
-
return { response: await
|
|
61
|
+
return { response: await o.fetchQuery(r, {
|
|
57
62
|
meta: { url: e.url },
|
|
58
|
-
fetcher: () =>
|
|
59
|
-
staleTime:
|
|
63
|
+
fetcher: () => h(e, n),
|
|
64
|
+
staleTime: u(e.staleTime),
|
|
60
65
|
isCacheable: (e) => e.status < 400
|
|
61
66
|
}) };
|
|
62
67
|
}
|
|
63
|
-
let
|
|
64
|
-
return
|
|
68
|
+
let r = await h(e, n, t?.signal);
|
|
69
|
+
return r.status >= 200 && r.status < 300 && a({
|
|
65
70
|
mode: e.invalidateQueries,
|
|
66
71
|
fallback: "origin",
|
|
67
72
|
elements: e.invalidateElements,
|
|
68
73
|
url: e.url
|
|
69
|
-
}), { response:
|
|
74
|
+
}), { response: r };
|
|
70
75
|
});
|
|
71
|
-
export {
|
|
76
|
+
export { g as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plitzi/sdk-interactions",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.17",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@plitzi/nexus": "^1.5.1",
|
|
42
|
-
"@plitzi/plitzi-ui": "^1.6.
|
|
43
|
-
"@plitzi/sdk-auth": "0.39.
|
|
44
|
-
"@plitzi/sdk-event-bridge": "0.39.
|
|
45
|
-
"@plitzi/sdk-shared": "0.39.
|
|
42
|
+
"@plitzi/plitzi-ui": "^1.6.42",
|
|
43
|
+
"@plitzi/sdk-auth": "0.39.17",
|
|
44
|
+
"@plitzi/sdk-event-bridge": "0.39.17",
|
|
45
|
+
"@plitzi/sdk-shared": "0.39.17"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"react": "^19"
|