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