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