@picked/client 0.0.1-dev.1786001783467 → 0.0.1-dev.1786065500148
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/.tsbuildinfo +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
- package/dist/cjs/server/index.js +1 -1
- package/dist/docs/reference/sdk/plugins/dynamic-experiences.md +11 -13
- package/dist/docs/reference/tools/vite-plugin.md +36 -18
- package/dist/esm/index.js +354 -270
- package/dist/esm/plugins/dynamic-experiences/index.js +3 -3
- package/dist/esm/server/index.js +36 -39
- package/dist/plugin-EFn9ALEF.cjs +1 -0
- package/dist/plugin-YytfMG0n.js +153 -0
- package/dist/registry-BYtEBdL1.js +111 -0
- package/dist/registry-DtmKJre-.cjs +1 -0
- package/dist/types/data-source/provider.d.ts +21 -16
- package/dist/types/data-source/provider.d.ts.map +1 -1
- package/dist/types/data-source/registry.d.ts +11 -20
- package/dist/types/data-source/registry.d.ts.map +1 -1
- package/dist/types/data-source/virtual-data.d.ts +19 -0
- package/dist/types/data-source/virtual-data.d.ts.map +1 -0
- package/dist/types/picked.d.ts +50 -1
- package/dist/types/picked.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/index.d.ts +1 -3
- package/dist/types/plugins/dynamic-experiences/index.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/plugin.d.ts +8 -7
- package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/types.d.ts +0 -24
- package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
- package/dist/types/server/index.d.ts +1 -1
- package/dist/types/server/index.d.ts.map +1 -1
- package/dist/types/server/serialize.d.ts +7 -25
- package/dist/types/server/serialize.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/api-BivzqML_.cjs +0 -1
- package/dist/api-i7XfDMTd.js +0 -38
- package/dist/plugin-Cbhl3kSg.js +0 -300
- package/dist/plugin-h2BTDtJ0.cjs +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
1
|
+
import { a as e, c as t, i as n, n as r } from "../../../registry-BYtEBdL1.js";
|
|
2
|
+
import { t as i } from "../../../plugin-YytfMG0n.js";
|
|
3
|
+
export { t as createClientHeaders, i as dynamicExperiencesPlugin, n as fetchExperienceContent, e as fetchProject, r as registerPickedBundle };
|
package/dist/esm/server/index.js
CHANGED
|
@@ -1,44 +1,41 @@
|
|
|
1
1
|
import { a as e, c as t, i as n, o as r, s as i, t as a, u as o } from "../../experience-instance-DGk11d8a.js";
|
|
2
|
-
import {
|
|
3
|
-
import { attach as
|
|
2
|
+
import { n as s } from "../../plugin-YytfMG0n.js";
|
|
3
|
+
import { attach as c, createEffect as l, createEvent as u, createStore as d, sample as f } from "effector";
|
|
4
4
|
//#region src/server/serialize.ts
|
|
5
|
-
var
|
|
6
|
-
function
|
|
5
|
+
var p = 1e4;
|
|
6
|
+
function m(e) {
|
|
7
7
|
if (e?.location !== void 0) return { location: e.location };
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function h(e, t) {
|
|
10
10
|
return e.nodes.filter(o).some((e) => t.get(e.stepId) === !0);
|
|
11
11
|
}
|
|
12
|
-
async function
|
|
13
|
-
let {
|
|
14
|
-
e.conditionResults.reset(),
|
|
12
|
+
async function g(e, n = {}) {
|
|
13
|
+
let i = n.previewToken === void 0 ? void 0 : { previewToken: n.previewToken }, a = await e.getProjectConfig(i), o = e.session.store.getState().id;
|
|
14
|
+
e.conditionResults.reset(), s(e, a, {
|
|
15
15
|
isPreview: !1,
|
|
16
|
-
sessionId:
|
|
16
|
+
sessionId: o
|
|
17
17
|
});
|
|
18
|
-
let
|
|
18
|
+
let c = m(n.attributes), l = n.timeoutMs ?? p, u = new Map(a.steps.map((e) => [e.id, e.layoutContentId !== void 0 && e.layoutContentId !== null])), d = Object.fromEntries(a.conditions.map((e) => [e.key, e])), f = a.experiences.filter((e) => !t(e.condition, d)), g = (await Promise.all(f.map(async (t) => ({
|
|
19
19
|
experience: t,
|
|
20
|
-
active: await r(e, { condition: t.condition }, { context:
|
|
21
|
-
})))).filter((e) => e.active).map((e) => e.experience), _ = await Promise.all(
|
|
20
|
+
active: await r(e, { condition: t.condition }, { context: c })
|
|
21
|
+
})))).filter((e) => e.active).map((e) => e.experience), _ = await Promise.all(g.filter((e) => h(e, u)).map((t) => e.getExperienceContent({
|
|
22
22
|
id: t.id,
|
|
23
23
|
key: t.key
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
key: t.key
|
|
27
|
-
}, { previewToken: n.previewToken }) : s(e.apiUrl, e.projectId, t.id, {
|
|
28
|
-
previewToken: n.previewToken,
|
|
24
|
+
}, {
|
|
25
|
+
...i,
|
|
29
26
|
signal: AbortSignal.timeout(l)
|
|
30
27
|
}))), v = /* @__PURE__ */ new Map();
|
|
31
28
|
for (let e of _) if (e) for (let t of e.content) v.set(t.id, t);
|
|
32
29
|
return {
|
|
33
|
-
versionId:
|
|
34
|
-
projectConfig:
|
|
30
|
+
versionId: a.versionId,
|
|
31
|
+
projectConfig: a,
|
|
35
32
|
content: Array.from(v.values()),
|
|
36
33
|
conditionResults: e.conditionResults.store.getState()
|
|
37
34
|
};
|
|
38
35
|
}
|
|
39
36
|
//#endregion
|
|
40
37
|
//#region src/server/index.ts
|
|
41
|
-
function
|
|
38
|
+
function _() {
|
|
42
39
|
let e, t;
|
|
43
40
|
return {
|
|
44
41
|
promise: new Promise((n, r) => {
|
|
@@ -48,16 +45,16 @@ function v() {
|
|
|
48
45
|
reject: (e) => t(e)
|
|
49
46
|
};
|
|
50
47
|
}
|
|
51
|
-
function
|
|
52
|
-
let { promise: n, resolve: r } =
|
|
48
|
+
function v(e, t) {
|
|
49
|
+
let { promise: n, resolve: r } = _(), i = u(), o = u(), s = u(), p = u(), m = u(), h = e.experiences.listStore.map((t) => t.map((t) => a({
|
|
53
50
|
client: e,
|
|
54
51
|
experience: t
|
|
55
|
-
}))), g =
|
|
52
|
+
}))), g = d({
|
|
56
53
|
currentExperienceIndex: 0,
|
|
57
54
|
renderedExperiences: [],
|
|
58
55
|
isComplete: !1
|
|
59
|
-
}),
|
|
60
|
-
let n =
|
|
56
|
+
}), v = l(async (t) => {
|
|
57
|
+
let n = c({
|
|
61
58
|
source: t.experience.componentStore,
|
|
62
59
|
effect: async (n, r) => {
|
|
63
60
|
let i = t.availableRenderers[r];
|
|
@@ -72,7 +69,7 @@ function y(e, t) {
|
|
|
72
69
|
if (t) return t;
|
|
73
70
|
}
|
|
74
71
|
return null;
|
|
75
|
-
}), y =
|
|
72
|
+
}), y = l(async ({ experience: e, availableRenderers: t, startRendererIndex: n = 0 }) => e ? v({
|
|
76
73
|
experience: e,
|
|
77
74
|
availableRenderers: t,
|
|
78
75
|
startRendererIndex: n
|
|
@@ -84,13 +81,13 @@ function y(e, t) {
|
|
|
84
81
|
})).on(m, (e) => ({
|
|
85
82
|
...e,
|
|
86
83
|
currentExperienceIndex: e.currentExperienceIndex + 1
|
|
87
|
-
})).on(
|
|
84
|
+
})).on(p, (e) => ({
|
|
88
85
|
...e,
|
|
89
86
|
isComplete: !0
|
|
90
|
-
})).reset(i),
|
|
87
|
+
})).reset(i), f({
|
|
91
88
|
clock: i,
|
|
92
89
|
target: o
|
|
93
|
-
}),
|
|
90
|
+
}), f({
|
|
94
91
|
clock: o,
|
|
95
92
|
source: {
|
|
96
93
|
experiences: h,
|
|
@@ -103,22 +100,22 @@ function y(e, t) {
|
|
|
103
100
|
startRendererIndex: 0
|
|
104
101
|
}),
|
|
105
102
|
target: y
|
|
106
|
-
}),
|
|
103
|
+
}), f({
|
|
107
104
|
clock: y.doneData,
|
|
108
105
|
filter: (e) => e !== null,
|
|
109
106
|
fn: (e) => e.rendered.body,
|
|
110
107
|
target: s
|
|
111
|
-
}),
|
|
108
|
+
}), f({
|
|
112
109
|
clock: s,
|
|
113
110
|
target: o
|
|
114
|
-
}),
|
|
111
|
+
}), f({
|
|
115
112
|
clock: y.doneData,
|
|
116
113
|
filter: (e) => e === null,
|
|
117
114
|
target: m
|
|
118
|
-
}),
|
|
115
|
+
}), f({
|
|
119
116
|
clock: m,
|
|
120
117
|
target: o
|
|
121
|
-
}),
|
|
118
|
+
}), f({
|
|
122
119
|
clock: [
|
|
123
120
|
o,
|
|
124
121
|
m,
|
|
@@ -129,18 +126,18 @@ function y(e, t) {
|
|
|
129
126
|
state: g
|
|
130
127
|
},
|
|
131
128
|
filter: ({ experiences: e, state: t }) => t.currentExperienceIndex >= e.length,
|
|
132
|
-
target:
|
|
129
|
+
target: p
|
|
133
130
|
});
|
|
134
|
-
let b =
|
|
131
|
+
let b = c({
|
|
135
132
|
source: g,
|
|
136
133
|
effect: (e) => {
|
|
137
134
|
e.isComplete && r(e.renderedExperiences);
|
|
138
135
|
}
|
|
139
136
|
});
|
|
140
|
-
return
|
|
141
|
-
clock:
|
|
137
|
+
return f({
|
|
138
|
+
clock: p,
|
|
142
139
|
target: b
|
|
143
140
|
}), i(), n;
|
|
144
141
|
}
|
|
145
142
|
//#endregion
|
|
146
|
-
export { a as createExperienceInstance, n as evaluateConditionMemo, e as hashRule, r as isExperienceActive,
|
|
143
|
+
export { a as createExperienceInstance, n as evaluateConditionMemo, e as hashRule, r as isExperienceActive, s as registerProjectConfig, v as render, i as ruleReferencesAction, t as ruleReferencesActionDeep, g as serialize };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require("./logger-CSTvAyyB.cjs");let e=require("effector");function t(e){let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return t>>>0}function n(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 r(e,r){return n(t(`${e}:${r}`))%100}function i(e,t){return t<=0?!1:t>=100||e<t}function a(e,t){if(Array.isArray(t.conditions))for(let n of t.conditions)e.registerCondition(n)}function o(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 s(e,t){if(Array.isArray(t.fields))for(let n of t.fields)e.registerField(n)}function c(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 l(e,t){if(Array.isArray(t.experiences))for(let n of t.experiences)o(e,n)}function u(e,t,n){p(e,t,n.isPreview,n.sessionId),a(e,t),s(e,t),c(e,t),l(e,t)}function d(e){let t=e.searchParams[`preview-token`];if(t&&t.length>0)return t[0]}function f(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 p(e,t,n,r){let i=f(e);for(let a of t.features)i.has(a.id)||m(e,a,n,r)}function m(e,t,n,a){let o=r(a,t.id);e.registerFeature(t.id,{key:`v${t.version}`,name:t.name,enabled:t.enabled,weight:t.weight,storage:n?`session`:`local`,decide:()=>i(o,t.weight)})}function h(e,t){for(let n of t.content)e.registerContent({id:n.id,contentModelKey:n.contentModelKey,data:n.data})}function g(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&&h(e,n),n}finally{n.delete(r.id)}})();return n.set(r.id,o),o}}function _(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)}function v(){return{name:`dynamic-experiences`,setup:t=>({onStart:(0,e.attach)({source:t.session.store.map(e=>e.id),effect:async e=>{let n=d(t),r=n!==void 0,i=n===void 0?void 0:{previewToken:n},a=await t.getProjectConfig(n===void 0?void 0:{previewToken:n}).catch(e=>null);if(t.contentLoader=g(t,_(e=>t.getExperienceContent(e,i),a)),!a)return;let o=t.seededVersionId;if(o!==null&&o!==a.versionId){t.versionSkew={seeded:o,resolved:a.versionId},`${a.versionId}${o}`;return}t.previewEmbedderOrigins=a.previewEmbedderOrigins??null,u(t,a,{isPreview:r,sessionId:e})}})})}}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return v}});
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import "./logger-DMN6TxJJ.js";
|
|
2
|
+
import { attach as e } from "effector";
|
|
3
|
+
//#region src/plugins/dynamic-experiences/hash.ts
|
|
4
|
+
function t(e) {
|
|
5
|
+
let t = 2166136261;
|
|
6
|
+
for (let n of e) t ^= n.codePointAt(0) ?? 0, t = Math.imul(t, 16777619);
|
|
7
|
+
return t >>> 0;
|
|
8
|
+
}
|
|
9
|
+
function n(e) {
|
|
10
|
+
let t = e;
|
|
11
|
+
return t ^= t >>> 16, t = Math.imul(t, 2246822507), t ^= t >>> 13, t = Math.imul(t, 3266489909), t ^= t >>> 16, t >>> 0;
|
|
12
|
+
}
|
|
13
|
+
function r(e, r) {
|
|
14
|
+
return n(t(`${e}:${r}`)) % 100;
|
|
15
|
+
}
|
|
16
|
+
function i(e, t) {
|
|
17
|
+
return t <= 0 ? !1 : t >= 100 || e < t;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/plugins/dynamic-experiences/plugin.ts
|
|
21
|
+
function a(e, t) {
|
|
22
|
+
if (Array.isArray(t.conditions)) for (let n of t.conditions) e.registerCondition(n);
|
|
23
|
+
}
|
|
24
|
+
function o(e, t) {
|
|
25
|
+
e.registerExperience({
|
|
26
|
+
id: t.id,
|
|
27
|
+
key: t.key,
|
|
28
|
+
name: t.name,
|
|
29
|
+
targets: t.targets,
|
|
30
|
+
nodes: t.nodes,
|
|
31
|
+
edges: t.edges,
|
|
32
|
+
condition: t.condition,
|
|
33
|
+
initializeOpen: t.initializeOpen,
|
|
34
|
+
componentName: t.componentName
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function s(e, t) {
|
|
38
|
+
if (Array.isArray(t.fields)) for (let n of t.fields) e.registerField(n);
|
|
39
|
+
}
|
|
40
|
+
function c(e, t) {
|
|
41
|
+
if (!Array.isArray(t.steps)) return;
|
|
42
|
+
let n = new Map(t.fields.map((e) => [e.id, e.key]));
|
|
43
|
+
for (let r of t.steps) {
|
|
44
|
+
let t = [];
|
|
45
|
+
for (let e of r.fieldIds ?? []) {
|
|
46
|
+
let i = n.get(e);
|
|
47
|
+
if (i === void 0) {
|
|
48
|
+
`${r.key}${e}`;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
t.push(i);
|
|
52
|
+
}
|
|
53
|
+
let i = r.layoutContentId ? e.contents.getById(r.layoutContentId) : null;
|
|
54
|
+
e.registerStep({
|
|
55
|
+
id: r.id,
|
|
56
|
+
key: r.key,
|
|
57
|
+
name: r.name,
|
|
58
|
+
fieldKeys: t,
|
|
59
|
+
layoutName: r.layoutName,
|
|
60
|
+
...r.layoutContentId !== void 0 && {
|
|
61
|
+
layoutContentId: r.layoutContentId,
|
|
62
|
+
layoutContentStore: i
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function l(e, t) {
|
|
68
|
+
if (Array.isArray(t.experiences)) for (let n of t.experiences) o(e, n);
|
|
69
|
+
}
|
|
70
|
+
function u(e, t, n) {
|
|
71
|
+
p(e, t, n.isPreview, n.sessionId), a(e, t), s(e, t), c(e, t), l(e, t);
|
|
72
|
+
}
|
|
73
|
+
function d(e) {
|
|
74
|
+
let t = e.searchParams["preview-token"];
|
|
75
|
+
if (t && t.length > 0) return t[0];
|
|
76
|
+
}
|
|
77
|
+
function f(e) {
|
|
78
|
+
let t = /* @__PURE__ */ new Set(), n = e.searchParams.feature;
|
|
79
|
+
if (!n) return t;
|
|
80
|
+
for (let e of n) {
|
|
81
|
+
let n = e.indexOf(":");
|
|
82
|
+
n > 0 && t.add(e.substring(0, n));
|
|
83
|
+
}
|
|
84
|
+
return t;
|
|
85
|
+
}
|
|
86
|
+
function p(e, t, n, r) {
|
|
87
|
+
let i = f(e);
|
|
88
|
+
for (let a of t.features) i.has(a.id) || m(e, a, n, r);
|
|
89
|
+
}
|
|
90
|
+
function m(e, t, n, a) {
|
|
91
|
+
let o = r(a, t.id);
|
|
92
|
+
e.registerFeature(t.id, {
|
|
93
|
+
key: `v${t.version}`,
|
|
94
|
+
name: t.name,
|
|
95
|
+
enabled: t.enabled,
|
|
96
|
+
weight: t.weight,
|
|
97
|
+
storage: n ? "session" : "local",
|
|
98
|
+
decide: () => i(o, t.weight)
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function h(e, t) {
|
|
102
|
+
for (let n of t.content) e.registerContent({
|
|
103
|
+
id: n.id,
|
|
104
|
+
contentModelKey: n.contentModelKey,
|
|
105
|
+
data: n.data
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function g(e, t) {
|
|
109
|
+
let n = /* @__PURE__ */ new Map();
|
|
110
|
+
return (r, i) => {
|
|
111
|
+
let a = n.get(r.id);
|
|
112
|
+
if (a) return a;
|
|
113
|
+
let o = (async () => {
|
|
114
|
+
try {
|
|
115
|
+
let n = await t(r, i);
|
|
116
|
+
return n && h(e, n), n;
|
|
117
|
+
} finally {
|
|
118
|
+
n.delete(r.id);
|
|
119
|
+
}
|
|
120
|
+
})();
|
|
121
|
+
return n.set(r.id, o), o;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function _(e, t) {
|
|
125
|
+
let n = new Set(t && Array.isArray(t.experiences) ? t.experiences.map((e) => e.id) : []);
|
|
126
|
+
return (t, r) => n.has(t.id) ? e(t, r) : Promise.resolve(null);
|
|
127
|
+
}
|
|
128
|
+
function v() {
|
|
129
|
+
return {
|
|
130
|
+
name: "dynamic-experiences",
|
|
131
|
+
setup: (t) => ({ onStart: e({
|
|
132
|
+
source: t.session.store.map((e) => e.id),
|
|
133
|
+
effect: async (e) => {
|
|
134
|
+
let n = d(t), r = n !== void 0, i = n === void 0 ? void 0 : { previewToken: n }, a = await t.getProjectConfig(n === void 0 ? void 0 : { previewToken: n }).catch((e) => null);
|
|
135
|
+
if (t.contentLoader = g(t, _((e) => t.getExperienceContent(e, i), a)), !a) return;
|
|
136
|
+
let o = t.seededVersionId;
|
|
137
|
+
if (o !== null && o !== a.versionId) {
|
|
138
|
+
t.versionSkew = {
|
|
139
|
+
seeded: o,
|
|
140
|
+
resolved: a.versionId
|
|
141
|
+
}, `${a.versionId}${o}`;
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
t.previewEmbedderOrigins = a.previewEmbedderOrigins ?? null, u(t, a, {
|
|
145
|
+
isPreview: r,
|
|
146
|
+
sessionId: e
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}) })
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
export { u as n, v as t };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import "./logger-DMN6TxJJ.js";
|
|
2
|
+
//#region src/utils/client-headers.ts
|
|
3
|
+
var e = "Picked-Client", t = "Picked-Version";
|
|
4
|
+
function n(n, r) {
|
|
5
|
+
return {
|
|
6
|
+
[e]: n,
|
|
7
|
+
[t]: r
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/utils/version.ts
|
|
12
|
+
var r = () => "0.0.1-dev.1786065500148", i = "v1";
|
|
13
|
+
function a(e, t) {
|
|
14
|
+
return new URL(`/api/${i}/${t}`, e).toString();
|
|
15
|
+
}
|
|
16
|
+
function o(e) {
|
|
17
|
+
return {
|
|
18
|
+
...n("sdk", r()),
|
|
19
|
+
...e
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async function s(e, t, n, r) {
|
|
23
|
+
let i = a(e, t);
|
|
24
|
+
return fetch(i, {
|
|
25
|
+
headers: o(n),
|
|
26
|
+
signal: r
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async function c(e, t, n, r) {
|
|
30
|
+
let i = a(e, t);
|
|
31
|
+
return fetch(i, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: {
|
|
34
|
+
"Content-Type": "application/json",
|
|
35
|
+
...o(r)
|
|
36
|
+
},
|
|
37
|
+
body: JSON.stringify(n)
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function l(e) {
|
|
41
|
+
return typeof e == "object" && !!e;
|
|
42
|
+
}
|
|
43
|
+
function u(e) {
|
|
44
|
+
return l(e) && "features" in e && Array.isArray(e.features);
|
|
45
|
+
}
|
|
46
|
+
function d(e) {
|
|
47
|
+
return !l(e) || !("experienceId" in e) || !("content" in e) ? !1 : Array.isArray(e.content);
|
|
48
|
+
}
|
|
49
|
+
function f(e) {
|
|
50
|
+
try {
|
|
51
|
+
let t = new URL(e).hostname;
|
|
52
|
+
return t === "localhost" || t === "127.0.0.1" || t === "::1";
|
|
53
|
+
} catch {
|
|
54
|
+
return !1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function p(e) {
|
|
58
|
+
if (!l(e) || !("cause" in e)) return !1;
|
|
59
|
+
let { cause: t } = e;
|
|
60
|
+
return !l(t) || !("code" in t) ? !1 : t.code === "ECONNREFUSED";
|
|
61
|
+
}
|
|
62
|
+
async function m(e, t, n) {
|
|
63
|
+
let r = n?.previewToken ? `projects/${t}?preview_token=${encodeURIComponent(n.previewToken)}` : `projects/${t}`, i;
|
|
64
|
+
try {
|
|
65
|
+
i = await s(e, r, n?.headers, n?.signal);
|
|
66
|
+
} catch (t) {
|
|
67
|
+
return f(e) && p(t), null;
|
|
68
|
+
}
|
|
69
|
+
if (!i.ok) return `${i.status.toString()}`, null;
|
|
70
|
+
let a;
|
|
71
|
+
try {
|
|
72
|
+
a = await i.json();
|
|
73
|
+
} catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
return u(a) ? a : null;
|
|
77
|
+
}
|
|
78
|
+
async function h(e, t, n, r) {
|
|
79
|
+
let i = r?.previewToken ? `projects/${t}/experiences/${n}/content?preview_token=${encodeURIComponent(r.previewToken)}` : `projects/${t}/experiences/${n}/content`, a;
|
|
80
|
+
try {
|
|
81
|
+
a = await s(e, i, r?.headers, r?.signal);
|
|
82
|
+
} catch (t) {
|
|
83
|
+
return f(e) && p(t) || `${n}`, null;
|
|
84
|
+
}
|
|
85
|
+
if (!a.ok) return `${n}${a.status.toString()}`, null;
|
|
86
|
+
let o;
|
|
87
|
+
try {
|
|
88
|
+
o = await a.json();
|
|
89
|
+
} catch {
|
|
90
|
+
return `${n}`, null;
|
|
91
|
+
}
|
|
92
|
+
return d(o) ? o : (`${n}`, null);
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/data-source/virtual-data.ts
|
|
96
|
+
function g(e) {
|
|
97
|
+
if (typeof e != "object" || !e || !("projectConfig" in e) || !("experienceContent" in e) || !("manifestMetadata" in e)) return !1;
|
|
98
|
+
let { experienceContent: t } = e;
|
|
99
|
+
return typeof t == "function";
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/data-source/registry.ts
|
|
103
|
+
var _ = null;
|
|
104
|
+
function v(e) {
|
|
105
|
+
g(e) && (_ = e);
|
|
106
|
+
}
|
|
107
|
+
function y() {
|
|
108
|
+
return _;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
export { m as a, n as c, h as i, v as n, c as o, g as r, r as s, y as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require("./logger-CSTvAyyB.cjs");var e=`Picked-Client`,t=`Picked-Version`;function n(n,r){return{[e]:n,[t]:r}}var r=()=>`0.0.1-dev.1786065500148`,i=`v1`;function a(e,t){return new URL(`/api/${i}/${t}`,e).toString()}function o(e){return{...n(`sdk`,r()),...e}}async function s(e,t,n,r){let i=a(e,t);return fetch(i,{headers:o(n),signal:r})}async function c(e,t,n,r){let i=a(e,t);return fetch(i,{method:`POST`,headers:{"Content-Type":`application/json`,...o(r)},body:JSON.stringify(n)})}function l(e){return typeof e==`object`&&!!e}function u(e){return l(e)&&`features`in e&&Array.isArray(e.features)}function d(e){return!l(e)||!(`experienceId`in e)||!(`content`in e)?!1:Array.isArray(e.content)}function f(e){try{let t=new URL(e).hostname;return t===`localhost`||t===`127.0.0.1`||t===`::1`}catch{return!1}}function p(e){if(!l(e)||!(`cause`in e))return!1;let{cause:t}=e;return!l(t)||!(`code`in t)?!1:t.code===`ECONNREFUSED`}async function m(e,t,n){let r=n?.previewToken?`projects/${t}?preview_token=${encodeURIComponent(n.previewToken)}`:`projects/${t}`,i;try{i=await s(e,r,n?.headers,n?.signal)}catch(t){return f(e)&&p(t),null}if(!i.ok)return`${i.status.toString()}`,null;let a;try{a=await i.json()}catch{return null}return u(a)?a:null}async function h(e,t,n,r){let i=r?.previewToken?`projects/${t}/experiences/${n}/content?preview_token=${encodeURIComponent(r.previewToken)}`:`projects/${t}/experiences/${n}/content`,a;try{a=await s(e,i,r?.headers,r?.signal)}catch(t){return f(e)&&p(t)||`${n}`,null}if(!a.ok)return`${n}${a.status.toString()}`,null;let o;try{o=await a.json()}catch{return`${n}`,null}return d(o)?o:(`${n}`,null)}function g(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`}var _=null;function v(e){g(e)&&(_=e)}function y(){return _}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return y}});
|
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
import type { ContentLoader, ExperienceContentResponse, PickedManifestMetadata, ProjectConfig, VirtualPickedData } from '../plugins/dynamic-experiences/types';
|
|
2
|
+
import { isVirtualPickedData } from './virtual-data';
|
|
2
3
|
/** Where a data provider reads project config and CMS content from. */
|
|
3
4
|
export type PickedDataMode = 'bundle' | 'api';
|
|
4
5
|
/** Options for {@link createPickedDataProvider}. */
|
|
5
6
|
export interface PickedDataProviderOptions {
|
|
6
|
-
/** Base URL for the Picked API.
|
|
7
|
+
/** Base URL for the Picked API. Used by `'api'` mode and by every preview session. */
|
|
7
8
|
apiUrl: string;
|
|
8
9
|
/** Project ID to resolve data for. */
|
|
9
10
|
projectId: string;
|
|
10
11
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
|
|
12
|
+
* Which source to read from. Omit to keep the legacy behaviour: `'bundle'` when
|
|
13
|
+
* `virtual:picked/data` resolves, `'api'` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
mode?: PickedDataMode;
|
|
16
|
+
/**
|
|
17
|
+
* Preview token from the current session. A present token forces `'api'` for both config
|
|
18
|
+
* and content and overrides `bundle` and `projectConfig`, because preview renders
|
|
19
|
+
* unpublished data that no bundled snapshot can contain.
|
|
14
20
|
*/
|
|
15
21
|
previewToken?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The `virtual:picked/data` module. Supply it to skip the dynamic import — which is also
|
|
24
|
+
* how a consumer places the module in a chosen chunk, since a module that is both
|
|
25
|
+
* statically and dynamically imported is placed in the static chunk. A value that does not
|
|
26
|
+
* match the module's shape is ignored with a warning, the same as an unresolvable import.
|
|
27
|
+
*/
|
|
28
|
+
bundle?: VirtualPickedData;
|
|
16
29
|
/** Explicit project config. Supersedes both sources, except under a preview token. */
|
|
17
30
|
projectConfig?: ProjectConfig;
|
|
18
31
|
/** Explicit content loader. Supersedes both sources, except under a preview token. */
|
|
@@ -37,6 +50,8 @@ export interface PickedDataProvider {
|
|
|
37
50
|
getContent: (experience: {
|
|
38
51
|
id: string;
|
|
39
52
|
key: string;
|
|
53
|
+
}, options?: {
|
|
54
|
+
signal?: AbortSignal;
|
|
40
55
|
}) => Promise<ExperienceContentResponse | null>;
|
|
41
56
|
}
|
|
42
57
|
/**
|
|
@@ -60,17 +75,7 @@ export interface PickedDataProvider {
|
|
|
60
75
|
* ```
|
|
61
76
|
*/
|
|
62
77
|
export declare function resolveVirtualDataModule(): Promise<VirtualPickedData | null>;
|
|
63
|
-
|
|
64
|
-
* Runtime type guard that validates the shape of an imported `virtual:picked/data` module.
|
|
65
|
-
*
|
|
66
|
-
* @param {unknown} value - Candidate module exports.
|
|
67
|
-
* @returns {boolean} Whether `value` matches the {@link VirtualPickedData} shape.
|
|
68
|
-
* @example
|
|
69
|
-
* ```typescript
|
|
70
|
-
* if (isVirtualPickedData(mod)) { useVirtualModule(mod) }
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
export declare function isVirtualPickedData(value: unknown): value is VirtualPickedData;
|
|
78
|
+
export { isVirtualPickedData };
|
|
74
79
|
/**
|
|
75
80
|
* Creates the data provider for a session.
|
|
76
81
|
*
|
|
@@ -78,7 +83,7 @@ export declare function isVirtualPickedData(value: unknown): value is VirtualPic
|
|
|
78
83
|
* @returns {PickedDataProvider} A provider resolving config and content from one source.
|
|
79
84
|
* @example
|
|
80
85
|
* ```typescript
|
|
81
|
-
* const provider = createPickedDataProvider({ apiUrl, projectId })
|
|
86
|
+
* const provider = createPickedDataProvider({ mode: 'api', apiUrl, projectId })
|
|
82
87
|
* const config = await provider.getProjectConfig()
|
|
83
88
|
* ```
|
|
84
89
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/data-source/provider.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,aAAa,EACb,yBAAyB,EACzB,sBAAsB,EACtB,aAAa,EACb,iBAAiB,EAClB,MAAM,sCAAsC,CAAA;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/data-source/provider.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,aAAa,EACb,yBAAyB,EACzB,sBAAsB,EACtB,aAAa,EACb,iBAAiB,EAClB,MAAM,sCAAsC,CAAA;AAG7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,uEAAuE;AACvE,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,KAAK,CAAA;AAQ7C,oDAAoD;AACpD,MAAM,WAAW,yBAAyB;IACxC,sFAAsF;IACtF,MAAM,EAAE,MAAM,CAAA;IACd,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,IAAI,CAAC,EAAE,cAAc,CAAA;IACrB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,sFAAsF;IACtF,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B,sFAAsF;IACtF,UAAU,CAAC,EAAE,aAAa,CAAA;IAC1B,sFAAsF;IACtF,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED,4DAA4D;AAC5D,MAAM,WAAW,sBAAsB;IACrC,yDAAyD;IACzD,IAAI,EAAE,cAAc,CAAA;IACpB,gFAAgF;IAChF,QAAQ,EAAE,sBAAsB,GAAG,IAAI,CAAA;CACxC;AAED,6EAA6E;AAC7E,MAAM,WAAW,kBAAkB;IACjC,wFAAwF;IACxF,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAA;IACrC,4FAA4F;IAC5F,gBAAgB,EAAE,MAAM,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAA;IACrD,oGAAoG;IACpG,UAAU,EAAE,CACV,UAAU,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EACvC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,KAC/B,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAAA;CAC/C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAYlF;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA;AA0B9B;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,kBAAkB,CAwK/F"}
|
|
@@ -1,36 +1,27 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file The registry the generated `virtual:picked/data` module writes itself into.
|
|
3
|
-
*
|
|
4
|
-
* `@picked/vite-plugin-picked` emits a module whose last statement calls
|
|
5
|
-
* `registerPickedBundle`. That call is a real side effect, so a bare
|
|
6
|
-
* `import 'virtual:picked/data'` in a consumer's client entry survives tree-shaking and places
|
|
7
|
-
* the data chunk in the static graph — which is what earns it a `modulepreload` from a
|
|
8
|
-
* framework's own build manifest. The same call hands the bundle over synchronously, so
|
|
9
|
-
* resolving project config costs no dynamic import.
|
|
10
|
-
*
|
|
11
|
-
* Import-time cost is a single binding declaration, which keeps the core module free of
|
|
12
|
-
* import-time side effects.
|
|
13
|
-
*/
|
|
14
1
|
import type { VirtualPickedData } from '../plugins/dynamic-experiences/types';
|
|
15
2
|
/**
|
|
16
|
-
* Records the bundle
|
|
3
|
+
* Records the bundle the build generated, for this session's data provider to read.
|
|
4
|
+
*
|
|
5
|
+
* A value that does not match the module shape is refused rather than stored, so a malformed
|
|
6
|
+
* registration lands on the already-defined "no bundle" path instead of an undefined read at
|
|
7
|
+
* the first content resolution. Any usable bundle registered earlier is kept.
|
|
17
8
|
*
|
|
18
|
-
* @param {
|
|
9
|
+
* @param {unknown} bundle - The generated module's exports.
|
|
19
10
|
* @returns {void} Nothing.
|
|
20
11
|
* @example
|
|
21
12
|
* ```typescript
|
|
22
13
|
* registerPickedBundle({ projectConfig, experienceContent, manifestMetadata })
|
|
23
14
|
* ```
|
|
24
15
|
*/
|
|
25
|
-
export declare function registerPickedBundle(bundle:
|
|
16
|
+
export declare function registerPickedBundle(bundle: unknown): void;
|
|
26
17
|
/**
|
|
27
|
-
* Reads the bundle
|
|
18
|
+
* Reads the registered bundle.
|
|
28
19
|
*
|
|
29
|
-
* @returns {VirtualPickedData |
|
|
20
|
+
* @returns {VirtualPickedData | null} The bundle, or `null` when nothing has registered one.
|
|
30
21
|
* @example
|
|
31
22
|
* ```typescript
|
|
32
|
-
* const bundle =
|
|
23
|
+
* const bundle = readRegisteredBundle()
|
|
33
24
|
* ```
|
|
34
25
|
*/
|
|
35
|
-
export declare function
|
|
26
|
+
export declare function readRegisteredBundle(): VirtualPickedData | null;
|
|
36
27
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/data-source/registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/data-source/registry.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AAK7E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAQ1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,IAAI,iBAAiB,GAAG,IAAI,CAE/D"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The shape guard for the generated `virtual:picked/data` module.
|
|
3
|
+
*
|
|
4
|
+
* Lives apart from the provider and the registry because both validate against it, and a guard
|
|
5
|
+
* shared by two modules that also reference each other would otherwise close an import cycle.
|
|
6
|
+
*/
|
|
7
|
+
import type { VirtualPickedData } from '../plugins/dynamic-experiences/types';
|
|
8
|
+
/**
|
|
9
|
+
* Runtime type guard that validates the shape of a `virtual:picked/data` module.
|
|
10
|
+
*
|
|
11
|
+
* @param {unknown} value - Candidate module exports.
|
|
12
|
+
* @returns {boolean} Whether `value` matches the {@link VirtualPickedData} shape.
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* if (isVirtualPickedData(mod)) { useVirtualModule(mod) }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function isVirtualPickedData(value: unknown): value is VirtualPickedData;
|
|
19
|
+
//# sourceMappingURL=virtual-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtual-data.d.ts","sourceRoot":"","sources":["../../../src/data-source/virtual-data.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AAE7E;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB,CAU9E"}
|