Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@commercetools/sdk-middleware-auth

Package Overview
Dependencies
Maintainers
14
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.1.3 to 6.1.4

30

dist/sdk-middleware-auth.cjs.js

@@ -150,4 +150,4 @@ 'use strict';

function mergeAuthHeader(token, req) {
return _objectSpread2({}, req, {
headers: _objectSpread2({}, req.headers, {
return _objectSpread2(_objectSpread2({}, req), {}, {
headers: _objectSpread2(_objectSpread2({}, req.headers), {}, {
Authorization: "Bearer ".concat(token)

@@ -286,7 +286,7 @@ })

;
executeRequest(_objectSpread2({
executeRequest(_objectSpread2(_objectSpread2({
fetcher: fetcher
}, buildRequestForRefreshTokenFlow(_objectSpread2({}, userOptions, {
}, buildRequestForRefreshTokenFlow(_objectSpread2(_objectSpread2({}, userOptions), {}, {
refreshToken: tokenObj.refreshToken
})), {
}))), {}, {
tokenCacheKey: tokenCacheKey,

@@ -344,6 +344,6 @@ tokenCache: tokenCache,

var params = _objectSpread2({
var params = _objectSpread2(_objectSpread2({
request: request,
response: response
}, buildRequestForClientCredentialsFlow(options), {
}, buildRequestForClientCredentialsFlow(options)), {}, {
pendingTasks: pendingTasks,

@@ -374,6 +374,6 @@ requestState: requestState,

var params = _objectSpread2({
var params = _objectSpread2(_objectSpread2({
request: request,
response: response
}, buildRequestForPasswordFlow(options), {
}, buildRequestForPasswordFlow(options)), {}, {
pendingTasks: pendingTasks,

@@ -403,6 +403,6 @@ requestState: requestState,

var params = _objectSpread2({
var params = _objectSpread2(_objectSpread2({
request: request,
response: response
}, buildRequestForRefreshTokenFlow(options), {
}, buildRequestForRefreshTokenFlow(options)), {}, {
pendingTasks: pendingTasks,

@@ -432,6 +432,6 @@ requestState: requestState,

var params = _objectSpread2({
var params = _objectSpread2(_objectSpread2({
request: request,
response: response
}, buildRequestForAnonymousSessionFlow(options), {
}, buildRequestForAnonymousSessionFlow(options)), {}, {
pendingTasks: pendingTasks,

@@ -464,4 +464,4 @@ requestState: requestState,

var requestWithAuth = _objectSpread2({}, request, {
headers: _objectSpread2({}, request.headers, {
var requestWithAuth = _objectSpread2(_objectSpread2({}, request), {}, {
headers: _objectSpread2(_objectSpread2({}, request.headers), {}, {
Authorization: authorization

@@ -468,0 +468,0 @@ })

@@ -146,4 +146,4 @@ function _defineProperty(obj, key, value) {

function mergeAuthHeader(token, req) {
return _objectSpread2({}, req, {
headers: _objectSpread2({}, req.headers, {
return _objectSpread2(_objectSpread2({}, req), {}, {
headers: _objectSpread2(_objectSpread2({}, req.headers), {}, {
Authorization: "Bearer ".concat(token)

@@ -282,7 +282,7 @@ })

;
executeRequest(_objectSpread2({
executeRequest(_objectSpread2(_objectSpread2({
fetcher: fetcher
}, buildRequestForRefreshTokenFlow(_objectSpread2({}, userOptions, {
}, buildRequestForRefreshTokenFlow(_objectSpread2(_objectSpread2({}, userOptions), {}, {
refreshToken: tokenObj.refreshToken
})), {
}))), {}, {
tokenCacheKey: tokenCacheKey,

@@ -340,6 +340,6 @@ tokenCache: tokenCache,

var params = _objectSpread2({
var params = _objectSpread2(_objectSpread2({
request: request,
response: response
}, buildRequestForClientCredentialsFlow(options), {
}, buildRequestForClientCredentialsFlow(options)), {}, {
pendingTasks: pendingTasks,

@@ -370,6 +370,6 @@ requestState: requestState,

var params = _objectSpread2({
var params = _objectSpread2(_objectSpread2({
request: request,
response: response
}, buildRequestForPasswordFlow(options), {
}, buildRequestForPasswordFlow(options)), {}, {
pendingTasks: pendingTasks,

@@ -399,6 +399,6 @@ requestState: requestState,

var params = _objectSpread2({
var params = _objectSpread2(_objectSpread2({
request: request,
response: response
}, buildRequestForRefreshTokenFlow(options), {
}, buildRequestForRefreshTokenFlow(options)), {}, {
pendingTasks: pendingTasks,

@@ -428,6 +428,6 @@ requestState: requestState,

var params = _objectSpread2({
var params = _objectSpread2(_objectSpread2({
request: request,
response: response
}, buildRequestForAnonymousSessionFlow(options), {
}, buildRequestForAnonymousSessionFlow(options)), {}, {
pendingTasks: pendingTasks,

@@ -460,4 +460,4 @@ requestState: requestState,

var requestWithAuth = _objectSpread2({}, request, {
headers: _objectSpread2({}, request.headers, {
var requestWithAuth = _objectSpread2(_objectSpread2({}, request), {}, {
headers: _objectSpread2(_objectSpread2({}, request.headers), {}, {
Authorization: authorization

@@ -464,0 +464,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=t||self).CommercetoolsSdkMiddlewareAuth={})}(this,function(t){"use strict";function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function g(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 p(){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 l(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 n(t){var e;c||p();for(var r=t.length,n=r%3,o="",i=[],s=0,a=r-n;s<a;s+=16383)i.push(l(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 o(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,p=r?-1:1,l=t[e+c];for(c+=p,i=l&(1<<-f)-1,l>>=-f,f+=a;0<f;i=256*i+t[e+c],c+=p,f-=8);for(s=i&(1<<-f)-1,i>>=-f,f+=n;0<f;s=256*s+t[e+c],c+=p,f-=8);if(0===i)i=1-h;else{if(i===u)return s?NaN:1/0*(l?-1:1);s+=Math.pow(2,n),i-=h}return(l?-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,p=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,l=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?p/u:p*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+l]=255&a,l+=g,a/=256,o-=8);for(s=s<<o|a,h+=o;0<h;t[r+l]=255&s,l+=g,s/=256,h-=8);t[r+l-g]|=128*d}var s={}.toString,a=Array.isArray||function(t){return"[object Array]"==s.call(t)};function d(){return w.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function y(t,e){if(d()<e)throw new RangeError("Invalid typed array length");return w.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=w.prototype:(null===t&&(t=new w(e)),t.length=e),t}function w(t,e,r){if(!(w.TYPED_ARRAY_SUPPORT||this instanceof w))return new w(t,e,r);if("number"!=typeof t)return v(this,t,e,r);if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return A(this,t)}function v(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);w.TYPED_ARRAY_SUPPORT?(t=e).__proto__=w.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(!w.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|R(e,r),o=(t=y(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|_(e.length);return 0===(t=y(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)?y(t,0):b(t,e);if("Buffer"===e.type&&a(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 E(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 A(t,e){if(E(e),t=y(t,e<0?0:0|_(e)),!w.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|_(e.length);t=y(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function _(t){if(t>=d())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+d().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 W(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return J(t).length;default:if(n)return W(t).length;e=(""+e).toLowerCase(),n=!0}}function T(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function P(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=w.from(e,n)),m(e))return 0===e.length?-1:S(t,e,r,n,o);if("number"==typeof e)return e&=255,w.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):S(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function S(t,e,r,n,o){var i,s=1,a=t.length,u=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;a/=s=2,u/=2,r/=2}function h(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(o){var f=-1;for(i=r;i<a;i++)if(h(t,i)===h(e,-1===f?0:i-f)){if(-1===f&&(f=i),i-f+1===u)return f*s}else-1!==f&&(i-=i-f),f=-1}else for(a<r+u&&(r=a-u),i=r;0<=i;i--){for(var c=!0,p=0;p<u;p++)if(h(t,i+p)!==h(e,p)){c=!1;break}if(c)return i}return-1}function M(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}function U(t,e,r,n){return $(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function O(t,e,r,n){return $(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){return 0===e&&r===t.length?n(t):n(t.slice(e,r))}function I(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<=C)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=C));return r}(n)}w.TYPED_ARRAY_SUPPORT=void 0===r.TYPED_ARRAY_SUPPORT||r.TYPED_ARRAY_SUPPORT,w.poolSize=8192,w._augment=function(t){return t.__proto__=w.prototype,t},w.from=function(t,e,r){return v(null,t,e,r)},w.TYPED_ARRAY_SUPPORT&&(w.prototype.__proto__=Uint8Array.prototype,w.__proto__=Uint8Array),w.alloc=function(t,e,r){return n=null,i=e,s=r,E(o=t),o<=0||void 0===i?y(n,o):"string"==typeof s?y(n,o).fill(i,s):y(n,o).fill(i);var n,o,i,s},w.allocUnsafe=function(t){return A(null,t)},w.allocUnsafeSlow=function(t){return A(null,t)},w.isBuffer=function(t){return null!=t&&(!!t._isBuffer||Z(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&Z(t.slice(0,0))}(t))},w.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},w.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}},w.concat=function(t,e){if(!a(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return w.alloc(0);var r;if(void 0===e)for(r=e=0;r<t.length;++r)e+=t[r].length;var n=w.allocUnsafe(e),o=0;for(r=0;r<t.length;++r){var i=t[r];if(!m(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(n,o),o+=i.length}return n},w.byteLength=R,w.prototype._isBuffer=!0,w.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)T(this,e,e+1);return this},w.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)T(this,e,e+3),T(this,e+1,e+2);return this},w.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)T(this,e,e+7),T(this,e+1,e+6),T(this,e+2,e+5),T(this,e+3,e+4);return this},w.prototype.toString=function(){var t=0|this.length;return 0==t?"":0===arguments.length?I(this,0,t):function(t,e,r){var n=!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 j(this,e,r);case"utf8":case"utf-8":return I(this,e,r);case"ascii":return B(this,e,r);case"latin1":case"binary":return Y(this,e,r);case"base64":return k(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return D(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},w.prototype.equals=function(t){if(!m(t))throw new TypeError("Argument must be a Buffer");return this===t||0===w.compare(this,t)},w.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+">"},w.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},w.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},w.prototype.indexOf=function(t,e,r){return P(this,t,e,r,!0)},w.prototype.lastIndexOf=function(t,e,r){return P(this,t,e,r,!1)},w.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 M(this,t,e,r);case"utf8":case"utf-8":return h=e,f=r,$(W(t,(u=this).length-h),u,h,f);case"ascii":return U(this,t,e,r);case"latin1":case"binary":return U(this,t,e,r);case"base64":return i=this,s=e,a=r,$(J(t),i,s,a);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,t,e,r);default:if(c)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),c=!0}},w.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var C=4096;function B(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}function Y(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}function j(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+=V(t[i]);return o}function D(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}function q(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 x(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 L(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 N(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 z(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 K(t,e,r,n,o){return o||z(t,0,r,4),i(t,e,r,n,23,4),r+4}function F(t,e,r,n,o){return o||z(t,0,r,8),i(t,e,r,n,52,8),r+8}w.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):n<t&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):n<e&&(e=n),e<t&&(e=t),w.TYPED_ARRAY_SUPPORT)(r=this.subarray(t,e)).__proto__=w.prototype;else{var o=e-t;r=new w(o,void 0);for(var i=0;i<o;++i)r[i]=this[i+t]}return r},w.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||q(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n},w.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||q(t,e,this.length);for(var n=this[t+--e],o=1;0<e&&(o*=256);)n+=this[t+--e]*o;return n},w.prototype.readUInt8=function(t,e){return e||q(t,1,this.length),this[t]},w.prototype.readUInt16LE=function(t,e){return e||q(t,2,this.length),this[t]|this[t+1]<<8},w.prototype.readUInt16BE=function(t,e){return e||q(t,2,this.length),this[t]<<8|this[t+1]},w.prototype.readUInt32LE=function(t,e){return e||q(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},w.prototype.readUInt32BE=function(t,e){return e||q(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},w.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||q(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},w.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||q(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},w.prototype.readInt8=function(t,e){return e||q(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},w.prototype.readInt16LE=function(t,e){e||q(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},w.prototype.readInt16BE=function(t,e){e||q(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},w.prototype.readInt32LE=function(t,e){return e||q(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},w.prototype.readInt32BE=function(t,e){return e||q(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},w.prototype.readFloatLE=function(t,e){return e||q(t,4,this.length),o(this,t,!0,23,4)},w.prototype.readFloatBE=function(t,e){return e||q(t,4,this.length),o(this,t,!1,23,4)},w.prototype.readDoubleLE=function(t,e){return e||q(t,8,this.length),o(this,t,!0,52,8)},w.prototype.readDoubleBE=function(t,e){return e||q(t,8,this.length),o(this,t,!1,52,8)},w.prototype.writeUIntLE=function(t,e,r,n){t=+t,e|=0,r|=0,n||x(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},w.prototype.writeUIntBE=function(t,e,r,n){t=+t,e|=0,r|=0,n||x(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},w.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,1,255,0),w.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},w.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,2,65535,0),w.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},w.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,2,65535,0),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},w.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,4,4294967295,0),w.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):N(this,t,e,!0),e+4},w.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,4,4294967295,0),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},w.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);x(this,t,e,r,o-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},w.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);x(this,t,e,r,o-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},w.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,1,127,-128),w.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},w.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,2,32767,-32768),w.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},w.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,2,32767,-32768),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},w.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,4,2147483647,-2147483648),w.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):N(this,t,e,!0),e+4},w.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},w.prototype.writeFloatLE=function(t,e,r){return K(this,t,e,!0,r)},w.prototype.writeFloatBE=function(t,e,r){return K(this,t,e,!1,r)},w.prototype.writeDoubleLE=function(t,e,r){return F(this,t,e,!0,r)},w.prototype.writeDoubleBE=function(t,e,r){return F(this,t,e,!1,r)},w.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||!w.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},w.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===t.length){var o=t.charCodeAt(0);o<256&&(t=o)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!w.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;var i;if(e>>>=0,r=void 0===r?this.length:r>>>0,"number"==typeof(t=t||0))for(i=e;i<r;++i)this[i]=t;else{var s=m(t)?t:W(new w(t,n).toString()),a=s.length;for(i=0;i<r-e;++i)this[i+e]=s[i%a]}return this};var G=/[^+\/0-9A-Za-z-_]/g;function V(t){return t<16?"0"+t.toString(16):t.toString(16)}function W(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 J(t){return function(t){var e,r,n,o,i;c||p();var s=t.length;if(0<s%4)throw new Error("Invalid string. Length must be a multiple of 4");o="="===t[s-2]?2:"="===t[s-1]?1:0,i=new f(3*s/4-o),r=0<o?s-4:s;var a=0;for(e=0;e<r;e+=4,0)n=h[t.charCodeAt(e)]<<18|h[t.charCodeAt(e+1)]<<12|h[t.charCodeAt(e+2)]<<6|h[t.charCodeAt(e+3)],i[a++]=n>>16&255,i[a++]=n>>8&255,i[a++]=255&n;return 2==o?(n=h[t.charCodeAt(e)]<<2|h[t.charCodeAt(e+1)]>>4,i[a++]=255&n):1==o&&(n=h[t.charCodeAt(e)]<<10|h[t.charCodeAt(e+1)]<<4|h[t.charCodeAt(e+2)]>>2,i[a++]=n>>8&255,i[a++]=255&n),i}(function(t){var e;if((t=((e=t).trim?e.trim():e.replace(/^\s+|\s+$/g,"")).replace(G,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function $(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 Z(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}function H(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=w.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 Q(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=w.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 X(t,e){return g({},e,{headers:g({},e.headers,{Authorization:"Bearer ".concat(t)})})}function tt(t){var e=t.fetcher,r=t.url,n=t.basicAuth,o=t.body,a=t.tokenCache,u=t.requestState,h=t.pendingTasks,i=t.response,f=t.tokenCacheKey;e(r,{method:"POST",headers:{Authorization:"Basic ".concat(n),"Content-Length":w.byteLength(o).toString(),"Content-Type":"application/x-www-form-urlencoded"},body:o}).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);a.set({token:r,expirationTime:i,refreshToken:o},f),u.set(!1);var s=h.slice();h=[],s.forEach(function(t){var e=X(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);e&&(r.body=e),u.set(!1),i.reject(r)})}).catch(function(t){u.set(!1),i&&"function"==typeof i.reject&&i.reject(t)})}function et(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,p=t.fetch;if(!p&&"undefined"==typeof fetch)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");if(p=p||fetch,n.headers&&n.headers.authorization||n.headers&&n.headers.Authorization)e(n,o);else{var l=f.get(c);if(l&&l.token&&Date.now()<l.expirationTime)e(X(l.token,n),o);else if(u.push({request:n,response:o,next:e}),!h.get())if(h.set(!0),l&&l.refreshToken&&(!l.token||l.token&&Date.now()>l.expirationTime)){if(!r)throw new Error("Missing required options");tt(g({fetcher:p},Q(g({},r,{refreshToken:l.refreshToken})),{tokenCacheKey:c,tokenCache:f,requestState:h,pendingTasks:u,response:o}))}else tt({fetcher:p,url:i,basicAuth:s,body:a,tokenCacheKey:c,tokenCache:f,requestState:h,pendingTasks:u,response:o})}}function rt(t){var e=t;return{get:function(){return e},set:function(t){return e=t}}}var nt=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=rt({}),i=[],s=rt(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):et(g({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=H(t);return t.credentials.anonymousId&&(r.body+="&anonymous_id=".concat(t.credentials.anonymousId)),g({},r)}(n),{pendingTasks:i,requestState:s,tokenCache:o,fetch:n.fetch}),r,n)}}},t.createAuthMiddlewareForClientCredentialsFlow=function(o){var i=o.tokenCache||rt({token:"",expirationTime:-1}),s=rt(!1),a=[];return function(n){return function(t,e){var r;t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?n(t,e):et(g({request:t,response:e},H(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=rt({}),i=[],s=rt(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):et(g({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=w.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=rt({}),i=[],s=rt(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):et(g({request:t,response:e},Q(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=g({},t,{headers:g({},t.headers,{Authorization:i})});return o(n,e)}}},t.scopes=nt,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=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 g(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 p(){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 l(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 n(t){var e;c||p();for(var r=t.length,n=r%3,o="",i=[],s=0,a=r-n;s<a;s+=16383)i.push(l(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 o(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,p=r?-1:1,l=t[e+c];for(c+=p,i=l&(1<<-f)-1,l>>=-f,f+=a;0<f;i=256*i+t[e+c],c+=p,f-=8);for(s=i&(1<<-f)-1,i>>=-f,f+=n;0<f;s=256*s+t[e+c],c+=p,f-=8);if(0===i)i=1-h;else{if(i===u)return s?NaN:1/0*(l?-1:1);s+=Math.pow(2,n),i-=h}return(l?-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,p=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,l=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?p/u:p*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+l]=255&a,l+=g,a/=256,o-=8);for(s=s<<o|a,h+=o;0<h;t[r+l]=255&s,l+=g,s/=256,h-=8);t[r+l-g]|=128*d}var s={}.toString,a=Array.isArray||function(t){return"[object Array]"==s.call(t)};function d(){return w.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function y(t,e){if(d()<e)throw new RangeError("Invalid typed array length");return w.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=w.prototype:(null===t&&(t=new w(e)),t.length=e),t}function w(t,e,r){if(!(w.TYPED_ARRAY_SUPPORT||this instanceof w))return new w(t,e,r);if("number"!=typeof t)return v(this,t,e,r);if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return A(this,t)}function v(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);w.TYPED_ARRAY_SUPPORT?(t=e).__proto__=w.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(!w.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|R(e,r),o=(t=y(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|_(e.length);return 0===(t=y(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)?y(t,0):b(t,e);if("Buffer"===e.type&&a(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 E(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 A(t,e){if(E(e),t=y(t,e<0?0:0|_(e)),!w.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|_(e.length);t=y(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function _(t){if(t>=d())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+d().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 W(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return J(t).length;default:if(n)return W(t).length;e=(""+e).toLowerCase(),n=!0}}function T(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function P(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=w.from(e,n)),m(e))return 0===e.length?-1:S(t,e,r,n,o);if("number"==typeof e)return e&=255,w.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):S(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function S(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,p=0;p<a;p++)if(u(t,f+p)!==u(e,p)){c=!1;break}if(c)return f}return-1}function M(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}function U(t,e,r,n){return $(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function O(t,e,r,n){return $(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){return 0===e&&r===t.length?n(t):n(t.slice(e,r))}function I(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<=C)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=C));return r}(n)}w.TYPED_ARRAY_SUPPORT=void 0===r.TYPED_ARRAY_SUPPORT||r.TYPED_ARRAY_SUPPORT,w.poolSize=8192,w._augment=function(t){return t.__proto__=w.prototype,t},w.from=function(t,e,r){return v(null,t,e,r)},w.TYPED_ARRAY_SUPPORT&&(w.prototype.__proto__=Uint8Array.prototype,w.__proto__=Uint8Array),w.alloc=function(t,e,r){return n=null,i=e,s=r,E(o=t),o<=0||void 0===i?y(n,o):"string"==typeof s?y(n,o).fill(i,s):y(n,o).fill(i);var n,o,i,s},w.allocUnsafe=function(t){return A(null,t)},w.allocUnsafeSlow=function(t){return A(null,t)},w.isBuffer=function(t){return null!=t&&(!!t._isBuffer||Z(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&Z(t.slice(0,0))}(t))},w.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},w.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}},w.concat=function(t,e){if(!a(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return w.alloc(0);if(void 0===e)for(o=e=0;o<t.length;++o)e+=t[o].length;for(var r=w.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},w.byteLength=R,w.prototype._isBuffer=!0,w.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)T(this,e,e+1);return this},w.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)T(this,e,e+3),T(this,e+1,e+2);return this},w.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)T(this,e,e+7),T(this,e+1,e+6),T(this,e+2,e+5),T(this,e+3,e+4);return this},w.prototype.toString=function(){var t=0|this.length;return 0==t?"":0===arguments.length?I(this,0,t):function(t,e,r){var n=!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 j(this,e,r);case"utf8":case"utf-8":return I(this,e,r);case"ascii":return B(this,e,r);case"latin1":case"binary":return Y(this,e,r);case"base64":return k(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return D(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},w.prototype.equals=function(t){if(!m(t))throw new TypeError("Argument must be a Buffer");return this===t||0===w.compare(this,t)},w.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+">"},w.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},w.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},w.prototype.indexOf=function(t,e,r){return P(this,t,e,r,!0)},w.prototype.lastIndexOf=function(t,e,r){return P(this,t,e,r,!1)},w.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 M(this,t,e,r);case"utf8":case"utf-8":return h=e,f=r,$(W(t,(u=this).length-h),u,h,f);case"ascii":return U(this,t,e,r);case"latin1":case"binary":return U(this,t,e,r);case"base64":return i=this,s=e,a=r,$(J(t),i,s,a);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,t,e,r);default:if(c)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),c=!0}},w.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var C=4096;function B(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}function Y(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}function j(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+=V(t[i]);return o}function D(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}function q(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 x(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 L(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 N(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 z(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 K(t,e,r,n,o){return o||z(t,0,r,4),i(t,e,r,n,23,4),r+4}function F(t,e,r,n,o){return o||z(t,0,r,8),i(t,e,r,n,52,8),r+8}w.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),w.TYPED_ARRAY_SUPPORT)(o=this.subarray(t,e)).__proto__=w.prototype;else for(var n=e-t,o=new w(n,void 0),i=0;i<n;++i)o[i]=this[i+t];return o},w.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||q(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n},w.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||q(t,e,this.length);for(var n=this[t+--e],o=1;0<e&&(o*=256);)n+=this[t+--e]*o;return n},w.prototype.readUInt8=function(t,e){return e||q(t,1,this.length),this[t]},w.prototype.readUInt16LE=function(t,e){return e||q(t,2,this.length),this[t]|this[t+1]<<8},w.prototype.readUInt16BE=function(t,e){return e||q(t,2,this.length),this[t]<<8|this[t+1]},w.prototype.readUInt32LE=function(t,e){return e||q(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},w.prototype.readUInt32BE=function(t,e){return e||q(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},w.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||q(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},w.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||q(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},w.prototype.readInt8=function(t,e){return e||q(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},w.prototype.readInt16LE=function(t,e){e||q(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},w.prototype.readInt16BE=function(t,e){e||q(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},w.prototype.readInt32LE=function(t,e){return e||q(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},w.prototype.readInt32BE=function(t,e){return e||q(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},w.prototype.readFloatLE=function(t,e){return e||q(t,4,this.length),o(this,t,!0,23,4)},w.prototype.readFloatBE=function(t,e){return e||q(t,4,this.length),o(this,t,!1,23,4)},w.prototype.readDoubleLE=function(t,e){return e||q(t,8,this.length),o(this,t,!0,52,8)},w.prototype.readDoubleBE=function(t,e){return e||q(t,8,this.length),o(this,t,!1,52,8)},w.prototype.writeUIntLE=function(t,e,r,n){t=+t,e|=0,r|=0,n||x(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},w.prototype.writeUIntBE=function(t,e,r,n){t=+t,e|=0,r|=0,n||x(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},w.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,1,255,0),w.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},w.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,2,65535,0),w.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},w.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,2,65535,0),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},w.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,4,4294967295,0),w.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):N(this,t,e,!0),e+4},w.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,4,4294967295,0),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},w.prototype.writeIntLE=function(t,e,r,n){var o;t=+t,e|=0,n||x(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},w.prototype.writeIntBE=function(t,e,r,n){var o;t=+t,e|=0,n||x(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},w.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,1,127,-128),w.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},w.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,2,32767,-32768),w.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},w.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,2,32767,-32768),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},w.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,4,2147483647,-2147483648),w.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):N(this,t,e,!0),e+4},w.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||x(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},w.prototype.writeFloatLE=function(t,e,r){return K(this,t,e,!0,r)},w.prototype.writeFloatBE=function(t,e,r){return K(this,t,e,!1,r)},w.prototype.writeDoubleLE=function(t,e,r){return F(this,t,e,!0,r)},w.prototype.writeDoubleBE=function(t,e,r){return F(this,t,e,!1,r)},w.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||!w.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},w.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&&!w.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:W(new w(t,n).toString()),s=i.length,a=0;a<r-e;++a)this[a+e]=i[a%s];return this};var G=/[^+\/0-9A-Za-z-_]/g;function V(t){return t<16?"0"+t.toString(16):t.toString(16)}function W(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 J(t){return function(t){var e,r,n,o;c||p();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(G,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function $(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 Z(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}function H(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=w.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 Q(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=w.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 X(t,e){return g(g({},e),{},{headers:g(g({},e.headers),{},{Authorization:"Bearer ".concat(t)})})}function tt(t){var e=t.fetcher,r=t.url,n=t.basicAuth,o=t.body,a=t.tokenCache,u=t.requestState,h=t.pendingTasks,i=t.response,f=t.tokenCacheKey;e(r,{method:"POST",headers:{Authorization:"Basic ".concat(n),"Content-Length":w.byteLength(o).toString(),"Content-Type":"application/x-www-form-urlencoded"},body:o}).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);a.set({token:r,expirationTime:i,refreshToken:o},f),u.set(!1);var s=h.slice();h=[],s.forEach(function(t){var e=X(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);e&&(r.body=e),u.set(!1),i.reject(r)})}).catch(function(t){u.set(!1),i&&"function"==typeof i.reject&&i.reject(t)})}function et(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,p=t.fetch;if(!p&&"undefined"==typeof fetch)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");if(p=p||fetch,n.headers&&n.headers.authorization||n.headers&&n.headers.Authorization)e(n,o);else{var l=f.get(c);if(l&&l.token&&Date.now()<l.expirationTime)e(X(l.token,n),o);else if(u.push({request:n,response:o,next:e}),!h.get())if(h.set(!0),l&&l.refreshToken&&(!l.token||l.token&&Date.now()>l.expirationTime)){if(!r)throw new Error("Missing required options");tt(g(g({fetcher:p},Q(g(g({},r),{},{refreshToken:l.refreshToken}))),{},{tokenCacheKey:c,tokenCache:f,requestState:h,pendingTasks:u,response:o}))}else tt({fetcher:p,url:i,basicAuth:s,body:a,tokenCacheKey:c,tokenCache:f,requestState:h,pendingTasks:u,response:o})}}function rt(t){var e=t;return{get:function(){return e},set:function(t){return e=t}}}var nt=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=rt({}),i=[],s=rt(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):et(g(g({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=H(t);return t.credentials.anonymousId&&(r.body+="&anonymous_id=".concat(t.credentials.anonymousId)),g({},r)}(n)),{},{pendingTasks:i,requestState:s,tokenCache:o,fetch:n.fetch}),r,n)}}},t.createAuthMiddlewareForClientCredentialsFlow=function(o){var i=o.tokenCache||rt({token:"",expirationTime:-1}),s=rt(!1),a=[];return function(n){return function(t,e){var r;t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?n(t,e):et(g(g({request:t,response:e},H(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=rt({}),i=[],s=rt(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):et(g(g({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=w.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=rt({}),i=[],s=rt(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):et(g(g({request:t,response:e},Q(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=g(g({},t),{},{headers:g(g({},t.headers),{},{Authorization:i})});return o(n,e)}}},t.scopes=nt,Object.defineProperty(t,"__esModule",{value:!0})});

@@ -7,3 +7,3 @@ {

"name": "@commercetools/sdk-middleware-auth",
"version": "6.1.3",
"version": "6.1.4",
"description": "Middleware for different authentication flows of commercetools platform API, to use with @commercetools/sdk-client",

@@ -40,5 +40,5 @@ "keywords": [

"devDependencies": {
"nock": "12.0.2"
"nock": "12.0.3"
},
"gitHead": "a28b0742eeea89cbe04e7b4b4265df25c9f8f665"
"gitHead": "015a7a95bf67793d0cef452f592ff3ea6818aef3"
}

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