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