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