Socket
Socket
Sign inDemoInstall

@commercetools/sdk-middleware-auth

Package Overview
Dependencies
Maintainers
9
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 5.1.1 to 5.1.2

50

dist/commercetools-sdk-middleware-auth.cjs.js

@@ -20,16 +20,20 @@ 'use strict';

function _objectSpread(target) {
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (i % 2) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(arguments[i]));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}

@@ -159,8 +163,8 @@

if (options.credentials.anonymousId) result.body += "&anonymous_id=".concat(options.credentials.anonymousId);
return _objectSpread({}, result);
return _objectSpread2({}, result);
}
function mergeAuthHeader(token, req) {
return _objectSpread({}, req, {
headers: _objectSpread({}, req.headers, {
return _objectSpread2({}, req, {
headers: _objectSpread2({}, req.headers, {
Authorization: "Bearer ".concat(token)

@@ -285,5 +289,5 @@ })

if (tokenObj && tokenObj.refreshToken && (!tokenObj.token || tokenObj.token && Date.now() > tokenObj.expirationTime)) {
executeRequest(_objectSpread({
executeRequest(_objectSpread2({
fetcher: fetcher
}, buildRequestForRefreshTokenFlow(_objectSpread({}, userOptions, {
}, buildRequestForRefreshTokenFlow(_objectSpread2({}, userOptions, {
refreshToken: tokenObj.refreshToken

@@ -338,3 +342,3 @@ })), {

var params = _objectSpread({
var params = _objectSpread2({
request: request,

@@ -367,3 +371,3 @@ response: response

var params = _objectSpread({
var params = _objectSpread2({
request: request,

@@ -396,3 +400,3 @@ response: response

var params = _objectSpread({
var params = _objectSpread2({
request: request,

@@ -425,3 +429,3 @@ response: response

var params = _objectSpread({
var params = _objectSpread2({
request: request,

@@ -457,4 +461,4 @@ response: response

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

@@ -469,4 +473,2 @@ })

/* eslint-disable max-len */
exports.createAuthMiddlewareForAnonymousSessionFlow = createAuthMiddlewareForAnonymousSessionFlow;

@@ -473,0 +475,0 @@ exports.createAuthMiddlewareForClientCredentialsFlow = createAuthMiddlewareForClientCredentialsFlow;

@@ -16,16 +16,20 @@ function _defineProperty(obj, key, value) {

function _objectSpread(target) {
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (i % 2) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(arguments[i]));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}

@@ -155,8 +159,8 @@

if (options.credentials.anonymousId) result.body += "&anonymous_id=".concat(options.credentials.anonymousId);
return _objectSpread({}, result);
return _objectSpread2({}, result);
}
function mergeAuthHeader(token, req) {
return _objectSpread({}, req, {
headers: _objectSpread({}, req.headers, {
return _objectSpread2({}, req, {
headers: _objectSpread2({}, req.headers, {
Authorization: "Bearer ".concat(token)

@@ -281,5 +285,5 @@ })

if (tokenObj && tokenObj.refreshToken && (!tokenObj.token || tokenObj.token && Date.now() > tokenObj.expirationTime)) {
executeRequest(_objectSpread({
executeRequest(_objectSpread2({
fetcher: fetcher
}, buildRequestForRefreshTokenFlow(_objectSpread({}, userOptions, {
}, buildRequestForRefreshTokenFlow(_objectSpread2({}, userOptions, {
refreshToken: tokenObj.refreshToken

@@ -334,3 +338,3 @@ })), {

var params = _objectSpread({
var params = _objectSpread2({
request: request,

@@ -363,3 +367,3 @@ response: response

var params = _objectSpread({
var params = _objectSpread2({
request: request,

@@ -392,3 +396,3 @@ response: response

var params = _objectSpread({
var params = _objectSpread2({
request: request,

@@ -421,3 +425,3 @@ response: response

var params = _objectSpread({
var params = _objectSpread2({
request: request,

@@ -453,4 +457,4 @@ response: response

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

@@ -465,5 +469,3 @@ })

/* eslint-disable max-len */
export { createAuthMiddlewareForAnonymousSessionFlow, createAuthMiddlewareForClientCredentialsFlow, createAuthMiddlewareForPasswordFlow, createAuthMiddlewareForRefreshTokenFlow, createAuthMiddlewareWithExistingToken, scopes };
//# sourceMappingURL=commercetools-sdk-middleware-auth.es.js.map

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

!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 l(o){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{},e=Object.keys(i);"function"==typeof Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(i).filter(function(t){return Object.getOwnPropertyDescriptor(i,t).enumerable}))),e.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})}return o}var e="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 r(t){var e,r,n,o,i,s;c||p();var a=t.length;if(0<a%4)throw new Error("Invalid string. Length must be a multiple of 4");i="="===t[a-2]?2:"="===t[a-1]?1:0,s=new f(3*a/4-i),n=0<i?a-4:a;var u=0;for(r=e=0;e<n;e+=4,r+=3)o=h[t.charCodeAt(e)]<<18|h[t.charCodeAt(e+1)]<<12|h[t.charCodeAt(e+2)]<<6|h[t.charCodeAt(e+3)],s[u++]=o>>16&255,s[u++]=o>>8&255,s[u++]=255&o;return 2===i?(o=h[t.charCodeAt(e)]<<2|h[t.charCodeAt(e+1)]>>4,s[u++]=255&o):1===i&&(o=h[t.charCodeAt(e)]<<10|h[t.charCodeAt(e+1)]<<4|h[t.charCodeAt(e+2)]>>2,s[u++]=o>>8&255,s[u++]=255&o),s}function g(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(g(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 y.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function w(t,e){if(d()<e)throw new RangeError("Invalid typed array length");return y.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=y.prototype:(null===t&&(t=new y(e)),t.length=e),t}function y(t,e,r){if(!(y.TYPED_ARRAY_SUPPORT||this instanceof y))return new y(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);y.TYPED_ARRAY_SUPPORT?(t=e).__proto__=y.prototype:t=_(t,e);return t}(t,e,r,n):"string"==typeof e?function(t,e,r){"string"==typeof r&&""!==r||(r="utf8");if(!y.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|R(e,r),o=(t=w(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|b(e.length);return 0===(t=w(t,r)).length||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||(n=e.length)!=n?w(t,0):_(t,e);if("Buffer"===e.type&&a(e.data))return _(t,e.data)}var n;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=w(t,e<0?0:0|b(e)),!y.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function _(t,e){var r=e.length<0?0:0|b(e.length);t=w(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function b(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 V(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return W(t).length;default:if(n)return V(t).length;e=(""+e).toLowerCase(),n=!0}}function T(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=y.from(e,n)),m(e))return 0===e.length?-1:P(t,e,r,n,o);if("number"==typeof e)return e&=255,y.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):P(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function P(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):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 J(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function I(t,e,r){return 0===e&&r===t.length?n(t):n(t.slice(e,r))}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)}y.TYPED_ARRAY_SUPPORT=void 0===e.TYPED_ARRAY_SUPPORT||e.TYPED_ARRAY_SUPPORT,y.poolSize=8192,y._augment=function(t){return t.__proto__=y.prototype,t},y.from=function(t,e,r){return v(null,t,e,r)},y.TYPED_ARRAY_SUPPORT&&(y.prototype.__proto__=Uint8Array.prototype,y.__proto__=Uint8Array),y.alloc=function(t,e,r){return n=null,i=e,s=r,E(o=t),o<=0?w(n,o):void 0!==i?"string"==typeof s?w(n,o).fill(i,s):w(n,o).fill(i):w(n,o);var n,o,i,s},y.allocUnsafe=function(t){return A(null,t)},y.allocUnsafeSlow=function(t){return A(null,t)},y.isBuffer=function(t){return null!=t&&(!!t._isBuffer||$(t)||(e=t,"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&$(e.slice(0,0))));var e},y.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},y.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}},y.concat=function(t,e){if(!a(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return y.alloc(0);var r;if(void 0===e)for(r=e=0;r<t.length;++r)e+=t[r].length;var n=y.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},y.byteLength=R,y.prototype._isBuffer=!0,y.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},y.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},y.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},y.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?k(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 Y(this,e,r);case"utf8":case"utf-8":return k(this,e,r);case"ascii":return C(this,e,r);case"latin1":case"binary":return B(this,e,r);case"base64":return I(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return q(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},y.prototype.equals=function(t){if(!m(t))throw new TypeError("Argument must be a Buffer");return this===t||0===y.compare(this,t)},y.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+">"},y.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},y.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},y.prototype.indexOf=function(t,e,r){return S(this,t,e,r,!0)},y.prototype.lastIndexOf=function(t,e,r){return S(this,t,e,r,!1)},y.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,p,l,g=!1;;)switch(n){case"hex":return M(this,t,e,r);case"utf8":case"utf-8":return p=e,l=r,J(V(t,(c=this).length-p),c,p,l);case"ascii":return U(this,t,e,r);case"latin1":case"binary":return U(this,t,e,r);case"base64":return u=this,h=e,f=r,J(W(t),u,h,f);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return s=e,a=r,J(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}(t,(i=this).length-s),i,s,a);default:if(g)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),g=!0}},y.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var O=4096;function C(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 B(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 Y(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+=G(t[i]);return o}function q(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 D(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 L(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 j(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 x(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,o,i){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 F(t,e,r,n,o){return o||N(t,0,r,8),i(t,e,r,n,52,8),r+8}y.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),y.TYPED_ARRAY_SUPPORT)(r=this.subarray(t,e)).__proto__=y.prototype;else{var o=e-t;r=new y(o,void 0);for(var i=0;i<o;++i)r[i]=this[i+t]}return r},y.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||D(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n},y.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||D(t,e,this.length);for(var n=this[t+--e],o=1;0<e&&(o*=256);)n+=this[t+--e]*o;return n},y.prototype.readUInt8=function(t,e){return e||D(t,1,this.length),this[t]},y.prototype.readUInt16LE=function(t,e){return e||D(t,2,this.length),this[t]|this[t+1]<<8},y.prototype.readUInt16BE=function(t,e){return e||D(t,2,this.length),this[t]<<8|this[t+1]},y.prototype.readUInt32LE=function(t,e){return e||D(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},y.prototype.readUInt32BE=function(t,e){return e||D(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},y.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||D(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},y.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||D(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},y.prototype.readInt8=function(t,e){return e||D(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},y.prototype.readInt16LE=function(t,e){e||D(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},y.prototype.readInt16BE=function(t,e){e||D(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},y.prototype.readInt32LE=function(t,e){return e||D(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},y.prototype.readInt32BE=function(t,e){return e||D(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},y.prototype.readFloatLE=function(t,e){return e||D(t,4,this.length),o(this,t,!0,23,4)},y.prototype.readFloatBE=function(t,e){return e||D(t,4,this.length),o(this,t,!1,23,4)},y.prototype.readDoubleLE=function(t,e){return e||D(t,8,this.length),o(this,t,!0,52,8)},y.prototype.readDoubleBE=function(t,e){return e||D(t,8,this.length),o(this,t,!1,52,8)},y.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||L(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},y.prototype.writeUIntBE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||L(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},y.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,1,255,0),y.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},y.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,65535,0),y.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):j(this,t,e,!0),e+2},y.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,65535,0),y.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):j(this,t,e,!1),e+2},y.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,4294967295,0),y.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):x(this,t,e,!0),e+4},y.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,4294967295,0),y.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):x(this,t,e,!1),e+4},y.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);L(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},y.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);L(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},y.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,1,127,-128),y.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},y.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,32767,-32768),y.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):j(this,t,e,!0),e+2},y.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,32767,-32768),y.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):j(this,t,e,!1),e+2},y.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,2147483647,-2147483648),y.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):x(this,t,e,!0),e+4},y.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),y.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):x(this,t,e,!1),e+4},y.prototype.writeFloatLE=function(t,e,r){return z(this,t,e,!0,r)},y.prototype.writeFloatBE=function(t,e,r){return z(this,t,e,!1,r)},y.prototype.writeDoubleLE=function(t,e,r){return F(this,t,e,!0,r)},y.prototype.writeDoubleBE=function(t,e,r){return F(this,t,e,!1,r)},y.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||!y.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},y.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&&!y.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,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{var s=m(t)?t:V(new y(t,n).toString()),a=s.length;for(i=0;i<r-e;++i)this[i+e]=s[i%a]}return this};var K=/[^+\/0-9A-Za-z-_]/g;function G(t){return t<16?"0"+t.toString(16):t.toString(16)}function V(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-=1)<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 W(t){return r(function(t){var e;if((t=(e=t,e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")).replace(K,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function J(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 $(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}var Z="manage_project",H=Object.freeze({MANAGE_PROJECT:Z,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"});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)");var e=t.credentials,r=e.clientId,n=e.clientSecret;if(!r||!n)throw new Error("Missing required credentials (clientId, clientSecret)");var o="".concat(Z,":").concat(t.projectKey),i=(t.scopes||[o]).join(" "),s=y.from("".concat(r,":").concat(n)).toString("base64"),a=t.oauthUri||"/oauth/token";return{basicAuth:s,url:t.host.replace(/\/$/,"")+a,body:"grant_type=client_credentials&scope=".concat(i)}}function X(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=y.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 tt(t,e){return l({},e,{headers:l({},e.headers,{Authorization:"Bearer ".concat(t)})})}function et(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;e(r,{method:"POST",headers:{Authorization:"Basic ".concat(n),"Content-Length":y.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}),u.set(!1);var s=h.slice();h=[],s.forEach(function(t){var e=tt(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),i.reject(r)})}).catch(function(t){i&&"function"==typeof i.reject&&i.reject(t)})}function rt(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.fetch;if(!c&&"undefined"==typeof fetch)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");if(c||(c=fetch),n.headers&&n.headers.authorization||n.headers&&n.headers.Authorization)e(n,o);else{var p=f.get();if(p&&p.token&&Date.now()<p.expirationTime)e(tt(p.token,n),o);else u.push({request:n,response:o,next:e}),h.get()||(h.set(!0),p&&p.refreshToken&&(!p.token||p.token&&Date.now()>p.expirationTime)?et(l({fetcher:c},X(l({},r,{refreshToken:p.refreshToken})),{tokenCache:f,requestState:h,pendingTasks:u,response:o})):et({fetcher:c,url:i,basicAuth:s,body:a,tokenCache:f,requestState:h,pendingTasks:u,response:o}))}}function nt(t){var e=t;return{get:function(){return e},set:function(t){return e=t}}}t.createAuthMiddlewareForAnonymousSessionFlow=function(n){var o=nt({}),i=[],s=nt(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):rt(l({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=Q(t);return t.credentials.anonymousId&&(r.body+="&anonymous_id=".concat(t.credentials.anonymousId)),l({},r)}(n),{pendingTasks:i,requestState:s,tokenCache:o,fetch:n.fetch}),r,n)}}},t.createAuthMiddlewareForClientCredentialsFlow=function(n){var o=nt({}),i=[],s=nt(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):rt(l({request:t,response:e},Q(n),{pendingTasks:i,requestState:s,tokenCache:o,fetch:n.fetch}),r)}}},t.createAuthMiddlewareForPasswordFlow=function(n){var o=nt({}),i=[],s=nt(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):rt(l({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=y.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=nt({}),i=[],s=nt(!1);return function(r){return function(t,e){t.headers&&t.headers.authorization||t.headers&&t.headers.Authorization?r(t,e):rt(l({request:t,response:e},X(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=l({},t,{headers:l({},t.headers,{Authorization:i})});return o(n,e)}}},t.scopes=H,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 l(o){for(var t=1;t<arguments.length;t++)if(t%2){var i=null!=arguments[t]?arguments[t]:{},e=Object.keys(i);"function"==typeof Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(i).filter(function(t){return Object.getOwnPropertyDescriptor(i,t).enumerable}))),e.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})}else Object.defineProperties(o,Object.getOwnPropertyDescriptors(arguments[t]));return o}var e="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},u=[],f=[],h="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],f[t.charCodeAt(e)]=e;f["-".charCodeAt(0)]=62,f["_".charCodeAt(0)]=63}function g(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(g(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 r(t,e,r,n,o){var i,s,a=8*o-n-1,u=(1<<a)-1,f=u>>1,h=-7,c=r?o-1:0,p=r?-1:1,l=t[e+c];for(c+=p,i=l&(1<<-h)-1,l>>=-h,h+=a;0<h;i=256*i+t[e+c],c+=p,h-=8);for(s=i&(1<<-h)-1,i>>=-h,h+=n;0<h;s=256*s+t[e+c],c+=p,h-=8);if(0===i)i=1-f;else{if(i===u)return s?NaN:1/0*(l?-1:1);s+=Math.pow(2,n),i-=f}return(l?-1:1)*s*Math.pow(2,i-n)}function i(t,e,r,n,o,i){var s,a,u,f=8*i-o-1,h=(1<<f)-1,c=h>>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=h):(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),h<=s+c?(a=0,s=h):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,f+=o;0<f;t[r+l]=255&s,l+=g,s/=256,f-=8);t[r+l-g]|=128*d}var o={}.toString,s=Array.isArray||function(t){return"[object Array]"==o.call(t)};function a(){return w.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function d(t,e){if(a()<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 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);w.TYPED_ARRAY_SUPPORT?(t=e).__proto__=w.prototype:t=A(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|m(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(b(e)){var r=0|_(e.length);return 0===(t=d(t,r)).length||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):A(t,e);if("Buffer"===e.type&&s(e.data))return A(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|_(e)),!w.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function A(t,e){var r=e.length<0?0:0|_(e.length);t=d(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function _(t){if(t>=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function b(t){return!(null==t||!t._isBuffer)}function m(t,e){if(b(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 G(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return V(t).length;default:if(n)return G(t).length;e=(""+e).toLowerCase(),n=!0}}function R(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function T(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)),b(e))return 0===e.length?-1:P(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):P(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function P(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 f(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(o){var h=-1;for(i=r;i<a;i++)if(f(t,i)===f(e,-1===h?0:i-h)){if(-1===h&&(h=i),i-h+1===u)return h*s}else-1!==h&&(i-=i-h),h=-1}else for(a<r+u&&(r=a-u),i=r;0<=i;i--){for(var c=!0,p=0;p<u;p++)if(f(t,i+p)!==f(e,p)){c=!1;break}if(c)return i}return-1}function S(t,e,r,n){r=Number(r)||0;var o=t.length-r;n?o<(n=Number(n))&&(n=o):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 M(t,e,r,n){return W(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){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,f=t[o],h=null,c=239<f?4:223<f?3:191<f?2:1;if(o+c<=r)switch(c){case 1:f<128&&(h=f);break;case 2:128==(192&(i=t[o+1]))&&127<(u=(31&f)<<6|63&i)&&(h=u);break;case 3:i=t[o+1],s=t[o+2],128==(192&i)&&128==(192&s)&&2047<(u=(15&f)<<12|(63&i)<<6|63&s)&&(u<55296||57343<u)&&(h=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&f)<<18|(63&i)<<12|(63&s)<<6|63&a)&&u<1114112&&(h=u)}null===h?(h=65533,c=1):65535<h&&(h-=65536,n.push(h>>>10&1023|55296),h=56320|1023&h),n.push(h),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)}w.TYPED_ARRAY_SUPPORT=void 0===e.TYPED_ARRAY_SUPPORT||e.TYPED_ARRAY_SUPPORT,w.poolSize=8192,w._augment=function(t){return t.__proto__=w.prototype,t},w.from=function(t,e,r){return y(null,t,e,r)},w.TYPED_ARRAY_SUPPORT&&(w.prototype.__proto__=Uint8Array.prototype,w.__proto__=Uint8Array),w.alloc=function(t,e,r){return function(t,e,r,n){return v(e),e<=0?d(t,e):void 0!==r?"string"==typeof n?d(t,e).fill(r,n):d(t,e).fill(r):d(t,e)}(null,t,e,r)},w.allocUnsafe=function(t){return E(null,t)},w.allocUnsafeSlow=function(t){return E(null,t)},w.isBuffer=function(t){return null!=t&&(!!t._isBuffer||J(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&J(t.slice(0,0))}(t))},w.compare=function(t,e){if(!b(t)||!b(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(!s(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(!b(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(n,o),o+=i.length}return n},w.byteLength=m,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)R(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)R(this,e,e+3),R(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)R(this,e,e+7),R(this,e+1,e+6),R(this,e+2,e+5),R(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 B(this,e,r);case"utf8":case"utf-8":return I(this,e,r);case"ascii":return k(this,e,r);case"latin1":case"binary":return C(this,e,r);case"base64":return U(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Y(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(!b(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(!b(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),f=t.slice(e,r),h=0;h<a;++h)if(u[h]!==f[h]){i=u[h],s=f[h];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 T(this,t,e,r,!0)},w.prototype.lastIndexOf=function(t,e,r){return T(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,f,h,c,p,l,g=!1;;)switch(n){case"hex":return S(this,t,e,r);case"utf8":case"utf-8":return p=e,l=r,W(G(t,(c=this).length-p),c,p,l);case"ascii":return M(this,t,e,r);case"latin1":case"binary":return M(this,t,e,r);case"base64":return u=this,f=e,h=r,W(V(t),u,f,h);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return s=e,a=r,W(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}(t,(i=this).length-s),i,s,a);default:if(g)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),g=!0}},w.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var O=4096;function k(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 C(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 B(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+=K(t[i]);return o}function Y(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 D(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 q(t,e,r,n,o,i){if(!b(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 j(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 L(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 x(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 N(t,e,r,n,o){return o||x(t,0,r,4),i(t,e,r,n,23,4),r+4}function z(t,e,r,n,o){return o||x(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||D(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||D(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||D(t,1,this.length),this[t]},w.prototype.readUInt16LE=function(t,e){return e||D(t,2,this.length),this[t]|this[t+1]<<8},w.prototype.readUInt16BE=function(t,e){return e||D(t,2,this.length),this[t]<<8|this[t+1]},w.prototype.readUInt32LE=function(t,e){return e||D(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||D(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||D(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||D(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||D(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},w.prototype.readInt16LE=function(t,e){e||D(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||D(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||D(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||D(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||D(t,4,this.length),r(this,t,!0,23,4)},w.prototype.readFloatBE=function(t,e){return e||D(t,4,this.length),r(this,t,!1,23,4)},w.prototype.readDoubleLE=function(t,e){return e||D(t,8,this.length),r(this,t,!0,52,8)},w.prototype.readDoubleBE=function(t,e){return e||D(t,8,this.length),r(this,t,!1,52,8)},w.prototype.writeUIntLE=function(t,e,r,n){t=+t,e|=0,r|=0,n||q(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||q(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||q(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||q(this,t,e,2,65535,0),w.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):j(this,t,e,!0),e+2},w.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||q(this,t,e,2,65535,0),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):j(this,t,e,!1),e+2},w.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||q(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):L(this,t,e,!0),e+4},w.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||q(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):L(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);q(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);q(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||q(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||q(this,t,e,2,32767,-32768),w.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):j(this,t,e,!0),e+2},w.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||q(this,t,e,2,32767,-32768),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):j(this,t,e,!1),e+2},w.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||q(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):L(this,t,e,!0),e+4},w.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||q(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):L(this,t,e,!1),e+4},w.prototype.writeFloatLE=function(t,e,r){return N(this,t,e,!0,r)},w.prototype.writeFloatBE=function(t,e,r){return N(this,t,e,!1,r)},w.prototype.writeDoubleLE=function(t,e,r){return z(this,t,e,!0,r)},w.prototype.writeDoubleBE=function(t,e,r){return z(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=b(t)?t:G(new w(t,n).toString()),a=s.length;for(i=0;i<r-e;++i)this[i+e]=s[i%a]}return this};var F=/[^+\/0-9A-Za-z-_]/g;function K(t){return t<16?"0"+t.toString(16):t.toString(16)}function G(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-=1)<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 V(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 h(3*s/4-o),r=0<o?s-4:s;var a=0;for(e=0;e<r;e+=4,3)n=f[t.charCodeAt(e)]<<18|f[t.charCodeAt(e+1)]<<12|f[t.charCodeAt(e+2)]<<6|f[t.charCodeAt(e+3)],i[a++]=n>>16&255,i[a++]=n>>8&255,i[a++]=255&n;return 2==o?(n=f[t.charCodeAt(e)]<<2|f[t.charCodeAt(e+1)]>>4,i[a++]=255&n):1==o&&(n=f[t.charCodeAt(e)]<<10|f[t.charCodeAt(e+1)]<<4|f[t.charCodeAt(e+2)]>>2,i[a++]=n>>8&255,i[a++]=255&n),i}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(F,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function W(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 J(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}var $="manage_project",Z=Object.freeze({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"});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="".concat($,":").concat(t.projectKey),i=(t.scopes||[o]).join(" "),s=w.from("".concat(r,":").concat(n)).toString("base64"),a=t.oauthUri||"/oauth/token";return{basicAuth:s,url:t.host.replace(/\/$/,"")+a,body:"grant_type=client_credentials&scope=".concat(i)}}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 l({},e,{headers:l({},e.headers,{Authorization:"Bearer ".concat(t)})})}function tt(t){var e=t.fetcher,r=t.url,n=t.basicAuth,o=t.body,s=t.tokenCache,a=t.requestState,u=t.pendingTasks,i=t.response;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 r=t.access_token,e=t.expires_in,n=t.refresh_token,o=function(t){return Date.now()+1e3*t-72e5}(e);s.set({token:r,expirationTime:o,refreshToken:n}),a.set(!1);var i=u.slice();u=[],i.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),i.reject(r)})}).catch(function(t){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,f=t.requestState,h=t.tokenCache,c=t.fetch;if(!c&&"undefined"==typeof fetch)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");if(c=c||fetch,n.headers&&n.headers.authorization||n.headers&&n.headers.Authorization)e(n,o);else{var p=h.get();if(p&&p.token&&Date.now()<p.expirationTime)e(X(p.token,n),o);else u.push({request:n,response:o,next:e}),f.get()||(f.set(!0),p&&p.refreshToken&&(!p.token||p.token&&Date.now()>p.expirationTime)?tt(l({fetcher:c},Q(l({},r,{refreshToken:p.refreshToken})),{tokenCache:h,requestState:f,pendingTasks:u,response:o})):tt({fetcher:c,url:i,basicAuth:s,body:a,tokenCache:h,requestState:f,pendingTasks:u,response:o}))}}function rt(t){var e=t;return{get:function(){return e},set:function(t){return e=t}}}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(l({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)),l({},r)}(n),{pendingTasks:i,requestState:s,tokenCache:o,fetch:n.fetch}),r,n)}}},t.createAuthMiddlewareForClientCredentialsFlow=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(l({request:t,response:e},H(n),{pendingTasks:i,requestState:s,tokenCache:o,fetch:n.fetch}),r)}}},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(l({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(" "),f=u?"&scope=".concat(u):"",h=w.from("".concat(r,":").concat(n)).toString("base64"),c=t.oauthUri||"/oauth/".concat(i,"/customers/token");return{basicAuth:h,url:t.host.replace(/\/$/,"")+c,body:"grant_type=password&username=".concat(encodeURIComponent(s),"&password=").concat(encodeURIComponent(a)).concat(f)}}(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(l({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=l({},t,{headers:l({},t.headers,{Authorization:i})});return o(n,e)}}},t.scopes=Z,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=commercetools-sdk-middleware-auth.umd.min.js.map

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

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

@@ -45,3 +45,3 @@ "keywords": [

},
"gitHead": "6174f1cb95737926c8cc73a16fbc5e13342ace9d"
"gitHead": "b43af701481792e883437b92be227ce8bc2e0130"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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