@builder.io/sdk-react 0.12.7 → 0.13.0
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/index.cjs +27 -27
- package/lib/browser/index.mjs +471 -566
- package/lib/browser/server-entry-a7214151.js +690 -0
- package/lib/browser/server-entry-f1003541.cjs +2 -0
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +4 -3
- package/lib/edge/index.cjs +31 -31
- package/lib/edge/index.mjs +818 -913
- package/lib/edge/server-entry-12a6f428.js +690 -0
- package/lib/edge/server-entry-f1003541.cjs +2 -0
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +4 -3
- package/lib/node/index.cjs +10 -10
- package/lib/node/index.mjs +227 -322
- package/lib/node/server-entry-3743f8cd.cjs +2 -0
- package/lib/node/server-entry-3f9209d6.js +690 -0
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +4 -3
- package/package.json +1 -1
- package/types/components/content-variants/helpers.d.ts +1 -1
- package/types/constants/sdk-version.d.ts +1 -1
- package/types/functions/get-content/types.d.ts +2 -2
- package/types/helpers/subscribe-to-editor.d.ts +35 -0
- package/types/server-index.d.ts +18 -3
- package/types/types/api-version.d.ts +1 -1
- package/lib/browser/server-entry-b9bdd327.js +0 -551
- package/lib/browser/server-entry-fc715776.cjs +0 -2
- package/lib/edge/server-entry-57d4ae22.js +0 -551
- package/lib/edge/server-entry-fc715776.cjs +0 -2
- package/lib/node/server-entry-0457c4c8.js +0 -551
- package/lib/node/server-entry-bcb725be.cjs +0 -2
|
@@ -1,551 +0,0 @@
|
|
|
1
|
-
const b = "react", h = "[Builder.io]: ", l = {
|
|
2
|
-
log: (...t) => console.log(h, ...t),
|
|
3
|
-
error: (...t) => console.error(h, ...t),
|
|
4
|
-
warn: (...t) => console.warn(h, ...t),
|
|
5
|
-
debug: (...t) => console.debug(h, ...t)
|
|
6
|
-
};
|
|
7
|
-
function a() {
|
|
8
|
-
return typeof window != "undefined" && typeof document != "undefined";
|
|
9
|
-
}
|
|
10
|
-
function Y() {
|
|
11
|
-
return a() && window.self !== window.top;
|
|
12
|
-
}
|
|
13
|
-
function B() {
|
|
14
|
-
return Y() && window.location.search.indexOf("builder.frameEditing=") !== -1;
|
|
15
|
-
}
|
|
16
|
-
const Q = () => {
|
|
17
|
-
if (a()) {
|
|
18
|
-
const t = new URL(location.href);
|
|
19
|
-
return t.pathname === "" && (t.pathname = "/"), t;
|
|
20
|
-
} else
|
|
21
|
-
return console.warn("Cannot get location for tracking in non-browser environment"), null;
|
|
22
|
-
}, Z = () => typeof navigator == "object" && navigator.userAgent || "", tt = () => {
|
|
23
|
-
const t = Z(), e = {
|
|
24
|
-
Android() {
|
|
25
|
-
return t.match(/Android/i);
|
|
26
|
-
},
|
|
27
|
-
BlackBerry() {
|
|
28
|
-
return t.match(/BlackBerry/i);
|
|
29
|
-
},
|
|
30
|
-
iOS() {
|
|
31
|
-
return t.match(/iPhone|iPod/i);
|
|
32
|
-
},
|
|
33
|
-
Opera() {
|
|
34
|
-
return t.match(/Opera Mini/i);
|
|
35
|
-
},
|
|
36
|
-
Windows() {
|
|
37
|
-
return t.match(/IEMobile/i) || t.match(/WPDesktop/i);
|
|
38
|
-
},
|
|
39
|
-
any() {
|
|
40
|
-
return e.Android() || e.BlackBerry() || e.iOS() || e.Opera() || e.Windows() || b === "reactNative";
|
|
41
|
-
}
|
|
42
|
-
}, n = t.match(/Tablet|iPad/i), r = Q();
|
|
43
|
-
return {
|
|
44
|
-
urlPath: r == null ? void 0 : r.pathname,
|
|
45
|
-
host: (r == null ? void 0 : r.host) || (r == null ? void 0 : r.hostname),
|
|
46
|
-
device: n ? "tablet" : e.any() ? "mobile" : "desktop"
|
|
47
|
-
};
|
|
48
|
-
}, L = (t) => JSON.parse(JSON.stringify(t)), d = (t) => t != null, et = (t) => {
|
|
49
|
-
if (t === "localhost" || t === "127.0.0.1")
|
|
50
|
-
return t;
|
|
51
|
-
const e = t.split(".");
|
|
52
|
-
return e.length > 2 ? e.slice(1).join(".") : t;
|
|
53
|
-
}, N = ({
|
|
54
|
-
name: t,
|
|
55
|
-
canTrack: e
|
|
56
|
-
}) => {
|
|
57
|
-
var n;
|
|
58
|
-
try {
|
|
59
|
-
return e ? (n = document.cookie.split("; ").find((r) => r.startsWith(`${t}=`))) == null ? void 0 : n.split("=")[1] : void 0;
|
|
60
|
-
} catch (r) {
|
|
61
|
-
l.warn("[COOKIE] GET error: ", (r == null ? void 0 : r.message) || r);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
}, $ = async (t) => N(t), nt = (t) => t.map(([e, n]) => n ? `${e}=${n}` : e).filter(d).join("; "), rt = [["secure", ""], ["SameSite", "None"]], ot = ({
|
|
65
|
-
name: t,
|
|
66
|
-
value: e,
|
|
67
|
-
expires: n
|
|
68
|
-
}) => {
|
|
69
|
-
const o = (a() ? location.protocol === "https:" : !0) ? rt : [[]], s = n ? [["expires", n.toUTCString()]] : [[]], c = [[t, e], ...s, ["path", "/"], ["domain", et(window.location.hostname)], ...o];
|
|
70
|
-
return nt(c);
|
|
71
|
-
}, j = async ({
|
|
72
|
-
name: t,
|
|
73
|
-
value: e,
|
|
74
|
-
expires: n,
|
|
75
|
-
canTrack: r
|
|
76
|
-
}) => {
|
|
77
|
-
try {
|
|
78
|
-
if (!r)
|
|
79
|
-
return;
|
|
80
|
-
const o = ot({
|
|
81
|
-
name: t,
|
|
82
|
-
value: e,
|
|
83
|
-
expires: n
|
|
84
|
-
});
|
|
85
|
-
document.cookie = o;
|
|
86
|
-
} catch (o) {
|
|
87
|
-
l.warn("[COOKIE] SET error: ", (o == null ? void 0 : o.message) || o);
|
|
88
|
-
}
|
|
89
|
-
}, st = "builder.tests", v = (t) => `${st}.${t}`, it = ({
|
|
90
|
-
contentId: t
|
|
91
|
-
}) => $({
|
|
92
|
-
name: v(t),
|
|
93
|
-
canTrack: !0
|
|
94
|
-
}), at = ({
|
|
95
|
-
contentId: t
|
|
96
|
-
}) => N({
|
|
97
|
-
name: v(t),
|
|
98
|
-
canTrack: !0
|
|
99
|
-
}), ct = ({
|
|
100
|
-
contentId: t,
|
|
101
|
-
value: e
|
|
102
|
-
}) => j({
|
|
103
|
-
name: v(t),
|
|
104
|
-
value: e,
|
|
105
|
-
canTrack: !0
|
|
106
|
-
}), F = (t) => d(t.id) && d(t.variations) && Object.keys(t.variations).length > 0, ut = ({
|
|
107
|
-
id: t,
|
|
108
|
-
variations: e
|
|
109
|
-
}) => {
|
|
110
|
-
var o;
|
|
111
|
-
let n = 0;
|
|
112
|
-
const r = Math.random();
|
|
113
|
-
for (const s in e) {
|
|
114
|
-
const c = (o = e[s]) == null ? void 0 : o.testRatio;
|
|
115
|
-
if (n += c, r < n)
|
|
116
|
-
return s;
|
|
117
|
-
}
|
|
118
|
-
return t;
|
|
119
|
-
}, U = (t) => {
|
|
120
|
-
const e = ut(t);
|
|
121
|
-
return ct({
|
|
122
|
-
contentId: t.id,
|
|
123
|
-
value: e
|
|
124
|
-
}).catch((n) => {
|
|
125
|
-
l.error("could not store A/B test variation: ", n);
|
|
126
|
-
}), e;
|
|
127
|
-
}, K = ({
|
|
128
|
-
item: t,
|
|
129
|
-
testGroupId: e
|
|
130
|
-
}) => {
|
|
131
|
-
const n = t.variations[e];
|
|
132
|
-
return e === t.id || // handle edge-case where `testGroupId` points to non-existing variation
|
|
133
|
-
!n ? {
|
|
134
|
-
testVariationId: t.id,
|
|
135
|
-
testVariationName: "Default"
|
|
136
|
-
} : {
|
|
137
|
-
data: n.data,
|
|
138
|
-
testVariationId: n.id,
|
|
139
|
-
testVariationName: n.name || (n.id === t.id ? "Default" : "")
|
|
140
|
-
};
|
|
141
|
-
}, jt = ({
|
|
142
|
-
item: t,
|
|
143
|
-
canTrack: e
|
|
144
|
-
}) => {
|
|
145
|
-
if (!e)
|
|
146
|
-
return t;
|
|
147
|
-
if (!t)
|
|
148
|
-
return;
|
|
149
|
-
if (!F(t))
|
|
150
|
-
return t;
|
|
151
|
-
const n = at({
|
|
152
|
-
contentId: t.id
|
|
153
|
-
}) || U({
|
|
154
|
-
variations: t.variations,
|
|
155
|
-
id: t.id
|
|
156
|
-
}), r = K({
|
|
157
|
-
item: t,
|
|
158
|
-
testGroupId: n
|
|
159
|
-
});
|
|
160
|
-
return {
|
|
161
|
-
...t,
|
|
162
|
-
...r
|
|
163
|
-
};
|
|
164
|
-
}, lt = async ({
|
|
165
|
-
item: t,
|
|
166
|
-
canTrack: e
|
|
167
|
-
}) => {
|
|
168
|
-
if (!e || !F(t))
|
|
169
|
-
return t;
|
|
170
|
-
const r = await it({
|
|
171
|
-
contentId: t.id
|
|
172
|
-
}) || U({
|
|
173
|
-
variations: t.variations,
|
|
174
|
-
id: t.id
|
|
175
|
-
}), o = K({
|
|
176
|
-
item: t,
|
|
177
|
-
testGroupId: r
|
|
178
|
-
});
|
|
179
|
-
return {
|
|
180
|
-
...t,
|
|
181
|
-
...o
|
|
182
|
-
};
|
|
183
|
-
}, dt = (t) => d(t) ? t : !0, Ft = [], Ut = (t) => ({
|
|
184
|
-
type: "builder.registerComponent",
|
|
185
|
-
data: gt(t)
|
|
186
|
-
}), ft = (t) => {
|
|
187
|
-
const e = t.toString().trim();
|
|
188
|
-
return `return (${!e.startsWith("function") && !e.startsWith("(") ? "function " : ""}${e}).apply(this, arguments)`;
|
|
189
|
-
}, ht = (t) => typeof t == "function" ? ft(t) : L(t), gt = ({
|
|
190
|
-
inputs: t,
|
|
191
|
-
...e
|
|
192
|
-
}) => ({
|
|
193
|
-
...L(e),
|
|
194
|
-
inputs: t == null ? void 0 : t.map((n) => Object.entries(n).reduce((r, [o, s]) => ({
|
|
195
|
-
...r,
|
|
196
|
-
[o]: ht(s)
|
|
197
|
-
}), {}))
|
|
198
|
-
});
|
|
199
|
-
function pt() {
|
|
200
|
-
return typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : globalThis;
|
|
201
|
-
}
|
|
202
|
-
function yt() {
|
|
203
|
-
const t = pt().fetch;
|
|
204
|
-
if (typeof t == "undefined")
|
|
205
|
-
throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
|
|
206
|
-
For more information, read https://github.com/BuilderIO/this-package-uses-fetch`), new Error("Builder SDK could not find a global `fetch` function");
|
|
207
|
-
return t;
|
|
208
|
-
}
|
|
209
|
-
const mt = yt();
|
|
210
|
-
function g(t, e = null, n = ".") {
|
|
211
|
-
return Object.keys(t).reduce((r, o) => {
|
|
212
|
-
const s = t[o], c = [e, o].filter(Boolean).join(n);
|
|
213
|
-
return [typeof s == "object", s !== null, !(Array.isArray(s) && s.length === 0)].every(Boolean) ? {
|
|
214
|
-
...r,
|
|
215
|
-
...g(s, c, n)
|
|
216
|
-
} : {
|
|
217
|
-
...r,
|
|
218
|
-
[c]: s
|
|
219
|
-
};
|
|
220
|
-
}, {});
|
|
221
|
-
}
|
|
222
|
-
const St = "v3", A = "builder.", wt = "options.", bt = (t) => {
|
|
223
|
-
const e = {};
|
|
224
|
-
return t.forEach((n, r) => {
|
|
225
|
-
e[r] = n;
|
|
226
|
-
}), e;
|
|
227
|
-
}, M = (t) => {
|
|
228
|
-
if (!t)
|
|
229
|
-
return {};
|
|
230
|
-
const e = D(t), n = {};
|
|
231
|
-
return Object.keys(e).forEach((r) => {
|
|
232
|
-
if (r.startsWith(A)) {
|
|
233
|
-
const o = r.replace(A, "").replace(wt, "");
|
|
234
|
-
n[o] = e[r];
|
|
235
|
-
}
|
|
236
|
-
}), n;
|
|
237
|
-
}, vt = () => {
|
|
238
|
-
if (!a())
|
|
239
|
-
return {};
|
|
240
|
-
const t = new URLSearchParams(window.location.search);
|
|
241
|
-
return M(t);
|
|
242
|
-
}, D = (t) => t instanceof URLSearchParams ? bt(t) : t, T = (t) => typeof t == "number" && !isNaN(t) && t >= 0, I = (t) => {
|
|
243
|
-
let {
|
|
244
|
-
noTraverse: e = !1
|
|
245
|
-
} = t;
|
|
246
|
-
const {
|
|
247
|
-
limit: n = 30,
|
|
248
|
-
userAttributes: r,
|
|
249
|
-
query: o,
|
|
250
|
-
model: s,
|
|
251
|
-
apiKey: c,
|
|
252
|
-
includeRefs: p = !0,
|
|
253
|
-
enrich: O,
|
|
254
|
-
locale: k,
|
|
255
|
-
apiVersion: y = St,
|
|
256
|
-
fields: C,
|
|
257
|
-
omit: q,
|
|
258
|
-
offset: m,
|
|
259
|
-
cacheSeconds: S,
|
|
260
|
-
staleCacheSeconds: w,
|
|
261
|
-
sort: E,
|
|
262
|
-
includeUnpublished: P
|
|
263
|
-
} = t;
|
|
264
|
-
if (!c)
|
|
265
|
-
throw new Error("Missing API key");
|
|
266
|
-
if (!["v2", "v3"].includes(y))
|
|
267
|
-
throw new Error(`Invalid apiVersion: expected 'v2' or 'v3', received '${y}'`);
|
|
268
|
-
(t.limit === void 0 || t.limit > 1) && !("noTraverse" in t) && (e = !0);
|
|
269
|
-
const i = new URL(`https://cdn.builder.io/api/${y}/content/${s}?apiKey=${c}&limit=${n}&noTraverse=${e}&includeRefs=${p}${k ? `&locale=${k}` : ""}${O ? `&enrich=${O}` : ""}`);
|
|
270
|
-
if (i.searchParams.set("omit", q || "meta.componentsUsed"), C && i.searchParams.set("fields", C), Number.isFinite(m) && m > -1 && i.searchParams.set("offset", String(Math.floor(m))), typeof P == "boolean" && i.searchParams.set("includeUnpublished", String(P)), S && T(S) && i.searchParams.set("cacheSeconds", String(S)), w && T(w) && i.searchParams.set("staleCacheSeconds", String(w)), E) {
|
|
271
|
-
const u = g({
|
|
272
|
-
sort: E
|
|
273
|
-
});
|
|
274
|
-
for (const f in u)
|
|
275
|
-
i.searchParams.set(f, JSON.stringify(u[f]));
|
|
276
|
-
}
|
|
277
|
-
const H = {
|
|
278
|
-
...vt(),
|
|
279
|
-
...D(t.options || {})
|
|
280
|
-
}, x = g(H);
|
|
281
|
-
for (const u in x)
|
|
282
|
-
i.searchParams.set(u, String(x[u]));
|
|
283
|
-
if (r && i.searchParams.set("userAttributes", JSON.stringify(r)), o) {
|
|
284
|
-
const u = g({
|
|
285
|
-
query: o
|
|
286
|
-
});
|
|
287
|
-
for (const f in u)
|
|
288
|
-
i.searchParams.set(f, JSON.stringify(u[f]));
|
|
289
|
-
}
|
|
290
|
-
return i;
|
|
291
|
-
}, It = (t) => "results" in t;
|
|
292
|
-
async function _(t) {
|
|
293
|
-
const e = await G({
|
|
294
|
-
...t,
|
|
295
|
-
limit: 1
|
|
296
|
-
});
|
|
297
|
-
return e && e[0] || null;
|
|
298
|
-
}
|
|
299
|
-
const Kt = _, Ot = async (t) => {
|
|
300
|
-
const e = I(t);
|
|
301
|
-
return await (await mt(e.href)).json();
|
|
302
|
-
}, kt = async (t, e, n = I(t)) => {
|
|
303
|
-
const r = dt(t.canTrack);
|
|
304
|
-
if (n.search.includes("preview="), !r || !(a() || b === "reactNative"))
|
|
305
|
-
return e.results;
|
|
306
|
-
try {
|
|
307
|
-
const o = [];
|
|
308
|
-
for (const s of e.results)
|
|
309
|
-
o.push(await lt({
|
|
310
|
-
item: s,
|
|
311
|
-
canTrack: r
|
|
312
|
-
}));
|
|
313
|
-
e.results = o;
|
|
314
|
-
} catch (o) {
|
|
315
|
-
l.error("Could not process A/B tests. ", o);
|
|
316
|
-
}
|
|
317
|
-
return e.results;
|
|
318
|
-
};
|
|
319
|
-
async function G(t) {
|
|
320
|
-
try {
|
|
321
|
-
const e = I(t), n = await Ot(t);
|
|
322
|
-
return It(n) ? kt(t, n) : (l.error("Error fetching data. ", {
|
|
323
|
-
url: e,
|
|
324
|
-
content: n,
|
|
325
|
-
options: t
|
|
326
|
-
}), null);
|
|
327
|
-
} catch (e) {
|
|
328
|
-
return l.error("Error fetching data. ", e), null;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
const Mt = G;
|
|
332
|
-
function Dt() {
|
|
333
|
-
return !a() || B() ? !1 : location.search.indexOf("builder.preview=") !== -1;
|
|
334
|
-
}
|
|
335
|
-
function Ct() {
|
|
336
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t) {
|
|
337
|
-
const e = Math.random() * 16 | 0;
|
|
338
|
-
return (t == "x" ? e : e & 3 | 8).toString(16);
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
function W() {
|
|
342
|
-
return Ct().replace(/-/g, "");
|
|
343
|
-
}
|
|
344
|
-
const J = "builderSessionId", Et = async ({
|
|
345
|
-
canTrack: t
|
|
346
|
-
}) => {
|
|
347
|
-
if (!t)
|
|
348
|
-
return;
|
|
349
|
-
const e = await $({
|
|
350
|
-
name: J,
|
|
351
|
-
canTrack: t
|
|
352
|
-
});
|
|
353
|
-
if (d(e))
|
|
354
|
-
return e;
|
|
355
|
-
{
|
|
356
|
-
const n = Pt();
|
|
357
|
-
return xt({
|
|
358
|
-
id: n,
|
|
359
|
-
canTrack: t
|
|
360
|
-
}), n;
|
|
361
|
-
}
|
|
362
|
-
}, Pt = () => W(), xt = ({
|
|
363
|
-
id: t,
|
|
364
|
-
canTrack: e
|
|
365
|
-
}) => j({
|
|
366
|
-
name: J,
|
|
367
|
-
value: t,
|
|
368
|
-
canTrack: e
|
|
369
|
-
}), z = () => a() && typeof localStorage != "undefined" ? localStorage : void 0, At = ({
|
|
370
|
-
key: t,
|
|
371
|
-
canTrack: e
|
|
372
|
-
}) => {
|
|
373
|
-
var n;
|
|
374
|
-
try {
|
|
375
|
-
return e ? (n = z()) == null ? void 0 : n.getItem(t) : void 0;
|
|
376
|
-
} catch (r) {
|
|
377
|
-
console.debug("[LocalStorage] GET error: ", r);
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
}, Tt = ({
|
|
381
|
-
key: t,
|
|
382
|
-
canTrack: e,
|
|
383
|
-
value: n
|
|
384
|
-
}) => {
|
|
385
|
-
var r;
|
|
386
|
-
try {
|
|
387
|
-
e && ((r = z()) == null || r.setItem(t, n));
|
|
388
|
-
} catch (o) {
|
|
389
|
-
console.debug("[LocalStorage] SET error: ", o);
|
|
390
|
-
}
|
|
391
|
-
}, X = "builderVisitorId", Rt = ({
|
|
392
|
-
canTrack: t
|
|
393
|
-
}) => {
|
|
394
|
-
if (!t)
|
|
395
|
-
return;
|
|
396
|
-
const e = At({
|
|
397
|
-
key: X,
|
|
398
|
-
canTrack: t
|
|
399
|
-
});
|
|
400
|
-
if (d(e))
|
|
401
|
-
return e;
|
|
402
|
-
{
|
|
403
|
-
const n = Vt();
|
|
404
|
-
return Bt({
|
|
405
|
-
id: n,
|
|
406
|
-
canTrack: t
|
|
407
|
-
}), n;
|
|
408
|
-
}
|
|
409
|
-
}, Vt = () => W(), Bt = ({
|
|
410
|
-
id: t,
|
|
411
|
-
canTrack: e
|
|
412
|
-
}) => Tt({
|
|
413
|
-
key: X,
|
|
414
|
-
value: t,
|
|
415
|
-
canTrack: e
|
|
416
|
-
}), Lt = async ({
|
|
417
|
-
canTrack: t
|
|
418
|
-
}) => {
|
|
419
|
-
if (!t)
|
|
420
|
-
return {
|
|
421
|
-
visitorId: void 0,
|
|
422
|
-
sessionId: void 0
|
|
423
|
-
};
|
|
424
|
-
const e = await Et({
|
|
425
|
-
canTrack: t
|
|
426
|
-
}), n = Rt({
|
|
427
|
-
canTrack: t
|
|
428
|
-
});
|
|
429
|
-
return {
|
|
430
|
-
sessionId: e,
|
|
431
|
-
visitorId: n
|
|
432
|
-
};
|
|
433
|
-
}, Nt = async ({
|
|
434
|
-
type: t,
|
|
435
|
-
canTrack: e,
|
|
436
|
-
apiKey: n,
|
|
437
|
-
metadata: r,
|
|
438
|
-
...o
|
|
439
|
-
}) => ({
|
|
440
|
-
type: t,
|
|
441
|
-
data: {
|
|
442
|
-
...o,
|
|
443
|
-
metadata: {
|
|
444
|
-
url: location.href,
|
|
445
|
-
...r
|
|
446
|
-
},
|
|
447
|
-
...await Lt({
|
|
448
|
-
canTrack: e
|
|
449
|
-
}),
|
|
450
|
-
userAttributes: tt(),
|
|
451
|
-
ownerId: n
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
async function $t(t) {
|
|
455
|
-
if (!t.apiKey) {
|
|
456
|
-
l.error("Missing API key for track call. Please provide your API key.");
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
if (t.canTrack && !B() && (a() || b === "reactNative"))
|
|
460
|
-
return fetch("https://cdn.builder.io/api/v1/track", {
|
|
461
|
-
method: "POST",
|
|
462
|
-
body: JSON.stringify({
|
|
463
|
-
events: [await Nt(t)]
|
|
464
|
-
}),
|
|
465
|
-
headers: {
|
|
466
|
-
"content-type": "application/json"
|
|
467
|
-
},
|
|
468
|
-
mode: "cors"
|
|
469
|
-
}).catch((e) => {
|
|
470
|
-
console.error("Failed to track: ", e);
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
const _t = (t) => $t({
|
|
474
|
-
...t,
|
|
475
|
-
canTrack: !0
|
|
476
|
-
}), R = {};
|
|
477
|
-
function Gt(t, e) {
|
|
478
|
-
let n = R[t];
|
|
479
|
-
if (n || (n = R[t] = []), n.push(e), a()) {
|
|
480
|
-
const r = {
|
|
481
|
-
type: "builder.register",
|
|
482
|
-
data: {
|
|
483
|
-
type: t,
|
|
484
|
-
info: e
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
try {
|
|
488
|
-
parent.postMessage(r, "*"), parent !== window && window.postMessage(r, "*");
|
|
489
|
-
} catch (o) {
|
|
490
|
-
console.debug("Could not postmessage", o);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
const V = {};
|
|
495
|
-
function Wt(t) {
|
|
496
|
-
if (a()) {
|
|
497
|
-
Object.assign(V, t);
|
|
498
|
-
const e = {
|
|
499
|
-
type: "builder.settingsChange",
|
|
500
|
-
data: V
|
|
501
|
-
};
|
|
502
|
-
parent.postMessage(e, "*");
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
const Jt = async (t) => {
|
|
506
|
-
var r, o, s;
|
|
507
|
-
const e = t.path || ((r = t.url) == null ? void 0 : r.pathname) || ((o = t.userAttributes) == null ? void 0 : o.urlPath), n = {
|
|
508
|
-
...t,
|
|
509
|
-
apiKey: t.apiKey,
|
|
510
|
-
model: t.model || "page",
|
|
511
|
-
userAttributes: {
|
|
512
|
-
...t.userAttributes,
|
|
513
|
-
...e ? {
|
|
514
|
-
urlPath: e
|
|
515
|
-
} : {}
|
|
516
|
-
},
|
|
517
|
-
options: M(t.searchParams || ((s = t.url) == null ? void 0 : s.searchParams) || t.options)
|
|
518
|
-
};
|
|
519
|
-
return {
|
|
520
|
-
apiKey: n.apiKey,
|
|
521
|
-
model: n.model,
|
|
522
|
-
content: await _(n)
|
|
523
|
-
};
|
|
524
|
-
};
|
|
525
|
-
export {
|
|
526
|
-
b as T,
|
|
527
|
-
kt as _,
|
|
528
|
-
Dt as a,
|
|
529
|
-
_ as b,
|
|
530
|
-
Ut as c,
|
|
531
|
-
Kt as d,
|
|
532
|
-
M as e,
|
|
533
|
-
G as f,
|
|
534
|
-
Mt as g,
|
|
535
|
-
Jt as h,
|
|
536
|
-
B as i,
|
|
537
|
-
a as j,
|
|
538
|
-
tt as k,
|
|
539
|
-
L as l,
|
|
540
|
-
d as m,
|
|
541
|
-
l as n,
|
|
542
|
-
dt as o,
|
|
543
|
-
$t as p,
|
|
544
|
-
mt as q,
|
|
545
|
-
Gt as r,
|
|
546
|
-
Wt as s,
|
|
547
|
-
_t as t,
|
|
548
|
-
Ft as u,
|
|
549
|
-
gt as v,
|
|
550
|
-
jt as w
|
|
551
|
-
};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const p="react",h="[Builder.io]: ",l={log:(...t)=>console.log(h,...t),error:(...t)=>console.error(h,...t),warn:(...t)=>console.warn(h,...t),debug:(...t)=>console.debug(h,...t)};function a(){return typeof window!="undefined"&&typeof document!="undefined"}function rt(){return a()&&window.self!==window.top}function v(){return rt()&&window.location.search.indexOf("builder.frameEditing=")!==-1}const ot=()=>{if(a()){const t=new URL(location.href);return t.pathname===""&&(t.pathname="/"),t}else return console.warn("Cannot get location for tracking in non-browser environment"),null},st=()=>typeof navigator=="object"&&navigator.userAgent||"",U=()=>{const t=st(),e={Android(){return t.match(/Android/i)},BlackBerry(){return t.match(/BlackBerry/i)},iOS(){return t.match(/iPhone|iPod/i)},Opera(){return t.match(/Opera Mini/i)},Windows(){return t.match(/IEMobile/i)||t.match(/WPDesktop/i)},any(){return e.Android()||e.BlackBerry()||e.iOS()||e.Opera()||e.Windows()||p==="reactNative"}},n=t.match(/Tablet|iPad/i),r=ot();return{urlPath:r==null?void 0:r.pathname,host:(r==null?void 0:r.host)||(r==null?void 0:r.hostname),device:n?"tablet":e.any()?"mobile":"desktop"}},I=t=>JSON.parse(JSON.stringify(t)),d=t=>t!=null,it=t=>{if(t==="localhost"||t==="127.0.0.1")return t;const e=t.split(".");return e.length>2?e.slice(1).join("."):t},F=({name:t,canTrack:e})=>{var n;try{return e?(n=document.cookie.split("; ").find(r=>r.startsWith(`${t}=`)))==null?void 0:n.split("=")[1]:void 0}catch(r){l.warn("[COOKIE] GET error: ",(r==null?void 0:r.message)||r);return}},M=async t=>F(t),at=t=>t.map(([e,n])=>n?`${e}=${n}`:e).filter(d).join("; "),ct=[["secure",""],["SameSite","None"]],ut=({name:t,value:e,expires:n})=>{const o=(a()?location.protocol==="https:":!0)?ct:[[]],s=n?[["expires",n.toUTCString()]]:[[]],c=[[t,e],...s,["path","/"],["domain",it(window.location.hostname)],...o];return at(c)},D=async({name:t,value:e,expires:n,canTrack:r})=>{try{if(!r)return;const o=ut({name:t,value:e,expires:n});document.cookie=o}catch(o){l.warn("[COOKIE] SET error: ",(o==null?void 0:o.message)||o)}},lt="builder.tests",C=t=>`${lt}.${t}`,dt=({contentId:t})=>M({name:C(t),canTrack:!0}),ft=({contentId:t})=>F({name:C(t),canTrack:!0}),ht=({contentId:t,value:e})=>D({name:C(t),value:e,canTrack:!0}),K=t=>d(t.id)&&d(t.variations)&&Object.keys(t.variations).length>0,gt=({id:t,variations:e})=>{var o;let n=0;const r=Math.random();for(const s in e){const c=(o=e[s])==null?void 0:o.testRatio;if(n+=c,r<n)return s}return t},_=t=>{const e=gt(t);return ht({contentId:t.id,value:e}).catch(n=>{l.error("could not store A/B test variation: ",n)}),e},G=({item:t,testGroupId:e})=>{const n=t.variations[e];return e===t.id||!n?{testVariationId:t.id,testVariationName:"Default"}:{data:n.data,testVariationId:n.id,testVariationName:n.name||(n.id===t.id?"Default":"")}},pt=({item:t,canTrack:e})=>{if(!e)return t;if(!t)return;if(!K(t))return t;const n=ft({contentId:t.id})||_({variations:t.variations,id:t.id}),r=G({item:t,testGroupId:n});return{...t,...r}},yt=async({item:t,canTrack:e})=>{if(!e||!K(t))return t;const r=await dt({contentId:t.id})||_({variations:t.variations,id:t.id}),o=G({item:t,testGroupId:r});return{...t,...o}},W=t=>d(t)?t:!0,mt=[],St=t=>({type:"builder.registerComponent",data:J(t)}),wt=t=>{const e=t.toString().trim();return`return (${!e.startsWith("function")&&!e.startsWith("(")?"function ":""}${e}).apply(this, arguments)`},bt=t=>typeof t=="function"?wt(t):I(t),J=({inputs:t,...e})=>({...I(e),inputs:t==null?void 0:t.map(n=>Object.entries(n).reduce((r,[o,s])=>({...r,[o]:bt(s)}),{}))});function vt(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function It(){const t=vt().fetch;if(typeof t=="undefined")throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
|
|
2
|
-
For more information, read https://github.com/BuilderIO/this-package-uses-fetch`),new Error("Builder SDK could not find a global `fetch` function");return t}const z=It();function g(t,e=null,n="."){return Object.keys(t).reduce((r,o)=>{const s=t[o],c=[e,o].filter(Boolean).join(n);return[typeof s=="object",s!==null,!(Array.isArray(s)&&s.length===0)].every(Boolean)?{...r,...g(s,c,n)}:{...r,[c]:s}},{})}const Ct="v3",L="builder.",kt="options.",Et=t=>{const e={};return t.forEach((n,r)=>{e[r]=n}),e},k=t=>{if(!t)return{};const e=X(t),n={};return Object.keys(e).forEach(r=>{if(r.startsWith(L)){const o=r.replace(L,"").replace(kt,"");n[o]=e[r]}}),n},Ot=()=>{if(!a())return{};const t=new URLSearchParams(window.location.search);return k(t)},X=t=>t instanceof URLSearchParams?Et(t):t,N=t=>typeof t=="number"&&!isNaN(t)&&t>=0,E=t=>{let{noTraverse:e=!1}=t;const{limit:n=30,userAttributes:r,query:o,model:s,apiKey:c,includeRefs:y=!0,enrich:A,locale:x,apiVersion:m=Ct,fields:T,omit:et,offset:S,cacheSeconds:w,staleCacheSeconds:b,sort:R,includeUnpublished:B}=t;if(!c)throw new Error("Missing API key");if(!["v2","v3"].includes(m))throw new Error(`Invalid apiVersion: expected 'v2' or 'v3', received '${m}'`);(t.limit===void 0||t.limit>1)&&!("noTraverse"in t)&&(e=!0);const i=new URL(`https://cdn.builder.io/api/${m}/content/${s}?apiKey=${c}&limit=${n}&noTraverse=${e}&includeRefs=${y}${x?`&locale=${x}`:""}${A?`&enrich=${A}`:""}`);if(i.searchParams.set("omit",et||"meta.componentsUsed"),T&&i.searchParams.set("fields",T),Number.isFinite(S)&&S>-1&&i.searchParams.set("offset",String(Math.floor(S))),typeof B=="boolean"&&i.searchParams.set("includeUnpublished",String(B)),w&&N(w)&&i.searchParams.set("cacheSeconds",String(w)),b&&N(b)&&i.searchParams.set("staleCacheSeconds",String(b)),R){const u=g({sort:R});for(const f in u)i.searchParams.set(f,JSON.stringify(u[f]))}const nt={...Ot(),...X(t.options||{})},V=g(nt);for(const u in V)i.searchParams.set(u,String(V[u]));if(r&&i.searchParams.set("userAttributes",JSON.stringify(r)),o){const u=g({query:o});for(const f in u)i.searchParams.set(f,JSON.stringify(u[f]))}return i},Pt=t=>"results"in t;async function O(t){const e=await P({...t,limit:1});return e&&e[0]||null}const At=O,xt=async t=>{const e=E(t);return await(await z(e.href)).json()},q=async(t,e,n=E(t))=>{const r=W(t.canTrack);if(n.search.includes("preview="),!r||!(a()||p==="reactNative"))return e.results;try{const o=[];for(const s of e.results)o.push(await yt({item:s,canTrack:r}));e.results=o}catch(o){l.error("Could not process A/B tests. ",o)}return e.results};async function P(t){try{const e=E(t),n=await xt(t);return Pt(n)?q(t,n):(l.error("Error fetching data. ",{url:e,content:n,options:t}),null)}catch(e){return l.error("Error fetching data. ",e),null}}const Tt=P;function Rt(){return!a()||v()?!1:location.search.indexOf("builder.preview=")!==-1}function Bt(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const e=Math.random()*16|0;return(t=="x"?e:e&3|8).toString(16)})}function H(){return Bt().replace(/-/g,"")}const Y="builderSessionId",Vt=async({canTrack:t})=>{if(!t)return;const e=await M({name:Y,canTrack:t});if(d(e))return e;{const n=Lt();return Nt({id:n,canTrack:t}),n}},Lt=()=>H(),Nt=({id:t,canTrack:e})=>D({name:Y,value:t,canTrack:e}),Q=()=>a()&&typeof localStorage!="undefined"?localStorage:void 0,$t=({key:t,canTrack:e})=>{var n;try{return e?(n=Q())==null?void 0:n.getItem(t):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},jt=({key:t,canTrack:e,value:n})=>{var r;try{e&&((r=Q())==null||r.setItem(t,n))}catch(o){console.debug("[LocalStorage] SET error: ",o)}},Z="builderVisitorId",Ut=({canTrack:t})=>{if(!t)return;const e=$t({key:Z,canTrack:t});if(d(e))return e;{const n=Ft();return Mt({id:n,canTrack:t}),n}},Ft=()=>H(),Mt=({id:t,canTrack:e})=>jt({key:Z,value:t,canTrack:e}),Dt=async({canTrack:t})=>{if(!t)return{visitorId:void 0,sessionId:void 0};const e=await Vt({canTrack:t}),n=Ut({canTrack:t});return{sessionId:e,visitorId:n}},Kt=async({type:t,canTrack:e,apiKey:n,metadata:r,...o})=>({type:t,data:{...o,metadata:{url:location.href,...r},...await Dt({canTrack:e}),userAttributes:U(),ownerId:n}});async function tt(t){if(!t.apiKey){l.error("Missing API key for track call. Please provide your API key.");return}if(t.canTrack&&!v()&&(a()||p==="reactNative"))return fetch("https://cdn.builder.io/api/v1/track",{method:"POST",body:JSON.stringify({events:[await Kt(t)]}),headers:{"content-type":"application/json"},mode:"cors"}).catch(e=>{console.error("Failed to track: ",e)})}const _t=t=>tt({...t,canTrack:!0}),$={};function Gt(t,e){let n=$[t];if(n||(n=$[t]=[]),n.push(e),a()){const r={type:"builder.register",data:{type:t,info:e}};try{parent.postMessage(r,"*"),parent!==window&&window.postMessage(r,"*")}catch(o){console.debug("Could not postmessage",o)}}}const j={};function Wt(t){if(a()){Object.assign(j,t);const e={type:"builder.settingsChange",data:j};parent.postMessage(e,"*")}}const Jt=async t=>{var r,o,s;const e=t.path||((r=t.url)==null?void 0:r.pathname)||((o=t.userAttributes)==null?void 0:o.urlPath),n={...t,apiKey:t.apiKey,model:t.model||"page",userAttributes:{...t.userAttributes,...e?{urlPath:e}:{}},options:k(t.searchParams||((s=t.url)==null?void 0:s.searchParams)||t.options)};return{apiKey:n.apiKey,model:n.model,content:await O(n)}};exports.TARGET=p;exports._processContentResult=q;exports._track=tt;exports.checkIsDefined=d;exports.components=mt;exports.createRegisterComponentMessage=St;exports.fastClone=I;exports.fetch=z;exports.fetchBuilderProps=Jt;exports.fetchEntries=P;exports.fetchOneEntry=O;exports.getAllContent=Tt;exports.getBuilderSearchParams=k;exports.getContent=At;exports.getDefaultCanTrack=W;exports.getUserAttributes=U;exports.handleABTestingSync=pt;exports.isBrowser=a;exports.isEditing=v;exports.isPreviewing=Rt;exports.logger=l;exports.register=Gt;exports.serializeComponentInfo=J;exports.setEditorSettings=Wt;exports.track=_t;
|