UNPKG

83.4 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Ketting=t():e.Ketting=t()}(window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=11)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.LinkNotFound=t.Links=void 0;class n{constructor(e,t){if(this.defaultContext=e,this.store=new Map,t)if(t instanceof n)this.add(...t.getAll());else for(const e of t)this.add(e)}add(...e){let t;t="string"==typeof e[0]?[{rel:e[0],href:e[1],context:this.defaultContext}]:e.map(e=>Object.assign({context:this.defaultContext},e));for(const e of t)this.store.has(e.rel)?this.store.get(e.rel).push(e):this.store.set(e.rel,[e])}set(e,t){let r;r="string"==typeof e?{rel:e,href:t,context:this.defaultContext}:Object.assign({context:this.defaultContext},e),this.store.set(r.rel,[r])}get(e){const t=this.store.get(e);if(t&&!(t.length<0))return t[0]}delete(e){this.store.delete(e)}getMany(e){return this.store.get(e)||[]}getAll(){const e=[];for(const t of this.store.values())e.push(...t);return e}has(e){return this.store.has(e)}}t.Links=n;class i extends Error{}t.LinkNotFound=i},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isSafeMethod=t.parseLink=t.parseContentType=void 0;const n=r(7),i=r(0);t.parseContentType=function(e){return e?(e.includes(";")&&(e=e.split(";")[0]),e.trim()):null},t.parseLink=function(e,t){const r=new i.Links(e);if(!t)return r;for(const i of n.parse(t).refs)for(const t of i.rel.split(" ")){const n={rel:t,href:i.uri,context:e,title:i.title,hreflang:i.hreflang,type:i.type};r.add(n)}return r};const o=["GET","HEAD","OPTIONS","PRI","PROPFIND","REPORT","SEARCH","TRACE"];t.isSafeMethod=function(e){return o.includes(e)}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.parse=t.resolve=void 0,t.resolve=function(e,t){var r;if("string"!=typeof e&&(t=e.href,e=e.context),"undefined"!=typeof URL&&0===(null===(r=/https?:\/\//.exec(e))||void 0===r?void 0:r.index))return new URL(t,e).toString();const n=document,i=n.getElementsByTagName("base")[0],o=i&&i.href,s=n.head||n.getElementsByTagName("head")[0],a=i||s.appendChild(n.createElement("base")),u=n.createElement("a");a.href=e,u.href=t;const c=u.href;return i?i.href=o:s.removeChild(a),c},t.parse=function(e){return{host:new URL(e).host}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.BaseState=void 0;const n=r(17);t.BaseState=class{constructor(e,t,r,n,i=[],o=[]){this.uri=e,this.data=t,this.headers=r,this.links=n,this.embedded=i,this.actionInfo=o,this.timestamp=Date.now()}contentHeaders(){const e=["Content-Type","Content-Language","ETag","Last-Modified"],t={};for(const r of e)this.headers.has(r)&&(t[r]=this.headers.get(r));return new Headers(t)}action(e){if(!this.actionInfo.length)throw new n.ActionNotFound("This State does not define any actions");if(void 0===e)return new n.SimpleAction(this.client,this.actionInfo[0]);for(const t of this.actionInfo)if(t.name===e)return new n.SimpleAction(this.client,this.actionInfo[0]);throw new n.ActionNotFound("This State defines no action")}actions(){return this.actionInfo.map(e=>new n.SimpleAction(this.client,e))}hasAction(e){if(void 0===e)return this.actionInfo.length>0;for(const t of this.actionInfo)if(e===t.name)return!0;return!1}getEmbedded(){return this.embedded}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.headStateFactory=t.HtmlState=t.htmlStateFactory=t.CjState=t.cjStateFactory=t.TextState=t.textStateFactory=t.SirenState=t.sirenStateFactory=t.JsonApiState=t.jsonApiStateFactory=t.BinaryState=t.binaryStateFactory=t.HalState=t.halStateFactory=t.BaseState=t.isState=void 0;var n=r(16);Object.defineProperty(t,"isState",{enumerable:!0,get:function(){return n.isState}});var i=r(3);Object.defineProperty(t,"BaseState",{enumerable:!0,get:function(){return i.BaseState}});var o=r(24);Object.defineProperty(t,"halStateFactory",{enumerable:!0,get:function(){return o.factory}}),Object.defineProperty(t,"HalState",{enumerable:!0,get:function(){return o.HalState}});var s=r(25);Object.defineProperty(t,"binaryStateFactory",{enumerable:!0,get:function(){return s.factory}}),Object.defineProperty(t,"BinaryState",{enumerable:!0,get:function(){return s.BinaryState}});var a=r(26);Object.defineProperty(t,"jsonApiStateFactory",{enumerable:!0,get:function(){return a.factory}}),Object.defineProperty(t,"JsonApiState",{enumerable:!0,get:function(){return a.JsonApiState}});var u=r(27);Object.defineProperty(t,"sirenStateFactory",{enumerable:!0,get:function(){return u.factory}}),Object.defineProperty(t,"SirenState",{enumerable:!0,get:function(){return u.SirenState}});var c=r(28);Object.defineProperty(t,"textStateFactory",{enumerable:!0,get:function(){return c.factory}}),Object.defineProperty(t,"TextState",{enumerable:!0,get:function(){return c.TextState}});var l=r(29);Object.defineProperty(t,"cjStateFactory",{enumerable:!0,get:function(){return l.factory}}),Object.defineProperty(t,"CjState",{enumerable:!0,get:function(){return l.CjState}});var f=r(30);Object.defineProperty(t,"htmlStateFactory",{enumerable:!0,get:function(){return f.factory}}),Object.defineProperty(t,"HtmlState",{enumerable:!0,get:function(){return f.HtmlState}});var h=r(32);Object.defineProperty(t,"headStateFactory",{enumerable:!0,get:function(){return h.factory}})},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Problem=t.HttpError=void 0;class n extends Error{constructor(e){super("HTTP error "+e.status),this.response=e,this.status=e.status}}t.HttpError=n;class i extends n{constructor(e,t){super(e),this.body=t,this.body.title&&(this.message="HTTP Error "+this.status+": "+this.body.title)}}t.Problem=i,t.default=async function(e){const t=e.headers.get("Content-Type");if(t&&t.match(/^application\/problem\+json/i)){const t=await e.json();return new i(e,t)}return new n(e)}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Resource=void 0;const n=r(4),i=r(2),o=r(8),s=r(0),a=r(38),u=r(39);class c extends a.EventEmitter{constructor(e,t){super(),this.client=e,this.uri=t,this.activeRefresh=null}get(e){const t=this.client.cache.get(this.uri);return t?Promise.resolve(t):this.refresh(e)}async head(e){let t=this.client.cache.get(this.uri);if(t)return t;const r=await this.fetchOrThrow(l("HEAD",e));return t=await n.headStateFactory(this.uri,r),t}refresh(e){const t={cache:"reload"};return(null==e?void 0:e.getContentHeaders)&&!(null==e?void 0:e.headers)?t.headers=e.getContentHeaders():!(null==e?void 0:e.getContentHeaders)&&(null==e?void 0:e.headers)?t.headers=e.headers:(null==e?void 0:e.getContentHeaders)&&(null==e?void 0:e.headers)&&(t.headers=e.getContentHeaders(),t.headers=Object.assign(Object.assign({},e.headers),t.headers)),this.activeRefresh||(this.activeRefresh=(async()=>{try{const e=await this.fetchOrThrow(t),r=await this.client.getStateForResponse(this.uri,e);return this.updateCache(r),r}finally{this.activeRefresh=null}})()),this.activeRefresh}async put(e){const t=l("PUT",e);n.isState(e)&&t.headers.set("X-KETTING-NO-STALE","1"),await this.fetchOrThrow(t),n.isState(e)&&this.updateCache(e)}async delete(){await this.fetchOrThrow({method:"DELETE"})}async post(e){const t=await this.fetchOrThrow(l("POST",e));return this.client.getStateForResponse(this.uri,t)}async postFollow(e){const t=await this.fetchOrThrow(l("POST",e));switch(t.status){case 201:if(t.headers.has("location"))return this.go(t.headers.get("location"));throw new Error("Could not follow after a 201 request, because the server did not reply with a Location header");case 204:case 205:return this;default:throw new Error("Did not receive a 201, 204 or 205 status code so we could not follow to the next resource")}}async patch(e){const t=await this.fetchOrThrow(l("PATCH",e));if(200===t.status)return await this.client.getStateForResponse(this.uri,t)}follow(e,t){return new o.FollowPromiseOne(this,e,t)}followAll(e){return new o.FollowPromiseMany(this,e)}go(e){return e=i.resolve(this.uri,e),this.client.go(e)}fetch(e){return this.client.fetcher.fetch(this.uri,e)}fetchOrThrow(e){return this.client.fetcher.fetchOrThrow(this.uri,e)}updateCache(e){if(e.uri!==this.uri)throw new Error("When calling updateCache on a resource, the uri of the State object must match the uri of the Resource");this.client.cacheState(e)}clearCache(){this.client.cache.delete(this.uri)}async link(e){const t=(await this.get()).links.get(e);if(!t)throw new s.LinkNotFound(`Link with rel: ${e} not found on ${this.uri}`);return t}async links(e){const t=await this.get();return e?t.links.getMany(e):t.links.getAll()}async hasLink(e){return(await this.get()).links.has(e)}}function l(e,t){if(!t)return{method:e,headers:new Headers};let r,n;return r=t.getContentHeaders?new Headers(t.getContentHeaders()):t.headers?new Headers(t.headers):new Headers,r.has("Content-Type")||r.set("Content-Type","application/json"),void 0!==t.serializeBody?n=t.serializeBody():t.data?(n=t.data,u.needsJsonStringify(n)&&(n=JSON.stringify(n))):n=null,{method:e,body:n,headers:r}}t.Resource=c,t.default=c},function(e,t,r){"use strict";var n=/^utf-?8|ascii|utf-?16-?le|ucs-?2|base-?64|latin-?1$/i,i=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,o=/\s|\uFEFF|\xA0/,s=/\r?\n[\x20\x09]+/g,a=/[;,"]/,u=/[;,"]|\s/,c=/^[!#$%&'*+\-\.^_`|~\da-zA-Z]+$/,l=1,f=2,h=4;function p(e){return e.replace(i,"")}function d(e){return o.test(e)}function y(e,t){for(;d(e[t]);)t++;return t}function g(e){return u.test(e)||!c.test(e)}class v{constructor(e){this.refs=[],e&&this.parse(e)}rel(e){for(var t=[],r=e.toLowerCase(),n=0;n<this.refs.length;n++)this.refs[n].rel.toLowerCase()===r&&t.push(this.refs[n]);return t}get(e,t){e=e.toLowerCase();for(var r=[],n=0;n<this.refs.length;n++)this.refs[n][e]===t&&r.push(this.refs[n]);return r}set(e){return this.refs.push(e),this}has(e,t){e=e.toLowerCase();for(var r=0;r<this.refs.length;r++)if(this.refs[r][e]===t)return!0;return!1}parse(e,t){e=p(e=(t=t||0)?e.slice(t):e).replace(s,"");for(var r=l,n=e.length,i=(t=0,null);t<n;)if(r===l){if(d(e[t])){t++;continue}if("<"!==e[t])throw new Error('Unexpected character "'+e[t]+'" at offset '+t);if(null!=i&&(null!=i.rel?this.refs.push(...v.expandRelations(i)):this.refs.push(i)),-1===(c=e.indexOf(">",t)))throw new Error("Expected end of URI delimiter at offset "+t);i={uri:e.slice(t+1,c)},t=c,r=f,t++}else if(r===f){if(d(e[t])){t++;continue}if(";"===e[t])r=h,t++;else{if(","!==e[t])throw new Error('Unexpected character "'+e[t]+'" at offset '+t);r=l,t++}}else{if(r!==h)throw new Error('Unknown parser state "'+r+'"');if(";"===e[t]||d(e[t])){t++;continue}if(-1===(c=e.indexOf("=",t)))throw new Error("Expected attribute delimiter at offset "+t);var o=p(e.slice(t,c)).toLowerCase(),u="";if('"'===e[t=y(e,t=c+1)])for(t++;t<n;){if('"'===e[t]){t++;break}"\\"===e[t]&&t++,u+=e[t],t++}else{for(var c=t+1;!a.test(e[c])&&c<n;)c++;u=e.slice(t,c),t=c}switch(i[o]&&v.isSingleOccurenceAttr(o)||("*"===o[o.length-1]?i[o]=v.parseExtendedValue(u):(u="type"===o?u.toLowerCase():u,null!=i[o]?Array.isArray(i[o])?i[o].push(u):i[o]=[i[o],u]:i[o]=u)),e[t]){case",":r=l;break;case";":r=h}t++}return null!=i&&(null!=i.rel?this.refs.push(...v.expandRelations(i)):this.refs.push(i)),i=null,this}toString(){for(var e=[],t="",r=null,n=0;n<this.refs.length;n++)r=this.refs[n],t=Object.keys(this.refs[n]).reduce((function(e,t){return"uri"===t?e:e+"; "+v.formatAttribute(t,r[t])}),"<"+r.uri+">"),e.push(t);return e.join(", ")}}v.isCompatibleEncoding=function(e){return n.test(e)},v.parse=function(e,t){return(new v).parse(e,t)},v.isSingleOccurenceAttr=function(e){return"rel"===e||"type"===e||"media"===e||"title"===e||"title*"===e},v.isTokenAttr=function(e){return"rel"===e||"type"===e||"anchor"===e},v.escapeQuotes=function(e){return e.replace(/"/g,'\\"')},v.expandRelations=function(e){return e.rel.split(" ").map((function(t){var r=Object.assign({},e);return r.rel=t,r}))},v.parseExtendedValue=function(e){var t=/([^']+)?(?:'([^']+)')?(.+)/.exec(e);return{language:t[2].toLowerCase(),encoding:v.isCompatibleEncoding(t[1])?null:t[1].toLowerCase(),value:v.isCompatibleEncoding(t[1])?decodeURIComponent(t[3]):t[3]}},v.formatExtendedAttribute=function(e,t){var r=(t.encoding||"utf-8").toUpperCase();return e+"="+r+"'"+(t.language||"en")+"'"+(Buffer.isBuffer(t.value)&&v.isCompatibleEncoding(r)?t.value.toString(r):Buffer.isBuffer(t.value)?t.value.toString("hex").replace(/[0-9a-f]{2}/gi,"%$1"):encodeURIComponent(t.value))},v.formatAttribute=function(e,t){return Array.isArray(t)?t.map(t=>v.formatAttribute(e,t)).join("; "):"*"===e[e.length-1]||"string"!=typeof t?v.formatExtendedAttribute(e,t):(v.isTokenAttr(e)?t=g(t)?'"'+v.escapeQuotes(t)+'"':v.escapeQuotes(t):g(t)&&(t='"'+(t=(t=encodeURIComponent(t)).replace(/%20/g," ").replace(/%2C/g,",").replace(/%3B/g,";"))+'"'),e+"="+t)},e.exports=v},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FollowPromiseMany=t.FollowPromiseOne=void 0;const n=r(0),i=r(2),o=r(33);class s{constructor(){this.prefetchEnabled=!1,this.preferPushEnabled=!1,this.preferTranscludeEnabled=!1,this.useHeadEnabled=!1}preFetch(){return this.prefetchEnabled=!0,this}preferPush(){return this.preferPushEnabled=!0,this}preferTransclude(){return this.preferTranscludeEnabled=!0,this}useHead(){return this.useHeadEnabled=!0,this}}class a extends s{constructor(e,t,r){super(),this.resource=e,this.rel=t,this.variables=r}then(e,t){return this.fetchLinkedResource().then(e,t)}catch(e){return this.fetchLinkedResource().then(void 0,e)}finally(e){return this.then(()=>e(),()=>e())}follow(e,t){return new a(this.fetchLinkedResource(),e,t)}followAll(e){return new u(this.fetchLinkedResource(),e)}async fetchLinkedResource(){const e=await this.resource,t={};let r;this.preferPushEnabled&&(t["Prefer-Push"]=this.rel),!this.useHeadEnabled&&this.preferTranscludeEnabled&&(t.Prefer="transclude="+this.rel),r=this.useHeadEnabled?await e.head({headers:t}):await e.get({headers:t});const s=r.links.get(this.rel);if(!s)throw new n.LinkNotFound(`Link with rel ${this.rel} on ${r.uri} not found`);let a;a=s.templated&&this.variables?o.expand(s,this.variables):i.resolve(s);const u=e.go(a);return this.prefetchEnabled&&u.get().catch(e=>{console.warn("Error while prefetching linked resource",e)}),u}}t.FollowPromiseOne=a;class u extends s{constructor(e,t){super(),this.resource=e,this.rel=t}then(e,t){return this.fetchLinkedResources().then(e,t)}catch(e){return this.fetchLinkedResources().then(void 0,e)}finally(e){return this.then(()=>e(),()=>e())}async fetchLinkedResources(){const e=await this.resource,t={};let r;this.preferPushEnabled&&(t["Prefer-Push"]=this.rel),!this.useHeadEnabled&&this.preferTranscludeEnabled&&(t.Prefer="transclude="+this.rel),r=this.useHeadEnabled?await e.head({headers:t}):await e.get({headers:t});const n=r.links.getMany(this.rel);let o;const s=[];for(const t of n){o=i.resolve(t);const r=e.go(o);s.push(r),this.prefetchEnabled&&r.get().catch(e=>{console.warn("Error while prefetching linked resource",e)})}return s}}t.FollowPromiseMany=u},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.NeverCache=t.ShortCache=t.ForeverCache=void 0;var n=r(10);Object.defineProperty(t,"ForeverCache",{enumerable:!0,get:function(){return n.ForeverCache}});var i=r(40);Object.defineProperty(t,"ShortCache",{enumerable:!0,get:function(){return i.ShortCache}});var o=r(41);Object.defineProperty(t,"NeverCache",{enumerable:!0,get:function(){return o.NeverCache}})},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ForeverCache=void 0;t.ForeverCache=class{constructor(){this.cache=new Map}store(e){this.cache.set(e.uri,e.clone())}get(e){const t=this.cache.get(e);return t?t.clone():null}has(e){return this.cache.has(e)}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FollowPromiseMany=t.FollowPromiseOne=t.Field=t.Problem=t.oauth2=t.bearerAuth=t.basicAuth=t.ShortCache=t.NeverCache=t.ForeverCache=t.isState=t.HtmlState=t.CjState=t.TextState=t.SirenState=t.JsonApiState=t.BinaryState=t.HalState=t.resolve=t.Links=t.LinkNotFound=t.Resource=t.default=t.Ketting=t.Client=void 0;var n=r(12);Object.defineProperty(t,"Client",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(t,"Ketting",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(t,"default",{enumerable:!0,get:function(){return n.default}});var i=r(6);Object.defineProperty(t,"Resource",{enumerable:!0,get:function(){return i.default}});var o=r(0);Object.defineProperty(t,"LinkNotFound",{enumerable:!0,get:function(){return o.LinkNotFound}}),Object.defineProperty(t,"Links",{enumerable:!0,get:function(){return o.Links}});var s=r(2);Object.defineProperty(t,"resolve",{enumerable:!0,get:function(){return s.resolve}});var a=r(4);Object.defineProperty(t,"HalState",{enumerable:!0,get:function(){return a.HalState}}),Object.defineProperty(t,"BinaryState",{enumerable:!0,get:function(){return a.BinaryState}}),Object.defineProperty(t,"JsonApiState",{enumerable:!0,get:function(){return a.JsonApiState}}),Object.defineProperty(t,"SirenState",{enumerable:!0,get:function(){return a.SirenState}}),Object.defineProperty(t,"TextState",{enumerable:!0,get:function(){return a.TextState}}),Object.defineProperty(t,"CjState",{enumerable:!0,get:function(){return a.CjState}}),Object.defineProperty(t,"HtmlState",{enumerable:!0,get:function(){return a.HtmlState}}),Object.defineProperty(t,"isState",{enumerable:!0,get:function(){return a.isState}});var u=r(9);Object.defineProperty(t,"ForeverCache",{enumerable:!0,get:function(){return u.ForeverCache}}),Object.defineProperty(t,"NeverCache",{enumerable:!0,get:function(){return u.NeverCache}}),Object.defineProperty(t,"ShortCache",{enumerable:!0,get:function(){return u.ShortCache}});var c=r(42);Object.defineProperty(t,"basicAuth",{enumerable:!0,get:function(){return c.default}});var l=r(44);Object.defineProperty(t,"bearerAuth",{enumerable:!0,get:function(){return l.default}});var f=r(45);Object.defineProperty(t,"oauth2",{enumerable:!0,get:function(){return f.default}});var h=r(5);Object.defineProperty(t,"Problem",{enumerable:!0,get:function(){return h.Problem}}),t.Field=r(47);var p=r(8);Object.defineProperty(t,"FollowPromiseOne",{enumerable:!0,get:function(){return p.FollowPromiseOne}}),Object.defineProperty(t,"FollowPromiseMany",{enumerable:!0,get:function(){return p.FollowPromiseMany}})},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(13),i=r(6),o=r(4),s=r(1),a=r(2),u=r(9),c=r(7);t.default=class{constructor(e){this.contentTypeMap={"application/prs.hal-forms+json":[o.halStateFactory,"1.0"],"application/hal+json":[o.halStateFactory,"0.9"],"application/vnd.api+json":[o.jsonApiStateFactory,"0.8"],"application/vnd.siren+json":[o.sirenStateFactory,"0.8"],"application/vnd.collection+json":[o.cjStateFactory,"0.8"],"application/json":[o.halStateFactory,"0.7"],"text/html":[o.htmlStateFactory,"0.6"]},this.acceptHeader=(e,t)=>{if(!e.headers.has("Accept")){const t=Object.entries(this.contentTypeMap).map(([e,[t,r]])=>e+";q="+r).join(", ");e.headers.set("Accept",t)}return t(e)},this.cacheExpireHandler=async(e,t)=>{let r=!1;e.headers.has("X-KETTING-NO-STALE")&&(r=!0,e.headers.delete("X-KETTING-NO-STALE"));const n=await t(e);if(s.isSafeMethod(e.method))return n;if(!n.ok)return n;const i=[];if(r||"DELETE"===e.method||i.push(e.url),n.headers.has("Link"))for(const t of c.parse(n.headers.get("Link")).rel("invalidates")){const r=a.resolve(e.url,t.uri);i.push(r)}n.headers.has("Location")&&i.push(a.resolve(e.url,n.headers.get("Location"))),n.headers.has("Content-Location")&&i.push(a.resolve(e.url,n.headers.get("Content-Location")));for(const t of i){this.cache.delete(e.url);const r=this.resources.get(t);r&&r.emit("stale")}if("DELETE"===e.method){this.cache.delete(e.url);const t=this.resources.get(e.url);t&&t.emit("delete")}return n},this.bookmarkUri=e,this.fetcher=new n.Fetcher,this.fetcher.use(this.cacheExpireHandler),this.fetcher.use(this.acceptHeader),this.cache=new u.ForeverCache,this.resources=new Map}follow(e,t){return this.go().follow(e,t)}go(e){let t;if(t=void 0!==e?a.resolve(this.bookmarkUri,e):this.bookmarkUri,!this.resources.has(t)){const e=new i.default(this,t);return this.resources.set(t,e),e}return this.resources.get(t)}use(e,t="*"){this.fetcher.use(e,t)}clearCache(){this.cache.clear()}async getStateForResponse(e,t){const r=s.parseContentType(t.headers.get("Content-Type"));let n;return r?(n=r in this.contentTypeMap?await this.contentTypeMap[r][0](e,t):r.startsWith("text/")?await o.textStateFactory(e,t):r.match(/^application\/[A-Za-z-.]+\+json/)?await o.halStateFactory(e,t):await o.binaryStateFactory(e,t),n.client=this,n):o.binaryStateFactory(e,t)}cacheState(e){this.cache.store(e);const t=this.resources.get(e.uri);t&&t.emit("update",e);for(const t of e.getEmbedded())this.cacheState(t)}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Fetcher=void 0;const n=r(5);r(14);class i{constructor(){this.middlewares=[],this.advertiseKetting=!0}fetch(e,t){const n=new Request(e,t),i=new URL(n.url).origin,o=this.getMiddlewaresByOrigin(i);return o.push(e=>(!e.headers.has("User-Agent")&&this.advertiseKetting&&e.headers.set("User-Agent","Ketting/"+r(15).version),fetch(e))),function e(t,r){return t[0](r,r=>e(t.slice(1),r))}(o,n)}getMiddlewaresByOrigin(e){return this.middlewares.filter(([t,r])=>t.test(e)).map(([e,t])=>t)}use(e,t="*"){const r=t.split("*").map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("(.*)"),n=new RegExp("^"+r+"$");this.middlewares.push([n,e])}async fetchOrThrow(e,t){const r=await this.fetch(e,t);if(r.ok)return r;throw await n.default(r)}}t.Fetcher=i,t.default=i},function(e,t,r){},function(e){e.exports=JSON.parse('{"name":"ketting","version":"6.1.0","description":"Opiniated HATEAOS / Rest client.","main":"dist/index.js","browser":"browser/ketting.min.js","scripts":{"test":"make test","prepublishOnly":"make build","build":"make build"},"repository":{"type":"git","url":"git+https://github.com/badgateway/ketting.git"},"keywords":["rest","hypermedia","client","http","hateoas","hal"],"author":"Evert Pot","license":"MIT","bugs":{"url":"https://github.com/badgateway/ketting/issues"},"homepage":"https://github.com/badgateway/ketting#readme","files":["src/","dist/","browser/ketting.min.js","browser/ketting.min.js.map"],"types":"dist/index.d.ts","dependencies":{"fetch-mw-oauth2":"^0.5.0","hal-types":"^1.2.1","http-link-header":"^1.0.3","node-fetch":"^2.6.1","querystring-browser":"^1.0.4","sax":"^1.2.4","uri-template":"^1.0.1"},"devDependencies":{"@types/chai":"^4.2.12","@types/http-link-header":"^1.0.1","@types/koa-bodyparser":"^4.3.0","@types/koa-logger":"^3.1.1","@types/koa-static":"^4.0.1","@types/mocha":"^8.0.3","@types/node":"^10.17.35","@types/node-fetch":"^2.5.7","@types/sax":"^1.2.1","@typescript-eslint/eslint-plugin":"^4.3.0","@typescript-eslint/parser":"^4.3.0","awesome-typescript-loader":"^5.2.1","chai":"^4.2.0","eslint":"^7.10.0","koa":"^2.13.0","koa-bodyparser":"^4.3.0","koa-logger":"^3.2.1","koa-path-match":"^3.0.0","koa-static":"^5.0.0","mocha":"^8.1.3","nyc":"^15.1.0","ts-node":"^9.0.0","typescript":"^4.0.3","webpack":"^4.44.2","webpack-cli":"^3.3.12"},"nyc":{"extension":[".ts"]},"mocha":{"require":["ts-node/register","test/testserver.ts"],"ignore":"test/test-entrypoint.ts","recursive":true,"extension":["ts","js","tsx"],"exit":true}}')},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isState=void 0;const n=r(0);t.isState=function(e){return"string"==typeof e.uri&&e.links instanceof n.Links&&e.headers instanceof Headers}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ActionNotFound=t.SimpleAction=void 0;const n=r(18);t.SimpleAction=class{constructor(e,t){this.client=e;for(const[e,r]of Object.entries(t))this[e]=r}async submit(e){const t=new URL(this.uri);if("GET"===this.method){t.search=n.stringify(e);return this.client.go(t.toString()).get()}let r;switch(this.contentType){case"application/x-www-form-urlencoded":r=n.stringify(e);break;case"application/json":r=JSON.stringify(e);break;default:throw new Error(`Serializing mimetype ${this.contentType} is not yet supported in actions`)}const i=await this.client.fetcher.fetchOrThrow(t.toString(),{method:this.method,body:r,headers:{"Content-Type":this.contentType}});return this.client.getStateForResponse(t.toString(),i)}};class i extends Error{}t.ActionNotFound=i},function(e,t,r){"use strict";var n=t,i=r(19).Buffer;function o(e,t){try{return decodeURIComponent(e)}catch(r){return n.unescapeBuffer(e,t).toString()}}n.unescapeBuffer=function(e,t){for(var r,n,o,s=new i(e.length),a=0,u=0,c=0;u<=e.length;u++){var l=u<e.length?e.charCodeAt(u):NaN;switch(a){case 0:switch(l){case 37:r=0,n=0,a=1;break;case 43:t&&(l=32);default:s[c++]=l}break;case 1:if(o=l,l>=48&&l<=57)r=l-48;else if(l>=65&&l<=70)r=l-65+10;else{if(!(l>=97&&l<=102)){s[c++]=37,s[c++]=l,a=0;break}r=l-97+10}a=2;break;case 2:if(a=0,l>=48&&l<=57)n=l-48;else if(l>=65&&l<=70)n=l-65+10;else{if(!(l>=97&&l<=102)){s[c++]=37,s[c++]=o,s[c++]=l;break}n=l-97+10}s[c++]=16*r+n}}return s.slice(0,c-1)},n.unescape=o;for(var s=new Array(256),a=0;a<256;++a)s[a]="%"+((a<16?"0":"")+a.toString(16)).toUpperCase();n.escape=function(e){"string"!=typeof e&&(e+="");for(var t="",r=0,n=0;n<e.length;++n){var i=e.charCodeAt(n);if(!(33===i||45===i||46===i||95===i||126===i||i>=39&&i<=42||i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122))if(n-r>0&&(t+=e.slice(r,n)),i<128)r=n+1,t+=s[i];else if(i<2048)r=n+1,t+=s[192|i>>6]+s[128|63&i];else if(i<55296||i>=57344)r=n+1,t+=s[224|i>>12]+s[128|i>>6&63]+s[128|63&i];else{var o;if(!(++n<e.length))throw new URIError("URI malformed");o=1023&e.charCodeAt(n),r=n+1,t+=s[240|(i=65536+((1023&i)<<10|o))>>18]+s[128|i>>12&63]+s[128|i>>6&63]+s[128|63&i]}}return 0===r?e:r<e.length?t+e.slice(r):t};var u=function(e){return"string"==typeof e?e:"number"==typeof e&&isFinite(e)?""+e:"boolean"==typeof e?e?"true":"false":""};function c(e,t){try{return t(e)}catch(t){return n.unescape(e,!0)}}n.stringify=n.encode=function(e,t,r,i){t=t||"&",r=r||"=";var o=n.escape;if(i&&"function"==typeof i.encodeURIComponent&&(o=i.encodeURIComponent),null!==e&&"object"==typeof e){for(var s=Object.keys(e),a=s.length,c=a-1,l="",f=0;f<a;++f){var h=s[f],p=e[h],d=o(u(h))+r;if(Array.isArray(p)){for(var y=p.length,g=y-1,v=0;v<y;++v)l+=d+o(u(p[v])),v<g&&(l+=t);y&&f<c&&(l+=t)}else l+=d+o(u(p)),f<c&&(l+=t)}return l}return""},n.parse=n.decode=function(e,t,r,i){t=t||"&",r=r||"=";var s={};if("string"!=typeof e||0===e.length)return s;"string"!=typeof t&&(t+="");var a=r.length,u=t.length,l=1e3;i&&"number"==typeof i.maxKeys&&(l=i.maxKeys);var f=1/0;l>0&&(f=l);var h=n.unescape;i&&"function"==typeof i.decodeURIComponent&&(h=i.decodeURIComponent);for(var p=h!==o,d=[],y=0,g=0,v=0,w="",m="",b=p,_=p,S=0,A=0;A<e.length;++A){var O=e.charCodeAt(A);if(O!==t.charCodeAt(g)){if(g=0,_||(37===O?S=1:S>0&&(O>=48&&O<=57||O>=65&&O<=70||O>=97&&O<=102)?3==++S&&(_=!0):S=0),v<a){if(O===r.charCodeAt(v)){if(++v===a)y<(E=A-v+1)&&(w+=e.slice(y,E)),S=0,y=A+1;continue}v=0,b||(37===O?S=1:S>0&&(O>=48&&O<=57||O>=65&&O<=70||O>=97&&O<=102)?3==++S&&(b=!0):S=0)}43===O&&(v<a?(A-y>0&&(w+=e.slice(y,A)),w+="%20",b=!0):(A-y>0&&(m+=e.slice(y,A)),m+="%20",_=!0),y=A+1)}else if(++g===u){var x,E=A-g+1;if(v<a?y<E&&(w+=e.slice(y,E)):y<E&&(m+=e.slice(y,E)),b&&(w=c(w,h)),_&&(m=c(m,h)),-1===d.indexOf(w))s[w]=m,d[d.length]=w;else(x=s[w])instanceof Array?x[x.length]=m:s[w]=[x,m];if(0==--f)break;b=_=p,S=0,w=m="",y=A+1,g=v=0}}f>0&&(y<e.length||v>0)&&(y<e.length&&(v<a?w+=e.slice(y):g<u&&(m+=e.slice(y))),b&&(w=c(w,h)),_&&(m=c(m,h)),-1===d.indexOf(w)?(s[w]=m,d[d.length]=w):(x=s[w])instanceof Array?x[x.length]=m:s[w]=[x,m]);return s}},function(e,t,r){"use strict";(function(e){
2/*!
3 * The buffer module from node.js, for the browser.
4 *
5 * @author Feross Aboukhadijeh <http://feross.org>
6 * @license MIT
7 */
8var n=r(21),i=r(22),o=r(23);function s(){return u.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(e,t){if(s()<t)throw new RangeError("Invalid typed array length");return u.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=u.prototype:(null===e&&(e=new u(t)),e.length=t),e}function u(e,t,r){if(!(u.TYPED_ARRAY_SUPPORT||this instanceof u))return new u(e,t,r);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return f(this,e)}return c(this,e,t,r)}function c(e,t,r,n){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,r,n){if(t.byteLength,r<0||t.byteLength<r)throw new RangeError("'offset' is out of bounds");if(t.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");t=void 0===r&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,r):new Uint8Array(t,r,n);u.TYPED_ARRAY_SUPPORT?(e=t).__proto__=u.prototype:e=h(e,t);return e}(e,t,r,n):"string"==typeof t?function(e,t,r){"string"==typeof r&&""!==r||(r="utf8");if(!u.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|d(t,r),i=(e=a(e,n)).write(t,r);i!==n&&(e=e.slice(0,i));return e}(e,t,r):function(e,t){if(u.isBuffer(t)){var r=0|p(t.length);return 0===(e=a(e,r)).length||t.copy(e,0,0,r),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(n=t.length)!=n?a(e,0):h(e,t);if("Buffer"===t.type&&o(t.data))return h(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function l(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function f(e,t){if(l(t),e=a(e,t<0?0:0|p(t)),!u.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function h(e,t){var r=t.length<0?0:0|p(t.length);e=a(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function p(e){if(e>=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|e}function d(e,t){if(u.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var r=e.length;if(0===r)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return H(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Y(e).length;default:if(n)return H(e).length;t=(""+t).toLowerCase(),n=!0}}function y(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return j(this,t,r);case"utf8":case"utf-8":return E(this,t,r);case"ascii":return k(this,t,r);case"latin1":case"binary":return P(this,t,r);case"base64":return x(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function g(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function v(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=u.from(t,n)),u.isBuffer(t))return 0===t.length?-1:w(e,t,r,n,i);if("number"==typeof t)return t&=255,u.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):w(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function w(e,t,r,n,i){var o,s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}function c(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var l=-1;for(o=r;o<a;o++)if(c(e,o)===c(t,-1===l?0:o-l)){if(-1===l&&(l=o),o-l+1===u)return l*s}else-1!==l&&(o-=o-l),l=-1}else for(r+u>a&&(r=a-u),o=r;o>=0;o--){for(var f=!0,h=0;h<u;h++)if(c(e,o+h)!==c(t,h)){f=!1;break}if(f)return o}return-1}function m(e,t,r,n){r=Number(r)||0;var i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s<n;++s){var a=parseInt(t.substr(2*s,2),16);if(isNaN(a))return s;e[r+s]=a}return s}function b(e,t,r,n){return D(H(t,e.length-r),e,r,n)}function _(e,t,r,n){return D(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function S(e,t,r,n){return _(e,t,r,n)}function A(e,t,r,n){return D(Y(t),e,r,n)}function O(e,t,r,n){return D(function(e,t){for(var r,n,i,o=[],s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(t,e.length-r),e,r,n)}function x(e,t,r){return 0===t&&r===e.length?n.fromByteArray(e):n.fromByteArray(e.slice(t,r))}function E(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i<r;){var o,s,a,u,c=e[i],l=null,f=c>239?4:c>223?3:c>191?2:1;if(i+f<=r)switch(f){case 1:c<128&&(l=c);break;case 2:128==(192&(o=e[i+1]))&&(u=(31&c)<<6|63&o)>127&&(l=u);break;case 3:o=e[i+1],s=e[i+2],128==(192&o)&&128==(192&s)&&(u=(15&c)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(l=u);break;case 4:o=e[i+1],s=e[i+2],a=e[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(u=(15&c)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(l=u)}null===l?(l=65533,f=1):l>65535&&(l-=65536,n.push(l>>>10&1023|55296),l=56320|1023&l),n.push(l),i+=f}return function(e){var t=e.length;if(t<=4096)return String.fromCharCode.apply(String,e);var r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=4096));return r}(n)}t.Buffer=u,t.SlowBuffer=function(e){+e!=e&&(e=0);return u.alloc(+e)},t.INSPECT_MAX_BYTES=50,u.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(e){return!1}}(),t.kMaxLength=s(),u.poolSize=8192,u._augment=function(e){return e.__proto__=u.prototype,e},u.from=function(e,t,r){return c(null,e,t,r)},u.TYPED_ARRAY_SUPPORT&&(u.prototype.__proto__=Uint8Array.prototype,u.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&u[Symbol.species]===u&&Object.defineProperty(u,Symbol.species,{value:null,configurable:!0})),u.alloc=function(e,t,r){return function(e,t,r,n){return l(t),t<=0?a(e,t):void 0!==r?"string"==typeof n?a(e,t).fill(r,n):a(e,t).fill(r):a(e,t)}(null,e,t,r)},u.allocUnsafe=function(e){return f(null,e)},u.allocUnsafeSlow=function(e){return f(null,e)},u.isBuffer=function(e){return!(null==e||!e._isBuffer)},u.compare=function(e,t){if(!u.isBuffer(e)||!u.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var r=e.length,n=t.length,i=0,o=Math.min(r,n);i<o;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},u.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},u.concat=function(e,t){if(!o(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return u.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=u.allocUnsafe(t),i=0;for(r=0;r<e.length;++r){var s=e[r];if(!u.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(n,i),i+=s.length}return n},u.byteLength=d,u.prototype._isBuffer=!0,u.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)g(this,t,t+1);return this},u.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)g(this,t,t+3),g(this,t+1,t+2);return this},u.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)g(this,t,t+7),g(this,t+1,t+6),g(this,t+2,t+5),g(this,t+3,t+4);return this},u.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?E(this,0,e):y.apply(this,arguments)},u.prototype.equals=function(e){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===u.compare(this,e)},u.prototype.inspect=function(){var e="",r=t.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(e+=" ... ")),"<Buffer "+e+">"},u.prototype.compare=function(e,t,r,n,i){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(t>>>=0),a=Math.min(o,s),c=this.slice(n,i),l=e.slice(t,r),f=0;f<a;++f)if(c[f]!==l[f]){o=c[f],s=l[f];break}return o<s?-1:s<o?1:0},u.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},u.prototype.indexOf=function(e,t,r){return v(this,e,t,r,!0)},u.prototype.lastIndexOf=function(e,t,r){return v(this,e,t,r,!1)},u.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return m(this,e,t,r);case"utf8":case"utf-8":return b(this,e,t,r);case"ascii":return _(this,e,t,r);case"latin1":case"binary":return S(this,e,t,r);case"base64":return A(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function k(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function P(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function j(e,t,r){var n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);for(var i="",o=t;o<r;++o)i+=N(e[o]);return i}function T(e,t,r){for(var n=e.slice(t,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function C(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function L(e,t,r,n,i,o){if(!u.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function R(e,t,r,n){t<0&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-r,2);i<o;++i)e[r+i]=(t&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function M(e,t,r,n){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-r,4);i<o;++i)e[r+i]=t>>>8*(n?i:3-i)&255}function B(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function F(e,t,r,n,o){return o||B(e,0,r,4),i.write(e,t,r,n,23,4),r+4}function U(e,t,r,n,o){return o||B(e,0,r,8),i.write(e,t,r,n,52,8),r+8}u.prototype.slice=function(e,t){var r,n=this.length;if((e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e),u.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=u.prototype;else{var i=t-e;r=new u(i,void 0);for(var o=0;o<i;++o)r[o]=this[o+e]}return r},u.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||C(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return n},u.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||C(e,t,this.length);for(var n=this[e+--t],i=1;t>0&&(i*=256);)n+=this[e+--t]*i;return n},u.prototype.readUInt8=function(e,t){return t||C(e,1,this.length),this[e]},u.prototype.readUInt16LE=function(e,t){return t||C(e,2,this.length),this[e]|this[e+1]<<8},u.prototype.readUInt16BE=function(e,t){return t||C(e,2,this.length),this[e]<<8|this[e+1]},u.prototype.readUInt32LE=function(e,t){return t||C(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},u.prototype.readUInt32BE=function(e,t){return t||C(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},u.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||C(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*t)),n},u.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||C(e,t,this.length);for(var n=t,i=1,o=this[e+--n];n>0&&(i*=256);)o+=this[e+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*t)),o},u.prototype.readInt8=function(e,t){return t||C(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},u.prototype.readInt16LE=function(e,t){t||C(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt16BE=function(e,t){t||C(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt32LE=function(e,t){return t||C(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},u.prototype.readInt32BE=function(e,t){return t||C(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},u.prototype.readFloatLE=function(e,t){return t||C(e,4,this.length),i.read(this,e,!0,23,4)},u.prototype.readFloatBE=function(e,t){return t||C(e,4,this.length),i.read(this,e,!1,23,4)},u.prototype.readDoubleLE=function(e,t){return t||C(e,8,this.length),i.read(this,e,!0,52,8)},u.prototype.readDoubleBE=function(e,t){return t||C(e,8,this.length),i.read(this,e,!1,52,8)},u.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||L(this,e,t,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[t]=255&e;++o<r&&(i*=256);)this[t+o]=e/i&255;return t+r},u.prototype.writeUIntBE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||L(this,e,t,r,Math.pow(2,8*r)-1,0);var i=r-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+r},u.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||L(this,e,t,1,255,0),u.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},u.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||L(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):R(this,e,t,!0),t+2},u.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||L(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):R(this,e,t,!1),t+2},u.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||L(this,e,t,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):M(this,e,t,!0),t+4},u.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||L(this,e,t,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):M(this,e,t,!1),t+4},u.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);L(this,e,t,r,i-1,-i)}var o=0,s=1,a=0;for(this[t]=255&e;++o<r&&(s*=256);)e<0&&0===a&&0!==this[t+o-1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+r},u.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);L(this,e,t,r,i-1,-i)}var o=r-1,s=1,a=0;for(this[t+o]=255&e;--o>=0&&(s*=256);)e<0&&0===a&&0!==this[t+o+1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+r},u.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||L(this,e,t,1,127,-128),u.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},u.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||L(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):R(this,e,t,!0),t+2},u.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||L(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):R(this,e,t,!1),t+2},u.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||L(this,e,t,4,2147483647,-2147483648),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):M(this,e,t,!0),t+4},u.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||L(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):M(this,e,t,!1),t+4},u.prototype.writeFloatLE=function(e,t,r){return F(this,e,t,!0,r)},u.prototype.writeFloatBE=function(e,t,r){return F(this,e,t,!1,r)},u.prototype.writeDoubleLE=function(e,t,r){return U(this,e,t,!0,r)},u.prototype.writeDoubleBE=function(e,t,r){return U(this,e,t,!1,r)},u.prototype.copy=function(e,t,r,n){if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var i,o=n-r;if(this===e&&r<t&&t<n)for(i=o-1;i>=0;--i)e[i+t]=this[i+r];else if(o<1e3||!u.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)e[i+t]=this[i+r];else Uint8Array.prototype.set.call(e,this.subarray(r,r+o),t);return o},u.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===e.length){var i=e.charCodeAt(0);i<256&&(e=i)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!u.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;var o;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(o=t;o<r;++o)this[o]=e;else{var s=u.isBuffer(e)?e:H(new u(e,n).toString()),a=s.length;for(o=0;o<r-t;++o)this[o+t]=s[o%a]}return this};var I=/[^+\/0-9A-Za-z-_]/g;function N(e){return e<16?"0"+e.toString(16):e.toString(16)}function H(e,t){var r;t=t||1/0;for(var n=e.length,i=null,o=[],s=0;s<n;++s){if((r=e.charCodeAt(s))>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function Y(e){return n.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(I,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function D(e,t,r,n){for(var i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}}).call(this,r(20))},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){"use strict";t.byteLength=function(e){var t=c(e),r=t[0],n=t[1];return 3*(r+n)/4-n},t.toByteArray=function(e){var t,r,n=c(e),s=n[0],a=n[1],u=new o(function(e,t,r){return 3*(t+r)/4-r}(0,s,a)),l=0,f=a>0?s-4:s;for(r=0;r<f;r+=4)t=i[e.charCodeAt(r)]<<18|i[e.charCodeAt(r+1)]<<12|i[e.charCodeAt(r+2)]<<6|i[e.charCodeAt(r+3)],u[l++]=t>>16&255,u[l++]=t>>8&255,u[l++]=255&t;2===a&&(t=i[e.charCodeAt(r)]<<2|i[e.charCodeAt(r+1)]>>4,u[l++]=255&t);1===a&&(t=i[e.charCodeAt(r)]<<10|i[e.charCodeAt(r+1)]<<4|i[e.charCodeAt(r+2)]>>2,u[l++]=t>>8&255,u[l++]=255&t);return u},t.fromByteArray=function(e){for(var t,r=e.length,i=r%3,o=[],s=0,a=r-i;s<a;s+=16383)o.push(l(e,s,s+16383>a?a:s+16383));1===i?(t=e[r-1],o.push(n[t>>2]+n[t<<4&63]+"==")):2===i&&(t=(e[r-2]<<8)+e[r-1],o.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"="));return o.join("")};for(var n=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,u=s.length;a<u;++a)n[a]=s[a],i[s.charCodeAt(a)]=a;function c(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function l(e,t,r){for(var i,o,s=[],a=t;a<r;a+=3)i=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),s.push(n[(o=i)>>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return s.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(e,t){t.read=function(e,t,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,c=u>>1,l=-7,f=r?i-1:0,h=r?-1:1,p=e[t+f];for(f+=h,o=p&(1<<-l)-1,p>>=-l,l+=a;l>0;o=256*o+e[t+f],f+=h,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=n;l>0;s=256*s+e[t+f],f+=h,l-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),o-=c}return(p?-1:1)*s*Math.pow(2,o-n)},t.write=function(e,t,r,n,i,o){var s,a,u,c=8*o-i-1,l=(1<<c)-1,f=l>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,y=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=l):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+f>=1?h/u:h*Math.pow(2,1-f))*u>=2&&(s++,u/=2),s+f>=l?(a=0,s=l):s+f>=1?(a=(t*u-1)*Math.pow(2,i),s+=f):(a=t*Math.pow(2,f-1)*Math.pow(2,i),s=0));i>=8;e[r+p]=255&a,p+=d,a/=256,i-=8);for(s=s<<i|a,c+=i;c>0;e[r+p]=255&s,p+=d,s/=256,c-=8);e[r+p-d]|=128*y}},function(e,t){var r={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==r.call(e)}},function(e,t,r){"use strict";var n=this&&this.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r};Object.defineProperty(t,"__esModule",{value:!0}),t.factory=t.HalState=void 0;const i=r(3),o=r(1),s=r(0),a=r(2);class u extends i.BaseState{serializeBody(){return JSON.stringify(Object.assign({_links:this.serializeLinks()},this.data))}serializeLinks(){const e={self:{href:this.uri}};for(const t of this.links.getAll()){const{rel:r,context:i}=t,o=n(t,["rel","context"]);"self"!==r&&(void 0===e[r]?e[r]=o:Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o])}return e}clone(){return new u(this.uri,this.data,new Headers(this.headers),new s.Links(this.uri,this.links),[],this.actionInfo)}}function c(e,t){var r,n;if(void 0===t._links)return[];const i=[],o=new Set;for(const[r,n]of Object.entries(t._links)){const t=Array.isArray(n)?n:[n];for(const e of t)o.add(r+";"+e.href);i.push(...l(e,r,t))}if(t._embedded)for(let[s,a]of Object.entries(t._embedded)){Array.isArray(a)||(a=[a]);for(const t of a){const a=null===(n=null===(r=null==t?void 0:t._links)||void 0===r?void 0:r.self)||void 0===n?void 0:n.href;a&&(o.has(s+";"+a)||i.push({rel:s,href:a,context:e}))}}return i}function l(e,t,r){const n=[];for(const i of r)n.push(Object.assign({rel:t,context:e},i));return n}t.HalState=u,t.factory=async(e,t)=>{var r;const i=await t.json(),l=o.parseLink(e,t.headers.get("Link"));if(Array.isArray(i))return new u(e,i,t.headers,l,[]);l.add(...c(e,i));const{_embedded:f,_links:h,_templates:p}=i,d=n(i,["_embedded","_links","_templates"]),y=null===(r=i._templates)||void 0===r?void 0:r.default;return new u(e,d,t.headers,l,function e(t,r,i){if(void 0===r._embedded)return[];const o=[];for(const l of Object.values(r._embedded)){let r;r=Array.isArray(l)?l:[l];for(const l of r){if(void 0===l._links||void 0===l._links.self||Array.isArray(l._links.self))continue;const{_embedded:r,_links:f}=l,h=n(l,["_embedded","_links"]);o.push(new u(a.resolve(t,l._links.self.href),h,new Headers({"Content-Type":i.get("Content-Type")}),new s.Links(t,c(t,l)),e(t,l,i)))}}return o}(e,i,t.headers),y?[(g=e,v=y,{uri:g,name:"default",title:v.title,method:v.method,contentType:v.contentType||"application/json",fields:v.properties?v.properties.map(e=>{return{name:(t=e).name,type:"text",required:t.required||!1,readOnly:t.readOnly||!1,value:t.value,pattern:t.regex?new RegExp(t.regex):void 0,label:t.prompt};var t}):[]})]:[]);var g,v}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.factory=t.BinaryState=void 0;const n=r(3),i=r(1),o=r(0);class s extends n.BaseState{serializeBody(){return this.data}clone(){return new s(this.uri,this.data,new Headers(this.headers),new o.Links(this.uri,this.links))}}t.BinaryState=s,t.factory=async(e,t)=>new s(e,await t.blob(),t.headers,i.parseLink(e,t.headers.get("Link")))},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.factory=t.JsonApiState=void 0;const n=r(3),i=r(1),o=r(0);class s extends n.BaseState{serializeBody(){return JSON.stringify(this.data)}clone(){return new s(this.uri,this.data,new Headers(this.headers),new o.Links(this.uri,this.links))}}function a(e,t,r){return{context:e,rel:t,href:"string"==typeof r?r:r.href}}t.JsonApiState=s,t.factory=async(e,t)=>{const r=await t.json(),n=i.parseLink(e,t.headers.get("Link"));return n.add(...function(e,t){const r=[];if(void 0===t.links)return r;for(const[n,i]of Object.entries(t.links))Array.isArray(i)?r.push(...i.map(t=>a(e,n,t))):r.push(a(e,n,i));return r}(e,r),...function(e,t){if(!Array.isArray(t.data))return[];const r=[];for(const n of t.data)if("links"in n&&"self"in n.links){const t=a(e,"self",n.links.self);r.push({context:e,href:t.href,rel:"item"})}return r}(e,r)),new s(e,r,t.headers,n)}},function(e,t,r){"use strict";var n=this&&this.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r};Object.defineProperty(t,"__esModule",{value:!0}),t.factory=t.SirenState=void 0;const i=r(3),o=r(1),s=r(0),a=r(2);class u extends i.BaseState{serializeBody(){throw new Error("Reserializing Siren states is not yet supported. Please log an issue in the Ketting project to help figure out how this should be done")}clone(){return new u(this.uri,this.data,new Headers(this.headers),new s.Links(this.uri,this.links),[],this.actionInfo)}}function c(e,t){const r=[];if(void 0!==t.links)for(const n of t.links)r.push(...l(e,n));if(void 0!==t.entities)for(const n of t.entities)void 0!==n.href?r.push(...l(e,n)):r.push(...f(e,n));return r}function l(e,t){const r=[],{rel:i}=t,o=n(t,["rel"]);for(const t of i){const n=Object.assign({rel:t,context:e},o);r.push(n)}return r}function f(e,t){if(void 0===t.links)return[];let r=null;for(const e of t.links)e.rel.includes("self")&&(r=e.href);return null===r?[]:t.rel.map(n=>{const i=t.title,o={href:r,rel:n,context:e};return i&&(o.title=i),o})}function h(e,t,r){if(void 0===t.links)return null;let n=null;for(const e of t.links)e.rel.includes("self")&&(n=e.href);if(!n)return null;const i=a.resolve(e,n);return new u(i,t.properties,r,new s.Links(n,c(n,t)))}t.SirenState=u,t.factory=async(e,t)=>{const r=await t.json(),n=o.parseLink(e,t.headers.get("Link"));return n.add(...c(e,r)),new u(e,r.properties,t.headers,n,function(e,t,r){if(void 0===t.entities)return[];const n=[];for(const i of t.entities)if(void 0===i.href){const t=h(e,i,r);null!==t&&n.push(t)}return n}(e,r,t.headers),r.actions?r.actions.map(t=>function(e,t){return{uri:a.resolve(e,t.href),name:t.name,title:t.title,method:t.method||"GET",contentType:t.type||"application/x-www-form-urlencoded",fields:t.fields?t.fields.map(e=>{return{name:(t=e).name,type:t.type||"text",required:!1,readOnly:!1};var t}):[]}}(e,t)):[])}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.factory=t.TextState=void 0;const n=r(3),i=r(1),o=r(0);class s extends n.BaseState{serializeBody(){return this.data}clone(){return new s(this.uri,this.data,new Headers(this.headers),new o.Links(this.uri,this.links))}}t.TextState=s,t.factory=async(e,t)=>new s(e,await t.text(),t.headers,i.parseLink(e,t.headers.get("Link")))},function(e,t,r){"use strict";var n=this&&this.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r};Object.defineProperty(t,"__esModule",{value:!0}),t.factory=t.CjState=void 0;const i=r(3),o=r(1),s=r(0);class a extends i.BaseState{serializeBody(){throw new Error("Reserializing Collection+JSON states is not yet supported. Please log an issue in the Ketting project to help figure out how this should be done")}clone(){return new a(this.uri,this.data,new Headers(this.headers),new s.Links(this.uri,this.links))}}t.CjState=a,t.factory=async(e,t)=>{const r=await t.json(),i=o.parseLink(e,t.headers.get("Link"));i.add(...function(e,t){const r=[];if(void 0!==t.collection.links)for(const n of t.collection.links)r.push({context:e,href:n.href,rel:n.rel,title:n.name});if(void 0!==t.collection.items)for(const n of t.collection.items)n.href&&r.push({context:e,href:n.href,rel:"item"});if(void 0!==t.collection.queries)for(const n of t.collection.queries)n.data?r.push({context:e,href:n.href+n.data.map(e=>"{?"+e.name+"}").join(""),templated:!0,rel:n.rel,title:n.name}):r.push({context:e,href:n.href,rel:n.rel,title:n.name});return r}(e,r));const{_embedded:s,_links:u}=r,c=n(r,["_embedded","_links"]);return new a(e,c,t.headers,i)}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.factory=t.HtmlState=void 0;const n=r(3),i=r(1),o=r(31),s=r(0),a=r(2);class u extends n.BaseState{serializeBody(){return this.data}clone(){const e=new u(this.uri,this.data,new Headers(this.headers),new s.Links(this.uri,this.links),[],this.actionInfo);return e.client=this.client,e}}t.HtmlState=u,t.factory=async(e,t)=>{const r=await t.text(),n=i.parseLink(e,t.headers.get("Link")),s=o.parseHtml(e,r);return n.add(...s.links),new u(e,r,t.headers,n,[],s.forms.map(t=>function(e,t){return{uri:a.resolve(e,t.action),name:t.rel||t.id||"",method:t.method||"GET",contentType:t.enctype||"application/x-www-form-urlencoded",fields:[]}}(e,t)))}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.parseHtml=void 0;const n=r(2);function i(e,t){const r=[];for(const n of t){const t=n.getAttribute("rel"),i=n.getAttribute("href"),o=n.getAttribute("type")||void 0;if(t&&i)for(const n of t.split(" ")){const t={rel:n,context:e,href:i};o&&(t.type=o),r.push(t)}}return r}function o(e,t){const r=[];for(const i of t){const t=i.getAttribute("rel"),o=i.getAttribute("action"),s=i.getAttribute("enctype")||"application/x-www-form-urlencoded",a=i.getAttribute("id"),u=i.getAttribute("method")||"GET";if(t)for(const i of t.split(" ")){const t={rel:i,action:n.resolve(e,o),enctype:s,id:a,method:u};r.push(t)}else r.push({rel:null,action:n.resolve(e,o),enctype:s,id:a,method:u})}return r}t.parseHtml=function(e,t){const r=(new DOMParser).parseFromString(t,"text/html");return{forms:o(e,r.getElementsByTagName("form")),links:[...i(e,r.getElementsByTagName("link")),...i(e,r.getElementsByTagName("a"))]}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.factory=void 0;const n=r(1);t.factory=async(e,t)=>{const r=n.parseLink(e,t.headers.get("Link"));return{uri:e,headers:t.headers,contentHeaders:()=>{const e=["Content-Type","Content-Language"],r={};for(const n of e)t.headers.has(n)&&(r[n]=t.headers.get(n));return new Headers(r)},links:r,timestamp:Date.now()}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.expand=void 0;const n=r(34),i=r(2);t.expand=function(e,t,r){let o,s,a;"string"==typeof e?(o=e,s=t,a=r):(o=e.context,s=e.href,a=t);const u=n.parse(s).expand(a);return i.resolve(o,u)}},function(e,t,r){e.exports=function(){function e(e){return'"'+e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var t={parse:function(t,n){var i={uriTemplate:function(){var e,t,r;r=o,e=[],null===(t=g())&&(t=c());for(;null!==t;)e.push(t),null===(t=g())&&(t=c());null!==e&&(e=new m(e));null===e&&(o=r);return e},expression:c,op:l,pathExpression:function(){var e;"{/"===t.substr(o,2)?(e="{/",o+=2):(e=null,u('"{/"'));return e},paramList:f,param:h,cut:p,listMarker:d,substr:y,nonexpression:g,extension:v};if(void 0!==n){if(void 0===i[n])throw new Error("Invalid rule name: "+e(n)+".")}else n="uriTemplate";var o=0,s=0,a=[];function u(e){o<s||(o>s&&(s=o,a=[]),a.push(e))}function c(){var e,r,n,i,s,a,c,h;return s=o,a=o,123===t.charCodeAt(o)?(e="{",o++):(e=null,u('"{"')),null!==e&&null!==(r=l())&&null!==(n=f())?(125===t.charCodeAt(o)?(i="}",o++):(i=null,u('"}"')),null!==i?e=[e,r,n,i]:(e=null,o=a)):(e=null,o=a),null!==e&&(c=e[1],h=e[2],e=b(c,h)),null===e&&(o=s),e}function l(){var e;return/^[\/;:.?&+#]/.test(t.charAt(o))?(e=t.charAt(o),o++):(e=null,u("[\\/;:.?&+#]")),null===e&&(e=""),e}function f(){var e,r,n,i,s,a,c,l,f,p;if(s=o,a=o,null!==(e=h())){for(r=[],c=o,l=o,44===t.charCodeAt(o)?(n=",",o++):(n=null,u('","')),null!==n&&null!==(i=h())?n=[n,i]:(n=null,o=l),null!==n&&(n=n[1]),null===n&&(o=c);null!==n;)r.push(n),c=o,l=o,44===t.charCodeAt(o)?(n=",",o++):(n=null,u('","')),null!==n&&null!==(i=h())?n=[n,i]:(n=null,o=l),null!==n&&(n=function(e,t){return t}(0,n[1])),null===n&&(o=c);null!==r?e=[e,r]:(e=null,o=a)}else e=null,o=a;return null!==e&&(f=e[0],(p=e[1]).unshift(f),e=p),null===e&&(o=s),e}function h(){var e,r,n,i,s,a,c,l;for(i=o,s=o,e=[],/^[a-zA-Z0-9_.%]/.test(t.charAt(o))?(r=t.charAt(o),o++):(r=null,u("[a-zA-Z0-9_.%]"));null!==r;)e.push(r),/^[a-zA-Z0-9_.%]/.test(t.charAt(o))?(r=t.charAt(o),o++):(r=null,u("[a-zA-Z0-9_.%]"));return null!==e?(null===(r=p())&&(r=d()),null!==(r=null!==r?r:"")&&null!==(n=null!==(n=v())?n:"")?e=[e,r,n]:(e=null,o=s)):(e=null,o=s),null!==e&&(a=e[0],c=e[1],l=e[2],c=c||{},e={name:a.join(""),explode:c.listMarker,cut:c.cut,extended:l}),null===e&&(o=i),e}function p(){var e,t;return t=o,null!==(e=y())&&(e={cut:e}),null===e&&(o=t),e}function d(){var e,r;return r=o,42===t.charCodeAt(o)?(e="*",o++):(e=null,u('"*"')),null!==e&&(e={listMarker:e}),null===e&&(o=r),e}function y(){var e,r,n,i,s,a;if(i=o,s=o,58===t.charCodeAt(o)?(e=":",o++):(e=null,u('":"')),null!==e){if(/^[0-9]/.test(t.charAt(o))?(n=t.charAt(o),o++):(n=null,u("[0-9]")),null!==n)for(r=[];null!==n;)r.push(n),/^[0-9]/.test(t.charAt(o))?(n=t.charAt(o),o++):(n=null,u("[0-9]"));else r=null;null!==r?e=[e,r]:(e=null,o=s)}else e=null,o=s;return null!==e&&(a=e[1],e=parseInt(a.join(""))),null===e&&(o=i),e}function g(){var e,r,n;if(n=o,/^[^{]/.test(t.charAt(o))?(r=t.charAt(o),o++):(r=null,u("[^{]")),null!==r)for(e=[];null!==r;)e.push(r),/^[^{]/.test(t.charAt(o))?(r=t.charAt(o),o++):(r=null,u("[^{]"));else e=null;return null!==e&&(e=e.join("")),null===e&&(o=n),e}function v(){var e,r,n,i,s;if(i=o,s=o,40===t.charCodeAt(o)?(e="(",o++):(e=null,u('"("')),null!==e){if(/^[^)]/.test(t.charAt(o))?(n=t.charAt(o),o++):(n=null,u("[^)]")),null!==n)for(r=[];null!==n;)r.push(n),/^[^)]/.test(t.charAt(o))?(n=t.charAt(o),o++):(n=null,u("[^)]"));else r=null;null!==r?(41===t.charCodeAt(o)?(n=")",o++):(n=null,u('")"')),null!==n?e=[e,r,n]:(e=null,o=s)):(e=null,o=s)}else e=null,o=s;return null!==e&&(e=e[1].join("")),null===e&&(o=i),e}var w=r(35),m=w.Template,b=w.expression,_=i[n]();if(null===_||o!==t.length){var S=Math.max(o,s),A=S<t.length?t.charAt(S):null,O=function(){for(var e=1,r=1,n=!1,i=0;i<Math.max(o,s);i++){var a=t.charAt(i);"\n"===a?(n||e++,r=1,n=!1):"\r"===a||"\u2028"===a||"\u2029"===a?(e++,r=1,n=!0):(r++,n=!1)}return{line:e,column:r}}();throw new this.SyntaxError(function(e){e.sort();for(var t=null,r=[],n=0;n<e.length;n++)e[n]!==t&&(r.push(e[n]),t=e[n]);return r}(a),A,S,O.line,O.column)}return _},toSource:function(){return this._source},SyntaxError:function(t,r,n,i,o){this.name="SyntaxError",this.expected=t,this.found=r,this.message=function(t,r){var n;switch(t.length){case 0:n="end of input";break;case 1:n=t[0];break;default:n=t.slice(0,t.length-1).join(", ")+" or "+t[t.length-1]}return"Expected "+n+" but "+(r?e(r):"end of input")+" found."}(t,r),this.offset=n,this.line=i,this.column=o}};return t.SyntaxError.prototype=Error.prototype,t}()},function(e,t,r){(function(){var t,n,i,o,s,a,u,c,l,f,h,p=function(e,t){return function(){return e.apply(t,arguments)}},d={}.hasOwnProperty,y=function(e,t){for(var r in t)d.call(t,r)&&(e[r]=t[r]);function n(){this.constructor=e}return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e};h=r(36),f=f=function(){function e(e){var t,r=this;this.expressions=[],this.prefix="string"==typeof e[0]?e.shift():"",t=0,e.forEach((function(e){switch(typeof e){case"object":return r.expressions[t++]=e;case"string":return r.expressions[t-1].suffix=e}}))}return e.prototype.expand=function(e){return this.prefix+this.expressions.map((function(t){return t.expand(e)})).join("")},e.prototype.toString=function(){return this.prefix+this.expressions.join("")},e.prototype.toJSON=function(){return this.toString()},e}(),s=function(e){function t(){return this.explodeArray=p(this.explodeArray,this),this.stringifySingle=p(this.stringifySingle,this),t.__super__.constructor.apply(this,arguments)}return y(t,e),t.prototype.stringifySingle=function(e,r){return r=(r=t.__super__.stringifySingle.apply(this,arguments))?"="+r:this.empty,""+e.name+r},t.prototype.explodeArray=function(e,t){var r=this;return t.map((function(t){return e.name+"="+r.encode(t)})).join(this.sep)},t}(l=function(){var e;function t(e){this.params=e,this.explodeObject=p(this.explodeObject,this),this.explodeArray=p(this.explodeArray,this),this._expandPair=p(this._expandPair,this),this.stringifySingle=p(this.stringifySingle,this),this.encode=p(this.encode,this),null==this.params&&(this.params=[]),this.suffix=""}return t.prototype.first="",t.prototype.sep=",",t.prototype.named=!1,t.prototype.empty="",t.prototype.allow="U",t.prototype.encode=function(e){return h[this.allow](e)},t.prototype.stringifySingle=function(e,t){var r,n,i;if("string"===(n=typeof t)||"boolean"===n||"number"===n)return t=t.toString(),this.encode(t.substring(0,e.cut||t.length));if(Array.isArray(t)){if(e.cut)throw new Error("Prefixed Values do not support lists. Check "+e.name);return t.map(this.encode).join(",")}if(e.cut)throw new Error("Prefixed Values do not support maps. Check "+e.name);return function(){var e;for(r in e=[],t)i=t[r],e.push([r,i].map(this.encode).join(","));return e}.call(this).join(",")},t.prototype.expand=function(t){var r,n,i=this;return(n=(r=e(this.params,t)).map((function(e){return i._expandPair.apply(i,e)})).join(this.sep))?this.first+n+this.suffix:this.empty&&r.length?this.empty+this.suffix:this.suffix},e=function(e,t){return e.map((function(e){return[e,t[e.name]]})).filter((function(e){var t,r;switch(typeof(r=e[1])){case"undefined":return!1;case"object":for(t in Array.isArray(r)&&r.length,r)if(r[t])return!0;return!1;default:return!0}}))},t.prototype._expandPair=function(e,t){return e.name,e.explode?Array.isArray(t)?this.explodeArray(e,t):"string"==typeof t?this.stringifySingle(e,t):this.explodeObject(t):this.stringifySingle(e,t)},t.prototype.explodeArray=function(e,t){return t.map(this.encode).join(this.sep)},t.prototype.explodeObject=function(e){var t,r,n,i,o,s;for(t in r=[],e)if(n=e[t],t=this.encode(t),Array.isArray(n))for(o=0,s=n.length;o<s;o++)i=n[o],r.push([t,this.encode(i)]);else r.push([t,this.encode(n)]);return r.map((function(e){return e.join("=")})).join(this.sep)},t.prototype.toString=function(){var e;return e=this.params.map((function(e){return e.name+e.explode})).join(","),"{"+this.first+e+"}"+this.suffix},t.prototype.toJSON=function(){return this.toString()},t}()),c=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return y(t,e),t.prototype.encode=function(e){return h["U+R"](e)},t.prototype.toString=function(){return"{+"+t.__super__.toString.apply(this,arguments).substring(1)},t}(l),i=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return y(t,e),t.prototype.first="#",t.prototype.empty="#",t.prototype.encode=function(e){return h["U+R"](e)},t}(l),o=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return y(t,e),t.prototype.first=".",t.prototype.sep=".",t.prototype.empty=".",t}(l),u=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return y(t,e),t.prototype.first="/",t.prototype.sep="/",t}(l),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return y(t,e),t.prototype.first=";",t.prototype.sep=";",t}(s),n=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return y(t,e),t.prototype.first="?",t.prototype.sep="&",t.prototype.empty="=",t}(s),t=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return y(t,e),t.prototype.first="&",t}(n),e.exports={Template:f,SimpleExpression:l,NamedExpression:s,ReservedExpression:c,FragmentExpression:i,LabelExpression:o,PathSegmentExpression:u,PathParamExpression:a,FormStartExpression:n,FormContinuationExpression:t,expression:function(e,r){return new(function(){switch(e){case"":return l;case"+":return c;case"#":return i;case".":return o;case"/":return u;case";":return a;case"?":return n;case"&":return t}}())(r)}}}).call(this)},function(e,t,r){(function(){var e;e=r(37),t.U=e(/[^\w~.-]/g),t["U+R"]=e(/[^\w.~:\/\?#\[\]@!\$&'()*+,;=%-]|%(?!\d\d)/g)}).call(this)},function(e,t){e.exports=function(e){return e=e||/\W/g,function(t){return(t=String(t)).replace(e,(function(e){var t=e[0].charCodeAt(0),r=[];return t<128?r.push(t):128<=t&&t<2048?(r.push(t>>6|192),r.push(63&t|128)):(r.push(t>>12|224),r.push(t>>6&63|128),r.push(63&t|128)),r.map((function(e){return"%"+e.toString(16).toUpperCase()})).join("")}))}}},function(e,t,r){"use strict";var n,i="object"==typeof Reflect?Reflect:null,o=i&&"function"==typeof i.apply?i.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};n=i&&"function"==typeof i.ownKeys?i.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var s=Number.isNaN||function(e){return e!=e};function a(){a.init.call(this)}e.exports=a,e.exports.once=function(e,t){return new Promise((function(r,n){function i(){void 0!==o&&e.removeListener("error",o),r([].slice.call(arguments))}var o;"error"!==t&&(o=function(r){e.removeListener(t,i),n(r)},e.once("error",o)),e.once(t,i)}))},a.EventEmitter=a,a.prototype._events=void 0,a.prototype._eventsCount=0,a.prototype._maxListeners=void 0;var u=10;function c(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function l(e){return void 0===e._maxListeners?a.defaultMaxListeners:e._maxListeners}function f(e,t,r,n){var i,o,s,a;if(c(r),void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),s=o[t]),void 0===s)s=o[t]=r,++e._eventsCount;else if("function"==typeof s?s=o[t]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),(i=l(e))>0&&s.length>i&&!s.warned){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,a=u,console&&console.warn&&console.warn(a)}return e}function h(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=h.bind(n);return i.listener=r,n.wrapFn=i,i}function d(e,t,r){var n=e._events;if(void 0===n)return[];var i=n[t];return void 0===i?[]:"function"==typeof i?r?[i.listener||i]:[i]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(i):g(i,i.length)}function y(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function g(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}Object.defineProperty(a,"defaultMaxListeners",{enumerable:!0,get:function(){return u},set:function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");u=e}}),a.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},a.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},a.prototype.getMaxListeners=function(){return l(this)},a.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var n="error"===e,i=this._events;if(void 0!==i)n=n&&void 0===i.error;else if(!n)return!1;if(n){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var u=i[e];if(void 0===u)return!1;if("function"==typeof u)o(u,this,t);else{var c=u.length,l=g(u,c);for(r=0;r<c;++r)o(l[r],this,t)}return!0},a.prototype.addListener=function(e,t){return f(this,e,t,!1)},a.prototype.on=a.prototype.addListener,a.prototype.prependListener=function(e,t){return f(this,e,t,!0)},a.prototype.once=function(e,t){return c(t),this.on(e,p(this,e,t)),this},a.prototype.prependOnceListener=function(e,t){return c(t),this.prependListener(e,p(this,e,t)),this},a.prototype.removeListener=function(e,t){var r,n,i,o,s;if(c(t),void 0===(n=this._events))return this;if(void 0===(r=n[e]))return this;if(r===t||r.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(i=-1,o=r.length-1;o>=0;o--)if(r[o]===t||r[o].listener===t){s=r[o].listener,i=o;break}if(i<0)return this;0===i?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,i),1===r.length&&(n[e]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",e,s||t)}return this},a.prototype.off=a.prototype.removeListener,a.prototype.removeAllListeners=function(e){var t,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var i,o=Object.keys(r);for(n=0;n<o.length;++n)"removeListener"!==(i=o[n])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},a.prototype.listeners=function(e){return d(this,e,!0)},a.prototype.rawListeners=function(e){return d(this,e,!1)},a.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):y.call(e,t)},a.prototype.listenerCount=y,a.prototype.eventNames=function(){return this._eventsCount>0?n(this._events):[]}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.needsJsonStringify=void 0,t.needsJsonStringify=function(e){return"string"!=typeof e&&!(e instanceof Blob)}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ShortCache=void 0;const n=r(10);class i extends n.ForeverCache{constructor(e=3e4){super(),this.cacheTimeout=e,this.activeTimers=new Map}store(e){super.store(e),this.setTimer(e.uri)}setTimer(e){this.activeTimers.has(e)&&clearTimeout(this.activeTimers.get(e)),this.activeTimers.set(e,setTimeout(()=>{this.delete(e),this.activeTimers.delete(e)},this.cacheTimeout))}}t.ShortCache=i},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.NeverCache=void 0;t.NeverCache=class{store(e){}get(e){return null}has(e){return!1}delete(e){}clear(){}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(43);t.default=(e,t)=>{const r="Basic "+n.encode(e+":"+t);return(e,t)=>(e.headers.set("Authorization",r),t(e))}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.encode=void 0,t.encode=function(e){return btoa(e)}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=e=>{const t="Bearer "+e;return(e,r)=>(e.headers.set("Authorization",t),r(e))}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(46);t.default=e=>{const t=new n.OAuth2(e);return t.fetchMw.bind(t)}},function(e,t,r){window,e.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});class n extends Error{constructor(e,t,r){super(e),this.oauth2Code=t,this.httpCode=r}}t.default=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(2);t.default=n.default,t.fetchMwOAuth2=n.default,t.OAuth2=n.default;var i=r(0);t.OAuth2Error=i.default},function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(3),o=n(r(0)),s=r(4);async function a(e,t){return e.headers.set("Authorization","Bearer "+t),await fetch(e)}t.default=class{constructor(e){this.options=e,this.token={accessToken:e.accessToken||"",expiresAt:e.accessToken?null:0,refreshToken:e.refreshToken||null}}async fetch(e,t){const r=new Request(e,t);let n=await this.getAccessToken(),i=await a(r.clone(),n);return i.ok||401!==i.status||(n=await this.refreshToken(),i=await a(r,n)),i}async fetchMw(e,t){let r=await this.getAccessToken(),n=e.clone();n.headers.set("Authorization","Bearer "+r);let i=await t(n);return i.ok||401!==i.status||(r=await this.refreshToken(),n=e.clone(),n.headers.set("Authorization","Bearer "+r),i=await t(n)),i}async getOptions(){const e=await this.getToken();return{clientId:this.options.clientId,grantType:void 0,accessToken:e.accessToken,refreshToken:e.refreshToken||void 0,tokenEndpoint:this.options.tokenEndpoint}}async getToken(){return await this.getAccessToken(),this.token}async getAccessToken(){return null===this.token.expiresAt||this.token.expiresAt>Date.now()?this.token.accessToken:this.refreshToken()}async refreshToken(){let e;const t=this.token;if(t.refreshToken)e={grant_type:"refresh_token",refresh_token:t.refreshToken},this.options.clientSecret||(e.client_id=this.options.clientId);else switch(this.options.grantType){case"client_credentials":e={grant_type:"client_credentials"},this.options.scope&&(e.scope=this.options.scope.join(" "));break;case"password":e={grant_type:"password",username:this.options.userName,password:this.options.password},this.options.scope&&(e.scope=this.options.scope.join(" "));break;case"authorization_code":e={grant_type:"authorization_code",code:this.options.code,redirect_uri:this.options.redirectUri,client_id:this.options.clientId};break;default:throw new Error("Unknown grantType: "+this.options.grantType)}const r={"Content-Type":"application/x-www-form-urlencoded"};if(void 0!==this.options.clientSecret){const e=i.encode(this.options.clientId+":"+this.options.clientSecret);r.Authorization="Basic "+e}const n=await fetch(this.options.tokenEndpoint,{method:"POST",headers:r,body:s.objToQueryString(e)}),a=await n.json();if(!n.ok){if("refresh_token"===e.grant_type&&this.options.grantType)return this.token={accessToken:"",expiresAt:0,refreshToken:null},this.getAccessToken();let t="OAuth2 error "+a.error+".";throw a.error_description&&(t+=" "+a.error_description),new o.default(t,a.error,401)}return this.token={accessToken:a.access_token,expiresAt:a.expires_in?Date.now()+1e3*a.expires_in:null,refreshToken:a.refresh_token?a.refresh_token:null},this.options.onTokenUpdate&&this.options.onTokenUpdate(this.token),this.token.accessToken}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.encode=function(e){return btoa(e)}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.objToQueryString=function(e){return Object.entries(e).map(([e,t])=>void 0===t?"":encodeURIComponent(e)+"="+encodeURIComponent(t)).join("&")}}])},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0})}])}));
9//# sourceMappingURL=ketting.min.js.map
\No newline at end of file