@storyblok/js 1.0.1 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +5 -3
- package/dist/storyblok-js.js +2 -3
- package/dist/storyblok-js.mjs +166 -1250
- package/package.json +1 -1
package/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
</a>
|
5
5
|
<h1 align="center">@storyblok/js</h1>
|
6
6
|
<p align="center">
|
7
|
-
The JavaScript
|
7
|
+
The JavaScript SDK you need to interact with <a href="http://www.storyblok.com?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-js" target="_blank">Storyblok API</a> and enable the <a href="https://www.storyblok.com/docs/guide/essentials/visual-editor?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-js" target="_blank">Real-time Visual Editing Experience</a>.
|
8
8
|
</p>
|
9
9
|
<br />
|
10
10
|
</div>
|
@@ -32,6 +32,8 @@
|
|
32
32
|
|
33
33
|
## 🚀 Usage
|
34
34
|
|
35
|
+
<!-- -->
|
36
|
+
|
35
37
|
> If you are first-time user of the Storyblok, read the [Getting Started](https://www.storyblok.com/docs/guide/getting-started?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-js) guide to get a project ready in less than 5 minutes.
|
36
38
|
|
37
39
|
### Installation
|
@@ -39,8 +41,8 @@
|
|
39
41
|
Install `@storyblok/js`:
|
40
42
|
|
41
43
|
```bash
|
42
|
-
npm install
|
43
|
-
// yarn add
|
44
|
+
npm install @storyblok/js
|
45
|
+
// yarn add @storyblok/js
|
44
46
|
```
|
45
47
|
|
46
48
|
#### From a CDN
|
package/dist/storyblok-js.js
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
var
|
2
|
-
`),function(u){if(i=u.indexOf(":"),r=z.trim(u.substr(0,i)).toLowerCase(),s=z.trim(u.substr(i+1)),r){if(t[r]&&nt.indexOf(r)>=0)return;r==="set-cookie"?t[r]=(t[r]?t[r]:[]).concat([s]):t[r]=t[r]?t[r]+", "+s:s}}),t},ae=b,it=ae.isStandardBrowserEnv()?function(){var e=/(msie|trident)/i.test(navigator.userAgent),t=document.createElement("a"),r;function s(i){var o=i;return e&&(t.setAttribute("href",o),o=t.href),t.setAttribute("href",o),{href:t.href,protocol:t.protocol?t.protocol.replace(/:$/,""):"",host:t.host,search:t.search?t.search.replace(/^\?/,""):"",hash:t.hash?t.hash.replace(/^#/,""):"",hostname:t.hostname,port:t.port,pathname:t.pathname.charAt(0)==="/"?t.pathname:"/"+t.pathname}}return r=s(window.location.href),function(o){var u=ae.isString(o)?s(o):o;return u.protocol===r.protocol&&u.host===r.host}}():function(){return function(){return!0}}(),N=b,at=Ge,ot=Ye,ut=ne,lt=rt,ct=st,dt=it,V=ie,oe=function(e){return new Promise(function(r,s){var i=e.data,o=e.headers,u=e.responseType;N.isFormData(i)&&delete o["Content-Type"];var a=new XMLHttpRequest;if(e.auth){var l=e.auth.username||"",f=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";o.Authorization="Basic "+btoa(l+":"+f)}var h=lt(e.baseURL,e.url);a.open(e.method.toUpperCase(),ut(h,e.params,e.paramsSerializer),!0),a.timeout=e.timeout;function d(){if(!!a){var R="getAllResponseHeaders"in a?ct(a.getAllResponseHeaders()):null,k=!u||u==="text"||u==="json"?a.responseText:a.response,A={data:k,status:a.status,statusText:a.statusText,headers:R,config:e,request:a};at(r,s,A),a=null}}if("onloadend"in a?a.onloadend=d:a.onreadystatechange=function(){!a||a.readyState!==4||a.status===0&&!(a.responseURL&&a.responseURL.indexOf("file:")===0)||setTimeout(d)},a.onabort=function(){!a||(s(V("Request aborted",e,"ECONNABORTED",a)),a=null)},a.onerror=function(){s(V("Network Error",e,null,a)),a=null},a.ontimeout=function(){var k="timeout of "+e.timeout+"ms exceeded";e.timeoutErrorMessage&&(k=e.timeoutErrorMessage),s(V(k,e,e.transitional&&e.transitional.clarifyTimeoutError?"ETIMEDOUT":"ECONNABORTED",a)),a=null},N.isStandardBrowserEnv()){var c=(e.withCredentials||dt(h))&&e.xsrfCookieName?ot.read(e.xsrfCookieName):void 0;c&&(o[e.xsrfHeaderName]=c)}"setRequestHeader"in a&&N.forEach(o,function(k,A){typeof i=="undefined"&&A.toLowerCase()==="content-type"?delete o[A]:a.setRequestHeader(A,k)}),N.isUndefined(e.withCredentials)||(a.withCredentials=!!e.withCredentials),u&&u!=="json"&&(a.responseType=e.responseType),typeof e.onDownloadProgress=="function"&&a.addEventListener("progress",e.onDownloadProgress),typeof e.onUploadProgress=="function"&&a.upload&&a.upload.addEventListener("progress",e.onUploadProgress),e.cancelToken&&e.cancelToken.promise.then(function(k){!a||(a.abort(),s(k),a=null)}),i||(i=null),a.send(i)})},v=b,ue=Ke,ft=se,ht={"Content-Type":"application/x-www-form-urlencoded"};function le(n,e){!v.isUndefined(n)&&v.isUndefined(n["Content-Type"])&&(n["Content-Type"]=e)}function pt(){var n;return(typeof XMLHttpRequest!="undefined"||typeof process!="undefined"&&Object.prototype.toString.call(process)==="[object process]")&&(n=oe),n}function mt(n,e,t){if(v.isString(n))try{return(e||JSON.parse)(n),v.trim(n)}catch(r){if(r.name!=="SyntaxError")throw r}return(t||JSON.stringify)(n)}var _={transitional:{silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},adapter:pt(),transformRequest:[function(e,t){return ue(t,"Accept"),ue(t,"Content-Type"),v.isFormData(e)||v.isArrayBuffer(e)||v.isBuffer(e)||v.isStream(e)||v.isFile(e)||v.isBlob(e)?e:v.isArrayBufferView(e)?e.buffer:v.isURLSearchParams(e)?(le(t,"application/x-www-form-urlencoded;charset=utf-8"),e.toString()):v.isObject(e)||t&&t["Content-Type"]==="application/json"?(le(t,"application/json"),mt(e)):e}],transformResponse:[function(e){var t=this.transitional,r=t&&t.silentJSONParsing,s=t&&t.forcedJSONParsing,i=!r&&this.responseType==="json";if(i||s&&v.isString(e)&&e.length)try{return JSON.parse(e)}catch(o){if(i)throw o.name==="SyntaxError"?ft(o,this,"E_JSON_PARSE"):o}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,validateStatus:function(e){return e>=200&&e<300}};_.headers={common:{Accept:"application/json, text/plain, */*"}},v.forEach(["delete","get","head"],function(e){_.headers[e]={}}),v.forEach(["post","put","patch"],function(e){_.headers[e]=v.merge(ht)});var K=_,vt=b,gt=K,yt=function(e,t,r){var s=this||gt;return vt.forEach(r,function(o){e=o.call(s,e,t)}),e},ce=function(e){return!!(e&&e.__CANCEL__)},de=b,W=yt,bt=ce,wt=K;function X(n){n.cancelToken&&n.cancelToken.throwIfRequested()}var kt=function(e){X(e),e.headers=e.headers||{},e.data=W.call(e,e.data,e.headers,e.transformRequest),e.headers=de.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),de.forEach(["delete","get","head","post","put","patch","common"],function(s){delete e.headers[s]});var t=e.adapter||wt.adapter;return t(e).then(function(s){return X(e),s.data=W.call(e,s.data,s.headers,e.transformResponse),s},function(s){return bt(s)||(X(e),s&&s.response&&(s.response.data=W.call(e,s.response.data,s.response.headers,e.transformResponse))),Promise.reject(s)})},g=b,fe=function(e,t){t=t||{};var r={},s=["url","method","data"],i=["headers","auth","proxy","params"],o=["baseURL","transformRequest","transformResponse","paramsSerializer","timeout","timeoutMessage","withCredentials","adapter","responseType","xsrfCookieName","xsrfHeaderName","onUploadProgress","onDownloadProgress","decompress","maxContentLength","maxBodyLength","maxRedirects","transport","httpAgent","httpsAgent","cancelToken","socketPath","responseEncoding"],u=["validateStatus"];function a(d,c){return g.isPlainObject(d)&&g.isPlainObject(c)?g.merge(d,c):g.isPlainObject(c)?g.merge({},c):g.isArray(c)?c.slice():c}function l(d){g.isUndefined(t[d])?g.isUndefined(e[d])||(r[d]=a(void 0,e[d])):r[d]=a(e[d],t[d])}g.forEach(s,function(c){g.isUndefined(t[c])||(r[c]=a(void 0,t[c]))}),g.forEach(i,l),g.forEach(o,function(c){g.isUndefined(t[c])?g.isUndefined(e[c])||(r[c]=a(void 0,e[c])):r[c]=a(void 0,t[c])}),g.forEach(u,function(c){c in t?r[c]=a(e[c],t[c]):c in e&&(r[c]=a(void 0,e[c]))});var f=s.concat(i).concat(o).concat(u),h=Object.keys(e).concat(Object.keys(t)).filter(function(c){return f.indexOf(c)===-1});return g.forEach(h,l),r},Et={name:"axios",version:"0.21.4",description:"Promise based HTTP client for the browser and node.js",main:"index.js",scripts:{test:"grunt test",start:"node ./sandbox/server.js",build:"NODE_ENV=production grunt build",preversion:"npm test",version:"npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json",postversion:"git push && git push --tags",examples:"node ./examples/server.js",coveralls:"cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",fix:"eslint --fix lib/**/*.js"},repository:{type:"git",url:"https://github.com/axios/axios.git"},keywords:["xhr","http","ajax","promise","node"],author:"Matt Zabriskie",license:"MIT",bugs:{url:"https://github.com/axios/axios/issues"},homepage:"https://axios-http.com",devDependencies:{coveralls:"^3.0.0","es6-promise":"^4.2.4",grunt:"^1.3.0","grunt-banner":"^0.6.0","grunt-cli":"^1.2.0","grunt-contrib-clean":"^1.1.0","grunt-contrib-watch":"^1.0.0","grunt-eslint":"^23.0.0","grunt-karma":"^4.0.0","grunt-mocha-test":"^0.13.3","grunt-ts":"^6.0.0-beta.19","grunt-webpack":"^4.0.2","istanbul-instrumenter-loader":"^1.0.0","jasmine-core":"^2.4.1",karma:"^6.3.2","karma-chrome-launcher":"^3.1.0","karma-firefox-launcher":"^2.1.0","karma-jasmine":"^1.1.1","karma-jasmine-ajax":"^0.1.13","karma-safari-launcher":"^1.0.0","karma-sauce-launcher":"^4.3.6","karma-sinon":"^1.0.5","karma-sourcemap-loader":"^0.3.8","karma-webpack":"^4.0.2","load-grunt-tasks":"^3.5.2",minimist:"^1.2.0",mocha:"^8.2.1",sinon:"^4.5.0","terser-webpack-plugin":"^4.2.3",typescript:"^4.0.5","url-search-params":"^0.10.0",webpack:"^4.44.2","webpack-dev-server":"^3.11.0"},browser:{"./lib/adapters/http.js":"./lib/adapters/xhr.js"},jsdelivr:"dist/axios.min.js",unpkg:"dist/axios.min.js",typings:"./index.d.ts",dependencies:{"follow-redirects":"^1.14.0"},bundlesize:[{path:"./dist/axios.min.js",threshold:"5kB"}]},he=Et,G={};["object","boolean","number","function","string","symbol"].forEach(function(n,e){G[n]=function(r){return typeof r===n||"a"+(e<1?"n ":" ")+n}});var pe={},Rt=he.version.split(".");function me(n,e){for(var t=e?e.split("."):Rt,r=n.split("."),s=0;s<3;s++){if(t[s]>r[s])return!0;if(t[s]<r[s])return!1}return!1}G.transitional=function(e,t,r){var s=t&&me(t);function i(o,u){return"[Axios v"+he.version+"] Transitional option '"+o+"'"+u+(r?". "+r:"")}return function(o,u,a){if(e===!1)throw new Error(i(u," has been removed in "+t));return s&&!pe[u]&&(pe[u]=!0,console.warn(i(u," has been deprecated since v"+t+" and will be removed in the near future"))),e?e(o,u,a):!0}};function xt(n,e,t){if(typeof n!="object")throw new TypeError("options must be an object");for(var r=Object.keys(n),s=r.length;s-- >0;){var i=r[s],o=e[i];if(o){var u=n[i],a=u===void 0||o(u,i,n);if(a!==!0)throw new TypeError("option "+i+" must be "+a);continue}if(t!==!0)throw Error("Unknown option "+i)}}var Tt={isOlderVersion:me,assertOptions:xt,validators:G},ve=b,St=ne,ge=ze,ye=kt,U=fe,be=Tt,S=be.validators;function C(n){this.defaults=n,this.interceptors={request:new ge,response:new ge}}C.prototype.request=function(e){typeof e=="string"?(e=arguments[1]||{},e.url=arguments[0]):e=e||{},e=U(this.defaults,e),e.method?e.method=e.method.toLowerCase():this.defaults.method?e.method=this.defaults.method.toLowerCase():e.method="get";var t=e.transitional;t!==void 0&&be.assertOptions(t,{silentJSONParsing:S.transitional(S.boolean,"1.0.0"),forcedJSONParsing:S.transitional(S.boolean,"1.0.0"),clarifyTimeoutError:S.transitional(S.boolean,"1.0.0")},!1);var r=[],s=!0;this.interceptors.request.forEach(function(d){typeof d.runWhen=="function"&&d.runWhen(e)===!1||(s=s&&d.synchronous,r.unshift(d.fulfilled,d.rejected))});var i=[];this.interceptors.response.forEach(function(d){i.push(d.fulfilled,d.rejected)});var o;if(!s){var u=[ye,void 0];for(Array.prototype.unshift.apply(u,r),u=u.concat(i),o=Promise.resolve(e);u.length;)o=o.then(u.shift(),u.shift());return o}for(var a=e;r.length;){var l=r.shift(),f=r.shift();try{a=l(a)}catch(h){f(h);break}}try{o=ye(a)}catch(h){return Promise.reject(h)}for(;i.length;)o=o.then(i.shift(),i.shift());return o},C.prototype.getUri=function(e){return e=U(this.defaults,e),St(e.url,e.params,e.paramsSerializer).replace(/^\?/,"")},ve.forEach(["delete","get","head","options"],function(e){C.prototype[e]=function(t,r){return this.request(U(r||{},{method:e,url:t,data:(r||{}).data}))}}),ve.forEach(["post","put","patch"],function(e){C.prototype[e]=function(t,r,s){return this.request(U(s||{},{method:e,url:t,data:r}))}});var Ot=C;function Y(n){this.message=n}Y.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},Y.prototype.__CANCEL__=!0;var we=Y,Ct=we;function B(n){if(typeof n!="function")throw new TypeError("executor must be a function.");var e;this.promise=new Promise(function(s){e=s});var t=this;n(function(s){t.reason||(t.reason=new Ct(s),e(t.reason))})}B.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},B.source=function(){var e,t=new B(function(s){e=s});return{token:t,cancel:e}};var At=B,jt=function(e){return function(r){return e.apply(null,r)}},$t=function(e){return typeof e=="object"&&e.isAxiosError===!0},ke=b,Pt=Q,L=Ot,Nt=fe,_t=K;function Ee(n){var e=new L(n),t=Pt(L.prototype.request,e);return ke.extend(t,L.prototype,e),ke.extend(t,e),t}var w=Ee(_t);w.Axios=L,w.create=function(e){return Ee(Nt(w.defaults,e))},w.Cancel=we,w.CancelToken=At,w.isCancel=ce,w.all=function(e){return Promise.all(e)},w.spread=jt,w.isAxiosError=$t,M.exports=w,M.exports.default=w;var Ut=M.exports;/*!
|
1
|
+
var B=Object.defineProperty,L=Object.defineProperties;var U=Object.getOwnPropertyDescriptors;var R=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var E=(h,d,p)=>d in h?B(h,d,{enumerable:!0,configurable:!0,writable:!0,value:p}):h[d]=p,g=(h,d)=>{for(var p in d||(d={}))D.call(d,p)&&E(h,p,d[p]);if(R)for(var p of R(d))J.call(d,p)&&E(h,p,d[p]);return h},m=(h,d)=>L(h,U(d));(function(h,d){typeof exports=="object"&&typeof module!="undefined"?d(exports,require("axios")):typeof define=="function"&&define.amd?define(["exports","axios"],d):(h=typeof globalThis!="undefined"?globalThis:h||self,d(h.storyblok={},h.t))})(this,function(h,d){"use strict";function p(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}var S=p(d);let v=!1;const w=[],j=n=>new Promise((e,r)=>{if(typeof window=="undefined"||(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}v?s():w.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const t=document.createElement("script");t.async=!0,t.src=n,t.id="storyblok-javascript-bridge",t.onerror=s=>r(s),t.onload=s=>{w.forEach(o=>o()),v=!0,e(s)},document.getElementsByTagName("head")[0].appendChild(t)});/*!
|
3
2
|
* storyblok-js-client v0.0.0-development
|
4
3
|
* Universal JavaScript SDK for Storyblok's API
|
5
4
|
* (c) 2020-2022 Stobylok Team
|
6
|
-
*/function Re(n){return typeof n=="number"&&n==n&&n!==1/0&&n!==-1/0}function xe(n,e,t){if(!Re(e))throw new TypeError("Expected `limit` to be a finite number");if(!Re(t))throw new TypeError("Expected `interval` to be a finite number");var r=[],s=[],i=0,o=function(){i++;var a=setTimeout(function(){i--,r.length>0&&o(),s=s.filter(function(f){return f!==a})},t);s.indexOf(a)<0&&s.push(a);var l=r.shift();l.resolve(n.apply(l.self,l.args))},u=function(){var a=arguments,l=this;return new Promise(function(f,h){r.push({resolve:f,reject:h,args:a,self:l}),i<e&&o()})};return u.abort=function(){s.forEach(clearTimeout),s=[],r.forEach(function(a){a.reject(new throttle.AbortError)}),r.length=0},u}xe.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const Bt=function(n,e){if(!n)return null;let t={};for(let r in n){let s=n[r];e.indexOf(r)>-1&&s!==null&&(t[r]=s)}return t};var Lt={nodes:{horizontal_rule:n=>({singleTag:"hr"}),blockquote:n=>({tag:"blockquote"}),bullet_list:n=>({tag:"ul"}),code_block:n=>({tag:["pre",{tag:"code",attrs:n.attrs}]}),hard_break:n=>({singleTag:"br"}),heading:n=>({tag:"h"+n.attrs.level}),image:n=>({singleTag:[{tag:"img",attrs:Bt(n.attrs,["src","alt","title"])}]}),list_item:n=>({tag:"li"}),ordered_list:n=>({tag:"ol"}),paragraph:n=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(n){const e=x({},n.attrs),{linktype:t="url"}=n.attrs;return t==="email"&&(e.href="mailto:"+e.href),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},styled:n=>({tag:[{tag:"span",attrs:n.attrs}]})}};class qt{constructor(e){e||(e=Lt),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(r=>{t+=this.renderNode(r)}),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(s=>{const i=this.getMatchingMark(s);i&&t.push(this.renderOpeningTag(i.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(s=>{t.push(this.renderNode(s))}):e.text?t.push(function(s){const i={"&":"&","<":"<",">":">",'"':""","'":"'"},o=/[&<>"']/g,u=RegExp(o.source);return s&&u.test(s)?s.replace(o,a=>i[a]):s}(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(s=>{const i=this.getMatchingMark(s);i&&t.push(this.renderClosingTag(i.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(r=>{if(r.constructor===String)return`<${r}${t}>`;{let s="<"+r.tag;if(r.attrs)for(let i in r.attrs){let o=r.attrs[i];o!==null&&(s+=` ${i}="${o}"`)}return`${s}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){if(typeof this.nodes[e.type]=="function")return this.nodes[e.type](e)}getMatchingMark(e){if(typeof this.marks[e.type]=="function")return this.marks[e.type](e)}}const Dt=(n=0,e=n)=>{const t=Math.abs(e-n)||0,r=n<e?1:-1;return((s=0,i)=>[...Array(s)].map(i))(t,(s,i)=>i*r+n)},Z=(n,e,t)=>{const r=[];for(const s in n){if(!Object.prototype.hasOwnProperty.call(n,s))continue;const i=n[s],o=t?"":encodeURIComponent(s);let u;u=typeof i=="object"?Z(i,e?e+encodeURIComponent("["+o+"]"):o,Array.isArray(i)):(e?e+encodeURIComponent("["+o+"]"):o)+"="+encodeURIComponent(i),r.push(u)}return r.join("&")};let q={},O={};class Mt{constructor(e,t){if(!t){let i=e.region?"-"+e.region:"",o=e.https===!1?"http":"https";t=e.oauthToken===void 0?`${o}://api${i}.storyblok.com/v2`:`${o}://api${i}.storyblok.com/v1`}let r=Object.assign({},e.headers),s=5;e.oauthToken!==void 0&&(r.Authorization=e.oauthToken,s=3),e.rateLimit!==void 0&&(s=e.rateLimit),this.richTextResolver=new qt(e.richTextSchema),typeof e.componentResolver=="function"&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=xe(this.throttledRequest,s,1e3),this.accessToken=e.accessToken,this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.client=Ut.create({baseURL:t,timeout:e.timeout||0,headers:r,proxy:e.proxy||!1}),e.responseInterceptor&&this.client.interceptors.response.use(i=>e.responseInterceptor(i))}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let r="";return t.attrs.body.forEach(s=>{r+=e(s.component,s)}),{html:r}})}parseParams(e={}){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=O[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t={}){return((r="")=>r.indexOf("/cdn/")>-1)(e)?this.parseParams(t):t}makeRequest(e,t,r,s){const i=this.factoryParamOptions(e,((o={},u=25,a=1)=>D(x({},o),{per_page:u,page:a}))(t,r,s));return this.cacheResponse(e,i)}get(e,t){let r="/"+e;const s=this.factoryParamOptions(r,t);return this.cacheResponse(r,s)}async getAll(e,t={},r){const s=t.per_page||25,i="/"+e,o=i.split("/");r=r||o[o.length-1];const u=await this.makeRequest(i,t,s,1),a=Math.ceil(u.total/s);return((l=[],f)=>l.map(f).reduce((h,d)=>[...h,...d],[]))([u,...await(async(l=[],f)=>Promise.all(l.map(f)))(Dt(1,a),async l=>this.makeRequest(i,t,s,l+1))],l=>Object.values(l.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&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[r.id]?r.story=this._cleanCopy(this.links[r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[r.uuid]&&(r.story=this._cleanCopy(this.links[r.uuid]))}_insertRelations(e,t,r){if(r.indexOf(e.component+"."+t)>-1){if(typeof e[t]=="string")this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t].constructor===Array){let s=[];e[t].forEach(i=>{this.relations[i]&&s.push(this._cleanCopy(this.relations[i]))}),e[t]=s}}}iterateTree(e,t){let r=s=>{if(s!=null){if(s.constructor===Array)for(let i=0;i<s.length;i++)r(s[i]);else if(s.constructor===Object){if(s._stopResolving)return;for(let i in s)(s.component&&s._uid||s.type==="link")&&(this._insertRelations(s,i,t),this._insertLinks(s,i)),r(s[i])}}};r(e.content)}async resolveLinks(e,t){let r=[];if(e.link_uuids){const s=e.link_uuids.length;let i=[];const o=50;for(let u=0;u<s;u+=o){const a=Math.min(s,u+o);i.push(e.link_uuids.slice(u,a))}for(let u=0;u<i.length;u++)(await this.getStories({per_page:o,language:t.language,version:t.version,by_uuids:i[u].join(",")})).data.stories.forEach(a=>{r.push(a)})}else r=e.links;r.forEach(s=>{this.links[s.uuid]=D(x({},s),{_stopResolving:!0})})}async resolveRelations(e,t){let r=[];if(e.rel_uuids){const s=e.rel_uuids.length;let i=[];const o=50;for(let u=0;u<s;u+=o){const a=Math.min(s,u+o);i.push(e.rel_uuids.slice(u,a))}for(let u=0;u<i.length;u++)(await this.getStories({per_page:o,language:t.language,version:t.version,by_uuids:i[u].join(",")})).data.stories.forEach(a=>{r.push(a)})}else r=e.rels;r.forEach(s=>{this.relations[s.uuid]=D(x({},s),{_stopResolving:!0})})}async resolveStories(e,t){let r=[];t.resolve_relations!==void 0&&t.resolve_relations.length>0&&(r=t.resolve_relations.split(","),await this.resolveRelations(e,t)),["1","story","url"].indexOf(t.resolve_links)>-1&&await this.resolveLinks(e,t);for(const s in this.relations)this.iterateTree(this.relations[s],r);e.story?this.iterateTree(e.story,r):e.stories.forEach(s=>{this.iterateTree(s,r)})}cacheResponse(e,t,r){return r===void 0&&(r=0),new Promise(async(s,i)=>{let o=Z({url:e,params:t}),u=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const l=await u.get(o);if(l)return s(l)}try{let l=await this.throttle("get",e,{params:t,paramsSerializer:h=>Z(h)}),f={data:l.data,headers:l.headers};if(l.headers["per-page"]&&(f=Object.assign({},f,{perPage:parseInt(l.headers["per-page"]),total:parseInt(l.headers.total)})),l.status!=200)return i(l);(f.data.story||f.data.stories)&&await this.resolveStories(f.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&u.set(o,f),f.data.cv&&(t.version=="draft"&&O[t.token]!=f.data.cv&&this.flushCache(),O[t.token]=f.data.cv),s(f)}catch(l){if(l.response&&l.response.status===429&&(r+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${r} seconds.`),await(a=1e3*r,new Promise(f=>setTimeout(f,a))),this.cacheResponse(e,t,r).then(s).catch(i);i(l)}var a})}throttledRequest(e,t,r){return this.client[e](t,r)}cacheVersions(){return O}cacheVersion(){return O[this.accessToken]}setCacheVersion(e){this.accessToken&&(O[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get:e=>q[e],getAll:()=>q,set(e,t){q[e]=t},flush(){q={}}};default:return{get(){},getAll(){},set(){},flush(){}}}}async flushCache(){return await this.cacheProvider().flush(),this}}var It=(n={})=>{const{apiOptions:e}=n;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new Mt(e)}},Ft=n=>{if(typeof n!="object"||typeof n._editable=="undefined")return{};const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};const Ht=(n,e,t={})=>{if(typeof window!="undefined"){if(typeof window.storyblokRegisterEvent=="undefined"){console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],s=>{s.action=="input"&&s.story.id===n?e(s.story):window.location.reload()})})}},Jt=(n={})=>{const{bridge:e,accessToken:t,use:r=[],apiOptions:s={}}=n;s.accessToken=s.accessToken||t;const i={bridge:e,apiOptions:s};let o={};return r.forEach(u=>{o=x(x({},o),u(i))}),e!==!1&&Oe("https://app.storyblok.com/f/storyblok-v2-latest.js"),o};p.apiPlugin=It,p.storyblokEditable=Ft,p.storyblokInit=Jt,p.useStoryblokBridge=Ht,Object.defineProperty(p,"__esModule",{value:!0}),p[Symbol.toStringTag]="Module"});
|
5
|
+
*/function T(n){return typeof n=="number"&&n==n&&n!==1/0&&n!==-1/0}function _(n,e,r){if(!T(e))throw new TypeError("Expected `limit` to be a finite number");if(!T(r))throw new TypeError("Expected `interval` to be a finite number");var t=[],s=[],o=0,i=function(){o++;var c=setTimeout(function(){o--,t.length>0&&i(),s=s.filter(function(u){return u!==c})},r);s.indexOf(c)<0&&s.push(c);var l=t.shift();l.resolve(n.apply(l.self,l.args))},a=function(){var c=arguments,l=this;return new Promise(function(u,y){t.push({resolve:u,reject:y,args:c,self:l}),o<e&&i()})};return a.abort=function(){s.forEach(clearTimeout),s=[],t.forEach(function(c){c.reject(new throttle.AbortError)}),t.length=0},a}_.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const O=function(n,e){if(!n)return null;let r={};for(let t in n){let s=n[t];e.indexOf(t)>-1&&s!==null&&(r[t]=s)}return r};var C={nodes:{horizontal_rule:n=>({singleTag:"hr"}),blockquote:n=>({tag:"blockquote"}),bullet_list:n=>({tag:"ul"}),code_block:n=>({tag:["pre",{tag:"code",attrs:n.attrs}]}),hard_break:n=>({singleTag:"br"}),heading:n=>({tag:"h"+n.attrs.level}),image:n=>({singleTag:[{tag:"img",attrs:O(n.attrs,["src","alt","title"])}]}),list_item:n=>({tag:"li"}),ordered_list:n=>({tag:"ol"}),paragraph:n=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(n){const e=g({},n.attrs),{linktype:r="url"}=n.attrs;return r==="email"&&(e.href="mailto:"+e.href),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},styled:n=>({tag:[{tag:"span",attrs:n.attrs}]})}};class P{constructor(e){e||(e=C),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,r){this.nodes[e]=r}addMark(e,r){this.marks[e]=r}render(e={}){if(e.content&&Array.isArray(e.content)){let r="";return e.content.forEach(t=>{r+=this.renderNode(t)}),r}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let r=[];e.marks&&e.marks.forEach(s=>{const o=this.getMatchingMark(s);o&&r.push(this.renderOpeningTag(o.tag))});const t=this.getMatchingNode(e);return t&&t.tag&&r.push(this.renderOpeningTag(t.tag)),e.content?e.content.forEach(s=>{r.push(this.renderNode(s))}):e.text?r.push(function(s){const o={"&":"&","<":"<",">":">",'"':""","'":"'"},i=/[&<>"']/g,a=RegExp(i.source);return s&&a.test(s)?s.replace(i,c=>o[c]):s}(e.text)):t&&t.singleTag?r.push(this.renderTag(t.singleTag," /")):t&&t.html&&r.push(t.html),t&&t.tag&&r.push(this.renderClosingTag(t.tag)),e.marks&&e.marks.slice(0).reverse().forEach(s=>{const o=this.getMatchingMark(s);o&&r.push(this.renderClosingTag(o.tag))}),r.join("")}renderTag(e,r){return e.constructor===String?`<${e}${r}>`:e.map(t=>{if(t.constructor===String)return`<${t}${r}>`;{let s="<"+t.tag;if(t.attrs)for(let o in t.attrs){let i=t.attrs[o];i!==null&&(s+=` ${o}="${i}"`)}return`${s}${r}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(e){if(typeof this.nodes[e.type]=="function")return this.nodes[e.type](e)}getMatchingMark(e){if(typeof this.marks[e.type]=="function")return this.marks[e.type](e)}}const A=(n=0,e=n)=>{const r=Math.abs(e-n)||0,t=n<e?1:-1;return((s=0,o)=>[...Array(s)].map(o))(r,(s,o)=>o*t+n)},b=(n,e,r)=>{const t=[];for(const s in n){if(!Object.prototype.hasOwnProperty.call(n,s))continue;const o=n[s],i=r?"":encodeURIComponent(s);let a;a=typeof o=="object"?b(o,e?e+encodeURIComponent("["+i+"]"):i,Array.isArray(o)):(e?e+encodeURIComponent("["+i+"]"):i)+"="+encodeURIComponent(o),t.push(a)}return t.join("&")};let k={},f={};class ${constructor(e,r){if(!r){let o=e.region?"-"+e.region:"",i=e.https===!1?"http":"https";r=e.oauthToken===void 0?`${i}://api${o}.storyblok.com/v2`:`${i}://api${o}.storyblok.com/v1`}let t=Object.assign({},e.headers),s=5;e.oauthToken!==void 0&&(t.Authorization=e.oauthToken,s=3),e.rateLimit!==void 0&&(s=e.rateLimit),this.richTextResolver=new P(e.richTextSchema),typeof e.componentResolver=="function"&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=_(this.throttledRequest,s,1e3),this.accessToken=e.accessToken,this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.client=S.default.create({baseURL:r,timeout:e.timeout||0,headers:t,proxy:e.proxy||!1}),e.responseInterceptor&&this.client.interceptors.response.use(o=>e.responseInterceptor(o))}setComponentResolver(e){this.richTextResolver.addNode("blok",r=>{let t="";return r.attrs.body.forEach(s=>{t+=e(s.component,s)}),{html:t}})}parseParams(e={}){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=f[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,r={}){return((t="")=>t.indexOf("/cdn/")>-1)(e)?this.parseParams(r):r}makeRequest(e,r,t,s){const o=this.factoryParamOptions(e,((i={},a=25,c=1)=>m(g({},i),{per_page:a,page:c}))(r,t,s));return this.cacheResponse(e,o)}get(e,r){let t="/"+e;const s=this.factoryParamOptions(t,r);return this.cacheResponse(t,s)}async getAll(e,r={},t){const s=r.per_page||25,o="/"+e,i=o.split("/");t=t||i[i.length-1];const a=await this.makeRequest(o,r,s,1),c=Math.ceil(a.total/s);return((l=[],u)=>l.map(u).reduce((y,q)=>[...y,...q],[]))([a,...await(async(l=[],u)=>Promise.all(l.map(u)))(A(1,c),async l=>this.makeRequest(o,r,s,l+1))],l=>Object.values(l.data[t]))}post(e,r){let t="/"+e;return this.throttle("post",t,r)}put(e,r){let t="/"+e;return this.throttle("put",t,r)}delete(e,r){let t="/"+e;return this.throttle("delete",t,r)}getStories(e){return this.get("cdn/stories",e)}getStory(e,r){return this.get("cdn/stories/"+e,r)}setToken(e){this.accessToken=e}getToken(){return this.accessToken}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,r){const t=e[r];t&&t.fieldtype=="multilink"&&t.linktype=="story"&&typeof t.id=="string"&&this.links[t.id]?t.story=this._cleanCopy(this.links[t.id]):t&&t.linktype==="story"&&typeof t.uuid=="string"&&this.links[t.uuid]&&(t.story=this._cleanCopy(this.links[t.uuid]))}_insertRelations(e,r,t){if(t.indexOf(e.component+"."+r)>-1){if(typeof e[r]=="string")this.relations[e[r]]&&(e[r]=this._cleanCopy(this.relations[e[r]]));else if(e[r].constructor===Array){let s=[];e[r].forEach(o=>{this.relations[o]&&s.push(this._cleanCopy(this.relations[o]))}),e[r]=s}}}iterateTree(e,r){let t=s=>{if(s!=null){if(s.constructor===Array)for(let o=0;o<s.length;o++)t(s[o]);else if(s.constructor===Object){if(s._stopResolving)return;for(let o in s)(s.component&&s._uid||s.type==="link")&&(this._insertRelations(s,o,r),this._insertLinks(s,o)),t(s[o])}}};t(e.content)}async resolveLinks(e,r){let t=[];if(e.link_uuids){const s=e.link_uuids.length;let o=[];const i=50;for(let a=0;a<s;a+=i){const c=Math.min(s,a+i);o.push(e.link_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:r.language,version:r.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{t.push(c)})}else t=e.links;t.forEach(s=>{this.links[s.uuid]=m(g({},s),{_stopResolving:!0})})}async resolveRelations(e,r){let t=[];if(e.rel_uuids){const s=e.rel_uuids.length;let o=[];const i=50;for(let a=0;a<s;a+=i){const c=Math.min(s,a+i);o.push(e.rel_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:r.language,version:r.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{t.push(c)})}else t=e.rels;t.forEach(s=>{this.relations[s.uuid]=m(g({},s),{_stopResolving:!0})})}async resolveStories(e,r){let t=[];r.resolve_relations!==void 0&&r.resolve_relations.length>0&&(t=r.resolve_relations.split(","),await this.resolveRelations(e,r)),["1","story","url"].indexOf(r.resolve_links)>-1&&await this.resolveLinks(e,r);for(const s in this.relations)this.iterateTree(this.relations[s],t);e.story?this.iterateTree(e.story,t):e.stories.forEach(s=>{this.iterateTree(s,t)})}cacheResponse(e,r,t){return t===void 0&&(t=0),new Promise(async(s,o)=>{let i=b({url:e,params:r}),a=this.cacheProvider();if(this.cache.clear==="auto"&&r.version==="draft"&&await this.flushCache(),r.version==="published"&&e!="/cdn/spaces/me"){const l=await a.get(i);if(l)return s(l)}try{let l=await this.throttle("get",e,{params:r,paramsSerializer:y=>b(y)}),u={data:l.data,headers:l.headers};if(l.headers["per-page"]&&(u=Object.assign({},u,{perPage:parseInt(l.headers["per-page"]),total:parseInt(l.headers.total)})),l.status!=200)return o(l);(u.data.story||u.data.stories)&&await this.resolveStories(u.data,r),r.version==="published"&&e!="/cdn/spaces/me"&&a.set(i,u),u.data.cv&&(r.version=="draft"&&f[r.token]!=u.data.cv&&this.flushCache(),f[r.token]=u.data.cv),s(u)}catch(l){if(l.response&&l.response.status===429&&(t+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${t} seconds.`),await(c=1e3*t,new Promise(u=>setTimeout(u,c))),this.cacheResponse(e,r,t).then(s).catch(o);o(l)}var c})}throttledRequest(e,r,t){return this.client[e](r,t)}cacheVersions(){return f}cacheVersion(){return f[this.accessToken]}setCacheVersion(e){this.accessToken&&(f[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get:e=>k[e],getAll:()=>k,set(e,r){k[e]=r},flush(){k={}}};default:return{get(){},getAll(){},set(){},flush(){}}}}async flushCache(){return await this.cacheProvider().flush(),this}}var x=(n={})=>{const{apiOptions:e}=n;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new $(e)}},M=n=>{if(typeof n!="object"||typeof n._editable=="undefined")return{};const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};const I=(n,e,r={})=>{if(typeof window!="undefined"){if(typeof window.storyblokRegisterEvent=="undefined"){console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");return}if(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(r).on(["input","published","change"],s=>{s.action=="input"&&s.story.id===n?e(s.story):window.location.reload()})})}},N=(n={})=>{const{bridge:e,accessToken:r,use:t=[],apiOptions:s={}}=n;s.accessToken=s.accessToken||r;const o={bridge:e,apiOptions:s};let i={};return t.forEach(a=>{i=g(g({},i),a(o))}),e!==!1&&j("https://app.storyblok.com/f/storyblok-v2-latest.js"),i};h.apiPlugin=x,h.storyblokEditable=M,h.storyblokInit=N,h.useStoryblokBridge=I,Object.defineProperty(h,"__esModule",{value:!0}),h[Symbol.toStringTag]="Module"});
|