@builder.io/sdk-react 2.0.24 → 2.0.26

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