@picked/client 0.0.1-dev.1767832235641 → 0.0.1-dev.1767845350659
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/responses-browser-storage/index.js +1 -1
- package/dist/cjs/server/index.js +1 -1
- package/dist/esm/index.js +965 -256
- package/dist/esm/plugins/responses-browser-storage/index.js +23 -22
- 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-Du9C8zgX.js → experience-instance-BmL4VkmP.js} +8 -8
- package/dist/{experience-instance-DjjpHk0t.cjs → experience-instance-IpJwvfUH.cjs} +1 -1
- package/dist/{supports-DBMT17KZ.js → supports-BjhuLJ8z.js} +10 -10
- package/dist/types/entities/action/action.d.ts +5 -3
- package/dist/types/entities/action/action.d.ts.map +1 -1
- package/dist/types/entities/feature/feature.d.ts +6 -3
- package/dist/types/entities/feature/feature.d.ts.map +1 -1
- package/dist/types/entities/predicate/predicate.d.ts +4 -5
- package/dist/types/entities/predicate/predicate.d.ts.map +1 -1
- package/dist/types/entities/response/response.d.ts +4 -1
- package/dist/types/entities/response/response.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/picked-attributes.d.ts +47 -0
- package/dist/types/picked-attributes.d.ts.map +1 -0
- package/dist/types/picked.d.ts +11 -7
- package/dist/types/picked.d.ts.map +1 -1
- package/dist/types/plugins/responses-browser-storage/plugin.d.ts.map +1 -1
- package/dist/types/utils/events.d.ts +1 -10
- 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/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,809 @@
|
|
|
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 ee = Object.defineProperty;
|
|
2
|
+
var te = (t, e, r) => e in t ? ee(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var h = (t, e, r) => te(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
|
+
import { createDomain as E, createApi as x, createStore as q, createEffect as $, sample as F, attach as re, combine as D, createEvent as U } from "effector";
|
|
5
|
+
import { createFactory as w, invoke as I } from "@withease/factories";
|
|
6
|
+
import { g as K, t as ne, c as se, i as ie, e as P, a as oe, b as ae, d as ce } from "../experience-instance-BmL4VkmP.js";
|
|
7
|
+
import { f as Rt } from "../experience-instance-BmL4VkmP.js";
|
|
8
|
+
import { l as v } from "../logger-C9a75KZn.js";
|
|
9
|
+
import { c as B, l as z, s as O } from "../storage-BLmAhfhl.js";
|
|
10
|
+
import { a as Ct } from "../storage-BLmAhfhl.js";
|
|
11
|
+
import { g as ue } from "../id-BW-g3y32.js";
|
|
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);
|
|
102
|
+
if (s) {
|
|
103
|
+
const d = r[n] ?? {};
|
|
104
|
+
r[n] = Object.freeze({ ...d, ...s });
|
|
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 () => y(k);
|
|
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: g }) => {
|
|
318
|
+
const S = u.find(
|
|
319
|
+
(R) => R.id === l && R.key === g
|
|
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}:${g}`);
|
|
327
|
+
if (j !== void 0) {
|
|
328
|
+
const R = await j;
|
|
329
|
+
return { id: b.id, bucket: R, key: g, storage: b.feature.storage };
|
|
330
|
+
}
|
|
331
|
+
const N = p();
|
|
332
|
+
i.set(`${l}:${g}`, N);
|
|
333
|
+
const Z = await N;
|
|
334
|
+
return { id: b.id, bucket: Z, key: g, 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: g } = u, S = (b = c[l]) == null ? void 0 : b.feature.key;
|
|
350
|
+
return S ? { key: S, id: l, bucket: p, storage: g } : 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
|
+
(g) => g.id === l.id && g.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
|
+
(g) => g.id === u && g.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 m(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((g) => g.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: m
|
|
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);
|
|
18
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);
|
|
19
567
|
};
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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(m, c) {
|
|
574
|
+
return {
|
|
575
|
+
...m,
|
|
576
|
+
[c.fieldId]: c.response
|
|
577
|
+
};
|
|
578
|
+
},
|
|
579
|
+
registerBatch(m, c) {
|
|
580
|
+
return {
|
|
581
|
+
...m,
|
|
582
|
+
...c
|
|
583
|
+
};
|
|
584
|
+
},
|
|
585
|
+
clear(m, c) {
|
|
586
|
+
const { [c]: u, ...l } = m;
|
|
587
|
+
return l;
|
|
588
|
+
},
|
|
589
|
+
clearAll() {
|
|
590
|
+
return {};
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
function d(m, c) {
|
|
594
|
+
if (typeof m == "string") {
|
|
595
|
+
if (c === void 0)
|
|
596
|
+
throw new Error("Response is required when registering a single field");
|
|
597
|
+
s.register({ fieldId: m, response: c });
|
|
598
|
+
} else
|
|
599
|
+
s.registerBatch(m);
|
|
600
|
+
}
|
|
601
|
+
async function o(m) {
|
|
602
|
+
const c = [];
|
|
603
|
+
return await Promise.allSettled(
|
|
604
|
+
Object.entries(m).map(async ([u, l]) => {
|
|
605
|
+
let p = l;
|
|
606
|
+
const g = t.fields.getById(u).getState();
|
|
607
|
+
if (!g) {
|
|
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 (g.multiple && (typeof p == "string" || typeof p == "number" || typeof p == "boolean") && (p = [p]), g.validation && !de(g.validation) && !H(p)) {
|
|
617
|
+
const S = await P(t, g.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 (g.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 (!g.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 (g.options) {
|
|
658
|
+
const S = g.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: m, validationErrors: c };
|
|
668
|
+
}
|
|
669
|
+
async function i(m) {
|
|
670
|
+
const { responsesToCommit: c, validationErrors: u } = await o(m);
|
|
671
|
+
return u.length ? { errors: u } : (s.registerBatch(c), { errors: [] });
|
|
672
|
+
}
|
|
673
|
+
const a = e.map((m) => m), f = e.map((m) => Object.keys(m).map((u) => ({
|
|
674
|
+
fieldId: u,
|
|
675
|
+
value: m[u]
|
|
676
|
+
})));
|
|
677
|
+
function y(m) {
|
|
678
|
+
const c = t.fields.getById(m), u = e.map((l) => l[m] || null);
|
|
679
|
+
return D({ f: c, r: u }, ({ f: l, r: p }) => p || (l != null && l.defaultValue ? l.defaultValue : null));
|
|
680
|
+
}
|
|
681
|
+
function k(m) {
|
|
682
|
+
const c = t.fields.getByName(m);
|
|
683
|
+
return D({ f: c, s: e }, ({ f: u, s: l }) => {
|
|
684
|
+
const p = u && l[u.id] || null;
|
|
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
|
|
29
704
|
};
|
|
30
|
-
|
|
705
|
+
});
|
|
706
|
+
function et(t) {
|
|
707
|
+
return I(Ze, t);
|
|
31
708
|
}
|
|
32
|
-
const
|
|
33
|
-
function
|
|
34
|
-
if (
|
|
35
|
-
const
|
|
709
|
+
const tt = () => "0.0.1-dev.1767845350659";
|
|
710
|
+
function rt() {
|
|
711
|
+
if (V()) {
|
|
712
|
+
const t = [
|
|
36
713
|
document.currentScript,
|
|
37
714
|
document.getElementById("picked_script"),
|
|
38
715
|
document.getElementById("picked"),
|
|
39
716
|
document.getElementById("cvly"),
|
|
40
717
|
document.getElementById("cvly-x")
|
|
41
718
|
];
|
|
42
|
-
for (const
|
|
43
|
-
if (
|
|
44
|
-
return
|
|
719
|
+
for (const e of t)
|
|
720
|
+
if (e != null && e.dataset.api)
|
|
721
|
+
return e.dataset.api;
|
|
45
722
|
}
|
|
46
723
|
return "https://api.picked.app";
|
|
47
724
|
}
|
|
48
|
-
function
|
|
49
|
-
if (!
|
|
725
|
+
function nt() {
|
|
726
|
+
if (!M())
|
|
50
727
|
return {};
|
|
51
|
-
const
|
|
52
|
-
for (const [
|
|
53
|
-
|
|
54
|
-
for (const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
-
|
|
728
|
+
const t = new URLSearchParams(window.location.search), e = {}, r = /* @__PURE__ */ new Set();
|
|
729
|
+
for (const [s] of t.entries())
|
|
730
|
+
s.startsWith("picked-") && r.add(s);
|
|
731
|
+
for (const s of r) {
|
|
732
|
+
const d = s.replace("picked-", "");
|
|
733
|
+
e[d] = t.getAll(s);
|
|
734
|
+
}
|
|
735
|
+
const n = B("s");
|
|
736
|
+
if (r.size > 0)
|
|
737
|
+
O.set(n, e);
|
|
61
738
|
else {
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
return
|
|
739
|
+
const s = O.get(n);
|
|
740
|
+
if (s)
|
|
741
|
+
return s.json() || {};
|
|
65
742
|
}
|
|
66
|
-
return
|
|
743
|
+
return e;
|
|
67
744
|
}
|
|
68
|
-
function
|
|
69
|
-
if (
|
|
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}`;
|
|
750
|
+
}
|
|
751
|
+
const it = B("session", "global"), ot = () => {
|
|
752
|
+
const t = z.get(it);
|
|
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())
|
|
70
779
|
return globalThis.window.pickedConfig;
|
|
71
780
|
}
|
|
72
|
-
function
|
|
73
|
-
if (!
|
|
781
|
+
function ut() {
|
|
782
|
+
if (!M())
|
|
74
783
|
return;
|
|
75
|
-
const
|
|
76
|
-
return
|
|
784
|
+
const t = ct(), e = t == null ? void 0 : t.organizationId, r = t == null ? void 0 : t.projectId;
|
|
785
|
+
return e && r ? { organizationId: e, projectId: r } : void 0;
|
|
77
786
|
}
|
|
78
|
-
function
|
|
79
|
-
if (!
|
|
787
|
+
function dt() {
|
|
788
|
+
if (!V())
|
|
80
789
|
return;
|
|
81
|
-
const
|
|
790
|
+
const t = document.getElementById("picked_script") || document.querySelector("script#picked") || // legacy support for 'cvly' script tag
|
|
82
791
|
document.getElementById("cvly");
|
|
83
|
-
if (!
|
|
792
|
+
if (!t)
|
|
84
793
|
return;
|
|
85
|
-
const
|
|
86
|
-
return
|
|
794
|
+
const e = t.dataset.organizationid || t.getAttribute("organization-id"), r = t.dataset.projectid || t.getAttribute("project-id");
|
|
795
|
+
return e && r ? { organizationId: e, projectId: r } : void 0;
|
|
87
796
|
}
|
|
88
|
-
function
|
|
89
|
-
const { organizationId:
|
|
90
|
-
if (
|
|
91
|
-
return { organizationId:
|
|
92
|
-
const
|
|
93
|
-
if (s)
|
|
94
|
-
return s;
|
|
95
|
-
const n = et();
|
|
797
|
+
function lt(t) {
|
|
798
|
+
const { organizationId: e, projectId: r } = t;
|
|
799
|
+
if (e && r)
|
|
800
|
+
return { organizationId: e, projectId: r };
|
|
801
|
+
const n = ut();
|
|
96
802
|
if (n)
|
|
97
803
|
return n;
|
|
804
|
+
const s = dt();
|
|
805
|
+
if (s)
|
|
806
|
+
return s;
|
|
98
807
|
throw new Error(
|
|
99
808
|
`organizationId and projectId are required. You can provide them via one of:
|
|
100
809
|
(1) createClient({ organizationId, projectId }) options;
|
|
@@ -102,92 +811,92 @@ function it(e) {
|
|
|
102
811
|
(3) a <script> tag with id 'picked_script', 'picked', or 'cvly' that includes data-organizationid/data-projectid (or organization-id/project-id) attributes.`
|
|
103
812
|
);
|
|
104
813
|
}
|
|
105
|
-
function
|
|
106
|
-
return
|
|
814
|
+
function C(t) {
|
|
815
|
+
return t == null || t === "" || Number.isNaN(t);
|
|
107
816
|
}
|
|
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
|
|
817
|
+
const pt = {
|
|
818
|
+
default: (t, e) => C(t) ? String(e ?? "") : String(t),
|
|
819
|
+
append: (t, e) => e && !C(t) ? `${t} ${e}` : t,
|
|
820
|
+
prepend: (t, e) => e && !C(t) ? `${e} ${t}` : t,
|
|
821
|
+
upper: (t) => typeof t == "string" ? t.toUpperCase() : t,
|
|
822
|
+
lower: (t) => typeof t == "string" ? t.toLowerCase() : t,
|
|
823
|
+
capitalize: (t) => typeof t == "string" ? t.charAt(0).toUpperCase() + t.slice(1) : t,
|
|
824
|
+
list: (t) => {
|
|
825
|
+
if (!t || typeof t != "object")
|
|
826
|
+
return t;
|
|
827
|
+
const e = new Intl.ListFormat("en", { style: "long", type: "conjunction" });
|
|
828
|
+
if (Array.isArray(t))
|
|
829
|
+
return e.format(t.map(String));
|
|
830
|
+
if (t instanceof Map) {
|
|
831
|
+
const r = Array.from(t.entries()).map(([n, s]) => `${n}: ${s}`);
|
|
832
|
+
return e.format(r);
|
|
124
833
|
}
|
|
125
|
-
return
|
|
834
|
+
return t instanceof Set ? e.format(Array.from(t).map(String)) : t;
|
|
126
835
|
}
|
|
127
836
|
};
|
|
128
|
-
function
|
|
129
|
-
return typeof
|
|
837
|
+
function ft(t) {
|
|
838
|
+
return typeof t == "object" && t !== null;
|
|
130
839
|
}
|
|
131
|
-
function
|
|
132
|
-
let
|
|
133
|
-
for (const
|
|
134
|
-
if (
|
|
135
|
-
|
|
840
|
+
function gt(t, e) {
|
|
841
|
+
let r = e;
|
|
842
|
+
for (const n of t.split("."))
|
|
843
|
+
if (ft(r) && n in r)
|
|
844
|
+
r = r[n];
|
|
136
845
|
else
|
|
137
846
|
return;
|
|
138
|
-
return typeof
|
|
847
|
+
return typeof r == "function" ? r() : r;
|
|
139
848
|
}
|
|
140
|
-
function
|
|
141
|
-
const
|
|
142
|
-
let
|
|
143
|
-
for (const
|
|
144
|
-
const [
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
return
|
|
849
|
+
function mt(t, e) {
|
|
850
|
+
const r = t.split("|").map((d) => d.trim()), n = r.shift() ?? "";
|
|
851
|
+
let s = gt(n, e);
|
|
852
|
+
for (const d of r) {
|
|
853
|
+
const [o, ...i] = d.split(":"), a = (o == null ? void 0 : o.trim()) ?? "", f = i.join(":").trim().replaceAll(/(?:^['"]|['"]$)/g, ""), y = pt[a];
|
|
854
|
+
y && (s = y(s, f));
|
|
855
|
+
}
|
|
856
|
+
return C(s) ? "" : typeof s == "object" ? JSON.stringify(s) : String(s);
|
|
148
857
|
}
|
|
149
|
-
function
|
|
150
|
-
let
|
|
151
|
-
for (;
|
|
152
|
-
if (
|
|
153
|
-
|
|
154
|
-
let
|
|
155
|
-
for (;
|
|
156
|
-
if (
|
|
157
|
-
|
|
858
|
+
function ht(t, e) {
|
|
859
|
+
let r = "", n = 0;
|
|
860
|
+
for (; n < t.length; )
|
|
861
|
+
if (t[n] === "{" && t[n + 1] === "{") {
|
|
862
|
+
n += 2;
|
|
863
|
+
let s = "";
|
|
864
|
+
for (; n < t.length; ) {
|
|
865
|
+
if (t[n] === "}" && t[n + 1] === "}") {
|
|
866
|
+
n += 2;
|
|
158
867
|
break;
|
|
159
868
|
}
|
|
160
|
-
|
|
869
|
+
s += t[n++];
|
|
161
870
|
}
|
|
162
|
-
|
|
871
|
+
r += mt(s.trim(), e);
|
|
163
872
|
} else
|
|
164
|
-
|
|
165
|
-
return
|
|
873
|
+
r += t[n++];
|
|
874
|
+
return r;
|
|
166
875
|
}
|
|
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
|
-
|
|
876
|
+
class Q {
|
|
877
|
+
constructor(e) {
|
|
878
|
+
h(this, "options");
|
|
879
|
+
h(this, "isReady", !1);
|
|
880
|
+
h(this, "project");
|
|
881
|
+
h(this, "plugins", {});
|
|
882
|
+
h(this, "eventBus", Le());
|
|
883
|
+
h(this, "organizationId");
|
|
884
|
+
h(this, "projectId");
|
|
885
|
+
h(this, "apiUrl");
|
|
886
|
+
h(this, "session");
|
|
887
|
+
h(this, "precondition");
|
|
888
|
+
h(this, "condition");
|
|
889
|
+
h(this, "searchParams", nt());
|
|
890
|
+
h(this, "history", _e());
|
|
891
|
+
h(this, "components", Ee({ client: this }));
|
|
892
|
+
h(this, "experienceInstances", ae({ client: this }));
|
|
893
|
+
h(this, "experiences", ye({ client: this }));
|
|
894
|
+
h(this, "frameworks", Pe({ client: this }));
|
|
895
|
+
h(this, "predicates", De({ client: this }));
|
|
896
|
+
h(this, "features", Me({ client: this }));
|
|
897
|
+
h(this, "responses", et({ client: this }));
|
|
898
|
+
h(this, "fields", qe());
|
|
899
|
+
h(this, "actions", Je());
|
|
191
900
|
/**
|
|
192
901
|
* Interpolates a template string using values from the client's response store and/or a provided context.
|
|
193
902
|
* Supports dot-notation, modifiers, and executing functions found in the context.
|
|
@@ -230,67 +939,67 @@ class S {
|
|
|
230
939
|
* renderString("Fruits: {{ fruits | list }}", { fruits: ["apple", "banana", "cherry"] })
|
|
231
940
|
* // => "Fruits: apple, banana, and cherry"
|
|
232
941
|
*/
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
return
|
|
236
|
-
...
|
|
237
|
-
responses:
|
|
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
|
|
238
947
|
});
|
|
239
948
|
});
|
|
240
|
-
|
|
241
|
-
const { organizationId:
|
|
242
|
-
this.organizationId =
|
|
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.");
|
|
243
952
|
}
|
|
244
953
|
start() {
|
|
245
|
-
|
|
246
|
-
if (!
|
|
954
|
+
Ce(this), (async () => {
|
|
955
|
+
if (!V())
|
|
247
956
|
return;
|
|
248
|
-
let
|
|
249
|
-
typeof this.precondition > "u" ?
|
|
250
|
-
let
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
if (typeof
|
|
254
|
-
const
|
|
255
|
-
this.session.setIsUser(
|
|
957
|
+
let r;
|
|
958
|
+
typeof this.precondition > "u" ? r = !0 : typeof this.precondition == "boolean" ? r = this.precondition : r = await P(this, this.precondition) === !0;
|
|
959
|
+
let n;
|
|
960
|
+
r && (this.condition === void 0 ? n = !0 : typeof this.condition == "boolean" ? n = this.condition : n = await P(this, this.condition) === !0);
|
|
961
|
+
const s = r && n === !0;
|
|
962
|
+
if (typeof n == "boolean" && this.session) {
|
|
963
|
+
const d = n;
|
|
964
|
+
this.session.setIsUser(d), this.eventBus({ type: "user_decide", value: d });
|
|
256
965
|
}
|
|
257
|
-
this.eventBus({ type: "initialize" }), document.body &&
|
|
966
|
+
this.eventBus({ type: "initialize" }), document.body && s && T(this), await ce(), s && T(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session && this.eventBus({ type: "session", ...this.session });
|
|
258
967
|
})();
|
|
259
968
|
}
|
|
260
|
-
registerFramework(
|
|
261
|
-
|
|
969
|
+
registerFramework(e) {
|
|
970
|
+
Ae(e, this.frameworks);
|
|
262
971
|
}
|
|
263
|
-
registerComponent(
|
|
264
|
-
|
|
972
|
+
registerComponent(e, r) {
|
|
973
|
+
_(e, r, this.components);
|
|
265
974
|
}
|
|
266
|
-
registerPlugin(
|
|
267
|
-
|
|
975
|
+
registerPlugin(e) {
|
|
976
|
+
ve(this, e, this.plugins);
|
|
268
977
|
}
|
|
269
|
-
registerFeature(
|
|
270
|
-
|
|
978
|
+
registerFeature(e, r) {
|
|
979
|
+
Ne(e, r, this.features);
|
|
271
980
|
}
|
|
272
|
-
registerPredicate(
|
|
273
|
-
|
|
981
|
+
registerPredicate(e, r) {
|
|
982
|
+
Ue(e, r, this.predicates);
|
|
274
983
|
}
|
|
275
|
-
registerField(
|
|
276
|
-
|
|
984
|
+
registerField(e) {
|
|
985
|
+
Ke(e, this.fields);
|
|
277
986
|
}
|
|
278
|
-
registerAction(
|
|
279
|
-
|
|
987
|
+
registerAction(e, r) {
|
|
988
|
+
Qe(e, r, this.actions);
|
|
280
989
|
}
|
|
281
|
-
registerExperience(
|
|
282
|
-
|
|
990
|
+
registerExperience(e) {
|
|
991
|
+
e.component && _(`experience:${e.id}`, e.component, this.components), Se(e, this.experiences);
|
|
283
992
|
}
|
|
284
993
|
getStateSnapshot() {
|
|
285
994
|
return J(this);
|
|
286
995
|
}
|
|
287
|
-
async launchExperienceById(
|
|
288
|
-
const
|
|
289
|
-
if (!
|
|
290
|
-
|
|
996
|
+
async launchExperienceById(e) {
|
|
997
|
+
const r = this.experiences.getById(e).getState();
|
|
998
|
+
if (!r) {
|
|
999
|
+
v("warn", `Experience with id '${e}' not found.`);
|
|
291
1000
|
return;
|
|
292
1001
|
}
|
|
293
|
-
|
|
1002
|
+
Y(this, r);
|
|
294
1003
|
}
|
|
295
1004
|
// private async fetchProject() {
|
|
296
1005
|
// if (this.project) {
|
|
@@ -302,39 +1011,39 @@ class S {
|
|
|
302
1011
|
// this.project.experiences.forEach((experience) => setupExperience(experience, this.experiences))
|
|
303
1012
|
// }
|
|
304
1013
|
setupPlugins() {
|
|
305
|
-
var
|
|
306
|
-
(
|
|
307
|
-
if (Array.isArray(
|
|
308
|
-
|
|
309
|
-
this.registerPlugin(
|
|
1014
|
+
var e;
|
|
1015
|
+
(e = this.options.plugins) == null || e.forEach((r) => {
|
|
1016
|
+
if (Array.isArray(r)) {
|
|
1017
|
+
r.forEach((s) => {
|
|
1018
|
+
this.registerPlugin(s);
|
|
310
1019
|
});
|
|
311
1020
|
return;
|
|
312
1021
|
}
|
|
313
|
-
const
|
|
314
|
-
if (Array.isArray(
|
|
315
|
-
|
|
1022
|
+
const n = typeof r == "function" ? r() : r;
|
|
1023
|
+
if (Array.isArray(n)) {
|
|
1024
|
+
n.forEach((s) => this.registerPlugin(s));
|
|
316
1025
|
return;
|
|
317
1026
|
}
|
|
318
|
-
this.registerPlugin(
|
|
1027
|
+
this.registerPlugin(n);
|
|
319
1028
|
});
|
|
320
1029
|
}
|
|
321
1030
|
setupFeatures() {
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
const
|
|
325
|
-
this.registerFeature(
|
|
326
|
-
}), this.searchParams.feature && this.searchParams.feature.forEach((
|
|
1031
|
+
const e = this.options.features;
|
|
1032
|
+
e && (Object.entries(e).forEach(([r, n]) => {
|
|
1033
|
+
const s = typeof n == "function" ? n() : n;
|
|
1034
|
+
this.registerFeature(r, s);
|
|
1035
|
+
}), this.searchParams.feature && this.searchParams.feature.forEach((r) => {
|
|
327
1036
|
try {
|
|
328
|
-
const [
|
|
329
|
-
if (!
|
|
1037
|
+
const [n, s] = r.split(":");
|
|
1038
|
+
if (!n || !s)
|
|
330
1039
|
return;
|
|
331
|
-
let
|
|
332
|
-
|
|
333
|
-
key: `${
|
|
1040
|
+
let d = s;
|
|
1041
|
+
d === "true" && (d = !0), d === "false" && (d = !1), this.registerFeature(n, {
|
|
1042
|
+
key: `${d}`,
|
|
334
1043
|
// use the assigned bucket value as the key
|
|
335
|
-
name:
|
|
1044
|
+
name: n,
|
|
336
1045
|
// eslint-disable-next-line sonarjs/function-return-type
|
|
337
|
-
decide: () =>
|
|
1046
|
+
decide: () => d,
|
|
338
1047
|
storage: "session"
|
|
339
1048
|
});
|
|
340
1049
|
} catch {
|
|
@@ -342,75 +1051,75 @@ class S {
|
|
|
342
1051
|
}));
|
|
343
1052
|
}
|
|
344
1053
|
setupPredicates() {
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
if (typeof
|
|
348
|
-
|
|
1054
|
+
const e = this.options.predicates;
|
|
1055
|
+
e && Object.entries(e).forEach(([r, n]) => {
|
|
1056
|
+
if (typeof n != "function") {
|
|
1057
|
+
v("warn", `Predicate "${r}" is not a function.`);
|
|
349
1058
|
return;
|
|
350
1059
|
}
|
|
351
|
-
this.registerPredicate(
|
|
1060
|
+
this.registerPredicate(r, n);
|
|
352
1061
|
});
|
|
353
1062
|
}
|
|
354
1063
|
setupActions() {
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
if (typeof
|
|
358
|
-
|
|
1064
|
+
const e = this.options.actions;
|
|
1065
|
+
e && Object.entries(e).forEach(([r, n]) => {
|
|
1066
|
+
if (typeof n != "function") {
|
|
1067
|
+
v("warn", `Action "${r}" is not a function.`);
|
|
359
1068
|
return;
|
|
360
1069
|
}
|
|
361
|
-
this.registerAction(
|
|
1070
|
+
this.registerAction(r, n);
|
|
362
1071
|
});
|
|
363
1072
|
}
|
|
364
|
-
getPluginConfig(
|
|
365
|
-
return this.plugins[
|
|
1073
|
+
getPluginConfig(e) {
|
|
1074
|
+
return this.plugins[e] ?? {};
|
|
366
1075
|
}
|
|
367
1076
|
}
|
|
368
|
-
|
|
369
|
-
function
|
|
370
|
-
var
|
|
371
|
-
return ((
|
|
1077
|
+
h(Q, "logger", v);
|
|
1078
|
+
function X(t) {
|
|
1079
|
+
var e;
|
|
1080
|
+
return ((e = t.options) == null ? void 0 : e.some((r) => "condition" in r)) ?? !1;
|
|
372
1081
|
}
|
|
373
|
-
function
|
|
374
|
-
return
|
|
1082
|
+
function yt(t) {
|
|
1083
|
+
return t.some((e) => e.condition || X(e));
|
|
375
1084
|
}
|
|
376
|
-
async function
|
|
377
|
-
return
|
|
378
|
-
|
|
379
|
-
if (!(
|
|
1085
|
+
async function jt(t, e) {
|
|
1086
|
+
return e.length === 0 || !yt(e) ? e : (await Promise.all(
|
|
1087
|
+
e.map(async (n) => {
|
|
1088
|
+
if (!(n.condition ? await P(t, n.condition) : !0))
|
|
380
1089
|
return null;
|
|
381
|
-
if (!
|
|
382
|
-
return
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
)).filter((
|
|
386
|
-
return
|
|
1090
|
+
if (!n.options || !X(n))
|
|
1091
|
+
return n;
|
|
1092
|
+
const o = (await Promise.all(
|
|
1093
|
+
n.options.map(async (a) => a.condition ? await P(t, a.condition) ? a : null : a)
|
|
1094
|
+
)).filter((a) => a !== null);
|
|
1095
|
+
return o.length === n.options.length ? n : o.length === 0 ? null : { ...n, options: o };
|
|
387
1096
|
})
|
|
388
|
-
)).filter((
|
|
1097
|
+
)).filter((n) => n !== null);
|
|
389
1098
|
}
|
|
390
|
-
const
|
|
391
|
-
const
|
|
392
|
-
return
|
|
1099
|
+
const Pt = (t) => {
|
|
1100
|
+
const e = new Q(t);
|
|
1101
|
+
return fe(e), e;
|
|
393
1102
|
};
|
|
394
1103
|
export {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
1104
|
+
Q as Picked,
|
|
1105
|
+
Pt as createClient,
|
|
1106
|
+
B as createStorageKey,
|
|
1107
|
+
P as evaluateRuleLogic,
|
|
1108
|
+
ct as getPickedConfig,
|
|
1109
|
+
jt as getStepFields,
|
|
1110
|
+
Rt as isPickedRoot,
|
|
1111
|
+
z as localStore,
|
|
1112
|
+
O as sessionStore,
|
|
1113
|
+
Ct as subscribe,
|
|
1114
|
+
Ot as supportsCookies,
|
|
1115
|
+
pe as supportsCryptoRandomUUID,
|
|
1116
|
+
V as supportsDocument,
|
|
1117
|
+
Dt as supportsHistory,
|
|
1118
|
+
Ut as supportsIntersectionObserver,
|
|
1119
|
+
le as supportsLocalStorage,
|
|
1120
|
+
Vt as supportsLocation,
|
|
1121
|
+
Mt as supportsSessionStorage,
|
|
1122
|
+
Nt as supportsShadowRoot,
|
|
1123
|
+
Tt as supportsWebComponents,
|
|
1124
|
+
M as supportsWindow
|
|
416
1125
|
};
|