@builder.io/sdk-react 1.0.20 → 1.0.22
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 +22 -22
- package/lib/browser/blocks-exports.mjs +428 -432
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +1 -1
- package/lib/browser/init.cjs +1 -0
- package/lib/browser/init.mjs +13 -0
- package/lib/browser/{server-entry-a562cf23.js → server-entry-3e30c656.js} +81 -82
- package/lib/browser/server-entry-8951c0c5.cjs +2 -0
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/blocks-5705f416.cjs +32 -0
- package/lib/edge/{blocks-683aad9f.js → blocks-b1f5ec2b.js} +742 -747
- package/lib/edge/blocks-exports.cjs +1 -1
- package/lib/edge/blocks-exports.mjs +2 -2
- package/lib/edge/{button-9f6acf3e.js → button-2b710146.js} +2 -2
- package/lib/edge/{button-0d418bcf.cjs → button-3c20ccff.cjs} +1 -1
- package/lib/edge/{columns-b0785992.js → columns-38a397cd.js} +3 -3
- package/lib/edge/{columns-1613d62d.cjs → columns-761d98c4.cjs} +1 -1
- package/lib/edge/{content-variants-281298f6.cjs → content-variants-befe3587.cjs} +4 -4
- package/lib/edge/{content-variants-13f821c6.js → content-variants-f165fa88.js} +21 -21
- package/lib/edge/{form-0483aa64.cjs → form-b0d65d74.cjs} +1 -1
- package/lib/edge/{form-db27fc26.js → form-d0cfb830.js} +3 -3
- package/lib/edge/{get-class-prop-name-e3ba0522.cjs → get-class-prop-name-27f8a4f1.cjs} +1 -1
- package/lib/edge/{get-class-prop-name-6bfc4756.js → get-class-prop-name-49d9b54f.js} +1 -1
- package/lib/edge/{img-43a8ffe0.js → img-e321016e.js} +1 -1
- package/lib/edge/{img-f01d904d.cjs → img-fcf6e57f.cjs} +1 -1
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +1 -1
- package/lib/edge/init.cjs +1 -0
- package/lib/edge/init.mjs +13 -0
- package/lib/edge/{input-805a9ac6.js → input-27f575fe.js} +1 -1
- package/lib/edge/{input-e6483bd7.cjs → input-f0319ee6.cjs} +1 -1
- package/lib/edge/{select-4966723f.js → select-dd4c61db.js} +1 -1
- package/lib/edge/{select-e5d1e627.cjs → select-e31522ee.cjs} +1 -1
- package/lib/edge/{server-entry-c13e82bd.js → server-entry-253a0fa1.js} +80 -81
- package/lib/edge/server-entry-dd363108.cjs +2 -0
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/edge/{slot-3ef77ae1.cjs → slot-a2388031.cjs} +1 -1
- package/lib/edge/{slot-1b0351de.js → slot-fea27ccf.js} +3 -3
- package/lib/edge/{symbol-f1632f93.js → symbol-686edeb8.js} +2 -2
- package/lib/edge/{symbol-883d624f.cjs → symbol-ba2c6245.cjs} +1 -1
- package/lib/node/blocks-exports.cjs +30 -70
- package/lib/node/blocks-exports.mjs +916 -1046
- package/lib/node/index.cjs +1 -1
- package/lib/node/index.mjs +23 -22
- package/lib/node/init.cjs +1 -0
- package/lib/node/init.mjs +9 -0
- package/lib/node/node-runtime-6587ed2e.js +155 -0
- package/lib/node/node-runtime-fa43cf07.cjs +48 -0
- package/lib/node/{server-entry-8c712c9b.js → server-entry-14d7a1d0.js} +82 -82
- package/lib/node/server-entry-3abae5dd.cjs +2 -0
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +1 -1
- package/package.json +6 -1
- package/types/components/block/animator.d.ts +1 -1
- package/types/constants/sdk-version.d.ts +1 -1
- package/types/functions/evaluate/node-runtime/init.d.ts +10 -0
- package/types/functions/evaluate/node-runtime/node-runtime.d.ts +6 -0
- package/types/functions/get-content/types.d.ts +3 -3
- package/types/functions/is-previewing.d.ts +1 -1
- package/types/helpers/logger.d.ts +1 -0
- package/lib/browser/server-entry-a77461d4.cjs +0 -2
- package/lib/edge/blocks-523eb4f1.cjs +0 -32
- package/lib/edge/server-entry-83648311.cjs +0 -2
- package/lib/node/server-entry-bedf45f8.cjs +0 -2
package/lib/node/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./blocks-exports.cjs"),e=require("./server-entry-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./blocks-exports.cjs"),e=require("./server-entry-3abae5dd.cjs");require("react/jsx-runtime");require("react");require("./node-runtime-fa43cf07.cjs");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,29 +1,30 @@
|
|
|
1
|
-
import { Blocks as
|
|
2
|
-
import { _processContentResult as
|
|
1
|
+
import { Blocks as s, BuilderContext as n, Button as m, Columns as c, Content as g, Fragment as a, Image as p, Section as d, Symbol as l, Text as u, Video as f } from "./blocks-exports.mjs";
|
|
2
|
+
import { _processContentResult as C, createRegisterComponentMessage as E, fetchBuilderProps as h, fetchEntries as x, fetchOneEntry as S, getBuilderSearchParams as b, isEditing as P, isPreviewing as k, register as y, setEditorSettings as R, subscribeToEditor as T, track as v } from "./server-entry-14d7a1d0.js";
|
|
3
3
|
import "react/jsx-runtime";
|
|
4
4
|
import "react";
|
|
5
|
+
import "./node-runtime-6587ed2e.js";
|
|
5
6
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
s as Blocks,
|
|
8
|
+
n as BuilderContext,
|
|
9
|
+
m as Button,
|
|
9
10
|
c as Columns,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
g as Content,
|
|
12
|
+
a as Fragment,
|
|
13
|
+
p as Image,
|
|
13
14
|
d as Section,
|
|
14
15
|
l as Symbol,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
u as Text,
|
|
17
|
+
f as Video,
|
|
18
|
+
C as _processContentResult,
|
|
19
|
+
E as createRegisterComponentMessage,
|
|
20
|
+
h as fetchBuilderProps,
|
|
21
|
+
x as fetchEntries,
|
|
22
|
+
S as fetchOneEntry,
|
|
23
|
+
b as getBuilderSearchParams,
|
|
24
|
+
P as isEditing,
|
|
25
|
+
k as isPreviewing,
|
|
26
|
+
y as register,
|
|
27
|
+
R as setEditorSettings,
|
|
28
|
+
T as subscribeToEditor,
|
|
29
|
+
v as track
|
|
29
30
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("isolated-vm"),i=require("./node-runtime-fa43cf07.cjs");require("./server-entry-3abae5dd.cjs");const t=()=>{i.setIvm(e)};exports.initializeNodeRuntime=t;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { isEditing, isBrowser, getUserAttributes, fastClone, logger, MSG_PREFIX } from "./server-entry-14d7a1d0.js";
|
|
2
|
+
const getFunctionArguments = ({
|
|
3
|
+
builder: e,
|
|
4
|
+
context: n,
|
|
5
|
+
event: r,
|
|
6
|
+
state: t
|
|
7
|
+
}) => Object.entries({
|
|
8
|
+
state: t,
|
|
9
|
+
Builder: e,
|
|
10
|
+
// legacy
|
|
11
|
+
builder: e,
|
|
12
|
+
context: n,
|
|
13
|
+
event: r
|
|
14
|
+
}), getBuilderGlobals = () => ({
|
|
15
|
+
isEditing: isEditing(),
|
|
16
|
+
isBrowser: isBrowser(),
|
|
17
|
+
isServer: !isBrowser(),
|
|
18
|
+
getUserAttributes: () => getUserAttributes()
|
|
19
|
+
}), parseCode = (e, {
|
|
20
|
+
isExpression: n = !0
|
|
21
|
+
}) => /* we disable this for cases where we definitely don't want a return */ n && !(e.includes(";") || e.includes(" return ") || e.trim().startsWith("return ")) ? `return (${e});` : e, set = (e, n, r) => {
|
|
22
|
+
if (Object(e) !== e)
|
|
23
|
+
return e;
|
|
24
|
+
const t = Array.isArray(n) ? n : n.toString().match(/[^.[\]]+/g);
|
|
25
|
+
return t.slice(0, -1).reduce((i, o, c) => Object(i[o]) === i[o] ? i[o] : i[o] = Math.abs(Number(t[c + 1])) >> 0 === +t[c + 1] ? [] : {}, e)[t[t.length - 1]] = r, e;
|
|
26
|
+
}, noop = () => {
|
|
27
|
+
};
|
|
28
|
+
let safeDynamicRequire = noop;
|
|
29
|
+
try {
|
|
30
|
+
safeDynamicRequire = eval("require");
|
|
31
|
+
} catch (e) {
|
|
32
|
+
}
|
|
33
|
+
const getSyncValName = (e) => `bldr_${e}_sync`, BUILDER_SET_STATE_NAME = "BUILDER_SET_STATE", INJECTED_IVM_GLOBAL = "BUILDER_IVM", REF_TO_PROXY_FN = `
|
|
34
|
+
var refToProxy = (obj) => {
|
|
35
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
36
|
+
return obj;
|
|
37
|
+
}
|
|
38
|
+
return new Proxy({}, {
|
|
39
|
+
get(target, key) {
|
|
40
|
+
if (key === 'copySync') {
|
|
41
|
+
return () => obj.copySync();
|
|
42
|
+
}
|
|
43
|
+
const val = obj.getSync(key);
|
|
44
|
+
if (typeof val?.getSync === 'function') {
|
|
45
|
+
return refToProxy(val);
|
|
46
|
+
}
|
|
47
|
+
return val;
|
|
48
|
+
},
|
|
49
|
+
set(target, key, value) {
|
|
50
|
+
const v = typeof value === 'object' ? new ${INJECTED_IVM_GLOBAL}.Reference(value) : value;
|
|
51
|
+
obj.setSync(key, v);
|
|
52
|
+
${BUILDER_SET_STATE_NAME}(key, value)
|
|
53
|
+
},
|
|
54
|
+
deleteProperty(target, key) {
|
|
55
|
+
obj.deleteSync(key);
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
`, processCode = ({
|
|
60
|
+
code: e,
|
|
61
|
+
args: n
|
|
62
|
+
}) => {
|
|
63
|
+
const r = n.map(([t]) => `var ${t} = refToProxy(${getSyncValName(t)}); `).join("");
|
|
64
|
+
return `
|
|
65
|
+
${REF_TO_PROXY_FN}
|
|
66
|
+
${r}
|
|
67
|
+
function theFunction() {
|
|
68
|
+
${e}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let output = theFunction()
|
|
72
|
+
|
|
73
|
+
if (typeof output === 'object' && output !== null) {
|
|
74
|
+
output = JSON.stringify(output.copySync ? output.copySync() : output);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
output;
|
|
78
|
+
`;
|
|
79
|
+
};
|
|
80
|
+
let IVM_INSTANCE = null;
|
|
81
|
+
const setIvm = (e) => {
|
|
82
|
+
IVM_INSTANCE = e;
|
|
83
|
+
}, getIvm = () => {
|
|
84
|
+
try {
|
|
85
|
+
if (IVM_INSTANCE)
|
|
86
|
+
return IVM_INSTANCE;
|
|
87
|
+
const e = safeDynamicRequire("isolated-vm");
|
|
88
|
+
if (e)
|
|
89
|
+
return e;
|
|
90
|
+
} catch (e) {
|
|
91
|
+
logger.error("isolated-vm import error.", e);
|
|
92
|
+
}
|
|
93
|
+
throw new Error(`${MSG_PREFIX}could not import \`isolated-vm\` module for safe script execution on Node server.
|
|
94
|
+
|
|
95
|
+
In certain Node environments, the SDK requires additional initialization steps. This can be achieved by
|
|
96
|
+
importing and calling \`initializeNodeRuntime()\` from "@builder.io/sdk-react/node/init". This must be done in
|
|
97
|
+
a server-only execution path within your application.
|
|
98
|
+
|
|
99
|
+
Please see the documentation for more information: https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments
|
|
100
|
+
`);
|
|
101
|
+
}, getIsolateContext = () => {
|
|
102
|
+
const e = getIvm();
|
|
103
|
+
return new e.Isolate({
|
|
104
|
+
memoryLimit: 128
|
|
105
|
+
}).createContextSync();
|
|
106
|
+
}, runInNode = ({
|
|
107
|
+
code: e,
|
|
108
|
+
builder: n,
|
|
109
|
+
context: r,
|
|
110
|
+
event: t,
|
|
111
|
+
localState: i,
|
|
112
|
+
rootSetState: o,
|
|
113
|
+
rootState: c
|
|
114
|
+
}) => {
|
|
115
|
+
const a = getIvm(), m = fastClone({
|
|
116
|
+
...c,
|
|
117
|
+
...i
|
|
118
|
+
}), y = getFunctionArguments({
|
|
119
|
+
builder: n,
|
|
120
|
+
context: r,
|
|
121
|
+
event: t,
|
|
122
|
+
state: m
|
|
123
|
+
}), g = getIsolateContext(), u = g.global;
|
|
124
|
+
u.setSync("global", u.derefInto()), u.setSync("log", function(...s) {
|
|
125
|
+
console.log(...s);
|
|
126
|
+
}), u.setSync(BUILDER_SET_STATE_NAME, function(s, l) {
|
|
127
|
+
set(c, s, l), o == null || o(c);
|
|
128
|
+
}), y.forEach(([s, l]) => {
|
|
129
|
+
const f = typeof l == "object" ? new a.Reference(
|
|
130
|
+
// workaround: methods with default values for arguments is not being cloned over
|
|
131
|
+
s === "builder" ? {
|
|
132
|
+
...l,
|
|
133
|
+
getUserAttributes: () => l.getUserAttributes()
|
|
134
|
+
} : l
|
|
135
|
+
) : null;
|
|
136
|
+
u.setSync(getSyncValName(s), f);
|
|
137
|
+
}), u.setSync(INJECTED_IVM_GLOBAL, a);
|
|
138
|
+
const p = processCode({
|
|
139
|
+
code: e,
|
|
140
|
+
args: y
|
|
141
|
+
}), d = g.evalSync(p);
|
|
142
|
+
try {
|
|
143
|
+
return JSON.parse(d);
|
|
144
|
+
} catch {
|
|
145
|
+
return d;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
export {
|
|
149
|
+
getBuilderGlobals,
|
|
150
|
+
getFunctionArguments,
|
|
151
|
+
parseCode,
|
|
152
|
+
runInNode,
|
|
153
|
+
set,
|
|
154
|
+
setIvm
|
|
155
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";const serverEntry=require("./server-entry-3abae5dd.cjs"),getFunctionArguments=({builder:e,context:r,event:n,state:t})=>Object.entries({state:t,Builder:e,builder:e,context:r,event:n}),getBuilderGlobals=()=>({isEditing:serverEntry.isEditing(),isBrowser:serverEntry.isBrowser(),isServer:!serverEntry.isBrowser(),getUserAttributes:()=>serverEntry.getUserAttributes()}),parseCode=(e,{isExpression:r=!0})=>r&&!(e.includes(";")||e.includes(" return ")||e.trim().startsWith("return "))?`return (${e});`: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((i,o,c)=>Object(i[o])===i[o]?i[o]:i[o]=Math.abs(Number(t[c+1]))>>0===+t[c+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
|
+
let output = theFunction()
|
|
35
|
+
|
|
36
|
+
if (typeof output === 'object' && output !== null) {
|
|
37
|
+
output = JSON.stringify(output.copySync ? output.copySync() : output);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
output;
|
|
41
|
+
`};let IVM_INSTANCE=null;const setIvm=e=>{IVM_INSTANCE=e},getIvm=()=>{try{if(IVM_INSTANCE)return IVM_INSTANCE;const e=safeDynamicRequire("isolated-vm");if(e)return e}catch(e){serverEntry.logger.error("isolated-vm import error.",e)}throw new Error(`${serverEntry.MSG_PREFIX}could not import \`isolated-vm\` module for safe script execution on Node server.
|
|
42
|
+
|
|
43
|
+
In certain Node environments, the SDK requires additional initialization steps. This can be achieved by
|
|
44
|
+
importing and calling \`initializeNodeRuntime()\` from "@builder.io/sdk-react/node/init". This must be done in
|
|
45
|
+
a server-only execution path within your application.
|
|
46
|
+
|
|
47
|
+
Please see the documentation for more information: https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments
|
|
48
|
+
`)},getIsolateContext=()=>{const e=getIvm();return new e.Isolate({memoryLimit:128}).createContextSync()},runInNode=({code:e,builder:r,context:n,event:t,localState:i,rootSetState:o,rootState:c})=>{const a=getIvm(),v=serverEntry.fastClone({...c,...i}),y=getFunctionArguments({builder:r,context:n,event:t,state:v}),g=getIsolateContext(),u=g.global;u.setSync("global",u.derefInto()),u.setSync("log",function(...s){console.log(...s)}),u.setSync(BUILDER_SET_STATE_NAME,function(s,l){set(c,s,l),o==null||o(c)}),y.forEach(([s,l])=>{const E=typeof l=="object"?new a.Reference(s==="builder"?{...l,getUserAttributes:()=>l.getUserAttributes()}:l):null;u.setSync(getSyncValName(s),E)}),u.setSync(INJECTED_IVM_GLOBAL,a);const p=processCode({code:e,args:y}),d=g.evalSync(p);try{return JSON.parse(d)}catch{return d}};exports.getBuilderGlobals=getBuilderGlobals;exports.getFunctionArguments=getFunctionArguments;exports.parseCode=parseCode;exports.runInNode=runInNode;exports.set=set;exports.setIvm=setIvm;
|