storyblok-js-client
Advanced tools
Comparing version 6.2.0 to 6.3.0
@@ -1,2 +0,2 @@ | ||
(function(f,h){typeof exports=="object"&&typeof module<"u"?module.exports=h():typeof define=="function"&&define.amd?define(h):(f=typeof globalThis<"u"?globalThis:f||self,f.StoryblokJSClient=h())})(this,function(){"use strict";var D=Object.defineProperty;var z=(f,h,p)=>h in f?D(f,h,{enumerable:!0,configurable:!0,writable:!0,value:p}):f[h]=p;var u=(f,h,p)=>(z(f,typeof h!="symbol"?h+"":h,p),p);function f(i){return!(i!==i||i===1/0||i===-1/0)}function h(i,e,t){if(!f(e))throw new TypeError("Expected `limit` to be a finite number");if(!f(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let o=[],n=0;const r=function(){n++;const a=setTimeout(function(){n--,s.length>0&&r(),o=o.filter(function(d){return d!==a})},t);o.indexOf(a)<0&&o.push(a);const c=s.shift();c.resolve(i.apply(c.self,c.args))},l=function(...a){const c=this;return new Promise(function(d,m){s.push({resolve:d,reject:m,args:a,self:c}),n<e&&r()})};return l.abort=function(){o.forEach(clearTimeout),o=[],s.forEach(function(a){a.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},l}class p{constructor(){u(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1);u(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s}));u(this,"delay",e=>new Promise(t=>setTimeout(t,e)));u(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t));u(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,o=e<t?1:-1;return this.arrayFrom(s,(n,r)=>r*o+e)});u(this,"asyncMap",async(e,t)=>Promise.all(e.map(t)));u(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,o)=>[...s,...o],[]));u(this,"escapeHTML",function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,o=RegExp(s.source);return e&&o.test(e)?e.replace(s,n=>t[n]):e})}stringify(e,t,s){const o=[];for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const r=e[n],l=s?"":encodeURIComponent(n);let a;typeof r=="object"?a=this.stringify(r,t?t+encodeURIComponent("["+l+"]"):l,Array.isArray(r)):a=(t?t+encodeURIComponent("["+l+"]"):l)+"="+encodeURIComponent(r),o.push(a)}return o.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",o="app.storyblokchina.cn";switch(e){case"us":return s;case"cn":return o;default:return t}}}const L=Object.freeze(Object.defineProperty({__proto__:null,SbHelpers:p},Symbol.toStringTag,{value:"Module"})),N=function(i,e){const t={};for(const s in i){const o=i[s];e.indexOf(s)>-1&&o!==null&&(t[s]=o)}return t},S=i=>i==="email",I={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:i=>({tag:["pre",{tag:"code",attrs:i.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:i=>({tag:`h${i.attrs.level}`}),image:i=>({singleTag:[{tag:"img",attrs:N(i.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"}),emoji:i=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":i.attrs.name,emoji:i.attrs.emoji}}]})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link:i=>{if(!i.attrs)return{tag:""};const e=new p().escapeHTML,t={...i.attrs},{linktype:s="url"}=i.attrs;if(delete t.linktype,t.href&&(t.href=e(i.attrs.href||"")),S(s)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const o in t.custom)t[o]=t.custom[o];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},styled:i=>({tag:[{tag:"span",attrs:i.attrs}]}),subscript:()=>({tag:"sub"}),superscript:()=>({tag:"sup"}),anchor:i=>({tag:[{tag:"span",attrs:i.attrs}]}),highlight:i=>{var t;return(t=i.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`background-color:${i.attrs.color};`}}]}:{tag:""}},textStyle:i=>{var t;return(t=i.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`color:${i.attrs.color}`}}]}:{tag:""}}}},U=function(i){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=RegExp(t.source);return i&&s.test(i)?i.replace(t,o=>e[o]):i};class k{constructor(e){u(this,"marks");u(this,"nodes");e||(e=I),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e,t={optimizeImages:!1}){if(e&&e.content&&Array.isArray(e.content)){let s="";return e.content.forEach(o=>{s+=this.renderNode(o)}),t.optimizeImages?this.optimizeImages(s,t.optimizeImages):s}return console.warn(`The render method must receive an Object with a "content" field. | ||
(function(p,h){typeof exports=="object"&&typeof module<"u"?module.exports=h():typeof define=="function"&&define.amd?define(h):(p=typeof globalThis<"u"?globalThis:p||self,p.StoryblokJSClient=h())})(this,function(){"use strict";var z=Object.defineProperty;var $=(p,h,m)=>h in p?z(p,h,{enumerable:!0,configurable:!0,writable:!0,value:m}):p[h]=m;var u=(p,h,m)=>($(p,typeof h!="symbol"?h+"":h,m),m);function p(i){return!(i!==i||i===1/0||i===-1/0)}function h(i,e,t){if(!p(e))throw new TypeError("Expected `limit` to be a finite number");if(!p(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let o=[],n=0;const r=function(){n++;const a=setTimeout(function(){n--,s.length>0&&r(),o=o.filter(function(d){return d!==a})},t);o.indexOf(a)<0&&o.push(a);const c=s.shift();c.resolve(i.apply(c.self,c.args))},l=function(...a){const c=this;return new Promise(function(d,b){s.push({resolve:d,reject:b,args:a,self:c}),n<e&&r()})};return l.abort=function(){o.forEach(clearTimeout),o=[],s.forEach(function(a){a.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},l}class m{constructor(){u(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1);u(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s}));u(this,"delay",e=>new Promise(t=>setTimeout(t,e)));u(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t));u(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,o=e<t?1:-1;return this.arrayFrom(s,(n,r)=>r*o+e)});u(this,"asyncMap",async(e,t)=>Promise.all(e.map(t)));u(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,o)=>[...s,...o],[]));u(this,"escapeHTML",function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,o=RegExp(s.source);return e&&o.test(e)?e.replace(s,n=>t[n]):e})}stringify(e,t,s){const o=[];for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const r=e[n],l=s?"":encodeURIComponent(n);let a;typeof r=="object"?a=this.stringify(r,t?t+encodeURIComponent("["+l+"]"):l,Array.isArray(r)):a=(t?t+encodeURIComponent("["+l+"]"):l)+"="+encodeURIComponent(r),o.push(a)}return o.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",o="app.storyblokchina.cn";switch(e){case"us":return s;case"cn":return o;default:return t}}}const L=Object.freeze(Object.defineProperty({__proto__:null,SbHelpers:m},Symbol.toStringTag,{value:"Module"})),N=function(i,e){const t={};for(const s in i){const o=i[s];e.indexOf(s)>-1&&o!==null&&(t[s]=o)}return t},S=i=>i==="email",I={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:i=>({tag:["pre",{tag:"code",attrs:i.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:i=>({tag:`h${i.attrs.level}`}),image:i=>({singleTag:[{tag:"img",attrs:N(i.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"}),emoji:i=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":i.attrs.name,emoji:i.attrs.emoji}}]})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link:i=>{if(!i.attrs)return{tag:""};const e=new m().escapeHTML,t={...i.attrs},{linktype:s="url"}=i.attrs;if(delete t.linktype,t.href&&(t.href=e(i.attrs.href||"")),S(s)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const o in t.custom)t[o]=t.custom[o];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},styled:i=>({tag:[{tag:"span",attrs:i.attrs}]}),subscript:()=>({tag:"sub"}),superscript:()=>({tag:"sup"}),anchor:i=>({tag:[{tag:"span",attrs:i.attrs}]}),highlight:i=>{var t;return(t=i.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`background-color:${i.attrs.color};`}}]}:{tag:""}},textStyle:i=>{var t;return(t=i.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`color:${i.attrs.color}`}}]}:{tag:""}}}},U=function(i){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=RegExp(t.source);return i&&s.test(i)?i.replace(t,o=>e[o]):i};class k{constructor(e){u(this,"marks");u(this,"nodes");e||(e=I),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e,t={optimizeImages:!1}){if(e&&e.content&&Array.isArray(e.content)){let s="";return e.content.forEach(o=>{s+=this.renderNode(o)}),t.optimizeImages?this.optimizeImages(s,t.optimizeImages):s}return console.warn(`The render method must receive an Object with a "content" field. | ||
The "content" field must be an array of nodes as the type ISbRichtext. | ||
@@ -24,2 +24,2 @@ ISbRichtext: | ||
type: 'doc' | ||
}`),""}optimizeImages(e,t){let s=0,o=0,n="",r="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(n+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(n+=`height="${t.height}" `,o=t.height),(t.loading==="lazy"||t.loading==="eager")&&(n+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(n+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(r+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(r+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(r+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(r+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(r+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(r+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(r+=`:rotate(${t.filters.rotate})`),r.length>0&&(r="/filters"+r))),n.length>0&&(e=e.replace(/<img/g,`<img ${n.trim()}`));const l=s>0||o>0||r.length>0?`${s}x${o}${r}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${l}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var d,m;const c=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(c&&c.length>0){const _={srcset:(d=t.srcset)==null?void 0:d.map(b=>{if(typeof b=="number")return`//${c}/m/${b}x0${r} ${b}w`;if(typeof b=="object"&&b.length===2){let O=0,C=0;return typeof b[0]=="number"&&(O=b[0]),typeof b[1]=="number"&&(C=b[1]),`//${c}/m/${O}x${C}${r} ${O}w`}}).join(", "),sizes:(m=t.sizes)==null?void 0:m.map(b=>b).join(", ")};let R="";return _.srcset&&(R+=`srcset="${_.srcset}" `),_.sizes&&(R+=`sizes="${_.sizes}" `),a.replace(/<img/g,`<img ${R.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(o=>{const n=this.getMatchingMark(o);n&&n.tag!==""&&t.push(this.renderOpeningTag(n.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(o=>{t.push(this.renderNode(o))}):e.text?t.push(U(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(o=>{const n=this.getMatchingMark(o);n&&n.tag!==""&&t.push(this.renderClosingTag(n.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(o=>{if(o.constructor===String)return`<${o}${t}>`;{let n=`<${o.tag}`;if(o.attrs)for(const r in o.attrs){const l=o.attrs[r];l!==null&&(n+=` ${r}="${l}"`)}return`${n}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(s=>s.constructor===String?`</${s}>`:`</${s.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class w{constructor(e){u(this,"baseURL");u(this,"timeout");u(this,"headers");u(this,"responseInterceptor");u(this,"fetch");u(this,"ejectInterceptor");u(this,"url");u(this,"parameters");this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(o=>{s.data=o});for(const o of e.headers.entries())t[o[0]]=o[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const a=new p;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const o=new URL(t),n=new AbortController,{signal:r}=n;let l;this.timeout&&(l=setTimeout(()=>n.abort(),this.timeout));try{const a=await this.fetch(`${o}`,{method:e,headers:this.headers,body:s,signal:r});this.timeout&&clearTimeout(l);const c=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,o)=>{if(t.test(`${e.status}`))return s(e);const n={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};o(n)})}}const v="SB-Agent",E={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.2.0"};let y={};const g={};class T{constructor(e,t){u(this,"client");u(this,"maxRetries");u(this,"throttle");u(this,"accessToken");u(this,"cache");u(this,"helpers");u(this,"resolveCounter");u(this,"relations");u(this,"links");u(this,"richTextResolver");u(this,"resolveNestedRelations");let s=e.endpoint||t;if(!s){const r=new p().getRegionURL,l=e.https===!1?"http":"https";e.oauthToken?s=`${l}://${r(e.region)}/v1`:s=`${l}://${r(e.region)}/v2`}const o=new Headers;if(o.set("Content-Type","application/json"),o.set("Accept","application/json"),e.headers)for(const r in e.headers)o.set(r,e.headers[r]);o.has(v)||(o.set(v,E.defaultAgentName),o.set(E.defaultAgentVersion,E.packageVersion));let n=5;e.oauthToken&&(o.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new k(e.richTextSchema):this.richTextResolver=new k,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=h(this.throttledRequest,n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new p,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.client=new w({baseURL:s,timeout:e.timeout||0,headers:o,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(o=>{s+=e(o.component,o)}),{html:s}})}parseParams(e){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=g[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,o){const n=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,o));return this.cacheResponse(e,n)}get(e,t){t||(t={});const s=`/${e}`,o=this.factoryParamOptions(s,t);return this.cacheResponse(s,o)}async getAll(e,t,s){const o=(t==null?void 0:t.per_page)||25,n=`/${e}`,r=n.split("/"),l=s||r[r.length-1],a=1,c=await this.makeRequest(n,t,o,a),d=c.total?Math.ceil(c.total/o):1,m=await this.helpers.asyncMap(this.helpers.range(a,d),_=>this.makeRequest(n,t,o,_+1));return this.helpers.flatMap([c,...m],_=>Object.values(_.data[l]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const o=e[t];o&&o.fieldtype=="multilink"&&o.linktype=="story"&&typeof o.id=="string"&&this.links[s][o.id]?o.story=this._cleanCopy(this.links[s][o.id]):o&&o.linktype==="story"&&typeof o.uuid=="string"&&this.links[s][o.uuid]&&(o.story=this._cleanCopy(this.links[s][o.uuid]))}_insertRelations(e,t,s,o){if(s.indexOf(`${e.component}.${t}`)>-1){if(typeof e[t]=="string")this.relations[o][e[t]]&&(e[t]=this._cleanCopy(this.relations[o][e[t]]));else if(e[t]&&e[t].constructor===Array){const n=[];e[t].forEach(r=>{this.relations[o][r]&&n.push(this._cleanCopy(this.relations[o][r]))}),e[t]=n}}}iterateTree(e,t,s){const o=n=>{if(n!=null){if(n.constructor===Array)for(let r=0;r<n.length;r++)o(n[r]);else if(n.constructor===Object){if(n._stopResolving)return;for(const r in n)(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,r,t,s),this._insertLinks(n,r,s)),o(n[r])}}};o(e.content)}async resolveLinks(e,t,s){let o=[];if(e.link_uuids){const n=e.link_uuids.length,r=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);r.push(e.link_uuids.slice(a,c))}for(let a=0;a<r.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:r[a].join(",")})).data.stories.forEach(d=>{o.push(d)})}else o=e.links;o.forEach(n=>{this.links[s][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,s){let o=[];if(e.rel_uuids){const n=e.rel_uuids.length,r=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);r.push(e.rel_uuids.slice(a,c))}for(let a=0;a<r.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:r[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(d=>{o.push(d)})}else o=e.rels;o&&o.length>0&&o.forEach(n=>{this.relations[s][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,s){var n,r;let o=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(o=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].indexOf(t.resolve_links)>-1&&((n=e.links)!=null&&n.length||(r=e.link_uuids)!=null&&r.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const l in this.relations[s])this.iterateTree(this.relations[s][l],o,s);e.story?this.iterateTree(e.story,o,s):e.stories.forEach(l=>{this.iterateTree(l,o,s)}),delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){(typeof s>"u"||!s)&&(s=0);const o=this.helpers.stringify({url:e,params:t}),n=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const r=await n.get(o);if(r)return Promise.resolve(r)}return new Promise(async(r,l)=>{var a;try{const c=await this.throttle("get",e,t);if(c.status!==200)return l(c);let d={data:c.data,headers:c.headers};if((a=c.headers)!=null&&a["per-page"]&&(d=Object.assign({},d,{perPage:c.headers["per-page"]?parseInt(c.headers["per-page"]):0,total:c.headers["per-page"]?parseInt(c.headers.total):0})),d.data.story||d.data.stories){const m=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(d.data,t,`${m}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await n.set(o,d),d.data.cv&&t.token&&(t.version=="draft"&&g[t.token]!=d.data.cv&&await this.flushCache(),g[t.token]=d.data.cv),r(d)}catch(c){if(c.response&&c.response.status===429&&(s=s?s+1:0,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await this.helpers.delay(1e3*s),this.cacheResponse(e,t,s).then(r).catch(l);l(c)}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return g}cacheVersion(){return g[this.accessToken]}setCacheVersion(e){this.accessToken&&(g[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(y[e])},getAll(){return Promise.resolve(y)},set(e,t){return y[e]=t,Promise.resolve(void 0)},flush(){return y={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(void 0)},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this}}const A=(i,e)=>{for(const t in e)i[t]=e[t]};return A(T,{RichtextResolver:k,SbFetch:w,RichTextSchema:I}),A(T,L),T}); | ||
}`),""}optimizeImages(e,t){let s=0,o=0,n="",r="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(n+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(n+=`height="${t.height}" `,o=t.height),(t.loading==="lazy"||t.loading==="eager")&&(n+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(n+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(r+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(r+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(r+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(r+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(r+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(r+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(r+=`:rotate(${t.filters.rotate})`),r.length>0&&(r="/filters"+r))),n.length>0&&(e=e.replace(/<img/g,`<img ${n.trim()}`));const l=s>0||o>0||r.length>0?`${s}x${o}${r}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${l}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var d,b;const c=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(c&&c.length>0){const _={srcset:(d=t.srcset)==null?void 0:d.map(f=>{if(typeof f=="number")return`//${c}/m/${f}x0${r} ${f}w`;if(typeof f=="object"&&f.length===2){let O=0,C=0;return typeof f[0]=="number"&&(O=f[0]),typeof f[1]=="number"&&(C=f[1]),`//${c}/m/${O}x${C}${r} ${O}w`}}).join(", "),sizes:(b=t.sizes)==null?void 0:b.map(f=>f).join(", ")};let R="";return _.srcset&&(R+=`srcset="${_.srcset}" `),_.sizes&&(R+=`sizes="${_.sizes}" `),a.replace(/<img/g,`<img ${R.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(o=>{const n=this.getMatchingMark(o);n&&n.tag!==""&&t.push(this.renderOpeningTag(n.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(o=>{t.push(this.renderNode(o))}):e.text?t.push(U(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(o=>{const n=this.getMatchingMark(o);n&&n.tag!==""&&t.push(this.renderClosingTag(n.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(o=>{if(o.constructor===String)return`<${o}${t}>`;{let n=`<${o.tag}`;if(o.attrs)for(const r in o.attrs){const l=o.attrs[r];l!==null&&(n+=` ${r}="${l}"`)}return`${n}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(s=>s.constructor===String?`</${s}>`:`</${s.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class w{constructor(e){u(this,"baseURL");u(this,"timeout");u(this,"headers");u(this,"responseInterceptor");u(this,"fetch");u(this,"ejectInterceptor");u(this,"url");u(this,"parameters");this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=e.fetch||fetch,this.ejectInterceptor=!1,this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(o=>{s.data=o});for(const o of e.headers.entries())t[o[0]]=o[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const a=new m;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const o=new URL(t),n=new AbortController,{signal:r}=n;let l;this.timeout&&(l=setTimeout(()=>n.abort(),this.timeout));try{const a=await this.fetch(`${o}`,{method:e,headers:this.headers,body:s,signal:r});this.timeout&&clearTimeout(l);const c=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,o)=>{if(t.test(`${e.status}`))return s(e);const n={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};o(n)})}}var D={MAVEN_OPTS:"-Dmaven.wagon.httpconnectionManager.maxPerRoute=2",CODEBUILD_LAST_EXIT:"0",GIT_COMMITTER_NAME:"semantic-release-bot",CODEBUILD_START_TIME:"1701265828978",CODEBUILD_BMR_URL:"https://CODEBUILD_AGENT:3000",npm_config_user_agent:"npm/10.2.4 node/v18.18.2 linux x64 workspaces/false ci/aws-codebuild",GIT_AUTHOR_EMAIL:"semantic-release-bot@martynus.net",CODEBUILD_SOURCE_VERSION:"arn:aws:s3:::codepipeline-us-east-1-627980213760/storyblok-js-client/SourceArti/mWRXcmG",GOLANG_18_VERSION:"1.18.10",JDK_17_HOME:"/usr/lib/jvm/java-17-amazon-corretto",CODEBUILD_AGENT_ENDPOINT:"http://127.0.0.1:7831",HOSTNAME:"0a3ae6a4578e",CODEBUILD_KMS_KEY_ID:"arn:aws:kms:us-east-1:211471875135:alias/aws/s3",CODEBUILD_BUILD_ID:"storyblok-js-client-node16:606c78a9-e8cc-4683-90db-553e09c10602",GH_TOKEN:"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",npm_node_execpath:"/usr/local/bin/node",GIT_ASKPASS:"echo",npm_package_resolved:"/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/storyblok/storyblok-js-client",npm_config_noproxy:"",NODE_16_VERSION:"16.20.2",HOME:"/root",OLDPWD:"/codebuild/readonly",JRE_HOME:"/usr/lib/jvm/java-17-amazon-corretto",CODEBUILD_GOPATH:"/codebuild/output/src3578067798",npm_package_json:"/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/storyblok/storyblok-js-client/package.json",CODEBUILD_CI:"true",GOENV_DISABLE_GOPATH:"1",CODEBUILD_RESOLVED_SOURCE_VERSION:"fa2f5c88c4281afe5f427730b646e857c7057f44",CODEBUILD_BUILD_NUMBER:"249",CODEBUILD_BUILD_SUCCEEDING:"1",GIT_AUTHOR_NAME:"semantic-release-bot",AWS_CONTAINER_CREDENTIALS_RELATIVE_URI:"/v2/credentials/222103ea-716d-4dda-87a0-54ea53b5ac02",CODEBUILD_BUILD_ARN:"arn:aws:codebuild:us-east-1:211471875135:build/storyblok-js-client-node16:606c78a9-e8cc-4683-90db-553e09c10602",LC_CTYPE:"C.UTF-8",npm_config_userconfig:"/tmp/b025b716d0f382723a1f9781c4972e91/.npmrc",npm_config_local_prefix:"/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/storyblok/storyblok-js-client",npm_package_integrity:"null",AWS_EXECUTION_ENV:"AWS_ECS_EC2",JRE_17_HOME:"/usr/lib/jvm/java-17-amazon-corretto",CODEBUILD_ACTION_RUNNER_URL:"https://codefactory-us-east-1-prod-default-build-agent-executor.s3.us-east-1.amazonaws.com/cawsrunner.zip",RUBY_BUILD_SRC_DIR:"/usr/local/rbenv/plugins/ruby-build",COLOR:"0",CODEBUILD_INITIATOR:"codepipeline/storyblok-js-client",DOTNET_6_SDK_VERSION:"6.0.410",NPM_TOKEN:"a04f2f84-3927-4a58-8379-bf35c8ddb438",AWS_DEFAULT_REGION:"us-east-1",npm_config_prefix:"/usr/local",npm_config_npm_version:"10.2.4",RUBY_31_VERSION:"3.1.4",PHP_81_VERSION:"8.1.20",ECS_CONTAINER_METADATA_URI_V4:"http://169.254.170.2/v4/9273e462-745c-41b9-803b-139d02bda372",npm_config_cache:"/root/.npm",ECS_CONTAINER_METADATA_URI:"http://169.254.170.2/v3/9273e462-745c-41b9-803b-139d02bda372",DOTNET_ROOT:"/root/.dotnet",CODEBUILD_EXECUTION_ROLE_BUILD:"",npm_config_node_gyp:"/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js",PATH:"/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/storyblok/storyblok-js-client/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/storyblok/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/node_modules/.bin:/codebuild/output/src3578067798/src/node_modules/.bin:/codebuild/output/src3578067798/node_modules/.bin:/codebuild/output/node_modules/.bin:/codebuild/node_modules/.bin:/node_modules/.bin:/usr/local/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/storyblok/storyblok-js-client/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/storyblok/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/node_modules/.bin:/codebuild/output/src3578067798/src/node_modules/.bin:/codebuild/output/src3578067798/node_modules/.bin:/codebuild/output/node_modules/.bin:/codebuild/node_modules/.bin:/node_modules/.bin:/usr/local/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/storyblok/storyblok-js-client/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/storyblok/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/node_modules/.bin:/codebuild/output/src3578067798/src/node_modules/.bin:/codebuild/output/src3578067798/node_modules/.bin:/codebuild/output/node_modules/.bin:/codebuild/node_modules/.bin:/node_modules/.bin:/usr/local/bin:/root/.npm/_npx/cdf31b77322f1d44/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/storyblok/storyblok-js-client/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/storyblok/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/node_modules/.bin:/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/node_modules/.bin:/codebuild/output/src3578067798/src/node_modules/.bin:/codebuild/output/src3578067798/node_modules/.bin:/codebuild/output/node_modules/.bin:/codebuild/node_modules/.bin:/node_modules/.bin:/usr/local/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/usr/local/bin/sbt/bin:/root/.goenv/shims:/root/.goenv/bin:/go/bin:/root/.phpenv/shims:/root/.phpenv/bin:/root/.pyenv/shims:/root/.pyenv/bin:/root/.rbenv/shims:/usr/local/rbenv/bin:/usr/local/rbenv/shims:/root/.dotnet/:/root/.dotnet/tools/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/tools:/codebuild/user/bin",NODE:"/usr/local/bin/node",npm_package_name:"storyblok-js-client",CODEBUILD_LOG_PATH:"606c78a9-e8cc-4683-90db-553e09c10602",PYYAML_VERSION:"5.4.1",CODEBUILD_BUILD_IMAGE:"aws/codebuild/standard:6.0",npm_lifecycle_script:"node vite.build.mjs && tsc",GOPATH:"/go:/codebuild/output/src3578067798",npm_package_version:"6.3.0",npm_lifecycle_event:"build",GIT_TERMINAL_PROMPT:"0",CODEBUILD_BUILD_URL:"https://us-east-1.console.aws.amazon.com/codebuild/home?region=us-east-1#/builds/storyblok-js-client-node16:606c78a9-e8cc-4683-90db-553e09c10602/view/new",AWS_REGION:"us-east-1",CODEBUILD_SRC_DIR:"/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/storyblok/storyblok-js-client",CODEBUILD_PROJECT_UUID:"32cade05-a75b-4c83-a9ee-1b765b71d873",CODEBUILD_CONTAINER_NAME:"default",CODEBUILD_AUTH_TOKEN:"f60252b0-f09b-4695-b37b-3d947af2f400",npm_config_globalconfig:"/usr/local/etc/npmrc",npm_config_init_module:"/root/.npm-init.js",GIT_COMMITTER_EMAIL:"semantic-release-bot@martynus.net",LOG4J_UNSAFE_VERSIONS:"2.11.1 1.2.8",JAVA_HOME:"/usr/lib/jvm/java-17-amazon-corretto",PWD:"/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/storyblok/storyblok-js-client",npm_execpath:"/usr/local/lib/node_modules/npm/bin/npm-cli.js",CODEBUILD_FE_REPORT_ENDPOINT:"https://codebuild.us-east-1.amazonaws.com/",npm_config_global_prefix:"/usr/local",npm_command:"run-script",PYTHON_310_VERSION:"3.10.12",JAVA_17_HOME:"/usr/lib/jvm/java-17-amazon-corretto",NUGET_XMLDOC_MODE:"skip",JDK_HOME:"/usr/lib/jvm/java-17-amazon-corretto",INIT_CWD:"/codebuild/output/src3578067798/src/codestar-connections.us-east-1.amazonaws.com/git-http/211471875135/eu-central-1/7d060832-ad20-4152-b085-4826ef8a8eed/storyblok/storyblok-js-client",EDITOR:"vi",NODE_ENV:"production"};const v="SB-Agent",E={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:D.npm_package_version};let y={};const g={};class T{constructor(e,t){u(this,"client");u(this,"maxRetries");u(this,"throttle");u(this,"accessToken");u(this,"cache");u(this,"helpers");u(this,"resolveCounter");u(this,"relations");u(this,"links");u(this,"richTextResolver");u(this,"resolveNestedRelations");let s=e.endpoint||t;if(!s){const r=new m().getRegionURL,l=e.https===!1?"http":"https";e.oauthToken?s=`${l}://${r(e.region)}/v1`:s=`${l}://${r(e.region)}/v2`}const o=new Headers;if(o.set("Content-Type","application/json"),o.set("Accept","application/json"),e.headers)for(const r in e.headers)o.set(r,e.headers[r]);o.has(v)||(o.set(v,E.defaultAgentName),o.set(E.defaultAgentVersion,E.packageVersion));let n=5;e.oauthToken&&(o.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new k(e.richTextSchema):this.richTextResolver=new k,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=h(this.throttledRequest,n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new m,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.client=new w({baseURL:s,timeout:e.timeout||0,headers:o,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(o=>{s+=e(o.component,o)}),{html:s}})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=g[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,o){const n=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,o));return this.cacheResponse(e,n)}get(e,t){t||(t={});const s=`/${e}`,o=this.factoryParamOptions(s,t);return this.cacheResponse(s,o)}async getAll(e,t,s){const o=(t==null?void 0:t.per_page)||25,n=`/${e}`,r=n.split("/"),l=s||r[r.length-1],a=1,c=await this.makeRequest(n,t,o,a),d=c.total?Math.ceil(c.total/o):1,b=await this.helpers.asyncMap(this.helpers.range(a,d),_=>this.makeRequest(n,t,o,_+1));return this.helpers.flatMap([c,...b],_=>Object.values(_.data[l]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const o=e[t];o&&o.fieldtype=="multilink"&&o.linktype=="story"&&typeof o.id=="string"&&this.links[s][o.id]?o.story=this._cleanCopy(this.links[s][o.id]):o&&o.linktype==="story"&&typeof o.uuid=="string"&&this.links[s][o.uuid]&&(o.story=this._cleanCopy(this.links[s][o.uuid]))}_insertRelations(e,t,s,o){if(s.indexOf(`${e.component}.${t}`)>-1){if(typeof e[t]=="string")this.relations[o][e[t]]&&(e[t]=this._cleanCopy(this.relations[o][e[t]]));else if(e[t]&&e[t].constructor===Array){const n=[];e[t].forEach(r=>{this.relations[o][r]&&n.push(this._cleanCopy(this.relations[o][r]))}),e[t]=n}}}iterateTree(e,t,s){const o=n=>{if(n!=null){if(n.constructor===Array)for(let r=0;r<n.length;r++)o(n[r]);else if(n.constructor===Object){if(n._stopResolving)return;for(const r in n)(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,r,t,s),this._insertLinks(n,r,s)),o(n[r])}}};o(e.content)}async resolveLinks(e,t,s){let o=[];if(e.link_uuids){const n=e.link_uuids.length,r=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);r.push(e.link_uuids.slice(a,c))}for(let a=0;a<r.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:r[a].join(",")})).data.stories.forEach(d=>{o.push(d)})}else o=e.links;o.forEach(n=>{this.links[s][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,s){let o=[];if(e.rel_uuids){const n=e.rel_uuids.length,r=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);r.push(e.rel_uuids.slice(a,c))}for(let a=0;a<r.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:r[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(d=>{o.push(d)})}else o=e.rels;o&&o.length>0&&o.forEach(n=>{this.relations[s][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,s){var n,r;let o=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(o=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].indexOf(t.resolve_links)>-1&&((n=e.links)!=null&&n.length||(r=e.link_uuids)!=null&&r.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const l in this.relations[s])this.iterateTree(this.relations[s][l],o,s);e.story?this.iterateTree(e.story,o,s):e.stories.forEach(l=>{this.iterateTree(l,o,s)}),delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){(typeof s>"u"||!s)&&(s=0);const o=this.helpers.stringify({url:e,params:t}),n=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const r=await n.get(o);if(r)return Promise.resolve(r)}return new Promise(async(r,l)=>{var a;try{const c=await this.throttle("get",e,t);if(c.status!==200)return l(c);let d={data:c.data,headers:c.headers};if((a=c.headers)!=null&&a["per-page"]&&(d=Object.assign({},d,{perPage:c.headers["per-page"]?parseInt(c.headers["per-page"]):0,total:c.headers["per-page"]?parseInt(c.headers.total):0})),d.data.story||d.data.stories){const b=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(d.data,t,`${b}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await n.set(o,d),d.data.cv&&t.token&&(t.version==="draft"&&g[t.token]!=d.data.cv&&await this.flushCache(),g[t.token]=t.cv?t.cv:d.data.cv),r(d)}catch(c){if(c.response&&c.response.status===429&&(s=s?s+1:0,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await this.helpers.delay(1e3*s),this.cacheResponse(e,t,s).then(r).catch(l);l(c)}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return g}cacheVersion(){return g[this.accessToken]}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(y[e])},getAll(){return Promise.resolve(y)},set(e,t){return y[e]=t,Promise.resolve(void 0)},flush(){return y={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this}}const A=(i,e)=>{for(const t in e)i[t]=e[t]};return A(T,{RichtextResolver:k,SbFetch:w,RichTextSchema:I}),A(T,L),T}); |
@@ -64,3 +64,2 @@ import { ISbStoriesParams, ISbConfig, ISbResult, ISbStories, ISbStory, ISbStoryData, ISbStoryParams, ISbContentMangmntAPI } from './interfaces'; | ||
cacheVersion(): number; | ||
setCacheVersion(cv: number): void; | ||
private cacheProvider; | ||
@@ -67,0 +66,0 @@ flushCache(): Promise<this>; |
{ | ||
"name": "storyblok-js-client", | ||
"version": "6.2.0", | ||
"version": "6.3.0", | ||
"description": "Universal JavaScript SDK for Storyblok's API", | ||
@@ -55,15 +55,15 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@commitlint/cli": "^17.2.0", | ||
"@commitlint/config-conventional": "^17.2.0", | ||
"@tsconfig/recommended": "^1.0.1", | ||
"@typescript-eslint/eslint-plugin": "^5.43.0", | ||
"@typescript-eslint/parser": "^5.43.0", | ||
"eslint": "^8.27.0", | ||
"@commitlint/cli": "^18.4.3", | ||
"@commitlint/config-conventional": "^18.4.3", | ||
"@tsconfig/recommended": "^1.0.3", | ||
"@typescript-eslint/eslint-plugin": "^6.12.0", | ||
"@typescript-eslint/parser": "^6.12.0", | ||
"eslint": "^8.54.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"husky": "^8.0.2", | ||
"husky": "^8.0.3", | ||
"isomorphic-fetch": "^3.0.0", | ||
"prettier": "^3.0.0", | ||
"typescript": "^5.0.2", | ||
"vite": "^4.4.8", | ||
"vitest": "^0.34.1" | ||
"prettier": "^3.1.0", | ||
"typescript": "^5.3.2", | ||
"vite": "^5.0.2", | ||
"vitest": "^0.34.6" | ||
}, | ||
@@ -70,0 +70,0 @@ "release": { |
@@ -178,6 +178,2 @@ import throttledQueue from './throttlePromise' | ||
private parseParams(params: ISbStoriesParams): ISbStoriesParams { | ||
if (!params.version) { | ||
params.version = 'published' | ||
} | ||
if (!params.token) { | ||
@@ -580,3 +576,3 @@ params.token = this.getToken() | ||
if ( | ||
params.version == 'draft' && | ||
params.version === 'draft' && | ||
cacheVersions[params.token] != response.data.cv | ||
@@ -586,4 +582,3 @@ ) { | ||
} | ||
cacheVersions[params.token] = response.data.cv | ||
cacheVersions[params.token] = params.cv ? params.cv : response.data.cv | ||
} | ||
@@ -625,8 +620,2 @@ | ||
public setCacheVersion(cv: number): void { | ||
if (this.accessToken) { | ||
cacheVersions[this.accessToken] = cv | ||
} | ||
} | ||
private cacheProvider(): ICacheProvider { | ||
@@ -657,3 +646,3 @@ switch (this.cache.type) { | ||
get() { | ||
return Promise.resolve(undefined) | ||
return Promise.resolve() | ||
}, | ||
@@ -660,0 +649,0 @@ getAll() { |
@@ -33,4 +33,5 @@ import { SbHelpers } from './sbHelpers' | ||
this.responseInterceptor = $c.responseInterceptor | ||
this.fetch = (...args) => ($c.fetch ? $c.fetch(...args) : fetch(...args)) | ||
this.fetch = $c.fetch || fetch | ||
this.ejectInterceptor = false | ||
this.ejectInterceptor = false | ||
this.url = '' | ||
@@ -37,0 +38,0 @@ this.parameters = {} as ISbStoriesParams |
Sorry, the diff of this file is not supported yet
225435
5691
3