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