storyblok-js-client
Advanced tools
Comparing version 4.5.7 to 4.5.8
@@ -6,2 +6,2 @@ /*! | ||
*/ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=e(require("axios"));function s(e){return"number"==typeof e&&(e==e&&e!==1/0&&e!==-1/0)}function r(e,t,r){if(!s(t))throw new TypeError("Expected `limit` to be a finite number");if(!s(r))throw new TypeError("Expected `interval` to be a finite number");var i=[],n=[],o=0,a=function(){o++;var t=setTimeout((function(){o--,i.length>0&&a(),n=n.filter((function(e){return e!==t}))}),r);n.indexOf(t)<0&&n.push(t);var s=i.shift();s.resolve(e.apply(s.self,s.args))},l=function(){var e=arguments,s=this;return new Promise((function(r,n){i.push({resolve:r,reject:n,args:e,self:s}),o<t&&a()}))};return l.abort=function(){n.forEach(clearTimeout),n=[],i.forEach((function(e){e.reject(new throttle.AbortError)})),i.length=0},l}r.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const i=function(e,t){if(!e)return null;let s={};for(let r in e){let i=e[r];t.indexOf(r)>-1&&null!==i&&(s[r]=i)}return s};var n={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:e=>({tag:["pre",{tag:"code",attrs:e.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:e=>({tag:`h${e.attrs.level}`}),image:e=>({singleTag:[{tag:"img",attrs:i(e.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(e){const t={...e.attrs},{linktype:s="url"}=e.attrs;return"email"===s&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},styled:e=>({tag:[{tag:"span",attrs:e.attrs}]})}};class o{constructor(e){e||(e=n),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach((e=>{t+=this.renderNode(e)})),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach((e=>{const s=this.getMatchingMark(e);s&&t.push(this.renderOpeningTag(s.tag))}));const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach((e=>{t.push(this.renderNode(e))})):e.text?t.push(function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,r=RegExp(s.source);return e&&r.test(e)?e.replace(s,(e=>t[e])):e}(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html&&t.push(s.html),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach((e=>{const s=this.getMatchingMark(e);s&&t.push(this.renderClosingTag(s.tag))})),t.join("")}renderTag(e,t){if(e.constructor===String)return`<${e}${t}>`;return e.map((e=>{if(e.constructor===String)return`<${e}${t}>`;{let s=`<${e.tag}`;if(e.attrs)for(let t in e.attrs){let r=e.attrs[t];null!==r&&(s+=` ${t}="${r}"`)}return`${s}${t}>`}})).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){if(e.constructor===String)return`</${e}>`;return e.slice(0).reverse().map((e=>e.constructor===String?`</${e}>`:`</${e.tag}>`)).join("")}getMatchingNode(e){if("function"==typeof this.nodes[e.type])return this.nodes[e.type](e)}getMatchingMark(e){if("function"==typeof this.marks[e.type])return this.marks[e.type](e)}}const a=(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return((e=0,t)=>[...Array(e)].map(t))(s,((t,s)=>s*r+e))},l=(e,t,s)=>{const r=[];for(const i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;const n=e[i],o=s?"":encodeURIComponent(i);let a;a="object"==typeof n?l(n,t?t+encodeURIComponent("["+o+"]"):o,Array.isArray(n)):(t?t+encodeURIComponent("["+o+"]"):o)+"="+encodeURIComponent(n),r.push(a)}return r.join("&")};let c={},h={};module.exports=class{constructor(e,s){if(!s){let t=e.region?`-${e.region}`:"",r=!1===e.https?"http":"https";s=void 0===e.oauthToken?`${r}://api${t}.storyblok.com/v2`:`${r}://api${t}.storyblok.com/v1`}let i=Object.assign({},e.headers),n=5;void 0!==e.oauthToken&&(i.Authorization=e.oauthToken,n=3),void 0!==e.rateLimit&&(n=e.rateLimit),this.richTextResolver=new o(e.richTextSchema),"function"==typeof e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=r(this.throttledRequest,n,1e3),this.accessToken=e.accessToken,this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.client=t.default.create({baseURL:s,timeout:e.timeout||0,headers:i,proxy:e.proxy||!1}),e.responseInterceptor&&this.client.interceptors.response.use((t=>e.responseInterceptor(t))),this.resolveNestedRelations=e.resolveNestedRelations||!0}setComponentResolver(e){this.richTextResolver.addNode("blok",(t=>{let s="";return t.attrs.body.forEach((t=>{s+=e(t.component,t)})),{html:s}}))}parseParams(e={}){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=h[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t={}){return((e="")=>e.indexOf("/cdn/")>-1)(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const i=this.factoryParamOptions(e,((e={},t=25,s=1)=>({...e,per_page:t,page:s}))(t,s,r));return this.cacheResponse(e,i)}get(e,t){let s=`/${e}`;const r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t={},s){const r=t.per_page||25,i=`/${e}`,n=i.split("/");s=s||n[n.length-1];const o=await this.makeRequest(i,t,r,1),l=Math.ceil(o.total/r);return((e=[],t)=>e.map(t).reduce(((e,t)=>[...e,...t]),[]))([o,...await(async(e=[],t)=>Promise.all(e.map(t)))(a(1,l),(async e=>this.makeRequest(i,t,r,e+1)))],(e=>Object.values(e.data[s])))}post(e,t){let s=`/${e}`;return this.throttle("post",s,t)}put(e,t){let s=`/${e}`;return this.throttle("put",s,t)}delete(e,t){let s=`/${e}`;return this.throttle("delete",s,t)}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}setToken(e){this.accessToken=e}getToken(){return this.accessToken}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const s=e[t];s&&"multilink"==s.fieldtype&&"story"==s.linktype&&"string"==typeof s.id&&this.links[s.id]?s.story=this._cleanCopy(this.links[s.id]):s&&"story"===s.linktype&&"string"==typeof s.uuid&&this.links[s.uuid]&&(s.story=this._cleanCopy(this.links[s.uuid]))}_insertRelations(e,t,s){if(s.indexOf(e.component+"."+t)>-1)if("string"==typeof e[t])this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t].constructor===Array){let s=[];e[t].forEach((e=>{this.relations[e]&&s.push(this._cleanCopy(this.relations[e]))})),e[t]=s}}_insertAssetsRelations(e,t){t.forEach((t=>{e.id===t.id&&(e.original=t,e.original.filename=e.filename,e.original.filename=e.original.filename.includes("https://s3.amazonaws.com/")?e.original.filename:e.original.filename.replace("https://","https://s3.amazonaws.com/"),delete e.original.s3_filename)}))}iterateTree(e,t){let s=e=>{if(null!=e)if(e.constructor===Array)for(let t=0;t<e.length;t++)s(e[t]);else if(e.constructor===Object){if(e._stopResolving)return;for(let r in e)e.component&&e._uid||"link"===e.type?(this._insertRelations(e,r,t),this._insertLinks(e,r)):"id"in e&&"asset"===e.fieldtype&&this._insertAssetsRelations(e,t),s(e[r])}};s(e.content)}async resolveLinks(e,t){let s=[];if(e.link_uuids){const r=e.link_uuids.length;let i=[];const n=50;for(let t=0;t<r;t+=n){const s=Math.min(r,t+n);i.push(e.link_uuids.slice(t,s))}for(let e=0;e<i.length;e++){(await this.getStories({per_page:n,language:t.language,version:t.version,by_uuids:i[e].join(",")})).data.stories.forEach((e=>{s.push(e)}))}}else s=e.links;s.forEach((e=>{this.links[e.uuid]={...e,_stopResolving:!0}}))}async resolveRelations(e,t){let s=[];if(e.rel_uuids){const r=e.rel_uuids.length;let i=[];const n=50;for(let t=0;t<r;t+=n){const s=Math.min(r,t+n);i.push(e.rel_uuids.slice(t,s))}for(let e=0;e<i.length;e++){(await this.getStories({per_page:n,language:t.language,version:t.version,by_uuids:i[e].join(",")})).data.stories.forEach((e=>{s.push(e)}))}}else s=e.rels;s.forEach((e=>{this.relations[e.uuid]={...e,_stopResolving:!0}}))}async resolveStories(e,t){let s=[];if(void 0!==t.resolve_relations&&t.resolve_relations.length>0&&(e.rels||e.rel_uuids)&&(s=t.resolve_relations.split(","),await this.resolveRelations(e,t)),["1","story","url"].indexOf(t.resolve_links)>-1&&(e.links||e.link_uuids)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const e in this.relations)this.iterateTree(this.relations[e],s);e.story?this.iterateTree(e.story,s):e.stories.forEach((e=>{this.iterateTree(e,s)}))}resolveAssetsRelations(e){const{assets:t,stories:s,story:r}=e;if(s)for(const e of s)this.iterateTree(e,t);else{if(!r)return e;this.iterateTree(r,t)}}cacheResponse(e,t,s){return void 0===s&&(s=0),new Promise((async(r,i)=>{let n=l({url:e,params:t}),o=this.cacheProvider();if("auto"===this.cache.clear&&"draft"===t.version&&await this.flushCache(),"published"===t.version&&"/cdn/spaces/me"!=e){const e=await o.get(n);if(e)return r(e)}try{let s=await this.throttle("get",e,{params:t,paramsSerializer:e=>l(e)}),a={data:s.data,headers:s.headers};if(a.data.assets&&a.data.assets.length&&this.resolveAssetsRelations(a.data),s.headers["per-page"]&&(a=Object.assign({},a,{perPage:parseInt(s.headers["per-page"]),total:parseInt(s.headers.total)})),200!=s.status)return i(s);(a.data.story||a.data.stories)&&await this.resolveStories(a.data,t),"published"===t.version&&"/cdn/spaces/me"!=e&&o.set(n,a),a.data.cv&&("draft"==t.version&&h[t.token]!=a.data.cv&&this.flushCache(),h[t.token]=a.data.cv),r(a)}catch(n){if(n.response&&429===n.response.status&&(s+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await(a=1e3*s,new Promise((e=>setTimeout(e,a)))),this.cacheResponse(e,t,s).then(r).catch(i);i(n)}var a}))}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return h}cacheVersion(){return h[this.accessToken]}setCacheVersion(e){this.accessToken&&(h[this.accessToken]=e)}cacheProvider(){return"memory"===this.cache.type?{get:e=>c[e],getAll:()=>c,set(e,t){c[e]=t},flush(){c={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=e(require("axios"));function s(e){return"number"==typeof e&&(e==e&&e!==1/0&&e!==-1/0)}function r(e,t,r){if(!s(t))throw new TypeError("Expected `limit` to be a finite number");if(!s(r))throw new TypeError("Expected `interval` to be a finite number");var i=[],n=[],o=0,a=function(){o++;var t=setTimeout((function(){o--,i.length>0&&a(),n=n.filter((function(e){return e!==t}))}),r);n.indexOf(t)<0&&n.push(t);var s=i.shift();s.resolve(e.apply(s.self,s.args))},l=function(){var e=arguments,s=this;return new Promise((function(r,n){i.push({resolve:r,reject:n,args:e,self:s}),o<t&&a()}))};return l.abort=function(){n.forEach(clearTimeout),n=[],i.forEach((function(e){e.reject(new throttle.AbortError)})),i.length=0},l}r.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const i=function(e,t){if(!e)return null;let s={};for(let r in e){let i=e[r];t.indexOf(r)>-1&&null!==i&&(s[r]=i)}return s};var n={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:e=>({tag:["pre",{tag:"code",attrs:e.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:e=>({tag:`h${e.attrs.level}`}),image:e=>({singleTag:[{tag:"img",attrs:i(e.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(e){const t={...e.attrs},{linktype:s="url"}=e.attrs;return"email"===s&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},styled:e=>({tag:[{tag:"span",attrs:e.attrs}]})}};class o{constructor(e){e||(e=n),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach((e=>{t+=this.renderNode(e)})),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach((e=>{const s=this.getMatchingMark(e);s&&t.push(this.renderOpeningTag(s.tag))}));const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach((e=>{t.push(this.renderNode(e))})):e.text?t.push(function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,r=RegExp(s.source);return e&&r.test(e)?e.replace(s,(e=>t[e])):e}(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html&&t.push(s.html),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach((e=>{const s=this.getMatchingMark(e);s&&t.push(this.renderClosingTag(s.tag))})),t.join("")}renderTag(e,t){if(e.constructor===String)return`<${e}${t}>`;return e.map((e=>{if(e.constructor===String)return`<${e}${t}>`;{let s=`<${e.tag}`;if(e.attrs)for(let t in e.attrs){let r=e.attrs[t];null!==r&&(s+=` ${t}="${r}"`)}return`${s}${t}>`}})).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){if(e.constructor===String)return`</${e}>`;return e.slice(0).reverse().map((e=>e.constructor===String?`</${e}>`:`</${e.tag}>`)).join("")}getMatchingNode(e){if("function"==typeof this.nodes[e.type])return this.nodes[e.type](e)}getMatchingMark(e){if("function"==typeof this.marks[e.type])return this.marks[e.type](e)}}const a=(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return((e=0,t)=>[...Array(e)].map(t))(s,((t,s)=>s*r+e))},l=(e,t,s)=>{const r=[];for(const i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;const n=e[i],o=s?"":encodeURIComponent(i);let a;a="object"==typeof n?l(n,t?t+encodeURIComponent("["+o+"]"):o,Array.isArray(n)):(t?t+encodeURIComponent("["+o+"]"):o)+"="+encodeURIComponent(n),r.push(a)}return r.join("&")};let c={},h={};module.exports=class{constructor(e,s){if(!s){let t=e.region?`-${e.region}`:"",r=!1===e.https?"http":"https";s=void 0===e.oauthToken?`${r}://api${t}.storyblok.com/v2`:`${r}://api${t}.storyblok.com/v1`}let i=Object.assign({},e.headers),n=5;void 0!==e.oauthToken&&(i.Authorization=e.oauthToken,n=3),void 0!==e.rateLimit&&(n=e.rateLimit),this.richTextResolver=new o(e.richTextSchema),"function"==typeof e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=r(this.throttledRequest,n,1e3),this.accessToken=e.accessToken,this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.client=t.default.create({baseURL:s,timeout:e.timeout||0,headers:i,proxy:e.proxy||!1}),e.responseInterceptor&&this.client.interceptors.response.use((t=>e.responseInterceptor(t))),this.resolveNestedRelations=e.resolveNestedRelations||!0}setComponentResolver(e){this.richTextResolver.addNode("blok",(t=>{let s="";return t.attrs.body.forEach((t=>{s+=e(t.component,t)})),{html:s}}))}parseParams(e={}){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=h[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t={}){return((e="")=>e.indexOf("/cdn/")>-1)(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const i=this.factoryParamOptions(e,((e={},t=25,s=1)=>({...e,per_page:t,page:s}))(t,s,r));return this.cacheResponse(e,i)}get(e,t){let s=`/${e}`;const r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t={},s){const r=t.per_page||25,i=`/${e}`,n=i.split("/");s=s||n[n.length-1];const o=await this.makeRequest(i,t,r,1),l=o.total?Math.ceil(o.total/r):1;return((e=[],t)=>e.map(t).reduce(((e,t)=>[...e,...t]),[]))([o,...await(async(e=[],t)=>Promise.all(e.map(t)))(a(1,l),(async e=>this.makeRequest(i,t,r,e+1)))],(e=>Object.values(e.data[s])))}post(e,t){let s=`/${e}`;return this.throttle("post",s,t)}put(e,t){let s=`/${e}`;return this.throttle("put",s,t)}delete(e,t){let s=`/${e}`;return this.throttle("delete",s,t)}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}setToken(e){this.accessToken=e}getToken(){return this.accessToken}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const s=e[t];s&&"multilink"==s.fieldtype&&"story"==s.linktype&&"string"==typeof s.id&&this.links[s.id]?s.story=this._cleanCopy(this.links[s.id]):s&&"story"===s.linktype&&"string"==typeof s.uuid&&this.links[s.uuid]&&(s.story=this._cleanCopy(this.links[s.uuid]))}_insertRelations(e,t,s){if(s.indexOf(e.component+"."+t)>-1)if("string"==typeof e[t])this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t].constructor===Array){let s=[];e[t].forEach((e=>{this.relations[e]&&s.push(this._cleanCopy(this.relations[e]))})),e[t]=s}}_insertAssetsRelations(e,t){t.forEach((t=>{e.id===t.id&&(e.original=t,e.original.filename=e.filename,e.original.filename=e.original.filename.includes("https://s3.amazonaws.com/")?e.original.filename:e.original.filename.replace("https://","https://s3.amazonaws.com/"),delete e.original.s3_filename)}))}iterateTree(e,t){let s=e=>{if(null!=e)if(e.constructor===Array)for(let t=0;t<e.length;t++)s(e[t]);else if(e.constructor===Object){if(e._stopResolving)return;for(let r in e)e.component&&e._uid||"link"===e.type?(this._insertRelations(e,r,t),this._insertLinks(e,r)):"id"in e&&"asset"===e.fieldtype&&this._insertAssetsRelations(e,t),s(e[r])}};s(e.content)}async resolveLinks(e,t){let s=[];if(e.link_uuids){const r=e.link_uuids.length;let i=[];const n=50;for(let t=0;t<r;t+=n){const s=Math.min(r,t+n);i.push(e.link_uuids.slice(t,s))}for(let e=0;e<i.length;e++){(await this.getStories({per_page:n,language:t.language,version:t.version,by_uuids:i[e].join(",")})).data.stories.forEach((e=>{s.push(e)}))}}else s=e.links;s.forEach((e=>{this.links[e.uuid]={...e,_stopResolving:!0}}))}async resolveRelations(e,t){let s=[];if(e.rel_uuids){const r=e.rel_uuids.length;let i=[];const n=50;for(let t=0;t<r;t+=n){const s=Math.min(r,t+n);i.push(e.rel_uuids.slice(t,s))}for(let e=0;e<i.length;e++){(await this.getStories({per_page:n,language:t.language,version:t.version,by_uuids:i[e].join(",")})).data.stories.forEach((e=>{s.push(e)}))}}else s=e.rels;s.forEach((e=>{this.relations[e.uuid]={...e,_stopResolving:!0}}))}async resolveStories(e,t){let s=[];if(void 0!==t.resolve_relations&&t.resolve_relations.length>0&&(e.rels||e.rel_uuids)&&(s=t.resolve_relations.split(","),await this.resolveRelations(e,t)),["1","story","url"].indexOf(t.resolve_links)>-1&&(e.links||e.link_uuids)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const e in this.relations)this.iterateTree(this.relations[e],s);e.story?this.iterateTree(e.story,s):e.stories.forEach((e=>{this.iterateTree(e,s)}))}resolveAssetsRelations(e){const{assets:t,stories:s,story:r}=e;if(s)for(const e of s)this.iterateTree(e,t);else{if(!r)return e;this.iterateTree(r,t)}}cacheResponse(e,t,s){return void 0===s&&(s=0),new Promise((async(r,i)=>{let n=l({url:e,params:t}),o=this.cacheProvider();if("auto"===this.cache.clear&&"draft"===t.version&&await this.flushCache(),"published"===t.version&&"/cdn/spaces/me"!=e){const e=await o.get(n);if(e)return r(e)}try{let s=await this.throttle("get",e,{params:t,paramsSerializer:e=>l(e)}),a={data:s.data,headers:s.headers};if(a.data.assets&&a.data.assets.length&&this.resolveAssetsRelations(a.data),a=Object.assign({},a,{perPage:s.headers["per-page"]?parseInt(s.headers["per-page"]):0,total:s.headers["per-page"]?parseInt(s.headers.total):0}),200!=s.status)return i(s);(a.data.story||a.data.stories)&&await this.resolveStories(a.data,t),"published"===t.version&&"/cdn/spaces/me"!=e&&o.set(n,a),a.data.cv&&("draft"==t.version&&h[t.token]!=a.data.cv&&this.flushCache(),h[t.token]=a.data.cv),r(a)}catch(n){if(n.response&&429===n.response.status&&(s+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await(a=1e3*s,new Promise((e=>setTimeout(e,a)))),this.cacheResponse(e,t,s).then(r).catch(i);i(n)}var a}))}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return h}cacheVersion(){return h[this.accessToken]}setCacheVersion(e){this.accessToken&&(h[this.accessToken]=e)}cacheProvider(){return"memory"===this.cache.type?{get:e=>c[e],getAll:()=>c,set(e,t){c[e]=t},flush(){c={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}; |
@@ -6,2 +6,2 @@ /*! | ||
*/ | ||
import e from"axios";function t(e){return"number"==typeof e&&(e==e&&e!==1/0&&e!==-1/0)}function s(e,s,r){if(!t(s))throw new TypeError("Expected `limit` to be a finite number");if(!t(r))throw new TypeError("Expected `interval` to be a finite number");var i=[],n=[],o=0,a=function(){o++;var t=setTimeout((function(){o--,i.length>0&&a(),n=n.filter((function(e){return e!==t}))}),r);n.indexOf(t)<0&&n.push(t);var s=i.shift();s.resolve(e.apply(s.self,s.args))},l=function(){var e=arguments,t=this;return new Promise((function(r,n){i.push({resolve:r,reject:n,args:e,self:t}),o<s&&a()}))};return l.abort=function(){n.forEach(clearTimeout),n=[],i.forEach((function(e){e.reject(new throttle.AbortError)})),i.length=0},l}s.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const r=function(e,t){if(!e)return null;let s={};for(let r in e){let i=e[r];t.indexOf(r)>-1&&null!==i&&(s[r]=i)}return s};var i={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:e=>({tag:["pre",{tag:"code",attrs:e.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:e=>({tag:`h${e.attrs.level}`}),image:e=>({singleTag:[{tag:"img",attrs:r(e.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(e){const t={...e.attrs},{linktype:s="url"}=e.attrs;return"email"===s&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},styled:e=>({tag:[{tag:"span",attrs:e.attrs}]})}};class n{constructor(e){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={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach((e=>{t+=this.renderNode(e)})),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach((e=>{const s=this.getMatchingMark(e);s&&t.push(this.renderOpeningTag(s.tag))}));const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach((e=>{t.push(this.renderNode(e))})):e.text?t.push(function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,r=RegExp(s.source);return e&&r.test(e)?e.replace(s,(e=>t[e])):e}(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html&&t.push(s.html),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach((e=>{const s=this.getMatchingMark(e);s&&t.push(this.renderClosingTag(s.tag))})),t.join("")}renderTag(e,t){if(e.constructor===String)return`<${e}${t}>`;return e.map((e=>{if(e.constructor===String)return`<${e}${t}>`;{let s=`<${e.tag}`;if(e.attrs)for(let t in e.attrs){let r=e.attrs[t];null!==r&&(s+=` ${t}="${r}"`)}return`${s}${t}>`}})).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){if(e.constructor===String)return`</${e}>`;return e.slice(0).reverse().map((e=>e.constructor===String?`</${e}>`:`</${e.tag}>`)).join("")}getMatchingNode(e){if("function"==typeof this.nodes[e.type])return this.nodes[e.type](e)}getMatchingMark(e){if("function"==typeof this.marks[e.type])return this.marks[e.type](e)}}const o=(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return((e=0,t)=>[...Array(e)].map(t))(s,((t,s)=>s*r+e))},a=(e,t,s)=>{const r=[];for(const i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;const n=e[i],o=s?"":encodeURIComponent(i);let l;l="object"==typeof n?a(n,t?t+encodeURIComponent("["+o+"]"):o,Array.isArray(n)):(t?t+encodeURIComponent("["+o+"]"):o)+"="+encodeURIComponent(n),r.push(l)}return r.join("&")};let l={},c={};class h{constructor(t,r){if(!r){let e=t.region?`-${t.region}`:"",s=!1===t.https?"http":"https";r=void 0===t.oauthToken?`${s}://api${e}.storyblok.com/v2`:`${s}://api${e}.storyblok.com/v1`}let i=Object.assign({},t.headers),o=5;void 0!==t.oauthToken&&(i.Authorization=t.oauthToken,o=3),void 0!==t.rateLimit&&(o=t.rateLimit),this.richTextResolver=new n(t.richTextSchema),"function"==typeof t.componentResolver&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=s(this.throttledRequest,o,1e3),this.accessToken=t.accessToken,this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.client=e.create({baseURL:r,timeout:t.timeout||0,headers:i,proxy:t.proxy||!1}),t.responseInterceptor&&this.client.interceptors.response.use((e=>t.responseInterceptor(e))),this.resolveNestedRelations=t.resolveNestedRelations||!0}setComponentResolver(e){this.richTextResolver.addNode("blok",(t=>{let s="";return t.attrs.body.forEach((t=>{s+=e(t.component,t)})),{html:s}}))}parseParams(e={}){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=c[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t={}){return((e="")=>e.indexOf("/cdn/")>-1)(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const i=this.factoryParamOptions(e,((e={},t=25,s=1)=>({...e,per_page:t,page:s}))(t,s,r));return this.cacheResponse(e,i)}get(e,t){let s=`/${e}`;const r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t={},s){const r=t.per_page||25,i=`/${e}`,n=i.split("/");s=s||n[n.length-1];const a=await this.makeRequest(i,t,r,1),l=Math.ceil(a.total/r);return((e=[],t)=>e.map(t).reduce(((e,t)=>[...e,...t]),[]))([a,...await(async(e=[],t)=>Promise.all(e.map(t)))(o(1,l),(async e=>this.makeRequest(i,t,r,e+1)))],(e=>Object.values(e.data[s])))}post(e,t){let s=`/${e}`;return this.throttle("post",s,t)}put(e,t){let s=`/${e}`;return this.throttle("put",s,t)}delete(e,t){let s=`/${e}`;return this.throttle("delete",s,t)}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}setToken(e){this.accessToken=e}getToken(){return this.accessToken}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const s=e[t];s&&"multilink"==s.fieldtype&&"story"==s.linktype&&"string"==typeof s.id&&this.links[s.id]?s.story=this._cleanCopy(this.links[s.id]):s&&"story"===s.linktype&&"string"==typeof s.uuid&&this.links[s.uuid]&&(s.story=this._cleanCopy(this.links[s.uuid]))}_insertRelations(e,t,s){if(s.indexOf(e.component+"."+t)>-1)if("string"==typeof e[t])this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t].constructor===Array){let s=[];e[t].forEach((e=>{this.relations[e]&&s.push(this._cleanCopy(this.relations[e]))})),e[t]=s}}_insertAssetsRelations(e,t){t.forEach((t=>{e.id===t.id&&(e.original=t,e.original.filename=e.filename,e.original.filename=e.original.filename.includes("https://s3.amazonaws.com/")?e.original.filename:e.original.filename.replace("https://","https://s3.amazonaws.com/"),delete e.original.s3_filename)}))}iterateTree(e,t){let s=e=>{if(null!=e)if(e.constructor===Array)for(let t=0;t<e.length;t++)s(e[t]);else if(e.constructor===Object){if(e._stopResolving)return;for(let r in e)e.component&&e._uid||"link"===e.type?(this._insertRelations(e,r,t),this._insertLinks(e,r)):"id"in e&&"asset"===e.fieldtype&&this._insertAssetsRelations(e,t),s(e[r])}};s(e.content)}async resolveLinks(e,t){let s=[];if(e.link_uuids){const r=e.link_uuids.length;let i=[];const n=50;for(let t=0;t<r;t+=n){const s=Math.min(r,t+n);i.push(e.link_uuids.slice(t,s))}for(let e=0;e<i.length;e++){(await this.getStories({per_page:n,language:t.language,version:t.version,by_uuids:i[e].join(",")})).data.stories.forEach((e=>{s.push(e)}))}}else s=e.links;s.forEach((e=>{this.links[e.uuid]={...e,_stopResolving:!0}}))}async resolveRelations(e,t){let s=[];if(e.rel_uuids){const r=e.rel_uuids.length;let i=[];const n=50;for(let t=0;t<r;t+=n){const s=Math.min(r,t+n);i.push(e.rel_uuids.slice(t,s))}for(let e=0;e<i.length;e++){(await this.getStories({per_page:n,language:t.language,version:t.version,by_uuids:i[e].join(",")})).data.stories.forEach((e=>{s.push(e)}))}}else s=e.rels;s.forEach((e=>{this.relations[e.uuid]={...e,_stopResolving:!0}}))}async resolveStories(e,t){let s=[];if(void 0!==t.resolve_relations&&t.resolve_relations.length>0&&(e.rels||e.rel_uuids)&&(s=t.resolve_relations.split(","),await this.resolveRelations(e,t)),["1","story","url"].indexOf(t.resolve_links)>-1&&(e.links||e.link_uuids)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const e in this.relations)this.iterateTree(this.relations[e],s);e.story?this.iterateTree(e.story,s):e.stories.forEach((e=>{this.iterateTree(e,s)}))}resolveAssetsRelations(e){const{assets:t,stories:s,story:r}=e;if(s)for(const e of s)this.iterateTree(e,t);else{if(!r)return e;this.iterateTree(r,t)}}cacheResponse(e,t,s){return void 0===s&&(s=0),new Promise((async(r,i)=>{let n=a({url:e,params:t}),o=this.cacheProvider();if("auto"===this.cache.clear&&"draft"===t.version&&await this.flushCache(),"published"===t.version&&"/cdn/spaces/me"!=e){const e=await o.get(n);if(e)return r(e)}try{let s=await this.throttle("get",e,{params:t,paramsSerializer:e=>a(e)}),l={data:s.data,headers:s.headers};if(l.data.assets&&l.data.assets.length&&this.resolveAssetsRelations(l.data),s.headers["per-page"]&&(l=Object.assign({},l,{perPage:parseInt(s.headers["per-page"]),total:parseInt(s.headers.total)})),200!=s.status)return i(s);(l.data.story||l.data.stories)&&await this.resolveStories(l.data,t),"published"===t.version&&"/cdn/spaces/me"!=e&&o.set(n,l),l.data.cv&&("draft"==t.version&&c[t.token]!=l.data.cv&&this.flushCache(),c[t.token]=l.data.cv),r(l)}catch(n){if(n.response&&429===n.response.status&&(s+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await(l=1e3*s,new Promise((e=>setTimeout(e,l)))),this.cacheResponse(e,t,s).then(r).catch(i);i(n)}var l}))}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return c}cacheVersion(){return c[this.accessToken]}setCacheVersion(e){this.accessToken&&(c[this.accessToken]=e)}cacheProvider(){return"memory"===this.cache.type?{get:e=>l[e],getAll:()=>l,set(e,t){l[e]=t},flush(){l={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}export{h as default}; | ||
import e from"axios";function t(e){return"number"==typeof e&&(e==e&&e!==1/0&&e!==-1/0)}function s(e,s,r){if(!t(s))throw new TypeError("Expected `limit` to be a finite number");if(!t(r))throw new TypeError("Expected `interval` to be a finite number");var i=[],n=[],o=0,a=function(){o++;var t=setTimeout((function(){o--,i.length>0&&a(),n=n.filter((function(e){return e!==t}))}),r);n.indexOf(t)<0&&n.push(t);var s=i.shift();s.resolve(e.apply(s.self,s.args))},l=function(){var e=arguments,t=this;return new Promise((function(r,n){i.push({resolve:r,reject:n,args:e,self:t}),o<s&&a()}))};return l.abort=function(){n.forEach(clearTimeout),n=[],i.forEach((function(e){e.reject(new throttle.AbortError)})),i.length=0},l}s.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const r=function(e,t){if(!e)return null;let s={};for(let r in e){let i=e[r];t.indexOf(r)>-1&&null!==i&&(s[r]=i)}return s};var i={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:e=>({tag:["pre",{tag:"code",attrs:e.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:e=>({tag:`h${e.attrs.level}`}),image:e=>({singleTag:[{tag:"img",attrs:r(e.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(e){const t={...e.attrs},{linktype:s="url"}=e.attrs;return"email"===s&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},styled:e=>({tag:[{tag:"span",attrs:e.attrs}]})}};class n{constructor(e){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={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach((e=>{t+=this.renderNode(e)})),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach((e=>{const s=this.getMatchingMark(e);s&&t.push(this.renderOpeningTag(s.tag))}));const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach((e=>{t.push(this.renderNode(e))})):e.text?t.push(function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,r=RegExp(s.source);return e&&r.test(e)?e.replace(s,(e=>t[e])):e}(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html&&t.push(s.html),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach((e=>{const s=this.getMatchingMark(e);s&&t.push(this.renderClosingTag(s.tag))})),t.join("")}renderTag(e,t){if(e.constructor===String)return`<${e}${t}>`;return e.map((e=>{if(e.constructor===String)return`<${e}${t}>`;{let s=`<${e.tag}`;if(e.attrs)for(let t in e.attrs){let r=e.attrs[t];null!==r&&(s+=` ${t}="${r}"`)}return`${s}${t}>`}})).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){if(e.constructor===String)return`</${e}>`;return e.slice(0).reverse().map((e=>e.constructor===String?`</${e}>`:`</${e.tag}>`)).join("")}getMatchingNode(e){if("function"==typeof this.nodes[e.type])return this.nodes[e.type](e)}getMatchingMark(e){if("function"==typeof this.marks[e.type])return this.marks[e.type](e)}}const o=(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return((e=0,t)=>[...Array(e)].map(t))(s,((t,s)=>s*r+e))},a=(e,t,s)=>{const r=[];for(const i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;const n=e[i],o=s?"":encodeURIComponent(i);let l;l="object"==typeof n?a(n,t?t+encodeURIComponent("["+o+"]"):o,Array.isArray(n)):(t?t+encodeURIComponent("["+o+"]"):o)+"="+encodeURIComponent(n),r.push(l)}return r.join("&")};let l={},c={};class h{constructor(t,r){if(!r){let e=t.region?`-${t.region}`:"",s=!1===t.https?"http":"https";r=void 0===t.oauthToken?`${s}://api${e}.storyblok.com/v2`:`${s}://api${e}.storyblok.com/v1`}let i=Object.assign({},t.headers),o=5;void 0!==t.oauthToken&&(i.Authorization=t.oauthToken,o=3),void 0!==t.rateLimit&&(o=t.rateLimit),this.richTextResolver=new n(t.richTextSchema),"function"==typeof t.componentResolver&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=s(this.throttledRequest,o,1e3),this.accessToken=t.accessToken,this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.client=e.create({baseURL:r,timeout:t.timeout||0,headers:i,proxy:t.proxy||!1}),t.responseInterceptor&&this.client.interceptors.response.use((e=>t.responseInterceptor(e))),this.resolveNestedRelations=t.resolveNestedRelations||!0}setComponentResolver(e){this.richTextResolver.addNode("blok",(t=>{let s="";return t.attrs.body.forEach((t=>{s+=e(t.component,t)})),{html:s}}))}parseParams(e={}){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=c[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t={}){return((e="")=>e.indexOf("/cdn/")>-1)(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const i=this.factoryParamOptions(e,((e={},t=25,s=1)=>({...e,per_page:t,page:s}))(t,s,r));return this.cacheResponse(e,i)}get(e,t){let s=`/${e}`;const r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t={},s){const r=t.per_page||25,i=`/${e}`,n=i.split("/");s=s||n[n.length-1];const a=await this.makeRequest(i,t,r,1),l=a.total?Math.ceil(a.total/r):1;return((e=[],t)=>e.map(t).reduce(((e,t)=>[...e,...t]),[]))([a,...await(async(e=[],t)=>Promise.all(e.map(t)))(o(1,l),(async e=>this.makeRequest(i,t,r,e+1)))],(e=>Object.values(e.data[s])))}post(e,t){let s=`/${e}`;return this.throttle("post",s,t)}put(e,t){let s=`/${e}`;return this.throttle("put",s,t)}delete(e,t){let s=`/${e}`;return this.throttle("delete",s,t)}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}setToken(e){this.accessToken=e}getToken(){return this.accessToken}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const s=e[t];s&&"multilink"==s.fieldtype&&"story"==s.linktype&&"string"==typeof s.id&&this.links[s.id]?s.story=this._cleanCopy(this.links[s.id]):s&&"story"===s.linktype&&"string"==typeof s.uuid&&this.links[s.uuid]&&(s.story=this._cleanCopy(this.links[s.uuid]))}_insertRelations(e,t,s){if(s.indexOf(e.component+"."+t)>-1)if("string"==typeof e[t])this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t].constructor===Array){let s=[];e[t].forEach((e=>{this.relations[e]&&s.push(this._cleanCopy(this.relations[e]))})),e[t]=s}}_insertAssetsRelations(e,t){t.forEach((t=>{e.id===t.id&&(e.original=t,e.original.filename=e.filename,e.original.filename=e.original.filename.includes("https://s3.amazonaws.com/")?e.original.filename:e.original.filename.replace("https://","https://s3.amazonaws.com/"),delete e.original.s3_filename)}))}iterateTree(e,t){let s=e=>{if(null!=e)if(e.constructor===Array)for(let t=0;t<e.length;t++)s(e[t]);else if(e.constructor===Object){if(e._stopResolving)return;for(let r in e)e.component&&e._uid||"link"===e.type?(this._insertRelations(e,r,t),this._insertLinks(e,r)):"id"in e&&"asset"===e.fieldtype&&this._insertAssetsRelations(e,t),s(e[r])}};s(e.content)}async resolveLinks(e,t){let s=[];if(e.link_uuids){const r=e.link_uuids.length;let i=[];const n=50;for(let t=0;t<r;t+=n){const s=Math.min(r,t+n);i.push(e.link_uuids.slice(t,s))}for(let e=0;e<i.length;e++){(await this.getStories({per_page:n,language:t.language,version:t.version,by_uuids:i[e].join(",")})).data.stories.forEach((e=>{s.push(e)}))}}else s=e.links;s.forEach((e=>{this.links[e.uuid]={...e,_stopResolving:!0}}))}async resolveRelations(e,t){let s=[];if(e.rel_uuids){const r=e.rel_uuids.length;let i=[];const n=50;for(let t=0;t<r;t+=n){const s=Math.min(r,t+n);i.push(e.rel_uuids.slice(t,s))}for(let e=0;e<i.length;e++){(await this.getStories({per_page:n,language:t.language,version:t.version,by_uuids:i[e].join(",")})).data.stories.forEach((e=>{s.push(e)}))}}else s=e.rels;s.forEach((e=>{this.relations[e.uuid]={...e,_stopResolving:!0}}))}async resolveStories(e,t){let s=[];if(void 0!==t.resolve_relations&&t.resolve_relations.length>0&&(e.rels||e.rel_uuids)&&(s=t.resolve_relations.split(","),await this.resolveRelations(e,t)),["1","story","url"].indexOf(t.resolve_links)>-1&&(e.links||e.link_uuids)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const e in this.relations)this.iterateTree(this.relations[e],s);e.story?this.iterateTree(e.story,s):e.stories.forEach((e=>{this.iterateTree(e,s)}))}resolveAssetsRelations(e){const{assets:t,stories:s,story:r}=e;if(s)for(const e of s)this.iterateTree(e,t);else{if(!r)return e;this.iterateTree(r,t)}}cacheResponse(e,t,s){return void 0===s&&(s=0),new Promise((async(r,i)=>{let n=a({url:e,params:t}),o=this.cacheProvider();if("auto"===this.cache.clear&&"draft"===t.version&&await this.flushCache(),"published"===t.version&&"/cdn/spaces/me"!=e){const e=await o.get(n);if(e)return r(e)}try{let s=await this.throttle("get",e,{params:t,paramsSerializer:e=>a(e)}),l={data:s.data,headers:s.headers};if(l.data.assets&&l.data.assets.length&&this.resolveAssetsRelations(l.data),l=Object.assign({},l,{perPage:s.headers["per-page"]?parseInt(s.headers["per-page"]):0,total:s.headers["per-page"]?parseInt(s.headers.total):0}),200!=s.status)return i(s);(l.data.story||l.data.stories)&&await this.resolveStories(l.data,t),"published"===t.version&&"/cdn/spaces/me"!=e&&o.set(n,l),l.data.cv&&("draft"==t.version&&c[t.token]!=l.data.cv&&this.flushCache(),c[t.token]=l.data.cv),r(l)}catch(n){if(n.response&&429===n.response.status&&(s+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await(l=1e3*s,new Promise((e=>setTimeout(e,l)))),this.cacheResponse(e,t,s).then(r).catch(i);i(n)}var l}))}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return c}cacheVersion(){return c[this.accessToken]}setCacheVersion(e){this.accessToken&&(c[this.accessToken]=e)}cacheProvider(){return"memory"===this.cache.type?{get:e=>l[e],getAll:()=>l,set(e,t){l[e]=t},flush(){l={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}export{h as default}; |
@@ -6,2 +6,2 @@ /*! | ||
*/ | ||
var StoryblokClient=function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t,r={exports:{}},n={exports:{}},o=function(e,t){return function(){for(var r=new Array(arguments.length),n=0;n<r.length;n++)r[n]=arguments[n];return e.apply(t,r)}},i=o,s=Object.prototype.toString,a=(t=Object.create(null),function(e){var r=s.call(e);return t[r]||(t[r]=r.slice(8,-1).toLowerCase())});function u(e){return e=e.toLowerCase(),function(t){return a(t)===e}}function c(e){return Array.isArray(e)}function l(e){return void 0===e}var f=u("ArrayBuffer");function h(e){return null!==e&&"object"==typeof e}function p(e){if("object"!==a(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}var d=u("Date"),g=u("File"),m=u("Blob"),v=u("FileList");function y(e){return"[object Function]"===s.call(e)}var E=u("URLSearchParams");function b(e,t){if(null!=e)if("object"!=typeof e&&(e=[e]),c(e))for(var r=0,n=e.length;r<n;r++)t.call(null,e[r],r,e);else for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.call(null,e[o],o,e)}var R,w=(R="undefined"!=typeof Uint8Array&&Object.getPrototypeOf(Uint8Array),function(e){return R&&e instanceof R}),O={isArray:c,isArrayBuffer:f,isBuffer:function(e){return null!==e&&!l(e)&&null!==e.constructor&&!l(e.constructor)&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)},isFormData:function(e){var t="[object FormData]";return e&&("function"==typeof FormData&&e instanceof FormData||s.call(e)===t||y(e.toString)&&e.toString()===t)},isArrayBufferView:function(e){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&f(e.buffer)},isString:function(e){return"string"==typeof e},isNumber:function(e){return"number"==typeof e},isObject:h,isPlainObject:p,isUndefined:l,isDate:d,isFile:g,isBlob:m,isFunction:y,isStream:function(e){return h(e)&&y(e.pipe)},isURLSearchParams:E,isStandardBrowserEnv:function(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product&&"NativeScript"!==navigator.product&&"NS"!==navigator.product)&&("undefined"!=typeof window&&"undefined"!=typeof document)},forEach:b,merge:function e(){var t={};function r(r,n){p(t[n])&&p(r)?t[n]=e(t[n],r):p(r)?t[n]=e({},r):c(r)?t[n]=r.slice():t[n]=r}for(var n=0,o=arguments.length;n<o;n++)b(arguments[n],r);return t},extend:function(e,t,r){return b(t,(function(t,n){e[n]=r&&"function"==typeof t?i(t,r):t})),e},trim:function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")},stripBOM:function(e){return 65279===e.charCodeAt(0)&&(e=e.slice(1)),e},inherits:function(e,t,r,n){e.prototype=Object.create(t.prototype,n),e.prototype.constructor=e,r&&Object.assign(e.prototype,r)},toFlatObject:function(e,t,r){var n,o,i,s={};t=t||{};do{for(o=(n=Object.getOwnPropertyNames(e)).length;o-- >0;)s[i=n[o]]||(t[i]=e[i],s[i]=!0);e=Object.getPrototypeOf(e)}while(e&&(!r||r(e,t))&&e!==Object.prototype);return t},kindOf:a,kindOfTest:u,endsWith:function(e,t,r){e=String(e),(void 0===r||r>e.length)&&(r=e.length),r-=t.length;var n=e.indexOf(t,r);return-1!==n&&n===r},toArray:function(e){if(!e)return null;var t=e.length;if(l(t))return null;for(var r=new Array(t);t-- >0;)r[t]=e[t];return r},isTypedArray:w,isFileList:v},T=O;function _(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var k=function(e,t,r){if(!t)return e;var n;if(r)n=r(t);else if(T.isURLSearchParams(t))n=t.toString();else{var o=[];T.forEach(t,(function(e,t){null!=e&&(T.isArray(e)?t+="[]":e=[e],T.forEach(e,(function(e){T.isDate(e)?e=e.toISOString():T.isObject(e)&&(e=JSON.stringify(e)),o.push(_(t)+"="+_(e))})))})),n=o.join("&")}if(n){var i=e.indexOf("#");-1!==i&&(e=e.slice(0,i)),e+=(-1===e.indexOf("?")?"?":"&")+n}return e},A=O;function S(){this.handlers=[]}S.prototype.use=function(e,t,r){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!r&&r.synchronous,runWhen:r?r.runWhen:null}),this.handlers.length-1},S.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},S.prototype.forEach=function(e){A.forEach(this.handlers,(function(t){null!==t&&e(t)}))};var x,C,j=S,N=O;function P(){if(C)return x;C=1;var e=O;function t(e,t,r,n,o){Error.call(this),this.message=e,this.name="AxiosError",t&&(this.code=t),r&&(this.config=r),n&&(this.request=n),o&&(this.response=o)}e.inherits(t,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code,status:this.response&&this.response.status?this.response.status:null}}});var r=t.prototype,n={};return["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED"].forEach((function(e){n[e]={value:e}})),Object.defineProperties(t,n),Object.defineProperty(r,"isAxiosError",{value:!0}),t.from=function(n,o,i,s,a,u){var c=Object.create(r);return e.toFlatObject(n,c,(function(e){return e!==Error.prototype})),t.call(c,n.message,o,i,s,a),c.name=n.name,u&&Object.assign(c,u),c},x=t}var U,B,D,L,$,q,I={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1};function M(){if(B)return U;B=1;var e=O;return U=function(t,r){r=r||new FormData;var n=[];function o(t){return null===t?"":e.isDate(t)?t.toISOString():e.isArrayBuffer(t)||e.isTypedArray(t)?"function"==typeof Blob?new Blob([t]):Buffer.from(t):t}return function t(i,s){if(e.isPlainObject(i)||e.isArray(i)){if(-1!==n.indexOf(i))throw Error("Circular reference detected in "+s);n.push(i),e.forEach(i,(function(n,i){if(!e.isUndefined(n)){var a,u=s?s+"."+i:i;if(n&&!s&&"object"==typeof n)if(e.endsWith(i,"{}"))n=JSON.stringify(n);else if(e.endsWith(i,"[]")&&(a=e.toArray(n)))return void a.forEach((function(t){!e.isUndefined(t)&&r.append(u,o(t))}));t(n,u)}})),n.pop()}else r.append(s,o(i))}(t),r},U}function F(){if(L)return D;L=1;var e=P();return D=function(t,r,n){var o=n.config.validateStatus;n.status&&o&&!o(n.status)?r(new e("Request failed with status code "+n.status,[e.ERR_BAD_REQUEST,e.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n)):t(n)}}function J(){if(q)return $;q=1;var e=O;return $=e.isStandardBrowserEnv()?{write:function(t,r,n,o,i,s){var a=[];a.push(t+"="+encodeURIComponent(r)),e.isNumber(n)&&a.push("expires="+new Date(n).toGMTString()),e.isString(o)&&a.push("path="+o),e.isString(i)&&a.push("domain="+i),!0===s&&a.push("secure"),document.cookie=a.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}}}var z,V,H,W,X,K,Q,G,Y,Z,ee,te,re=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},ne=function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e},oe=function(e,t){return e&&!re(t)?ne(e,t):t};function ie(){if(V)return z;V=1;var e=O,t=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"];return z=function(r){var n,o,i,s={};return r?(e.forEach(r.split("\n"),(function(r){if(i=r.indexOf(":"),n=e.trim(r.substr(0,i)).toLowerCase(),o=e.trim(r.substr(i+1)),n){if(s[n]&&t.indexOf(n)>=0)return;s[n]="set-cookie"===n?(s[n]?s[n]:[]).concat([o]):s[n]?s[n]+", "+o:o}})),s):s}}function se(){if(W)return H;W=1;var e=O;return H=e.isStandardBrowserEnv()?function(){var t,r=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");function o(e){var t=e;return r&&(n.setAttribute("href",t),t=n.href),n.setAttribute("href",t),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:"/"===n.pathname.charAt(0)?n.pathname:"/"+n.pathname}}return t=o(window.location.href),function(r){var n=e.isString(r)?o(r):r;return n.protocol===t.protocol&&n.host===t.host}}():function(){return!0}}function ae(){if(K)return X;K=1;var e=P();function t(t){e.call(this,null==t?"canceled":t,e.ERR_CANCELED),this.name="CanceledError"}return O.inherits(t,e,{__CANCEL__:!0}),X=t}function ue(){return G?Q:(G=1,Q=function(e){var t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""})}function ce(){if(Z)return Y;Z=1;var e=O,t=F(),r=J(),n=k,o=oe,i=ie(),s=se(),a=I,u=P(),c=ae(),l=ue();return Y=function(f){return new Promise((function(h,p){var d,g=f.data,m=f.headers,v=f.responseType;function y(){f.cancelToken&&f.cancelToken.unsubscribe(d),f.signal&&f.signal.removeEventListener("abort",d)}e.isFormData(g)&&e.isStandardBrowserEnv()&&delete m["Content-Type"];var E=new XMLHttpRequest;if(f.auth){var b=f.auth.username||"",R=f.auth.password?unescape(encodeURIComponent(f.auth.password)):"";m.Authorization="Basic "+btoa(b+":"+R)}var w=o(f.baseURL,f.url);function O(){if(E){var e="getAllResponseHeaders"in E?i(E.getAllResponseHeaders()):null,r={data:v&&"text"!==v&&"json"!==v?E.response:E.responseText,status:E.status,statusText:E.statusText,headers:e,config:f,request:E};t((function(e){h(e),y()}),(function(e){p(e),y()}),r),E=null}}if(E.open(f.method.toUpperCase(),n(w,f.params,f.paramsSerializer),!0),E.timeout=f.timeout,"onloadend"in E?E.onloadend=O:E.onreadystatechange=function(){E&&4===E.readyState&&(0!==E.status||E.responseURL&&0===E.responseURL.indexOf("file:"))&&setTimeout(O)},E.onabort=function(){E&&(p(new u("Request aborted",u.ECONNABORTED,f,E)),E=null)},E.onerror=function(){p(new u("Network Error",u.ERR_NETWORK,f,E,E)),E=null},E.ontimeout=function(){var e=f.timeout?"timeout of "+f.timeout+"ms exceeded":"timeout exceeded",t=f.transitional||a;f.timeoutErrorMessage&&(e=f.timeoutErrorMessage),p(new u(e,t.clarifyTimeoutError?u.ETIMEDOUT:u.ECONNABORTED,f,E)),E=null},e.isStandardBrowserEnv()){var T=(f.withCredentials||s(w))&&f.xsrfCookieName?r.read(f.xsrfCookieName):void 0;T&&(m[f.xsrfHeaderName]=T)}"setRequestHeader"in E&&e.forEach(m,(function(e,t){void 0===g&&"content-type"===t.toLowerCase()?delete m[t]:E.setRequestHeader(t,e)})),e.isUndefined(f.withCredentials)||(E.withCredentials=!!f.withCredentials),v&&"json"!==v&&(E.responseType=f.responseType),"function"==typeof f.onDownloadProgress&&E.addEventListener("progress",f.onDownloadProgress),"function"==typeof f.onUploadProgress&&E.upload&&E.upload.addEventListener("progress",f.onUploadProgress),(f.cancelToken||f.signal)&&(d=function(e){E&&(p(!e||e&&e.type?new c:e),E.abort(),E=null)},f.cancelToken&&f.cancelToken.subscribe(d),f.signal&&(f.signal.aborted?d():f.signal.addEventListener("abort",d))),g||(g=null);var _=l(w);_&&-1===["http","https","file"].indexOf(_)?p(new u("Unsupported protocol "+_+":",u.ERR_BAD_REQUEST,f)):E.send(g)}))},Y}var le=O,fe=function(e,t){N.forEach(e,(function(r,n){n!==t&&n.toUpperCase()===t.toUpperCase()&&(e[t]=r,delete e[n])}))},he=P(),pe=I,de=M(),ge={"Content-Type":"application/x-www-form-urlencoded"};function me(e,t){!le.isUndefined(e)&&le.isUndefined(e["Content-Type"])&&(e["Content-Type"]=t)}var ve,ye={transitional:pe,adapter:(("undefined"!=typeof XMLHttpRequest||"undefined"!=typeof process&&"[object process]"===Object.prototype.toString.call(process))&&(ve=ce()),ve),transformRequest:[function(e,t){if(fe(t,"Accept"),fe(t,"Content-Type"),le.isFormData(e)||le.isArrayBuffer(e)||le.isBuffer(e)||le.isStream(e)||le.isFile(e)||le.isBlob(e))return e;if(le.isArrayBufferView(e))return e.buffer;if(le.isURLSearchParams(e))return me(t,"application/x-www-form-urlencoded;charset=utf-8"),e.toString();var r,n=le.isObject(e),o=t&&t["Content-Type"];if((r=le.isFileList(e))||n&&"multipart/form-data"===o){var i=this.env&&this.env.FormData;return de(r?{"files[]":e}:e,i&&new i)}return n||"application/json"===o?(me(t,"application/json"),function(e,t,r){if(le.isString(e))try{return(t||JSON.parse)(e),le.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(r||JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){var t=this.transitional||ye.transitional,r=t&&t.silentJSONParsing,n=t&&t.forcedJSONParsing,o=!r&&"json"===this.responseType;if(o||n&&le.isString(e)&&e.length)try{return JSON.parse(e)}catch(e){if(o){if("SyntaxError"===e.name)throw he.from(e,he.ERR_BAD_RESPONSE,this,null,this.response);throw e}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:te?ee:(te=1,ee=null)},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};le.forEach(["delete","get","head"],(function(e){ye.headers[e]={}})),le.forEach(["post","put","patch"],(function(e){ye.headers[e]=le.merge(ge)}));var Ee,be,Re=ye,we=O,Oe=Re;function Te(){return be?Ee:(be=1,Ee=function(e){return!(!e||!e.__CANCEL__)})}var _e=O,ke=function(e,t,r){var n=this||Oe;return we.forEach(r,(function(r){e=r.call(n,e,t)})),e},Ae=Te(),Se=Re,xe=ae();function Ce(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new xe}var je,Ne,Pe=O,Ue=function(e,t){t=t||{};var r={};function n(e,t){return Pe.isPlainObject(e)&&Pe.isPlainObject(t)?Pe.merge(e,t):Pe.isPlainObject(t)?Pe.merge({},t):Pe.isArray(t)?t.slice():t}function o(r){return Pe.isUndefined(t[r])?Pe.isUndefined(e[r])?void 0:n(void 0,e[r]):n(e[r],t[r])}function i(e){if(!Pe.isUndefined(t[e]))return n(void 0,t[e])}function s(r){return Pe.isUndefined(t[r])?Pe.isUndefined(e[r])?void 0:n(void 0,e[r]):n(void 0,t[r])}function a(r){return r in t?n(e[r],t[r]):r in e?n(void 0,e[r]):void 0}var u={url:i,method:i,data:i,baseURL:s,transformRequest:s,transformResponse:s,paramsSerializer:s,timeout:s,timeoutMessage:s,withCredentials:s,adapter:s,responseType:s,xsrfCookieName:s,xsrfHeaderName:s,onUploadProgress:s,onDownloadProgress:s,decompress:s,maxContentLength:s,maxBodyLength:s,beforeRedirect:s,transport:s,httpAgent:s,httpsAgent:s,cancelToken:s,socketPath:s,responseEncoding:s,validateStatus:a};return Pe.forEach(Object.keys(e).concat(Object.keys(t)),(function(e){var t=u[e]||o,n=t(e);Pe.isUndefined(n)&&t!==a||(r[e]=n)})),r};function Be(){return Ne?je:(Ne=1,je={version:"0.27.2"})}var De=Be().version,Le=P(),$e={};["object","boolean","number","function","string","symbol"].forEach((function(e,t){$e[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}}));var qe={};$e.transitional=function(e,t,r){function n(e,t){return"[Axios v"+De+"] Transitional option '"+e+"'"+t+(r?". "+r:"")}return function(r,o,i){if(!1===e)throw new Le(n(o," has been removed"+(t?" in "+t:"")),Le.ERR_DEPRECATED);return t&&!qe[o]&&(qe[o]=!0,console.warn(n(o," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(r,o,i)}};var Ie,Me,Fe,Je,ze,Ve,He={assertOptions:function(e,t,r){if("object"!=typeof e)throw new Le("options must be an object",Le.ERR_BAD_OPTION_VALUE);for(var n=Object.keys(e),o=n.length;o-- >0;){var i=n[o],s=t[i];if(s){var a=e[i],u=void 0===a||s(a,i,e);if(!0!==u)throw new Le("option "+i+" must be "+u,Le.ERR_BAD_OPTION_VALUE)}else if(!0!==r)throw new Le("Unknown option "+i,Le.ERR_BAD_OPTION)}},validators:$e},We=O,Xe=k,Ke=j,Qe=function(e){return Ce(e),e.headers=e.headers||{},e.data=ke.call(e,e.data,e.headers,e.transformRequest),e.headers=_e.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),_e.forEach(["delete","get","head","post","put","patch","common"],(function(t){delete e.headers[t]})),(e.adapter||Se.adapter)(e).then((function(t){return Ce(e),t.data=ke.call(e,t.data,t.headers,e.transformResponse),t}),(function(t){return Ae(t)||(Ce(e),t&&t.response&&(t.response.data=ke.call(e,t.response.data,t.response.headers,e.transformResponse))),Promise.reject(t)}))},Ge=Ue,Ye=oe,Ze=He,et=Ze.validators;function tt(e){this.defaults=e,this.interceptors={request:new Ke,response:new Ke}}tt.prototype.request=function(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{},(t=Ge(this.defaults,t)).method?t.method=t.method.toLowerCase():this.defaults.method?t.method=this.defaults.method.toLowerCase():t.method="get";var r=t.transitional;void 0!==r&&Ze.assertOptions(r,{silentJSONParsing:et.transitional(et.boolean),forcedJSONParsing:et.transitional(et.boolean),clarifyTimeoutError:et.transitional(et.boolean)},!1);var n=[],o=!0;this.interceptors.request.forEach((function(e){"function"==typeof e.runWhen&&!1===e.runWhen(t)||(o=o&&e.synchronous,n.unshift(e.fulfilled,e.rejected))}));var i,s=[];if(this.interceptors.response.forEach((function(e){s.push(e.fulfilled,e.rejected)})),!o){var a=[Qe,void 0];for(Array.prototype.unshift.apply(a,n),a=a.concat(s),i=Promise.resolve(t);a.length;)i=i.then(a.shift(),a.shift());return i}for(var u=t;n.length;){var c=n.shift(),l=n.shift();try{u=c(u)}catch(e){l(e);break}}try{i=Qe(u)}catch(e){return Promise.reject(e)}for(;s.length;)i=i.then(s.shift(),s.shift());return i},tt.prototype.getUri=function(e){e=Ge(this.defaults,e);var t=Ye(e.baseURL,e.url);return Xe(t,e.params,e.paramsSerializer)},We.forEach(["delete","get","head","options"],(function(e){tt.prototype[e]=function(t,r){return this.request(Ge(r||{},{method:e,url:t,data:(r||{}).data}))}})),We.forEach(["post","put","patch"],(function(e){function t(t){return function(r,n,o){return this.request(Ge(o||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:r,data:n}))}}tt.prototype[e]=t(),tt.prototype[e+"Form"]=t(!0)}));var rt=O,nt=o,ot=tt,it=Ue;var st=function e(t){var r=new ot(t),n=nt(ot.prototype.request,r);return rt.extend(n,ot.prototype,r),rt.extend(n,r),n.create=function(r){return e(it(t,r))},n}(Re);st.Axios=ot,st.CanceledError=ae(),st.CancelToken=function(){if(Me)return Ie;Me=1;var e=ae();function t(t){if("function"!=typeof t)throw new TypeError("executor must be a function.");var r;this.promise=new Promise((function(e){r=e}));var n=this;this.promise.then((function(e){if(n._listeners){var t,r=n._listeners.length;for(t=0;t<r;t++)n._listeners[t](e);n._listeners=null}})),this.promise.then=function(e){var t,r=new Promise((function(e){n.subscribe(e),t=e})).then(e);return r.cancel=function(){n.unsubscribe(t)},r},t((function(t){n.reason||(n.reason=new e(t),r(n.reason))}))}return t.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},t.prototype.subscribe=function(e){this.reason?e(this.reason):this._listeners?this._listeners.push(e):this._listeners=[e]},t.prototype.unsubscribe=function(e){if(this._listeners){var t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1)}},t.source=function(){var e;return{token:new t((function(t){e=t})),cancel:e}},Ie=t}(),st.isCancel=Te(),st.VERSION=Be().version,st.toFormData=M(),st.AxiosError=P(),st.Cancel=st.CanceledError,st.all=function(e){return Promise.all(e)},st.spread=Je?Fe:(Je=1,Fe=function(e){return function(t){return e.apply(null,t)}}),st.isAxiosError=function(){if(Ve)return ze;Ve=1;var e=O;return ze=function(t){return e.isObject(t)&&!0===t.isAxiosError}}(),n.exports=st,n.exports.default=st,r.exports=n.exports;var at=e(r.exports);function ut(e){return"number"==typeof e&&(e==e&&e!==1/0&&e!==-1/0)}function ct(e,t,r){if(!ut(t))throw new TypeError("Expected `limit` to be a finite number");if(!ut(r))throw new TypeError("Expected `interval` to be a finite number");var n=[],o=[],i=0,s=function(){i++;var t=setTimeout((function(){i--,n.length>0&&s(),o=o.filter((function(e){return e!==t}))}),r);o.indexOf(t)<0&&o.push(t);var a=n.shift();a.resolve(e.apply(a.self,a.args))},a=function(){var e=arguments,r=this;return new Promise((function(o,a){n.push({resolve:o,reject:a,args:e,self:r}),i<t&&s()}))};return a.abort=function(){o.forEach(clearTimeout),o=[],n.forEach((function(e){e.reject(new throttle.AbortError)})),n.length=0},a}ct.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const lt=function(e,t){if(!e)return null;let r={};for(let n in e){let o=e[n];t.indexOf(n)>-1&&null!==o&&(r[n]=o)}return r};var ft={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:e=>({tag:["pre",{tag:"code",attrs:e.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:e=>({tag:`h${e.attrs.level}`}),image:e=>({singleTag:[{tag:"img",attrs:lt(e.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(e){const t={...e.attrs},{linktype:r="url"}=e.attrs;return"email"===r&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},styled:e=>({tag:[{tag:"span",attrs:e.attrs}]})}};class ht{constructor(e){e||(e=ft),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach((e=>{t+=this.renderNode(e)})),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach((e=>{const r=this.getMatchingMark(e);r&&t.push(this.renderOpeningTag(r.tag))}));const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach((e=>{t.push(this.renderNode(e))})):e.text?t.push(function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},r=/[&<>"']/g,n=RegExp(r.source);return e&&n.test(e)?e.replace(r,(e=>t[e])):e}(e.text)):r&&r.singleTag?t.push(this.renderTag(r.singleTag," /")):r&&r.html&&t.push(r.html),r&&r.tag&&t.push(this.renderClosingTag(r.tag)),e.marks&&e.marks.slice(0).reverse().forEach((e=>{const r=this.getMatchingMark(e);r&&t.push(this.renderClosingTag(r.tag))})),t.join("")}renderTag(e,t){if(e.constructor===String)return`<${e}${t}>`;return e.map((e=>{if(e.constructor===String)return`<${e}${t}>`;{let r=`<${e.tag}`;if(e.attrs)for(let t in e.attrs){let n=e.attrs[t];null!==n&&(r+=` ${t}="${n}"`)}return`${r}${t}>`}})).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){if(e.constructor===String)return`</${e}>`;return e.slice(0).reverse().map((e=>e.constructor===String?`</${e}>`:`</${e.tag}>`)).join("")}getMatchingNode(e){if("function"==typeof this.nodes[e.type])return this.nodes[e.type](e)}getMatchingMark(e){if("function"==typeof this.marks[e.type])return this.marks[e.type](e)}}const pt=(e=0,t=e)=>{const r=Math.abs(t-e)||0,n=e<t?1:-1;return((e=0,t)=>[...Array(e)].map(t))(r,((t,r)=>r*n+e))},dt=(e,t,r)=>{const n=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const i=e[o],s=r?"":encodeURIComponent(o);let a;a="object"==typeof i?dt(i,t?t+encodeURIComponent("["+s+"]"):s,Array.isArray(i)):(t?t+encodeURIComponent("["+s+"]"):s)+"="+encodeURIComponent(i),n.push(a)}return n.join("&")};let gt={},mt={};return class{constructor(e,t){if(!t){let r=e.region?`-${e.region}`:"",n=!1===e.https?"http":"https";t=void 0===e.oauthToken?`${n}://api${r}.storyblok.com/v2`:`${n}://api${r}.storyblok.com/v1`}let r=Object.assign({},e.headers),n=5;void 0!==e.oauthToken&&(r.Authorization=e.oauthToken,n=3),void 0!==e.rateLimit&&(n=e.rateLimit),this.richTextResolver=new ht(e.richTextSchema),"function"==typeof e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=ct(this.throttledRequest,n,1e3),this.accessToken=e.accessToken,this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.client=at.create({baseURL:t,timeout:e.timeout||0,headers:r,proxy:e.proxy||!1}),e.responseInterceptor&&this.client.interceptors.response.use((t=>e.responseInterceptor(t))),this.resolveNestedRelations=e.resolveNestedRelations||!0}setComponentResolver(e){this.richTextResolver.addNode("blok",(t=>{let r="";return t.attrs.body.forEach((t=>{r+=e(t.component,t)})),{html:r}}))}parseParams(e={}){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=mt[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t={}){return((e="")=>e.indexOf("/cdn/")>-1)(e)?this.parseParams(t):t}makeRequest(e,t,r,n){const o=this.factoryParamOptions(e,((e={},t=25,r=1)=>({...e,per_page:t,page:r}))(t,r,n));return this.cacheResponse(e,o)}get(e,t){let r=`/${e}`;const n=this.factoryParamOptions(r,t);return this.cacheResponse(r,n)}async getAll(e,t={},r){const n=t.per_page||25,o=`/${e}`,i=o.split("/");r=r||i[i.length-1];const s=await this.makeRequest(o,t,n,1),a=Math.ceil(s.total/n);return((e=[],t)=>e.map(t).reduce(((e,t)=>[...e,...t]),[]))([s,...await(async(e=[],t)=>Promise.all(e.map(t)))(pt(1,a),(async e=>this.makeRequest(o,t,n,e+1)))],(e=>Object.values(e.data[r])))}post(e,t){let r=`/${e}`;return this.throttle("post",r,t)}put(e,t){let r=`/${e}`;return this.throttle("put",r,t)}delete(e,t){let r=`/${e}`;return this.throttle("delete",r,t)}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}setToken(e){this.accessToken=e}getToken(){return this.accessToken}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const r=e[t];r&&"multilink"==r.fieldtype&&"story"==r.linktype&&"string"==typeof r.id&&this.links[r.id]?r.story=this._cleanCopy(this.links[r.id]):r&&"story"===r.linktype&&"string"==typeof r.uuid&&this.links[r.uuid]&&(r.story=this._cleanCopy(this.links[r.uuid]))}_insertRelations(e,t,r){if(r.indexOf(e.component+"."+t)>-1)if("string"==typeof e[t])this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t].constructor===Array){let r=[];e[t].forEach((e=>{this.relations[e]&&r.push(this._cleanCopy(this.relations[e]))})),e[t]=r}}_insertAssetsRelations(e,t){t.forEach((t=>{e.id===t.id&&(e.original=t,e.original.filename=e.filename,e.original.filename=e.original.filename.includes("https://s3.amazonaws.com/")?e.original.filename:e.original.filename.replace("https://","https://s3.amazonaws.com/"),delete e.original.s3_filename)}))}iterateTree(e,t){let r=e=>{if(null!=e)if(e.constructor===Array)for(let t=0;t<e.length;t++)r(e[t]);else if(e.constructor===Object){if(e._stopResolving)return;for(let n in e)e.component&&e._uid||"link"===e.type?(this._insertRelations(e,n,t),this._insertLinks(e,n)):"id"in e&&"asset"===e.fieldtype&&this._insertAssetsRelations(e,t),r(e[n])}};r(e.content)}async resolveLinks(e,t){let r=[];if(e.link_uuids){const n=e.link_uuids.length;let o=[];const i=50;for(let t=0;t<n;t+=i){const r=Math.min(n,t+i);o.push(e.link_uuids.slice(t,r))}for(let e=0;e<o.length;e++){(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:o[e].join(",")})).data.stories.forEach((e=>{r.push(e)}))}}else r=e.links;r.forEach((e=>{this.links[e.uuid]={...e,_stopResolving:!0}}))}async resolveRelations(e,t){let r=[];if(e.rel_uuids){const n=e.rel_uuids.length;let o=[];const i=50;for(let t=0;t<n;t+=i){const r=Math.min(n,t+i);o.push(e.rel_uuids.slice(t,r))}for(let e=0;e<o.length;e++){(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:o[e].join(",")})).data.stories.forEach((e=>{r.push(e)}))}}else r=e.rels;r.forEach((e=>{this.relations[e.uuid]={...e,_stopResolving:!0}}))}async resolveStories(e,t){let r=[];if(void 0!==t.resolve_relations&&t.resolve_relations.length>0&&(e.rels||e.rel_uuids)&&(r=t.resolve_relations.split(","),await this.resolveRelations(e,t)),["1","story","url"].indexOf(t.resolve_links)>-1&&(e.links||e.link_uuids)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const e in this.relations)this.iterateTree(this.relations[e],r);e.story?this.iterateTree(e.story,r):e.stories.forEach((e=>{this.iterateTree(e,r)}))}resolveAssetsRelations(e){const{assets:t,stories:r,story:n}=e;if(r)for(const e of r)this.iterateTree(e,t);else{if(!n)return e;this.iterateTree(n,t)}}cacheResponse(e,t,r){return void 0===r&&(r=0),new Promise((async(n,o)=>{let i=dt({url:e,params:t}),s=this.cacheProvider();if("auto"===this.cache.clear&&"draft"===t.version&&await this.flushCache(),"published"===t.version&&"/cdn/spaces/me"!=e){const e=await s.get(i);if(e)return n(e)}try{let r=await this.throttle("get",e,{params:t,paramsSerializer:e=>dt(e)}),a={data:r.data,headers:r.headers};if(a.data.assets&&a.data.assets.length&&this.resolveAssetsRelations(a.data),r.headers["per-page"]&&(a=Object.assign({},a,{perPage:parseInt(r.headers["per-page"]),total:parseInt(r.headers.total)})),200!=r.status)return o(r);(a.data.story||a.data.stories)&&await this.resolveStories(a.data,t),"published"===t.version&&"/cdn/spaces/me"!=e&&s.set(i,a),a.data.cv&&("draft"==t.version&&mt[t.token]!=a.data.cv&&this.flushCache(),mt[t.token]=a.data.cv),n(a)}catch(i){if(i.response&&429===i.response.status&&(r+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${r} seconds.`),await(a=1e3*r,new Promise((e=>setTimeout(e,a)))),this.cacheResponse(e,t,r).then(n).catch(o);o(i)}var a}))}throttledRequest(e,t,r){return this.client[e](t,r)}cacheVersions(){return mt}cacheVersion(){return mt[this.accessToken]}setCacheVersion(e){this.accessToken&&(mt[this.accessToken]=e)}cacheProvider(){return"memory"===this.cache.type?{get:e=>gt[e],getAll:()=>gt,set(e,t){gt[e]=t},flush(){gt={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}}(); | ||
var StoryblokClient=function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t,r={exports:{}},n={exports:{}},o=function(e,t){return function(){for(var r=new Array(arguments.length),n=0;n<r.length;n++)r[n]=arguments[n];return e.apply(t,r)}},i=o,s=Object.prototype.toString,a=(t=Object.create(null),function(e){var r=s.call(e);return t[r]||(t[r]=r.slice(8,-1).toLowerCase())});function u(e){return e=e.toLowerCase(),function(t){return a(t)===e}}function c(e){return Array.isArray(e)}function l(e){return void 0===e}var f=u("ArrayBuffer");function h(e){return null!==e&&"object"==typeof e}function p(e){if("object"!==a(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}var d=u("Date"),g=u("File"),m=u("Blob"),v=u("FileList");function y(e){return"[object Function]"===s.call(e)}var E=u("URLSearchParams");function b(e,t){if(null!=e)if("object"!=typeof e&&(e=[e]),c(e))for(var r=0,n=e.length;r<n;r++)t.call(null,e[r],r,e);else for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.call(null,e[o],o,e)}var R,w=(R="undefined"!=typeof Uint8Array&&Object.getPrototypeOf(Uint8Array),function(e){return R&&e instanceof R}),O={isArray:c,isArrayBuffer:f,isBuffer:function(e){return null!==e&&!l(e)&&null!==e.constructor&&!l(e.constructor)&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)},isFormData:function(e){var t="[object FormData]";return e&&("function"==typeof FormData&&e instanceof FormData||s.call(e)===t||y(e.toString)&&e.toString()===t)},isArrayBufferView:function(e){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&f(e.buffer)},isString:function(e){return"string"==typeof e},isNumber:function(e){return"number"==typeof e},isObject:h,isPlainObject:p,isUndefined:l,isDate:d,isFile:g,isBlob:m,isFunction:y,isStream:function(e){return h(e)&&y(e.pipe)},isURLSearchParams:E,isStandardBrowserEnv:function(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product&&"NativeScript"!==navigator.product&&"NS"!==navigator.product)&&("undefined"!=typeof window&&"undefined"!=typeof document)},forEach:b,merge:function e(){var t={};function r(r,n){p(t[n])&&p(r)?t[n]=e(t[n],r):p(r)?t[n]=e({},r):c(r)?t[n]=r.slice():t[n]=r}for(var n=0,o=arguments.length;n<o;n++)b(arguments[n],r);return t},extend:function(e,t,r){return b(t,(function(t,n){e[n]=r&&"function"==typeof t?i(t,r):t})),e},trim:function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")},stripBOM:function(e){return 65279===e.charCodeAt(0)&&(e=e.slice(1)),e},inherits:function(e,t,r,n){e.prototype=Object.create(t.prototype,n),e.prototype.constructor=e,r&&Object.assign(e.prototype,r)},toFlatObject:function(e,t,r){var n,o,i,s={};t=t||{};do{for(o=(n=Object.getOwnPropertyNames(e)).length;o-- >0;)s[i=n[o]]||(t[i]=e[i],s[i]=!0);e=Object.getPrototypeOf(e)}while(e&&(!r||r(e,t))&&e!==Object.prototype);return t},kindOf:a,kindOfTest:u,endsWith:function(e,t,r){e=String(e),(void 0===r||r>e.length)&&(r=e.length),r-=t.length;var n=e.indexOf(t,r);return-1!==n&&n===r},toArray:function(e){if(!e)return null;var t=e.length;if(l(t))return null;for(var r=new Array(t);t-- >0;)r[t]=e[t];return r},isTypedArray:w,isFileList:v},T=O;function _(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var k=function(e,t,r){if(!t)return e;var n;if(r)n=r(t);else if(T.isURLSearchParams(t))n=t.toString();else{var o=[];T.forEach(t,(function(e,t){null!=e&&(T.isArray(e)?t+="[]":e=[e],T.forEach(e,(function(e){T.isDate(e)?e=e.toISOString():T.isObject(e)&&(e=JSON.stringify(e)),o.push(_(t)+"="+_(e))})))})),n=o.join("&")}if(n){var i=e.indexOf("#");-1!==i&&(e=e.slice(0,i)),e+=(-1===e.indexOf("?")?"?":"&")+n}return e},A=O;function S(){this.handlers=[]}S.prototype.use=function(e,t,r){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!r&&r.synchronous,runWhen:r?r.runWhen:null}),this.handlers.length-1},S.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},S.prototype.forEach=function(e){A.forEach(this.handlers,(function(t){null!==t&&e(t)}))};var x,C,j=S,N=O;function P(){if(C)return x;C=1;var e=O;function t(e,t,r,n,o){Error.call(this),this.message=e,this.name="AxiosError",t&&(this.code=t),r&&(this.config=r),n&&(this.request=n),o&&(this.response=o)}e.inherits(t,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code,status:this.response&&this.response.status?this.response.status:null}}});var r=t.prototype,n={};return["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED"].forEach((function(e){n[e]={value:e}})),Object.defineProperties(t,n),Object.defineProperty(r,"isAxiosError",{value:!0}),t.from=function(n,o,i,s,a,u){var c=Object.create(r);return e.toFlatObject(n,c,(function(e){return e!==Error.prototype})),t.call(c,n.message,o,i,s,a),c.name=n.name,u&&Object.assign(c,u),c},x=t}var U,B,D,L,$,q,I={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1};function M(){if(B)return U;B=1;var e=O;return U=function(t,r){r=r||new FormData;var n=[];function o(t){return null===t?"":e.isDate(t)?t.toISOString():e.isArrayBuffer(t)||e.isTypedArray(t)?"function"==typeof Blob?new Blob([t]):Buffer.from(t):t}return function t(i,s){if(e.isPlainObject(i)||e.isArray(i)){if(-1!==n.indexOf(i))throw Error("Circular reference detected in "+s);n.push(i),e.forEach(i,(function(n,i){if(!e.isUndefined(n)){var a,u=s?s+"."+i:i;if(n&&!s&&"object"==typeof n)if(e.endsWith(i,"{}"))n=JSON.stringify(n);else if(e.endsWith(i,"[]")&&(a=e.toArray(n)))return void a.forEach((function(t){!e.isUndefined(t)&&r.append(u,o(t))}));t(n,u)}})),n.pop()}else r.append(s,o(i))}(t),r},U}function F(){if(L)return D;L=1;var e=P();return D=function(t,r,n){var o=n.config.validateStatus;n.status&&o&&!o(n.status)?r(new e("Request failed with status code "+n.status,[e.ERR_BAD_REQUEST,e.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n)):t(n)}}function J(){if(q)return $;q=1;var e=O;return $=e.isStandardBrowserEnv()?{write:function(t,r,n,o,i,s){var a=[];a.push(t+"="+encodeURIComponent(r)),e.isNumber(n)&&a.push("expires="+new Date(n).toGMTString()),e.isString(o)&&a.push("path="+o),e.isString(i)&&a.push("domain="+i),!0===s&&a.push("secure"),document.cookie=a.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}}}var z,V,H,W,X,K,Q,G,Y,Z,ee,te,re=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},ne=function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e},oe=function(e,t){return e&&!re(t)?ne(e,t):t};function ie(){if(V)return z;V=1;var e=O,t=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"];return z=function(r){var n,o,i,s={};return r?(e.forEach(r.split("\n"),(function(r){if(i=r.indexOf(":"),n=e.trim(r.substr(0,i)).toLowerCase(),o=e.trim(r.substr(i+1)),n){if(s[n]&&t.indexOf(n)>=0)return;s[n]="set-cookie"===n?(s[n]?s[n]:[]).concat([o]):s[n]?s[n]+", "+o:o}})),s):s}}function se(){if(W)return H;W=1;var e=O;return H=e.isStandardBrowserEnv()?function(){var t,r=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");function o(e){var t=e;return r&&(n.setAttribute("href",t),t=n.href),n.setAttribute("href",t),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:"/"===n.pathname.charAt(0)?n.pathname:"/"+n.pathname}}return t=o(window.location.href),function(r){var n=e.isString(r)?o(r):r;return n.protocol===t.protocol&&n.host===t.host}}():function(){return!0}}function ae(){if(K)return X;K=1;var e=P();function t(t){e.call(this,null==t?"canceled":t,e.ERR_CANCELED),this.name="CanceledError"}return O.inherits(t,e,{__CANCEL__:!0}),X=t}function ue(){return G?Q:(G=1,Q=function(e){var t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""})}function ce(){if(Z)return Y;Z=1;var e=O,t=F(),r=J(),n=k,o=oe,i=ie(),s=se(),a=I,u=P(),c=ae(),l=ue();return Y=function(f){return new Promise((function(h,p){var d,g=f.data,m=f.headers,v=f.responseType;function y(){f.cancelToken&&f.cancelToken.unsubscribe(d),f.signal&&f.signal.removeEventListener("abort",d)}e.isFormData(g)&&e.isStandardBrowserEnv()&&delete m["Content-Type"];var E=new XMLHttpRequest;if(f.auth){var b=f.auth.username||"",R=f.auth.password?unescape(encodeURIComponent(f.auth.password)):"";m.Authorization="Basic "+btoa(b+":"+R)}var w=o(f.baseURL,f.url);function O(){if(E){var e="getAllResponseHeaders"in E?i(E.getAllResponseHeaders()):null,r={data:v&&"text"!==v&&"json"!==v?E.response:E.responseText,status:E.status,statusText:E.statusText,headers:e,config:f,request:E};t((function(e){h(e),y()}),(function(e){p(e),y()}),r),E=null}}if(E.open(f.method.toUpperCase(),n(w,f.params,f.paramsSerializer),!0),E.timeout=f.timeout,"onloadend"in E?E.onloadend=O:E.onreadystatechange=function(){E&&4===E.readyState&&(0!==E.status||E.responseURL&&0===E.responseURL.indexOf("file:"))&&setTimeout(O)},E.onabort=function(){E&&(p(new u("Request aborted",u.ECONNABORTED,f,E)),E=null)},E.onerror=function(){p(new u("Network Error",u.ERR_NETWORK,f,E,E)),E=null},E.ontimeout=function(){var e=f.timeout?"timeout of "+f.timeout+"ms exceeded":"timeout exceeded",t=f.transitional||a;f.timeoutErrorMessage&&(e=f.timeoutErrorMessage),p(new u(e,t.clarifyTimeoutError?u.ETIMEDOUT:u.ECONNABORTED,f,E)),E=null},e.isStandardBrowserEnv()){var T=(f.withCredentials||s(w))&&f.xsrfCookieName?r.read(f.xsrfCookieName):void 0;T&&(m[f.xsrfHeaderName]=T)}"setRequestHeader"in E&&e.forEach(m,(function(e,t){void 0===g&&"content-type"===t.toLowerCase()?delete m[t]:E.setRequestHeader(t,e)})),e.isUndefined(f.withCredentials)||(E.withCredentials=!!f.withCredentials),v&&"json"!==v&&(E.responseType=f.responseType),"function"==typeof f.onDownloadProgress&&E.addEventListener("progress",f.onDownloadProgress),"function"==typeof f.onUploadProgress&&E.upload&&E.upload.addEventListener("progress",f.onUploadProgress),(f.cancelToken||f.signal)&&(d=function(e){E&&(p(!e||e&&e.type?new c:e),E.abort(),E=null)},f.cancelToken&&f.cancelToken.subscribe(d),f.signal&&(f.signal.aborted?d():f.signal.addEventListener("abort",d))),g||(g=null);var _=l(w);_&&-1===["http","https","file"].indexOf(_)?p(new u("Unsupported protocol "+_+":",u.ERR_BAD_REQUEST,f)):E.send(g)}))},Y}var le=O,fe=function(e,t){N.forEach(e,(function(r,n){n!==t&&n.toUpperCase()===t.toUpperCase()&&(e[t]=r,delete e[n])}))},he=P(),pe=I,de=M(),ge={"Content-Type":"application/x-www-form-urlencoded"};function me(e,t){!le.isUndefined(e)&&le.isUndefined(e["Content-Type"])&&(e["Content-Type"]=t)}var ve,ye={transitional:pe,adapter:(("undefined"!=typeof XMLHttpRequest||"undefined"!=typeof process&&"[object process]"===Object.prototype.toString.call(process))&&(ve=ce()),ve),transformRequest:[function(e,t){if(fe(t,"Accept"),fe(t,"Content-Type"),le.isFormData(e)||le.isArrayBuffer(e)||le.isBuffer(e)||le.isStream(e)||le.isFile(e)||le.isBlob(e))return e;if(le.isArrayBufferView(e))return e.buffer;if(le.isURLSearchParams(e))return me(t,"application/x-www-form-urlencoded;charset=utf-8"),e.toString();var r,n=le.isObject(e),o=t&&t["Content-Type"];if((r=le.isFileList(e))||n&&"multipart/form-data"===o){var i=this.env&&this.env.FormData;return de(r?{"files[]":e}:e,i&&new i)}return n||"application/json"===o?(me(t,"application/json"),function(e,t,r){if(le.isString(e))try{return(t||JSON.parse)(e),le.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(r||JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){var t=this.transitional||ye.transitional,r=t&&t.silentJSONParsing,n=t&&t.forcedJSONParsing,o=!r&&"json"===this.responseType;if(o||n&&le.isString(e)&&e.length)try{return JSON.parse(e)}catch(e){if(o){if("SyntaxError"===e.name)throw he.from(e,he.ERR_BAD_RESPONSE,this,null,this.response);throw e}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:te?ee:(te=1,ee=null)},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};le.forEach(["delete","get","head"],(function(e){ye.headers[e]={}})),le.forEach(["post","put","patch"],(function(e){ye.headers[e]=le.merge(ge)}));var Ee,be,Re=ye,we=O,Oe=Re;function Te(){return be?Ee:(be=1,Ee=function(e){return!(!e||!e.__CANCEL__)})}var _e=O,ke=function(e,t,r){var n=this||Oe;return we.forEach(r,(function(r){e=r.call(n,e,t)})),e},Ae=Te(),Se=Re,xe=ae();function Ce(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new xe}var je,Ne,Pe=O,Ue=function(e,t){t=t||{};var r={};function n(e,t){return Pe.isPlainObject(e)&&Pe.isPlainObject(t)?Pe.merge(e,t):Pe.isPlainObject(t)?Pe.merge({},t):Pe.isArray(t)?t.slice():t}function o(r){return Pe.isUndefined(t[r])?Pe.isUndefined(e[r])?void 0:n(void 0,e[r]):n(e[r],t[r])}function i(e){if(!Pe.isUndefined(t[e]))return n(void 0,t[e])}function s(r){return Pe.isUndefined(t[r])?Pe.isUndefined(e[r])?void 0:n(void 0,e[r]):n(void 0,t[r])}function a(r){return r in t?n(e[r],t[r]):r in e?n(void 0,e[r]):void 0}var u={url:i,method:i,data:i,baseURL:s,transformRequest:s,transformResponse:s,paramsSerializer:s,timeout:s,timeoutMessage:s,withCredentials:s,adapter:s,responseType:s,xsrfCookieName:s,xsrfHeaderName:s,onUploadProgress:s,onDownloadProgress:s,decompress:s,maxContentLength:s,maxBodyLength:s,beforeRedirect:s,transport:s,httpAgent:s,httpsAgent:s,cancelToken:s,socketPath:s,responseEncoding:s,validateStatus:a};return Pe.forEach(Object.keys(e).concat(Object.keys(t)),(function(e){var t=u[e]||o,n=t(e);Pe.isUndefined(n)&&t!==a||(r[e]=n)})),r};function Be(){return Ne?je:(Ne=1,je={version:"0.27.2"})}var De=Be().version,Le=P(),$e={};["object","boolean","number","function","string","symbol"].forEach((function(e,t){$e[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}}));var qe={};$e.transitional=function(e,t,r){function n(e,t){return"[Axios v"+De+"] Transitional option '"+e+"'"+t+(r?". "+r:"")}return function(r,o,i){if(!1===e)throw new Le(n(o," has been removed"+(t?" in "+t:"")),Le.ERR_DEPRECATED);return t&&!qe[o]&&(qe[o]=!0,console.warn(n(o," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(r,o,i)}};var Ie,Me,Fe,Je,ze,Ve,He={assertOptions:function(e,t,r){if("object"!=typeof e)throw new Le("options must be an object",Le.ERR_BAD_OPTION_VALUE);for(var n=Object.keys(e),o=n.length;o-- >0;){var i=n[o],s=t[i];if(s){var a=e[i],u=void 0===a||s(a,i,e);if(!0!==u)throw new Le("option "+i+" must be "+u,Le.ERR_BAD_OPTION_VALUE)}else if(!0!==r)throw new Le("Unknown option "+i,Le.ERR_BAD_OPTION)}},validators:$e},We=O,Xe=k,Ke=j,Qe=function(e){return Ce(e),e.headers=e.headers||{},e.data=ke.call(e,e.data,e.headers,e.transformRequest),e.headers=_e.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),_e.forEach(["delete","get","head","post","put","patch","common"],(function(t){delete e.headers[t]})),(e.adapter||Se.adapter)(e).then((function(t){return Ce(e),t.data=ke.call(e,t.data,t.headers,e.transformResponse),t}),(function(t){return Ae(t)||(Ce(e),t&&t.response&&(t.response.data=ke.call(e,t.response.data,t.response.headers,e.transformResponse))),Promise.reject(t)}))},Ge=Ue,Ye=oe,Ze=He,et=Ze.validators;function tt(e){this.defaults=e,this.interceptors={request:new Ke,response:new Ke}}tt.prototype.request=function(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{},(t=Ge(this.defaults,t)).method?t.method=t.method.toLowerCase():this.defaults.method?t.method=this.defaults.method.toLowerCase():t.method="get";var r=t.transitional;void 0!==r&&Ze.assertOptions(r,{silentJSONParsing:et.transitional(et.boolean),forcedJSONParsing:et.transitional(et.boolean),clarifyTimeoutError:et.transitional(et.boolean)},!1);var n=[],o=!0;this.interceptors.request.forEach((function(e){"function"==typeof e.runWhen&&!1===e.runWhen(t)||(o=o&&e.synchronous,n.unshift(e.fulfilled,e.rejected))}));var i,s=[];if(this.interceptors.response.forEach((function(e){s.push(e.fulfilled,e.rejected)})),!o){var a=[Qe,void 0];for(Array.prototype.unshift.apply(a,n),a=a.concat(s),i=Promise.resolve(t);a.length;)i=i.then(a.shift(),a.shift());return i}for(var u=t;n.length;){var c=n.shift(),l=n.shift();try{u=c(u)}catch(e){l(e);break}}try{i=Qe(u)}catch(e){return Promise.reject(e)}for(;s.length;)i=i.then(s.shift(),s.shift());return i},tt.prototype.getUri=function(e){e=Ge(this.defaults,e);var t=Ye(e.baseURL,e.url);return Xe(t,e.params,e.paramsSerializer)},We.forEach(["delete","get","head","options"],(function(e){tt.prototype[e]=function(t,r){return this.request(Ge(r||{},{method:e,url:t,data:(r||{}).data}))}})),We.forEach(["post","put","patch"],(function(e){function t(t){return function(r,n,o){return this.request(Ge(o||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:r,data:n}))}}tt.prototype[e]=t(),tt.prototype[e+"Form"]=t(!0)}));var rt=O,nt=o,ot=tt,it=Ue;var st=function e(t){var r=new ot(t),n=nt(ot.prototype.request,r);return rt.extend(n,ot.prototype,r),rt.extend(n,r),n.create=function(r){return e(it(t,r))},n}(Re);st.Axios=ot,st.CanceledError=ae(),st.CancelToken=function(){if(Me)return Ie;Me=1;var e=ae();function t(t){if("function"!=typeof t)throw new TypeError("executor must be a function.");var r;this.promise=new Promise((function(e){r=e}));var n=this;this.promise.then((function(e){if(n._listeners){var t,r=n._listeners.length;for(t=0;t<r;t++)n._listeners[t](e);n._listeners=null}})),this.promise.then=function(e){var t,r=new Promise((function(e){n.subscribe(e),t=e})).then(e);return r.cancel=function(){n.unsubscribe(t)},r},t((function(t){n.reason||(n.reason=new e(t),r(n.reason))}))}return t.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},t.prototype.subscribe=function(e){this.reason?e(this.reason):this._listeners?this._listeners.push(e):this._listeners=[e]},t.prototype.unsubscribe=function(e){if(this._listeners){var t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1)}},t.source=function(){var e;return{token:new t((function(t){e=t})),cancel:e}},Ie=t}(),st.isCancel=Te(),st.VERSION=Be().version,st.toFormData=M(),st.AxiosError=P(),st.Cancel=st.CanceledError,st.all=function(e){return Promise.all(e)},st.spread=Je?Fe:(Je=1,Fe=function(e){return function(t){return e.apply(null,t)}}),st.isAxiosError=function(){if(Ve)return ze;Ve=1;var e=O;return ze=function(t){return e.isObject(t)&&!0===t.isAxiosError}}(),n.exports=st,n.exports.default=st,r.exports=n.exports;var at=e(r.exports);function ut(e){return"number"==typeof e&&(e==e&&e!==1/0&&e!==-1/0)}function ct(e,t,r){if(!ut(t))throw new TypeError("Expected `limit` to be a finite number");if(!ut(r))throw new TypeError("Expected `interval` to be a finite number");var n=[],o=[],i=0,s=function(){i++;var t=setTimeout((function(){i--,n.length>0&&s(),o=o.filter((function(e){return e!==t}))}),r);o.indexOf(t)<0&&o.push(t);var a=n.shift();a.resolve(e.apply(a.self,a.args))},a=function(){var e=arguments,r=this;return new Promise((function(o,a){n.push({resolve:o,reject:a,args:e,self:r}),i<t&&s()}))};return a.abort=function(){o.forEach(clearTimeout),o=[],n.forEach((function(e){e.reject(new throttle.AbortError)})),n.length=0},a}ct.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const lt=function(e,t){if(!e)return null;let r={};for(let n in e){let o=e[n];t.indexOf(n)>-1&&null!==o&&(r[n]=o)}return r};var ft={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:e=>({tag:["pre",{tag:"code",attrs:e.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:e=>({tag:`h${e.attrs.level}`}),image:e=>({singleTag:[{tag:"img",attrs:lt(e.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(e){const t={...e.attrs},{linktype:r="url"}=e.attrs;return"email"===r&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},styled:e=>({tag:[{tag:"span",attrs:e.attrs}]})}};class ht{constructor(e){e||(e=ft),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach((e=>{t+=this.renderNode(e)})),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach((e=>{const r=this.getMatchingMark(e);r&&t.push(this.renderOpeningTag(r.tag))}));const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach((e=>{t.push(this.renderNode(e))})):e.text?t.push(function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},r=/[&<>"']/g,n=RegExp(r.source);return e&&n.test(e)?e.replace(r,(e=>t[e])):e}(e.text)):r&&r.singleTag?t.push(this.renderTag(r.singleTag," /")):r&&r.html&&t.push(r.html),r&&r.tag&&t.push(this.renderClosingTag(r.tag)),e.marks&&e.marks.slice(0).reverse().forEach((e=>{const r=this.getMatchingMark(e);r&&t.push(this.renderClosingTag(r.tag))})),t.join("")}renderTag(e,t){if(e.constructor===String)return`<${e}${t}>`;return e.map((e=>{if(e.constructor===String)return`<${e}${t}>`;{let r=`<${e.tag}`;if(e.attrs)for(let t in e.attrs){let n=e.attrs[t];null!==n&&(r+=` ${t}="${n}"`)}return`${r}${t}>`}})).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){if(e.constructor===String)return`</${e}>`;return e.slice(0).reverse().map((e=>e.constructor===String?`</${e}>`:`</${e.tag}>`)).join("")}getMatchingNode(e){if("function"==typeof this.nodes[e.type])return this.nodes[e.type](e)}getMatchingMark(e){if("function"==typeof this.marks[e.type])return this.marks[e.type](e)}}const pt=(e=0,t=e)=>{const r=Math.abs(t-e)||0,n=e<t?1:-1;return((e=0,t)=>[...Array(e)].map(t))(r,((t,r)=>r*n+e))},dt=(e,t,r)=>{const n=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const i=e[o],s=r?"":encodeURIComponent(o);let a;a="object"==typeof i?dt(i,t?t+encodeURIComponent("["+s+"]"):s,Array.isArray(i)):(t?t+encodeURIComponent("["+s+"]"):s)+"="+encodeURIComponent(i),n.push(a)}return n.join("&")};let gt={},mt={};return class{constructor(e,t){if(!t){let r=e.region?`-${e.region}`:"",n=!1===e.https?"http":"https";t=void 0===e.oauthToken?`${n}://api${r}.storyblok.com/v2`:`${n}://api${r}.storyblok.com/v1`}let r=Object.assign({},e.headers),n=5;void 0!==e.oauthToken&&(r.Authorization=e.oauthToken,n=3),void 0!==e.rateLimit&&(n=e.rateLimit),this.richTextResolver=new ht(e.richTextSchema),"function"==typeof e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=ct(this.throttledRequest,n,1e3),this.accessToken=e.accessToken,this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.client=at.create({baseURL:t,timeout:e.timeout||0,headers:r,proxy:e.proxy||!1}),e.responseInterceptor&&this.client.interceptors.response.use((t=>e.responseInterceptor(t))),this.resolveNestedRelations=e.resolveNestedRelations||!0}setComponentResolver(e){this.richTextResolver.addNode("blok",(t=>{let r="";return t.attrs.body.forEach((t=>{r+=e(t.component,t)})),{html:r}}))}parseParams(e={}){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=mt[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t={}){return((e="")=>e.indexOf("/cdn/")>-1)(e)?this.parseParams(t):t}makeRequest(e,t,r,n){const o=this.factoryParamOptions(e,((e={},t=25,r=1)=>({...e,per_page:t,page:r}))(t,r,n));return this.cacheResponse(e,o)}get(e,t){let r=`/${e}`;const n=this.factoryParamOptions(r,t);return this.cacheResponse(r,n)}async getAll(e,t={},r){const n=t.per_page||25,o=`/${e}`,i=o.split("/");r=r||i[i.length-1];const s=await this.makeRequest(o,t,n,1),a=s.total?Math.ceil(s.total/n):1;return((e=[],t)=>e.map(t).reduce(((e,t)=>[...e,...t]),[]))([s,...await(async(e=[],t)=>Promise.all(e.map(t)))(pt(1,a),(async e=>this.makeRequest(o,t,n,e+1)))],(e=>Object.values(e.data[r])))}post(e,t){let r=`/${e}`;return this.throttle("post",r,t)}put(e,t){let r=`/${e}`;return this.throttle("put",r,t)}delete(e,t){let r=`/${e}`;return this.throttle("delete",r,t)}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}setToken(e){this.accessToken=e}getToken(){return this.accessToken}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const r=e[t];r&&"multilink"==r.fieldtype&&"story"==r.linktype&&"string"==typeof r.id&&this.links[r.id]?r.story=this._cleanCopy(this.links[r.id]):r&&"story"===r.linktype&&"string"==typeof r.uuid&&this.links[r.uuid]&&(r.story=this._cleanCopy(this.links[r.uuid]))}_insertRelations(e,t,r){if(r.indexOf(e.component+"."+t)>-1)if("string"==typeof e[t])this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t].constructor===Array){let r=[];e[t].forEach((e=>{this.relations[e]&&r.push(this._cleanCopy(this.relations[e]))})),e[t]=r}}_insertAssetsRelations(e,t){t.forEach((t=>{e.id===t.id&&(e.original=t,e.original.filename=e.filename,e.original.filename=e.original.filename.includes("https://s3.amazonaws.com/")?e.original.filename:e.original.filename.replace("https://","https://s3.amazonaws.com/"),delete e.original.s3_filename)}))}iterateTree(e,t){let r=e=>{if(null!=e)if(e.constructor===Array)for(let t=0;t<e.length;t++)r(e[t]);else if(e.constructor===Object){if(e._stopResolving)return;for(let n in e)e.component&&e._uid||"link"===e.type?(this._insertRelations(e,n,t),this._insertLinks(e,n)):"id"in e&&"asset"===e.fieldtype&&this._insertAssetsRelations(e,t),r(e[n])}};r(e.content)}async resolveLinks(e,t){let r=[];if(e.link_uuids){const n=e.link_uuids.length;let o=[];const i=50;for(let t=0;t<n;t+=i){const r=Math.min(n,t+i);o.push(e.link_uuids.slice(t,r))}for(let e=0;e<o.length;e++){(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:o[e].join(",")})).data.stories.forEach((e=>{r.push(e)}))}}else r=e.links;r.forEach((e=>{this.links[e.uuid]={...e,_stopResolving:!0}}))}async resolveRelations(e,t){let r=[];if(e.rel_uuids){const n=e.rel_uuids.length;let o=[];const i=50;for(let t=0;t<n;t+=i){const r=Math.min(n,t+i);o.push(e.rel_uuids.slice(t,r))}for(let e=0;e<o.length;e++){(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:o[e].join(",")})).data.stories.forEach((e=>{r.push(e)}))}}else r=e.rels;r.forEach((e=>{this.relations[e.uuid]={...e,_stopResolving:!0}}))}async resolveStories(e,t){let r=[];if(void 0!==t.resolve_relations&&t.resolve_relations.length>0&&(e.rels||e.rel_uuids)&&(r=t.resolve_relations.split(","),await this.resolveRelations(e,t)),["1","story","url"].indexOf(t.resolve_links)>-1&&(e.links||e.link_uuids)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const e in this.relations)this.iterateTree(this.relations[e],r);e.story?this.iterateTree(e.story,r):e.stories.forEach((e=>{this.iterateTree(e,r)}))}resolveAssetsRelations(e){const{assets:t,stories:r,story:n}=e;if(r)for(const e of r)this.iterateTree(e,t);else{if(!n)return e;this.iterateTree(n,t)}}cacheResponse(e,t,r){return void 0===r&&(r=0),new Promise((async(n,o)=>{let i=dt({url:e,params:t}),s=this.cacheProvider();if("auto"===this.cache.clear&&"draft"===t.version&&await this.flushCache(),"published"===t.version&&"/cdn/spaces/me"!=e){const e=await s.get(i);if(e)return n(e)}try{let r=await this.throttle("get",e,{params:t,paramsSerializer:e=>dt(e)}),a={data:r.data,headers:r.headers};if(a.data.assets&&a.data.assets.length&&this.resolveAssetsRelations(a.data),a=Object.assign({},a,{perPage:r.headers["per-page"]?parseInt(r.headers["per-page"]):0,total:r.headers["per-page"]?parseInt(r.headers.total):0}),200!=r.status)return o(r);(a.data.story||a.data.stories)&&await this.resolveStories(a.data,t),"published"===t.version&&"/cdn/spaces/me"!=e&&s.set(i,a),a.data.cv&&("draft"==t.version&&mt[t.token]!=a.data.cv&&this.flushCache(),mt[t.token]=a.data.cv),n(a)}catch(i){if(i.response&&429===i.response.status&&(r+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${r} seconds.`),await(a=1e3*r,new Promise((e=>setTimeout(e,a)))),this.cacheResponse(e,t,r).then(n).catch(o);o(i)}var a}))}throttledRequest(e,t,r){return this.client[e](t,r)}cacheVersions(){return mt}cacheVersion(){return mt[this.accessToken]}setCacheVersion(e){this.accessToken&&(mt[this.accessToken]=e)}cacheProvider(){return"memory"===this.cache.type?{get:e=>gt[e],getAll:()=>gt,set(e,t){gt[e]=t},flush(){gt={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}}(); |
{ | ||
"name": "storyblok-js-client", | ||
"version": "4.5.7", | ||
"version": "4.5.8", | ||
"description": "Universal JavaScript SDK for Storyblok's API", | ||
@@ -5,0 +5,0 @@ "types": "./types/index.d.ts", |
@@ -137,3 +137,3 @@ "use strict"; | ||
const firstRes = await this.makeRequest(url, params, perPage, firstPage); | ||
const lastPage = Math.ceil(firstRes.total / perPage); | ||
const lastPage = firstRes.total ? Math.ceil(firstRes.total / perPage) : 1; | ||
@@ -405,8 +405,6 @@ const restRes = await asyncMap(range(firstPage, lastPage), async (i) => { | ||
if (res.headers["per-page"]) { | ||
response = Object.assign({}, response, { | ||
perPage: parseInt(res.headers["per-page"]), | ||
total: parseInt(res.headers["total"]), | ||
}); | ||
} | ||
response = Object.assign({}, response, { | ||
perPage: res.headers["per-page"] ? parseInt(res.headers["per-page"]) : 0, | ||
total: res.headers["per-page"] ? parseInt(res.headers["total"]): 0, | ||
}); | ||
@@ -413,0 +411,0 @@ if (res.status != 200) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
425155