@builder.io/sdk-react 0.13.4 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/index.cjs +16 -16
- package/lib/browser/index.mjs +254 -277
- package/lib/browser/server-entry-a595b1cf.cjs +2 -0
- package/lib/browser/{server-entry-2a8acf68.js → server-entry-f6f9bdcb.js} +221 -230
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +9 -11
- package/lib/edge/index.cjs +28 -28
- package/lib/edge/index.mjs +381 -404
- package/lib/edge/server-entry-a595b1cf.cjs +2 -0
- package/lib/{node/server-entry-c8223f30.js → edge/server-entry-f6f9bdcb.js} +221 -230
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +9 -11
- package/lib/node/index.cjs +10 -10
- package/lib/node/index.mjs +274 -294
- package/lib/node/server-entry-31b5d683.cjs +2 -0
- package/lib/{edge/server-entry-13732838.js → node/server-entry-c2b6d198.js} +221 -230
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +9 -11
- package/package.json +1 -1
- package/types/components/content-variants/content-variants.types.d.ts +0 -2
- package/types/constants/sdk-version.d.ts +1 -1
- package/types/functions/get-content/index.d.ts +0 -10
- package/types/functions/get-content/types.d.ts +0 -11
- package/types/functions/register-component.d.ts +0 -9
- package/types/index-helpers/blocks-exports.d.ts +0 -8
- package/types/server-index.d.ts +1 -1
- package/lib/browser/server-entry-881c178e.cjs +0 -2
- package/lib/edge/server-entry-881c178e.cjs +0 -2
- package/lib/node/server-entry-ad7cbbbf.cjs +0 -2
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
const
|
|
2
|
-
log: (...e) => console.log(
|
|
3
|
-
error: (...e) => console.error(
|
|
4
|
-
warn: (...e) => console.warn(
|
|
5
|
-
debug: (...e) => console.debug(
|
|
1
|
+
const I = "react", S = "[Builder.io]: ", f = {
|
|
2
|
+
log: (...e) => console.log(S, ...e),
|
|
3
|
+
error: (...e) => console.error(S, ...e),
|
|
4
|
+
warn: (...e) => console.warn(S, ...e),
|
|
5
|
+
debug: (...e) => console.debug(S, ...e)
|
|
6
6
|
};
|
|
7
|
-
function
|
|
7
|
+
function c() {
|
|
8
8
|
return typeof window != "undefined" && typeof document != "undefined";
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
return
|
|
10
|
+
function X() {
|
|
11
|
+
return c() && window.self !== window.top;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
return
|
|
13
|
+
function V() {
|
|
14
|
+
return X() && window.location.search.indexOf("builder.frameEditing=") !== -1;
|
|
15
15
|
}
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
16
|
+
const Y = () => {
|
|
17
|
+
if (c()) {
|
|
18
18
|
const e = new URL(location.href);
|
|
19
19
|
return e.pathname === "" && (e.pathname = "/"), e;
|
|
20
20
|
} else
|
|
21
21
|
return console.warn("Cannot get location for tracking in non-browser environment"), null;
|
|
22
|
-
},
|
|
23
|
-
const e =
|
|
22
|
+
}, Q = () => typeof navigator == "object" && navigator.userAgent || "", Z = () => {
|
|
23
|
+
const e = Q(), t = {
|
|
24
24
|
Android() {
|
|
25
25
|
return e.match(/Android/i);
|
|
26
26
|
},
|
|
@@ -37,20 +37,20 @@ const ee = () => {
|
|
|
37
37
|
return e.match(/IEMobile/i) || e.match(/WPDesktop/i);
|
|
38
38
|
},
|
|
39
39
|
any() {
|
|
40
|
-
return t.Android() || t.BlackBerry() || t.iOS() || t.Opera() || t.Windows() ||
|
|
40
|
+
return t.Android() || t.BlackBerry() || t.iOS() || t.Opera() || t.Windows() || I === "reactNative";
|
|
41
41
|
}
|
|
42
|
-
}, n = e.match(/Tablet|iPad/i), r =
|
|
42
|
+
}, n = e.match(/Tablet|iPad/i), r = Y();
|
|
43
43
|
return {
|
|
44
44
|
urlPath: r == null ? void 0 : r.pathname,
|
|
45
45
|
host: (r == null ? void 0 : r.host) || (r == null ? void 0 : r.hostname),
|
|
46
46
|
device: n ? "tablet" : t.any() ? "mobile" : "desktop"
|
|
47
47
|
};
|
|
48
|
-
}, m = (e) => e != null,
|
|
48
|
+
}, m = (e) => e != null, L = (e) => JSON.parse(JSON.stringify(e)), ee = (e) => {
|
|
49
49
|
if (e === "localhost" || e === "127.0.0.1")
|
|
50
50
|
return e;
|
|
51
51
|
const t = e.split(".");
|
|
52
52
|
return t.length > 2 ? t.slice(1).join(".") : e;
|
|
53
|
-
},
|
|
53
|
+
}, U = ({
|
|
54
54
|
name: e,
|
|
55
55
|
canTrack: t
|
|
56
56
|
}) => {
|
|
@@ -58,17 +58,17 @@ const ee = () => {
|
|
|
58
58
|
try {
|
|
59
59
|
return t ? (n = document.cookie.split("; ").find((r) => r.startsWith(`${e}=`))) == null ? void 0 : n.split("=")[1] : void 0;
|
|
60
60
|
} catch (r) {
|
|
61
|
-
|
|
61
|
+
f.warn("[COOKIE] GET error: ", (r == null ? void 0 : r.message) || r);
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
-
},
|
|
64
|
+
}, M = async (e) => U(e), te = (e) => e.map(([t, n]) => n ? `${t}=${n}` : t).filter(m).join("; "), ne = [["secure", ""], ["SameSite", "None"]], re = ({
|
|
65
65
|
name: e,
|
|
66
66
|
value: t,
|
|
67
67
|
expires: n
|
|
68
68
|
}) => {
|
|
69
|
-
const o = (
|
|
70
|
-
return
|
|
71
|
-
},
|
|
69
|
+
const o = (c() ? location.protocol === "https:" : !0) ? ne : [[]], s = n ? [["expires", n.toUTCString()]] : [[]], i = [[e, t], ...s, ["path", "/"], ["domain", ee(window.location.hostname)], ...o];
|
|
70
|
+
return te(i);
|
|
71
|
+
}, N = async ({
|
|
72
72
|
name: e,
|
|
73
73
|
value: t,
|
|
74
74
|
expires: n,
|
|
@@ -77,33 +77,33 @@ const ee = () => {
|
|
|
77
77
|
try {
|
|
78
78
|
if (!r)
|
|
79
79
|
return;
|
|
80
|
-
const o =
|
|
80
|
+
const o = re({
|
|
81
81
|
name: e,
|
|
82
82
|
value: t,
|
|
83
83
|
expires: n
|
|
84
84
|
});
|
|
85
85
|
document.cookie = o;
|
|
86
86
|
} catch (o) {
|
|
87
|
-
|
|
87
|
+
f.warn("[COOKIE] SET error: ", (o == null ? void 0 : o.message) || o);
|
|
88
88
|
}
|
|
89
|
-
},
|
|
89
|
+
}, oe = "builder.tests", E = (e) => `${oe}.${e}`, se = ({
|
|
90
90
|
contentId: e
|
|
91
|
-
}) =>
|
|
92
|
-
name:
|
|
91
|
+
}) => M({
|
|
92
|
+
name: E(e),
|
|
93
93
|
canTrack: !0
|
|
94
|
-
}),
|
|
94
|
+
}), ae = ({
|
|
95
95
|
contentId: e
|
|
96
|
-
}) =>
|
|
97
|
-
name:
|
|
96
|
+
}) => U({
|
|
97
|
+
name: E(e),
|
|
98
98
|
canTrack: !0
|
|
99
|
-
}),
|
|
99
|
+
}), ie = ({
|
|
100
100
|
contentId: e,
|
|
101
101
|
value: t
|
|
102
|
-
}) =>
|
|
103
|
-
name:
|
|
102
|
+
}) => N({
|
|
103
|
+
name: E(e),
|
|
104
104
|
value: t,
|
|
105
105
|
canTrack: !0
|
|
106
|
-
}),
|
|
106
|
+
}), F = (e) => m(e.id) && m(e.variations) && Object.keys(e.variations).length > 0, ce = ({
|
|
107
107
|
id: e,
|
|
108
108
|
variations: t
|
|
109
109
|
}) => {
|
|
@@ -111,20 +111,20 @@ const ee = () => {
|
|
|
111
111
|
let n = 0;
|
|
112
112
|
const r = Math.random();
|
|
113
113
|
for (const s in t) {
|
|
114
|
-
const
|
|
115
|
-
if (n +=
|
|
114
|
+
const i = (o = t[s]) == null ? void 0 : o.testRatio;
|
|
115
|
+
if (n += i, r < n)
|
|
116
116
|
return s;
|
|
117
117
|
}
|
|
118
118
|
return e;
|
|
119
|
-
},
|
|
120
|
-
const t =
|
|
121
|
-
return
|
|
119
|
+
}, j = (e) => {
|
|
120
|
+
const t = ce(e);
|
|
121
|
+
return ie({
|
|
122
122
|
contentId: e.id,
|
|
123
123
|
value: t
|
|
124
124
|
}).catch((n) => {
|
|
125
|
-
|
|
125
|
+
f.error("could not store A/B test variation: ", n);
|
|
126
126
|
}), t;
|
|
127
|
-
},
|
|
127
|
+
}, D = ({
|
|
128
128
|
item: e,
|
|
129
129
|
testGroupId: t
|
|
130
130
|
}) => {
|
|
@@ -146,14 +146,14 @@ const ee = () => {
|
|
|
146
146
|
return e;
|
|
147
147
|
if (!e)
|
|
148
148
|
return;
|
|
149
|
-
if (!
|
|
149
|
+
if (!F(e))
|
|
150
150
|
return e;
|
|
151
|
-
const n =
|
|
151
|
+
const n = ae({
|
|
152
152
|
contentId: e.id
|
|
153
|
-
}) ||
|
|
153
|
+
}) || j({
|
|
154
154
|
variations: e.variations,
|
|
155
155
|
id: e.id
|
|
156
|
-
}), r =
|
|
156
|
+
}), r = D({
|
|
157
157
|
item: e,
|
|
158
158
|
testGroupId: n
|
|
159
159
|
});
|
|
@@ -161,18 +161,18 @@ const ee = () => {
|
|
|
161
161
|
...e,
|
|
162
162
|
...r
|
|
163
163
|
};
|
|
164
|
-
},
|
|
164
|
+
}, ue = async ({
|
|
165
165
|
item: e,
|
|
166
166
|
canTrack: t
|
|
167
167
|
}) => {
|
|
168
|
-
if (!t || !
|
|
168
|
+
if (!t || !F(e))
|
|
169
169
|
return e;
|
|
170
|
-
const r = await
|
|
170
|
+
const r = await se({
|
|
171
171
|
contentId: e.id
|
|
172
|
-
}) ||
|
|
172
|
+
}) || j({
|
|
173
173
|
variations: e.variations,
|
|
174
174
|
id: e.id
|
|
175
|
-
}), o =
|
|
175
|
+
}), o = D({
|
|
176
176
|
item: e,
|
|
177
177
|
testGroupId: r
|
|
178
178
|
});
|
|
@@ -180,240 +180,234 @@ const ee = () => {
|
|
|
180
180
|
...e,
|
|
181
181
|
...o
|
|
182
182
|
};
|
|
183
|
-
},
|
|
183
|
+
}, de = (e) => m(e) ? e : !0, $e = (e) => ({
|
|
184
184
|
type: "builder.registerComponent",
|
|
185
|
-
data:
|
|
186
|
-
}),
|
|
185
|
+
data: he(e)
|
|
186
|
+
}), le = (e) => {
|
|
187
187
|
const t = e.toString().trim();
|
|
188
188
|
return `return (${!t.startsWith("function") && !t.startsWith("(") ? "function " : ""}${t}).apply(this, arguments)`;
|
|
189
|
-
},
|
|
189
|
+
}, fe = (e) => typeof e == "function" ? le(e) : L(e), he = ({
|
|
190
190
|
inputs: e,
|
|
191
191
|
...t
|
|
192
192
|
}) => ({
|
|
193
|
-
...
|
|
193
|
+
...L(t),
|
|
194
194
|
inputs: e == null ? void 0 : e.map((n) => Object.entries(n).reduce((r, [o, s]) => ({
|
|
195
195
|
...r,
|
|
196
|
-
[o]:
|
|
196
|
+
[o]: fe(s)
|
|
197
197
|
}), {}))
|
|
198
198
|
});
|
|
199
|
-
function
|
|
199
|
+
function ge() {
|
|
200
200
|
return typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : globalThis;
|
|
201
201
|
}
|
|
202
|
-
function
|
|
203
|
-
const e =
|
|
202
|
+
function pe() {
|
|
203
|
+
const e = ge().fetch;
|
|
204
204
|
if (typeof e == "undefined")
|
|
205
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
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
207
|
return e;
|
|
208
208
|
}
|
|
209
|
-
const
|
|
210
|
-
function
|
|
209
|
+
const me = pe();
|
|
210
|
+
function v(e, t = null, n = ".") {
|
|
211
211
|
return Object.keys(e).reduce((r, o) => {
|
|
212
|
-
const s = e[o],
|
|
212
|
+
const s = e[o], i = [t, o].filter(Boolean).join(n);
|
|
213
213
|
return [typeof s == "object", s !== null, !(Array.isArray(s) && s.length === 0)].every(Boolean) ? {
|
|
214
214
|
...r,
|
|
215
|
-
...
|
|
215
|
+
...v(s, i, n)
|
|
216
216
|
} : {
|
|
217
217
|
...r,
|
|
218
|
-
[
|
|
218
|
+
[i]: s
|
|
219
219
|
};
|
|
220
220
|
}, {});
|
|
221
221
|
}
|
|
222
|
-
const
|
|
222
|
+
const ye = "v3", x = "builder.", we = "options.", be = (e) => {
|
|
223
223
|
const t = {};
|
|
224
224
|
return e.forEach((n, r) => {
|
|
225
225
|
t[r] = n;
|
|
226
226
|
}), t;
|
|
227
|
-
},
|
|
227
|
+
}, K = (e) => {
|
|
228
228
|
if (!e)
|
|
229
229
|
return {};
|
|
230
|
-
const t =
|
|
230
|
+
const t = _(e), n = {};
|
|
231
231
|
return Object.keys(t).forEach((r) => {
|
|
232
|
-
if (r.startsWith(
|
|
233
|
-
const o = r.replace(
|
|
232
|
+
if (r.startsWith(x)) {
|
|
233
|
+
const o = r.replace(x, "").replace(we, "");
|
|
234
234
|
n[o] = t[r];
|
|
235
235
|
}
|
|
236
236
|
}), n;
|
|
237
|
-
},
|
|
238
|
-
if (!
|
|
237
|
+
}, Se = () => {
|
|
238
|
+
if (!c())
|
|
239
239
|
return {};
|
|
240
240
|
const e = new URLSearchParams(window.location.search);
|
|
241
|
-
return
|
|
242
|
-
},
|
|
243
|
-
let {
|
|
244
|
-
noTraverse: t = !1
|
|
245
|
-
} = e;
|
|
241
|
+
return K(e);
|
|
242
|
+
}, _ = (e) => e instanceof URLSearchParams ? be(e) : e, T = (e) => typeof e == "number" && !isNaN(e) && e >= 0, C = (e) => {
|
|
246
243
|
const {
|
|
247
|
-
limit:
|
|
248
|
-
userAttributes:
|
|
249
|
-
query:
|
|
250
|
-
model:
|
|
251
|
-
apiKey:
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
includeUnpublished: A
|
|
244
|
+
limit: t = 30,
|
|
245
|
+
userAttributes: n,
|
|
246
|
+
query: r,
|
|
247
|
+
model: o,
|
|
248
|
+
apiKey: s,
|
|
249
|
+
enrich: i,
|
|
250
|
+
locale: d,
|
|
251
|
+
apiVersion: y = ye,
|
|
252
|
+
fields: p,
|
|
253
|
+
omit: k,
|
|
254
|
+
offset: u,
|
|
255
|
+
cacheSeconds: h,
|
|
256
|
+
staleCacheSeconds: g,
|
|
257
|
+
sort: w,
|
|
258
|
+
includeUnpublished: O
|
|
263
259
|
} = e;
|
|
264
|
-
if (!
|
|
260
|
+
if (!s)
|
|
265
261
|
throw new Error("Missing API key");
|
|
266
262
|
if (!["v3"].includes(y))
|
|
267
263
|
throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
sort: x
|
|
264
|
+
const q = t !== 1, a = new URL(`https://cdn.builder.io/api/${y}/content/${o}`);
|
|
265
|
+
if (a.searchParams.set("apiKey", s), a.searchParams.set("limit", String(t)), a.searchParams.set("noTraverse", String(q)), a.searchParams.set("includeRefs", String(!0)), d && a.searchParams.set("locale", d), i && a.searchParams.set("enrich", String(i)), a.searchParams.set("omit", k || "meta.componentsUsed"), p && a.searchParams.set("fields", p), Number.isFinite(u) && u > -1 && a.searchParams.set("offset", String(Math.floor(u))), typeof O == "boolean" && a.searchParams.set("includeUnpublished", String(O)), h && T(h) && a.searchParams.set("cacheSeconds", String(h)), g && T(g) && a.searchParams.set("staleCacheSeconds", String(g)), w) {
|
|
266
|
+
const l = v({
|
|
267
|
+
sort: w
|
|
273
268
|
});
|
|
274
|
-
for (const b in
|
|
275
|
-
|
|
269
|
+
for (const b in l)
|
|
270
|
+
a.searchParams.set(b, JSON.stringify(l[b]));
|
|
276
271
|
}
|
|
277
|
-
const
|
|
278
|
-
...
|
|
279
|
-
...
|
|
280
|
-
}, P =
|
|
281
|
-
for (const
|
|
282
|
-
|
|
283
|
-
if (
|
|
284
|
-
const
|
|
285
|
-
query:
|
|
272
|
+
const z = {
|
|
273
|
+
...Se(),
|
|
274
|
+
..._(e.options || {})
|
|
275
|
+
}, P = v(z);
|
|
276
|
+
for (const l in P)
|
|
277
|
+
a.searchParams.set(l, String(P[l]));
|
|
278
|
+
if (n && a.searchParams.set("userAttributes", JSON.stringify(n)), r) {
|
|
279
|
+
const l = v({
|
|
280
|
+
query: r
|
|
286
281
|
});
|
|
287
|
-
for (const b in
|
|
288
|
-
|
|
282
|
+
for (const b in l)
|
|
283
|
+
a.searchParams.set(b, JSON.stringify(l[b]));
|
|
289
284
|
}
|
|
290
|
-
return
|
|
291
|
-
},
|
|
292
|
-
async function
|
|
293
|
-
const t = await
|
|
285
|
+
return a;
|
|
286
|
+
}, ve = (e) => "results" in e;
|
|
287
|
+
async function Ie(e) {
|
|
288
|
+
const t = await Ce({
|
|
294
289
|
...e,
|
|
295
290
|
limit: 1
|
|
296
291
|
});
|
|
297
292
|
return t && t[0] || null;
|
|
298
293
|
}
|
|
299
|
-
const
|
|
300
|
-
const t =
|
|
301
|
-
return await (await
|
|
302
|
-
},
|
|
303
|
-
const r =
|
|
304
|
-
if (n.search.includes("preview="), !r || !(
|
|
294
|
+
const ke = async (e) => {
|
|
295
|
+
const t = C(e);
|
|
296
|
+
return await (await me(t.href)).json();
|
|
297
|
+
}, Ee = async (e, t, n = C(e)) => {
|
|
298
|
+
const r = de(e.canTrack);
|
|
299
|
+
if (n.search.includes("preview="), !r || !(c() || I === "reactNative"))
|
|
305
300
|
return t.results;
|
|
306
301
|
try {
|
|
307
302
|
const o = [];
|
|
308
303
|
for (const s of t.results)
|
|
309
|
-
o.push(await
|
|
304
|
+
o.push(await ue({
|
|
310
305
|
item: s,
|
|
311
306
|
canTrack: r
|
|
312
307
|
}));
|
|
313
308
|
t.results = o;
|
|
314
309
|
} catch (o) {
|
|
315
|
-
|
|
310
|
+
f.error("Could not process A/B tests. ", o);
|
|
316
311
|
}
|
|
317
312
|
return t.results;
|
|
318
313
|
};
|
|
319
|
-
async function
|
|
314
|
+
async function Ce(e) {
|
|
320
315
|
try {
|
|
321
|
-
const t =
|
|
322
|
-
return
|
|
316
|
+
const t = C(e), n = await ke(e);
|
|
317
|
+
return ve(n) ? Ee(e, n) : (f.error("Error fetching data. ", {
|
|
323
318
|
url: t,
|
|
324
319
|
content: n,
|
|
325
320
|
options: e
|
|
326
321
|
}), null);
|
|
327
322
|
} catch (t) {
|
|
328
|
-
return
|
|
323
|
+
return f.error("Error fetching data. ", t), null;
|
|
329
324
|
}
|
|
330
325
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
return !i() || U() ? !1 : location.search.indexOf("builder.preview=") !== -1;
|
|
326
|
+
function Ge() {
|
|
327
|
+
return !c() || V() ? !1 : location.search.indexOf("builder.preview=") !== -1;
|
|
334
328
|
}
|
|
335
|
-
function
|
|
329
|
+
function Oe() {
|
|
336
330
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(e) {
|
|
337
331
|
const t = Math.random() * 16 | 0;
|
|
338
332
|
return (e == "x" ? t : t & 3 | 8).toString(16);
|
|
339
333
|
});
|
|
340
334
|
}
|
|
341
|
-
function
|
|
342
|
-
return
|
|
335
|
+
function W() {
|
|
336
|
+
return Oe().replace(/-/g, "");
|
|
343
337
|
}
|
|
344
|
-
const
|
|
338
|
+
const $ = "builderSessionId", Pe = async ({
|
|
345
339
|
canTrack: e
|
|
346
340
|
}) => {
|
|
347
341
|
if (!e)
|
|
348
342
|
return;
|
|
349
|
-
const t = await
|
|
350
|
-
name:
|
|
343
|
+
const t = await M({
|
|
344
|
+
name: $,
|
|
351
345
|
canTrack: e
|
|
352
346
|
});
|
|
353
347
|
if (m(t))
|
|
354
348
|
return t;
|
|
355
349
|
{
|
|
356
|
-
const n =
|
|
350
|
+
const n = xe();
|
|
357
351
|
return Te({
|
|
358
352
|
id: n,
|
|
359
353
|
canTrack: e
|
|
360
354
|
}), n;
|
|
361
355
|
}
|
|
362
|
-
},
|
|
356
|
+
}, xe = () => W(), Te = ({
|
|
363
357
|
id: e,
|
|
364
358
|
canTrack: t
|
|
365
|
-
}) =>
|
|
366
|
-
name:
|
|
359
|
+
}) => N({
|
|
360
|
+
name: $,
|
|
367
361
|
value: e,
|
|
368
362
|
canTrack: t
|
|
369
|
-
}),
|
|
363
|
+
}), G = () => c() && typeof localStorage != "undefined" ? localStorage : void 0, Ae = ({
|
|
370
364
|
key: e,
|
|
371
365
|
canTrack: t
|
|
372
366
|
}) => {
|
|
373
367
|
var n;
|
|
374
368
|
try {
|
|
375
|
-
return t ? (n =
|
|
369
|
+
return t ? (n = G()) == null ? void 0 : n.getItem(e) : void 0;
|
|
376
370
|
} catch (r) {
|
|
377
371
|
console.debug("[LocalStorage] GET error: ", r);
|
|
378
372
|
return;
|
|
379
373
|
}
|
|
380
|
-
},
|
|
374
|
+
}, Re = ({
|
|
381
375
|
key: e,
|
|
382
376
|
canTrack: t,
|
|
383
377
|
value: n
|
|
384
378
|
}) => {
|
|
385
379
|
var r;
|
|
386
380
|
try {
|
|
387
|
-
t && ((r =
|
|
381
|
+
t && ((r = G()) == null || r.setItem(e, n));
|
|
388
382
|
} catch (o) {
|
|
389
383
|
console.debug("[LocalStorage] SET error: ", o);
|
|
390
384
|
}
|
|
391
|
-
},
|
|
385
|
+
}, J = "builderVisitorId", Be = ({
|
|
392
386
|
canTrack: e
|
|
393
387
|
}) => {
|
|
394
388
|
if (!e)
|
|
395
389
|
return;
|
|
396
|
-
const t =
|
|
397
|
-
key:
|
|
390
|
+
const t = Ae({
|
|
391
|
+
key: J,
|
|
398
392
|
canTrack: e
|
|
399
393
|
});
|
|
400
394
|
if (m(t))
|
|
401
395
|
return t;
|
|
402
396
|
{
|
|
403
|
-
const n =
|
|
404
|
-
return
|
|
397
|
+
const n = Ve();
|
|
398
|
+
return Le({
|
|
405
399
|
id: n,
|
|
406
400
|
canTrack: e
|
|
407
401
|
}), n;
|
|
408
402
|
}
|
|
409
|
-
},
|
|
403
|
+
}, Ve = () => W(), Le = ({
|
|
410
404
|
id: e,
|
|
411
405
|
canTrack: t
|
|
412
|
-
}) =>
|
|
413
|
-
key:
|
|
406
|
+
}) => Re({
|
|
407
|
+
key: J,
|
|
414
408
|
value: e,
|
|
415
409
|
canTrack: t
|
|
416
|
-
}),
|
|
410
|
+
}), Ue = async ({
|
|
417
411
|
canTrack: e
|
|
418
412
|
}) => {
|
|
419
413
|
if (!e)
|
|
@@ -421,16 +415,16 @@ const H = "builderSessionId", Ae = async ({
|
|
|
421
415
|
visitorId: void 0,
|
|
422
416
|
sessionId: void 0
|
|
423
417
|
};
|
|
424
|
-
const t = await
|
|
418
|
+
const t = await Pe({
|
|
425
419
|
canTrack: e
|
|
426
|
-
}), n =
|
|
420
|
+
}), n = Be({
|
|
427
421
|
canTrack: e
|
|
428
422
|
});
|
|
429
423
|
return {
|
|
430
424
|
sessionId: t,
|
|
431
425
|
visitorId: n
|
|
432
426
|
};
|
|
433
|
-
},
|
|
427
|
+
}, Me = async ({
|
|
434
428
|
type: e,
|
|
435
429
|
canTrack: t,
|
|
436
430
|
apiKey: n,
|
|
@@ -444,23 +438,23 @@ const H = "builderSessionId", Ae = async ({
|
|
|
444
438
|
url: location.href,
|
|
445
439
|
...r
|
|
446
440
|
},
|
|
447
|
-
...await
|
|
441
|
+
...await Ue({
|
|
448
442
|
canTrack: t
|
|
449
443
|
}),
|
|
450
|
-
userAttributes:
|
|
444
|
+
userAttributes: Z(),
|
|
451
445
|
ownerId: n
|
|
452
446
|
}
|
|
453
447
|
});
|
|
454
|
-
async function
|
|
448
|
+
async function Ne(e) {
|
|
455
449
|
if (!e.apiKey) {
|
|
456
|
-
|
|
450
|
+
f.error("Missing API key for track call. Please provide your API key.");
|
|
457
451
|
return;
|
|
458
452
|
}
|
|
459
|
-
if (e.canTrack && !
|
|
453
|
+
if (e.canTrack && !V() && (c() || I === "reactNative"))
|
|
460
454
|
return fetch("https://cdn.builder.io/api/v1/track", {
|
|
461
455
|
method: "POST",
|
|
462
456
|
body: JSON.stringify({
|
|
463
|
-
events: [await
|
|
457
|
+
events: [await Me(e)]
|
|
464
458
|
}),
|
|
465
459
|
headers: {
|
|
466
460
|
"content-type": "application/json"
|
|
@@ -470,18 +464,18 @@ async function Fe(e) {
|
|
|
470
464
|
console.error("Failed to track: ", t);
|
|
471
465
|
});
|
|
472
466
|
}
|
|
473
|
-
const
|
|
467
|
+
const Je = (e) => Ne({
|
|
474
468
|
...e,
|
|
475
469
|
canTrack: !0
|
|
476
|
-
}),
|
|
477
|
-
function
|
|
470
|
+
}), Fe = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
|
|
471
|
+
function H(e, t) {
|
|
478
472
|
const n = new URL(t.origin), r = n.hostname;
|
|
479
|
-
return (e ||
|
|
473
|
+
return (e || Fe).findIndex((o) => o.startsWith("*.") ? r.endsWith(o.slice(1)) : o === r) > -1;
|
|
480
474
|
}
|
|
481
|
-
const je = "0.
|
|
475
|
+
const je = "1.0.2", A = {};
|
|
482
476
|
function De(e, t) {
|
|
483
|
-
let n =
|
|
484
|
-
if (n || (n =
|
|
477
|
+
let n = A[e];
|
|
478
|
+
if (n || (n = A[e] = []), n.push(t), c()) {
|
|
485
479
|
const r = {
|
|
486
480
|
type: "builder.register",
|
|
487
481
|
data: {
|
|
@@ -496,7 +490,7 @@ function De(e, t) {
|
|
|
496
490
|
}
|
|
497
491
|
}
|
|
498
492
|
}
|
|
499
|
-
const
|
|
493
|
+
const He = () => {
|
|
500
494
|
De("insertMenu", {
|
|
501
495
|
name: "_default",
|
|
502
496
|
default: !0,
|
|
@@ -519,13 +513,13 @@ const Ye = () => {
|
|
|
519
513
|
}]
|
|
520
514
|
});
|
|
521
515
|
};
|
|
522
|
-
let
|
|
516
|
+
let R = !1;
|
|
523
517
|
const Ke = (e = {}) => {
|
|
524
518
|
var t, n;
|
|
525
|
-
|
|
519
|
+
R || (R = !0, c() && ((t = window.parent) == null || t.postMessage({
|
|
526
520
|
type: "builder.sdkInfo",
|
|
527
521
|
data: {
|
|
528
|
-
target:
|
|
522
|
+
target: I,
|
|
529
523
|
version: je,
|
|
530
524
|
supportsPatchUpdates: !1,
|
|
531
525
|
// Supports builder-model="..." attribute which is needed to
|
|
@@ -539,8 +533,8 @@ const Ke = (e = {}) => {
|
|
|
539
533
|
options: e
|
|
540
534
|
}
|
|
541
535
|
}, "*"), window.addEventListener("message", (r) => {
|
|
542
|
-
var s,
|
|
543
|
-
if (!
|
|
536
|
+
var s, i;
|
|
537
|
+
if (!H(e.trustedHosts, r))
|
|
544
538
|
return;
|
|
545
539
|
const {
|
|
546
540
|
data: o
|
|
@@ -548,33 +542,33 @@ const Ke = (e = {}) => {
|
|
|
548
542
|
if (o != null && o.type)
|
|
549
543
|
switch (o.type) {
|
|
550
544
|
case "builder.evaluate": {
|
|
551
|
-
const
|
|
552
|
-
let u,
|
|
545
|
+
const d = o.data.text, y = o.data.arguments || [], p = o.data.id, k = new Function(d);
|
|
546
|
+
let u, h = null;
|
|
553
547
|
try {
|
|
554
|
-
u =
|
|
548
|
+
u = k.apply(null, y);
|
|
555
549
|
} catch (g) {
|
|
556
|
-
|
|
550
|
+
h = g;
|
|
557
551
|
}
|
|
558
|
-
|
|
552
|
+
h ? (s = window.parent) == null || s.postMessage({
|
|
559
553
|
type: "builder.evaluateError",
|
|
560
554
|
data: {
|
|
561
|
-
id:
|
|
562
|
-
error:
|
|
555
|
+
id: p,
|
|
556
|
+
error: h.message
|
|
563
557
|
}
|
|
564
558
|
}, "*") : u && typeof u.then == "function" ? u.then((g) => {
|
|
565
|
-
var
|
|
566
|
-
(
|
|
559
|
+
var w;
|
|
560
|
+
(w = window.parent) == null || w.postMessage({
|
|
567
561
|
type: "builder.evaluateResult",
|
|
568
562
|
data: {
|
|
569
|
-
id:
|
|
563
|
+
id: p,
|
|
570
564
|
result: g
|
|
571
565
|
}
|
|
572
566
|
}, "*");
|
|
573
|
-
}).catch(console.error) : (
|
|
567
|
+
}).catch(console.error) : (i = window.parent) == null || i.postMessage({
|
|
574
568
|
type: "builder.evaluateResult",
|
|
575
569
|
data: {
|
|
576
570
|
result: u,
|
|
577
|
-
id:
|
|
571
|
+
id: p
|
|
578
572
|
}
|
|
579
573
|
}, "*");
|
|
580
574
|
break;
|
|
@@ -586,7 +580,7 @@ const Ke = (e = {}) => {
|
|
|
586
580
|
trustedHosts: t,
|
|
587
581
|
callbacks: n
|
|
588
582
|
}) => (r) => {
|
|
589
|
-
if (!
|
|
583
|
+
if (!H(t, r))
|
|
590
584
|
return;
|
|
591
585
|
const {
|
|
592
586
|
data: o
|
|
@@ -602,14 +596,14 @@ const Ke = (e = {}) => {
|
|
|
602
596
|
break;
|
|
603
597
|
}
|
|
604
598
|
case "builder.contentUpdate": {
|
|
605
|
-
const s = o.data,
|
|
606
|
-
|
|
599
|
+
const s = o.data, i = s.key || s.alias || s.entry || s.modelName, d = s.data;
|
|
600
|
+
i === e && n.contentUpdate(d);
|
|
607
601
|
break;
|
|
608
602
|
}
|
|
609
603
|
}
|
|
610
|
-
},
|
|
611
|
-
if (!
|
|
612
|
-
return
|
|
604
|
+
}, qe = (e, t, n) => {
|
|
605
|
+
if (!c)
|
|
606
|
+
return f.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."), () => {
|
|
613
607
|
};
|
|
614
608
|
Ke();
|
|
615
609
|
const r = _e({
|
|
@@ -626,18 +620,18 @@ const Ke = (e = {}) => {
|
|
|
626
620
|
return window.addEventListener("message", r), () => {
|
|
627
621
|
window.removeEventListener("message", r);
|
|
628
622
|
};
|
|
629
|
-
},
|
|
630
|
-
function
|
|
631
|
-
if (
|
|
632
|
-
Object.assign(
|
|
623
|
+
}, B = {};
|
|
624
|
+
function ze(e) {
|
|
625
|
+
if (c()) {
|
|
626
|
+
Object.assign(B, e);
|
|
633
627
|
const t = {
|
|
634
628
|
type: "builder.settingsChange",
|
|
635
|
-
data:
|
|
629
|
+
data: B
|
|
636
630
|
};
|
|
637
631
|
parent.postMessage(t, "*");
|
|
638
632
|
}
|
|
639
633
|
}
|
|
640
|
-
const
|
|
634
|
+
const Xe = async (e) => {
|
|
641
635
|
var r, o, s;
|
|
642
636
|
const t = e.path || ((r = e.url) == null ? void 0 : r.pathname) || ((o = e.userAttributes) == null ? void 0 : o.urlPath), n = {
|
|
643
637
|
...e,
|
|
@@ -649,42 +643,39 @@ const et = async (e) => {
|
|
|
649
643
|
urlPath: t
|
|
650
644
|
} : {}
|
|
651
645
|
},
|
|
652
|
-
options:
|
|
646
|
+
options: K(e.searchParams || ((s = e.url) == null ? void 0 : s.searchParams) || e.options)
|
|
653
647
|
};
|
|
654
648
|
return {
|
|
655
649
|
apiKey: n.apiKey,
|
|
656
650
|
model: n.model,
|
|
657
|
-
content: await
|
|
651
|
+
content: await Ie(n)
|
|
658
652
|
};
|
|
659
653
|
};
|
|
660
654
|
export {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
qe as
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
Fe as q,
|
|
655
|
+
I as T,
|
|
656
|
+
Ee as _,
|
|
657
|
+
Ge as a,
|
|
658
|
+
qe as b,
|
|
659
|
+
$e as c,
|
|
660
|
+
Ce as d,
|
|
661
|
+
Ie as e,
|
|
662
|
+
Xe as f,
|
|
663
|
+
K as g,
|
|
664
|
+
c as h,
|
|
665
|
+
V as i,
|
|
666
|
+
Z as j,
|
|
667
|
+
m as k,
|
|
668
|
+
f as l,
|
|
669
|
+
L as m,
|
|
670
|
+
de as n,
|
|
671
|
+
Ne as o,
|
|
672
|
+
_e as p,
|
|
673
|
+
He as q,
|
|
681
674
|
De as r,
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
Ge as y,
|
|
689
|
-
me as z
|
|
675
|
+
ze as s,
|
|
676
|
+
Je as t,
|
|
677
|
+
Ke as u,
|
|
678
|
+
me as v,
|
|
679
|
+
he as w,
|
|
680
|
+
We as x
|
|
690
681
|
};
|