@picked/client 0.0.71 → 0.0.72-next.2
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/{api-CkWvU-fy.js → api-B8SVav6V.js} +1 -1
- package/dist/api-D9899KCk.cjs +1 -0
- 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/explanation/how-picked-works.md +25 -3
- package/dist/docs/reference/sdk/plugins/dynamic-experiences.md +50 -2
- package/dist/docs/reference/tools/vite-plugin.md +90 -8
- package/dist/esm/index.js +22 -1
- package/dist/esm/plugins/dynamic-experiences/index.js +4 -3
- package/dist/esm/server/index.js +43 -46
- package/dist/plugin-EFn9ALEF.cjs +1 -0
- package/dist/plugin-YytfMG0n.js +153 -0
- package/dist/provider-DmXJ58nW.cjs +1 -0
- package/dist/provider-GuxX7UDO.js +68 -0
- package/dist/registry-CMsN5pHn.cjs +1 -0
- package/dist/registry-DzpNnRIF.js +74 -0
- package/dist/types/data-source/api.d.ts +60 -0
- package/dist/types/data-source/api.d.ts.map +1 -0
- package/dist/types/data-source/provider.d.ts +90 -0
- package/dist/types/data-source/provider.d.ts.map +1 -0
- package/dist/types/data-source/registry.d.ts +26 -0
- package/dist/types/data-source/registry.d.ts.map +1 -0
- 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 +65 -1
- package/dist/types/picked.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 +9 -40
- package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/types.d.ts +15 -23
- 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 +21 -33
- package/dist/types/server/serialize.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/api-Du5sDt-A.cjs +0 -1
- package/dist/plugin-DaGxLHkq.js +0 -252
- package/dist/plugin-nhx7zYeB.cjs +0 -1
package/dist/api-Du5sDt-A.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function e(e,t){return{"Picked-Client":e,"Picked-Version":t}}var t=()=>`0.0.71`,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}});
|
package/dist/plugin-DaGxLHkq.js
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import "./logger-DMN6TxJJ.js";
|
|
2
|
-
import { t as e } from "./api-CkWvU-fy.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 };
|
package/dist/plugin-nhx7zYeB.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
require("./logger-CSTvAyyB.cjs");const e=require("./api-Du5sDt-A.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}});
|