@builder.io/sdk-react 1.0.20 → 1.0.21
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 +1 -1
- package/lib/browser/blocks-exports.mjs +1 -1
- 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-166d8ec9.js} +1 -1
- package/lib/browser/{server-entry-a77461d4.cjs → server-entry-c6e9a10a.cjs} +1 -1
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/{blocks-683aad9f.js → blocks-793a81d9.js} +36 -37
- package/lib/edge/{blocks-523eb4f1.cjs → blocks-c26b2ffc.cjs} +5 -5
- package/lib/edge/blocks-exports.cjs +1 -1
- package/lib/edge/blocks-exports.mjs +2 -2
- package/lib/edge/{button-9f6acf3e.js → button-659db379.js} +2 -2
- package/lib/edge/{button-0d418bcf.cjs → button-f62c1e15.cjs} +1 -1
- package/lib/edge/{columns-b0785992.js → columns-07ef2925.js} +3 -3
- package/lib/edge/{columns-1613d62d.cjs → columns-5fe66f05.cjs} +1 -1
- package/lib/edge/{content-variants-281298f6.cjs → content-variants-9aedb66d.cjs} +1 -1
- package/lib/edge/{content-variants-13f821c6.js → content-variants-fcba4b5b.js} +8 -8
- package/lib/edge/{form-0483aa64.cjs → form-5c293cd8.cjs} +1 -1
- package/lib/edge/{form-db27fc26.js → form-82e6d435.js} +3 -3
- package/lib/edge/{get-class-prop-name-6bfc4756.js → get-class-prop-name-6242df6a.js} +1 -1
- package/lib/edge/{get-class-prop-name-e3ba0522.cjs → get-class-prop-name-c54d7ada.cjs} +1 -1
- package/lib/edge/{img-43a8ffe0.js → img-11c91db6.js} +1 -1
- package/lib/edge/{img-f01d904d.cjs → img-73cc7d69.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-6b8ac645.js} +1 -1
- package/lib/edge/{input-e6483bd7.cjs → input-9c7d1291.cjs} +1 -1
- package/lib/edge/{select-e5d1e627.cjs → select-42de6b22.cjs} +1 -1
- package/lib/edge/{select-4966723f.js → select-f324140d.js} +1 -1
- package/lib/edge/{server-entry-c13e82bd.js → server-entry-396b1a7b.js} +1 -1
- package/lib/edge/{server-entry-83648311.cjs → server-entry-bc7f82dd.cjs} +1 -1
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/edge/{slot-1b0351de.js → slot-4e55a3d1.js} +3 -3
- package/lib/edge/{slot-3ef77ae1.cjs → slot-746347ff.cjs} +1 -1
- package/lib/edge/{symbol-883d624f.cjs → symbol-4b8cffaa.cjs} +1 -1
- package/lib/edge/{symbol-f1632f93.js → symbol-e3905b86.js} +2 -2
- package/lib/node/blocks-exports.cjs +30 -70
- package/lib/node/blocks-exports.mjs +891 -1017
- 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-2a838da2.cjs +48 -0
- package/lib/node/node-runtime-eb3ca94b.js +155 -0
- package/lib/node/{server-entry-8c712c9b.js → server-entry-54c1491b.js} +2 -1
- package/lib/node/{server-entry-bedf45f8.cjs → server-entry-cb0df432.cjs} +2 -2
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +1 -1
- package/package.json +6 -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/helpers/logger.d.ts +1 -0
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-cb0df432.cjs");require("react/jsx-runtime");require("react");require("./node-runtime-2a838da2.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-54c1491b.js";
|
|
3
3
|
import "react/jsx-runtime";
|
|
4
4
|
import "react";
|
|
5
|
+
import "./node-runtime-eb3ca94b.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-2a838da2.cjs");require("./server-entry-cb0df432.cjs");const t=()=>{i.setIvm(e)};exports.initializeNodeRuntime=t;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";const serverEntry=require("./server-entry-cb0df432.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;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { isEditing, isBrowser, getUserAttributes, fastClone, logger, MSG_PREFIX } from "./server-entry-54c1491b.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
|
+
};
|
|
@@ -477,7 +477,7 @@ function H(e, t) {
|
|
|
477
477
|
const n = new URL(t.origin), r = n.hostname;
|
|
478
478
|
return (e || je).findIndex((o) => o.startsWith("*.") ? r.endsWith(o.slice(1)) : o === r) > -1;
|
|
479
479
|
}
|
|
480
|
-
const De = "1.0.
|
|
480
|
+
const De = "1.0.21", T = {};
|
|
481
481
|
function Ke(e, t) {
|
|
482
482
|
let n = T[e];
|
|
483
483
|
if (n || (n = T[e] = []), n.push(t), c()) {
|
|
@@ -657,6 +657,7 @@ const Ye = async (e) => {
|
|
|
657
657
|
};
|
|
658
658
|
};
|
|
659
659
|
export {
|
|
660
|
+
b as MSG_PREFIX,
|
|
660
661
|
v as TARGET,
|
|
661
662
|
Pe as _processContentResult,
|
|
662
663
|
Fe as _track,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const
|
|
2
|
-
For more information, read https://github.com/BuilderIO/this-package-uses-fetch`),new Error("Builder SDK could not find a global `fetch` function");return e}const J=Oe();function v(e,t=null,n="."){return Object.keys(e).reduce((r,o)=>{const s=e[o],a=[t,o].filter(Boolean).join(n);return[typeof s=="object",s!==null,!(Array.isArray(s)&&s.length===0)].every(Boolean)?{...r,...v(s,a,n)}:{...r,[a]:s}},{})}const Te="v3",R="builder.",xe="options.",O=e=>{if(!e)return{};const t=M(e),n={};return Object.keys(t).forEach(r=>{if(r.startsWith(R)){const o=r.replace(R,"").replace(xe,"");n[o]=t[r]}}),n},Ae=()=>{if(!c())return{};const e=new URLSearchParams(window.location.search);return O(e)},B=e=>typeof e=="number"&&!isNaN(e)&&e>=0,T=e=>{const{limit:t=30,userAttributes:n,query:r,model:o,apiKey:s,enrich:a,locale:l,apiVersion:y=Te,fields:m,omit:E,offset:u,cacheSeconds:g,staleCacheSeconds:h,sort:
|
|
1
|
+
"use strict";const I="react",b="[Builder.io]: ",d={log:(...e)=>console.log(b,...e),error:(...e)=>console.error(b,...e),warn:(...e)=>console.warn(b,...e),debug:(...e)=>console.debug(b,...e)};function c(){return typeof window!="undefined"&&typeof document!="undefined"}const ce=e=>{const t={};return e.forEach((n,r)=>{t[r]=n}),t},M=e=>e instanceof URLSearchParams?ce(e):e,F=e=>typeof e=="string"?e:e instanceof URLSearchParams?e.toString():new URLSearchParams(e).toString();function ue(){return c()&&window.self!==window.top}function k(e){return ue()&&F(e||window.location.search).indexOf("builder.frameEditing=")!==-1}const de=()=>{if(c()){const e=new URL(location.href);return e.pathname===""&&(e.pathname="/"),e}else return console.warn("Cannot get location for tracking in non-browser environment"),null},le=()=>typeof navigator=="object"&&navigator.userAgent||"",N=()=>{const e=le(),t={Android(){return e.match(/Android/i)},BlackBerry(){return e.match(/BlackBerry/i)},iOS(){return e.match(/iPhone|iPod/i)},Opera(){return e.match(/Opera Mini/i)},Windows(){return e.match(/IEMobile/i)||e.match(/WPDesktop/i)},any(){return t.Android()||t.BlackBerry()||t.iOS()||t.Opera()||t.Windows()||I==="reactNative"}},n=e.match(/Tablet|iPad/i),r=de();return{urlPath:r==null?void 0:r.pathname,host:(r==null?void 0:r.host)||(r==null?void 0:r.hostname),device:n?"tablet":t.any()?"mobile":"desktop"}},C=e=>JSON.parse(JSON.stringify(e)),p=e=>e!=null,fe=e=>{if(e==="localhost"||e==="127.0.0.1")return e;const t=e.split(".");return t.length>2?t.slice(1).join("."):e},D=({name:e,canTrack:t})=>{var n;try{return t?(n=document.cookie.split("; ").find(r=>r.startsWith(`${e}=`)))==null?void 0:n.split("=")[1]:void 0}catch(r){d.warn("[COOKIE] GET error: ",(r==null?void 0:r.message)||r);return}},_=async e=>D(e),ge=e=>e.map(([t,n])=>n?`${t}=${n}`:t).filter(p).join("; "),he=[["secure",""],["SameSite","None"]],pe=({name:e,value:t,expires:n})=>{const o=(c()?location.protocol==="https:":!0)?he:[[]],s=n?[["expires",n.toUTCString()]]:[[]],a=[[e,t],...s,["path","/"],["domain",fe(window.location.hostname)],...o];return ge(a)},j=async({name:e,value:t,expires:n,canTrack:r})=>{try{if(!r)return;const o=pe({name:e,value:t,expires:n});document.cookie=o}catch(o){d.warn("[COOKIE] SET error: ",(o==null?void 0:o.message)||o)}},me="builder.tests",P=e=>`${me}.${e}`,ye=({contentId:e})=>_({name:P(e),canTrack:!0}),Se=({contentId:e})=>D({name:P(e),canTrack:!0}),we=({contentId:e,value:t})=>j({name:P(e),value:t,canTrack:!0}),K=e=>p(e.id)&&p(e.variations)&&Object.keys(e.variations).length>0,be=({id:e,variations:t})=>{var o;let n=0;const r=Math.random();for(const s in t){const a=(o=t[s])==null?void 0:o.testRatio;if(n+=a,r<n)return s}return e},G=e=>{const t=be(e);return we({contentId:e.id,value:t}).catch(n=>{d.error("could not store A/B test variation: ",n)}),t},W=({item:e,testGroupId:t})=>{const n=e.variations[t];return t===e.id||!n?{testVariationId:e.id,testVariationName:"Default"}:{data:n.data,testVariationId:n.id,testVariationName:n.name||(n.id===e.id?"Default":"")}},Ie=({item:e,canTrack:t})=>{if(!t)return e;if(!e)return;if(!K(e))return e;const n=Se({contentId:e.id})||G({variations:e.variations,id:e.id}),r=W({item:e,testGroupId:n});return{...e,...r}},ve=async({item:e,canTrack:t})=>{if(!t||!K(e))return e;const r=await ye({contentId:e.id})||G({variations:e.variations,id:e.id}),o=W({item:e,testGroupId:r});return{...e,...o}},$=e=>p(e)?e:!0,Ee=e=>({type:"builder.registerComponent",data:z(e)}),ke=e=>{const t=e.toString().trim();return`return (${!t.startsWith("function")&&!t.startsWith("(")?"function ":""}${t}).apply(this, arguments)`},Ce=e=>typeof e=="function"?ke(e):C(e),z=({inputs:e,...t})=>({...C(t),inputs:e==null?void 0:e.map(n=>Object.entries(n).reduce((r,[o,s])=>({...r,[o]:Ce(s)}),{}))});function Pe(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function Oe(){const e=Pe().fetch;if(typeof e=="undefined")throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
|
|
2
|
+
For more information, read https://github.com/BuilderIO/this-package-uses-fetch`),new Error("Builder SDK could not find a global `fetch` function");return e}const J=Oe();function v(e,t=null,n="."){return Object.keys(e).reduce((r,o)=>{const s=e[o],a=[t,o].filter(Boolean).join(n);return[typeof s=="object",s!==null,!(Array.isArray(s)&&s.length===0)].every(Boolean)?{...r,...v(s,a,n)}:{...r,[a]:s}},{})}const Te="v3",R="builder.",xe="options.",O=e=>{if(!e)return{};const t=M(e),n={};return Object.keys(t).forEach(r=>{if(r.startsWith(R)){const o=r.replace(R,"").replace(xe,"");n[o]=t[r]}}),n},Ae=()=>{if(!c())return{};const e=new URLSearchParams(window.location.search);return O(e)},B=e=>typeof e=="number"&&!isNaN(e)&&e>=0,T=e=>{const{limit:t=30,userAttributes:n,query:r,model:o,apiKey:s,enrich:a,locale:l,apiVersion:y=Te,fields:m,omit:E,offset:u,cacheSeconds:g,staleCacheSeconds:h,sort:S,includeUnpublished:x}=e;if(!s)throw new Error("Missing API key");if(!["v3"].includes(y))throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);const ie=t!==1,i=new URL(`https://cdn.builder.io/api/${y}/content/${o}`);if(i.searchParams.set("apiKey",s),i.searchParams.set("limit",String(t)),i.searchParams.set("noTraverse",String(ie)),i.searchParams.set("includeRefs",String(!0)),l&&i.searchParams.set("locale",l),a&&i.searchParams.set("enrich",String(a)),i.searchParams.set("omit",E||"meta.componentsUsed"),m&&i.searchParams.set("fields",m),Number.isFinite(u)&&u>-1&&i.searchParams.set("offset",String(Math.floor(u))),typeof x=="boolean"&&i.searchParams.set("includeUnpublished",String(x)),g&&B(g)&&i.searchParams.set("cacheSeconds",String(g)),h&&B(h)&&i.searchParams.set("staleCacheSeconds",String(h)),S){const f=v({sort:S});for(const w in f)i.searchParams.set(w,JSON.stringify(f[w]))}const ae={...Ae(),...M(e.options||{})},A=v(ae);for(const f in A)i.searchParams.set(f,String(A[f]));if(n&&i.searchParams.set("userAttributes",JSON.stringify(n)),r){const f=v({query:r});for(const w in f)i.searchParams.set(w,JSON.stringify(f[w]))}return i},Re=e=>"results"in e;async function H(e){const t=await q({...e,limit:1});return t&&t[0]||null}const Be=async e=>{var s;const t=T(e);return await(await((s=e.fetch)!=null?s:J)(t.href,e.fetchOptions)).json()},X=async(e,t,n=T(e))=>{const r=$(e.canTrack);if(n.search.includes("preview="),!r||!(c()||I==="reactNative"))return t.results;try{const o=[];for(const s of t.results)o.push(await ve({item:s,canTrack:r}));t.results=o}catch(o){d.error("Could not process A/B tests. ",o)}return t.results};async function q(e){try{const t=T(e),n=await Be(e);return Re(n)?X(e,n):(d.error("Error fetching data. ",{url:t,content:n,options:e}),null)}catch(t){return d.error("Error fetching data. ",t),null}}function Le(e){if(!c())return!1;const t=F(e||window.location.search);return k(t)?!1:t.indexOf("builder.preview=")!==-1}function Ve(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){const t=Math.random()*16|0;return(e=="x"?t:t&3|8).toString(16)})}function Y(){return Ve().replace(/-/g,"")}const Q="builderSessionId",Ue=async({canTrack:e})=>{if(!e)return;const t=await _({name:Q,canTrack:e});if(p(t))return t;{const n=Me();return Fe({id:n,canTrack:e}),n}},Me=()=>Y(),Fe=({id:e,canTrack:t})=>j({name:Q,value:e,canTrack:t}),Z=()=>c()&&typeof localStorage!="undefined"?localStorage:void 0,Ne=({key:e,canTrack:t})=>{var n;try{return t?(n=Z())==null?void 0:n.getItem(e):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},De=({key:e,canTrack:t,value:n})=>{var r;try{t&&((r=Z())==null||r.setItem(e,n))}catch(o){console.debug("[LocalStorage] SET error: ",o)}},ee="builderVisitorId",_e=({canTrack:e})=>{if(!e)return;const t=Ne({key:ee,canTrack:e});if(p(t))return t;{const n=je();return Ke({id:n,canTrack:e}),n}},je=()=>Y(),Ke=({id:e,canTrack:t})=>De({key:ee,value:e,canTrack:t}),Ge=async({canTrack:e})=>{if(!e)return{visitorId:void 0,sessionId:void 0};const t=await Ue({canTrack:e}),n=_e({canTrack:e});return{sessionId:t,visitorId:n}},We=async({type:e,canTrack:t,apiKey:n,metadata:r,...o})=>({type:e,data:{...o,metadata:{url:location.href,...r},...await Ge({canTrack:t}),userAttributes:N(),ownerId:n}});async function te(e){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(e.canTrack&&!k()&&(c()||I==="reactNative"))return fetch("https://cdn.builder.io/api/v1/track",{method:"POST",body:JSON.stringify({events:[await We(e)]}),headers:{"content-type":"application/json"},mode:"cors"}).catch(t=>{console.error("Failed to track: ",t)})}const $e=e=>te({...e,canTrack:!0}),ze=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function ne(e,t){const n=new URL(t.origin),r=n.hostname;return(e||ze).findIndex(o=>o.startsWith("*.")?r.endsWith(o.slice(1)):o===r)>-1}const Je="1.0.21",L={};function re(e,t){let n=L[e];if(n||(n=L[e]=[]),n.push(t),c()){const r={type:"builder.register",data:{type:e,info:t}};try{parent.postMessage(r,"*"),parent!==window&&window.postMessage(r,"*")}catch(o){console.debug("Could not postmessage",o)}}}const He=()=>{re("insertMenu",{name:"_default",default:!0,items:[{name:"Box"},{name:"Text"},{name:"Image"},{name:"Columns"},{name:"Core:Section"},{name:"Core:Button"},{name:"Embed"},{name:"Custom Code"}]})};let V=!1;const oe=(e={})=>{var t,n;V||(V=!0,c()&&((t=window.parent)==null||t.postMessage({type:"builder.sdkInfo",data:{target:I,version:Je,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0}},"*"),(n=window.parent)==null||n.postMessage({type:"builder.updateContent",data:{options:e}},"*"),window.addEventListener("message",r=>{var s,a;if(!ne(e.trustedHosts,r))return;const{data:o}=r;if(o!=null&&o.type)switch(o.type){case"builder.evaluate":{const l=o.data.text,y=o.data.arguments||[],m=o.data.id,E=new Function(l);let u,g=null;try{u=E.apply(null,y)}catch(h){g=h}g?(s=window.parent)==null||s.postMessage({type:"builder.evaluateError",data:{id:m,error:g.message}},"*"):u&&typeof u.then=="function"?u.then(h=>{var S;(S=window.parent)==null||S.postMessage({type:"builder.evaluateResult",data:{id:m,result:h}},"*")}).catch(console.error):(a=window.parent)==null||a.postMessage({type:"builder.evaluateResult",data:{result:u,id:m}},"*");break}}})))},se=({model:e,trustedHosts:t,callbacks:n})=>r=>{if(!ne(t,r))return;const{data:o}=r;if(o)switch(o.type){case"builder.configureSdk":{n.configureSdk(o.data);break}case"builder.triggerAnimation":{n.animation(o.data);break}case"builder.contentUpdate":{const s=o.data,a=s.key||s.alias||s.entry||s.modelName,l=s.data;a===e&&n.contentUpdate(l);break}}},Xe=(e,t,n)=>{if(!c)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};oe();const r=se({callbacks:{contentUpdate:t,animation:()=>{},configureSdk:()=>{}},model:e,trustedHosts:n==null?void 0:n.trustedHosts});return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},U={};function qe(e){if(c()){Object.assign(U,e);const t={type:"builder.settingsChange",data:U};parent.postMessage(t,"*")}}const Ye=async e=>{var r,o,s;const t=e.path||((r=e.url)==null?void 0:r.pathname)||((o=e.userAttributes)==null?void 0:o.urlPath),n={...e,apiKey:e.apiKey,model:e.model||"page",userAttributes:{...e.userAttributes,...t?{urlPath:t}:{}},options:O(e.searchParams||((s=e.url)==null?void 0:s.searchParams)||e.options)};return{apiKey:n.apiKey,model:n.model,content:await H(n)}};exports.MSG_PREFIX=b;exports.TARGET=I;exports._processContentResult=X;exports._track=te;exports.checkIsDefined=p;exports.createEditorListener=se;exports.createRegisterComponentMessage=Ee;exports.fastClone=C;exports.fetch=J;exports.fetchBuilderProps=Ye;exports.fetchEntries=q;exports.fetchOneEntry=H;exports.getBuilderSearchParams=O;exports.getDefaultCanTrack=$;exports.getUserAttributes=N;exports.handleABTestingSync=Ie;exports.isBrowser=c;exports.isEditing=k;exports.isPreviewing=Le;exports.logger=d;exports.register=re;exports.registerInsertMenu=He;exports.serializeComponentInfo=z;exports.setEditorSettings=qe;exports.setupBrowserForEditing=oe;exports.subscribeToEditor=Xe;exports.track=$e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./server-entry-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./server-entry-cb0df432.cjs");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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _processContentResult as r, createRegisterComponentMessage as s, fetchBuilderProps as i, fetchEntries as n, fetchOneEntry as o, getBuilderSearchParams as c, isEditing as g, isPreviewing as a, register as d, setEditorSettings as E, subscribeToEditor as f, track as h } from "./server-entry-
|
|
1
|
+
import { _processContentResult as r, createRegisterComponentMessage as s, fetchBuilderProps as i, fetchEntries as n, fetchOneEntry as o, getBuilderSearchParams as c, isEditing as g, isPreviewing as a, register as d, setEditorSettings as E, subscribeToEditor as f, track as h } from "./server-entry-54c1491b.js";
|
|
2
2
|
export {
|
|
3
3
|
r as _processContentResult,
|
|
4
4
|
s as createRegisterComponentMessage,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-react",
|
|
3
3
|
"description": "Builder.io SDK for React",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.21",
|
|
5
5
|
"homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/react",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|
|
@@ -79,6 +79,11 @@
|
|
|
79
79
|
"require": "./lib/browser/index.cjs"
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
|
+
"./node/init": {
|
|
83
|
+
"types": "./types/functions/evaluate/node-runtime/init.d.ts",
|
|
84
|
+
"import": "./lib/node/init.mjs",
|
|
85
|
+
"require": "./lib/node/init.cjs"
|
|
86
|
+
},
|
|
82
87
|
"./edge": {
|
|
83
88
|
"types": "./types/index.d.ts",
|
|
84
89
|
"import": "./lib/edge/edge-entry.mjs",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.21";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function initializes the SDK on a Node server. It handles importing the
|
|
3
|
+
* `isolated-vm` package which is needed for dynamic bindings.
|
|
4
|
+
*
|
|
5
|
+
* NOTE: this function cannot be called on the client. You must call this function
|
|
6
|
+
* from a server-only location, such as:
|
|
7
|
+
* - The NextJS Pages router's `_document.tsx`
|
|
8
|
+
* - Your Remix route's `loader`
|
|
9
|
+
*/
|
|
10
|
+
export declare const initializeNodeRuntime: () => void;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import type { ExecutorArgs } from '../helpers';
|
|
2
|
+
/**
|
|
3
|
+
* Set the `isolated-vm` instance to be used by the node runtime.
|
|
4
|
+
* This is useful for environments that are not able to rely on our
|
|
5
|
+
* `safeDynamicRequire` trick to import the `isolated-vm` package.
|
|
6
|
+
*/
|
|
7
|
+
export declare const setIvm: (ivm: typeof import('isolated-vm')) => void;
|
|
2
8
|
export declare const runInNode: ({ code, builder, context, event, localState, rootSetState, rootState }: ExecutorArgs) => any;
|
|
@@ -131,9 +131,9 @@ export interface GetContentOptions {
|
|
|
131
131
|
/**
|
|
132
132
|
* Optional override of the `fetch` function. (Defaults to global `fetch`)
|
|
133
133
|
*/
|
|
134
|
-
fetch?:
|
|
134
|
+
fetch?: (input: string, init?: object) => Promise<any>;
|
|
135
135
|
/**
|
|
136
|
-
* Optional fetch options to be passed to the `fetch` function.
|
|
136
|
+
* Optional fetch options to be passed as the second argument to the `fetch` function.
|
|
137
137
|
*/
|
|
138
|
-
fetchOptions?:
|
|
138
|
+
fetchOptions?: object;
|
|
139
139
|
}
|