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