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