@builder.io/sdk-react-nextjs 0.14.28 → 0.14.30-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.
- package/lib/browser/blocks-exports.cjs +188 -0
- package/lib/browser/blocks-exports.mjs +2812 -0
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +25 -26
- package/lib/browser/init.cjs +8 -0
- package/lib/browser/init.mjs +60 -0
- package/lib/browser/server-entry-5cac64f5.js +720 -0
- package/lib/browser/server-entry-c9d4cfc0.cjs +2 -0
- package/lib/browser/server-entry.cjs +1 -0
- package/lib/browser/server-entry.mjs +16 -0
- package/lib/edge/blocks-exports.cjs +208 -0
- package/lib/edge/{bundle-c67d25d8.js → blocks-exports.mjs} +2388 -2405
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +25 -26
- package/lib/edge/init.cjs +8 -0
- package/lib/edge/init.mjs +60 -0
- package/lib/edge/server-entry-5cac64f5.js +720 -0
- package/lib/edge/server-entry-c9d4cfc0.cjs +2 -0
- package/lib/edge/server-entry.cjs +1 -0
- package/lib/edge/server-entry.mjs +16 -0
- package/lib/node/blocks-exports.cjs +188 -0
- package/lib/node/blocks-exports.mjs +2788 -0
- package/lib/node/index.cjs +1 -1
- package/lib/node/index.mjs +23 -23
- package/lib/node/init.cjs +1 -0
- package/lib/node/init.mjs +13 -0
- package/lib/node/node-runtime-591c4640.cjs +48 -0
- package/lib/node/node-runtime-8d503570.js +167 -0
- package/lib/node/server-entry-00baa89f.js +720 -0
- package/lib/node/server-entry-1c6e06e6.cjs +2 -0
- package/lib/node/server-entry.cjs +1 -0
- package/lib/node/server-entry.mjs +16 -0
- package/package.json +14 -9
- package/types/cjs/blocks/BaseText.d.ts +6 -0
- package/types/cjs/blocks/form/component-info.d.ts +2 -0
- package/types/cjs/blocks/form/form.d.ts +33 -0
- package/types/cjs/blocks/input/component-info.d.ts +2 -0
- package/types/cjs/blocks/input/input.d.ts +15 -0
- package/types/cjs/blocks/raw-text/component-info.d.ts +2 -0
- package/types/cjs/blocks/raw-text/index.d.ts +1 -0
- package/types/cjs/blocks/raw-text/raw-text.d.ts +7 -0
- package/types/cjs/blocks/submit-button/component-info.d.ts +2 -0
- package/types/cjs/blocks/submit-button/submit-button.d.ts +10 -0
- package/types/cjs/blocks/textarea/component-info.d.ts +2 -0
- package/types/cjs/blocks/textarea/index.d.ts +1 -0
- package/types/cjs/blocks/textarea/textarea.d.ts +13 -0
- package/types/cjs/components/content/index.d.ts +1 -0
- package/types/cjs/components/error-boundary.d.ts +11 -0
- package/types/cjs/constants/sdk-name.d.ts +1 -0
- package/types/cjs/constants/sdk-version.d.ts +1 -1
- package/types/cjs/functions/apply-patch-with-mutation.d.ts +10 -0
- package/types/cjs/functions/evaluate/edge-runtime/acorn-interpreter.d.ts +2 -0
- package/types/cjs/functions/evaluate/edge-runtime/edge-runtime.d.ts +2 -0
- package/types/cjs/functions/evaluate/edge-runtime/index.d.ts +1 -0
- package/types/cjs/functions/evaluate/node-runtime/index.d.ts +1 -0
- package/types/cjs/functions/evaluate/node-runtime/init.d.ts +13 -0
- package/types/cjs/functions/evaluate/node-runtime/node-runtime.d.ts +11 -0
- package/types/cjs/functions/evaluate/node-runtime/safeDynamicRequire.d.ts +8 -0
- package/types/cjs/functions/evaluate/placeholder-runtime.d.ts +2 -0
- package/types/cjs/functions/extract-css-var-default-value.d.ts +1 -0
- package/types/cjs/functions/get-react-native-block-styles.d.ts +15 -0
- package/types/cjs/functions/is-edge-runtime.d.ts +4 -0
- package/types/cjs/functions/on-change.d.ts +7 -0
- package/types/cjs/functions/sanitize-react-native-block-styles.d.ts +3 -0
- package/types/cjs/functions/sanitize-rn-allowed-css.d.ts +8 -0
- package/types/cjs/helpers/omit.d.ts +1 -0
- package/types/cjs/helpers/time.d.ts +1 -0
- package/types/esm/blocks/BaseText.d.ts +6 -0
- package/types/esm/blocks/form/component-info.d.ts +2 -0
- package/types/esm/blocks/form/form.d.ts +33 -0
- package/types/esm/blocks/input/component-info.d.ts +2 -0
- package/types/esm/blocks/input/input.d.ts +15 -0
- package/types/esm/blocks/raw-text/component-info.d.ts +2 -0
- package/types/esm/blocks/raw-text/index.d.ts +1 -0
- package/types/esm/blocks/raw-text/raw-text.d.ts +7 -0
- package/types/esm/blocks/submit-button/component-info.d.ts +2 -0
- package/types/esm/blocks/submit-button/submit-button.d.ts +10 -0
- package/types/esm/blocks/textarea/component-info.d.ts +2 -0
- package/types/esm/blocks/textarea/index.d.ts +1 -0
- package/types/esm/blocks/textarea/textarea.d.ts +13 -0
- package/types/esm/components/content/index.d.ts +1 -0
- package/types/esm/components/error-boundary.d.ts +11 -0
- package/types/esm/constants/sdk-name.d.ts +1 -0
- package/types/esm/constants/sdk-version.d.ts +1 -1
- package/types/esm/functions/apply-patch-with-mutation.d.ts +10 -0
- package/types/esm/functions/evaluate/edge-runtime/acorn-interpreter.d.ts +2 -0
- package/types/esm/functions/evaluate/edge-runtime/edge-runtime.d.ts +2 -0
- package/types/esm/functions/evaluate/edge-runtime/index.d.ts +1 -0
- package/types/esm/functions/evaluate/node-runtime/index.d.ts +1 -0
- package/types/esm/functions/evaluate/node-runtime/init.d.ts +13 -0
- package/types/esm/functions/evaluate/node-runtime/node-runtime.d.ts +11 -0
- package/types/esm/functions/evaluate/node-runtime/safeDynamicRequire.d.ts +8 -0
- package/types/esm/functions/evaluate/placeholder-runtime.d.ts +2 -0
- package/types/esm/functions/extract-css-var-default-value.d.ts +1 -0
- package/types/esm/functions/get-react-native-block-styles.d.ts +15 -0
- package/types/esm/functions/is-edge-runtime.d.ts +4 -0
- package/types/esm/functions/on-change.d.ts +7 -0
- package/types/esm/functions/sanitize-react-native-block-styles.d.ts +3 -0
- package/types/esm/functions/sanitize-rn-allowed-css.d.ts +8 -0
- package/types/esm/helpers/omit.d.ts +1 -0
- package/types/esm/helpers/time.d.ts +1 -0
- package/lib/browser/USE_CLIENT_BUNDLE-1c35fc0a.js +0 -703
- package/lib/browser/USE_CLIENT_BUNDLE-65950ed4.cjs +0 -21
- package/lib/browser/USE_SERVER_BUNDLE-3ea7f606.cjs +0 -1
- package/lib/browser/USE_SERVER_BUNDLE-812dfc95.js +0 -11
- package/lib/browser/bundle-763c7cf6.js +0 -2829
- package/lib/browser/bundle-aff841a2.cjs +0 -169
- package/lib/edge/USE_CLIENT_BUNDLE-cf0350f7.js +0 -703
- package/lib/edge/USE_CLIENT_BUNDLE-fc025b97.cjs +0 -21
- package/lib/edge/USE_SERVER_BUNDLE-8e198f44.cjs +0 -1
- package/lib/edge/USE_SERVER_BUNDLE-ded4dbdc.js +0 -11
- package/lib/edge/bundle-05000fd3.cjs +0 -189
- package/lib/node/USE_CLIENT_BUNDLE-0fda6fd8.js +0 -703
- package/lib/node/USE_CLIENT_BUNDLE-c57c9376.cjs +0 -21
- package/lib/node/USE_SERVER_BUNDLE-15a235fc.js +0 -11
- package/lib/node/USE_SERVER_BUNDLE-5472e997.cjs +0 -1
- package/lib/node/bundle-40b09581.js +0 -2950
- package/lib/node/bundle-acffe20a.cjs +0 -216
package/lib/node/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./blocks-exports.cjs"),e=require("./server-entry-1c6e06e6.cjs");require("react/jsx-runtime");require("./node-runtime-591c4640.cjs");require("react");require("next/navigation");require("lru-cache");exports.Blocks=t.Blocks;exports.BuilderContext=t.BuilderContext;exports.Button=t.Button;exports.Columns=t.Columns;exports.Content=t.Content;exports.Fragment=t.Fragment;exports.Image=t.Image;exports.Section=t.Section;exports.Symbol=t.Symbol;exports.Text=t.Text;exports.Video=t.Video;exports._processContentResult=e._processContentResult;exports.createRegisterComponentMessage=e.createRegisterComponentMessage;exports.fetchBuilderProps=e.fetchBuilderProps;exports.fetchEntries=e.fetchEntries;exports.fetchOneEntry=e.fetchOneEntry;exports.getBuilderSearchParams=e.getBuilderSearchParams;exports.isEditing=e.isEditing;exports.isPreviewing=e.isPreviewing;exports.register=e.register;exports.setEditorSettings=e.setEditorSettings;exports.subscribeToEditor=e.subscribeToEditor;exports.track=e.track;
|
package/lib/node/index.mjs
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Blocks as m, BuilderContext as c, Button as p, Columns as g, Content as a, Fragment as d, Image as l, Section as u, Symbol as f, Text as B, Video as C } from "./blocks-exports.mjs";
|
|
2
|
+
import { _processContentResult as h, createRegisterComponentMessage as x, fetchBuilderProps as S, fetchEntries as b, fetchOneEntry as P, getBuilderSearchParams as k, isEditing as y, isPreviewing as R, register as T, setEditorSettings as v, subscribeToEditor as w, track as F } from "./server-entry-00baa89f.js";
|
|
3
3
|
import "react/jsx-runtime";
|
|
4
|
+
import "./node-runtime-8d503570.js";
|
|
4
5
|
import "react";
|
|
5
|
-
import "./USE_SERVER_BUNDLE-15a235fc.js";
|
|
6
6
|
import "next/navigation";
|
|
7
7
|
import "lru-cache";
|
|
8
8
|
export {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
m as Blocks,
|
|
10
|
+
c as BuilderContext,
|
|
11
|
+
p as Button,
|
|
12
|
+
g as Columns,
|
|
13
|
+
a as Content,
|
|
14
|
+
d as Fragment,
|
|
15
|
+
l as Image,
|
|
16
|
+
u as Section,
|
|
17
|
+
f as Symbol,
|
|
18
|
+
B as Text,
|
|
19
|
+
C as Video,
|
|
20
|
+
h as _processContentResult,
|
|
21
21
|
x as createRegisterComponentMessage,
|
|
22
|
-
|
|
22
|
+
S as fetchBuilderProps,
|
|
23
23
|
b as fetchEntries,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
P as fetchOneEntry,
|
|
25
|
+
k as getBuilderSearchParams,
|
|
26
|
+
y as isEditing,
|
|
27
|
+
R as isPreviewing,
|
|
28
|
+
T as register,
|
|
29
29
|
v as setEditorSettings,
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
w as subscribeToEditor,
|
|
31
|
+
F as track
|
|
32
32
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("isolated-vm"),n=require("./node-runtime-591c4640.cjs");require("./server-entry-1c6e06e6.cjs");require("lru-cache");const o=e=>{const{ivmIsolateOptions:i}=e||{};n.setIvm(t,i)};exports.initializeNodeRuntime=o;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import t from "isolated-vm";
|
|
2
|
+
import { setIvm as m } from "./node-runtime-8d503570.js";
|
|
3
|
+
import "./server-entry-00baa89f.js";
|
|
4
|
+
import "lru-cache";
|
|
5
|
+
const s = (i) => {
|
|
6
|
+
const {
|
|
7
|
+
ivmIsolateOptions: o
|
|
8
|
+
} = i || {};
|
|
9
|
+
m(t, o);
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
s as initializeNodeRuntime
|
|
13
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";const serverEntry=require("./server-entry-1c6e06e6.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,SDK_NAME_FOR_TARGET=(()=>{switch(serverEntry.TARGET){case"rsc":return"nextjs";case"reactNative":return"react-native";default:return serverEntry.TARGET}})(),SDK_NAME=`@builder.io/sdk-${SDK_NAME_FOR_TARGET}`,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,c)=>Object(n[o])===n[o]?n[o]:n[o]=Math.abs(Number(r[c+1]))>>0===+r[c+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=e,setIsolateContext(t)},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
|
+
- 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}){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=()=>IVM_CONTEXT||setIsolateContext(),runInNode=({code:e,builder:t,context:s,event:r,localState:n,rootSetState:o,rootState:c})=>{const v=getIvm(),g=serverEntry.fastClone({...c,...n}),l=getFunctionArguments({builder:t,context:s,event:r,state:g}),a=getIsolateContext(),y=a.global;y.setSync(BUILDER_SET_STATE_NAME,function(i,u){set(c,i,u),o==null||o(c)}),l.forEach(([i,u])=>{const _=typeof u=="object"?new v.Reference(i==="builder"?{...u,getUserAttributes:()=>u.getUserAttributes()}:u):null;y.setSync(getSyncValName(i),_)});const I=processCode({code:e,args:l}),E=a.evalClosureSync(I);try{return JSON.parse(E)}catch{return E}};exports.getBuilderGlobals=getBuilderGlobals;exports.getFunctionArguments=getFunctionArguments;exports.parseCode=parseCode;exports.runInNode=runInNode;exports.set=set;exports.setIvm=setIvm;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { isEditing, isBrowser, getUserAttributes, TARGET, logger, MSG_PREFIX, fastClone } from "./server-entry-00baa89f.js";
|
|
2
|
+
const getFunctionArguments = ({
|
|
3
|
+
builder: e,
|
|
4
|
+
context: t,
|
|
5
|
+
event: s,
|
|
6
|
+
state: n
|
|
7
|
+
}) => Object.entries({
|
|
8
|
+
state: n,
|
|
9
|
+
Builder: e,
|
|
10
|
+
// legacy
|
|
11
|
+
builder: e,
|
|
12
|
+
context: t,
|
|
13
|
+
event: s
|
|
14
|
+
}), getBuilderGlobals = () => ({
|
|
15
|
+
isEditing: isEditing(),
|
|
16
|
+
isBrowser: isBrowser(),
|
|
17
|
+
isServer: !isBrowser(),
|
|
18
|
+
getUserAttributes: () => getUserAttributes()
|
|
19
|
+
}), parseCode = (e, {
|
|
20
|
+
isExpression: t = !0
|
|
21
|
+
}) => /* 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, SDK_NAME_FOR_TARGET = (() => {
|
|
22
|
+
switch (TARGET) {
|
|
23
|
+
case "rsc":
|
|
24
|
+
return "nextjs";
|
|
25
|
+
case "reactNative":
|
|
26
|
+
return "react-native";
|
|
27
|
+
default:
|
|
28
|
+
return TARGET;
|
|
29
|
+
}
|
|
30
|
+
})(), SDK_NAME = `@builder.io/sdk-${SDK_NAME_FOR_TARGET}`, set = (e, t, s) => {
|
|
31
|
+
if (Object(e) !== e)
|
|
32
|
+
return e;
|
|
33
|
+
const n = Array.isArray(t) ? t : t.toString().match(/[^.[\]]+/g);
|
|
34
|
+
return n.slice(0, -1).reduce((r, o, i) => Object(r[o]) === r[o] ? r[o] : r[o] = Math.abs(Number(n[i + 1])) >> 0 === +n[i + 1] ? [] : {}, e)[n[n.length - 1]] = s, e;
|
|
35
|
+
}, noop = () => {
|
|
36
|
+
};
|
|
37
|
+
let safeDynamicRequire = noop;
|
|
38
|
+
try {
|
|
39
|
+
safeDynamicRequire = eval("require");
|
|
40
|
+
} catch (e) {
|
|
41
|
+
}
|
|
42
|
+
const getSyncValName = (e) => `bldr_${e}_sync`, BUILDER_SET_STATE_NAME = "BUILDER_SET_STATE", INJECTED_IVM_GLOBAL = "BUILDER_IVM", REF_TO_PROXY_FN = `
|
|
43
|
+
var refToProxy = (obj) => {
|
|
44
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
45
|
+
return obj;
|
|
46
|
+
}
|
|
47
|
+
return new Proxy({}, {
|
|
48
|
+
get(target, key) {
|
|
49
|
+
if (key === 'copySync') {
|
|
50
|
+
return () => obj.copySync();
|
|
51
|
+
}
|
|
52
|
+
const val = obj.getSync(key);
|
|
53
|
+
if (typeof val?.getSync === 'function') {
|
|
54
|
+
return refToProxy(val);
|
|
55
|
+
}
|
|
56
|
+
return val;
|
|
57
|
+
},
|
|
58
|
+
set(target, key, value) {
|
|
59
|
+
const v = typeof value === 'object' ? new ${INJECTED_IVM_GLOBAL}.Reference(value) : value;
|
|
60
|
+
obj.setSync(key, v);
|
|
61
|
+
${BUILDER_SET_STATE_NAME}(key, value)
|
|
62
|
+
},
|
|
63
|
+
deleteProperty(target, key) {
|
|
64
|
+
obj.deleteSync(key);
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
`, processCode = ({
|
|
69
|
+
code: e,
|
|
70
|
+
args: t
|
|
71
|
+
}) => {
|
|
72
|
+
const s = t.map(([n]) => `var ${n} = refToProxy(${getSyncValName(n)}); `).join("");
|
|
73
|
+
return `
|
|
74
|
+
${REF_TO_PROXY_FN}
|
|
75
|
+
${s}
|
|
76
|
+
function theFunction() {
|
|
77
|
+
${e}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const output = theFunction()
|
|
81
|
+
|
|
82
|
+
if (typeof output === 'object' && output !== null) {
|
|
83
|
+
return JSON.stringify(output.copySync ? output.copySync() : output);
|
|
84
|
+
} else {
|
|
85
|
+
return output;
|
|
86
|
+
}
|
|
87
|
+
`;
|
|
88
|
+
};
|
|
89
|
+
let IVM_INSTANCE = null, IVM_CONTEXT = null;
|
|
90
|
+
const setIvm = (e, t = {}) => {
|
|
91
|
+
IVM_INSTANCE = e, setIsolateContext(t);
|
|
92
|
+
}, getIvm = () => {
|
|
93
|
+
try {
|
|
94
|
+
if (IVM_INSTANCE)
|
|
95
|
+
return IVM_INSTANCE;
|
|
96
|
+
const t = safeDynamicRequire("isolated-vm");
|
|
97
|
+
if (t)
|
|
98
|
+
return t;
|
|
99
|
+
} catch (t) {
|
|
100
|
+
logger.error("isolated-vm import error.", t);
|
|
101
|
+
}
|
|
102
|
+
const e = `${MSG_PREFIX}could not import \`isolated-vm\` module for safe script execution on a Node server.
|
|
103
|
+
|
|
104
|
+
SOLUTION: In a server-only execution path within your application, do one of the following:
|
|
105
|
+
|
|
106
|
+
- import and call \`initializeNodeRuntime()\` from "${SDK_NAME}/node/init".
|
|
107
|
+
- add the following import: \`await import('isolated-vm')\`.
|
|
108
|
+
|
|
109
|
+
For more information, visit https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments`;
|
|
110
|
+
throw new Error(e);
|
|
111
|
+
};
|
|
112
|
+
function setIsolateContext(e = {
|
|
113
|
+
memoryLimit: 128
|
|
114
|
+
}) {
|
|
115
|
+
const t = getIvm(), n = new t.Isolate(e).createContextSync(), r = n.global;
|
|
116
|
+
return r.setSync("global", r.derefInto()), r.setSync("log", function(...o) {
|
|
117
|
+
console.log(...o);
|
|
118
|
+
}), r.setSync(INJECTED_IVM_GLOBAL, t), IVM_CONTEXT = n, n;
|
|
119
|
+
}
|
|
120
|
+
const getIsolateContext = () => IVM_CONTEXT || setIsolateContext(), runInNode = ({
|
|
121
|
+
code: e,
|
|
122
|
+
builder: t,
|
|
123
|
+
context: s,
|
|
124
|
+
event: n,
|
|
125
|
+
localState: r,
|
|
126
|
+
rootSetState: o,
|
|
127
|
+
rootState: i
|
|
128
|
+
}) => {
|
|
129
|
+
const g = getIvm(), _ = fastClone({
|
|
130
|
+
...i,
|
|
131
|
+
...r
|
|
132
|
+
}), l = getFunctionArguments({
|
|
133
|
+
builder: t,
|
|
134
|
+
context: s,
|
|
135
|
+
event: n,
|
|
136
|
+
state: _
|
|
137
|
+
}), a = getIsolateContext(), y = a.global;
|
|
138
|
+
y.setSync(BUILDER_SET_STATE_NAME, function(c, u) {
|
|
139
|
+
set(i, c, u), o == null || o(i);
|
|
140
|
+
}), l.forEach(([c, u]) => {
|
|
141
|
+
const T = typeof u == "object" ? new g.Reference(
|
|
142
|
+
// workaround: methods with default values for arguments is not being cloned over
|
|
143
|
+
c === "builder" ? {
|
|
144
|
+
...u,
|
|
145
|
+
getUserAttributes: () => u.getUserAttributes()
|
|
146
|
+
} : u
|
|
147
|
+
) : null;
|
|
148
|
+
y.setSync(getSyncValName(c), T);
|
|
149
|
+
});
|
|
150
|
+
const I = processCode({
|
|
151
|
+
code: e,
|
|
152
|
+
args: l
|
|
153
|
+
}), E = a.evalClosureSync(I);
|
|
154
|
+
try {
|
|
155
|
+
return JSON.parse(E);
|
|
156
|
+
} catch {
|
|
157
|
+
return E;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
export {
|
|
161
|
+
getBuilderGlobals,
|
|
162
|
+
getFunctionArguments,
|
|
163
|
+
parseCode,
|
|
164
|
+
runInNode,
|
|
165
|
+
set,
|
|
166
|
+
setIvm
|
|
167
|
+
};
|