@picked/client 0.0.62-next.12 → 0.0.62-next.3

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 (55) hide show
  1. package/dist/{api-BTbEUnGh.js → api-DnsQgAfY.js} +1 -1
  2. package/dist/api-Dy5cTzV6.cjs +1 -0
  3. package/dist/cjs/index.js +2 -2
  4. package/dist/cjs/plugins/create-experience/index.js +1 -1
  5. package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
  6. package/dist/cjs/plugins/experience-browser-storage/index.js +1 -1
  7. package/dist/cjs/plugins/history-browser-storage/index.js +1 -1
  8. package/dist/cjs/plugins/responses-browser-storage/index.js +1 -1
  9. package/dist/cjs/server/index.js +1 -1
  10. package/dist/docs/image-optimisation-service.md +6 -6
  11. package/dist/docs/sdk/content-security-policy.md +7 -8
  12. package/dist/docs/sdk/fields.md +2 -2
  13. package/dist/docs/workspaces.mdx +1 -1
  14. package/dist/esm/index.js +277 -342
  15. package/dist/esm/plugins/create-experience/index.js +1 -1
  16. package/dist/esm/plugins/dynamic-experiences/index.js +38 -109
  17. package/dist/esm/plugins/experience-browser-storage/index.js +1 -1
  18. package/dist/esm/plugins/history-browser-storage/index.js +1 -1
  19. package/dist/esm/plugins/responses-browser-storage/index.js +1 -1
  20. package/dist/esm/server/index.js +1 -1
  21. package/dist/experience-instance-BrLWgVAN.js +501 -0
  22. package/dist/experience-instance-Ct3ogC7n.cjs +1 -0
  23. package/dist/types/entities/experience/experience.d.ts +2 -22
  24. package/dist/types/entities/experience/experience.d.ts.map +1 -1
  25. package/dist/types/entities/step/step.d.ts +2 -17
  26. package/dist/types/entities/step/step.d.ts.map +1 -1
  27. package/dist/types/index.d.ts +0 -2
  28. package/dist/types/index.d.ts.map +1 -1
  29. package/dist/types/lifecycle/state-snapshot.d.ts.map +1 -1
  30. package/dist/types/picked.d.ts +0 -39
  31. package/dist/types/picked.d.ts.map +1 -1
  32. package/dist/types/plugins/dynamic-experiences/index.d.ts +1 -2
  33. package/dist/types/plugins/dynamic-experiences/index.d.ts.map +1 -1
  34. package/dist/types/plugins/dynamic-experiences/plugin.d.ts +1 -18
  35. package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
  36. package/dist/types/plugins/dynamic-experiences/types.d.ts +1 -63
  37. package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
  38. package/package.json +1 -11
  39. package/dist/api-DDd_Zf11.cjs +0 -1
  40. package/dist/cjs/plugins/dom-observer/index.js +0 -1
  41. package/dist/dom-C3C6Fmwz.cjs +0 -1
  42. package/dist/dom-DGePXPpM.js +0 -84
  43. package/dist/esm/plugins/dom-observer/index.js +0 -87
  44. package/dist/experience-instance-DImym3m_.js +0 -419
  45. package/dist/experience-instance-DygAdzbn.cjs +0 -1
  46. package/dist/types/entities/content/content.d.ts +0 -37
  47. package/dist/types/entities/content/content.d.ts.map +0 -1
  48. package/dist/types/plugins/dom-observer/index.d.ts +0 -3
  49. package/dist/types/plugins/dom-observer/index.d.ts.map +0 -1
  50. package/dist/types/plugins/dom-observer/plugin.d.ts +0 -50
  51. package/dist/types/plugins/dom-observer/plugin.d.ts.map +0 -1
  52. /package/dist/{id-Cg7fVl1O.cjs → id-Bv44ilEo.cjs} +0 -0
  53. /package/dist/{id-n2yrHvNo.js → id-CRqy981z.js} +0 -0
  54. /package/dist/{storage-hOHCCXvP.js → storage-6Xk0uAxB.js} +0 -0
  55. /package/dist/{storage-BXSlLTRa.cjs → storage-B6lQtc4-.cjs} +0 -0
@@ -1,4 +1,4 @@
1
- import { t as e } from "../../../id-n2yrHvNo.js";
1
+ import { t as e } from "../../../id-CRqy981z.js";
2
2
  //#region src/plugins/create-experience/serialization.ts
3
3
  var t = {
4
4
  serialize(e) {
@@ -1,5 +1,5 @@
1
1
  import "../../../logger-6z_gb4rA.js";
2
- import { i as e, t } from "../../../api-BTbEUnGh.js";
2
+ import { i as e, t } from "../../../api-DnsQgAfY.js";
3
3
  import { attach as n } from "effector";
4
4
  //#region src/plugins/dynamic-experiences/hash.ts
5
5
  function r(e) {
@@ -50,17 +50,12 @@ function u(e, t) {
50
50
  }
51
51
  t.push(i);
52
52
  }
53
- let i = r.layoutContentId ? e.contents.getById(r.layoutContentId) : null;
54
53
  e.registerStep({
55
54
  id: r.id,
56
55
  key: r.key,
57
56
  name: r.name,
58
57
  fieldKeys: t,
59
- layoutName: r.layoutName,
60
- ...r.layoutContentId !== void 0 && {
61
- layoutContentId: r.layoutContentId,
62
- layoutContentStore: i
63
- }
58
+ layoutName: r.layoutName
64
59
  });
65
60
  }
66
61
  }
@@ -92,7 +87,24 @@ function h(e, t, n, r) {
92
87
  decide: () => t.enabled ? a(r, t.weight) : !1
93
88
  });
94
89
  }
95
- function g(e) {
90
+ function g() {
91
+ let e;
92
+ try {
93
+ e = __PICKED_PROJECT_CONFIG__;
94
+ } catch {
95
+ return;
96
+ }
97
+ if (e === void 0) return;
98
+ let t;
99
+ if (typeof e == "string") try {
100
+ t = JSON.parse(e);
101
+ } catch {
102
+ return;
103
+ }
104
+ else t = e;
105
+ if (o(t)) return t;
106
+ }
107
+ function _(e) {
96
108
  try {
97
109
  let t = new URL(e).hostname;
98
110
  return t === "localhost" || t === "127.0.0.1" || t === "::1";
@@ -100,17 +112,17 @@ function g(e) {
100
112
  return !1;
101
113
  }
102
114
  }
103
- function _(e) {
115
+ function v(e) {
104
116
  if (typeof e != "object" || !e || !("cause" in e)) return !1;
105
117
  let { cause: t } = e;
106
118
  return typeof t != "object" || !t || !("code" in t) ? !1 : t.code === "ECONNREFUSED";
107
119
  }
108
- async function v(e, n, r) {
120
+ async function y(e, n, r) {
109
121
  let i = r?.previewToken ? `projects/${n}?preview_token=${encodeURIComponent(r.previewToken)}` : `projects/${n}`, a;
110
122
  try {
111
123
  a = await t(e, i, r?.headers);
112
124
  } catch (t) {
113
- return g(e) && _(t), null;
125
+ return _(e) && v(t), null;
114
126
  }
115
127
  if (!a.ok) return `${a.status.toString()}`, null;
116
128
  let s;
@@ -121,97 +133,7 @@ async function v(e, n, r) {
121
133
  }
122
134
  return o(s) ? s : null;
123
135
  }
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
- async function C() {
155
- try {
156
- let e = await import("virtual:picked/data");
157
- return S(e) ? e : null;
158
- } catch {
159
- return null;
160
- }
161
- }
162
- function w(e, t, n) {
163
- return (r) => b(e, t, r.id, n ? { previewToken: n } : void 0);
164
- }
165
- function T(e, t) {
166
- return (n) => e(n, t ? { previewToken: t } : void 0);
167
- }
168
- function E(e) {
169
- return (t, n) => e.experienceContent(t, n);
170
- }
171
- function D(e, t) {
172
- let n = /* @__PURE__ */ new Map();
173
- return (r, i) => {
174
- let a = n.get(r.id);
175
- if (a) return a;
176
- let o = (async () => {
177
- try {
178
- let n = await t(r, i);
179
- return n && x(e, n), n;
180
- } finally {
181
- n.delete(r.id);
182
- }
183
- })();
184
- return n.set(r.id, o), o;
185
- };
186
- }
187
- async function O(e) {
188
- let { client: t, apiUrl: n, options: r } = e, i = f(t), a = !!i, o = r?.projectConfig ?? null, s = r?.getContent ? T(r.getContent, i) : null, c = null;
189
- if (i) return o ??= await v(n, t.projectId, { previewToken: i }), s ??= w(n, t.projectId, i), {
190
- config: o,
191
- contentLoader: s,
192
- dataSource: c,
193
- isPreview: a
194
- };
195
- if (o && s) return {
196
- config: o,
197
- contentLoader: s,
198
- dataSource: c,
199
- isPreview: a
200
- };
201
- let l = await C();
202
- return l ? (o ??= l.projectConfig, s ??= E(l), c = l.manifestMetadata, {
203
- config: o,
204
- contentLoader: s,
205
- dataSource: c,
206
- isPreview: a
207
- }) : (o ??= await v(n, t.projectId), s ??= w(n, t.projectId), {
208
- config: o,
209
- contentLoader: s,
210
- dataSource: c,
211
- isPreview: a
212
- });
213
- }
214
- function k(e) {
136
+ function b(e) {
215
137
  return {
216
138
  name: "dynamic-experiences",
217
139
  setup: (t) => {
@@ -219,16 +141,23 @@ function k(e) {
219
141
  return { onStart: n({
220
142
  source: t.session.store.map((e) => e.id),
221
143
  effect: async (n) => {
222
- let { config: i, contentLoader: a, dataSource: o, isPreview: c } = await O({
223
- client: t,
224
- apiUrl: r,
225
- options: e
226
- });
227
- a && (t.contentLoader = D(t, a)), t.dataSource = o, i && (m(t, i, c, n), s(t, i), l(t, i), u(t, i), d(t, i));
144
+ let i = f(t);
145
+ if (i) {
146
+ let e = await y(r, t.projectId, { previewToken: i });
147
+ e && (m(t, e, !0, n), s(t, e), l(t, e), u(t, e), d(t, e));
148
+ return;
149
+ }
150
+ let a = e?.projectConfig ?? g();
151
+ if (a) {
152
+ m(t, a, !1, n), s(t, a), l(t, a), u(t, a), d(t, a);
153
+ return;
154
+ }
155
+ let o = await y(r, t.projectId);
156
+ o && (m(t, o, !1, n), s(t, o), l(t, o), u(t, o), d(t, o));
228
157
  }
229
158
  }) };
230
159
  }
231
160
  };
232
161
  }
233
162
  //#endregion
234
- export { e as createClientHeaders, k as dynamicExperiencesPlugin, b as fetchExperienceContent, v as fetchProject };
163
+ export { e as createClientHeaders, b as dynamicExperiencesPlugin, y as fetchProject };
@@ -1,6 +1,6 @@
1
1
  import "../../../logger-6z_gb4rA.js";
2
2
  import { d as e } from "../../../supports-0XIfd4-R.js";
3
- import { n as t, r as n, t as r } from "../../../storage-hOHCCXvP.js";
3
+ import { n as t, r as n, t as r } from "../../../storage-6Xk0uAxB.js";
4
4
  import { createEffect as i, sample as a } from "effector";
5
5
  //#region src/plugins/experience-browser-storage/plugin.ts
6
6
  var o = ({ storage: o = "local" } = {}) => ({
@@ -1,5 +1,5 @@
1
1
  import { d as e } from "../../../supports-0XIfd4-R.js";
2
- import { n as t, r as n, t as r } from "../../../storage-hOHCCXvP.js";
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
5
  var o = r("history", "global"), s = ({ storage: r = "local" } = {}) => ({
@@ -1,5 +1,5 @@
1
1
  import { d as e } from "../../../supports-0XIfd4-R.js";
2
- import { n as t, r as n, t as r } from "../../../storage-hOHCCXvP.js";
2
+ import { n as t, r as n, t as r } from "../../../storage-6Xk0uAxB.js";
3
3
  import { attach as i, createEffect as a, sample as o } from "effector";
4
4
  //#region src/plugins/responses-browser-storage/plugin.ts
5
5
  var s = r("responses", "global");
@@ -1,4 +1,4 @@
1
- import { t as e } from "../../experience-instance-DImym3m_.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() {