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