@builder.io/sdk-react 1.0.20 → 1.0.22
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 +22 -22
- package/lib/browser/blocks-exports.mjs +428 -432
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +1 -1
- package/lib/browser/init.cjs +1 -0
- package/lib/browser/init.mjs +13 -0
- package/lib/browser/{server-entry-a562cf23.js → server-entry-3e30c656.js} +81 -82
- package/lib/browser/server-entry-8951c0c5.cjs +2 -0
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/blocks-5705f416.cjs +32 -0
- package/lib/edge/{blocks-683aad9f.js → blocks-b1f5ec2b.js} +742 -747
- package/lib/edge/blocks-exports.cjs +1 -1
- package/lib/edge/blocks-exports.mjs +2 -2
- package/lib/edge/{button-9f6acf3e.js → button-2b710146.js} +2 -2
- package/lib/edge/{button-0d418bcf.cjs → button-3c20ccff.cjs} +1 -1
- package/lib/edge/{columns-b0785992.js → columns-38a397cd.js} +3 -3
- package/lib/edge/{columns-1613d62d.cjs → columns-761d98c4.cjs} +1 -1
- package/lib/edge/{content-variants-281298f6.cjs → content-variants-befe3587.cjs} +4 -4
- package/lib/edge/{content-variants-13f821c6.js → content-variants-f165fa88.js} +21 -21
- package/lib/edge/{form-0483aa64.cjs → form-b0d65d74.cjs} +1 -1
- package/lib/edge/{form-db27fc26.js → form-d0cfb830.js} +3 -3
- package/lib/edge/{get-class-prop-name-e3ba0522.cjs → get-class-prop-name-27f8a4f1.cjs} +1 -1
- package/lib/edge/{get-class-prop-name-6bfc4756.js → get-class-prop-name-49d9b54f.js} +1 -1
- package/lib/edge/{img-43a8ffe0.js → img-e321016e.js} +1 -1
- package/lib/edge/{img-f01d904d.cjs → img-fcf6e57f.cjs} +1 -1
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +1 -1
- package/lib/edge/init.cjs +1 -0
- package/lib/edge/init.mjs +13 -0
- package/lib/edge/{input-805a9ac6.js → input-27f575fe.js} +1 -1
- package/lib/edge/{input-e6483bd7.cjs → input-f0319ee6.cjs} +1 -1
- package/lib/edge/{select-4966723f.js → select-dd4c61db.js} +1 -1
- package/lib/edge/{select-e5d1e627.cjs → select-e31522ee.cjs} +1 -1
- package/lib/edge/{server-entry-c13e82bd.js → server-entry-253a0fa1.js} +80 -81
- package/lib/edge/server-entry-dd363108.cjs +2 -0
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/edge/{slot-3ef77ae1.cjs → slot-a2388031.cjs} +1 -1
- package/lib/edge/{slot-1b0351de.js → slot-fea27ccf.js} +3 -3
- package/lib/edge/{symbol-f1632f93.js → symbol-686edeb8.js} +2 -2
- package/lib/edge/{symbol-883d624f.cjs → symbol-ba2c6245.cjs} +1 -1
- package/lib/node/blocks-exports.cjs +30 -70
- package/lib/node/blocks-exports.mjs +916 -1046
- package/lib/node/index.cjs +1 -1
- package/lib/node/index.mjs +23 -22
- package/lib/node/init.cjs +1 -0
- package/lib/node/init.mjs +9 -0
- package/lib/node/node-runtime-6587ed2e.js +155 -0
- package/lib/node/node-runtime-fa43cf07.cjs +48 -0
- package/lib/node/{server-entry-8c712c9b.js → server-entry-14d7a1d0.js} +82 -82
- package/lib/node/server-entry-3abae5dd.cjs +2 -0
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +1 -1
- package/package.json +6 -1
- package/types/components/block/animator.d.ts +1 -1
- package/types/constants/sdk-version.d.ts +1 -1
- package/types/functions/evaluate/node-runtime/init.d.ts +10 -0
- package/types/functions/evaluate/node-runtime/node-runtime.d.ts +6 -0
- package/types/functions/get-content/types.d.ts +3 -3
- package/types/functions/is-previewing.d.ts +1 -1
- package/types/helpers/logger.d.ts +1 -0
- package/lib/browser/server-entry-a77461d4.cjs +0 -2
- package/lib/edge/blocks-523eb4f1.cjs +0 -32
- package/lib/edge/server-entry-83648311.cjs +0 -2
- package/lib/node/server-entry-bedf45f8.cjs +0 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const I = "react", b = "[Builder.io]: ", f = {
|
|
2
2
|
log: (...e) => console.log(b, ...e),
|
|
3
3
|
error: (...e) => console.error(b, ...e),
|
|
4
4
|
warn: (...e) => console.warn(b, ...e),
|
|
@@ -7,17 +7,18 @@ const v = "react", b = "[Builder.io]: ", f = {
|
|
|
7
7
|
function c() {
|
|
8
8
|
return typeof window != "undefined" && typeof document != "undefined";
|
|
9
9
|
}
|
|
10
|
-
const
|
|
10
|
+
const q = (e) => {
|
|
11
11
|
const t = {};
|
|
12
12
|
return e.forEach((n, r) => {
|
|
13
13
|
t[r] = n;
|
|
14
14
|
}), t;
|
|
15
|
-
}, L = (e) => e instanceof URLSearchParams ?
|
|
16
|
-
function
|
|
15
|
+
}, L = (e) => e instanceof URLSearchParams ? q(e) : e, V = (e) => typeof e == "string" ? e : e instanceof URLSearchParams ? e.toString() : new URLSearchParams(e).toString();
|
|
16
|
+
function Y() {
|
|
17
17
|
return c() && window.self !== window.top;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
return
|
|
19
|
+
function Q(e) {
|
|
20
|
+
return Y() && // accessing window.location.search is safe here because `isIframe()` is only `true` if we're in a browser.
|
|
21
|
+
V(e || window.location.search).indexOf("builder.frameEditing=") !== -1;
|
|
21
22
|
}
|
|
22
23
|
const Z = () => {
|
|
23
24
|
if (c()) {
|
|
@@ -43,7 +44,7 @@ const Z = () => {
|
|
|
43
44
|
return e.match(/IEMobile/i) || e.match(/WPDesktop/i);
|
|
44
45
|
},
|
|
45
46
|
any() {
|
|
46
|
-
return t.Android() || t.BlackBerry() || t.iOS() || t.Opera() || t.Windows() ||
|
|
47
|
+
return t.Android() || t.BlackBerry() || t.iOS() || t.Opera() || t.Windows() || I === "reactNative";
|
|
47
48
|
}
|
|
48
49
|
}, n = e.match(/Tablet|iPad/i), r = Z();
|
|
49
50
|
return {
|
|
@@ -51,12 +52,12 @@ const Z = () => {
|
|
|
51
52
|
host: (r == null ? void 0 : r.host) || (r == null ? void 0 : r.hostname),
|
|
52
53
|
device: n ? "tablet" : t.any() ? "mobile" : "desktop"
|
|
53
54
|
};
|
|
54
|
-
},
|
|
55
|
+
}, U = (e) => JSON.parse(JSON.stringify(e)), m = (e) => e != null, ne = (e) => {
|
|
55
56
|
if (e === "localhost" || e === "127.0.0.1")
|
|
56
57
|
return e;
|
|
57
58
|
const t = e.split(".");
|
|
58
59
|
return t.length > 2 ? t.slice(1).join(".") : e;
|
|
59
|
-
},
|
|
60
|
+
}, M = ({
|
|
60
61
|
name: e,
|
|
61
62
|
canTrack: t
|
|
62
63
|
}) => {
|
|
@@ -67,14 +68,14 @@ const Z = () => {
|
|
|
67
68
|
f.warn("[COOKIE] GET error: ", (r == null ? void 0 : r.message) || r);
|
|
68
69
|
return;
|
|
69
70
|
}
|
|
70
|
-
},
|
|
71
|
+
}, N = async (e) => M(e), re = (e) => e.map(([t, n]) => n ? `${t}=${n}` : t).filter(m).join("; "), oe = [["secure", ""], ["SameSite", "None"]], se = ({
|
|
71
72
|
name: e,
|
|
72
73
|
value: t,
|
|
73
74
|
expires: n
|
|
74
75
|
}) => {
|
|
75
76
|
const o = (c() ? location.protocol === "https:" : !0) ? oe : [[]], s = n ? [["expires", n.toUTCString()]] : [[]], a = [[e, t], ...s, ["path", "/"], ["domain", ne(window.location.hostname)], ...o];
|
|
76
77
|
return re(a);
|
|
77
|
-
},
|
|
78
|
+
}, F = async ({
|
|
78
79
|
name: e,
|
|
79
80
|
value: t,
|
|
80
81
|
expires: n,
|
|
@@ -94,22 +95,22 @@ const Z = () => {
|
|
|
94
95
|
}
|
|
95
96
|
}, ie = "builder.tests", E = (e) => `${ie}.${e}`, ae = ({
|
|
96
97
|
contentId: e
|
|
97
|
-
}) =>
|
|
98
|
+
}) => N({
|
|
98
99
|
name: E(e),
|
|
99
100
|
canTrack: !0
|
|
100
101
|
}), ce = ({
|
|
101
102
|
contentId: e
|
|
102
|
-
}) =>
|
|
103
|
+
}) => M({
|
|
103
104
|
name: E(e),
|
|
104
105
|
canTrack: !0
|
|
105
106
|
}), ue = ({
|
|
106
107
|
contentId: e,
|
|
107
108
|
value: t
|
|
108
|
-
}) =>
|
|
109
|
+
}) => F({
|
|
109
110
|
name: E(e),
|
|
110
111
|
value: t,
|
|
111
112
|
canTrack: !0
|
|
112
|
-
}),
|
|
113
|
+
}), j = (e) => m(e.id) && m(e.variations) && Object.keys(e.variations).length > 0, de = ({
|
|
113
114
|
id: e,
|
|
114
115
|
variations: t
|
|
115
116
|
}) => {
|
|
@@ -122,7 +123,7 @@ const Z = () => {
|
|
|
122
123
|
return s;
|
|
123
124
|
}
|
|
124
125
|
return e;
|
|
125
|
-
},
|
|
126
|
+
}, D = (e) => {
|
|
126
127
|
const t = de(e);
|
|
127
128
|
return ue({
|
|
128
129
|
contentId: e.id,
|
|
@@ -130,7 +131,7 @@ const Z = () => {
|
|
|
130
131
|
}).catch((n) => {
|
|
131
132
|
f.error("could not store A/B test variation: ", n);
|
|
132
133
|
}), t;
|
|
133
|
-
},
|
|
134
|
+
}, K = ({
|
|
134
135
|
item: e,
|
|
135
136
|
testGroupId: t
|
|
136
137
|
}) => {
|
|
@@ -152,14 +153,14 @@ const Z = () => {
|
|
|
152
153
|
return e;
|
|
153
154
|
if (!e)
|
|
154
155
|
return;
|
|
155
|
-
if (!
|
|
156
|
+
if (!j(e))
|
|
156
157
|
return e;
|
|
157
158
|
const n = ce({
|
|
158
159
|
contentId: e.id
|
|
159
|
-
}) ||
|
|
160
|
+
}) || D({
|
|
160
161
|
variations: e.variations,
|
|
161
162
|
id: e.id
|
|
162
|
-
}), r =
|
|
163
|
+
}), r = K({
|
|
163
164
|
item: e,
|
|
164
165
|
testGroupId: n
|
|
165
166
|
});
|
|
@@ -171,14 +172,14 @@ const Z = () => {
|
|
|
171
172
|
item: e,
|
|
172
173
|
canTrack: t
|
|
173
174
|
}) => {
|
|
174
|
-
if (!t || !
|
|
175
|
+
if (!t || !j(e))
|
|
175
176
|
return e;
|
|
176
177
|
const r = await ae({
|
|
177
178
|
contentId: e.id
|
|
178
|
-
}) ||
|
|
179
|
+
}) || D({
|
|
179
180
|
variations: e.variations,
|
|
180
181
|
id: e.id
|
|
181
|
-
}), o =
|
|
182
|
+
}), o = K({
|
|
182
183
|
item: e,
|
|
183
184
|
testGroupId: r
|
|
184
185
|
});
|
|
@@ -192,11 +193,11 @@ const Z = () => {
|
|
|
192
193
|
}), he = (e) => {
|
|
193
194
|
const t = e.toString().trim();
|
|
194
195
|
return `return (${!t.startsWith("function") && !t.startsWith("(") ? "function " : ""}${t}).apply(this, arguments)`;
|
|
195
|
-
}, ge = (e) => typeof e == "function" ? he(e) :
|
|
196
|
+
}, ge = (e) => typeof e == "function" ? he(e) : U(e), pe = ({
|
|
196
197
|
inputs: e,
|
|
197
198
|
...t
|
|
198
199
|
}) => ({
|
|
199
|
-
...
|
|
200
|
+
...U(t),
|
|
200
201
|
inputs: e == null ? void 0 : e.map((n) => Object.entries(n).reduce((r, [o, s]) => ({
|
|
201
202
|
...r,
|
|
202
203
|
[o]: ge(s)
|
|
@@ -212,20 +213,20 @@ function ye() {
|
|
|
212
213
|
For more information, read https://github.com/BuilderIO/this-package-uses-fetch`), new Error("Builder SDK could not find a global `fetch` function");
|
|
213
214
|
return e;
|
|
214
215
|
}
|
|
215
|
-
const
|
|
216
|
-
function
|
|
216
|
+
const Se = ye();
|
|
217
|
+
function v(e, t = null, n = ".") {
|
|
217
218
|
return Object.keys(e).reduce((r, o) => {
|
|
218
219
|
const s = e[o], a = [t, o].filter(Boolean).join(n);
|
|
219
220
|
return [typeof s == "object", s !== null, !(Array.isArray(s) && s.length === 0)].every(Boolean) ? {
|
|
220
221
|
...r,
|
|
221
|
-
...
|
|
222
|
+
...v(s, a, n)
|
|
222
223
|
} : {
|
|
223
224
|
...r,
|
|
224
225
|
[a]: s
|
|
225
226
|
};
|
|
226
227
|
}, {});
|
|
227
228
|
}
|
|
228
|
-
const
|
|
229
|
+
const we = "v3", x = "builder.", be = "options.", _ = (e) => {
|
|
229
230
|
if (!e)
|
|
230
231
|
return {};
|
|
231
232
|
const t = L(e), n = {};
|
|
@@ -235,11 +236,11 @@ const Se = "v3", x = "builder.", be = "options.", W = (e) => {
|
|
|
235
236
|
n[o] = t[r];
|
|
236
237
|
}
|
|
237
238
|
}), n;
|
|
238
|
-
},
|
|
239
|
+
}, ve = () => {
|
|
239
240
|
if (!c())
|
|
240
241
|
return {};
|
|
241
242
|
const e = new URLSearchParams(window.location.search);
|
|
242
|
-
return
|
|
243
|
+
return _(e);
|
|
243
244
|
}, A = (e) => typeof e == "number" && !isNaN(e) && e >= 0, P = (e) => {
|
|
244
245
|
const {
|
|
245
246
|
limit: t = 30,
|
|
@@ -249,42 +250,42 @@ const Se = "v3", x = "builder.", be = "options.", W = (e) => {
|
|
|
249
250
|
apiKey: s,
|
|
250
251
|
enrich: a,
|
|
251
252
|
locale: d,
|
|
252
|
-
apiVersion: y =
|
|
253
|
+
apiVersion: y = we,
|
|
253
254
|
fields: p,
|
|
254
255
|
omit: k,
|
|
255
256
|
offset: u,
|
|
256
257
|
cacheSeconds: h,
|
|
257
258
|
staleCacheSeconds: g,
|
|
258
|
-
sort:
|
|
259
|
+
sort: S,
|
|
259
260
|
includeUnpublished: C
|
|
260
261
|
} = e;
|
|
261
262
|
if (!s)
|
|
262
263
|
throw new Error("Missing API key");
|
|
263
264
|
if (!["v3"].includes(y))
|
|
264
265
|
throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);
|
|
265
|
-
const
|
|
266
|
-
if (i.searchParams.set("apiKey", s), i.searchParams.set("limit", String(t)), i.searchParams.set("noTraverse", String(
|
|
267
|
-
const l =
|
|
268
|
-
sort:
|
|
266
|
+
const H = t !== 1, i = new URL(`https://cdn.builder.io/api/${y}/content/${o}`);
|
|
267
|
+
if (i.searchParams.set("apiKey", s), i.searchParams.set("limit", String(t)), i.searchParams.set("noTraverse", String(H)), i.searchParams.set("includeRefs", String(!0)), d && i.searchParams.set("locale", d), a && i.searchParams.set("enrich", String(a)), i.searchParams.set("omit", k || "meta.componentsUsed"), p && i.searchParams.set("fields", p), Number.isFinite(u) && u > -1 && i.searchParams.set("offset", String(Math.floor(u))), typeof C == "boolean" && i.searchParams.set("includeUnpublished", String(C)), h && A(h) && i.searchParams.set("cacheSeconds", String(h)), g && A(g) && i.searchParams.set("staleCacheSeconds", String(g)), S) {
|
|
268
|
+
const l = v({
|
|
269
|
+
sort: S
|
|
269
270
|
});
|
|
270
|
-
for (const
|
|
271
|
-
i.searchParams.set(
|
|
271
|
+
for (const w in l)
|
|
272
|
+
i.searchParams.set(w, JSON.stringify(l[w]));
|
|
272
273
|
}
|
|
273
|
-
const
|
|
274
|
-
...
|
|
274
|
+
const X = {
|
|
275
|
+
...ve(),
|
|
275
276
|
...L(e.options || {})
|
|
276
|
-
}, O =
|
|
277
|
+
}, O = v(X);
|
|
277
278
|
for (const l in O)
|
|
278
279
|
i.searchParams.set(l, String(O[l]));
|
|
279
280
|
if (n && i.searchParams.set("userAttributes", JSON.stringify(n)), r) {
|
|
280
|
-
const l =
|
|
281
|
+
const l = v({
|
|
281
282
|
query: r
|
|
282
283
|
});
|
|
283
|
-
for (const
|
|
284
|
-
i.searchParams.set(
|
|
284
|
+
for (const w in l)
|
|
285
|
+
i.searchParams.set(w, JSON.stringify(l[w]));
|
|
285
286
|
}
|
|
286
287
|
return i;
|
|
287
|
-
},
|
|
288
|
+
}, Ie = (e) => "results" in e;
|
|
288
289
|
async function ke(e) {
|
|
289
290
|
const t = await Ce({
|
|
290
291
|
...e,
|
|
@@ -295,10 +296,10 @@ async function ke(e) {
|
|
|
295
296
|
const Ee = async (e) => {
|
|
296
297
|
var s;
|
|
297
298
|
const t = P(e);
|
|
298
|
-
return await (await ((s = e.fetch) != null ? s :
|
|
299
|
+
return await (await ((s = e.fetch) != null ? s : Se)(t.href, e.fetchOptions)).json();
|
|
299
300
|
}, Pe = async (e, t, n = P(e)) => {
|
|
300
301
|
const r = fe(e.canTrack);
|
|
301
|
-
if (n.search.includes("preview="), !r || !(c() ||
|
|
302
|
+
if (n.search.includes("preview="), !r || !(c() || I === "reactNative"))
|
|
302
303
|
return t.results;
|
|
303
304
|
try {
|
|
304
305
|
const o = [];
|
|
@@ -316,7 +317,7 @@ const Ee = async (e) => {
|
|
|
316
317
|
async function Ce(e) {
|
|
317
318
|
try {
|
|
318
319
|
const t = P(e), n = await Ee(e);
|
|
319
|
-
return
|
|
320
|
+
return Ie(n) ? Pe(e, n) : (f.error("Error fetching data. ", {
|
|
320
321
|
url: t,
|
|
321
322
|
content: n,
|
|
322
323
|
options: e
|
|
@@ -325,11 +326,9 @@ async function Ce(e) {
|
|
|
325
326
|
return f.error("Error fetching data. ", t), null;
|
|
326
327
|
}
|
|
327
328
|
}
|
|
328
|
-
function
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const t = V(e || window.location.search);
|
|
332
|
-
return U(t) ? !1 : t.indexOf("builder.preview=") !== -1;
|
|
329
|
+
function ze(e) {
|
|
330
|
+
const t = e || (c() ? window.location.search : void 0);
|
|
331
|
+
return t ? V(t).indexOf("builder.preview=") !== -1 : !1;
|
|
333
332
|
}
|
|
334
333
|
function Oe() {
|
|
335
334
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(e) {
|
|
@@ -337,16 +336,16 @@ function Oe() {
|
|
|
337
336
|
return (e == "x" ? t : t & 3 | 8).toString(16);
|
|
338
337
|
});
|
|
339
338
|
}
|
|
340
|
-
function
|
|
339
|
+
function W() {
|
|
341
340
|
return Oe().replace(/-/g, "");
|
|
342
341
|
}
|
|
343
|
-
const
|
|
342
|
+
const $ = "builderSessionId", xe = async ({
|
|
344
343
|
canTrack: e
|
|
345
344
|
}) => {
|
|
346
345
|
if (!e)
|
|
347
346
|
return;
|
|
348
|
-
const t = await
|
|
349
|
-
name:
|
|
347
|
+
const t = await N({
|
|
348
|
+
name: $,
|
|
350
349
|
canTrack: e
|
|
351
350
|
});
|
|
352
351
|
if (m(t))
|
|
@@ -358,20 +357,20 @@ const G = "builderSessionId", xe = async ({
|
|
|
358
357
|
canTrack: e
|
|
359
358
|
}), n;
|
|
360
359
|
}
|
|
361
|
-
}, Ae = () =>
|
|
360
|
+
}, Ae = () => W(), Te = ({
|
|
362
361
|
id: e,
|
|
363
362
|
canTrack: t
|
|
364
|
-
}) =>
|
|
365
|
-
name:
|
|
363
|
+
}) => F({
|
|
364
|
+
name: $,
|
|
366
365
|
value: e,
|
|
367
366
|
canTrack: t
|
|
368
|
-
}),
|
|
367
|
+
}), G = () => c() && typeof localStorage != "undefined" ? localStorage : void 0, Re = ({
|
|
369
368
|
key: e,
|
|
370
369
|
canTrack: t
|
|
371
370
|
}) => {
|
|
372
371
|
var n;
|
|
373
372
|
try {
|
|
374
|
-
return t ? (n =
|
|
373
|
+
return t ? (n = G()) == null ? void 0 : n.getItem(e) : void 0;
|
|
375
374
|
} catch (r) {
|
|
376
375
|
console.debug("[LocalStorage] GET error: ", r);
|
|
377
376
|
return;
|
|
@@ -383,7 +382,7 @@ const G = "builderSessionId", xe = async ({
|
|
|
383
382
|
}) => {
|
|
384
383
|
var r;
|
|
385
384
|
try {
|
|
386
|
-
t && ((r =
|
|
385
|
+
t && ((r = G()) == null || r.setItem(e, n));
|
|
387
386
|
} catch (o) {
|
|
388
387
|
console.debug("[LocalStorage] SET error: ", o);
|
|
389
388
|
}
|
|
@@ -405,7 +404,7 @@ const G = "builderSessionId", xe = async ({
|
|
|
405
404
|
canTrack: e
|
|
406
405
|
}), n;
|
|
407
406
|
}
|
|
408
|
-
}, Ve = () =>
|
|
407
|
+
}, Ve = () => W(), Ue = ({
|
|
409
408
|
id: e,
|
|
410
409
|
canTrack: t
|
|
411
410
|
}) => Be({
|
|
@@ -455,7 +454,7 @@ async function Fe(e) {
|
|
|
455
454
|
f.error("Missing API key for track call. Please provide your API key.");
|
|
456
455
|
return;
|
|
457
456
|
}
|
|
458
|
-
if (e.canTrack && !
|
|
457
|
+
if (e.canTrack && !Q() && (c() || I === "reactNative"))
|
|
459
458
|
return fetch("https://cdn.builder.io/api/v1/track", {
|
|
460
459
|
method: "POST",
|
|
461
460
|
body: JSON.stringify({
|
|
@@ -469,15 +468,15 @@ async function Fe(e) {
|
|
|
469
468
|
console.error("Failed to track: ", t);
|
|
470
469
|
});
|
|
471
470
|
}
|
|
472
|
-
const
|
|
471
|
+
const Je = (e) => Fe({
|
|
473
472
|
...e,
|
|
474
473
|
canTrack: !0
|
|
475
474
|
}), je = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
|
|
476
|
-
function
|
|
475
|
+
function J(e, t) {
|
|
477
476
|
const n = new URL(t.origin), r = n.hostname;
|
|
478
477
|
return (e || je).findIndex((o) => o.startsWith("*.") ? r.endsWith(o.slice(1)) : o === r) > -1;
|
|
479
478
|
}
|
|
480
|
-
const De = "1.0.
|
|
479
|
+
const De = "1.0.22", T = {};
|
|
481
480
|
function Ke(e, t) {
|
|
482
481
|
let n = T[e];
|
|
483
482
|
if (n || (n = T[e] = []), n.push(t), c()) {
|
|
@@ -524,7 +523,7 @@ const _e = (e = {}) => {
|
|
|
524
523
|
R || (R = !0, c() && ((t = window.parent) == null || t.postMessage({
|
|
525
524
|
type: "builder.sdkInfo",
|
|
526
525
|
data: {
|
|
527
|
-
target:
|
|
526
|
+
target: I,
|
|
528
527
|
version: De,
|
|
529
528
|
supportsPatchUpdates: !1,
|
|
530
529
|
// Supports builder-model="..." attribute which is needed to
|
|
@@ -539,7 +538,7 @@ const _e = (e = {}) => {
|
|
|
539
538
|
}
|
|
540
539
|
}, "*"), window.addEventListener("message", (r) => {
|
|
541
540
|
var s, a;
|
|
542
|
-
if (!
|
|
541
|
+
if (!J(e.trustedHosts, r))
|
|
543
542
|
return;
|
|
544
543
|
const {
|
|
545
544
|
data: o
|
|
@@ -561,8 +560,8 @@ const _e = (e = {}) => {
|
|
|
561
560
|
error: h.message
|
|
562
561
|
}
|
|
563
562
|
}, "*") : u && typeof u.then == "function" ? u.then((g) => {
|
|
564
|
-
var
|
|
565
|
-
(
|
|
563
|
+
var S;
|
|
564
|
+
(S = window.parent) == null || S.postMessage({
|
|
566
565
|
type: "builder.evaluateResult",
|
|
567
566
|
data: {
|
|
568
567
|
id: p,
|
|
@@ -585,7 +584,7 @@ const _e = (e = {}) => {
|
|
|
585
584
|
trustedHosts: t,
|
|
586
585
|
callbacks: n
|
|
587
586
|
}) => (r) => {
|
|
588
|
-
if (!
|
|
587
|
+
if (!J(t, r))
|
|
589
588
|
return;
|
|
590
589
|
const {
|
|
591
590
|
data: o
|
|
@@ -648,7 +647,7 @@ const Ye = async (e) => {
|
|
|
648
647
|
urlPath: t
|
|
649
648
|
} : {}
|
|
650
649
|
},
|
|
651
|
-
options:
|
|
650
|
+
options: _(e.searchParams || ((s = e.url) == null ? void 0 : s.searchParams) || e.options)
|
|
652
651
|
};
|
|
653
652
|
return {
|
|
654
653
|
apiKey: n.apiKey,
|
|
@@ -657,24 +656,25 @@ const Ye = async (e) => {
|
|
|
657
656
|
};
|
|
658
657
|
};
|
|
659
658
|
export {
|
|
660
|
-
|
|
659
|
+
b as MSG_PREFIX,
|
|
660
|
+
I as TARGET,
|
|
661
661
|
Pe as _processContentResult,
|
|
662
662
|
Fe as _track,
|
|
663
663
|
m as checkIsDefined,
|
|
664
664
|
We as createEditorListener,
|
|
665
665
|
Ge as createRegisterComponentMessage,
|
|
666
|
-
|
|
667
|
-
|
|
666
|
+
U as fastClone,
|
|
667
|
+
Se as fetch,
|
|
668
668
|
Ye as fetchBuilderProps,
|
|
669
669
|
Ce as fetchEntries,
|
|
670
670
|
ke as fetchOneEntry,
|
|
671
|
-
|
|
671
|
+
_ as getBuilderSearchParams,
|
|
672
672
|
fe as getDefaultCanTrack,
|
|
673
673
|
te as getUserAttributes,
|
|
674
674
|
$e as handleABTestingSync,
|
|
675
675
|
c as isBrowser,
|
|
676
|
-
|
|
677
|
-
|
|
676
|
+
Q as isEditing,
|
|
677
|
+
ze as isPreviewing,
|
|
678
678
|
f as logger,
|
|
679
679
|
Ke as register,
|
|
680
680
|
He as registerInsertMenu,
|
|
@@ -682,5 +682,5 @@ export {
|
|
|
682
682
|
qe as setEditorSettings,
|
|
683
683
|
_e as setupBrowserForEditing,
|
|
684
684
|
Xe as subscribeToEditor,
|
|
685
|
-
|
|
685
|
+
Je as track
|
|
686
686
|
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const I="react",b="[Builder.io]: ",d={log:(...e)=>console.log(b,...e),error:(...e)=>console.error(b,...e),warn:(...e)=>console.warn(b,...e),debug:(...e)=>console.debug(b,...e)};function c(){return typeof window!="undefined"&&typeof document!="undefined"}const ce=e=>{const t={};return e.forEach((n,r)=>{t[r]=n}),t},U=e=>e instanceof URLSearchParams?ce(e):e,M=e=>typeof e=="string"?e:e instanceof URLSearchParams?e.toString():new URLSearchParams(e).toString();function ue(){return c()&&window.self!==window.top}function F(e){return ue()&&M(e||window.location.search).indexOf("builder.frameEditing=")!==-1}const de=()=>{if(c()){const e=new URL(location.href);return e.pathname===""&&(e.pathname="/"),e}else return console.warn("Cannot get location for tracking in non-browser environment"),null},le=()=>typeof navigator=="object"&&navigator.userAgent||"",N=()=>{const e=le(),t={Android(){return e.match(/Android/i)},BlackBerry(){return e.match(/BlackBerry/i)},iOS(){return e.match(/iPhone|iPod/i)},Opera(){return e.match(/Opera Mini/i)},Windows(){return e.match(/IEMobile/i)||e.match(/WPDesktop/i)},any(){return t.Android()||t.BlackBerry()||t.iOS()||t.Opera()||t.Windows()||I==="reactNative"}},n=e.match(/Tablet|iPad/i),r=de();return{urlPath:r==null?void 0:r.pathname,host:(r==null?void 0:r.host)||(r==null?void 0:r.hostname),device:n?"tablet":t.any()?"mobile":"desktop"}},k=e=>JSON.parse(JSON.stringify(e)),p=e=>e!=null,fe=e=>{if(e==="localhost"||e==="127.0.0.1")return e;const t=e.split(".");return t.length>2?t.slice(1).join("."):e},D=({name:e,canTrack:t})=>{var n;try{return t?(n=document.cookie.split("; ").find(r=>r.startsWith(`${e}=`)))==null?void 0:n.split("=")[1]:void 0}catch(r){d.warn("[COOKIE] GET error: ",(r==null?void 0:r.message)||r);return}},_=async e=>D(e),ge=e=>e.map(([t,n])=>n?`${t}=${n}`:t).filter(p).join("; "),he=[["secure",""],["SameSite","None"]],pe=({name:e,value:t,expires:n})=>{const o=(c()?location.protocol==="https:":!0)?he:[[]],s=n?[["expires",n.toUTCString()]]:[[]],a=[[e,t],...s,["path","/"],["domain",fe(window.location.hostname)],...o];return ge(a)},j=async({name:e,value:t,expires:n,canTrack:r})=>{try{if(!r)return;const o=pe({name:e,value:t,expires:n});document.cookie=o}catch(o){d.warn("[COOKIE] SET error: ",(o==null?void 0:o.message)||o)}},me="builder.tests",C=e=>`${me}.${e}`,ye=({contentId:e})=>_({name:C(e),canTrack:!0}),Se=({contentId:e})=>D({name:C(e),canTrack:!0}),we=({contentId:e,value:t})=>j({name:C(e),value:t,canTrack:!0}),K=e=>p(e.id)&&p(e.variations)&&Object.keys(e.variations).length>0,be=({id:e,variations:t})=>{var o;let n=0;const r=Math.random();for(const s in t){const a=(o=t[s])==null?void 0:o.testRatio;if(n+=a,r<n)return s}return e},G=e=>{const t=be(e);return we({contentId:e.id,value:t}).catch(n=>{d.error("could not store A/B test variation: ",n)}),t},W=({item:e,testGroupId:t})=>{const n=e.variations[t];return t===e.id||!n?{testVariationId:e.id,testVariationName:"Default"}:{data:n.data,testVariationId:n.id,testVariationName:n.name||(n.id===e.id?"Default":"")}},Ie=({item:e,canTrack:t})=>{if(!t)return e;if(!e)return;if(!K(e))return e;const n=Se({contentId:e.id})||G({variations:e.variations,id:e.id}),r=W({item:e,testGroupId:n});return{...e,...r}},ve=async({item:e,canTrack:t})=>{if(!t||!K(e))return e;const r=await ye({contentId:e.id})||G({variations:e.variations,id:e.id}),o=W({item:e,testGroupId:r});return{...e,...o}},$=e=>p(e)?e:!0,Ee=e=>({type:"builder.registerComponent",data:z(e)}),ke=e=>{const t=e.toString().trim();return`return (${!t.startsWith("function")&&!t.startsWith("(")?"function ":""}${t}).apply(this, arguments)`},Ce=e=>typeof e=="function"?ke(e):k(e),z=({inputs:e,...t})=>({...k(t),inputs:e==null?void 0:e.map(n=>Object.entries(n).reduce((r,[o,s])=>({...r,[o]:Ce(s)}),{}))});function Pe(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function Oe(){const e=Pe().fetch;if(typeof e=="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 e}const J=Oe();function v(e,t=null,n="."){return Object.keys(e).reduce((r,o)=>{const s=e[o],a=[t,o].filter(Boolean).join(n);return[typeof s=="object",s!==null,!(Array.isArray(s)&&s.length===0)].every(Boolean)?{...r,...v(s,a,n)}:{...r,[a]:s}},{})}const Te="v3",A="builder.",xe="options.",P=e=>{if(!e)return{};const t=U(e),n={};return Object.keys(t).forEach(r=>{if(r.startsWith(A)){const o=r.replace(A,"").replace(xe,"");n[o]=t[r]}}),n},Ae=()=>{if(!c())return{};const e=new URLSearchParams(window.location.search);return P(e)},R=e=>typeof e=="number"&&!isNaN(e)&&e>=0,O=e=>{const{limit:t=30,userAttributes:n,query:r,model:o,apiKey:s,enrich:a,locale:l,apiVersion:y=Te,fields:m,omit:E,offset:u,cacheSeconds:g,staleCacheSeconds:h,sort:S,includeUnpublished:T}=e;if(!s)throw new Error("Missing API key");if(!["v3"].includes(y))throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);const ie=t!==1,i=new URL(`https://cdn.builder.io/api/${y}/content/${o}`);if(i.searchParams.set("apiKey",s),i.searchParams.set("limit",String(t)),i.searchParams.set("noTraverse",String(ie)),i.searchParams.set("includeRefs",String(!0)),l&&i.searchParams.set("locale",l),a&&i.searchParams.set("enrich",String(a)),i.searchParams.set("omit",E||"meta.componentsUsed"),m&&i.searchParams.set("fields",m),Number.isFinite(u)&&u>-1&&i.searchParams.set("offset",String(Math.floor(u))),typeof T=="boolean"&&i.searchParams.set("includeUnpublished",String(T)),g&&R(g)&&i.searchParams.set("cacheSeconds",String(g)),h&&R(h)&&i.searchParams.set("staleCacheSeconds",String(h)),S){const f=v({sort:S});for(const w in f)i.searchParams.set(w,JSON.stringify(f[w]))}const ae={...Ae(),...U(e.options||{})},x=v(ae);for(const f in x)i.searchParams.set(f,String(x[f]));if(n&&i.searchParams.set("userAttributes",JSON.stringify(n)),r){const f=v({query:r});for(const w in f)i.searchParams.set(w,JSON.stringify(f[w]))}return i},Re=e=>"results"in e;async function H(e){const t=await q({...e,limit:1});return t&&t[0]||null}const Be=async e=>{var s;const t=O(e);return await(await((s=e.fetch)!=null?s:J)(t.href,e.fetchOptions)).json()},X=async(e,t,n=O(e))=>{const r=$(e.canTrack);if(n.search.includes("preview="),!r||!(c()||I==="reactNative"))return t.results;try{const o=[];for(const s of t.results)o.push(await ve({item:s,canTrack:r}));t.results=o}catch(o){d.error("Could not process A/B tests. ",o)}return t.results};async function q(e){try{const t=O(e),n=await Be(e);return Re(n)?X(e,n):(d.error("Error fetching data. ",{url:t,content:n,options:e}),null)}catch(t){return d.error("Error fetching data. ",t),null}}function Le(e){const t=e||(c()?window.location.search:void 0);return t?M(t).indexOf("builder.preview=")!==-1:!1}function Ve(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){const t=Math.random()*16|0;return(e=="x"?t:t&3|8).toString(16)})}function Y(){return Ve().replace(/-/g,"")}const Q="builderSessionId",Ue=async({canTrack:e})=>{if(!e)return;const t=await _({name:Q,canTrack:e});if(p(t))return t;{const n=Me();return Fe({id:n,canTrack:e}),n}},Me=()=>Y(),Fe=({id:e,canTrack:t})=>j({name:Q,value:e,canTrack:t}),Z=()=>c()&&typeof localStorage!="undefined"?localStorage:void 0,Ne=({key:e,canTrack:t})=>{var n;try{return t?(n=Z())==null?void 0:n.getItem(e):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},De=({key:e,canTrack:t,value:n})=>{var r;try{t&&((r=Z())==null||r.setItem(e,n))}catch(o){console.debug("[LocalStorage] SET error: ",o)}},ee="builderVisitorId",_e=({canTrack:e})=>{if(!e)return;const t=Ne({key:ee,canTrack:e});if(p(t))return t;{const n=je();return Ke({id:n,canTrack:e}),n}},je=()=>Y(),Ke=({id:e,canTrack:t})=>De({key:ee,value:e,canTrack:t}),Ge=async({canTrack:e})=>{if(!e)return{visitorId:void 0,sessionId:void 0};const t=await Ue({canTrack:e}),n=_e({canTrack:e});return{sessionId:t,visitorId:n}},We=async({type:e,canTrack:t,apiKey:n,metadata:r,...o})=>({type:e,data:{...o,metadata:{url:location.href,...r},...await Ge({canTrack:t}),userAttributes:N(),ownerId:n}});async function te(e){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(e.canTrack&&!F()&&(c()||I==="reactNative"))return fetch("https://cdn.builder.io/api/v1/track",{method:"POST",body:JSON.stringify({events:[await We(e)]}),headers:{"content-type":"application/json"},mode:"cors"}).catch(t=>{console.error("Failed to track: ",t)})}const $e=e=>te({...e,canTrack:!0}),ze=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function ne(e,t){const n=new URL(t.origin),r=n.hostname;return(e||ze).findIndex(o=>o.startsWith("*.")?r.endsWith(o.slice(1)):o===r)>-1}const Je="1.0.22",B={};function re(e,t){let n=B[e];if(n||(n=B[e]=[]),n.push(t),c()){const r={type:"builder.register",data:{type:e,info:t}};try{parent.postMessage(r,"*"),parent!==window&&window.postMessage(r,"*")}catch(o){console.debug("Could not postmessage",o)}}}const He=()=>{re("insertMenu",{name:"_default",default:!0,items:[{name:"Box"},{name:"Text"},{name:"Image"},{name:"Columns"},{name:"Core:Section"},{name:"Core:Button"},{name:"Embed"},{name:"Custom Code"}]})};let L=!1;const oe=(e={})=>{var t,n;L||(L=!0,c()&&((t=window.parent)==null||t.postMessage({type:"builder.sdkInfo",data:{target:I,version:Je,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0}},"*"),(n=window.parent)==null||n.postMessage({type:"builder.updateContent",data:{options:e}},"*"),window.addEventListener("message",r=>{var s,a;if(!ne(e.trustedHosts,r))return;const{data:o}=r;if(o!=null&&o.type)switch(o.type){case"builder.evaluate":{const l=o.data.text,y=o.data.arguments||[],m=o.data.id,E=new Function(l);let u,g=null;try{u=E.apply(null,y)}catch(h){g=h}g?(s=window.parent)==null||s.postMessage({type:"builder.evaluateError",data:{id:m,error:g.message}},"*"):u&&typeof u.then=="function"?u.then(h=>{var S;(S=window.parent)==null||S.postMessage({type:"builder.evaluateResult",data:{id:m,result:h}},"*")}).catch(console.error):(a=window.parent)==null||a.postMessage({type:"builder.evaluateResult",data:{result:u,id:m}},"*");break}}})))},se=({model:e,trustedHosts:t,callbacks:n})=>r=>{if(!ne(t,r))return;const{data:o}=r;if(o)switch(o.type){case"builder.configureSdk":{n.configureSdk(o.data);break}case"builder.triggerAnimation":{n.animation(o.data);break}case"builder.contentUpdate":{const s=o.data,a=s.key||s.alias||s.entry||s.modelName,l=s.data;a===e&&n.contentUpdate(l);break}}},Xe=(e,t,n)=>{if(!c)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};oe();const r=se({callbacks:{contentUpdate:t,animation:()=>{},configureSdk:()=>{}},model:e,trustedHosts:n==null?void 0:n.trustedHosts});return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},V={};function qe(e){if(c()){Object.assign(V,e);const t={type:"builder.settingsChange",data:V};parent.postMessage(t,"*")}}const Ye=async e=>{var r,o,s;const t=e.path||((r=e.url)==null?void 0:r.pathname)||((o=e.userAttributes)==null?void 0:o.urlPath),n={...e,apiKey:e.apiKey,model:e.model||"page",userAttributes:{...e.userAttributes,...t?{urlPath:t}:{}},options:P(e.searchParams||((s=e.url)==null?void 0:s.searchParams)||e.options)};return{apiKey:n.apiKey,model:n.model,content:await H(n)}};exports.MSG_PREFIX=b;exports.TARGET=I;exports._processContentResult=X;exports._track=te;exports.checkIsDefined=p;exports.createEditorListener=se;exports.createRegisterComponentMessage=Ee;exports.fastClone=k;exports.fetch=J;exports.fetchBuilderProps=Ye;exports.fetchEntries=q;exports.fetchOneEntry=H;exports.getBuilderSearchParams=P;exports.getDefaultCanTrack=$;exports.getUserAttributes=N;exports.handleABTestingSync=Ie;exports.isBrowser=c;exports.isEditing=F;exports.isPreviewing=Le;exports.logger=d;exports.register=re;exports.registerInsertMenu=He;exports.serializeComponentInfo=z;exports.setEditorSettings=qe;exports.setupBrowserForEditing=oe;exports.subscribeToEditor=Xe;exports.track=$e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./server-entry-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./server-entry-3abae5dd.cjs");exports._processContentResult=e._processContentResult;exports.createRegisterComponentMessage=e.createRegisterComponentMessage;exports.fetchBuilderProps=e.fetchBuilderProps;exports.fetchEntries=e.fetchEntries;exports.fetchOneEntry=e.fetchOneEntry;exports.getBuilderSearchParams=e.getBuilderSearchParams;exports.isEditing=e.isEditing;exports.isPreviewing=e.isPreviewing;exports.register=e.register;exports.setEditorSettings=e.setEditorSettings;exports.subscribeToEditor=e.subscribeToEditor;exports.track=e.track;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _processContentResult as r, createRegisterComponentMessage as s, fetchBuilderProps as i, fetchEntries as n, fetchOneEntry as o, getBuilderSearchParams as c, isEditing as g, isPreviewing as a, register as d, setEditorSettings as E, subscribeToEditor as f, track as h } from "./server-entry-
|
|
1
|
+
import { _processContentResult as r, createRegisterComponentMessage as s, fetchBuilderProps as i, fetchEntries as n, fetchOneEntry as o, getBuilderSearchParams as c, isEditing as g, isPreviewing as a, register as d, setEditorSettings as E, subscribeToEditor as f, track as h } from "./server-entry-14d7a1d0.js";
|
|
2
2
|
export {
|
|
3
3
|
r as _processContentResult,
|
|
4
4
|
s as createRegisterComponentMessage,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-react",
|
|
3
3
|
"description": "Builder.io SDK for React",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.22",
|
|
5
5
|
"homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/react",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|
|
@@ -79,6 +79,11 @@
|
|
|
79
79
|
"require": "./lib/browser/index.cjs"
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
|
+
"./node/init": {
|
|
83
|
+
"types": "./types/functions/evaluate/node-runtime/init.d.ts",
|
|
84
|
+
"import": "./lib/node/init.mjs",
|
|
85
|
+
"require": "./lib/node/init.cjs"
|
|
86
|
+
},
|
|
82
87
|
"./edge": {
|
|
83
88
|
"types": "./types/index.d.ts",
|
|
84
89
|
"import": "./lib/edge/edge-entry.mjs",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BuilderAnimation } from '../../types/builder-block';
|
|
2
|
+
export declare const camelCaseToKebabCase: (str?: string) => string;
|
|
2
3
|
export declare function bindAnimations(animations: BuilderAnimation[]): void;
|
|
3
4
|
export declare function triggerAnimation(animation: BuilderAnimation): void;
|
|
4
|
-
export declare function bindHoverAnimation(animation: BuilderAnimation): void;
|
|
5
5
|
export declare function bindScrollInViewAnimation(animation: BuilderAnimation): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.22";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function initializes the SDK on a Node server. It handles importing the
|
|
3
|
+
* `isolated-vm` package which is needed for dynamic bindings.
|
|
4
|
+
*
|
|
5
|
+
* NOTE: this function cannot be called on the client. You must call this function
|
|
6
|
+
* from a server-only location, such as:
|
|
7
|
+
* - The NextJS Pages router's `_document.tsx`
|
|
8
|
+
* - Your Remix route's `loader`
|
|
9
|
+
*/
|
|
10
|
+
export declare const initializeNodeRuntime: () => void;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import type { ExecutorArgs } from '../helpers';
|
|
2
|
+
/**
|
|
3
|
+
* Set the `isolated-vm` instance to be used by the node runtime.
|
|
4
|
+
* This is useful for environments that are not able to rely on our
|
|
5
|
+
* `safeDynamicRequire` trick to import the `isolated-vm` package.
|
|
6
|
+
*/
|
|
7
|
+
export declare const setIvm: (ivm: typeof import('isolated-vm')) => void;
|
|
2
8
|
export declare const runInNode: ({ code, builder, context, event, localState, rootSetState, rootState }: ExecutorArgs) => any;
|
|
@@ -131,9 +131,9 @@ export interface GetContentOptions {
|
|
|
131
131
|
/**
|
|
132
132
|
* Optional override of the `fetch` function. (Defaults to global `fetch`)
|
|
133
133
|
*/
|
|
134
|
-
fetch?:
|
|
134
|
+
fetch?: (input: string, init?: object) => Promise<any>;
|
|
135
135
|
/**
|
|
136
|
-
* Optional fetch options to be passed to the `fetch` function.
|
|
136
|
+
* Optional fetch options to be passed as the second argument to the `fetch` function.
|
|
137
137
|
*/
|
|
138
|
-
fetchOptions?:
|
|
138
|
+
fetchOptions?: object;
|
|
139
139
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Search } from '../helpers/search/search';
|
|
2
|
-
export declare function isPreviewing(
|
|
2
|
+
export declare function isPreviewing(_search?: Search): boolean;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const b="react",I="[Builder.io]: ",d={log:(...e)=>console.log(I,...e),error:(...e)=>console.error(I,...e),warn:(...e)=>console.warn(I,...e),debug:(...e)=>console.debug(I,...e)};function c(){return typeof window!="undefined"&&typeof document!="undefined"}const ce=e=>{const t={};return e.forEach((n,r)=>{t[r]=n}),t},M=e=>e instanceof URLSearchParams?ce(e):e,F=e=>typeof e=="string"?e:e instanceof URLSearchParams?e.toString():new URLSearchParams(e).toString();function ue(){return c()&&window.self!==window.top}function k(e){return ue()&&F(e||window.location.search).indexOf("builder.frameEditing=")!==-1}const de=()=>{if(c()){const e=new URL(location.href);return e.pathname===""&&(e.pathname="/"),e}else return console.warn("Cannot get location for tracking in non-browser environment"),null},le=()=>typeof navigator=="object"&&navigator.userAgent||"",N=()=>{const e=le(),t={Android(){return e.match(/Android/i)},BlackBerry(){return e.match(/BlackBerry/i)},iOS(){return e.match(/iPhone|iPod/i)},Opera(){return e.match(/Opera Mini/i)},Windows(){return e.match(/IEMobile/i)||e.match(/WPDesktop/i)},any(){return t.Android()||t.BlackBerry()||t.iOS()||t.Opera()||t.Windows()||b==="reactNative"}},n=e.match(/Tablet|iPad/i),r=de();return{urlPath:r==null?void 0:r.pathname,host:(r==null?void 0:r.host)||(r==null?void 0:r.hostname),device:n?"tablet":t.any()?"mobile":"desktop"}},p=e=>e!=null,C=e=>JSON.parse(JSON.stringify(e)),fe=e=>{if(e==="localhost"||e==="127.0.0.1")return e;const t=e.split(".");return t.length>2?t.slice(1).join("."):e},D=({name:e,canTrack:t})=>{var n;try{return t?(n=document.cookie.split("; ").find(r=>r.startsWith(`${e}=`)))==null?void 0:n.split("=")[1]:void 0}catch(r){d.warn("[COOKIE] GET error: ",(r==null?void 0:r.message)||r);return}},j=async e=>D(e),ge=e=>e.map(([t,n])=>n?`${t}=${n}`:t).filter(p).join("; "),he=[["secure",""],["SameSite","None"]],pe=({name:e,value:t,expires:n})=>{const o=(c()?location.protocol==="https:":!0)?he:[[]],s=n?[["expires",n.toUTCString()]]:[[]],a=[[e,t],...s,["path","/"],["domain",fe(window.location.hostname)],...o];return ge(a)},_=async({name:e,value:t,expires:n,canTrack:r})=>{try{if(!r)return;const o=pe({name:e,value:t,expires:n});document.cookie=o}catch(o){d.warn("[COOKIE] SET error: ",(o==null?void 0:o.message)||o)}},me="builder.tests",P=e=>`${me}.${e}`,ye=({contentId:e})=>j({name:P(e),canTrack:!0}),we=({contentId:e})=>D({name:P(e),canTrack:!0}),Se=({contentId:e,value:t})=>_({name:P(e),value:t,canTrack:!0}),K=e=>p(e.id)&&p(e.variations)&&Object.keys(e.variations).length>0,be=({id:e,variations:t})=>{var o;let n=0;const r=Math.random();for(const s in t){const a=(o=t[s])==null?void 0:o.testRatio;if(n+=a,r<n)return s}return e},W=e=>{const t=be(e);return Se({contentId:e.id,value:t}).catch(n=>{d.error("could not store A/B test variation: ",n)}),t},$=({item:e,testGroupId:t})=>{const n=e.variations[t];return t===e.id||!n?{testVariationId:e.id,testVariationName:"Default"}:{data:n.data,testVariationId:n.id,testVariationName:n.name||(n.id===e.id?"Default":"")}},Ie=({item:e,canTrack:t})=>{if(!t)return e;if(!e)return;if(!K(e))return e;const n=we({contentId:e.id})||W({variations:e.variations,id:e.id}),r=$({item:e,testGroupId:n});return{...e,...r}},ve=async({item:e,canTrack:t})=>{if(!t||!K(e))return e;const r=await ye({contentId:e.id})||W({variations:e.variations,id:e.id}),o=$({item:e,testGroupId:r});return{...e,...o}},G=e=>p(e)?e:!0,Ee=e=>({type:"builder.registerComponent",data:z(e)}),ke=e=>{const t=e.toString().trim();return`return (${!t.startsWith("function")&&!t.startsWith("(")?"function ":""}${t}).apply(this, arguments)`},Ce=e=>typeof e=="function"?ke(e):C(e),z=({inputs:e,...t})=>({...C(t),inputs:e==null?void 0:e.map(n=>Object.entries(n).reduce((r,[o,s])=>({...r,[o]:Ce(s)}),{}))});function Pe(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function Oe(){const e=Pe().fetch;if(typeof e=="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 e}const J=Oe();function v(e,t=null,n="."){return Object.keys(e).reduce((r,o)=>{const s=e[o],a=[t,o].filter(Boolean).join(n);return[typeof s=="object",s!==null,!(Array.isArray(s)&&s.length===0)].every(Boolean)?{...r,...v(s,a,n)}:{...r,[a]:s}},{})}const Te="v3",R="builder.",xe="options.",O=e=>{if(!e)return{};const t=M(e),n={};return Object.keys(t).forEach(r=>{if(r.startsWith(R)){const o=r.replace(R,"").replace(xe,"");n[o]=t[r]}}),n},Ae=()=>{if(!c())return{};const e=new URLSearchParams(window.location.search);return O(e)},B=e=>typeof e=="number"&&!isNaN(e)&&e>=0,T=e=>{const{limit:t=30,userAttributes:n,query:r,model:o,apiKey:s,enrich:a,locale:l,apiVersion:y=Te,fields:m,omit:E,offset:u,cacheSeconds:g,staleCacheSeconds:h,sort:w,includeUnpublished:x}=e;if(!s)throw new Error("Missing API key");if(!["v3"].includes(y))throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);const ie=t!==1,i=new URL(`https://cdn.builder.io/api/${y}/content/${o}`);if(i.searchParams.set("apiKey",s),i.searchParams.set("limit",String(t)),i.searchParams.set("noTraverse",String(ie)),i.searchParams.set("includeRefs",String(!0)),l&&i.searchParams.set("locale",l),a&&i.searchParams.set("enrich",String(a)),i.searchParams.set("omit",E||"meta.componentsUsed"),m&&i.searchParams.set("fields",m),Number.isFinite(u)&&u>-1&&i.searchParams.set("offset",String(Math.floor(u))),typeof x=="boolean"&&i.searchParams.set("includeUnpublished",String(x)),g&&B(g)&&i.searchParams.set("cacheSeconds",String(g)),h&&B(h)&&i.searchParams.set("staleCacheSeconds",String(h)),w){const f=v({sort:w});for(const S in f)i.searchParams.set(S,JSON.stringify(f[S]))}const ae={...Ae(),...M(e.options||{})},A=v(ae);for(const f in A)i.searchParams.set(f,String(A[f]));if(n&&i.searchParams.set("userAttributes",JSON.stringify(n)),r){const f=v({query:r});for(const S in f)i.searchParams.set(S,JSON.stringify(f[S]))}return i},Re=e=>"results"in e;async function H(e){const t=await q({...e,limit:1});return t&&t[0]||null}const Be=async e=>{var s;const t=T(e);return await(await((s=e.fetch)!=null?s:J)(t.href,e.fetchOptions)).json()},X=async(e,t,n=T(e))=>{const r=G(e.canTrack);if(n.search.includes("preview="),!r||!(c()||b==="reactNative"))return t.results;try{const o=[];for(const s of t.results)o.push(await ve({item:s,canTrack:r}));t.results=o}catch(o){d.error("Could not process A/B tests. ",o)}return t.results};async function q(e){try{const t=T(e),n=await Be(e);return Re(n)?X(e,n):(d.error("Error fetching data. ",{url:t,content:n,options:e}),null)}catch(t){return d.error("Error fetching data. ",t),null}}function Le(e){if(!c())return!1;const t=F(e||window.location.search);return k(t)?!1:t.indexOf("builder.preview=")!==-1}function Ve(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){const t=Math.random()*16|0;return(e=="x"?t:t&3|8).toString(16)})}function Y(){return Ve().replace(/-/g,"")}const Q="builderSessionId",Ue=async({canTrack:e})=>{if(!e)return;const t=await j({name:Q,canTrack:e});if(p(t))return t;{const n=Me();return Fe({id:n,canTrack:e}),n}},Me=()=>Y(),Fe=({id:e,canTrack:t})=>_({name:Q,value:e,canTrack:t}),Z=()=>c()&&typeof localStorage!="undefined"?localStorage:void 0,Ne=({key:e,canTrack:t})=>{var n;try{return t?(n=Z())==null?void 0:n.getItem(e):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},De=({key:e,canTrack:t,value:n})=>{var r;try{t&&((r=Z())==null||r.setItem(e,n))}catch(o){console.debug("[LocalStorage] SET error: ",o)}},ee="builderVisitorId",je=({canTrack:e})=>{if(!e)return;const t=Ne({key:ee,canTrack:e});if(p(t))return t;{const n=_e();return Ke({id:n,canTrack:e}),n}},_e=()=>Y(),Ke=({id:e,canTrack:t})=>De({key:ee,value:e,canTrack:t}),We=async({canTrack:e})=>{if(!e)return{visitorId:void 0,sessionId:void 0};const t=await Ue({canTrack:e}),n=je({canTrack:e});return{sessionId:t,visitorId:n}},$e=async({type:e,canTrack:t,apiKey:n,metadata:r,...o})=>({type:e,data:{...o,metadata:{url:location.href,...r},...await We({canTrack:t}),userAttributes:N(),ownerId:n}});async function te(e){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(e.canTrack&&!k()&&(c()||b==="reactNative"))return fetch("https://cdn.builder.io/api/v1/track",{method:"POST",body:JSON.stringify({events:[await $e(e)]}),headers:{"content-type":"application/json"},mode:"cors"}).catch(t=>{console.error("Failed to track: ",t)})}const Ge=e=>te({...e,canTrack:!0}),ze=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function ne(e,t){const n=new URL(t.origin),r=n.hostname;return(e||ze).findIndex(o=>o.startsWith("*.")?r.endsWith(o.slice(1)):o===r)>-1}const Je="1.0.20",L={};function re(e,t){let n=L[e];if(n||(n=L[e]=[]),n.push(t),c()){const r={type:"builder.register",data:{type:e,info:t}};try{parent.postMessage(r,"*"),parent!==window&&window.postMessage(r,"*")}catch(o){console.debug("Could not postmessage",o)}}}const He=()=>{re("insertMenu",{name:"_default",default:!0,items:[{name:"Box"},{name:"Text"},{name:"Image"},{name:"Columns"},{name:"Core:Section"},{name:"Core:Button"},{name:"Embed"},{name:"Custom Code"}]})};let V=!1;const oe=(e={})=>{var t,n;V||(V=!0,c()&&((t=window.parent)==null||t.postMessage({type:"builder.sdkInfo",data:{target:b,version:Je,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0}},"*"),(n=window.parent)==null||n.postMessage({type:"builder.updateContent",data:{options:e}},"*"),window.addEventListener("message",r=>{var s,a;if(!ne(e.trustedHosts,r))return;const{data:o}=r;if(o!=null&&o.type)switch(o.type){case"builder.evaluate":{const l=o.data.text,y=o.data.arguments||[],m=o.data.id,E=new Function(l);let u,g=null;try{u=E.apply(null,y)}catch(h){g=h}g?(s=window.parent)==null||s.postMessage({type:"builder.evaluateError",data:{id:m,error:g.message}},"*"):u&&typeof u.then=="function"?u.then(h=>{var w;(w=window.parent)==null||w.postMessage({type:"builder.evaluateResult",data:{id:m,result:h}},"*")}).catch(console.error):(a=window.parent)==null||a.postMessage({type:"builder.evaluateResult",data:{result:u,id:m}},"*");break}}})))},se=({model:e,trustedHosts:t,callbacks:n})=>r=>{if(!ne(t,r))return;const{data:o}=r;if(o)switch(o.type){case"builder.configureSdk":{n.configureSdk(o.data);break}case"builder.triggerAnimation":{n.animation(o.data);break}case"builder.contentUpdate":{const s=o.data,a=s.key||s.alias||s.entry||s.modelName,l=s.data;a===e&&n.contentUpdate(l);break}}},Xe=(e,t,n)=>{if(!c)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};oe();const r=se({callbacks:{contentUpdate:t,animation:()=>{},configureSdk:()=>{}},model:e,trustedHosts:n==null?void 0:n.trustedHosts});return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},U={};function qe(e){if(c()){Object.assign(U,e);const t={type:"builder.settingsChange",data:U};parent.postMessage(t,"*")}}const Ye=async e=>{var r,o,s;const t=e.path||((r=e.url)==null?void 0:r.pathname)||((o=e.userAttributes)==null?void 0:o.urlPath),n={...e,apiKey:e.apiKey,model:e.model||"page",userAttributes:{...e.userAttributes,...t?{urlPath:t}:{}},options:O(e.searchParams||((s=e.url)==null?void 0:s.searchParams)||e.options)};return{apiKey:n.apiKey,model:n.model,content:await H(n)}};exports.TARGET=b;exports._processContentResult=X;exports._track=te;exports.checkIsDefined=p;exports.createEditorListener=se;exports.createRegisterComponentMessage=Ee;exports.fastClone=C;exports.fetch=J;exports.fetchBuilderProps=Ye;exports.fetchEntries=q;exports.fetchOneEntry=H;exports.getBuilderSearchParams=O;exports.getDefaultCanTrack=G;exports.getUserAttributes=N;exports.handleABTestingSync=Ie;exports.isBrowser=c;exports.isEditing=k;exports.isPreviewing=Le;exports.logger=d;exports.register=re;exports.registerInsertMenu=He;exports.serializeComponentInfo=z;exports.setEditorSettings=qe;exports.setupBrowserForEditing=oe;exports.subscribeToEditor=Xe;exports.track=Ge;
|