@builder.io/sdk-react 0.7.1-0 → 0.7.1

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