@builder.io/sdk-vue 5.2.15 → 5.3.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 (108) hide show
  1. package/README.md +4 -0
  2. package/lib/browser/{awaiter-2lM_rT3U.cjs → awaiter-2uzflb3S.cjs} +1 -1
  3. package/lib/browser/{awaiter-252HRRNi.js → awaiter-4aFQAEvG.js} +1 -1
  4. package/lib/browser/{block-wrapper-cfaTbC1n.cjs → block-wrapper-1ItsXF0j.cjs} +1 -1
  5. package/lib/browser/{block-wrapper-C1nlMTqm.js → block-wrapper-Uj0c_ct-.js} +3 -3
  6. package/lib/browser/{component-ref-Xhuf1e4j.js → component-ref-826ipClg.js} +4 -4
  7. package/lib/browser/{component-ref-d6ezDlQq.cjs → component-ref-U0GRcehd.cjs} +1 -1
  8. package/lib/browser/components/block/block.helpers.d.ts +1 -1
  9. package/lib/browser/components/block/block.vue.d.ts +6 -11
  10. package/lib/browser/components/content/components/styles.helpers.d.ts +1 -1
  11. package/lib/browser/components/content/content.helpers.d.ts +5 -1
  12. package/lib/browser/components/content/content.vue.d.ts +3 -5
  13. package/lib/browser/constants/builder-registered-components.d.ts +1 -0
  14. package/lib/browser/constants/sdk-version.d.ts +1 -1
  15. package/lib/browser/functions/evaluate/safe-state-expression.d.ts +33 -0
  16. package/lib/browser/functions/extract-localized-values.d.ts +4 -0
  17. package/lib/browser/functions/get-processed-block.d.ts +0 -1
  18. package/lib/browser/functions/is-editing-or-previewing.d.ts +1 -0
  19. package/lib/browser/functions/set.d.ts +29 -1
  20. package/lib/browser/get-block-properties-XhHpZEJX.cjs +1 -0
  21. package/lib/browser/{get-block-properties-ti8MfeDj.js → get-block-properties-u3S8CkNp.js} +21 -18
  22. package/lib/browser/helpers/bounded-cache.d.ts +4 -0
  23. package/lib/browser/helpers/copy-plain-data.d.ts +6 -0
  24. package/lib/browser/{index-Su1HB7sT.js → index-Jf8hjJYZ.js} +1098 -998
  25. package/lib/browser/index-KofqhXXd.cjs +368 -0
  26. package/lib/browser/index.cjs +1 -1
  27. package/lib/browser/index.mjs +1 -1
  28. package/lib/browser/{live-edit-z4s9J22F.cjs → live-edit-BxSoS0rX.cjs} +1 -1
  29. package/lib/browser/{live-edit-CB5gYO0t.js → live-edit-uev5ovOr.js} +1 -1
  30. package/lib/browser/{repeated-block-Y6bY0Wng.cjs → repeated-block-Mj7AAxUa.cjs} +1 -1
  31. package/lib/browser/{repeated-block-xzflsmu_.js → repeated-block-s-uTJJ2l.js} +2 -2
  32. package/lib/browser/{style-wrapper-akXULsFD.cjs → style-wrapper-C17hpa9C.cjs} +1 -1
  33. package/lib/browser/{style-wrapper-0oQEXIZd.js → style-wrapper-WeOZ3wU5.js} +1 -1
  34. package/lib/edge/{awaiter-ILD5v_T5.js → awaiter-3P7HNK2U.js} +1 -1
  35. package/lib/edge/{awaiter-98XudUPT.cjs → awaiter-tL_1GDRg.cjs} +1 -1
  36. package/lib/edge/{block-wrapper-8HiqIpnM.cjs → block-wrapper-AJ9g81fv.cjs} +1 -1
  37. package/lib/{node/block-wrapper-rW0pbE89.js → edge/block-wrapper-W6_AJxdH.js} +3 -3
  38. package/lib/edge/{component-ref-iOnqc5Jy.js → component-ref-2H6t6CVL.js} +4 -4
  39. package/lib/edge/{component-ref-VMmpuF1Z.cjs → component-ref-kOTGaG_S.cjs} +1 -1
  40. package/lib/edge/components/block/block.helpers.d.ts +1 -1
  41. package/lib/edge/components/block/block.vue.d.ts +6 -11
  42. package/lib/edge/components/content/components/styles.helpers.d.ts +1 -1
  43. package/lib/edge/components/content/content.helpers.d.ts +5 -1
  44. package/lib/edge/components/content/content.vue.d.ts +3 -5
  45. package/lib/edge/constants/builder-registered-components.d.ts +1 -0
  46. package/lib/edge/constants/sdk-version.d.ts +1 -1
  47. package/lib/edge/functions/evaluate/safe-state-expression.d.ts +33 -0
  48. package/lib/edge/functions/extract-localized-values.d.ts +4 -0
  49. package/lib/edge/functions/get-processed-block.d.ts +0 -1
  50. package/lib/edge/functions/is-editing-or-previewing.d.ts +1 -0
  51. package/lib/edge/functions/set.d.ts +29 -1
  52. package/lib/edge/get-block-properties-Cf0JYe8s.cjs +1 -0
  53. package/lib/edge/{get-block-properties-uLvX_s0g.js → get-block-properties-yDy5CcoJ.js} +21 -18
  54. package/lib/edge/helpers/bounded-cache.d.ts +4 -0
  55. package/lib/edge/helpers/copy-plain-data.d.ts +6 -0
  56. package/lib/edge/{index-n8ujdiJM.js → index-0OjD7npr.js} +1879 -1779
  57. package/lib/edge/{index-srIF83gr.cjs → index-Vo2N3MOA.cjs} +49 -49
  58. package/lib/edge/index.cjs +1 -1
  59. package/lib/edge/index.mjs +1 -1
  60. package/lib/edge/{live-edit-alyPFECH.js → live-edit-es0ntXpd.js} +1 -1
  61. package/lib/{node/live-edit-S1qfZXZ1.cjs → edge/live-edit-hyHdyjeL.cjs} +1 -1
  62. package/lib/edge/{repeated-block-iLuTUVQ1.js → repeated-block-UG8Sns3u.js} +2 -2
  63. package/lib/edge/{repeated-block-BbhF26Bz.cjs → repeated-block-d6gfiTTu.cjs} +1 -1
  64. package/lib/edge/{style-wrapper-EmhgSKHB.js → style-wrapper-UpCDtTSA.js} +1 -1
  65. package/lib/edge/{style-wrapper-YcHBIann.cjs → style-wrapper-pawaG9qF.cjs} +1 -1
  66. package/lib/node/{awaiter-9J3ijUCH.js → awaiter-AN3_pw27.js} +1 -1
  67. package/lib/node/{awaiter-NWae7gVL.cjs → awaiter-bGTvqMbD.cjs} +1 -1
  68. package/lib/{edge/block-wrapper-RE0mDatJ.js → node/block-wrapper-e5lqTjH4.js} +3 -3
  69. package/lib/node/{block-wrapper-qJrfCMGq.cjs → block-wrapper-uIhnB7Vo.cjs} +1 -1
  70. package/lib/node/{component-ref-DYOularh.cjs → component-ref-hWkVL5In.cjs} +1 -1
  71. package/lib/node/{component-ref-EUVN2TYe.js → component-ref-lBfIlbHs.js} +5 -5
  72. package/lib/node/components/block/block.helpers.d.ts +1 -1
  73. package/lib/node/components/block/block.vue.d.ts +6 -11
  74. package/lib/node/components/content/components/styles.helpers.d.ts +1 -1
  75. package/lib/node/components/content/content.helpers.d.ts +5 -1
  76. package/lib/node/components/content/content.vue.d.ts +3 -5
  77. package/lib/node/constants/builder-registered-components.d.ts +1 -0
  78. package/lib/node/constants/sdk-version.d.ts +1 -1
  79. package/lib/node/functions/evaluate/safe-state-expression.d.ts +33 -0
  80. package/lib/node/functions/extract-localized-values.d.ts +4 -0
  81. package/lib/node/functions/get-processed-block.d.ts +0 -1
  82. package/lib/node/functions/is-editing-or-previewing.d.ts +1 -0
  83. package/lib/node/functions/set.d.ts +29 -1
  84. package/lib/node/get-block-properties-VD2nOy1H.cjs +1 -0
  85. package/lib/node/{get-block-properties-IJF6DYIj.js → get-block-properties-pMlEyIJy.js} +20 -17
  86. package/lib/node/helpers/bounded-cache.d.ts +4 -0
  87. package/lib/node/helpers/copy-plain-data.d.ts +6 -0
  88. package/lib/node/{index-jMlC_wZp.cjs → index-3pN6fdOW.cjs} +42 -42
  89. package/lib/node/{index-Jlkd4q2q.js → index-xfji5jj1.js} +1078 -1005
  90. package/lib/node/index.cjs +1 -1
  91. package/lib/node/index.mjs +8 -8
  92. package/lib/node/init.cjs +1 -1
  93. package/lib/node/init.mjs +1 -1
  94. package/lib/node/{live-edit-xVy-DugY.js → live-edit-GfW2VTki.js} +1 -1
  95. package/lib/{edge/live-edit-eVRi7gn8.cjs → node/live-edit-iCnhUEuS.cjs} +1 -1
  96. package/lib/node/{repeated-block-qrXKn9Na.cjs → repeated-block-RuIC6FQv.cjs} +1 -1
  97. package/lib/node/{repeated-block-N4moJ_ma.js → repeated-block-hte-wY9-.js} +2 -2
  98. package/lib/node/should-force-browser-runtime-in-node-oNYv8BG3.cjs +56 -0
  99. package/lib/node/should-force-browser-runtime-in-node-r2oi-Y6E.js +725 -0
  100. package/lib/node/{style-wrapper-l93hb5Pq.cjs → style-wrapper-c9ma8_oR.cjs} +1 -1
  101. package/lib/node/{style-wrapper-ItVc2ksk.js → style-wrapper-y6_fa2q6.js} +8 -8
  102. package/package.json +1 -1
  103. package/lib/browser/get-block-properties-rnyASgT2.cjs +0 -1
  104. package/lib/browser/index-ut_ryl3Q.cjs +0 -368
  105. package/lib/edge/get-block-properties-enTU2L6v.cjs +0 -1
  106. package/lib/node/get-block-properties-7IX5w2pQ.cjs +0 -1
  107. package/lib/node/should-force-browser-runtime-in-node-EZPrW2gu.js +0 -503
  108. package/lib/node/should-force-browser-runtime-in-node-bKybXtCz.cjs +0 -48
@@ -0,0 +1,725 @@
1
+ import { createRequire } from "node:module";
2
+ const TARGET = "vue", createBoundedCache = (e) => {
3
+ const t = /* @__PURE__ */ new Map();
4
+ return {
5
+ get: (r) => t.get(r),
6
+ set: (r, n) => {
7
+ !t.has(r) && t.size >= e && t.delete(t.keys().next().value), t.set(r, n);
8
+ }
9
+ };
10
+ }, MSG_PREFIX = "[Builder.io]: ", logger = {
11
+ log: (...e) => console.log(MSG_PREFIX, ...e),
12
+ error: (...e) => console.error(MSG_PREFIX, ...e),
13
+ warn: (...e) => console.warn(MSG_PREFIX, ...e),
14
+ debug: (...e) => console.debug(MSG_PREFIX, ...e)
15
+ };
16
+ function isBrowser() {
17
+ return typeof window < "u" && typeof document < "u";
18
+ }
19
+ const convertSearchParamsToQueryObject = (e) => {
20
+ const t = {};
21
+ return e.forEach((r, n) => {
22
+ t[n] = r;
23
+ }), t;
24
+ }, normalizeSearchParams = (e) => e instanceof URLSearchParams ? convertSearchParamsToQueryObject(e) : e, getSearchString = (e) => typeof e == "string" ? e : e instanceof URLSearchParams ? e.toString() : new URLSearchParams(e).toString();
25
+ function isIframe() {
26
+ return isBrowser() && window.self !== window.top;
27
+ }
28
+ function isEditing(e) {
29
+ return isIframe() && // accessing window.location.search is safe here because `isIframe()` is only `true` if we're in a browser.
30
+ getSearchString(e || window.location.search).indexOf("builder.frameEditing=") !== -1;
31
+ }
32
+ const getLocation = () => {
33
+ if (isBrowser()) {
34
+ const e = new URL(location.href);
35
+ return e.pathname === "" && (e.pathname = "/"), e;
36
+ } else
37
+ return console.warn("Cannot get location for tracking in non-browser environment"), null;
38
+ }, getUserAgent = () => typeof navigator == "object" && navigator.userAgent || "", getUserAttributes = () => {
39
+ const e = getUserAgent(), t = {
40
+ Android() {
41
+ return e.match(/Android/i);
42
+ },
43
+ BlackBerry() {
44
+ return e.match(/BlackBerry/i);
45
+ },
46
+ iOS() {
47
+ return e.match(/iPhone|iPod/i);
48
+ },
49
+ Opera() {
50
+ return e.match(/Opera Mini/i);
51
+ },
52
+ Windows() {
53
+ return e.match(/IEMobile/i) || e.match(/WPDesktop/i);
54
+ },
55
+ any() {
56
+ return t.Android() || t.BlackBerry() || t.iOS() || t.Opera() || t.Windows() || TARGET === "reactNative";
57
+ }
58
+ }, r = e.match(/Tablet|iPad/i), n = getLocation();
59
+ return {
60
+ urlPath: n == null ? void 0 : n.pathname,
61
+ host: (n == null ? void 0 : n.host) || (n == null ? void 0 : n.hostname),
62
+ device: r ? "tablet" : t.any() ? "mobile" : "desktop"
63
+ };
64
+ }, SDK_VERSION = "5.3.0", getSdkHeaders = () => ({
65
+ "X-Builder-SDK": TARGET,
66
+ "X-Builder-SDK-GEN": "2",
67
+ "X-Builder-SDK-Version": SDK_VERSION
68
+ }), checkIsDefined = (e) => e != null, getTopLevelDomain = (e) => {
69
+ if (e === "localhost" || e === "127.0.0.1")
70
+ return e;
71
+ const t = e.split(".");
72
+ return t.length > 2 ? t.slice(1).join(".") : e;
73
+ }, getCookieSync = ({
74
+ name: e,
75
+ canTrack: t
76
+ }) => {
77
+ var r;
78
+ try {
79
+ return t ? (r = document.cookie.split("; ").find((n) => n.startsWith(`${e}=`))) == null ? void 0 : r.split("=")[1] : void 0;
80
+ } catch (n) {
81
+ logger.warn("[COOKIE] GET error: ", (n == null ? void 0 : n.message) || n);
82
+ return;
83
+ }
84
+ }, getCookie = async (e) => getCookieSync(e), stringifyCookie = (e) => e.map(([t, r]) => r ? `${t}=${r}` : t).filter(checkIsDefined).join("; "), SECURE_CONFIG = [["secure", ""], ["SameSite", "None"]], createCookieString = ({
85
+ name: e,
86
+ value: t,
87
+ expires: r
88
+ }) => {
89
+ const o = (isBrowser() ? location.protocol === "https:" : !0) ? SECURE_CONFIG : [[]], s = r ? [["expires", r.toUTCString()]] : [[]], a = [[e, t], ...s, ["path", "/"], ["domain", getTopLevelDomain(window.location.hostname)], ...o];
90
+ return stringifyCookie(a);
91
+ }, setCookie = async ({
92
+ name: e,
93
+ value: t,
94
+ expires: r,
95
+ canTrack: n
96
+ }) => {
97
+ try {
98
+ if (!n)
99
+ return;
100
+ const o = createCookieString({
101
+ name: e,
102
+ value: t,
103
+ expires: r
104
+ });
105
+ document.cookie = o;
106
+ } catch (o) {
107
+ logger.warn("[COOKIE] SET error: ", (o == null ? void 0 : o.message) || o);
108
+ }
109
+ };
110
+ function uuidv4() {
111
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(e) {
112
+ const t = Math.random() * 16 | 0;
113
+ return (e == "x" ? t : t & 3 | 8).toString(16);
114
+ });
115
+ }
116
+ function uuid() {
117
+ return uuidv4().replace(/-/g, "");
118
+ }
119
+ const SESSION_LOCAL_STORAGE_KEY = "builderSessionId", getSessionId = async ({
120
+ canTrack: e
121
+ }) => {
122
+ if (!e)
123
+ return;
124
+ const t = await getCookie({
125
+ name: SESSION_LOCAL_STORAGE_KEY,
126
+ canTrack: e
127
+ });
128
+ if (checkIsDefined(t))
129
+ return t;
130
+ {
131
+ const r = createSessionId();
132
+ return setSessionId({
133
+ id: r,
134
+ canTrack: e
135
+ }), r;
136
+ }
137
+ }, createSessionId = () => uuid(), setSessionId = ({
138
+ id: e,
139
+ canTrack: t
140
+ }) => setCookie({
141
+ name: SESSION_LOCAL_STORAGE_KEY,
142
+ value: e,
143
+ canTrack: t
144
+ }), getLocalStorage = () => isBrowser() && typeof localStorage < "u" ? localStorage : void 0, getLocalStorageItem = ({
145
+ key: e,
146
+ canTrack: t
147
+ }) => {
148
+ var r;
149
+ try {
150
+ return t ? (r = getLocalStorage()) == null ? void 0 : r.getItem(e) : void 0;
151
+ } catch (n) {
152
+ console.debug("[LocalStorage] GET error: ", n);
153
+ return;
154
+ }
155
+ }, setLocalStorageItem = ({
156
+ key: e,
157
+ canTrack: t,
158
+ value: r
159
+ }) => {
160
+ var n;
161
+ try {
162
+ t && ((n = getLocalStorage()) == null || n.setItem(e, r));
163
+ } catch (o) {
164
+ console.debug("[LocalStorage] SET error: ", o);
165
+ }
166
+ }, VISITOR_LOCAL_STORAGE_KEY = "builderVisitorId", getVisitorId = ({
167
+ canTrack: e
168
+ }) => {
169
+ if (!e)
170
+ return;
171
+ const t = getLocalStorageItem({
172
+ key: VISITOR_LOCAL_STORAGE_KEY,
173
+ canTrack: e
174
+ });
175
+ if (checkIsDefined(t))
176
+ return t;
177
+ {
178
+ const r = createVisitorId();
179
+ return setVisitorId({
180
+ id: r,
181
+ canTrack: e
182
+ }), r;
183
+ }
184
+ }, createVisitorId = () => uuid(), setVisitorId = ({
185
+ id: e,
186
+ canTrack: t
187
+ }) => setLocalStorageItem({
188
+ key: VISITOR_LOCAL_STORAGE_KEY,
189
+ value: e,
190
+ canTrack: t
191
+ });
192
+ function logFetch(e) {
193
+ var t;
194
+ typeof process < "u" && ((t = process.env) != null && t.DEBUG) && String(process.env.DEBUG) == "true" && logger.log(e);
195
+ }
196
+ const getTrackingEventData = async ({
197
+ canTrack: e
198
+ }) => {
199
+ if (!e)
200
+ return {
201
+ visitorId: void 0,
202
+ sessionId: void 0
203
+ };
204
+ const t = await getSessionId({
205
+ canTrack: e
206
+ }), r = getVisitorId({
207
+ canTrack: e
208
+ });
209
+ return {
210
+ sessionId: t,
211
+ visitorId: r
212
+ };
213
+ }, createEvent = async ({
214
+ type: e,
215
+ canTrack: t,
216
+ apiKey: r,
217
+ metadata: n,
218
+ ...o
219
+ }) => ({
220
+ type: e,
221
+ data: {
222
+ ...o,
223
+ metadata: {
224
+ url: location.href,
225
+ ...n
226
+ },
227
+ ...await getTrackingEventData({
228
+ canTrack: t
229
+ }),
230
+ userAttributes: getUserAttributes(),
231
+ ownerId: r
232
+ }
233
+ });
234
+ async function _track({
235
+ apiHost: e,
236
+ ...t
237
+ }) {
238
+ if (!t.apiKey) {
239
+ logger.error("Missing API key for track call. Please provide your API key.");
240
+ return;
241
+ }
242
+ if (!t.canTrack || isEditing() || !(isBrowser() || TARGET === "reactNative"))
243
+ return;
244
+ const n = `${e || "https://cdn.builder.io"}/api/v1/track`;
245
+ return logFetch(n), fetch(n, {
246
+ method: "POST",
247
+ body: JSON.stringify({
248
+ events: [await createEvent(t)]
249
+ }),
250
+ headers: {
251
+ "content-type": "application/json",
252
+ ...getSdkHeaders()
253
+ },
254
+ mode: "cors"
255
+ }).catch((o) => {
256
+ console.error("Failed to track: ", o);
257
+ });
258
+ }
259
+ const track = (e) => _track({
260
+ ...e,
261
+ canTrack: !0
262
+ }), getFunctionArguments = ({
263
+ builder: e,
264
+ context: t,
265
+ event: r,
266
+ state: n
267
+ }) => Object.entries({
268
+ state: n,
269
+ Builder: e,
270
+ // legacy
271
+ builder: e,
272
+ context: t,
273
+ event: r
274
+ }), getBuilderGlobals = (e) => ({
275
+ isEditing: isEditing(),
276
+ isBrowser: isBrowser(),
277
+ isServer: !isBrowser(),
278
+ getUserAttributes: () => getUserAttributes(),
279
+ trackConversion: (t, r) => {
280
+ !(e != null && e.apiKey) || (e == null ? void 0 : e.canTrack) === !1 || _track({
281
+ type: "conversion",
282
+ apiKey: e.apiKey,
283
+ canTrack: e.canTrack ?? !0,
284
+ contentId: e.contentId,
285
+ variationId: e.variationId !== e.contentId ? e.variationId : void 0,
286
+ metadata: {
287
+ ...r || {},
288
+ ...t !== void 0 ? {
289
+ amount: t
290
+ } : {}
291
+ }
292
+ });
293
+ }
294
+ }), parseCode = (e, {
295
+ isExpression: t = !0
296
+ }) => /* we disable this for cases where we definitely don't want a return */ t && !(e.includes(";") || e.includes(" return ") || e.trim().startsWith("return ")) ? `return (${e});` : e;
297
+ function flattenState({
298
+ rootState: e,
299
+ localState: t,
300
+ rootSetState: r
301
+ }) {
302
+ return new Proxy(e, {
303
+ get: (n, o) => {
304
+ if (t && o in t)
305
+ return t[o];
306
+ const s = n[o];
307
+ return typeof s == "object" && s !== null ? flattenState({
308
+ rootState: s,
309
+ localState: void 0,
310
+ rootSetState: r ? (a) => {
311
+ n[o] = a, r(n);
312
+ } : void 0
313
+ }) : s;
314
+ },
315
+ set: (n, o, s) => {
316
+ if (t && o in t)
317
+ throw new Error("Writing to local state is not allowed as it is read-only.");
318
+ return n[o] = s, r == null || r(n), !0;
319
+ }
320
+ });
321
+ }
322
+ const SDK_NAME_FOR_TARGET = (() => {
323
+ switch (TARGET) {
324
+ case "rsc":
325
+ return "react-nextjs";
326
+ case "reactNative":
327
+ return "react-native";
328
+ default:
329
+ return TARGET;
330
+ }
331
+ })(), SDK_NAME = `@builder.io/sdk-${SDK_NAME_FOR_TARGET}`, fastClone = (e) => JSON.parse(JSON.stringify(e)), parsePath = (e) => e.toString().match(/[^.[\]]+/g), isArrayIndex = (e) => Math.abs(Number(e)) >> 0 === +e, hasUnsafeSegment = (e) => e.some((t, r) => t === "__proto__" || r < e.length - 1 && (t === "constructor" || t === "prototype")), getOwn = (e, t) => Object.prototype.hasOwnProperty.call(e, t) ? e[t] : void 0, set = (e, t, r) => {
332
+ if (Object(e) !== e)
333
+ return e;
334
+ const n = Array.isArray(t) ? t : parsePath(t);
335
+ return !n || hasUnsafeSegment(n) || (n.slice(0, -1).reduce((o, s, a) => {
336
+ const c = getOwn(o, s);
337
+ return Object(c) === c ? c : o[s] = isArrayIndex(n[a + 1]) ? [] : {};
338
+ }, e)[n[n.length - 1]] = r), e;
339
+ }, setCopyOnWrite = (e, t, r, n) => {
340
+ if (Object(e) !== e)
341
+ return e;
342
+ const o = parsePath(t);
343
+ if (!o || hasUnsafeSegment(o))
344
+ return e;
345
+ n.add(e);
346
+ let s = e;
347
+ for (let a = 0; a < o.length - 1; a++) {
348
+ const c = o[a];
349
+ let i = getOwn(s, c);
350
+ Object(i) !== i ? (i = isArrayIndex(o[a + 1]) ? [] : {}, n.add(i), s[c] = i) : typeof i == "object" && !n.has(i) && (i = Array.isArray(i) ? i.slice() : {
351
+ ...i
352
+ }, n.add(i), s[c] = i), s = i;
353
+ }
354
+ return s[o[o.length - 1]] = r, e;
355
+ }, unset = (e, t) => {
356
+ if (Object(e) !== e || !t.length || hasUnsafeSegment(t))
357
+ return e;
358
+ const r = t.slice(0, -1).reduce((n, o) => Object(n) === n ? getOwn(n, o) : void 0, e);
359
+ return Object(r) === r && delete r[t[t.length - 1]], e;
360
+ }, IDENTIFIER = /^[A-Za-z_$][\w$]*/, NUMBER = /^(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/, getStringLiteralLength = (e) => {
361
+ const t = e[0];
362
+ if (t !== '"' && t !== "'")
363
+ return 0;
364
+ for (let r = 1; r < e.length; r++) {
365
+ const n = e[r];
366
+ if (n === t)
367
+ return r + 1;
368
+ if (n === "\\" || n === `
369
+ ` || n === "\r")
370
+ return 0;
371
+ }
372
+ return 0;
373
+ }, OPERATORS = ["===", "!==", "==", "!=", "<=", ">=", "&&", "||", "??", "<", ">", "!", "+", "-", "*", "/", "%", "?", ":"], LITERAL_KEYWORDS = /* @__PURE__ */ new Set(["true", "false", "null", "undefined"]), BLOCKED_PROPERTIES = /* @__PURE__ */ new Set(["constructor", "__proto__", "prototype", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__"]), MAX_EXPRESSION_LENGTH = 500, getSafeStateExpression = (e) => {
374
+ var s;
375
+ if (e.length > MAX_EXPRESSION_LENGTH)
376
+ return null;
377
+ let t = e.trim();
378
+ if (!t)
379
+ return null;
380
+ let r = 0, n = !1, o = !1;
381
+ for (; t; ) {
382
+ const a = /^\s+/.exec(t);
383
+ if (a) {
384
+ t = t.slice(a[0].length);
385
+ continue;
386
+ }
387
+ const c = IDENTIFIER.exec(t);
388
+ if (c) {
389
+ if (n)
390
+ return null;
391
+ const E = c[0];
392
+ if (t = t.slice(E.length), LITERAL_KEYWORDS.has(E)) {
393
+ n = !0;
394
+ continue;
395
+ }
396
+ if (E !== "state")
397
+ return null;
398
+ let S = !1, l = /^\s*\.\s*([A-Za-z_$][\w$]*)/.exec(t);
399
+ for (; l; ) {
400
+ if (BLOCKED_PROPERTIES.has(l[1]))
401
+ return null;
402
+ S = !0, t = t.slice(l[0].length), l = /^\s*\.\s*([A-Za-z_$][\w$]*)/.exec(t);
403
+ }
404
+ if (!S)
405
+ return null;
406
+ o = !0, n = !0;
407
+ continue;
408
+ }
409
+ const i = ((s = NUMBER.exec(t)) == null ? void 0 : s[0].length) || getStringLiteralLength(t);
410
+ if (i) {
411
+ if (n)
412
+ return null;
413
+ t = t.slice(i), n = !0;
414
+ continue;
415
+ }
416
+ if (t[0] === "(") {
417
+ if (n)
418
+ return null;
419
+ r++, t = t.slice(1);
420
+ continue;
421
+ }
422
+ if (t[0] === ")") {
423
+ if (r === 0)
424
+ return null;
425
+ r--, t = t.slice(1), n = !0;
426
+ continue;
427
+ }
428
+ const u = OPERATORS.find((E) => t.startsWith(E));
429
+ if (!u || u === "?" && t[1] === "." || (u === "+" || u === "-") && t[1] === u)
430
+ return null;
431
+ t = t.slice(u.length), n = !1;
432
+ }
433
+ return r !== 0 || !o || !n ? null : e.trim();
434
+ }, RETURN_EXPRESSION = /^\s*return\s*\(([\s\S]*)\);\s*$/, VIRTUAL_INDEX_EXPRESSION = /^\s*var\s+_virtual_index\s*=\s*([\s\S]*?);?\s*return\s+_virtual_index\s*;?\s*$/, getSafeStateExpressionFromCode = (e) => {
435
+ const t = RETURN_EXPRESSION.exec(e) || VIRTUAL_INDEX_EXPRESSION.exec(e);
436
+ return t ? getSafeStateExpression(t[1]) : null;
437
+ }, isPrimitiveValue = (e) => e === null || typeof e != "object" && typeof e != "function", MAX_CACHED_EXPRESSIONS = 5e3, COMPILED_EXPRESSIONS = createBoundedCache(MAX_CACHED_EXPRESSIONS), getSafeStateExpressionFn = (e) => {
438
+ let t = COMPILED_EXPRESSIONS.get(e);
439
+ if (t === void 0) {
440
+ const r = getSafeStateExpressionFromCode(e);
441
+ if (t = null, r)
442
+ try {
443
+ t = new Function("state", `return (${r});`);
444
+ } catch {
445
+ t = null;
446
+ }
447
+ COMPILED_EXPRESSIONS.set(e, t);
448
+ }
449
+ return t;
450
+ }, UNSAFE_STATE_READ = Symbol("unsafe state read"), isPlainContainer = (e) => {
451
+ const t = Object.getPrototypeOf(e);
452
+ return t === Object.prototype || t === Array.prototype || t === null;
453
+ }, READ_ONLY_TRAPS = {
454
+ set: () => !1,
455
+ deleteProperty: () => !1
456
+ }, findDescriptor = (e, t) => {
457
+ for (let r = e; r; r = Object.getPrototypeOf(r)) {
458
+ const n = Object.getOwnPropertyDescriptor(r, t);
459
+ if (n)
460
+ return n;
461
+ }
462
+ }, getReadOnlyStateView = (e, t, r) => {
463
+ const n = (c) => !r(c) && isPlainContainer(c);
464
+ if (!n(e) || t && r(t))
465
+ throw UNSAFE_STATE_READ;
466
+ const o = /* @__PURE__ */ new WeakMap(), s = (c) => {
467
+ if (c === null || typeof c != "object") {
468
+ if (typeof c == "function")
469
+ throw UNSAFE_STATE_READ;
470
+ return c;
471
+ }
472
+ if (!n(c))
473
+ throw UNSAFE_STATE_READ;
474
+ let i = o.get(c);
475
+ return i || (i = new Proxy(Array.isArray(c) ? [] : {}, {
476
+ get: (u, E) => a(c, E),
477
+ ...READ_ONLY_TRAPS
478
+ }), o.set(c, i)), i;
479
+ }, a = (c, i) => {
480
+ const u = findDescriptor(c, i);
481
+ if (u && (u.get || u.set))
482
+ throw UNSAFE_STATE_READ;
483
+ return s(u == null ? void 0 : u.value);
484
+ };
485
+ return new Proxy({}, {
486
+ get: (c, i) => t && Object.prototype.hasOwnProperty.call(t, i) ? a(t, i) : a(e, i),
487
+ ...READ_ONLY_TRAPS
488
+ });
489
+ }, NOT_EVALUATED = Symbol("not evaluated"), evaluateSafeStateExpression = (e, t, r, n) => {
490
+ const o = getSafeStateExpressionFn(e);
491
+ if (!o)
492
+ return NOT_EVALUATED;
493
+ let s;
494
+ try {
495
+ s = o(getReadOnlyStateView(t, r, n));
496
+ } catch {
497
+ return NOT_EVALUATED;
498
+ }
499
+ return isPrimitiveValue(s) ? s : NOT_EVALUATED;
500
+ }, noop = () => {
501
+ };
502
+ let safeDynamicRequire = noop;
503
+ try {
504
+ safeDynamicRequire = createRequire(import.meta.url);
505
+ } catch (error) {
506
+ try {
507
+ safeDynamicRequire = eval("require");
508
+ } catch (e) {
509
+ }
510
+ }
511
+ const getSyncValName = (e) => `bldr_${e}_sync`, BUILDER_SET_STATE_NAME = "BUILDER_SET_STATE", BUILDER_DELETE_STATE_NAME = "BUILDER_DELETE_STATE", INJECTED_IVM_GLOBAL = "BUILDER_IVM", REF_TO_PROXY_FN = `
512
+ var refToProxy = (obj, path) => {
513
+ if (typeof obj !== 'object' || obj === null) {
514
+ return obj;
515
+ }
516
+ return new Proxy({}, {
517
+ get(target, key) {
518
+ if (key === 'copySync') {
519
+ return () => obj.copySync();
520
+ }
521
+ const val = obj.getSync(key);
522
+ if (typeof val?.getSync === 'function') {
523
+ return refToProxy(val, path && path.concat(key));
524
+ }
525
+ return val;
526
+ },
527
+ set(target, key, value) {
528
+ // Functions cannot cross the isolate boundary, and server renders never call them.
529
+ if (typeof value === 'function') {
530
+ return true;
531
+ }
532
+ const v = typeof value === 'object' ? new ${INJECTED_IVM_GLOBAL}.Reference(value) : value;
533
+ obj.setSync(key, v);
534
+ if (path) ${BUILDER_SET_STATE_NAME}(path.concat(key), value);
535
+ return true;
536
+ },
537
+ deleteProperty(target, key) {
538
+ obj.deleteSync(key);
539
+ if (path) ${BUILDER_DELETE_STATE_NAME}(path.concat(key));
540
+ return true;
541
+ }
542
+ })
543
+ }
544
+ `, processCode = ({
545
+ code: e,
546
+ args: t
547
+ }) => {
548
+ const r = t.map(([n]) => `var ${n} = refToProxy(${getSyncValName(n)}${n === "state" ? ", []" : ""}); `).join("");
549
+ return `(function () {
550
+ ${REF_TO_PROXY_FN}
551
+ ${r}
552
+ function theFunction() {
553
+ ${e}
554
+ }
555
+
556
+ const output = theFunction()
557
+
558
+ if (typeof output === 'object' && output !== null) {
559
+ return JSON.stringify(output.copySync ? output.copySync() : output);
560
+ } else {
561
+ return output;
562
+ }
563
+ })()`;
564
+ };
565
+ let IVM_INSTANCE = null, IVM_OPTIONS = {
566
+ memoryLimit: 128
567
+ };
568
+ const MAX_EVALUATIONS_PER_ISOLATE = 1e3;
569
+ let POOLED = null, DISPOSE_TIMER = null, IS_EXIT_HANDLER_REGISTERED = !1;
570
+ const disposePooledIsolate = () => {
571
+ if (DISPOSE_TIMER && (clearTimeout(DISPOSE_TIMER), DISPOSE_TIMER = null), POOLED && !POOLED.isolate.isDisposed)
572
+ try {
573
+ POOLED.isolate.dispose();
574
+ } catch {
575
+ }
576
+ POOLED = null;
577
+ }, getPooledIsolate = (e) => {
578
+ var t;
579
+ return (!POOLED || POOLED.isolate.isDisposed || POOLED.evaluations >= MAX_EVALUATIONS_PER_ISOLATE) && (disposePooledIsolate(), POOLED = {
580
+ isolate: new e.Isolate(IVM_OPTIONS),
581
+ evaluations: 0,
582
+ scripts: /* @__PURE__ */ new Map()
583
+ }), DISPOSE_TIMER || (DISPOSE_TIMER = setTimeout(disposePooledIsolate, 0), (t = DISPOSE_TIMER.unref) == null || t.call(DISPOSE_TIMER)), !IS_EXIT_HANDLER_REGISTERED && typeof process < "u" && typeof process.once == "function" && (IS_EXIT_HANDLER_REGISTERED = !0, process.once("exit", disposePooledIsolate)), POOLED.evaluations++, POOLED;
584
+ }, setIvm = (e, t) => {
585
+ IVM_INSTANCE || (IVM_INSTANCE = e, t && (IVM_OPTIONS = t));
586
+ }, SHOULD_MENTION_INITIALIZE_SCRIPT = SDK_NAME === "@builder.io/sdk-react-nextjs" || SDK_NAME === "@builder.io/sdk-react" || SDK_NAME === "@builder.io/sdk-qwik" || SDK_NAME === "@builder.io/sdk-vue", getIvm = () => {
587
+ try {
588
+ if (IVM_INSTANCE)
589
+ return IVM_INSTANCE;
590
+ const t = safeDynamicRequire("isolated-vm");
591
+ if (t)
592
+ return t;
593
+ } catch (t) {
594
+ logger.error("isolated-vm import error.", t);
595
+ }
596
+ const e = `${MSG_PREFIX}could not import \`isolated-vm\` module for safe script execution on a Node server.
597
+
598
+ SOLUTION: In a server-only execution path within your application, do one of the following:
599
+
600
+ ${SHOULD_MENTION_INITIALIZE_SCRIPT ? `- import and call \`initializeNodeRuntime()\` from "${SDK_NAME}/node/init".` : ""}
601
+ - add the following import: \`await import('isolated-vm')\`.
602
+
603
+ For more information, visit https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments`;
604
+ throw new Error(e);
605
+ };
606
+ let IS_PROXY;
607
+ const getIsProxy = () => {
608
+ var e, t;
609
+ if (IS_PROXY === void 0)
610
+ try {
611
+ IS_PROXY = ((t = (e = safeDynamicRequire("node:util")) == null ? void 0 : e.types) == null ? void 0 : t.isProxy) ?? null;
612
+ } catch {
613
+ IS_PROXY = null;
614
+ }
615
+ return IS_PROXY;
616
+ }, runInNode = ({
617
+ code: e,
618
+ builder: t,
619
+ context: r,
620
+ event: n,
621
+ localState: o,
622
+ rootSetState: s,
623
+ rootState: a
624
+ }) => {
625
+ const c = getIsProxy();
626
+ if (c) {
627
+ const l = evaluateSafeStateExpression(e, a, o, c);
628
+ if (l !== NOT_EVALUATED)
629
+ return l;
630
+ }
631
+ const i = getIvm(), u = getPooledIsolate(i), E = u.isolate.createContextSync(), S = [];
632
+ try {
633
+ const l = E.global;
634
+ l.setSync("global", l.derefInto()), l.setSync("log", function(...d) {
635
+ console.log(...d);
636
+ }), l.setSync(INJECTED_IVM_GLOBAL, i);
637
+ const g = fastClone({
638
+ ...a,
639
+ ...o
640
+ }), p = getFunctionArguments({
641
+ builder: t,
642
+ context: r,
643
+ event: n,
644
+ state: g
645
+ });
646
+ l.setSync(BUILDER_SET_STATE_NAME, function(d, f) {
647
+ set(a, d, f), s == null || s(a);
648
+ }), l.setSync(BUILDER_DELETE_STATE_NAME, function(d) {
649
+ unset(a, d), s == null || s(a);
650
+ }), p.forEach(([d, f]) => {
651
+ const _ = typeof f == "object" ? new i.Reference(
652
+ // workaround: methods with default values for arguments is not being cloned over
653
+ d === "builder" ? {
654
+ ...f,
655
+ getUserAttributes: () => f.getUserAttributes()
656
+ } : f
657
+ ) : null;
658
+ _ && S.push(_), l.setSync(getSyncValName(d), _);
659
+ });
660
+ let I = u.scripts.get(e);
661
+ I || (I = u.isolate.compileScriptSync(processCode({
662
+ code: e,
663
+ args: p
664
+ })), u.scripts.set(e, I));
665
+ const O = I.runSync(E);
666
+ try {
667
+ return JSON.parse(O);
668
+ } catch {
669
+ return O;
670
+ }
671
+ } finally {
672
+ S.forEach((l) => {
673
+ try {
674
+ l.release();
675
+ } catch {
676
+ }
677
+ });
678
+ try {
679
+ E.release();
680
+ } catch {
681
+ }
682
+ }
683
+ };
684
+ function isNodeRuntime() {
685
+ var e;
686
+ return typeof process < "u" && checkIsDefined((e = process == null ? void 0 : process.versions) == null ? void 0 : e.node);
687
+ }
688
+ let hasLoggedWarning = !1;
689
+ const shouldForceBrowserRuntimeInNode = ({
690
+ shouldLogWarning: e
691
+ }) => {
692
+ var o;
693
+ if (!isNodeRuntime())
694
+ return !1;
695
+ const t = process.arch === "arm64", r = process.version.startsWith("v20"), n = (o = process.env.NODE_OPTIONS) == null ? void 0 : o.includes("--no-node-snapshot");
696
+ return t && r && !n ? (e && !hasLoggedWarning && (hasLoggedWarning = !0, logger.log("Skipping usage of `isolated-vm` to avoid crashes in Node v20 on an arm64 machine.\n If you would like to use the `isolated-vm` package on this machine, please provide the `NODE_OPTIONS=--no-node-snapshot` config to your Node process.\n See https://github.com/BuilderIO/builder/blob/main/packages/sdks/README.md#node-v20--m1-macs-apple-silicon-support for more information.\n ")), !0) : !1;
697
+ };
698
+ export {
699
+ SDK_VERSION as S,
700
+ TARGET as T,
701
+ _track as _,
702
+ getBuilderGlobals as a,
703
+ getSearchString as b,
704
+ createBoundedCache as c,
705
+ isEditing as d,
706
+ setCopyOnWrite as e,
707
+ flattenState as f,
708
+ getFunctionArguments as g,
709
+ getCookieSync as h,
710
+ isBrowser as i,
711
+ checkIsDefined as j,
712
+ getCookie as k,
713
+ logger as l,
714
+ setCookie as m,
715
+ normalizeSearchParams as n,
716
+ getSdkHeaders as o,
717
+ parseCode as p,
718
+ set as q,
719
+ runInNode as r,
720
+ shouldForceBrowserRuntimeInNode as s,
721
+ logFetch as t,
722
+ fastClone as u,
723
+ track as v,
724
+ setIvm as w
725
+ };