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