UNPKG

@venuecms/sdk-next

Version:

This is a work in progress and is heavily in flux until we launch 1.0 in February.

5 lines 10.1 kB
"use client"; "use strict";var N=Object.create;var y=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var V=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),G=(t,e)=>{for(var r in e)y(t,r,{get:e[r],enumerable:!0})},C=(t,e,r,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of M(e))!J.call(t,s)&&s!==r&&y(t,s,{get:()=>e[s],enumerable:!(l=B(e,s))||l.enumerable});return t};var F=(t,e,r)=>(r=t!=null?N(H(t)):{},C(e||!t||!t.__esModule?y(r,"default",{value:t,enumerable:!0}):r,t)),Y=t=>C(y({},"__esModule",{value:!0}),t);var W=V((we,_)=>{"use strict";_.exports=function(t,e){e=e||{},e.listUnicodeChar=e.hasOwnProperty("listUnicodeChar")?e.listUnicodeChar:!1,e.stripListLeaders=e.hasOwnProperty("stripListLeaders")?e.stripListLeaders:!0,e.gfm=e.hasOwnProperty("gfm")?e.gfm:!0,e.useImgAltText=e.hasOwnProperty("useImgAltText")?e.useImgAltText:!0,e.abbr=e.hasOwnProperty("abbr")?e.abbr:!1,e.replaceLinksWithURL=e.hasOwnProperty("replaceLinksWithURL")?e.replaceLinksWithURL:!1,e.htmlTagsToSkip=e.hasOwnProperty("htmlTagsToSkip")?e.htmlTagsToSkip:[],e.throwError=e.hasOwnProperty("throwError")?e.throwError:!1;var r=t||"";r=r.replace(/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/gm,"");try{e.stripListLeaders&&(e.listUnicodeChar?r=r.replace(/^([\s\t]*)([\*\-\+]|\d+\.)\s+/gm,e.listUnicodeChar+" $1"):r=r.replace(/^([\s\t]*)([\*\-\+]|\d+\.)\s+/gm,"$1")),e.gfm&&(r=r.replace(/\n={2,}/g,` `).replace(/~{3}.*\n/g,"").replace(/~~/g,"").replace(/`{3}.*\n/g,"")),e.abbr&&(r=r.replace(/\*\[.*\]:.*\n/,""));let l=/<[^>]*>/g;if(e.htmlTagsToSkip&&e.htmlTagsToSkip.length>0){let s=e.htmlTagsToSkip.join("|");l=new RegExp(`<(?!/?(${s})(?=>|s[^>]*>))[^>]*>`,"g")}r=r.replace(l,"").replace(/^[=\-]{2,}\s*$/g,"").replace(/\[\^.+?\](\: .*?$)?/g,"").replace(/\s{0,2}\[.*?\]: .*?$/g,"").replace(/\!\[(.*?)\][\[\(].*?[\]\)]/g,e.useImgAltText?"$1":"").replace(/\[([^\]]*?)\][\[\(].*?[\]\)]/g,e.replaceLinksWithURL?"$2":"$1").replace(/^(\n)?\s{0,3}>\s?/gm,"$1").replace(/^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$/g,"").replace(/^(\n)?\s{0,}#{1,6}\s*( (.+))? +#+$|^(\n)?\s{0,}#{1,6}\s*( (.+))?$/gm,"$1$3$4$6").replace(/([\*]+)(\S)(.*?\S)??\1/g,"$2$3").replace(/(^|\W)([_]+)(\S)(.*?\S)??\2($|\W)/g,"$1$3$4$5").replace(/(`{3,})(.*?)\1/gm,"$2").replace(/`(.+?)`/g,"$1").replace(/~(.*?)~/g,"$1")}catch(l){if(e.throwError)throw l;return console.error("remove-markdown encountered error: %s",l),t}return r}});var fe={};G(fe,{getGenerateMetadata:()=>ge,getLocalizedMetadata:()=>D});module.exports=Y(fe);var Q=/\{[^{}]+\}/g,v=({allowReserved:t,name:e,value:r})=>{if(r==null)return"";if(typeof r=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return`${e}=${t?r:encodeURIComponent(r)}`},X=t=>{switch(t){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},Z=t=>{switch(t){case"form":return",";case"pipeDelimited":return"|";case"spaceDelimited":return"%20";default:return","}},ee=t=>{switch(t){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},j=({allowReserved:t,explode:e,name:r,style:l,value:s})=>{if(!e){let i=(t?s:s.map(o=>encodeURIComponent(o))).join(Z(l));switch(l){case"label":return`.${i}`;case"matrix":return`;${r}=${i}`;case"simple":return i;default:return`${r}=${i}`}}let n=X(l),a=s.map(i=>l==="label"||l==="simple"?t?i:encodeURIComponent(i):v({allowReserved:t,name:r,value:i})).join(n);return l==="label"||l==="matrix"?n+a:a},O=({allowReserved:t,explode:e,name:r,style:l,value:s})=>{if(s instanceof Date)return`${r}=${s.toISOString()}`;if(l!=="deepObject"&&!e){let i=[];Object.entries(s).forEach(([p,u])=>{i=[...i,p,t?u:encodeURIComponent(u)]});let o=i.join(",");switch(l){case"form":return`${r}=${o}`;case"label":return`.${o}`;case"matrix":return`;${r}=${o}`;default:return o}}let n=ee(l),a=Object.entries(s).map(([i,o])=>v({allowReserved:t,name:l==="deepObject"?`${r}[${i}]`:i,value:o})).join(n);return l==="label"||l==="matrix"?n+a:a},te=({path:t,url:e})=>{let r=e,l=e.match(Q);if(l)for(let s of l){let n=!1,a=s.substring(1,s.length-1),i="simple";a.endsWith("*")&&(n=!0,a=a.substring(0,a.length-1)),a.startsWith(".")?(a=a.substring(1),i="label"):a.startsWith(";")&&(a=a.substring(1),i="matrix");let o=t[a];if(o==null)continue;if(Array.isArray(o)){r=r.replace(s,j({explode:n,name:a,style:i,value:o}));continue}if(typeof o=="object"){r=r.replace(s,O({explode:n,name:a,style:i,value:o}));continue}if(i==="matrix"){r=r.replace(s,`;${v({name:a,value:o})}`);continue}let p=encodeURIComponent(i==="label"?`.${o}`:o);r=r.replace(s,p)}return r},L=({allowReserved:t,array:e,object:r}={})=>l=>{let s=[];if(l&&typeof l=="object")for(let n in l){let a=l[n];if(a!=null){if(Array.isArray(a)){s=[...s,j({allowReserved:t,explode:!0,name:n,style:"form",value:a,...e})];continue}if(typeof a=="object"){s=[...s,O({allowReserved:t,explode:!0,name:n,style:"deepObject",value:a,...r})];continue}s=[...s,v({allowReserved:t,name:n,value:a})]}}return s.join("&")},re=t=>{if(!t)return;let e=t.split(";")[0]?.trim();if(e){if(e.startsWith("application/json")||e.endsWith("+json"))return"json";if(e==="multipart/form-data")return"formData";if(["application/","audio/","image/","video/"].some(r=>e.startsWith(r)))return"blob";if(e.startsWith("text/"))return"text"}},ae=async(t,e)=>{if(t.fn==="accessToken"){let r=typeof e.accessToken=="function"?await e.accessToken():e.accessToken;return r?`Bearer ${r}`:void 0}if(t.fn==="apiKey")return typeof e.apiKey=="function"?await e.apiKey():e.apiKey},ie=async({security:t,...e})=>{for(let r of t){let l=await ae(r,e);if(l){r.in==="header"?e.headers.set(r.name,l):r.in==="query"&&(e.query||(e.query={}),e.query[r.name]=l);return}}},T=t=>se({baseUrl:t.baseUrl??"",path:t.path,query:t.query,querySerializer:typeof t.querySerializer=="function"?t.querySerializer:L(t.querySerializer),url:t.url}),se=({baseUrl:t,path:e,query:r,querySerializer:l,url:s})=>{let n=s.startsWith("/")?s:`/${s}`,a=t+n;e&&(a=te({path:e,url:a}));let i=r?l(r):"";return i.startsWith("?")&&(i=i.substring(1)),i&&(a+=`?${i}`),a},E=(t,e)=>{let r={...t,...e};return r.baseUrl?.endsWith("/")&&(r.baseUrl=r.baseUrl.substring(0,r.baseUrl.length-1)),r.headers=U(t.headers,e.headers),r},U=(...t)=>{let e=new Headers;for(let r of t){if(!r||typeof r!="object")continue;let l=r instanceof Headers?r.entries():Object.entries(r);for(let[s,n]of l)if(n===null)e.delete(s);else if(Array.isArray(n))for(let a of n)e.append(s,a);else n!==void 0&&e.set(s,typeof n=="object"?JSON.stringify(n):n)}return e},w=class{_fns;constructor(){this._fns=[]}clear(){this._fns=[]}exists(t){return this._fns.indexOf(t)!==-1}eject(t){let e=this._fns.indexOf(t);e!==-1&&(this._fns=[...this._fns.slice(0,e),...this._fns.slice(e+1)])}use(t){this._fns=[...this._fns,t]}},le=()=>({error:new w,request:new w,response:new w});var ne={bodySerializer:t=>JSON.stringify(t)};var oe=L({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),ce={"Content-Type":"application/json"},$=(t={})=>({...ne,baseUrl:"",headers:ce,parseAs:"auto",querySerializer:oe,...t}),z=(t={})=>{let e=E($(),t),r=()=>({...e}),l=a=>(e=E(e,a),r()),s=le(),n=async a=>{let i={...e,...a,fetch:a.fetch??e.fetch??globalThis.fetch,headers:U(e.headers,a.headers)};i.security&&await ie({...i,security:i.security}),i.body&&i.bodySerializer&&(i.body=i.bodySerializer(i.body)),i.body||i.headers.delete("Content-Type");let o=T(i),p={redirect:"follow",...i},u=new Request(o,p);for(let d of s.request._fns)u=await d(u,i);let b=i.fetch,c=await b(u);for(let d of s.response._fns)c=await d(c,u,i);let g={request:u,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return{data:{},...g};if(i.parseAs==="stream")return{data:c.body,...g};let d=(i.parseAs==="auto"?re(c.headers.get("Content-Type")):i.parseAs)??"json",h=await c[d]();return d==="json"&&(i.responseValidator&&await i.responseValidator(h),i.responseTransformer&&(h=await i.responseTransformer(h))),{data:h,...g}}let m=await c.text();try{m=JSON.parse(m)}catch{}let f=m;for(let d of s.error._fns)f=await d(m,c,u,i);if(f=f||{},i.throwOnError)throw f;return{error:f,...g}};return{buildUrl:T,connect:a=>n({...a,method:"CONNECT"}),delete:a=>n({...a,method:"DELETE"}),get:a=>n({...a,method:"GET"}),getConfig:r,head:a=>n({...a,method:"HEAD"}),interceptors:s,options:a=>n({...a,method:"OPTIONS"}),patch:a=>n({...a,method:"PATCH"}),post:a=>n({...a,method:"POST"}),put:a=>n({...a,method:"PUT"}),request:n,setConfig:l,trace:a=>n({...a,method:"TRACE"})}};var R=(t,e)=>{let r=e;return{content:t?.find(n=>n.locale===r)??t?.[0]??{},currentLocale:r}},S=z($()),ue=t=>(t?.client??S).get({...t,url:"/api/v2/{siteKey}/public/site"});var q=process.env.VENUE_SITE_KEY,pe=process.env.VENUE_API_KEY,A={Authorization:`Bearer ${pe}`},de="https://app.venuecms.com",K={baseUrl:de,headers:A};S.setConfig(K);var I=t=>{q=t.siteKey,S.setConfig({...K,...t.options})},k=()=>ue({path:{siteKey:q},headers:A});var P=F(W());var x=t=>t?.url&&`/media/${encodeURIComponent(t.url)}`;var D=({locale:t,item:e,site:r,overrides:l={}})=>{let{content:s}=e?.localizedContent?R(e?.localizedContent,t):{},{title:n,content:a,shortContent:i,metaTitle:o,metaDescription:p,keywords:u}=s??l,b=c=>{let g=c?.image&&x(c.image),m=r.image&&x(r.image),f=a?(0,P.default)(a).split(` `)[0]:void 0;return{title:o||n,description:p||i||f,siteName:r.name,...c?.image&&g?{images:[{width:c.image.metadata?.width,height:c.image.metadata?.height,url:g}]}:{images:[{width:r.image?.metadata?.width,height:r.image?.metadata?.height,url:m}]},locale:t,type:"website",...l}};return{title:`${r.name}${n?` - ${n}`:""}`,description:p||i||(a?(0,P.default)(a):void 0),keywords:u?.split(", "),openGraph:b(e),...l}},ge=t=>async({params:e})=>{try{let{siteKey:r,slug:l,locale:s}=await e;I({siteKey:r});let[{data:n},{data:a}]=await Promise.all([k(),t({slug:l})]);return!n||!a?{}:D({locale:s,item:a,site:n})}catch{return{}}};0&&(module.exports={getGenerateMetadata,getLocalizedMetadata}); //# sourceMappingURL=index.js.map