@builder.io/sdk-react 5.1.0 → 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-7b82deab.cjs → server-entry-85aa99e6.cjs} +2 -2
- package/lib/browser/{server-entry-1df58bc2.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-ac489baa.cjs → accordion-1e467b30.cjs} +1 -1
- package/lib/edge/{accordion-a57423b4.js → accordion-83f68de4.js} +1 -1
- package/lib/edge/{blocks-612edfa7.cjs → blocks-4d57d38f.cjs} +12 -12
- package/lib/edge/{blocks-966052b8.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-da479943.js → button-52af8a54.js} +2 -2
- package/lib/edge/{button-33b8e000.cjs → button-b2eb1d64.cjs} +1 -1
- package/lib/edge/{columns-476f3763.cjs → columns-8eb66fad.cjs} +1 -1
- package/lib/edge/{columns-384a8553.js → columns-e0489b50.js} +3 -3
- package/lib/edge/{content-variants-b281c0c9.js → content-variants-5003144d.js} +12 -12
- package/lib/edge/{content-variants-21daab2e.cjs → content-variants-6c1ee307.cjs} +2 -2
- package/lib/edge/{custom-code-8f1a8bf6.js → custom-code-4e76fc0d.js} +1 -1
- package/lib/edge/{custom-code-d420a6d1.cjs → custom-code-bc787526.cjs} +1 -1
- package/lib/edge/{embed-36d96f7c.cjs → embed-8ef248c5.cjs} +1 -1
- package/lib/edge/{embed-4baabd44.js → embed-fd344d6d.js} +1 -1
- package/lib/edge/{form-597542fa.cjs → form-107c9eae.cjs} +1 -1
- package/lib/edge/{form-7b4ce85e.js → form-4efa40a5.js} +3 -3
- package/lib/edge/{get-class-prop-name-0e04739a.cjs → get-class-prop-name-2c2513e9.cjs} +1 -1
- package/lib/edge/{get-class-prop-name-71cc2ebb.js → get-class-prop-name-e6f7321f.js} +1 -1
- package/lib/edge/{img-f7f612f5.js → img-a32b0723.js} +2 -2
- package/lib/edge/{img-ac7c30e0.cjs → img-ab241f22.cjs} +1 -1
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +1 -1
- package/lib/edge/{input-b6bd8bd9.cjs → input-ada30ffb.cjs} +1 -1
- package/lib/edge/{input-eb1cbd99.js → input-c48fe23a.js} +1 -1
- package/lib/edge/{personalization-container-c5a53dee.cjs → personalization-container-375a1501.cjs} +1 -1
- package/lib/edge/{personalization-container-5fd328ca.js → personalization-container-ad7cf89c.js} +4 -4
- package/lib/edge/{select-e0f16408.cjs → select-879c52dd.cjs} +1 -1
- package/lib/edge/{select-3f4a8f91.js → select-a49d819c.js} +1 -1
- package/lib/edge/{server-entry-00719c56.cjs → server-entry-560732da.cjs} +1 -1
- package/lib/edge/{server-entry-2d0b2a53.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-38a6fa40.js → slot-005d6258.js} +3 -3
- package/lib/edge/{slot-bf1f3ed7.cjs → slot-5da991d1.cjs} +1 -1
- package/lib/edge/{symbol-54dc2d3c.js → symbol-155906ed.js} +2 -2
- package/lib/edge/{symbol-3a09c0c2.cjs → symbol-7e6ac72e.cjs} +1 -1
- package/lib/edge/{tabs-312a6e0a.js → tabs-69a36a5c.js} +3 -3
- package/lib/edge/{tabs-c4a1844c.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-6fc232c7.cjs → server-entry-2529c06e.cjs} +2 -2
- package/lib/node/{server-entry-4228cc2b.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-29867fb3.js → setIvm-41d8b067.js} +60 -44
- 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-eab67c2a.cjs → should-force-browser-runtime-in-node-1d85a066.cjs} +1 -1
- package/lib/node/{should-force-browser-runtime-in-node-7c48ac04.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-5abc9e0c.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: (
|
|
44
|
+
get: (r, s) => {
|
|
29
45
|
if (t && s in t)
|
|
30
46
|
return t[s];
|
|
31
|
-
const
|
|
32
|
-
return typeof
|
|
33
|
-
rootState:
|
|
47
|
+
const o = r[s];
|
|
48
|
+
return typeof o == "object" && o !== null ? flattenState({
|
|
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: (
|
|
56
|
+
set: (r, s, o) => {
|
|
41
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
|
}
|
|
@@ -139,49 +155,49 @@ const setIvm = (e, t) => {
|
|
|
139
155
|
}, runInNode = ({
|
|
140
156
|
code: e,
|
|
141
157
|
builder: t,
|
|
142
|
-
context:
|
|
143
|
-
event:
|
|
158
|
+
context: n,
|
|
159
|
+
event: r,
|
|
144
160
|
localState: s,
|
|
145
|
-
rootSetState:
|
|
161
|
+
rootSetState: o,
|
|
146
162
|
rootState: i
|
|
147
163
|
}) => {
|
|
148
164
|
const y = getIvm();
|
|
149
165
|
let a;
|
|
150
166
|
try {
|
|
151
167
|
a = new y.Isolate(IVM_OPTIONS);
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
console.log(...
|
|
155
|
-
}),
|
|
156
|
-
const
|
|
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({
|
|
157
173
|
...i,
|
|
158
174
|
...s
|
|
159
|
-
}),
|
|
175
|
+
}), I = getFunctionArguments({
|
|
160
176
|
builder: t,
|
|
161
|
-
context:
|
|
162
|
-
event:
|
|
163
|
-
state:
|
|
177
|
+
context: n,
|
|
178
|
+
event: r,
|
|
179
|
+
state: _
|
|
164
180
|
});
|
|
165
|
-
|
|
166
|
-
set(i,
|
|
167
|
-
}),
|
|
181
|
+
c.setSync(BUILDER_SET_STATE_NAME, function(u, l) {
|
|
182
|
+
set(i, u, l), o == null || o(i);
|
|
183
|
+
}), I.forEach(([u, l]) => {
|
|
168
184
|
const N = typeof l == "object" ? new y.Reference(
|
|
169
185
|
// workaround: methods with default values for arguments is not being cloned over
|
|
170
|
-
|
|
186
|
+
u === "builder" ? {
|
|
171
187
|
...l,
|
|
172
188
|
getUserAttributes: () => l.getUserAttributes()
|
|
173
189
|
} : l
|
|
174
190
|
) : null;
|
|
175
|
-
|
|
191
|
+
c.setSync(getSyncValName(u), N);
|
|
176
192
|
});
|
|
177
|
-
const
|
|
193
|
+
const f = processCode({
|
|
178
194
|
code: e,
|
|
179
|
-
args:
|
|
180
|
-
}),
|
|
195
|
+
args: I
|
|
196
|
+
}), E = d.evalClosureSync(f);
|
|
181
197
|
try {
|
|
182
|
-
return JSON.parse(
|
|
198
|
+
return JSON.parse(E);
|
|
183
199
|
} catch {
|
|
184
|
-
return
|
|
200
|
+
return E;
|
|
185
201
|
}
|
|
186
202
|
} finally {
|
|
187
203
|
if (a)
|
|
@@ -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.
|
|
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-6fc232c7.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,o)=>{if(t&&o in t)return t[o];const n=r[o];return typeof n=="object"&&n!==null?flattenState({rootState:n,localState:void 0,rootSetState:s?i=>{r[o]=i,s(r)}:void 0}):n},set:(r,o,n)=>{if(t&&o in t)throw new Error("Writing to local state is not allowed as it is read-only.");return r[o]=n,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((o,n,i)=>Object(o[n])===o[n]?o[n]:o[n]=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_OPTIONS={memoryLimit:128};const setIvm=(e,t)=>{IVM_INSTANCE||(IVM_INSTANCE=e,t&&(IVM_OPTIONS=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)},runInNode=({code:e,builder:t,context:s,event:r,localState:o,rootSetState:n,rootState:i})=>{const y=getIvm();let a;try{a=new y.Isolate(IVM_OPTIONS);const E=a.createContextSync(),c=E.global;c.setSync("global",c.derefInto()),c.setSync("log",function(...u){console.log(...u)}),c.setSync(INJECTED_IVM_GLOBAL,y);const I=fastClone({...i,...o}),d=getFunctionArguments({builder:t,context:s,event:r,state:I});c.setSync(BUILDER_SET_STATE_NAME,function(u,l){set(i,u,l),n==null||n(i)}),d.forEach(([u,l])=>{const N=typeof l=="object"?new y.Reference(u==="builder"?{...l,getUserAttributes:()=>l.getUserAttributes()}:l):null;c.setSync(getSyncValName(u),N)});const _=processCode({code:e,args:d}),f=E.evalClosureSync(_);try{return JSON.parse(f)}catch{return f}}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;
|