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