@picked/client 0.0.70-next.4 → 0.0.70-next.6
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/{api-K1zSYLAz.cjs → api-CoUkIxIr.cjs} +1 -1
- package/dist/{api-2Dfw4cZJ.js → api-ahdSBQ3Y.js} +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/features.mdx +27 -13
- package/dist/docs/sdk/feature-allocation.md +16 -16
- package/dist/docs/sdk/features.md +30 -30
- package/dist/esm/index.js +272 -243
- package/dist/esm/plugins/dynamic-experiences/index.js +2 -2
- package/dist/esm/server/index.js +1 -1
- package/dist/{plugin-BIHbKsf7.js → plugin-BxMR7fOV.js} +58 -53
- package/dist/plugin-CASdGtTX.cjs +1 -0
- package/dist/types/entities/feature/feature.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/hash.d.ts +40 -5
- package/dist/types/plugins/dynamic-experiences/hash.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
- package/dist/types/utils/rehydrate-scripts.d.ts +6 -0
- package/dist/types/utils/rehydrate-scripts.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/plugin-C9epZ61H.cjs +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as e } from "../../../api-
|
|
2
|
-
import { n as t, r as n, t as r } from "../../../plugin-
|
|
1
|
+
import { i as e } from "../../../api-ahdSBQ3Y.js";
|
|
2
|
+
import { n as t, r as n, t as r } from "../../../plugin-BxMR7fOV.js";
|
|
3
3
|
export { e as createClientHeaders, r as dynamicExperiencesPlugin, t as fetchExperienceContent, n as fetchProject };
|
package/dist/esm/server/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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-DOJShRk5.js";
|
|
2
|
-
import { i as s, n as c } from "../../plugin-
|
|
2
|
+
import { i as s, n as c } from "../../plugin-BxMR7fOV.js";
|
|
3
3
|
import { attach as l, createEffect as u, createEvent as d, createStore as f, sample as p } from "effector";
|
|
4
4
|
//#region src/server/serialize.ts
|
|
5
5
|
var m = 1e4;
|
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
import "./logger-DMN6TxJJ.js";
|
|
2
|
-
import { t as e } from "./api-
|
|
2
|
+
import { t as e } from "./api-ahdSBQ3Y.js";
|
|
3
3
|
import { attach as t } from "effector";
|
|
4
4
|
//#region src/plugins/dynamic-experiences/hash.ts
|
|
5
5
|
function n(e) {
|
|
6
6
|
let t = 2166136261;
|
|
7
|
-
for (let n
|
|
7
|
+
for (let n of e) t ^= n.codePointAt(0) ?? 0, t = Math.imul(t, 16777619);
|
|
8
8
|
return t >>> 0;
|
|
9
9
|
}
|
|
10
10
|
function r(e) {
|
|
11
|
-
|
|
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;
|
|
12
13
|
}
|
|
13
14
|
function i(e, t) {
|
|
15
|
+
return r(n(`${e}:${t}`)) % 100;
|
|
16
|
+
}
|
|
17
|
+
function a(e, t) {
|
|
14
18
|
return t <= 0 ? !1 : t >= 100 ? !0 : e < t;
|
|
15
19
|
}
|
|
16
20
|
//#endregion
|
|
17
21
|
//#region src/plugins/dynamic-experiences/plugin.ts
|
|
18
|
-
function
|
|
22
|
+
function o(e) {
|
|
19
23
|
return typeof e == "object" && !!e && "features" in e && Array.isArray(e.features);
|
|
20
24
|
}
|
|
21
|
-
function
|
|
25
|
+
function s(e, t) {
|
|
22
26
|
if (Array.isArray(t.conditions)) for (let n of t.conditions) e.registerCondition(n);
|
|
23
27
|
}
|
|
24
|
-
function
|
|
28
|
+
function c(e, t) {
|
|
25
29
|
e.registerExperience({
|
|
26
30
|
id: t.id,
|
|
27
31
|
key: t.key,
|
|
@@ -34,10 +38,10 @@ function s(e, t) {
|
|
|
34
38
|
componentName: t.componentName
|
|
35
39
|
});
|
|
36
40
|
}
|
|
37
|
-
function
|
|
41
|
+
function l(e, t) {
|
|
38
42
|
if (Array.isArray(t.fields)) for (let n of t.fields) e.registerField(n);
|
|
39
43
|
}
|
|
40
|
-
function
|
|
44
|
+
function u(e, t) {
|
|
41
45
|
if (!Array.isArray(t.steps)) return;
|
|
42
46
|
let n = new Map(t.fields.map((e) => [e.id, e.key]));
|
|
43
47
|
for (let r of t.steps) {
|
|
@@ -64,17 +68,17 @@ function l(e, t) {
|
|
|
64
68
|
});
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
|
-
function
|
|
68
|
-
if (Array.isArray(t.experiences)) for (let n of t.experiences)
|
|
71
|
+
function d(e, t) {
|
|
72
|
+
if (Array.isArray(t.experiences)) for (let n of t.experiences) c(e, n);
|
|
69
73
|
}
|
|
70
|
-
function
|
|
71
|
-
|
|
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);
|
|
72
76
|
}
|
|
73
|
-
function
|
|
77
|
+
function p(e) {
|
|
74
78
|
let t = e.searchParams["preview-token"];
|
|
75
79
|
if (t && t.length > 0) return t[0];
|
|
76
80
|
}
|
|
77
|
-
function
|
|
81
|
+
function m(e) {
|
|
78
82
|
let t = /* @__PURE__ */ new Set(), n = e.searchParams.feature;
|
|
79
83
|
if (!n) return t;
|
|
80
84
|
for (let e of n) {
|
|
@@ -83,21 +87,22 @@ function p(e) {
|
|
|
83
87
|
}
|
|
84
88
|
return t;
|
|
85
89
|
}
|
|
86
|
-
function m(e, t, n, i) {
|
|
87
|
-
let a = p(e), o = r(i);
|
|
88
|
-
for (let r of t.features) a.has(r.id) || h(e, r, n, o);
|
|
89
|
-
}
|
|
90
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);
|
|
91
96
|
e.registerFeature(t.id, {
|
|
92
97
|
key: `v${t.version}`,
|
|
93
98
|
name: t.name,
|
|
94
99
|
enabled: t.enabled,
|
|
95
100
|
weight: t.weight,
|
|
96
101
|
storage: n ? "session" : "local",
|
|
97
|
-
decide: () =>
|
|
102
|
+
decide: () => a(o, t.weight)
|
|
98
103
|
});
|
|
99
104
|
}
|
|
100
|
-
function
|
|
105
|
+
function _(e) {
|
|
101
106
|
try {
|
|
102
107
|
let t = new URL(e).hostname;
|
|
103
108
|
return t === "localhost" || t === "127.0.0.1" || t === "::1";
|
|
@@ -105,36 +110,36 @@ function g(e) {
|
|
|
105
110
|
return !1;
|
|
106
111
|
}
|
|
107
112
|
}
|
|
108
|
-
function
|
|
113
|
+
function v(e) {
|
|
109
114
|
if (typeof e != "object" || !e || !("cause" in e)) return !1;
|
|
110
115
|
let { cause: t } = e;
|
|
111
116
|
return typeof t != "object" || !t || !("code" in t) ? !1 : t.code === "ECONNREFUSED";
|
|
112
117
|
}
|
|
113
|
-
async function
|
|
114
|
-
let i = r?.previewToken ? `projects/${n}?preview_token=${encodeURIComponent(r.previewToken)}` : `projects/${n}`,
|
|
118
|
+
async function y(t, n, r) {
|
|
119
|
+
let i = r?.previewToken ? `projects/${n}?preview_token=${encodeURIComponent(r.previewToken)}` : `projects/${n}`, a;
|
|
115
120
|
try {
|
|
116
|
-
|
|
121
|
+
a = await e(t, i, r?.headers);
|
|
117
122
|
} catch (e) {
|
|
118
|
-
return
|
|
123
|
+
return _(t) && v(e), null;
|
|
119
124
|
}
|
|
120
|
-
if (!
|
|
125
|
+
if (!a.ok) return `${a.status.toString()}`, null;
|
|
121
126
|
let s;
|
|
122
127
|
try {
|
|
123
|
-
s = await
|
|
128
|
+
s = await a.json();
|
|
124
129
|
} catch {
|
|
125
130
|
return null;
|
|
126
131
|
}
|
|
127
|
-
return
|
|
132
|
+
return o(s) ? s : null;
|
|
128
133
|
}
|
|
129
|
-
function
|
|
134
|
+
function b(e) {
|
|
130
135
|
return typeof e != "object" || !e || !("experienceId" in e) || !("content" in e) ? !1 : Array.isArray(e.content);
|
|
131
136
|
}
|
|
132
|
-
async function
|
|
137
|
+
async function x(t, n, r, i) {
|
|
133
138
|
let a = i?.previewToken ? `projects/${n}/experiences/${r}/content?preview_token=${encodeURIComponent(i.previewToken)}` : `projects/${n}/experiences/${r}/content`, o;
|
|
134
139
|
try {
|
|
135
140
|
o = await e(t, a, i?.headers, i?.signal);
|
|
136
141
|
} catch (e) {
|
|
137
|
-
return
|
|
142
|
+
return _(t) && v(e) || `${r}`, null;
|
|
138
143
|
}
|
|
139
144
|
if (!o.ok) return `${r}${o.status.toString()}`, null;
|
|
140
145
|
let s;
|
|
@@ -143,38 +148,38 @@ async function b(t, n, r, i) {
|
|
|
143
148
|
} catch {
|
|
144
149
|
return `${r}`, null;
|
|
145
150
|
}
|
|
146
|
-
return
|
|
151
|
+
return b(s) ? s : (`${r}`, null);
|
|
147
152
|
}
|
|
148
|
-
function
|
|
153
|
+
function S(e, t) {
|
|
149
154
|
for (let n of t.content) e.registerContent({
|
|
150
155
|
id: n.id,
|
|
151
156
|
contentModelKey: n.contentModelKey,
|
|
152
157
|
data: n.data
|
|
153
158
|
});
|
|
154
159
|
}
|
|
155
|
-
function
|
|
160
|
+
function C(e) {
|
|
156
161
|
if (typeof e != "object" || !e || !("projectConfig" in e) || !("experienceContent" in e) || !("manifestMetadata" in e)) return !1;
|
|
157
162
|
let { experienceContent: t } = e;
|
|
158
163
|
return typeof t == "function";
|
|
159
164
|
}
|
|
160
|
-
async function
|
|
165
|
+
async function w() {
|
|
161
166
|
try {
|
|
162
167
|
let e = await import("virtual:picked/data");
|
|
163
|
-
return
|
|
168
|
+
return C(e) ? e : null;
|
|
164
169
|
} catch {
|
|
165
170
|
return null;
|
|
166
171
|
}
|
|
167
172
|
}
|
|
168
|
-
function
|
|
169
|
-
return (r) =>
|
|
173
|
+
function T(e, t, n) {
|
|
174
|
+
return (r) => x(e, t, r.id, n ? { previewToken: n } : void 0);
|
|
170
175
|
}
|
|
171
|
-
function
|
|
176
|
+
function E(e, t) {
|
|
172
177
|
return (n) => e(n, t ? { previewToken: t } : void 0);
|
|
173
178
|
}
|
|
174
|
-
function
|
|
179
|
+
function D(e) {
|
|
175
180
|
return (t, n) => e.experienceContent(t, n);
|
|
176
181
|
}
|
|
177
|
-
function
|
|
182
|
+
function O(e, t) {
|
|
178
183
|
let n = /* @__PURE__ */ new Map();
|
|
179
184
|
return (r, i) => {
|
|
180
185
|
let a = n.get(r.id);
|
|
@@ -182,7 +187,7 @@ function D(e, t) {
|
|
|
182
187
|
let o = (async () => {
|
|
183
188
|
try {
|
|
184
189
|
let n = await t(r, i);
|
|
185
|
-
return n &&
|
|
190
|
+
return n && S(e, n), n;
|
|
186
191
|
} finally {
|
|
187
192
|
n.delete(r.id);
|
|
188
193
|
}
|
|
@@ -190,13 +195,13 @@ function D(e, t) {
|
|
|
190
195
|
return n.set(r.id, o), o;
|
|
191
196
|
};
|
|
192
197
|
}
|
|
193
|
-
function
|
|
198
|
+
function k(e, t) {
|
|
194
199
|
let n = new Set(t && Array.isArray(t.experiences) ? t.experiences.map((e) => e.id) : []);
|
|
195
200
|
return (t, r) => n.has(t.id) ? e(t, r) : Promise.resolve(null);
|
|
196
201
|
}
|
|
197
|
-
async function
|
|
198
|
-
let { client: t, apiUrl: n, options: r } = e, i =
|
|
199
|
-
if (i) return o ??= await
|
|
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), {
|
|
200
205
|
config: o,
|
|
201
206
|
contentLoader: s,
|
|
202
207
|
dataSource: c,
|
|
@@ -208,20 +213,20 @@ async function k(e) {
|
|
|
208
213
|
dataSource: c,
|
|
209
214
|
isPreview: a
|
|
210
215
|
};
|
|
211
|
-
let l = await
|
|
212
|
-
return l ? (o ??= l.projectConfig, s ??=
|
|
216
|
+
let l = await w();
|
|
217
|
+
return l ? (o ??= l.projectConfig, s ??= D(l), c = l.manifestMetadata, {
|
|
213
218
|
config: o,
|
|
214
219
|
contentLoader: s,
|
|
215
220
|
dataSource: c,
|
|
216
221
|
isPreview: a
|
|
217
|
-
}) : (o ??= await
|
|
222
|
+
}) : (o ??= await y(n, t.projectId), s ??= T(n, t.projectId), {
|
|
218
223
|
config: o,
|
|
219
224
|
contentLoader: s,
|
|
220
225
|
dataSource: c,
|
|
221
226
|
isPreview: a
|
|
222
227
|
});
|
|
223
228
|
}
|
|
224
|
-
function
|
|
229
|
+
function j(e) {
|
|
225
230
|
return {
|
|
226
231
|
name: "dynamic-experiences",
|
|
227
232
|
setup: (n) => {
|
|
@@ -229,12 +234,12 @@ function A(e) {
|
|
|
229
234
|
return { onStart: t({
|
|
230
235
|
source: n.session.store.map((e) => e.id),
|
|
231
236
|
effect: async (t) => {
|
|
232
|
-
let { config: i, contentLoader: a, dataSource: o, isPreview: s } = await
|
|
237
|
+
let { config: i, contentLoader: a, dataSource: o, isPreview: s } = await A({
|
|
233
238
|
client: n,
|
|
234
239
|
apiUrl: r,
|
|
235
240
|
options: e
|
|
236
241
|
});
|
|
237
|
-
a && (n.contentLoader =
|
|
242
|
+
a && (n.contentLoader = O(n, k(a, i))), n.dataSource = o, i && (n.previewEmbedderOrigins = i.previewEmbedderOrigins ?? null, f(n, i, {
|
|
238
243
|
isPreview: s,
|
|
239
244
|
sessionId: t
|
|
240
245
|
}));
|
|
@@ -244,4 +249,4 @@ function A(e) {
|
|
|
244
249
|
};
|
|
245
250
|
}
|
|
246
251
|
//#endregion
|
|
247
|
-
export {
|
|
252
|
+
export { f as i, x as n, y as r, j as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require("./logger-CSTvAyyB.cjs");const e=require("./api-CoUkIxIr.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?!0: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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../../../../src/entities/feature/feature.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,OAAO,EAQL,KAAK,aAAa,EAElB,KAAK,KAAK,EACX,MAAM,UAAU,CAAA;AAEjB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAI1C,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC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uBAAwB,SAAQ,iBAAiB;IAChE,UAAU,EAAE,KAAK,CAAA;IACjB,SAAS,EAAE,MAAM,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC,CAAA;CACnE;AAED,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,UAAU,EAAE,IAAI,CAAA;IAChB,SAAS,EAAE,MAAM;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAA;CAC1D;AAED,MAAM,MAAM,aAAa,GAAG,uBAAuB,GAAG,qBAAqB,CAAA;AAqB3E,QAAA,MAAM,yBAAyB,eAA8B;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE;;YAoBzC,MAAM;iBAAW,OAAO;;kBAwOvC,MAAM;sBAaF,MAAM;;sCAahB,MAAM,KAClB,KAAK,CAAC,MAAM,OAAO,CAAC,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC;CA6CrD,CAAA;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC,CAAC,CAAC,EAC1F,MAAM,EAAE,CAAC,GACR,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAE9C;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,EAAE,SAAS,OAAO,EAAE,UAAU,aAAa,SAEnF,CAAA"}
|
|
@@ -1,18 +1,53 @@
|
|
|
1
|
+
/** @file Deterministic, independent per-feature bucket allocation for A/B testing. */
|
|
1
2
|
/**
|
|
2
3
|
* FNV-1a 32-bit hash.
|
|
3
4
|
* Deterministic, fast, well-distributed for short strings.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} input - String to hash.
|
|
7
|
+
* @returns {number} Unsigned 32-bit hash.
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* fnv1a32('sess_1:winter-sale')
|
|
11
|
+
* ```
|
|
4
12
|
*/
|
|
5
13
|
export declare function fnv1a32(input: string): number;
|
|
6
14
|
/**
|
|
7
15
|
* Deterministic dice roll for A/B testing.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
16
|
+
*
|
|
17
|
+
* Returns a value 0–99 that is stable for a given session and feature. Seeding
|
|
18
|
+
* on the feature as well as the session keeps flags independent of one another:
|
|
19
|
+
* two flags at weight 50 each take half of sessions, and a quarter of sessions
|
|
20
|
+
* land in both. Independence rests on the avalanche in {@link fmix32}, not on
|
|
21
|
+
* the seed alone.
|
|
22
|
+
*
|
|
23
|
+
* The feature version keys the stored bucket rather than the roll, so
|
|
24
|
+
* publishing a new version re-runs `decide` against the current weight and an
|
|
25
|
+
* unchanged weight keeps the same audience.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} sessionId - Current session id, stable across page loads.
|
|
28
|
+
* @param {string} featureId - Feature the roll is for.
|
|
29
|
+
* @returns {number} A value in the range 0–99.
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const diceRoll = featureDiceRoll('sess_1', 'winter-sale')
|
|
33
|
+
* ```
|
|
10
34
|
*/
|
|
11
|
-
export declare function
|
|
35
|
+
export declare function featureDiceRoll(sessionId: string, featureId: string): number;
|
|
12
36
|
/**
|
|
13
37
|
* Whether the given dice roll falls within the feature's weight.
|
|
14
|
-
*
|
|
15
|
-
*
|
|
38
|
+
*
|
|
39
|
+
* Widening a weight admits sessions the narrower weight excluded and never
|
|
40
|
+
* evicts one already inside, so a rollout can ratchet up without re-bucketing
|
|
41
|
+
* anyone. The roll is per feature, so this describes one feature's own weight
|
|
42
|
+
* changing over time; two features at the same weight overlap by chance.
|
|
43
|
+
*
|
|
44
|
+
* @param {number} diceRoll - Roll from {@link featureDiceRoll}, 0–99.
|
|
45
|
+
* @param {number} weight - Feature weight, 0–100.
|
|
46
|
+
* @returns {boolean} Whether the session is allocated to the feature.
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* isAllocated(42, 50) // true
|
|
50
|
+
* ```
|
|
16
51
|
*/
|
|
17
52
|
export declare function isAllocated(diceRoll: number, weight: number): boolean;
|
|
18
53
|
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../../src/plugins/dynamic-experiences/hash.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../../src/plugins/dynamic-experiences/hash.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAEtF;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAY7C;AA8BD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAE5E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAUrE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/dynamic-experiences/plugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,cAAc,CAAA;AAI5D,OAAO,KAAK,EAEV,+BAA+B,EAC/B,yBAAyB,EACzB,mBAAmB,EACnB,aAAa,EAId,MAAM,SAAS,CAAA;AA4JhB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACjD,IAAI,CAMN;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/dynamic-experiences/plugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,cAAc,CAAA;AAI5D,OAAO,KAAK,EAEV,+BAA+B,EAC/B,yBAAyB,EACzB,mBAAmB,EACnB,aAAa,EAId,MAAM,SAAS,CAAA;AA4JhB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACjD,IAAI,CAMN;AAyJD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAmC/B;AAoBD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAsC3C;AA4QD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,+BAA+B,GAAG,MAAM,CAsC1F"}
|
|
@@ -22,6 +22,12 @@ declare global {
|
|
|
22
22
|
* inside a shadow tree, each inline script's own root is published on `globalThis.__pickedEmbedScriptRoot`
|
|
23
23
|
* while it runs, so shadow-scoped page scripts read `window.__pickedEmbedScriptRoot` to find their own root.
|
|
24
24
|
*
|
|
25
|
+
* Classic inline scripts are pre-parsed with the `Function` constructor and skipped only when that
|
|
26
|
+
* throws a `SyntaxError`, so a body that would blank the experience on insertion is logged and left
|
|
27
|
+
* inert. Any other failure says nothing about the body — a CSP omitting `'unsafe-eval'` throws an
|
|
28
|
+
* `EvalError` and Trusted Types throws a `TypeError` however well the body parses — so the script is
|
|
29
|
+
* injected unchanged and the page keeps working under those policies.
|
|
30
|
+
*
|
|
25
31
|
* This function intentionally references only globals and its own parameter, never the exported
|
|
26
32
|
* `PICKED_*` constants above, so {@link buildRehydrateBootstrap} can serialise it with `.toString()` for
|
|
27
33
|
* injection into a sandboxed iframe, where module imports are unavailable.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehydrate-scripts.d.ts","sourceRoot":"","sources":["../../../src/utils/rehydrate-scripts.ts"],"names":[],"mappings":"AAAA,mFAAmF;AAEnF,mGAAmG;AACnG,eAAO,MAAM,kBAAkB,kCAAkC,CAAA;AACjE,2GAA2G;AAC3G,eAAO,MAAM,yBAAyB,8BAA8B,CAAA;AACpE,sEAAsE;AACtE,eAAO,MAAM,oBAAoB,yBAAyB,CAAA;AAE1D,OAAO,CAAC,MAAM,CAAC;IACb;;;;OAIG;IACH,IAAI,uBAAuB,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,CAAA;CACrD;AAED
|
|
1
|
+
{"version":3,"file":"rehydrate-scripts.d.ts","sourceRoot":"","sources":["../../../src/utils/rehydrate-scripts.ts"],"names":[],"mappings":"AAAA,mFAAmF;AAEnF,mGAAmG;AACnG,eAAO,MAAM,kBAAkB,kCAAkC,CAAA;AACjE,2GAA2G;AAC3G,eAAO,MAAM,yBAAyB,8BAA8B,CAAA;AACpE,sEAAsE;AACtE,eAAO,MAAM,oBAAoB,yBAAyB,CAAA;AAE1D,OAAO,CAAC,MAAM,CAAC;IACb;;;;OAIG;IACH,IAAI,uBAAuB,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,CAAA;CACrD;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAoGtE;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD"}
|
package/package.json
CHANGED
package/dist/plugin-C9epZ61H.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
require("./logger-CSTvAyyB.cjs");const e=require("./api-K1zSYLAz.cjs");let t=require("effector");function n(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}function r(e){return n(e)%100}function i(e,t){return t<=0?!1:t>=100?!0:e<t}function a(e){return typeof e==`object`&&!!e&&`features`in e&&Array.isArray(e.features)}function o(e,t){if(Array.isArray(t.conditions))for(let n of t.conditions)e.registerCondition(n)}function s(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 c(e,t){if(Array.isArray(t.fields))for(let n of t.fields)e.registerField(n)}function l(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 u(e,t){if(Array.isArray(t.experiences))for(let n of t.experiences)s(e,n)}function d(e,t,n){m(e,t,n.isPreview,n.sessionId),o(e,t),c(e,t),l(e,t),u(e,t)}function f(e){let t=e.searchParams[`preview-token`];if(t&&t.length>0)return t[0]}function p(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 m(e,t,n,i){let a=p(e),o=r(i);for(let r of t.features)a.has(r.id)||h(e,r,n,o)}function h(e,t,n,r){e.registerFeature(t.id,{key:`v${t.version}`,name:t.name,enabled:t.enabled,weight:t.weight,storage:n?`session`:`local`,decide:()=>t.enabled?i(r,t.weight):!1})}function g(e){try{let t=new URL(e).hostname;return t===`localhost`||t===`127.0.0.1`||t===`::1`}catch{return!1}}function _(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 v(t,n,r){let i=r?.previewToken?`projects/${n}?preview_token=${encodeURIComponent(r.previewToken)}`:`projects/${n}`,o;try{o=await e.t(t,i,r?.headers)}catch(e){return g(t)&&_(e),null}if(!o.ok)return`${o.status.toString()}`,null;let s;try{s=await o.json()}catch{return null}return a(s)?s:null}function y(e){return typeof e!=`object`||!e||!(`experienceId`in e)||!(`content`in e)?!1:Array.isArray(e.content)}async function b(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 g(t)&&_(e)||`${r}`,null}if(!o.ok)return`${r}${o.status.toString()}`,null;let s;try{s=await o.json()}catch{return`${r}`,null}return y(s)?s:(`${r}`,null)}function x(e,t){for(let n of t.content)e.registerContent({id:n.id,contentModelKey:n.contentModelKey,data:n.data})}function S(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 C(){try{let e=await import(`virtual:picked/data`);return S(e)?e:null}catch{return null}}function w(e,t,n){return r=>b(e,t,r.id,n?{previewToken:n}:void 0)}function T(e,t){return n=>e(n,t?{previewToken:t}:void 0)}function E(e){return(t,n)=>e.experienceContent(t,n)}function D(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&&x(e,n),n}finally{n.delete(r.id)}})();return n.set(r.id,o),o}}function O(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 k(e){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;if(i)return o??=await v(n,t.projectId,{previewToken:i}),s??=w(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 C();return l?(o??=l.projectConfig,s??=E(l),c=l.manifestMetadata,{config:o,contentLoader:s,dataSource:c,isPreview:a}):(o??=await v(n,t.projectId),s??=w(n,t.projectId),{config:o,contentLoader:s,dataSource:c,isPreview:a})}function A(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 k({client:n,apiUrl:r,options:e});a&&(n.contentLoader=D(n,O(a,i))),n.dataSource=o,i&&(n.previewEmbedderOrigins=i.previewEmbedderOrigins??null,d(n,i,{isPreview:s,sessionId:t}))}})}}}}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return A}});
|