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