@picked/client 0.0.1-dev.1769554766412 → 0.0.1-dev.1769991916367
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/dist/cjs/index.js +2 -2
- package/dist/cjs/plugins/experience-browser-storage/index.js +1 -1
- package/dist/cjs/plugins/history-browser-storage/index.js +1 -1
- package/dist/cjs/plugins/responses-browser-storage/index.js +1 -1
- package/dist/esm/index.js +939 -221
- package/dist/esm/plugins/experience-browser-storage/index.js +1 -1
- package/dist/esm/plugins/history-browser-storage/index.js +1 -1
- package/dist/esm/plugins/responses-browser-storage/index.js +1 -1
- package/dist/esm/plugins/single-page-app/index.js +3 -3
- package/dist/esm/plugins/web-components/index.js +1 -1
- package/dist/esm/plugins/window-object/index.js +1 -1
- package/dist/esm/server/index.js +7 -7
- package/dist/{experience-instance-DJCJUe0h.js → experience-instance-CwXYJkRx.js} +7 -7
- package/dist/storage-Be5xWNPC.cjs +1 -0
- package/dist/storage-Co_LbKr_.js +239 -0
- package/dist/{supports-DCSoenK6.js → supports-COb-sl36.js} +10 -10
- package/dist/types/utils/events.d.ts +1 -6
- package/dist/types/utils/events.d.ts.map +1 -1
- package/dist/types/utils/storage.d.ts +357 -1
- package/dist/types/utils/storage.d.ts.map +1 -1
- package/package.json +1 -7
- package/dist/cjs/plugins/data-layer/index.js +0 -1
- package/dist/esm/plugins/data-layer/index.js +0 -202
- package/dist/storage-BLmAhfhl.js +0 -94
- package/dist/storage-YlR83AWP.cjs +0 -1
- package/dist/types/plugins/data-layer/custom-event.d.ts +0 -5
- package/dist/types/plugins/data-layer/custom-event.d.ts.map +0 -1
- package/dist/types/plugins/data-layer/index.d.ts +0 -2
- package/dist/types/plugins/data-layer/index.d.ts.map +0 -1
- package/dist/types/plugins/data-layer/plugin.d.ts +0 -55
- package/dist/types/plugins/data-layer/plugin.d.ts.map +0 -1
- package/dist/types/plugins/data-layer/utils.d.ts +0 -39
- package/dist/types/plugins/data-layer/utils.d.ts.map +0 -1
- package/dist/user-session-DQh0BBTx.cjs +0 -1
- package/dist/user-session-XidjAPGf.js +0 -747
package/dist/esm/index.js
CHANGED
|
@@ -1,84 +1,802 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { c as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { createDomain as b, createApi as F, createStore as H, createEffect as R, sample as I, attach as X, combine as O, createEvent as D } from "effector";
|
|
2
|
+
import { createFactory as w, invoke as v } from "@withease/factories";
|
|
3
|
+
import { g as q, t as Z, c as ee, i as te, e as j, a as re, b as ne, d as se } from "../experience-instance-CwXYJkRx.js";
|
|
4
|
+
import { f as jt } from "../experience-instance-CwXYJkRx.js";
|
|
5
|
+
import { l as k } from "../logger-C9a75KZn.js";
|
|
6
|
+
import { c as A, l as C, s as z } from "../storage-Co_LbKr_.js";
|
|
7
|
+
import { a as At } from "../storage-Co_LbKr_.js";
|
|
8
|
+
import { g as ie } from "../id-BW-g3y32.js";
|
|
9
|
+
import { i as oe } from "../object-JwZ58NOH.js";
|
|
10
|
+
import { s as U, a as V, b as ae, c as ce, d as ue } from "../supports-COb-sl36.js";
|
|
11
|
+
import { h as Rt, f as $t, j as Ct, e as zt, g as Ot, i as Dt, k as Ut } from "../supports-COb-sl36.js";
|
|
12
|
+
const K = b("experience"), de = w(
|
|
13
|
+
({ client: t, experience: e }) => {
|
|
14
|
+
const r = K.store(e), n = F(r, {
|
|
15
|
+
merge(a, f) {
|
|
16
|
+
return {
|
|
17
|
+
...a,
|
|
18
|
+
...f.experience
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}), i = r.map((a) => ({
|
|
22
|
+
name: a.name,
|
|
23
|
+
decisionLogic: a.condition ?? a.decide,
|
|
24
|
+
targetSelectors: a.targets,
|
|
25
|
+
initializeOpenLogic: e.initializeOpen
|
|
26
|
+
})), u = t.components.listStore.map(
|
|
27
|
+
(a) => a.find((f) => f.name === `experience:${e.id}`) || a.find((f) => f.name === "experience"),
|
|
28
|
+
{ skipVoid: !1 }
|
|
29
|
+
), o = r.map((a) => ({
|
|
30
|
+
steps: a.steps,
|
|
31
|
+
nodes: a.nodes,
|
|
32
|
+
edges: a.edges,
|
|
33
|
+
conditionals: a.conditionals
|
|
34
|
+
})), s = e.actions ?? [];
|
|
35
|
+
return {
|
|
36
|
+
id: e.id,
|
|
37
|
+
configStore: i,
|
|
38
|
+
treeStore: o,
|
|
39
|
+
componentStore: u,
|
|
40
|
+
actions: s,
|
|
41
|
+
merge: n.merge
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
function le(t) {
|
|
46
|
+
return v(de, t);
|
|
47
|
+
}
|
|
48
|
+
const pe = w(({ client: t }) => {
|
|
49
|
+
const e = K.store({}), r = F(e, {
|
|
50
|
+
register(o, s) {
|
|
51
|
+
return {
|
|
52
|
+
...o,
|
|
53
|
+
[s.id]: s
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
function n(o) {
|
|
58
|
+
const s = e.getState()[o.id];
|
|
59
|
+
if (s) {
|
|
60
|
+
s.merge({ experience: o, strategy: "override" });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const a = le({ client: t, experience: o });
|
|
64
|
+
r.register(a);
|
|
65
|
+
}
|
|
66
|
+
const i = e.map((o) => Object.values(o));
|
|
67
|
+
function u(o) {
|
|
68
|
+
return e.map((s) => s[o], { skipVoid: !1 });
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
register: n,
|
|
72
|
+
getById: u,
|
|
73
|
+
listStore: i
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
function fe(t) {
|
|
77
|
+
return v(pe, t);
|
|
78
|
+
}
|
|
79
|
+
const ge = (t, e) => {
|
|
80
|
+
e.register(t);
|
|
81
|
+
}, W = (t, e) => {
|
|
82
|
+
const { targetSelectors: r } = e.configStore.getState(), n = q(r, e.id);
|
|
83
|
+
n.forEach(
|
|
84
|
+
({ elements: u }) => u.forEach((o) => Z(o, e.id))
|
|
85
|
+
), ee(n, e.id).forEach((u) => {
|
|
86
|
+
t.experienceInstances.spawn(e, u);
|
|
87
|
+
});
|
|
88
|
+
}, M = async (t) => {
|
|
89
|
+
await Promise.all(
|
|
90
|
+
t.experiences.listStore.getState().map(async (e) => {
|
|
91
|
+
await me(t, e) && W(t, e);
|
|
92
|
+
})
|
|
93
|
+
);
|
|
94
|
+
}, me = async (t, e) => {
|
|
95
|
+
const { decisionLogic: r, targetSelectors: n } = e.configStore.getState();
|
|
96
|
+
return q(n, e.id).length < 1 || n.length === 0 ? !1 : r && te(r) ? await j(t, r) === !0 : !0;
|
|
97
|
+
}, he = (t, e, r) => {
|
|
98
|
+
const n = e.name, i = e.setup(t);
|
|
99
|
+
if (i) {
|
|
100
|
+
const u = r[n] ?? {};
|
|
101
|
+
r[n] = Object.freeze({ ...u, ...i });
|
|
102
|
+
}
|
|
103
|
+
}, ye = b("component"), Se = w(
|
|
104
|
+
({ client: t, component: e, name: r }) => {
|
|
105
|
+
const n = t.frameworks.getByName(e.frameworkName);
|
|
106
|
+
return {
|
|
107
|
+
name: r,
|
|
108
|
+
component: e,
|
|
109
|
+
frameworkStore: n
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
function ke(t) {
|
|
114
|
+
return v(Se, t);
|
|
115
|
+
}
|
|
116
|
+
const we = w(({ client: t }) => {
|
|
117
|
+
const e = ye.store({}), r = F(e, {
|
|
118
|
+
register(o, s) {
|
|
119
|
+
return {
|
|
120
|
+
...o,
|
|
121
|
+
[s.name]: s
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
function n(o, s) {
|
|
126
|
+
e.getState()[o] && k(
|
|
127
|
+
"warn",
|
|
128
|
+
`Component '${o}' already registered. Registering again will override the previous registration.`
|
|
129
|
+
);
|
|
130
|
+
const f = ke({ client: t, name: o, component: s });
|
|
131
|
+
r.register(f);
|
|
132
|
+
}
|
|
133
|
+
const i = e.map((o) => Object.values(o));
|
|
134
|
+
function u(o) {
|
|
135
|
+
return e.map((s) => s[o], { skipVoid: !1 });
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
register: n,
|
|
139
|
+
getByName: u,
|
|
140
|
+
listStore: i
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
function ve(t) {
|
|
144
|
+
return v(we, t);
|
|
145
|
+
}
|
|
146
|
+
const T = (t, e, r) => {
|
|
147
|
+
r.register(t, e);
|
|
148
|
+
}, Ie = b("framework"), be = w(({ client: t }) => {
|
|
149
|
+
const e = Ie.store({}), r = F(e, {
|
|
150
|
+
register(o, s) {
|
|
151
|
+
return {
|
|
152
|
+
...o,
|
|
153
|
+
[s.name]: s.framework
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
function n(o, s) {
|
|
158
|
+
e.getState()[o] && k(
|
|
159
|
+
"warn",
|
|
160
|
+
`Framework '${o}' already registered. Registering again will override the previous registration.`
|
|
161
|
+
), r.register({ name: o, framework: s });
|
|
162
|
+
}
|
|
163
|
+
const i = e.map((o) => Object.values(o));
|
|
164
|
+
function u(o) {
|
|
165
|
+
return e.map((s) => s[o], { skipVoid: !1 });
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
register: n,
|
|
169
|
+
getByName: u,
|
|
170
|
+
listStore: i
|
|
171
|
+
};
|
|
172
|
+
});
|
|
173
|
+
function Fe(t) {
|
|
174
|
+
return v(be, t);
|
|
175
|
+
}
|
|
176
|
+
const Ee = (t, e) => {
|
|
177
|
+
e.register(t.name, t);
|
|
178
|
+
}, xe = 6e3, je = A("last_ping", "global"), Pe = (t) => `${t}/api/v1/ping`, Ae = async (t) => {
|
|
179
|
+
try {
|
|
180
|
+
const e = Date.now(), r = C.get(je);
|
|
181
|
+
let n = 0;
|
|
182
|
+
if (r.isSet() && (n = r.json() ?? 0), n && e - n < xe)
|
|
183
|
+
return !0;
|
|
184
|
+
const i = Pe(t.apiUrl), u = {
|
|
185
|
+
projectId: t.projectId,
|
|
186
|
+
path: window.location.pathname
|
|
187
|
+
}, o = JSON.stringify(u), s = {
|
|
188
|
+
"Content-Type": "application/json"
|
|
189
|
+
}, f = document.getElementById("picked_script")?.dataset.verceltoken;
|
|
190
|
+
f && (s["x-vercel-protection-bypass"] = f);
|
|
191
|
+
const S = (await fetch(i, {
|
|
192
|
+
method: "POST",
|
|
193
|
+
headers: s,
|
|
194
|
+
body: o
|
|
195
|
+
})).ok;
|
|
196
|
+
return S && r.set(e), S;
|
|
197
|
+
} catch (e) {
|
|
198
|
+
return k("error", e), !1;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
function Y(t) {
|
|
202
|
+
const e = typeof window < "u", r = {
|
|
203
|
+
client: t,
|
|
204
|
+
responses: t.responses.listStore.getState(),
|
|
205
|
+
fields: t.fields.listStore.getState(),
|
|
206
|
+
location: e ? window.location : void 0,
|
|
207
|
+
document: e ? window.document : void 0,
|
|
208
|
+
sessionStorage: e ? window.sessionStorage : void 0,
|
|
209
|
+
localStorage: e ? window.localStorage : void 0
|
|
210
|
+
};
|
|
211
|
+
return Object.freeze(r);
|
|
212
|
+
}
|
|
213
|
+
const Be = b("predicate"), Re = w(({ client: t }) => {
|
|
214
|
+
const e = Be.store({}), r = F(e, {
|
|
215
|
+
register(s, a) {
|
|
216
|
+
return {
|
|
217
|
+
...s,
|
|
218
|
+
[a.name]: {
|
|
219
|
+
name: a.name,
|
|
220
|
+
predicate: a.predicate
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
function n(s, a) {
|
|
226
|
+
e.getState()[s] && k(
|
|
227
|
+
"warn",
|
|
228
|
+
`Predicate '${s}' already registered. Registering again will override the previous registration.`
|
|
229
|
+
), r.register(Object.freeze({ name: s, predicate: a }));
|
|
230
|
+
}
|
|
231
|
+
const i = e.map((s) => Object.values(s));
|
|
232
|
+
function u(s) {
|
|
233
|
+
return e.map((a) => a[s]?.predicate, { skipVoid: !1 });
|
|
234
|
+
}
|
|
235
|
+
function o(s) {
|
|
236
|
+
const a = H(() => {
|
|
237
|
+
}, {
|
|
238
|
+
skipVoid: !1
|
|
239
|
+
}), f = R(async () => {
|
|
240
|
+
const h = u(s).getState();
|
|
241
|
+
if (!h)
|
|
242
|
+
return;
|
|
243
|
+
const S = Y(t);
|
|
244
|
+
return (...g) => h({ ...S, args: g });
|
|
245
|
+
});
|
|
246
|
+
return I({
|
|
247
|
+
source: { responses: t.responses.listStore, fields: t.fields.listStore },
|
|
248
|
+
target: f
|
|
249
|
+
}), I({
|
|
250
|
+
clock: f.doneData,
|
|
251
|
+
filter: (h) => h !== void 0,
|
|
252
|
+
target: a
|
|
253
|
+
}), f(), a;
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
register: n,
|
|
257
|
+
getByName: u,
|
|
258
|
+
listStore: i,
|
|
259
|
+
getEvokablePredicate: o
|
|
260
|
+
};
|
|
261
|
+
});
|
|
262
|
+
function $e(t) {
|
|
263
|
+
return v(Re, t);
|
|
264
|
+
}
|
|
265
|
+
const Ce = (t, e, r) => {
|
|
266
|
+
r.register(t, e);
|
|
267
|
+
}, _ = b("feature"), ze = w(({ client: t }) => {
|
|
268
|
+
const e = _.store({}), r = _.store([]), n = F(e, {
|
|
269
|
+
register(c, d) {
|
|
270
|
+
return {
|
|
271
|
+
...c,
|
|
272
|
+
[d.id]: d.feature
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
function i(c, d) {
|
|
277
|
+
e.getState()[c] && k(
|
|
278
|
+
"warn",
|
|
279
|
+
`Feature '${c}' already registered. Registering again will override the previous registration.`
|
|
280
|
+
);
|
|
281
|
+
const l = {
|
|
282
|
+
id: c,
|
|
283
|
+
feature: {
|
|
284
|
+
...d,
|
|
285
|
+
id: c
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
n.register(
|
|
289
|
+
Object.freeze({
|
|
290
|
+
id: c,
|
|
291
|
+
feature: l
|
|
292
|
+
})
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
const u = R(
|
|
296
|
+
async ({
|
|
297
|
+
id: c,
|
|
298
|
+
key: d,
|
|
299
|
+
storage: p = "local"
|
|
300
|
+
}) => {
|
|
301
|
+
const l = A(`feature:${c}:${d}`, "global"), y = (p === "session" ? z : C).get(l).boolean();
|
|
302
|
+
return y === null ? null : { id: c, key: d, bucket: y, storage: p };
|
|
303
|
+
}
|
|
304
|
+
), o = R((c) => {
|
|
305
|
+
if (!c)
|
|
306
|
+
return null;
|
|
307
|
+
const d = A(`feature:${c.id}:${c.key}`, "global");
|
|
308
|
+
(c.storage === "session" ? z : C).set(d, c.bucket);
|
|
309
|
+
}), s = /* @__PURE__ */ new Map(), a = X({
|
|
310
|
+
source: { allFeaturesStore: e, resolvedFeaturesStore: r },
|
|
311
|
+
effect: async ({ allFeaturesStore: c, resolvedFeaturesStore: d }, { id: p, decide: l, key: m }) => {
|
|
312
|
+
const y = d.find(
|
|
313
|
+
(B) => B.id === p && B.key === m
|
|
314
|
+
);
|
|
315
|
+
if (y)
|
|
316
|
+
return y;
|
|
317
|
+
const E = c[p];
|
|
318
|
+
if (!E)
|
|
319
|
+
throw new Error(`Feature with id '${p}' not found`);
|
|
320
|
+
const x = s.get(`${p}:${m}`);
|
|
321
|
+
if (x !== void 0) {
|
|
322
|
+
const B = await x;
|
|
323
|
+
return { id: E.id, bucket: B, key: m, storage: E.feature.storage };
|
|
324
|
+
}
|
|
325
|
+
const N = l();
|
|
326
|
+
s.set(`${p}:${m}`, N);
|
|
327
|
+
const Q = await N;
|
|
328
|
+
return { id: E.id, bucket: Q, key: m, storage: E.feature.storage };
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
I({
|
|
332
|
+
clock: n.register,
|
|
333
|
+
fn: (c) => {
|
|
334
|
+
const { id: d, feature: p } = c;
|
|
335
|
+
return { id: d, key: p.feature.key, storage: p.feature.storage };
|
|
336
|
+
},
|
|
337
|
+
target: u
|
|
338
|
+
}), I({
|
|
339
|
+
source: e,
|
|
340
|
+
clock: a.doneData,
|
|
341
|
+
fn: (c, d) => {
|
|
342
|
+
const { id: p, bucket: l, storage: m } = d, y = c[p]?.feature.key;
|
|
343
|
+
return y ? { key: y, id: p, bucket: l, storage: m } : null;
|
|
344
|
+
},
|
|
345
|
+
target: o
|
|
346
|
+
});
|
|
347
|
+
const f = O({ allFeaturesStore: e, resolvedFeaturesStore: r }).map(
|
|
348
|
+
({
|
|
349
|
+
allFeaturesStore: c,
|
|
350
|
+
resolvedFeaturesStore: d
|
|
351
|
+
}) => Object.values(c).map((p) => {
|
|
352
|
+
const l = d.find(
|
|
353
|
+
(m) => m.id === p.id && m.key === p.feature.key
|
|
354
|
+
);
|
|
355
|
+
return l ? {
|
|
356
|
+
id: p.id,
|
|
357
|
+
name: p.feature.name,
|
|
358
|
+
key: p.feature.key,
|
|
359
|
+
getBucket: () => ({ id: p.id, bucket: l.bucket }),
|
|
360
|
+
isResolved: !0
|
|
361
|
+
} : {
|
|
362
|
+
id: p.id,
|
|
363
|
+
name: p.feature.name,
|
|
364
|
+
key: p.feature.key,
|
|
365
|
+
getBucket: async () => await a(p.feature),
|
|
366
|
+
isResolved: !1
|
|
367
|
+
};
|
|
368
|
+
})
|
|
369
|
+
);
|
|
370
|
+
I({
|
|
371
|
+
clock: a.doneData,
|
|
372
|
+
source: { resolvedFeatures: r },
|
|
373
|
+
filter: ({ resolvedFeatures: c }, { id: d, key: p }) => !c.some(
|
|
374
|
+
(m) => m.id === d && m.key === p
|
|
375
|
+
),
|
|
376
|
+
fn: (c, d) => d,
|
|
377
|
+
target: t.eventBus.prepend((c) => ({
|
|
378
|
+
type: "feature_decide",
|
|
379
|
+
feature: c
|
|
380
|
+
}))
|
|
381
|
+
}), I({
|
|
382
|
+
clock: [u.doneData, a.doneData],
|
|
383
|
+
source: r,
|
|
384
|
+
fn: (c, d) => !d || c.some(
|
|
385
|
+
(l) => l.id === d.id && l.key === d.key
|
|
386
|
+
) ? c : [...c, d],
|
|
387
|
+
target: r
|
|
388
|
+
});
|
|
389
|
+
function h(c) {
|
|
390
|
+
return f.map((d) => d.find((p) => p.id === c));
|
|
391
|
+
}
|
|
392
|
+
function S(c) {
|
|
393
|
+
return e.map((d) => d[c], { skipVoid: !1 });
|
|
394
|
+
}
|
|
395
|
+
function g(c) {
|
|
396
|
+
const d = H(
|
|
397
|
+
async () => {
|
|
398
|
+
},
|
|
399
|
+
{ skipVoid: !1 }
|
|
400
|
+
), p = R(async () => {
|
|
401
|
+
const l = h(c).getState();
|
|
402
|
+
if (l)
|
|
403
|
+
return async () => (await l.getBucket()).bucket;
|
|
404
|
+
});
|
|
405
|
+
return I({
|
|
406
|
+
source: r,
|
|
407
|
+
filter: (l) => l.some((m) => m.id === c),
|
|
408
|
+
target: p
|
|
409
|
+
}), I({
|
|
410
|
+
clock: p.doneData,
|
|
411
|
+
filter: (l) => l !== void 0,
|
|
412
|
+
target: d
|
|
413
|
+
}), p(), d;
|
|
414
|
+
}
|
|
415
|
+
return {
|
|
416
|
+
register: i,
|
|
417
|
+
getById: h,
|
|
418
|
+
getByName: S,
|
|
419
|
+
listStore: f,
|
|
420
|
+
getEvokableFeature: g
|
|
421
|
+
};
|
|
422
|
+
});
|
|
423
|
+
function Oe(t) {
|
|
424
|
+
return v(ze, t);
|
|
425
|
+
}
|
|
426
|
+
const De = (t, e, r) => {
|
|
427
|
+
r.register(t, e);
|
|
428
|
+
}, P = b("history");
|
|
429
|
+
function L(t, e) {
|
|
430
|
+
return {
|
|
431
|
+
// eslint-disable-next-line sonarjs/pseudo-random
|
|
432
|
+
id: ie(`history-entry-${Date.now()}-${Math.random()}}`),
|
|
433
|
+
node: e,
|
|
434
|
+
at: Date.now(),
|
|
435
|
+
experienceId: t
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
const Ue = w(() => {
|
|
439
|
+
const t = P.store({ entries: [] }), e = P.event(), r = P.event(), n = P.event(), i = P.event();
|
|
440
|
+
t.on(e, (o, s) => ({
|
|
441
|
+
entries: [...o.entries, L(s.experienceId, s.node)]
|
|
442
|
+
})), t.on(r, (o, s) => ({
|
|
443
|
+
entries: [
|
|
444
|
+
...o.entries.slice(0, -1),
|
|
445
|
+
L(s.experienceId, s.node)
|
|
446
|
+
]
|
|
447
|
+
})), t.on(i, (o, s) => s);
|
|
448
|
+
function u(o, s) {
|
|
449
|
+
const a = { lastStepIndex: -1, secondLastStepIndex: -1 };
|
|
450
|
+
for (let f = o.length - 1; f >= 0; f--) {
|
|
451
|
+
const h = o[f], S = h?.node;
|
|
452
|
+
if (!(!S || !re(S)) && !(s && h?.experienceId !== s))
|
|
453
|
+
if (a.lastStepIndex === -1)
|
|
454
|
+
a.lastStepIndex = f;
|
|
455
|
+
else {
|
|
456
|
+
a.secondLastStepIndex = f;
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return a;
|
|
461
|
+
}
|
|
462
|
+
return t.on(n, (o, s) => {
|
|
463
|
+
const { secondLastStepIndex: a } = u(o.entries, s.experienceId), f = a !== -1 ? o.entries.slice(0, a + 1) : o.entries;
|
|
464
|
+
return {
|
|
465
|
+
...o,
|
|
466
|
+
entries: f
|
|
467
|
+
};
|
|
468
|
+
}), {
|
|
469
|
+
push: e,
|
|
470
|
+
replace: r,
|
|
471
|
+
back: n,
|
|
472
|
+
restore: i,
|
|
473
|
+
entriesStore: t.map((o) => o.entries)
|
|
474
|
+
};
|
|
475
|
+
});
|
|
476
|
+
function Ve() {
|
|
477
|
+
return v(Ue);
|
|
478
|
+
}
|
|
479
|
+
const Ne = () => D(), Me = b("field"), Te = w(() => {
|
|
480
|
+
const t = Me.store({}), e = F(t, {
|
|
481
|
+
register(s, a) {
|
|
482
|
+
return {
|
|
483
|
+
...s,
|
|
484
|
+
[a.field.id]: a.field
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
function r(s) {
|
|
489
|
+
e.register({ field: s });
|
|
490
|
+
}
|
|
491
|
+
function n(s, a) {
|
|
492
|
+
const f = u(s).getState();
|
|
493
|
+
if (!f)
|
|
494
|
+
return;
|
|
495
|
+
const h = Object.assign({}, f, {
|
|
496
|
+
...a
|
|
497
|
+
});
|
|
498
|
+
e.register({ field: { ...h } });
|
|
499
|
+
}
|
|
500
|
+
const i = t.map((s) => Object.values(s));
|
|
501
|
+
function u(s) {
|
|
502
|
+
return t.map((a) => a[s] || null);
|
|
503
|
+
}
|
|
504
|
+
function o(s) {
|
|
505
|
+
return t.map((a) => Object.values(a).find((f) => f.name === s) || null);
|
|
506
|
+
}
|
|
507
|
+
return {
|
|
508
|
+
register: r,
|
|
509
|
+
update: n,
|
|
510
|
+
getById: u,
|
|
511
|
+
listStore: i,
|
|
512
|
+
getByName: o
|
|
513
|
+
};
|
|
514
|
+
});
|
|
515
|
+
function _e() {
|
|
516
|
+
return v(Te);
|
|
517
|
+
}
|
|
518
|
+
const Le = (t, e) => {
|
|
519
|
+
e.register(t);
|
|
520
|
+
}, Ge = b("action"), He = w(() => {
|
|
521
|
+
const t = Ge.store({}), e = F(t, {
|
|
522
|
+
register(o, s) {
|
|
523
|
+
return {
|
|
524
|
+
...o,
|
|
525
|
+
[s.name]: {
|
|
526
|
+
name: s.name,
|
|
527
|
+
action: s.action
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
function r(o, s) {
|
|
533
|
+
e.register({ name: o, action: s });
|
|
534
|
+
}
|
|
535
|
+
const n = t.map((o) => Object.values(o));
|
|
536
|
+
function i(o) {
|
|
537
|
+
return t.map((s) => s[o], { skipVoid: !1 });
|
|
538
|
+
}
|
|
539
|
+
function u(o) {
|
|
540
|
+
return t.map(
|
|
541
|
+
(s) => {
|
|
542
|
+
const a = s[o];
|
|
543
|
+
return a ? a.action : void 0;
|
|
544
|
+
},
|
|
545
|
+
{ skipVoid: !1 }
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
return {
|
|
549
|
+
register: r,
|
|
550
|
+
getByName: i,
|
|
551
|
+
listStore: n,
|
|
552
|
+
getEvokableAction: u
|
|
553
|
+
};
|
|
554
|
+
});
|
|
555
|
+
function qe() {
|
|
556
|
+
return v(He);
|
|
557
|
+
}
|
|
558
|
+
const Ke = (t, e, r) => {
|
|
559
|
+
r.register(t, e);
|
|
560
|
+
};
|
|
561
|
+
function G(t) {
|
|
562
|
+
return typeof t > "u" || t === null || t === "" || Array.isArray(t) && !t.length;
|
|
563
|
+
}
|
|
564
|
+
const We = b("response"), Ye = w(({ client: t }) => {
|
|
565
|
+
const e = We.store({}), r = D(), n = D(), i = F(e, {
|
|
566
|
+
register(g, c) {
|
|
567
|
+
return {
|
|
568
|
+
...g,
|
|
569
|
+
[c.fieldId]: c.response
|
|
570
|
+
};
|
|
571
|
+
},
|
|
572
|
+
registerBatch(g, c) {
|
|
573
|
+
return {
|
|
574
|
+
...g,
|
|
575
|
+
...c
|
|
576
|
+
};
|
|
577
|
+
},
|
|
578
|
+
clear(g, c) {
|
|
579
|
+
const { [c]: d, ...p } = g;
|
|
580
|
+
return p;
|
|
581
|
+
},
|
|
582
|
+
clearAll() {
|
|
583
|
+
return {};
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
function u(g, c) {
|
|
587
|
+
if (typeof g == "string") {
|
|
588
|
+
if (c === void 0)
|
|
589
|
+
throw new Error("Response is required when registering a single field");
|
|
590
|
+
i.register({ fieldId: g, response: c });
|
|
591
|
+
} else
|
|
592
|
+
i.registerBatch(g);
|
|
593
|
+
}
|
|
594
|
+
async function o(g) {
|
|
595
|
+
const c = [];
|
|
596
|
+
return await Promise.allSettled(
|
|
597
|
+
Object.entries(g).map(async ([d, p]) => {
|
|
598
|
+
let l = p;
|
|
599
|
+
const m = t.fields.getById(d).getState();
|
|
600
|
+
if (!m) {
|
|
601
|
+
c.push({
|
|
602
|
+
fieldId: d,
|
|
603
|
+
userMessage: `Field '${d}' not found`,
|
|
604
|
+
systemMessage: `No field with ID '${d}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,
|
|
605
|
+
value: l
|
|
606
|
+
});
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
if (m.multiple && (typeof l == "string" || typeof l == "number" || typeof l == "boolean") && (l = [l]), m.validation && !oe(m.validation) && !G(l)) {
|
|
610
|
+
const y = await j(t, m.validation, {
|
|
611
|
+
$input: l
|
|
612
|
+
});
|
|
613
|
+
if (typeof y == "string") {
|
|
614
|
+
c.push({
|
|
615
|
+
fieldId: d,
|
|
616
|
+
userMessage: y,
|
|
617
|
+
systemMessage: `Field validation resulted in an error: ${y}.`,
|
|
618
|
+
value: l
|
|
619
|
+
});
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
if (y === !1) {
|
|
623
|
+
c.push({
|
|
624
|
+
fieldId: d,
|
|
625
|
+
userMessage: "This field is invalid",
|
|
626
|
+
systemMessage: "Field validation resulted in an unspecified error.",
|
|
627
|
+
value: l
|
|
628
|
+
});
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
if (m.required && G(l)) {
|
|
633
|
+
c.push({
|
|
634
|
+
fieldId: d,
|
|
635
|
+
userMessage: "This field is required",
|
|
636
|
+
systemMessage: "Field is required.",
|
|
637
|
+
value: l
|
|
638
|
+
});
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
if (!m.multiple && Array.isArray(l) && l.length > 1) {
|
|
642
|
+
c.push({
|
|
643
|
+
fieldId: d,
|
|
644
|
+
userMessage: "This field expects a single response",
|
|
645
|
+
systemMessage: "Field expects a single response.",
|
|
646
|
+
value: l
|
|
647
|
+
});
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
if (m.options) {
|
|
651
|
+
const y = m.options.map((x) => x.value), E = Array.isArray(l) ? l : [l];
|
|
652
|
+
Array.isArray(l) && (E.every((x) => y.includes(x)) || c.push({
|
|
653
|
+
fieldId: d,
|
|
654
|
+
userMessage: "This field expects a valid option",
|
|
655
|
+
systemMessage: `Field expects a valid option. Valid options are: ${y.join(", ")}`,
|
|
656
|
+
value: l
|
|
657
|
+
}));
|
|
658
|
+
}
|
|
659
|
+
})
|
|
660
|
+
), { responsesToCommit: g, validationErrors: c };
|
|
661
|
+
}
|
|
662
|
+
async function s(g) {
|
|
663
|
+
const { responsesToCommit: c, validationErrors: d } = await o(g);
|
|
664
|
+
return d.length ? { errors: d } : (i.registerBatch(c), { errors: [] });
|
|
665
|
+
}
|
|
666
|
+
const a = e.map((g) => g), f = e.map((g) => Object.keys(g).map((d) => ({
|
|
667
|
+
fieldId: d,
|
|
668
|
+
value: g[d]
|
|
669
|
+
})));
|
|
670
|
+
function h(g) {
|
|
671
|
+
const c = t.fields.getById(g), d = e.map((p) => p[g] || null);
|
|
672
|
+
return O({ f: c, r: d }, ({ f: p, r: l }) => l || (p?.defaultValue ? p.defaultValue : null));
|
|
673
|
+
}
|
|
674
|
+
function S(g) {
|
|
675
|
+
const c = t.fields.getByName(g);
|
|
676
|
+
return O({ f: c, s: e }, ({ f: d, s: p }) => {
|
|
677
|
+
const l = d && p[d.id] || null;
|
|
678
|
+
return l || (d?.defaultValue ? d.defaultValue : null);
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
return I({
|
|
682
|
+
clock: r,
|
|
683
|
+
target: i.clearAll
|
|
684
|
+
}), I({
|
|
685
|
+
clock: n,
|
|
686
|
+
target: i.clear
|
|
687
|
+
}), {
|
|
688
|
+
register: u,
|
|
689
|
+
clearAll: r,
|
|
690
|
+
clear: n,
|
|
691
|
+
commit: s,
|
|
692
|
+
getResponsesToCommit: o,
|
|
693
|
+
listStore: f,
|
|
694
|
+
getAllStore: a,
|
|
695
|
+
getByFieldId: h,
|
|
696
|
+
getByFieldName: S
|
|
697
|
+
};
|
|
698
|
+
});
|
|
699
|
+
function Je(t) {
|
|
700
|
+
return v(Ye, t);
|
|
701
|
+
}
|
|
702
|
+
const Qe = () => "0.0.1-dev.1769991916367";
|
|
703
|
+
function Xe() {
|
|
704
|
+
if (U()) {
|
|
705
|
+
const t = [
|
|
20
706
|
document.currentScript,
|
|
21
707
|
document.getElementById("picked_script"),
|
|
22
708
|
document.getElementById("picked"),
|
|
23
709
|
document.getElementById("cvly"),
|
|
24
710
|
document.getElementById("cvly-x")
|
|
25
711
|
];
|
|
26
|
-
for (const
|
|
27
|
-
if (
|
|
28
|
-
return
|
|
712
|
+
for (const e of t)
|
|
713
|
+
if (e?.dataset.api)
|
|
714
|
+
return e.dataset.api;
|
|
29
715
|
}
|
|
30
716
|
return "https://api.picked.app";
|
|
31
717
|
}
|
|
32
|
-
function
|
|
33
|
-
if (!
|
|
718
|
+
function Ze() {
|
|
719
|
+
if (!V())
|
|
34
720
|
return {};
|
|
35
|
-
const
|
|
36
|
-
for (const [
|
|
37
|
-
|
|
38
|
-
for (const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
const n =
|
|
43
|
-
if (
|
|
44
|
-
|
|
721
|
+
const t = new URLSearchParams(window.location.search), e = {}, r = /* @__PURE__ */ new Set();
|
|
722
|
+
for (const [i] of t.entries())
|
|
723
|
+
i.startsWith("picked-") && r.add(i);
|
|
724
|
+
for (const i of r) {
|
|
725
|
+
const u = i.replace("picked-", "");
|
|
726
|
+
e[u] = t.getAll(i);
|
|
727
|
+
}
|
|
728
|
+
const n = A("s");
|
|
729
|
+
if (r.size > 0)
|
|
730
|
+
z.set(n, e);
|
|
45
731
|
else {
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
return
|
|
732
|
+
const i = z.get(n);
|
|
733
|
+
if (i)
|
|
734
|
+
return i.json() || {};
|
|
49
735
|
}
|
|
50
|
-
return
|
|
736
|
+
return e;
|
|
737
|
+
}
|
|
738
|
+
function et() {
|
|
739
|
+
if (ce())
|
|
740
|
+
return crypto.randomUUID();
|
|
741
|
+
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);
|
|
742
|
+
return `${t}-${e}-${r}-${n}`;
|
|
51
743
|
}
|
|
52
|
-
|
|
53
|
-
|
|
744
|
+
const tt = A("session", "global"), rt = () => {
|
|
745
|
+
const t = C.get(tt);
|
|
746
|
+
let e;
|
|
747
|
+
t.isSet() && (e = t.json());
|
|
748
|
+
const r = (i) => t.set({
|
|
749
|
+
id: i.id,
|
|
750
|
+
isUser: i.isUser,
|
|
751
|
+
identifiers: i.identifiers
|
|
752
|
+
}), n = {
|
|
753
|
+
id: e?.id ?? et(),
|
|
754
|
+
isUser: e?.isUser ?? void 0,
|
|
755
|
+
identifiers: e?.identifiers ?? void 0,
|
|
756
|
+
setIsUser(i) {
|
|
757
|
+
this.isUser = i, r(this);
|
|
758
|
+
},
|
|
759
|
+
setIdentifier(i, u) {
|
|
760
|
+
this.identifiers = { ...this.identifiers, [i]: u }, r(this);
|
|
761
|
+
},
|
|
762
|
+
removeIdentifier(i) {
|
|
763
|
+
this.identifiers && (this.identifiers = Object.fromEntries(
|
|
764
|
+
Object.entries(this.identifiers).filter(([u]) => u !== i)
|
|
765
|
+
), this.identifiers = Object.keys(this.identifiers).length ? this.identifiers : void 0, r(this));
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
return r(n), n;
|
|
769
|
+
}, nt = () => ae() ? rt() : null;
|
|
770
|
+
function st() {
|
|
771
|
+
if (V())
|
|
54
772
|
return globalThis.window.pickedConfig;
|
|
55
773
|
}
|
|
56
|
-
function
|
|
57
|
-
if (!
|
|
774
|
+
function it() {
|
|
775
|
+
if (!V())
|
|
58
776
|
return;
|
|
59
|
-
const
|
|
60
|
-
return
|
|
777
|
+
const t = st(), e = t?.organizationId, r = t?.projectId;
|
|
778
|
+
return e && r ? { organizationId: e, projectId: r } : void 0;
|
|
61
779
|
}
|
|
62
|
-
function
|
|
63
|
-
if (!
|
|
780
|
+
function ot() {
|
|
781
|
+
if (!U())
|
|
64
782
|
return;
|
|
65
|
-
const
|
|
783
|
+
const t = document.getElementById("picked_script") || document.querySelector("script#picked") || // legacy support for 'cvly' script tag
|
|
66
784
|
document.getElementById("cvly");
|
|
67
|
-
if (!
|
|
785
|
+
if (!t)
|
|
68
786
|
return;
|
|
69
|
-
const
|
|
70
|
-
return
|
|
787
|
+
const e = t.dataset.organizationid || t.getAttribute("organization-id"), r = t.dataset.projectid || t.getAttribute("project-id");
|
|
788
|
+
return e && r ? { organizationId: e, projectId: r } : void 0;
|
|
71
789
|
}
|
|
72
|
-
function
|
|
73
|
-
const { organizationId:
|
|
74
|
-
if (
|
|
75
|
-
return { organizationId:
|
|
76
|
-
const n =
|
|
790
|
+
function at(t) {
|
|
791
|
+
const { organizationId: e, projectId: r } = t;
|
|
792
|
+
if (e && r)
|
|
793
|
+
return { organizationId: e, projectId: r };
|
|
794
|
+
const n = it();
|
|
77
795
|
if (n)
|
|
78
796
|
return n;
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
return
|
|
797
|
+
const i = ot();
|
|
798
|
+
if (i)
|
|
799
|
+
return i;
|
|
82
800
|
throw new Error(
|
|
83
801
|
`organizationId and projectId are required. You can provide them via one of:
|
|
84
802
|
(1) createClient({ organizationId, projectId }) options;
|
|
@@ -86,147 +804,147 @@ function X(e) {
|
|
|
86
804
|
(3) a <script> tag with id 'picked_script', 'picked', or 'cvly' that includes data-organizationid/data-projectid (or organization-id/project-id) attributes.`
|
|
87
805
|
);
|
|
88
806
|
}
|
|
89
|
-
function
|
|
90
|
-
return
|
|
807
|
+
function $(t) {
|
|
808
|
+
return t == null || t === "" || Number.isNaN(t);
|
|
91
809
|
}
|
|
92
|
-
const
|
|
93
|
-
default: (
|
|
94
|
-
append: (
|
|
95
|
-
prepend: (
|
|
96
|
-
upper: (
|
|
97
|
-
lower: (
|
|
98
|
-
capitalize: (
|
|
99
|
-
list: (
|
|
100
|
-
if (!
|
|
101
|
-
return
|
|
102
|
-
const
|
|
103
|
-
if (Array.isArray(
|
|
104
|
-
return
|
|
105
|
-
if (
|
|
106
|
-
const
|
|
107
|
-
return
|
|
810
|
+
const ct = {
|
|
811
|
+
default: (t, e) => $(t) ? String(e ?? "") : String(t),
|
|
812
|
+
append: (t, e) => e && !$(t) ? `${t} ${e}` : t,
|
|
813
|
+
prepend: (t, e) => e && !$(t) ? `${e} ${t}` : t,
|
|
814
|
+
upper: (t) => typeof t == "string" ? t.toUpperCase() : t,
|
|
815
|
+
lower: (t) => typeof t == "string" ? t.toLowerCase() : t,
|
|
816
|
+
capitalize: (t) => typeof t == "string" ? t.charAt(0).toUpperCase() + t.slice(1) : t,
|
|
817
|
+
list: (t) => {
|
|
818
|
+
if (!t || typeof t != "object")
|
|
819
|
+
return t;
|
|
820
|
+
const e = new Intl.ListFormat("en", { style: "long", type: "conjunction" });
|
|
821
|
+
if (Array.isArray(t))
|
|
822
|
+
return e.format(t.map(String));
|
|
823
|
+
if (t instanceof Map) {
|
|
824
|
+
const r = Array.from(t.entries()).map(([n, i]) => `${n}: ${i}`);
|
|
825
|
+
return e.format(r);
|
|
108
826
|
}
|
|
109
|
-
return
|
|
827
|
+
return t instanceof Set ? e.format(Array.from(t).map(String)) : t;
|
|
110
828
|
}
|
|
111
829
|
};
|
|
112
|
-
function
|
|
113
|
-
return typeof
|
|
830
|
+
function ut(t) {
|
|
831
|
+
return typeof t == "object" && t !== null;
|
|
114
832
|
}
|
|
115
|
-
function
|
|
116
|
-
let
|
|
117
|
-
for (const n of
|
|
118
|
-
if (
|
|
119
|
-
|
|
833
|
+
function dt(t, e) {
|
|
834
|
+
let r = e;
|
|
835
|
+
for (const n of t.split("."))
|
|
836
|
+
if (ut(r) && n in r)
|
|
837
|
+
r = r[n];
|
|
120
838
|
else
|
|
121
839
|
return;
|
|
122
|
-
return typeof
|
|
840
|
+
return typeof r == "function" ? r() : r;
|
|
123
841
|
}
|
|
124
|
-
function
|
|
125
|
-
const
|
|
126
|
-
let
|
|
127
|
-
for (const
|
|
128
|
-
const [
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
return
|
|
842
|
+
function lt(t, e) {
|
|
843
|
+
const r = t.split("|").map((u) => u.trim()), n = r.shift() ?? "";
|
|
844
|
+
let i = dt(n, e);
|
|
845
|
+
for (const u of r) {
|
|
846
|
+
const [o, ...s] = u.split(":"), a = o?.trim() ?? "", f = s.join(":").trim().replaceAll(/(?:^['"]|['"]$)/g, ""), h = ct[a];
|
|
847
|
+
h && (i = h(i, f));
|
|
848
|
+
}
|
|
849
|
+
return $(i) ? "" : typeof i == "object" ? JSON.stringify(i) : String(i);
|
|
132
850
|
}
|
|
133
|
-
function
|
|
134
|
-
let
|
|
135
|
-
for (; n <
|
|
136
|
-
if (
|
|
851
|
+
function pt(t, e) {
|
|
852
|
+
let r = "", n = 0;
|
|
853
|
+
for (; n < t.length; )
|
|
854
|
+
if (t[n] === "{" && t[n + 1] === "{") {
|
|
137
855
|
n += 2;
|
|
138
|
-
let
|
|
139
|
-
for (; n <
|
|
140
|
-
if (
|
|
856
|
+
let i = "";
|
|
857
|
+
for (; n < t.length; ) {
|
|
858
|
+
if (t[n] === "}" && t[n + 1] === "}") {
|
|
141
859
|
n += 2;
|
|
142
860
|
break;
|
|
143
861
|
}
|
|
144
|
-
|
|
862
|
+
i += t[n++];
|
|
145
863
|
}
|
|
146
|
-
|
|
864
|
+
r += lt(i.trim(), e);
|
|
147
865
|
} else
|
|
148
|
-
|
|
149
|
-
return
|
|
866
|
+
r += t[n++];
|
|
867
|
+
return r;
|
|
150
868
|
}
|
|
151
|
-
class
|
|
152
|
-
static logger =
|
|
869
|
+
class ft {
|
|
870
|
+
static logger = k;
|
|
153
871
|
options;
|
|
154
872
|
isReady = !1;
|
|
155
873
|
project;
|
|
156
874
|
plugins = {};
|
|
157
|
-
eventBus =
|
|
875
|
+
eventBus = Ne();
|
|
158
876
|
organizationId;
|
|
159
877
|
projectId;
|
|
160
878
|
apiUrl;
|
|
161
879
|
session;
|
|
162
880
|
precondition;
|
|
163
881
|
condition;
|
|
164
|
-
searchParams =
|
|
165
|
-
history =
|
|
166
|
-
components =
|
|
167
|
-
experienceInstances =
|
|
168
|
-
experiences =
|
|
169
|
-
frameworks =
|
|
170
|
-
predicates =
|
|
171
|
-
features =
|
|
172
|
-
responses =
|
|
173
|
-
fields =
|
|
174
|
-
actions =
|
|
175
|
-
constructor(
|
|
176
|
-
|
|
177
|
-
const { organizationId:
|
|
178
|
-
this.organizationId =
|
|
882
|
+
searchParams = Ze();
|
|
883
|
+
history = Ve();
|
|
884
|
+
components = ve({ client: this });
|
|
885
|
+
experienceInstances = ne({ client: this });
|
|
886
|
+
experiences = fe({ client: this });
|
|
887
|
+
frameworks = Fe({ client: this });
|
|
888
|
+
predicates = $e({ client: this });
|
|
889
|
+
features = Oe({ client: this });
|
|
890
|
+
responses = Je({ client: this });
|
|
891
|
+
fields = _e();
|
|
892
|
+
actions = qe();
|
|
893
|
+
constructor(e) {
|
|
894
|
+
k("info", "Picked client initializing.");
|
|
895
|
+
const { organizationId: r, projectId: n } = at(e);
|
|
896
|
+
this.organizationId = r, this.projectId = n, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || Xe(), this.session = nt(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.setupActions(), this.precondition = e.precondition, this.condition = e.condition, this.eventBus({ type: "load", version: Qe() }), k("info", "Picked client initialized.");
|
|
179
897
|
}
|
|
180
898
|
start() {
|
|
181
|
-
|
|
182
|
-
if (!
|
|
899
|
+
Ae(this), (async () => {
|
|
900
|
+
if (!U())
|
|
183
901
|
return;
|
|
184
|
-
let
|
|
185
|
-
typeof this.precondition > "u" ?
|
|
902
|
+
let r;
|
|
903
|
+
typeof this.precondition > "u" ? r = !0 : typeof this.precondition == "boolean" ? r = this.precondition : r = await j(this, this.precondition) === !0;
|
|
186
904
|
let n;
|
|
187
|
-
|
|
188
|
-
const
|
|
905
|
+
r && (this.condition === void 0 ? n = !0 : typeof this.condition == "boolean" ? n = this.condition : n = await j(this, this.condition) === !0);
|
|
906
|
+
const i = r && n === !0;
|
|
189
907
|
if (typeof n == "boolean" && this.session) {
|
|
190
|
-
const
|
|
191
|
-
this.session.setIsUser(
|
|
908
|
+
const u = n;
|
|
909
|
+
this.session.setIsUser(u), this.eventBus({ type: "user_decide", value: u });
|
|
192
910
|
}
|
|
193
|
-
this.eventBus({ type: "initialize" }), document.body &&
|
|
911
|
+
this.eventBus({ type: "initialize" }), document.body && i && M(this), await se(), i && M(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session && this.eventBus({ type: "session", ...this.session });
|
|
194
912
|
})();
|
|
195
913
|
}
|
|
196
|
-
registerFramework(
|
|
197
|
-
|
|
914
|
+
registerFramework(e) {
|
|
915
|
+
Ee(e, this.frameworks);
|
|
198
916
|
}
|
|
199
|
-
registerComponent(
|
|
200
|
-
|
|
917
|
+
registerComponent(e, r) {
|
|
918
|
+
T(e, r, this.components);
|
|
201
919
|
}
|
|
202
|
-
registerPlugin(
|
|
203
|
-
|
|
920
|
+
registerPlugin(e) {
|
|
921
|
+
he(this, e, this.plugins);
|
|
204
922
|
}
|
|
205
|
-
registerFeature(
|
|
206
|
-
|
|
923
|
+
registerFeature(e, r) {
|
|
924
|
+
De(e, r, this.features);
|
|
207
925
|
}
|
|
208
|
-
registerPredicate(
|
|
209
|
-
|
|
926
|
+
registerPredicate(e, r) {
|
|
927
|
+
Ce(e, r, this.predicates);
|
|
210
928
|
}
|
|
211
|
-
registerField(
|
|
212
|
-
|
|
929
|
+
registerField(e) {
|
|
930
|
+
Le(e, this.fields);
|
|
213
931
|
}
|
|
214
|
-
registerAction(
|
|
215
|
-
|
|
932
|
+
registerAction(e, r) {
|
|
933
|
+
Ke(e, r, this.actions);
|
|
216
934
|
}
|
|
217
|
-
registerExperience(
|
|
218
|
-
|
|
935
|
+
registerExperience(e) {
|
|
936
|
+
e.component && T(`experience:${e.id}`, e.component, this.components), ge(e, this.experiences);
|
|
219
937
|
}
|
|
220
938
|
getStateSnapshot() {
|
|
221
|
-
return
|
|
939
|
+
return Y(this);
|
|
222
940
|
}
|
|
223
|
-
async launchExperienceById(
|
|
224
|
-
const
|
|
225
|
-
if (!
|
|
226
|
-
|
|
941
|
+
async launchExperienceById(e) {
|
|
942
|
+
const r = this.experiences.getById(e).getState();
|
|
943
|
+
if (!r) {
|
|
944
|
+
k("warn", `Experience with id '${e}' not found.`);
|
|
227
945
|
return;
|
|
228
946
|
}
|
|
229
|
-
|
|
947
|
+
W(this, r);
|
|
230
948
|
}
|
|
231
949
|
// private async fetchProject() {
|
|
232
950
|
// if (this.project) {
|
|
@@ -238,38 +956,38 @@ class st {
|
|
|
238
956
|
// this.project.experiences.forEach((experience) => setupExperience(experience, this.experiences))
|
|
239
957
|
// }
|
|
240
958
|
setupPlugins() {
|
|
241
|
-
this.options.plugins?.forEach((
|
|
242
|
-
if (Array.isArray(
|
|
243
|
-
|
|
959
|
+
this.options.plugins?.forEach((e) => {
|
|
960
|
+
if (Array.isArray(e)) {
|
|
961
|
+
e.forEach((n) => {
|
|
244
962
|
this.registerPlugin(n);
|
|
245
963
|
});
|
|
246
964
|
return;
|
|
247
965
|
}
|
|
248
|
-
const
|
|
249
|
-
if (Array.isArray(
|
|
250
|
-
|
|
966
|
+
const r = typeof e == "function" ? e() : e;
|
|
967
|
+
if (Array.isArray(r)) {
|
|
968
|
+
r.forEach((n) => this.registerPlugin(n));
|
|
251
969
|
return;
|
|
252
970
|
}
|
|
253
|
-
this.registerPlugin(
|
|
971
|
+
this.registerPlugin(r);
|
|
254
972
|
});
|
|
255
973
|
}
|
|
256
974
|
setupFeatures() {
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
const
|
|
260
|
-
this.registerFeature(
|
|
261
|
-
}), this.searchParams.feature && this.searchParams.feature.forEach((
|
|
975
|
+
const e = this.options.features;
|
|
976
|
+
e && (Object.entries(e).forEach(([r, n]) => {
|
|
977
|
+
const i = typeof n == "function" ? n() : n;
|
|
978
|
+
this.registerFeature(r, i);
|
|
979
|
+
}), this.searchParams.feature && this.searchParams.feature.forEach((r) => {
|
|
262
980
|
try {
|
|
263
|
-
const [n,
|
|
264
|
-
if (!n || !
|
|
981
|
+
const [n, i] = r.split(":");
|
|
982
|
+
if (!n || !i)
|
|
265
983
|
return;
|
|
266
|
-
let
|
|
267
|
-
|
|
268
|
-
key: `${
|
|
984
|
+
let u = i;
|
|
985
|
+
u === "true" && (u = !0), u === "false" && (u = !1), this.registerFeature(n, {
|
|
986
|
+
key: `${u}`,
|
|
269
987
|
// use the assigned bucket value as the key
|
|
270
988
|
name: n,
|
|
271
989
|
// eslint-disable-next-line sonarjs/function-return-type
|
|
272
|
-
decide: () =>
|
|
990
|
+
decide: () => u,
|
|
273
991
|
storage: "session"
|
|
274
992
|
});
|
|
275
993
|
} catch {
|
|
@@ -277,27 +995,27 @@ class st {
|
|
|
277
995
|
}));
|
|
278
996
|
}
|
|
279
997
|
setupPredicates() {
|
|
280
|
-
const
|
|
281
|
-
|
|
998
|
+
const e = this.options.predicates;
|
|
999
|
+
e && Object.entries(e).forEach(([r, n]) => {
|
|
282
1000
|
if (typeof n != "function") {
|
|
283
|
-
|
|
1001
|
+
k("warn", `Predicate "${r}" is not a function.`);
|
|
284
1002
|
return;
|
|
285
1003
|
}
|
|
286
|
-
this.registerPredicate(
|
|
1004
|
+
this.registerPredicate(r, n);
|
|
287
1005
|
});
|
|
288
1006
|
}
|
|
289
1007
|
setupActions() {
|
|
290
|
-
const
|
|
291
|
-
|
|
1008
|
+
const e = this.options.actions;
|
|
1009
|
+
e && Object.entries(e).forEach(([r, n]) => {
|
|
292
1010
|
if (typeof n != "function") {
|
|
293
|
-
|
|
1011
|
+
k("warn", `Action "${r}" is not a function.`);
|
|
294
1012
|
return;
|
|
295
1013
|
}
|
|
296
|
-
this.registerAction(
|
|
1014
|
+
this.registerAction(r, n);
|
|
297
1015
|
});
|
|
298
1016
|
}
|
|
299
|
-
getPluginConfig(
|
|
300
|
-
return this.plugins[
|
|
1017
|
+
getPluginConfig(e) {
|
|
1018
|
+
return this.plugins[e] ?? {};
|
|
301
1019
|
}
|
|
302
1020
|
/**
|
|
303
1021
|
* Interpolates a template string using values from the client's response store and/or a provided context.
|
|
@@ -341,58 +1059,58 @@ class st {
|
|
|
341
1059
|
* renderString("Fruits: {{ fruits | list }}", { fruits: ["apple", "banana", "cherry"] })
|
|
342
1060
|
* // => "Fruits: apple, banana, and cherry"
|
|
343
1061
|
*/
|
|
344
|
-
renderString = (
|
|
345
|
-
const n = this.responses.listStore.getState().reduce((
|
|
346
|
-
return
|
|
347
|
-
...
|
|
1062
|
+
renderString = (e, r) => {
|
|
1063
|
+
const n = this.responses.listStore.getState().reduce((i, u) => (i[u.fieldId] = u.value, i), {});
|
|
1064
|
+
return pt(e, {
|
|
1065
|
+
...r,
|
|
348
1066
|
responses: n
|
|
349
1067
|
});
|
|
350
1068
|
};
|
|
351
1069
|
}
|
|
352
|
-
function
|
|
353
|
-
return
|
|
1070
|
+
function J(t) {
|
|
1071
|
+
return t.options?.some((e) => "condition" in e) ?? !1;
|
|
354
1072
|
}
|
|
355
|
-
function
|
|
356
|
-
return
|
|
1073
|
+
function gt(t) {
|
|
1074
|
+
return t.some((e) => e.condition || J(e));
|
|
357
1075
|
}
|
|
358
|
-
async function
|
|
359
|
-
return
|
|
360
|
-
|
|
361
|
-
if (!(n.condition ? await
|
|
1076
|
+
async function bt(t, e) {
|
|
1077
|
+
return e.length === 0 || !gt(e) ? e : (await Promise.all(
|
|
1078
|
+
e.map(async (n) => {
|
|
1079
|
+
if (!(n.condition ? await j(t, n.condition) : !0))
|
|
362
1080
|
return null;
|
|
363
|
-
if (!n.options || !
|
|
1081
|
+
if (!n.options || !J(n))
|
|
364
1082
|
return n;
|
|
365
|
-
const
|
|
366
|
-
n.options.map(async (
|
|
367
|
-
)).filter((
|
|
368
|
-
return
|
|
1083
|
+
const o = (await Promise.all(
|
|
1084
|
+
n.options.map(async (a) => a.condition ? await j(t, a.condition) ? a : null : a)
|
|
1085
|
+
)).filter((a) => a !== null);
|
|
1086
|
+
return o.length === n.options.length ? n : o.length === 0 ? null : { ...n, options: o };
|
|
369
1087
|
})
|
|
370
1088
|
)).filter((n) => n !== null);
|
|
371
1089
|
}
|
|
372
|
-
const
|
|
373
|
-
const
|
|
374
|
-
return
|
|
1090
|
+
const Ft = (t) => {
|
|
1091
|
+
const e = new ft(t);
|
|
1092
|
+
return ue(e), e;
|
|
375
1093
|
};
|
|
376
1094
|
export {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
1095
|
+
ft as Picked,
|
|
1096
|
+
Ft as createClient,
|
|
1097
|
+
A as createStorageKey,
|
|
1098
|
+
j as evaluateRuleLogic,
|
|
1099
|
+
st as getPickedConfig,
|
|
1100
|
+
bt as getStepFields,
|
|
1101
|
+
jt as isPickedRoot,
|
|
1102
|
+
C as localStore,
|
|
1103
|
+
z as sessionStore,
|
|
386
1104
|
At as subscribe,
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
1105
|
+
Rt as supportsCookies,
|
|
1106
|
+
ce as supportsCryptoRandomUUID,
|
|
1107
|
+
U as supportsDocument,
|
|
1108
|
+
$t as supportsHistory,
|
|
1109
|
+
Ct as supportsIntersectionObserver,
|
|
1110
|
+
ae as supportsLocalStorage,
|
|
1111
|
+
zt as supportsLocation,
|
|
1112
|
+
Ot as supportsSessionStorage,
|
|
1113
|
+
Dt as supportsShadowRoot,
|
|
1114
|
+
Ut as supportsWebComponents,
|
|
1115
|
+
V as supportsWindow
|
|
398
1116
|
};
|