UNPKG

30.6 kBJavaScriptView Raw
1var Ketting=function(e){var t={};function r(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,r),s.l=!0,s.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 s in e)r.d(n,s,function(t){return e[t]}.bind(null,s));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=7)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.resolve=function(e,t){if("undefined"!=typeof URL)return new URL(t,e).toString();const r=document,n=r.getElementsByTagName("base")[0],s=n&&n.href,o=r.head||r.getElementsByTagName("head")[0],i=n||o.appendChild(r.createElement("base")),u=r.createElement("a");i.href=e,u.href=t;const c=u.href;return n?n.href=s:o.removeChild(i),c},t.parse=function(e){return{host:new URL(e).host}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(10),s=r(0);t.default=class{constructor(e){this.templated=!1,this.title=null,this.type=null;for(const t of["context","href","name","rel","templated","title","type"])e[t]&&(this[t]=e[t])}resolve(){return s.resolve(this.context,this.href)}expand(e){if(this.templated){const t=n.parse(this.href).expand(e);return s.resolve(this.context,t)}return s.resolve(this.context,this.href)}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(e,t,r){this.uri=e,this.contentType=t,this.body=r,this.links=[],this.embedded={}}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(16),s=r(17),o=r(18),i=r(1),u=r(4),c=r(0);t.default=class{constructor(e,t,r=null){this.inFlightRefresh=null,this.client=e,this.uri=t,this.repr=null,this.contentType=r,this.preferPushRels=new Set}async get(){return(await this.representation()).body}async put(e){const t=this.contentType||this.client.contentTypes[0].mime,r={method:"PUT",body:JSON.stringify(e),headers:{"Content-Type":t,Accept:this.contentType?this.contentType:this.client.getAcceptHeader()}};await this.fetchAndThrow(r)}async delete(){await this.fetchAndThrow({method:"DELETE"})}async post(e){const t=this.contentType||this.client.contentTypes[0].mime,r=await this.fetchAndThrow({method:"POST",body:JSON.stringify(e),headers:{"Content-Type":t}});return r.headers.has("location")?this.go(r.headers.get("location")):null}async patch(e){await this.fetchAndThrow({method:"PATCH",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}})}async refresh(){let e,t;if(this.inFlightRefresh)[e,t]=await this.inFlightRefresh;else{const r={Accept:this.contentType?this.contentType:this.client.getAcceptHeader()};this.preferPushRels.size>0&&(r["Prefer-Push"]=Array.from(this.preferPushRels).join(" "),r.Prefer='transclude="'+Array.from(this.preferPushRels).join(";")+'"'),this.inFlightRefresh=this.fetchAndThrow({method:"GET",headers:r}).then(t=>(e=t).text()).then(r=>[e,t=r]);try{await this.inFlightRefresh}finally{this.inFlightRefresh=null}}const r=e.headers.get("Content-Type");if(!r)throw new Error("Server did not respond with a Content-Type header");this.repr=new(this.client.getRepresentor(r))(this.uri,r,t),this.contentType||(this.contentType=r);const s=e.headers.get("Link");if(s)for(const e of n.parse(s).refs)for(const t of e.rel.split(" "))this.repr.links.push(new i.default({rel:t,context:this.uri,href:e.uri}));for(const e of Object.keys(this.repr.embedded)){this.go(e).repr=new(this.client.getRepresentor(r))(e,r,this.repr.embedded[e])}return this.repr.body}async links(e){const t=await this.representation();return this.preferPushRels=new Set,e?t.links.filter(t=>t.rel===e):t.links}follow(e,t){return this.preferPushRels.add(e),new s.default(async(r,n)=>{try{const n=await this.links(e);let s;if(0===n.length)throw new Error("Relation with type "+e+" not found on resource "+this.uri);s=n[0].templated&&t?n[0].expand(t):n[0].resolve();const o=this.go(s);n[0].type&&(o.contentType=n[0].type),r(o)}catch(e){n(e)}})}async followAll(e){return this.preferPushRels.add(e),(await this.links(e)).map(e=>{const t=this.go(e.resolve());return e.type&&(t.contentType=e.type),t})}go(e){return e=c.resolve(this.uri,e),this.client.go(e)}async representation(){return this.repr||await this.refresh(),this.repr}clearCache(){this.repr=null}fetch(e,t){let r=null,n={};if(void 0===e)r=this.uri;else if("string"==typeof e)r=c.resolve(this.uri,e);else if(e instanceof Request)r=c.resolve(this.uri,e.url),n.method=e.method,n.headers=new Headers(e.headers),n.body=e.body,n.mode=e.mode,n.credentials=e.credentials,n.cache=e.cache,n.redirect=e.redirect,n.referrer=e.referrer,n.integrity=e.integrity;else{if(!(e instanceof Object))throw new TypeError("When specified, input must be a string, Request object or a key-value object");r=this.uri,n=e}if(t){for(const e of Object.keys(t))"headers"!==e&&(n[e]=t[e]);n.headers=u.mergeHeaders([n.headers,t.headers])}const s=new Request(r,n);return this.client.fetch(s)}async fetchAndThrow(e,t){const r=await this.fetch(e,t);if(r.ok)return r;throw await o.default(r)}}},function(e,t,r){"use strict";(function(e){Object.defineProperty(t,"__esModule",{value:!0});const n=r(20),s=r(24);r(6);const o=r(0);function i(e){const t=new Headers;for(const r of e)if(r instanceof Headers)for(const e of r.keys())t.set(e,r.get(e));else if(r)for(const e of Object.keys(r))t.set(e,r[e]);return t}t.default=class{constructor(t,r=null){this.options=t,this.oAuth2Buckets=new Map,this.innerFetch=fetch.bind(e),this.onBeforeRequest=r}fetch(e,t){const n=this.getDomainOptions("string"==typeof e?e:e.url),s=function(e){const t=i(e.map(e=>e?e.headers:null)),r=Object.assign({},...e);return r.headers=t,r}([this.options.fetchInit,n.fetchInit,t,{headers:e instanceof Request?e.headers:{}}]),o=new Request(e,s);return o.headers.has("User-Agent")||o.headers.set("User-Agent","Ketting/"+r(25).version),this.fetchAuth(o)}getDomainOptions(e){if(!this.options.match)return{fetchInit:this.options.fetchInit,auth:this.options.auth,authBucket:"*"};const{host:t}=o.parse(e);for(const[e,r]of Object.entries(this.options.match)){const n=e.split("*").map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("(.*)");if(new RegExp("^"+n+"$").test(t))return{fetchInit:r.fetchInit,auth:r.auth||this.options.auth,authBucket:e}}return{fetchInit:this.options.fetchInit,auth:this.options.auth,authBucket:"*"}}fetchAuth(e){const t=this.getDomainOptions(e.url),r=t.auth,o=t.authBucket;if(!r)return this.doFetch(e);switch(r.type){case"basic":return e.headers.set("Authorization","Basic "+s.encode(r.userName+":"+r.password)),this.doFetch(e);case"bearer":return e.headers.set("Authorization","Bearer "+r.token),this.doFetch(e);case"oauth2":return this.oAuth2Buckets.has(o)||this.oAuth2Buckets.set(o,new n.default(r)),this.onBeforeRequest&&this.onBeforeRequest(e),this.oAuth2Buckets.get(o).fetch(e)}}doFetch(e){return this.onBeforeRequest&&this.onBeforeRequest(e),this.innerFetch(e)}},t.mergeHeaders=i}).call(this,r(19))},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){},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(8);t.Ketting=n.default,t.default=n.default;var s=r(3);t.Resource=s.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(9),s=r(14),o=r(15),i=r(3),u=r(4);r(6);const c=r(0);t.default=class{constructor(e,t){void 0===t&&(t={}),this.resourceCache={},this.contentTypes=[{mime:"application/hal+json",representor:"hal",q:"1.0"},{mime:"application/vnd.api+json",representor:"jsonapi",q:"0.9"},{mime:"application/json",representor:"hal",q:"0.8"},{mime:"text/html",representor:"html",q:"0.7"}],this.bookMark=e,this.fetchHelper=new u.default(t,this.beforeRequest.bind(this))}follow(e,t){return this.getResource().follow(e,t)}go(e){return void 0===e&&(e=""),e=c.resolve(this.bookMark,e),this.resourceCache[e]||(this.resourceCache[e]=new i.default(this,e)),this.resourceCache[e]}getResource(e){return this.go(e)}fetch(e,t){return this.fetchHelper.fetch(e,t)}getRepresentor(e){-1!==e.indexOf(";")&&(e=e.split(";")[0]),e=e.trim();const t=this.contentTypes.find(t=>t.mime===e);if(!t)throw new Error("Could not find a representor for contentType: "+e);switch(t.representor){case"html":return s.default;case"hal":return n.default;case"jsonapi":return o.default;default:throw new Error("Unknown representor: "+t.representor)}}getAcceptHeader(){return this.contentTypes.map(e=>{let t=e.mime;return e.q&&(t+=";q="+e.q),t}).join(", ")}beforeRequest(e){["GET","HEAD","OPTIONS","PRI","PROPFIND","REPORT","SEARCH","TRACE"].includes(e.method)||e.url in this.resourceCache&&this.resourceCache[e.url].clearCache()}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(1),s=r(0),o=r(2);class i extends o.default{constructor(e,t,r){super(e,t,r),this.body="string"==typeof r?JSON.parse(r):r,void 0!==this.body._links&&u(this),void 0!==this.body._embedded&&a(this),delete this.body._links,delete this.body._embedded}}t.default=i;const u=e=>{for(const t of Object.keys(e.body._links)){let r=e.body._links[t];Array.isArray(r)||(r=[r]),c(e,t,r)}},c=(e,t,r)=>{for(const s of r)e.links.push(new n.default({rel:t,context:e.uri,href:s.href,title:s.title,type:s.type,templated:s.templated,name:s.name}))},a=e=>{for(const t of Object.keys(e.body._embedded)){let r=e.body._embedded[t];Array.isArray(r)||(r=[r]);for(const o of r){const r=s.resolve(e.uri,o._links.self.href);e.links.find(e=>e.rel===t&&o._links.self.href===e.href)||e.links.push(new n.default({rel:t,context:e.uri,href:o._links.self.href})),e.embedded[r]=o}}}},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 s={uriTemplate:function(){var e,t,r;r=o,e=[],null===(t=m())&&(t=l());for(;null!==t;)e.push(t),null===(t=m())&&(t=l());null!==e&&(e=new x(e));null===e&&(o=r);return e},expression:l,op:h,pathExpression:function(){var e;"{/"===t.substr(o,2)?(e="{/",o+=2):(e=null,0===i&&a('"{/"'));return e},paramList:p,param:f,cut:d,listMarker:y,substr:g,nonexpression:m,extension:w};if(void 0!==n){if(void 0===s[n])throw new Error("Invalid rule name: "+e(n)+".")}else n="uriTemplate";var o=0,i=0,u=0,c=[];function a(e){o<u||(o>u&&(u=o,c=[]),c.push(e))}function l(){var e,r,n,s,u,c,l,f;return u=o,c=o,123===t.charCodeAt(o)?(e="{",o++):(e=null,0===i&&a('"{"')),null!==e&&null!==(r=h())&&null!==(n=p())?(125===t.charCodeAt(o)?(s="}",o++):(s=null,0===i&&a('"}"')),null!==s?e=[e,r,n,s]:(e=null,o=c)):(e=null,o=c),null!==e&&(l=e[1],f=e[2],e=_(l,f)),null===e&&(o=u),e}function h(){var e;return/^[\/;:.?&+#]/.test(t.charAt(o))?(e=t.charAt(o),o++):(e=null,0===i&&a("[\\/;:.?&+#]")),null===e&&(e=""),e}function p(){var e,r,n,s,u,c,l,h,p,d;if(u=o,c=o,null!==(e=f())){for(r=[],l=o,h=o,44===t.charCodeAt(o)?(n=",",o++):(n=null,0===i&&a('","')),null!==n&&null!==(s=f())?n=[n,s]:(n=null,o=h),null!==n&&(n=n[1]),null===n&&(o=l);null!==n;)r.push(n),l=o,h=o,44===t.charCodeAt(o)?(n=",",o++):(n=null,0===i&&a('","')),null!==n&&null!==(s=f())?n=[n,s]:(n=null,o=h),null!==n&&(n=function(e,t){return t}(0,n[1])),null===n&&(o=l);null!==r?e=[e,r]:(e=null,o=c)}else e=null,o=c;return null!==e&&(p=e[0],(d=e[1]).unshift(p),e=d),null===e&&(o=u),e}function f(){var e,r,n,s,u,c,l,h;for(s=o,u=o,e=[],/^[a-zA-Z0-9_.%]/.test(t.charAt(o))?(r=t.charAt(o),o++):(r=null,0===i&&a("[a-zA-Z0-9_.%]"));null!==r;)e.push(r),/^[a-zA-Z0-9_.%]/.test(t.charAt(o))?(r=t.charAt(o),o++):(r=null,0===i&&a("[a-zA-Z0-9_.%]"));return null!==e?(null===(r=d())&&(r=y()),null!==(r=null!==r?r:"")&&null!==(n=null!==(n=w())?n:"")?e=[e,r,n]:(e=null,o=u)):(e=null,o=u),null!==e&&(c=e[0],l=e[1],h=e[2],l=l||{},e={name:c.join(""),explode:l.listMarker,cut:l.cut,extended:h}),null===e&&(o=s),e}function d(){var e,t;return t=o,null!==(e=g())&&(e={cut:e}),null===e&&(o=t),e}function y(){var e,r;return r=o,42===t.charCodeAt(o)?(e="*",o++):(e=null,0===i&&a('"*"')),null!==e&&(e={listMarker:e}),null===e&&(o=r),e}function g(){var e,r,n,s,u,c;if(s=o,u=o,58===t.charCodeAt(o)?(e=":",o++):(e=null,0===i&&a('":"')),null!==e){if(/^[0-9]/.test(t.charAt(o))?(n=t.charAt(o),o++):(n=null,0===i&&a("[0-9]")),null!==n)for(r=[];null!==n;)r.push(n),/^[0-9]/.test(t.charAt(o))?(n=t.charAt(o),o++):(n=null,0===i&&a("[0-9]"));else r=null;null!==r?e=[e,r]:(e=null,o=u)}else e=null,o=u;return null!==e&&(c=e[1],e=parseInt(c.join(""))),null===e&&(o=s),e}function m(){var e,r,n;if(n=o,/^[^{]/.test(t.charAt(o))?(r=t.charAt(o),o++):(r=null,0===i&&a("[^{]")),null!==r)for(e=[];null!==r;)e.push(r),/^[^{]/.test(t.charAt(o))?(r=t.charAt(o),o++):(r=null,0===i&&a("[^{]"));else e=null;return null!==e&&(e=e.join("")),null===e&&(o=n),e}function w(){var e,r,n,s,u;if(s=o,u=o,40===t.charCodeAt(o)?(e="(",o++):(e=null,0===i&&a('"("')),null!==e){if(/^[^)]/.test(t.charAt(o))?(n=t.charAt(o),o++):(n=null,0===i&&a("[^)]")),null!==n)for(r=[];null!==n;)r.push(n),/^[^)]/.test(t.charAt(o))?(n=t.charAt(o),o++):(n=null,0===i&&a("[^)]"));else r=null;null!==r?(41===t.charCodeAt(o)?(n=")",o++):(n=null,0===i&&a('")"')),null!==n?e=[e,r,n]:(e=null,o=u)):(e=null,o=u)}else e=null,o=u;return null!==e&&(e=e[1].join("")),null===e&&(o=s),e}var b=r(11),x=b.Template,_=b.expression,k=s[n]();if(null===k||o!==t.length){var A=Math.max(o,u),v=A<t.length?t.charAt(A):null,T=function(){for(var e=1,r=1,n=!1,s=0;s<Math.max(o,u);s++){var i=t.charAt(s);"\n"===i?(n||e++,r=1,n=!1):"\r"===i||"\u2028"===i||"\u2029"===i?(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}(c),v,A,T.line,T.column)}return k},toSource:function(){return this._source},SyntaxError:function(t,r,n,s,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=s,this.column=o}};return t.SyntaxError.prototype=Error.prototype,t}()},function(e,t,r){(function(){var t,n,s,o,i,u,c,a,l,h,p,f=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};p=r(12),h=h=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}(),i=function(e){function t(){return this.explodeArray=f(this.explodeArray,this),this.stringifySingle=f(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=f(this.explodeObject,this),this.explodeArray=f(this.explodeArray,this),this._expandPair=f(this._expandPair,this),this.stringifySingle=f(this.stringifySingle,this),this.encode=f(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 p[this.allow](e)},t.prototype.stringifySingle=function(e,t){var r,n,s;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)s=t[r],e.push([r,s].map(this.encode).join(","));return e}.call(this).join(",")},t.prototype.expand=function(t){var r,n,s=this;return(n=(r=e(this.params,t)).map((function(e){return s._expandPair.apply(s,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,s,o,i;for(t in r=[],e)if(n=e[t],t=this.encode(t),Array.isArray(n))for(o=0,i=n.length;o<i;o++)s=n[o],r.push([t,this.encode(s)]);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}()),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return y(t,e),t.prototype.encode=function(e){return p["U+R"](e)},t.prototype.toString=function(){return"{+"+t.__super__.toString.apply(this,arguments).substring(1)},t}(l),s=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 p["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),c=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return y(t,e),t.prototype.first="/",t.prototype.sep="/",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}(i),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}(i),t=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return y(t,e),t.prototype.first="&",t}(n),e.exports={Template:h,SimpleExpression:l,NamedExpression:i,ReservedExpression:a,FragmentExpression:s,LabelExpression:o,PathSegmentExpression:c,PathParamExpression:u,FormStartExpression:n,FormContinuationExpression:t,expression:function(e,r){return new(function(){switch(e){case"":return l;case"+":return a;case"#":return s;case".":return o;case"/":return c;case";":return u;case"?":return n;case"&":return t}}())(r)}}}).call(this)},function(e,t,r){(function(){var e;e=r(13),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";Object.defineProperty(t,"__esModule",{value:!0});const n=r(1),s=r(2);class o extends s.default{constructor(e,t,r){super(e,t,r);const n=(new DOMParser).parseFromString(r,"text/html");i(this,n.getElementsByTagName("link")),i(this,n.getElementsByTagName("a"))}}function i(e,t){for(const r of t){const t=r.getAttribute("rel"),s=r.getAttribute("href"),o=r.getAttribute("type")||void 0;if(t&&s)for(const r of t.split(" ")){const t=new n.default({rel:r,context:e.uri,href:s,type:o});e.links.push(t)}}}t.default=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(1),s=r(2);class o extends s.default{constructor(e,t,r){super(e,t,r),this.body="string"==typeof r?JSON.parse(r):r,this.links=[...i(e,this.body),...u(e,this.body)]}}function i(e,t){const r=[];if(void 0===t.links)return r;for(const[n,s]of Object.entries(t.links))Array.isArray(s)?r.push(...s.map(t=>c(e,n,t))):r.push(c(e,n,s));return r}function u(e,t){if(!Array.isArray(t.data))return[];const r=[];for(const s of t.data)if("self"in s.links){const t=c(e,"self",s.links.self);r.push(new n.default({context:e,href:t.href,rel:"item"}))}return r}function c(e,t,r){return new n.default({context:e,rel:t,href:"string"==typeof r?r:r.href})}t.default=o},function(e,t,r){"use strict";var n=/^utf-?8|ascii|utf-?16-?le|ucs-?2|base-?64|latin-?1$/i,s=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,o=/\s|\uFEFF|\xA0/,i=/\r?\n[\x20\x09]+/g,u=/[;,"]/,c=/[;,"]|\s/,a={IDLE:1,URI:2,ATTR:4};function l(e){return e.replace(s,"")}function h(e){return o.test(e)}function p(e,t){for(;h(e[t]);)t++;return t}function f(e){return c.test(e)}class d{constructor(e){this.refs=[],e&&this.parse(e)}rel(e){for(var t=[],r=0;r<this.refs.length;r++)this.refs[r].rel===e&&t.push(this.refs[r]);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=l(e=(t=t||0)?e.slice(t):e).replace(i,"");for(var r=a.IDLE,n=e.length,s=(t=0,null);t<n;)if(r===a.IDLE){if(h(e[t])){t++;continue}if("<"!==e[t])throw new Error('Unexpected character "'+e[t]+'" at offset '+t);if(-1===(f=e.indexOf(">",t)))throw new Error("Expected end of URI delimiter at offset "+t);s={uri:e.slice(t+1,f)},this.refs.push(s),t=f,r=a.URI,t++}else if(r===a.URI){if(h(e[t])){t++;continue}if(";"===e[t])r=a.ATTR,t++;else{if(","!==e[t])throw new Error('Unexpected character "'+e[t]+'" at offset '+t);r=a.IDLE,t++}}else{if(r!==a.ATTR)throw new Error('Unknown parser state "'+r+'"');if(";"===e[t]||h(e[t])){t++;continue}if(-1===(f=e.indexOf("=",t)))throw new Error("Expected attribute delimiter at offset "+t);var o=l(e.slice(t,f)).toLowerCase(),c="";if('"'===e[t=p(e,t=f+1)])for(t++;t<n;){if('"'===e[t]){t++;break}"\\"===e[t]&&t++,c+=e[t],t++}else{for(var f=t+1;!u.test(e[f])&&f<n;)f++;c=e.slice(t,f),t=f}switch(s[o]&&d.isSingleOccurenceAttr(o)||("*"===o[o.length-1]?s[o]=d.parseExtendedValue(c):(c="rel"===o||"type"===o?c.toLowerCase():c,null!=s[o]?Array.isArray(s[o])?s[o].push(c):s[o]=[s[o],c]:s[o]=c)),e[t]){case",":r=a.IDLE;break;case";":r=a.ATTR}t++}return s=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+"; "+d.formatAttribute(t,r[t])}),"<"+r.uri+">"),e.push(t);return e.join(", ")}}d.isCompatibleEncoding=function(e){return n.test(e)},d.parse=function(e,t){return(new d).parse(e,t)},d.isSingleOccurenceAttr=function(e){return"rel"===e||"type"===e||"media"===e||"title"===e||"title*"===e},d.isTokenAttr=function(e){return"rel"===e||"type"===e||"anchor"===e},d.escapeQuotes=function(e){return e.replace(/"/g,'\\"')},d.parseExtendedValue=function(e){var t=/([^']+)?(?:'([^']+)')?(.+)/.exec(e);return{language:t[2].toLowerCase(),encoding:d.isCompatibleEncoding(t[1])?null:t[1].toLowerCase(),value:d.isCompatibleEncoding(t[1])?decodeURIComponent(t[3]):t[3]}},d.formatExtendedAttribute=function(e,t){var r=(t.encoding||"utf-8").toUpperCase();return e+"="+r+"'"+(t.language||"en")+"'"+(Buffer.isBuffer(t.value)&&d.isCompatibleEncoding(r)?t.value.toString(r):Buffer.isBuffer(t.value)?t.value.toString("hex").replace(/[0-9a-f]{2}/gi,"%$1"):encodeURIComponent(t.value))},d.formatAttribute=function(e,t){return Array.isArray(t)?t.map(t=>d.formatAttribute(e,t)).join("; "):"*"===e[e.length-1]||"string"!=typeof t?d.formatExtendedAttribute(e,t):(d.isTokenAttr(e)?t=f(t)?'"'+d.escapeQuotes(t)+'"':d.escapeQuotes(t):f(t)&&(t='"'+(t=(t=encodeURIComponent(t)).replace(/%20/g," ").replace(/%2C/g,",").replace(/%3B/g,";"))+'"'),e+"="+t)},e.exports=d},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});class n{constructor(e){this.realPromise=new Promise(e)}then(e,t){return this.realPromise.then(e,t)}catch(e){return this.realPromise.catch(e)}follow(e,t){return new n((r,n)=>{this.realPromise.then(n=>{r(n.follow(e,t))}).catch(e=>{n(e)})})}followAll(e){return this.realPromise.then(t=>t.followAll(e))}}t.default=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});class n extends Error{constructor(e){super("HTTP error "+e.status),this.response=e,this.status=e.status}}t.HttpError=n;class s extends n{constructor(e,t){super(e),this.body=t,this.body.title&&(this.message="HTTP Error "+this.status+": "+this.body.title)}}t.Problem=s,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 s(e,t)}return new n(e)}},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";Object.defineProperty(t,"__esModule",{value:!0});var n=r(21);t.default=n.default,t.fetchMwOAuth2=n.default,t.OAuth2=n.default;var s=r(5);t.OAuth2Error=s.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 s=r(22),o=n(r(5)),i=r(23);async function u(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(),s=await u(r.clone(),n);return s.ok||401!==s.status||(n=await this.refreshToken(),s=await u(r,n)),s}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=s.encode(this.options.clientId+":"+this.options.clientSecret);r.Authorization="Basic "+e}const n=await fetch(this.options.tokenEndpoint,{method:"POST",headers:r,body:i.objToQueryString(e)}),u=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 "+u.error+".";throw u.error_description&&(t+=" "+u.error_description),new o.default(t,u.error,n.status)}return this.token={accessToken:u.access_token,expiresAt:u.expires_in?Date.now()+1e3*u.expires_in:null,refreshToken:u.refresh_token?u.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}),t.encode=function(e){return btoa(e)}},function(e){e.exports=JSON.parse('{"name":"ketting","version":"4.0.4","description":"Opiniated HATEAOS / Rest client.","main":"dist/index.js","scripts":{"test":"make test","prepublishOnly":"make build","build":"make build"},"repository":{"type":"git","url":"git+https://github.com/evert/ketting.git"},"keywords":["rest","hypermedia","client","http","hateoas","hal"],"author":"Evert Pot","license":"MIT","bugs":{"url":"https://github.com/evert/ketting/issues"},"homepage":"https://github.com/evert/ketting#readme","files":["src/","dist/","browser/ketting.min.js","browser/ketting.min.js.map"],"types":"dist/index.d.ts","dependencies":{"fetch-mw-oauth2":"^0.3.4","http-link-header":"^1.0.2","node-fetch":"^2.6.0","querystring-browser":"^1.0.4","sax":"^1.2.4","uri-template":"^1.0.1"},"devDependencies":{"@types/chai":"^4.2.1","@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":"^5.2.7","@types/node":"^12.7.3","@types/node-fetch":"^2.5.0","@types/sax":"^1.2.0","awesome-typescript-loader":"^5.2.1","chai":"^4.2.0","koa":"^2.8.1","koa-bodyparser":"^4.2.1","koa-logger":"^3.2.1","koa-path-match":"^2.0.0","koa-static":"^5.0.0","mocha":"^6.2.0","nyc":"^14.1.1","ts-node":"^8.3.0","tslint":"^5.19.0","typescript":"^3.6.2","webpack":"^4.39.3","webpack-cli":"^3.3.7"},"nyc":{"extension":[".ts"]}}')}]);
2//# sourceMappingURL=ketting.min.js.map
\No newline at end of file