@builder.io/sdk-react-nextjs 0.23.2 → 0.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/lib/browser/components/block/components/block-wrapper.cjs +1 -1
  2. package/lib/browser/components/block/components/block-wrapper.mjs +16 -9
  3. package/lib/browser/components/block/components/interactive-element.cjs +1 -1
  4. package/lib/browser/components/block/components/interactive-element.mjs +28 -21
  5. package/lib/browser/constants/sdk-version.cjs +1 -1
  6. package/lib/browser/constants/sdk-version.mjs +1 -1
  7. package/lib/browser/functions/evaluate/evaluate.cjs +1 -1
  8. package/lib/browser/functions/evaluate/evaluate.mjs +18 -17
  9. package/lib/browser/functions/evaluate/helpers.cjs +1 -1
  10. package/lib/browser/functions/evaluate/helpers.mjs +52 -35
  11. package/lib/browser/functions/get-block-actions-handler.cjs +1 -1
  12. package/lib/browser/functions/get-block-actions-handler.mjs +4 -3
  13. package/lib/browser/init.cjs +1 -1
  14. package/lib/browser/init.mjs +7 -12
  15. package/lib/edge/components/block/components/block-wrapper.cjs +1 -1
  16. package/lib/edge/components/block/components/block-wrapper.mjs +16 -9
  17. package/lib/edge/components/block/components/interactive-element.cjs +1 -1
  18. package/lib/edge/components/block/components/interactive-element.mjs +28 -21
  19. package/lib/edge/constants/sdk-version.cjs +1 -1
  20. package/lib/edge/constants/sdk-version.mjs +1 -1
  21. package/lib/edge/functions/evaluate/evaluate.cjs +1 -1
  22. package/lib/edge/functions/evaluate/evaluate.mjs +18 -17
  23. package/lib/edge/functions/evaluate/helpers.cjs +1 -1
  24. package/lib/edge/functions/evaluate/helpers.mjs +52 -35
  25. package/lib/edge/functions/get-block-actions-handler.cjs +1 -1
  26. package/lib/edge/functions/get-block-actions-handler.mjs +4 -3
  27. package/lib/edge/init.cjs +1 -1
  28. package/lib/edge/init.mjs +7 -12
  29. package/lib/node/components/block/components/block-wrapper.cjs +1 -1
  30. package/lib/node/components/block/components/block-wrapper.mjs +16 -9
  31. package/lib/node/components/block/components/interactive-element.cjs +1 -1
  32. package/lib/node/components/block/components/interactive-element.mjs +28 -21
  33. package/lib/node/constants/sdk-version.cjs +1 -1
  34. package/lib/node/constants/sdk-version.mjs +1 -1
  35. package/lib/node/functions/evaluate/evaluate.cjs +1 -1
  36. package/lib/node/functions/evaluate/evaluate.mjs +18 -17
  37. package/lib/node/functions/evaluate/helpers.cjs +1 -1
  38. package/lib/node/functions/evaluate/helpers.mjs +52 -35
  39. package/lib/node/functions/evaluate/node-runtime/node-runtime.cjs +7 -7
  40. package/lib/node/functions/evaluate/node-runtime/node-runtime.mjs +83 -77
  41. package/lib/node/functions/get-block-actions-handler.cjs +1 -1
  42. package/lib/node/functions/get-block-actions-handler.mjs +4 -3
  43. package/package.json +1 -1
  44. package/types/cjs/constants/sdk-version.d.ts +1 -1
  45. package/types/cjs/functions/evaluate/evaluate.d.ts +1 -1
  46. package/types/cjs/functions/evaluate/helpers.d.ts +9 -1
  47. package/types/cjs/functions/get-block-actions-handler.d.ts +2 -0
  48. package/types/cjs/functions/get-block-actions.d.ts +2 -0
  49. package/types/esm/constants/sdk-version.d.ts +1 -1
  50. package/types/esm/functions/evaluate/evaluate.d.ts +1 -1
  51. package/types/esm/functions/evaluate/helpers.d.ts +9 -1
  52. package/types/esm/functions/get-block-actions-handler.d.ts +2 -0
  53. package/types/esm/functions/get-block-actions.d.ts +2 -0
  54. package/lib/browser/constants/sdk-name.cjs +0 -1
  55. package/lib/browser/constants/sdk-name.mjs +0 -14
  56. package/lib/browser/functions/evaluate/node-runtime/node-runtime.cjs +0 -8
  57. package/lib/browser/functions/evaluate/node-runtime/node-runtime.mjs +0 -40
  58. package/lib/edge/constants/sdk-name.cjs +0 -1
  59. package/lib/edge/constants/sdk-name.mjs +0 -14
  60. package/lib/edge/functions/evaluate/node-runtime/node-runtime.cjs +0 -8
  61. package/lib/edge/functions/evaluate/node-runtime/node-runtime.mjs +0 -40
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../../constants/sdk-name.cjs"),m=require("../../../helpers/logger.cjs"),A=require("../../fast-clone.cjs"),R=require("../../set.cjs"),M=require("../helpers.cjs"),k=require("./safeDynamicRequire.cjs"),g=t=>`bldr_${t}_sync`,b="BUILDER_SET_STATE",I="BUILDER_IVM",h=`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../../../constants/sdk-name.cjs"),m=require("../../../helpers/logger.cjs"),j=require("../../fast-clone.cjs"),A=require("../../set.cjs"),R=require("../helpers.cjs"),M=require("./safeDynamicRequire.cjs"),S=t=>`bldr_${t}_sync`,b="BUILDER_SET_STATE",g="BUILDER_IVM",h=`
2
2
  var refToProxy = (obj) => {
3
3
  if (typeof obj !== 'object' || obj === null) {
4
4
  return obj;
@@ -15,7 +15,7 @@ var refToProxy = (obj) => {
15
15
  return val;
16
16
  },
17
17
  set(target, key, value) {
18
- const v = typeof value === 'object' ? new ${I}.Reference(value) : value;
18
+ const v = typeof value === 'object' ? new ${g}.Reference(value) : value;
19
19
  obj.setSync(key, v);
20
20
  ${b}(key, value)
21
21
  },
@@ -24,9 +24,9 @@ var refToProxy = (obj) => {
24
24
  }
25
25
  })
26
26
  }
27
- `,x=({code:t,args:e})=>{const u=e.map(([o])=>`var ${o} = refToProxy(${g(o)}); `).join("");return`
27
+ `,k=({code:t,args:e})=>{const l=e.map(([s])=>`var ${s} = refToProxy(${S(s)}); `).join("");return`
28
28
  ${h}
29
- ${u}
29
+ ${l}
30
30
  function theFunction() {
31
31
  ${t}
32
32
  }
@@ -38,11 +38,11 @@ if (typeof output === 'object' && output !== null) {
38
38
  } else {
39
39
  return output;
40
40
  }
41
- `};let l=null,y=null;const C=(t,e={})=>{l||(l=t,E(e))},D=c.SDK_NAME==="@builder.io/sdk-react-nextjs"||c.SDK_NAME==="@builder.io/sdk-react"||c.SDK_NAME==="@builder.io/sdk-qwik"||c.SDK_NAME==="@builder.io/sdk-vue",S=()=>{try{if(l)return l;const e=k.safeDynamicRequire("isolated-vm");if(e)return e}catch(e){m.logger.error("isolated-vm import error.",e)}const t=`${m.MSG_PREFIX}could not import \`isolated-vm\` module for safe script execution on a Node server.
41
+ `};let u=null,I={memoryLimit:128};const O=(t,e)=>{u||(u=t,e&&(I=e))},D=i.SDK_NAME==="@builder.io/sdk-react-nextjs"||i.SDK_NAME==="@builder.io/sdk-react"||i.SDK_NAME==="@builder.io/sdk-qwik"||i.SDK_NAME==="@builder.io/sdk-vue",w=()=>{try{if(u)return u;const e=M.safeDynamicRequire("isolated-vm");if(e)return e}catch(e){m.logger.error("isolated-vm import error.",e)}const t=`${m.MSG_PREFIX}could not import \`isolated-vm\` module for safe script execution on a Node server.
42
42
 
43
43
  SOLUTION: In a server-only execution path within your application, do one of the following:
44
44
 
45
- ${D?`- import and call \`initializeNodeRuntime()\` from "${c.SDK_NAME}/node/init".`:""}
45
+ ${D?`- import and call \`initializeNodeRuntime()\` from "${i.SDK_NAME}/node/init".`:""}
46
46
  - add the following import: \`await import('isolated-vm')\`.
47
47
 
48
- For more information, visit https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments`;throw new Error(t)};function E(t={memoryLimit:128}){if(y)return y;const e=S(),o=new e.Isolate(t).createContextSync(),n=o.global;return n.setSync("global",n.derefInto()),n.setSync("log",function(...i){console.log(...i)}),n.setSync(I,e),y=o,o}const O=()=>E(),w=({code:t,builder:e,context:u,event:o,localState:n,rootSetState:i,rootState:a})=>{const _=S(),N=A.fastClone({...a,...n}),d=M.getFunctionArguments({builder:e,context:u,event:o,state:N}),f=O(),p=f.global;p.setSync(b,function(r,s){R.set(a,r,s),i==null||i(a)}),d.forEach(([r,s])=>{const j=typeof s=="object"?new _.Reference(r==="builder"?{...s,getUserAttributes:()=>s.getUserAttributes()}:s):null;p.setSync(g(r),j)});const T=x({code:t,args:d}),v=f.evalClosureSync(T);try{return JSON.parse(v)}catch{return v}};exports.runInNode=w;exports.setIvm=C;
48
+ For more information, visit https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments`;throw new Error(t)},$=({code:t,builder:e,context:l,event:s,localState:_,rootSetState:a,rootState:y})=>{const d=w();let c;try{c=new d.Isolate(I);const f=c.createContextSync(),n=f.global;n.setSync("global",n.derefInto()),n.setSync("log",function(...o){console.log(...o)}),n.setSync(g,d);const E=j.fastClone({...y,..._}),p=R.getFunctionArguments({builder:e,context:l,event:s,state:E});n.setSync(b,function(o,r){A.set(y,o,r),a==null||a(y)}),p.forEach(([o,r])=>{const T=typeof r=="object"?new d.Reference(o==="builder"?{...r,getUserAttributes:()=>r.getUserAttributes()}:r):null;n.setSync(S(o),T)});const N=k({code:t,args:p}),v=f.evalClosureSync(N);try{return JSON.parse(v)}catch{return v}}finally{if(c)try{c.dispose()}catch{}}};exports.runInNode=$;exports.setIvm=O;
@@ -1,10 +1,10 @@
1
- import { SDK_NAME as c } from "../../../constants/sdk-name.mjs";
2
- import { logger as j, MSG_PREFIX as R } from "../../../helpers/logger.mjs";
3
- import { fastClone as x } from "../../fast-clone.mjs";
4
- import { set as k } from "../../set.mjs";
5
- import { getFunctionArguments as A } from "../helpers.mjs";
6
- import { safeDynamicRequire as h } from "./safeDynamicRequire.mjs";
7
- const v = (e) => `bldr_${e}_sync`, b = "BUILDER_SET_STATE", I = "BUILDER_IVM", w = `
1
+ import { SDK_NAME as i } from "../../../constants/sdk-name.mjs";
2
+ import { logger as T, MSG_PREFIX as j } from "../../../helpers/logger.mjs";
3
+ import { fastClone as R } from "../../fast-clone.mjs";
4
+ import { set as h } from "../../set.mjs";
5
+ import { getFunctionArguments as k } from "../helpers.mjs";
6
+ import { safeDynamicRequire as A } from "./safeDynamicRequire.mjs";
7
+ const v = (t) => `bldr_${t}_sync`, b = "BUILDER_SET_STATE", I = "BUILDER_IVM", O = `
8
8
  var refToProxy = (obj) => {
9
9
  if (typeof obj !== 'object' || obj === null) {
10
10
  return obj;
@@ -30,16 +30,16 @@ var refToProxy = (obj) => {
30
30
  }
31
31
  })
32
32
  }
33
- `, C = ({
34
- code: e,
35
- args: t
33
+ `, w = ({
34
+ code: t,
35
+ args: e
36
36
  }) => {
37
- const l = t.map(([o]) => `var ${o} = refToProxy(${v(o)}); `).join("");
37
+ const u = e.map(([c]) => `var ${c} = refToProxy(${v(c)}); `).join("");
38
38
  return `
39
- ${w}
40
- ${l}
39
+ ${O}
40
+ ${u}
41
41
  function theFunction() {
42
- ${e}
42
+ ${t}
43
43
  }
44
44
 
45
45
  const output = theFunction()
@@ -51,80 +51,86 @@ if (typeof output === 'object' && output !== null) {
51
51
  }
52
52
  `;
53
53
  };
54
- let u = null, y = null;
55
- const V = (e, t = {}) => {
56
- u || (u = e, E(t));
57
- }, O = c === "@builder.io/sdk-react-nextjs" || c === "@builder.io/sdk-react" || c === "@builder.io/sdk-qwik" || c === "@builder.io/sdk-vue", g = () => {
54
+ let l = null, g = {
55
+ memoryLimit: 128
56
+ };
57
+ const U = (t, e) => {
58
+ l || (l = t, e && (g = e));
59
+ }, $ = i === "@builder.io/sdk-react-nextjs" || i === "@builder.io/sdk-react" || i === "@builder.io/sdk-qwik" || i === "@builder.io/sdk-vue", x = () => {
58
60
  try {
59
- if (u)
60
- return u;
61
- const t = h("isolated-vm");
62
- if (t)
63
- return t;
64
- } catch (t) {
65
- j.error("isolated-vm import error.", t);
61
+ if (l)
62
+ return l;
63
+ const e = A("isolated-vm");
64
+ if (e)
65
+ return e;
66
+ } catch (e) {
67
+ T.error("isolated-vm import error.", e);
66
68
  }
67
- const e = `${R}could not import \`isolated-vm\` module for safe script execution on a Node server.
69
+ const t = `${j}could not import \`isolated-vm\` module for safe script execution on a Node server.
68
70
 
69
71
  SOLUTION: In a server-only execution path within your application, do one of the following:
70
72
 
71
- ${O ? `- import and call \`initializeNodeRuntime()\` from "${c}/node/init".` : ""}
73
+ ${$ ? `- import and call \`initializeNodeRuntime()\` from "${i}/node/init".` : ""}
72
74
  - add the following import: \`await import('isolated-vm')\`.
73
75
 
74
76
  For more information, visit https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments`;
75
- throw new Error(e);
76
- };
77
- function E(e = {
78
- memoryLimit: 128
79
- }) {
80
- if (y)
81
- return y;
82
- const t = g(), o = new t.Isolate(e).createContextSync(), n = o.global;
83
- return n.setSync("global", n.derefInto()), n.setSync("log", function(...s) {
84
- console.log(...s);
85
- }), n.setSync(I, t), y = o, o;
86
- }
87
- const $ = () => E(), B = ({
88
- code: e,
89
- builder: t,
90
- context: l,
91
- event: o,
92
- localState: n,
93
- rootSetState: s,
94
- rootState: a
77
+ throw new Error(t);
78
+ }, V = ({
79
+ code: t,
80
+ builder: e,
81
+ context: u,
82
+ event: c,
83
+ localState: S,
84
+ rootSetState: a,
85
+ rootState: y
95
86
  }) => {
96
- const S = g(), _ = x({
97
- ...a,
98
- ...n
99
- }), f = A({
100
- builder: t,
101
- context: l,
102
- event: o,
103
- state: _
104
- }), m = $(), p = m.global;
105
- p.setSync(b, function(r, i) {
106
- k(a, r, i), s == null || s(a);
107
- }), f.forEach(([r, i]) => {
108
- const N = typeof i == "object" ? new S.Reference(
109
- // workaround: methods with default values for arguments is not being cloned over
110
- r === "builder" ? {
111
- ...i,
112
- getUserAttributes: () => i.getUserAttributes()
113
- } : i
114
- ) : null;
115
- p.setSync(v(r), N);
116
- });
117
- const T = C({
118
- code: e,
119
- args: f
120
- }), d = m.evalClosureSync(T);
87
+ const f = x();
88
+ let s;
121
89
  try {
122
- return JSON.parse(d);
123
- } catch {
124
- return d;
90
+ s = new f.Isolate(g);
91
+ const p = s.createContextSync(), n = p.global;
92
+ n.setSync("global", n.derefInto()), n.setSync("log", function(...o) {
93
+ console.log(...o);
94
+ }), n.setSync(I, f);
95
+ const _ = R({
96
+ ...y,
97
+ ...S
98
+ }), m = k({
99
+ builder: e,
100
+ context: u,
101
+ event: c,
102
+ state: _
103
+ });
104
+ n.setSync(b, function(o, r) {
105
+ h(y, o, r), a == null || a(y);
106
+ }), m.forEach(([o, r]) => {
107
+ const N = typeof r == "object" ? new f.Reference(
108
+ // workaround: methods with default values for arguments is not being cloned over
109
+ o === "builder" ? {
110
+ ...r,
111
+ getUserAttributes: () => r.getUserAttributes()
112
+ } : r
113
+ ) : null;
114
+ n.setSync(v(o), N);
115
+ });
116
+ const E = w({
117
+ code: t,
118
+ args: m
119
+ }), d = p.evalClosureSync(E);
120
+ try {
121
+ return JSON.parse(d);
122
+ } catch {
123
+ return d;
124
+ }
125
+ } finally {
126
+ if (s)
127
+ try {
128
+ s.dispose();
129
+ } catch {
130
+ }
125
131
  }
126
132
  };
127
133
  export {
128
- B as runInNode,
129
- V as setIvm
134
+ V as runInNode,
135
+ U as setIvm
130
136
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./evaluate/evaluate.cjs"),o=(t,e)=>a=>r.evaluate({code:t,context:e.context,localState:e.localState,rootState:e.rootState,rootSetState:e.rootSetState,event:a,isExpression:!1});exports.createEventHandler=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./evaluate/evaluate.cjs"),o=(e,t)=>a=>r.evaluate({code:e,context:t.context,localState:t.localState,rootState:t.rootState,rootSetState:t.rootSetState,event:a,isExpression:!1,trackingContext:t.trackingContext});exports.createEventHandler=o;
@@ -1,13 +1,14 @@
1
1
  import { evaluate as o } from "./evaluate/evaluate.mjs";
2
- const S = (e, t) => (a) => o({
2
+ const c = (e, t) => (a) => o({
3
3
  code: e,
4
4
  context: t.context,
5
5
  localState: t.localState,
6
6
  rootState: t.rootState,
7
7
  rootSetState: t.rootSetState,
8
8
  event: a,
9
- isExpression: !1
9
+ isExpression: !1,
10
+ trackingContext: t.trackingContext
10
11
  });
11
12
  export {
12
- S as createEventHandler
13
+ c as createEventHandler
13
14
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-react-nextjs",
3
3
  "description": "Builder.io RSC SDK for NextJS App Directory",
4
- "version": "0.23.2",
4
+ "version": "0.24.1",
5
5
  "homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/nextjs",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.23.2";
1
+ export declare const SDK_VERSION = "0.24.1";
@@ -1,5 +1,5 @@
1
1
  import type { EvaluatorArgs } from './helpers.js';
2
2
  type EvalValue = unknown;
3
3
  export declare const getSimpleExpressionGetPath: (code: string) => string;
4
- export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression }: EvaluatorArgs): EvalValue;
4
+ export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression, trackingContext }: EvaluatorArgs): EvalValue;
5
5
  export {};
@@ -1,14 +1,22 @@
1
1
  import type { BuilderContextInterface, BuilderRenderState } from '../../context/types.js';
2
2
  import { getUserAttributes } from '../track/helpers.js';
3
+ export type TrackingContext = {
4
+ apiKey: string | null;
5
+ canTrack?: boolean;
6
+ contentId?: string;
7
+ variationId?: string;
8
+ };
3
9
  export type EvaluatorArgs = Omit<ExecutorArgs, 'builder' | 'event'> & {
4
10
  event?: Event;
5
11
  isExpression?: boolean;
12
+ trackingContext?: TrackingContext;
6
13
  };
7
14
  export type BuilderGlobals = {
8
15
  isEditing: boolean | undefined;
9
16
  isBrowser: boolean | undefined;
10
17
  isServer: boolean | undefined;
11
18
  getUserAttributes: typeof getUserAttributes;
19
+ trackConversion: (amount?: number, customProperties?: Record<string, any>) => void;
12
20
  };
13
21
  export type ExecutorArgs = Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'> & {
14
22
  code: string;
@@ -20,7 +28,7 @@ export type FunctionArguments = ReturnType<typeof getFunctionArguments>;
20
28
  export declare const getFunctionArguments: ({ builder, context, event, state }: Pick<ExecutorArgs, "context" | "builder" | "event"> & {
21
29
  state: BuilderRenderState;
22
30
  }) => [string, Event | BuilderRenderState | import("../../context/types.js").BuilderRenderContext | BuilderGlobals][];
23
- export declare const getBuilderGlobals: () => BuilderGlobals;
31
+ export declare const getBuilderGlobals: (trackingContext?: TrackingContext) => BuilderGlobals;
24
32
  export declare const parseCode: (code: string, { isExpression }: Pick<EvaluatorArgs, 'isExpression'>) => string;
25
33
  export declare function flattenState({ rootState, localState, rootSetState }: {
26
34
  rootState: Record<string | symbol, any>;
@@ -1,7 +1,9 @@
1
1
  import type { BuilderContextInterface } from '../context/types.js';
2
2
  import type { BuilderBlock } from '../types/builder-block.js';
3
+ import type { TrackingContext } from './evaluate/helpers.js';
3
4
  type Options = {
4
5
  block: BuilderBlock;
6
+ trackingContext?: TrackingContext;
5
7
  } & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>;
6
8
  type EventHandler = (event: Event) => any;
7
9
  export declare const createEventHandler: (value: string, options: Options) => EventHandler;
@@ -1,10 +1,12 @@
1
1
  import type { BuilderContextInterface } from '../context/types.js';
2
2
  import type { BuilderBlock } from '../types/builder-block.js';
3
+ import type { TrackingContext } from './evaluate/helpers.js';
3
4
  type Actions = {
4
5
  [index: string]: (event: Event) => any;
5
6
  };
6
7
  export declare function getBlockActions(options: {
7
8
  block: BuilderBlock;
8
9
  stripPrefix?: boolean;
10
+ trackingContext?: TrackingContext;
9
11
  } & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): Actions;
10
12
  export {};
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.23.2";
1
+ export declare const SDK_VERSION = "0.24.1";
@@ -1,5 +1,5 @@
1
1
  import type { EvaluatorArgs } from './helpers.js';
2
2
  type EvalValue = unknown;
3
3
  export declare const getSimpleExpressionGetPath: (code: string) => string;
4
- export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression }: EvaluatorArgs): EvalValue;
4
+ export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression, trackingContext }: EvaluatorArgs): EvalValue;
5
5
  export {};
@@ -1,14 +1,22 @@
1
1
  import type { BuilderContextInterface, BuilderRenderState } from '../../context/types.js';
2
2
  import { getUserAttributes } from '../track/helpers.js';
3
+ export type TrackingContext = {
4
+ apiKey: string | null;
5
+ canTrack?: boolean;
6
+ contentId?: string;
7
+ variationId?: string;
8
+ };
3
9
  export type EvaluatorArgs = Omit<ExecutorArgs, 'builder' | 'event'> & {
4
10
  event?: Event;
5
11
  isExpression?: boolean;
12
+ trackingContext?: TrackingContext;
6
13
  };
7
14
  export type BuilderGlobals = {
8
15
  isEditing: boolean | undefined;
9
16
  isBrowser: boolean | undefined;
10
17
  isServer: boolean | undefined;
11
18
  getUserAttributes: typeof getUserAttributes;
19
+ trackConversion: (amount?: number, customProperties?: Record<string, any>) => void;
12
20
  };
13
21
  export type ExecutorArgs = Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'> & {
14
22
  code: string;
@@ -20,7 +28,7 @@ export type FunctionArguments = ReturnType<typeof getFunctionArguments>;
20
28
  export declare const getFunctionArguments: ({ builder, context, event, state }: Pick<ExecutorArgs, "context" | "builder" | "event"> & {
21
29
  state: BuilderRenderState;
22
30
  }) => [string, Event | BuilderRenderState | import("../../context/types.js").BuilderRenderContext | BuilderGlobals][];
23
- export declare const getBuilderGlobals: () => BuilderGlobals;
31
+ export declare const getBuilderGlobals: (trackingContext?: TrackingContext) => BuilderGlobals;
24
32
  export declare const parseCode: (code: string, { isExpression }: Pick<EvaluatorArgs, 'isExpression'>) => string;
25
33
  export declare function flattenState({ rootState, localState, rootSetState }: {
26
34
  rootState: Record<string | symbol, any>;
@@ -1,7 +1,9 @@
1
1
  import type { BuilderContextInterface } from '../context/types.js';
2
2
  import type { BuilderBlock } from '../types/builder-block.js';
3
+ import type { TrackingContext } from './evaluate/helpers.js';
3
4
  type Options = {
4
5
  block: BuilderBlock;
6
+ trackingContext?: TrackingContext;
5
7
  } & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>;
6
8
  type EventHandler = (event: Event) => any;
7
9
  export declare const createEventHandler: (value: string, options: Options) => EventHandler;
@@ -1,10 +1,12 @@
1
1
  import type { BuilderContextInterface } from '../context/types.js';
2
2
  import type { BuilderBlock } from '../types/builder-block.js';
3
+ import type { TrackingContext } from './evaluate/helpers.js';
3
4
  type Actions = {
4
5
  [index: string]: (event: Event) => any;
5
6
  };
6
7
  export declare function getBlockActions(options: {
7
8
  block: BuilderBlock;
8
9
  stripPrefix?: boolean;
10
+ trackingContext?: TrackingContext;
9
11
  } & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): Actions;
10
12
  export {};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./target.cjs"),t=(()=>{switch(e.TARGET){case"rsc":return"react-nextjs";case"reactNative":return"react-native";default:return e.TARGET}})(),r=`@builder.io/sdk-${t}`;exports.SDK_NAME=r;
@@ -1,14 +0,0 @@
1
- import { TARGET as t } from "./target.mjs";
2
- const e = (() => {
3
- switch (t) {
4
- case "rsc":
5
- return "react-nextjs";
6
- case "reactNative":
7
- return "react-native";
8
- default:
9
- return t;
10
- }
11
- })(), c = `@builder.io/sdk-${e}`;
12
- export {
13
- c as SDK_NAME
14
- };
@@ -1,8 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../../../constants/sdk-name.cjs"),l=require("../../../helpers/logger.cjs"),c=require("./safeDynamicRequire.cjs"),d="BUILDER_IVM";let n=null,s=null;const u=(t,e={})=>{n||(n=t,S(e))},m=o.SDK_NAME==="@builder.io/sdk-react-nextjs"||o.SDK_NAME==="@builder.io/sdk-react"||o.SDK_NAME==="@builder.io/sdk-qwik"||o.SDK_NAME==="@builder.io/sdk-vue",I=()=>{try{if(n)return n;const e=c.safeDynamicRequire("isolated-vm");if(e)return e}catch(e){l.logger.error("isolated-vm import error.",e)}const t=`${l.MSG_PREFIX}could not import \`isolated-vm\` module for safe script execution on a Node server.
2
-
3
- SOLUTION: In a server-only execution path within your application, do one of the following:
4
-
5
- ${m?`- import and call \`initializeNodeRuntime()\` from "${o.SDK_NAME}/node/init".`:""}
6
- - add the following import: \`await import('isolated-vm')\`.
7
-
8
- For more information, visit https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments`;throw new Error(t)};function S(t={memoryLimit:128}){if(s)return s;const e=I(),r=new e.Isolate(t).createContextSync(),i=r.global;return i.setSync("global",i.derefInto()),i.setSync("log",function(...a){console.log(...a)}),i.setSync(d,e),s=r,r}exports.setIvm=u;
@@ -1,40 +0,0 @@
1
- import { SDK_NAME as e } from "../../../constants/sdk-name.mjs";
2
- import { logger as a, MSG_PREFIX as c } from "../../../helpers/logger.mjs";
3
- import { safeDynamicRequire as d } from "./safeDynamicRequire.mjs";
4
- const m = "BUILDER_IVM";
5
- let n = null, l = null;
6
- const S = (t, o = {}) => {
7
- n || (n = t, f(o));
8
- }, u = e === "@builder.io/sdk-react-nextjs" || e === "@builder.io/sdk-react" || e === "@builder.io/sdk-qwik" || e === "@builder.io/sdk-vue", I = () => {
9
- try {
10
- if (n)
11
- return n;
12
- const o = d("isolated-vm");
13
- if (o)
14
- return o;
15
- } catch (o) {
16
- a.error("isolated-vm import error.", o);
17
- }
18
- const t = `${c}could not import \`isolated-vm\` module for safe script execution on a Node server.
19
-
20
- SOLUTION: In a server-only execution path within your application, do one of the following:
21
-
22
- ${u ? `- import and call \`initializeNodeRuntime()\` from "${e}/node/init".` : ""}
23
- - add the following import: \`await import('isolated-vm')\`.
24
-
25
- For more information, visit https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments`;
26
- throw new Error(t);
27
- };
28
- function f(t = {
29
- memoryLimit: 128
30
- }) {
31
- if (l)
32
- return l;
33
- const o = I(), r = new o.Isolate(t).createContextSync(), i = r.global;
34
- return i.setSync("global", i.derefInto()), i.setSync("log", function(...s) {
35
- console.log(...s);
36
- }), i.setSync(m, o), l = r, r;
37
- }
38
- export {
39
- S as setIvm
40
- };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./target.cjs"),t=(()=>{switch(e.TARGET){case"rsc":return"react-nextjs";case"reactNative":return"react-native";default:return e.TARGET}})(),r=`@builder.io/sdk-${t}`;exports.SDK_NAME=r;
@@ -1,14 +0,0 @@
1
- import { TARGET as t } from "./target.mjs";
2
- const e = (() => {
3
- switch (t) {
4
- case "rsc":
5
- return "react-nextjs";
6
- case "reactNative":
7
- return "react-native";
8
- default:
9
- return t;
10
- }
11
- })(), c = `@builder.io/sdk-${e}`;
12
- export {
13
- c as SDK_NAME
14
- };
@@ -1,8 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../../../constants/sdk-name.cjs"),l=require("../../../helpers/logger.cjs"),c=require("./safeDynamicRequire.cjs"),d="BUILDER_IVM";let n=null,s=null;const u=(t,e={})=>{n||(n=t,S(e))},m=o.SDK_NAME==="@builder.io/sdk-react-nextjs"||o.SDK_NAME==="@builder.io/sdk-react"||o.SDK_NAME==="@builder.io/sdk-qwik"||o.SDK_NAME==="@builder.io/sdk-vue",I=()=>{try{if(n)return n;const e=c.safeDynamicRequire("isolated-vm");if(e)return e}catch(e){l.logger.error("isolated-vm import error.",e)}const t=`${l.MSG_PREFIX}could not import \`isolated-vm\` module for safe script execution on a Node server.
2
-
3
- SOLUTION: In a server-only execution path within your application, do one of the following:
4
-
5
- ${m?`- import and call \`initializeNodeRuntime()\` from "${o.SDK_NAME}/node/init".`:""}
6
- - add the following import: \`await import('isolated-vm')\`.
7
-
8
- For more information, visit https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments`;throw new Error(t)};function S(t={memoryLimit:128}){if(s)return s;const e=I(),r=new e.Isolate(t).createContextSync(),i=r.global;return i.setSync("global",i.derefInto()),i.setSync("log",function(...a){console.log(...a)}),i.setSync(d,e),s=r,r}exports.setIvm=u;
@@ -1,40 +0,0 @@
1
- import { SDK_NAME as e } from "../../../constants/sdk-name.mjs";
2
- import { logger as a, MSG_PREFIX as c } from "../../../helpers/logger.mjs";
3
- import { safeDynamicRequire as d } from "./safeDynamicRequire.mjs";
4
- const m = "BUILDER_IVM";
5
- let n = null, l = null;
6
- const S = (t, o = {}) => {
7
- n || (n = t, f(o));
8
- }, u = e === "@builder.io/sdk-react-nextjs" || e === "@builder.io/sdk-react" || e === "@builder.io/sdk-qwik" || e === "@builder.io/sdk-vue", I = () => {
9
- try {
10
- if (n)
11
- return n;
12
- const o = d("isolated-vm");
13
- if (o)
14
- return o;
15
- } catch (o) {
16
- a.error("isolated-vm import error.", o);
17
- }
18
- const t = `${c}could not import \`isolated-vm\` module for safe script execution on a Node server.
19
-
20
- SOLUTION: In a server-only execution path within your application, do one of the following:
21
-
22
- ${u ? `- import and call \`initializeNodeRuntime()\` from "${e}/node/init".` : ""}
23
- - add the following import: \`await import('isolated-vm')\`.
24
-
25
- For more information, visit https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments`;
26
- throw new Error(t);
27
- };
28
- function f(t = {
29
- memoryLimit: 128
30
- }) {
31
- if (l)
32
- return l;
33
- const o = I(), r = new o.Isolate(t).createContextSync(), i = r.global;
34
- return i.setSync("global", i.derefInto()), i.setSync("log", function(...s) {
35
- console.log(...s);
36
- }), i.setSync(m, o), l = r, r;
37
- }
38
- export {
39
- S as setIvm
40
- };