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