@builder.io/sdk-react 0.9.0 → 0.10.0
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 +17 -17
- package/lib/browser/index.mjs +363 -362
- package/lib/browser/server-entry-df9eba5d.cjs +2 -0
- package/lib/browser/{server-entry-0aebe4be.js → server-entry-f978b3a5.js} +7 -7
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/index.cjs +20 -20
- package/lib/edge/index.mjs +239 -238
- package/lib/edge/server-entry-df9eba5d.cjs +2 -0
- package/lib/edge/{server-entry-0aebe4be.js → server-entry-f978b3a5.js} +7 -7
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/node/index.cjs +14 -14
- package/lib/node/index.mjs +200 -199
- package/lib/node/{server-entry-e4cd1e05.js → server-entry-46908b1b.js} +7 -7
- package/lib/node/server-entry-df9eba5d.cjs +2 -0
- package/lib/node/server-entry.cjs +1 -1
- 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/get-content/index.d.ts +2 -2
- package/lib/browser/server-entry-a5d2c777.cjs +0 -2
- package/lib/edge/server-entry-a5d2c777.cjs +0 -2
- package/lib/node/server-entry-a5d2c777.cjs +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const 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"}const p="react";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)),d=t=>t!=null,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
|
+
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;
|
|
@@ -5,7 +5,7 @@ const h = "[Builder.io]: ", l = {
|
|
|
5
5
|
debug: (...t) => console.debug(h, ...t)
|
|
6
6
|
};
|
|
7
7
|
function a() {
|
|
8
|
-
return typeof window
|
|
8
|
+
return typeof window != "undefined" && typeof document != "undefined";
|
|
9
9
|
}
|
|
10
10
|
const b = "react";
|
|
11
11
|
function Y() {
|
|
@@ -198,11 +198,11 @@ const Q = () => {
|
|
|
198
198
|
}), {}))
|
|
199
199
|
});
|
|
200
200
|
function pt() {
|
|
201
|
-
return typeof globalThis
|
|
201
|
+
return typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : globalThis;
|
|
202
202
|
}
|
|
203
203
|
function yt() {
|
|
204
204
|
const t = pt().fetch;
|
|
205
|
-
if (typeof t
|
|
205
|
+
if (typeof t == "undefined")
|
|
206
206
|
throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
|
|
207
207
|
For more information, read https://github.com/BuilderIO/this-package-uses-fetch`), new Error("Builder SDK could not find a global `fetch` function");
|
|
208
208
|
return t;
|
|
@@ -295,7 +295,7 @@ async function _(t) {
|
|
|
295
295
|
...t,
|
|
296
296
|
limit: 1
|
|
297
297
|
});
|
|
298
|
-
return e && e
|
|
298
|
+
return e && e[0] || null;
|
|
299
299
|
}
|
|
300
300
|
const Kt = _, Ot = async (t) => {
|
|
301
301
|
const e = I(t);
|
|
@@ -303,7 +303,7 @@ const Kt = _, Ot = async (t) => {
|
|
|
303
303
|
}, kt = async (t, e, n = I(t)) => {
|
|
304
304
|
const r = dt(t.canTrack);
|
|
305
305
|
if (n.search.includes("preview="), !r || !(a() || b === "reactNative"))
|
|
306
|
-
return e;
|
|
306
|
+
return e.results;
|
|
307
307
|
try {
|
|
308
308
|
const o = [];
|
|
309
309
|
for (const s of e.results)
|
|
@@ -315,7 +315,7 @@ const Kt = _, Ot = async (t) => {
|
|
|
315
315
|
} catch (o) {
|
|
316
316
|
l.error("Could not process A/B tests. ", o);
|
|
317
317
|
}
|
|
318
|
-
return e;
|
|
318
|
+
return e.results;
|
|
319
319
|
};
|
|
320
320
|
async function G(t) {
|
|
321
321
|
try {
|
|
@@ -367,7 +367,7 @@ const J = "builderSessionId", Et = async ({
|
|
|
367
367
|
name: J,
|
|
368
368
|
value: t,
|
|
369
369
|
canTrack: e
|
|
370
|
-
}), z = () => a() && typeof localStorage
|
|
370
|
+
}), z = () => a() && typeof localStorage != "undefined" ? localStorage : void 0, At = ({
|
|
371
371
|
key: t,
|
|
372
372
|
canTrack: e
|
|
373
373
|
}) => {
|
|
@@ -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-df9eba5d.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-f978b3a5.js";
|
|
2
2
|
export {
|
|
3
3
|
t as _processContentResult,
|
|
4
4
|
a as createRegisterComponentMessage,
|