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