@builder.io/sdk-react-nextjs 0.16.2 → 0.16.3
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 +24 -24
- package/lib/browser/blocks-exports.mjs +93 -92
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +1 -1
- package/lib/browser/init.cjs +1 -1
- package/lib/browser/init.mjs +1 -1
- package/lib/browser/server-entry-8a47b9f9.cjs +2 -0
- package/lib/browser/{server-entry-242f596f.js → server-entry-b8ecec52.js} +152 -158
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/blocks-exports.cjs +33 -33
- package/lib/edge/blocks-exports.mjs +60 -58
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +1 -1
- package/lib/edge/init.cjs +1 -1
- package/lib/edge/init.mjs +1 -1
- package/lib/edge/server-entry-8a47b9f9.cjs +2 -0
- package/lib/{node/server-entry-fbf4e3a9.js → edge/server-entry-b8ecec52.js} +152 -158
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/node/blocks-exports.cjs +8 -8
- package/lib/node/blocks-exports.mjs +60 -59
- package/lib/node/index.cjs +1 -1
- package/lib/node/index.mjs +2 -2
- package/lib/node/init.cjs +1 -1
- package/lib/node/init.mjs +2 -2
- package/lib/node/{node-runtime-e1243cd6.cjs → node-runtime-e2a21ba1.cjs} +2 -2
- package/lib/node/{node-runtime-42e494ca.js → node-runtime-ffe74dec.js} +3 -2
- package/lib/node/server-entry-8a47b9f9.cjs +2 -0
- package/lib/{edge/server-entry-242f596f.js → node/server-entry-b8ecec52.js} +152 -158
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +1 -1
- package/package.json +1 -1
- package/types/cjs/constants/sdk-version.d.ts +1 -1
- package/types/cjs/functions/register-component.d.ts +2 -2
- package/types/esm/constants/sdk-version.d.ts +1 -1
- package/types/esm/functions/register-component.d.ts +2 -2
- package/lib/browser/server-entry-494604dc.cjs +0 -2
- package/lib/edge/server-entry-494604dc.cjs +0 -2
- package/lib/node/server-entry-db7b41aa.cjs +0 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isEditing, isBrowser, getUserAttributes, TARGET, logger, MSG_PREFIX
|
|
1
|
+
import { isEditing, isBrowser, getUserAttributes, TARGET, logger, MSG_PREFIX } from "./server-entry-b8ecec52.js";
|
|
2
2
|
const getFunctionArguments = ({
|
|
3
3
|
builder: e,
|
|
4
4
|
context: t,
|
|
@@ -27,7 +27,7 @@ const getFunctionArguments = ({
|
|
|
27
27
|
default:
|
|
28
28
|
return TARGET;
|
|
29
29
|
}
|
|
30
|
-
})(), SDK_NAME = `@builder.io/sdk-${SDK_NAME_FOR_TARGET}`, set = (e, t, s) => {
|
|
30
|
+
})(), SDK_NAME = `@builder.io/sdk-${SDK_NAME_FOR_TARGET}`, fastClone = (e) => JSON.parse(JSON.stringify(e)), set = (e, t, s) => {
|
|
31
31
|
if (Object(e) !== e)
|
|
32
32
|
return e;
|
|
33
33
|
const n = Array.isArray(t) ? t : t.toString().match(/[^.[\]]+/g);
|
|
@@ -158,6 +158,7 @@ const getIsolateContext = () => IVM_CONTEXT || setIsolateContext(), runInNode =
|
|
|
158
158
|
}
|
|
159
159
|
};
|
|
160
160
|
export {
|
|
161
|
+
fastClone,
|
|
161
162
|
getBuilderGlobals,
|
|
162
163
|
getFunctionArguments,
|
|
163
164
|
parseCode,
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const ue=require("lru-cache"),I="rsc",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 de=e=>{const t={};return e.forEach((n,r)=>{t[r]=n}),t},U=e=>e instanceof URLSearchParams?de(e):e,V=e=>typeof e=="string"?e:e instanceof URLSearchParams?e.toString():new URLSearchParams(e).toString();function le(){return c()&&window.self!==window.top}function M(e){return le()&&V(e||window.location.search).indexOf("builder.frameEditing=")!==-1}const fe=()=>{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},ge=()=>typeof navigator=="object"&&navigator.userAgent||"",_=()=>{const e=ge(),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=fe();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"}},p=e=>e!=null,he=e=>{if(e==="localhost"||e==="127.0.0.1")return e;const t=e.split(".");return t.length>2?t.slice(1).join("."):e},F=({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}},D=async e=>F(e),pe=e=>e.map(([t,n])=>n?`${t}=${n}`:t).filter(p).join("; "),me=[["secure",""],["SameSite","None"]],ye=({name:e,value:t,expires:n})=>{const o=(c()?location.protocol==="https:":!0)?me:[[]],s=n?[["expires",n.toUTCString()]]:[[]],i=[[e,t],...s,["path","/"],["domain",he(window.location.hostname)],...o];return pe(i)},N=async({name:e,value:t,expires:n,canTrack:r})=>{try{if(!r)return;const o=ye({name:e,value:t,expires:n});document.cookie=o}catch(o){d.warn("[COOKIE] SET error: ",(o==null?void 0:o.message)||o)}},we="builder.tests",k=e=>`${we}.${e}`,Se=({contentId:e})=>D({name:k(e),canTrack:!0}),be=({contentId:e})=>F({name:k(e),canTrack:!0}),Ie=({contentId:e,value:t})=>N({name:k(e),value:t,canTrack:!0}),j=e=>p(e.id)&&p(e.variations)&&Object.keys(e.variations).length>0,ve=({id:e,variations:t})=>{var o;let n=0;const r=Math.random();for(const s in t){const i=(o=t[s])==null?void 0:o.testRatio;if(n+=i,r<n)return s}return e},K=e=>{const t=ve(e);return Ie({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":"")}},Ee=({item:e,canTrack:t})=>{if(!t)return e;if(!e)return;if(!j(e))return e;const n=be({contentId:e.id})||K({variations:e.variations,id:e.id}),r=W({item:e,testGroupId:n});return{...e,...r}},ke=async({item:e,canTrack:t})=>{if(!t||!j(e))return e;const r=await Se({contentId:e.id})||K({variations:e.variations,id:e.id}),o=W({item:e,testGroupId:r});return{...e,...o}},$=e=>p(e)?e:!0,Ce=e=>({type:"builder.registerComponent",data:G(e)}),Pe=e=>{const t=e.toString().trim();return`return (${!t.startsWith("function")&&!t.startsWith("(")?"function ":""}${t}).apply(this, arguments)`};function G(e){return JSON.parse(JSON.stringify(e,(t,n)=>typeof n=="function"?Pe(n):n))}const Re=e=>{const t=e.get("preview"),n=e.get("overrides."+t);return n||d.warn("No previewed ID found in search params."),n};function H(){globalThis._BUILDER_PREVIEW_LRU_CACHE||(globalThis._BUILDER_PREVIEW_LRU_CACHE=new ue.LRUCache({max:500,ttl:1e3*60*5}))}function Oe(e){H();const t=Re(e);return typeof t=="string"?globalThis._BUILDER_PREVIEW_LRU_CACHE.get(t):void 0}function Ae(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function Te(){const e=Ae().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 z=Te();function E(e,t=null,n="."){return Object.keys(e).reduce((r,o)=>{const s=e[o],i=[t,o].filter(Boolean).join(n);return[typeof s=="object",s!==null,!(Array.isArray(s)&&s.length===0)].every(Boolean)?{...r,...E(s,i,n)}:{...r,[i]:s}},{})}function J(e,t,n={}){for(const r in e){const o=e[r],s=t?t+"."+r:r;o&&typeof o=="object"&&!Array.isArray(o)&&!Object.keys(o).find(i=>i.startsWith("$"))?J(o,s,n):n[s]=o}return n}const xe="v3",A="builder.",Be="options.",C=e=>{if(!e)return{};const t=U(e),n={};return Object.keys(t).forEach(r=>{if(r.startsWith(A)){const o=r.replace(A,"").replace(Be,"");n[o]=t[r]}}),n},Le=()=>{if(!c())return{};const e=new URLSearchParams(window.location.search);return C(e)},T=e=>typeof e=="number"&&!isNaN(e)&&e>=0,P=e=>{const{limit:t=30,userAttributes:n,query:r,model:o,apiKey:s,enrich:i,locale:u,apiVersion:y=xe,fields:m,omit:v,offset:l,cacheSeconds:g,staleCacheSeconds:h,sort:w,includeUnpublished:R}=e;if(!s)throw new Error("Missing API key");if(!["v3"].includes(y))throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);const ae=t!==1,a=new URL(`https://cdn.builder.io/api/${y}/content/${o}`);if(a.searchParams.set("apiKey",s),a.searchParams.set("limit",String(t)),a.searchParams.set("noTraverse",String(ae)),a.searchParams.set("includeRefs",String(!0)),u&&a.searchParams.set("locale",u),i&&a.searchParams.set("enrich",String(i)),a.searchParams.set("omit",v||"meta.componentsUsed"),m&&a.searchParams.set("fields",m),Number.isFinite(l)&&l>-1&&a.searchParams.set("offset",String(Math.floor(l))),typeof R=="boolean"&&a.searchParams.set("includeUnpublished",String(R)),g&&T(g)&&a.searchParams.set("cacheSeconds",String(g)),h&&T(h)&&a.searchParams.set("staleCacheSeconds",String(h)),w){const f=E({sort:w});for(const S in f)a.searchParams.set(S,JSON.stringify(f[S]))}const ce={...Le(),...U(e.options||{})},O=E(ce);for(const f in O)a.searchParams.set(f,String(O[f]));if(n&&a.searchParams.set("userAttributes",JSON.stringify(n)),r){const f=J({query:r});for(const S in f)a.searchParams.set(S,JSON.stringify(f[S]))}return a},Ue=e=>"results"in e;async function X(e){const t=await Q({...e,limit:1});return t&&t[0]||null}const Ve=async e=>{var s;const t=P(e);return await(await((s=e.fetch)!=null?s:z)(t.href,e.fetchOptions)).json()},q=async(e,t,n=P(e))=>{const r=$(e.canTrack);if(n.search.includes("preview=")){const s=[];for(const i of t.results){const u=Oe(n.searchParams);s.push(u||i)}t.results=s}if(!r||!(c()||I==="reactNative"))return t.results;try{const s=[];for(const i of t.results)s.push(await ke({item:i,canTrack:r}));t.results=s}catch(s){d.error("Could not process A/B tests. ",s)}return t.results};async function Q(e){try{const t=P(e),n=await Ve(e);return Ue(n)?q(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 Me(e){const t=e||(c()?window.location.search:void 0);return t?V(t).indexOf("builder.preview=")!==-1:!1}function _e(){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 _e().replace(/-/g,"")}const Z="builderSessionId",Fe=async({canTrack:e})=>{if(!e)return;const t=await D({name:Z,canTrack:e});if(p(t))return t;{const n=De();return Ne({id:n,canTrack:e}),n}},De=()=>Y(),Ne=({id:e,canTrack:t})=>N({name:Z,value:e,canTrack:t}),ee=()=>c()&&typeof localStorage!="undefined"?localStorage:void 0,je=({key:e,canTrack:t})=>{var n;try{return t?(n=ee())==null?void 0:n.getItem(e):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},Ke=({key:e,canTrack:t,value:n})=>{var r;try{t&&((r=ee())==null||r.setItem(e,n))}catch(o){console.debug("[LocalStorage] SET error: ",o)}},te="builderVisitorId",We=({canTrack:e})=>{if(!e)return;const t=je({key:te,canTrack:e});if(p(t))return t;{const n=$e();return Ge({id:n,canTrack:e}),n}},$e=()=>Y(),Ge=({id:e,canTrack:t})=>Ke({key:te,value:e,canTrack:t}),He=async({canTrack:e})=>{if(!e)return{visitorId:void 0,sessionId:void 0};const t=await Fe({canTrack:e}),n=We({canTrack:e});return{sessionId:t,visitorId:n}},ze=async({type:e,canTrack:t,apiKey:n,metadata:r,...o})=>({type:e,data:{...o,metadata:{url:location.href,...r},...await He({canTrack:t}),userAttributes:_(),ownerId:n}});async function ne(e){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(e.canTrack&&!M()&&(c()||I==="reactNative"))return fetch("https://cdn.builder.io/api/v1/track",{method:"POST",body:JSON.stringify({events:[await ze(e)]}),headers:{"content-type":"application/json"},mode:"cors"}).catch(t=>{console.error("Failed to track: ",t)})}const Je=e=>ne({...e,canTrack:!0}),Xe=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function re(e,t){if(!t.origin.startsWith("http")&&!t.origin.startsWith("https"))return!1;const n=new URL(t.origin),r=n.hostname;return(e||Xe).findIndex(o=>o.startsWith("*.")?r.endsWith(o.slice(1)):o===r)>-1}const qe="0.16.3",x={};function oe(e,t){let n=x[e];if(n||(n=x[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 Qe=()=>{oe("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 B=!1;const se=(e={})=>{var t,n;B||(B=!0,c()&&((t=window.parent)==null||t.postMessage({type:"builder.sdkInfo",data:{target:I,version:qe,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0}},"*"),(n=window.parent)==null||n.postMessage({type:"builder.updateContent",data:{options:e}},"*"),window.addEventListener("message",r=>{var s,i;if(!re(e.trustedHosts,r))return;const{data:o}=r;if(o!=null&&o.type)switch(o.type){case"builder.evaluate":{const u=o.data.text,y=o.data.arguments||[],m=o.data.id,v=new Function(u);let l,g=null;try{l=v.apply(null,y)}catch(h){g=h}g?(s=window.parent)==null||s.postMessage({type:"builder.evaluateError",data:{id:m,error:g.message}},"*"):l&&typeof l.then=="function"?l.then(h=>{var w;(w=window.parent)==null||w.postMessage({type:"builder.evaluateResult",data:{id:m,result:h}},"*")}).catch(console.error):(i=window.parent)==null||i.postMessage({type:"builder.evaluateResult",data:{result:l,id:m}},"*");break}}})))},ie=({model:e,trustedHosts:t,callbacks:n})=>r=>{if(!re(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,i=s.key||s.alias||s.entry||s.modelName,u=s.data;i===e&&n.contentUpdate(u);break}}},Ye=(e,t,n)=>{if(!c)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};se();const r=ie({callbacks:{contentUpdate:t,animation:()=>{},configureSdk:()=>{}},model:e,trustedHosts:n==null?void 0:n.trustedHosts});return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},L={};function Ze(e){if(c()){Object.assign(L,e);const t={type:"builder.settingsChange",data:L};parent.postMessage(t,"*")}}const et=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:C(e.searchParams||((s=e.url)==null?void 0:s.searchParams)||e.options)};return{apiKey:n.apiKey,model:n.model,content:await X(n)}};exports.MSG_PREFIX=b;exports.TARGET=I;exports._processContentResult=q;exports._track=ne;exports.checkIsDefined=p;exports.createEditorListener=ie;exports.createRegisterComponentMessage=Ce;exports.fetch=z;exports.fetchBuilderProps=et;exports.fetchEntries=Q;exports.fetchOneEntry=X;exports.getBuilderSearchParams=C;exports.getDefaultCanTrack=$;exports.getUserAttributes=_;exports.handleABTestingSync=Ee;exports.init=H;exports.isBrowser=c;exports.isEditing=M;exports.isPreviewing=Me;exports.logger=d;exports.register=oe;exports.registerInsertMenu=Qe;exports.serializeComponentInfo=G;exports.setEditorSettings=Ze;exports.setupBrowserForEditing=se;exports.subscribeToEditor=Ye;exports.track=Je;
|