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