@builder.io/sdk-svelte 1.0.24 → 1.0.26
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/components/block/block.helpers.d.ts +4 -4
- package/lib/browser/components/block/block.helpers.js +4 -4
- package/lib/browser/components/block/block.svelte +2 -2
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/browser/functions/evaluate/node-runtime/init.d.ts +4 -1
- package/lib/browser/functions/evaluate/node-runtime/init.js +3 -2
- package/lib/browser/functions/evaluate/node-runtime/node-runtime.d.ts +4 -1
- package/lib/browser/functions/evaluate/node-runtime/node-runtime.js +29 -18
- package/lib/edge/components/block/block.helpers.d.ts +4 -4
- package/lib/edge/components/block/block.helpers.js +4 -4
- package/lib/edge/components/block/block.svelte +2 -2
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/edge/functions/evaluate/node-runtime/init.d.ts +4 -1
- package/lib/edge/functions/evaluate/node-runtime/init.js +3 -2
- package/lib/edge/functions/evaluate/node-runtime/node-runtime.d.ts +4 -1
- package/lib/edge/functions/evaluate/node-runtime/node-runtime.js +29 -18
- package/lib/node/components/block/block.helpers.d.ts +4 -4
- package/lib/node/components/block/block.helpers.js +4 -4
- package/lib/node/components/block/block.svelte +2 -2
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/lib/node/functions/evaluate/node-runtime/init.d.ts +4 -1
- package/lib/node/functions/evaluate/node-runtime/init.js +3 -2
- package/lib/node/functions/evaluate/node-runtime/node-runtime.d.ts +4 -1
- package/lib/node/functions/evaluate/node-runtime/node-runtime.js +29 -18
- package/package.json +1 -1
- package/src/components/block/block.helpers.ts +5 -5
- package/src/components/block/block.svelte +2 -2
- package/src/constants/sdk-version.ts +1 -1
- package/src/functions/evaluate/node-runtime/init.ts +8 -2
- package/src/functions/evaluate/node-runtime/node-runtime.ts +34 -21
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { BuilderContextInterface, RegisteredComponents } from '../../context/types';
|
|
1
|
+
import type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from '../../context/types';
|
|
2
2
|
import type { BuilderBlock } from '../../types/builder-block';
|
|
3
3
|
import type { RepeatData } from './types';
|
|
4
4
|
export declare const getComponent: ({ block, context, registeredComponents }: {
|
|
5
5
|
block: BuilderBlock;
|
|
6
6
|
context: BuilderContextInterface;
|
|
7
7
|
registeredComponents: RegisteredComponents;
|
|
8
|
-
}) =>
|
|
8
|
+
}) => RegisteredComponent | null | undefined;
|
|
9
9
|
export declare const getRepeatItemData: ({ block, context }: {
|
|
10
10
|
block: BuilderBlock;
|
|
11
11
|
context: BuilderContextInterface;
|
|
@@ -14,5 +14,5 @@ export declare const getInheritedStyles: ({ block, context }: {
|
|
|
14
14
|
block: BuilderBlock;
|
|
15
15
|
context: BuilderContextInterface;
|
|
16
16
|
}) => Partial<CSSStyleDeclaration>;
|
|
17
|
-
export declare const shouldPassLinkComponent: (
|
|
18
|
-
export declare const shouldPassRegisteredComponents: (
|
|
17
|
+
export declare const shouldPassLinkComponent: (block: RegisteredComponent | null | undefined) => boolean | null | undefined;
|
|
18
|
+
export declare const shouldPassRegisteredComponents: (block: RegisteredComponent | null | undefined) => boolean | null | undefined;
|
|
@@ -73,9 +73,9 @@ export const getInheritedStyles = ({ block, context }) => {
|
|
|
73
73
|
}
|
|
74
74
|
return extractTextStyles(style);
|
|
75
75
|
};
|
|
76
|
-
export const shouldPassLinkComponent = (
|
|
77
|
-
return
|
|
76
|
+
export const shouldPassLinkComponent = (block) => {
|
|
77
|
+
return block && (block.isRSC || ['Core:Button', 'Symbol', 'Columns', 'Form:Form', 'Builder: Tabs'].includes(block.name));
|
|
78
78
|
};
|
|
79
|
-
export const shouldPassRegisteredComponents = (
|
|
80
|
-
return
|
|
79
|
+
export const shouldPassRegisteredComponents = (block) => {
|
|
80
|
+
return block && (block.isRSC || ['Symbol', 'Columns', 'Form:Form', 'Builder: Tabs'].includes(block.name));
|
|
81
81
|
};
|
|
@@ -77,12 +77,12 @@ $: componentRefProps = () => {
|
|
|
77
77
|
componentOptions: {
|
|
78
78
|
...getBlockComponentOptions(processedBlock()),
|
|
79
79
|
builderContext: context,
|
|
80
|
-
...(shouldPassLinkComponent(blockComponent
|
|
80
|
+
...(shouldPassLinkComponent(blockComponent())
|
|
81
81
|
? {
|
|
82
82
|
builderLinkComponent: linkComponent,
|
|
83
83
|
}
|
|
84
84
|
: {}),
|
|
85
|
-
...(shouldPassRegisteredComponents(blockComponent
|
|
85
|
+
...(shouldPassRegisteredComponents(blockComponent())
|
|
86
86
|
? {
|
|
87
87
|
builderComponents: registeredComponents,
|
|
88
88
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.26";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.26";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IsolateOptions } from 'isolated-vm';
|
|
1
2
|
/**
|
|
2
3
|
* This function initializes the SDK on a Node server. It handles importing the
|
|
3
4
|
* `isolated-vm` package which is needed for dynamic bindings.
|
|
@@ -7,4 +8,6 @@
|
|
|
7
8
|
* - The NextJS Pages router's `_document.tsx`
|
|
8
9
|
* - Your Remix route's `loader`
|
|
9
10
|
*/
|
|
10
|
-
export declare const initializeNodeRuntime: (
|
|
11
|
+
export declare const initializeNodeRuntime: (args?: {
|
|
12
|
+
ivmIsolateOptions?: IsolateOptions;
|
|
13
|
+
}) => void;
|
|
@@ -21,6 +21,7 @@ import { setIvm } from './node-runtime';
|
|
|
21
21
|
* - The NextJS Pages router's `_document.tsx`
|
|
22
22
|
* - Your Remix route's `loader`
|
|
23
23
|
*/
|
|
24
|
-
export const initializeNodeRuntime = () => {
|
|
25
|
-
|
|
24
|
+
export const initializeNodeRuntime = (args) => {
|
|
25
|
+
const { ivmIsolateOptions } = args || {};
|
|
26
|
+
setIvm(ivm, ivmIsolateOptions);
|
|
26
27
|
};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import type { IsolateOptions } from 'isolated-vm';
|
|
1
2
|
import type { ExecutorArgs } from '../helpers';
|
|
3
|
+
type IsolatedVMImport = typeof import('isolated-vm');
|
|
2
4
|
/**
|
|
3
5
|
* Set the `isolated-vm` instance to be used by the node runtime.
|
|
4
6
|
* This is useful for environments that are not able to rely on our
|
|
5
7
|
* `safeDynamicRequire` trick to import the `isolated-vm` package.
|
|
6
8
|
*/
|
|
7
|
-
export declare const setIvm: (ivm:
|
|
9
|
+
export declare const setIvm: (ivm: IsolatedVMImport, options?: IsolateOptions) => void;
|
|
8
10
|
export declare const runInNode: ({ code, builder, context, event, localState, rootSetState, rootState }: ExecutorArgs) => any;
|
|
11
|
+
export {};
|
|
@@ -45,23 +45,25 @@ function theFunction() {
|
|
|
45
45
|
${code}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
const output = theFunction()
|
|
49
49
|
|
|
50
50
|
if (typeof output === 'object' && output !== null) {
|
|
51
|
-
|
|
51
|
+
return JSON.stringify(output.copySync ? output.copySync() : output);
|
|
52
|
+
} else {
|
|
53
|
+
return output;
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
output;
|
|
55
55
|
`;
|
|
56
56
|
};
|
|
57
57
|
let IVM_INSTANCE = null;
|
|
58
|
+
let IVM_CONTEXT = null;
|
|
58
59
|
/**
|
|
59
60
|
* Set the `isolated-vm` instance to be used by the node runtime.
|
|
60
61
|
* This is useful for environments that are not able to rely on our
|
|
61
62
|
* `safeDynamicRequire` trick to import the `isolated-vm` package.
|
|
62
63
|
*/
|
|
63
|
-
export const setIvm = (ivm) => {
|
|
64
|
+
export const setIvm = (ivm, options = {}) => {
|
|
64
65
|
IVM_INSTANCE = ivm;
|
|
66
|
+
setIsolateContext(options);
|
|
65
67
|
};
|
|
66
68
|
const getIvm = () => {
|
|
67
69
|
try {
|
|
@@ -83,12 +85,29 @@ const getIvm = () => {
|
|
|
83
85
|
Please see the documentation for more information: https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments
|
|
84
86
|
`);
|
|
85
87
|
};
|
|
86
|
-
|
|
88
|
+
function setIsolateContext(options = {
|
|
89
|
+
memoryLimit: 128
|
|
90
|
+
}) {
|
|
87
91
|
const ivm = getIvm();
|
|
88
|
-
const isolate = new ivm.Isolate(
|
|
89
|
-
|
|
92
|
+
const isolate = new ivm.Isolate(options);
|
|
93
|
+
const context = isolate.createContextSync();
|
|
94
|
+
const jail = context.global;
|
|
95
|
+
// This makes the global object available in the context as `global`. We use `derefInto()` here
|
|
96
|
+
// because otherwise `global` would actually be a Reference{} object in the new isolate.
|
|
97
|
+
jail.setSync('global', jail.derefInto());
|
|
98
|
+
// We will create a basic `log` function for the new isolate to use.
|
|
99
|
+
jail.setSync('log', function (...logArgs) {
|
|
100
|
+
console.log(...logArgs);
|
|
90
101
|
});
|
|
91
|
-
|
|
102
|
+
jail.setSync(INJECTED_IVM_GLOBAL, ivm);
|
|
103
|
+
IVM_CONTEXT = context;
|
|
104
|
+
return context;
|
|
105
|
+
}
|
|
106
|
+
const getIsolateContext = () => {
|
|
107
|
+
if (IVM_CONTEXT)
|
|
108
|
+
return IVM_CONTEXT;
|
|
109
|
+
const context = setIsolateContext();
|
|
110
|
+
return context;
|
|
92
111
|
};
|
|
93
112
|
export const runInNode = ({ code, builder, context, event, localState, rootSetState, rootState }) => {
|
|
94
113
|
const ivm = getIvm();
|
|
@@ -104,13 +123,6 @@ export const runInNode = ({ code, builder, context, event, localState, rootSetSt
|
|
|
104
123
|
});
|
|
105
124
|
const isolateContext = getIsolateContext();
|
|
106
125
|
const jail = isolateContext.global;
|
|
107
|
-
// This makes the global object available in the context as `global`. We use `derefInto()` here
|
|
108
|
-
// because otherwise `global` would actually be a Reference{} object in the new isolate.
|
|
109
|
-
jail.setSync('global', jail.derefInto());
|
|
110
|
-
// We will create a basic `log` function for the new isolate to use.
|
|
111
|
-
jail.setSync('log', function (...logArgs) {
|
|
112
|
-
console.log(...logArgs);
|
|
113
|
-
});
|
|
114
126
|
/**
|
|
115
127
|
* Propagate state changes back to the reactive root state.
|
|
116
128
|
*/
|
|
@@ -130,12 +142,11 @@ export const runInNode = ({ code, builder, context, event, localState, rootSetSt
|
|
|
130
142
|
} : arg) : null;
|
|
131
143
|
jail.setSync(getSyncValName(key), val);
|
|
132
144
|
});
|
|
133
|
-
jail.setSync(INJECTED_IVM_GLOBAL, ivm);
|
|
134
145
|
const evalStr = processCode({
|
|
135
146
|
code,
|
|
136
147
|
args
|
|
137
148
|
});
|
|
138
|
-
const resultStr = isolateContext.
|
|
149
|
+
const resultStr = isolateContext.evalClosureSync(evalStr);
|
|
139
150
|
try {
|
|
140
151
|
// returning objects throw errors in isolated vm, so we stringify it and parse it back
|
|
141
152
|
const res = JSON.parse(resultStr);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { BuilderContextInterface, RegisteredComponents } from '../../context/types';
|
|
1
|
+
import type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from '../../context/types';
|
|
2
2
|
import type { BuilderBlock } from '../../types/builder-block';
|
|
3
3
|
import type { RepeatData } from './types';
|
|
4
4
|
export declare const getComponent: ({ block, context, registeredComponents }: {
|
|
5
5
|
block: BuilderBlock;
|
|
6
6
|
context: BuilderContextInterface;
|
|
7
7
|
registeredComponents: RegisteredComponents;
|
|
8
|
-
}) =>
|
|
8
|
+
}) => RegisteredComponent | null | undefined;
|
|
9
9
|
export declare const getRepeatItemData: ({ block, context }: {
|
|
10
10
|
block: BuilderBlock;
|
|
11
11
|
context: BuilderContextInterface;
|
|
@@ -14,5 +14,5 @@ export declare const getInheritedStyles: ({ block, context }: {
|
|
|
14
14
|
block: BuilderBlock;
|
|
15
15
|
context: BuilderContextInterface;
|
|
16
16
|
}) => Partial<CSSStyleDeclaration>;
|
|
17
|
-
export declare const shouldPassLinkComponent: (
|
|
18
|
-
export declare const shouldPassRegisteredComponents: (
|
|
17
|
+
export declare const shouldPassLinkComponent: (block: RegisteredComponent | null | undefined) => boolean | null | undefined;
|
|
18
|
+
export declare const shouldPassRegisteredComponents: (block: RegisteredComponent | null | undefined) => boolean | null | undefined;
|
|
@@ -73,9 +73,9 @@ export const getInheritedStyles = ({ block, context }) => {
|
|
|
73
73
|
}
|
|
74
74
|
return extractTextStyles(style);
|
|
75
75
|
};
|
|
76
|
-
export const shouldPassLinkComponent = (
|
|
77
|
-
return
|
|
76
|
+
export const shouldPassLinkComponent = (block) => {
|
|
77
|
+
return block && (block.isRSC || ['Core:Button', 'Symbol', 'Columns', 'Form:Form', 'Builder: Tabs'].includes(block.name));
|
|
78
78
|
};
|
|
79
|
-
export const shouldPassRegisteredComponents = (
|
|
80
|
-
return
|
|
79
|
+
export const shouldPassRegisteredComponents = (block) => {
|
|
80
|
+
return block && (block.isRSC || ['Symbol', 'Columns', 'Form:Form', 'Builder: Tabs'].includes(block.name));
|
|
81
81
|
};
|
|
@@ -77,12 +77,12 @@ $: componentRefProps = () => {
|
|
|
77
77
|
componentOptions: {
|
|
78
78
|
...getBlockComponentOptions(processedBlock()),
|
|
79
79
|
builderContext: context,
|
|
80
|
-
...(shouldPassLinkComponent(blockComponent
|
|
80
|
+
...(shouldPassLinkComponent(blockComponent())
|
|
81
81
|
? {
|
|
82
82
|
builderLinkComponent: linkComponent,
|
|
83
83
|
}
|
|
84
84
|
: {}),
|
|
85
|
-
...(shouldPassRegisteredComponents(blockComponent
|
|
85
|
+
...(shouldPassRegisteredComponents(blockComponent())
|
|
86
86
|
? {
|
|
87
87
|
builderComponents: registeredComponents,
|
|
88
88
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.26";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.26";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IsolateOptions } from 'isolated-vm';
|
|
1
2
|
/**
|
|
2
3
|
* This function initializes the SDK on a Node server. It handles importing the
|
|
3
4
|
* `isolated-vm` package which is needed for dynamic bindings.
|
|
@@ -7,4 +8,6 @@
|
|
|
7
8
|
* - The NextJS Pages router's `_document.tsx`
|
|
8
9
|
* - Your Remix route's `loader`
|
|
9
10
|
*/
|
|
10
|
-
export declare const initializeNodeRuntime: (
|
|
11
|
+
export declare const initializeNodeRuntime: (args?: {
|
|
12
|
+
ivmIsolateOptions?: IsolateOptions;
|
|
13
|
+
}) => void;
|
|
@@ -21,6 +21,7 @@ import { setIvm } from './node-runtime';
|
|
|
21
21
|
* - The NextJS Pages router's `_document.tsx`
|
|
22
22
|
* - Your Remix route's `loader`
|
|
23
23
|
*/
|
|
24
|
-
export const initializeNodeRuntime = () => {
|
|
25
|
-
|
|
24
|
+
export const initializeNodeRuntime = (args) => {
|
|
25
|
+
const { ivmIsolateOptions } = args || {};
|
|
26
|
+
setIvm(ivm, ivmIsolateOptions);
|
|
26
27
|
};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import type { IsolateOptions } from 'isolated-vm';
|
|
1
2
|
import type { ExecutorArgs } from '../helpers';
|
|
3
|
+
type IsolatedVMImport = typeof import('isolated-vm');
|
|
2
4
|
/**
|
|
3
5
|
* Set the `isolated-vm` instance to be used by the node runtime.
|
|
4
6
|
* This is useful for environments that are not able to rely on our
|
|
5
7
|
* `safeDynamicRequire` trick to import the `isolated-vm` package.
|
|
6
8
|
*/
|
|
7
|
-
export declare const setIvm: (ivm:
|
|
9
|
+
export declare const setIvm: (ivm: IsolatedVMImport, options?: IsolateOptions) => void;
|
|
8
10
|
export declare const runInNode: ({ code, builder, context, event, localState, rootSetState, rootState }: ExecutorArgs) => any;
|
|
11
|
+
export {};
|
|
@@ -45,23 +45,25 @@ function theFunction() {
|
|
|
45
45
|
${code}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
const output = theFunction()
|
|
49
49
|
|
|
50
50
|
if (typeof output === 'object' && output !== null) {
|
|
51
|
-
|
|
51
|
+
return JSON.stringify(output.copySync ? output.copySync() : output);
|
|
52
|
+
} else {
|
|
53
|
+
return output;
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
output;
|
|
55
55
|
`;
|
|
56
56
|
};
|
|
57
57
|
let IVM_INSTANCE = null;
|
|
58
|
+
let IVM_CONTEXT = null;
|
|
58
59
|
/**
|
|
59
60
|
* Set the `isolated-vm` instance to be used by the node runtime.
|
|
60
61
|
* This is useful for environments that are not able to rely on our
|
|
61
62
|
* `safeDynamicRequire` trick to import the `isolated-vm` package.
|
|
62
63
|
*/
|
|
63
|
-
export const setIvm = (ivm) => {
|
|
64
|
+
export const setIvm = (ivm, options = {}) => {
|
|
64
65
|
IVM_INSTANCE = ivm;
|
|
66
|
+
setIsolateContext(options);
|
|
65
67
|
};
|
|
66
68
|
const getIvm = () => {
|
|
67
69
|
try {
|
|
@@ -83,12 +85,29 @@ const getIvm = () => {
|
|
|
83
85
|
Please see the documentation for more information: https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments
|
|
84
86
|
`);
|
|
85
87
|
};
|
|
86
|
-
|
|
88
|
+
function setIsolateContext(options = {
|
|
89
|
+
memoryLimit: 128
|
|
90
|
+
}) {
|
|
87
91
|
const ivm = getIvm();
|
|
88
|
-
const isolate = new ivm.Isolate(
|
|
89
|
-
|
|
92
|
+
const isolate = new ivm.Isolate(options);
|
|
93
|
+
const context = isolate.createContextSync();
|
|
94
|
+
const jail = context.global;
|
|
95
|
+
// This makes the global object available in the context as `global`. We use `derefInto()` here
|
|
96
|
+
// because otherwise `global` would actually be a Reference{} object in the new isolate.
|
|
97
|
+
jail.setSync('global', jail.derefInto());
|
|
98
|
+
// We will create a basic `log` function for the new isolate to use.
|
|
99
|
+
jail.setSync('log', function (...logArgs) {
|
|
100
|
+
console.log(...logArgs);
|
|
90
101
|
});
|
|
91
|
-
|
|
102
|
+
jail.setSync(INJECTED_IVM_GLOBAL, ivm);
|
|
103
|
+
IVM_CONTEXT = context;
|
|
104
|
+
return context;
|
|
105
|
+
}
|
|
106
|
+
const getIsolateContext = () => {
|
|
107
|
+
if (IVM_CONTEXT)
|
|
108
|
+
return IVM_CONTEXT;
|
|
109
|
+
const context = setIsolateContext();
|
|
110
|
+
return context;
|
|
92
111
|
};
|
|
93
112
|
export const runInNode = ({ code, builder, context, event, localState, rootSetState, rootState }) => {
|
|
94
113
|
const ivm = getIvm();
|
|
@@ -104,13 +123,6 @@ export const runInNode = ({ code, builder, context, event, localState, rootSetSt
|
|
|
104
123
|
});
|
|
105
124
|
const isolateContext = getIsolateContext();
|
|
106
125
|
const jail = isolateContext.global;
|
|
107
|
-
// This makes the global object available in the context as `global`. We use `derefInto()` here
|
|
108
|
-
// because otherwise `global` would actually be a Reference{} object in the new isolate.
|
|
109
|
-
jail.setSync('global', jail.derefInto());
|
|
110
|
-
// We will create a basic `log` function for the new isolate to use.
|
|
111
|
-
jail.setSync('log', function (...logArgs) {
|
|
112
|
-
console.log(...logArgs);
|
|
113
|
-
});
|
|
114
126
|
/**
|
|
115
127
|
* Propagate state changes back to the reactive root state.
|
|
116
128
|
*/
|
|
@@ -130,12 +142,11 @@ export const runInNode = ({ code, builder, context, event, localState, rootSetSt
|
|
|
130
142
|
} : arg) : null;
|
|
131
143
|
jail.setSync(getSyncValName(key), val);
|
|
132
144
|
});
|
|
133
|
-
jail.setSync(INJECTED_IVM_GLOBAL, ivm);
|
|
134
145
|
const evalStr = processCode({
|
|
135
146
|
code,
|
|
136
147
|
args
|
|
137
148
|
});
|
|
138
|
-
const resultStr = isolateContext.
|
|
149
|
+
const resultStr = isolateContext.evalClosureSync(evalStr);
|
|
139
150
|
try {
|
|
140
151
|
// returning objects throw errors in isolated vm, so we stringify it and parse it back
|
|
141
152
|
const res = JSON.parse(resultStr);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { BuilderContextInterface, RegisteredComponents } from '../../context/types';
|
|
1
|
+
import type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from '../../context/types';
|
|
2
2
|
import type { BuilderBlock } from '../../types/builder-block';
|
|
3
3
|
import type { RepeatData } from './types';
|
|
4
4
|
export declare const getComponent: ({ block, context, registeredComponents }: {
|
|
5
5
|
block: BuilderBlock;
|
|
6
6
|
context: BuilderContextInterface;
|
|
7
7
|
registeredComponents: RegisteredComponents;
|
|
8
|
-
}) =>
|
|
8
|
+
}) => RegisteredComponent | null | undefined;
|
|
9
9
|
export declare const getRepeatItemData: ({ block, context }: {
|
|
10
10
|
block: BuilderBlock;
|
|
11
11
|
context: BuilderContextInterface;
|
|
@@ -14,5 +14,5 @@ export declare const getInheritedStyles: ({ block, context }: {
|
|
|
14
14
|
block: BuilderBlock;
|
|
15
15
|
context: BuilderContextInterface;
|
|
16
16
|
}) => Partial<CSSStyleDeclaration>;
|
|
17
|
-
export declare const shouldPassLinkComponent: (
|
|
18
|
-
export declare const shouldPassRegisteredComponents: (
|
|
17
|
+
export declare const shouldPassLinkComponent: (block: RegisteredComponent | null | undefined) => boolean | null | undefined;
|
|
18
|
+
export declare const shouldPassRegisteredComponents: (block: RegisteredComponent | null | undefined) => boolean | null | undefined;
|
|
@@ -73,9 +73,9 @@ export const getInheritedStyles = ({ block, context }) => {
|
|
|
73
73
|
}
|
|
74
74
|
return extractTextStyles(style);
|
|
75
75
|
};
|
|
76
|
-
export const shouldPassLinkComponent = (
|
|
77
|
-
return
|
|
76
|
+
export const shouldPassLinkComponent = (block) => {
|
|
77
|
+
return block && (block.isRSC || ['Core:Button', 'Symbol', 'Columns', 'Form:Form', 'Builder: Tabs'].includes(block.name));
|
|
78
78
|
};
|
|
79
|
-
export const shouldPassRegisteredComponents = (
|
|
80
|
-
return
|
|
79
|
+
export const shouldPassRegisteredComponents = (block) => {
|
|
80
|
+
return block && (block.isRSC || ['Symbol', 'Columns', 'Form:Form', 'Builder: Tabs'].includes(block.name));
|
|
81
81
|
};
|
|
@@ -77,12 +77,12 @@ $: componentRefProps = () => {
|
|
|
77
77
|
componentOptions: {
|
|
78
78
|
...getBlockComponentOptions(processedBlock()),
|
|
79
79
|
builderContext: context,
|
|
80
|
-
...(shouldPassLinkComponent(blockComponent
|
|
80
|
+
...(shouldPassLinkComponent(blockComponent())
|
|
81
81
|
? {
|
|
82
82
|
builderLinkComponent: linkComponent,
|
|
83
83
|
}
|
|
84
84
|
: {}),
|
|
85
|
-
...(shouldPassRegisteredComponents(blockComponent
|
|
85
|
+
...(shouldPassRegisteredComponents(blockComponent())
|
|
86
86
|
? {
|
|
87
87
|
builderComponents: registeredComponents,
|
|
88
88
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.26";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.26";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IsolateOptions } from 'isolated-vm';
|
|
1
2
|
/**
|
|
2
3
|
* This function initializes the SDK on a Node server. It handles importing the
|
|
3
4
|
* `isolated-vm` package which is needed for dynamic bindings.
|
|
@@ -7,4 +8,6 @@
|
|
|
7
8
|
* - The NextJS Pages router's `_document.tsx`
|
|
8
9
|
* - Your Remix route's `loader`
|
|
9
10
|
*/
|
|
10
|
-
export declare const initializeNodeRuntime: (
|
|
11
|
+
export declare const initializeNodeRuntime: (args?: {
|
|
12
|
+
ivmIsolateOptions?: IsolateOptions;
|
|
13
|
+
}) => void;
|
|
@@ -21,6 +21,7 @@ import { setIvm } from './node-runtime';
|
|
|
21
21
|
* - The NextJS Pages router's `_document.tsx`
|
|
22
22
|
* - Your Remix route's `loader`
|
|
23
23
|
*/
|
|
24
|
-
export const initializeNodeRuntime = () => {
|
|
25
|
-
|
|
24
|
+
export const initializeNodeRuntime = (args) => {
|
|
25
|
+
const { ivmIsolateOptions } = args || {};
|
|
26
|
+
setIvm(ivm, ivmIsolateOptions);
|
|
26
27
|
};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import type { IsolateOptions } from 'isolated-vm';
|
|
1
2
|
import type { ExecutorArgs } from '../helpers';
|
|
3
|
+
type IsolatedVMImport = typeof import('isolated-vm');
|
|
2
4
|
/**
|
|
3
5
|
* Set the `isolated-vm` instance to be used by the node runtime.
|
|
4
6
|
* This is useful for environments that are not able to rely on our
|
|
5
7
|
* `safeDynamicRequire` trick to import the `isolated-vm` package.
|
|
6
8
|
*/
|
|
7
|
-
export declare const setIvm: (ivm:
|
|
9
|
+
export declare const setIvm: (ivm: IsolatedVMImport, options?: IsolateOptions) => void;
|
|
8
10
|
export declare const runInNode: ({ code, builder, context, event, localState, rootSetState, rootState }: ExecutorArgs) => any;
|
|
11
|
+
export {};
|
|
@@ -45,23 +45,25 @@ function theFunction() {
|
|
|
45
45
|
${code}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
const output = theFunction()
|
|
49
49
|
|
|
50
50
|
if (typeof output === 'object' && output !== null) {
|
|
51
|
-
|
|
51
|
+
return JSON.stringify(output.copySync ? output.copySync() : output);
|
|
52
|
+
} else {
|
|
53
|
+
return output;
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
output;
|
|
55
55
|
`;
|
|
56
56
|
};
|
|
57
57
|
let IVM_INSTANCE = null;
|
|
58
|
+
let IVM_CONTEXT = null;
|
|
58
59
|
/**
|
|
59
60
|
* Set the `isolated-vm` instance to be used by the node runtime.
|
|
60
61
|
* This is useful for environments that are not able to rely on our
|
|
61
62
|
* `safeDynamicRequire` trick to import the `isolated-vm` package.
|
|
62
63
|
*/
|
|
63
|
-
export const setIvm = (ivm) => {
|
|
64
|
+
export const setIvm = (ivm, options = {}) => {
|
|
64
65
|
IVM_INSTANCE = ivm;
|
|
66
|
+
setIsolateContext(options);
|
|
65
67
|
};
|
|
66
68
|
const getIvm = () => {
|
|
67
69
|
try {
|
|
@@ -83,12 +85,29 @@ const getIvm = () => {
|
|
|
83
85
|
Please see the documentation for more information: https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments
|
|
84
86
|
`);
|
|
85
87
|
};
|
|
86
|
-
|
|
88
|
+
function setIsolateContext(options = {
|
|
89
|
+
memoryLimit: 128
|
|
90
|
+
}) {
|
|
87
91
|
const ivm = getIvm();
|
|
88
|
-
const isolate = new ivm.Isolate(
|
|
89
|
-
|
|
92
|
+
const isolate = new ivm.Isolate(options);
|
|
93
|
+
const context = isolate.createContextSync();
|
|
94
|
+
const jail = context.global;
|
|
95
|
+
// This makes the global object available in the context as `global`. We use `derefInto()` here
|
|
96
|
+
// because otherwise `global` would actually be a Reference{} object in the new isolate.
|
|
97
|
+
jail.setSync('global', jail.derefInto());
|
|
98
|
+
// We will create a basic `log` function for the new isolate to use.
|
|
99
|
+
jail.setSync('log', function (...logArgs) {
|
|
100
|
+
console.log(...logArgs);
|
|
90
101
|
});
|
|
91
|
-
|
|
102
|
+
jail.setSync(INJECTED_IVM_GLOBAL, ivm);
|
|
103
|
+
IVM_CONTEXT = context;
|
|
104
|
+
return context;
|
|
105
|
+
}
|
|
106
|
+
const getIsolateContext = () => {
|
|
107
|
+
if (IVM_CONTEXT)
|
|
108
|
+
return IVM_CONTEXT;
|
|
109
|
+
const context = setIsolateContext();
|
|
110
|
+
return context;
|
|
92
111
|
};
|
|
93
112
|
export const runInNode = ({ code, builder, context, event, localState, rootSetState, rootState }) => {
|
|
94
113
|
const ivm = getIvm();
|
|
@@ -104,13 +123,6 @@ export const runInNode = ({ code, builder, context, event, localState, rootSetSt
|
|
|
104
123
|
});
|
|
105
124
|
const isolateContext = getIsolateContext();
|
|
106
125
|
const jail = isolateContext.global;
|
|
107
|
-
// This makes the global object available in the context as `global`. We use `derefInto()` here
|
|
108
|
-
// because otherwise `global` would actually be a Reference{} object in the new isolate.
|
|
109
|
-
jail.setSync('global', jail.derefInto());
|
|
110
|
-
// We will create a basic `log` function for the new isolate to use.
|
|
111
|
-
jail.setSync('log', function (...logArgs) {
|
|
112
|
-
console.log(...logArgs);
|
|
113
|
-
});
|
|
114
126
|
/**
|
|
115
127
|
* Propagate state changes back to the reactive root state.
|
|
116
128
|
*/
|
|
@@ -130,12 +142,11 @@ export const runInNode = ({ code, builder, context, event, localState, rootSetSt
|
|
|
130
142
|
} : arg) : null;
|
|
131
143
|
jail.setSync(getSyncValName(key), val);
|
|
132
144
|
});
|
|
133
|
-
jail.setSync(INJECTED_IVM_GLOBAL, ivm);
|
|
134
145
|
const evalStr = processCode({
|
|
135
146
|
code,
|
|
136
147
|
args
|
|
137
148
|
});
|
|
138
|
-
const resultStr = isolateContext.
|
|
149
|
+
const resultStr = isolateContext.evalClosureSync(evalStr);
|
|
139
150
|
try {
|
|
140
151
|
// returning objects throw errors in isolated vm, so we stringify it and parse it back
|
|
141
152
|
const res = JSON.parse(resultStr);
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BuilderContextInterface, RegisteredComponents } from '../../context/types';
|
|
1
|
+
import type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from '../../context/types';
|
|
2
2
|
import { evaluate } from '../../functions/evaluate/index';
|
|
3
3
|
import { extractTextStyles } from '../../functions/extract-text-styles';
|
|
4
4
|
import { getProcessedBlock } from '../../functions/get-processed-block';
|
|
@@ -98,9 +98,9 @@ export const getInheritedStyles = ({
|
|
|
98
98
|
}
|
|
99
99
|
return extractTextStyles(style);
|
|
100
100
|
};
|
|
101
|
-
export const shouldPassLinkComponent = (
|
|
102
|
-
return
|
|
101
|
+
export const shouldPassLinkComponent = (block: RegisteredComponent | null | undefined) => {
|
|
102
|
+
return block && (block.isRSC || ['Core:Button', 'Symbol', 'Columns', 'Form:Form', 'Builder: Tabs'].includes(block.name));
|
|
103
103
|
};
|
|
104
|
-
export const shouldPassRegisteredComponents = (
|
|
105
|
-
return
|
|
104
|
+
export const shouldPassRegisteredComponents = (block: RegisteredComponent | null | undefined) => {
|
|
105
|
+
return block && (block.isRSC || ['Symbol', 'Columns', 'Form:Form', 'Builder: Tabs'].includes(block.name));
|
|
106
106
|
}
|
|
@@ -104,12 +104,12 @@
|
|
|
104
104
|
componentOptions: {
|
|
105
105
|
...getBlockComponentOptions(processedBlock()),
|
|
106
106
|
builderContext: context,
|
|
107
|
-
...(shouldPassLinkComponent(blockComponent
|
|
107
|
+
...(shouldPassLinkComponent(blockComponent())
|
|
108
108
|
? {
|
|
109
109
|
builderLinkComponent: linkComponent,
|
|
110
110
|
}
|
|
111
111
|
: {}),
|
|
112
|
-
...(shouldPassRegisteredComponents(blockComponent
|
|
112
|
+
...(shouldPassRegisteredComponents(blockComponent())
|
|
113
113
|
? {
|
|
114
114
|
builderComponents: registeredComponents,
|
|
115
115
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.26"
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import ivm from 'isolated-vm';
|
|
14
14
|
import { setIvm } from './node-runtime';
|
|
15
|
+
import type { IsolateOptions } from 'isolated-vm';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* This function initializes the SDK on a Node server. It handles importing the
|
|
@@ -22,6 +23,11 @@ import { setIvm } from './node-runtime';
|
|
|
22
23
|
* - The NextJS Pages router's `_document.tsx`
|
|
23
24
|
* - Your Remix route's `loader`
|
|
24
25
|
*/
|
|
25
|
-
export const initializeNodeRuntime = (
|
|
26
|
-
|
|
26
|
+
export const initializeNodeRuntime = (args?: {
|
|
27
|
+
ivmIsolateOptions?: IsolateOptions;
|
|
28
|
+
}) => {
|
|
29
|
+
const {
|
|
30
|
+
ivmIsolateOptions
|
|
31
|
+
} = args || {};
|
|
32
|
+
setIvm(ivm, ivmIsolateOptions);
|
|
27
33
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Context, IsolateOptions } from 'isolated-vm';
|
|
1
2
|
import { MSG_PREFIX, logger } from '../../../helpers/logger';
|
|
2
3
|
import { fastClone } from '../../fast-clone';
|
|
3
4
|
import { set } from '../../set';
|
|
@@ -54,26 +55,29 @@ function theFunction() {
|
|
|
54
55
|
${code}
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
const output = theFunction()
|
|
58
59
|
|
|
59
60
|
if (typeof output === 'object' && output !== null) {
|
|
60
|
-
|
|
61
|
+
return JSON.stringify(output.copySync ? output.copySync() : output);
|
|
62
|
+
} else {
|
|
63
|
+
return output;
|
|
61
64
|
}
|
|
62
|
-
|
|
63
|
-
output;
|
|
64
65
|
`;
|
|
65
66
|
};
|
|
66
|
-
|
|
67
|
+
type IsolatedVMImport = typeof import('isolated-vm');
|
|
68
|
+
let IVM_INSTANCE: IsolatedVMImport | null = null;
|
|
69
|
+
let IVM_CONTEXT: Context | null = null;
|
|
67
70
|
|
|
68
71
|
/**
|
|
69
72
|
* Set the `isolated-vm` instance to be used by the node runtime.
|
|
70
73
|
* This is useful for environments that are not able to rely on our
|
|
71
74
|
* `safeDynamicRequire` trick to import the `isolated-vm` package.
|
|
72
75
|
*/
|
|
73
|
-
export const setIvm = (ivm:
|
|
76
|
+
export const setIvm = (ivm: IsolatedVMImport, options: IsolateOptions = {}) => {
|
|
74
77
|
IVM_INSTANCE = ivm;
|
|
78
|
+
setIsolateContext(options);
|
|
75
79
|
};
|
|
76
|
-
const getIvm = ():
|
|
80
|
+
const getIvm = (): IsolatedVMImport => {
|
|
77
81
|
try {
|
|
78
82
|
if (IVM_INSTANCE) return IVM_INSTANCE;
|
|
79
83
|
const dynRequiredIvm = safeDynamicRequire('isolated-vm');
|
|
@@ -90,12 +94,30 @@ const getIvm = (): typeof import('isolated-vm') => {
|
|
|
90
94
|
Please see the documentation for more information: https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments
|
|
91
95
|
`);
|
|
92
96
|
};
|
|
93
|
-
|
|
97
|
+
function setIsolateContext(options: IsolateOptions = {
|
|
98
|
+
memoryLimit: 128
|
|
99
|
+
}) {
|
|
94
100
|
const ivm = getIvm();
|
|
95
|
-
const isolate = new ivm.Isolate(
|
|
96
|
-
|
|
101
|
+
const isolate = new ivm.Isolate(options);
|
|
102
|
+
const context = isolate.createContextSync();
|
|
103
|
+
const jail = context.global;
|
|
104
|
+
|
|
105
|
+
// This makes the global object available in the context as `global`. We use `derefInto()` here
|
|
106
|
+
// because otherwise `global` would actually be a Reference{} object in the new isolate.
|
|
107
|
+
jail.setSync('global', jail.derefInto());
|
|
108
|
+
|
|
109
|
+
// We will create a basic `log` function for the new isolate to use.
|
|
110
|
+
jail.setSync('log', function (...logArgs: any[]) {
|
|
111
|
+
console.log(...logArgs);
|
|
97
112
|
});
|
|
98
|
-
|
|
113
|
+
jail.setSync(INJECTED_IVM_GLOBAL, ivm);
|
|
114
|
+
IVM_CONTEXT = context;
|
|
115
|
+
return context;
|
|
116
|
+
}
|
|
117
|
+
const getIsolateContext = () => {
|
|
118
|
+
if (IVM_CONTEXT) return IVM_CONTEXT;
|
|
119
|
+
const context = setIsolateContext();
|
|
120
|
+
return context;
|
|
99
121
|
};
|
|
100
122
|
export const runInNode = ({
|
|
101
123
|
code,
|
|
@@ -119,14 +141,6 @@ export const runInNode = ({
|
|
|
119
141
|
});
|
|
120
142
|
const isolateContext = getIsolateContext();
|
|
121
143
|
const jail = isolateContext.global;
|
|
122
|
-
// This makes the global object available in the context as `global`. We use `derefInto()` here
|
|
123
|
-
// because otherwise `global` would actually be a Reference{} object in the new isolate.
|
|
124
|
-
jail.setSync('global', jail.derefInto());
|
|
125
|
-
|
|
126
|
-
// We will create a basic `log` function for the new isolate to use.
|
|
127
|
-
jail.setSync('log', function (...logArgs: any[]) {
|
|
128
|
-
console.log(...logArgs);
|
|
129
|
-
});
|
|
130
144
|
|
|
131
145
|
/**
|
|
132
146
|
* Propagate state changes back to the reactive root state.
|
|
@@ -147,12 +161,11 @@ export const runInNode = ({
|
|
|
147
161
|
} : arg) : null;
|
|
148
162
|
jail.setSync(getSyncValName(key), val);
|
|
149
163
|
});
|
|
150
|
-
jail.setSync(INJECTED_IVM_GLOBAL, ivm);
|
|
151
164
|
const evalStr = processCode({
|
|
152
165
|
code,
|
|
153
166
|
args
|
|
154
167
|
});
|
|
155
|
-
const resultStr = isolateContext.
|
|
168
|
+
const resultStr = isolateContext.evalClosureSync(evalStr);
|
|
156
169
|
try {
|
|
157
170
|
// returning objects throw errors in isolated vm, so we stringify it and parse it back
|
|
158
171
|
const res = JSON.parse(resultStr);
|