@picked/client 0.0.1-dev.1777938796953 → 0.0.1-dev.1778136207545

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.
Files changed (102) hide show
  1. package/README.md +0 -8
  2. package/dist/{api-Bn4z854o.js → api-Crj5wFbR.js} +1 -1
  3. package/dist/{api-GE6C0lxp.cjs → api-NcKXNrkY.cjs} +1 -1
  4. package/dist/cjs/form/index.js +1 -1
  5. package/dist/cjs/index.js +4 -4
  6. package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
  7. package/dist/cjs/plugins/experience-browser-storage/index.js +1 -1
  8. package/dist/cjs/plugins/history-browser-storage/index.js +1 -1
  9. package/dist/cjs/plugins/single-page-app/index.js +1 -1
  10. package/dist/cjs/plugins/web-components/index.js +1 -1
  11. package/dist/cjs/server/index.js +1 -1
  12. package/dist/docs/actions.mdx +0 -1
  13. package/dist/docs/index.md +0 -2
  14. package/dist/docs/pickedql/dimensions.md +2 -0
  15. package/dist/docs/pickedql/virtual-functions.md +27 -0
  16. package/dist/docs/sdk/actions.md +0 -1
  17. package/dist/docs/sdk/features.md +0 -1
  18. package/dist/docs/sdk/index.md +0 -1
  19. package/dist/docs/sdk/plugins/create-experience.md +0 -1
  20. package/dist/docs/sdk/plugins/dynamic-experiences.md +0 -1
  21. package/dist/docs/sdk/plugins/window-object.md +0 -1
  22. package/dist/docs/sdk/predicates.md +0 -1
  23. package/dist/esm/form/index.js +1 -1
  24. package/dist/esm/index.js +1011 -533
  25. package/dist/esm/plugins/dynamic-experiences/index.js +127 -60
  26. package/dist/esm/plugins/experience-browser-storage/index.js +8 -5
  27. package/dist/esm/plugins/history-browser-storage/index.js +3 -3
  28. package/dist/esm/plugins/single-page-app/index.js +1 -1
  29. package/dist/esm/plugins/web-components/index.js +1 -1
  30. package/dist/esm/server/index.js +23 -13
  31. package/dist/{experience-instance-CWYRLfFM.js → experience-instance-BrLWgVAN.js} +135 -127
  32. package/dist/experience-instance-Ct3ogC7n.cjs +1 -0
  33. package/dist/rules-logic-D_CVBuv7.js +13 -0
  34. package/dist/rules-logic-H6P8xwHF.cjs +1 -0
  35. package/dist/types/client.d.ts +2 -2
  36. package/dist/types/entities/action/action.d.ts +6 -3
  37. package/dist/types/entities/action/action.d.ts.map +1 -1
  38. package/dist/types/entities/component/component.d.ts +39 -2
  39. package/dist/types/entities/component/component.d.ts.map +1 -1
  40. package/dist/types/entities/content/content.d.ts +37 -0
  41. package/dist/types/entities/content/content.d.ts.map +1 -0
  42. package/dist/types/entities/experience/experience.d.ts +69 -112
  43. package/dist/types/entities/experience/experience.d.ts.map +1 -1
  44. package/dist/types/entities/experience-instance/experience-instance.d.ts +17 -2
  45. package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
  46. package/dist/types/entities/feature/feature.d.ts +26 -2
  47. package/dist/types/entities/feature/feature.d.ts.map +1 -1
  48. package/dist/types/entities/field/field.d.ts.map +1 -1
  49. package/dist/types/entities/framework/framework.d.ts +24 -3
  50. package/dist/types/entities/framework/framework.d.ts.map +1 -1
  51. package/dist/types/entities/history/history.d.ts +15 -27
  52. package/dist/types/entities/history/history.d.ts.map +1 -1
  53. package/dist/types/entities/plugin/plugin.d.ts +32 -1
  54. package/dist/types/entities/plugin/plugin.d.ts.map +1 -1
  55. package/dist/types/entities/predicate/predicate.d.ts +24 -3
  56. package/dist/types/entities/predicate/predicate.d.ts.map +1 -1
  57. package/dist/types/entities/session/session.d.ts +45 -0
  58. package/dist/types/entities/session/session.d.ts.map +1 -0
  59. package/dist/types/entities/step/step.d.ts +14 -0
  60. package/dist/types/entities/step/step.d.ts.map +1 -1
  61. package/dist/types/exports.d.ts +9 -3
  62. package/dist/types/exports.d.ts.map +1 -1
  63. package/dist/types/index.d.ts +3 -1
  64. package/dist/types/index.d.ts.map +1 -1
  65. package/dist/types/lifecycle/lifecycle.d.ts +47 -0
  66. package/dist/types/lifecycle/lifecycle.d.ts.map +1 -0
  67. package/dist/types/lifecycle/rules-logic.d.ts +24 -0
  68. package/dist/types/lifecycle/rules-logic.d.ts.map +1 -0
  69. package/dist/types/lifecycle/state-snapshot.d.ts +37 -0
  70. package/dist/types/lifecycle/state-snapshot.d.ts.map +1 -0
  71. package/dist/types/logic-engine.d.ts +1 -1
  72. package/dist/types/logic-engine.d.ts.map +1 -1
  73. package/dist/types/picked.d.ts +149 -190
  74. package/dist/types/picked.d.ts.map +1 -1
  75. package/dist/types/plugins/dynamic-experiences/index.d.ts +2 -1
  76. package/dist/types/plugins/dynamic-experiences/index.d.ts.map +1 -1
  77. package/dist/types/plugins/dynamic-experiences/plugin.d.ts +18 -1
  78. package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
  79. package/dist/types/plugins/dynamic-experiences/types.d.ts +62 -1
  80. package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
  81. package/dist/types/plugins/experience-browser-storage/plugin.d.ts.map +1 -1
  82. package/dist/types/plugins/history-browser-storage/plugin.d.ts +0 -14
  83. package/dist/types/plugins/history-browser-storage/plugin.d.ts.map +1 -1
  84. package/dist/types/plugins/web-components/plugin.d.ts.map +1 -1
  85. package/dist/types/server/index.d.ts +7 -0
  86. package/dist/types/server/index.d.ts.map +1 -1
  87. package/dist/types/utils/events.d.ts +1 -1
  88. package/dist/types/utils/events.d.ts.map +1 -1
  89. package/dist/types/utils/picked-config.d.ts +12 -4
  90. package/dist/types/utils/picked-config.d.ts.map +1 -1
  91. package/dist/types/utils/rules-logic.d.ts +4 -9
  92. package/dist/types/utils/rules-logic.d.ts.map +1 -1
  93. package/package.json +2 -2
  94. package/dist/experience-instance-BDTNGT8a.cjs +0 -1
  95. package/dist/rules-logic-BTIxfrJJ.js +0 -240
  96. package/dist/rules-logic-DNLOv90w.cjs +0 -1
  97. package/dist/types/utils/state-snaphot.d.ts +0 -26
  98. package/dist/types/utils/state-snaphot.d.ts.map +0 -1
  99. package/dist/types/utils/user-session.d.ts +0 -12
  100. package/dist/types/utils/user-session.d.ts.map +0 -1
  101. /package/dist/{object-C82v79xc.js → object-DvUDOytC.js} +0 -0
  102. /package/dist/{object-CUJOjanb.cjs → object-ThO1DEyl.cjs} +0 -0
@@ -1,26 +1,27 @@
1
1
  import "../../../logger-6z_gb4rA.js";
2
- import { i as e, t } from "../../../api-Bn4z854o.js";
2
+ import { i as e, t } from "../../../api-Crj5wFbR.js";
3
+ import { attach as n } from "effector";
3
4
  //#region src/plugins/dynamic-experiences/hash.ts
4
- function n(e) {
5
+ function r(e) {
5
6
  let t = 2166136261;
6
7
  for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, 16777619);
7
8
  return t >>> 0;
8
9
  }
9
- function r(e) {
10
- return n(e) % 100;
10
+ function i(e) {
11
+ return r(e) % 100;
11
12
  }
12
- function i(e, t) {
13
+ function a(e, t) {
13
14
  return t <= 0 ? !1 : t >= 100 ? !0 : e < t;
14
15
  }
15
16
  //#endregion
16
17
  //#region src/plugins/dynamic-experiences/plugin.ts
17
- function a(e) {
18
+ function o(e) {
18
19
  return typeof e == "object" && !!e && "features" in e && Array.isArray(e.features);
19
20
  }
20
- function o(e, t) {
21
+ function s(e, t) {
21
22
  if (Array.isArray(t.conditions)) for (let n of t.conditions) e.registerCondition(n);
22
23
  }
23
- function s(e, t) {
24
+ function c(e, t) {
24
25
  e.registerExperience({
25
26
  id: t.id,
26
27
  key: t.key,
@@ -33,10 +34,10 @@ function s(e, t) {
33
34
  componentName: t.componentName
34
35
  });
35
36
  }
36
- function c(e, t) {
37
+ function l(e, t) {
37
38
  if (Array.isArray(t.fields)) for (let n of t.fields) e.registerField(n);
38
39
  }
39
- function l(e, t) {
40
+ function u(e, t) {
40
41
  if (!Array.isArray(t.steps)) return;
41
42
  let n = new Map(t.fields.map((e) => [e.id, e.key]));
42
43
  for (let r of t.steps) {
@@ -49,23 +50,28 @@ function l(e, t) {
49
50
  }
50
51
  t.push(i);
51
52
  }
53
+ let i = r.layoutContentId ? e.contents.getById(r.layoutContentId) : null;
52
54
  e.registerStep({
53
55
  id: r.id,
54
56
  key: r.key,
55
57
  name: r.name,
56
58
  fieldKeys: t,
57
- layoutName: r.layoutName
59
+ layoutName: r.layoutName,
60
+ ...r.layoutContentId !== void 0 && {
61
+ layoutContentId: r.layoutContentId,
62
+ layoutContentStore: i
63
+ }
58
64
  });
59
65
  }
60
66
  }
61
- function u(e, t) {
62
- if (Array.isArray(t.experiences)) for (let n of t.experiences) s(e, n);
67
+ function d(e, t) {
68
+ if (Array.isArray(t.experiences)) for (let n of t.experiences) c(e, n);
63
69
  }
64
- function d(e) {
70
+ function f(e) {
65
71
  let t = e.searchParams["preview-token"];
66
72
  if (t && t.length > 0) return t[0];
67
73
  }
68
- function f(e) {
74
+ function p(e) {
69
75
  let t = /* @__PURE__ */ new Set(), n = e.searchParams.feature;
70
76
  if (!n) return t;
71
77
  for (let e of n) {
@@ -74,37 +80,18 @@ function f(e) {
74
80
  }
75
81
  return t;
76
82
  }
77
- function p(e, t, n) {
78
- let i = f(e), a = e.session?.id;
79
- if (!a) throw Error("Session ID is required for feature registration");
80
- let o = r(a);
81
- for (let r of t.features) i.has(r.id) || m(e, r, n, o);
82
- }
83
83
  function m(e, t, n, r) {
84
+ let a = p(e), o = i(r);
85
+ for (let r of t.features) a.has(r.id) || h(e, r, n, o);
86
+ }
87
+ function h(e, t, n, r) {
84
88
  e.registerFeature(t.id, {
85
89
  key: `v${t.version}`,
86
90
  name: t.name,
87
91
  storage: n ? "session" : "local",
88
- decide: () => t.enabled ? i(r, t.weight) : !1
92
+ decide: () => t.enabled ? a(r, t.weight) : !1
89
93
  });
90
94
  }
91
- function h() {
92
- let e;
93
- try {
94
- e = __PICKED_PROJECT_CONFIG__;
95
- } catch {
96
- return;
97
- }
98
- if (e === void 0) return;
99
- let t;
100
- if (typeof e == "string") try {
101
- t = JSON.parse(e);
102
- } catch {
103
- return;
104
- }
105
- else t = e;
106
- if (a(t)) return t;
107
- }
108
95
  function g(e) {
109
96
  try {
110
97
  let t = new URL(e).hostname;
@@ -119,43 +106,123 @@ function _(e) {
119
106
  return typeof t != "object" || !t || !("code" in t) ? !1 : t.code === "ECONNREFUSED";
120
107
  }
121
108
  async function v(e, n, r) {
122
- let i = r?.previewToken ? `projects/${n}?preview_token=${encodeURIComponent(r.previewToken)}` : `projects/${n}`, o;
109
+ let i = r?.previewToken ? `projects/${n}?preview_token=${encodeURIComponent(r.previewToken)}` : `projects/${n}`, a;
123
110
  try {
124
- o = await t(e, i, r?.headers);
111
+ a = await t(e, i, r?.headers);
125
112
  } catch (t) {
126
113
  return g(e) && _(t), null;
127
114
  }
128
- if (!o.ok) return `${o.status.toString()}`, null;
115
+ if (!a.ok) return `${a.status.toString()}`, null;
129
116
  let s;
130
117
  try {
131
- s = await o.json();
118
+ s = await a.json();
132
119
  } catch {
133
120
  return null;
134
121
  }
135
- return a(s) ? s : null;
122
+ return o(s) ? s : null;
136
123
  }
137
124
  function y(e) {
125
+ return typeof e != "object" || !e || !("experienceId" in e) || !("content" in e) ? !1 : Array.isArray(e.content);
126
+ }
127
+ async function b(e, n, r, i) {
128
+ let a = i?.previewToken ? `projects/${n}/experiences/${r}/content?preview_token=${encodeURIComponent(i.previewToken)}` : `projects/${n}/experiences/${r}/content`, o;
129
+ try {
130
+ o = await t(e, a, i?.headers);
131
+ } catch (t) {
132
+ return g(e) && _(t) || `${r}`, null;
133
+ }
134
+ if (!o.ok) return `${r}${o.status.toString()}`, null;
135
+ let s;
136
+ try {
137
+ s = await o.json();
138
+ } catch {
139
+ return `${r}`, null;
140
+ }
141
+ return y(s) ? s : (`${r}`, null);
142
+ }
143
+ function x(e, t) {
144
+ for (let n of t.content) e.registerContent({
145
+ id: n.id,
146
+ data: n.data
147
+ });
148
+ }
149
+ function S(e) {
150
+ if (typeof e != "object" || !e || !("projectConfig" in e) || !("experienceContent" in e) || !("manifestMetadata" in e)) return !1;
151
+ let { experienceContent: t } = e;
152
+ return typeof t == "function";
153
+ }
154
+ var C = "virtual:picked/data";
155
+ async function w() {
156
+ try {
157
+ let e = await import(
158
+ /* @vite-ignore */
159
+ C
160
+ );
161
+ return S(e) ? e : null;
162
+ } catch {
163
+ return null;
164
+ }
165
+ }
166
+ function T(e, t, n) {
167
+ return (r) => b(e, t, r.id, n ? { previewToken: n } : void 0);
168
+ }
169
+ function E(e, t) {
170
+ return (n) => e(n, t ? { previewToken: t } : void 0);
171
+ }
172
+ function D(e) {
173
+ return (t, n) => e.experienceContent(t, n);
174
+ }
175
+ function O(e, t) {
176
+ return async (n, r) => {
177
+ let i = await t(n, r);
178
+ return i && x(e, i), i;
179
+ };
180
+ }
181
+ async function k(e) {
182
+ let { client: t, apiUrl: n, options: r } = e, i = f(t), a = !!i, o = r?.projectConfig ?? null, s = r?.getContent ? E(r.getContent, i) : null, c = null;
183
+ if (i) return o ||= await v(n, t.projectId, { previewToken: i }), s ||= T(n, t.projectId, i), {
184
+ config: o,
185
+ contentLoader: s,
186
+ dataSource: c,
187
+ isPreview: a
188
+ };
189
+ if (o && s) return {
190
+ config: o,
191
+ contentLoader: s,
192
+ dataSource: c,
193
+ isPreview: a
194
+ };
195
+ let l = await w();
196
+ return l ? (o ??= l.projectConfig, s ??= D(l), c = l.manifestMetadata, {
197
+ config: o,
198
+ contentLoader: s,
199
+ dataSource: c,
200
+ isPreview: a
201
+ }) : (o ||= await v(n, t.projectId), s ||= T(n, t.projectId), {
202
+ config: o,
203
+ contentLoader: s,
204
+ dataSource: c,
205
+ isPreview: a
206
+ });
207
+ }
208
+ function A(e) {
138
209
  return {
139
210
  name: "dynamic-experiences",
140
211
  setup: (t) => {
141
- let n = e?.apiUrl ?? t.apiUrl;
142
- return { onStart: async () => {
143
- let r = d(t);
144
- if (r) {
145
- let e = await v(n, t.projectId, { previewToken: r });
146
- e && (p(t, e, !0), o(t, e), c(t, e), l(t, e), u(t, e));
147
- return;
148
- }
149
- let i = e?.projectConfig ?? h();
150
- if (i) {
151
- p(t, i, !1), o(t, i), c(t, i), l(t, i), u(t, i);
152
- return;
212
+ let r = e?.apiUrl ?? t.apiUrl;
213
+ return { onStart: n({
214
+ source: t.session.store.map((e) => e.id),
215
+ effect: async (n) => {
216
+ let { config: i, contentLoader: a, dataSource: o, isPreview: c } = await k({
217
+ client: t,
218
+ apiUrl: r,
219
+ options: e
220
+ });
221
+ a && (t.contentLoader = O(t, a)), t.dataSource = o, i && (m(t, i, c, n), s(t, i), l(t, i), u(t, i), d(t, i));
153
222
  }
154
- let a = await v(n, t.projectId);
155
- a && (p(t, a, !1), o(t, a), c(t, a), l(t, a), u(t, a));
156
- } };
223
+ }) };
157
224
  }
158
225
  };
159
226
  }
160
227
  //#endregion
161
- export { e as createClientHeaders, y as dynamicExperiencesPlugin, v as fetchProject };
228
+ export { e as createClientHeaders, A as dynamicExperiencesPlugin, b as fetchExperienceContent, v as fetchProject };
@@ -10,7 +10,7 @@ var o = ({ storage: o = "local" } = {}) => ({
10
10
  let c = o === "local" ? t : n, l = i(async (e) => {
11
11
  if (!e) return;
12
12
  let t = r("open-close", "experience", e), n = c.get(t).boolean();
13
- e.setOpen(n ?? e.isOpenStore.getState());
13
+ n !== null && e.setOpen(n);
14
14
  });
15
15
  a({
16
16
  source: s.eventBus,
@@ -18,12 +18,15 @@ var o = ({ storage: o = "local" } = {}) => ({
18
18
  fn: (e) => e.experience,
19
19
  target: l
20
20
  });
21
- let u = i(async (e) => {
22
- let t = r("open-close", "experience", e), n = e.isOpenStore.getState();
23
- c.set(t, n);
21
+ let u = i(async ({ experience: e, isOpen: t }) => {
22
+ let n = r("open-close", "experience", e);
23
+ c.set(n, t);
24
24
  }), d = (e) => a({
25
25
  source: e.isOpenStore,
26
- fn: () => e,
26
+ fn: (t) => ({
27
+ experience: e,
28
+ isOpen: t
29
+ }),
27
30
  target: u
28
31
  });
29
32
  s.experienceInstances.listStore.watch((e) => {
@@ -2,13 +2,13 @@ import { d as e } from "../../../supports-0XIfd4-R.js";
2
2
  import { n as t, r as n, t as r } from "../../../storage-6Xk0uAxB.js";
3
3
  import { createEffect as i, sample as a } from "effector";
4
4
  //#region src/plugins/history-browser-storage/plugin.ts
5
- var o = r("history-v2", "global"), s = ({ storage: r = "local" } = {}) => ({
5
+ var o = r("history", "global"), s = ({ storage: r = "local" } = {}) => ({
6
6
  name: "history-browser-storage-plugin",
7
7
  setup: (s) => {
8
8
  if (!e()) return;
9
9
  let c = r === "local" ? t : n, l = i(async () => {
10
10
  let e = c.get(o).json();
11
- e && s.history.restoreSnapshots({ snapshots: e });
11
+ e && s.history.restore({ entries: e });
12
12
  }), u = i(async (e) => {
13
13
  c.set(o, e);
14
14
  });
@@ -17,7 +17,7 @@ var o = r("history-v2", "global"), s = ({ storage: r = "local" } = {}) => ({
17
17
  filter: (e) => e.type === "load",
18
18
  target: l
19
19
  }), a({
20
- source: s.history.snapshotStore,
20
+ source: s.history.entriesStore,
21
21
  target: u
22
22
  });
23
23
  }
@@ -1,4 +1,4 @@
1
- import { n as e } from "../../../object-C82v79xc.js";
1
+ import { n as e } from "../../../object-DvUDOytC.js";
2
2
  import { d as t, f as n, i as r } from "../../../supports-0XIfd4-R.js";
3
3
  //#region src/plugins/single-page-app/plugin.ts
4
4
  var i = n, a, o = (e) => ({
@@ -9,7 +9,7 @@ var n = () => ({
9
9
  class i extends HTMLElement {
10
10
  connectedCallback() {
11
11
  let e = this.getAttribute("experience-id");
12
- n.isReady && e && n.experiences.launch({ id: e });
12
+ n.readyStore.getState() && e && n.experiences.launch({ id: e });
13
13
  }
14
14
  }
15
15
  window.customElements.define(r, i);
@@ -1,4 +1,4 @@
1
- import { t as e } from "../../experience-instance-CWYRLfFM.js";
1
+ import { t as e } from "../../experience-instance-BrLWgVAN.js";
2
2
  import { attach as t, createEffect as n, createEvent as r, createStore as i, sample as a } from "effector";
3
3
  //#region src/server/index.ts
4
4
  function o() {
@@ -19,17 +19,27 @@ function s(s, c) {
19
19
  currentExperienceIndex: 0,
20
20
  renderedExperiences: [],
21
21
  isComplete: !1
22
- }), v = n(async ({ experience: e, availableRenderers: t, startRendererIndex: n = 0 }) => {
23
- if (!e) return null;
24
- for (let r = n; r < t.length; r++) {
25
- let n = t[r], i = e.componentStore.getState();
26
- if (i && n?.isValidComponent(i.component)) return {
27
- rendered: await n.render(i.component, s, e),
28
- rendererIndex: r
29
- };
22
+ }), v = n(async (e) => {
23
+ let n = t({
24
+ source: e.experience.componentStore,
25
+ effect: async (t, n) => {
26
+ let r = e.availableRenderers[n];
27
+ return t && r?.isValidComponent(t.component) ? {
28
+ rendered: await r.render(t.component, s, e.experience),
29
+ rendererIndex: n
30
+ } : null;
31
+ }
32
+ }), r = e.startRendererIndex ?? 0;
33
+ for (let t = r; t < e.availableRenderers.length; t++) {
34
+ let e = await n(t);
35
+ if (e) return e;
30
36
  }
31
37
  return null;
32
- });
38
+ }), y = n(async ({ experience: e, availableRenderers: t, startRendererIndex: n = 0 }) => e ? v({
39
+ experience: e,
40
+ availableRenderers: t,
41
+ startRendererIndex: n
42
+ }) : null);
33
43
  return _.on(p, (e, t) => ({
34
44
  ...e,
35
45
  renderedExperiences: [...e.renderedExperiences, t],
@@ -55,9 +65,9 @@ function s(s, c) {
55
65
  availableRenderers: c,
56
66
  startRendererIndex: 0
57
67
  }),
58
- target: v
68
+ target: y
59
69
  }), a({
60
- clock: v.doneData,
70
+ clock: y.doneData,
61
71
  filter: (e) => e !== null,
62
72
  fn: (e) => e.rendered.body,
63
73
  target: p
@@ -65,7 +75,7 @@ function s(s, c) {
65
75
  clock: p,
66
76
  target: f
67
77
  }), a({
68
- clock: v.doneData,
78
+ clock: y.doneData,
69
79
  filter: (e) => e === null,
70
80
  target: h
71
81
  }), a({