@picked/client 0.0.1-dev.1773371977114 → 0.0.1-dev.1773724362573
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-B3x8PEp4.js} +1 -1
- package/dist/{api-Cn-rv5A5.cjs → api-Z3Hn2Kw-.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 +723 -662
- 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/exports.d.ts +0 -1
- package/dist/types/exports.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/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 +10 -14
- 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/get-step-fields.d.ts +0 -4
- package/dist/types/utils/get-step-fields.d.ts.map +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,236 +1,236 @@
|
|
|
1
|
-
import { createDomain as
|
|
2
|
-
import { createFactory as
|
|
3
|
-
import { g as
|
|
4
|
-
import { f as zt } from "../experience-instance-
|
|
5
|
-
import { l as
|
|
6
|
-
import { c as $, l 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 R, sample as w, combine as E, createEvent as P } from "effector";
|
|
2
|
+
import { createFactory as I, invoke as x } from "@withease/factories";
|
|
3
|
+
import { g as Q, t as re, c as se, i as ne, e as D, a as ie, b as oe, d as ae } from "../experience-instance-DTyL1fNb.js";
|
|
4
|
+
import { f as zt } from "../experience-instance-DTyL1fNb.js";
|
|
5
|
+
import { l as b } from "../logger-C9a75KZn.js";
|
|
6
|
+
import { c as $, l as M, s as O } from "../storage-B2d81EOI.js";
|
|
7
|
+
import { a as Ct } from "../storage-B2d81EOI.js";
|
|
8
|
+
import { p as ce, g as ue } from "../api-B3x8PEp4.js";
|
|
9
|
+
import { g as de } from "../id-BW-g3y32.js";
|
|
10
|
+
import { i as le } 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 Ot, f as Dt, g as Ut, h as Vt, i as Nt, j as Tt, k as Lt } 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), n = 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
|
+
}), a = 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:
|
|
43
|
-
merge:
|
|
38
|
+
configStore: a,
|
|
39
|
+
treeStore: p,
|
|
40
|
+
fieldsStore: u,
|
|
41
|
+
componentStore: l,
|
|
42
|
+
actions: f,
|
|
43
|
+
merge: n.merge
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
);
|
|
47
|
-
function
|
|
48
|
-
return
|
|
47
|
+
function he(t) {
|
|
48
|
+
return x(me, t);
|
|
49
49
|
}
|
|
50
|
-
const
|
|
51
|
-
const e =
|
|
52
|
-
register(
|
|
50
|
+
const ye = 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
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
62
|
-
|
|
59
|
+
function n(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 = he({ client: t, experience: f });
|
|
66
|
+
r.register(h);
|
|
67
67
|
}
|
|
68
|
-
const
|
|
69
|
-
function f
|
|
70
|
-
return e.map((
|
|
68
|
+
const a = 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
|
-
register:
|
|
99
|
+
register: n,
|
|
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: a
|
|
110
110
|
};
|
|
111
111
|
});
|
|
112
|
-
function
|
|
113
|
-
return
|
|
112
|
+
function ve(t) {
|
|
113
|
+
return x(ye, t);
|
|
114
114
|
}
|
|
115
115
|
const Se = (t, e) => {
|
|
116
116
|
e.register(t);
|
|
117
|
-
},
|
|
118
|
-
const { targetSelectors:
|
|
119
|
-
|
|
120
|
-
({ elements:
|
|
121
|
-
),
|
|
122
|
-
r ? t.experienceInstances.spawn(e,
|
|
117
|
+
}, L = (t, e, r) => {
|
|
118
|
+
const { targetSelectors: n } = e.configStore.getState(), a = Q(n, e.id);
|
|
119
|
+
a.forEach(
|
|
120
|
+
({ elements: p }) => p.forEach((u) => re(u, e.id))
|
|
121
|
+
), se(a, 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
|
-
const { decisionLogic: r, targetSelectors:
|
|
134
|
-
return
|
|
135
|
-
},
|
|
136
|
-
const
|
|
137
|
-
if (
|
|
138
|
-
const
|
|
139
|
-
r[
|
|
133
|
+
const { decisionLogic: r, targetSelectors: n } = e.configStore.getState();
|
|
134
|
+
return Q(n, e.id).length < 1 || n.length === 0 ? !1 : r === void 0 ? !0 : ne(r) ? await D(t, r) === !0 : !0;
|
|
135
|
+
}, ke = (t, e, r) => {
|
|
136
|
+
const n = e.name, a = e.setup(t);
|
|
137
|
+
if (a) {
|
|
138
|
+
const l = r[n] ?? {};
|
|
139
|
+
r[n] = Object.freeze({ ...l, ...a });
|
|
140
140
|
}
|
|
141
|
-
},
|
|
141
|
+
}, we = F("component"), be = I(
|
|
142
142
|
({ client: t, component: e, name: r }) => {
|
|
143
|
-
const
|
|
143
|
+
const n = t.frameworks.getByName(e.frameworkName);
|
|
144
144
|
return {
|
|
145
145
|
name: r,
|
|
146
146
|
component: e,
|
|
147
|
-
frameworkStore:
|
|
147
|
+
frameworkStore: n
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
150
|
);
|
|
151
|
-
function
|
|
152
|
-
return
|
|
151
|
+
function Ie(t) {
|
|
152
|
+
return x(be, t);
|
|
153
153
|
}
|
|
154
|
-
const
|
|
155
|
-
const e =
|
|
156
|
-
register(
|
|
154
|
+
const xe = I(({ client: t }) => {
|
|
155
|
+
const e = we.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
|
|
164
|
-
e.getState()[
|
|
163
|
+
function n(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 = Ie({ client: t, name: p, component: u });
|
|
169
|
+
r.register(d);
|
|
170
170
|
}
|
|
171
|
-
const
|
|
172
|
-
function
|
|
173
|
-
return e.map((
|
|
171
|
+
const a = 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
|
-
register:
|
|
177
|
-
getByName:
|
|
178
|
-
listStore:
|
|
176
|
+
register: n,
|
|
177
|
+
getByName: l,
|
|
178
|
+
listStore: a
|
|
179
179
|
};
|
|
180
180
|
});
|
|
181
181
|
function Fe(t) {
|
|
182
|
-
return
|
|
182
|
+
return x(xe, t);
|
|
183
183
|
}
|
|
184
|
-
const
|
|
184
|
+
const q = (t, e, r) => {
|
|
185
185
|
r.register(t, e);
|
|
186
|
-
},
|
|
187
|
-
const e =
|
|
188
|
-
register(
|
|
186
|
+
}, je = F("framework"), Ee = I(({ client: t }) => {
|
|
187
|
+
const e = je.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
|
|
196
|
-
e.getState()[
|
|
195
|
+
function n(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 a = 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
|
-
register:
|
|
207
|
-
getByName:
|
|
208
|
-
listStore:
|
|
206
|
+
register: n,
|
|
207
|
+
getByName: l,
|
|
208
|
+
listStore: a
|
|
209
209
|
};
|
|
210
210
|
});
|
|
211
|
-
function
|
|
212
|
-
return
|
|
211
|
+
function Ae(t) {
|
|
212
|
+
return x(Ee, t);
|
|
213
213
|
}
|
|
214
214
|
const Pe = (t, e) => {
|
|
215
215
|
e.register(t.name, t);
|
|
216
|
-
},
|
|
216
|
+
}, $e = 6e3, Be = $("last_ping", "global"), ze = async (t) => {
|
|
217
217
|
try {
|
|
218
|
-
const e = Date.now(), r =
|
|
219
|
-
let
|
|
220
|
-
if (r.isSet() && (
|
|
218
|
+
const e = Date.now(), r = M.get(Be);
|
|
219
|
+
let n = 0;
|
|
220
|
+
if (r.isSet() && (n = r.json() ?? 0), n && e - n < $e)
|
|
221
221
|
return !0;
|
|
222
|
-
const
|
|
222
|
+
const a = {
|
|
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 ce(t.apiUrl, "ping", a, 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,686 @@ function Z(t) {
|
|
|
242
242
|
};
|
|
243
243
|
return Object.freeze(r);
|
|
244
244
|
}
|
|
245
|
-
const Re =
|
|
245
|
+
const Re = F("predicate"), Ce = I(({ client: t }) => {
|
|
246
246
|
const e = Re.store({}), r = j(e, {
|
|
247
|
-
register(
|
|
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
|
|
258
|
-
e.getState()[
|
|
257
|
+
function n(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 a = 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 = R(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
|
-
register:
|
|
289
|
-
getByName:
|
|
290
|
-
listStore:
|
|
291
|
-
getEvokablePredicate:
|
|
288
|
+
register: n,
|
|
289
|
+
getByName: l,
|
|
290
|
+
listStore: a,
|
|
291
|
+
getEvokablePredicate: p
|
|
292
292
|
};
|
|
293
293
|
});
|
|
294
|
-
function
|
|
295
|
-
return
|
|
294
|
+
function Me(t) {
|
|
295
|
+
return x(Ce, t);
|
|
296
296
|
}
|
|
297
297
|
const Oe = (t, e, r) => {
|
|
298
298
|
r.register(t, e);
|
|
299
|
-
},
|
|
300
|
-
const e =
|
|
301
|
-
register(
|
|
299
|
+
}, K = F("feature"), De = I(({ client: t }) => {
|
|
300
|
+
const e = K.store({}), r = K.store([]), n = j(e, {
|
|
301
|
+
register(c, s) {
|
|
302
302
|
return {
|
|
303
|
-
...
|
|
304
|
-
[
|
|
303
|
+
...c,
|
|
304
|
+
[s.id]: s.feature
|
|
305
305
|
};
|
|
306
306
|
}
|
|
307
307
|
});
|
|
308
|
-
function
|
|
309
|
-
e.getState()[
|
|
308
|
+
function a(c, s) {
|
|
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 o = {
|
|
314
|
+
id: c,
|
|
315
315
|
feature: {
|
|
316
|
-
...
|
|
317
|
-
id:
|
|
316
|
+
...s,
|
|
317
|
+
id: c
|
|
318
318
|
}
|
|
319
319
|
};
|
|
320
|
-
|
|
320
|
+
n.register(
|
|
321
321
|
Object.freeze({
|
|
322
|
-
id:
|
|
323
|
-
feature:
|
|
322
|
+
id: c,
|
|
323
|
+
feature: o
|
|
324
324
|
})
|
|
325
325
|
);
|
|
326
326
|
}
|
|
327
|
-
const
|
|
327
|
+
const l = R(
|
|
328
328
|
async ({
|
|
329
|
-
id:
|
|
330
|
-
key:
|
|
331
|
-
storage:
|
|
329
|
+
id: c,
|
|
330
|
+
key: s,
|
|
331
|
+
storage: i = "local"
|
|
332
332
|
}) => {
|
|
333
|
-
const
|
|
334
|
-
return
|
|
333
|
+
const o = $(`feature:${c}:${s}`, "global"), v = (i === "session" ? O : M).get(o).boolean();
|
|
334
|
+
return v === null ? null : { id: c, key: s, bucket: v, storage: i };
|
|
335
335
|
}
|
|
336
|
-
),
|
|
337
|
-
if (!
|
|
336
|
+
), p = R((c) => {
|
|
337
|
+
if (!c)
|
|
338
338
|
return null;
|
|
339
|
-
const
|
|
340
|
-
(
|
|
341
|
-
}),
|
|
339
|
+
const s = $(`feature:${c.id}:${c.key}`, "global");
|
|
340
|
+
(c.storage === "session" ? O : M).set(s, 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: s }, { id: i, decide: o, key: g }) => {
|
|
344
|
+
const v = s.find(
|
|
345
|
+
(z) => z.id === i && z.key === g
|
|
346
346
|
);
|
|
347
|
-
if (
|
|
348
|
-
return
|
|
349
|
-
const S =
|
|
347
|
+
if (v)
|
|
348
|
+
return v;
|
|
349
|
+
const S = c[i];
|
|
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 '${i}' not found`);
|
|
352
|
+
const B = u.get(`${i}:${g}`);
|
|
353
|
+
if (B !== void 0) {
|
|
354
|
+
const z = await B;
|
|
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 = o();
|
|
358
|
+
u.set(`${i}:${g}`, k);
|
|
359
|
+
const te = await k;
|
|
360
|
+
return { id: S.id, bucket: te, key: g, storage: S.feature.storage };
|
|
361
361
|
}
|
|
362
362
|
});
|
|
363
|
-
|
|
364
|
-
clock:
|
|
365
|
-
fn: (
|
|
366
|
-
const { id:
|
|
367
|
-
return { id:
|
|
363
|
+
w({
|
|
364
|
+
clock: n.register,
|
|
365
|
+
fn: (c) => {
|
|
366
|
+
const { id: s, feature: i } = c;
|
|
367
|
+
return { id: s, key: i.feature.key, storage: i.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, s) => {
|
|
374
|
+
const { id: i, bucket: o, storage: g } = s, v = c[i]?.feature.key;
|
|
375
|
+
return v ? { key: v, id: i, bucket: o, 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: s
|
|
383
|
+
}) => Object.values(c).map((i) => {
|
|
384
|
+
const o = s.find(
|
|
385
|
+
(g) => g.id === i.id && g.key === i.feature.key
|
|
386
386
|
);
|
|
387
|
-
return
|
|
388
|
-
id:
|
|
389
|
-
name:
|
|
390
|
-
key:
|
|
391
|
-
getBucket: () => ({ id:
|
|
387
|
+
return o ? {
|
|
388
|
+
id: i.id,
|
|
389
|
+
name: i.feature.name,
|
|
390
|
+
key: i.feature.key,
|
|
391
|
+
getBucket: () => ({ id: i.id, bucket: o.bucket }),
|
|
392
392
|
isResolved: !0
|
|
393
393
|
} : {
|
|
394
|
-
id:
|
|
395
|
-
name:
|
|
396
|
-
key:
|
|
397
|
-
getBucket: async () => await
|
|
394
|
+
id: i.id,
|
|
395
|
+
name: i.feature.name,
|
|
396
|
+
key: i.feature.key,
|
|
397
|
+
getBucket: async () => await f(i.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: s, key: i }) => !c.some(
|
|
406
|
+
(g) => g.id === s && g.key === i
|
|
407
407
|
),
|
|
408
|
-
fn: (
|
|
409
|
-
target: t.eventBus.prepend((
|
|
408
|
+
fn: (c, s) => s,
|
|
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, s) => !s || c.some(
|
|
417
|
+
(o) => o.id === s.id && o.key === s.key
|
|
418
|
+
) ? c : [...c, s],
|
|
419
419
|
target: r
|
|
420
420
|
});
|
|
421
|
-
function
|
|
422
|
-
return
|
|
421
|
+
function h(c) {
|
|
422
|
+
return d.map((s) => s.find((i) => i.id === c));
|
|
423
423
|
}
|
|
424
|
-
function y(
|
|
425
|
-
return e.map((
|
|
424
|
+
function y(c) {
|
|
425
|
+
return e.map((s) => s[c], { skipVoid: !1 });
|
|
426
426
|
}
|
|
427
|
-
function
|
|
428
|
-
const
|
|
427
|
+
function m(c) {
|
|
428
|
+
const s = _(
|
|
429
429
|
async () => {
|
|
430
430
|
},
|
|
431
431
|
{ skipVoid: !1 }
|
|
432
|
-
),
|
|
433
|
-
const
|
|
434
|
-
if (
|
|
435
|
-
return async () => (await
|
|
432
|
+
), i = R(async () => {
|
|
433
|
+
const o = h(c).getState();
|
|
434
|
+
if (o)
|
|
435
|
+
return async () => (await o.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: (o) => o.some((g) => g.id === c),
|
|
440
|
+
target: i
|
|
441
|
+
}), w({
|
|
442
|
+
clock: i.doneData,
|
|
443
|
+
filter: (o) => o !== void 0,
|
|
444
|
+
target: s
|
|
445
|
+
}), i(), s;
|
|
446
446
|
}
|
|
447
447
|
return {
|
|
448
|
-
register:
|
|
449
|
-
getById:
|
|
448
|
+
register: a,
|
|
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
456
|
function Ue(t) {
|
|
456
|
-
return
|
|
457
|
+
return x(De, t);
|
|
457
458
|
}
|
|
458
|
-
const
|
|
459
|
+
const Ve = (t, e, r) => {
|
|
459
460
|
r.register(t, e);
|
|
460
|
-
},
|
|
461
|
-
function
|
|
461
|
+
}, A = F("history");
|
|
462
|
+
function W(t, e) {
|
|
462
463
|
return {
|
|
463
464
|
// eslint-disable-next-line sonarjs/pseudo-random
|
|
464
|
-
id:
|
|
465
|
+
id: de(`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 =
|
|
472
|
-
t.on(e, (
|
|
473
|
-
entries: [...
|
|
474
|
-
})), t.on(r, (
|
|
471
|
+
const Ne = I(() => {
|
|
472
|
+
const t = A.store({ entries: [] }), e = A.event(), r = A.event(), n = A.event(), a = A.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(a, (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 || !ie(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(
|
|
495
|
-
const { secondLastStepIndex:
|
|
495
|
+
return t.on(n, (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
|
-
back:
|
|
504
|
-
restore:
|
|
505
|
-
entriesStore: t.map((
|
|
504
|
+
back: n,
|
|
505
|
+
restore: a,
|
|
506
|
+
entriesStore: t.map((p) => p.entries)
|
|
506
507
|
};
|
|
507
508
|
});
|
|
508
|
-
function
|
|
509
|
-
return
|
|
509
|
+
function Te() {
|
|
510
|
+
return x(Ne);
|
|
510
511
|
}
|
|
511
|
-
let
|
|
512
|
-
const
|
|
513
|
-
const e =
|
|
514
|
-
return
|
|
512
|
+
let Le = 0;
|
|
513
|
+
const _e = (t) => {
|
|
514
|
+
const e = _([]);
|
|
515
|
+
return w({
|
|
515
516
|
clock: t,
|
|
516
517
|
source: e,
|
|
517
|
-
fn: (r,
|
|
518
|
+
fn: (r, n) => [
|
|
518
519
|
...r,
|
|
519
520
|
{
|
|
520
|
-
id:
|
|
521
|
+
id: Le++,
|
|
521
522
|
at: /* @__PURE__ */ new Date(),
|
|
522
|
-
payload:
|
|
523
|
+
payload: n
|
|
523
524
|
}
|
|
524
525
|
],
|
|
525
526
|
target: e
|
|
526
527
|
}), e;
|
|
527
|
-
},
|
|
528
|
-
|
|
529
|
-
|
|
528
|
+
}, U = F("field");
|
|
529
|
+
function He(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 = Array.isArray(t.options) ? t.options : null, n = e ?? { status: "idle", options: r };
|
|
536
|
+
return {
|
|
537
|
+
...t,
|
|
538
|
+
...n,
|
|
539
|
+
options: n.options ?? r
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
const Ge = I(({ client: t }) => {
|
|
543
|
+
const e = U.store({}), r = j(e, {
|
|
544
|
+
register(s, i) {
|
|
530
545
|
return {
|
|
531
|
-
...
|
|
532
|
-
[
|
|
546
|
+
...s,
|
|
547
|
+
[i.field.id]: i.field
|
|
533
548
|
};
|
|
549
|
+
},
|
|
550
|
+
updateById(s, i) {
|
|
551
|
+
const o = s[i.fieldId];
|
|
552
|
+
return o ? { ...s, [i.fieldId]: Object.assign({}, o, i.updates) } : s;
|
|
534
553
|
}
|
|
535
554
|
});
|
|
536
|
-
function
|
|
537
|
-
|
|
555
|
+
function n(s) {
|
|
556
|
+
r.register({ field: s });
|
|
538
557
|
}
|
|
539
|
-
function s
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
558
|
+
function a(s, i) {
|
|
559
|
+
r.updateById({ fieldId: s, updates: i });
|
|
560
|
+
}
|
|
561
|
+
const l = U.store({}), p = E(
|
|
562
|
+
e,
|
|
563
|
+
l,
|
|
564
|
+
(s, i) => Object.values(s).map((o) => V(o, i[o.id]))
|
|
565
|
+
);
|
|
566
|
+
function u(s) {
|
|
567
|
+
return E(e, l, (i, o) => {
|
|
568
|
+
const g = i[s];
|
|
569
|
+
return g ? V(g, o[s]) : null;
|
|
545
570
|
});
|
|
546
|
-
e.register({ field: { ...y }, resolvedKey: o });
|
|
547
571
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
572
|
+
function f(s) {
|
|
573
|
+
return E(e, l, (i, o) => {
|
|
574
|
+
const g = Object.values(i).find((v) => v.name === s);
|
|
575
|
+
return g ? V(g, o[g.id]) : null;
|
|
576
|
+
});
|
|
551
577
|
}
|
|
552
|
-
|
|
553
|
-
|
|
578
|
+
const d = U.effect(
|
|
579
|
+
async ({
|
|
580
|
+
fieldId: s,
|
|
581
|
+
fieldOptions: i,
|
|
582
|
+
context: o
|
|
583
|
+
}) => {
|
|
584
|
+
if (t && !Array.isArray(i) && i !== null) {
|
|
585
|
+
const g = await D(t, i, o);
|
|
586
|
+
return He(g) ? { fieldId: s, options: g } : { fieldId: s, options: null };
|
|
587
|
+
}
|
|
588
|
+
return { fieldId: s, options: Array.isArray(i) ? i : null };
|
|
589
|
+
}
|
|
590
|
+
);
|
|
591
|
+
l.on(d, (s, { fieldId: i }) => {
|
|
592
|
+
const o = s[i];
|
|
593
|
+
return {
|
|
594
|
+
...s,
|
|
595
|
+
[i]: {
|
|
596
|
+
status: "loading",
|
|
597
|
+
// Preserve stale options during re-fetch so the UI doesn't flash blank
|
|
598
|
+
options: o?.status === "resolved" ? o.options : null
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
}), l.on(d.doneData, (s, { fieldId: i, options: o }) => ({
|
|
602
|
+
...s,
|
|
603
|
+
[i]: { status: "resolved", options: o }
|
|
604
|
+
})), l.on(d.fail, (s, { params: { fieldId: i } }) => ({
|
|
605
|
+
...s,
|
|
606
|
+
[i]: { status: "error", options: null, error: "Failed to resolve field options" }
|
|
607
|
+
}));
|
|
608
|
+
const h = P();
|
|
609
|
+
l.on(h, (s, i) => ({
|
|
610
|
+
...s,
|
|
611
|
+
[i]: { status: "waiting", options: null }
|
|
612
|
+
}));
|
|
613
|
+
const y = P();
|
|
614
|
+
t && w({
|
|
615
|
+
clock: y,
|
|
616
|
+
source: {
|
|
617
|
+
states: l,
|
|
618
|
+
fields: e
|
|
619
|
+
},
|
|
620
|
+
filter: ({ states: s }, { fieldId: i, force: o }) => {
|
|
621
|
+
if (o) return !0;
|
|
622
|
+
const g = s[i];
|
|
623
|
+
return !g || g.status === "idle";
|
|
624
|
+
},
|
|
625
|
+
fn: ({ fields: s }, { fieldId: i, context: o }) => {
|
|
626
|
+
const g = s[i] ?? null;
|
|
627
|
+
return {
|
|
628
|
+
fieldId: i,
|
|
629
|
+
fieldOptions: g?.options ?? null,
|
|
630
|
+
context: o
|
|
631
|
+
};
|
|
632
|
+
},
|
|
633
|
+
target: d
|
|
634
|
+
});
|
|
635
|
+
function m(s, i) {
|
|
636
|
+
y({ fieldId: s, force: i?.force, context: i?.context });
|
|
554
637
|
}
|
|
555
|
-
function
|
|
556
|
-
|
|
638
|
+
function c(s, i) {
|
|
639
|
+
for (const o of s)
|
|
640
|
+
y({ fieldId: o, force: i?.force, context: i?.context });
|
|
557
641
|
}
|
|
558
642
|
return {
|
|
559
|
-
register:
|
|
560
|
-
update:
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
643
|
+
register: n,
|
|
644
|
+
update: a,
|
|
645
|
+
getById: u,
|
|
646
|
+
listStore: p,
|
|
647
|
+
getByName: f,
|
|
648
|
+
resolve: m,
|
|
649
|
+
resolveAll: c,
|
|
650
|
+
setWaiting: h
|
|
567
651
|
};
|
|
568
652
|
});
|
|
569
|
-
function
|
|
570
|
-
return
|
|
653
|
+
function Je(t) {
|
|
654
|
+
return x(Ge, t ?? {});
|
|
571
655
|
}
|
|
572
|
-
const
|
|
656
|
+
const qe = (t, e) => {
|
|
573
657
|
e.register(t);
|
|
574
|
-
},
|
|
575
|
-
const
|
|
576
|
-
register(
|
|
658
|
+
}, Ke = F("action"), We = I(({ client: t }) => {
|
|
659
|
+
const e = Ke.store({}), r = j(e, {
|
|
660
|
+
register(u, f) {
|
|
577
661
|
return {
|
|
578
|
-
...
|
|
579
|
-
[
|
|
580
|
-
name:
|
|
581
|
-
action:
|
|
662
|
+
...u,
|
|
663
|
+
[f.name]: {
|
|
664
|
+
name: f.name,
|
|
665
|
+
action: f.action
|
|
582
666
|
}
|
|
583
667
|
};
|
|
584
668
|
}
|
|
585
669
|
});
|
|
586
|
-
function
|
|
587
|
-
|
|
670
|
+
function n(u, f) {
|
|
671
|
+
r.register({ name: u, action: f });
|
|
588
672
|
}
|
|
589
|
-
const
|
|
590
|
-
function
|
|
591
|
-
return
|
|
673
|
+
const a = e.map((u) => Object.values(u));
|
|
674
|
+
function l(u) {
|
|
675
|
+
return e.map((f) => f[u], { skipVoid: !1 });
|
|
592
676
|
}
|
|
593
|
-
function
|
|
594
|
-
return
|
|
595
|
-
(
|
|
596
|
-
const
|
|
597
|
-
return
|
|
677
|
+
function p(u) {
|
|
678
|
+
return e.map(
|
|
679
|
+
(f) => {
|
|
680
|
+
const d = f[u];
|
|
681
|
+
return d ? d.action : void 0;
|
|
598
682
|
},
|
|
599
683
|
{ skipVoid: !1 }
|
|
600
684
|
);
|
|
601
685
|
}
|
|
602
686
|
return {
|
|
603
|
-
register:
|
|
604
|
-
getByName:
|
|
605
|
-
listStore:
|
|
606
|
-
getEvokableAction:
|
|
687
|
+
register: n,
|
|
688
|
+
getByName: l,
|
|
689
|
+
listStore: a,
|
|
690
|
+
getEvokableAction: p
|
|
607
691
|
};
|
|
608
692
|
});
|
|
609
|
-
function
|
|
610
|
-
return
|
|
693
|
+
function Ye(t) {
|
|
694
|
+
return x(We, t);
|
|
611
695
|
}
|
|
612
|
-
const
|
|
696
|
+
const Qe = (t, e, r) => {
|
|
613
697
|
r.register(t, e);
|
|
614
698
|
};
|
|
615
|
-
function
|
|
699
|
+
function N(t) {
|
|
616
700
|
return typeof t > "u" || t === null || t === "" || Array.isArray(t) && !t.length;
|
|
617
701
|
}
|
|
618
|
-
function
|
|
702
|
+
function Xe(t) {
|
|
619
703
|
return typeof t == "string" || typeof t == "number" || typeof t == "boolean" || t === null;
|
|
620
704
|
}
|
|
621
|
-
function
|
|
705
|
+
function Y(t) {
|
|
622
706
|
try {
|
|
623
707
|
return JSON.stringify(t), !0;
|
|
624
708
|
} catch {
|
|
625
709
|
return !1;
|
|
626
710
|
}
|
|
627
711
|
}
|
|
628
|
-
const
|
|
629
|
-
const e =
|
|
630
|
-
register(
|
|
712
|
+
const Ze = F("response"), et = I(({ client: t }) => {
|
|
713
|
+
const e = Ze.store({}), r = P(), n = P(), a = j(e, {
|
|
714
|
+
register(m, c) {
|
|
631
715
|
return {
|
|
632
|
-
...
|
|
633
|
-
[
|
|
716
|
+
...m,
|
|
717
|
+
[c.fieldId]: c.response
|
|
634
718
|
};
|
|
635
719
|
},
|
|
636
|
-
registerBatch(
|
|
720
|
+
registerBatch(m, c) {
|
|
637
721
|
return {
|
|
638
|
-
...
|
|
639
|
-
...
|
|
722
|
+
...m,
|
|
723
|
+
...c
|
|
640
724
|
};
|
|
641
725
|
},
|
|
642
|
-
clear(
|
|
643
|
-
const { [
|
|
644
|
-
return
|
|
726
|
+
clear(m, c) {
|
|
727
|
+
const { [c]: s, ...i } = m;
|
|
728
|
+
return i;
|
|
645
729
|
},
|
|
646
730
|
clearAll() {
|
|
647
731
|
return {};
|
|
648
732
|
}
|
|
649
733
|
});
|
|
650
|
-
function
|
|
651
|
-
if (typeof
|
|
652
|
-
if (
|
|
734
|
+
function l(m, c) {
|
|
735
|
+
if (typeof m == "string") {
|
|
736
|
+
if (c === void 0)
|
|
653
737
|
throw new Error("Response is required when registering a single field");
|
|
654
|
-
|
|
738
|
+
a.register({ fieldId: m, response: c });
|
|
655
739
|
} else
|
|
656
|
-
|
|
740
|
+
a.registerBatch(m);
|
|
657
741
|
}
|
|
658
|
-
async function
|
|
659
|
-
const
|
|
742
|
+
async function p(m) {
|
|
743
|
+
const c = [];
|
|
660
744
|
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:
|
|
745
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity -- comprehensive validation logic; refactoring would harm readability
|
|
746
|
+
Object.entries(m).map(async ([s, i]) => {
|
|
747
|
+
let o = i;
|
|
748
|
+
const g = t.fields.getById(s).getState();
|
|
749
|
+
if (!g) {
|
|
750
|
+
c.push({
|
|
751
|
+
fieldId: s,
|
|
752
|
+
userMessage: `Field '${s}' not found`,
|
|
753
|
+
systemMessage: `No field with ID '${s}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,
|
|
754
|
+
value: o
|
|
671
755
|
});
|
|
672
756
|
return;
|
|
673
757
|
}
|
|
674
|
-
if (
|
|
675
|
-
const S = await
|
|
676
|
-
$input:
|
|
758
|
+
if (g.multiple && (typeof o == "string" || typeof o == "number" || typeof o == "boolean") && (o = [o]), g.validation && !le(g.validation) && !N(o)) {
|
|
759
|
+
const v = { ...e.getState(), ...m }, S = await D(t, g.validation, {
|
|
760
|
+
$input: o,
|
|
761
|
+
responses: v
|
|
677
762
|
});
|
|
678
763
|
if (typeof S == "string") {
|
|
679
|
-
|
|
680
|
-
fieldId:
|
|
764
|
+
c.push({
|
|
765
|
+
fieldId: s,
|
|
681
766
|
userMessage: S,
|
|
682
767
|
systemMessage: `Field validation resulted in an error: ${S}.`,
|
|
683
|
-
value:
|
|
768
|
+
value: o
|
|
684
769
|
});
|
|
685
770
|
return;
|
|
686
771
|
}
|
|
687
772
|
if (S === !1) {
|
|
688
|
-
|
|
689
|
-
fieldId:
|
|
773
|
+
c.push({
|
|
774
|
+
fieldId: s,
|
|
690
775
|
userMessage: "This field is invalid",
|
|
691
776
|
systemMessage: "Field validation resulted in an unspecified error.",
|
|
692
|
-
value:
|
|
777
|
+
value: o
|
|
693
778
|
});
|
|
694
779
|
return;
|
|
695
780
|
}
|
|
696
781
|
}
|
|
697
|
-
if (
|
|
698
|
-
|
|
699
|
-
fieldId:
|
|
782
|
+
if (g.required && N(o)) {
|
|
783
|
+
c.push({
|
|
784
|
+
fieldId: s,
|
|
700
785
|
userMessage: "This field is required",
|
|
701
786
|
systemMessage: "Field is required.",
|
|
702
|
-
value:
|
|
787
|
+
value: o
|
|
703
788
|
});
|
|
704
789
|
return;
|
|
705
790
|
}
|
|
706
|
-
if (!
|
|
707
|
-
|
|
708
|
-
fieldId:
|
|
791
|
+
if (!g.multiple && Array.isArray(o) && o.length > 1) {
|
|
792
|
+
c.push({
|
|
793
|
+
fieldId: s,
|
|
709
794
|
userMessage: "This field expects a single response",
|
|
710
795
|
systemMessage: "Field expects a single response.",
|
|
711
|
-
value:
|
|
796
|
+
value: o
|
|
712
797
|
});
|
|
713
798
|
return;
|
|
714
799
|
}
|
|
715
|
-
if (
|
|
716
|
-
if (
|
|
717
|
-
if (!Array.isArray(
|
|
718
|
-
|
|
719
|
-
fieldId:
|
|
800
|
+
if (g.type === "object" && !N(o))
|
|
801
|
+
if (g.multiple) {
|
|
802
|
+
if (!Array.isArray(o)) {
|
|
803
|
+
c.push({
|
|
804
|
+
fieldId: s,
|
|
720
805
|
userMessage: "This field expects multiple values",
|
|
721
806
|
systemMessage: "Field expects an array of objects.",
|
|
722
|
-
value:
|
|
807
|
+
value: o
|
|
723
808
|
});
|
|
724
809
|
return;
|
|
725
810
|
}
|
|
726
|
-
for (const
|
|
727
|
-
if (typeof
|
|
728
|
-
|
|
729
|
-
fieldId:
|
|
811
|
+
for (const v of o) {
|
|
812
|
+
if (typeof v != "object" || v === null) {
|
|
813
|
+
c.push({
|
|
814
|
+
fieldId: s,
|
|
730
815
|
userMessage: "This field expects object values",
|
|
731
816
|
systemMessage: "Field expects an array of objects, but received non-object value.",
|
|
732
|
-
value:
|
|
817
|
+
value: o
|
|
733
818
|
});
|
|
734
819
|
return;
|
|
735
820
|
}
|
|
736
|
-
if (!
|
|
737
|
-
|
|
738
|
-
fieldId:
|
|
821
|
+
if (!Y(v)) {
|
|
822
|
+
c.push({
|
|
823
|
+
fieldId: s,
|
|
739
824
|
userMessage: "This field contains non-serializable data",
|
|
740
825
|
systemMessage: "Field value contains non-JSON-serializable data (functions, circular references, etc.).",
|
|
741
|
-
value:
|
|
826
|
+
value: o
|
|
742
827
|
});
|
|
743
828
|
return;
|
|
744
829
|
}
|
|
745
830
|
}
|
|
746
831
|
} else {
|
|
747
|
-
if (Array.isArray(
|
|
748
|
-
|
|
749
|
-
fieldId:
|
|
832
|
+
if (Array.isArray(o)) {
|
|
833
|
+
c.push({
|
|
834
|
+
fieldId: s,
|
|
750
835
|
userMessage: "This field expects a single value",
|
|
751
836
|
systemMessage: "Field expects a single object, not an array.",
|
|
752
|
-
value:
|
|
837
|
+
value: o
|
|
753
838
|
});
|
|
754
839
|
return;
|
|
755
840
|
}
|
|
756
|
-
if (typeof
|
|
757
|
-
|
|
758
|
-
fieldId:
|
|
841
|
+
if (typeof o != "object" || o === null) {
|
|
842
|
+
c.push({
|
|
843
|
+
fieldId: s,
|
|
759
844
|
userMessage: "This field expects an object value",
|
|
760
845
|
systemMessage: "Field expects an object value.",
|
|
761
|
-
value:
|
|
846
|
+
value: o
|
|
762
847
|
});
|
|
763
848
|
return;
|
|
764
849
|
}
|
|
765
|
-
if (!
|
|
766
|
-
|
|
767
|
-
fieldId:
|
|
850
|
+
if (!Y(o)) {
|
|
851
|
+
c.push({
|
|
852
|
+
fieldId: s,
|
|
768
853
|
userMessage: "This field contains non-serializable data",
|
|
769
854
|
systemMessage: "Field value contains non-JSON-serializable data (functions, circular references, etc.).",
|
|
770
|
-
value:
|
|
855
|
+
value: o
|
|
771
856
|
});
|
|
772
857
|
return;
|
|
773
858
|
}
|
|
774
859
|
}
|
|
775
|
-
if (Array.isArray(
|
|
776
|
-
const
|
|
777
|
-
if (
|
|
778
|
-
const
|
|
779
|
-
|
|
780
|
-
fieldId:
|
|
860
|
+
if (Array.isArray(g.options) && g.options.length > 0) {
|
|
861
|
+
const v = Array.isArray(o) ? o : [o];
|
|
862
|
+
if (g.type === "object") {
|
|
863
|
+
const S = g.options.map((k) => JSON.stringify(k.value));
|
|
864
|
+
v.every((k) => S.includes(JSON.stringify(k))) || c.push({
|
|
865
|
+
fieldId: s,
|
|
781
866
|
userMessage: "This field expects a valid option",
|
|
782
867
|
systemMessage: "Field expects a valid option from the defined choices.",
|
|
783
|
-
value:
|
|
868
|
+
value: o
|
|
784
869
|
});
|
|
785
870
|
} else {
|
|
786
|
-
const
|
|
787
|
-
|
|
788
|
-
fieldId:
|
|
871
|
+
const S = g.options.map((k) => k.value);
|
|
872
|
+
v.every((k) => !Xe(k) || k === null ? !1 : S.includes(k)) || c.push({
|
|
873
|
+
fieldId: s,
|
|
789
874
|
userMessage: "This field expects a valid option",
|
|
790
|
-
systemMessage: `Field expects a valid option. Valid options are: ${
|
|
791
|
-
value:
|
|
875
|
+
systemMessage: `Field expects a valid option. Valid options are: ${S.join(", ")}`,
|
|
876
|
+
value: o
|
|
792
877
|
});
|
|
793
878
|
}
|
|
794
879
|
}
|
|
795
880
|
})
|
|
796
|
-
), { responsesToCommit:
|
|
881
|
+
), { responsesToCommit: m, validationErrors: c };
|
|
797
882
|
}
|
|
798
|
-
async function
|
|
799
|
-
const { responsesToCommit:
|
|
800
|
-
return
|
|
883
|
+
async function u(m) {
|
|
884
|
+
const { responsesToCommit: c, validationErrors: s } = await p(m);
|
|
885
|
+
return s.length ? { errors: s } : (a.registerBatch(c), { errors: [] });
|
|
801
886
|
}
|
|
802
|
-
const
|
|
803
|
-
fieldId:
|
|
804
|
-
value:
|
|
887
|
+
const f = e.map((m) => m), d = e.map((m) => Object.keys(m).map((s) => ({
|
|
888
|
+
fieldId: s,
|
|
889
|
+
value: m[s]
|
|
805
890
|
})));
|
|
806
|
-
function
|
|
807
|
-
const
|
|
808
|
-
return
|
|
891
|
+
function h(m) {
|
|
892
|
+
const c = t.fields.getById(m), s = e.map((i) => i[m] || null);
|
|
893
|
+
return E({ f: c, r: s }, ({ f: i, r: o }) => o || (i?.defaultValue ? i.defaultValue : null));
|
|
809
894
|
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
return p || (u?.defaultValue ? u.defaultValue : null);
|
|
895
|
+
function y(m) {
|
|
896
|
+
const c = t.fields.getByName(m);
|
|
897
|
+
return E({ f: c, s: e }, ({ f: s, s: i }) => {
|
|
898
|
+
const o = s && i[s.id] || null;
|
|
899
|
+
return o || (s?.defaultValue ? s.defaultValue : null);
|
|
816
900
|
});
|
|
817
901
|
}
|
|
818
|
-
return
|
|
902
|
+
return w({
|
|
819
903
|
clock: r,
|
|
820
|
-
target:
|
|
821
|
-
}),
|
|
822
|
-
clock:
|
|
823
|
-
target:
|
|
904
|
+
target: a.clearAll
|
|
905
|
+
}), w({
|
|
906
|
+
clock: n,
|
|
907
|
+
target: a.clear
|
|
824
908
|
}), {
|
|
825
|
-
register:
|
|
909
|
+
register: l,
|
|
826
910
|
clearAll: r,
|
|
827
|
-
clear:
|
|
828
|
-
commit:
|
|
829
|
-
getResponsesToCommit:
|
|
830
|
-
listStore:
|
|
831
|
-
getAllStore:
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
getByFieldId: y,
|
|
835
|
-
getByFieldName: F
|
|
911
|
+
clear: n,
|
|
912
|
+
commit: u,
|
|
913
|
+
getResponsesToCommit: p,
|
|
914
|
+
listStore: d,
|
|
915
|
+
getAllStore: f,
|
|
916
|
+
getByFieldId: h,
|
|
917
|
+
getByFieldName: y
|
|
836
918
|
};
|
|
837
919
|
});
|
|
838
|
-
function
|
|
839
|
-
return
|
|
920
|
+
function tt(t) {
|
|
921
|
+
return x(et, t);
|
|
840
922
|
}
|
|
841
|
-
function
|
|
842
|
-
if (
|
|
923
|
+
function rt() {
|
|
924
|
+
if (H()) {
|
|
843
925
|
const t = [
|
|
844
926
|
document.currentScript,
|
|
845
927
|
document.getElementById("picked_script"),
|
|
@@ -853,70 +935,70 @@ function tt() {
|
|
|
853
935
|
}
|
|
854
936
|
return "https://api.picked.app";
|
|
855
937
|
}
|
|
856
|
-
function
|
|
857
|
-
if (!
|
|
938
|
+
function st() {
|
|
939
|
+
if (!G())
|
|
858
940
|
return {};
|
|
859
941
|
const t = new URLSearchParams(window.location.search), e = {}, r = /* @__PURE__ */ new Set();
|
|
860
|
-
for (const [
|
|
861
|
-
|
|
862
|
-
for (const
|
|
863
|
-
const
|
|
864
|
-
e[
|
|
942
|
+
for (const [a] of t.entries())
|
|
943
|
+
a.startsWith("picked-") && r.add(a);
|
|
944
|
+
for (const a of r) {
|
|
945
|
+
const l = a.replace("picked-", "");
|
|
946
|
+
e[l] = t.getAll(a);
|
|
865
947
|
}
|
|
866
|
-
const
|
|
948
|
+
const n = $("s");
|
|
867
949
|
if (r.size > 0)
|
|
868
|
-
|
|
950
|
+
O.set(n, e);
|
|
869
951
|
else {
|
|
870
|
-
const
|
|
871
|
-
if (
|
|
872
|
-
return
|
|
952
|
+
const a = O.get(n);
|
|
953
|
+
if (a)
|
|
954
|
+
return a.json() || {};
|
|
873
955
|
}
|
|
874
956
|
return e;
|
|
875
957
|
}
|
|
876
|
-
function
|
|
877
|
-
if (
|
|
958
|
+
function nt() {
|
|
959
|
+
if (fe())
|
|
878
960
|
return crypto.randomUUID();
|
|
879
|
-
const t = Date.now().toString(36), e = Math.random().toString(36).substring(2, 15), r = Math.random().toString(36).substring(2, 15),
|
|
880
|
-
return `${t}-${e}-${r}-${
|
|
961
|
+
const t = Date.now().toString(36), e = Math.random().toString(36).substring(2, 15), r = Math.random().toString(36).substring(2, 15), n = Math.random().toString(36).substring(2, 15);
|
|
962
|
+
return `${t}-${e}-${r}-${n}`;
|
|
881
963
|
}
|
|
882
|
-
const
|
|
883
|
-
const t =
|
|
964
|
+
const it = $("session", "global"), ot = () => {
|
|
965
|
+
const t = M.get(it);
|
|
884
966
|
let e;
|
|
885
967
|
t.isSet() && (e = t.json());
|
|
886
|
-
const r = (
|
|
887
|
-
id:
|
|
888
|
-
isUser:
|
|
889
|
-
identifiers:
|
|
890
|
-
}),
|
|
891
|
-
id: e?.id ??
|
|
968
|
+
const r = (a) => t.set({
|
|
969
|
+
id: a.id,
|
|
970
|
+
isUser: a.isUser,
|
|
971
|
+
identifiers: a.identifiers
|
|
972
|
+
}), n = {
|
|
973
|
+
id: e?.id ?? nt(),
|
|
892
974
|
isUser: e?.isUser ?? void 0,
|
|
893
975
|
identifiers: e?.identifiers ?? void 0,
|
|
894
|
-
setIsUser(
|
|
895
|
-
this.isUser =
|
|
976
|
+
setIsUser(a) {
|
|
977
|
+
this.isUser = a, r(this);
|
|
896
978
|
},
|
|
897
|
-
setIdentifier(
|
|
898
|
-
this.identifiers = { ...this.identifiers, [
|
|
979
|
+
setIdentifier(a, l) {
|
|
980
|
+
this.identifiers = { ...this.identifiers, [a]: l }, r(this);
|
|
899
981
|
},
|
|
900
|
-
removeIdentifier(
|
|
982
|
+
removeIdentifier(a) {
|
|
901
983
|
this.identifiers && (this.identifiers = Object.fromEntries(
|
|
902
|
-
Object.entries(this.identifiers).filter(([
|
|
984
|
+
Object.entries(this.identifiers).filter(([l]) => l !== a)
|
|
903
985
|
), this.identifiers = Object.keys(this.identifiers).length ? this.identifiers : void 0, r(this));
|
|
904
986
|
}
|
|
905
987
|
};
|
|
906
|
-
return r(
|
|
907
|
-
},
|
|
908
|
-
function
|
|
909
|
-
if (
|
|
988
|
+
return r(n), n;
|
|
989
|
+
}, at = () => pe() ? ot() : null;
|
|
990
|
+
function ct() {
|
|
991
|
+
if (G())
|
|
910
992
|
return globalThis.window.pickedConfig;
|
|
911
993
|
}
|
|
912
|
-
function
|
|
913
|
-
if (!
|
|
994
|
+
function ut() {
|
|
995
|
+
if (!G())
|
|
914
996
|
return;
|
|
915
|
-
const t =
|
|
997
|
+
const t = ct(), e = t?.organizationId, r = t?.projectId;
|
|
916
998
|
return e && r ? { organizationId: e, projectId: r } : void 0;
|
|
917
999
|
}
|
|
918
|
-
function
|
|
919
|
-
if (!
|
|
1000
|
+
function dt() {
|
|
1001
|
+
if (!H())
|
|
920
1002
|
return;
|
|
921
1003
|
const t = document.getElementById("picked_script") || document.querySelector("script#picked") || // legacy support for 'cvly' script tag
|
|
922
1004
|
document.getElementById("cvly");
|
|
@@ -925,16 +1007,16 @@ function ut() {
|
|
|
925
1007
|
const e = t.dataset.organizationid || t.getAttribute("organization-id"), r = t.dataset.projectid || t.getAttribute("project-id");
|
|
926
1008
|
return e && r ? { organizationId: e, projectId: r } : void 0;
|
|
927
1009
|
}
|
|
928
|
-
function
|
|
1010
|
+
function lt(t) {
|
|
929
1011
|
const { organizationId: e, projectId: r } = t;
|
|
930
1012
|
if (e && r)
|
|
931
1013
|
return { organizationId: e, projectId: r };
|
|
932
|
-
const s = ct();
|
|
933
|
-
if (s)
|
|
934
|
-
return s;
|
|
935
1014
|
const n = ut();
|
|
936
1015
|
if (n)
|
|
937
1016
|
return n;
|
|
1017
|
+
const a = dt();
|
|
1018
|
+
if (a)
|
|
1019
|
+
return a;
|
|
938
1020
|
throw new Error(
|
|
939
1021
|
`organizationId and projectId are required. You can provide them via one of:
|
|
940
1022
|
(1) createClient({ organizationId, projectId }) options;
|
|
@@ -945,7 +1027,7 @@ function dt(t) {
|
|
|
945
1027
|
function C(t) {
|
|
946
1028
|
return t == null || t === "" || Number.isNaN(t);
|
|
947
1029
|
}
|
|
948
|
-
const
|
|
1030
|
+
const pt = {
|
|
949
1031
|
default: (t, e) => C(t) ? String(e ?? "") : String(t),
|
|
950
1032
|
append: (t, e) => e && !C(t) ? `${t} ${e}` : t,
|
|
951
1033
|
prepend: (t, e) => e && !C(t) ? `${e} ${t}` : t,
|
|
@@ -959,59 +1041,59 @@ const lt = {
|
|
|
959
1041
|
if (Array.isArray(t))
|
|
960
1042
|
return e.format(t.map(String));
|
|
961
1043
|
if (t instanceof Map) {
|
|
962
|
-
const r = Array.from(t.entries()).map(([
|
|
1044
|
+
const r = Array.from(t.entries()).map(([n, a]) => `${n}: ${a}`);
|
|
963
1045
|
return e.format(r);
|
|
964
1046
|
}
|
|
965
1047
|
return t instanceof Set ? e.format(Array.from(t).map(String)) : t;
|
|
966
1048
|
}
|
|
967
1049
|
};
|
|
968
|
-
function
|
|
1050
|
+
function ft(t) {
|
|
969
1051
|
return typeof t == "object" && t !== null;
|
|
970
1052
|
}
|
|
971
|
-
function
|
|
1053
|
+
function gt(t, e) {
|
|
972
1054
|
let r = e;
|
|
973
|
-
for (const
|
|
974
|
-
if (
|
|
975
|
-
r = r[
|
|
1055
|
+
for (const n of t.split("."))
|
|
1056
|
+
if (ft(r) && n in r)
|
|
1057
|
+
r = r[n];
|
|
976
1058
|
else
|
|
977
1059
|
return;
|
|
978
1060
|
return typeof r == "function" ? r() : r;
|
|
979
1061
|
}
|
|
980
|
-
function
|
|
981
|
-
const r = t.split("|").map((
|
|
982
|
-
let
|
|
983
|
-
for (const
|
|
984
|
-
const [
|
|
985
|
-
|
|
1062
|
+
function mt(t, e) {
|
|
1063
|
+
const r = t.split("|").map((l) => l.trim()), n = r.shift() ?? "";
|
|
1064
|
+
let a = gt(n, e);
|
|
1065
|
+
for (const l of r) {
|
|
1066
|
+
const [p, ...u] = l.split(":"), f = p?.trim() ?? "", d = u.join(":").trim().replaceAll(/(?:^['"]|['"]$)/g, ""), h = pt[f];
|
|
1067
|
+
h && (a = h(a, d));
|
|
986
1068
|
}
|
|
987
|
-
return C(
|
|
1069
|
+
return C(a) ? "" : typeof a == "object" ? JSON.stringify(a) : String(a);
|
|
988
1070
|
}
|
|
989
|
-
function
|
|
990
|
-
let r = "",
|
|
991
|
-
for (;
|
|
992
|
-
if (t[
|
|
993
|
-
|
|
994
|
-
let
|
|
995
|
-
for (;
|
|
996
|
-
if (t[
|
|
997
|
-
|
|
1071
|
+
function ht(t, e) {
|
|
1072
|
+
let r = "", n = 0;
|
|
1073
|
+
for (; n < t.length; )
|
|
1074
|
+
if (t[n] === "{" && t[n + 1] === "{") {
|
|
1075
|
+
n += 2;
|
|
1076
|
+
let a = "";
|
|
1077
|
+
for (; n < t.length; ) {
|
|
1078
|
+
if (t[n] === "}" && t[n + 1] === "}") {
|
|
1079
|
+
n += 2;
|
|
998
1080
|
break;
|
|
999
1081
|
}
|
|
1000
|
-
|
|
1082
|
+
a += t[n++];
|
|
1001
1083
|
}
|
|
1002
|
-
r +=
|
|
1084
|
+
r += mt(a.trim(), e);
|
|
1003
1085
|
} else
|
|
1004
|
-
r += t[
|
|
1086
|
+
r += t[n++];
|
|
1005
1087
|
return r;
|
|
1006
1088
|
}
|
|
1007
|
-
class
|
|
1008
|
-
static logger =
|
|
1089
|
+
class yt {
|
|
1090
|
+
static logger = b;
|
|
1009
1091
|
options;
|
|
1010
1092
|
isReady = !1;
|
|
1011
1093
|
project;
|
|
1012
1094
|
plugins = {};
|
|
1013
1095
|
pluginStartHooks = [];
|
|
1014
|
-
eventBus =
|
|
1096
|
+
eventBus = P();
|
|
1015
1097
|
events;
|
|
1016
1098
|
organizationId;
|
|
1017
1099
|
projectId;
|
|
@@ -1022,39 +1104,39 @@ class ht {
|
|
|
1022
1104
|
precondition;
|
|
1023
1105
|
condition;
|
|
1024
1106
|
preconditionPassed;
|
|
1025
|
-
searchParams =
|
|
1026
|
-
history =
|
|
1107
|
+
searchParams = st();
|
|
1108
|
+
history = Te();
|
|
1027
1109
|
components = Fe({ client: this });
|
|
1028
|
-
experienceInstances =
|
|
1029
|
-
experiences =
|
|
1030
|
-
frameworks =
|
|
1031
|
-
predicates =
|
|
1110
|
+
experienceInstances = oe({ client: this });
|
|
1111
|
+
experiences = ve({ client: this });
|
|
1112
|
+
frameworks = Ae({ client: this });
|
|
1113
|
+
predicates = Me({ client: this });
|
|
1032
1114
|
features = Ue({ client: this });
|
|
1033
|
-
responses =
|
|
1034
|
-
fields =
|
|
1035
|
-
actions =
|
|
1115
|
+
responses = tt({ client: this });
|
|
1116
|
+
fields = Je({ client: this });
|
|
1117
|
+
actions = Ye({ client: this });
|
|
1036
1118
|
constructor(e) {
|
|
1037
|
-
|
|
1038
|
-
const { organizationId: r, projectId:
|
|
1039
|
-
this.organizationId = r, this.projectId =
|
|
1119
|
+
b("info", "Picked client initializing."), this.events = _e(this.eventBus);
|
|
1120
|
+
const { organizationId: r, projectId: n } = lt(e);
|
|
1121
|
+
this.organizationId = r, this.projectId = n, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || rt(), this.dashboardUrl = e.dashboardUrl ?? "https://dashboard.picked.app", this.documentationSiteUrl = e.documentationSiteUrl ?? "https://docs.picked.app", this.session = at(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.setupActions(), this.setupComponents(), this.precondition = e.precondition, this.condition = e.condition, this.eventBus({ type: "load", version: ue() }), b("info", "Picked client initialized.");
|
|
1040
1122
|
}
|
|
1041
1123
|
start = () => {
|
|
1042
|
-
|
|
1043
|
-
if (!
|
|
1124
|
+
ze(this), (async () => {
|
|
1125
|
+
if (!H())
|
|
1044
1126
|
return;
|
|
1045
1127
|
await this.runPluginStartHooks();
|
|
1046
1128
|
const r = await this.evaluateGate(this.precondition);
|
|
1047
1129
|
this.preconditionPassed = r;
|
|
1048
|
-
let
|
|
1049
|
-
r && (
|
|
1050
|
-
const
|
|
1051
|
-
if (typeof
|
|
1052
|
-
const
|
|
1053
|
-
this.session.setIsUser(
|
|
1130
|
+
let n;
|
|
1131
|
+
r && (n = await this.evaluateGate(this.condition));
|
|
1132
|
+
const a = r && n === !0;
|
|
1133
|
+
if (typeof n == "boolean" && this.session) {
|
|
1134
|
+
const l = n;
|
|
1135
|
+
this.session.setIsUser(l), this.eventBus({ type: "user_decide", value: l });
|
|
1054
1136
|
}
|
|
1055
|
-
if (this.eventBus({ type: "initialize" }),
|
|
1056
|
-
const { id:
|
|
1057
|
-
this.eventBus({ type: "session", id:
|
|
1137
|
+
if (this.eventBus({ type: "initialize" }), a && J(this), await ae(), a && J(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session) {
|
|
1138
|
+
const { id: l, isUser: p, identifiers: u } = this.session;
|
|
1139
|
+
this.eventBus({ type: "session", id: l, isUser: p, identifiers: u });
|
|
1058
1140
|
}
|
|
1059
1141
|
})();
|
|
1060
1142
|
};
|
|
@@ -1062,29 +1144,29 @@ class ht {
|
|
|
1062
1144
|
Pe(e, this.frameworks);
|
|
1063
1145
|
};
|
|
1064
1146
|
registerComponent = (e, r) => {
|
|
1065
|
-
|
|
1147
|
+
q(e, r, this.components);
|
|
1066
1148
|
};
|
|
1067
1149
|
registerPlugin = (e) => {
|
|
1068
|
-
|
|
1150
|
+
ke(this, e, this.plugins);
|
|
1069
1151
|
const r = this.plugins[e.name];
|
|
1070
1152
|
r?.onStart && this.pluginStartHooks.push(r.onStart);
|
|
1071
1153
|
};
|
|
1072
1154
|
registerFeature = (e, r) => {
|
|
1073
|
-
|
|
1155
|
+
Ve(e, r, this.features);
|
|
1074
1156
|
};
|
|
1075
1157
|
registerPredicate = (e, r) => {
|
|
1076
1158
|
Oe(e, r, this.predicates);
|
|
1077
1159
|
};
|
|
1078
1160
|
registerField = (e) => {
|
|
1079
|
-
|
|
1161
|
+
qe(e, this.fields);
|
|
1080
1162
|
};
|
|
1081
1163
|
registerAction = (e, r) => {
|
|
1082
|
-
|
|
1164
|
+
Qe(e, r, this.actions);
|
|
1083
1165
|
};
|
|
1084
1166
|
registerExperience = (e) => {
|
|
1085
|
-
e.component &&
|
|
1167
|
+
e.component && q(`experience:${e.id}`, e.component, this.components), Se(e, this.experiences);
|
|
1086
1168
|
};
|
|
1087
|
-
getStateSnapshot = () =>
|
|
1169
|
+
getStateSnapshot = () => ee(this);
|
|
1088
1170
|
/** @deprecated Use `client.experiences.launch({ id: experienceId })` instead. */
|
|
1089
1171
|
launchExperienceById = async (e, r) => {
|
|
1090
1172
|
this.experiences.launch({ id: e, options: r });
|
|
@@ -1098,19 +1180,19 @@ class ht {
|
|
|
1098
1180
|
await e();
|
|
1099
1181
|
}
|
|
1100
1182
|
async evaluateGate(e) {
|
|
1101
|
-
return e === void 0 ? !0 : typeof e == "boolean" ? e : await
|
|
1183
|
+
return e === void 0 ? !0 : typeof e == "boolean" ? e : await D(this, e) === !0;
|
|
1102
1184
|
}
|
|
1103
1185
|
setupPlugins() {
|
|
1104
1186
|
this.options.plugins?.forEach((e) => {
|
|
1105
1187
|
if (Array.isArray(e)) {
|
|
1106
|
-
e.forEach((
|
|
1107
|
-
this.registerPlugin(
|
|
1188
|
+
e.forEach((n) => {
|
|
1189
|
+
this.registerPlugin(n);
|
|
1108
1190
|
});
|
|
1109
1191
|
return;
|
|
1110
1192
|
}
|
|
1111
1193
|
const r = typeof e == "function" ? e() : e;
|
|
1112
1194
|
if (Array.isArray(r)) {
|
|
1113
|
-
r.forEach((
|
|
1195
|
+
r.forEach((n) => this.registerPlugin(n));
|
|
1114
1196
|
return;
|
|
1115
1197
|
}
|
|
1116
1198
|
this.registerPlugin(r);
|
|
@@ -1118,21 +1200,21 @@ class ht {
|
|
|
1118
1200
|
}
|
|
1119
1201
|
setupFeatures() {
|
|
1120
1202
|
const e = this.options.features;
|
|
1121
|
-
e && (Object.entries(e).forEach(([r,
|
|
1122
|
-
const
|
|
1123
|
-
this.registerFeature(r,
|
|
1203
|
+
e && (Object.entries(e).forEach(([r, n]) => {
|
|
1204
|
+
const a = typeof n == "function" ? n() : n;
|
|
1205
|
+
this.registerFeature(r, a);
|
|
1124
1206
|
}), this.searchParams.feature && this.searchParams.feature.forEach((r) => {
|
|
1125
1207
|
try {
|
|
1126
|
-
const [
|
|
1127
|
-
if (!
|
|
1208
|
+
const [n, a] = r.split(":");
|
|
1209
|
+
if (!n || !a)
|
|
1128
1210
|
return;
|
|
1129
|
-
let
|
|
1130
|
-
|
|
1131
|
-
key: `${
|
|
1211
|
+
let l = a;
|
|
1212
|
+
l === "true" && (l = !0), l === "false" && (l = !1), this.registerFeature(n, {
|
|
1213
|
+
key: `${l}`,
|
|
1132
1214
|
// use the assigned bucket value as the key
|
|
1133
|
-
name:
|
|
1215
|
+
name: n,
|
|
1134
1216
|
// eslint-disable-next-line sonarjs/function-return-type
|
|
1135
|
-
decide: () =>
|
|
1217
|
+
decide: () => l,
|
|
1136
1218
|
storage: "session"
|
|
1137
1219
|
});
|
|
1138
1220
|
} catch {
|
|
@@ -1141,28 +1223,28 @@ class ht {
|
|
|
1141
1223
|
}
|
|
1142
1224
|
setupPredicates() {
|
|
1143
1225
|
const e = this.options.predicates;
|
|
1144
|
-
e && Object.entries(e).forEach(([r,
|
|
1145
|
-
if (typeof
|
|
1146
|
-
|
|
1226
|
+
e && Object.entries(e).forEach(([r, n]) => {
|
|
1227
|
+
if (typeof n != "function") {
|
|
1228
|
+
b("warn", `Predicate "${r}" is not a function.`);
|
|
1147
1229
|
return;
|
|
1148
1230
|
}
|
|
1149
|
-
this.registerPredicate(r,
|
|
1231
|
+
this.registerPredicate(r, n);
|
|
1150
1232
|
});
|
|
1151
1233
|
}
|
|
1152
1234
|
setupActions() {
|
|
1153
1235
|
const e = this.options.actions;
|
|
1154
|
-
e && Object.entries(e).forEach(([r,
|
|
1155
|
-
if (typeof
|
|
1156
|
-
|
|
1236
|
+
e && Object.entries(e).forEach(([r, n]) => {
|
|
1237
|
+
if (typeof n != "function") {
|
|
1238
|
+
b("warn", `Action "${r}" is not a function.`);
|
|
1157
1239
|
return;
|
|
1158
1240
|
}
|
|
1159
|
-
this.registerAction(r,
|
|
1241
|
+
this.registerAction(r, n);
|
|
1160
1242
|
});
|
|
1161
1243
|
}
|
|
1162
1244
|
setupComponents() {
|
|
1163
1245
|
const e = this.options.components;
|
|
1164
|
-
e && Object.entries(e).forEach(([r,
|
|
1165
|
-
this.registerComponent(r,
|
|
1246
|
+
e && Object.entries(e).forEach(([r, n]) => {
|
|
1247
|
+
this.registerComponent(r, n);
|
|
1166
1248
|
});
|
|
1167
1249
|
}
|
|
1168
1250
|
getPluginConfig = (e) => this.plugins[e] ?? {};
|
|
@@ -1209,34 +1291,14 @@ class ht {
|
|
|
1209
1291
|
* // => "Fruits: apple, banana, and cherry"
|
|
1210
1292
|
*/
|
|
1211
1293
|
renderString = (e, r) => {
|
|
1212
|
-
const
|
|
1213
|
-
return
|
|
1294
|
+
const n = this.responses.listStore.getState().reduce((a, l) => (a[l.fieldId] = l.value, a), {});
|
|
1295
|
+
return ht(e, {
|
|
1214
1296
|
...r,
|
|
1215
|
-
responses:
|
|
1297
|
+
responses: n
|
|
1216
1298
|
});
|
|
1217
1299
|
};
|
|
1218
1300
|
}
|
|
1219
|
-
function
|
|
1220
|
-
return t.options?.some((e) => "condition" in e) ?? !1;
|
|
1221
|
-
}
|
|
1222
|
-
function yt(t) {
|
|
1223
|
-
return t.some((e) => e.condition || ee(e));
|
|
1224
|
-
}
|
|
1225
|
-
async function Et(t, e) {
|
|
1226
|
-
return e.length === 0 || !yt(e) ? e : (await Promise.all(
|
|
1227
|
-
e.map(async (s) => {
|
|
1228
|
-
if (!(s.condition ? await A(t, s.condition) : !0))
|
|
1229
|
-
return null;
|
|
1230
|
-
if (!s.options || !ee(s))
|
|
1231
|
-
return s;
|
|
1232
|
-
const i = (await Promise.all(
|
|
1233
|
-
s.options.map(async (o) => o.condition ? await A(t, o.condition) ? o : null : o)
|
|
1234
|
-
)).filter((o) => o !== null);
|
|
1235
|
-
return i.length === s.options.length ? s : i.length === 0 ? null : { ...s, options: i };
|
|
1236
|
-
})
|
|
1237
|
-
)).filter((s) => s !== null);
|
|
1238
|
-
}
|
|
1239
|
-
function Pt(t) {
|
|
1301
|
+
function Et(t) {
|
|
1240
1302
|
return {
|
|
1241
1303
|
$$type: "lazy-component",
|
|
1242
1304
|
load: t
|
|
@@ -1245,32 +1307,31 @@ function Pt(t) {
|
|
|
1245
1307
|
function At(t) {
|
|
1246
1308
|
return typeof t == "object" && t !== null && "$$type" in t && t.$$type === "lazy-component";
|
|
1247
1309
|
}
|
|
1248
|
-
const
|
|
1249
|
-
const e = new
|
|
1250
|
-
return
|
|
1310
|
+
const Pt = (t) => {
|
|
1311
|
+
const e = new yt(t);
|
|
1312
|
+
return ge(e), e;
|
|
1251
1313
|
};
|
|
1252
1314
|
export {
|
|
1253
|
-
|
|
1254
|
-
|
|
1315
|
+
yt as Picked,
|
|
1316
|
+
Pt as createClient,
|
|
1255
1317
|
$ as createStorageKey,
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
Et as getStepFields,
|
|
1318
|
+
D as evaluateRuleLogic,
|
|
1319
|
+
ct as getPickedConfig,
|
|
1259
1320
|
At as isLazyLoader,
|
|
1260
1321
|
zt as isPickedRoot,
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1322
|
+
Et as lazyComponent,
|
|
1323
|
+
M as localStore,
|
|
1324
|
+
O as sessionStore,
|
|
1325
|
+
Ct as subscribe,
|
|
1326
|
+
Ot as supportsCookies,
|
|
1327
|
+
fe as supportsCryptoRandomUUID,
|
|
1328
|
+
H as supportsDocument,
|
|
1268
1329
|
Dt as supportsHistory,
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1330
|
+
Ut as supportsIntersectionObserver,
|
|
1331
|
+
pe as supportsLocalStorage,
|
|
1332
|
+
Vt as supportsLocation,
|
|
1333
|
+
Nt as supportsSessionStorage,
|
|
1334
|
+
Tt as supportsShadowRoot,
|
|
1335
|
+
Lt as supportsWebComponents,
|
|
1336
|
+
G as supportsWindow
|
|
1276
1337
|
};
|