@builder.io/sdk-react-nextjs 0.16.4 → 0.16.8

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