@plitzi/sdk-interactions 0.33.2 → 0.34.0

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 (35) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/InteractionsHelper.d.ts +3 -3
  3. package/dist/InteractionsHelper.mjs +92 -86
  4. package/dist/InteractionsManager.mjs +1 -1
  5. package/dist/InteractionsSourcesProvider.d.ts +4 -1
  6. package/dist/InteractionsSourcesProvider.mjs +24 -19
  7. package/dist/hooks/useInteractions.d.ts +1 -1
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.mjs +8 -5
  10. package/dist/sources/ActionsSource/ActionInteractions.d.ts +13 -0
  11. package/dist/sources/ActionsSource/ActionInteractions.mjs +409 -0
  12. package/dist/sources/ActionsSource/callbacks.d.ts +12 -0
  13. package/dist/sources/ActionsSource/callbacks.mjs +63 -0
  14. package/dist/sources/ActionsSource/index.d.ts +3 -0
  15. package/dist/sources/ActionsSource/index.mjs +2 -0
  16. package/dist/sources/AuthSource/AuthInteractions.mjs +17 -94
  17. package/dist/sources/AuthSource/callbacks.d.ts +32 -0
  18. package/dist/sources/AuthSource/callbacks.mjs +71 -0
  19. package/dist/sources/HostSource/HostInteractions.d.ts +16 -0
  20. package/dist/sources/HostSource/HostInteractions.mjs +20 -0
  21. package/dist/sources/HostSource/callbacks.d.ts +15 -0
  22. package/dist/sources/HostSource/callbacks.mjs +20 -0
  23. package/dist/sources/HostSource/index.d.ts +3 -0
  24. package/dist/sources/HostSource/index.mjs +3 -0
  25. package/dist/sources/NavigationSource/NavigationInteractions.mjs +27 -48
  26. package/dist/sources/NavigationSource/callbacks.d.ts +9 -0
  27. package/dist/sources/NavigationSource/callbacks.mjs +30 -0
  28. package/dist/sources/StateSource/StateInteractions.mjs +69 -64
  29. package/dist/sources/StateSource/callbacks.d.ts +3 -0
  30. package/dist/sources/StateSource/callbacks.mjs +151 -0
  31. package/dist/sources/index.d.ts +5 -1
  32. package/dist/sources/index.mjs +7 -4
  33. package/dist/utility/transformer.mjs +0 -0
  34. package/dist/utility/webHook.mjs +15 -11
  35. package/package.json +54 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @plitzi/sdk-interactions
2
2
 
3
+ ## 0.34.0
4
+
5
+ ### Minor Changes
6
+
7
+ - v0.34.0
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [5aceda0]
12
+ - Updated dependencies
13
+ - Updated dependencies [5aceda0]
14
+ - @plitzi/sdk-shared@0.34.0
15
+ - @plitzi/sdk-auth@0.34.0
16
+ - @plitzi/sdk-dev-tools@0.34.0
17
+ - @plitzi/sdk-event-bridge@0.34.0
18
+ - @plitzi/sdk-navigation@0.34.0
19
+ - @plitzi/sdk-schema@0.34.0
20
+
3
21
  ## 0.33.2
4
22
 
5
23
  ### Patch Changes
@@ -1,9 +1,9 @@
1
1
  import { ElementInteraction } from '@plitzi/sdk-shared';
2
2
  declare const flowTrigger: (triggerNode: ElementInteraction, nodes?: {}, callbacksAvailables?: {}, flowParams?: Record<string, unknown>, globalParams?: {},
3
- /** The idRef of the element this fired on, carried through purely so the log can name it. */
4
- elementRef?: string, postCallbacksTotal?: never[]) => Promise<void>;
3
+ /** The id of the element this fired on, carried through purely so the log can name it. */
4
+ hostElementId?: string, postCallbacksTotal?: never[]) => Promise<void>;
5
5
  export { flowTrigger };
6
6
  declare const InteractionsHelper: {
7
- flowTrigger: (triggerNode: ElementInteraction, nodes?: {}, callbacksAvailables?: {}, flowParams?: Record<string, unknown>, globalParams?: {}, elementRef?: string, postCallbacksTotal?: never[]) => Promise<void>;
7
+ flowTrigger: (triggerNode: ElementInteraction, nodes?: {}, callbacksAvailables?: {}, flowParams?: Record<string, unknown>, globalParams?: {}, hostElementId?: string, postCallbacksTotal?: never[]) => Promise<void>;
8
8
  };
9
9
  export default InteractionsHelper;
@@ -5,144 +5,150 @@ import { pConsole as i } from "@plitzi/sdk-shared/devTools/utils/PlitziConsole";
5
5
  import { hasValidToken as a, processTwig as o } from "@plitzi/sdk-shared/helpers/twigWrapper";
6
6
  import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
7
7
  //#region src/InteractionsHelper.tsx
8
- var u = 5, d = (e, t, n, r, s) => e === "utility" && s === "twigTemplate" ? t : Object.keys(t).reduce((s, d) => {
9
- let f = t[d];
10
- if (e !== "trigger") {
11
- let e = u;
12
- for (; typeof f == "string" && a(f) && e > 0;) f = o(f, {
13
- ...n,
14
- ...r
15
- }, !1, !0), e--;
16
- typeof f == "string" && a(f) && i.warning("interactions", /* @__PURE__ */ l("span", { children: [
17
- "Twig token resolution exceeded ",
18
- u,
19
- " passes for ",
20
- /* @__PURE__ */ c("b", { children: d }),
21
- ", leaving unresolved tokens"
22
- ] }), {
23
- param: d,
24
- value: f
25
- });
26
- }
27
- return {
28
- ...s,
29
- [d]: f
8
+ var u = 5, d = 5, f = (e, t, n, r, s) => {
9
+ if (e === "utility" && s === "twigTemplate") return t;
10
+ let f = {
11
+ ...n,
12
+ ...r
13
+ }, p = (e, t, n) => {
14
+ if (typeof e == "string") {
15
+ let n = e, r = u;
16
+ for (; typeof n == "string" && a(n) && r > 0;) n = o(n, f, !1, !0), r--;
17
+ return typeof n == "string" && a(n) && i.warning("interactions", /* @__PURE__ */ l("span", { children: [
18
+ "Twig token resolution exceeded ",
19
+ u,
20
+ " passes for ",
21
+ /* @__PURE__ */ c("b", { children: t }),
22
+ ", leaving unresolved tokens"
23
+ ] }), {
24
+ param: t,
25
+ value: n
26
+ }), n;
27
+ }
28
+ return n >= d || typeof e != "object" || !e ? e : Array.isArray(e) ? e.map((e) => p(e, t, n + 1)) : Object.fromEntries(Object.entries(e).map(([e, r]) => [e, p(r, t, n + 1)]));
30
29
  };
31
- }, {}), f = async (n, a = {}, o = {}, s = {}) => {
32
- let u = {}, f = [], { id: p, action: m, enabled: h, params: g, elementId: _, type: v, when: y } = n;
33
- if (!m || !h) return {
30
+ return Object.keys(t).reduce((n, r) => {
31
+ let i = e === "trigger" ? t[r] : p(t[r], r, 0);
32
+ return {
33
+ ...n,
34
+ [r]: i
35
+ };
36
+ }, {});
37
+ }, p = async (n, a = {}, o = {}, s = {}, u = {}) => {
38
+ let d = {}, p = [], { id: m, action: h, enabled: g, params: _, elementId: v, type: y, when: b } = n;
39
+ if (!h || !g) return {
34
40
  status: "disabled",
35
- result: u,
36
- postCallbacks: f
41
+ result: d,
42
+ postCallbacks: p
37
43
  };
38
- let b = {
44
+ let x = {
39
45
  ...s,
40
46
  ...o,
41
- [p]: g
47
+ [m]: _
42
48
  };
43
- if (y && !r(y, b)) return {
49
+ if (b && !r(b, x)) return {
44
50
  status: "skipped",
45
- result: u,
46
- postCallbacks: f,
47
- whenParams: b
51
+ result: d,
52
+ postCallbacks: p,
53
+ whenParams: x
48
54
  };
49
- let x = {
55
+ let S = {
50
56
  ...o,
51
57
  ...s,
52
- ...d(v, g, o, s, m)
58
+ ...f(y, _, o, s, h)
53
59
  };
54
60
  try {
55
- switch (v) {
61
+ switch (y) {
56
62
  case "callback":
57
63
  case "globalCallback": {
58
- if (!_) return i.warning("interactions", /* @__PURE__ */ l("span", { children: [
64
+ if (!v) return i.warning("interactions", /* @__PURE__ */ l("span", { children: [
59
65
  "Step ",
60
- /* @__PURE__ */ c("b", { children: m }),
66
+ /* @__PURE__ */ c("b", { children: h }),
61
67
  " names no element, so there is nothing to run it on"
62
68
  ] }), { node: n }), {
63
69
  status: "failed",
64
- result: u,
65
- postCallbacks: f,
66
- whenParams: b
70
+ result: d,
71
+ postCallbacks: p,
72
+ whenParams: x
67
73
  };
68
- let e = t(a, `${_}.${m}`);
74
+ let e = t(a, `${v}.${h}`);
69
75
  if (!e) return i.warning("interactions", /* @__PURE__ */ l("span", { children: [
70
76
  "Nothing is registered as ",
71
- /* @__PURE__ */ c("b", { children: `${_}.${m}` }),
77
+ /* @__PURE__ */ c("b", { children: `${v}.${h}` }),
72
78
  ", so this step did nothing"
73
79
  ] }), {
74
80
  node: n,
75
- available: Object.keys(t(a, _, {}))
81
+ available: Object.keys(t(a, v, {}))
76
82
  }), {
77
83
  status: "failed",
78
- result: u,
79
- postCallbacks: f,
80
- whenParams: b
84
+ result: d,
85
+ postCallbacks: p,
86
+ whenParams: x
81
87
  };
82
88
  let { callback: r, postCallback: o } = e;
83
- r && (u = await r(x)), o && f.push({
84
- id: p,
89
+ r && (d = await r(S, u)), o && p.push({
90
+ id: m,
85
91
  callback: o,
86
92
  params: {
87
- ...x,
88
- [p]: u
93
+ ...S,
94
+ [m]: d
89
95
  }
90
96
  });
91
97
  break;
92
98
  }
93
99
  case "utility": {
94
- let { callback: n, postCallback: r } = t(e, m, {});
95
- n && (u = await n(x)), r && f.push({
96
- id: p,
100
+ let { callback: n, postCallback: r } = t(e, h, {});
101
+ n && (d = await n(S, u)), r && p.push({
102
+ id: m,
97
103
  callback: r,
98
104
  params: {
99
- ...x,
100
- [p]: u
105
+ ...S,
106
+ [m]: d
101
107
  }
102
108
  });
103
109
  break;
104
110
  }
105
111
  }
106
112
  } catch (e) {
107
- return i.danger("interactions", /* @__PURE__ */ l("span", { children: ["Interaction node failed ", /* @__PURE__ */ c("b", { children: m })] }), {
113
+ return i.danger("interactions", /* @__PURE__ */ l("span", { children: ["Interaction node failed ", /* @__PURE__ */ c("b", { children: h })] }), {
108
114
  error: e instanceof Error ? e.message : String(e),
109
115
  node: n
110
116
  }), {
111
117
  status: "failed",
112
- result: u,
113
- postCallbacks: f,
114
- whenParams: b
118
+ result: d,
119
+ postCallbacks: p,
120
+ whenParams: x
115
121
  };
116
122
  }
117
123
  return {
118
124
  status: "success",
119
- result: u,
120
- postCallbacks: f,
121
- whenParams: b
125
+ result: d,
126
+ postCallbacks: p,
127
+ whenParams: x
122
128
  };
123
- }, p = async (e = []) => {
129
+ }, m = async (e = []) => {
124
130
  let t = {};
125
131
  return await Promise.all(e.reverse().map(async ({ id: e, callback: r, params: i }) => {
126
132
  t[e] = await r?.(n(i, [e]), i[e]);
127
133
  })), t;
128
- }, m = async (e, n = {}, r = {}, a = {}, o = {}, s = [], c = {}) => {
134
+ }, h = async (e, n = {}, r = {}, a = {}, o = {}, s = [], c = {}, l = {}) => {
129
135
  if (!e) return c;
130
- let l = t(n, e.afterNode);
131
- if (!l && s.length > 0 && await p(s), !l) return c;
132
- let u = i.getTime().valueOf(), { status: d, result: h, postCallbacks: g, whenParams: _ } = await f(l, r, a, o);
133
- return c[l.id] = {
134
- node: l,
135
- status: d,
136
- result: h,
137
- postCallbacks: g,
138
- whenParams: _,
139
- startTime: u,
136
+ let u = t(n, e.afterNode);
137
+ if (!u && s.length > 0 && await m(s), !u) return c;
138
+ let d = i.getTime().valueOf(), { status: f, result: g, postCallbacks: _, whenParams: v } = await p(u, r, a, o, l);
139
+ return c[u.id] = {
140
+ node: u,
141
+ status: f,
142
+ result: g,
143
+ postCallbacks: _,
144
+ whenParams: v,
145
+ startTime: d,
140
146
  endTime: i.getTime().valueOf()
141
- }, s.push(...g), m(l, n, r, {
147
+ }, s.push(..._), h(u, n, r, {
142
148
  ...a,
143
- [l.id]: h
144
- }, o, s, c);
145
- }, h = (e, t, n = {}, r, a) => {
149
+ [u.id]: g
150
+ }, o, s, c, l);
151
+ }, g = (e, t, n = {}, r, a) => {
146
152
  let o = i.getTime().valueOf(), u = r === "skipped" ? "skipped" : "success", d = /* @__PURE__ */ l("span", { children: [
147
153
  "Interaction triggered ",
148
154
  /* @__PURE__ */ c("b", { children: `${e.title} [${e.action}]` }),
@@ -151,7 +157,7 @@ var u = 5, d = (e, t, n, r, s) => e === "utility" && s === "twigTemplate" ? t :
151
157
  status: r,
152
158
  node: e,
153
159
  elementId: e.elementId,
154
- elementRef: a,
160
+ hostElementId: a,
155
161
  nodes: {
156
162
  ...n,
157
163
  [e.id]: {
@@ -171,17 +177,17 @@ var u = 5, d = (e, t, n, r, s) => e === "utility" && s === "twigTemplate" ? t :
171
177
  return;
172
178
  }
173
179
  i.info("interactions", d, f);
174
- }, g = (e) => Object.values(e).some(({ status: e }) => e === "failed") ? "failed" : "completed", _ = async (e, t = {}, n = {}, a = {}, o = {}, s, c = []) => {
180
+ }, _ = (e) => Object.values(e).some(({ status: e }) => e === "failed") ? "failed" : "completed", v = async (e, t = {}, n = {}, a = {}, o = {}, s, c = []) => {
175
181
  let l = i.getTime().valueOf(), { action: u, enabled: d, when: f } = e;
176
182
  if (!u || !d || f && !r(f, {
177
183
  ...o,
178
184
  ...a
179
185
  })) {
180
- h(e, l, {}, "skipped", s);
186
+ g(e, l, {}, "skipped", s);
181
187
  return;
182
188
  }
183
- let p = await m(e, t, n, a, o, c);
184
- h(e, l, p, g(p), s);
185
- }, v = { flowTrigger: _ };
189
+ let p = await h(e, t, n, a, o, c, {}, { hostElementId: s });
190
+ g(e, l, p, _(p), s);
191
+ }, y = { flowTrigger: v };
186
192
  //#endregion
187
- export { v as default, _ as flowTrigger };
193
+ export { y as default, v as flowTrigger };
@@ -20,7 +20,7 @@ var i = class i {
20
20
  }, this.lastUpdate = Date.now();
21
21
  }
22
22
  eventBridgeCallback = (r) => async (i, a, o) => {
23
- if (!(!r || !a || !i || t(this.interactionsRunning, `${i}.${a}`))) {
23
+ if (r && a && i && !t(this.interactionsRunning, `${i}.${a}`)) {
24
24
  n(this.interactionsRunning, `${i}.${a}`, !0);
25
25
  try {
26
26
  let n = t(this.subscriptors, `${i}.getAdditionalParams`, void 0), s;
@@ -1,6 +1,9 @@
1
+ import { HostActions } from '@plitzi/sdk-shared';
1
2
  import { ReactNode } from 'react';
2
3
  export type InteractionsSourcesProviderProps = {
3
4
  children?: ReactNode;
5
+ /** What the embedding application is willing to be asked to do — see {@link HostActions}. */
6
+ hostActions?: HostActions;
4
7
  };
5
- declare const InteractionsSourcesProvider: ({ children }: InteractionsSourcesProviderProps) => import("react").JSX.Element;
8
+ declare const InteractionsSourcesProvider: ({ children, hostActions }: InteractionsSourcesProviderProps) => import("react").JSX.Element;
6
9
  export default InteractionsSourcesProvider;
@@ -1,29 +1,34 @@
1
1
  import e from "./InteractionsContextProvider.mjs";
2
- import t from "./sources/AuthSource/AuthInteractions.mjs";
3
- import n from "./sources/NavigationSource/NavigationInteractions.mjs";
4
- import r from "./sources/StateSource/StateInteractions.mjs";
5
- import { jsx as i } from "react/jsx-runtime";
6
- import { useRenderSettings as a, useSdkStore as o } from "@plitzi/sdk-shared/store";
2
+ import t from "./sources/ActionsSource/ActionInteractions.mjs";
3
+ import n from "./sources/AuthSource/AuthInteractions.mjs";
4
+ import r from "./sources/HostSource/HostInteractions.mjs";
5
+ import i from "./sources/NavigationSource/NavigationInteractions.mjs";
6
+ import a from "./sources/StateSource/StateInteractions.mjs";
7
+ import { jsx as o } from "react/jsx-runtime";
8
+ import { useRenderSettings as s, useSdkStore as c } from "@plitzi/sdk-shared/store";
7
9
  //#region src/InteractionsSourcesProvider.tsx
8
- var s = ({ children: s }) => {
9
- let [[c = "basic", l, u, d]] = o([
10
+ var l = ({ children: l, hostActions: u }) => {
11
+ let [[d = "basic", f, p, m]] = c([
10
12
  "schema.settings.userProvider",
11
13
  "navigation.routeParams",
12
14
  "navigation.queryParams",
13
15
  "navigation.currentPageId"
14
- ]), { previewMode: f } = a();
15
- return /* @__PURE__ */ i(e, {
16
- currentPageId: d,
17
- routeParams: l,
18
- queryParams: u,
19
- children: /* @__PURE__ */ i(t, {
20
- authProvider: c,
21
- children: /* @__PURE__ */ i(r, { children: /* @__PURE__ */ i(n, {
22
- previewMode: f,
23
- children: s
24
- }) })
16
+ ]), { previewMode: h } = s();
17
+ return /* @__PURE__ */ o(e, {
18
+ currentPageId: m,
19
+ routeParams: f,
20
+ queryParams: p,
21
+ children: /* @__PURE__ */ o(n, {
22
+ authProvider: d,
23
+ children: /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o(t, { children: /* @__PURE__ */ o(i, {
24
+ previewMode: h,
25
+ children: /* @__PURE__ */ o(r, {
26
+ actions: u,
27
+ children: l
28
+ })
29
+ }) }) })
25
30
  })
26
31
  });
27
32
  };
28
33
  //#endregion
29
- export { s as default };
34
+ export { l as default };
@@ -1,6 +1,6 @@
1
1
  import { ElementInteraction, InteractionCallback, Subscriptor } from '@plitzi/sdk-shared';
2
2
  export type UseInteractionsProps<TParams extends Record<string, unknown> = Record<string, unknown>> = {
3
- /** The element's idRef: interactions are wired by ref only. Absent for an element that has none, which is then
3
+ /** The element's id the one name it answers to, and the key interactions are wired by. Absent for a caller
4
4
  * left unregistered rather than falling back to its opaque id. */
5
5
  id?: string;
6
6
  interactions?: Record<string, ElementInteraction>;
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { default as InteractionsContextProvider } from './InteractionsContextPro
4
4
  import { default as InteractionsHelper } from './InteractionsHelper';
5
5
  import { default as InteractionsManager } from './InteractionsManager';
6
6
  import { default as InteractionsSourcesProvider } from './InteractionsSourcesProvider';
7
- import { AuthInteractions, NavigationInteractions, StateInteractions } from './sources';
7
+ import { ActionInteractions, AuthInteractions, NavigationInteractions, StateInteractions } from './sources';
8
8
  import { default as utility } from './utility';
9
9
  export * from './utility';
10
10
  export * from './InteractionsContext';
@@ -14,4 +14,4 @@ export * from './InteractionsSourcesProvider';
14
14
  export * from './hooks/useInteractions';
15
15
  export * from './sources';
16
16
  export * from './InteractionsManager';
17
- export { InteractionsManager, utility, InteractionsContext, InteractionsContextProvider, InteractionsHelper, InteractionsSourcesProvider, useInteractions, AuthInteractions, NavigationInteractions, StateInteractions };
17
+ export { InteractionsManager, utility, InteractionsContext, InteractionsContextProvider, InteractionsHelper, InteractionsSourcesProvider, useInteractions, ActionInteractions, AuthInteractions, NavigationInteractions, StateInteractions };
package/dist/index.mjs CHANGED
@@ -4,8 +4,11 @@ import n from "./utility/index.mjs";
4
4
  import r, { flowTrigger as i } from "./InteractionsHelper.mjs";
5
5
  import a from "./InteractionsManager.mjs";
6
6
  import o from "./InteractionsContextProvider.mjs";
7
- import s from "./sources/AuthSource/AuthInteractions.mjs";
8
- import c from "./sources/NavigationSource/NavigationInteractions.mjs";
9
- import l from "./sources/StateSource/StateInteractions.mjs";
10
- import u from "./InteractionsSourcesProvider.mjs";
11
- export { s as AuthInteractions, e as InteractionsContext, o as InteractionsContextProvider, r as InteractionsHelper, a as InteractionsManager, u as InteractionsSourcesProvider, c as NavigationInteractions, l as StateInteractions, i as flowTrigger, t as useInteractions, n as utility };
7
+ import s from "./sources/ActionsSource/ActionInteractions.mjs";
8
+ import c from "./sources/AuthSource/AuthInteractions.mjs";
9
+ import l from "./sources/HostSource/callbacks.mjs";
10
+ import u from "./sources/HostSource/HostInteractions.mjs";
11
+ import d from "./sources/NavigationSource/NavigationInteractions.mjs";
12
+ import f from "./sources/StateSource/StateInteractions.mjs";
13
+ import p from "./InteractionsSourcesProvider.mjs";
14
+ export { s as ActionInteractions, c as AuthInteractions, u as HostInteractions, e as InteractionsContext, o as InteractionsContextProvider, r as InteractionsHelper, a as InteractionsManager, p as InteractionsSourcesProvider, d as NavigationInteractions, f as StateInteractions, i as flowTrigger, l as hostCallbacks, t as useInteractions, n as utility };
@@ -0,0 +1,13 @@
1
+ import { ReactNode } from 'react';
2
+ export type ActionInteractionsProps = {
3
+ children?: ReactNode;
4
+ };
5
+ /**
6
+ * Running a server action from a client flow.
7
+ *
8
+ * The step names an action and hands it inputs — never a URL, a connector or a credential. Which one it can reach
9
+ * is the server's to decide from the space's own documents, so a page can only ever run what that space already
10
+ * declared.
11
+ */
12
+ declare const ActionInteractions: ({ children }: ActionInteractionsProps) => ReactNode;
13
+ export default ActionInteractions;