@picked/client 0.0.1-dev.1786072899095 → 0.0.1-dev.1786601464574

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 (96) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/api-C8B96Kwv.js +22 -0
  3. package/dist/api-DS7fA9kj.cjs +1 -0
  4. package/dist/cjs/index.js +2 -2
  5. package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
  6. package/dist/cjs/server/index.js +1 -1
  7. package/dist/docs/explanation/content-references.md +99 -0
  8. package/dist/docs/explanation/how-picked-works.md +25 -3
  9. package/dist/docs/explanation/the-content-model.md +38 -28
  10. package/dist/docs/how-to/authenticate-the-cli.md +95 -0
  11. package/dist/docs/how-to/create-a-content-entry.md +48 -0
  12. package/dist/docs/how-to/define-a-page-layout.md +12 -5
  13. package/dist/docs/how-to/install-the-sdk.md +7 -0
  14. package/dist/docs/how-to/point-one-entry-at-another.md +61 -0
  15. package/dist/docs/how-to/read-a-referenced-entry.md +111 -0
  16. package/dist/docs/how-to/reuse-a-section.md +26 -10
  17. package/dist/docs/how-to/switch-workspaces.md +123 -0
  18. package/dist/docs/index.md +1 -1
  19. package/dist/docs/reference/dashboard/content/blocks.mdx +57 -0
  20. package/dist/docs/reference/dashboard/content/content-entries.mdx +61 -10
  21. package/dist/docs/reference/dashboard/content/models.mdx +108 -0
  22. package/dist/docs/reference/dashboard/content/pages.mdx +4 -3
  23. package/dist/docs/reference/dashboard/fields.mdx +1 -1
  24. package/dist/docs/reference/dashboard/steps.mdx +2 -2
  25. package/dist/docs/reference/delivery-api/experience-content.md +68 -13
  26. package/dist/docs/reference/delivery-api/workspace-schema.md +74 -0
  27. package/dist/docs/reference/glossary.md +13 -5
  28. package/dist/docs/reference/management-api/error-handling.md +2 -2
  29. package/dist/docs/reference/sdk/content.md +216 -0
  30. package/dist/docs/reference/sdk/plugins/dynamic-experiences.md +51 -3
  31. package/dist/docs/reference/sdk/ssr/serialize.md +6 -3
  32. package/dist/docs/reference/sdk/type-generation.md +130 -0
  33. package/dist/docs/reference/tools/cli.md +141 -0
  34. package/dist/docs/reference/tools/vite-plugin.md +90 -8
  35. package/dist/docs/tutorials/first-api-call.md +1 -1
  36. package/dist/docs/tutorials/first-server-rendered-page.mdx +1 -1
  37. package/dist/esm/index.js +496 -432
  38. package/dist/esm/plugins/dynamic-experiences/index.js +5 -3
  39. package/dist/esm/server/index.js +43 -46
  40. package/dist/plugin-C8hWW3ed.js +157 -0
  41. package/dist/plugin-Dtg2sOad.cjs +1 -0
  42. package/dist/provider-BEpRDCyr.js +69 -0
  43. package/dist/provider-ixdOyYTA.cjs +1 -0
  44. package/dist/registry-C1t8l3t9.cjs +1 -0
  45. package/dist/registry-CXZv0uLg.js +18 -0
  46. package/dist/types/data-source/api.d.ts +60 -0
  47. package/dist/types/data-source/api.d.ts.map +1 -0
  48. package/dist/types/data-source/provider.d.ts +90 -0
  49. package/dist/types/data-source/provider.d.ts.map +1 -0
  50. package/dist/types/data-source/registry.d.ts +26 -0
  51. package/dist/types/data-source/registry.d.ts.map +1 -0
  52. package/dist/types/data-source/virtual-data.d.ts +19 -0
  53. package/dist/types/data-source/virtual-data.d.ts.map +1 -0
  54. package/dist/types/entities/content/reference.d.ts +101 -0
  55. package/dist/types/entities/content/reference.d.ts.map +1 -0
  56. package/dist/types/entities/response/response.d.ts +22 -6
  57. package/dist/types/entities/response/response.d.ts.map +1 -1
  58. package/dist/types/exports.d.ts +2 -0
  59. package/dist/types/exports.d.ts.map +1 -1
  60. package/dist/types/form/create-submit-pipeline.d.ts +32 -3
  61. package/dist/types/form/create-submit-pipeline.d.ts.map +1 -1
  62. package/dist/types/index.d.ts +3 -0
  63. package/dist/types/index.d.ts.map +1 -1
  64. package/dist/types/picked.d.ts +68 -4
  65. package/dist/types/picked.d.ts.map +1 -1
  66. package/dist/types/ping.d.ts +4 -3
  67. package/dist/types/ping.d.ts.map +1 -1
  68. package/dist/types/plugins/dynamic-experiences/index.d.ts +2 -1
  69. package/dist/types/plugins/dynamic-experiences/index.d.ts.map +1 -1
  70. package/dist/types/plugins/dynamic-experiences/plugin.d.ts +9 -40
  71. package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
  72. package/dist/types/plugins/dynamic-experiences/types.d.ts +22 -129
  73. package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
  74. package/dist/types/schema-registry.d.ts +190 -0
  75. package/dist/types/schema-registry.d.ts.map +1 -0
  76. package/dist/types/server/index.d.ts +2 -2
  77. package/dist/types/server/index.d.ts.map +1 -1
  78. package/dist/types/server/serialize.d.ts +37 -34
  79. package/dist/types/server/serialize.d.ts.map +1 -1
  80. package/dist/types/typed-content.d.ts +17 -0
  81. package/dist/types/typed-content.d.ts.map +1 -0
  82. package/dist/types/utils/picked-config.d.ts +19 -1
  83. package/dist/types/utils/picked-config.d.ts.map +1 -1
  84. package/dist/version-BLzNWQ-j.cjs +1 -0
  85. package/dist/version-IAAIvoH9.js +4 -0
  86. package/package.json +5 -3
  87. package/dist/api-BzK4kXRt.js +0 -38
  88. package/dist/api-CgENjKwJ.cjs +0 -1
  89. package/dist/docs/reference/dashboard/content/layouts.mdx +0 -62
  90. package/dist/docs/reference/dashboard/content/sections.mdx +0 -28
  91. package/dist/plugin-DJjtc5df.js +0 -252
  92. package/dist/plugin-jHxSAqGG.cjs +0 -1
  93. package/dist/types/utils/api.d.ts +0 -25
  94. package/dist/types/utils/api.d.ts.map +0 -1
  95. package/dist/types/utils/client-headers.d.ts +0 -2
  96. package/dist/types/utils/client-headers.d.ts.map +0 -1
@@ -1,38 +0,0 @@
1
- function e(e, t) {
2
- return {
3
- "Picked-Client": e,
4
- "Picked-Version": t
5
- };
6
- }
7
- //#endregion
8
- //#region src/utils/version.ts
9
- var t = () => "0.0.1-dev.1786072899095", n = "v1";
10
- function r(e, t) {
11
- return new URL(`/api/${n}/${t}`, e).toString();
12
- }
13
- function i(n) {
14
- return {
15
- ...e("sdk", t()),
16
- ...n
17
- };
18
- }
19
- async function a(e, t, n, a) {
20
- let o = r(e, t);
21
- return fetch(o, {
22
- headers: i(n),
23
- signal: a
24
- });
25
- }
26
- async function o(e, t, n, a) {
27
- let o = r(e, t);
28
- return fetch(o, {
29
- method: "POST",
30
- headers: {
31
- "Content-Type": "application/json",
32
- ...i(a)
33
- },
34
- body: JSON.stringify(n)
35
- });
36
- }
37
- //#endregion
38
- export { e as i, o as n, t as r, a as t };
@@ -1 +0,0 @@
1
- function e(e,t){return{"Picked-Client":e,"Picked-Version":t}}var t=()=>`0.0.1-dev.1786072899095`,n=`v1`;function r(e,t){return new URL(`/api/${n}/${t}`,e).toString()}function i(n){return{...e(`sdk`,t()),...n}}async function a(e,t,n,a){let o=r(e,t);return fetch(o,{headers:i(n),signal:a})}async function o(e,t,n,a){let o=r(e,t);return fetch(o,{method:`POST`,headers:{"Content-Type":`application/json`,...i(a)},body:JSON.stringify(n)})}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return a}});
@@ -1,62 +0,0 @@
1
- ---
2
- type: reference
3
- layout: docs
4
- ---
5
-
6
- import { Screenshot } from '../../../../../components/Screenshot'
7
-
8
- # Page & Step Layouts
9
-
10
- Layouts are reusable JSON schemas. Page Layouts back standalone Pages; Step Layouts back individual Steps inside a Flow.
11
-
12
- <Screenshot
13
- route="/{orgSlug}/{projectId}/workspaces/{workspaceId}/models"
14
- alt="The layouts list in the schema builder on the Picked dashboard"
15
- />
16
-
17
- ## A page layout and a step layout
18
-
19
- Each layout has a fixed category, and the category decides what the layout gives its
20
- shape to:
21
-
22
- | Layout | It gives its shape to | Who renders it |
23
- | --- | --- | --- |
24
- | **Page Layout** | A standalone [Page](/reference/dashboard/content/pages). | The SDK renders the entry on your server. |
25
- | **Step Layout** | One [Step](/reference/dashboard/steps) inside a Flow. | The Step renders the entry in the browser. |
26
-
27
- ## Field types
28
-
29
- A layout is built from fields. Each field has a type that decides its editor and the shape of the value it stores.
30
-
31
- | Type | Stores | Use it for |
32
- | --- | --- | --- |
33
- | **Single-line text** | A short string. | A title, a label, or a short headline. |
34
- | **Multi-line text** | A longer plain string. | A description, or a paragraph with no format marks. |
35
- | **Markdown** | A Markdown string. | Body copy with format marks. |
36
- | **Slug** | A URL-safe string. | A part of a path, or an identifier. |
37
- | **Number** | A numeric value. | A price, a count, or a rating. |
38
- | **Boolean** | A true or false value. | A toggle or a flag. |
39
- | **Date** | A date value. | A publish date or a deadline. |
40
- | **Color** | A color value. | A theme accent or a swatch. |
41
- | **JSON** | Any JSON value. | Structured data with no editor of its own. |
42
- | **Group** | An object of fields inside the layout. | A set of related fields, held together. |
43
- | **Section** | A [Section](/reference/dashboard/content/sections) schema inside the layout. | A shared schema fragment that you reuse. |
44
- | **Asset** | A link to an [Asset Library](/reference/dashboard/content/asset-library) item. | An image, a video, or a document. |
45
- | **HTML asset** | A link to a `.html` file in your library. | HTML that you wrote before, held inside the content. |
46
-
47
- ## Repeatable and grouped fields
48
-
49
- You can make any field **repeatable**. It then renders as a sortable list of values,
50
- and not as one value. Use it for a gallery, for a list of features, or for any
51
- collection.
52
-
53
- A **Group** field holds a set of fields under one key, and it gives a structured
54
- object. Make a group repeatable to describe a list of objects, such as a list of
55
- feature cards.
56
-
57
- ## Related
58
-
59
- - [About the content model](/explanation/the-content-model) — why a schema change does not
60
- migrate your data.
61
- - [How to define a page layout](/how-to/define-a-page-layout)
62
- - [How to reuse a section](/how-to/reuse-a-section)
@@ -1,28 +0,0 @@
1
- ---
2
- type: reference
3
- layout: docs
4
- ---
5
-
6
- import { Screenshot } from '../../../../../components/Screenshot'
7
-
8
- # Sections
9
-
10
- Sections are reusable schema fragments you embed inside layouts, so common structures such as a hero or a feature list are defined once.
11
-
12
- <Screenshot
13
- route="/{orgSlug}/{projectId}/workspaces/{workspaceId}/blocks"
14
- alt="The sections list in the schema builder on the Picked dashboard"
15
- />
16
-
17
- ## What a section is
18
-
19
- A Section is a reusable schema fragment with its own **Key**. A
20
- [layout](/reference/dashboard/content/layouts) gives its shape to a whole Page or Step. A Section is a
21
- part that you put into one or more layouts. Define the shape one time, then reuse it
22
- everywhere.
23
-
24
- ## Related
25
-
26
- - [About the content model](/explanation/the-content-model) — why sections exist.
27
- - [How to reuse a section](/how-to/reuse-a-section)
28
- - [Page and step layouts](/reference/dashboard/content/layouts)
@@ -1,252 +0,0 @@
1
- import "./logger-DMN6TxJJ.js";
2
- import { t as e } from "./api-BzK4kXRt.js";
3
- import { attach as t } from "effector";
4
- //#region src/plugins/dynamic-experiences/hash.ts
5
- function n(e) {
6
- let t = 2166136261;
7
- for (let n of e) t ^= n.codePointAt(0) ?? 0, t = Math.imul(t, 16777619);
8
- return t >>> 0;
9
- }
10
- function r(e) {
11
- let t = e;
12
- return t ^= t >>> 16, t = Math.imul(t, 2246822507), t ^= t >>> 13, t = Math.imul(t, 3266489909), t ^= t >>> 16, t >>> 0;
13
- }
14
- function i(e, t) {
15
- return r(n(`${e}:${t}`)) % 100;
16
- }
17
- function a(e, t) {
18
- return t <= 0 ? !1 : t >= 100 || e < t;
19
- }
20
- //#endregion
21
- //#region src/plugins/dynamic-experiences/plugin.ts
22
- function o(e) {
23
- return typeof e == "object" && !!e && "features" in e && Array.isArray(e.features);
24
- }
25
- function s(e, t) {
26
- if (Array.isArray(t.conditions)) for (let n of t.conditions) e.registerCondition(n);
27
- }
28
- function c(e, t) {
29
- e.registerExperience({
30
- id: t.id,
31
- key: t.key,
32
- name: t.name,
33
- targets: t.targets,
34
- nodes: t.nodes,
35
- edges: t.edges,
36
- condition: t.condition,
37
- initializeOpen: t.initializeOpen,
38
- componentName: t.componentName
39
- });
40
- }
41
- function l(e, t) {
42
- if (Array.isArray(t.fields)) for (let n of t.fields) e.registerField(n);
43
- }
44
- function u(e, t) {
45
- if (!Array.isArray(t.steps)) return;
46
- let n = new Map(t.fields.map((e) => [e.id, e.key]));
47
- for (let r of t.steps) {
48
- let t = [];
49
- for (let e of r.fieldIds ?? []) {
50
- let i = n.get(e);
51
- if (i === void 0) {
52
- `${r.key}${e}`;
53
- continue;
54
- }
55
- t.push(i);
56
- }
57
- let i = r.layoutContentId ? e.contents.getById(r.layoutContentId) : null;
58
- e.registerStep({
59
- id: r.id,
60
- key: r.key,
61
- name: r.name,
62
- fieldKeys: t,
63
- layoutName: r.layoutName,
64
- ...r.layoutContentId !== void 0 && {
65
- layoutContentId: r.layoutContentId,
66
- layoutContentStore: i
67
- }
68
- });
69
- }
70
- }
71
- function d(e, t) {
72
- if (Array.isArray(t.experiences)) for (let n of t.experiences) c(e, n);
73
- }
74
- function f(e, t, n) {
75
- h(e, t, n.isPreview, n.sessionId), s(e, t), l(e, t), u(e, t), d(e, t);
76
- }
77
- function p(e) {
78
- let t = e.searchParams["preview-token"];
79
- if (t && t.length > 0) return t[0];
80
- }
81
- function m(e) {
82
- let t = /* @__PURE__ */ new Set(), n = e.searchParams.feature;
83
- if (!n) return t;
84
- for (let e of n) {
85
- let n = e.indexOf(":");
86
- n > 0 && t.add(e.substring(0, n));
87
- }
88
- return t;
89
- }
90
- function h(e, t, n, r) {
91
- let i = m(e);
92
- for (let a of t.features) i.has(a.id) || g(e, a, n, r);
93
- }
94
- function g(e, t, n, r) {
95
- let o = i(r, t.id);
96
- e.registerFeature(t.id, {
97
- key: `v${t.version}`,
98
- name: t.name,
99
- enabled: t.enabled,
100
- weight: t.weight,
101
- storage: n ? "session" : "local",
102
- decide: () => a(o, t.weight)
103
- });
104
- }
105
- function _(e) {
106
- try {
107
- let t = new URL(e).hostname;
108
- return t === "localhost" || t === "127.0.0.1" || t === "::1";
109
- } catch {
110
- return !1;
111
- }
112
- }
113
- function v(e) {
114
- if (typeof e != "object" || !e || !("cause" in e)) return !1;
115
- let { cause: t } = e;
116
- return typeof t != "object" || !t || !("code" in t) ? !1 : t.code === "ECONNREFUSED";
117
- }
118
- async function y(t, n, r) {
119
- let i = r?.previewToken ? `projects/${n}?preview_token=${encodeURIComponent(r.previewToken)}` : `projects/${n}`, a;
120
- try {
121
- a = await e(t, i, r?.headers);
122
- } catch (e) {
123
- return _(t) && v(e), null;
124
- }
125
- if (!a.ok) return `${a.status.toString()}`, null;
126
- let s;
127
- try {
128
- s = await a.json();
129
- } catch {
130
- return null;
131
- }
132
- return o(s) ? s : null;
133
- }
134
- function b(e) {
135
- return typeof e != "object" || !e || !("experienceId" in e) || !("content" in e) ? !1 : Array.isArray(e.content);
136
- }
137
- async function x(t, n, r, i) {
138
- let a = i?.previewToken ? `projects/${n}/experiences/${r}/content?preview_token=${encodeURIComponent(i.previewToken)}` : `projects/${n}/experiences/${r}/content`, o;
139
- try {
140
- o = await e(t, a, i?.headers, i?.signal);
141
- } catch (e) {
142
- return _(t) && v(e) || `${r}`, null;
143
- }
144
- if (!o.ok) return `${r}${o.status.toString()}`, null;
145
- let s;
146
- try {
147
- s = await o.json();
148
- } catch {
149
- return `${r}`, null;
150
- }
151
- return b(s) ? s : (`${r}`, null);
152
- }
153
- function S(e, t) {
154
- for (let n of t.content) e.registerContent({
155
- id: n.id,
156
- contentModelKey: n.contentModelKey,
157
- data: n.data
158
- });
159
- }
160
- function C(e) {
161
- if (typeof e != "object" || !e || !("projectConfig" in e) || !("experienceContent" in e) || !("manifestMetadata" in e)) return !1;
162
- let { experienceContent: t } = e;
163
- return typeof t == "function";
164
- }
165
- async function w() {
166
- try {
167
- let e = await import("virtual:picked/data");
168
- return C(e) ? e : null;
169
- } catch {
170
- return null;
171
- }
172
- }
173
- function T(e, t, n) {
174
- return (r) => x(e, t, r.id, n ? { previewToken: n } : void 0);
175
- }
176
- function E(e, t) {
177
- return (n) => e(n, t ? { previewToken: t } : void 0);
178
- }
179
- function D(e) {
180
- return (t, n) => e.experienceContent(t, n);
181
- }
182
- function O(e, t) {
183
- let n = /* @__PURE__ */ new Map();
184
- return (r, i) => {
185
- let a = n.get(r.id);
186
- if (a) return a;
187
- let o = (async () => {
188
- try {
189
- let n = await t(r, i);
190
- return n && S(e, n), n;
191
- } finally {
192
- n.delete(r.id);
193
- }
194
- })();
195
- return n.set(r.id, o), o;
196
- };
197
- }
198
- function k(e, t) {
199
- let n = new Set(t && Array.isArray(t.experiences) ? t.experiences.map((e) => e.id) : []);
200
- return (t, r) => n.has(t.id) ? e(t, r) : Promise.resolve(null);
201
- }
202
- async function A(e) {
203
- let { client: t, apiUrl: n, options: r } = e, i = p(t), a = !!i, o = r?.projectConfig ?? null, s = r?.getContent ? E(r.getContent, i) : null, c = null;
204
- if (i) return o ??= await y(n, t.projectId, { previewToken: i }), s ??= T(n, t.projectId, i), {
205
- config: o,
206
- contentLoader: s,
207
- dataSource: c,
208
- isPreview: a
209
- };
210
- if (o && s) return {
211
- config: o,
212
- contentLoader: s,
213
- dataSource: c,
214
- isPreview: a
215
- };
216
- let l = await w();
217
- return l ? (o ??= l.projectConfig, s ??= D(l), c = l.manifestMetadata, {
218
- config: o,
219
- contentLoader: s,
220
- dataSource: c,
221
- isPreview: a
222
- }) : (o ??= await y(n, t.projectId), s ??= T(n, t.projectId), {
223
- config: o,
224
- contentLoader: s,
225
- dataSource: c,
226
- isPreview: a
227
- });
228
- }
229
- function j(e) {
230
- return {
231
- name: "dynamic-experiences",
232
- setup: (n) => {
233
- let r = e?.apiUrl ?? n.apiUrl;
234
- return { onStart: t({
235
- source: n.session.store.map((e) => e.id),
236
- effect: async (t) => {
237
- let { config: i, contentLoader: a, dataSource: o, isPreview: s } = await A({
238
- client: n,
239
- apiUrl: r,
240
- options: e
241
- });
242
- a && (n.contentLoader = O(n, k(a, i))), n.dataSource = o, i && (n.previewEmbedderOrigins = i.previewEmbedderOrigins ?? null, f(n, i, {
243
- isPreview: s,
244
- sessionId: t
245
- }));
246
- }
247
- }) };
248
- }
249
- };
250
- }
251
- //#endregion
252
- export { f as i, x as n, y as r, j as t };
@@ -1 +0,0 @@
1
- require("./logger-CSTvAyyB.cjs");const e=require("./api-CgENjKwJ.cjs");let t=require("effector");function n(e){let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return t>>>0}function r(e){let t=e;return t^=t>>>16,t=Math.imul(t,2246822507),t^=t>>>13,t=Math.imul(t,3266489909),t^=t>>>16,t>>>0}function i(e,t){return r(n(`${e}:${t}`))%100}function a(e,t){return t<=0?!1:t>=100||e<t}function o(e){return typeof e==`object`&&!!e&&`features`in e&&Array.isArray(e.features)}function s(e,t){if(Array.isArray(t.conditions))for(let n of t.conditions)e.registerCondition(n)}function c(e,t){e.registerExperience({id:t.id,key:t.key,name:t.name,targets:t.targets,nodes:t.nodes,edges:t.edges,condition:t.condition,initializeOpen:t.initializeOpen,componentName:t.componentName})}function l(e,t){if(Array.isArray(t.fields))for(let n of t.fields)e.registerField(n)}function u(e,t){if(!Array.isArray(t.steps))return;let n=new Map(t.fields.map(e=>[e.id,e.key]));for(let r of t.steps){let t=[];for(let e of r.fieldIds??[]){let i=n.get(e);if(i===void 0){`${r.key}${e}`;continue}t.push(i)}let i=r.layoutContentId?e.contents.getById(r.layoutContentId):null;e.registerStep({id:r.id,key:r.key,name:r.name,fieldKeys:t,layoutName:r.layoutName,...r.layoutContentId!==void 0&&{layoutContentId:r.layoutContentId,layoutContentStore:i}})}}function d(e,t){if(Array.isArray(t.experiences))for(let n of t.experiences)c(e,n)}function f(e,t,n){h(e,t,n.isPreview,n.sessionId),s(e,t),l(e,t),u(e,t),d(e,t)}function p(e){let t=e.searchParams[`preview-token`];if(t&&t.length>0)return t[0]}function m(e){let t=new Set,n=e.searchParams.feature;if(!n)return t;for(let e of n){let n=e.indexOf(`:`);n>0&&t.add(e.substring(0,n))}return t}function h(e,t,n,r){let i=m(e);for(let a of t.features)i.has(a.id)||g(e,a,n,r)}function g(e,t,n,r){let o=i(r,t.id);e.registerFeature(t.id,{key:`v${t.version}`,name:t.name,enabled:t.enabled,weight:t.weight,storage:n?`session`:`local`,decide:()=>a(o,t.weight)})}function _(e){try{let t=new URL(e).hostname;return t===`localhost`||t===`127.0.0.1`||t===`::1`}catch{return!1}}function v(e){if(typeof e!=`object`||!e||!(`cause`in e))return!1;let{cause:t}=e;return typeof t!=`object`||!t||!(`code`in t)?!1:t.code===`ECONNREFUSED`}async function y(t,n,r){let i=r?.previewToken?`projects/${n}?preview_token=${encodeURIComponent(r.previewToken)}`:`projects/${n}`,a;try{a=await e.t(t,i,r?.headers)}catch(e){return _(t)&&v(e),null}if(!a.ok)return`${a.status.toString()}`,null;let s;try{s=await a.json()}catch{return null}return o(s)?s:null}function b(e){return typeof e!=`object`||!e||!(`experienceId`in e)||!(`content`in e)?!1:Array.isArray(e.content)}async function x(t,n,r,i){let a=i?.previewToken?`projects/${n}/experiences/${r}/content?preview_token=${encodeURIComponent(i.previewToken)}`:`projects/${n}/experiences/${r}/content`,o;try{o=await e.t(t,a,i?.headers,i?.signal)}catch(e){return _(t)&&v(e)||`${r}`,null}if(!o.ok)return`${r}${o.status.toString()}`,null;let s;try{s=await o.json()}catch{return`${r}`,null}return b(s)?s:(`${r}`,null)}function S(e,t){for(let n of t.content)e.registerContent({id:n.id,contentModelKey:n.contentModelKey,data:n.data})}function C(e){if(typeof e!=`object`||!e||!(`projectConfig`in e)||!(`experienceContent`in e)||!(`manifestMetadata`in e))return!1;let{experienceContent:t}=e;return typeof t==`function`}async function w(){try{let e=await import(`virtual:picked/data`);return C(e)?e:null}catch{return null}}function T(e,t,n){return r=>x(e,t,r.id,n?{previewToken:n}:void 0)}function E(e,t){return n=>e(n,t?{previewToken:t}:void 0)}function D(e){return(t,n)=>e.experienceContent(t,n)}function O(e,t){let n=new Map;return(r,i)=>{let a=n.get(r.id);if(a)return a;let o=(async()=>{try{let n=await t(r,i);return n&&S(e,n),n}finally{n.delete(r.id)}})();return n.set(r.id,o),o}}function k(e,t){let n=new Set(t&&Array.isArray(t.experiences)?t.experiences.map(e=>e.id):[]);return(t,r)=>n.has(t.id)?e(t,r):Promise.resolve(null)}async function A(e){let{client:t,apiUrl:n,options:r}=e,i=p(t),a=!!i,o=r?.projectConfig??null,s=r?.getContent?E(r.getContent,i):null,c=null;if(i)return o??=await y(n,t.projectId,{previewToken:i}),s??=T(n,t.projectId,i),{config:o,contentLoader:s,dataSource:c,isPreview:a};if(o&&s)return{config:o,contentLoader:s,dataSource:c,isPreview:a};let l=await w();return l?(o??=l.projectConfig,s??=D(l),c=l.manifestMetadata,{config:o,contentLoader:s,dataSource:c,isPreview:a}):(o??=await y(n,t.projectId),s??=T(n,t.projectId),{config:o,contentLoader:s,dataSource:c,isPreview:a})}function j(e){return{name:`dynamic-experiences`,setup:n=>{let r=e?.apiUrl??n.apiUrl;return{onStart:(0,t.attach)({source:n.session.store.map(e=>e.id),effect:async t=>{let{config:i,contentLoader:a,dataSource:o,isPreview:s}=await A({client:n,apiUrl:r,options:e});a&&(n.contentLoader=O(n,k(a,i))),n.dataSource=o,i&&(n.previewEmbedderOrigins=i.previewEmbedderOrigins??null,f(n,i,{isPreview:s,sessionId:t}))}})}}}}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return j}});
@@ -1,25 +0,0 @@
1
- /**
2
- * Performs a GET request against the Picked API.
3
- *
4
- * @param {string} baseUrl - The API origin.
5
- * @param {string} path - The path relative to `/api/v1/`.
6
- * @param {Record<string, string>} [headers] - Optional header overrides.
7
- * @param {AbortSignal} [signal] - Optional abort signal, such as a timeout deadline.
8
- * @returns {Promise<Response>} The fetch response.
9
- * @example
10
- * const response = await get('https://api.picked.app', 'projects/p1')
11
- */
12
- export declare function get(baseUrl: string, path: string, headers?: Record<string, string>, signal?: AbortSignal): Promise<Response>;
13
- /**
14
- * Performs a JSON POST request against the Picked API.
15
- *
16
- * @param {string} baseUrl - The API origin.
17
- * @param {string} path - The path relative to `/api/v1/`.
18
- * @param {unknown} data - The request body, serialised as JSON.
19
- * @param {Record<string, string>} [headers] - Optional header overrides.
20
- * @returns {Promise<Response>} The fetch response.
21
- * @example
22
- * const response = await post('https://api.picked.app', 'events', { type: 'load' })
23
- */
24
- export declare function post(baseUrl: string, path: string, data: unknown, headers?: Record<string, string>): Promise<Response>;
25
- //# sourceMappingURL=api.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/utils/api.ts"],"names":[],"mappings":"AA+BA;;;;;;;;;;GAUG;AACH,wBAAsB,GAAG,CACvB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,QAAQ,CAAC,CAInB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,IAAI,CACxB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,QAAQ,CAAC,CAQnB"}
@@ -1,2 +0,0 @@
1
- export declare function createClientHeaders(name: string, version: string): Record<string, string>;
2
- //# sourceMappingURL=client-headers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client-headers.d.ts","sourceRoot":"","sources":["../../../src/utils/client-headers.ts"],"names":[],"mappings":"AAGA,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAKzF"}