@plitzi/sdk-interactions 0.39.1 → 0.39.2
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 +11 -0
- package/dist/InteractionsContext.mjs +1 -2
- package/dist/InteractionsContextProvider.mjs +5 -6
- package/dist/InteractionsHelper.mjs +40 -42
- package/dist/InteractionsManager.d.ts +13 -0
- package/dist/InteractionsManager.mjs +79 -37
- package/dist/InteractionsSourcesProvider.mjs +1 -2
- package/dist/declarations/index.mjs +9 -9
- package/dist/helpers/coerceDeclaredParams.mjs +1 -2
- package/dist/hooks/useInteractions.mjs +1 -2
- package/dist/index.mjs +6 -6
- package/dist/sources/ActionsSource/ActionInteractions.mjs +205 -196
- package/dist/sources/ActionsSource/ServerActionContext.mjs +2 -3
- package/dist/sources/ActionsSource/callbacks.mjs +1 -2
- package/dist/sources/ActionsSource/deliverCall.d.ts +45 -0
- package/dist/sources/ActionsSource/deliverCall.mjs +80 -0
- package/dist/sources/ActionsSource/index.mjs +3 -3
- package/dist/sources/AuthSource/AuthInteractions.mjs +5 -6
- package/dist/sources/AuthSource/callbacks.mjs +1 -2
- package/dist/sources/HostSource/HostInteractions.mjs +5 -6
- package/dist/sources/HostSource/callbacks.mjs +1 -2
- package/dist/sources/HostSource/index.mjs +3 -3
- package/dist/sources/NavigationSource/NavigationInteractions.mjs +9 -10
- package/dist/sources/NavigationSource/callbacks.mjs +1 -2
- package/dist/sources/NavigationSource/navigateHow.mjs +1 -2
- package/dist/sources/QueriesSource/QueriesInteractions.mjs +5 -6
- package/dist/sources/QueriesSource/callbacks.mjs +1 -2
- package/dist/sources/QueriesSource/writeParams.mjs +1 -2
- package/dist/sources/StateSource/StateInteractions.mjs +5 -6
- package/dist/sources/StateSource/callbacks.mjs +1 -2
- package/dist/utility/copyToClipboard.mjs +1 -2
- package/dist/utility/copyToClipboardSpec.mjs +1 -2
- package/dist/utility/delayTime.mjs +1 -2
- package/dist/utility/index.mjs +1 -2
- package/dist/utility/twigTemplate.mjs +1 -2
- package/dist/utility/webHook.mjs +1 -2
- package/dist/utility/webHookSpec.mjs +1 -2
- package/package.json +14 -11
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import e from "
|
|
2
|
-
import {
|
|
1
|
+
import { actionsCallbacks as e } from "./callbacks.mjs";
|
|
2
|
+
import { deliverCall as t } from "./deliverCall.mjs";
|
|
3
3
|
import { ServerActionContext as n, endedStatusOf as r } from "./ServerActionContext.mjs";
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
import i from "../../InteractionsContext.mjs";
|
|
5
|
+
import { use as a, useCallback as o, useMemo as s } from "react";
|
|
6
|
+
import { pConsole as c } from "@plitzi/sdk-shared/devTools";
|
|
7
|
+
import { toBuilderParams as l, toInteractionCallbacks as u } from "@plitzi/sdk-shared/authoring";
|
|
8
|
+
import { invalidateAfterWrite as d } from "@plitzi/sdk-shared/queries";
|
|
9
|
+
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
10
|
+
import { recordActionProgress as m, recordActionRun as h, registerActionCanceller as g, releaseActionCanceller as _, updateActionRun as v, useCommonStore as y } from "@plitzi/sdk-shared/store";
|
|
11
|
+
import { authFailureFromResponse as b, reportAuthFailure as x } from "@plitzi/sdk-shared/auth";
|
|
12
|
+
// src/sources/ActionsSource/ActionInteractions.tsx
|
|
13
|
+
var S = (e) => Array.isArray(e) ? e : void 0, C = async (e, t) => {
|
|
13
14
|
let n = e.getReader(), r = new TextDecoder(), i = "";
|
|
14
15
|
for (;;) {
|
|
15
16
|
let { done: e, value: a } = await n.read();
|
|
@@ -29,7 +30,7 @@ var x = (e) => Array.isArray(e) ? e : void 0, S = async (e, t) => {
|
|
|
29
30
|
} catch {}
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
|
-
},
|
|
33
|
+
}, w = (e) => {
|
|
33
34
|
if (!e) return {};
|
|
34
35
|
if (typeof e == "object") return e;
|
|
35
36
|
try {
|
|
@@ -38,151 +39,161 @@ var x = (e) => Array.isArray(e) ? e : void 0, S = async (e, t) => {
|
|
|
38
39
|
} catch {
|
|
39
40
|
return {};
|
|
40
41
|
}
|
|
41
|
-
},
|
|
42
|
+
}, T = {
|
|
42
43
|
status: "failed",
|
|
43
44
|
reason: "failed",
|
|
44
45
|
runId: "",
|
|
45
46
|
output: {}
|
|
46
|
-
},
|
|
47
|
+
}, E = (e, t) => e.signal.aborted ? {
|
|
47
48
|
status: "aborted",
|
|
48
49
|
error: "Cancelled"
|
|
49
50
|
} : {
|
|
50
51
|
status: "failed",
|
|
51
52
|
error: t instanceof Error ? t.message : String(t)
|
|
52
|
-
},
|
|
53
|
+
}, D = (e, t, n) => {
|
|
53
54
|
if (e !== 401) return;
|
|
54
|
-
let r =
|
|
55
|
-
r &&
|
|
55
|
+
let r = b(e, t);
|
|
56
|
+
r && x({
|
|
56
57
|
reason: r,
|
|
57
58
|
url: n
|
|
58
59
|
});
|
|
59
|
-
},
|
|
60
|
+
}, O = (e) => ({
|
|
60
61
|
status: "failed",
|
|
61
62
|
...e.runId ? { runId: e.runId } : {},
|
|
62
63
|
...e.reason ? { reason: e.reason } : {},
|
|
63
64
|
...e.error ? { error: e.error } : {},
|
|
64
65
|
...e.steps ? { steps: e.steps } : {},
|
|
65
66
|
...e.trace ? { trace: e.trace } : {}
|
|
66
|
-
}),
|
|
67
|
+
}), k = (e, t) => ({
|
|
67
68
|
actionId: e,
|
|
68
69
|
runId: t.runId ?? "",
|
|
69
70
|
error: t.error ?? "",
|
|
70
71
|
reason: t.reason ?? "failed",
|
|
71
72
|
...t.code ? { code: t.code } : {}
|
|
72
|
-
}),
|
|
73
|
-
let { useInteractions:
|
|
74
|
-
e &&
|
|
75
|
-
}, [
|
|
76
|
-
let { actionId:
|
|
77
|
-
if (!
|
|
73
|
+
}), A = ({ children: b }) => {
|
|
74
|
+
let { useInteractions: x, interactionsManager: A } = a(i), [j] = y("actions.endpoint"), [[M, N]] = y(["actions.catalog", "actions.available"]), P = o((e, t, n) => {
|
|
75
|
+
e && A.interactionTrigger(e, t, n);
|
|
76
|
+
}, [A]), F = o(async (e, n) => {
|
|
77
|
+
let { actionId: i, mode: a = "await", idempotencyKey: o } = e;
|
|
78
|
+
if (!j) return c.warning("actions", /* @__PURE__ */ p("span", { children: [
|
|
78
79
|
"Server action ",
|
|
79
|
-
/* @__PURE__ */
|
|
80
|
+
/* @__PURE__ */ f("b", { children: i }),
|
|
80
81
|
" was skipped: this page is served without a Plitzi server"
|
|
81
82
|
] }), {
|
|
82
|
-
actionId:
|
|
83
|
+
actionId: i,
|
|
83
84
|
status: "skipped"
|
|
84
85
|
}), {
|
|
85
86
|
status: "skipped",
|
|
86
87
|
runId: "",
|
|
87
88
|
output: {}
|
|
88
89
|
};
|
|
89
|
-
if (!
|
|
90
|
+
if (!i) return {
|
|
90
91
|
status: "skipped",
|
|
91
92
|
runId: "",
|
|
92
93
|
output: {}
|
|
93
94
|
};
|
|
94
|
-
let
|
|
95
|
-
actionId:
|
|
96
|
-
input:
|
|
97
|
-
...
|
|
98
|
-
}
|
|
99
|
-
actionId:
|
|
100
|
-
mode:
|
|
101
|
-
input:
|
|
102
|
-
}),
|
|
103
|
-
|
|
95
|
+
let s = w(e.input), l = {
|
|
96
|
+
actionId: i,
|
|
97
|
+
input: s,
|
|
98
|
+
...o ? { idempotencyKey: o } : {}
|
|
99
|
+
}, u = JSON.stringify(l), y = h({
|
|
100
|
+
actionId: i,
|
|
101
|
+
mode: a,
|
|
102
|
+
input: s
|
|
103
|
+
}), b = new AbortController(), x = "", A = () => {
|
|
104
|
+
b.abort(), v(y, {
|
|
104
105
|
status: "aborted",
|
|
105
106
|
endedAt: Date.now(),
|
|
106
107
|
cancellable: !1
|
|
107
|
-
}),
|
|
108
|
+
}), x && fetch(`${j}/run/${x}`, {
|
|
108
109
|
method: "DELETE",
|
|
109
|
-
credentials: "
|
|
110
|
+
credentials: "include"
|
|
110
111
|
}).catch(() => void 0);
|
|
111
112
|
};
|
|
112
|
-
|
|
113
|
-
let
|
|
114
|
-
|
|
115
|
-
let
|
|
116
|
-
|
|
113
|
+
g(y, A);
|
|
114
|
+
let M = n?.signal;
|
|
115
|
+
M?.addEventListener("abort", A, { once: !0 });
|
|
116
|
+
let N = (t) => {
|
|
117
|
+
M?.removeEventListener("abort", A), _(y), v(y, {
|
|
117
118
|
endedAt: Date.now(),
|
|
118
119
|
cancellable: !1,
|
|
119
120
|
...t
|
|
120
|
-
}), t.status === "completed" &&
|
|
121
|
+
}), t.status === "completed" && d({
|
|
121
122
|
mode: e.invalidateQueries,
|
|
122
123
|
fallback: "all",
|
|
123
124
|
elements: e.invalidateElements
|
|
124
125
|
});
|
|
126
|
+
}, F = () => {
|
|
127
|
+
v(y, { status: "queued" }), c.info("actions", /* @__PURE__ */ p("span", { children: [
|
|
128
|
+
"Server action ",
|
|
129
|
+
/* @__PURE__ */ f("b", { children: i }),
|
|
130
|
+
" is waiting: nothing could run it now, and it runs as soon as something can"
|
|
131
|
+
] }), {
|
|
132
|
+
actionId: i,
|
|
133
|
+
mode: a,
|
|
134
|
+
status: "queued"
|
|
135
|
+
});
|
|
125
136
|
};
|
|
126
|
-
if (
|
|
137
|
+
if (a === "detached") return c.info("actions", /* @__PURE__ */ p("span", { children: [
|
|
127
138
|
"Server action ",
|
|
128
|
-
/* @__PURE__ */
|
|
139
|
+
/* @__PURE__ */ f("b", { children: i }),
|
|
129
140
|
" sent"
|
|
130
141
|
] }), {
|
|
131
|
-
actionId:
|
|
132
|
-
mode:
|
|
142
|
+
actionId: i,
|
|
143
|
+
mode: a,
|
|
133
144
|
status: "accepted"
|
|
134
|
-
}),
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
145
|
+
}), t({
|
|
146
|
+
endpoint: j,
|
|
147
|
+
call: l,
|
|
148
|
+
signal: b.signal,
|
|
138
149
|
keepalive: !0,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
let
|
|
143
|
-
|
|
150
|
+
onQueued: F
|
|
151
|
+
}).then((e) => {
|
|
152
|
+
if ("unreachable" in e) throw e.unreachable;
|
|
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__ */ p("span", { children: [
|
|
144
155
|
"Server action ",
|
|
145
|
-
/* @__PURE__ */
|
|
156
|
+
/* @__PURE__ */ f("b", { children: i }),
|
|
146
157
|
" failed"
|
|
147
158
|
] }), {
|
|
148
|
-
actionId:
|
|
149
|
-
mode:
|
|
159
|
+
actionId: i,
|
|
160
|
+
mode: a,
|
|
150
161
|
runId: r.runId,
|
|
151
162
|
reason: r.reason,
|
|
152
163
|
error: r.error
|
|
153
|
-
}),
|
|
164
|
+
}), P(n?.hostElementId, "onFlowError", k(i, r))) : (N({
|
|
154
165
|
status: r.status === "completed" ? "completed" : "accepted",
|
|
155
166
|
...r.runId ? { runId: r.runId } : {},
|
|
156
167
|
...r.output ? { output: r.output } : {},
|
|
157
168
|
...r.steps ? { steps: r.steps } : {},
|
|
158
169
|
...r.trace ? { trace: r.trace } : {}
|
|
159
|
-
}),
|
|
170
|
+
}), c.success("actions", /* @__PURE__ */ p("span", { children: [
|
|
160
171
|
"Server action ",
|
|
161
|
-
/* @__PURE__ */
|
|
172
|
+
/* @__PURE__ */ f("b", { children: i }),
|
|
162
173
|
" finished"
|
|
163
174
|
] }), {
|
|
164
|
-
actionId:
|
|
165
|
-
mode:
|
|
175
|
+
actionId: i,
|
|
176
|
+
mode: a,
|
|
166
177
|
runId: r.runId,
|
|
167
178
|
status: r.status,
|
|
168
179
|
output: r.output
|
|
169
|
-
}),
|
|
170
|
-
actionId:
|
|
180
|
+
}), P(n?.hostElementId, "onFlowEnd", {
|
|
181
|
+
actionId: i,
|
|
171
182
|
runId: r.runId ?? "",
|
|
172
183
|
status: r.status ?? "completed",
|
|
173
184
|
output: r.output ?? {}
|
|
174
|
-
}))
|
|
185
|
+
}));
|
|
175
186
|
}).catch((e) => {
|
|
176
|
-
|
|
187
|
+
N(E(b, e)), c.warning("actions", /* @__PURE__ */ p("span", { children: [
|
|
177
188
|
"Server action ",
|
|
178
|
-
/* @__PURE__ */
|
|
189
|
+
/* @__PURE__ */ f("b", { children: i }),
|
|
179
190
|
" could not be sent"
|
|
180
191
|
] }), {
|
|
181
|
-
actionId:
|
|
182
|
-
mode:
|
|
192
|
+
actionId: i,
|
|
193
|
+
mode: a,
|
|
183
194
|
error: e instanceof Error ? e.message : String(e)
|
|
184
|
-
}),
|
|
185
|
-
actionId:
|
|
195
|
+
}), P(n?.hostElementId, "onFlowError", {
|
|
196
|
+
actionId: i,
|
|
186
197
|
runId: "",
|
|
187
198
|
error: "",
|
|
188
199
|
reason: "failed"
|
|
@@ -193,183 +204,182 @@ var x = (e) => Array.isArray(e) ? e : void 0, S = async (e, t) => {
|
|
|
193
204
|
runId: "",
|
|
194
205
|
output: {}
|
|
195
206
|
};
|
|
196
|
-
if (
|
|
197
|
-
|
|
207
|
+
if (a === "stream") {
|
|
208
|
+
c.info("actions", /* @__PURE__ */ p("span", { children: [
|
|
198
209
|
"Server action ",
|
|
199
|
-
/* @__PURE__ */
|
|
210
|
+
/* @__PURE__ */ f("b", { children: i }),
|
|
200
211
|
" streaming"
|
|
201
212
|
] }), {
|
|
202
|
-
actionId:
|
|
203
|
-
mode:
|
|
213
|
+
actionId: i,
|
|
214
|
+
mode: a,
|
|
204
215
|
status: "streaming"
|
|
205
216
|
});
|
|
206
217
|
let e;
|
|
207
218
|
try {
|
|
208
|
-
e = await fetch(
|
|
219
|
+
e = await fetch(j, {
|
|
209
220
|
method: "POST",
|
|
210
221
|
headers: {
|
|
211
222
|
"Content-Type": "application/json",
|
|
212
223
|
Accept: "text/event-stream"
|
|
213
224
|
},
|
|
214
|
-
credentials: "
|
|
215
|
-
signal:
|
|
216
|
-
body:
|
|
225
|
+
credentials: "include",
|
|
226
|
+
signal: b.signal,
|
|
227
|
+
body: u
|
|
217
228
|
});
|
|
218
229
|
} catch (e) {
|
|
219
|
-
return
|
|
230
|
+
return N(E(b, e)), c.warning("actions", /* @__PURE__ */ p("span", { children: [
|
|
220
231
|
"Server action ",
|
|
221
|
-
/* @__PURE__ */
|
|
232
|
+
/* @__PURE__ */ f("b", { children: i }),
|
|
222
233
|
" could not be reached"
|
|
223
234
|
] }), {
|
|
224
|
-
actionId:
|
|
225
|
-
mode:
|
|
235
|
+
actionId: i,
|
|
236
|
+
mode: a,
|
|
226
237
|
error: e instanceof Error ? e.message : String(e)
|
|
227
|
-
}),
|
|
228
|
-
actionId:
|
|
238
|
+
}), P(n?.hostElementId, "onFlowError", {
|
|
239
|
+
actionId: i,
|
|
229
240
|
runId: "",
|
|
230
241
|
error: "",
|
|
231
242
|
reason: "failed"
|
|
232
|
-
}),
|
|
243
|
+
}), T;
|
|
233
244
|
}
|
|
234
245
|
if (!e.ok || !e.body) {
|
|
235
|
-
let
|
|
236
|
-
return
|
|
246
|
+
let t = await e.json().catch(() => ({}));
|
|
247
|
+
return D(e.status, t, j), N(O(t)), P(n?.hostElementId, "onFlowError", k(i, t)), {
|
|
237
248
|
status: "failed",
|
|
238
|
-
reason:
|
|
249
|
+
reason: t.reason ?? "failed",
|
|
239
250
|
runId: "",
|
|
240
251
|
output: {},
|
|
241
|
-
...
|
|
252
|
+
...t.error ? { error: t.error } : {}
|
|
242
253
|
};
|
|
243
254
|
}
|
|
244
|
-
let
|
|
245
|
-
return
|
|
255
|
+
let t = e.headers.get("X-Plitzi-Run-Id") ?? "";
|
|
256
|
+
return x = t, v(y, {
|
|
246
257
|
status: "streaming",
|
|
247
|
-
...
|
|
248
|
-
}),
|
|
249
|
-
if (e.event === "data")
|
|
250
|
-
actionId:
|
|
251
|
-
runId:
|
|
258
|
+
...t ? { runId: t } : {}
|
|
259
|
+
}), C(e.body, (e) => {
|
|
260
|
+
if (e.event === "data") m(y, e.data.chunk ?? e.data), P(n?.hostElementId, "onFlowProgress", {
|
|
261
|
+
actionId: i,
|
|
262
|
+
runId: t,
|
|
252
263
|
...e.data
|
|
253
264
|
});
|
|
254
265
|
else if (e.event === "error") {
|
|
255
|
-
let
|
|
256
|
-
|
|
266
|
+
let r = S(e.data.steps);
|
|
267
|
+
N({
|
|
257
268
|
status: "failed",
|
|
258
269
|
...typeof e.data.reason == "string" ? { reason: e.data.reason } : {},
|
|
259
270
|
...typeof e.data.error == "string" ? { error: e.data.error } : {},
|
|
260
|
-
...
|
|
261
|
-
}),
|
|
262
|
-
actionId:
|
|
263
|
-
runId:
|
|
271
|
+
...r ? { steps: r } : {}
|
|
272
|
+
}), P(n?.hostElementId, "onFlowError", {
|
|
273
|
+
actionId: i,
|
|
274
|
+
runId: t,
|
|
264
275
|
...e.data
|
|
265
276
|
});
|
|
266
277
|
} else if (e.event === "done") {
|
|
267
|
-
let
|
|
268
|
-
|
|
278
|
+
let r = S(e.data.steps);
|
|
279
|
+
N({
|
|
269
280
|
status: e.data.status === "completed" ? "completed" : "failed",
|
|
270
281
|
...e.data.output ? { output: e.data.output } : {},
|
|
271
282
|
...typeof e.data.error == "string" ? { error: e.data.error } : {},
|
|
272
|
-
...
|
|
273
|
-
}),
|
|
274
|
-
actionId:
|
|
275
|
-
runId:
|
|
283
|
+
...r ? { steps: r } : {}
|
|
284
|
+
}), P(n?.hostElementId, "onFlowEnd", {
|
|
285
|
+
actionId: i,
|
|
286
|
+
runId: t,
|
|
276
287
|
...e.data
|
|
277
288
|
});
|
|
278
289
|
}
|
|
279
290
|
}).catch((e) => {
|
|
280
|
-
if (
|
|
281
|
-
let
|
|
282
|
-
|
|
291
|
+
if (b.signal.aborted) return;
|
|
292
|
+
let r = e instanceof Error ? e.message : String(e);
|
|
293
|
+
N({
|
|
283
294
|
status: "failed",
|
|
284
|
-
error:
|
|
285
|
-
}),
|
|
295
|
+
error: r
|
|
296
|
+
}), c.warning("actions", /* @__PURE__ */ p("span", { children: [
|
|
286
297
|
"Server action ",
|
|
287
|
-
/* @__PURE__ */
|
|
298
|
+
/* @__PURE__ */ f("b", { children: i }),
|
|
288
299
|
" stopped mid-stream"
|
|
289
300
|
] }), {
|
|
290
|
-
actionId:
|
|
291
|
-
mode:
|
|
292
|
-
runId:
|
|
293
|
-
error:
|
|
294
|
-
}),
|
|
295
|
-
actionId:
|
|
296
|
-
runId:
|
|
297
|
-
error:
|
|
301
|
+
actionId: i,
|
|
302
|
+
mode: a,
|
|
303
|
+
runId: t,
|
|
304
|
+
error: r
|
|
305
|
+
}), P(n?.hostElementId, "onFlowError", {
|
|
306
|
+
actionId: i,
|
|
307
|
+
runId: t,
|
|
308
|
+
error: r,
|
|
298
309
|
reason: "failed"
|
|
299
310
|
});
|
|
300
311
|
}), {
|
|
301
312
|
accepted: !0,
|
|
302
313
|
status: "streaming",
|
|
303
|
-
runId:
|
|
314
|
+
runId: t,
|
|
304
315
|
output: {}
|
|
305
316
|
};
|
|
306
317
|
}
|
|
307
|
-
let
|
|
318
|
+
let I;
|
|
308
319
|
try {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
});
|
|
320
|
+
if (I = await t({
|
|
321
|
+
endpoint: j,
|
|
322
|
+
call: l,
|
|
323
|
+
signal: b.signal,
|
|
324
|
+
onQueued: F
|
|
325
|
+
}), "unreachable" in I) throw I.unreachable;
|
|
316
326
|
} catch (e) {
|
|
317
|
-
return
|
|
327
|
+
return N(E(b, e)), c.warning("interactions", /* @__PURE__ */ p("span", { children: [
|
|
318
328
|
"Server action ",
|
|
319
|
-
/* @__PURE__ */
|
|
329
|
+
/* @__PURE__ */ f("b", { children: i }),
|
|
320
330
|
" could not be reached"
|
|
321
331
|
] }), {
|
|
322
|
-
actionId:
|
|
332
|
+
actionId: i,
|
|
323
333
|
error: e instanceof Error ? e.message : String(e)
|
|
324
|
-
}),
|
|
325
|
-
actionId:
|
|
334
|
+
}), P(n?.hostElementId, "onFlowError", {
|
|
335
|
+
actionId: i,
|
|
326
336
|
runId: "",
|
|
327
337
|
error: "",
|
|
328
338
|
reason: "failed"
|
|
329
|
-
}),
|
|
339
|
+
}), T;
|
|
330
340
|
}
|
|
331
|
-
let
|
|
332
|
-
return
|
|
333
|
-
status: P.status === "completed" ? "completed" : "failed",
|
|
334
|
-
...P.runId ? { runId: P.runId } : {},
|
|
335
|
-
...P.output ? { output: P.output } : {},
|
|
336
|
-
...P.error ? { error: P.error } : {},
|
|
337
|
-
...P.steps ? { steps: P.steps } : {},
|
|
338
|
-
...P.trace ? { trace: P.trace } : {}
|
|
339
|
-
}), P.status === "failed" && N(t?.hostElementId, "onFlowError", O(n, P)), {
|
|
340
|
-
status: r(P.status),
|
|
341
|
-
runId: P.runId ?? "",
|
|
342
|
-
output: P.output ?? {},
|
|
343
|
-
...P.error ? { error: P.error } : {},
|
|
344
|
-
...P.code ? { code: P.code } : {}
|
|
345
|
-
}) : (E(M.status, P, A), j(D(P)), N(t?.hostElementId, "onFlowError", O(n, P)), s.warning("actions", /* @__PURE__ */ f("span", { children: [
|
|
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__ */ p("span", { children: [
|
|
346
343
|
"Server action ",
|
|
347
|
-
/* @__PURE__ */
|
|
344
|
+
/* @__PURE__ */ f("b", { children: i }),
|
|
348
345
|
" was refused"
|
|
349
346
|
] }), {
|
|
350
|
-
actionId:
|
|
351
|
-
mode:
|
|
352
|
-
runId:
|
|
353
|
-
reason:
|
|
354
|
-
error:
|
|
355
|
-
status: String(
|
|
347
|
+
actionId: i,
|
|
348
|
+
mode: a,
|
|
349
|
+
runId: R.runId,
|
|
350
|
+
reason: R.reason,
|
|
351
|
+
error: R.error,
|
|
352
|
+
status: String(L)
|
|
356
353
|
}), {
|
|
357
354
|
status: "failed",
|
|
358
|
-
reason:
|
|
359
|
-
runId:
|
|
355
|
+
reason: R.reason ?? "failed",
|
|
356
|
+
runId: R.runId ?? "",
|
|
360
357
|
output: {},
|
|
361
|
-
...
|
|
358
|
+
...R.error ? { error: R.error } : {}
|
|
359
|
+
}) : (N({
|
|
360
|
+
status: R.status === "completed" ? "completed" : "failed",
|
|
361
|
+
...R.runId ? { runId: R.runId } : {},
|
|
362
|
+
...R.output ? { output: R.output } : {},
|
|
363
|
+
...R.error ? { error: R.error } : {},
|
|
364
|
+
...R.steps ? { steps: R.steps } : {},
|
|
365
|
+
...R.trace ? { trace: R.trace } : {}
|
|
366
|
+
}), R.status === "failed" && P(n?.hostElementId, "onFlowError", k(i, R)), {
|
|
367
|
+
status: r(R.status),
|
|
368
|
+
runId: R.runId ?? "",
|
|
369
|
+
output: R.output ?? {},
|
|
370
|
+
...R.error ? { error: R.error } : {},
|
|
371
|
+
...R.code ? { code: R.code } : {}
|
|
362
372
|
});
|
|
363
|
-
}, [
|
|
364
|
-
if (!
|
|
373
|
+
}, [j, P]), I = o(async (e) => {
|
|
374
|
+
if (!j || !e.runId) return { cancelled: !1 };
|
|
365
375
|
try {
|
|
366
|
-
let t = (await fetch(`${
|
|
376
|
+
let t = (await fetch(`${j}/run/${e.runId}`, {
|
|
367
377
|
method: "DELETE",
|
|
368
|
-
credentials: "
|
|
378
|
+
credentials: "include"
|
|
369
379
|
})).status === 204;
|
|
370
|
-
return
|
|
380
|
+
return c.info("actions", /* @__PURE__ */ p("span", { children: [
|
|
371
381
|
"Server action run ",
|
|
372
|
-
/* @__PURE__ */
|
|
382
|
+
/* @__PURE__ */ f("b", { children: e.runId }),
|
|
373
383
|
" ",
|
|
374
384
|
t ? "cancelled" : "was not cancelled"
|
|
375
385
|
] }), {
|
|
@@ -381,25 +391,25 @@ var x = (e) => Array.isArray(e) ? e : void 0, S = async (e, t) => {
|
|
|
381
391
|
} catch {
|
|
382
392
|
return { cancelled: !1 };
|
|
383
393
|
}
|
|
384
|
-
}, [
|
|
394
|
+
}, [j]), L = s(() => (M ?? []).map((e) => ({
|
|
385
395
|
label: `${e.name} (${e.identifier})`,
|
|
386
396
|
value: e.identifier
|
|
387
|
-
})), [
|
|
388
|
-
|
|
397
|
+
})), [M]);
|
|
398
|
+
x({
|
|
389
399
|
id: "actions",
|
|
390
|
-
callbacks:
|
|
391
|
-
cancelServerAction:
|
|
392
|
-
runServerAction:
|
|
393
|
-
}, { runServerAction: { params: (
|
|
394
|
-
let n =
|
|
400
|
+
callbacks: s(() => u(e, {
|
|
401
|
+
cancelServerAction: I,
|
|
402
|
+
runServerAction: F
|
|
403
|
+
}, { runServerAction: { params: (t) => {
|
|
404
|
+
let n = l(e.runServerAction.params), r = (M ?? []).find((e) => e.identifier === t.actionId), i = Object.entries(r?.input ?? {});
|
|
395
405
|
return {
|
|
396
406
|
...n,
|
|
397
407
|
actionId: {
|
|
398
408
|
...n.actionId,
|
|
399
|
-
type: () =>
|
|
409
|
+
type: () => L.length > 0 ? "select" : "text",
|
|
400
410
|
canBind: !0,
|
|
401
|
-
label:
|
|
402
|
-
options:
|
|
411
|
+
label: N === !1 ? "Action — this space has no server to run it" : "Action",
|
|
412
|
+
options: L
|
|
403
413
|
},
|
|
404
414
|
input: {
|
|
405
415
|
...n.input,
|
|
@@ -408,24 +418,23 @@ var x = (e) => Array.isArray(e) ? e : void 0, S = async (e, t) => {
|
|
|
408
418
|
}
|
|
409
419
|
};
|
|
410
420
|
} } }), [
|
|
411
|
-
P,
|
|
412
421
|
F,
|
|
413
422
|
I,
|
|
414
|
-
|
|
415
|
-
M
|
|
423
|
+
L,
|
|
424
|
+
M,
|
|
425
|
+
N
|
|
416
426
|
])
|
|
417
427
|
});
|
|
418
|
-
let
|
|
428
|
+
let R = o(({ actionId: e, input: t, idempotencyKey: n = "", invalidateQueries: r }) => F({
|
|
419
429
|
actionId: e,
|
|
420
430
|
input: t,
|
|
421
431
|
mode: "await",
|
|
422
432
|
idempotencyKey: n,
|
|
423
433
|
invalidateQueries: r
|
|
424
|
-
}), [
|
|
425
|
-
return /* @__PURE__ */
|
|
426
|
-
value:
|
|
427
|
-
children:
|
|
434
|
+
}), [F]);
|
|
435
|
+
return /* @__PURE__ */ f(n, {
|
|
436
|
+
value: R,
|
|
437
|
+
children: b
|
|
428
438
|
});
|
|
429
439
|
};
|
|
430
|
-
|
|
431
|
-
export { k as default };
|
|
440
|
+
export { A as default };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { sharedContext as e } from "@plitzi/sdk-shared/
|
|
2
|
-
|
|
1
|
+
import { sharedContext as e } from "@plitzi/sdk-shared/react";
|
|
2
|
+
// src/sources/ActionsSource/ServerActionContext.ts
|
|
3
3
|
var t = [
|
|
4
4
|
"completed",
|
|
5
5
|
"failed",
|
|
6
6
|
"skipped",
|
|
7
7
|
"aborted"
|
|
8
8
|
], n = (e) => e === void 0 ? "completed" : t.find((t) => t === e) ?? "failed", r = e("ServerActionContext", void 0);
|
|
9
|
-
//#endregion
|
|
10
9
|
export { r as ServerActionContext, n as endedStatusOf };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { writeInvalidationParams as e } from "../QueriesSource/writeParams.mjs";
|
|
2
|
-
|
|
2
|
+
// src/sources/ActionsSource/callbacks.ts
|
|
3
3
|
var t = {
|
|
4
4
|
runServerAction: {
|
|
5
5
|
source: "actions",
|
|
@@ -67,5 +67,4 @@ var t = {
|
|
|
67
67
|
preview: { cancelled: "" }
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
|
-
//#endregion
|
|
71
70
|
export { t as actionsCallbacks };
|