@plitzi/sdk-interactions 0.37.2 → 0.37.3

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.
@@ -4,72 +4,85 @@ import { use as n, useCallback as r, useMemo as i } from "react";
4
4
  import { toInteractionCallbacks as a } from "@plitzi/sdk-shared/authoring/builder";
5
5
  import { useCommonStoreSetter as o } from "@plitzi/sdk-shared/store";
6
6
  //#region src/sources/StateSource/StateInteractions.tsx
7
- var s = 0, c = () => typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `e${++s}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`, l = ({ children: s }) => {
8
- let { useInteractions: l } = n(e), u = o(), d = r((e) => {
9
- let { key: t, type: n } = e, { value: r } = e;
10
- n === "boolean" ? r = r === !0 || r === "true" : n === "number" && (r = parseInt(r, 10)), u(`runtime.state.${t}`, r);
11
- }, [u]), f = r((e) => {
7
+ var s = 0, c = () => typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `e${++s}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`, l = (e, t) => {
8
+ if (typeof t != "string") return t;
9
+ try {
10
+ return JSON.parse(t);
11
+ } catch {
12
+ throw Error(`setState "${e}" is typed json, and its value is not JSON: ${t.slice(0, 80)}`);
13
+ }
14
+ }, u = ({ children: s }) => {
15
+ let { useInteractions: u } = n(e), d = o(), f = r((e) => {
16
+ let { key: t, type: n } = e, r = e.value;
17
+ if (n === "boolean") r = r === !0 || r === "true";
18
+ else if (n === "number") r = typeof r == "number" ? r : parseFloat(String(r));
19
+ else if (n === "json") {
20
+ d(`runtime.state.${t}`, l(t, r));
21
+ return;
22
+ }
23
+ d(`runtime.state.${t}`, r);
24
+ }, [d]), p = r((e) => {
12
25
  let { key: t } = e;
13
- t && u(`runtime.state.${t}`, (e) => e !== !0 && e !== "true");
14
- }, [u]), p = (e) => e === !0 || e === "true", m = r((e) => {
26
+ t && d(`runtime.state.${t}`, (e) => e !== !0 && e !== "true");
27
+ }, [d]), m = (e) => e === !0 || e === "true", h = r((e) => {
15
28
  let { key: t, value: n, unique: r, withId: i } = e;
16
- t && u(`runtime.state.${t}`, (e) => {
29
+ t && d(`runtime.state.${t}`, (e) => {
17
30
  let t = Array.isArray(e) ? e : [];
18
- return p(i) ? [...t, {
31
+ return m(i) ? [...t, {
19
32
  id: c(),
20
33
  value: n
21
- }] : p(r) && t.includes(n) ? t : [...t, n];
34
+ }] : m(r) && t.includes(n) ? t : [...t, n];
22
35
  });
23
- }, [u]), h = r((e) => {
36
+ }, [d]), g = r((e) => {
24
37
  let { key: t, index: n, value: r, by: i } = e;
25
38
  if (!t) return;
26
39
  if (r !== void 0 && r !== "") {
27
- u(`runtime.state.${t}`, (e) => Array.isArray(e) ? e.filter((e) => i ? e?.[i] !== r : e !== r) : []);
40
+ d(`runtime.state.${t}`, (e) => Array.isArray(e) ? e.filter((e) => i ? e?.[i] !== r : e !== r) : []);
28
41
  return;
29
42
  }
30
43
  let a = typeof n == "number" ? n : parseInt(n ?? "", 10);
31
- Number.isNaN(a) || u(`runtime.state.${t}`, (e) => Array.isArray(e) ? e.filter((e, t) => t !== a) : []);
32
- }, [u]), g = r((e) => {
44
+ Number.isNaN(a) || d(`runtime.state.${t}`, (e) => Array.isArray(e) ? e.filter((e, t) => t !== a) : []);
45
+ }, [d]), _ = r((e) => {
33
46
  let { from: t, to: n, value: r } = e;
34
47
  if (!t || !n || r === void 0 || r === "") return;
35
48
  let i = { moved: !1 };
36
- u(`runtime.state.${t}`, (e) => {
49
+ d(`runtime.state.${t}`, (e) => {
37
50
  let t = Array.isArray(e) ? e : [];
38
51
  return i.moved = t.includes(r), i.moved ? t.filter((e) => e !== r) : t;
39
- }), i.moved && u(`runtime.state.${n}`, (e) => {
52
+ }), i.moved && d(`runtime.state.${n}`, (e) => {
40
53
  let t = Array.isArray(e) ? e : [];
41
54
  return t.includes(r) ? t : [...t, r];
42
55
  });
43
- }, [u]), _ = r((e) => {
56
+ }, [d]), v = r((e) => {
44
57
  let { key: t, value: n } = e;
45
- t && n !== void 0 && n !== "" && u(`runtime.state.${t}`, (e) => {
58
+ t && n !== void 0 && n !== "" && d(`runtime.state.${t}`, (e) => {
46
59
  let t = Array.isArray(e) ? e : [];
47
60
  return t.includes(n) ? t.filter((e) => e !== n) : [...t, n];
48
61
  });
49
- }, [u]), v = r((e) => {
62
+ }, [d]), y = r((e) => {
50
63
  let { key: t } = e;
51
- u(t ? `runtime.state.${t}` : "runtime.state", t ? [] : {});
52
- }, [u]);
53
- return l({
64
+ d(t ? `runtime.state.${t}` : "runtime.state", t ? [] : {});
65
+ }, [d]);
66
+ return u({
54
67
  id: "state",
55
68
  callbacks: i(() => a(t, {
56
- setState: d,
57
- toggleState: f,
58
- appendState: m,
59
- removeState: h,
60
- moveState: g,
61
- toggleInState: _,
62
- clearState: v
69
+ setState: f,
70
+ toggleState: p,
71
+ appendState: h,
72
+ removeState: g,
73
+ moveState: _,
74
+ toggleInState: v,
75
+ clearState: y
63
76
  }), [
64
- d,
65
77
  f,
66
- m,
78
+ p,
67
79
  h,
68
80
  g,
69
81
  _,
70
- v
82
+ v,
83
+ y
71
84
  ])
72
85
  }), s;
73
86
  };
74
87
  //#endregion
75
- export { l as default };
88
+ export { u as default };
@@ -12,21 +12,23 @@ var e = {
12
12
  },
13
13
  type: {
14
14
  type: "select",
15
- description: "The value type. What is stored is coerced to it — a boolean is a real boolean, not \"true\".",
15
+ description: "The value type. What is stored is coerced to it — a boolean is a real boolean, not \"true\"; `json` stores an object or a list (a template naming one, or JSON text).",
16
16
  options: [
17
17
  "boolean",
18
18
  "number",
19
- "text"
19
+ "text",
20
+ "json"
20
21
  ],
21
22
  optionLabels: {
22
23
  boolean: "True / False",
23
24
  number: "Numeric",
24
- text: "Text"
25
+ text: "Text",
26
+ json: "Object / List (JSON)"
25
27
  }
26
28
  },
27
29
  value: {
28
- type: "scalar",
29
- description: "The value to store — its type follows the `type` param (a real boolean/number, or text).",
30
+ type: "json",
31
+ description: "The value to store — its type follows the `type` param (a real boolean/number, text, or an object/list).",
30
32
  when: (e) => !!e.type,
31
33
  builderType: (e) => e.type === "boolean" ? "select" : "text",
32
34
  options: ["true", "false"]
@@ -9,8 +9,9 @@ declare const _default: {
9
9
  webHook: import('@plitzi/sdk-shared').InteractionCallback<{
10
10
  url: string;
11
11
  method: string;
12
- body: Record<string, string | Blob>;
12
+ body: Record<string, string | Blob> | string;
13
13
  authorizationToken: string;
14
+ headers?: Record<string, unknown> | string | null;
14
15
  credentials: RequestCredentials;
15
16
  cache?: boolean | string;
16
17
  staleTime?: number | string;
@@ -2,8 +2,11 @@ import { InteractionCallback } from '@plitzi/sdk-shared';
2
2
  type WebHookParams = {
3
3
  url: string;
4
4
  method: string;
5
- body: Record<string, string | Blob>;
5
+ /** The fields to send — or, left as the step's default, the empty text. */
6
+ body: Record<string, string | Blob> | string;
6
7
  authorizationToken: string;
8
+ /** Extra headers, by name — or, left as the step's default, the empty text. Values are what the templates resolved to. */
9
+ headers?: Record<string, unknown> | string | null;
7
10
  credentials: RequestCredentials;
8
11
  cache?: boolean | string;
9
12
  staleTime?: number | string;
@@ -9,56 +9,59 @@ var a = /* @__PURE__ */ new Set(["GET", "HEAD"]), o = /* @__PURE__ */ new Set([
9
9
  ]), s = (t) => {
10
10
  let n = Number(t);
11
11
  return (Number.isFinite(n) && n >= 0 ? n : Number(e.params.staleTime.default)) * 1e3;
12
- }, c = (e) => e ? { Authorization: `Bearer ${e}` } : {}, l = async ({ url: e, authorizationToken: t, body: n, credentials: r }, i) => {
12
+ }, c = (e) => e ? { Authorization: `Bearer ${e}` } : {}, l = (e) => typeof e == "object" && e ? e : {}, u = /* @__PURE__ */ new Set(["authorization", "content-type"]), d = (e) => typeof e == "object" && e ? Object.fromEntries(Object.entries(e).flatMap(([e, t]) => (typeof t == "string" || typeof t == "number") && t !== "" && !u.has(e.toLowerCase()) ? [[e, String(t)]] : [])) : {}, f = async ({ url: e, authorizationToken: t, headers: n, body: r, credentials: i }, a) => {
13
+ let s = l(r), u = Object.values(s).some((e) => e instanceof Blob);
13
14
  try {
14
- let a = {
15
- "Content-Type": "application/json",
16
- ...c(t)
15
+ let r = {
16
+ method: a,
17
+ headers: {
18
+ ...d(n),
19
+ ...u ? {} : { "Content-Type": "application/json" },
20
+ ...c(t)
21
+ },
22
+ credentials: i
17
23
  };
18
- Object.values(n).some((e) => e instanceof Blob) && (a["Content-Type"] = "multipart/form-data");
19
- let s = {
20
- method: i,
21
- headers: a,
22
- credentials: r
23
- };
24
- if (!o.has(i)) {
25
- if (a["Content-Type"] === "application/json") s.body = JSON.stringify(n);
24
+ if (!o.has(a)) {
25
+ if (!u) r.body = JSON.stringify(s);
26
26
  else {
27
27
  let e = new FormData();
28
- Object.entries(n).forEach(([t, n]) => {
28
+ Object.entries(s).forEach(([t, n]) => {
29
29
  e.append(t, n);
30
- }), s.body = e;
30
+ }), r.body = e;
31
31
  }
32
32
  }
33
- let l = await fetch(e, s), u = "";
33
+ let l = await fetch(e, r), f = "";
34
34
  try {
35
- u = await l.json();
35
+ f = await l.json();
36
36
  } catch {}
37
37
  return {
38
38
  status: l.status,
39
- data: u
39
+ data: f
40
40
  };
41
41
  } catch (e) {
42
42
  return console.error(e), {};
43
43
  }
44
- }, u = t("webHook", e, async (e) => {
44
+ }, p = t("webHook", e, async (e) => {
45
45
  let t = (e.method || "get").toUpperCase();
46
46
  if (a.has(t)) {
47
- if (e.cache !== !0 && e.cache !== "true") return { response: await l(e, t) };
47
+ if (e.cache !== !0 && e.cache !== "true") return { response: await f(e, t) };
48
48
  let n = i({
49
49
  method: t,
50
50
  url: e.url,
51
51
  credentials: e.credentials,
52
- headers: c(e.authorizationToken)
52
+ headers: {
53
+ ...d(e.headers),
54
+ ...c(e.authorizationToken)
55
+ }
53
56
  });
54
57
  return { response: await r.fetchQuery(n, {
55
58
  meta: { url: e.url },
56
- fetcher: () => l(e, t),
59
+ fetcher: () => f(e, t),
57
60
  staleTime: s(e.staleTime),
58
61
  isCacheable: (e) => e.status !== void 0 && e.status < 400
59
62
  }) ?? {} };
60
63
  }
61
- let o = await l(e, t);
64
+ let o = await f(e, t);
62
65
  return o.status !== void 0 && o.status >= 200 && o.status < 300 && n({
63
66
  mode: e.invalidateQueries,
64
67
  fallback: "origin",
@@ -67,4 +70,4 @@ var a = /* @__PURE__ */ new Set(["GET", "HEAD"]), o = /* @__PURE__ */ new Set([
67
70
  }), { response: o };
68
71
  });
69
72
  //#endregion
70
- export { u as default };
73
+ export { p as default };
@@ -29,15 +29,22 @@ var t = (e) => {
29
29
  canBind: !1
30
30
  },
31
31
  body: {
32
- type: "textarea",
33
- description: "Request body.",
34
- default: ""
32
+ type: "json",
33
+ description: "Request body: an object of fields (sent as JSON, or as form data when one of them is a file). Pass a real object, with templates for its values — `{ email: \"{{ submitted.values.email }}\" }`.",
34
+ default: "",
35
+ builderType: "textarea"
35
36
  },
36
37
  authorizationToken: {
37
38
  type: "text",
38
39
  description: "Value sent as the Authorization header.",
39
40
  default: ""
40
41
  },
42
+ headers: {
43
+ type: "json",
44
+ description: "Headers of the request, as an object of name to value, with templates for the values like the body: `{ \"x-api-key\": \"{{ apiKey }}\" }`. Authorization is set by `authorizationToken` and the content type follows the body, so neither is set here.",
45
+ default: "",
46
+ builderType: "textarea"
47
+ },
41
48
  credentials: {
42
49
  type: "select",
43
50
  description: "fetch credentials mode.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-interactions",
3
- "version": "0.37.2",
3
+ "version": "0.37.3",
4
4
  "license": "AGPL-3.0",
5
5
  "files": [
6
6
  "dist"
@@ -185,16 +185,16 @@
185
185
  "devDependencies": {
186
186
  "eslint": "^9.39.5",
187
187
  "typescript": "^6.0.3",
188
- "vite": "^8.3.0",
188
+ "vite": "^8.3.1",
189
189
  "vitest": "^5.0.1"
190
190
  },
191
191
  "dependencies": {
192
- "@plitzi/plitzi-ui": "^1.6.22",
193
- "@plitzi/sdk-auth": "0.37.2",
194
- "@plitzi/sdk-dev-tools": "0.37.2",
195
- "@plitzi/sdk-event-bridge": "0.37.2",
196
- "@plitzi/sdk-navigation": "0.37.2",
197
- "@plitzi/sdk-schema": "0.37.2",
198
- "@plitzi/sdk-shared": "0.37.2"
192
+ "@plitzi/plitzi-ui": "^1.6.24",
193
+ "@plitzi/sdk-auth": "0.37.3",
194
+ "@plitzi/sdk-dev-tools": "0.37.3",
195
+ "@plitzi/sdk-event-bridge": "0.37.3",
196
+ "@plitzi/sdk-navigation": "0.37.3",
197
+ "@plitzi/sdk-schema": "0.37.3",
198
+ "@plitzi/sdk-shared": "0.37.3"
199
199
  }
200
200
  }
@@ -1 +0,0 @@
1
- export {};
File without changes