@builder.io/sdk-react-nextjs 0.16.18 → 0.16.19

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/content/components/enable-editor.cjs +1 -1
  2. package/lib/browser/components/content/components/enable-editor.mjs +107 -105
  3. package/lib/browser/components/content/content.cjs +1 -1
  4. package/lib/browser/components/content/content.mjs +23 -21
  5. package/lib/browser/components/content-variants/content-variants.cjs +1 -1
  6. package/lib/browser/components/content-variants/content-variants.mjs +10 -8
  7. package/lib/browser/constants/sdk-version.cjs +1 -1
  8. package/lib/browser/constants/sdk-version.mjs +1 -1
  9. package/lib/browser/functions/get-content/generate-content-url.cjs +1 -1
  10. package/lib/browser/functions/get-content/generate-content-url.mjs +24 -23
  11. package/lib/browser/functions/track/index.cjs +1 -1
  12. package/lib/browser/functions/track/index.mjs +21 -19
  13. package/lib/edge/components/content/components/enable-editor.cjs +1 -1
  14. package/lib/edge/components/content/components/enable-editor.mjs +107 -105
  15. package/lib/edge/components/content/content.cjs +1 -1
  16. package/lib/edge/components/content/content.mjs +23 -21
  17. package/lib/edge/components/content-variants/content-variants.cjs +1 -1
  18. package/lib/edge/components/content-variants/content-variants.mjs +10 -8
  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/get-content/generate-content-url.cjs +1 -1
  22. package/lib/edge/functions/get-content/generate-content-url.mjs +24 -23
  23. package/lib/edge/functions/track/index.cjs +1 -1
  24. package/lib/edge/functions/track/index.mjs +21 -19
  25. package/lib/node/components/content/components/enable-editor.cjs +1 -1
  26. package/lib/node/components/content/components/enable-editor.mjs +107 -105
  27. package/lib/node/components/content/content.cjs +1 -1
  28. package/lib/node/components/content/content.mjs +23 -21
  29. package/lib/node/components/content-variants/content-variants.cjs +1 -1
  30. package/lib/node/components/content-variants/content-variants.mjs +10 -8
  31. package/lib/node/constants/sdk-version.cjs +1 -1
  32. package/lib/node/constants/sdk-version.mjs +1 -1
  33. package/lib/node/functions/get-content/generate-content-url.cjs +1 -1
  34. package/lib/node/functions/get-content/generate-content-url.mjs +24 -23
  35. package/lib/node/functions/track/index.cjs +1 -1
  36. package/lib/node/functions/track/index.mjs +21 -19
  37. package/package.json +1 -1
  38. package/types/cjs/components/content/components/enable-editor.d.ts +1 -1
  39. package/types/cjs/components/content-variants/content-variants.types.d.ts +4 -0
  40. package/types/cjs/constants/sdk-version.d.ts +1 -1
  41. package/types/cjs/functions/get-content/types.d.ts +4 -0
  42. package/types/cjs/functions/track/index.d.ts +3 -1
  43. package/types/esm/components/content/components/enable-editor.d.ts +1 -1
  44. package/types/esm/components/content-variants/content-variants.types.d.ts +4 -0
  45. package/types/esm/constants/sdk-version.d.ts +1 -1
  46. package/types/esm/functions/get-content/types.d.ts +4 -0
  47. package/types/esm/functions/track/index.d.ts +3 -1
@@ -1,8 +1,8 @@
1
- import { flatten as g, flattenMongoQuery as U } from "../../helpers/flatten.mjs";
2
- import { normalizeSearchParams as A } from "../../helpers/search/search.mjs";
3
- import { DEFAULT_API_VERSION as O } from "../../types/api-version.mjs";
4
- import { getBuilderSearchParamsFromWindow as k } from "../get-builder-search-params/index.mjs";
5
- const y = (s) => typeof s == "number" && !isNaN(s) && s >= 0, J = (s) => {
1
+ import { flatten as g, flattenMongoQuery as O } from "../../helpers/flatten.mjs";
2
+ import { normalizeSearchParams as k } from "../../helpers/search/search.mjs";
3
+ import { DEFAULT_API_VERSION as E } from "../../types/api-version.mjs";
4
+ import { getBuilderSearchParamsFromWindow as I } from "../get-builder-search-params/index.mjs";
5
+ const y = (r) => typeof r == "number" && !isNaN(r) && r >= 0, M = (r) => {
6
6
  const {
7
7
  limit: c = 30,
8
8
  userAttributes: m,
@@ -11,42 +11,43 @@ const y = (s) => typeof s == "number" && !isNaN(s) && s >= 0, J = (s) => {
11
11
  apiKey: l,
12
12
  enrich: h,
13
13
  locale: d,
14
- apiVersion: a = O,
14
+ apiVersion: a = E,
15
15
  fields: u,
16
16
  omit: N,
17
17
  offset: i,
18
18
  cacheSeconds: n,
19
19
  staleCacheSeconds: o,
20
20
  sort: P,
21
- includeUnpublished: S
22
- } = s;
21
+ includeUnpublished: p,
22
+ apiHost: v
23
+ } = r;
23
24
  if (!l)
24
25
  throw new Error("Missing API key");
25
26
  if (!["v3"].includes(a))
26
27
  throw new Error(`Invalid apiVersion: expected 'v3', received '${a}'`);
27
- const v = c !== 1, e = new URL(`https://cdn.builder.io/api/${a}/content/${b}`);
28
- if (e.searchParams.set("apiKey", l), e.searchParams.set("limit", String(c)), e.searchParams.set("noTraverse", String(v)), e.searchParams.set("includeRefs", String(!0)), d && e.searchParams.set("locale", d), h && e.searchParams.set("enrich", String(h)), e.searchParams.set("omit", N || "meta.componentsUsed"), u && e.searchParams.set("fields", u), Number.isFinite(i) && i > -1 && e.searchParams.set("offset", String(Math.floor(i))), typeof S == "boolean" && e.searchParams.set("includeUnpublished", String(S)), n && y(n) && e.searchParams.set("cacheSeconds", String(n)), o && y(o) && e.searchParams.set("staleCacheSeconds", String(o)), P) {
29
- const r = g({
28
+ const U = c !== 1, w = v || "https://cdn.builder.io", e = new URL(`${w}/api/${a}/content/${b}`);
29
+ if (e.searchParams.set("apiKey", l), e.searchParams.set("limit", String(c)), e.searchParams.set("noTraverse", String(U)), e.searchParams.set("includeRefs", String(!0)), d && e.searchParams.set("locale", d), h && e.searchParams.set("enrich", String(h)), e.searchParams.set("omit", N || "meta.componentsUsed"), u && e.searchParams.set("fields", u), Number.isFinite(i) && i > -1 && e.searchParams.set("offset", String(Math.floor(i))), typeof p == "boolean" && e.searchParams.set("includeUnpublished", String(p)), n && y(n) && e.searchParams.set("cacheSeconds", String(n)), o && y(o) && e.searchParams.set("staleCacheSeconds", String(o)), P) {
30
+ const s = g({
30
31
  sort: P
31
32
  });
32
- for (const t in r)
33
- e.searchParams.set(t, JSON.stringify(r[t]));
33
+ for (const t in s)
34
+ e.searchParams.set(t, JSON.stringify(s[t]));
34
35
  }
35
- const w = {
36
- ...k(),
37
- ...A(s.options || {})
38
- }, p = g(w);
39
- for (const r in p)
40
- e.searchParams.set(r, String(p[r]));
36
+ const A = {
37
+ ...I(),
38
+ ...k(r.options || {})
39
+ }, S = g(A);
40
+ for (const s in S)
41
+ e.searchParams.set(s, String(S[s]));
41
42
  if (m && e.searchParams.set("userAttributes", JSON.stringify(m)), f) {
42
- const r = U({
43
+ const s = O({
43
44
  query: f
44
45
  });
45
- for (const t in r)
46
- e.searchParams.set(t, JSON.stringify(r[t]));
46
+ for (const t in s)
47
+ e.searchParams.set(t, JSON.stringify(s[t]));
47
48
  }
48
49
  return e;
49
50
  };
50
51
  export {
51
- J as generateContentUrl
52
+ M as generateContentUrl
52
53
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../../constants/target.cjs"),a=require("../../helpers/logger.cjs"),c=require("../../helpers/sdk-headers.cjs"),d=require("../../helpers/sessionId.cjs"),u=require("../../helpers/visitorId.cjs"),g=require("../is-browser.cjs"),l=require("../is-editing.cjs"),y=require("./helpers.cjs"),I=async({canTrack:e})=>{if(!e)return{visitorId:void 0,sessionId:void 0};const t=await d.getSessionId({canTrack:e}),r=u.getVisitorId({canTrack:e});return{sessionId:t,visitorId:r}},k=async({type:e,canTrack:t,apiKey:r,metadata:s,...o})=>({type:e,data:{...o,metadata:{url:location.href,...s},...await I({canTrack:t}),userAttributes:y.getUserAttributes(),ownerId:r}});async function i(e){if(!e.apiKey){a.logger.error("Missing API key for track call. Please provide your API key.");return}if(e.canTrack&&!l.isEditing()&&(g.isBrowser()||n.TARGET==="reactNative"))return fetch("https://cdn.builder.io/api/v1/track",{method:"POST",body:JSON.stringify({events:[await k(e)]}),headers:{"content-type":"application/json",...c.getSdkHeaders()},mode:"cors"}).catch(t=>{console.error("Failed to track: ",t)})}const f=e=>i({...e,canTrack:!0});exports._track=i;exports.track=f;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../../constants/target.cjs"),a=require("../../helpers/logger.cjs"),c=require("../../helpers/sdk-headers.cjs"),d=require("../../helpers/sessionId.cjs"),u=require("../../helpers/visitorId.cjs"),g=require("../is-browser.cjs"),l=require("../is-editing.cjs"),y=require("./helpers.cjs"),I=async({canTrack:e})=>{if(!e)return{visitorId:void 0,sessionId:void 0};const t=await d.getSessionId({canTrack:e}),r=u.getVisitorId({canTrack:e});return{sessionId:t,visitorId:r}},k=async({type:e,canTrack:t,apiKey:r,metadata:i,...o})=>({type:e,data:{...o,metadata:{url:location.href,...i},...await I({canTrack:t}),userAttributes:y.getUserAttributes(),ownerId:r}});async function s({apiHost:e,...t}){if(!t.apiKey){a.logger.error("Missing API key for track call. Please provide your API key.");return}return!t.canTrack||l.isEditing()||!(g.isBrowser()||n.TARGET==="reactNative")?void 0:fetch(`${e||"https://cdn.builder.io"}/api/v1/track`,{method:"POST",body:JSON.stringify({events:[await k(t)]}),headers:{"content-type":"application/json",...c.getSdkHeaders()},mode:"cors"}).catch(i=>{console.error("Failed to track: ",i)})}const f=e=>s({...e,canTrack:!0});exports._track=s;exports.track=f;
@@ -23,7 +23,7 @@ const u = async ({
23
23
  sessionId: r,
24
24
  visitorId: e
25
25
  };
26
- }, y = async ({
26
+ }, l = async ({
27
27
  type: t,
28
28
  canTrack: r,
29
29
  apiKey: e,
@@ -44,31 +44,33 @@ const u = async ({
44
44
  ownerId: e
45
45
  }
46
46
  });
47
- async function g(t) {
48
- if (!t.apiKey) {
47
+ async function y({
48
+ apiHost: t,
49
+ ...r
50
+ }) {
51
+ if (!r.apiKey) {
49
52
  s.error("Missing API key for track call. Please provide your API key.");
50
53
  return;
51
54
  }
52
- if (t.canTrack && !f() && (m() || a === "reactNative"))
53
- return fetch("https://cdn.builder.io/api/v1/track", {
54
- method: "POST",
55
- body: JSON.stringify({
56
- events: [await y(t)]
57
- }),
58
- headers: {
59
- "content-type": "application/json",
60
- ...n()
61
- },
62
- mode: "cors"
63
- }).catch((r) => {
64
- console.error("Failed to track: ", r);
65
- });
55
+ return !r.canTrack || f() || !(m() || a === "reactNative") ? void 0 : fetch(`${t || "https://cdn.builder.io"}/api/v1/track`, {
56
+ method: "POST",
57
+ body: JSON.stringify({
58
+ events: [await l(r)]
59
+ }),
60
+ headers: {
61
+ "content-type": "application/json",
62
+ ...n()
63
+ },
64
+ mode: "cors"
65
+ }).catch((o) => {
66
+ console.error("Failed to track: ", o);
67
+ });
66
68
  }
67
- const E = (t) => g({
69
+ const E = (t) => y({
68
70
  ...t,
69
71
  canTrack: !0
70
72
  });
71
73
  export {
72
- g as _track,
74
+ y as _track,
73
75
  E as track
74
76
  };
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.16.18",
4
+ "version": "0.16.19",
5
5
  "homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/nextjs",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- type BuilderEditorProps = Omit<ContentProps, "customComponents" | "apiVersion" | "isSsrAbTest" | "blocksWrapper" | "blocksWrapperProps" | "isNestedRender" | "linkComponent"> & {
2
+ type BuilderEditorProps = Omit<ContentProps, "customComponents" | "apiVersion" | "isSsrAbTest" | "blocksWrapper" | "blocksWrapperProps" | "linkComponent"> & {
3
3
  builderContextSignal: BuilderContextInterface;
4
4
  setBuilderContextSignal?: (signal: any) => any;
5
5
  children?: any;
@@ -26,6 +26,10 @@ export interface ContentVariantsPrps extends ExtraFrameworkProps {
26
26
  * Your API Key: needed to enable visual editing, and to dynamically fetch symbols (required).
27
27
  */
28
28
  apiKey: string;
29
+ /**
30
+ * Sets the host of Builder API calls. (Defaults to global `https://cdn.builder.io`)
31
+ */
32
+ apiHost?: string;
29
33
  apiVersion?: ApiVersion;
30
34
  /**
31
35
  * An array of custom components to register (optional).
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.16.18";
1
+ export declare const SDK_VERSION = "0.16.19";
@@ -136,4 +136,8 @@ export interface GetContentOptions {
136
136
  * Optional fetch options to be passed as the second argument to the `fetch` function.
137
137
  */
138
138
  fetchOptions?: object;
139
+ /**
140
+ * Sets the host of Builder API calls. (Defaults to global `https://cdn.builder.io`)
141
+ */
142
+ apiHost?: string;
139
143
  }
@@ -46,6 +46,8 @@ type EventProperties = Pick<Event, 'type'> & Pick<Event['data'], 'contentId' | '
46
46
  [index: string]: any;
47
47
  };
48
48
  export type EventProps = EventProperties & CanTrack;
49
- export declare function _track(eventProps: EventProps): Promise<void | Response>;
49
+ export declare function _track({ apiHost, ...eventProps }: EventProps & {
50
+ apiHost?: string;
51
+ }): Promise<void | Response>;
50
52
  export declare const track: (args: EventProperties) => Promise<void | Response>;
51
53
  export {};
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- type BuilderEditorProps = Omit<ContentProps, "customComponents" | "apiVersion" | "isSsrAbTest" | "blocksWrapper" | "blocksWrapperProps" | "isNestedRender" | "linkComponent"> & {
2
+ type BuilderEditorProps = Omit<ContentProps, "customComponents" | "apiVersion" | "isSsrAbTest" | "blocksWrapper" | "blocksWrapperProps" | "linkComponent"> & {
3
3
  builderContextSignal: BuilderContextInterface;
4
4
  setBuilderContextSignal?: (signal: any) => any;
5
5
  children?: any;
@@ -26,6 +26,10 @@ export interface ContentVariantsPrps extends ExtraFrameworkProps {
26
26
  * Your API Key: needed to enable visual editing, and to dynamically fetch symbols (required).
27
27
  */
28
28
  apiKey: string;
29
+ /**
30
+ * Sets the host of Builder API calls. (Defaults to global `https://cdn.builder.io`)
31
+ */
32
+ apiHost?: string;
29
33
  apiVersion?: ApiVersion;
30
34
  /**
31
35
  * An array of custom components to register (optional).
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.16.18";
1
+ export declare const SDK_VERSION = "0.16.19";
@@ -136,4 +136,8 @@ export interface GetContentOptions {
136
136
  * Optional fetch options to be passed as the second argument to the `fetch` function.
137
137
  */
138
138
  fetchOptions?: object;
139
+ /**
140
+ * Sets the host of Builder API calls. (Defaults to global `https://cdn.builder.io`)
141
+ */
142
+ apiHost?: string;
139
143
  }
@@ -46,6 +46,8 @@ type EventProperties = Pick<Event, 'type'> & Pick<Event['data'], 'contentId' | '
46
46
  [index: string]: any;
47
47
  };
48
48
  export type EventProps = EventProperties & CanTrack;
49
- export declare function _track(eventProps: EventProps): Promise<void | Response>;
49
+ export declare function _track({ apiHost, ...eventProps }: EventProps & {
50
+ apiHost?: string;
51
+ }): Promise<void | Response>;
50
52
  export declare const track: (args: EventProperties) => Promise<void | Response>;
51
53
  export {};