@builder.io/sdk-react-nextjs 0.24.0 → 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 (47) 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/edge/components/block/components/block-wrapper.cjs +1 -1
  14. package/lib/edge/components/block/components/block-wrapper.mjs +16 -9
  15. package/lib/edge/components/block/components/interactive-element.cjs +1 -1
  16. package/lib/edge/components/block/components/interactive-element.mjs +28 -21
  17. package/lib/edge/constants/sdk-version.cjs +1 -1
  18. package/lib/edge/constants/sdk-version.mjs +1 -1
  19. package/lib/edge/functions/evaluate/evaluate.cjs +1 -1
  20. package/lib/edge/functions/evaluate/evaluate.mjs +18 -17
  21. package/lib/edge/functions/evaluate/helpers.cjs +1 -1
  22. package/lib/edge/functions/evaluate/helpers.mjs +52 -35
  23. package/lib/edge/functions/get-block-actions-handler.cjs +1 -1
  24. package/lib/edge/functions/get-block-actions-handler.mjs +4 -3
  25. package/lib/node/components/block/components/block-wrapper.cjs +1 -1
  26. package/lib/node/components/block/components/block-wrapper.mjs +16 -9
  27. package/lib/node/components/block/components/interactive-element.cjs +1 -1
  28. package/lib/node/components/block/components/interactive-element.mjs +28 -21
  29. package/lib/node/constants/sdk-version.cjs +1 -1
  30. package/lib/node/constants/sdk-version.mjs +1 -1
  31. package/lib/node/functions/evaluate/evaluate.cjs +1 -1
  32. package/lib/node/functions/evaluate/evaluate.mjs +18 -17
  33. package/lib/node/functions/evaluate/helpers.cjs +1 -1
  34. package/lib/node/functions/evaluate/helpers.mjs +52 -35
  35. package/lib/node/functions/get-block-actions-handler.cjs +1 -1
  36. package/lib/node/functions/get-block-actions-handler.mjs +4 -3
  37. package/package.json +1 -1
  38. package/types/cjs/constants/sdk-version.d.ts +1 -1
  39. package/types/cjs/functions/evaluate/evaluate.d.ts +1 -1
  40. package/types/cjs/functions/evaluate/helpers.d.ts +9 -1
  41. package/types/cjs/functions/get-block-actions-handler.d.ts +2 -0
  42. package/types/cjs/functions/get-block-actions.d.ts +2 -0
  43. package/types/esm/constants/sdk-version.d.ts +1 -1
  44. package/types/esm/functions/evaluate/evaluate.d.ts +1 -1
  45. package/types/esm/functions/evaluate/helpers.d.ts +9 -1
  46. package/types/esm/functions/get-block-actions-handler.d.ts +2 -0
  47. package/types/esm/functions/get-block-actions.d.ts +2 -0
@@ -1,54 +1,71 @@
1
- import { isBrowser as u } from "../is-browser.mjs";
2
- import { isEditing as f } from "../is-editing.mjs";
3
- import { getUserAttributes as d } from "../track/helpers.mjs";
4
- const w = ({
1
+ import { isBrowser as d } from "../is-browser.mjs";
2
+ import { isEditing as o } from "../is-editing.mjs";
3
+ import { getUserAttributes as v } from "../track/helpers.mjs";
4
+ import { _track as m } from "../track/index.mjs";
5
+ const B = ({
5
6
  builder: r,
6
- context: n,
7
- event: i,
8
- state: e
7
+ context: s,
8
+ event: e,
9
+ state: i
9
10
  }) => Object.entries({
10
- state: e,
11
+ state: i,
11
12
  Builder: r,
12
13
  // legacy
13
14
  builder: r,
14
- context: n,
15
- event: i
16
- }), b = () => ({
17
- isEditing: f(),
18
- isBrowser: u(),
19
- isServer: !u(),
20
- getUserAttributes: () => d()
21
- }), v = (r, {
22
- isExpression: n = !0
23
- }) => /* we disable this for cases where we definitely don't want a return */ n && !(r.includes(";") || r.includes(" return ") || r.trim().startsWith("return ")) ? `return (${r});` : r;
15
+ context: s,
16
+ event: e
17
+ }), a = (r) => ({
18
+ isEditing: o(),
19
+ isBrowser: d(),
20
+ isServer: !d(),
21
+ getUserAttributes: () => v(),
22
+ trackConversion: (s, e) => {
23
+ var i;
24
+ !(r != null && r.apiKey) || (r == null ? void 0 : r.canTrack) === !1 || m({
25
+ type: "conversion",
26
+ apiKey: r.apiKey,
27
+ canTrack: (i = r.canTrack) != null ? i : !0,
28
+ contentId: r.contentId,
29
+ variationId: r.variationId !== r.contentId ? r.variationId : void 0,
30
+ metadata: {
31
+ ...e || {},
32
+ ...s !== void 0 ? {
33
+ amount: s
34
+ } : {}
35
+ }
36
+ });
37
+ }
38
+ }), c = (r, {
39
+ isExpression: s = !0
40
+ }) => /* we disable this for cases where we definitely don't want a return */ s && !(r.includes(";") || r.includes(" return ") || r.trim().startsWith("return ")) ? `return (${r});` : r;
24
41
  function l({
25
42
  rootState: r,
26
- localState: n,
27
- rootSetState: i
43
+ localState: s,
44
+ rootSetState: e
28
45
  }) {
29
46
  return new Proxy(r, {
30
- get: (e, s) => {
31
- if (n && s in n)
32
- return n[s];
33
- const t = e[s];
34
- return typeof t == "object" && t !== null ? l({
35
- rootState: t,
47
+ get: (i, u) => {
48
+ if (s && u in s)
49
+ return s[u];
50
+ const n = i[u];
51
+ return typeof n == "object" && n !== null ? l({
52
+ rootState: n,
36
53
  localState: void 0,
37
- rootSetState: i ? (o) => {
38
- e[s] = o, i(e);
54
+ rootSetState: e ? (f) => {
55
+ i[u] = f, e(i);
39
56
  } : void 0
40
- }) : t;
57
+ }) : n;
41
58
  },
42
- set: (e, s, t) => {
43
- if (n && s in n)
59
+ set: (i, u, n) => {
60
+ if (s && u in s)
44
61
  throw new Error("Writing to local state is not allowed as it is read-only.");
45
- return e[s] = t, i == null || i(e), !0;
62
+ return i[u] = n, e == null || e(i), !0;
46
63
  }
47
64
  });
48
65
  }
49
66
  export {
50
67
  l as flattenState,
51
- b as getBuilderGlobals,
52
- w as getFunctionArguments,
53
- v as parseCode
68
+ a as getBuilderGlobals,
69
+ B as getFunctionArguments,
70
+ c as parseCode
54
71
  };
@@ -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
  };
@@ -1 +1 @@
1
- "use client";"use strict";const e=require("react/jsx-runtime"),c=require("../../../functions/get-block-actions.cjs"),o=require("../../../functions/get-block-properties.cjs"),r=require("../../dynamic-renderer/dynamic-renderer.cjs");function n(t){return e.jsx(r,{TagName:t.Wrapper,attributes:o.getBlockProperties({block:t.block,context:t.context}),actionAttributes:c.getBlockActions({block:t.block,rootState:t.context.rootState,rootSetState:t.context.rootSetState,localState:t.context.localState,context:t.context.context,stripPrefix:!0}),children:t.children})}module.exports=n;
1
+ "use client";"use strict";const o=require("react/jsx-runtime"),i=require("../../../functions/get-block-actions.cjs"),r=require("../../../functions/get-block-properties.cjs"),a=require("../../dynamic-renderer/dynamic-renderer.cjs");function x(t){var e,c,n;return o.jsx(a,{TagName:t.Wrapper,attributes:r.getBlockProperties({block:t.block,context:t.context}),actionAttributes:i.getBlockActions({block:t.block,rootState:t.context.rootState,rootSetState:t.context.rootSetState,localState:t.context.localState,context:t.context.context,stripPrefix:!0,trackingContext:{apiKey:t.context.apiKey,canTrack:(e=t.context.canTrack)!=null?e:!0,contentId:(c=t.context.content)==null?void 0:c.id,variationId:(n=t.context.content)==null?void 0:n.testVariationId}}),children:t.children})}module.exports=x;
@@ -1,29 +1,36 @@
1
1
  "use client";
2
- import { jsx as e } from "react/jsx-runtime";
3
- import { getBlockActions as o } from "../../../functions/get-block-actions.mjs";
4
- import { getBlockProperties as c } from "../../../functions/get-block-properties.mjs";
2
+ import { jsx as n } from "react/jsx-runtime";
3
+ import { getBlockActions as a } from "../../../functions/get-block-actions.mjs";
4
+ import { getBlockProperties as i } from "../../../functions/get-block-properties.mjs";
5
5
  import r from "../../dynamic-renderer/dynamic-renderer.mjs";
6
- function x(t) {
7
- return /* @__PURE__ */ e(
6
+ function d(t) {
7
+ var e, c, o;
8
+ return /* @__PURE__ */ n(
8
9
  r,
9
10
  {
10
11
  TagName: t.Wrapper,
11
- attributes: c({
12
+ attributes: i({
12
13
  block: t.block,
13
14
  context: t.context
14
15
  }),
15
- actionAttributes: o({
16
+ actionAttributes: a({
16
17
  block: t.block,
17
18
  rootState: t.context.rootState,
18
19
  rootSetState: t.context.rootSetState,
19
20
  localState: t.context.localState,
20
21
  context: t.context.context,
21
- stripPrefix: !0
22
+ stripPrefix: !0,
23
+ trackingContext: {
24
+ apiKey: t.context.apiKey,
25
+ canTrack: (e = t.context.canTrack) != null ? e : !0,
26
+ contentId: (c = t.context.content) == null ? void 0 : c.id,
27
+ variationId: (o = t.context.content) == null ? void 0 : o.testVariationId
28
+ }
22
29
  }),
23
30
  children: t.children
24
31
  }
25
32
  );
26
33
  }
27
34
  export {
28
- x as default
35
+ d as default
29
36
  };
@@ -1 +1 @@
1
- "use client";"use strict";const e=require("react/jsx-runtime"),i=require("react"),o=require("../../../functions/get-block-actions.cjs"),l=require("../../../functions/get-block-properties.cjs"),u=require("../../../functions/is-editing.cjs");require("../../../helpers/user-attributes.cjs");require("../../../functions/get-fetch.cjs");const d=require("../../awaiter.cjs"),s=require("../../live-edit.cjs");function x(t){var c,n;i.useState(()=>0);function r(){return t.includeBlockProps?{...l.getBlockProperties({block:t.block,context:t.context}),...o.getBlockActions({block:t.block,rootState:t.context.rootState,rootSetState:t.context.rootSetState,localState:t.context.localState,context:t.context.context})}:{}}function a(){return t.wrapperProps}return i.useEffect(()=>{},[t.wrapperProps,(n=(c=t.block)==null?void 0:c.component)==null?void 0:n.options]),e.jsx(e.Fragment,{children:t.Wrapper.load?e.jsx(e.Fragment,{children:e.jsx(d,{load:t.Wrapper.load,fallback:t.Wrapper.fallback,props:t.wrapperProps,attributes:r(),children:t.children})}):u.isEditing()?e.jsx(s,{Wrapper:t.Wrapper,id:t.block.id||"",attributes:r(),children:t.children}):e.jsx(t.Wrapper,{...a(),attributes:r(),children:t.children})})}module.exports=x;
1
+ "use client";"use strict";const e=require("react/jsx-runtime"),l=require("react"),d=require("../../../functions/get-block-actions.cjs"),x=require("../../../functions/get-block-properties.cjs"),k=require("../../../functions/is-editing.cjs");require("../../../helpers/user-attributes.cjs");require("../../../functions/get-fetch.cjs");const s=require("../../awaiter.cjs"),b=require("../../live-edit.cjs");function g(t){var n,r;l.useState(()=>0);function c(){var i,a,o;return t.includeBlockProps?{...x.getBlockProperties({block:t.block,context:t.context}),...d.getBlockActions({block:t.block,rootState:t.context.rootState,rootSetState:t.context.rootSetState,localState:t.context.localState,context:t.context.context,trackingContext:{apiKey:t.context.apiKey,canTrack:(i=t.context.canTrack)!=null?i:!0,contentId:(a=t.context.content)==null?void 0:a.id,variationId:(o=t.context.content)==null?void 0:o.testVariationId}})}:{}}function u(){return t.wrapperProps}return l.useEffect(()=>{},[t.wrapperProps,(r=(n=t.block)==null?void 0:n.component)==null?void 0:r.options]),e.jsx(e.Fragment,{children:t.Wrapper.load?e.jsx(e.Fragment,{children:e.jsx(s,{load:t.Wrapper.load,fallback:t.Wrapper.fallback,props:t.wrapperProps,attributes:c(),children:t.children})}):k.isEditing()?e.jsx(b,{Wrapper:t.Wrapper,id:t.block.id||"",attributes:c(),children:t.children}):e.jsx(t.Wrapper,{...u(),attributes:c(),children:t.children})})}module.exports=g;
@@ -1,37 +1,44 @@
1
1
  "use client";
2
- import { jsx as e, Fragment as i } from "react/jsx-runtime";
3
- import { useState as n, useEffect as l } from "react";
4
- import { getBlockActions as m } from "../../../functions/get-block-actions.mjs";
5
- import { getBlockProperties as d } from "../../../functions/get-block-properties.mjs";
6
- import { isEditing as f } from "../../../functions/is-editing.mjs";
2
+ import { jsx as e, Fragment as l } from "react/jsx-runtime";
3
+ import { useState as m, useEffect as u } from "react";
4
+ import { getBlockActions as f } from "../../../functions/get-block-actions.mjs";
5
+ import { getBlockProperties as x } from "../../../functions/get-block-properties.mjs";
6
+ import { isEditing as k } from "../../../functions/is-editing.mjs";
7
7
  import "../../../helpers/user-attributes.mjs";
8
8
  import "../../../functions/get-fetch.mjs";
9
- import u from "../../awaiter.mjs";
10
- import b from "../../live-edit.mjs";
11
- function B(t) {
12
- var o, c;
13
- n(() => 0);
9
+ import b from "../../awaiter.mjs";
10
+ import S from "../../live-edit.mjs";
11
+ function y(t) {
12
+ var n, c;
13
+ m(() => 0);
14
14
  function r() {
15
+ var o, a, i;
15
16
  return t.includeBlockProps ? {
16
- ...d({
17
+ ...x({
17
18
  block: t.block,
18
19
  context: t.context
19
20
  }),
20
- ...m({
21
+ ...f({
21
22
  block: t.block,
22
23
  rootState: t.context.rootState,
23
24
  rootSetState: t.context.rootSetState,
24
25
  localState: t.context.localState,
25
- context: t.context.context
26
+ context: t.context.context,
27
+ trackingContext: {
28
+ apiKey: t.context.apiKey,
29
+ canTrack: (o = t.context.canTrack) != null ? o : !0,
30
+ contentId: (a = t.context.content) == null ? void 0 : a.id,
31
+ variationId: (i = t.context.content) == null ? void 0 : i.testVariationId
32
+ }
26
33
  })
27
34
  } : {};
28
35
  }
29
- function a() {
36
+ function d() {
30
37
  return t.wrapperProps;
31
38
  }
32
- return l(() => {
33
- }, [t.wrapperProps, (c = (o = t.block) == null ? void 0 : o.component) == null ? void 0 : c.options]), /* @__PURE__ */ e(i, { children: t.Wrapper.load ? /* @__PURE__ */ e(i, { children: /* @__PURE__ */ e(
34
- u,
39
+ return u(() => {
40
+ }, [t.wrapperProps, (c = (n = t.block) == null ? void 0 : n.component) == null ? void 0 : c.options]), /* @__PURE__ */ e(l, { children: t.Wrapper.load ? /* @__PURE__ */ e(l, { children: /* @__PURE__ */ e(
41
+ b,
35
42
  {
36
43
  load: t.Wrapper.load,
37
44
  fallback: t.Wrapper.fallback,
@@ -39,16 +46,16 @@ function B(t) {
39
46
  attributes: r(),
40
47
  children: t.children
41
48
  }
42
- ) }) : f() ? /* @__PURE__ */ e(
43
- b,
49
+ ) }) : k() ? /* @__PURE__ */ e(
50
+ S,
44
51
  {
45
52
  Wrapper: t.Wrapper,
46
53
  id: t.block.id || "",
47
54
  attributes: r(),
48
55
  children: t.children
49
56
  }
50
- ) : /* @__PURE__ */ e(t.Wrapper, { ...a(), attributes: r(), children: t.children }) });
57
+ ) : /* @__PURE__ */ e(t.Wrapper, { ...d(), attributes: r(), children: t.children }) });
51
58
  }
52
59
  export {
53
- B as default
60
+ y as default
54
61
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.24.0";exports.SDK_VERSION=e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.24.1";exports.SDK_VERSION=e;
@@ -1,4 +1,4 @@
1
- const o = "0.24.0";
1
+ const o = "0.24.1";
2
2
  export {
3
3
  o as SDK_VERSION
4
4
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../../helpers/logger.cjs"),E=require("../get.cjs"),h=require("./choose-eval.cjs"),l=require("./helpers.cjs"),p=/^(return )?(\s*)?state(?<getPath>(\.\w+)+)(\s*);?$/,d=/(\s)*var(\s)+_virtual_index(\s)*=(\s)*state(?<getPath>(\.\w+)+)(\s*);?(\s)*return(\s)*_virtual_index(\s)*/,g=e=>{var s,t,r,i,n,a;return((r=(t=(s=p.exec(e.trim()))==null?void 0:s.groups)==null?void 0:t.getPath)==null?void 0:r.slice(1))||((a=(n=(i=d.exec(e.trim()))==null?void 0:i.groups)==null?void 0:n.getPath)==null?void 0:a.slice(1))};function m({code:e,context:s,localState:t,rootState:r,rootSetState:i,event:n,isExpression:a=!0}){if(e.trim()==="")return;const o=g(e.trim());if(o)return E.get({...r,...t},o);const c={code:l.parseCode(e,{isExpression:a}),builder:l.getBuilderGlobals(),context:s,event:n,rootSetState:i,rootState:r,localState:t};try{return h.chooseBrowserOrServerEval(c)}catch(u){v.logger.error("Failed code evaluation: "+u.message,{code:e});return}}exports.evaluate=m;exports.getSimpleExpressionGetPath=g;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("../../helpers/logger.cjs"),h=require("../get.cjs"),p=require("./choose-eval.cjs"),l=require("./helpers.cjs"),d=/^(return )?(\s*)?state(?<getPath>(\.\w+)+)(\s*);?$/,m=/(\s)*var(\s)+_virtual_index(\s)*=(\s)*state(?<getPath>(\.\w+)+)(\s*);?(\s)*return(\s)*_virtual_index(\s)*/,g=e=>{var s,t,r,i,n,a;return((r=(t=(s=d.exec(e.trim()))==null?void 0:s.groups)==null?void 0:t.getPath)==null?void 0:r.slice(1))||((a=(n=(i=m.exec(e.trim()))==null?void 0:i.groups)==null?void 0:n.getPath)==null?void 0:a.slice(1))};function P({code:e,context:s,localState:t,rootState:r,rootSetState:i,event:n,isExpression:a=!0,trackingContext:c}){if(e.trim()==="")return;const o=g(e.trim());if(o)return h.get({...r,...t},o);const v={code:l.parseCode(e,{isExpression:a}),builder:l.getBuilderGlobals(c),context:s,event:n,rootSetState:i,rootState:r,localState:t};try{return p.chooseBrowserOrServerEval(v)}catch(u){E.logger.error("Failed code evaluation: "+u.message,{code:e});return}}exports.evaluate=P;exports.getSimpleExpressionGetPath=g;
@@ -1,33 +1,34 @@
1
- import { logger as l } from "../../helpers/logger.mjs";
2
- import { get as m } from "../get.mjs";
3
- import { chooseBrowserOrServerEval as E } from "./choose-eval.mjs";
4
- import { parseCode as c, getBuilderGlobals as v } from "./helpers.mjs";
5
- const p = /^(return )?(\s*)?state(?<getPath>(\.\w+)+)(\s*);?$/, h = /(\s)*var(\s)+_virtual_index(\s)*=(\s)*state(?<getPath>(\.\w+)+)(\s*);?(\s)*return(\s)*_virtual_index(\s)*/, _ = (r) => {
1
+ import { logger as m } from "../../helpers/logger.mjs";
2
+ import { get as E } from "../get.mjs";
3
+ import { chooseBrowserOrServerEval as c } from "./choose-eval.mjs";
4
+ import { parseCode as v, getBuilderGlobals as p } from "./helpers.mjs";
5
+ const h = /^(return )?(\s*)?state(?<getPath>(\.\w+)+)(\s*);?$/, _ = /(\s)*var(\s)+_virtual_index(\s)*=(\s)*state(?<getPath>(\.\w+)+)(\s*);?(\s)*return(\s)*_virtual_index(\s)*/, f = (r) => {
6
6
  var s, e, t, i, o, a;
7
- return ((t = (e = (s = p.exec(r.trim())) == null ? void 0 : s.groups) == null ? void 0 : e.getPath) == null ? void 0 : t.slice(1)) || ((a = (o = (i = h.exec(r.trim())) == null ? void 0 : i.groups) == null ? void 0 : o.getPath) == null ? void 0 : a.slice(1));
7
+ return ((t = (e = (s = h.exec(r.trim())) == null ? void 0 : s.groups) == null ? void 0 : e.getPath) == null ? void 0 : t.slice(1)) || ((a = (o = (i = _.exec(r.trim())) == null ? void 0 : i.groups) == null ? void 0 : o.getPath) == null ? void 0 : a.slice(1));
8
8
  };
9
- function w({
9
+ function G({
10
10
  code: r,
11
11
  context: s,
12
12
  localState: e,
13
13
  rootState: t,
14
14
  rootSetState: i,
15
15
  event: o,
16
- isExpression: a = !0
16
+ isExpression: a = !0,
17
+ trackingContext: g
17
18
  }) {
18
19
  if (r.trim() === "")
19
20
  return;
20
- const n = _(r.trim());
21
+ const n = f(r.trim());
21
22
  if (n)
22
- return m({
23
+ return E({
23
24
  ...t,
24
25
  ...e
25
26
  }, n);
26
- const g = {
27
- code: c(r, {
27
+ const l = {
28
+ code: v(r, {
28
29
  isExpression: a
29
30
  }),
30
- builder: v(),
31
+ builder: p(g),
31
32
  context: s,
32
33
  event: o,
33
34
  rootSetState: i,
@@ -35,15 +36,15 @@ function w({
35
36
  localState: e
36
37
  };
37
38
  try {
38
- return E(g);
39
+ return c(l);
39
40
  } catch (u) {
40
- l.error("Failed code evaluation: " + u.message, {
41
+ m.error("Failed code evaluation: " + u.message, {
41
42
  code: r
42
43
  });
43
44
  return;
44
45
  }
45
46
  }
46
47
  export {
47
- w as evaluate,
48
- _ as getSimpleExpressionGetPath
48
+ G as evaluate,
49
+ f as getSimpleExpressionGetPath
49
50
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../is-browser.cjs"),d=require("../is-editing.cjs"),c=require("../track/helpers.cjs"),g=({builder:e,context:r,event:n,state:s})=>Object.entries({state:s,Builder:e,builder:e,context:r,event:n}),f=()=>({isEditing:d.isEditing(),isBrowser:u.isBrowser(),isServer:!u.isBrowser(),getUserAttributes:()=>c.getUserAttributes()}),w=(e,{isExpression:r=!0})=>r&&!(e.includes(";")||e.includes(" return ")||e.trim().startsWith("return "))?`return (${e});`:e;function o({rootState:e,localState:r,rootSetState:n}){return new Proxy(e,{get:(s,t)=>{if(r&&t in r)return r[t];const i=s[t];return typeof i=="object"&&i!==null?o({rootState:i,localState:void 0,rootSetState:n?l=>{s[t]=l,n(s)}:void 0}):i},set:(s,t,i)=>{if(r&&t in r)throw new Error("Writing to local state is not allowed as it is read-only.");return s[t]=i,n==null||n(s),!0}})}exports.flattenState=o;exports.getBuilderGlobals=f;exports.getFunctionArguments=g;exports.parseCode=w;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("../is-browser.cjs"),t=require("../is-editing.cjs"),v=require("../track/helpers.cjs"),c=require("../track/index.cjs"),f=({builder:e,context:r,event:i,state:s})=>Object.entries({state:s,Builder:e,builder:e,context:r,event:i}),a=e=>({isEditing:t.isEditing(),isBrowser:d.isBrowser(),isServer:!d.isBrowser(),getUserAttributes:()=>v.getUserAttributes(),trackConversion:(r,i)=>{var s;!(e!=null&&e.apiKey)||(e==null?void 0:e.canTrack)===!1||c._track({type:"conversion",apiKey:e.apiKey,canTrack:(s=e.canTrack)!=null?s:!0,contentId:e.contentId,variationId:e.variationId!==e.contentId?e.variationId:void 0,metadata:{...i||{},...r!==void 0?{amount:r}:{}}})}}),y=(e,{isExpression:r=!0})=>r&&!(e.includes(";")||e.includes(" return ")||e.trim().startsWith("return "))?`return (${e});`:e;function l({rootState:e,localState:r,rootSetState:i}){return new Proxy(e,{get:(s,u)=>{if(r&&u in r)return r[u];const n=s[u];return typeof n=="object"&&n!==null?l({rootState:n,localState:void 0,rootSetState:i?o=>{s[u]=o,i(s)}:void 0}):n},set:(s,u,n)=>{if(r&&u in r)throw new Error("Writing to local state is not allowed as it is read-only.");return s[u]=n,i==null||i(s),!0}})}exports.flattenState=l;exports.getBuilderGlobals=a;exports.getFunctionArguments=f;exports.parseCode=y;
@@ -1,54 +1,71 @@
1
- import { isBrowser as u } from "../is-browser.mjs";
2
- import { isEditing as f } from "../is-editing.mjs";
3
- import { getUserAttributes as d } from "../track/helpers.mjs";
4
- const w = ({
1
+ import { isBrowser as d } from "../is-browser.mjs";
2
+ import { isEditing as o } from "../is-editing.mjs";
3
+ import { getUserAttributes as v } from "../track/helpers.mjs";
4
+ import { _track as m } from "../track/index.mjs";
5
+ const B = ({
5
6
  builder: r,
6
- context: n,
7
- event: i,
8
- state: e
7
+ context: s,
8
+ event: e,
9
+ state: i
9
10
  }) => Object.entries({
10
- state: e,
11
+ state: i,
11
12
  Builder: r,
12
13
  // legacy
13
14
  builder: r,
14
- context: n,
15
- event: i
16
- }), b = () => ({
17
- isEditing: f(),
18
- isBrowser: u(),
19
- isServer: !u(),
20
- getUserAttributes: () => d()
21
- }), v = (r, {
22
- isExpression: n = !0
23
- }) => /* we disable this for cases where we definitely don't want a return */ n && !(r.includes(";") || r.includes(" return ") || r.trim().startsWith("return ")) ? `return (${r});` : r;
15
+ context: s,
16
+ event: e
17
+ }), a = (r) => ({
18
+ isEditing: o(),
19
+ isBrowser: d(),
20
+ isServer: !d(),
21
+ getUserAttributes: () => v(),
22
+ trackConversion: (s, e) => {
23
+ var i;
24
+ !(r != null && r.apiKey) || (r == null ? void 0 : r.canTrack) === !1 || m({
25
+ type: "conversion",
26
+ apiKey: r.apiKey,
27
+ canTrack: (i = r.canTrack) != null ? i : !0,
28
+ contentId: r.contentId,
29
+ variationId: r.variationId !== r.contentId ? r.variationId : void 0,
30
+ metadata: {
31
+ ...e || {},
32
+ ...s !== void 0 ? {
33
+ amount: s
34
+ } : {}
35
+ }
36
+ });
37
+ }
38
+ }), c = (r, {
39
+ isExpression: s = !0
40
+ }) => /* we disable this for cases where we definitely don't want a return */ s && !(r.includes(";") || r.includes(" return ") || r.trim().startsWith("return ")) ? `return (${r});` : r;
24
41
  function l({
25
42
  rootState: r,
26
- localState: n,
27
- rootSetState: i
43
+ localState: s,
44
+ rootSetState: e
28
45
  }) {
29
46
  return new Proxy(r, {
30
- get: (e, s) => {
31
- if (n && s in n)
32
- return n[s];
33
- const t = e[s];
34
- return typeof t == "object" && t !== null ? l({
35
- rootState: t,
47
+ get: (i, u) => {
48
+ if (s && u in s)
49
+ return s[u];
50
+ const n = i[u];
51
+ return typeof n == "object" && n !== null ? l({
52
+ rootState: n,
36
53
  localState: void 0,
37
- rootSetState: i ? (o) => {
38
- e[s] = o, i(e);
54
+ rootSetState: e ? (f) => {
55
+ i[u] = f, e(i);
39
56
  } : void 0
40
- }) : t;
57
+ }) : n;
41
58
  },
42
- set: (e, s, t) => {
43
- if (n && s in n)
59
+ set: (i, u, n) => {
60
+ if (s && u in s)
44
61
  throw new Error("Writing to local state is not allowed as it is read-only.");
45
- return e[s] = t, i == null || i(e), !0;
62
+ return i[u] = n, e == null || e(i), !0;
46
63
  }
47
64
  });
48
65
  }
49
66
  export {
50
67
  l as flattenState,
51
- b as getBuilderGlobals,
52
- w as getFunctionArguments,
53
- v as parseCode
68
+ a as getBuilderGlobals,
69
+ B as getFunctionArguments,
70
+ c as parseCode
54
71
  };
@@ -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.24.0",
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.24.0";
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.24.0";
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>;