@plitzi/sdk-interactions 0.39.16 → 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 CHANGED
@@ -1,5 +1,13 @@
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
+
3
11
  ## 0.39.16
4
12
 
5
13
  ### Patch Changes
@@ -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 { 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";
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 = b(e, t);
56
- r && x({
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: 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) => {
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__ */ p("span", { children: [
78
+ if (!j) return c.warning("actions", /* @__PURE__ */ h("span", { children: [
79
79
  "Server action ",
80
- /* @__PURE__ */ f("b", { children: i }),
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), y = h({
99
+ }, u = JSON.stringify(l), d = _({
100
100
  actionId: i,
101
101
  mode: a,
102
102
  input: s
103
- }), b = new AbortController(), x = "", A = () => {
104
- b.abort(), v(y, {
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
- g(y, A);
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), _(y), v(y, {
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" && d({
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
- v(y, { status: "queued" }), c.info("actions", /* @__PURE__ */ p("span", { children: [
127
+ b(d, { status: "queued" }), c.info("actions", /* @__PURE__ */ h("span", { children: [
128
128
  "Server action ",
129
- /* @__PURE__ */ f("b", { children: i }),
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__ */ p("span", { children: [
137
+ if (a === "detached") return c.info("actions", /* @__PURE__ */ h("span", { children: [
138
138
  "Server action ",
139
- /* @__PURE__ */ f("b", { children: i }),
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: b.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__ */ p("span", { children: [
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__ */ f("b", { children: i }),
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__ */ p("span", { children: [
170
+ }), c.success("actions", /* @__PURE__ */ h("span", { children: [
171
171
  "Server action ",
172
- /* @__PURE__ */ f("b", { children: i }),
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(b, e)), c.warning("actions", /* @__PURE__ */ p("span", { children: [
187
+ N(E(f, e)), c.warning("actions", /* @__PURE__ */ h("span", { children: [
188
188
  "Server action ",
189
- /* @__PURE__ */ f("b", { children: i }),
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__ */ p("span", { children: [
208
+ c.info("actions", /* @__PURE__ */ h("span", { children: [
209
209
  "Server action ",
210
- /* @__PURE__ */ f("b", { children: i }),
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: b.signal,
226
+ signal: f.signal,
227
227
  body: u
228
228
  });
229
229
  } catch (e) {
230
- return N(E(b, e)), c.warning("actions", /* @__PURE__ */ p("span", { children: [
230
+ return N(E(f, e)), c.warning("actions", /* @__PURE__ */ h("span", { children: [
231
231
  "Server action ",
232
- /* @__PURE__ */ f("b", { children: i }),
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, v(y, {
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") m(y, e.data.chunk ?? e.data), P(n?.hostElementId, "onFlowProgress", {
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 (b.signal.aborted) return;
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__ */ p("span", { children: [
296
+ }), c.warning("actions", /* @__PURE__ */ h("span", { children: [
297
297
  "Server action ",
298
- /* @__PURE__ */ f("b", { children: i }),
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: b.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(b, e)), c.warning("interactions", /* @__PURE__ */ p("span", { children: [
327
+ return N(E(f, e)), c.warning("interactions", /* @__PURE__ */ h("span", { children: [
328
328
  "Server action ",
329
- /* @__PURE__ */ f("b", { children: i }),
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__ */ p("span", { children: [
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__ */ f("b", { children: i }),
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__ */ p("span", { children: [
380
+ return c.info("actions", /* @__PURE__ */ h("span", { children: [
381
381
  "Server action run ",
382
- /* @__PURE__ */ f("b", { children: e.runId }),
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
- x({
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__ */ f(n, {
435
+ return /* @__PURE__ */ m(n, {
436
436
  value: R,
437
- children: b
437
+ children: d
438
438
  });
439
439
  };
440
440
  export { A as default };
@@ -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 { csrfFetch as n } from "@plitzi/sdk-shared/csrf";
4
- import { invalidateAfterWrite as r, queryCache as i, requestKey as a } from "@plitzi/sdk-shared/queries";
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 o = /* @__PURE__ */ new Set(["GET", "HEAD"]), s = /* @__PURE__ */ new Set([
7
+ var c = /* @__PURE__ */ new Set(["GET", "HEAD"]), l = /* @__PURE__ */ new Set([
7
8
  "GET",
8
9
  "HEAD",
9
10
  "DELETE"
10
- ]), c = (t) => {
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
- }, l = (e) => e ? { Authorization: `Bearer ${e}` } : {}, u = (e) => typeof e == "object" && e ? e : {}, d = /* @__PURE__ */ new Set(["authorization", "content-type"]), f = (e) => typeof e == "object" && e ? Object.fromEntries(Object.entries(e).flatMap(([e, t]) => (typeof t == "string" || typeof t == "number") && t !== "" && !d.has(e.toLowerCase()) ? [[e, String(t)]] : [])) : {}, p = async ({ url: e, authorizationToken: t, headers: r, body: i, credentials: a }, o, c) => {
14
- let d = u(i), p = Object.values(d).some((e) => e instanceof Blob), m = {
15
- method: o,
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
- ...f(r),
18
- ...p ? {} : { "Content-Type": "application/json" },
19
- ...l(t)
18
+ ...m(u),
19
+ ...v ? {} : { "Content-Type": "application/json" },
20
+ ...d(c)
20
21
  },
21
- credentials: a,
22
- ...c ? { signal: c } : {}
22
+ credentials: g,
23
+ ...a ? { signal: a } : {}
23
24
  };
24
- if (!s.has(o)) {
25
- if (!p) m.body = JSON.stringify(d);
25
+ if (!l.has(t)) {
26
+ if (!v) y.body = JSON.stringify(_);
26
27
  else {
27
28
  let e = new FormData();
28
- Object.entries(d).forEach(([t, n]) => {
29
+ Object.entries(_).forEach(([t, n]) => {
29
30
  e.append(t, n);
30
- }), m.body = e;
31
+ }), y.body = e;
31
32
  }
32
33
  }
33
- let h = await n(e, m).catch((t) => {
34
- throw Error(`${o} ${e} got no answer: ${t instanceof Error ? t.message : String(t)}`);
35
- }), g = "";
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
- g = await h.json();
38
+ x = await b.json();
38
39
  } catch {}
39
- return {
40
- status: h.status,
41
- data: g
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
- }, m = t("webHook", e, async (e, t) => {
48
+ }, g = t("webHook", e, async (e, t) => {
44
49
  let n = (e.method || "get").toUpperCase();
45
- if (o.has(n)) {
46
- if (e.cache !== !0 && e.cache !== "true") return { response: await p(e, n, t?.signal) };
47
- let r = a({
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
- ...f(e.headers),
53
- ...l(e.authorizationToken)
57
+ ...m(e.headers),
58
+ ...d(e.authorizationToken)
54
59
  }
55
60
  });
56
- return { response: await i.fetchQuery(r, {
61
+ return { response: await o.fetchQuery(r, {
57
62
  meta: { url: e.url },
58
- fetcher: () => p(e, n),
59
- staleTime: c(e.staleTime),
63
+ fetcher: () => h(e, n),
64
+ staleTime: u(e.staleTime),
60
65
  isCacheable: (e) => e.status < 400
61
66
  }) };
62
67
  }
63
- let s = await p(e, n, t?.signal);
64
- return s.status >= 200 && s.status < 300 && r({
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: s };
74
+ }), { response: r };
70
75
  });
71
- export { m as default };
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.16",
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.41",
43
- "@plitzi/sdk-auth": "0.39.16",
44
- "@plitzi/sdk-event-bridge": "0.39.16",
45
- "@plitzi/sdk-shared": "0.39.16"
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"