Socket
Socket
Sign inDemoInstall

@commercetools/sdk-middleware-auth

Package Overview
Dependencies
Maintainers
15
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercetools/sdk-middleware-auth - npm Package Compare versions

Comparing version 6.2.1 to 7.0.0

6

CHANGELOG.md
# @commercetools/sdk-middleware-auth
## 7.0.0
### Major Changes
- [#1775](https://github.com/commercetools/nodejs/pull/1775) [`35669f30`](https://github.com/commercetools/nodejs/commit/35669f30dbc4b24d59ec3df3f38417b1f2a77837) Thanks [@ajimae](https://github.com/ajimae)! - Drop support for Node `v10` and `v12`. Supported versions now are `v14`, `v16` and `v18`.
## 6.2.1

@@ -4,0 +10,0 @@

30

dist/sdk-middleware-auth.cjs.js

@@ -10,10 +10,5 @@ 'use strict';

var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
enumerableOnly && (symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
})), keys.push.apply(keys, symbols);
}

@@ -26,15 +21,8 @@

for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}

@@ -41,0 +29,0 @@

@@ -6,10 +6,5 @@ function ownKeys(object, enumerableOnly) {

var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
enumerableOnly && (symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
})), keys.push.apply(keys, symbols);
}

@@ -22,15 +17,8 @@

for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}

@@ -37,0 +25,0 @@

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).CommercetoolsSdkMiddlewareAuth={})}(this,function(t){"use strict";function e(e,t){var r,n=Object.keys(e);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(e),t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)),n}function w(o){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?e(Object(i),!0).forEach(function(t){var e,r,n;e=o,n=i[r=t],r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(i)):e(Object(i)).forEach(function(t){Object.defineProperty(o,t,Object.getOwnPropertyDescriptor(i,t))})}return o}var r="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},u=[],h=[],f="undefined"!=typeof Uint8Array?Uint8Array:Array,c=!1;function l(){c=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0,r=t.length;e<r;++e)u[e]=t[e],h[t.charCodeAt(e)]=e;h["-".charCodeAt(0)]=62,h["_".charCodeAt(0)]=63}function p(t,e,r){for(var n,o,i=[],s=e;s<r;s+=3)n=(t[s]<<16)+(t[s+1]<<8)+t[s+2],i.push(u[(o=n)>>18&63]+u[o>>12&63]+u[o>>6&63]+u[63&o]);return i.join("")}function a(t){var e;c||l();for(var r=t.length,n=r%3,o="",i=[],s=0,a=r-n;s<a;s+=16383)i.push(p(t,s,a<s+16383?a:s+16383));return 1==n?(e=t[r-1],o+=u[e>>2],o+=u[e<<4&63],o+="=="):2==n&&(e=(t[r-2]<<8)+t[r-1],o+=u[e>>10],o+=u[e>>4&63],o+=u[e<<2&63],o+="="),i.push(o),i.join("")}function n(t,e,r,n,o){var i,s,a=8*o-n-1,u=(1<<a)-1,h=u>>1,f=-7,c=r?o-1:0,l=r?-1:1,p=t[e+c];for(c+=l,i=p&(1<<-f)-1,p>>=-f,f+=a;0<f;i=256*i+t[e+c],c+=l,f-=8);for(s=i&(1<<-f)-1,i>>=-f,f+=n;0<f;s=256*s+t[e+c],c+=l,f-=8);if(0===i)i=1-h;else{if(i===u)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),i-=h}return(p?-1:1)*s*Math.pow(2,i-n)}function i(t,e,r,n,o,i){var s,a,u,h=8*i-o-1,f=(1<<h)-1,c=f>>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,g=n?1:-1,d=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=f):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),2<=(e+=1<=s+c?l/u:l*Math.pow(2,1-c))*u&&(s++,u/=2),f<=s+c?(a=0,s=f):1<=s+c?(a=(e*u-1)*Math.pow(2,o),s+=c):(a=e*Math.pow(2,c-1)*Math.pow(2,o),s=0));8<=o;t[r+p]=255&a,p+=g,a/=256,o-=8);for(s=s<<o|a,h+=o;0<h;t[r+p]=255&s,p+=g,s/=256,h-=8);t[r+p-g]|=128*d}var o={}.toString,s=Array.isArray||function(t){return"[object Array]"==o.call(t)};function g(){return _.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function d(t,e){if(g()<e)throw new RangeError("Invalid typed array length");return _.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=_.prototype:(null===t&&(t=new _(e)),t.length=e),t}function _(t,e,r){if(!(_.TYPED_ARRAY_SUPPORT||this instanceof _))return new _(t,e,r);if("number"!=typeof t)return y(this,t,e,r);if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return E(this,t)}function y(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,r,n){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");e=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n);_.TYPED_ARRAY_SUPPORT?(t=e).__proto__=_.prototype:t=b(t,e);return t}(t,e,r,n):"string"==typeof e?function(t,e,r){"string"==typeof r&&""!==r||(r="utf8");if(!_.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|R(e,r),o=(t=d(t,n)).write(e,r);o!==n&&(t=t.slice(0,o));return t}(t,e,r):function(t,e){if(m(e)){var r=0|A(e.length);return 0===(t=d(t,r)).length?t:(e.copy(t,0,0,r),t)}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||function(t){return t!=t}(e.length)?d(t,0):b(t,e);if("Buffer"===e.type&&s(e.data))return b(t,e.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function v(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function E(t,e){if(v(e),t=d(t,e<0?0:0|A(e)),!_.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function b(t,e){var r=e.length<0?0:0|A(e.length);t=d(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function A(t){if(t>=g())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+g().toString(16)+" bytes");return 0|t}function m(t){return null!=t&&t._isBuffer}function R(t,e){if(m(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return N(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return z(t).length;default:if(n)return N(t).length;e=(""+e).toLowerCase(),n=!0}}function T(t,e,r){var n,o,i,s=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t=t||"utf8";;)switch(t){case"hex":return function(t,e,r){var n=t.length;(!e||e<0)&&(e=0);(!r||r<0||n<r)&&(r=n);for(var o="",i=e;i<r;++i)o+=function(t){return t<16?"0"+t.toString(16):t.toString(16)}(t[i]);return o}(this,e,r);case"utf8":case"utf-8":return k(this,e,r);case"ascii":return function(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(127&t[o]);return n}(this,e,r);case"latin1":case"binary":return function(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(t[o]);return n}(this,e,r);case"base64":return n=this,i=r,0===(o=e)&&i===n.length?a(n):a(n.slice(o,i));case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return function(t,e,r){for(var n=t.slice(e,r),o="",i=0;i<n.length;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}(this,e,r);default:if(s)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),s=!0}}function P(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function S(t,e,r,n,o){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):2147483647<r?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=o?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(o)return-1;r=t.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof e&&(e=_.from(e,n)),m(e))return 0===e.length?-1:C(t,e,r,n,o);if("number"==typeof e)return e&=255,_.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):C(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function C(t,e,r,n,o){var i=1,s=t.length,a=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s/=i=2,a/=2,r/=2}function u(t,e){return 1===i?t[e]:t.readUInt16BE(e*i)}if(o)for(var h=-1,f=r;f<s;f++)if(u(t,f)===u(e,-1===h?0:f-h)){if(-1===h&&(h=f),f-h+1===a)return h*i}else-1!==h&&(f-=f-h),h=-1;else for(s<r+a&&(r=s-a),f=r;0<=f;f--){for(var c=!0,l=0;l<a;l++)if(u(t,f+l)!==u(e,l)){c=!1;break}if(c)return f}return-1}function M(t,e,r,n){return K(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function U(t,e,r,n){return K(function(t,e){for(var r,n,o,i=[],s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}(e,t.length-r),t,r,n)}function k(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o<r;){var i,s,a,u,h=t[o],f=null,c=239<h?4:223<h?3:191<h?2:1;if(o+c<=r)switch(c){case 1:h<128&&(f=h);break;case 2:128==(192&(i=t[o+1]))&&127<(u=(31&h)<<6|63&i)&&(f=u);break;case 3:i=t[o+1],s=t[o+2],128==(192&i)&&128==(192&s)&&2047<(u=(15&h)<<12|(63&i)<<6|63&s)&&(u<55296||57343<u)&&(f=u);break;case 4:i=t[o+1],s=t[o+2],a=t[o+3],128==(192&i)&&128==(192&s)&&128==(192&a)&&65535<(u=(15&h)<<18|(63&i)<<12|(63&s)<<6|63&a)&&u<1114112&&(f=u)}null===f?(f=65533,c=1):65535<f&&(f-=65536,n.push(f>>>10&1023|55296),f=56320|1023&f),n.push(f),o+=c}return function(t){var e=t.length;if(e<=O)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=O));return r}(n)}_.TYPED_ARRAY_SUPPORT=void 0===r.TYPED_ARRAY_SUPPORT||r.TYPED_ARRAY_SUPPORT,_.poolSize=8192,_._augment=function(t){return t.__proto__=_.prototype,t},_.from=function(t,e,r){return y(null,t,e,r)},_.TYPED_ARRAY_SUPPORT&&(_.prototype.__proto__=Uint8Array.prototype,_.__proto__=Uint8Array),_.alloc=function(t,e,r){return n=null,i=e,s=r,v(o=t),!(o<=0)&&void 0!==i?"string"==typeof s?d(n,o).fill(i,s):d(n,o).fill(i):d(n,o);var n,o,i,s},_.allocUnsafe=function(t){return E(null,t)},_.allocUnsafeSlow=function(t){return E(null,t)},_.isBuffer=function(t){return null!=t&&(!!t._isBuffer||F(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&F(t.slice(0,0))}(t))},_.compare=function(t,e){if(!m(t)||!m(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,o=0,i=Math.min(r,n);o<i;++o)if(t[o]!==e[o]){r=t[o],n=e[o];break}return r<n?-1:n<r?1:0},_.isEncoding=function(t){switch(String(t).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}},_.concat=function(t,e){if(!s(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return _.alloc(0);if(void 0===e)for(o=e=0;o<t.length;++o)e+=t[o].length;for(var r=_.allocUnsafe(e),n=0,o=0;o<t.length;++o){var i=t[o];if(!m(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(r,n),n+=i.length}return r},_.byteLength=R,_.prototype._isBuffer=!0,_.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)P(this,e,e+1);return this},_.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)P(this,e,e+3),P(this,e+1,e+2);return this},_.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)P(this,e,e+7),P(this,e+1,e+6),P(this,e+2,e+5),P(this,e+3,e+4);return this},_.prototype.toString=function(){var t=0|this.length;return 0==t?"":0===arguments.length?k(this,0,t):T.apply(this,arguments)},_.prototype.equals=function(t){if(!m(t))throw new TypeError("Argument must be a Buffer");return this===t||0===_.compare(this,t)},_.prototype.inspect=function(){var t="";return 0<this.length&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),50<this.length&&(t+=" ... ")),"<Buffer "+t+">"},_.prototype.compare=function(t,e,r,n,o){if(!m(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),e<0||r>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(o<=n&&r<=e)return 0;if(o<=n)return-1;if(r<=e)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0),a=Math.min(i,s),u=this.slice(n,o),h=t.slice(e,r),f=0;f<a;++f)if(u[f]!==h[f]){i=u[f],s=h[f];break}return i<s?-1:s<i?1:0},_.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},_.prototype.indexOf=function(t,e,r){return S(this,t,e,r,!0)},_.prototype.lastIndexOf=function(t,e,r){return S(this,t,e,r,!1)},_.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-e;if((void 0===r||o<r)&&(r=o),0<t.length&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n=n||"utf8";for(var i,s,a,u,h,f,c=!1;;)switch(n){case"hex":return function(t,e,r,n){r=Number(r)||0;var o=t.length-r;(!n||o<(n=Number(n)))&&(n=o);var i=e.length;if(i%2!=0)throw new TypeError("Invalid hex string");i/2<n&&(n=i/2);for(var s=0;s<n;++s){var a=parseInt(e.substr(2*s,2),16);if(isNaN(a))return s;t[r+s]=a}return s}(this,t,e,r);case"utf8":case"utf-8":return h=e,f=r,K(N(t,(u=this).length-h),u,h,f);case"ascii":return M(this,t,e,r);case"latin1":case"binary":return M(this,t,e,r);case"base64":return i=this,s=e,a=r,K(z(t),i,s,a);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,t,e,r);default:if(c)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),c=!0}},_.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var O=4096;function I(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(r<t+e)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,r,n,o,i){if(!m(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(o<e||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function Y(t,e,r,n){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-r,2);o<i;++o)t[r+o]=(e&255<<8*(n?o:1-o))>>>8*(n?o:1-o)}function j(t,e,r,n){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-r,4);o<i;++o)t[r+o]=e>>>8*(n?o:3-o)&255}function q(t,e,r,n){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function D(t,e,r,n,o){return o||q(t,0,r,4),i(t,e,r,n,23,4),r+4}function x(t,e,r,n,o){return o||q(t,0,r,8),i(t,e,r,n,52,8),r+8}_.prototype.slice=function(t,e){var r=this.length;if((t=~~t)<0?(t+=r)<0&&(t=0):r<t&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):r<e&&(e=r),e<t&&(e=t),_.TYPED_ARRAY_SUPPORT)(o=this.subarray(t,e)).__proto__=_.prototype;else for(var n=e-t,o=new _(n,void 0),i=0;i<n;++i)o[i]=this[i+t];return o},_.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||I(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n},_.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||I(t,e,this.length);for(var n=this[t+--e],o=1;0<e&&(o*=256);)n+=this[t+--e]*o;return n},_.prototype.readUInt8=function(t,e){return e||I(t,1,this.length),this[t]},_.prototype.readUInt16LE=function(t,e){return e||I(t,2,this.length),this[t]|this[t+1]<<8},_.prototype.readUInt16BE=function(t,e){return e||I(t,2,this.length),this[t]<<8|this[t+1]},_.prototype.readUInt32LE=function(t,e){return e||I(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},_.prototype.readUInt32BE=function(t,e){return e||I(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},_.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||I(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return(o*=128)<=n&&(n-=Math.pow(2,8*e)),n},_.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||I(t,e,this.length);for(var n=e,o=1,i=this[t+--n];0<n&&(o*=256);)i+=this[t+--n]*o;return(o*=128)<=i&&(i-=Math.pow(2,8*e)),i},_.prototype.readInt8=function(t,e){return e||I(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},_.prototype.readInt16LE=function(t,e){e||I(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},_.prototype.readInt16BE=function(t,e){e||I(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},_.prototype.readInt32LE=function(t,e){return e||I(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},_.prototype.readInt32BE=function(t,e){return e||I(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},_.prototype.readFloatLE=function(t,e){return e||I(t,4,this.length),n(this,t,!0,23,4)},_.prototype.readFloatBE=function(t,e){return e||I(t,4,this.length),n(this,t,!1,23,4)},_.prototype.readDoubleLE=function(t,e){return e||I(t,8,this.length),n(this,t,!0,52,8)},_.prototype.readDoubleBE=function(t,e){return e||I(t,8,this.length),n(this,t,!1,52,8)},_.prototype.writeUIntLE=function(t,e,r,n){t=+t,e|=0,r|=0,n||B(this,t,e,r,Math.pow(2,8*r)-1,0);var o=1,i=0;for(this[e]=255&t;++i<r&&(o*=256);)this[e+i]=t/o&255;return e+r},_.prototype.writeUIntBE=function(t,e,r,n){t=+t,e|=0,r|=0,n||B(this,t,e,r,Math.pow(2,8*r)-1,0);var o=r-1,i=1;for(this[e+o]=255&t;0<=--o&&(i*=256);)this[e+o]=t/i&255;return e+r},_.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,1,255,0),_.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},_.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,65535,0),_.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):Y(this,t,e,!0),e+2},_.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,65535,0),_.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):Y(this,t,e,!1),e+2},_.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,4294967295,0),_.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):j(this,t,e,!0),e+4},_.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,4294967295,0),_.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):j(this,t,e,!1),e+4},_.prototype.writeIntLE=function(t,e,r,n){var o;t=+t,e|=0,n||B(this,t,e,r,(o=Math.pow(2,8*r-1))-1,-o);var i=0,s=1,a=0;for(this[e]=255&t;++i<r&&(s*=256);)t<0&&0===a&&0!==this[e+i-1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+r},_.prototype.writeIntBE=function(t,e,r,n){var o;t=+t,e|=0,n||B(this,t,e,r,(o=Math.pow(2,8*r-1))-1,-o);var i=r-1,s=1,a=0;for(this[e+i]=255&t;0<=--i&&(s*=256);)t<0&&0===a&&0!==this[e+i+1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+r},_.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,1,127,-128),_.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},_.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,32767,-32768),_.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):Y(this,t,e,!0),e+2},_.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,32767,-32768),_.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):Y(this,t,e,!1),e+2},_.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,2147483647,-2147483648),_.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):j(this,t,e,!0),e+4},_.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),_.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):j(this,t,e,!1),e+4},_.prototype.writeFloatLE=function(t,e,r){return D(this,t,e,!0,r)},_.prototype.writeFloatBE=function(t,e,r){return D(this,t,e,!1,r)},_.prototype.writeDoubleLE=function(t,e,r){return x(this,t,e,!0,r)},_.prototype.writeDoubleBE=function(t,e,r){return x(this,t,e,!1,r)},_.prototype.copy=function(t,e,r,n){if(r=r||0,n||0===n||(n=this.length),e>=t.length&&(e=t.length),e=e||0,0<n&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<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),t.length-e<n-r&&(n=t.length-e+r);var o,i=n-r;if(this===t&&r<e&&e<n)for(o=i-1;0<=o;--o)t[o+e]=this[o+r];else if(i<1e3||!_.TYPED_ARRAY_SUPPORT)for(o=0;o<i;++o)t[o+e]=this[o+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+i),e);return i},_.prototype.fill=function(t,e,r,n){if("string"==typeof t){var o;if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1!==t.length||(o=t.charCodeAt(0))<256&&(t=o),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!_.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;if(e>>>=0,r=void 0===r?this.length:r>>>0,"number"==typeof(t=t||0))for(a=e;a<r;++a)this[a]=t;else for(var i=m(t)?t:N(new _(t,n).toString()),s=i.length,a=0;a<r-e;++a)this[a+e]=i[a%s];return this};var L=/[^+\/0-9A-Za-z-_]/g;function N(t,e){var r;e=e||1/0;for(var n=t.length,o=null,i=[],s=0;s<n;++s){if(55295<(r=t.charCodeAt(s))&&r<57344){if(!o){if(56319<r){-1<(e-=3)&&i.push(239,191,189);continue}if(s+1===n){-1<(e-=3)&&i.push(239,191,189);continue}o=r;continue}if(r<56320){-1<(e-=3)&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&-1<(e-=3)&&i.push(239,191,189);if(o=null,r<128){if(--e<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function z(t){return function(t){var e,r,n,o;c||l();var i=t.length;if(0<i%4)throw new Error("Invalid string. Length must be a multiple of 4");n="="===t[i-2]?2:"="===t[i-1]?1:0,o=new f(3*i/4-n),e=0<n?i-4:i;for(var s=0,a=0;a<e;a+=4,0)r=h[t.charCodeAt(a)]<<18|h[t.charCodeAt(a+1)]<<12|h[t.charCodeAt(a+2)]<<6|h[t.charCodeAt(a+3)],o[s++]=r>>16&255,o[s++]=r>>8&255,o[s++]=255&r;return 2==n?(r=h[t.charCodeAt(a)]<<2|h[t.charCodeAt(a+1)]>>4,o[s++]=255&r):1==n&&(r=h[t.charCodeAt(a)]<<10|h[t.charCodeAt(a+1)]<<4|h[t.charCodeAt(a+2)]>>2,o[s++]=r>>8&255,o[s++]=255&r),o}(function(t){var e;if((t=((e=t).trim?e.trim():e.replace(/^\s+|\s+$/g,"")).replace(L,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function K(t,e,r,n){for(var o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}function F(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}function G(t){if(!t)throw new Error("Missing required options");if(!t.host)throw new Error("Missing required option (host)");if(!t.projectKey)throw new Error("Missing required option (projectKey)");if(!t.credentials)throw new Error("Missing required option (credentials)");var e=t.credentials,r=e.clientId,n=e.clientSecret;if(!r||!n)throw new Error("Missing required credentials (clientId, clientSecret)");var o=t.scopes?t.scopes.join(" "):void 0,i=_.from("".concat(r,":").concat(n)).toString("base64"),s=t.oauthUri||"/oauth/token";return{basicAuth:i,url:t.host.replace(/\/$/,"")+s,body:"grant_type=client_credentials".concat(o?"&scope=".concat(o):"")}}function V(t){if(!t)throw new Error("Missing required options");if(!t.host)throw new Error("Missing required option (host)");if(!t.projectKey)throw new Error("Missing required option (projectKey)");if(!t.credentials)throw new Error("Missing required option (credentials)");if(!t.refreshToken)throw new Error("Missing required option (refreshToken)");var e=t.credentials,r=e.clientId,n=e.clientSecret;if(!r||!n)throw new Error("Missing required credentials (clientId, clientSecret)");var o=_.from("".concat(r,":").concat(n)).toString("base64"),i=t.oauthUri||"/oauth/token";return{basicAuth:o,url:t.host.replace(/\/$/,"")+i,body:"grant_type=refresh_token&refresh_token=".concat(encodeURIComponent(t.refreshToken))}}function W(t,e){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.status=this.statusCode=this.code=t,this.message=e,Object.assign(this,r),this.name=this.constructor.name,this.constructor.prototype.__proto__=Error.prototype,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}function J(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];W.call.apply(W,[this,0].concat(e))}function $(t,e){return w(w({},e),{},{headers:w(w({},e.headers),{},{Authorization:"Bearer ".concat(t)})})}function Z(t){var n=t.fetcher,i=t.url,s=t.basicAuth,a=t.body,u=t.request,h=t.tokenCache,f=t.requestState,c=t.pendingTasks,l=t.response,p=t.tokenCacheKey,g=t.timeout,d=t.getAbortController,e=t.retryConfig,r=(e=void 0===e?{}:e).retryDelay,y=void 0===r?300:r,o=e.maxRetries,w=void 0===o?10:o,v=e.backoff,E=void 0===v||v,b=e.maxDelay,A=void 0===b?1/0:b;if(g&&!d&&"undefined"==typeof AbortController)throw new Error("`AbortController` is not available. Please pass in `getAbortController` as an option or have AbortController globally available when using timeout.");if(g&&"number"!=typeof g)throw new Error("The passed value for timeout is not a number, please provide a timeout of type number.");var m=0;!function o(){var t,e,r;(g||d)&&(e=(d?d():null)||new AbortController),e&&(t=e.signal),g&&(r=setTimeout(function(){e.abort()},g)),n(i,{method:"POST",headers:{Authorization:"Basic ".concat(s),"Content-Length":_.byteLength(a).toString(),"Content-Type":"application/x-www-form-urlencoded"},body:a,signal:t}).then(function(t){return t.ok?t.json().then(function(t){var e,r=t.access_token,n=t.expires_in,o=t.refresh_token,i=(e=n,Date.now()+1e3*e-72e5);h.set({token:r,expirationTime:i,refreshToken:o},p),f.set(!1);var s=c.slice();c=[],s.forEach(function(t){var e=$(r,t.request);t.next(e,t.response)})}):t.text().then(function(t){var e;try{e=JSON.parse(t)}catch(r){}var r=new Error(e?e.message:t);if(e&&(r.body=e),f.set(!1),r.message.includes("is suspended")){if(h.set(null),m<w)return setTimeout(o,function(t,e,r,n,o){var i=1<arguments.length&&void 0!==e?e:6e4,s=4<arguments.length&&void 0!==o?o:1/0;return 3<arguments.length&&void 0!==n&&!n||0===t?i:Math.min(Math.round((Math.random()+1)*i*Math.pow(2,t)),s)}(m,y,w,E,A)),void(m+=1);var n={message:r.body.error,statusCode:r.body.statusCode,originalRequest:u,retryCount:m};l.reject(n)}l.reject(r)})}).catch(function(t){var e;f.set(!1),l&&"function"==typeof l.reject&&l.reject(t),l&&"function"==typeof l.reject&&"aborted"===(null==t?void 0:t.type)&&(e=new J(t.message,{type:t.type,request:u}),l.reject(e))}).finally(function(){clearTimeout(r)})}()}function H(t,e,r){var n=t.request,o=t.response,i=t.url,s=t.basicAuth,a=t.body,u=t.pendingTasks,h=t.requestState,f=t.tokenCache,c=t.tokenCacheKey,l=t.fetch,p=t.timeout,g=t.getAbortController,d=t.retryConfig;if(!l&&"undefined"==typeof fetch)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");if(l=l||fetch,n.headers&&n.headers.authorization||n.headers&&n.headers.Authorization)e(n,o);else{var y=f.get(c);if(y&&y.token&&Date.now()<y.expirationTime)e($(y.token,n),o);else if(u.push({request:n,response:o,next:e}),!h.get())if(h.set(!0),y&&y.refreshToken&&(!y.token||y.token&&Date.now()>y.expirationTime)){if(!r)throw new Error("Missing required options");Z(w(w({fetcher:l},V(w(w({},r),{},{refreshToken:y.refreshToken}))),{},{tokenCacheKey:c,request:n,tokenCache:f,requestState:h,pendingTasks:u,response:o,timeout:p,getAbortController:g,retryConfig:d}))}else Z({fetcher:l,url:i,basicAuth:s,body:a,request:n,tokenCacheKey:c,tokenCache:f,requestState:h,pendingTasks:u,response:o,timeout:p,getAbortController:g,retryConfig:d})}}function Q(t){var e=t;return{get:function(){return e},set:function(t){return e=t}}}var X=Object.freeze({__proto__:null,MANAGE_PROJECT:"manage_project",MANAGE_PRODUCTS:"manage_products",VIEW_PRODUCTS:"view_products",MANAGE_ORDERS:"manage_orders",VIEW_ORDERS:"view_orders",MANAGE_MY_ORDERS:"manage_my_orders",MANAGE_CUSTOMERS:"manage_customers",VIEW_CUSTOMERS:"view_customers",MANAGE_MY_PROFILE:"manage_my_profile",MANAGE_TYPES:"manage_types",VIEW_TYPES:"view_types",MANAGE_PAYMENTS:"manage_payments",VIEW_PAYMENTS:"view_payments",CREATE_ANONYMOUS_TOKEN:"create_anonymous_token",MANAGE_SUBSCRIPTIONS:"manage_subscriptions"});t.createAuthMiddlewareForAnonymousSessionFlow=function(n){var o=Q({}),i=[],s=Q(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):H(w(w(w({},n),{},{request:t,response:e},function(t){if(!t)throw new Error("Missing required options");if(!t.projectKey)throw new Error("Missing required option (projectKey)");var e=t.projectKey;t.oauthUri=t.oauthUri||"/oauth/".concat(e,"/anonymous/token");var r=G(t);return t.credentials.anonymousId&&(r.body+="&anonymous_id=".concat(t.credentials.anonymousId)),w({},r)}(n)),{},{pendingTasks:i,requestState:s,tokenCache:o,fetch:n.fetch}),r,n)}}},t.createAuthMiddlewareForClientCredentialsFlow=function(o){var i=o.tokenCache||Q({token:"",expirationTime:-1}),s=Q(!1),a=[];return function(n){return function(t,e){var r;t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?n(t,e):H(w(w(w({},o),{},{request:t,response:e},G(o)),{},{pendingTasks:a,requestState:s,tokenCache:i,tokenCacheKey:{clientId:(r=o).credentials.clientId,host:r.host,projectKey:r.projectKey},fetch:o.fetch}),n)}}},t.createAuthMiddlewareForPasswordFlow=function(n){var o=Q({}),i=[],s=Q(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):H(w(w(w({},n),{},{request:t,response:e},function(t){if(!t)throw new Error("Missing required options");if(!t.host)throw new Error("Missing required option (host)");if(!t.projectKey)throw new Error("Missing required option (projectKey)");if(!t.credentials)throw new Error("Missing required option (credentials)");var e=t.credentials,r=e.clientId,n=e.clientSecret,o=e.user,i=t.projectKey;if(!(r&&n&&o))throw new Error("Missing required credentials (clientId, clientSecret, user)");var s=o.username,a=o.password;if(!s||!a)throw new Error("Missing required user credentials (username, password)");var u=(t.scopes||[]).join(" "),h=u?"&scope=".concat(u):"",f=_.from("".concat(r,":").concat(n)).toString("base64"),c=t.oauthUri||"/oauth/".concat(i,"/customers/token");return{basicAuth:f,url:t.host.replace(/\/$/,"")+c,body:"grant_type=password&username=".concat(encodeURIComponent(s),"&password=").concat(encodeURIComponent(a)).concat(h)}}(n)),{},{pendingTasks:i,requestState:s,tokenCache:o,fetch:n.fetch}),r,n)}}},t.createAuthMiddlewareForRefreshTokenFlow=function(n){var o=Q({}),i=[],s=Q(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):H(w(w(w({},n),{},{request:t,response:e},V(n)),{},{pendingTasks:i,requestState:s,tokenCache:o,fetch:n.fetch}),r)}}},t.createAuthMiddlewareWithExistingToken=function(){var i=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",s=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return function(o){return function(t,e){if("string"!=typeof i)throw new Error("authorization must be a string");var r=void 0===s.force||s.force;if(!i||(t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization)&&!1===r)return o(t,e);var n=w(w({},t),{},{headers:w(w({},t.headers),{},{Authorization:i})});return o(n,e)}}},t.scopes=X,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).CommercetoolsSdkMiddlewareAuth={})}(this,function(t){"use strict";function e(e,t){var r,n=Object.keys(e);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(e),t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)),n}function y(n){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?e(Object(o),!0).forEach(function(t){var e,r;e=n,r=o[t=t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach(function(t){Object.defineProperty(n,t,Object.getOwnPropertyDescriptor(o,t))})}return n}var r="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},u=[],h=[],j="undefined"!=typeof Uint8Array?Uint8Array:Array,f=!1;function c(){f=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0,r=t.length;e<r;++e)u[e]=t[e],h[t.charCodeAt(e)]=e;h["-".charCodeAt(0)]=62,h["_".charCodeAt(0)]=63}function q(t,e,r){for(var n,o=[],i=e;i<r;i+=3)n=(t[i]<<16)+(t[i+1]<<8)+t[i+2],o.push(u[n>>18&63]+u[n>>12&63]+u[n>>6&63]+u[63&n]);return o.join("")}function R(t){f||c();for(var e,r=t.length,n=r%3,o="",i=[],s=0,a=r-n;s<a;s+=16383)i.push(q(t,s,a<s+16383?a:s+16383));return 1==n?(e=t[r-1],o=(o+=u[e>>2])+u[e<<4&63]+"=="):2==n&&(e=(t[r-2]<<8)+t[r-1],o=(o=(o+=u[e>>10])+u[e>>4&63])+u[e<<2&63]+"="),i.push(o),i.join("")}function n(t,e,r,n,o){var i,s,a=8*o-n-1,u=(1<<a)-1,h=u>>1,f=-7,c=r?o-1:0,l=r?-1:1,o=t[e+c];for(c+=l,i=o&(1<<-f)-1,o>>=-f,f+=a;0<f;i=256*i+t[e+c],c+=l,f-=8);for(s=i&(1<<-f)-1,i>>=-f,f+=n;0<f;s=256*s+t[e+c],c+=l,f-=8);if(0===i)i=1-h;else{if(i===u)return s?NaN:1/0*(o?-1:1);s+=Math.pow(2,n),i-=h}return(o?-1:1)*s*Math.pow(2,i-n)}function i(t,e,r,n,o,i){var s,a,u=8*i-o-1,h=(1<<u)-1,f=h>>1,c=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,l=n?0:i-1,p=n?1:-1,i=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=h):(s=Math.floor(Math.log(e)/Math.LN2),e*(n=Math.pow(2,-s))<1&&(s--,n*=2),2<=(e+=1<=s+f?c/n:c*Math.pow(2,1-f))*n&&(s++,n/=2),h<=s+f?(a=0,s=h):1<=s+f?(a=(e*n-1)*Math.pow(2,o),s+=f):(a=e*Math.pow(2,f-1)*Math.pow(2,o),s=0));8<=o;t[r+l]=255&a,l+=p,a/=256,o-=8);for(s=s<<o|a,u+=o;0<u;t[r+l]=255&s,l+=p,s/=256,u-=8);t[r+l-p]|=128*i}var D={}.toString,a=Array.isArray||function(t){return"[object Array]"==D.call(t)};function o(){return A.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function l(t,e){if(o()<e)throw new RangeError("Invalid typed array length");return A.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=A.prototype:(t=null===t?new A(e):t).length=e,t}function A(t,e,r){if(!(A.TYPED_ARRAY_SUPPORT||this instanceof A))return new A(t,e,r);if("number"!=typeof t)return s(this,t,e,r);if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return g(this,t)}function s(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');if("undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer){var o=t,i=e,s=r;if(i.byteLength,s<0||i.byteLength<s)throw new RangeError("'offset' is out of bounds");if(i.byteLength<s+(n||0))throw new RangeError("'length' is out of bounds");return i=void 0===s&&void 0===n?new Uint8Array(i):void 0===n?new Uint8Array(i,s):new Uint8Array(i,s,n),A.TYPED_ARRAY_SUPPORT?(o=i).__proto__=A.prototype:o=d(o,i),o}if("string"!=typeof e){s=t,n=e;if(v(n))return i=0|w(n.length),0!==(s=l(s,i)).length&&n.copy(s,0,0,i),s;if(n){if("undefined"!=typeof ArrayBuffer&&n.buffer instanceof ArrayBuffer||"length"in n)return"number"!=typeof n.length||function(t){return t!=t}(n.length)?l(s,0):d(s,n);if("Buffer"===n.type&&a(n.data))return d(s,n.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}o=t,n=e,t=r;if(!A.isEncoding(t="string"==typeof t&&""!==t?t:"utf8"))throw new TypeError('"encoding" must be a valid string encoding');e=0|E(n,t);return o=(n=(o=l(o,e)).write(n,t))!==e?o.slice(0,n):o}function p(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function g(t,e){if(p(e),t=l(t,e<0?0:0|w(e)),!A.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function d(t,e){var r=e.length<0?0:0|w(e.length);t=l(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function w(t){if(t>=o())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o().toString(16)+" bytes");return 0|t}function v(t){return null!=t&&t._isBuffer}function E(t,e){if(v(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;var r=(t="string"!=typeof t?""+t:t).length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return O(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return G(t).length;default:if(n)return O(t).length;e=(""+e).toLowerCase(),n=!0}}function x(t,e,r){var n,o=!1;if((e=void 0===e||e<0?0:e)>this.length)return"";if((r=void 0===r||r>this.length?this.length:r)<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t=t||"utf8";;)switch(t){case"hex":var i=this,s=e,a=r,u=i.length;(!a||a<0||u<a)&&(a=u);for(var h="",f=s=!s||s<0?0:s;f<a;++f)h+=function(t){return t<16?"0"+t.toString(16):t.toString(16)}(i[f]);return h;case"utf8":case"utf-8":return P(this,e,r);case"ascii":var c=this,u=e,l=r,p="";l=Math.min(c.length,l);for(var g=u;g<l;++g)p+=String.fromCharCode(127&c[g]);return p;case"latin1":case"binary":var d=this,s=e,y=r,w="";y=Math.min(d.length,y);for(var v=s;v<y;++v)w+=String.fromCharCode(d[v]);return w;case"base64":return E=this,n=r,0===(b=e)&&n===E.length?R(E):R(E.slice(b,n));case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":for(var E=e,b=r,A=this.slice(E,b),m="",_=0;_<A.length;_+=2)m+=String.fromCharCode(A[_]+256*A[_+1]);return m;default:if(o)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),o=!0}}function b(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function m(t,e,r,n,o){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):2147483647<r?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,(r=(r=isNaN(r)?o?0:t.length-1:r)<0?t.length+r:r)>=t.length){if(o)return-1;r=t.length-1}else if(r<0){if(!o)return-1;r=0}if(v(e="string"==typeof e?A.from(e,n):e))return 0===e.length?-1:_(t,e,r,n,o);if("number"==typeof e)return e&=255,A.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?(o?Uint8Array.prototype.indexOf:Uint8Array.prototype.lastIndexOf).call(t,e,r):_(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function _(t,e,r,n,o){var i=1,s=t.length,a=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s/=i=2,a/=2,r/=2}function u(t,e){return 1===i?t[e]:t.readUInt16BE(e*i)}if(o)for(var h=-1,f=r;f<s;f++)if(u(t,f)===u(e,-1===h?0:f-h)){if(f-(h=-1===h?f:h)+1===a)return h*i}else-1!==h&&(f-=f-h),h=-1;else for(f=r=s<r+a?s-a:r;0<=f;f--){for(var c=!0,l=0;l<a;l++)if(u(t,f+l)!==u(e,l)){c=!1;break}if(c)return f}return-1}function T(t,e,r,n){return I(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function L(t,e,r,n){return I(function(t,e){for(var r,n,o=[],i=0;i<t.length&&!((e-=2)<0);++i)n=t.charCodeAt(i),r=n>>8,n=n%256,o.push(n),o.push(r);return o}(e,t.length-r),t,r,n)}function P(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o<r;){var i,s,a,u,h=t[o],f=null,c=239<h?4:223<h?3:191<h?2:1;if(o+c<=r)switch(c){case 1:h<128&&(f=h);break;case 2:128==(192&(i=t[o+1]))&&127<(u=(31&h)<<6|63&i)&&(f=u);break;case 3:i=t[o+1],s=t[o+2],128==(192&i)&&128==(192&s)&&2047<(u=(15&h)<<12|(63&i)<<6|63&s)&&(u<55296||57343<u)&&(f=u);break;case 4:i=t[o+1],s=t[o+2],a=t[o+3],128==(192&i)&&128==(192&s)&&128==(192&a)&&65535<(u=(15&h)<<18|(63&i)<<12|(63&s)<<6|63&a)&&u<1114112&&(f=u)}null===f?(f=65533,c=1):65535<f&&(f-=65536,n.push(f>>>10&1023|55296),f=56320|1023&f),n.push(f),o+=c}var l=n,p=l.length;if(p<=S)return String.fromCharCode.apply(String,l);for(var g="",d=0;d<p;)g+=String.fromCharCode.apply(String,l.slice(d,d+=S));return g}A.TYPED_ARRAY_SUPPORT=void 0===r.TYPED_ARRAY_SUPPORT||r.TYPED_ARRAY_SUPPORT,A.poolSize=8192,A._augment=function(t){return t.__proto__=A.prototype,t},A.from=function(t,e,r){return s(null,t,e,r)},A.TYPED_ARRAY_SUPPORT&&(A.prototype.__proto__=Uint8Array.prototype,A.__proto__=Uint8Array),A.alloc=function(t,e,r){return n=null,e=e,r=r,p(t=t),!(t<=0)&&void 0!==e?"string"==typeof r?l(n,t).fill(e,r):l(n,t).fill(e):l(n,t);var n},A.allocUnsafe=function(t){return g(null,t)},A.allocUnsafeSlow=function(t){return g(null,t)},A.isBuffer=function(t){return null!=t&&(!!t._isBuffer||V(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&V(t.slice(0,0))}(t))},A.compare=function(t,e){if(!v(t)||!v(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,o=0,i=Math.min(r,n);o<i;++o)if(t[o]!==e[o]){r=t[o],n=e[o];break}return r<n?-1:n<r?1:0},A.isEncoding=function(t){switch(String(t).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}},A.concat=function(t,e){if(!a(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return A.alloc(0);if(void 0===e)for(o=e=0;o<t.length;++o)e+=t[o].length;for(var r=A.allocUnsafe(e),n=0,o=0;o<t.length;++o){var i=t[o];if(!v(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(r,n),n+=i.length}return r},A.byteLength=E,A.prototype._isBuffer=!0,A.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)b(this,e,e+1);return this},A.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)b(this,e,e+3),b(this,e+1,e+2);return this},A.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)b(this,e,e+7),b(this,e+1,e+6),b(this,e+2,e+5),b(this,e+3,e+4);return this},A.prototype.toString=function(){var t=0|this.length;return 0==t?"":0===arguments.length?P(this,0,t):x.apply(this,arguments)},A.prototype.equals=function(t){if(v(t))return this===t||0===A.compare(this,t);throw new TypeError("Argument must be a Buffer")},A.prototype.inspect=function(){var t="";return 0<this.length&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),50<this.length&&(t+=" ... ")),"<Buffer "+t+">"},A.prototype.compare=function(t,e,r,n,o){if(!v(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),(e=void 0===e?0:e)<0||r>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(o<=n&&r<=e)return 0;if(o<=n)return-1;if(r<=e)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0),a=Math.min(i,s),u=this.slice(n,o),h=t.slice(e,r),f=0;f<a;++f)if(u[f]!==h[f]){i=u[f],s=h[f];break}return i<s?-1:s<i?1:0},A.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},A.prototype.indexOf=function(t,e,r){return m(this,t,e,r,!0)},A.prototype.lastIndexOf=function(t,e,r){return m(this,t,e,r,!1)},A.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-e;if((void 0===r||o<r)&&(r=o),0<t.length&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n=n||"utf8";for(var i,s,a,u=!1;;)switch(n){case"hex":var h=this,f=t,c=e,l=r,p=(c=Number(c)||0,h.length-c);if((!l||p<(l=Number(l)))&&(l=p),(p=f.length)%2!=0)throw new TypeError("Invalid hex string");p/2<l&&(l=p/2);for(var g=0;g<l;++g){var d=parseInt(f.substr(2*g,2),16);if(isNaN(d))return g;h[c+g]=d}return g;case"utf8":case"utf-8":return p=e,a=r,I(O(t,(s=this).length-p),s,p,a);case"ascii":return T(this,t,e,r);case"latin1":case"binary":return T(this,t,e,r);case"base64":return s=this,a=e,i=r,I(G(t),s,a,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return L(this,t,e,r);default:if(u)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),u=!0}},A.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var S=4096;function C(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(r<t+e)throw new RangeError("Trying to access beyond buffer length")}function M(t,e,r,n,o,i){if(!v(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(o<e||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function U(t,e,r,n){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-r,2);o<i;++o)t[r+o]=(e&255<<8*(n?o:1-o))>>>8*(n?o:1-o)}function k(t,e,r,n){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-r,4);o<i;++o)t[r+o]=e>>>8*(n?o:3-o)&255}function N(t,e,r,n){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function z(t,e,r,n,o){return o||N(t,0,r,4),i(t,e,r,n,23,4),r+4}function K(t,e,r,n,o){return o||N(t,0,r,8),i(t,e,r,n,52,8),r+8}A.prototype.slice=function(t,e){var r=this.length;if((t=~~t)<0?(t+=r)<0&&(t=0):r<t&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):r<e&&(e=r),e<t&&(e=t),A.TYPED_ARRAY_SUPPORT)(o=this.subarray(t,e)).__proto__=A.prototype;else for(var n=e-t,o=new A(n,void 0),i=0;i<n;++i)o[i]=this[i+t];return o},A.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||C(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n},A.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||C(t,e,this.length);for(var n=this[t+--e],o=1;0<e&&(o*=256);)n+=this[t+--e]*o;return n},A.prototype.readUInt8=function(t,e){return e||C(t,1,this.length),this[t]},A.prototype.readUInt16LE=function(t,e){return e||C(t,2,this.length),this[t]|this[t+1]<<8},A.prototype.readUInt16BE=function(t,e){return e||C(t,2,this.length),this[t]<<8|this[t+1]},A.prototype.readUInt32LE=function(t,e){return e||C(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},A.prototype.readUInt32BE=function(t,e){return e||C(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},A.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||C(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return(o*=128)<=n&&(n-=Math.pow(2,8*e)),n},A.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||C(t,e,this.length);for(var n=e,o=1,i=this[t+--n];0<n&&(o*=256);)i+=this[t+--n]*o;return(o*=128)<=i&&(i-=Math.pow(2,8*e)),i},A.prototype.readInt8=function(t,e){return e||C(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},A.prototype.readInt16LE=function(t,e){e||C(t,2,this.length);e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},A.prototype.readInt16BE=function(t,e){e||C(t,2,this.length);e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},A.prototype.readInt32LE=function(t,e){return e||C(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},A.prototype.readInt32BE=function(t,e){return e||C(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},A.prototype.readFloatLE=function(t,e){return e||C(t,4,this.length),n(this,t,!0,23,4)},A.prototype.readFloatBE=function(t,e){return e||C(t,4,this.length),n(this,t,!1,23,4)},A.prototype.readDoubleLE=function(t,e){return e||C(t,8,this.length),n(this,t,!0,52,8)},A.prototype.readDoubleBE=function(t,e){return e||C(t,8,this.length),n(this,t,!1,52,8)},A.prototype.writeUIntLE=function(t,e,r,n){t=+t,e|=0,r|=0,n||M(this,t,e,r,Math.pow(2,8*r)-1,0);var o=1,i=0;for(this[e]=255&t;++i<r&&(o*=256);)this[e+i]=t/o&255;return e+r},A.prototype.writeUIntBE=function(t,e,r,n){t=+t,e|=0,r|=0,n||M(this,t,e,r,Math.pow(2,8*r)-1,0);var o=r-1,i=1;for(this[e+o]=255&t;0<=--o&&(i*=256);)this[e+o]=t/i&255;return e+r},A.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||M(this,t,e,1,255,0),A.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},A.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||M(this,t,e,2,65535,0),A.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):U(this,t,e,!0),e+2},A.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||M(this,t,e,2,65535,0),A.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):U(this,t,e,!1),e+2},A.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||M(this,t,e,4,4294967295,0),A.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):k(this,t,e,!0),e+4},A.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||M(this,t,e,4,4294967295,0),A.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):k(this,t,e,!1),e+4},A.prototype.writeIntLE=function(t,e,r,n){t=+t,e|=0,n||M(this,t,e,r,(n=Math.pow(2,8*r-1))-1,-n);var o=0,i=1,s=0;for(this[e]=255&t;++o<r&&(i*=256);)t<0&&0===s&&0!==this[e+o-1]&&(s=1),this[e+o]=(t/i>>0)-s&255;return e+r},A.prototype.writeIntBE=function(t,e,r,n){t=+t,e|=0,n||M(this,t,e,r,(n=Math.pow(2,8*r-1))-1,-n);var o=r-1,i=1,s=0;for(this[e+o]=255&t;0<=--o&&(i*=256);)t<0&&0===s&&0!==this[e+o+1]&&(s=1),this[e+o]=(t/i>>0)-s&255;return e+r},A.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||M(this,t,e,1,127,-128),A.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&(t=t<0?255+t+1:t),e+1},A.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||M(this,t,e,2,32767,-32768),A.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):U(this,t,e,!0),e+2},A.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||M(this,t,e,2,32767,-32768),A.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):U(this,t,e,!1),e+2},A.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||M(this,t,e,4,2147483647,-2147483648),A.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):k(this,t,e,!0),e+4},A.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||M(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),A.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):k(this,t,e,!1),e+4},A.prototype.writeFloatLE=function(t,e,r){return z(this,t,e,!0,r)},A.prototype.writeFloatBE=function(t,e,r){return z(this,t,e,!1,r)},A.prototype.writeDoubleLE=function(t,e,r){return K(this,t,e,!0,r)},A.prototype.writeDoubleBE=function(t,e,r){return K(this,t,e,!1,r)},A.prototype.copy=function(t,e,r,n){if(r=r||0,n||0===n||(n=this.length),e>=t.length&&(e=t.length),(n=0<n&&n<r?r:n)===r)return 0;if(0===t.length||0===this.length)return 0;if((e=e||0)<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);var o,i=(n=t.length-e<n-r?t.length-e+r:n)-r;if(this===t&&r<e&&e<n)for(o=i-1;0<=o;--o)t[o+e]=this[o+r];else if(i<1e3||!A.TYPED_ARRAY_SUPPORT)for(o=0;o<i;++o)t[o+e]=this[o+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+i),e);return i},A.prototype.fill=function(t,e,r,n){if("string"==typeof t){var o;if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1!==t.length||(o=t.charCodeAt(0))<256&&(t=o),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!A.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(!(r<=e))if(e>>>=0,r=void 0===r?this.length:r>>>0,"number"==typeof(t=t||0))for(a=e;a<r;++a)this[a]=t;else for(var i=v(t)?t:O(new A(t,n).toString()),s=i.length,a=0;a<r-e;++a)this[a+e]=i[a%s];return this};var F=/[^+\/0-9A-Za-z-_]/g;function O(t,e){e=e||1/0;for(var r,n=t.length,o=null,i=[],s=0;s<n;++s){if(55295<(r=t.charCodeAt(s))&&r<57344){if(!o){if(56319<r){-1<(e-=3)&&i.push(239,191,189);continue}if(s+1===n){-1<(e-=3)&&i.push(239,191,189);continue}o=r;continue}if(r<56320){-1<(e-=3)&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&-1<(e-=3)&&i.push(239,191,189);if(o=null,r<128){if(--e<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function G(t){var e=function(t){var e;if((t=((e=t).trim?e.trim():e.replace(/^\s+|\s+$/g,"")).replace(F,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t);f||c();var r,t=e.length;if(0<t%4)throw new Error("Invalid string. Length must be a multiple of 4");for(var n="="===e[t-2]?2:"="===e[t-1]?1:0,o=new j(3*t/4-n),i=0<n?t-4:t,s=0,a=0;a<i;a+=4)r=h[e.charCodeAt(a)]<<18|h[e.charCodeAt(a+1)]<<12|h[e.charCodeAt(a+2)]<<6|h[e.charCodeAt(a+3)],o[s++]=r>>16&255,o[s++]=r>>8&255,o[s++]=255&r;return 2==n?(r=h[e.charCodeAt(a)]<<2|h[e.charCodeAt(a+1)]>>4,o[s++]=255&r):1==n&&(r=h[e.charCodeAt(a)]<<10|h[e.charCodeAt(a+1)]<<4|h[e.charCodeAt(a+2)]>>2,o[s++]=r>>8&255,o[s++]=255&r),o}function I(t,e,r,n){for(var o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}function V(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}function W(t){if(!t)throw new Error("Missing required options");if(!t.host)throw new Error("Missing required option (host)");if(!t.projectKey)throw new Error("Missing required option (projectKey)");if(!t.credentials)throw new Error("Missing required option (credentials)");var e=t.credentials,r=e.clientId,e=e.clientSecret;if(!r||!e)throw new Error("Missing required credentials (clientId, clientSecret)");var n=t.scopes?t.scopes.join(" "):void 0,r=A.from("".concat(r,":").concat(e)).toString("base64"),e=t.oauthUri||"/oauth/token";return{basicAuth:r,url:t.host.replace(/\/$/,"")+e,body:"grant_type=client_credentials".concat(n?"&scope=".concat(n):"")}}function J(t){if(!t)throw new Error("Missing required options");if(!t.host)throw new Error("Missing required option (host)");if(!t.projectKey)throw new Error("Missing required option (projectKey)");if(!t.credentials)throw new Error("Missing required option (credentials)");if(!t.refreshToken)throw new Error("Missing required option (refreshToken)");var e=t.credentials,r=e.clientId,e=e.clientSecret;if(!r||!e)throw new Error("Missing required credentials (clientId, clientSecret)");r=A.from("".concat(r,":").concat(e)).toString("base64"),e=t.oauthUri||"/oauth/token";return{basicAuth:r,url:t.host.replace(/\/$/,"")+e,body:"grant_type=refresh_token&refresh_token=".concat(encodeURIComponent(t.refreshToken))}}function $(t,e){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.status=this.statusCode=this.code=t,this.message=e,Object.assign(this,r),this.name=this.constructor.name,this.constructor.prototype.__proto__=Error.prototype,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}function Z(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];$.call.apply($,[this,0].concat(e))}function H(t,e){return y(y({},e),{},{headers:y(y({},e.headers),{},{Authorization:"Bearer ".concat(t)})})}function Q(t){var o=t.fetcher,i=t.url,s=t.basicAuth,a=t.body,u=t.request,h=t.tokenCache,f=t.requestState,c=t.pendingTasks,l=t.response,p=t.tokenCacheKey,g=t.timeout,d=t.getAbortController,t=t.retryConfig,e=(t=void 0===t?{}:t).retryDelay,y=void 0===e?300:e,e=t.maxRetries,w=void 0===e?10:e,e=t.backoff,v=void 0===e||e,e=t.maxDelay,E=void 0===e?1/0:e;if(g&&!d&&"undefined"==typeof AbortController)throw new Error("`AbortController` is not available. Please pass in `getAbortController` as an option or have AbortController globally available when using timeout.");if(g&&"number"!=typeof g)throw new Error("The passed value for timeout is not a number, please provide a timeout of type number.");var b=0;!function n(){var t,e,r;(e=g||d?(d?d():null)||new AbortController:e)&&(t=e.signal),g&&(r=setTimeout(function(){e.abort()},g)),o(i,{method:"POST",headers:{Authorization:"Basic ".concat(s),"Content-Length":A.byteLength(a).toString(),"Content-Type":"application/x-www-form-urlencoded"},body:a,signal:t}).then(function(t){return t.ok?t.json().then(function(t){var r=t.access_token,e=t.expires_in,t=t.refresh_token,e=Date.now()+1e3*e-72e5,e=(h.set({token:r,expirationTime:e,refreshToken:t},p),f.set(!1),c.slice());c=[],e.forEach(function(t){var e=H(r,t.request);t.next(e,t.response)})}):t.text().then(function(t){var e;try{e=JSON.parse(t)}catch(r){}var r=new Error(e?e.message:t);if(e&&(r.body=e),f.set(!1),r.message.includes("is suspended")){if(h.set(null),b<w)return setTimeout(n,function(t,e,r,n,o){return e=1<arguments.length&&void 0!==e?e:6e4,n=!(3<arguments.length&&void 0!==n)||n,o=4<arguments.length&&void 0!==o?o:1/0,n&&0!==t?Math.min(Math.round((Math.random()+1)*e*Math.pow(2,t)),o):e}(b,y,w,v,E)),void(b+=1);t={message:r.body.error,statusCode:r.body.statusCode,originalRequest:u,retryCount:b},l.reject(t)}l.reject(r)})}).catch(function(t){f.set(!1),l&&"function"==typeof l.reject&&l.reject(t),l&&"function"==typeof l.reject&&"aborted"===(null==t?void 0:t.type)&&(t=new Z(t.message,{type:t.type,request:u}),l.reject(t))}).finally(function(){clearTimeout(r)})}()}function B(t,e,r){var n=t.request,o=t.response,i=t.url,s=t.basicAuth,a=t.body,u=t.pendingTasks,h=t.requestState,f=t.tokenCache,c=t.tokenCacheKey,l=t.fetch,p=t.timeout,g=t.getAbortController,t=t.retryConfig;if(!l&&"undefined"==typeof fetch)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");if(l=l||fetch,n.headers&&n.headers.authorization||n.headers&&n.headers.Authorization)e(n,o);else{var d=f.get(c);if(d&&d.token&&Date.now()<d.expirationTime)e(H(d.token,n),o);else if(u.push({request:n,response:o,next:e}),!h.get()){if(h.set(!0),d&&d.refreshToken&&(!d.token||d.token&&Date.now()>d.expirationTime)){if(r)return void Q(y(y({fetcher:l},J(y(y({},r),{},{refreshToken:d.refreshToken}))),{},{tokenCacheKey:c,request:n,tokenCache:f,requestState:h,pendingTasks:u,response:o,timeout:p,getAbortController:g,retryConfig:t}));throw new Error("Missing required options")}Q({fetcher:l,url:i,basicAuth:s,body:a,request:n,tokenCacheKey:c,tokenCache:f,requestState:h,pendingTasks:u,response:o,timeout:p,getAbortController:g,retryConfig:t})}}}function Y(t){var e=t;return{get:function(){return e},set:function(t){return e=t}}}r=Object.freeze({__proto__:null,MANAGE_PROJECT:"manage_project",MANAGE_PRODUCTS:"manage_products",VIEW_PRODUCTS:"view_products",MANAGE_ORDERS:"manage_orders",VIEW_ORDERS:"view_orders",MANAGE_MY_ORDERS:"manage_my_orders",MANAGE_CUSTOMERS:"manage_customers",VIEW_CUSTOMERS:"view_customers",MANAGE_MY_PROFILE:"manage_my_profile",MANAGE_TYPES:"manage_types",VIEW_TYPES:"view_types",MANAGE_PAYMENTS:"manage_payments",VIEW_PAYMENTS:"view_payments",CREATE_ANONYMOUS_TOKEN:"create_anonymous_token",MANAGE_SUBSCRIPTIONS:"manage_subscriptions"});t.createAuthMiddlewareForAnonymousSessionFlow=function(n){var o=Y({}),i=[],s=Y(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):B(y(y(y({},n),{},{request:t,response:e},function(t){if(!t)throw new Error("Missing required options");if(!t.projectKey)throw new Error("Missing required option (projectKey)");var e=t.projectKey,e=(t.oauthUri=t.oauthUri||"/oauth/".concat(e,"/anonymous/token"),W(t));return t.credentials.anonymousId&&(e.body+="&anonymous_id=".concat(t.credentials.anonymousId)),y({},e)}(n)),{},{pendingTasks:i,requestState:s,tokenCache:o,fetch:n.fetch}),r,n)}}},t.createAuthMiddlewareForClientCredentialsFlow=function(n){var o=n.tokenCache||Y({token:"",expirationTime:-1}),i=Y(!1),s=[];return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):B(y(y(y({},n),{},{request:t,response:e},W(n)),{},{pendingTasks:s,requestState:i,tokenCache:o,tokenCacheKey:{clientId:n.credentials.clientId,host:n.host,projectKey:n.projectKey},fetch:n.fetch}),r)}}},t.createAuthMiddlewareForPasswordFlow=function(n){var o=Y({}),i=[],s=Y(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):B(y(y(y({},n),{},{request:t,response:e},function(t){if(!t)throw new Error("Missing required options");if(!t.host)throw new Error("Missing required option (host)");if(!t.projectKey)throw new Error("Missing required option (projectKey)");if(!t.credentials)throw new Error("Missing required option (credentials)");var e=(n=t.credentials).clientId,r=n.clientSecret,n=n.user,o=t.projectKey;if(!(e&&r&&n))throw new Error("Missing required credentials (clientId, clientSecret, user)");var i=n.username,n=n.password;if(!i||!n)throw new Error("Missing required user credentials (username, password)");var s=(s=(t.scopes||[]).join(" "))?"&scope=".concat(s):"",e=A.from("".concat(e,":").concat(r)).toString("base64"),r=t.oauthUri||"/oauth/".concat(o,"/customers/token");return{basicAuth:e,url:t.host.replace(/\/$/,"")+r,body:"grant_type=password&username=".concat(encodeURIComponent(i),"&password=").concat(encodeURIComponent(n)).concat(s)}}(n)),{},{pendingTasks:i,requestState:s,tokenCache:o,fetch:n.fetch}),r,n)}}},t.createAuthMiddlewareForRefreshTokenFlow=function(n){var o=Y({}),i=[],s=Y(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):B(y(y(y({},n),{},{request:t,response:e},J(n)),{},{pendingTasks:i,requestState:s,tokenCache:o,fetch:n.fetch}),r)}}},t.createAuthMiddlewareWithExistingToken=function(){var o=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",i=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return function(n){return function(t,e){if("string"!=typeof o)throw new Error("authorization must be a string");var r=void 0===i.force||i.force;if(!o||(t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization)&&!1===r)return n(t,e);r=y(y({},t),{},{headers:y(y({},t.headers),{},{Authorization:o})});return n(r,e)}}},t.scopes=r,Object.defineProperty(t,"__esModule",{value:!0})});

@@ -6,4 +6,7 @@ {

},
"engines": {
"node": ">=14"
},
"name": "@commercetools/sdk-middleware-auth",
"version": "6.2.1",
"version": "7.0.0",
"description": "Middleware for different authentication flows of commercetools platform API, to use with @commercetools/sdk-client",

@@ -10,0 +13,0 @@ "keywords": [

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc