@builder.io/sdk-react-nextjs 0.16.6 → 0.16.9
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/lib/browser/blocks-exports.cjs +30 -30
- package/lib/browser/blocks-exports.mjs +653 -620
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +2 -2
- package/lib/browser/init.cjs +2 -2
- package/lib/browser/init.mjs +20 -20
- package/lib/browser/server-entry-ed0910dd.cjs +2 -0
- package/lib/{node/server-entry-226d18cc.js → browser/server-entry-ff1eb217.js} +357 -355
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/blocks-exports.cjs +43 -43
- package/lib/edge/blocks-exports.mjs +1069 -1036
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +2 -2
- package/lib/edge/init.cjs +2 -2
- package/lib/edge/init.mjs +20 -20
- package/lib/edge/server-entry-ed0910dd.cjs +2 -0
- package/lib/{browser/server-entry-226d18cc.js → edge/server-entry-ff1eb217.js} +357 -355
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/node/blocks-exports.cjs +29 -29
- package/lib/node/blocks-exports.mjs +684 -651
- package/lib/node/index.cjs +1 -1
- package/lib/node/index.mjs +3 -3
- package/lib/node/init.cjs +1 -1
- package/lib/node/init.mjs +2 -2
- package/lib/node/{node-runtime-f354effa.cjs → node-runtime-3b9a05b3.cjs} +4 -4
- package/lib/node/{node-runtime-f79fed3b.js → node-runtime-606c2607.js} +3 -3
- package/lib/node/server-entry-ed0910dd.cjs +2 -0
- package/lib/{edge/server-entry-226d18cc.js → node/server-entry-ff1eb217.js} +357 -355
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +1 -1
- package/package.json +3 -3
- package/types/cjs/blocks/slot/slot.d.ts +2 -2
- package/types/cjs/components/block/block.helpers.d.ts +1 -2
- package/types/cjs/constants/sdk-version.d.ts +1 -1
- package/types/cjs/functions/evaluate/node-runtime/init.d.ts +1 -0
- package/types/cjs/functions/get-processed-block.d.ts +1 -0
- package/types/esm/blocks/slot/slot.d.ts +2 -2
- package/types/esm/components/block/block.helpers.d.ts +1 -2
- package/types/esm/constants/sdk-version.d.ts +1 -1
- package/types/esm/functions/evaluate/node-runtime/init.d.ts +1 -0
- package/types/esm/functions/get-processed-block.d.ts +1 -0
- package/lib/browser/server-entry-0418e1e6.cjs +0 -2
- package/lib/edge/server-entry-0418e1e6.cjs +0 -2
- package/lib/node/server-entry-0418e1e6.cjs +0 -2
|
@@ -53,12 +53,72 @@ const te = () => {
|
|
|
53
53
|
host: (r == null ? void 0 : r.host) || (r == null ? void 0 : r.hostname),
|
|
54
54
|
device: n ? "tablet" : t.any() ? "mobile" : "desktop"
|
|
55
55
|
};
|
|
56
|
-
}, m = (e) => e != null
|
|
56
|
+
}, m = (e) => e != null;
|
|
57
|
+
function ze(e) {
|
|
58
|
+
const t = e || (c() ? window.location.search : void 0);
|
|
59
|
+
return t ? U(t).indexOf("builder.preview=") !== -1 : !1;
|
|
60
|
+
}
|
|
61
|
+
const Xe = (e) => ({
|
|
62
|
+
type: "builder.registerComponent",
|
|
63
|
+
data: V(e)
|
|
64
|
+
}), oe = (e) => {
|
|
65
|
+
const t = e.toString().trim();
|
|
66
|
+
return `return (${!t.startsWith("function") && !t.startsWith("(") ? "function " : ""}${t}).apply(this, arguments)`;
|
|
67
|
+
};
|
|
68
|
+
function V(e) {
|
|
69
|
+
return JSON.parse(JSON.stringify(e, (t, n) => typeof n == "function" ? oe(n) : n));
|
|
70
|
+
}
|
|
71
|
+
const R = {};
|
|
72
|
+
function se(e, t) {
|
|
73
|
+
e === "plugin" && (t = V(t));
|
|
74
|
+
let n = R[e];
|
|
75
|
+
if (n || (n = R[e] = []), n.push(t), c()) {
|
|
76
|
+
const r = {
|
|
77
|
+
type: "builder.register",
|
|
78
|
+
data: {
|
|
79
|
+
type: e,
|
|
80
|
+
info: t
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
try {
|
|
84
|
+
parent.postMessage(r, "*"), parent !== window && window.postMessage(r, "*");
|
|
85
|
+
} catch (o) {
|
|
86
|
+
console.debug("Could not postmessage", o);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const x = {};
|
|
91
|
+
function qe(e) {
|
|
92
|
+
if (c()) {
|
|
93
|
+
Object.assign(x, e);
|
|
94
|
+
const t = {
|
|
95
|
+
type: "builder.settingsChange",
|
|
96
|
+
data: x
|
|
97
|
+
};
|
|
98
|
+
parent.postMessage(t, "*");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const A = "builder.", ie = "options.", M = (e) => {
|
|
102
|
+
if (!e)
|
|
103
|
+
return {};
|
|
104
|
+
const t = B(e), n = {};
|
|
105
|
+
return Object.keys(t).forEach((r) => {
|
|
106
|
+
if (r.startsWith(A)) {
|
|
107
|
+
const o = r.replace(A, "").replace(ie, "");
|
|
108
|
+
n[o] = t[r];
|
|
109
|
+
}
|
|
110
|
+
}), n;
|
|
111
|
+
}, ae = () => {
|
|
112
|
+
if (!c())
|
|
113
|
+
return {};
|
|
114
|
+
const e = new URLSearchParams(window.location.search);
|
|
115
|
+
return M(e);
|
|
116
|
+
}, ce = (e) => {
|
|
57
117
|
if (e === "localhost" || e === "127.0.0.1")
|
|
58
118
|
return e;
|
|
59
119
|
const t = e.split(".");
|
|
60
120
|
return t.length > 2 ? t.slice(1).join(".") : e;
|
|
61
|
-
},
|
|
121
|
+
}, _ = ({
|
|
62
122
|
name: e,
|
|
63
123
|
canTrack: t
|
|
64
124
|
}) => {
|
|
@@ -69,14 +129,14 @@ const te = () => {
|
|
|
69
129
|
l.warn("[COOKIE] GET error: ", (r == null ? void 0 : r.message) || r);
|
|
70
130
|
return;
|
|
71
131
|
}
|
|
72
|
-
},
|
|
132
|
+
}, F = async (e) => _(e), ue = (e) => e.map(([t, n]) => n ? `${t}=${n}` : t).filter(m).join("; "), de = [["secure", ""], ["SameSite", "None"]], le = ({
|
|
73
133
|
name: e,
|
|
74
134
|
value: t,
|
|
75
135
|
expires: n
|
|
76
136
|
}) => {
|
|
77
|
-
const o = (c() ? location.protocol === "https:" : !0) ?
|
|
78
|
-
return
|
|
79
|
-
},
|
|
137
|
+
const o = (c() ? location.protocol === "https:" : !0) ? de : [[]], s = n ? [["expires", n.toUTCString()]] : [[]], i = [[e, t], ...s, ["path", "/"], ["domain", ce(window.location.hostname)], ...o];
|
|
138
|
+
return ue(i);
|
|
139
|
+
}, N = async ({
|
|
80
140
|
name: e,
|
|
81
141
|
value: t,
|
|
82
142
|
expires: n,
|
|
@@ -85,7 +145,7 @@ const te = () => {
|
|
|
85
145
|
try {
|
|
86
146
|
if (!r)
|
|
87
147
|
return;
|
|
88
|
-
const o =
|
|
148
|
+
const o = le({
|
|
89
149
|
name: e,
|
|
90
150
|
value: t,
|
|
91
151
|
expires: n
|
|
@@ -94,350 +154,89 @@ const te = () => {
|
|
|
94
154
|
} catch (o) {
|
|
95
155
|
l.warn("[COOKIE] SET error: ", (o == null ? void 0 : o.message) || o);
|
|
96
156
|
}
|
|
97
|
-
}, ce = "builder.tests", k = (e) => `${ce}.${e}`, ue = ({
|
|
98
|
-
contentId: e
|
|
99
|
-
}) => M({
|
|
100
|
-
name: k(e),
|
|
101
|
-
canTrack: !0
|
|
102
|
-
}), de = ({
|
|
103
|
-
contentId: e
|
|
104
|
-
}) => V({
|
|
105
|
-
name: k(e),
|
|
106
|
-
canTrack: !0
|
|
107
|
-
}), le = ({
|
|
108
|
-
contentId: e,
|
|
109
|
-
value: t
|
|
110
|
-
}) => _({
|
|
111
|
-
name: k(e),
|
|
112
|
-
value: t,
|
|
113
|
-
canTrack: !0
|
|
114
|
-
}), F = (e) => m(e.id) && m(e.variations) && Object.keys(e.variations).length > 0, fe = ({
|
|
115
|
-
id: e,
|
|
116
|
-
variations: t
|
|
117
|
-
}) => {
|
|
118
|
-
var o;
|
|
119
|
-
let n = 0;
|
|
120
|
-
const r = Math.random();
|
|
121
|
-
for (const s in t) {
|
|
122
|
-
const i = (o = t[s]) == null ? void 0 : o.testRatio;
|
|
123
|
-
if (n += i, r < n)
|
|
124
|
-
return s;
|
|
125
|
-
}
|
|
126
|
-
return e;
|
|
127
|
-
}, N = (e) => {
|
|
128
|
-
const t = fe(e);
|
|
129
|
-
return le({
|
|
130
|
-
contentId: e.id,
|
|
131
|
-
value: t
|
|
132
|
-
}).catch((n) => {
|
|
133
|
-
l.error("could not store A/B test variation: ", n);
|
|
134
|
-
}), t;
|
|
135
|
-
}, D = ({
|
|
136
|
-
item: e,
|
|
137
|
-
testGroupId: t
|
|
138
|
-
}) => {
|
|
139
|
-
const n = e.variations[t];
|
|
140
|
-
return t === e.id || // handle edge-case where `testGroupId` points to non-existing variation
|
|
141
|
-
!n ? {
|
|
142
|
-
testVariationId: e.id,
|
|
143
|
-
testVariationName: "Default"
|
|
144
|
-
} : {
|
|
145
|
-
data: n.data,
|
|
146
|
-
testVariationId: n.id,
|
|
147
|
-
testVariationName: n.name || (n.id === e.id ? "Default" : "")
|
|
148
|
-
};
|
|
149
|
-
}, ze = ({
|
|
150
|
-
item: e,
|
|
151
|
-
canTrack: t
|
|
152
|
-
}) => {
|
|
153
|
-
if (!t)
|
|
154
|
-
return e;
|
|
155
|
-
if (!e)
|
|
156
|
-
return;
|
|
157
|
-
if (!F(e))
|
|
158
|
-
return e;
|
|
159
|
-
const n = de({
|
|
160
|
-
contentId: e.id
|
|
161
|
-
}) || N({
|
|
162
|
-
variations: e.variations,
|
|
163
|
-
id: e.id
|
|
164
|
-
}), r = D({
|
|
165
|
-
item: e,
|
|
166
|
-
testGroupId: n
|
|
167
|
-
});
|
|
168
|
-
return {
|
|
169
|
-
...e,
|
|
170
|
-
...r
|
|
171
|
-
};
|
|
172
|
-
}, he = async ({
|
|
173
|
-
item: e,
|
|
174
|
-
canTrack: t
|
|
175
|
-
}) => {
|
|
176
|
-
if (!t || !F(e))
|
|
177
|
-
return e;
|
|
178
|
-
const r = await ue({
|
|
179
|
-
contentId: e.id
|
|
180
|
-
}) || N({
|
|
181
|
-
variations: e.variations,
|
|
182
|
-
id: e.id
|
|
183
|
-
}), o = D({
|
|
184
|
-
item: e,
|
|
185
|
-
testGroupId: r
|
|
186
|
-
});
|
|
187
|
-
return {
|
|
188
|
-
...e,
|
|
189
|
-
...o
|
|
190
|
-
};
|
|
191
|
-
}, ge = (e) => m(e) ? e : !0, Xe = (e) => ({
|
|
192
|
-
type: "builder.registerComponent",
|
|
193
|
-
data: j(e)
|
|
194
|
-
}), pe = (e) => {
|
|
195
|
-
const t = e.toString().trim();
|
|
196
|
-
return `return (${!t.startsWith("function") && !t.startsWith("(") ? "function " : ""}${t}).apply(this, arguments)`;
|
|
197
|
-
};
|
|
198
|
-
function j(e) {
|
|
199
|
-
return JSON.parse(JSON.stringify(e, (t, n) => typeof n == "function" ? pe(n) : n));
|
|
200
|
-
}
|
|
201
|
-
const me = (e) => {
|
|
202
|
-
const t = e.get("preview"), n = e.get("overrides." + t);
|
|
203
|
-
return n || l.warn("No previewed ID found in search params."), n;
|
|
204
|
-
};
|
|
205
|
-
function ye() {
|
|
206
|
-
globalThis._BUILDER_PREVIEW_LRU_CACHE || (globalThis._BUILDER_PREVIEW_LRU_CACHE = new Q({
|
|
207
|
-
max: 500,
|
|
208
|
-
// how long to live in ms
|
|
209
|
-
ttl: 1e3 * 60 * 5
|
|
210
|
-
}));
|
|
211
|
-
}
|
|
212
|
-
function we(e) {
|
|
213
|
-
ye();
|
|
214
|
-
const t = me(e);
|
|
215
|
-
return typeof t == "string" ? globalThis._BUILDER_PREVIEW_LRU_CACHE.get(t) : void 0;
|
|
216
|
-
}
|
|
217
|
-
function Se() {
|
|
218
|
-
return typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : globalThis;
|
|
219
|
-
}
|
|
220
|
-
function be() {
|
|
221
|
-
const e = Se().fetch;
|
|
222
|
-
if (typeof e == "undefined")
|
|
223
|
-
throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
|
|
224
|
-
For more information, read https://github.com/BuilderIO/this-package-uses-fetch`), new Error("Builder SDK could not find a global `fetch` function");
|
|
225
|
-
return e;
|
|
226
|
-
}
|
|
227
|
-
const ve = be();
|
|
228
|
-
function E(e, t = null, n = ".") {
|
|
229
|
-
return Object.keys(e).reduce((r, o) => {
|
|
230
|
-
const s = e[o], i = [t, o].filter(Boolean).join(n);
|
|
231
|
-
return [typeof s == "object", s !== null, !(Array.isArray(s) && s.length === 0)].every(Boolean) ? {
|
|
232
|
-
...r,
|
|
233
|
-
...E(s, i, n)
|
|
234
|
-
} : {
|
|
235
|
-
...r,
|
|
236
|
-
[i]: s
|
|
237
|
-
};
|
|
238
|
-
}, {});
|
|
239
|
-
}
|
|
240
|
-
function K(e, t, n = {}) {
|
|
241
|
-
for (const r in e) {
|
|
242
|
-
const o = e[r], s = t ? t + "." + r : r;
|
|
243
|
-
o && typeof o == "object" && !Array.isArray(o) && !Object.keys(o).find((i) => i.startsWith("$")) ? K(o, s, n) : n[s] = o;
|
|
244
|
-
}
|
|
245
|
-
return n;
|
|
246
|
-
}
|
|
247
|
-
const Ie = "v3", R = "builder.", Ee = "options.", W = (e) => {
|
|
248
|
-
if (!e)
|
|
249
|
-
return {};
|
|
250
|
-
const t = B(e), n = {};
|
|
251
|
-
return Object.keys(t).forEach((r) => {
|
|
252
|
-
if (r.startsWith(R)) {
|
|
253
|
-
const o = r.replace(R, "").replace(Ee, "");
|
|
254
|
-
n[o] = t[r];
|
|
255
|
-
}
|
|
256
|
-
}), n;
|
|
257
|
-
}, ke = () => {
|
|
258
|
-
if (!c())
|
|
259
|
-
return {};
|
|
260
|
-
const e = new URLSearchParams(window.location.search);
|
|
261
|
-
return W(e);
|
|
262
|
-
}, x = (e) => typeof e == "number" && !isNaN(e) && e >= 0, P = (e) => {
|
|
263
|
-
const {
|
|
264
|
-
limit: t = 30,
|
|
265
|
-
userAttributes: n,
|
|
266
|
-
query: r,
|
|
267
|
-
model: o,
|
|
268
|
-
apiKey: s,
|
|
269
|
-
enrich: i,
|
|
270
|
-
locale: u,
|
|
271
|
-
apiVersion: y = Ie,
|
|
272
|
-
fields: p,
|
|
273
|
-
omit: I,
|
|
274
|
-
offset: d,
|
|
275
|
-
cacheSeconds: h,
|
|
276
|
-
staleCacheSeconds: g,
|
|
277
|
-
sort: w,
|
|
278
|
-
includeUnpublished: C
|
|
279
|
-
} = e;
|
|
280
|
-
if (!s)
|
|
281
|
-
throw new Error("Missing API key");
|
|
282
|
-
if (!["v3"].includes(y))
|
|
283
|
-
throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);
|
|
284
|
-
const X = t !== 1, a = new URL(`https://cdn.builder.io/api/${y}/content/${o}`);
|
|
285
|
-
if (a.searchParams.set("apiKey", s), a.searchParams.set("limit", String(t)), a.searchParams.set("noTraverse", String(X)), a.searchParams.set("includeRefs", String(!0)), u && a.searchParams.set("locale", u), i && a.searchParams.set("enrich", String(i)), a.searchParams.set("omit", I || "meta.componentsUsed"), p && a.searchParams.set("fields", p), Number.isFinite(d) && d > -1 && a.searchParams.set("offset", String(Math.floor(d))), typeof C == "boolean" && a.searchParams.set("includeUnpublished", String(C)), h && x(h) && a.searchParams.set("cacheSeconds", String(h)), g && x(g) && a.searchParams.set("staleCacheSeconds", String(g)), w) {
|
|
286
|
-
const f = E({
|
|
287
|
-
sort: w
|
|
288
|
-
});
|
|
289
|
-
for (const S in f)
|
|
290
|
-
a.searchParams.set(S, JSON.stringify(f[S]));
|
|
291
|
-
}
|
|
292
|
-
const q = {
|
|
293
|
-
...ke(),
|
|
294
|
-
...B(e.options || {})
|
|
295
|
-
}, O = E(q);
|
|
296
|
-
for (const f in O)
|
|
297
|
-
a.searchParams.set(f, String(O[f]));
|
|
298
|
-
if (n && a.searchParams.set("userAttributes", JSON.stringify(n)), r) {
|
|
299
|
-
const f = K({
|
|
300
|
-
query: r
|
|
301
|
-
});
|
|
302
|
-
for (const S in f)
|
|
303
|
-
a.searchParams.set(S, JSON.stringify(f[S]));
|
|
304
|
-
}
|
|
305
|
-
return a;
|
|
306
|
-
}, Pe = (e) => "results" in e;
|
|
307
|
-
async function Ce(e) {
|
|
308
|
-
const t = await xe({
|
|
309
|
-
...e,
|
|
310
|
-
limit: 1
|
|
311
|
-
});
|
|
312
|
-
return t && t[0] || null;
|
|
313
|
-
}
|
|
314
|
-
const Oe = async (e) => {
|
|
315
|
-
var s;
|
|
316
|
-
const t = P(e);
|
|
317
|
-
return await (await ((s = e.fetch) != null ? s : ve)(t.href, e.fetchOptions)).json();
|
|
318
|
-
}, Re = async (e, t, n = P(e)) => {
|
|
319
|
-
const r = ge(e.canTrack);
|
|
320
|
-
if (n.search.includes("preview=")) {
|
|
321
|
-
const s = [];
|
|
322
|
-
for (const i of t.results) {
|
|
323
|
-
const u = we(n.searchParams);
|
|
324
|
-
s.push(u || i);
|
|
325
|
-
}
|
|
326
|
-
t.results = s;
|
|
327
|
-
}
|
|
328
|
-
if (!r || !(c() || v === "reactNative"))
|
|
329
|
-
return t.results;
|
|
330
|
-
try {
|
|
331
|
-
const s = [];
|
|
332
|
-
for (const i of t.results)
|
|
333
|
-
s.push(await he({
|
|
334
|
-
item: i,
|
|
335
|
-
canTrack: r
|
|
336
|
-
}));
|
|
337
|
-
t.results = s;
|
|
338
|
-
} catch (s) {
|
|
339
|
-
l.error("Could not process A/B tests. ", s);
|
|
340
|
-
}
|
|
341
|
-
return t.results;
|
|
342
157
|
};
|
|
343
|
-
|
|
344
|
-
try {
|
|
345
|
-
const t = P(e), n = await Oe(e);
|
|
346
|
-
return Pe(n) ? Re(e, n) : (l.error("Error fetching data. ", {
|
|
347
|
-
url: t,
|
|
348
|
-
content: n,
|
|
349
|
-
options: e
|
|
350
|
-
}), null);
|
|
351
|
-
} catch (t) {
|
|
352
|
-
return l.error("Error fetching data. ", t), null;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
function qe(e) {
|
|
356
|
-
const t = e || (c() ? window.location.search : void 0);
|
|
357
|
-
return t ? U(t).indexOf("builder.preview=") !== -1 : !1;
|
|
358
|
-
}
|
|
359
|
-
function Ae() {
|
|
158
|
+
function fe() {
|
|
360
159
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(e) {
|
|
361
160
|
const t = Math.random() * 16 | 0;
|
|
362
161
|
return (e == "x" ? t : t & 3 | 8).toString(16);
|
|
363
162
|
});
|
|
364
163
|
}
|
|
365
|
-
function
|
|
366
|
-
return
|
|
164
|
+
function D() {
|
|
165
|
+
return fe().replace(/-/g, "");
|
|
367
166
|
}
|
|
368
|
-
const
|
|
167
|
+
const j = "builderSessionId", he = async ({
|
|
369
168
|
canTrack: e
|
|
370
169
|
}) => {
|
|
371
170
|
if (!e)
|
|
372
171
|
return;
|
|
373
|
-
const t = await
|
|
374
|
-
name:
|
|
172
|
+
const t = await F({
|
|
173
|
+
name: j,
|
|
375
174
|
canTrack: e
|
|
376
175
|
});
|
|
377
176
|
if (m(t))
|
|
378
177
|
return t;
|
|
379
178
|
{
|
|
380
|
-
const n =
|
|
381
|
-
return
|
|
179
|
+
const n = ge();
|
|
180
|
+
return pe({
|
|
382
181
|
id: n,
|
|
383
182
|
canTrack: e
|
|
384
183
|
}), n;
|
|
385
184
|
}
|
|
386
|
-
},
|
|
185
|
+
}, ge = () => D(), pe = ({
|
|
387
186
|
id: e,
|
|
388
187
|
canTrack: t
|
|
389
|
-
}) =>
|
|
390
|
-
name:
|
|
188
|
+
}) => N({
|
|
189
|
+
name: j,
|
|
391
190
|
value: e,
|
|
392
191
|
canTrack: t
|
|
393
|
-
}),
|
|
192
|
+
}), K = () => c() && typeof localStorage != "undefined" ? localStorage : void 0, me = ({
|
|
394
193
|
key: e,
|
|
395
194
|
canTrack: t
|
|
396
195
|
}) => {
|
|
397
196
|
var n;
|
|
398
197
|
try {
|
|
399
|
-
return t ? (n =
|
|
198
|
+
return t ? (n = K()) == null ? void 0 : n.getItem(e) : void 0;
|
|
400
199
|
} catch (r) {
|
|
401
200
|
console.debug("[LocalStorage] GET error: ", r);
|
|
402
201
|
return;
|
|
403
202
|
}
|
|
404
|
-
},
|
|
203
|
+
}, ye = ({
|
|
405
204
|
key: e,
|
|
406
205
|
canTrack: t,
|
|
407
206
|
value: n
|
|
408
207
|
}) => {
|
|
409
208
|
var r;
|
|
410
209
|
try {
|
|
411
|
-
t && ((r =
|
|
210
|
+
t && ((r = K()) == null || r.setItem(e, n));
|
|
412
211
|
} catch (o) {
|
|
413
212
|
console.debug("[LocalStorage] SET error: ", o);
|
|
414
213
|
}
|
|
415
|
-
},
|
|
214
|
+
}, W = "builderVisitorId", we = ({
|
|
416
215
|
canTrack: e
|
|
417
216
|
}) => {
|
|
418
217
|
if (!e)
|
|
419
218
|
return;
|
|
420
|
-
const t =
|
|
421
|
-
key:
|
|
219
|
+
const t = me({
|
|
220
|
+
key: W,
|
|
422
221
|
canTrack: e
|
|
423
222
|
});
|
|
424
223
|
if (m(t))
|
|
425
224
|
return t;
|
|
426
225
|
{
|
|
427
|
-
const n =
|
|
428
|
-
return
|
|
226
|
+
const n = Se();
|
|
227
|
+
return be({
|
|
429
228
|
id: n,
|
|
430
229
|
canTrack: e
|
|
431
230
|
}), n;
|
|
432
231
|
}
|
|
433
|
-
},
|
|
232
|
+
}, Se = () => D(), be = ({
|
|
434
233
|
id: e,
|
|
435
234
|
canTrack: t
|
|
436
|
-
}) =>
|
|
437
|
-
key:
|
|
235
|
+
}) => ye({
|
|
236
|
+
key: W,
|
|
438
237
|
value: e,
|
|
439
238
|
canTrack: t
|
|
440
|
-
}),
|
|
239
|
+
}), ve = async ({
|
|
441
240
|
canTrack: e
|
|
442
241
|
}) => {
|
|
443
242
|
if (!e)
|
|
@@ -445,16 +244,16 @@ const G = "builderSessionId", Te = async ({
|
|
|
445
244
|
visitorId: void 0,
|
|
446
245
|
sessionId: void 0
|
|
447
246
|
};
|
|
448
|
-
const t = await
|
|
247
|
+
const t = await he({
|
|
449
248
|
canTrack: e
|
|
450
|
-
}), n =
|
|
249
|
+
}), n = we({
|
|
451
250
|
canTrack: e
|
|
452
251
|
});
|
|
453
252
|
return {
|
|
454
253
|
sessionId: t,
|
|
455
254
|
visitorId: n
|
|
456
255
|
};
|
|
457
|
-
},
|
|
256
|
+
}, Ie = async ({
|
|
458
257
|
type: e,
|
|
459
258
|
canTrack: t,
|
|
460
259
|
apiKey: n,
|
|
@@ -468,14 +267,14 @@ const G = "builderSessionId", Te = async ({
|
|
|
468
267
|
url: location.href,
|
|
469
268
|
...r
|
|
470
269
|
},
|
|
471
|
-
...await
|
|
270
|
+
...await ve({
|
|
472
271
|
canTrack: t
|
|
473
272
|
}),
|
|
474
273
|
userAttributes: re(),
|
|
475
274
|
ownerId: n
|
|
476
275
|
}
|
|
477
276
|
});
|
|
478
|
-
async function
|
|
277
|
+
async function Ee(e) {
|
|
479
278
|
if (!e.apiKey) {
|
|
480
279
|
l.error("Missing API key for track call. Please provide your API key.");
|
|
481
280
|
return;
|
|
@@ -484,7 +283,7 @@ async function je(e) {
|
|
|
484
283
|
return fetch("https://cdn.builder.io/api/v1/track", {
|
|
485
284
|
method: "POST",
|
|
486
285
|
body: JSON.stringify({
|
|
487
|
-
events: [await
|
|
286
|
+
events: [await Ie(e)]
|
|
488
287
|
}),
|
|
489
288
|
headers: {
|
|
490
289
|
"content-type": "application/json"
|
|
@@ -494,37 +293,18 @@ async function je(e) {
|
|
|
494
293
|
console.error("Failed to track: ", t);
|
|
495
294
|
});
|
|
496
295
|
}
|
|
497
|
-
const Qe = (e) =>
|
|
296
|
+
const Qe = (e) => Ee({
|
|
498
297
|
...e,
|
|
499
298
|
canTrack: !0
|
|
500
|
-
}),
|
|
501
|
-
function
|
|
299
|
+
}), ke = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
|
|
300
|
+
function $(e, t) {
|
|
502
301
|
if (!t.origin.startsWith("http") && !t.origin.startsWith("https"))
|
|
503
302
|
return !1;
|
|
504
303
|
const n = new URL(t.origin), r = n.hostname;
|
|
505
|
-
return (e ||
|
|
506
|
-
}
|
|
507
|
-
const We = "0.16.6", A = {};
|
|
508
|
-
function $e(e, t) {
|
|
509
|
-
e === "plugin" && (t = j(t));
|
|
510
|
-
let n = A[e];
|
|
511
|
-
if (n || (n = A[e] = []), n.push(t), c()) {
|
|
512
|
-
const r = {
|
|
513
|
-
type: "builder.register",
|
|
514
|
-
data: {
|
|
515
|
-
type: e,
|
|
516
|
-
info: t
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
try {
|
|
520
|
-
parent.postMessage(r, "*"), parent !== window && window.postMessage(r, "*");
|
|
521
|
-
} catch (o) {
|
|
522
|
-
console.debug("Could not postmessage", o);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
304
|
+
return (e || ke).findIndex((o) => o.startsWith("*.") ? r.endsWith(o.slice(1)) : o === r) > -1;
|
|
525
305
|
}
|
|
526
|
-
const Ye = () => {
|
|
527
|
-
|
|
306
|
+
const Pe = "0.16.9", Ye = () => {
|
|
307
|
+
se("insertMenu", {
|
|
528
308
|
name: "_default",
|
|
529
309
|
default: !0,
|
|
530
310
|
items: [{
|
|
@@ -547,13 +327,13 @@ const Ye = () => {
|
|
|
547
327
|
});
|
|
548
328
|
};
|
|
549
329
|
let T = !1;
|
|
550
|
-
const
|
|
330
|
+
const Ce = (e = {}) => {
|
|
551
331
|
var t, n;
|
|
552
332
|
T || (T = !0, c() && ((t = window.parent) == null || t.postMessage({
|
|
553
333
|
type: "builder.sdkInfo",
|
|
554
334
|
data: {
|
|
555
335
|
target: v,
|
|
556
|
-
version:
|
|
336
|
+
version: Pe,
|
|
557
337
|
supportsPatchUpdates: !1,
|
|
558
338
|
// Supports builder-model="..." attribute which is needed to
|
|
559
339
|
// scope our '+ add block' button styling
|
|
@@ -567,7 +347,7 @@ const Ge = (e = {}) => {
|
|
|
567
347
|
}
|
|
568
348
|
}, "*"), window.addEventListener("message", (r) => {
|
|
569
349
|
var s, i;
|
|
570
|
-
if (
|
|
350
|
+
if (!$(e.trustedHosts, r))
|
|
571
351
|
return;
|
|
572
352
|
const {
|
|
573
353
|
data: o
|
|
@@ -608,12 +388,12 @@ const Ge = (e = {}) => {
|
|
|
608
388
|
}
|
|
609
389
|
}
|
|
610
390
|
})));
|
|
611
|
-
},
|
|
391
|
+
}, Oe = ({
|
|
612
392
|
model: e,
|
|
613
393
|
trustedHosts: t,
|
|
614
394
|
callbacks: n
|
|
615
395
|
}) => (r) => {
|
|
616
|
-
if (
|
|
396
|
+
if (!$(t, r))
|
|
617
397
|
return;
|
|
618
398
|
const {
|
|
619
399
|
data: o
|
|
@@ -638,8 +418,8 @@ const Ge = (e = {}) => {
|
|
|
638
418
|
if (!c)
|
|
639
419
|
return l.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."), () => {
|
|
640
420
|
};
|
|
641
|
-
|
|
642
|
-
const r =
|
|
421
|
+
Ce();
|
|
422
|
+
const r = Oe({
|
|
643
423
|
callbacks: {
|
|
644
424
|
contentUpdate: t,
|
|
645
425
|
animation: () => {
|
|
@@ -653,15 +433,237 @@ const Ge = (e = {}) => {
|
|
|
653
433
|
return window.addEventListener("message", r), () => {
|
|
654
434
|
window.removeEventListener("message", r);
|
|
655
435
|
};
|
|
656
|
-
},
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
436
|
+
}, Re = "builder.tests", k = (e) => `${Re}.${e}`, xe = ({
|
|
437
|
+
contentId: e
|
|
438
|
+
}) => F({
|
|
439
|
+
name: k(e),
|
|
440
|
+
canTrack: !0
|
|
441
|
+
}), Ae = ({
|
|
442
|
+
contentId: e
|
|
443
|
+
}) => _({
|
|
444
|
+
name: k(e),
|
|
445
|
+
canTrack: !0
|
|
446
|
+
}), Te = ({
|
|
447
|
+
contentId: e,
|
|
448
|
+
value: t
|
|
449
|
+
}) => N({
|
|
450
|
+
name: k(e),
|
|
451
|
+
value: t,
|
|
452
|
+
canTrack: !0
|
|
453
|
+
}), G = (e) => m(e.id) && m(e.variations) && Object.keys(e.variations).length > 0, Le = ({
|
|
454
|
+
id: e,
|
|
455
|
+
variations: t
|
|
456
|
+
}) => {
|
|
457
|
+
var o;
|
|
458
|
+
let n = 0;
|
|
459
|
+
const r = Math.random();
|
|
460
|
+
for (const s in t) {
|
|
461
|
+
const i = (o = t[s]) == null ? void 0 : o.testRatio;
|
|
462
|
+
if (n += i, r < n)
|
|
463
|
+
return s;
|
|
464
|
+
}
|
|
465
|
+
return e;
|
|
466
|
+
}, H = (e) => {
|
|
467
|
+
const t = Le(e);
|
|
468
|
+
return Te({
|
|
469
|
+
contentId: e.id,
|
|
470
|
+
value: t
|
|
471
|
+
}).catch((n) => {
|
|
472
|
+
l.error("could not store A/B test variation: ", n);
|
|
473
|
+
}), t;
|
|
474
|
+
}, J = ({
|
|
475
|
+
item: e,
|
|
476
|
+
testGroupId: t
|
|
477
|
+
}) => {
|
|
478
|
+
const n = e.variations[t];
|
|
479
|
+
return t === e.id || // handle edge-case where `testGroupId` points to non-existing variation
|
|
480
|
+
!n ? {
|
|
481
|
+
testVariationId: e.id,
|
|
482
|
+
testVariationName: "Default"
|
|
483
|
+
} : {
|
|
484
|
+
data: n.data,
|
|
485
|
+
testVariationId: n.id,
|
|
486
|
+
testVariationName: n.name || (n.id === e.id ? "Default" : "")
|
|
487
|
+
};
|
|
488
|
+
}, et = ({
|
|
489
|
+
item: e,
|
|
490
|
+
canTrack: t
|
|
491
|
+
}) => {
|
|
492
|
+
if (!t)
|
|
493
|
+
return e;
|
|
494
|
+
if (!e)
|
|
495
|
+
return;
|
|
496
|
+
if (!G(e))
|
|
497
|
+
return e;
|
|
498
|
+
const n = Ae({
|
|
499
|
+
contentId: e.id
|
|
500
|
+
}) || H({
|
|
501
|
+
variations: e.variations,
|
|
502
|
+
id: e.id
|
|
503
|
+
}), r = J({
|
|
504
|
+
item: e,
|
|
505
|
+
testGroupId: n
|
|
506
|
+
});
|
|
507
|
+
return {
|
|
508
|
+
...e,
|
|
509
|
+
...r
|
|
510
|
+
};
|
|
511
|
+
}, Be = async ({
|
|
512
|
+
item: e,
|
|
513
|
+
canTrack: t
|
|
514
|
+
}) => {
|
|
515
|
+
if (!t || !G(e))
|
|
516
|
+
return e;
|
|
517
|
+
const r = await xe({
|
|
518
|
+
contentId: e.id
|
|
519
|
+
}) || H({
|
|
520
|
+
variations: e.variations,
|
|
521
|
+
id: e.id
|
|
522
|
+
}), o = J({
|
|
523
|
+
item: e,
|
|
524
|
+
testGroupId: r
|
|
525
|
+
});
|
|
526
|
+
return {
|
|
527
|
+
...e,
|
|
528
|
+
...o
|
|
529
|
+
};
|
|
530
|
+
}, Ue = (e) => m(e) ? e : !0, Ve = (e) => {
|
|
531
|
+
const t = e.get("preview"), n = e.get("overrides." + t);
|
|
532
|
+
return n || l.warn("No previewed ID found in search params."), n;
|
|
533
|
+
};
|
|
534
|
+
function Me() {
|
|
535
|
+
globalThis._BUILDER_PREVIEW_LRU_CACHE || (globalThis._BUILDER_PREVIEW_LRU_CACHE = new Q({
|
|
536
|
+
max: 500,
|
|
537
|
+
// how long to live in ms
|
|
538
|
+
ttl: 1e3 * 60 * 5
|
|
539
|
+
}));
|
|
540
|
+
}
|
|
541
|
+
function _e(e) {
|
|
542
|
+
Me();
|
|
543
|
+
const t = Ve(e);
|
|
544
|
+
return typeof t == "string" ? globalThis._BUILDER_PREVIEW_LRU_CACHE.get(t) : void 0;
|
|
545
|
+
}
|
|
546
|
+
function Fe() {
|
|
547
|
+
return typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : globalThis;
|
|
548
|
+
}
|
|
549
|
+
function Ne() {
|
|
550
|
+
const e = Fe().fetch;
|
|
551
|
+
if (typeof e == "undefined")
|
|
552
|
+
throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
|
|
553
|
+
For more information, read https://github.com/BuilderIO/this-package-uses-fetch`), new Error("Builder SDK could not find a global `fetch` function");
|
|
554
|
+
return e;
|
|
555
|
+
}
|
|
556
|
+
const De = Ne();
|
|
557
|
+
function E(e, t = null, n = ".") {
|
|
558
|
+
return Object.keys(e).reduce((r, o) => {
|
|
559
|
+
const s = e[o], i = [t, o].filter(Boolean).join(n);
|
|
560
|
+
return [typeof s == "object", s !== null, !(Array.isArray(s) && s.length === 0)].every(Boolean) ? {
|
|
561
|
+
...r,
|
|
562
|
+
...E(s, i, n)
|
|
563
|
+
} : {
|
|
564
|
+
...r,
|
|
565
|
+
[i]: s
|
|
663
566
|
};
|
|
664
|
-
|
|
567
|
+
}, {});
|
|
568
|
+
}
|
|
569
|
+
function z(e, t, n = {}) {
|
|
570
|
+
for (const r in e) {
|
|
571
|
+
const o = e[r], s = t ? t + "." + r : r;
|
|
572
|
+
o && typeof o == "object" && !Array.isArray(o) && !Object.keys(o).find((i) => i.startsWith("$")) ? z(o, s, n) : n[s] = o;
|
|
573
|
+
}
|
|
574
|
+
return n;
|
|
575
|
+
}
|
|
576
|
+
const je = "v3", L = (e) => typeof e == "number" && !isNaN(e) && e >= 0, P = (e) => {
|
|
577
|
+
const {
|
|
578
|
+
limit: t = 30,
|
|
579
|
+
userAttributes: n,
|
|
580
|
+
query: r,
|
|
581
|
+
model: o,
|
|
582
|
+
apiKey: s,
|
|
583
|
+
enrich: i,
|
|
584
|
+
locale: u,
|
|
585
|
+
apiVersion: y = je,
|
|
586
|
+
fields: p,
|
|
587
|
+
omit: I,
|
|
588
|
+
offset: d,
|
|
589
|
+
cacheSeconds: h,
|
|
590
|
+
staleCacheSeconds: g,
|
|
591
|
+
sort: w,
|
|
592
|
+
includeUnpublished: C
|
|
593
|
+
} = e;
|
|
594
|
+
if (!s)
|
|
595
|
+
throw new Error("Missing API key");
|
|
596
|
+
if (!["v3"].includes(y))
|
|
597
|
+
throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);
|
|
598
|
+
const X = t !== 1, a = new URL(`https://cdn.builder.io/api/${y}/content/${o}`);
|
|
599
|
+
if (a.searchParams.set("apiKey", s), a.searchParams.set("limit", String(t)), a.searchParams.set("noTraverse", String(X)), a.searchParams.set("includeRefs", String(!0)), u && a.searchParams.set("locale", u), i && a.searchParams.set("enrich", String(i)), a.searchParams.set("omit", I || "meta.componentsUsed"), p && a.searchParams.set("fields", p), Number.isFinite(d) && d > -1 && a.searchParams.set("offset", String(Math.floor(d))), typeof C == "boolean" && a.searchParams.set("includeUnpublished", String(C)), h && L(h) && a.searchParams.set("cacheSeconds", String(h)), g && L(g) && a.searchParams.set("staleCacheSeconds", String(g)), w) {
|
|
600
|
+
const f = E({
|
|
601
|
+
sort: w
|
|
602
|
+
});
|
|
603
|
+
for (const S in f)
|
|
604
|
+
a.searchParams.set(S, JSON.stringify(f[S]));
|
|
605
|
+
}
|
|
606
|
+
const q = {
|
|
607
|
+
...ae(),
|
|
608
|
+
...B(e.options || {})
|
|
609
|
+
}, O = E(q);
|
|
610
|
+
for (const f in O)
|
|
611
|
+
a.searchParams.set(f, String(O[f]));
|
|
612
|
+
if (n && a.searchParams.set("userAttributes", JSON.stringify(n)), r) {
|
|
613
|
+
const f = z({
|
|
614
|
+
query: r
|
|
615
|
+
});
|
|
616
|
+
for (const S in f)
|
|
617
|
+
a.searchParams.set(S, JSON.stringify(f[S]));
|
|
618
|
+
}
|
|
619
|
+
return a;
|
|
620
|
+
}, Ke = (e) => "results" in e;
|
|
621
|
+
async function We(e) {
|
|
622
|
+
const t = await He({
|
|
623
|
+
...e,
|
|
624
|
+
limit: 1
|
|
625
|
+
});
|
|
626
|
+
return t && t[0] || null;
|
|
627
|
+
}
|
|
628
|
+
const $e = async (e) => {
|
|
629
|
+
var s;
|
|
630
|
+
const t = P(e);
|
|
631
|
+
return await (await ((s = e.fetch) != null ? s : De)(t.href, e.fetchOptions)).json();
|
|
632
|
+
}, Ge = async (e, t, n = P(e)) => {
|
|
633
|
+
const r = Ue(e.canTrack);
|
|
634
|
+
if (n.search.includes("preview=")) {
|
|
635
|
+
const s = [];
|
|
636
|
+
for (const i of t.results) {
|
|
637
|
+
const u = _e(n.searchParams);
|
|
638
|
+
s.push(u || i);
|
|
639
|
+
}
|
|
640
|
+
t.results = s;
|
|
641
|
+
}
|
|
642
|
+
if (!r || !(c() || v === "reactNative"))
|
|
643
|
+
return t.results;
|
|
644
|
+
try {
|
|
645
|
+
const s = [];
|
|
646
|
+
for (const i of t.results)
|
|
647
|
+
s.push(await Be({
|
|
648
|
+
item: i,
|
|
649
|
+
canTrack: r
|
|
650
|
+
}));
|
|
651
|
+
t.results = s;
|
|
652
|
+
} catch (s) {
|
|
653
|
+
l.error("Could not process A/B tests. ", s);
|
|
654
|
+
}
|
|
655
|
+
return t.results;
|
|
656
|
+
};
|
|
657
|
+
async function He(e) {
|
|
658
|
+
try {
|
|
659
|
+
const t = P(e), n = await $e(e);
|
|
660
|
+
return Ke(n) ? Ge(e, n) : (l.error("Error fetching data. ", {
|
|
661
|
+
url: t,
|
|
662
|
+
content: n,
|
|
663
|
+
options: e
|
|
664
|
+
}), null);
|
|
665
|
+
} catch (t) {
|
|
666
|
+
return l.error("Error fetching data. ", t), null;
|
|
665
667
|
}
|
|
666
668
|
}
|
|
667
669
|
const tt = async (e) => {
|
|
@@ -676,40 +678,40 @@ const tt = async (e) => {
|
|
|
676
678
|
urlPath: t
|
|
677
679
|
} : {}
|
|
678
680
|
},
|
|
679
|
-
options:
|
|
681
|
+
options: M(e.searchParams || ((s = e.url) == null ? void 0 : s.searchParams) || e.options)
|
|
680
682
|
};
|
|
681
683
|
return {
|
|
682
684
|
apiKey: n.apiKey,
|
|
683
685
|
model: n.model,
|
|
684
|
-
content: await
|
|
686
|
+
content: await We(n)
|
|
685
687
|
};
|
|
686
688
|
};
|
|
687
689
|
export {
|
|
688
690
|
b as MSG_PREFIX,
|
|
689
691
|
v as TARGET,
|
|
690
|
-
|
|
691
|
-
|
|
692
|
+
Ge as _processContentResult,
|
|
693
|
+
Ee as _track,
|
|
692
694
|
m as checkIsDefined,
|
|
693
|
-
|
|
695
|
+
Oe as createEditorListener,
|
|
694
696
|
Xe as createRegisterComponentMessage,
|
|
695
|
-
|
|
697
|
+
De as fetch,
|
|
696
698
|
tt as fetchBuilderProps,
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
699
|
+
He as fetchEntries,
|
|
700
|
+
We as fetchOneEntry,
|
|
701
|
+
M as getBuilderSearchParams,
|
|
702
|
+
Ue as getDefaultCanTrack,
|
|
701
703
|
re as getUserAttributes,
|
|
702
|
-
|
|
703
|
-
|
|
704
|
+
et as handleABTestingSync,
|
|
705
|
+
Me as init,
|
|
704
706
|
c as isBrowser,
|
|
705
707
|
ee as isEditing,
|
|
706
|
-
|
|
708
|
+
ze as isPreviewing,
|
|
707
709
|
l as logger,
|
|
708
|
-
|
|
710
|
+
se as register,
|
|
709
711
|
Ye as registerInsertMenu,
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
712
|
+
V as serializeIncludingFunctions,
|
|
713
|
+
qe as setEditorSettings,
|
|
714
|
+
Ce as setupBrowserForEditing,
|
|
713
715
|
Ze as subscribeToEditor,
|
|
714
716
|
Qe as track
|
|
715
717
|
};
|