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