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