@picked/client 0.0.1-dev.1756875690387 → 0.0.1-dev.1762750479117

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 (107) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/cjs/plugins/create-experience/index.js +1 -1
  3. package/dist/cjs/plugins/experience-browser-storage/index.js +1 -0
  4. package/dist/cjs/plugins/history-browser-storage/index.js +1 -0
  5. package/dist/cjs/plugins/responses-browser-storage/index.js +1 -0
  6. package/dist/cjs/plugins/{responses-indexeddb-plugin → responses-indexeddb}/index.js +1 -1
  7. package/dist/cjs/plugins/shopify/index.js +1 -1
  8. package/dist/cjs/plugins/single-page-app/index.js +1 -1
  9. package/dist/cjs/plugins/web-components/index.js +1 -0
  10. package/dist/cjs/plugins/window-object/index.js +1 -1
  11. package/dist/cjs/server/index.js +1 -1
  12. package/dist/esm/index.js +555 -443
  13. package/dist/esm/plugins/create-experience/index.js +172 -103
  14. package/dist/esm/plugins/experience-browser-storage/index.js +39 -0
  15. package/dist/esm/plugins/{history-browserstorage-plugin → history-browser-storage}/index.js +2 -2
  16. package/dist/esm/plugins/responses-browser-storage/index.js +41 -0
  17. package/dist/esm/plugins/{responses-indexeddb-plugin → responses-indexeddb}/index.js +24 -21
  18. package/dist/esm/plugins/shopify/index.js +38 -28
  19. package/dist/esm/plugins/single-page-app/index.js +3 -3
  20. package/dist/esm/plugins/web-components/index.js +21 -0
  21. package/dist/esm/plugins/window-object/index.js +1 -1
  22. package/dist/esm/server/index.js +1 -1
  23. package/dist/experience-instance-Bs9t-zff.js +777 -0
  24. package/dist/experience-instance-COUhADSj.cjs +1 -0
  25. package/dist/storage-Cb_71y48.js +94 -0
  26. package/dist/storage-DuRlyFaY.cjs +1 -0
  27. package/dist/{supports-BvrzQAVk.js → supports-BjhuLJ8z.js} +27 -11
  28. package/dist/supports-YvpQZxbh.cjs +1 -0
  29. package/dist/types/client.d.ts +26 -0
  30. package/dist/types/client.d.ts.map +1 -1
  31. package/dist/types/entities/action/action.d.ts +15 -0
  32. package/dist/types/entities/action/action.d.ts.map +1 -0
  33. package/dist/types/entities/experience/experience.d.ts +19 -6
  34. package/dist/types/entities/experience/experience.d.ts.map +1 -1
  35. package/dist/types/entities/experience-instance/experience-instance.d.ts +13 -10
  36. package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
  37. package/dist/types/entities/feature/feature.d.ts +5 -2
  38. package/dist/types/entities/feature/feature.d.ts.map +1 -1
  39. package/dist/types/entities/field/field.d.ts +27 -19
  40. package/dist/types/entities/field/field.d.ts.map +1 -1
  41. package/dist/types/entities/history/history.d.ts.map +1 -1
  42. package/dist/types/entities/predicate/predicate.d.ts +1 -1
  43. package/dist/types/entities/predicate/predicate.d.ts.map +1 -1
  44. package/dist/types/entities/response/response.d.ts +8 -0
  45. package/dist/types/entities/response/response.d.ts.map +1 -1
  46. package/dist/types/exports.d.ts +2 -0
  47. package/dist/types/exports.d.ts.map +1 -1
  48. package/dist/types/picked.d.ts +28 -10
  49. package/dist/types/picked.d.ts.map +1 -1
  50. package/dist/types/plugins/create-experience/create-experience.d.ts +48 -13
  51. package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
  52. package/dist/types/plugins/experience-browser-storage/index.d.ts.map +1 -0
  53. package/dist/types/plugins/experience-browser-storage/plugin.d.ts.map +1 -0
  54. package/dist/types/plugins/history-browser-storage/index.d.ts.map +1 -0
  55. package/dist/types/plugins/history-browser-storage/plugin.d.ts.map +1 -0
  56. package/dist/types/plugins/responses-browser-storage/index.d.ts.map +1 -0
  57. package/dist/types/plugins/responses-browser-storage/plugin.d.ts.map +1 -0
  58. package/dist/types/plugins/responses-indexeddb/index.d.ts.map +1 -0
  59. package/dist/types/plugins/responses-indexeddb/plugin.d.ts.map +1 -0
  60. package/dist/types/plugins/shopify/plugin.d.ts.map +1 -1
  61. package/dist/types/plugins/shopify/utils.d.ts +21 -0
  62. package/dist/types/plugins/shopify/utils.d.ts.map +1 -0
  63. package/dist/types/plugins/web-components/index.d.ts +2 -0
  64. package/dist/types/plugins/web-components/index.d.ts.map +1 -0
  65. package/dist/types/plugins/web-components/plugin.d.ts +3 -0
  66. package/dist/types/plugins/web-components/plugin.d.ts.map +1 -0
  67. package/dist/types/utils/dom.d.ts +5 -5
  68. package/dist/types/utils/dom.d.ts.map +1 -1
  69. package/dist/types/utils/events.d.ts +29 -24
  70. package/dist/types/utils/events.d.ts.map +1 -1
  71. package/dist/types/utils/get-step-fields.d.ts +4 -0
  72. package/dist/types/utils/get-step-fields.d.ts.map +1 -0
  73. package/dist/types/utils/nodes.d.ts +2 -1
  74. package/dist/types/utils/nodes.d.ts.map +1 -1
  75. package/dist/types/utils/storage.d.ts +3 -0
  76. package/dist/types/utils/storage.d.ts.map +1 -1
  77. package/dist/types/utils/supports.d.ts +2 -0
  78. package/dist/types/utils/supports.d.ts.map +1 -1
  79. package/dist/types/utils/user-session.d.ts +5 -0
  80. package/dist/types/utils/user-session.d.ts.map +1 -0
  81. package/package.json +32 -26
  82. package/dist/cjs/plugins/experience-browserstorage-plugin/index.js +0 -1
  83. package/dist/cjs/plugins/history-browserstorage-plugin/index.js +0 -1
  84. package/dist/cjs/plugins/responses-browserstorage-plugin/index.js +0 -1
  85. package/dist/esm/plugins/experience-browserstorage-plugin/index.js +0 -38
  86. package/dist/esm/plugins/responses-browserstorage-plugin/index.js +0 -36
  87. package/dist/experience-instance-6ZKZS7dF.cjs +0 -1
  88. package/dist/experience-instance-BA0EXYg5.js +0 -712
  89. package/dist/storage-BPJwmlva.cjs +0 -1
  90. package/dist/storage-D87xFySf.js +0 -85
  91. package/dist/supports-C0y3-V5V.cjs +0 -1
  92. package/dist/types/plugins/experience-browserstorage-plugin/index.d.ts.map +0 -1
  93. package/dist/types/plugins/experience-browserstorage-plugin/plugin.d.ts.map +0 -1
  94. package/dist/types/plugins/history-browserstorage-plugin/index.d.ts.map +0 -1
  95. package/dist/types/plugins/history-browserstorage-plugin/plugin.d.ts.map +0 -1
  96. package/dist/types/plugins/responses-browserstorage-plugin/index.d.ts.map +0 -1
  97. package/dist/types/plugins/responses-browserstorage-plugin/plugin.d.ts.map +0 -1
  98. package/dist/types/plugins/responses-indexeddb-plugin/index.d.ts.map +0 -1
  99. package/dist/types/plugins/responses-indexeddb-plugin/plugin.d.ts.map +0 -1
  100. /package/dist/types/plugins/{experience-browserstorage-plugin → experience-browser-storage}/index.d.ts +0 -0
  101. /package/dist/types/plugins/{experience-browserstorage-plugin → experience-browser-storage}/plugin.d.ts +0 -0
  102. /package/dist/types/plugins/{history-browserstorage-plugin → history-browser-storage}/index.d.ts +0 -0
  103. /package/dist/types/plugins/{history-browserstorage-plugin → history-browser-storage}/plugin.d.ts +0 -0
  104. /package/dist/types/plugins/{responses-browserstorage-plugin → responses-browser-storage}/index.d.ts +0 -0
  105. /package/dist/types/plugins/{responses-browserstorage-plugin → responses-browser-storage}/plugin.d.ts +0 -0
  106. /package/dist/types/plugins/{responses-indexeddb-plugin → responses-indexeddb}/index.d.ts +0 -0
  107. /package/dist/types/plugins/{responses-indexeddb-plugin → responses-indexeddb}/plugin.d.ts +0 -0
package/dist/esm/index.js CHANGED
@@ -1,206 +1,207 @@
1
- var K = Object.defineProperty;
2
- var q = (t, e, s) => e in t ? K(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
3
- var y = (t, e, s) => q(t, typeof e != "symbol" ? e + "" : e, s);
4
- import { createDomain as k, createApi as x, createEffect as $, attach as G, sample as b, combine as j, createEvent as A } from "effector";
5
- import { createFactory as v, invoke as w } from "@withease/factories";
6
- import { g as L, t as W, c as J, e as R, i as Y, a as Q, b as X, d as Z } from "../experience-instance-BA0EXYg5.js";
7
- import { f as rt } from "../experience-instance-BA0EXYg5.js";
8
- import { l as S } from "../logger-C9a75KZn.js";
9
- import { c as E, s as P, l as O } from "../storage-D87xFySf.js";
10
- import { a as nt } from "../storage-D87xFySf.js";
11
- import { g as ee } from "../id-BW-g3y32.js";
12
- import { i as te } from "../object-JwZ58NOH.js";
13
- import { s as M, a as re, b as se } from "../supports-BvrzQAVk.js";
14
- import { g as it, d as at, i as ct, e as ut, c as lt, f as dt, h as pt } from "../supports-BvrzQAVk.js";
15
- const z = k("experience"), ne = v(
1
+ var W = Object.defineProperty;
2
+ var Y = (t, e, r) => e in t ? W(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var m = (t, e, r) => Y(t, typeof e != "symbol" ? e + "" : e, r);
4
+ import { createDomain as I, createApi as x, createEffect as M, attach as J, sample as F, combine as O, createEvent as C } from "effector";
5
+ import { createFactory as w, invoke as k } from "@withease/factories";
6
+ import { g as U, t as Q, c as X, i as Z, e as B, a as ee, b as te, d as re } from "../experience-instance-Bs9t-zff.js";
7
+ import { f as St } from "../experience-instance-Bs9t-zff.js";
8
+ import { l as v } from "../logger-C9a75KZn.js";
9
+ import { c as R, s as $, l as D } from "../storage-Cb_71y48.js";
10
+ import { a as wt } from "../storage-Cb_71y48.js";
11
+ import { g as se } from "../id-BW-g3y32.js";
12
+ import { i as ne } from "../object-JwZ58NOH.js";
13
+ import { s as _, a as oe, b as ie, c as ae, d as ce } from "../supports-BjhuLJ8z.js";
14
+ import { h as bt, f as It, j as xt, e as Ft, g as Et, i as Pt, k as Rt } from "../supports-BjhuLJ8z.js";
15
+ const H = I("experience"), ue = w(
16
16
  ({ client: t, experience: e }) => {
17
- const s = z.store(e), o = x(s, {
18
- merge(n, f) {
17
+ const r = H.store(e), n = x(r, {
18
+ merge(l, h) {
19
19
  return {
20
- ...n,
21
- ...f.experience
20
+ ...l,
21
+ ...h.experience
22
22
  };
23
23
  }
24
- }), i = s.map((n) => ({
25
- type: n.type,
26
- name: n.name,
27
- decisionLogic: n.decide,
28
- targetSelectors: n.targets
24
+ }), c = r.map((l) => ({
25
+ name: l.name,
26
+ decisionLogic: l.decide,
27
+ targetSelectors: l.targets,
28
+ initializeOpenLogic: e.initializeOpen
29
29
  })), u = t.components.listStore.map(
30
- (n) => n.find((f) => f.name === `experience:${e.id}`) || n.find((f) => f.name === "experience"),
30
+ (l) => l.find((h) => h.name === `experience:${e.id}`) || l.find((h) => h.name === "experience"),
31
31
  { skipVoid: !1 }
32
- ), r = s.map((n) => ({
33
- steps: n.steps,
34
- nodes: n.nodes,
35
- edges: n.edges,
36
- conditionals: n.conditionals
37
- }));
32
+ ), s = r.map((l) => ({
33
+ steps: l.steps,
34
+ nodes: l.nodes,
35
+ edges: l.edges,
36
+ conditionals: l.conditionals
37
+ })), o = e.actions ?? [];
38
38
  return {
39
39
  id: e.id,
40
- configStore: i,
41
- treeStore: r,
40
+ configStore: c,
41
+ treeStore: s,
42
42
  componentStore: u,
43
- merge: o.merge
43
+ actions: o,
44
+ merge: n.merge
44
45
  };
45
46
  }
46
47
  );
47
- function oe(t) {
48
- return w(ne, t);
48
+ function le(t) {
49
+ return k(ue, t);
49
50
  }
50
- const ie = v(({ client: t }) => {
51
- const e = z.store({}), s = x(e, {
52
- register(r, n) {
51
+ const de = w(({ client: t }) => {
52
+ const e = H.store({}), r = x(e, {
53
+ register(s, o) {
53
54
  return {
54
- ...r,
55
- [n.id]: n
55
+ ...s,
56
+ [o.id]: o
56
57
  };
57
58
  }
58
59
  });
59
- function o(r) {
60
- const n = e.getState()[r.id];
61
- if (n) {
62
- n.merge({ experience: r, strategy: "override" });
60
+ function n(s) {
61
+ const o = e.getState()[s.id];
62
+ if (o) {
63
+ o.merge({ experience: s, strategy: "override" });
63
64
  return;
64
65
  }
65
- const f = oe({ client: t, experience: r });
66
- s.register(f);
66
+ const l = le({ client: t, experience: s });
67
+ r.register(l);
67
68
  }
68
- const i = e.map((r) => Object.values(r));
69
- function u(r) {
70
- return e.map((n) => n[r], { skipVoid: !1 });
69
+ const c = e.map((s) => Object.values(s));
70
+ function u(s) {
71
+ return e.map((o) => o[s], { skipVoid: !1 });
71
72
  }
72
73
  return {
73
- register: o,
74
+ register: n,
74
75
  getById: u,
75
- listStore: i
76
+ listStore: c
76
77
  };
77
78
  });
78
- function ae(t) {
79
- return w(ie, t);
79
+ function pe(t) {
80
+ return k(de, t);
80
81
  }
81
- const ce = (t, e) => {
82
+ const ge = (t, e) => {
82
83
  e.register(t);
83
- }, _ = (t, e) => {
84
- const { targetSelectors: s } = e.configStore.getState(), o = L(s, e.id);
85
- o.forEach(
86
- ({ elements: u }) => u.forEach((r) => W(r, e.id))
87
- ), J(o).forEach((u) => {
84
+ }, K = (t, e) => {
85
+ const { targetSelectors: r } = e.configStore.getState(), n = U(r, e.id);
86
+ n.forEach(
87
+ ({ elements: u }) => u.forEach((s) => Q(s, e.id))
88
+ ), X(n, e.id).forEach((u) => {
88
89
  t.experienceInstances.spawn(e, u);
89
90
  });
90
- }, D = async (t) => {
91
+ }, T = async (t) => {
91
92
  await Promise.all(
92
93
  t.experiences.listStore.getState().map(async (e) => {
93
- await ue(t, e) && _(t, e);
94
+ await fe(t, e) && K(t, e);
94
95
  })
95
96
  );
96
- }, ue = async (t, e) => {
97
- const { type: s, decisionLogic: o, targetSelectors: i } = e.configStore.getState();
98
- return L(i, e.id).length < 1 ? !1 : s === "funnel" ? o ? await R(t, o) === !0 : !1 : i.length === 0 ? !1 : Y(o) ? await R(t, o) === !0 : !0;
99
- }, le = (t, e, s) => {
100
- const o = e.name, i = e.setup(t);
101
- if (i) {
102
- const u = s[o] ?? {};
103
- s[o] = Object.freeze({ ...u, ...i });
104
- }
105
- }, de = k("component"), pe = v(
106
- ({ client: t, component: e, name: s }) => {
107
- const o = t.frameworks.getByName(e.frameworkName);
97
+ }, fe = async (t, e) => {
98
+ const { decisionLogic: r, targetSelectors: n } = e.configStore.getState();
99
+ return U(n, e.id).length < 1 || n.length === 0 ? !1 : r && Z(r) ? await B(t, r) === !0 : !0;
100
+ }, me = (t, e, r) => {
101
+ const n = e.name, c = e.setup(t);
102
+ if (c) {
103
+ const u = r[n] ?? {};
104
+ r[n] = Object.freeze({ ...u, ...c });
105
+ }
106
+ }, he = I("component"), ye = w(
107
+ ({ client: t, component: e, name: r }) => {
108
+ const n = t.frameworks.getByName(e.frameworkName);
108
109
  return {
109
- name: s,
110
+ name: r,
110
111
  component: e,
111
- frameworkStore: o
112
+ frameworkStore: n
112
113
  };
113
114
  }
114
115
  );
115
- function ge(t) {
116
- return w(pe, t);
116
+ function Se(t) {
117
+ return k(ye, t);
117
118
  }
118
- const fe = v(({ client: t }) => {
119
- const e = de.store({}), s = x(e, {
120
- register(r, n) {
119
+ const ve = w(({ client: t }) => {
120
+ const e = he.store({}), r = x(e, {
121
+ register(s, o) {
121
122
  return {
122
- ...r,
123
- [n.name]: n
123
+ ...s,
124
+ [o.name]: o
124
125
  };
125
126
  }
126
127
  });
127
- function o(r, n) {
128
- e.getState()[r] && S(
128
+ function n(s, o) {
129
+ e.getState()[s] && v(
129
130
  "warn",
130
- `Component '${r}' already registered. Registering again will override the previous registration.`
131
+ `Component '${s}' already registered. Registering again will override the previous registration.`
131
132
  );
132
- const c = ge({ client: t, name: r, component: n });
133
- s.register(c);
133
+ const h = Se({ client: t, name: s, component: o });
134
+ r.register(h);
134
135
  }
135
- const i = e.map((r) => Object.values(r));
136
- function u(r) {
137
- return e.map((n) => n[r], { skipVoid: !1 });
136
+ const c = e.map((s) => Object.values(s));
137
+ function u(s) {
138
+ return e.map((o) => o[s], { skipVoid: !1 });
138
139
  }
139
140
  return {
140
- register: o,
141
+ register: n,
141
142
  getByName: u,
142
- listStore: i
143
+ listStore: c
143
144
  };
144
145
  });
145
- function me(t) {
146
- return w(fe, t);
146
+ function we(t) {
147
+ return k(ve, t);
147
148
  }
148
- const V = (t, e, s) => {
149
- s.register(t, e);
150
- }, ye = k("framework"), he = v(({ client: t }) => {
151
- const e = ye.store({}), s = x(e, {
152
- register(r, n) {
149
+ const V = (t, e, r) => {
150
+ r.register(t, e);
151
+ }, ke = I("framework"), be = w(({ client: t }) => {
152
+ const e = ke.store({}), r = x(e, {
153
+ register(s, o) {
153
154
  return {
154
- ...r,
155
- [n.name]: n.framework
155
+ ...s,
156
+ [o.name]: o.framework
156
157
  };
157
158
  }
158
159
  });
159
- function o(r, n) {
160
- e.getState()[r] && S(
160
+ function n(s, o) {
161
+ e.getState()[s] && v(
161
162
  "warn",
162
- `Framework '${r}' already registered. Registering again will override the previous registration.`
163
- ), s.register({ name: r, framework: n });
163
+ `Framework '${s}' already registered. Registering again will override the previous registration.`
164
+ ), r.register({ name: s, framework: o });
164
165
  }
165
- const i = e.map((r) => Object.values(r));
166
- function u(r) {
167
- return e.map((n) => n[r], { skipVoid: !1 });
166
+ const c = e.map((s) => Object.values(s));
167
+ function u(s) {
168
+ return e.map((o) => o[s], { skipVoid: !1 });
168
169
  }
169
170
  return {
170
- register: o,
171
+ register: n,
171
172
  getByName: u,
172
- listStore: i
173
+ listStore: c
173
174
  };
174
175
  });
175
- function Se(t) {
176
- return w(he, t);
176
+ function Ie(t) {
177
+ return k(be, t);
177
178
  }
178
- const ve = (t, e) => {
179
+ const xe = (t, e) => {
179
180
  e.register(t.name, t);
180
- }, we = 6e3, C = E("last_ping", "global"), ke = (t) => `${t}/api/v1/ping`, xe = async (t) => {
181
+ }, Fe = 6e3, N = R("last_ping", "global"), Ee = (t) => `${t}/api/v1/ping`, Pe = async (t) => {
181
182
  try {
182
- const e = Date.now(), s = localStorage.getItem(C);
183
- if (s && e - parseInt(s) < we)
183
+ const e = Date.now(), r = localStorage.getItem(N);
184
+ if (r && e - parseInt(r) < Fe)
184
185
  return !0;
185
- const o = ke(t.apiUrl), i = {
186
+ const n = Ee(t.apiUrl), c = {
186
187
  projectId: t.projectId,
187
188
  path: window.location.pathname
188
- }, u = JSON.stringify(i), r = {
189
+ }, u = JSON.stringify(c), s = {
189
190
  "Content-Type": "application/json"
190
- }, n = document.getElementById("picked_script"), f = n == null ? void 0 : n.dataset.verceltoken;
191
- f && (r["x-vercel-protection-bypass"] = f);
192
- const l = (await fetch(o, {
191
+ }, o = document.getElementById("picked_script"), l = o == null ? void 0 : o.dataset.verceltoken;
192
+ l && (s["x-vercel-protection-bypass"] = l);
193
+ const S = (await fetch(n, {
193
194
  method: "POST",
194
- headers: r,
195
+ headers: s,
195
196
  body: u
196
197
  })).ok;
197
- return l && localStorage.setItem(C, e.toString()), l;
198
+ return S && localStorage.setItem(N, e.toString()), S;
198
199
  } catch (e) {
199
- return S("error", e), !1;
200
+ return v("error", e), !1;
200
201
  }
201
202
  };
202
- function Ie(t) {
203
- const e = typeof window < "u", s = {
203
+ function Re(t) {
204
+ const e = typeof window < "u", r = {
204
205
  client: t,
205
206
  responses: t.responses.listStore.getState(),
206
207
  fields: t.fields.listStore.getState(),
@@ -209,362 +210,418 @@ function Ie(t) {
209
210
  sessionStorage: e ? window.sessionStorage : void 0,
210
211
  localStorage: e ? window.localStorage : void 0
211
212
  };
212
- return Object.freeze(s);
213
+ return Object.freeze(r);
213
214
  }
214
- const Fe = k("predicate"), be = v(({ client: t }) => {
215
- const e = Fe.store({}), s = x(e, {
216
- register(r, n) {
215
+ const Ae = I("predicate"), Be = w(({ client: t }) => {
216
+ const e = Ae.store({}), r = x(e, {
217
+ register(s, o) {
217
218
  return {
218
- ...r,
219
- [n.name]: {
220
- name: n.name,
221
- predicate: n.predicate
219
+ ...s,
220
+ [o.name]: {
221
+ name: o.name,
222
+ predicate: o.predicate
222
223
  }
223
224
  };
224
225
  }
225
226
  });
226
- function o(r, n) {
227
- e.getState()[r] && S(
227
+ function n(s, o) {
228
+ e.getState()[s] && v(
228
229
  "warn",
229
- `Predicate '${r}' already registered. Registering again will override the previous registration.`
230
- ), s.register(Object.freeze({ name: r, predicate: n }));
230
+ `Predicate '${s}' already registered. Registering again will override the previous registration.`
231
+ ), r.register(Object.freeze({ name: s, predicate: o }));
231
232
  }
232
- const i = e.map((r) => Object.values(r));
233
- function u(r) {
234
- return e.map((n) => n[r], { skipVoid: !1 });
233
+ const c = e.map((s) => Object.values(s));
234
+ function u(s) {
235
+ return e.map((o) => o[s], { skipVoid: !1 });
235
236
  }
236
237
  return {
237
- register: o,
238
+ register: n,
238
239
  getByName: u,
239
- listStore: i
240
+ listStore: c
240
241
  };
241
242
  });
242
- function Ee(t) {
243
- return w(be, t);
243
+ function $e(t) {
244
+ return k(Be, t);
244
245
  }
245
- const Pe = (t, e, s) => {
246
- s.register(t, e);
247
- }, N = k("feature"), Be = v(() => {
248
- const t = N.store({}), e = N.store([]), s = x(t, {
249
- register(c, l) {
246
+ const je = (t, e, r) => {
247
+ r.register(t, e);
248
+ }, z = I("feature"), Oe = w(({ client: t }) => {
249
+ const e = z.store({}), r = z.store([]), n = x(e, {
250
+ register(d, a) {
250
251
  return {
251
- ...c,
252
- [l.id]: l.feature
252
+ ...d,
253
+ [a.id]: a.feature
253
254
  };
254
255
  }
255
256
  });
256
- function o(c, l) {
257
- t.getState()[c] && S(
257
+ function c(d, a) {
258
+ e.getState()[d] && v(
258
259
  "warn",
259
- `Feature '${c}' already registered. Registering again will override the previous registration.`
260
+ `Feature '${d}' already registered. Registering again will override the previous registration.`
260
261
  );
261
262
  const g = {
262
- id: c,
263
+ id: d,
263
264
  feature: {
264
- ...l,
265
- id: c
265
+ ...a,
266
+ id: d
266
267
  }
267
268
  };
268
- s.register(
269
+ n.register(
269
270
  Object.freeze({
270
- id: c,
271
+ id: d,
271
272
  feature: g
272
273
  })
273
274
  );
274
275
  }
275
- const i = $(
276
+ const u = M(
276
277
  async ({
277
- id: c,
278
- key: l,
279
- storage: a = "local"
278
+ id: d,
279
+ key: a,
280
+ storage: i = "local"
280
281
  }) => {
281
- const g = E(`feature:${c}:${l}`, "global"), m = (a === "session" ? P : O).get(g).boolean();
282
- if (m !== null)
283
- return { id: c, bucket: m };
282
+ const g = R(`feature:${d}:${a}`, "global"), p = (i === "session" ? $ : D).get(g).boolean();
283
+ return p ? { id: d, key: a, bucket: p } : null;
284
284
  }
285
- ), u = $((c) => {
286
- if (!c)
285
+ ), s = M((d) => {
286
+ if (!d)
287
287
  return null;
288
- const l = E(`feature:${c.id}:${c.key}`, "global");
289
- (c.storage === "session" ? P : O).set(l, c.bucket);
290
- }), r = G({
291
- source: { allFeaturesStore: t, resolvedFeaturesStore: e },
292
- effect: async ({ allFeaturesStore: c, resolvedFeaturesStore: l }, { id: a, decide: g }) => {
293
- const p = l.find((h) => h.id === a);
288
+ const a = R(`feature:${d.id}:${d.key}`, "global");
289
+ (d.storage === "session" ? $ : D).set(a, d.bucket);
290
+ }), o = /* @__PURE__ */ new Map(), l = J({
291
+ source: { allFeaturesStore: e, resolvedFeaturesStore: r },
292
+ effect: async ({ allFeaturesStore: d, resolvedFeaturesStore: a }, { id: i, decide: g, key: f }) => {
293
+ const p = a.find((j) => j.id === i);
294
294
  if (p)
295
295
  return p;
296
- const m = c[a];
297
- if (!m)
298
- throw new Error(`Feature with id '${a}' not found`);
299
- const d = await g();
300
- return { id: m.id, bucket: d, storage: m.feature.storage };
296
+ const y = d[i];
297
+ if (!y)
298
+ throw new Error(`Feature with id '${i}' not found`);
299
+ const b = o.get(`${i}:${f}`);
300
+ if (b !== void 0) {
301
+ const j = await b;
302
+ return { id: y.id, bucket: j, key: f, storage: y.feature.storage };
303
+ }
304
+ const A = g();
305
+ o.set(`${i}:${f}`, A);
306
+ const E = await A;
307
+ return { id: y.id, bucket: E, key: f, storage: y.feature.storage };
301
308
  }
302
309
  });
303
- b({
304
- clock: s.register,
305
- fn: (c) => {
306
- const { id: l, feature: a } = c;
307
- return { id: l, key: a.feature.key, storage: a.feature.storage };
310
+ F({
311
+ clock: n.register,
312
+ fn: (d) => {
313
+ const { id: a, feature: i } = d;
314
+ return { id: a, key: i.feature.key, storage: i.feature.storage };
308
315
  },
309
- target: i
310
- }), b({
316
+ target: u
317
+ }), F({
311
318
  source: e,
312
- clock: [i.doneData, r.doneData],
313
- fn: (c, l) => !l || c.some((a) => a.id === l.id) ? c : [...c, l],
314
- target: e
315
- }), b({
316
- source: t,
317
- clock: r.doneData,
318
- fn: (c, l) => {
319
- var d;
320
- const { id: a, bucket: g, storage: p } = l, m = (d = c[a]) == null ? void 0 : d.feature.key;
321
- return m ? { key: m, id: a, bucket: g, storage: p } : null;
319
+ clock: l.doneData,
320
+ fn: (d, a) => {
321
+ var y;
322
+ const { id: i, bucket: g, storage: f } = a, p = (y = d[i]) == null ? void 0 : y.feature.key;
323
+ return p ? { key: p, id: i, bucket: g, storage: f } : null;
322
324
  },
323
- target: u
325
+ target: s
324
326
  });
325
- const n = j({ allFeaturesStore: t, resolvedFeaturesStore: e }).map(
327
+ const h = O({ allFeaturesStore: e, resolvedFeaturesStore: r }).map(
326
328
  ({
327
- allFeaturesStore: c,
328
- resolvedFeaturesStore: l
329
- }) => Object.values(c).map((a) => {
330
- const g = l.find((p) => p.id === a.id);
329
+ allFeaturesStore: d,
330
+ resolvedFeaturesStore: a
331
+ }) => Object.values(d).map((i) => {
332
+ const g = a.find((f) => f.id === i.id);
331
333
  return g ? {
332
- id: a.id,
333
- name: a.feature.name,
334
- key: a.feature.key,
335
- getBucket: () => ({ id: a.id, bucket: g.bucket }),
334
+ id: i.id,
335
+ name: i.feature.name,
336
+ key: i.feature.key,
337
+ getBucket: () => ({ id: i.id, bucket: g.bucket }),
336
338
  isResolved: !0
337
339
  } : {
338
- id: a.id,
339
- name: a.feature.name,
340
- key: a.feature.key,
341
- getBucket: async () => await r(a.feature),
340
+ id: i.id,
341
+ name: i.feature.name,
342
+ key: i.feature.key,
343
+ getBucket: async () => await l(i.feature),
342
344
  isResolved: !1
343
345
  };
344
346
  })
345
347
  );
346
- function f(c) {
347
- return t.map((l) => l[c], { skipVoid: !1 });
348
+ F({
349
+ clock: l.doneData,
350
+ source: { resolvedFeatures: r },
351
+ filter: ({ resolvedFeatures: d }, { id: a }) => !d.some((i) => i.id === a),
352
+ fn: (d, a) => a,
353
+ target: t.eventBus.prepend((d) => ({
354
+ type: "feature_decide",
355
+ feature: d
356
+ }))
357
+ }), F({
358
+ clock: [u.doneData, l.doneData],
359
+ source: r,
360
+ fn: (d, a) => !a || d.some((i) => i.id === a.id) ? d : [...d, a],
361
+ target: r
362
+ });
363
+ function S(d) {
364
+ return e.map((a) => a[d], { skipVoid: !1 });
348
365
  }
349
366
  return {
350
- register: o,
351
- getByName: f,
352
- listStore: n
367
+ register: c,
368
+ getByName: S,
369
+ listStore: h
353
370
  };
354
371
  });
355
- function je() {
356
- return w(Be);
372
+ function Ce(t) {
373
+ return k(Oe, t);
357
374
  }
358
- const Ae = (t, e, s) => {
359
- s.register(t, e);
360
- }, F = k("history");
361
- function T(t, e) {
375
+ const De = (t, e, r) => {
376
+ r.register(t, e);
377
+ }, P = I("history");
378
+ function L(t, e) {
362
379
  return {
363
- id: ee("history-entry"),
380
+ // eslint-disable-next-line sonarjs/pseudo-random
381
+ id: se(`history-entry-${Date.now()}-${Math.random()}}`),
364
382
  node: e,
365
383
  at: Date.now(),
366
384
  experienceId: t
367
385
  };
368
386
  }
369
- const Re = v(() => {
370
- const t = F.store({ entries: [] }), e = F.event(), s = F.event(), o = F.event(), i = F.event();
371
- t.on(e, (r, n) => ({
372
- entries: [...r.entries, T(n.experienceId, n.node)]
373
- })), t.on(s, (r, n) => ({
387
+ const Me = w(() => {
388
+ const t = P.store({ entries: [] }), e = P.event(), r = P.event(), n = P.event(), c = P.event();
389
+ t.on(e, (s, o) => ({
390
+ entries: [...s.entries, L(o.experienceId, o.node)]
391
+ })), t.on(r, (s, o) => ({
374
392
  entries: [
375
- ...r.entries.slice(0, -1),
376
- T(n.experienceId, n.node)
393
+ ...s.entries.slice(0, -1),
394
+ L(o.experienceId, o.node)
377
395
  ]
378
- })), t.on(i, (r, n) => n);
379
- function u(r, n) {
380
- const f = { lastStepIndex: -1, secondLastStepIndex: -1 };
381
- for (let c = r.length - 1; c >= 0; c--) {
382
- const l = r[c], a = l == null ? void 0 : l.node;
383
- if (!(!a || !Q(a)) && !(n && (l == null ? void 0 : l.experienceId) !== n))
384
- if (f.lastStepIndex === -1)
385
- f.lastStepIndex = c;
396
+ })), t.on(c, (s, o) => o);
397
+ function u(s, o) {
398
+ const l = { lastStepIndex: -1, secondLastStepIndex: -1 };
399
+ for (let h = s.length - 1; h >= 0; h--) {
400
+ const S = s[h], d = S == null ? void 0 : S.node;
401
+ if (!(!d || !ee(d)) && !(o && (S == null ? void 0 : S.experienceId) !== o))
402
+ if (l.lastStepIndex === -1)
403
+ l.lastStepIndex = h;
386
404
  else {
387
- f.secondLastStepIndex = c;
405
+ l.secondLastStepIndex = h;
388
406
  break;
389
407
  }
390
408
  }
391
- return f;
409
+ return l;
392
410
  }
393
- return t.on(o, (r, n) => {
394
- const { secondLastStepIndex: f } = u(r.entries, n.experienceId), c = f !== -1 ? r.entries.slice(0, f + 1) : r.entries;
411
+ return t.on(n, (s, o) => {
412
+ const { secondLastStepIndex: l } = u(s.entries, o.experienceId), h = l !== -1 ? s.entries.slice(0, l + 1) : s.entries;
395
413
  return {
396
- ...r,
397
- entries: c
414
+ ...s,
415
+ entries: h
398
416
  };
399
417
  }), {
400
418
  push: e,
401
- replace: s,
402
- back: o,
403
- restore: i,
404
- entriesStore: t.map((r) => r.entries)
419
+ replace: r,
420
+ back: n,
421
+ restore: c,
422
+ entriesStore: t.map((s) => s.entries)
405
423
  };
406
424
  });
407
- function $e() {
408
- return w(Re);
425
+ function Te() {
426
+ return k(Me);
409
427
  }
410
- const Oe = () => A(), De = k("field"), Ve = v(() => {
411
- const t = De.store({}), e = x(t, {
412
- register(r, n) {
428
+ const Ve = () => C(), Ne = I("field"), ze = w(() => {
429
+ const t = Ne.store({}), e = x(t, {
430
+ register(s, o) {
413
431
  return {
414
- ...r,
415
- [n.field.id]: n.field
432
+ ...s,
433
+ [o.field.id]: o.field
416
434
  };
417
435
  }
418
436
  });
419
- function s(r) {
420
- e.register({ field: r });
437
+ function r(s) {
438
+ e.register({ field: s });
421
439
  }
422
- const o = t.map((r) => Object.values(r));
423
- function i(r) {
424
- return t.map((n) => n[r] || null);
440
+ const n = t.map((s) => Object.values(s));
441
+ function c(s) {
442
+ return t.map((o) => o[s] || null);
425
443
  }
426
- function u(r) {
427
- return t.map((n) => Object.values(n).find((f) => f.name === r) || null);
444
+ function u(s) {
445
+ return t.map((o) => Object.values(o).find((l) => l.name === s) || null);
428
446
  }
429
447
  return {
430
- register: s,
431
- getById: i,
432
- listStore: o,
448
+ register: r,
449
+ getById: c,
450
+ listStore: n,
433
451
  getByName: u
434
452
  };
435
453
  });
436
- function Ce() {
437
- return w(Ve);
454
+ function Le() {
455
+ return k(ze);
438
456
  }
439
- const Ne = (t, e) => {
457
+ const Ue = (t, e) => {
440
458
  e.register(t);
441
- }, Te = k("response"), Le = v(({ client: t }) => {
442
- const e = Te.store({}), s = A(), o = A(), i = x(e, {
443
- register(a, g) {
459
+ }, _e = I("action"), He = w(() => {
460
+ const t = _e.store({}), e = x(t, {
461
+ register(u, s) {
462
+ return {
463
+ ...u,
464
+ [s.name]: {
465
+ name: s.name,
466
+ action: s.action
467
+ }
468
+ };
469
+ }
470
+ });
471
+ function r(u, s) {
472
+ e.register({ name: u, action: s });
473
+ }
474
+ const n = t.map((u) => Object.values(u));
475
+ function c(u) {
476
+ return t.map((s) => s[u], { skipVoid: !1 });
477
+ }
478
+ return {
479
+ register: r,
480
+ getByName: c,
481
+ listStore: n
482
+ };
483
+ });
484
+ function Ke() {
485
+ return k(He);
486
+ }
487
+ const qe = (t, e, r) => {
488
+ r.register(t, e);
489
+ }, Ge = I("response"), We = w(({ client: t }) => {
490
+ const e = Ge.store({}), r = C(), n = C(), c = x(e, {
491
+ register(a, i) {
492
+ return {
493
+ ...a,
494
+ [i.fieldId]: i.response
495
+ };
496
+ },
497
+ registerBatch(a, i) {
444
498
  return {
445
499
  ...a,
446
- [g.fieldId]: g.response
500
+ ...i
447
501
  };
448
502
  },
449
- clear(a, g) {
450
- const { [g]: p, ...m } = a;
451
- return m;
503
+ clear(a, i) {
504
+ const { [i]: g, ...f } = a;
505
+ return f;
452
506
  },
453
507
  clearAll() {
454
508
  return {};
455
509
  }
456
510
  });
457
- function u(a, g) {
458
- i.register({ fieldId: a, response: g });
511
+ function u(a, i) {
512
+ c.register({ fieldId: a, response: i });
459
513
  }
460
- async function r(a) {
461
- const g = [];
514
+ async function s(a) {
515
+ const i = [];
462
516
  return await Promise.allSettled(
463
- Object.entries(a).map(async ([p, m]) => {
464
- let d = m;
465
- const h = t.fields.getById(p).getState();
466
- if (!h) {
467
- g.push({
468
- fieldId: p,
469
- userMessage: `Field '${p}' not found`,
470
- systemMessage: `No field with ID '${p}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,
471
- value: d
517
+ Object.entries(a).map(async ([g, f]) => {
518
+ let p = f;
519
+ const y = t.fields.getById(g).getState();
520
+ if (!y) {
521
+ i.push({
522
+ fieldId: g,
523
+ userMessage: `Field '${g}' not found`,
524
+ systemMessage: `No field with ID '${g}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,
525
+ value: p
472
526
  });
473
527
  return;
474
528
  }
475
- if (h.multiple && (typeof d == "string" || typeof d == "number" || typeof d == "boolean") && (d = [d]), !te(h.validation)) {
476
- const I = await R(t, h.validation, {
477
- $input: d
529
+ if (y.multiple && (typeof p == "string" || typeof p == "number" || typeof p == "boolean") && (p = [p]), y.validation && !ne(y.validation)) {
530
+ const b = await B(t, y.validation, {
531
+ $input: p
478
532
  });
479
- if (typeof I == "string") {
480
- g.push({
481
- fieldId: p,
482
- userMessage: I,
483
- systemMessage: `Field validation resulted in an error: ${I}.`,
484
- value: d
533
+ if (typeof b == "string") {
534
+ i.push({
535
+ fieldId: g,
536
+ userMessage: b,
537
+ systemMessage: `Field validation resulted in an error: ${b}.`,
538
+ value: p
485
539
  });
486
540
  return;
487
541
  }
488
- if (I === !1) {
489
- g.push({
490
- fieldId: p,
542
+ if (b === !1) {
543
+ i.push({
544
+ fieldId: g,
491
545
  userMessage: "This field is invalid",
492
546
  systemMessage: "Field validation resulted in an unspecified error.",
493
- value: d
547
+ value: p
494
548
  });
495
549
  return;
496
550
  }
497
551
  }
498
- if (h.required && (typeof d > "u" || d === null || d === "" || Array.isArray(d) && !d.length)) {
499
- g.push({
500
- fieldId: p,
552
+ if (y.required && (typeof p > "u" || p === null || p === "" || Array.isArray(p) && !p.length)) {
553
+ i.push({
554
+ fieldId: g,
501
555
  userMessage: "This field is required",
502
556
  systemMessage: "Field is required.",
503
- value: d
557
+ value: p
504
558
  });
505
559
  return;
506
560
  }
507
- if (!h.multiple && Array.isArray(d) && d.length > 1) {
508
- g.push({
509
- fieldId: p,
561
+ if (!y.multiple && Array.isArray(p) && p.length > 1) {
562
+ i.push({
563
+ fieldId: g,
510
564
  userMessage: "This field expects a single response",
511
565
  systemMessage: "Field expects a single response.",
512
- value: d
566
+ value: p
513
567
  });
514
568
  return;
515
569
  }
516
- if (h.options) {
517
- const I = h.options.map((B) => B.value), H = Array.isArray(d) ? d : [d];
518
- Array.isArray(d) && (H.every((B) => I.includes(B)) || g.push({
519
- fieldId: p,
570
+ if (y.options) {
571
+ const b = y.options.map((E) => E.value), A = Array.isArray(p) ? p : [p];
572
+ Array.isArray(p) && (A.every((E) => b.includes(E)) || i.push({
573
+ fieldId: g,
520
574
  userMessage: "This field expects a valid option",
521
- systemMessage: `Field expects a valid option. Valid options are: ${I.join(", ")}`,
522
- value: d
575
+ systemMessage: `Field expects a valid option. Valid options are: ${b.join(", ")}`,
576
+ value: p
523
577
  }));
524
578
  }
525
579
  })
526
- ), g.length ? { errors: g } : (Object.entries(a).forEach(([p, m]) => {
527
- u(p, m);
528
- }), { errors: [] });
580
+ ), { responsesToCommit: a, validationErrors: i };
529
581
  }
530
- const n = e.map((a) => a), f = e.map((a) => Object.keys(a).map((p) => ({
531
- fieldId: p,
532
- value: a[p]
582
+ async function o(a) {
583
+ const { responsesToCommit: i, validationErrors: g } = await s(a);
584
+ return g.length ? { errors: g } : (c.registerBatch(i), { errors: [] });
585
+ }
586
+ const l = e.map((a) => a), h = e.map((a) => Object.keys(a).map((g) => ({
587
+ fieldId: g,
588
+ value: a[g]
533
589
  })));
534
- function c(a) {
535
- const g = t.fields.getById(a), p = e.map((m) => m[a] || null);
536
- return j({ f: g, r: p }, ({ f: m, r: d }) => d || (m != null && m.defaultValue ? m.defaultValue : null));
537
- }
538
- function l(a) {
539
- const g = t.fields.getByName(a);
540
- return j({ f: g, s: e }, ({ f: p, s: m }) => {
541
- const d = p && m[p.id] || null;
542
- return d || (p != null && p.defaultValue ? p.defaultValue : null);
590
+ function S(a) {
591
+ const i = t.fields.getById(a), g = e.map((f) => f[a] || null);
592
+ return O({ f: i, r: g }, ({ f, r: p }) => p || (f != null && f.defaultValue ? f.defaultValue : null));
593
+ }
594
+ function d(a) {
595
+ const i = t.fields.getByName(a);
596
+ return O({ f: i, s: e }, ({ f: g, s: f }) => {
597
+ const p = g && f[g.id] || null;
598
+ return p || (g != null && g.defaultValue ? g.defaultValue : null);
543
599
  });
544
600
  }
545
- return b({
546
- clock: s,
547
- target: i.clearAll
548
- }), b({
549
- clock: o,
550
- target: i.clear
601
+ return F({
602
+ clock: r,
603
+ target: c.clearAll
604
+ }), F({
605
+ clock: n,
606
+ target: c.clear
551
607
  }), {
552
608
  register: u,
553
- clearAll: s,
554
- clear: o,
555
- commit: r,
556
- listStore: f,
557
- getAllStore: n,
558
- getByFieldId: c,
559
- getByFieldName: l
609
+ clearAll: r,
610
+ clear: n,
611
+ commit: o,
612
+ getResponsesToCommit: s,
613
+ listStore: h,
614
+ getAllStore: l,
615
+ getByFieldId: S,
616
+ getByFieldName: d
560
617
  };
561
618
  });
562
- function Me(t) {
563
- return w(Le, t);
619
+ function Ye(t) {
620
+ return k(We, t);
564
621
  }
565
- const ze = () => "0.0.1-dev.1756875690387";
566
- function _e() {
567
- if (M()) {
622
+ const Je = () => "0.0.1-dev.1762750479117";
623
+ function Qe() {
624
+ if (_()) {
568
625
  const t = [
569
626
  document.currentScript,
570
627
  document.getElementById("picked_script"),
@@ -578,84 +635,103 @@ function _e() {
578
635
  }
579
636
  return "https://api.picked.app";
580
637
  }
581
- function Ue() {
582
- if (!re())
638
+ function Xe() {
639
+ if (!oe())
583
640
  return {};
584
- const t = new URLSearchParams(window.location.search), e = {}, s = /* @__PURE__ */ new Set();
585
- for (const [i] of t.entries())
586
- i.startsWith("picked-") && s.add(i);
587
- for (const i of s) {
588
- const u = i.replace("picked-", "");
589
- e[u] = t.getAll(i);
590
- }
591
- const o = E("s");
592
- if (s.size > 0)
593
- P.set(o, e);
641
+ const t = new URLSearchParams(window.location.search), e = {}, r = /* @__PURE__ */ new Set();
642
+ for (const [c] of t.entries())
643
+ c.startsWith("picked-") && r.add(c);
644
+ for (const c of r) {
645
+ const u = c.replace("picked-", "");
646
+ e[u] = t.getAll(c);
647
+ }
648
+ const n = R("s");
649
+ if (r.size > 0)
650
+ $.set(n, e);
594
651
  else {
595
- const i = P.get(o);
596
- if (i)
597
- return i.json() || {};
652
+ const c = $.get(n);
653
+ if (c)
654
+ return c.json() || {};
598
655
  }
599
656
  return e;
600
657
  }
601
- class U {
658
+ function Ze() {
659
+ if (ae())
660
+ return crypto.randomUUID();
661
+ const t = Date.now().toString(36), e = Math.random().toString(36).substring(2, 15), r = Math.random().toString(36).substring(2, 15), n = Math.random().toString(36).substring(2, 15);
662
+ return `${t}-${e}-${r}-${n}`;
663
+ }
664
+ const et = () => ({
665
+ id: Ze()
666
+ }), tt = R("session", "global"), rt = () => {
667
+ if (!ie()) return null;
668
+ const t = D.get(tt);
669
+ let e = t.isSet() ? t.json() : null;
670
+ return e || (e = et(), t.set(e)), e;
671
+ }, st = () => rt();
672
+ class q {
602
673
  constructor(e) {
603
- y(this, "options");
604
- y(this, "isReady", !1);
605
- y(this, "project");
606
- y(this, "plugins", {});
607
- y(this, "eventBus", Oe());
608
- y(this, "organizationId");
609
- y(this, "projectId");
610
- y(this, "apiUrl");
611
- y(this, "searchParams", Ue());
612
- y(this, "history", $e());
613
- y(this, "components", me({ client: this }));
614
- y(this, "experienceInstances", X({ client: this }));
615
- y(this, "experiences", ae({ client: this }));
616
- y(this, "frameworks", Se({ client: this }));
617
- y(this, "predicates", Ee({ client: this }));
618
- y(this, "features", je());
619
- y(this, "fields", Ce());
620
- y(this, "responses", Me({ client: this }));
621
- S("info", "Picked client initializing."), this.organizationId = e.organizationId, this.projectId = e.projectId, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || _e(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.eventBus({ type: "initialized", version: ze() }), S("info", "Picked client initialized.");
674
+ m(this, "options");
675
+ m(this, "isReady", !1);
676
+ m(this, "project");
677
+ m(this, "plugins", {});
678
+ m(this, "eventBus", Ve());
679
+ m(this, "organizationId");
680
+ m(this, "projectId");
681
+ m(this, "apiUrl");
682
+ m(this, "session");
683
+ m(this, "searchParams", Xe());
684
+ m(this, "history", Te());
685
+ m(this, "components", we({ client: this }));
686
+ m(this, "experienceInstances", te({ client: this }));
687
+ m(this, "experiences", pe({ client: this }));
688
+ m(this, "frameworks", Ie({ client: this }));
689
+ m(this, "predicates", $e({ client: this }));
690
+ m(this, "features", Ce({ client: this }));
691
+ m(this, "responses", Ye({ client: this }));
692
+ m(this, "fields", Le());
693
+ m(this, "actions", Ke());
694
+ v("info", "Picked client initializing."), this.organizationId = e.organizationId, this.projectId = e.projectId, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || Qe(), this.session = st(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.setupActions(), this.eventBus({ type: "initialized", version: Je() }), v("info", "Picked client initialized.");
622
695
  }
623
696
  start() {
624
- xe(this), (async () => {
625
- M() && (document.body && await D(this), await Z(), await D(this), this.eventBus({ type: "ready" }), this.isReady = !0);
697
+ Pe(this), (async () => {
698
+ _() && (document.body && T(this), await re(), await T(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session && this.eventBus({ type: "session", ...this.session }));
626
699
  })();
627
700
  }
628
701
  registerFramework(e) {
629
- ve(e, this.frameworks);
702
+ xe(e, this.frameworks);
630
703
  }
631
- registerComponent(e, s) {
632
- V(e, s, this.components);
704
+ registerComponent(e, r) {
705
+ V(e, r, this.components);
633
706
  }
634
707
  registerPlugin(e) {
635
- le(this, e, this.plugins);
708
+ me(this, e, this.plugins);
636
709
  }
637
- registerFeature(e, s) {
638
- Ae(e, s, this.features);
710
+ registerFeature(e, r) {
711
+ De(e, r, this.features);
639
712
  }
640
- registerPredicate(e, s) {
641
- Pe(e, s, this.predicates);
713
+ registerPredicate(e, r) {
714
+ je(e, r, this.predicates);
642
715
  }
643
716
  registerField(e) {
644
- Ne(e, this.fields);
717
+ Ue(e, this.fields);
718
+ }
719
+ registerAction(e, r) {
720
+ qe(e, r, this.actions);
645
721
  }
646
722
  registerExperience(e) {
647
- e.component && V(`experience:${e.id}`, e.component, this.components), ce(e, this.experiences);
723
+ e.component && V(`experience:${e.id}`, e.component, this.components), ge(e, this.experiences);
648
724
  }
649
725
  getStateSnapshot() {
650
- return Ie(this);
726
+ return Re(this);
651
727
  }
652
728
  async launchExperienceById(e) {
653
- const s = this.experiences.getById(e).getState();
654
- if (!s) {
655
- S("warn", `Experience with id '${e}' not found.`);
729
+ const r = this.experiences.getById(e).getState();
730
+ if (!r) {
731
+ v("warn", `Experience with id '${e}' not found.`);
656
732
  return;
657
733
  }
658
- _(this, s);
734
+ K(this, r);
659
735
  }
660
736
  // private async fetchProject() {
661
737
  // if (this.project) {
@@ -668,35 +744,36 @@ class U {
668
744
  // }
669
745
  setupPlugins() {
670
746
  var e;
671
- (e = this.options.plugins) == null || e.forEach((s) => {
672
- if (Array.isArray(s)) {
673
- s.forEach((i) => {
674
- this.registerPlugin(i);
747
+ (e = this.options.plugins) == null || e.forEach((r) => {
748
+ if (Array.isArray(r)) {
749
+ r.forEach((c) => {
750
+ this.registerPlugin(c);
675
751
  });
676
752
  return;
677
753
  }
678
- const o = typeof s == "function" ? s() : s;
679
- if (Array.isArray(o)) {
680
- o.forEach((i) => this.registerPlugin(i));
754
+ const n = typeof r == "function" ? r() : r;
755
+ if (Array.isArray(n)) {
756
+ n.forEach((c) => this.registerPlugin(c));
681
757
  return;
682
758
  }
683
- this.registerPlugin(o);
759
+ this.registerPlugin(n);
684
760
  });
685
761
  }
686
762
  setupFeatures() {
687
763
  const e = this.options.features;
688
- e && (Object.entries(e).forEach(([s, o]) => {
689
- const i = typeof o == "function" ? o() : o;
690
- this.registerFeature(s, i);
691
- }), this.searchParams.feature && this.searchParams.feature.forEach((s) => {
764
+ e && (Object.entries(e).forEach(([r, n]) => {
765
+ const c = typeof n == "function" ? n() : n;
766
+ this.registerFeature(r, c);
767
+ }), this.searchParams.feature && this.searchParams.feature.forEach((r) => {
692
768
  try {
693
- const [o, i] = s.split(":");
694
- if (!o || !i)
769
+ const [n, c] = r.split(":");
770
+ if (!n || !c)
695
771
  return;
696
- let u = i;
697
- (u === "true" || u === "false") && (u = !!u), this.registerFeature(o, {
698
- key: "*",
699
- name: o,
772
+ let u = c;
773
+ u === "true" && (u = !0), u === "false" && (u = !1), this.registerFeature(n, {
774
+ key: `${u}`,
775
+ // use the assigned bucket value as the key
776
+ name: n,
700
777
  // eslint-disable-next-line sonarjs/function-return-type
701
778
  decide: () => u,
702
779
  storage: "session"
@@ -707,38 +784,73 @@ class U {
707
784
  }
708
785
  setupPredicates() {
709
786
  const e = this.options.predicates;
710
- e && Object.entries(e).forEach(([s, o]) => {
711
- if (typeof o != "function") {
712
- S("warn", `Predicate "${s}" is not a function.`);
787
+ e && Object.entries(e).forEach(([r, n]) => {
788
+ if (typeof n != "function") {
789
+ v("warn", `Predicate "${r}" is not a function.`);
790
+ return;
791
+ }
792
+ this.registerPredicate(r, n);
793
+ });
794
+ }
795
+ setupActions() {
796
+ const e = this.options.actions;
797
+ e && Object.entries(e).forEach(([r, n]) => {
798
+ if (typeof n != "function") {
799
+ v("warn", `Action "${r}" is not a function.`);
713
800
  return;
714
801
  }
715
- this.registerPredicate(s, o);
802
+ this.registerAction(r, n);
716
803
  });
717
804
  }
718
805
  getPluginConfig(e) {
719
806
  return this.plugins[e] ?? {};
720
807
  }
721
808
  }
722
- y(U, "logger", S);
723
- const Ze = (t) => {
724
- const e = new U(t);
725
- return se(e), e;
809
+ m(q, "logger", v);
810
+ function G(t) {
811
+ var e;
812
+ return ((e = t.options) == null ? void 0 : e.some((r) => "condition" in r)) ?? !1;
813
+ }
814
+ function nt(t) {
815
+ return t.some((e) => e.condition || G(e));
816
+ }
817
+ async function ft(t, e) {
818
+ return e.length === 0 || !nt(e) ? e : (await Promise.all(
819
+ e.map(async (n) => {
820
+ if (!(n.condition ? await B(t, n.condition) : !0))
821
+ return null;
822
+ if (!n.options || !G(n))
823
+ return n;
824
+ const s = (await Promise.all(
825
+ n.options.map(async (l) => l.condition ? await B(t, l.condition) ? l : null : l)
826
+ )).filter((l) => l !== null);
827
+ return s.length === n.options.length ? n : s.length === 0 ? null : { ...n, options: s };
828
+ })
829
+ )).filter((n) => n !== null);
830
+ }
831
+ const mt = (t) => {
832
+ const e = new q(t);
833
+ return ce(e), e;
726
834
  };
727
835
  export {
728
- U as Picked,
729
- Ze as createClient,
730
- E as createStorageKey,
731
- rt as isPickedRoot,
732
- O as localStore,
733
- P as sessionStore,
734
- nt as subscribe,
735
- it as supportsCookies,
736
- M as supportsDocument,
737
- at as supportsHistory,
738
- ct as supportsIntersectionObserver,
739
- ut as supportsLocalStorage,
740
- lt as supportsLocation,
741
- dt as supportsSessionStorage,
742
- pt as supportsShadowRoot,
743
- re as supportsWindow
836
+ q as Picked,
837
+ mt as createClient,
838
+ R as createStorageKey,
839
+ B as evaluateRuleLogic,
840
+ ft as getStepFields,
841
+ St as isPickedRoot,
842
+ D as localStore,
843
+ $ as sessionStore,
844
+ wt as subscribe,
845
+ bt as supportsCookies,
846
+ ae as supportsCryptoRandomUUID,
847
+ _ as supportsDocument,
848
+ It as supportsHistory,
849
+ xt as supportsIntersectionObserver,
850
+ ie as supportsLocalStorage,
851
+ Ft as supportsLocation,
852
+ Et as supportsSessionStorage,
853
+ Pt as supportsShadowRoot,
854
+ Rt as supportsWebComponents,
855
+ oe as supportsWindow
744
856
  };