@builder.io/sdk-react 0.12.4 → 0.12.5
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/index.cjs +22 -22
- package/lib/browser/index.mjs +415 -405
- package/lib/{edge/server-entry-0e4f0637.js → browser/server-entry-b9bdd327.js} +4 -4
- package/lib/browser/{server-entry-bcb725be.cjs → server-entry-fc715776.cjs} +1 -1
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/index.cjs +27 -27
- package/lib/edge/index.mjs +460 -449
- package/lib/{browser/server-entry-0e4f0637.js → edge/server-entry-57d4ae22.js} +3 -3
- package/lib/edge/{server-entry-bcb725be.cjs → server-entry-fc715776.cjs} +1 -1
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/node/index.cjs +6 -6
- package/lib/node/index.mjs +161 -150
- package/lib/node/{server-entry-9aa733e8.js → server-entry-0457c4c8.js} +2 -2
- package/lib/node/server-entry.mjs +1 -1
- package/package.json +1 -1
- package/types/constants/sdk-version.d.ts +1 -1
- package/types/functions/evaluate/should-force-browser-runtime-in-node.d.ts +1 -0
|
@@ -45,7 +45,7 @@ const Q = () => {
|
|
|
45
45
|
host: (r == null ? void 0 : r.host) || (r == null ? void 0 : r.hostname),
|
|
46
46
|
device: n ? "tablet" : e.any() ? "mobile" : "desktop"
|
|
47
47
|
};
|
|
48
|
-
},
|
|
48
|
+
}, d = (t) => t != null, L = (t) => JSON.parse(JSON.stringify(t)), et = (t) => {
|
|
49
49
|
if (t === "localhost" || t === "127.0.0.1")
|
|
50
50
|
return t;
|
|
51
51
|
const e = t.split(".");
|
|
@@ -536,9 +536,9 @@ export {
|
|
|
536
536
|
B as i,
|
|
537
537
|
a as j,
|
|
538
538
|
tt as k,
|
|
539
|
-
l,
|
|
540
|
-
|
|
541
|
-
|
|
539
|
+
d as l,
|
|
540
|
+
l as m,
|
|
541
|
+
L as n,
|
|
542
542
|
dt as o,
|
|
543
543
|
$t as p,
|
|
544
544
|
mt as q,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const p="react",h="[Builder.io]: ",l={log:(...t)=>console.log(h,...t),error:(...t)=>console.error(h,...t),warn:(...t)=>console.warn(h,...t),debug:(...t)=>console.debug(h,...t)};function a(){return typeof window!="undefined"&&typeof document!="undefined"}function rt(){return a()&&window.self!==window.top}function v(){return rt()&&window.location.search.indexOf("builder.frameEditing=")!==-1}const ot=()=>{if(a()){const t=new URL(location.href);return t.pathname===""&&(t.pathname="/"),t}else return console.warn("Cannot get location for tracking in non-browser environment"),null},st=()=>typeof navigator=="object"&&navigator.userAgent||"",U=()=>{const t=st(),e={Android(){return t.match(/Android/i)},BlackBerry(){return t.match(/BlackBerry/i)},iOS(){return t.match(/iPhone|iPod/i)},Opera(){return t.match(/Opera Mini/i)},Windows(){return t.match(/IEMobile/i)||t.match(/WPDesktop/i)},any(){return e.Android()||e.BlackBerry()||e.iOS()||e.Opera()||e.Windows()||p==="reactNative"}},n=t.match(/Tablet|iPad/i),r=ot();return{urlPath:r==null?void 0:r.pathname,host:(r==null?void 0:r.host)||(r==null?void 0:r.hostname),device:n?"tablet":e.any()?"mobile":"desktop"}},I=t=>JSON.parse(JSON.stringify(t)),
|
|
1
|
+
"use strict";const p="react",h="[Builder.io]: ",l={log:(...t)=>console.log(h,...t),error:(...t)=>console.error(h,...t),warn:(...t)=>console.warn(h,...t),debug:(...t)=>console.debug(h,...t)};function a(){return typeof window!="undefined"&&typeof document!="undefined"}function rt(){return a()&&window.self!==window.top}function v(){return rt()&&window.location.search.indexOf("builder.frameEditing=")!==-1}const ot=()=>{if(a()){const t=new URL(location.href);return t.pathname===""&&(t.pathname="/"),t}else return console.warn("Cannot get location for tracking in non-browser environment"),null},st=()=>typeof navigator=="object"&&navigator.userAgent||"",U=()=>{const t=st(),e={Android(){return t.match(/Android/i)},BlackBerry(){return t.match(/BlackBerry/i)},iOS(){return t.match(/iPhone|iPod/i)},Opera(){return t.match(/Opera Mini/i)},Windows(){return t.match(/IEMobile/i)||t.match(/WPDesktop/i)},any(){return e.Android()||e.BlackBerry()||e.iOS()||e.Opera()||e.Windows()||p==="reactNative"}},n=t.match(/Tablet|iPad/i),r=ot();return{urlPath:r==null?void 0:r.pathname,host:(r==null?void 0:r.host)||(r==null?void 0:r.hostname),device:n?"tablet":e.any()?"mobile":"desktop"}},d=t=>t!=null,I=t=>JSON.parse(JSON.stringify(t)),it=t=>{if(t==="localhost"||t==="127.0.0.1")return t;const e=t.split(".");return e.length>2?e.slice(1).join("."):t},F=({name:t,canTrack:e})=>{var n;try{return e?(n=document.cookie.split("; ").find(r=>r.startsWith(`${t}=`)))==null?void 0:n.split("=")[1]:void 0}catch(r){l.warn("[COOKIE] GET error: ",(r==null?void 0:r.message)||r);return}},M=async t=>F(t),at=t=>t.map(([e,n])=>n?`${e}=${n}`:e).filter(d).join("; "),ct=[["secure",""],["SameSite","None"]],ut=({name:t,value:e,expires:n})=>{const o=(a()?location.protocol==="https:":!0)?ct:[[]],s=n?[["expires",n.toUTCString()]]:[[]],c=[[t,e],...s,["path","/"],["domain",it(window.location.hostname)],...o];return at(c)},D=async({name:t,value:e,expires:n,canTrack:r})=>{try{if(!r)return;const o=ut({name:t,value:e,expires:n});document.cookie=o}catch(o){l.warn("[COOKIE] SET error: ",(o==null?void 0:o.message)||o)}},lt="builder.tests",C=t=>`${lt}.${t}`,dt=({contentId:t})=>M({name:C(t),canTrack:!0}),ft=({contentId:t})=>F({name:C(t),canTrack:!0}),ht=({contentId:t,value:e})=>D({name:C(t),value:e,canTrack:!0}),K=t=>d(t.id)&&d(t.variations)&&Object.keys(t.variations).length>0,gt=({id:t,variations:e})=>{var o;let n=0;const r=Math.random();for(const s in e){const c=(o=e[s])==null?void 0:o.testRatio;if(n+=c,r<n)return s}return t},_=t=>{const e=gt(t);return ht({contentId:t.id,value:e}).catch(n=>{l.error("could not store A/B test variation: ",n)}),e},G=({item:t,testGroupId:e})=>{const n=t.variations[e];return e===t.id||!n?{testVariationId:t.id,testVariationName:"Default"}:{data:n.data,testVariationId:n.id,testVariationName:n.name||(n.id===t.id?"Default":"")}},pt=({item:t,canTrack:e})=>{if(!e)return t;if(!t)return;if(!K(t))return t;const n=ft({contentId:t.id})||_({variations:t.variations,id:t.id}),r=G({item:t,testGroupId:n});return{...t,...r}},yt=async({item:t,canTrack:e})=>{if(!e||!K(t))return t;const r=await dt({contentId:t.id})||_({variations:t.variations,id:t.id}),o=G({item:t,testGroupId:r});return{...t,...o}},W=t=>d(t)?t:!0,mt=[],St=t=>({type:"builder.registerComponent",data:J(t)}),wt=t=>{const e=t.toString().trim();return`return (${!e.startsWith("function")&&!e.startsWith("(")?"function ":""}${e}).apply(this, arguments)`},bt=t=>typeof t=="function"?wt(t):I(t),J=({inputs:t,...e})=>({...I(e),inputs:t==null?void 0:t.map(n=>Object.entries(n).reduce((r,[o,s])=>({...r,[o]:bt(s)}),{}))});function vt(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function It(){const t=vt().fetch;if(typeof t=="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
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 t}const z=It();function g(t,e=null,n="."){return Object.keys(t).reduce((r,o)=>{const s=t[o],c=[e,o].filter(Boolean).join(n);return[typeof s=="object",s!==null,!(Array.isArray(s)&&s.length===0)].every(Boolean)?{...r,...g(s,c,n)}:{...r,[c]:s}},{})}const Ct="v3",L="builder.",kt="options.",Et=t=>{const e={};return t.forEach((n,r)=>{e[r]=n}),e},k=t=>{if(!t)return{};const e=X(t),n={};return Object.keys(e).forEach(r=>{if(r.startsWith(L)){const o=r.replace(L,"").replace(kt,"");n[o]=e[r]}}),n},Ot=()=>{if(!a())return{};const t=new URLSearchParams(window.location.search);return k(t)},X=t=>t instanceof URLSearchParams?Et(t):t,N=t=>typeof t=="number"&&!isNaN(t)&&t>=0,E=t=>{let{noTraverse:e=!1}=t;const{limit:n=30,userAttributes:r,query:o,model:s,apiKey:c,includeRefs:y=!0,enrich:A,locale:x,apiVersion:m=Ct,fields:T,omit:et,offset:S,cacheSeconds:w,staleCacheSeconds:b,sort:R,includeUnpublished:B}=t;if(!c)throw new Error("Missing API key");if(!["v2","v3"].includes(m))throw new Error(`Invalid apiVersion: expected 'v2' or 'v3', received '${m}'`);(t.limit===void 0||t.limit>1)&&!("noTraverse"in t)&&(e=!0);const i=new URL(`https://cdn.builder.io/api/${m}/content/${s}?apiKey=${c}&limit=${n}&noTraverse=${e}&includeRefs=${y}${x?`&locale=${x}`:""}${A?`&enrich=${A}`:""}`);if(i.searchParams.set("omit",et||"meta.componentsUsed"),T&&i.searchParams.set("fields",T),Number.isFinite(S)&&S>-1&&i.searchParams.set("offset",String(Math.floor(S))),typeof B=="boolean"&&i.searchParams.set("includeUnpublished",String(B)),w&&N(w)&&i.searchParams.set("cacheSeconds",String(w)),b&&N(b)&&i.searchParams.set("staleCacheSeconds",String(b)),R){const u=g({sort:R});for(const f in u)i.searchParams.set(f,JSON.stringify(u[f]))}const nt={...Ot(),...X(t.options||{})},V=g(nt);for(const u in V)i.searchParams.set(u,String(V[u]));if(r&&i.searchParams.set("userAttributes",JSON.stringify(r)),o){const u=g({query:o});for(const f in u)i.searchParams.set(f,JSON.stringify(u[f]))}return i},Pt=t=>"results"in t;async function O(t){const e=await P({...t,limit:1});return e&&e[0]||null}const At=O,xt=async t=>{const e=E(t);return await(await z(e.href)).json()},q=async(t,e,n=E(t))=>{const r=W(t.canTrack);if(n.search.includes("preview="),!r||!(a()||p==="reactNative"))return e.results;try{const o=[];for(const s of e.results)o.push(await yt({item:s,canTrack:r}));e.results=o}catch(o){l.error("Could not process A/B tests. ",o)}return e.results};async function P(t){try{const e=E(t),n=await xt(t);return Pt(n)?q(t,n):(l.error("Error fetching data. ",{url:e,content:n,options:t}),null)}catch(e){return l.error("Error fetching data. ",e),null}}const Tt=P;function Rt(){return!a()||v()?!1:location.search.indexOf("builder.preview=")!==-1}function Bt(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const e=Math.random()*16|0;return(t=="x"?e:e&3|8).toString(16)})}function H(){return Bt().replace(/-/g,"")}const Y="builderSessionId",Vt=async({canTrack:t})=>{if(!t)return;const e=await M({name:Y,canTrack:t});if(d(e))return e;{const n=Lt();return Nt({id:n,canTrack:t}),n}},Lt=()=>H(),Nt=({id:t,canTrack:e})=>D({name:Y,value:t,canTrack:e}),Q=()=>a()&&typeof localStorage!="undefined"?localStorage:void 0,$t=({key:t,canTrack:e})=>{var n;try{return e?(n=Q())==null?void 0:n.getItem(t):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},jt=({key:t,canTrack:e,value:n})=>{var r;try{e&&((r=Q())==null||r.setItem(t,n))}catch(o){console.debug("[LocalStorage] SET error: ",o)}},Z="builderVisitorId",Ut=({canTrack:t})=>{if(!t)return;const e=$t({key:Z,canTrack:t});if(d(e))return e;{const n=Ft();return Mt({id:n,canTrack:t}),n}},Ft=()=>H(),Mt=({id:t,canTrack:e})=>jt({key:Z,value:t,canTrack:e}),Dt=async({canTrack:t})=>{if(!t)return{visitorId:void 0,sessionId:void 0};const e=await Vt({canTrack:t}),n=Ut({canTrack:t});return{sessionId:e,visitorId:n}},Kt=async({type:t,canTrack:e,apiKey:n,metadata:r,...o})=>({type:t,data:{...o,metadata:{url:location.href,...r},...await Dt({canTrack:e}),userAttributes:U(),ownerId:n}});async function tt(t){if(!t.apiKey){l.error("Missing API key for track call. Please provide your API key.");return}if(t.canTrack&&!v()&&(a()||p==="reactNative"))return fetch("https://cdn.builder.io/api/v1/track",{method:"POST",body:JSON.stringify({events:[await Kt(t)]}),headers:{"content-type":"application/json"},mode:"cors"}).catch(e=>{console.error("Failed to track: ",e)})}const _t=t=>tt({...t,canTrack:!0}),$={};function Gt(t,e){let n=$[t];if(n||(n=$[t]=[]),n.push(e),a()){const r={type:"builder.register",data:{type:t,info:e}};try{parent.postMessage(r,"*"),parent!==window&&window.postMessage(r,"*")}catch(o){console.debug("Could not postmessage",o)}}}const j={};function Wt(t){if(a()){Object.assign(j,t);const e={type:"builder.settingsChange",data:j};parent.postMessage(e,"*")}}const Jt=async t=>{var r,o,s;const e=t.path||((r=t.url)==null?void 0:r.pathname)||((o=t.userAttributes)==null?void 0:o.urlPath),n={...t,apiKey:t.apiKey,model:t.model||"page",userAttributes:{...t.userAttributes,...e?{urlPath:e}:{}},options:k(t.searchParams||((s=t.url)==null?void 0:s.searchParams)||t.options)};return{apiKey:n.apiKey,model:n.model,content:await O(n)}};exports.TARGET=p;exports._processContentResult=q;exports._track=tt;exports.checkIsDefined=d;exports.components=mt;exports.createRegisterComponentMessage=St;exports.fastClone=I;exports.fetch=z;exports.fetchBuilderProps=Jt;exports.fetchEntries=P;exports.fetchOneEntry=O;exports.getAllContent=Tt;exports.getBuilderSearchParams=k;exports.getContent=At;exports.getDefaultCanTrack=W;exports.getUserAttributes=U;exports.handleABTestingSync=pt;exports.isBrowser=a;exports.isEditing=v;exports.isPreviewing=Rt;exports.logger=l;exports.register=Gt;exports.serializeComponentInfo=J;exports.setEditorSettings=Wt;exports.track=_t;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./server-entry-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./server-entry-fc715776.cjs");exports._processContentResult=e._processContentResult;exports.createRegisterComponentMessage=e.createRegisterComponentMessage;exports.fetchBuilderProps=e.fetchBuilderProps;exports.fetchEntries=e.fetchEntries;exports.fetchOneEntry=e.fetchOneEntry;exports.getAllContent=e.getAllContent;exports.getBuilderSearchParams=e.getBuilderSearchParams;exports.getContent=e.getContent;exports.isEditing=e.isEditing;exports.isPreviewing=e.isPreviewing;exports.register=e.register;exports.setEditorSettings=e.setEditorSettings;exports.track=e.track;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as t, c as a, h as r, f as i, b as n, g, e as o, d as c, i as d, a as f, r as h, s as l, t as p } from "./server-entry-
|
|
1
|
+
import { _ as t, c as a, h as r, f as i, b as n, g, e as o, d as c, i as d, a as f, r as h, s as l, t as p } from "./server-entry-b9bdd327.js";
|
|
2
2
|
export {
|
|
3
3
|
t as _processContentResult,
|
|
4
4
|
a as createRegisterComponentMessage,
|