@picked/client 0.0.1-dev.1772412203098 → 0.0.1-dev.1773363643396
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-C7ddxkUx.cjs +1 -0
- package/dist/api-CQ_YBH_c.js +32 -0
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/plugins/create-experience/index.js +1 -1
- package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
- package/dist/cjs/plugins/experience-browser-storage/index.js +1 -1
- package/dist/cjs/plugins/history-browser-storage/index.js +1 -1
- package/dist/cjs/plugins/responses-browser-storage/index.js +1 -1
- package/dist/cjs/plugins/responses-indexeddb/index.js +1 -1
- package/dist/cjs/plugins/single-page-app/index.js +1 -1
- package/dist/cjs/server/index.js +1 -1
- package/dist/esm/index.js +602 -687
- package/dist/esm/plugins/create-experience/index.js +237 -213
- package/dist/esm/plugins/dynamic-experiences/index.js +65 -43
- package/dist/esm/plugins/experience-browser-storage/index.js +1 -1
- package/dist/esm/plugins/history-browser-storage/index.js +1 -1
- package/dist/esm/plugins/responses-browser-storage/index.js +18 -17
- package/dist/esm/plugins/responses-indexeddb/index.js +46 -51
- package/dist/esm/plugins/single-page-app/index.js +24 -24
- package/dist/esm/server/index.js +1 -1
- package/dist/experience-instance-BsXG5XJ4.cjs +1 -0
- package/dist/{experience-instance-DTyL1fNb.js → experience-instance-fvSEb72i.js} +199 -205
- package/dist/object-BbFTsGh3.cjs +1 -0
- package/dist/{object-CJssU1Pm.js → object-JwZ58NOH.js} +1 -1
- package/dist/storage-Be5xWNPC.cjs +1 -0
- package/dist/{storage-B2d81EOI.js → storage-Co_LbKr_.js} +30 -35
- package/dist/to-kebab-case-BPnCZjhB.js +6 -0
- package/dist/to-kebab-case-BsOQ8CON.cjs +1 -0
- package/dist/types/client.d.ts +13 -0
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/entities/action/action.d.ts +2 -5
- package/dist/types/entities/action/action.d.ts.map +1 -1
- package/dist/types/entities/experience/experience.d.ts +31 -17
- package/dist/types/entities/experience/experience.d.ts.map +1 -1
- package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
- package/dist/types/entities/feature/feature.d.ts.map +1 -1
- package/dist/types/entities/field/field.d.ts +21 -52
- package/dist/types/entities/field/field.d.ts.map +1 -1
- package/dist/types/entities/history/history.d.ts.map +1 -1
- package/dist/types/entities/project/project.d.ts.map +1 -1
- package/dist/types/entities/response/response.d.ts +6 -6
- package/dist/types/entities/response/response.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/logic-engine.d.ts +8 -2
- package/dist/types/logic-engine.d.ts.map +1 -1
- package/dist/types/picked.d.ts +17 -23
- package/dist/types/picked.d.ts.map +1 -1
- package/dist/types/plugins/create-experience/create-experience.d.ts +28 -33
- package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/index.d.ts +1 -0
- package/dist/types/plugins/dynamic-experiences/index.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/plugin.d.ts +2 -2
- package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/types.d.ts +7 -1
- package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
- package/dist/types/plugins/experience-browser-storage/plugin.d.ts +1 -2
- package/dist/types/plugins/experience-browser-storage/plugin.d.ts.map +1 -1
- package/dist/types/plugins/history-browser-storage/plugin.d.ts +1 -2
- package/dist/types/plugins/history-browser-storage/plugin.d.ts.map +1 -1
- package/dist/types/plugins/responses-browser-storage/plugin.d.ts +1 -2
- package/dist/types/plugins/responses-browser-storage/plugin.d.ts.map +1 -1
- package/dist/types/plugins/responses-indexeddb/plugin.d.ts.map +1 -1
- package/dist/types/plugins/single-page-app/plugin.d.ts +1 -1
- package/dist/types/plugins/single-page-app/plugin.d.ts.map +1 -1
- package/dist/types/utils/api.d.ts +1 -1
- package/dist/types/utils/api.d.ts.map +1 -1
- package/dist/types/utils/client-headers.d.ts +2 -0
- package/dist/types/utils/client-headers.d.ts.map +1 -0
- package/dist/types/utils/dom.d.ts +3 -0
- package/dist/types/utils/dom.d.ts.map +1 -1
- package/dist/types/utils/events.d.ts +1 -1
- package/dist/types/utils/events.d.ts.map +1 -1
- package/dist/types/utils/get-step-fields.d.ts +1 -2
- package/dist/types/utils/get-step-fields.d.ts.map +1 -1
- package/dist/types/utils/global-obj.d.ts +1 -0
- package/dist/types/utils/global-obj.d.ts.map +1 -1
- package/dist/types/utils/indexed-db.d.ts +1 -2
- package/dist/types/utils/indexed-db.d.ts.map +1 -1
- package/dist/types/utils/logger.d.ts.map +1 -1
- package/dist/types/utils/node-tree/min-max-steps-to-leaf.d.ts.map +1 -1
- package/dist/types/utils/node-tree/min-max-steps-to-origin.d.ts.map +1 -1
- package/dist/types/utils/node-tree/next-reachable-step-nodes.d.ts.map +1 -1
- package/dist/types/utils/object.d.ts +8 -0
- package/dist/types/utils/object.d.ts.map +1 -1
- package/dist/types/utils/picked-config.d.ts +1 -1
- package/dist/types/utils/picked-config.d.ts.map +1 -1
- package/dist/types/utils/rules-logic.d.ts.map +1 -1
- package/dist/types/utils/search-params.d.ts.map +1 -1
- package/dist/types/utils/storage.d.ts.map +1 -1
- package/dist/types/utils/to-kebab-case.d.ts +9 -0
- package/dist/types/utils/to-kebab-case.d.ts.map +1 -0
- package/package.json +59 -8
- package/dist/api-CbXfbi_s.js +0 -19
- package/dist/api-DzSCgBQ2.cjs +0 -1
- package/dist/experience-instance-BX0aqKsC.cjs +0 -1
- package/dist/object-mwaxtjLG.cjs +0 -1
- package/dist/storage-58NoTSsc.cjs +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as l } from "../../../api-CQ_YBH_c.js";
|
|
2
|
+
import { c as S } from "../../../api-CQ_YBH_c.js";
|
|
2
3
|
import { l as a } from "../../../logger-C9a75KZn.js";
|
|
3
4
|
function d(e) {
|
|
4
5
|
let r = 2166136261;
|
|
@@ -12,104 +13,125 @@ function p(e) {
|
|
|
12
13
|
function g(e, r) {
|
|
13
14
|
return r <= 0 ? !1 : r >= 100 ? !0 : e < r;
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
return typeof e != "object" || e === null || !("
|
|
16
|
+
function h(e) {
|
|
17
|
+
return typeof e != "object" || e === null || !("key" in e && "name" in e && "enabled" in e && "weight" in e && "version" in e) ? !1 : typeof e.key == "string" && typeof e.name == "string" && typeof e.enabled == "boolean" && typeof e.weight == "number" && typeof e.version == "number";
|
|
17
18
|
}
|
|
18
|
-
function
|
|
19
|
-
return typeof e != "object" || e === null || !("features" in e) || !Array.isArray(e.features) ? !1 : e.features.every(
|
|
19
|
+
function f(e) {
|
|
20
|
+
return typeof e != "object" || e === null || !("features" in e) || !Array.isArray(e.features) ? !1 : e.features.every(h);
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
+
function m(e) {
|
|
22
23
|
const r = e.searchParams["preview-token"];
|
|
23
24
|
if (r && r.length > 0)
|
|
24
25
|
return r[0];
|
|
25
26
|
}
|
|
26
|
-
function
|
|
27
|
+
function y(e) {
|
|
27
28
|
const r = /* @__PURE__ */ new Set(), n = e.searchParams.feature;
|
|
28
29
|
if (!n)
|
|
29
30
|
return r;
|
|
30
|
-
for (const
|
|
31
|
-
const t =
|
|
32
|
-
t > 0 && r.add(
|
|
31
|
+
for (const o of n) {
|
|
32
|
+
const t = o.indexOf(":");
|
|
33
|
+
t > 0 && r.add(o.substring(0, t));
|
|
33
34
|
}
|
|
34
35
|
return r;
|
|
35
36
|
}
|
|
36
|
-
function
|
|
37
|
-
const
|
|
37
|
+
function c(e, r, n) {
|
|
38
|
+
const o = y(e), t = e.session?.id;
|
|
38
39
|
if (!t)
|
|
39
40
|
throw new Error("Session ID is required for feature registration");
|
|
40
|
-
const
|
|
41
|
+
const i = p(t);
|
|
41
42
|
for (const s of r.features)
|
|
42
|
-
|
|
43
|
+
o.has(s.key) || w(e, s, n, i);
|
|
43
44
|
}
|
|
44
|
-
function
|
|
45
|
-
e.registerFeature(r.
|
|
45
|
+
function w(e, r, n, o) {
|
|
46
|
+
e.registerFeature(r.key, {
|
|
46
47
|
key: `v${r.version}`,
|
|
47
48
|
name: r.name,
|
|
48
49
|
storage: n ? "session" : "local",
|
|
49
|
-
decide: () => r.enabled ? g(
|
|
50
|
+
decide: () => r.enabled ? g(o, r.weight) : !1
|
|
50
51
|
});
|
|
51
52
|
}
|
|
52
|
-
function
|
|
53
|
-
if (typeof __PICKED_PROJECT_CONFIG__ > "u")
|
|
54
|
-
return;
|
|
53
|
+
function v() {
|
|
55
54
|
let e;
|
|
56
|
-
|
|
55
|
+
try {
|
|
56
|
+
e = __PICKED_PROJECT_CONFIG__;
|
|
57
|
+
} catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (e === void 0)
|
|
61
|
+
return;
|
|
62
|
+
let r;
|
|
63
|
+
if (typeof e == "string")
|
|
57
64
|
try {
|
|
58
|
-
|
|
65
|
+
r = JSON.parse(e);
|
|
59
66
|
} catch {
|
|
60
67
|
a("warn", "Build-time project config is not valid JSON");
|
|
61
68
|
return;
|
|
62
69
|
}
|
|
63
70
|
else
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
return
|
|
71
|
+
r = e;
|
|
72
|
+
if (f(r))
|
|
73
|
+
return r;
|
|
67
74
|
a("warn", "Build-time project config has invalid shape, falling back to runtime fetch");
|
|
68
75
|
}
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
function j(e) {
|
|
77
|
+
try {
|
|
78
|
+
const r = new URL(e).hostname;
|
|
79
|
+
return r === "localhost" || r === "127.0.0.1" || r === "::1";
|
|
80
|
+
} catch {
|
|
81
|
+
return !1;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function k(e) {
|
|
85
|
+
if (typeof e != "object" || e === null || !("cause" in e))
|
|
86
|
+
return !1;
|
|
87
|
+
const { cause: r } = e;
|
|
88
|
+
return typeof r != "object" || r === null || !("code" in r) ? !1 : r.code === "ECONNREFUSED";
|
|
89
|
+
}
|
|
90
|
+
async function u(e, r, n) {
|
|
91
|
+
const o = n?.previewToken ? `projects/${r}?preview_token=${encodeURIComponent(n.previewToken)}` : `projects/${r}`;
|
|
71
92
|
let t;
|
|
72
93
|
try {
|
|
73
|
-
t = await l(e,
|
|
94
|
+
t = await l(e, o, n?.headers);
|
|
74
95
|
} catch (s) {
|
|
75
|
-
return a("warn", "Failed to fetch project config", s), null;
|
|
96
|
+
return j(e) && k(s) || a("warn", "Failed to fetch project config", s), null;
|
|
76
97
|
}
|
|
77
98
|
if (!t.ok)
|
|
78
99
|
return a("warn", `Project config request failed with status ${t.status.toString()}`), null;
|
|
79
|
-
let
|
|
100
|
+
let i;
|
|
80
101
|
try {
|
|
81
|
-
|
|
102
|
+
i = await t.json();
|
|
82
103
|
} catch {
|
|
83
104
|
return a("warn", "Failed to parse project config response"), null;
|
|
84
105
|
}
|
|
85
|
-
return
|
|
106
|
+
return f(i) ? i : (a("warn", "Invalid project config response shape"), null);
|
|
86
107
|
}
|
|
87
|
-
function
|
|
108
|
+
function P(e) {
|
|
88
109
|
return {
|
|
89
110
|
name: "dynamic-experiences",
|
|
90
111
|
setup: (r) => {
|
|
91
112
|
const n = e?.apiUrl ?? r.apiUrl;
|
|
92
113
|
return {
|
|
93
114
|
onStart: async () => {
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
96
|
-
const s = await
|
|
97
|
-
s &&
|
|
115
|
+
const o = m(r);
|
|
116
|
+
if (o) {
|
|
117
|
+
const s = await u(n, r.projectId, { previewToken: o });
|
|
118
|
+
s && c(r, s, !0);
|
|
98
119
|
return;
|
|
99
120
|
}
|
|
100
|
-
const t = e?.projectConfig ??
|
|
121
|
+
const t = e?.projectConfig ?? v();
|
|
101
122
|
if (t) {
|
|
102
|
-
|
|
123
|
+
c(r, t, !1);
|
|
103
124
|
return;
|
|
104
125
|
}
|
|
105
|
-
const
|
|
106
|
-
|
|
126
|
+
const i = await u(n, r.projectId);
|
|
127
|
+
i && c(r, i, !1);
|
|
107
128
|
}
|
|
108
129
|
};
|
|
109
130
|
}
|
|
110
131
|
};
|
|
111
132
|
}
|
|
112
133
|
export {
|
|
113
|
-
|
|
114
|
-
|
|
134
|
+
S as createClientHeaders,
|
|
135
|
+
P as dynamicExperiencesPlugin,
|
|
136
|
+
u as fetchProject
|
|
115
137
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createEffect as n, sample as i } from "effector";
|
|
2
|
-
import { c, l as g, s as S } from "../../../storage-
|
|
2
|
+
import { c, l as g, s as S } from "../../../storage-Co_LbKr_.js";
|
|
3
3
|
import { l as f } from "../../../logger-C9a75KZn.js";
|
|
4
4
|
const y = ({
|
|
5
5
|
storage: a = "local"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createEffect as s, sample as r } from "effector";
|
|
2
|
-
import { c as l, l as y, s as g } from "../../../storage-
|
|
2
|
+
import { c as l, l as y, s as g } from "../../../storage-Co_LbKr_.js";
|
|
3
3
|
const a = l("history", "global"), f = ({
|
|
4
4
|
storage: i = "local"
|
|
5
5
|
} = {}) => ({
|
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
import { createEffect as i, attach as f, sample as
|
|
2
|
-
import { c as u, l as g, s as
|
|
3
|
-
|
|
1
|
+
import { createEffect as i, attach as f, sample as p } from "effector";
|
|
2
|
+
import { c as u, l as g, s as m } from "../../../storage-Co_LbKr_.js";
|
|
3
|
+
import { t as S } from "../../../to-kebab-case-BPnCZjhB.js";
|
|
4
|
+
const c = u("responses", "global"), b = (n, s) => {
|
|
4
5
|
const o = {};
|
|
5
|
-
return Object.entries(
|
|
6
|
-
!s.find((
|
|
6
|
+
return Object.entries(n).forEach(([t, a]) => {
|
|
7
|
+
!s.find((r) => (r.key ?? S(r.name)) === t)?.policies?.doNotStoreValue && (o[t] = a);
|
|
7
8
|
}), o;
|
|
8
|
-
},
|
|
9
|
-
storage:
|
|
9
|
+
}, y = ({
|
|
10
|
+
storage: n = "local"
|
|
10
11
|
} = {}) => ({
|
|
11
12
|
name: "responses-browser-storage-plugin",
|
|
12
13
|
setup: (s) => {
|
|
13
|
-
const o =
|
|
14
|
-
const e = o.get(
|
|
14
|
+
const o = n === "local" ? g : m, t = i(async () => {
|
|
15
|
+
const e = o.get(c).json();
|
|
15
16
|
if (!e)
|
|
16
17
|
return null;
|
|
17
18
|
s.responses.register(e);
|
|
18
|
-
}),
|
|
19
|
+
}), a = f({
|
|
19
20
|
source: {
|
|
20
21
|
responses: s.responses.getAllStore,
|
|
21
22
|
fields: s.fields.listStore
|
|
22
23
|
},
|
|
23
|
-
effect: ({ responses: e, fields:
|
|
24
|
-
const
|
|
25
|
-
o.set(
|
|
24
|
+
effect: ({ responses: e, fields: l }) => {
|
|
25
|
+
const r = b(e, l);
|
|
26
|
+
o.set(c, r);
|
|
26
27
|
}
|
|
27
28
|
});
|
|
28
|
-
|
|
29
|
+
p({
|
|
29
30
|
source: s.eventBus,
|
|
30
31
|
filter: (e) => e.type === "load",
|
|
31
32
|
target: t
|
|
32
|
-
}),
|
|
33
|
+
}), p({
|
|
33
34
|
source: s.responses.getAllStore,
|
|
34
|
-
target:
|
|
35
|
+
target: a
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
38
|
});
|
|
38
39
|
export {
|
|
39
|
-
|
|
40
|
+
y as responsesBrowserStoragePlugin
|
|
40
41
|
};
|
|
@@ -1,91 +1,86 @@
|
|
|
1
1
|
import { createEffect as u, sample as d } from "effector";
|
|
2
2
|
const x = "picked";
|
|
3
|
-
async function p(
|
|
4
|
-
const { storeName:
|
|
5
|
-
return new Promise((a,
|
|
3
|
+
async function p(r) {
|
|
4
|
+
const { storeName: o, version: c = 1, keyPath: n = "id" } = r;
|
|
5
|
+
return new Promise((a, t) => {
|
|
6
6
|
const e = indexedDB.open(x, c);
|
|
7
7
|
e.onupgradeneeded = () => {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
}, e.onsuccess = () => a(e.result), e.onerror = () =>
|
|
8
|
+
const s = e.result;
|
|
9
|
+
s.objectStoreNames.contains(o) || s.createObjectStore(o, n ? { keyPath: n } : void 0);
|
|
10
|
+
}, e.onsuccess = () => a(e.result), e.onerror = () => t(new Error(e.error?.message));
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
-
async function g(
|
|
13
|
+
async function g(r, o) {
|
|
14
14
|
return new Promise((c, n) => {
|
|
15
|
-
const e =
|
|
15
|
+
const e = r.transaction(o, "readonly").objectStore(o).getAll();
|
|
16
16
|
e.onsuccess = () => c(e.result), e.onerror = () => n(new Error(e.error?.message));
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
async function y(
|
|
19
|
+
async function y(r, o, c) {
|
|
20
20
|
return new Promise((n, a) => {
|
|
21
|
-
const
|
|
22
|
-
|
|
21
|
+
const s = r.transaction(o, "readwrite").objectStore(o).put(c);
|
|
22
|
+
s.onsuccess = () => n(), s.onerror = () => a(new Error(s.error?.message));
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
-
async function
|
|
25
|
+
async function b(r, o, c) {
|
|
26
26
|
return new Promise((n, a) => {
|
|
27
|
-
const
|
|
28
|
-
|
|
27
|
+
const s = r.transaction(o, "readwrite").objectStore(o).delete(c);
|
|
28
|
+
s.onsuccess = () => n(), s.onerror = () => a(new Error(s.error?.message));
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
async function
|
|
31
|
+
async function S(r, o) {
|
|
32
32
|
return new Promise((c, n) => {
|
|
33
|
-
const e =
|
|
33
|
+
const e = r.transaction(o, "readwrite").objectStore(o).clear();
|
|
34
34
|
e.onsuccess = () => c(), e.onerror = () => n(new Error(e.error?.message));
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
const l = "responses",
|
|
37
|
+
const l = "responses", m = { storeName: l, keyPath: "fieldId" }, I = () => ({
|
|
38
38
|
name: "responses-indexdb-plugin",
|
|
39
|
-
setup: (
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
(i, { fieldId:
|
|
39
|
+
setup: (r) => {
|
|
40
|
+
const o = u(async () => {
|
|
41
|
+
const t = await p(m), s = (await g(t, l)).reduce(
|
|
42
|
+
(i, { fieldId: w, value: f }) => (i[w] = f, i),
|
|
43
43
|
{}
|
|
44
44
|
);
|
|
45
|
-
await
|
|
45
|
+
await r.responses.commit(s);
|
|
46
46
|
}), c = u(
|
|
47
|
-
async (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
);
|
|
56
|
-
})
|
|
57
|
-
);
|
|
47
|
+
async (t) => {
|
|
48
|
+
t.forEach((e) => {
|
|
49
|
+
p(m).then((s) => {
|
|
50
|
+
y(s, l, e);
|
|
51
|
+
}).catch((s) => {
|
|
52
|
+
console.error("Failed to store response in IndexedDB:", s);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
58
55
|
}
|
|
59
56
|
), n = u(async () => {
|
|
60
|
-
const
|
|
61
|
-
await
|
|
62
|
-
}), a = u(async (
|
|
63
|
-
const e = await p(
|
|
64
|
-
await
|
|
57
|
+
const t = await p(m);
|
|
58
|
+
await S(t, l);
|
|
59
|
+
}), a = u(async (t) => {
|
|
60
|
+
const e = await p(m);
|
|
61
|
+
await b(e, l, t);
|
|
65
62
|
});
|
|
66
63
|
d({
|
|
67
|
-
source:
|
|
68
|
-
filter: (
|
|
69
|
-
target:
|
|
64
|
+
source: r.eventBus,
|
|
65
|
+
filter: (t) => t.type === "load",
|
|
66
|
+
target: o
|
|
70
67
|
}), d({
|
|
71
|
-
clock:
|
|
72
|
-
source: { responses:
|
|
73
|
-
fn: ({ responses:
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
);
|
|
77
|
-
return r.filter((i) => o.has(i.fieldId));
|
|
68
|
+
clock: r.responses.listStore,
|
|
69
|
+
source: { responses: r.responses.listStore, fields: r.fields.listStore },
|
|
70
|
+
fn: ({ responses: t, fields: e }) => {
|
|
71
|
+
const s = e.filter((i) => !i.policies?.doNotStoreValue);
|
|
72
|
+
return t.filter((i) => s.some((w) => w.key === i.fieldId));
|
|
78
73
|
},
|
|
79
74
|
target: c
|
|
80
75
|
}), d({
|
|
81
|
-
clock:
|
|
76
|
+
clock: r.responses.clearAll,
|
|
82
77
|
target: n
|
|
83
78
|
}), d({
|
|
84
|
-
clock:
|
|
79
|
+
clock: r.responses.clear,
|
|
85
80
|
target: a
|
|
86
81
|
});
|
|
87
82
|
}
|
|
88
83
|
});
|
|
89
84
|
export {
|
|
90
|
-
|
|
85
|
+
I as responsesIndexedDBPlugin
|
|
91
86
|
};
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { p as
|
|
3
|
-
const
|
|
4
|
-
let
|
|
5
|
-
const
|
|
1
|
+
import { a as f, G as c, f as m } from "../../../supports-8YT4QKI7.js";
|
|
2
|
+
import { p as a } from "../../../object-JwZ58NOH.js";
|
|
3
|
+
const o = c;
|
|
4
|
+
let s;
|
|
5
|
+
const d = (r) => ({
|
|
6
6
|
name: "single-page-app",
|
|
7
|
-
setup: (
|
|
8
|
-
|
|
7
|
+
setup: (n) => {
|
|
8
|
+
r.instrumentHistory && f() && h(() => {
|
|
9
9
|
requestAnimationFrame(() => {
|
|
10
|
-
|
|
10
|
+
n.start();
|
|
11
11
|
});
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
|
-
function
|
|
16
|
-
if (
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
}), !
|
|
15
|
+
function h(r) {
|
|
16
|
+
if (o.addEventListener("popstate", () => {
|
|
17
|
+
const e = o.location.href, t = s;
|
|
18
|
+
s = e, t !== e && r();
|
|
19
|
+
}), !m())
|
|
20
20
|
return;
|
|
21
|
-
function e
|
|
22
|
-
return function(...
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
return
|
|
28
|
-
|
|
21
|
+
function n(e) {
|
|
22
|
+
return function(...t) {
|
|
23
|
+
const i = t.length > 2 ? t[2] : void 0;
|
|
24
|
+
if (i) {
|
|
25
|
+
const u = s, p = String(i);
|
|
26
|
+
if (s = p, u === p)
|
|
27
|
+
return e.apply(this, t);
|
|
28
|
+
r();
|
|
29
29
|
}
|
|
30
|
-
return
|
|
30
|
+
return e.apply(this, t);
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
a(o.history, "pushState", n), a(o.history, "replaceState", n);
|
|
34
34
|
}
|
|
35
35
|
export {
|
|
36
|
-
|
|
36
|
+
d as singlePageAppPlugin
|
|
37
37
|
};
|
package/dist/esm/server/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createEvent as i, createStore as v, createEffect as C, sample as n, attach as S } from "effector";
|
|
2
|
-
import { h as F } from "../../experience-instance-
|
|
2
|
+
import { h as F } from "../../experience-instance-fvSEb72i.js";
|
|
3
3
|
function R() {
|
|
4
4
|
let c, p;
|
|
5
5
|
return {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const s=require("effector"),W=require("@withease/factories"),j=require("./supports-YvpQZxbh.cjs"),N=require("./logger-BsmHUUw1.cjs"),xe=require("./object-BbFTsGh3.cjs");function Ne(e){return typeof e=="number"&&!isNaN(e)}function R(e){return typeof e=="string"}function x(e){return Array.isArray(e)}function ue(e){return e instanceof Promise}function ie(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1}function m(e){if(Ne(e))return e;const t=parseFloat(`${e}`);return isNaN(t)?0:t}function M(e){return`${e}`}const Ie={"==":(e,t)=>e==t,"===":(e,t)=>e===t,"!=":(e,t)=>e!=t,"!==":(e,t)=>e!==t,">":(e,t)=>m(e)>m(t),">=":(e,t)=>m(e)>=m(t),"<":(e,t,r)=>{const n=m(e),c=m(t);if(r===void 0)return n<c;const a=m(r);return n<c&&c<a},"<=":(e,t,r)=>{const n=m(e),c=m(t);if(r===void 0)return n<=c;const a=m(r);return n<=c&&c<=a},"!!":async e=>await v(e),"!":async e=>!await v(e),"%":(e,t)=>m(e)%m(t),log:e=>(console.log(e),e),in:(e,t)=>t?R(t)?t.indexOf(M(e))!==-1:x(t)?t.includes(e):!1:!1,cat:(...e)=>e.map(M).join(""),substr:(e,t,r)=>{const n=M(e),c=m(t);if(r===void 0)return n.substr(c);const a=m(r);if(a<0){const o=n.substr(c);return o.substr(0,o.length+a)}return n.substr(c,a)},"+":(...e)=>e.reduce((t,r)=>m(t)+m(r),0),"*":(...e)=>e.reduce((t,r)=>m(t)*m(r),1),"-":(e,t)=>{const r=m(e);return t===void 0?-r:r-m(t)},"/":(e,t)=>m(e)/m(t),min:(...e)=>Math.min(...e.map(m)),max:(...e)=>Math.max(...e.map(m)),merge:(...e)=>e.reduce((t,r)=>x(r)?t.concat(r):t.concat([r]),[]),var(e,t){const r=arguments.length>1?t:null;if(e===""||e==="."||e===null||e===void 0)return this;if(typeof e=="number"&&Array.isArray(this))return e>=0&&e<this.length?this[e]:r;const n=M(e);if(n===""||n===".")return this;const c=n.split(".");let a=this;for(const o of c){if(a==null)return r;if(Array.isArray(a)){const f=parseInt(o,10);isNaN(f)?a=a[o]:a=a[f]}else a=a[o]}return a!==void 0?a:r},async missing(...e){const t=x(e[0])?e[0]:e,r=[];for(const n of t){const c=await g({var:n},this);(c===null||c==="")&&r.push(`${n}`)}return r},async missing_some(e,t){const r=await g({missing:t},this);if(!x(r)||!x(t))return[];const n=r.filter(R);return t.filter(R).length-n.length>=m(e)?[]:n},invoke(...e){const[t,...r]=e;return typeof t!="function"?null:Reflect.apply(t,null,r)},regexp_matches(e,t){let r=e,n="";if(x(e)){const[a,o]=e;r=a,n=o}return!R(r)||!R(n)?!1:new RegExp(r,n).test(M(t))},throw(e){throw new Error(M(e))}};async function g(e,t){if(!e)return e;if(ue(e))return g(await e,t);if(x(e))return Promise.all(e.map(o=>g(o,t)));if(!ie(e))return e;const r=ke(e);let n=r?e[r]??[]:[];switch(x(n)||(n=[n]),r){case"if":case"?:":for(let o=0;o<n.length-1;o+=2)if(await v(await g(n[o],t)))return g(n[o+1],t);return n.length%2===1?g(n[n.length-1],t):null;case"and":{let o=null;for(const f of n)if(o=await g(f,t),!await v(o))return o;return o}case"or":{let o=null;for(const f of n)if(o=await g(f,t),await v(o))return o;return o}case"map":{const o=await g(n[0],t);return x(o)?await Promise.all(o.map(f=>g(n[1],f))):[]}case"filter":{const o=await g(n[0],t);return x(o)?(await Promise.all(o.map(async p=>{const h=await v(await g(n[1],p));return{item:p,shouldInclude:h}}))).filter(({shouldInclude:p})=>p).map(({item:p})=>p):[]}case"reduce":{const o=await g(n[0],t);if(!x(o))return n.length>2?await g(n[2],t):null;const f=n[1];let h=n.length>2?await g(n[2],t):null;for(const k of o)h=await g(f,{current:k,accumulator:h});return h}case"all":{const o=await g(n[0],t);if(!x(o)||o.length===0)return!1;for(const f of o)if(!await v(await g(n[1],f)))return!1;return!0}case"some":{const o=await g(n[0],t);if(!x(o))return!1;for(const f of o)if(await v(await g(n[1],f)))return!0;return!1}case"none":{const o=await g(n[0],t);if(!x(o))return!0;for(const f of o)if(await v(await g(n[1],f)))return!1;return!0}case"catch":try{return await g(n[0],t)}catch(o){return ie(o)?await g(o,t):n[1]?await g(n[1],o):o instanceof Error?o.message:o}}const c=await Promise.all(n.map(o=>g(o,t))),a=r?Ie[r]:void 0;if(!a)throw new Error(`Unrecognized operation ${r}`);return a.apply(t,c)}async function v(e){return ue(e)?v(await e):!(Array.isArray(e)&&e.length===0)&&!!e}function ke(e){return Object.keys(e)[0]}function fe(e){return!xe.isEmpty(e)}async function Y(e,t,r){const n=e.getStateSnapshot(),c=e.predicates.listStore.getState().reduce((f,p)=>({...f,[p.name]:(...h)=>p.predicate({...n,args:h})}),{}),a=e.features.listStore.getState().reduce((f,p)=>({...f,[p.id]:async()=>{const{bucket:h}=await p.getBucket();return h}}),{}),o={...r,responses:e.responses.getAllStore.getState(),location:typeof n.location=="object"?{hash:n.location.hash,host:n.location.host,hostname:n.location.hostname,href:n.location.href,origin:n.location.origin,pathname:n.location.pathname,port:n.location.port,protocol:n.location.protocol,search:n.location.search}:void 0,predicates:c,features:a};return await g(t,o)}function ve(e){return!j.supportsWindow()||!j.supportsDocument()?[]:Array.from(window.document.querySelectorAll(e)).filter(t=>t instanceof HTMLElement)}const be="open";function Ae(e){if(!j.supportsShadowRoot())throw new Error("Shadow DOM is not supported in this environment");return e.attachShadow({mode:be})}function Oe(){return new Promise((e,t)=>{if(!j.supportsDocument()){t();return}document.readyState!=="loading"?e():document.addEventListener("readystatechange",()=>e(),{once:!0})})}function Fe(e,t){const r=new MutationObserver(n=>{document.contains(e)||(r.disconnect(),t())});r.observe(document.body,{childList:!0,subtree:!0})}const q="picked-root",U="picked-target",Be="picked-root";function _e(e,t){return[...e,{selector:`${Be}[experience-id="${t}"]`,placement:"replace"}].flatMap(n=>{const c=ve(n.selector).filter(a=>!Me(a,t)&&!le(a,t));return{...n,elements:c}})}function $e(e,t){return e.flatMap(r=>r.elements.map(n=>De(n,r.placement,t)))}function Te(e,t){e.classList.add(U),e.classList.add(`${U}-${t}`)}function Me(e,t){return t?e.classList.contains(`${U}-${t}`):e.classList.contains(`${U}`)}function le(e,t){return t?e.classList.contains(`${q}-${t}`):e.classList.contains(q)}function Le(e){const t=document.createElement("div");return t.style.display="block",t.classList.add(q),t.classList.add(`${q}-${e}`),t}function De(e,t,r){let n;const c=Le(r);if(e instanceof Document)n=e.body.appendChild(c);else{switch(t){case"replace":e.replaceWith(c);break;case"before":e.before(c);break;case"after":e.after(c);break;case"prepend":e.prepend(c);break;default:e.append(c);break}n=c}return n}function se(e){return e.type==="conditional"}function B(e){return e.type==="step"}function ce(e){return e.type==="experience"}function J(e){return e.type==="origin"}function ae(e){return e.type==="action"}const de=(e,t,r,n,c=new Set)=>c.has(r.id)?[]:(c.add(r.id),B(r)&&!n?[r]:t.filter(o=>o.sourceNodeId===r.id).flatMap(o=>{const f=e.find(p=>p.id===o.destinationNodeId);return f?de(e,t,f,!1,c):[]})),Re=(e,t,r)=>de(e,t,r,!0,new Set),pe=(e,t,r,n,c=new Set)=>{if(c.has(r.id))return[-1,-1];c.add(r.id);const a=t.filter(p=>p.sourceNodeId===r.id);if(a.length===0)return[0,0];let o=1/0,f=-1/0;for(const p of a){const h=e.find(_=>_.id===p.destinationNodeId);if(!h)continue;const[k,A]=pe(e,t,h,!1,new Set(c));k!==-1&&(o=Math.min(o,k+1),f=Math.max(f,A+1))}return o===1/0?[-1,-1]:[o,f]},Pe=(e,t,r)=>pe(e,t,r,!0,new Set),ge=(e,t,r,n=new Set)=>{if(n.has(r.id))return[-1,-1];if(n.add(r.id),r.type==="origin")return[0,0];const c=t.filter(f=>f.destinationNodeId===r.id);if(c.length===0)return[-1,-1];let a=1/0,o=-1/0;for(const f of c){const p=e.find(A=>A.id===f.sourceNodeId);if(!p)continue;const[h,k]=ge(e,t,p,new Set(n));h!==-1&&(a=Math.min(a,h+1),o=Math.max(o,k+1))}return a===1/0?[-1,-1]:[a,o]},He=(e,t,r)=>ge(e,t,r,new Set),me=e=>e.find(r=>r.type==="origin")||null,Q=(e,t,r)=>{if(!e)return me(t);const n=r.find(a=>a.sourceNodeId===e.id);if(!n)return null;const c=t.find(a=>a.id===n.destinationNodeId);return c||null};async function Ce(e,t,r,n){const c=e?"true":"false",a=n.find(o=>o.sourceNodeHandle===c&&o.sourceNodeId===t);return r.find(o=>o.id===a?.destinationNodeId)}const Z=s.createDomain("experience-instance"),je=W.createFactory(({client:e,experience:t,target:r,options:n})=>{const c=s.createEvent(),a=s.createEvent(),o=s.createEvent(),f=s.createEvent(),p=s.createEvent(),h=s.createEvent(),k=t.componentStore,A=Z.store("transitioning"),_=e.history.entriesStore.map(i=>i.filter(d=>d.experienceId===t.id)),P=_.map(i=>i.filter(d=>B(d.node))),u=_.map(i=>i.at(-1)?.node||null),S=s.combine(t.treeStore,u,({steps:i},d)=>i.find(l=>d&&B(d)&&l.id===d.stepId)||null),E=s.combine(t.treeStore,P,({steps:i},d)=>{const l=d.at(-2);if(!l||!B(l.node))return null;const y=l.node;return i.find(O=>O.id===y.stepId)||null}),$=s.combine(t.treeStore,u,({nodes:i,edges:d},l)=>l?Re(i,d,l):[]),L=s.combine(t.treeStore,u,({nodes:i,edges:d},l)=>l?He(i,d,l):[-1,-1]),G=s.combine(t.treeStore,u,({nodes:i,edges:d},l)=>l?Pe(i,d,l):[-1,-1]),T=Z.store(!1),H=s.createApi(T,{open:()=>!0,close:()=>!1,toggle:i=>!i,set:(i,d)=>d}),he=s.createEffect(async()=>{e.history.back({experienceId:t.id})}),ye=s.attach({source:t.treeStore,effect:async(i,d)=>{const l=i.nodes.find(y=>B(y)&&y.stepId===d);l&&e.history.push({experienceId:t.id,node:l})}}),ee=s.attach({source:u,effect:i=>{}}),K=s.attach({source:t.treeStore,effect:async({nodes:i})=>me(i)}),V=s.attach({source:t.treeStore,effect:async({nodes:i,edges:d},l)=>{if(J(l))return Q(l,i,d)}}),z=s.attach({source:t.treeStore,effect:async({nodes:i,edges:d,conditionals:l},y)=>{if(!se(y))return;const O=l.find(b=>b.id===y.conditionalId);if(!O)return;const I=y.id,w=await Y(e,O.condition);return Ce(!!w,I,i,d)}}),te=s.attach({source:t.treeStore,effect:async({nodes:i,edges:d},l)=>{if(!ae(l))return;const y=l.action;if(!y){N.logger("warn",`Action node ${l.id} has no action name`);return}const O=e.actions.getByName(y).getState();if(!O){N.logger("warn",`Action '${y}' not registered on client`);const I=d.find(w=>w.sourceNodeId===l.id&&w.sourceNodeHandle==="false");return I?i.find(w=>w.id===I.destinationNodeId):null}if(typeof O.action!="function"){N.logger("warn",`Action '${y}' is not a function`);const I=d.find(w=>w.sourceNodeId===l.id&&w.sourceNodeHandle==="false");return I?i.find(w=>w.id===I.destinationNodeId):null}try{N.logger("info",`Executing action: ${y}`),await O.action(y);const I=d.find(b=>b.sourceNodeId===l.id&&b.sourceNodeHandle==="true");if(!I)return N.logger("warn",`No 'true' edge found for action node ${l.id}`),null;const w=i.find(b=>b.id===I.destinationNodeId);return N.logger("info",`Action '${y}' succeeded, moving to node ${w?.id}`),w||null}catch(I){N.logger("warn",`Action '${y}' failed:`,I);const w=d.find(C=>C.sourceNodeId===l.id&&C.sourceNodeHandle==="false");if(!w)return N.logger("warn",`No 'false' edge found for action node ${l.id}`),null;const b=i.find(C=>C.id===w.destinationNodeId);return N.logger("info",`Action '${y}' failed, moving to node ${b?.id}`),b||null}}}),we=s.createEffect(i=>{ce(i)&&e.experiences.launch({id:i.experienceId})}),ne=s.attach({source:[u,t.treeStore],effect:async([i,{nodes:d,edges:l}])=>Q(i,d,l)}),D=s.attach({source:[u,t.treeStore],effect:async([i,{nodes:d,edges:l}])=>Q(i,d,l)}),Ee=s.createEffect(i=>{e.history.push({experienceId:t.id,node:i})}),re=s.attach({source:t.configStore,effect:async({initializeOpenLogic:i})=>n?.initialiseOpen!==void 0?n.initialiseOpen:fe(i)?!!await Y(e,i):i??!1}),F=Object.freeze({id:Math.random().toString(36).substring(7),experienceId:t.id,configStore:t.configStore,target:r,componentStore:k,stateStore:A,isOpenStore:T,open:H.open,close:H.close,toggleOpen:H.toggle,setOpen:H.set,treeStore:t.treeStore,fieldsStore:t.fieldsStore,currentNodeStore:u,currentStepStore:S,previousStepStore:E,nextReachableStepNodesStore:$,stepsToOriginStore:L,stepsToLeafStore:G,goToNextStep:a,goToPreviousStep:o,goToStepById:f,stepsHistoryStore:P}),X=s.createEvent(),oe=s.createEvent();return s.sample({source:u,target:X}),s.sample({clock:X,filter:i=>i===null,target:K}),s.sample({clock:X,filter:i=>i!==null,target:oe}),s.split({source:oe,match:i=>se(i)?"condition":B(i)?"step":ce(i)?"launchExperience":J(i)?"origin":ae(i)?"action":"other",cases:{origin:V,condition:z,step:ee,launchExperience:we,action:te,__:s.createEvent()}}),s.sample({clock:[z.doneData,V.doneData,K.doneData,D.doneData,ne.doneData,te.doneData],filter:Boolean,target:Ee}),s.sample({clock:a,target:D}),s.sample({clock:a,source:S,filter:Boolean,target:e.eventBus.prepend(i=>({type:"step_submit",step:i,experience:F}))}),s.sample({clock:D.done,source:S,filter:Boolean,target:e.eventBus.prepend(i=>({type:"step_submit_success",step:i,experience:F}))}),s.sample({clock:D.fail,source:S,filter:Boolean,target:e.eventBus.prepend(i=>({type:"step_submit_error",step:i,experience:F}))}),s.sample({clock:o,target:he}),s.sample({clock:f,target:ye}),s.sample({source:s.combine([z.pending,V.pending,K.pending,D.pending]),fn:i=>i.some(Boolean)?"transitioning":"ready",target:A}),s.sample({clock:ee.doneData,source:S,filter:Boolean,target:e.eventBus.prepend(i=>({type:"step_enter",step:i,experience:F}))}),s.sample({clock:h,target:re}),s.sample({source:re.doneData,fn:Boolean,target:T}),s.sample({source:u,clock:c,filter:i=>i?J(i):!0,target:ne}),s.sample({source:T,filter:Boolean,target:c}),s.sample({source:T,filter:Boolean,target:e.eventBus.prepend(()=>({type:"experience_open",experience:F}))}),s.sample({source:T,filter:i=>!i,target:e.eventBus.prepend(()=>({type:"experience_close",experience:F}))}),s.sample({clock:p,target:[h]}),p(),F});function Se(e){return W.invoke(je,e)}const qe=W.createFactory(({client:e})=>{const t=Z.store({}),r=s.createEvent(),n=s.createEvent(),c=s.createEvent(),a=s.createApi(t,{register(u,S){const E=[...u[S.experienceId]??[]];return E.push(S),{...u,[S.experienceId]:E}},unregister(u,S){const E=S.experienceId,$=u[E]?.filter(L=>L!==S);return{...u,[E]:$??[]}}}),o=s.createEffect(({experience:u,target:S,options:E})=>Se({client:e,experience:u,target:S,options:E})),f=s.createEffect(u=>{a.register(u)}),p=s.createEffect(u=>{u.target&&Fe(u.target,()=>{c(u)})}),h=s.createEffect(u=>{a.unregister(u)}),k=s.createEffect(u=>{const S=u.componentStore.getState();if(!S){N.logger("warn","No app component registered. Skipping init.");return}const E=S.frameworkStore.getState();if(!E){N.logger("error",`No framework registered for component '${S.name}'. Skipping rendering.`);return}const $=u.target;if(!$){N.logger("error",`No target element registered for experience '${u.experienceId}'. Skipping rendering.`);return}const L=Ae($);try{E.render(L,S.component,e,u)}catch(G){N.logger("error",G)}});s.sample({clock:r,target:o}),s.sample({clock:c,target:h}),s.sample({clock:o.doneData,target:[f,p,n]}),s.sample({clock:o.doneData,target:e.eventBus.prepend(u=>({type:"experience_initialize",experience:u}))}),s.sample({clock:n,target:k});function A(u,S,E){r({experience:u,target:S,options:E})}const _=t.map(u=>Object.values(u).flat());function P(u){return t.map(S=>S[u]||[],{skipVoid:!1})}return{spawn:A,getByExperienceId:P,listStore:_}});function Ue(e){return W.invoke(qe,e)}exports.createAppHosts=$e;exports.createExperienceInstance=Se;exports.createExperienceInstanceIndex=Ue;exports.domInteractive=Oe;exports.evaluateRuleLogic=Y;exports.getTargetElements=_e;exports.isPickedRoot=le;exports.isRulesLogic=fe;exports.isStepNode=B;exports.tagTargetElement=Te;
|