@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.
Files changed (37) hide show
  1. package/lib/browser/index.cjs +25 -25
  2. package/lib/browser/index.mjs +617 -587
  3. package/lib/{node/server-entry-f7504f89.mjs → browser/server-entry-13b7e1e6.mjs} +208 -190
  4. package/lib/browser/server-entry-c98db16c.js +2 -0
  5. package/lib/browser/server-entry.cjs +1 -1
  6. package/lib/browser/server-entry.mjs +1 -1
  7. package/lib/edge/index.cjs +32 -32
  8. package/lib/edge/index.mjs +1284 -1226
  9. package/lib/{browser/server-entry-f7504f89.mjs → edge/server-entry-13b7e1e6.mjs} +208 -190
  10. package/lib/edge/server-entry-c98db16c.js +2 -0
  11. package/lib/edge/server-entry.cjs +1 -1
  12. package/lib/edge/server-entry.mjs +1 -1
  13. package/lib/index.cjs +14 -0
  14. package/lib/index.mjs +10 -0
  15. package/lib/node/index.cjs +68 -28
  16. package/lib/node/index.mjs +929 -802
  17. package/lib/{edge/server-entry-f7504f89.mjs → node/server-entry-13b7e1e6.mjs} +208 -190
  18. package/lib/node/server-entry-c98db16c.js +2 -0
  19. package/lib/node/server-entry.cjs +1 -1
  20. package/lib/node/server-entry.mjs +1 -1
  21. package/package.json +3 -1
  22. package/types/blocks/image/image.d.ts +1 -1
  23. package/types/constants/sdk-version.d.ts +1 -1
  24. package/types/functions/evaluate/choose-eval.d.ts +6 -0
  25. package/types/functions/evaluate/evaluate.d.ts +1 -5
  26. package/types/functions/evaluate/helpers.d.ts +7 -1
  27. package/types/functions/evaluate/node-runtime/index.d.ts +1 -1
  28. package/types/functions/evaluate/node-runtime/node-runtime.d.ts +2 -0
  29. package/types/functions/evaluate/node-runtime/safeDynamicRequire.d.ts +13 -0
  30. package/types/functions/get-content/types.d.ts +94 -3
  31. package/types/functions/is-node-runtime.d.ts +4 -0
  32. package/types/node-runtime/index.d.ts +1 -0
  33. package/types/node-runtime/node-runtime.d.ts +1 -0
  34. package/types/node-runtime.d.ts +1 -0
  35. package/lib/browser/server-entry-2e639417.js +0 -2
  36. package/lib/edge/server-entry-2e639417.js +0 -2
  37. package/lib/node/server-entry-2e639417.js +0 -2
@@ -1,26 +1,26 @@
1
- const C = (t) => JSON.parse(JSON.stringify(t)), y = "react", f = "[Builder.io]: ", c = {
2
- log: (...t) => console.log(f, ...t),
3
- error: (...t) => console.error(f, ...t),
4
- warn: (...t) => console.warn(f, ...t),
5
- debug: (...t) => console.debug(f, ...t)
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 i() {
7
+ function a() {
8
8
  return typeof window < "u" && typeof document < "u";
9
9
  }
10
- function _() {
11
- return i() && window.self !== window.top;
10
+ function Y() {
11
+ return a() && window.self !== window.top;
12
12
  }
13
- function x() {
14
- return _() && window.location.search.indexOf("builder.frameEditing=") !== -1;
13
+ function L() {
14
+ return Y() && window.location.search.indexOf("builder.frameEditing=") !== -1;
15
15
  }
16
- const G = () => {
17
- if (i()) {
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
- }, W = () => typeof navigator == "object" && navigator.userAgent || "", J = () => {
23
- const t = W(), e = {
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() || y === "reactNative";
40
+ return e.Android() || e.BlackBerry() || e.iOS() || e.Opera() || e.Windows() || b === "reactNative";
41
41
  }
42
- }, n = t.match(/Tablet|iPad/i), r = G();
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
- }, u = (t) => t != null, Pt = [], Tt = (t) => ({
48
+ }, d = (t) => t != null, jt = [], Ft = (t) => ({
49
49
  type: "builder.registerComponent",
50
- data: q(t)
51
- }), z = (t) => {
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
- }, X = (t) => typeof t == "function" ? z(t) : C(t), q = ({
54
+ }, nt = (t) => typeof t == "function" ? et(t) : B(t), rt = ({
55
55
  inputs: t,
56
56
  ...e
57
57
  }) => ({
58
- ...C(e),
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]: X(s)
61
+ [o]: nt(s)
62
62
  }), {}))
63
63
  });
64
- function H() {
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 Y() {
68
- const t = H().fetch;
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 Q = Y(), Z = (t) => {
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
- }, A = ({
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
- c.warn("[COOKIE] GET error: ", (r == null ? void 0 : r.message) || r);
87
+ l.warn("[COOKIE] GET error: ", (r == null ? void 0 : r.message) || r);
88
88
  return;
89
89
  }
90
- }, P = async (t) => A(t), tt = (t) => t.map(([e, n]) => n ? `${e}=${n}` : e).filter(u).join("; "), et = [["secure", ""], ["SameSite", "None"]], nt = ({
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 = (i() ? location.protocol === "https:" : !0) ? et : [[]], s = n ? [["expires", n.toUTCString()]] : [[]], a = [[t, e], ...s, ["path", "/"], ["domain", Z(window.location.hostname)], ...o];
96
- return tt(a);
97
- }, T = async ({
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 = nt({
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
- c.warn("[COOKIE] SET error: ", (o == null ? void 0 : o.message) || o);
113
+ l.warn("[COOKIE] SET error: ", (o == null ? void 0 : o.message) || o);
114
114
  }
115
115
  };
116
- function rt() {
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 R() {
123
- return rt().replace(/-/g, "");
122
+ function F() {
123
+ return dt().replace(/-/g, "");
124
124
  }
125
- const V = "builderSessionId", ot = async ({
125
+ const U = "builderSessionId", ft = async ({
126
126
  canTrack: t
127
127
  }) => {
128
128
  if (!t)
129
129
  return;
130
- const e = await P({
131
- name: V,
130
+ const e = await $({
131
+ name: U,
132
132
  canTrack: t
133
133
  });
134
- if (u(e))
134
+ if (d(e))
135
135
  return e;
136
136
  {
137
- const n = st();
138
- return it({
137
+ const n = ht();
138
+ return gt({
139
139
  id: n,
140
140
  canTrack: t
141
141
  }), n;
142
142
  }
143
- }, st = () => R(), it = ({
143
+ }, ht = () => F(), gt = ({
144
144
  id: t,
145
145
  canTrack: e
146
- }) => T({
147
- name: V,
146
+ }) => j({
147
+ name: U,
148
148
  value: t,
149
149
  canTrack: e
150
- }), B = () => i() && typeof localStorage < "u" ? localStorage : void 0, at = ({
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 = B()) == null ? void 0 : n.getItem(t) : void 0;
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
- }, ct = ({
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 = B()) == null || r.setItem(t, n));
168
+ e && ((r = K()) == null || r.setItem(t, n));
169
169
  } catch (o) {
170
170
  console.debug("[LocalStorage] SET error: ", o);
171
171
  }
172
- }, L = "builderVisitorId", ut = ({
172
+ }, M = "builderVisitorId", mt = ({
173
173
  canTrack: t
174
174
  }) => {
175
175
  if (!t)
176
176
  return;
177
- const e = at({
178
- key: L,
177
+ const e = pt({
178
+ key: M,
179
179
  canTrack: t
180
180
  });
181
- if (u(e))
181
+ if (d(e))
182
182
  return e;
183
183
  {
184
- const n = lt();
185
- return dt({
184
+ const n = St();
185
+ return wt({
186
186
  id: n,
187
187
  canTrack: t
188
188
  }), n;
189
189
  }
190
- }, lt = () => R(), dt = ({
190
+ }, St = () => F(), wt = ({
191
191
  id: t,
192
192
  canTrack: e
193
- }) => ct({
194
- key: L,
193
+ }) => yt({
194
+ key: M,
195
195
  value: t,
196
196
  canTrack: e
197
- }), ft = async ({
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 ot({
205
+ const e = await ft({
206
206
  canTrack: t
207
- }), n = ut({
207
+ }), n = mt({
208
208
  canTrack: t
209
209
  });
210
210
  return {
211
211
  sessionId: e,
212
212
  visitorId: n
213
213
  };
214
- }, ht = async ({
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 ft({
228
+ ...await bt({
229
229
  canTrack: e
230
230
  }),
231
- userAttributes: J(),
231
+ userAttributes: tt(),
232
232
  ownerId: n
233
233
  }
234
234
  });
235
- async function gt(t) {
235
+ async function It(t) {
236
236
  if (!t.apiKey) {
237
- c.error("Missing API key for track call. Please provide your API key.");
237
+ l.error("Missing API key for track call. Please provide your API key.");
238
238
  return;
239
239
  }
240
- if (t.canTrack && !x() && (i() || y === "reactNative"))
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 ht(t)]
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 Rt = (t) => gt({
254
+ const Ut = (t) => It({
255
255
  ...t,
256
256
  canTrack: !0
257
- }), O = {};
258
- function Vt(t, e) {
259
- let n = O[t];
260
- if (n || (n = O[t] = []), n.push(e), i()) {
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 pt = "builder.tests", m = (t) => `${pt}.${t}`, yt = ({
275
+ const Ot = "builder.tests", v = (t) => `${Ot}.${t}`, kt = ({
276
276
  contentId: t
277
- }) => P({
278
- name: m(t),
277
+ }) => $({
278
+ name: v(t),
279
279
  canTrack: !0
280
- }), mt = ({
280
+ }), Ct = ({
281
281
  contentId: t
282
- }) => A({
283
- name: m(t),
282
+ }) => N({
283
+ name: v(t),
284
284
  canTrack: !0
285
- }), wt = ({
285
+ }), Et = ({
286
286
  contentId: t,
287
287
  value: e
288
- }) => T({
289
- name: m(t),
288
+ }) => j({
289
+ name: v(t),
290
290
  value: e,
291
291
  canTrack: !0
292
- }), $ = (t) => u(t.id) && u(t.variations) && Object.keys(t.variations).length > 0, It = ({
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 a = (o = e[s]) == null ? void 0 : o.testRatio;
301
- if (n += a, r < 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
- }, j = (t) => {
306
- const e = It(t);
307
- return wt({
305
+ }, _ = (t) => {
306
+ const e = Pt(t);
307
+ return Et({
308
308
  contentId: t.id,
309
309
  value: e
310
310
  }).catch((n) => {
311
- c.error("could not store A/B test variation: ", n);
311
+ l.error("could not store A/B test variation: ", n);
312
312
  }), e;
313
- }, F = ({
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
- }, Bt = ({
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 (!$(t))
335
+ if (!D(t))
336
336
  return t;
337
- const n = mt({
337
+ const n = Ct({
338
338
  contentId: t.id
339
- }) || j({
339
+ }) || _({
340
340
  variations: t.variations,
341
341
  id: t.id
342
- }), r = F({
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
- }, St = async ({
350
+ }, xt = async ({
351
351
  item: t,
352
352
  canTrack: e
353
353
  }) => {
354
- if (!e || !$(t))
354
+ if (!e || !D(t))
355
355
  return t;
356
- const r = await yt({
356
+ const r = await kt({
357
357
  contentId: t.id
358
- }) || j({
358
+ }) || _({
359
359
  variations: t.variations,
360
360
  id: t.id
361
- }), o = F({
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
- }, vt = (t) => u(t) ? t : !0;
370
- function p(t, e = null, n = ".") {
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], a = [e, o].filter(Boolean).join(n);
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
- ...p(s, a, n)
375
+ ...g(s, c, n)
376
376
  } : {
377
377
  ...r,
378
- [a]: s
378
+ [c]: s
379
379
  };
380
380
  }, {});
381
381
  }
382
- const k = "builder.", bt = "options.", Ot = (t) => {
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
- }, K = (t) => {
387
+ }, W = (t) => {
388
388
  if (!t)
389
389
  return {};
390
- const e = N(t), n = {};
390
+ const e = J(t), n = {};
391
391
  return Object.keys(e).forEach((r) => {
392
- if (r.startsWith(k)) {
393
- const o = r.replace(k, "").replace(bt, "");
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
- }, kt = () => {
398
- if (!i())
397
+ }, Vt = () => {
398
+ if (!a())
399
399
  return {};
400
400
  const t = new URLSearchParams(window.location.search);
401
- return K(t);
402
- }, N = (t) => t instanceof URLSearchParams ? Ot(t) : t, Et = "v3", w = (t) => {
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: e = 30,
405
- userAttributes: n,
406
- query: r,
407
- noTraverse: o = !1,
407
+ limit: n = 30,
408
+ userAttributes: r,
409
+ query: o,
408
410
  model: s,
409
- apiKey: a,
410
- includeRefs: h = !0,
411
- enrich: I,
412
- locale: S,
413
- apiVersion: g = Et
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 (!a)
424
+ if (!c)
416
425
  throw new Error("Missing API key");
417
- if (!["v2", "v3"].includes(g))
418
- throw new Error(`Invalid apiVersion: expected 'v2' or 'v3', received '${g}'`);
419
- const d = new URL(`https://cdn.builder.io/api/${g}/content/${s}?apiKey=${a}&limit=${e}&noTraverse=${o}&includeRefs=${h}${S ? `&locale=${S}` : ""}${I ? `&enrich=${I}` : ""}`), U = {
420
- ...kt(),
421
- ...N(t.options || {})
422
- }, v = p(U);
423
- for (const l in v)
424
- d.searchParams.set(l, String(v[l]));
425
- if (n && d.searchParams.set("userAttributes", JSON.stringify(n)), r) {
426
- const l = p({
427
- query: r
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 b in l)
430
- d.searchParams.set(b, JSON.stringify(l[b]));
447
+ for (const f in u)
448
+ i.searchParams.set(f, JSON.stringify(u[f]));
431
449
  }
432
- return d;
433
- }, Ct = (t) => "results" in t;
434
- async function M(t) {
435
- const e = await D({
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 Lt = M, xt = async (t) => {
442
- const e = w(t);
443
- return await (await Q(e.href)).json();
444
- }, At = async (t, e, n = w(t)) => {
445
- const r = vt(t.canTrack);
446
- if (n.search.includes("preview="), !r || !(i() || y === "reactNative"))
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 St({
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
- c.error("Could not process A/B tests. ", o);
475
+ l.error("Could not process A/B tests. ", o);
458
476
  }
459
477
  return e;
460
478
  };
461
- async function D(t) {
479
+ async function X(t) {
462
480
  try {
463
- const e = w(t), n = await xt(t);
464
- return Ct(n) ? At(t, n) : (c.error("Error fetching data. ", {
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 c.error("Error fetching data. ", e), null;
488
+ return l.error("Error fetching data. ", e), null;
471
489
  }
472
490
  }
473
- const $t = D;
474
- function jt() {
475
- return !i() || x() ? !1 : location.search.indexOf("builder.preview=") !== -1;
491
+ const _t = X;
492
+ function Gt() {
493
+ return !a() || L() ? !1 : location.search.indexOf("builder.preview=") !== -1;
476
494
  }
477
- const E = {};
478
- function Ft(t) {
479
- if (i()) {
480
- Object.assign(E, t);
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: E
501
+ data: V
484
502
  };
485
503
  parent.postMessage(e, "*");
486
504
  }
487
505
  }
488
- const Kt = async (t) => {
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: K(t.searchParams || ((s = t.url) == null ? void 0 : s.searchParams) || t.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 M(n)
523
+ content: await z(n)
506
524
  };
507
525
  };
508
526
  export {
509
- y as T,
510
- At as _,
511
- jt as a,
512
- M as b,
513
- Tt as c,
514
- Lt as d,
515
- K as e,
516
- D as f,
517
- $t as g,
518
- Kt as h,
519
- x as i,
520
- C as j,
521
- i as k,
522
- c as l,
523
- J as m,
524
- u as n,
525
- gt as o,
526
- Q as p,
527
- Pt as q,
528
- Vt as r,
529
- Ft as s,
530
- Rt as t,
531
- q as u,
532
- vt as v,
533
- Bt as w
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
  };