@builder.io/sdk-react 5.0.1 → 5.1.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.
- package/lib/browser/blocks-exports.cjs +15 -15
- package/lib/browser/blocks-exports.mjs +400 -368
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +1 -1
- package/lib/browser/{server-entry-54562695.cjs → server-entry-85aa99e6.cjs} +2 -2
- package/lib/browser/{server-entry-48d8b908.js → server-entry-a3b5302c.js} +126 -126
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/{accordion-8b1f60fc.cjs → accordion-1e467b30.cjs} +1 -1
- package/lib/edge/{accordion-66ebf67c.js → accordion-83f68de4.js} +1 -1
- package/lib/edge/{blocks-1dc43011.cjs → blocks-4d57d38f.cjs} +12 -12
- package/lib/edge/{blocks-c00ca88f.js → blocks-6b821501.js} +359 -327
- package/lib/edge/blocks-exports.cjs +1 -1
- package/lib/edge/blocks-exports.mjs +2 -2
- package/lib/edge/{button-041e711c.js → button-52af8a54.js} +2 -2
- package/lib/edge/{button-1984c901.cjs → button-b2eb1d64.cjs} +1 -1
- package/lib/edge/{columns-2b2cf661.cjs → columns-8eb66fad.cjs} +1 -1
- package/lib/edge/{columns-92e5946e.js → columns-e0489b50.js} +3 -3
- package/lib/edge/{content-variants-cce99ed6.js → content-variants-5003144d.js} +12 -12
- package/lib/edge/{content-variants-bc4a2651.cjs → content-variants-6c1ee307.cjs} +2 -2
- package/lib/edge/{custom-code-f7e6cd68.js → custom-code-4e76fc0d.js} +1 -1
- package/lib/edge/{custom-code-1f128470.cjs → custom-code-bc787526.cjs} +1 -1
- package/lib/edge/{embed-bc36f168.cjs → embed-8ef248c5.cjs} +1 -1
- package/lib/edge/{embed-52205349.js → embed-fd344d6d.js} +1 -1
- package/lib/edge/{form-5786e8d3.cjs → form-107c9eae.cjs} +1 -1
- package/lib/edge/{form-3df2f242.js → form-4efa40a5.js} +3 -3
- package/lib/edge/{get-class-prop-name-0276175d.cjs → get-class-prop-name-2c2513e9.cjs} +1 -1
- package/lib/edge/{get-class-prop-name-219095c0.js → get-class-prop-name-e6f7321f.js} +1 -1
- package/lib/edge/{img-b5312e74.js → img-a32b0723.js} +2 -2
- package/lib/edge/{img-e7eefcb8.cjs → img-ab241f22.cjs} +1 -1
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +1 -1
- package/lib/edge/{input-46b7c2f4.cjs → input-ada30ffb.cjs} +1 -1
- package/lib/edge/{input-0ae31d0b.js → input-c48fe23a.js} +1 -1
- package/lib/edge/{personalization-container-8000ecb8.cjs → personalization-container-375a1501.cjs} +1 -1
- package/lib/edge/{personalization-container-31c5a316.js → personalization-container-ad7cf89c.js} +4 -4
- package/lib/edge/{select-c02d2710.cjs → select-879c52dd.cjs} +1 -1
- package/lib/edge/{select-b32b2a7b.js → select-a49d819c.js} +1 -1
- package/lib/edge/{server-entry-5edd9be5.cjs → server-entry-560732da.cjs} +1 -1
- package/lib/edge/{server-entry-406d9576.js → server-entry-68d59577.js} +1 -1
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/edge/{slot-63da11c0.js → slot-005d6258.js} +3 -3
- package/lib/edge/{slot-d9dad534.cjs → slot-5da991d1.cjs} +1 -1
- package/lib/edge/{symbol-a6bc073a.js → symbol-155906ed.js} +2 -2
- package/lib/edge/{symbol-9c9940fb.cjs → symbol-7e6ac72e.cjs} +1 -1
- package/lib/edge/{tabs-bb475169.js → tabs-69a36a5c.js} +3 -3
- package/lib/edge/{tabs-57b3f986.cjs → tabs-96367bf5.cjs} +1 -1
- package/lib/node/blocks-exports.cjs +5 -5
- package/lib/node/blocks-exports.mjs +143 -127
- package/lib/node/index.cjs +1 -1
- package/lib/node/index.mjs +3 -3
- package/lib/node/init.cjs +1 -1
- package/lib/node/init.mjs +3 -3
- package/lib/node/{server-entry-92d43cb8.cjs → server-entry-2529c06e.cjs} +2 -2
- package/lib/node/{server-entry-f9e5ab97.js → server-entry-fc7f08d8.js} +126 -126
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +1 -1
- package/lib/node/{setIvm-fb14c72b.js → setIvm-41d8b067.js} +90 -68
- package/lib/node/setIvm-b97cfb8b.cjs +48 -0
- package/lib/node/setIvm.cjs +1 -1
- package/lib/node/setIvm.mjs +2 -2
- package/lib/node/{should-force-browser-runtime-in-node-e9c386f7.cjs → should-force-browser-runtime-in-node-1d85a066.cjs} +1 -1
- package/lib/node/{should-force-browser-runtime-in-node-7a57d156.js → should-force-browser-runtime-in-node-fc5c3a06.js} +1 -1
- package/package.json +1 -1
- package/types/constants/sdk-version.d.ts +1 -1
- package/types/functions/evaluate/evaluate.d.ts +1 -1
- package/types/functions/evaluate/helpers.d.ts +9 -1
- package/types/functions/get-block-actions-handler.d.ts +2 -0
- package/types/functions/get-block-actions.d.ts +2 -0
- package/lib/node/setIvm-b11f9172.cjs +0 -48
|
@@ -1,46 +1,62 @@
|
|
|
1
|
-
import { isEditing, isBrowser, getUserAttributes, TARGET, logger, MSG_PREFIX } from "./server-entry-
|
|
1
|
+
import { isEditing, isBrowser, getUserAttributes, _track, TARGET, logger, MSG_PREFIX } from "./server-entry-fc7f08d8.js";
|
|
2
2
|
const getFunctionArguments = ({
|
|
3
3
|
builder: e,
|
|
4
4
|
context: t,
|
|
5
|
-
event:
|
|
6
|
-
state:
|
|
5
|
+
event: n,
|
|
6
|
+
state: r
|
|
7
7
|
}) => Object.entries({
|
|
8
|
-
state:
|
|
8
|
+
state: r,
|
|
9
9
|
Builder: e,
|
|
10
10
|
// legacy
|
|
11
11
|
builder: e,
|
|
12
12
|
context: t,
|
|
13
|
-
event:
|
|
14
|
-
}), getBuilderGlobals = () => ({
|
|
13
|
+
event: n
|
|
14
|
+
}), getBuilderGlobals = (e) => ({
|
|
15
15
|
isEditing: isEditing(),
|
|
16
16
|
isBrowser: isBrowser(),
|
|
17
17
|
isServer: !isBrowser(),
|
|
18
|
-
getUserAttributes: () => getUserAttributes()
|
|
18
|
+
getUserAttributes: () => getUserAttributes(),
|
|
19
|
+
trackConversion: (t, n) => {
|
|
20
|
+
var r;
|
|
21
|
+
!(e != null && e.apiKey) || (e == null ? void 0 : e.canTrack) === !1 || _track({
|
|
22
|
+
type: "conversion",
|
|
23
|
+
apiKey: e.apiKey,
|
|
24
|
+
canTrack: (r = e.canTrack) != null ? r : !0,
|
|
25
|
+
contentId: e.contentId,
|
|
26
|
+
variationId: e.variationId !== e.contentId ? e.variationId : void 0,
|
|
27
|
+
metadata: {
|
|
28
|
+
...n || {},
|
|
29
|
+
...t !== void 0 ? {
|
|
30
|
+
amount: t
|
|
31
|
+
} : {}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
19
35
|
}), parseCode = (e, {
|
|
20
36
|
isExpression: t = !0
|
|
21
37
|
}) => /* 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;
|
|
22
38
|
function flattenState({
|
|
23
39
|
rootState: e,
|
|
24
40
|
localState: t,
|
|
25
|
-
rootSetState:
|
|
41
|
+
rootSetState: n
|
|
26
42
|
}) {
|
|
27
43
|
return new Proxy(e, {
|
|
28
|
-
get: (
|
|
29
|
-
if (t &&
|
|
30
|
-
return t[
|
|
31
|
-
const o =
|
|
44
|
+
get: (r, s) => {
|
|
45
|
+
if (t && s in t)
|
|
46
|
+
return t[s];
|
|
47
|
+
const o = r[s];
|
|
32
48
|
return typeof o == "object" && o !== null ? flattenState({
|
|
33
49
|
rootState: o,
|
|
34
50
|
localState: void 0,
|
|
35
|
-
rootSetState:
|
|
36
|
-
|
|
51
|
+
rootSetState: n ? (i) => {
|
|
52
|
+
r[s] = i, n(r);
|
|
37
53
|
} : void 0
|
|
38
54
|
}) : o;
|
|
39
55
|
},
|
|
40
|
-
set: (
|
|
41
|
-
if (t &&
|
|
56
|
+
set: (r, s, o) => {
|
|
57
|
+
if (t && s in t)
|
|
42
58
|
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
43
|
-
return
|
|
59
|
+
return r[s] = o, n == null || n(r), !0;
|
|
44
60
|
}
|
|
45
61
|
});
|
|
46
62
|
}
|
|
@@ -53,11 +69,11 @@ const SDK_NAME_FOR_TARGET = (() => {
|
|
|
53
69
|
default:
|
|
54
70
|
return TARGET;
|
|
55
71
|
}
|
|
56
|
-
})(), SDK_NAME = `@builder.io/sdk-${SDK_NAME_FOR_TARGET}`, fastClone = (e) => JSON.parse(JSON.stringify(e)), set = (e, t,
|
|
72
|
+
})(), SDK_NAME = `@builder.io/sdk-${SDK_NAME_FOR_TARGET}`, fastClone = (e) => JSON.parse(JSON.stringify(e)), set = (e, t, n) => {
|
|
57
73
|
if (Object(e) !== e)
|
|
58
74
|
return e;
|
|
59
|
-
const
|
|
60
|
-
return
|
|
75
|
+
const r = Array.isArray(t) ? t : t.toString().match(/[^.[\]]+/g);
|
|
76
|
+
return r.slice(0, -1).reduce((s, o, i) => Object(s[o]) === s[o] ? s[o] : s[o] = Math.abs(Number(r[i + 1])) >> 0 === +r[i + 1] ? [] : {}, e)[r[r.length - 1]] = n, e;
|
|
61
77
|
}, noop = () => {
|
|
62
78
|
};
|
|
63
79
|
let safeDynamicRequire = noop;
|
|
@@ -95,10 +111,10 @@ var refToProxy = (obj) => {
|
|
|
95
111
|
code: e,
|
|
96
112
|
args: t
|
|
97
113
|
}) => {
|
|
98
|
-
const
|
|
114
|
+
const n = t.map(([r]) => `var ${r} = refToProxy(${getSyncValName(r)}); `).join("");
|
|
99
115
|
return `
|
|
100
116
|
${REF_TO_PROXY_FN}
|
|
101
|
-
${
|
|
117
|
+
${n}
|
|
102
118
|
function theFunction() {
|
|
103
119
|
${e}
|
|
104
120
|
}
|
|
@@ -112,9 +128,11 @@ if (typeof output === 'object' && output !== null) {
|
|
|
112
128
|
}
|
|
113
129
|
`;
|
|
114
130
|
};
|
|
115
|
-
let IVM_INSTANCE = null,
|
|
116
|
-
|
|
117
|
-
|
|
131
|
+
let IVM_INSTANCE = null, IVM_OPTIONS = {
|
|
132
|
+
memoryLimit: 128
|
|
133
|
+
};
|
|
134
|
+
const setIvm = (e, t) => {
|
|
135
|
+
IVM_INSTANCE || (IVM_INSTANCE = e, t && (IVM_OPTIONS = t));
|
|
118
136
|
}, 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 = () => {
|
|
119
137
|
try {
|
|
120
138
|
if (IVM_INSTANCE)
|
|
@@ -134,55 +152,59 @@ const setIvm = (e, t = {}) => {
|
|
|
134
152
|
|
|
135
153
|
For more information, visit https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments`;
|
|
136
154
|
throw new Error(e);
|
|
137
|
-
}
|
|
138
|
-
function setIsolateContext(e = {
|
|
139
|
-
memoryLimit: 128
|
|
140
|
-
}) {
|
|
141
|
-
if (IVM_CONTEXT)
|
|
142
|
-
return IVM_CONTEXT;
|
|
143
|
-
const t = getIvm(), n = new t.Isolate(e).createContextSync(), r = n.global;
|
|
144
|
-
return r.setSync("global", r.derefInto()), r.setSync("log", function(...o) {
|
|
145
|
-
console.log(...o);
|
|
146
|
-
}), r.setSync(INJECTED_IVM_GLOBAL, t), IVM_CONTEXT = n, n;
|
|
147
|
-
}
|
|
148
|
-
const getIsolateContext = () => setIsolateContext(), runInNode = ({
|
|
155
|
+
}, runInNode = ({
|
|
149
156
|
code: e,
|
|
150
157
|
builder: t,
|
|
151
|
-
context:
|
|
152
|
-
event:
|
|
153
|
-
localState:
|
|
158
|
+
context: n,
|
|
159
|
+
event: r,
|
|
160
|
+
localState: s,
|
|
154
161
|
rootSetState: o,
|
|
155
162
|
rootState: i
|
|
156
163
|
}) => {
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
...r
|
|
160
|
-
}), l = getFunctionArguments({
|
|
161
|
-
builder: t,
|
|
162
|
-
context: s,
|
|
163
|
-
event: n,
|
|
164
|
-
state: _
|
|
165
|
-
}), a = getIsolateContext(), E = a.global;
|
|
166
|
-
E.setSync(BUILDER_SET_STATE_NAME, function(c, u) {
|
|
167
|
-
set(i, c, u), o == null || o(i);
|
|
168
|
-
}), l.forEach(([c, u]) => {
|
|
169
|
-
const f = typeof u == "object" ? new I.Reference(
|
|
170
|
-
// workaround: methods with default values for arguments is not being cloned over
|
|
171
|
-
c === "builder" ? {
|
|
172
|
-
...u,
|
|
173
|
-
getUserAttributes: () => u.getUserAttributes()
|
|
174
|
-
} : u
|
|
175
|
-
) : null;
|
|
176
|
-
E.setSync(getSyncValName(c), f);
|
|
177
|
-
});
|
|
178
|
-
const d = processCode({
|
|
179
|
-
code: e,
|
|
180
|
-
args: l
|
|
181
|
-
}), y = a.evalClosureSync(d);
|
|
164
|
+
const y = getIvm();
|
|
165
|
+
let a;
|
|
182
166
|
try {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
167
|
+
a = new y.Isolate(IVM_OPTIONS);
|
|
168
|
+
const d = a.createContextSync(), c = d.global;
|
|
169
|
+
c.setSync("global", c.derefInto()), c.setSync("log", function(...u) {
|
|
170
|
+
console.log(...u);
|
|
171
|
+
}), c.setSync(INJECTED_IVM_GLOBAL, y);
|
|
172
|
+
const _ = fastClone({
|
|
173
|
+
...i,
|
|
174
|
+
...s
|
|
175
|
+
}), I = getFunctionArguments({
|
|
176
|
+
builder: t,
|
|
177
|
+
context: n,
|
|
178
|
+
event: r,
|
|
179
|
+
state: _
|
|
180
|
+
});
|
|
181
|
+
c.setSync(BUILDER_SET_STATE_NAME, function(u, l) {
|
|
182
|
+
set(i, u, l), o == null || o(i);
|
|
183
|
+
}), I.forEach(([u, l]) => {
|
|
184
|
+
const N = typeof l == "object" ? new y.Reference(
|
|
185
|
+
// workaround: methods with default values for arguments is not being cloned over
|
|
186
|
+
u === "builder" ? {
|
|
187
|
+
...l,
|
|
188
|
+
getUserAttributes: () => l.getUserAttributes()
|
|
189
|
+
} : l
|
|
190
|
+
) : null;
|
|
191
|
+
c.setSync(getSyncValName(u), N);
|
|
192
|
+
});
|
|
193
|
+
const f = processCode({
|
|
194
|
+
code: e,
|
|
195
|
+
args: I
|
|
196
|
+
}), E = d.evalClosureSync(f);
|
|
197
|
+
try {
|
|
198
|
+
return JSON.parse(E);
|
|
199
|
+
} catch {
|
|
200
|
+
return E;
|
|
201
|
+
}
|
|
202
|
+
} finally {
|
|
203
|
+
if (a)
|
|
204
|
+
try {
|
|
205
|
+
a.dispose();
|
|
206
|
+
} catch {
|
|
207
|
+
}
|
|
186
208
|
}
|
|
187
209
|
};
|
|
188
210
|
export {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";const serverEntry=require("./server-entry-2529c06e.cjs"),getFunctionArguments=({builder:e,context:r,event:n,state:t})=>Object.entries({state:t,Builder:e,builder:e,context:r,event:n}),getBuilderGlobals=e=>({isEditing:serverEntry.isEditing(),isBrowser:serverEntry.isBrowser(),isServer:!serverEntry.isBrowser(),getUserAttributes:()=>serverEntry.getUserAttributes(),trackConversion:(r,n)=>{var t;!(e!=null&&e.apiKey)||(e==null?void 0:e.canTrack)===!1||serverEntry._track({type:"conversion",apiKey:e.apiKey,canTrack:(t=e.canTrack)!=null?t:!0,contentId:e.contentId,variationId:e.variationId!==e.contentId?e.variationId:void 0,metadata:{...n||{},...r!==void 0?{amount:r}:{}}})}}),parseCode=(e,{isExpression:r=!0})=>r&&!(e.includes(";")||e.includes(" return ")||e.trim().startsWith("return "))?`return (${e});`:e;function flattenState({rootState:e,localState:r,rootSetState:n}){return new Proxy(e,{get:(t,o)=>{if(r&&o in r)return r[o];const s=t[o];return typeof s=="object"&&s!==null?flattenState({rootState:s,localState:void 0,rootSetState:n?i=>{t[o]=i,n(t)}:void 0}):s},set:(t,o,s)=>{if(r&&o in r)throw new Error("Writing to local state is not allowed as it is read-only.");return t[o]=s,n==null||n(t),!0}})}const SDK_NAME_FOR_TARGET=(()=>{switch(serverEntry.TARGET){case"rsc":return"react-nextjs";case"reactNative":return"react-native";default:return serverEntry.TARGET}})(),SDK_NAME=`@builder.io/sdk-${SDK_NAME_FOR_TARGET}`,fastClone=e=>JSON.parse(JSON.stringify(e)),set=(e,r,n)=>{if(Object(e)!==e)return e;const t=Array.isArray(r)?r:r.toString().match(/[^.[\]]+/g);return t.slice(0,-1).reduce((o,s,i)=>Object(o[s])===o[s]?o[s]:o[s]=Math.abs(Number(t[i+1]))>>0===+t[i+1]?[]:{},e)[t[t.length-1]]=n,e},noop=()=>{};let safeDynamicRequire=noop;try{safeDynamicRequire=eval("require")}catch(e){}const getSyncValName=e=>`bldr_${e}_sync`,BUILDER_SET_STATE_NAME="BUILDER_SET_STATE",INJECTED_IVM_GLOBAL="BUILDER_IVM",REF_TO_PROXY_FN=`
|
|
2
|
+
var refToProxy = (obj) => {
|
|
3
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
4
|
+
return obj;
|
|
5
|
+
}
|
|
6
|
+
return new Proxy({}, {
|
|
7
|
+
get(target, key) {
|
|
8
|
+
if (key === 'copySync') {
|
|
9
|
+
return () => obj.copySync();
|
|
10
|
+
}
|
|
11
|
+
const val = obj.getSync(key);
|
|
12
|
+
if (typeof val?.getSync === 'function') {
|
|
13
|
+
return refToProxy(val);
|
|
14
|
+
}
|
|
15
|
+
return val;
|
|
16
|
+
},
|
|
17
|
+
set(target, key, value) {
|
|
18
|
+
const v = typeof value === 'object' ? new ${INJECTED_IVM_GLOBAL}.Reference(value) : value;
|
|
19
|
+
obj.setSync(key, v);
|
|
20
|
+
${BUILDER_SET_STATE_NAME}(key, value)
|
|
21
|
+
},
|
|
22
|
+
deleteProperty(target, key) {
|
|
23
|
+
obj.deleteSync(key);
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
`,processCode=({code:e,args:r})=>{const n=r.map(([t])=>`var ${t} = refToProxy(${getSyncValName(t)}); `).join("");return`
|
|
28
|
+
${REF_TO_PROXY_FN}
|
|
29
|
+
${n}
|
|
30
|
+
function theFunction() {
|
|
31
|
+
${e}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const output = theFunction()
|
|
35
|
+
|
|
36
|
+
if (typeof output === 'object' && output !== null) {
|
|
37
|
+
return JSON.stringify(output.copySync ? output.copySync() : output);
|
|
38
|
+
} else {
|
|
39
|
+
return output;
|
|
40
|
+
}
|
|
41
|
+
`};let IVM_INSTANCE=null,IVM_OPTIONS={memoryLimit:128};const setIvm=(e,r)=>{IVM_INSTANCE||(IVM_INSTANCE=e,r&&(IVM_OPTIONS=r))},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=()=>{try{if(IVM_INSTANCE)return IVM_INSTANCE;const r=safeDynamicRequire("isolated-vm");if(r)return r}catch(r){serverEntry.logger.error("isolated-vm import error.",r)}const e=`${serverEntry.MSG_PREFIX}could not import \`isolated-vm\` module for safe script execution on a Node server.
|
|
42
|
+
|
|
43
|
+
SOLUTION: In a server-only execution path within your application, do one of the following:
|
|
44
|
+
|
|
45
|
+
${SHOULD_MENTION_INITIALIZE_SCRIPT?`- import and call \`initializeNodeRuntime()\` from "${SDK_NAME}/node/init".`:""}
|
|
46
|
+
- add the following import: \`await import('isolated-vm')\`.
|
|
47
|
+
|
|
48
|
+
For more information, visit https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments`;throw new Error(e)},runInNode=({code:e,builder:r,context:n,event:t,localState:o,rootSetState:s,rootState:i})=>{const y=getIvm();let a;try{a=new y.Isolate(IVM_OPTIONS);const d=a.createContextSync(),c=d.global;c.setSync("global",c.derefInto()),c.setSync("log",function(...u){console.log(...u)}),c.setSync(INJECTED_IVM_GLOBAL,y);const f=fastClone({...i,...o}),E=getFunctionArguments({builder:r,context:n,event:t,state:f});c.setSync(BUILDER_SET_STATE_NAME,function(u,l){set(i,u,l),s==null||s(i)}),E.forEach(([u,l])=>{const _=typeof l=="object"?new y.Reference(u==="builder"?{...l,getUserAttributes:()=>l.getUserAttributes()}:l):null;c.setSync(getSyncValName(u),_)});const v=processCode({code:e,args:E}),I=d.evalClosureSync(v);try{return JSON.parse(I)}catch{return I}}finally{if(a)try{a.dispose()}catch{}}};exports.fastClone=fastClone;exports.flattenState=flattenState;exports.getBuilderGlobals=getBuilderGlobals;exports.getFunctionArguments=getFunctionArguments;exports.parseCode=parseCode;exports.runInNode=runInNode;exports.set=set;exports.setIvm=setIvm;
|
package/lib/node/setIvm.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./setIvm-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./setIvm-b97cfb8b.cjs");require("./server-entry-2529c06e.cjs");exports.setIvm=e.setIvm;
|
package/lib/node/setIvm.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const s=require("./server-entry-
|
|
1
|
+
"use strict";const s=require("./server-entry-2529c06e.cjs");function t(){var e;return typeof process!="undefined"&&s.checkIsDefined((e=process==null?void 0:process.versions)==null?void 0:e.node)}const c=({shouldLogWarning:e})=>{var o;if(!t())return!1;const n=process.arch==="arm64",r=process.version.startsWith("v20"),i=(o=process.env.NODE_OPTIONS)==null?void 0:o.includes("--no-node-snapshot");return n&&r&&!i?(e&&s.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};exports.shouldForceBrowserRuntimeInNode=c;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkIsDefined as i, logger as t } from "./server-entry-
|
|
1
|
+
import { checkIsDefined as i, logger as t } from "./server-entry-fc7f08d8.js";
|
|
2
2
|
function a() {
|
|
3
3
|
var o;
|
|
4
4
|
return typeof process != "undefined" && i((o = process == null ? void 0 : process.versions) == null ? void 0 : o.node);
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "5.
|
|
1
|
+
export declare const SDK_VERSION = "5.1.1";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EvaluatorArgs } from './helpers';
|
|
2
2
|
type EvalValue = unknown;
|
|
3
3
|
export declare const getSimpleExpressionGetPath: (code: string) => string;
|
|
4
|
-
export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression }: EvaluatorArgs): EvalValue;
|
|
4
|
+
export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression, trackingContext }: EvaluatorArgs): EvalValue;
|
|
5
5
|
export {};
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import type { BuilderContextInterface, BuilderRenderState } from '../../context/types';
|
|
2
2
|
import { getUserAttributes } from '../track/helpers';
|
|
3
|
+
export type TrackingContext = {
|
|
4
|
+
apiKey: string | null;
|
|
5
|
+
canTrack?: boolean;
|
|
6
|
+
contentId?: string;
|
|
7
|
+
variationId?: string;
|
|
8
|
+
};
|
|
3
9
|
export type EvaluatorArgs = Omit<ExecutorArgs, 'builder' | 'event'> & {
|
|
4
10
|
event?: Event;
|
|
5
11
|
isExpression?: boolean;
|
|
12
|
+
trackingContext?: TrackingContext;
|
|
6
13
|
};
|
|
7
14
|
export type BuilderGlobals = {
|
|
8
15
|
isEditing: boolean | undefined;
|
|
9
16
|
isBrowser: boolean | undefined;
|
|
10
17
|
isServer: boolean | undefined;
|
|
11
18
|
getUserAttributes: typeof getUserAttributes;
|
|
19
|
+
trackConversion: (amount?: number, customProperties?: Record<string, any>) => void;
|
|
12
20
|
};
|
|
13
21
|
export type ExecutorArgs = Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'> & {
|
|
14
22
|
code: string;
|
|
@@ -20,7 +28,7 @@ export type FunctionArguments = ReturnType<typeof getFunctionArguments>;
|
|
|
20
28
|
export declare const getFunctionArguments: ({ builder, context, event, state }: Pick<ExecutorArgs, "context" | "builder" | "event"> & {
|
|
21
29
|
state: BuilderRenderState;
|
|
22
30
|
}) => [string, Event | BuilderRenderState | import("../../context/types").BuilderRenderContext | BuilderGlobals][];
|
|
23
|
-
export declare const getBuilderGlobals: () => BuilderGlobals;
|
|
31
|
+
export declare const getBuilderGlobals: (trackingContext?: TrackingContext) => BuilderGlobals;
|
|
24
32
|
export declare const parseCode: (code: string, { isExpression }: Pick<EvaluatorArgs, 'isExpression'>) => string;
|
|
25
33
|
export declare function flattenState({ rootState, localState, rootSetState }: {
|
|
26
34
|
rootState: Record<string | symbol, any>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { BuilderContextInterface } from '../context/types';
|
|
2
2
|
import type { BuilderBlock } from '../types/builder-block';
|
|
3
|
+
import type { TrackingContext } from './evaluate/helpers';
|
|
3
4
|
type Options = {
|
|
4
5
|
block: BuilderBlock;
|
|
6
|
+
trackingContext?: TrackingContext;
|
|
5
7
|
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>;
|
|
6
8
|
type EventHandler = (event: Event) => any;
|
|
7
9
|
export declare const createEventHandler: (value: string, options: Options) => EventHandler;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { BuilderContextInterface } from '../context/types';
|
|
2
2
|
import type { BuilderBlock } from '../types/builder-block';
|
|
3
|
+
import type { TrackingContext } from './evaluate/helpers';
|
|
3
4
|
type Actions = {
|
|
4
5
|
[index: string]: (event: Event) => any;
|
|
5
6
|
};
|
|
6
7
|
export declare function getBlockActions(options: {
|
|
7
8
|
block: BuilderBlock;
|
|
8
9
|
stripPrefix?: boolean;
|
|
10
|
+
trackingContext?: TrackingContext;
|
|
9
11
|
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): Actions;
|
|
10
12
|
export {};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";const serverEntry=require("./server-entry-92d43cb8.cjs"),getFunctionArguments=({builder:e,context:t,event:s,state:r})=>Object.entries({state:r,Builder:e,builder:e,context:t,event:s}),getBuilderGlobals=()=>({isEditing:serverEntry.isEditing(),isBrowser:serverEntry.isBrowser(),isServer:!serverEntry.isBrowser(),getUserAttributes:()=>serverEntry.getUserAttributes()}),parseCode=(e,{isExpression:t=!0})=>t&&!(e.includes(";")||e.includes(" return ")||e.trim().startsWith("return "))?`return (${e});`:e;function flattenState({rootState:e,localState:t,rootSetState:s}){return new Proxy(e,{get:(r,n)=>{if(t&&n in t)return t[n];const o=r[n];return typeof o=="object"&&o!==null?flattenState({rootState:o,localState:void 0,rootSetState:s?i=>{r[n]=i,s(r)}:void 0}):o},set:(r,n,o)=>{if(t&&n in t)throw new Error("Writing to local state is not allowed as it is read-only.");return r[n]=o,s==null||s(r),!0}})}const SDK_NAME_FOR_TARGET=(()=>{switch(serverEntry.TARGET){case"rsc":return"react-nextjs";case"reactNative":return"react-native";default:return serverEntry.TARGET}})(),SDK_NAME=`@builder.io/sdk-${SDK_NAME_FOR_TARGET}`,fastClone=e=>JSON.parse(JSON.stringify(e)),set=(e,t,s)=>{if(Object(e)!==e)return e;const r=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g);return r.slice(0,-1).reduce((n,o,i)=>Object(n[o])===n[o]?n[o]:n[o]=Math.abs(Number(r[i+1]))>>0===+r[i+1]?[]:{},e)[r[r.length-1]]=s,e},noop=()=>{};let safeDynamicRequire=noop;try{safeDynamicRequire=eval("require")}catch(e){}const getSyncValName=e=>`bldr_${e}_sync`,BUILDER_SET_STATE_NAME="BUILDER_SET_STATE",INJECTED_IVM_GLOBAL="BUILDER_IVM",REF_TO_PROXY_FN=`
|
|
2
|
-
var refToProxy = (obj) => {
|
|
3
|
-
if (typeof obj !== 'object' || obj === null) {
|
|
4
|
-
return obj;
|
|
5
|
-
}
|
|
6
|
-
return new Proxy({}, {
|
|
7
|
-
get(target, key) {
|
|
8
|
-
if (key === 'copySync') {
|
|
9
|
-
return () => obj.copySync();
|
|
10
|
-
}
|
|
11
|
-
const val = obj.getSync(key);
|
|
12
|
-
if (typeof val?.getSync === 'function') {
|
|
13
|
-
return refToProxy(val);
|
|
14
|
-
}
|
|
15
|
-
return val;
|
|
16
|
-
},
|
|
17
|
-
set(target, key, value) {
|
|
18
|
-
const v = typeof value === 'object' ? new ${INJECTED_IVM_GLOBAL}.Reference(value) : value;
|
|
19
|
-
obj.setSync(key, v);
|
|
20
|
-
${BUILDER_SET_STATE_NAME}(key, value)
|
|
21
|
-
},
|
|
22
|
-
deleteProperty(target, key) {
|
|
23
|
-
obj.deleteSync(key);
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
}
|
|
27
|
-
`,processCode=({code:e,args:t})=>{const s=t.map(([r])=>`var ${r} = refToProxy(${getSyncValName(r)}); `).join("");return`
|
|
28
|
-
${REF_TO_PROXY_FN}
|
|
29
|
-
${s}
|
|
30
|
-
function theFunction() {
|
|
31
|
-
${e}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const output = theFunction()
|
|
35
|
-
|
|
36
|
-
if (typeof output === 'object' && output !== null) {
|
|
37
|
-
return JSON.stringify(output.copySync ? output.copySync() : output);
|
|
38
|
-
} else {
|
|
39
|
-
return output;
|
|
40
|
-
}
|
|
41
|
-
`};let IVM_INSTANCE=null,IVM_CONTEXT=null;const setIvm=(e,t={})=>{IVM_INSTANCE||(IVM_INSTANCE=e,setIsolateContext(t))},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=()=>{try{if(IVM_INSTANCE)return IVM_INSTANCE;const t=safeDynamicRequire("isolated-vm");if(t)return t}catch(t){serverEntry.logger.error("isolated-vm import error.",t)}const e=`${serverEntry.MSG_PREFIX}could not import \`isolated-vm\` module for safe script execution on a Node server.
|
|
42
|
-
|
|
43
|
-
SOLUTION: In a server-only execution path within your application, do one of the following:
|
|
44
|
-
|
|
45
|
-
${SHOULD_MENTION_INITIALIZE_SCRIPT?`- import and call \`initializeNodeRuntime()\` from "${SDK_NAME}/node/init".`:""}
|
|
46
|
-
- add the following import: \`await import('isolated-vm')\`.
|
|
47
|
-
|
|
48
|
-
For more information, visit https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments`;throw new Error(e)};function setIsolateContext(e={memoryLimit:128}){if(IVM_CONTEXT)return IVM_CONTEXT;const t=getIvm(),r=new t.Isolate(e).createContextSync(),n=r.global;return n.setSync("global",n.derefInto()),n.setSync("log",function(...o){console.log(...o)}),n.setSync(INJECTED_IVM_GLOBAL,t),IVM_CONTEXT=r,r}const getIsolateContext=()=>setIsolateContext(),runInNode=({code:e,builder:t,context:s,event:r,localState:n,rootSetState:o,rootState:i})=>{const I=getIvm(),d=fastClone({...i,...n}),l=getFunctionArguments({builder:t,context:s,event:r,state:d}),a=getIsolateContext(),E=a.global;E.setSync(BUILDER_SET_STATE_NAME,function(u,c){set(i,u,c),o==null||o(i)}),l.forEach(([u,c])=>{const f=typeof c=="object"?new I.Reference(u==="builder"?{...c,getUserAttributes:()=>c.getUserAttributes()}:c):null;E.setSync(getSyncValName(u),f)});const _=processCode({code:e,args:l}),y=a.evalClosureSync(_);try{return JSON.parse(y)}catch{return y}};exports.fastClone=fastClone;exports.flattenState=flattenState;exports.getBuilderGlobals=getBuilderGlobals;exports.getFunctionArguments=getFunctionArguments;exports.parseCode=parseCode;exports.runInNode=runInNode;exports.set=set;exports.setIvm=setIvm;
|