@picked/client 0.0.12 → 0.0.13
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 +1 -1
- package/dist/cjs/plugins/create-experience/index.js +1 -1
- package/dist/cjs/plugins/shopify/index.js +1 -1
- package/dist/cjs/server/index.js +1 -1
- package/dist/esm/index.js +157 -707
- package/dist/esm/plugins/create-experience/index.js +229 -178
- package/dist/esm/plugins/shopify/index.js +68 -36
- 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-B2l_MG7I.cjs +1 -0
- package/dist/experience-instance-CeuHLrdL.js +781 -0
- package/dist/{supports-BjhuLJ8z.js → supports-DBMT17KZ.js} +10 -10
- package/dist/types/client.d.ts +26 -0
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/entities/action/action.d.ts +15 -0
- package/dist/types/entities/action/action.d.ts.map +1 -0
- package/dist/types/entities/experience/experience.d.ts +19 -6
- package/dist/types/entities/experience/experience.d.ts.map +1 -1
- package/dist/types/entities/experience-instance/experience-instance.d.ts +3 -3
- package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
- package/dist/types/entities/feature/feature.d.ts +5 -2
- package/dist/types/entities/feature/feature.d.ts.map +1 -1
- package/dist/types/picked.d.ts +14 -4
- package/dist/types/picked.d.ts.map +1 -1
- package/dist/types/plugins/create-experience/create-experience.d.ts +23 -5
- package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
- package/dist/types/plugins/shopify/{utils.d.ts → global-obj.d.ts} +8 -1
- package/dist/types/plugins/shopify/global-obj.d.ts.map +1 -0
- package/dist/types/plugins/shopify/index.d.ts +2 -0
- package/dist/types/plugins/shopify/index.d.ts.map +1 -1
- package/dist/types/plugins/shopify/picked-config.d.ts +96 -0
- package/dist/types/plugins/shopify/picked-config.d.ts.map +1 -0
- package/dist/types/plugins/shopify/{shopify.d.ts → predicates.d.ts} +20 -6
- package/dist/types/plugins/shopify/predicates.d.ts.map +1 -0
- package/dist/types/utils/events.d.ts +10 -4
- package/dist/types/utils/events.d.ts.map +1 -1
- package/dist/types/utils/nodes.d.ts +2 -1
- package/dist/types/utils/nodes.d.ts.map +1 -1
- package/dist/user-session-D-l-VMTb.cjs +1 -0
- package/dist/user-session-Ht0ayuo5.js +632 -0
- package/package.json +6 -6
- package/dist/experience-instance-DXWLnF-R.cjs +0 -1
- package/dist/experience-instance-XlIuqLrL.js +0 -716
- package/dist/types/plugins/shopify/shopify.d.ts.map +0 -1
- package/dist/types/plugins/shopify/utils.d.ts.map +0 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,693 +1,133 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
merge(n, d) {
|
|
19
|
-
return {
|
|
20
|
-
...n,
|
|
21
|
-
...d.experience
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}), i = s.map((n) => ({
|
|
25
|
-
type: n.type,
|
|
26
|
-
name: n.name,
|
|
27
|
-
decisionLogic: n.decide,
|
|
28
|
-
targetSelectors: n.targets
|
|
29
|
-
})), l = t.components.listStore.map(
|
|
30
|
-
(n) => n.find((d) => d.name === `experience:${e.id}`) || n.find((d) => d.name === "experience"),
|
|
31
|
-
{ skipVoid: !1 }
|
|
32
|
-
), r = s.map((n) => ({
|
|
33
|
-
steps: n.steps,
|
|
34
|
-
nodes: n.nodes,
|
|
35
|
-
edges: n.edges,
|
|
36
|
-
conditionals: n.conditionals
|
|
37
|
-
}));
|
|
38
|
-
return {
|
|
39
|
-
id: e.id,
|
|
40
|
-
configStore: i,
|
|
41
|
-
treeStore: r,
|
|
42
|
-
componentStore: l,
|
|
43
|
-
merge: o.merge
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
function ue(t) {
|
|
48
|
-
return b(ce, t);
|
|
49
|
-
}
|
|
50
|
-
const le = k(({ client: t }) => {
|
|
51
|
-
const e = _.store({}), s = x(e, {
|
|
52
|
-
register(r, n) {
|
|
53
|
-
return {
|
|
54
|
-
...r,
|
|
55
|
-
[n.id]: n
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
function o(r) {
|
|
60
|
-
const n = e.getState()[r.id];
|
|
61
|
-
if (n) {
|
|
62
|
-
n.merge({ experience: r, strategy: "override" });
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const d = ue({ client: t, experience: r });
|
|
66
|
-
s.register(d);
|
|
67
|
-
}
|
|
68
|
-
const i = e.map((r) => Object.values(r));
|
|
69
|
-
function l(r) {
|
|
70
|
-
return e.map((n) => n[r], { skipVoid: !1 });
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
register: o,
|
|
74
|
-
getById: l,
|
|
75
|
-
listStore: i
|
|
76
|
-
};
|
|
77
|
-
});
|
|
78
|
-
function de(t) {
|
|
79
|
-
return b(le, t);
|
|
80
|
-
}
|
|
81
|
-
const pe = (t, e) => {
|
|
82
|
-
e.register(t);
|
|
83
|
-
}, H = (t, e) => {
|
|
84
|
-
const { targetSelectors: s } = e.configStore.getState(), o = U(s, e.id);
|
|
85
|
-
o.forEach(
|
|
86
|
-
({ elements: l }) => l.forEach((r) => J(r, e.id))
|
|
87
|
-
), Q(o, e.id).forEach((l) => {
|
|
88
|
-
t.experienceInstances.spawn(e, l);
|
|
89
|
-
});
|
|
90
|
-
}, M = async (t) => {
|
|
91
|
-
await Promise.all(
|
|
92
|
-
t.experiences.listStore.getState().map(async (e) => {
|
|
93
|
-
await ge(t, e) && H(t, e);
|
|
94
|
-
})
|
|
95
|
-
);
|
|
96
|
-
}, ge = async (t, e) => {
|
|
97
|
-
const { type: s, decisionLogic: o, targetSelectors: i } = e.configStore.getState();
|
|
98
|
-
return U(i, e.id).length < 1 ? !1 : s === "funnel" ? o ? await R(t, o) === !0 : !1 : i.length === 0 ? !1 : X(o) ? await R(t, o) === !0 : !0;
|
|
99
|
-
}, fe = (t, e, s) => {
|
|
100
|
-
const o = e.name, i = e.setup(t);
|
|
101
|
-
if (i) {
|
|
102
|
-
const l = s[o] ?? {};
|
|
103
|
-
s[o] = Object.freeze({ ...l, ...i });
|
|
104
|
-
}
|
|
105
|
-
}, me = I("component"), he = k(
|
|
106
|
-
({ client: t, component: e, name: s }) => {
|
|
107
|
-
const o = t.frameworks.getByName(e.frameworkName);
|
|
108
|
-
return {
|
|
109
|
-
name: s,
|
|
110
|
-
component: e,
|
|
111
|
-
frameworkStore: o
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
function ye(t) {
|
|
116
|
-
return b(he, t);
|
|
117
|
-
}
|
|
118
|
-
const Se = k(({ client: t }) => {
|
|
119
|
-
const e = me.store({}), s = x(e, {
|
|
120
|
-
register(r, n) {
|
|
121
|
-
return {
|
|
122
|
-
...r,
|
|
123
|
-
[n.name]: n
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
function o(r, n) {
|
|
128
|
-
e.getState()[r] && v(
|
|
129
|
-
"warn",
|
|
130
|
-
`Component '${r}' already registered. Registering again will override the previous registration.`
|
|
131
|
-
);
|
|
132
|
-
const y = ye({ client: t, name: r, component: n });
|
|
133
|
-
s.register(y);
|
|
134
|
-
}
|
|
135
|
-
const i = e.map((r) => Object.values(r));
|
|
136
|
-
function l(r) {
|
|
137
|
-
return e.map((n) => n[r], { skipVoid: !1 });
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
register: o,
|
|
141
|
-
getByName: l,
|
|
142
|
-
listStore: i
|
|
143
|
-
};
|
|
144
|
-
});
|
|
145
|
-
function we(t) {
|
|
146
|
-
return b(Se, t);
|
|
147
|
-
}
|
|
148
|
-
const T = (t, e, s) => {
|
|
149
|
-
s.register(t, e);
|
|
150
|
-
}, ve = I("framework"), ke = k(({ client: t }) => {
|
|
151
|
-
const e = ve.store({}), s = x(e, {
|
|
152
|
-
register(r, n) {
|
|
153
|
-
return {
|
|
154
|
-
...r,
|
|
155
|
-
[n.name]: n.framework
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
function o(r, n) {
|
|
160
|
-
e.getState()[r] && v(
|
|
161
|
-
"warn",
|
|
162
|
-
`Framework '${r}' already registered. Registering again will override the previous registration.`
|
|
163
|
-
), s.register({ name: r, framework: n });
|
|
164
|
-
}
|
|
165
|
-
const i = e.map((r) => Object.values(r));
|
|
166
|
-
function l(r) {
|
|
167
|
-
return e.map((n) => n[r], { skipVoid: !1 });
|
|
168
|
-
}
|
|
169
|
-
return {
|
|
170
|
-
register: o,
|
|
171
|
-
getByName: l,
|
|
172
|
-
listStore: i
|
|
173
|
-
};
|
|
174
|
-
});
|
|
175
|
-
function be(t) {
|
|
176
|
-
return b(ke, t);
|
|
177
|
-
}
|
|
178
|
-
const Ie = (t, e) => {
|
|
179
|
-
e.register(t.name, t);
|
|
180
|
-
}, xe = 6e3, V = $("last_ping", "global"), Fe = (t) => `${t}/api/v1/ping`, Ee = async (t) => {
|
|
181
|
-
try {
|
|
182
|
-
const e = Date.now(), s = localStorage.getItem(V);
|
|
183
|
-
if (s && e - parseInt(s) < xe)
|
|
184
|
-
return !0;
|
|
185
|
-
const o = Fe(t.apiUrl), i = {
|
|
186
|
-
projectId: t.projectId,
|
|
187
|
-
path: window.location.pathname
|
|
188
|
-
}, l = JSON.stringify(i), r = {
|
|
189
|
-
"Content-Type": "application/json"
|
|
190
|
-
}, n = document.getElementById("picked_script"), d = n == null ? void 0 : n.dataset.verceltoken;
|
|
191
|
-
d && (r["x-vercel-protection-bypass"] = d);
|
|
192
|
-
const c = (await fetch(o, {
|
|
193
|
-
method: "POST",
|
|
194
|
-
headers: r,
|
|
195
|
-
body: l
|
|
196
|
-
})).ok;
|
|
197
|
-
return c && localStorage.setItem(V, e.toString()), c;
|
|
198
|
-
} catch (e) {
|
|
199
|
-
return v("error", e), !1;
|
|
1
|
+
var y = Object.defineProperty;
|
|
2
|
+
var w = (i, e, t) => e in i ? y(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var n = (i, e, t) => w(i, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { c as S, a as x, b as I, d as P, e as k, f as v, g as E, h as F, i as b, j as C, p as A, s as R, k as u, l as j, m as B, n as z, o as U, q as O, r as $, t as d } from "../user-session-Ht0ayuo5.js";
|
|
5
|
+
import { l as c } from "../logger-C9a75KZn.js";
|
|
6
|
+
import { c as K, d as L, e as l } from "../experience-instance-CeuHLrdL.js";
|
|
7
|
+
import { i as pe } from "../experience-instance-CeuHLrdL.js";
|
|
8
|
+
import { createEvent as W } from "effector";
|
|
9
|
+
import { s as h, a as _, b as D } from "../supports-DBMT17KZ.js";
|
|
10
|
+
import { g as de, k as le, d as fe, i as he, e as ge, c as me, f as ye, h as we, j as Se } from "../supports-DBMT17KZ.js";
|
|
11
|
+
import { c as H, s as f } from "../storage-Cb_71y48.js";
|
|
12
|
+
import { l as Ie, a as Pe } from "../storage-Cb_71y48.js";
|
|
13
|
+
const q = (i, e, t) => {
|
|
14
|
+
const s = e.name, r = e.setup(i);
|
|
15
|
+
if (r) {
|
|
16
|
+
const o = t[s] ?? {};
|
|
17
|
+
t[s] = Object.freeze({ ...o, ...r });
|
|
200
18
|
}
|
|
201
19
|
};
|
|
202
|
-
function
|
|
203
|
-
const e = typeof window < "u",
|
|
204
|
-
client:
|
|
205
|
-
responses:
|
|
206
|
-
fields:
|
|
20
|
+
function N(i) {
|
|
21
|
+
const e = typeof window < "u", t = {
|
|
22
|
+
client: i,
|
|
23
|
+
responses: i.responses.listStore.getState(),
|
|
24
|
+
fields: i.fields.listStore.getState(),
|
|
207
25
|
location: e ? window.location : void 0,
|
|
208
26
|
document: e ? window.document : void 0,
|
|
209
27
|
sessionStorage: e ? window.sessionStorage : void 0,
|
|
210
28
|
localStorage: e ? window.localStorage : void 0
|
|
211
29
|
};
|
|
212
|
-
return Object.freeze(
|
|
213
|
-
}
|
|
214
|
-
const Re = I("predicate"), $e = k(({ client: t }) => {
|
|
215
|
-
const e = Re.store({}), s = x(e, {
|
|
216
|
-
register(r, n) {
|
|
217
|
-
return {
|
|
218
|
-
...r,
|
|
219
|
-
[n.name]: {
|
|
220
|
-
name: n.name,
|
|
221
|
-
predicate: n.predicate
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
function o(r, n) {
|
|
227
|
-
e.getState()[r] && v(
|
|
228
|
-
"warn",
|
|
229
|
-
`Predicate '${r}' already registered. Registering again will override the previous registration.`
|
|
230
|
-
), s.register(Object.freeze({ name: r, predicate: n }));
|
|
231
|
-
}
|
|
232
|
-
const i = e.map((r) => Object.values(r));
|
|
233
|
-
function l(r) {
|
|
234
|
-
return e.map((n) => n[r], { skipVoid: !1 });
|
|
235
|
-
}
|
|
236
|
-
return {
|
|
237
|
-
register: o,
|
|
238
|
-
getByName: l,
|
|
239
|
-
listStore: i
|
|
240
|
-
};
|
|
241
|
-
});
|
|
242
|
-
function Be(t) {
|
|
243
|
-
return b($e, t);
|
|
30
|
+
return Object.freeze(t);
|
|
244
31
|
}
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
register(c, f) {
|
|
250
|
-
return {
|
|
251
|
-
...c,
|
|
252
|
-
[f.id]: f.feature
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
function o(c, f) {
|
|
257
|
-
t.getState()[c] && v(
|
|
258
|
-
"warn",
|
|
259
|
-
`Feature '${c}' already registered. Registering again will override the previous registration.`
|
|
260
|
-
);
|
|
261
|
-
const p = {
|
|
262
|
-
id: c,
|
|
263
|
-
feature: {
|
|
264
|
-
...f,
|
|
265
|
-
id: c
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
s.register(
|
|
269
|
-
Object.freeze({
|
|
270
|
-
id: c,
|
|
271
|
-
feature: p
|
|
272
|
-
})
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
const i = O(
|
|
276
|
-
async ({
|
|
277
|
-
id: c,
|
|
278
|
-
key: f,
|
|
279
|
-
storage: a = "local"
|
|
280
|
-
}) => {
|
|
281
|
-
const p = $(`feature:${c}:${f}`, "global"), m = (a === "session" ? B : D).get(p).boolean();
|
|
282
|
-
if (m !== null)
|
|
283
|
-
return { id: c, bucket: m };
|
|
284
|
-
}
|
|
285
|
-
), l = O((c) => {
|
|
286
|
-
if (!c)
|
|
287
|
-
return null;
|
|
288
|
-
const f = $(`feature:${c.id}:${c.key}`, "global");
|
|
289
|
-
(c.storage === "session" ? B : D).set(f, c.bucket);
|
|
290
|
-
}), r = /* @__PURE__ */ new Map(), n = Y({
|
|
291
|
-
source: { allFeaturesStore: t, resolvedFeaturesStore: e },
|
|
292
|
-
effect: async ({ allFeaturesStore: c, resolvedFeaturesStore: f }, { id: a, decide: p, key: g }) => {
|
|
293
|
-
const m = f.find((F) => F.id === a);
|
|
294
|
-
if (m)
|
|
295
|
-
return m;
|
|
296
|
-
const u = c[a];
|
|
297
|
-
if (!u)
|
|
298
|
-
throw new Error(`Feature with id '${a}' not found`);
|
|
299
|
-
const S = r.get(`${a}:${g}`);
|
|
300
|
-
if (S !== void 0) {
|
|
301
|
-
const F = await S;
|
|
302
|
-
return { id: u.id, bucket: F, storage: u.feature.storage };
|
|
303
|
-
}
|
|
304
|
-
const w = p();
|
|
305
|
-
r.set(`${a}:${g}`, w);
|
|
306
|
-
const j = await w;
|
|
307
|
-
return { id: u.id, bucket: j, storage: u.feature.storage };
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
P({
|
|
311
|
-
clock: s.register,
|
|
312
|
-
fn: (c) => {
|
|
313
|
-
const { id: f, feature: a } = c;
|
|
314
|
-
return { id: f, key: a.feature.key, storage: a.feature.storage };
|
|
315
|
-
},
|
|
316
|
-
target: i
|
|
317
|
-
}), P({
|
|
318
|
-
source: e,
|
|
319
|
-
clock: [i.doneData, n.doneData],
|
|
320
|
-
fn: (c, f) => !f || c.some((a) => a.id === f.id) ? c : [...c, f],
|
|
321
|
-
target: e
|
|
322
|
-
}), P({
|
|
323
|
-
source: t,
|
|
324
|
-
clock: n.doneData,
|
|
325
|
-
fn: (c, f) => {
|
|
326
|
-
var u;
|
|
327
|
-
const { id: a, bucket: p, storage: g } = f, m = (u = c[a]) == null ? void 0 : u.feature.key;
|
|
328
|
-
return m ? { key: m, id: a, bucket: p, storage: g } : null;
|
|
329
|
-
},
|
|
330
|
-
target: l
|
|
331
|
-
});
|
|
332
|
-
const d = A({ allFeaturesStore: t, resolvedFeaturesStore: e }).map(
|
|
333
|
-
({
|
|
334
|
-
allFeaturesStore: c,
|
|
335
|
-
resolvedFeaturesStore: f
|
|
336
|
-
}) => Object.values(c).map((a) => {
|
|
337
|
-
const p = f.find((g) => g.id === a.id);
|
|
338
|
-
return p ? {
|
|
339
|
-
id: a.id,
|
|
340
|
-
name: a.feature.name,
|
|
341
|
-
key: a.feature.key,
|
|
342
|
-
getBucket: () => ({ id: a.id, bucket: p.bucket }),
|
|
343
|
-
isResolved: !0
|
|
344
|
-
} : {
|
|
345
|
-
id: a.id,
|
|
346
|
-
name: a.feature.name,
|
|
347
|
-
key: a.feature.key,
|
|
348
|
-
getBucket: async () => await n(a.feature),
|
|
349
|
-
isResolved: !1
|
|
350
|
-
};
|
|
351
|
-
})
|
|
352
|
-
);
|
|
353
|
-
function y(c) {
|
|
354
|
-
return t.map((f) => f[c], { skipVoid: !1 });
|
|
355
|
-
}
|
|
356
|
-
return {
|
|
357
|
-
register: o,
|
|
358
|
-
getByName: y,
|
|
359
|
-
listStore: d
|
|
360
|
-
};
|
|
361
|
-
});
|
|
362
|
-
function Ce() {
|
|
363
|
-
return b(Ae);
|
|
364
|
-
}
|
|
365
|
-
const De = (t, e, s) => {
|
|
366
|
-
s.register(t, e);
|
|
367
|
-
}, E = I("history");
|
|
368
|
-
function L(t, e) {
|
|
369
|
-
return {
|
|
370
|
-
// eslint-disable-next-line sonarjs/pseudo-random
|
|
371
|
-
id: re(`history-entry-${Date.now()}-${Math.random()}}`),
|
|
372
|
-
node: e,
|
|
373
|
-
at: Date.now(),
|
|
374
|
-
experienceId: t
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
const Oe = k(() => {
|
|
378
|
-
const t = E.store({ entries: [] }), e = E.event(), s = E.event(), o = E.event(), i = E.event();
|
|
379
|
-
t.on(e, (r, n) => ({
|
|
380
|
-
entries: [...r.entries, L(n.experienceId, n.node)]
|
|
381
|
-
})), t.on(s, (r, n) => ({
|
|
382
|
-
entries: [
|
|
383
|
-
...r.entries.slice(0, -1),
|
|
384
|
-
L(n.experienceId, n.node)
|
|
385
|
-
]
|
|
386
|
-
})), t.on(i, (r, n) => n);
|
|
387
|
-
function l(r, n) {
|
|
388
|
-
const d = { lastStepIndex: -1, secondLastStepIndex: -1 };
|
|
389
|
-
for (let y = r.length - 1; y >= 0; y--) {
|
|
390
|
-
const c = r[y], f = c == null ? void 0 : c.node;
|
|
391
|
-
if (!(!f || !Z(f)) && !(n && (c == null ? void 0 : c.experienceId) !== n))
|
|
392
|
-
if (d.lastStepIndex === -1)
|
|
393
|
-
d.lastStepIndex = y;
|
|
394
|
-
else {
|
|
395
|
-
d.secondLastStepIndex = y;
|
|
396
|
-
break;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
return d;
|
|
400
|
-
}
|
|
401
|
-
return t.on(o, (r, n) => {
|
|
402
|
-
const { secondLastStepIndex: d } = l(r.entries, n.experienceId), y = d !== -1 ? r.entries.slice(0, d + 1) : r.entries;
|
|
403
|
-
return {
|
|
404
|
-
...r,
|
|
405
|
-
entries: y
|
|
406
|
-
};
|
|
407
|
-
}), {
|
|
408
|
-
push: e,
|
|
409
|
-
replace: s,
|
|
410
|
-
back: o,
|
|
411
|
-
restore: i,
|
|
412
|
-
entriesStore: t.map((r) => r.entries)
|
|
413
|
-
};
|
|
414
|
-
});
|
|
415
|
-
function Me() {
|
|
416
|
-
return b(Oe);
|
|
417
|
-
}
|
|
418
|
-
const Te = () => C(), Ve = I("field"), Ne = k(() => {
|
|
419
|
-
const t = Ve.store({}), e = x(t, {
|
|
420
|
-
register(r, n) {
|
|
421
|
-
return {
|
|
422
|
-
...r,
|
|
423
|
-
[n.field.id]: n.field
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
});
|
|
427
|
-
function s(r) {
|
|
428
|
-
e.register({ field: r });
|
|
429
|
-
}
|
|
430
|
-
const o = t.map((r) => Object.values(r));
|
|
431
|
-
function i(r) {
|
|
432
|
-
return t.map((n) => n[r] || null);
|
|
433
|
-
}
|
|
434
|
-
function l(r) {
|
|
435
|
-
return t.map((n) => Object.values(n).find((d) => d.name === r) || null);
|
|
436
|
-
}
|
|
437
|
-
return {
|
|
438
|
-
register: s,
|
|
439
|
-
getById: i,
|
|
440
|
-
listStore: o,
|
|
441
|
-
getByName: l
|
|
442
|
-
};
|
|
443
|
-
});
|
|
444
|
-
function Le() {
|
|
445
|
-
return b(Ne);
|
|
446
|
-
}
|
|
447
|
-
const Ue = (t, e) => {
|
|
448
|
-
e.register(t);
|
|
449
|
-
}, ze = I("response"), _e = k(({ client: t }) => {
|
|
450
|
-
const e = ze.store({}), s = C(), o = C(), i = x(e, {
|
|
451
|
-
register(a, p) {
|
|
452
|
-
return {
|
|
453
|
-
...a,
|
|
454
|
-
[p.fieldId]: p.response
|
|
455
|
-
};
|
|
456
|
-
},
|
|
457
|
-
registerBatch(a, p) {
|
|
458
|
-
return {
|
|
459
|
-
...a,
|
|
460
|
-
...p
|
|
461
|
-
};
|
|
462
|
-
},
|
|
463
|
-
clear(a, p) {
|
|
464
|
-
const { [p]: g, ...m } = a;
|
|
465
|
-
return m;
|
|
466
|
-
},
|
|
467
|
-
clearAll() {
|
|
468
|
-
return {};
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
function l(a, p) {
|
|
472
|
-
i.register({ fieldId: a, response: p });
|
|
473
|
-
}
|
|
474
|
-
async function r(a) {
|
|
475
|
-
const p = [];
|
|
476
|
-
return await Promise.allSettled(
|
|
477
|
-
Object.entries(a).map(async ([g, m]) => {
|
|
478
|
-
let u = m;
|
|
479
|
-
const S = t.fields.getById(g).getState();
|
|
480
|
-
if (!S) {
|
|
481
|
-
p.push({
|
|
482
|
-
fieldId: g,
|
|
483
|
-
userMessage: `Field '${g}' not found`,
|
|
484
|
-
systemMessage: `No field with ID '${g}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,
|
|
485
|
-
value: u
|
|
486
|
-
});
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
if (S.multiple && (typeof u == "string" || typeof u == "number" || typeof u == "boolean") && (u = [u]), S.validation && !se(S.validation)) {
|
|
490
|
-
const w = await R(t, S.validation, {
|
|
491
|
-
$input: u
|
|
492
|
-
});
|
|
493
|
-
if (typeof w == "string") {
|
|
494
|
-
p.push({
|
|
495
|
-
fieldId: g,
|
|
496
|
-
userMessage: w,
|
|
497
|
-
systemMessage: `Field validation resulted in an error: ${w}.`,
|
|
498
|
-
value: u
|
|
499
|
-
});
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
if (w === !1) {
|
|
503
|
-
p.push({
|
|
504
|
-
fieldId: g,
|
|
505
|
-
userMessage: "This field is invalid",
|
|
506
|
-
systemMessage: "Field validation resulted in an unspecified error.",
|
|
507
|
-
value: u
|
|
508
|
-
});
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
if (S.required && (typeof u > "u" || u === null || u === "" || Array.isArray(u) && !u.length)) {
|
|
513
|
-
p.push({
|
|
514
|
-
fieldId: g,
|
|
515
|
-
userMessage: "This field is required",
|
|
516
|
-
systemMessage: "Field is required.",
|
|
517
|
-
value: u
|
|
518
|
-
});
|
|
519
|
-
return;
|
|
520
|
-
}
|
|
521
|
-
if (!S.multiple && Array.isArray(u) && u.length > 1) {
|
|
522
|
-
p.push({
|
|
523
|
-
fieldId: g,
|
|
524
|
-
userMessage: "This field expects a single response",
|
|
525
|
-
systemMessage: "Field expects a single response.",
|
|
526
|
-
value: u
|
|
527
|
-
});
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
if (S.options) {
|
|
531
|
-
const w = S.options.map((F) => F.value), j = Array.isArray(u) ? u : [u];
|
|
532
|
-
Array.isArray(u) && (j.every((F) => w.includes(F)) || p.push({
|
|
533
|
-
fieldId: g,
|
|
534
|
-
userMessage: "This field expects a valid option",
|
|
535
|
-
systemMessage: `Field expects a valid option. Valid options are: ${w.join(", ")}`,
|
|
536
|
-
value: u
|
|
537
|
-
}));
|
|
538
|
-
}
|
|
539
|
-
})
|
|
540
|
-
), { responsesToCommit: a, validationErrors: p };
|
|
541
|
-
}
|
|
542
|
-
async function n(a) {
|
|
543
|
-
const { responsesToCommit: p, validationErrors: g } = await r(a);
|
|
544
|
-
return g.length ? { errors: g } : (i.registerBatch(p), { errors: [] });
|
|
545
|
-
}
|
|
546
|
-
const d = e.map((a) => a), y = e.map((a) => Object.keys(a).map((g) => ({
|
|
547
|
-
fieldId: g,
|
|
548
|
-
value: a[g]
|
|
549
|
-
})));
|
|
550
|
-
function c(a) {
|
|
551
|
-
const p = t.fields.getById(a), g = e.map((m) => m[a] || null);
|
|
552
|
-
return A({ f: p, r: g }, ({ f: m, r: u }) => u || (m != null && m.defaultValue ? m.defaultValue : null));
|
|
553
|
-
}
|
|
554
|
-
function f(a) {
|
|
555
|
-
const p = t.fields.getByName(a);
|
|
556
|
-
return A({ f: p, s: e }, ({ f: g, s: m }) => {
|
|
557
|
-
const u = g && m[g.id] || null;
|
|
558
|
-
return u || (g != null && g.defaultValue ? g.defaultValue : null);
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
return P({
|
|
562
|
-
clock: s,
|
|
563
|
-
target: i.clearAll
|
|
564
|
-
}), P({
|
|
565
|
-
clock: o,
|
|
566
|
-
target: i.clear
|
|
567
|
-
}), {
|
|
568
|
-
register: l,
|
|
569
|
-
clearAll: s,
|
|
570
|
-
clear: o,
|
|
571
|
-
commit: n,
|
|
572
|
-
getResponsesToCommit: r,
|
|
573
|
-
listStore: y,
|
|
574
|
-
getAllStore: d,
|
|
575
|
-
getByFieldId: c,
|
|
576
|
-
getByFieldName: f
|
|
577
|
-
};
|
|
578
|
-
});
|
|
579
|
-
function He(t) {
|
|
580
|
-
return b(_e, t);
|
|
581
|
-
}
|
|
582
|
-
const Ke = () => "0.0.12";
|
|
583
|
-
function qe() {
|
|
584
|
-
if (z()) {
|
|
585
|
-
const t = [
|
|
32
|
+
const T = () => W(), V = () => "0.0.13";
|
|
33
|
+
function G() {
|
|
34
|
+
if (h()) {
|
|
35
|
+
const i = [
|
|
586
36
|
document.currentScript,
|
|
587
37
|
document.getElementById("picked_script"),
|
|
588
38
|
document.getElementById("picked"),
|
|
589
39
|
document.getElementById("cvly"),
|
|
590
40
|
document.getElementById("cvly-x")
|
|
591
41
|
];
|
|
592
|
-
for (const e of
|
|
42
|
+
for (const e of i)
|
|
593
43
|
if (e != null && e.dataset.api)
|
|
594
44
|
return e.dataset.api;
|
|
595
45
|
}
|
|
596
46
|
return "https://api.picked.app";
|
|
597
47
|
}
|
|
598
|
-
function
|
|
599
|
-
if (!
|
|
48
|
+
function J() {
|
|
49
|
+
if (!_())
|
|
600
50
|
return {};
|
|
601
|
-
const
|
|
602
|
-
for (const [
|
|
603
|
-
|
|
604
|
-
for (const
|
|
605
|
-
const
|
|
606
|
-
e[
|
|
607
|
-
}
|
|
608
|
-
const
|
|
609
|
-
if (
|
|
610
|
-
|
|
51
|
+
const i = new URLSearchParams(window.location.search), e = {}, t = /* @__PURE__ */ new Set();
|
|
52
|
+
for (const [r] of i.entries())
|
|
53
|
+
r.startsWith("picked-") && t.add(r);
|
|
54
|
+
for (const r of t) {
|
|
55
|
+
const o = r.replace("picked-", "");
|
|
56
|
+
e[o] = i.getAll(r);
|
|
57
|
+
}
|
|
58
|
+
const s = H("s");
|
|
59
|
+
if (t.size > 0)
|
|
60
|
+
f.set(s, e);
|
|
611
61
|
else {
|
|
612
|
-
const
|
|
613
|
-
if (
|
|
614
|
-
return
|
|
62
|
+
const r = f.get(s);
|
|
63
|
+
if (r)
|
|
64
|
+
return r.json() || {};
|
|
615
65
|
}
|
|
616
66
|
return e;
|
|
617
67
|
}
|
|
618
|
-
|
|
619
|
-
if (ie())
|
|
620
|
-
return crypto.randomUUID();
|
|
621
|
-
const t = Date.now().toString(36), e = Math.random().toString(36).substring(2, 15), s = Math.random().toString(36).substring(2, 15), o = Math.random().toString(36).substring(2, 15);
|
|
622
|
-
return `${t}-${e}-${s}-${o}`;
|
|
623
|
-
}
|
|
624
|
-
const Ye = () => ({
|
|
625
|
-
id: We()
|
|
626
|
-
}), Je = $("session", "global"), Qe = () => {
|
|
627
|
-
if (!oe()) return null;
|
|
628
|
-
const t = D.get(Je);
|
|
629
|
-
let e = t.isSet() ? t.json() : null;
|
|
630
|
-
return e || (e = Ye(), t.set(e)), e;
|
|
631
|
-
}, Xe = () => Qe();
|
|
632
|
-
class K {
|
|
68
|
+
class g {
|
|
633
69
|
constructor(e) {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
70
|
+
n(this, "options");
|
|
71
|
+
n(this, "isReady", !1);
|
|
72
|
+
n(this, "project");
|
|
73
|
+
n(this, "plugins", {});
|
|
74
|
+
n(this, "eventBus", T());
|
|
75
|
+
n(this, "organizationId");
|
|
76
|
+
n(this, "projectId");
|
|
77
|
+
n(this, "apiUrl");
|
|
78
|
+
n(this, "session");
|
|
79
|
+
n(this, "searchParams", J());
|
|
80
|
+
n(this, "history", S());
|
|
81
|
+
n(this, "components", x({ client: this }));
|
|
82
|
+
n(this, "experienceInstances", K({ client: this }));
|
|
83
|
+
n(this, "experiences", I({ client: this }));
|
|
84
|
+
n(this, "frameworks", P({ client: this }));
|
|
85
|
+
n(this, "predicates", k({ client: this }));
|
|
86
|
+
n(this, "features", v({ client: this }));
|
|
87
|
+
n(this, "responses", E({ client: this }));
|
|
88
|
+
n(this, "fields", F());
|
|
89
|
+
n(this, "actions", b());
|
|
90
|
+
c("info", "Picked client initializing."), this.organizationId = e.organizationId, this.projectId = e.projectId, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || G(), this.session = C(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.setupActions(), this.eventBus({ type: "initialized", version: V() }), c("info", "Picked client initialized.");
|
|
654
91
|
}
|
|
655
92
|
start() {
|
|
656
|
-
|
|
657
|
-
|
|
93
|
+
A(this), (async () => {
|
|
94
|
+
h() && (document.body && d(this), await L(), await d(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session && this.eventBus({ type: "session", ...this.session }));
|
|
658
95
|
})();
|
|
659
96
|
}
|
|
660
97
|
registerFramework(e) {
|
|
661
|
-
|
|
98
|
+
R(e, this.frameworks);
|
|
662
99
|
}
|
|
663
|
-
registerComponent(e,
|
|
664
|
-
|
|
100
|
+
registerComponent(e, t) {
|
|
101
|
+
u(e, t, this.components);
|
|
665
102
|
}
|
|
666
103
|
registerPlugin(e) {
|
|
667
|
-
|
|
104
|
+
q(this, e, this.plugins);
|
|
668
105
|
}
|
|
669
|
-
registerFeature(e,
|
|
670
|
-
|
|
106
|
+
registerFeature(e, t) {
|
|
107
|
+
j(e, t, this.features);
|
|
671
108
|
}
|
|
672
|
-
registerPredicate(e,
|
|
673
|
-
|
|
109
|
+
registerPredicate(e, t) {
|
|
110
|
+
B(e, t, this.predicates);
|
|
674
111
|
}
|
|
675
112
|
registerField(e) {
|
|
676
|
-
|
|
113
|
+
z(e, this.fields);
|
|
114
|
+
}
|
|
115
|
+
registerAction(e, t) {
|
|
116
|
+
U(e, t, this.actions);
|
|
677
117
|
}
|
|
678
118
|
registerExperience(e) {
|
|
679
|
-
e.component &&
|
|
119
|
+
e.component && u(`experience:${e.id}`, e.component, this.components), O(e, this.experiences);
|
|
680
120
|
}
|
|
681
121
|
getStateSnapshot() {
|
|
682
|
-
return
|
|
122
|
+
return N(this);
|
|
683
123
|
}
|
|
684
124
|
async launchExperienceById(e) {
|
|
685
|
-
const
|
|
686
|
-
if (!
|
|
687
|
-
|
|
125
|
+
const t = this.experiences.getById(e).getState();
|
|
126
|
+
if (!t) {
|
|
127
|
+
c("warn", `Experience with id '${e}' not found.`);
|
|
688
128
|
return;
|
|
689
129
|
}
|
|
690
|
-
|
|
130
|
+
$(this, t);
|
|
691
131
|
}
|
|
692
132
|
// private async fetchProject() {
|
|
693
133
|
// if (this.project) {
|
|
@@ -700,38 +140,38 @@ class K {
|
|
|
700
140
|
// }
|
|
701
141
|
setupPlugins() {
|
|
702
142
|
var e;
|
|
703
|
-
(e = this.options.plugins) == null || e.forEach((
|
|
704
|
-
if (Array.isArray(
|
|
705
|
-
|
|
706
|
-
this.registerPlugin(
|
|
143
|
+
(e = this.options.plugins) == null || e.forEach((t) => {
|
|
144
|
+
if (Array.isArray(t)) {
|
|
145
|
+
t.forEach((r) => {
|
|
146
|
+
this.registerPlugin(r);
|
|
707
147
|
});
|
|
708
148
|
return;
|
|
709
149
|
}
|
|
710
|
-
const
|
|
711
|
-
if (Array.isArray(
|
|
712
|
-
|
|
150
|
+
const s = typeof t == "function" ? t() : t;
|
|
151
|
+
if (Array.isArray(s)) {
|
|
152
|
+
s.forEach((r) => this.registerPlugin(r));
|
|
713
153
|
return;
|
|
714
154
|
}
|
|
715
|
-
this.registerPlugin(
|
|
155
|
+
this.registerPlugin(s);
|
|
716
156
|
});
|
|
717
157
|
}
|
|
718
158
|
setupFeatures() {
|
|
719
159
|
const e = this.options.features;
|
|
720
|
-
e && (Object.entries(e).forEach(([
|
|
721
|
-
const
|
|
722
|
-
this.registerFeature(
|
|
723
|
-
}), this.searchParams.feature && this.searchParams.feature.forEach((
|
|
160
|
+
e && (Object.entries(e).forEach(([t, s]) => {
|
|
161
|
+
const r = typeof s == "function" ? s() : s;
|
|
162
|
+
this.registerFeature(t, r);
|
|
163
|
+
}), this.searchParams.feature && this.searchParams.feature.forEach((t) => {
|
|
724
164
|
try {
|
|
725
|
-
const [
|
|
726
|
-
if (!
|
|
165
|
+
const [s, r] = t.split(":");
|
|
166
|
+
if (!s || !r)
|
|
727
167
|
return;
|
|
728
|
-
let
|
|
729
|
-
|
|
730
|
-
key: `${
|
|
168
|
+
let o = r;
|
|
169
|
+
o === "true" && (o = !0), o === "false" && (o = !1), this.registerFeature(s, {
|
|
170
|
+
key: `${o}`,
|
|
731
171
|
// use the assigned bucket value as the key
|
|
732
|
-
name:
|
|
172
|
+
name: s,
|
|
733
173
|
// eslint-disable-next-line sonarjs/function-return-type
|
|
734
|
-
decide: () =>
|
|
174
|
+
decide: () => o,
|
|
735
175
|
storage: "session"
|
|
736
176
|
});
|
|
737
177
|
} catch {
|
|
@@ -740,63 +180,73 @@ class K {
|
|
|
740
180
|
}
|
|
741
181
|
setupPredicates() {
|
|
742
182
|
const e = this.options.predicates;
|
|
743
|
-
e && Object.entries(e).forEach(([
|
|
744
|
-
if (typeof
|
|
745
|
-
|
|
183
|
+
e && Object.entries(e).forEach(([t, s]) => {
|
|
184
|
+
if (typeof s != "function") {
|
|
185
|
+
c("warn", `Predicate "${t}" is not a function.`);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.registerPredicate(t, s);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
setupActions() {
|
|
192
|
+
const e = this.options.actions;
|
|
193
|
+
e && Object.entries(e).forEach(([t, s]) => {
|
|
194
|
+
if (typeof s != "function") {
|
|
195
|
+
c("warn", `Action "${t}" is not a function.`);
|
|
746
196
|
return;
|
|
747
197
|
}
|
|
748
|
-
this.
|
|
198
|
+
this.registerAction(t, s);
|
|
749
199
|
});
|
|
750
200
|
}
|
|
751
201
|
getPluginConfig(e) {
|
|
752
202
|
return this.plugins[e] ?? {};
|
|
753
203
|
}
|
|
754
204
|
}
|
|
755
|
-
|
|
756
|
-
function
|
|
205
|
+
n(g, "logger", c);
|
|
206
|
+
function m(i) {
|
|
757
207
|
var e;
|
|
758
|
-
return ((e =
|
|
208
|
+
return ((e = i.options) == null ? void 0 : e.some((t) => "condition" in t)) ?? !1;
|
|
759
209
|
}
|
|
760
|
-
function
|
|
761
|
-
return
|
|
210
|
+
function M(i) {
|
|
211
|
+
return i.some((e) => e.condition || m(e));
|
|
762
212
|
}
|
|
763
|
-
async function
|
|
764
|
-
return e.length === 0 || !
|
|
765
|
-
e.map(async (
|
|
766
|
-
if (!(
|
|
213
|
+
async function re(i, e) {
|
|
214
|
+
return e.length === 0 || !M(e) ? e : (await Promise.all(
|
|
215
|
+
e.map(async (s) => {
|
|
216
|
+
if (!(s.condition ? await l(i, s.condition) : !0))
|
|
767
217
|
return null;
|
|
768
|
-
if (!
|
|
769
|
-
return
|
|
770
|
-
const
|
|
771
|
-
|
|
772
|
-
)).filter((
|
|
773
|
-
return
|
|
218
|
+
if (!s.options || !m(s))
|
|
219
|
+
return s;
|
|
220
|
+
const p = (await Promise.all(
|
|
221
|
+
s.options.map(async (a) => a.condition ? await l(i, a.condition) ? a : null : a)
|
|
222
|
+
)).filter((a) => a !== null);
|
|
223
|
+
return p.length === s.options.length ? s : p.length === 0 ? null : { ...s, options: p };
|
|
774
224
|
})
|
|
775
|
-
)).filter((
|
|
225
|
+
)).filter((s) => s !== null);
|
|
776
226
|
}
|
|
777
|
-
const
|
|
778
|
-
const e = new
|
|
779
|
-
return
|
|
227
|
+
const oe = (i) => {
|
|
228
|
+
const e = new g(i);
|
|
229
|
+
return D(e), e;
|
|
780
230
|
};
|
|
781
231
|
export {
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
232
|
+
g as Picked,
|
|
233
|
+
oe as createClient,
|
|
234
|
+
H as createStorageKey,
|
|
235
|
+
l as evaluateRuleLogic,
|
|
236
|
+
re as getStepFields,
|
|
237
|
+
pe as isPickedRoot,
|
|
238
|
+
Ie as localStore,
|
|
239
|
+
f as sessionStore,
|
|
240
|
+
Pe as subscribe,
|
|
241
|
+
de as supportsCookies,
|
|
242
|
+
le as supportsCryptoRandomUUID,
|
|
243
|
+
h as supportsDocument,
|
|
244
|
+
fe as supportsHistory,
|
|
245
|
+
he as supportsIntersectionObserver,
|
|
246
|
+
ge as supportsLocalStorage,
|
|
247
|
+
me as supportsLocation,
|
|
248
|
+
ye as supportsSessionStorage,
|
|
249
|
+
we as supportsShadowRoot,
|
|
250
|
+
Se as supportsWebComponents,
|
|
251
|
+
_ as supportsWindow
|
|
802
252
|
};
|