@stackone/transport 2.7.2 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +62 -1
- package/dist/index.d.mts +62 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -122,7 +122,7 @@ var Or=9e15,kr=1e9,Ar=`0123456789abcdef`,jr=`2.302585092994045684017991454684364
|
|
|
122
122
|
* Copyright (c) 2023, Robert Eisele (robert@raw.org)
|
|
123
123
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
124
124
|
**/
|
|
125
|
-
(function(n){"use strict";var r=2e3,i={s:1,n:0,d:1};function a(e,t){if(isNaN(e=parseInt(e,10)))throw h();return e*t}function o(e,t){if(t===0)throw m();var n=Object.create(p.prototype);n.s=e<0?-1:1,e=e<0?-e:e;var r=f(e,t);return n.n=e/r,n.d=t/r,n}function s(e){for(var t={},n=e,r=2,i=4;i<=n;){for(;n%r===0;)n/=r,t[r]=(t[r]||0)+1;i+=1+2*r++}return n===e?t[e]=(t[e]||0)+1:n>1&&(t[n]=(t[n]||0)+1),t}var c=function(e,t){var n=0,r=1,o=1,s=0,c=0,l=0,u=1,d=1,f=0,p=1,_=1,v=1,y=1e7,b;if(e!=null)if(t!==void 0){if(n=e,r=t,o=n*r,n%1!=0||r%1!=0)throw g()}else switch(typeof e){case`object`:if(`d`in e&&`n`in e)n=e.n,r=e.d,`s`in e&&(n*=e.s);else if(0 in e)n=e[0],1 in e&&(r=e[1]);else throw h();o=n*r;break;case`number`:if(e<0&&(o=e,e=-e),e%1==0)n=e;else if(e>0){for(e>=1&&(d=10**Math.floor(1+Math.log(e)/Math.LN10),e/=d);p<=y&&v<=y;)if(b=(f+_)/(p+v),e===b){p+v<=y?(n=f+_,r=p+v):v>p?(n=_,r=v):(n=f,r=p);break}else e>b?(f+=_,p+=v):(_+=f,v+=p),p>y?(n=_,r=v):(n=f,r=p);n*=d}else (isNaN(e)||isNaN(t))&&(r=n=NaN);break;case`string`:if(p=e.match(/\d+|./g),p===null)throw h();if(p[f]===`-`?(o=-1,f++):p[f]===`+`&&f++,p.length===f+1?c=a(p[f++],o):p[f+1]===`.`||p[f]===`.`?(p[f]!==`.`&&(s=a(p[f++],o)),f++,(f+1===p.length||p[f+1]===`(`&&p[f+3]===`)`||p[f+1]===`'`&&p[f+3]===`'`)&&(c=a(p[f],o),u=10**p[f].length,f++),(p[f]===`(`&&p[f+2]===`)`||p[f]===`'`&&p[f+2]===`'`)&&(l=a(p[f+1],o),d=10**p[f+1].length-1,f+=3)):p[f+1]===`/`||p[f+1]===`:`?(c=a(p[f],o),u=a(p[f+2],1),f+=3):p[f+3]===`/`&&p[f+1]===` `&&(s=a(p[f],o),c=a(p[f+2],o),u=a(p[f+4],1),f+=5),p.length<=f){r=u*d,o=n=l+r*s+d*c;break}default:throw h()}if(r===0)throw m();i.s=o<0?-1:1,i.n=Math.abs(n),i.d=Math.abs(r)};function l(e,t,n){for(var r=1;t>0;e=e*e%n,t>>=1)t&1&&(r=r*e%n);return r}function u(e,t){for(;t%2==0;t/=2);for(;t%5==0;t/=5);if(t===1)return 0;for(var n=10%t,i=1;n!==1;i++)if(n=n*10%t,i>r)return 0;return i}function d(e,t,n){for(var r=1,i=l(10,n,t),a=0;a<300;a++){if(r===i)return a;r=r*10%t,i=i*10%t}return 0}function f(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function p(e,t){if(c(e,t),this instanceof p)e=f(i.d,i.n),this.s=i.s,this.n=i.n/e,this.d=i.d/e;else return o(i.s*i.n,i.d)}var m=function(){return Error(`Division by Zero`)},h=function(){return Error(`Invalid argument`)},g=function(){return Error(`Parameters must be integer`)};p.prototype={s:1,n:0,d:1,abs:function(){return o(this.n,this.d)},neg:function(){return o(-this.s*this.n,this.d)},add:function(e,t){return c(e,t),o(this.s*this.n*i.d+i.s*this.d*i.n,this.d*i.d)},sub:function(e,t){return c(e,t),o(this.s*this.n*i.d-i.s*this.d*i.n,this.d*i.d)},mul:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.n,this.d*i.d)},div:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.d,this.d*i.n)},clone:function(){return o(this.s*this.n,this.d)},mod:function(e,t){if(isNaN(this.n)||isNaN(this.d))return new p(NaN);if(e===void 0)return o(this.s*this.n%this.d,1);if(c(e,t),i.n===0&&this.d===0)throw m();return o(this.s*(i.d*this.n)%(i.n*this.d),i.d*this.d)},gcd:function(e,t){return c(e,t),o(f(i.n,this.n)*f(i.d,this.d),i.d*this.d)},lcm:function(e,t){return c(e,t),i.n===0&&this.n===0?o(0,1):o(i.n*this.n,f(i.n,this.n)*f(i.d,this.d))},ceil:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.ceil(e*this.s*this.n/this.d),e)},floor:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.floor(e*this.s*this.n/this.d),e)},round:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.round(e*this.s*this.n/this.d),e)},inverse:function(){return o(this.s*this.d,this.n)},pow:function(e,t){if(c(e,t),i.d===1)return i.s<0?o((this.s*this.d)**+i.n,this.n**+i.n):o((this.s*this.n)**+i.n,this.d**+i.n);if(this.s<0)return null;var n=s(this.n),r=s(this.d),a=1,l=1;for(var u in n)if(u!==`1`){if(u===`0`){a=0;break}if(n[u]*=i.n,n[u]%i.d===0)n[u]/=i.d;else return null;a*=u**+n[u]}for(var u in r)if(u!==`1`){if(r[u]*=i.n,r[u]%i.d===0)r[u]/=i.d;else return null;l*=u**+r[u]}return i.s<0?o(l,a):o(a,l)},equals:function(e,t){return c(e,t),this.s*this.n*i.d===i.s*i.n*this.d},compare:function(e,t){c(e,t);var n=this.s*this.n*i.d-i.s*i.n*this.d;return(0<n)-(n<0)},simplify:function(e){if(isNaN(this.n)||isNaN(this.d))return this;e||=.001;for(var t=this.abs(),n=t.toContinued(),r=1;r<n.length;r++){for(var i=o(n[r-1],1),a=r-2;a>=0;a--)i=i.inverse().add(n[a]);if(Math.abs(i.sub(t).valueOf())<e)return i.mul(this.s)}return this},divisible:function(e,t){return c(e,t),!(!(i.n*this.d)||this.n*i.d%(i.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,n+=` `,r%=i),n+=r,n+=`/`,n+=i),n},toLatex:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,r%=i),n+=`\\frac{`,n+=r,n+=`}{`,n+=i,n+=`}`),n},toContinued:function(){var e,t=this.n,n=this.d,r=[];if(isNaN(t)||isNaN(n))return r;do r.push(Math.floor(t/n)),e=t%n,t=n,n=e;while(t!==1);return r},toString:function(e){var t=this.n,n=this.d;if(isNaN(t)||isNaN(n))return`NaN`;e||=15;var r=u(t,n),i=d(t,n,r),a=this.s<0?`-`:``;if(a+=t/n|0,t%=n,t*=10,t&&(a+=`.`),r){for(var o=i;o--;)a+=t/n|0,t%=n,t*=10;a+=`(`;for(var o=r;o--;)a+=t/n|0,t%=n,t*=10;a+=`)`}else for(var o=e;t&&o--;)a+=t/n|0,t%=n,t*=10;return a}},typeof e==`object`?(Object.defineProperty(p,`__esModule`,{value:!0}),p.default=p,p.Fraction=p,t.exports=p):n.Fraction=p})(e)})),_a=c(ga(),1),va=`Fraction`,ya=[],ba=or(va,ya,()=>(Object.defineProperty(_a.default,`name`,{value:`Fraction`}),_a.default.prototype.constructor=_a.default,_a.default.prototype.type=`Fraction`,_a.default.prototype.isFraction=!0,_a.default.prototype.toJSON=function(){return{mathjs:`Fraction`,n:this.s*this.n,d:this.d}},_a.default.fromJSON=function(e){return new _a.default(e)},_a.default),{isClass:!0}),xa=`Matrix`,Sa=[],Ca=or(xa,Sa,()=>{function e(){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`)}return e.prototype.type=`Matrix`,e.prototype.isMatrix=!0,e.prototype.storage=function(){throw Error(`Cannot invoke storage on a Matrix interface`)},e.prototype.datatype=function(){throw Error(`Cannot invoke datatype on a Matrix interface`)},e.prototype.create=function(e,t){throw Error(`Cannot invoke create on a Matrix interface`)},e.prototype.subset=function(e,t,n){throw Error(`Cannot invoke subset on a Matrix interface`)},e.prototype.get=function(e){throw Error(`Cannot invoke get on a Matrix interface`)},e.prototype.set=function(e,t,n){throw Error(`Cannot invoke set on a Matrix interface`)},e.prototype.resize=function(e,t){throw Error(`Cannot invoke resize on a Matrix interface`)},e.prototype.reshape=function(e,t){throw Error(`Cannot invoke reshape on a Matrix interface`)},e.prototype.clone=function(){throw Error(`Cannot invoke clone on a Matrix interface`)},e.prototype.size=function(){throw Error(`Cannot invoke size on a Matrix interface`)},e.prototype.map=function(e,t){throw Error(`Cannot invoke map on a Matrix interface`)},e.prototype.forEach=function(e){throw Error(`Cannot invoke forEach on a Matrix interface`)},e.prototype[Symbol.iterator]=function(){throw Error(`Cannot iterate a Matrix interface`)},e.prototype.toArray=function(){throw Error(`Cannot invoke toArray on a Matrix interface`)},e.prototype.valueOf=function(){throw Error(`Cannot invoke valueOf on a Matrix interface`)},e.prototype.format=function(e){throw Error(`Cannot invoke format on a Matrix interface`)},e.prototype.toString=function(){throw Error(`Cannot invoke toString on a Matrix interface`)},e},{isClass:!0});function wa(e){return Object.keys(e.signatures||{}).reduce(function(e,t){var n=(t.match(/,/g)||[]).length+1;return Math.max(e,n)},-1)}var Ta=`DenseMatrix`,Ea=[`Matrix`],Da=or(Ta,Ea,e=>{var{Matrix:t}=e;function n(e,t){if(!(this instanceof n))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!Et(t))throw Error(`Invalid datatype: `+t);if(Dt(e))e.type===`DenseMatrix`?(this._data=sn(e._data),this._size=sn(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&M(e.data)&&M(e.size))this._data=e.data,this._size=e.size,Hn(this._data,this._size),this._datatype=t||e.datatype;else if(M(e))this._data=l(e),this._size=Bn(this._data),Hn(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+on(e)+`)`);else this._data=[],this._size=[0],this._datatype=t}n.prototype=new t,n.prototype.createDenseMatrix=function(e,t){return new n(e,t)},Object.defineProperty(n,`name`,{value:`DenseMatrix`}),n.prototype.constructor=n,n.prototype.type=`DenseMatrix`,n.prototype.isDenseMatrix=!0,n.prototype.getDataType=function(){return Qn(this._data,on)},n.prototype.storage=function(){return`dense`},n.prototype.datatype=function(){return this._datatype},n.prototype.create=function(e,t){return new n(e,t)},n.prototype.subset=function(e,t,n){switch(arguments.length){case 1:return r(this,e);case 2:case 3:return a(this,e,t,n);default:throw SyntaxError(`Wrong number of arguments`)}},n.prototype.get=function(e){if(!M(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new P(e.length,this._size.length);for(var t=0;t<e.length;t++)F(e[t],this._size[t]);for(var n=this._data,r=0,i=e.length;r<i;r++){var a=e[r];F(a,n.length),n=n[a]}return n},n.prototype.set=function(e,t,n){if(!M(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new P(e.length,this._size.length,`<`);var r,i,a,o=e.map(function(e){return e+1});c(this,o,n);var s=this._data;for(r=0,i=e.length-1;r<i;r++)a=e[r],F(a,s.length),s=s[a];return a=e[e.length-1],F(a,s.length),s[a]=t,this};function r(e,t){if(!Mt(t))throw TypeError(`Invalid index`);if(t.isScalar())return e.get(t.min());var r=t.size();if(r.length!==e._size.length)throw new P(r.length,e._size.length);for(var a=t.min(),o=t.max(),s=0,c=e._size.length;s<c;s++)F(a[s],e._size[s]),F(o[s],e._size[s]);return new n(i(e._data,t,r.length,0),e._datatype)}function i(e,t,n,r){var a=r===n-1,o=t.dimension(r);return a?o.map(function(t){return F(t,e.length),e[t]}).valueOf():o.map(function(a){F(a,e.length);var o=e[a];return i(o,t,n,r+1)}).valueOf()}function a(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Invalid index`);var i=t.size(),a=t.isScalar(),s;if(Dt(n)?(s=n.size(),n=n.valueOf()):s=Bn(n),a){if(s.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!ln(s,i))try{n=s.length===0?rr([n],i):rr(n,i),s=Bn(n)}catch{}if(i.length<e._size.length)throw new P(i.length,e._size.length,`<`);if(s.length<i.length){for(var l=0,u=0;i[l]===1&&s[l]===1;)l++;for(;i[l]===1;)u++,l++;n=Yn(n,i.length,u,s)}if(!ln(i,s))throw new P(i,s,`>`);c(e,t.max().map(function(e){return e+1}),r);var d=i.length;o(e._data,t,n,d,0)}return e}function o(e,t,n,r,i){var a=i===r-1,s=t.dimension(i);a?s.forEach(function(t,r){F(t),e[t]=n[r[0]]}):s.forEach(function(a,s){F(a),o(e[a],t,n[s[0]],r,i+1)})}n.prototype.resize=function(e,t,n){if(!Ot(e))throw TypeError(`Array or Matrix expected`);var r=e.valueOf().map(e=>Array.isArray(e)&&e.length===1?e[0]:e);return s(n?this.clone():this,r,t)};function s(e,t,n){if(t.length===0){for(var r=e._data;M(r);)r=r[0];return r}return e._size=t.slice(0),e._data=Un(e._data,e._size,n),e}n.prototype.reshape=function(e,t){var n=t?this.clone():this;return n._data=Gn(n._data,e),n._size=Kn(e,n._size.reduce((e,t)=>e*t)),n};function c(e,t,n){for(var r=e._size.slice(0),i=!1;r.length<t.length;)r.push(0),i=!0;for(var a=0,o=t.length;a<o;a++)t[a]>r[a]&&(r[a]=t[a],i=!0);i&&s(e,r,n)}n.prototype.clone=function(){return new n({data:sn(this._data),size:sn(this._size),datatype:this._datatype})},n.prototype.size=function(){return this._size.slice(0)},n.prototype.map=function(e){var t=this,r=wa(e),i=function n(i,a){return M(i)?i.map(function(e,t){return n(e,a.concat(t))}):r===1?e(i):r===2?e(i,a):e(i,a,t)}(this._data,[]);return new n(i,this._datatype===void 0?void 0:Qn(i,on))},n.prototype.forEach=function(e){var t=this;(function n(r,i){M(r)?r.forEach(function(e,t){n(e,i.concat(t))}):e(r,i,t)})(this._data,[])},n.prototype[Symbol.iterator]=function*(){yield*function*e(t,n){if(M(t))for(var r=0;r<t.length;r++)yield*e(t[r],n.concat(r));else yield{value:t,index:n}}(this._data,[])},n.prototype.rows=function(){var e=[];if(this.size().length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var t of this._data)e.push(new n([t],this._datatype));return e},n.prototype.columns=function(){var e=this,t=[],r=this.size();if(r.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var i=this._data,a=function(r){var a=i.map(e=>[e[r]]);t.push(new n(a,e._datatype))},o=0;o<r[1];o++)a(o);return t},n.prototype.toArray=function(){return sn(this._data)},n.prototype.valueOf=function(){return this._data},n.prototype.format=function(e){return Nn(this._data,e)},n.prototype.toString=function(){return Nn(this._data)},n.prototype.toJSON=function(){return{mathjs:`DenseMatrix`,data:this._data,size:this._size,datatype:this._datatype}},n.prototype.diagonal=function(e){if(e){if(j(e)&&(e=e.toNumber()),!A(e)||!N(e))throw TypeError(`The parameter k must be an integer number`)}else e=0;for(var t=e>0?e:0,r=e<0?-e:0,i=this._size[0],a=this._size[1],o=Math.min(i-r,a-t),s=[],c=0;c<o;c++)s[c]=this._data[c+r][c+t];return new n({data:s,size:[o],datatype:this._datatype})},n.diagonal=function(e,t,r,i){if(!M(e))throw TypeError(`Array expected, size parameter`);if(e.length!==2)throw Error(`Only two dimensions matrix are supported`);if(e=e.map(function(e){if(j(e)&&(e=e.toNumber()),!A(e)||!N(e)||e<1)throw Error(`Size values must be positive integers`);return e}),r){if(j(r)&&(r=r.toNumber()),!A(r)||!N(r))throw TypeError(`The parameter k must be an integer number`)}else r=0;var a=r>0?r:0,o=r<0?-r:0,s=e[0],c=e[1],l=Math.min(s-o,c-a),u;if(M(t)){if(t.length!==l)throw Error(`Invalid value array length`);u=function(e){return t[e]}}else if(Dt(t)){var d=t.size();if(d.length!==1||d[0]!==l)throw Error(`Invalid matrix length`);u=function(e){return t.get([e])}}else u=function(){return t};i||=j(u(0))?u(0).mul(0):0;var f=[];if(e.length>0){f=Un(f,e,i);for(var p=0;p<l;p++)f[p+o][p+a]=u(p)}return new n({data:f,size:[s,c]})},n.fromJSON=function(e){return new n(e)},n.prototype.swapRows=function(e,t){if(!A(e)||!N(e)||!A(t)||!N(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return F(e,this._size[0]),F(t,this._size[0]),n._swapRows(e,t,this._data),this},n._swapRows=function(e,t,n){var r=n[e];n[e]=n[t],n[t]=r};function l(e){return Dt(e)?l(e.valueOf()):M(e)?e.map(l):e}return n},{isClass:!0});function Oa(e,t,n){return e&&typeof e.map==`function`?e.map(function(e){return Oa(e,t,n)}):t(e)}var ka=`isNumeric`,Aa=[`typed`],ja=or(ka,Aa,e=>{var{typed:t}=e;return t(ka,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>Oa(t,e))})}),Ma=`hasNumericValue`,Na=[`typed`,`isNumeric`],Pa=or(Ma,Na,e=>{var{typed:t,isNumeric:n}=e;return t(Ma,{boolean:()=>!0,string:function(e){return e.trim().length>0&&!isNaN(Number(e))},any:function(e){return n(e)}})}),Fa=oa({config:hn}),Ia=ha({}),La=ba({}),Ra=Ca({}),za=Da({Matrix:Ra}),Ba=Cr({BigNumber:Fa,Complex:Ia,DenseMatrix:za,Fraction:La}),Va=ja({typed:Ba}),Ha=Pa({isNumeric:Va,typed:Ba});const Ua=e=>{let t=Number(e);return Number.isNaN(t)?!1:t>=120&&t<=36e4},Wa=e=>{let t=Number(e),n=Date.now();return Number.isNaN(t)?n+1e3:!Ua(t)&&(0,l.isFutureUnixTimestamp)(t)?bt(t):Ua(t)?n+t:n+t*_t},Ga=`ratelimitlimit`,Ka=`ratelimitremaining`,qa=`ratelimitreset`,Ja=`ratelimitconcurrencylimit`,Ya=`ratelimitconcurrencyremaining`,Xa=`ratelimitconcurrencyreset`,Za=e=>{let t={};for(let[n,r]of Object.entries(e)){let e=n.toLowerCase().replace(/^x-/,``).replace(/concurren.+-/g,`concurrency-`).replace(/-/g,``);t[e]=Ha(r)?Number(r):null}return t},Qa=e=>{let t=Za(e);return{rateLimitLimit:t.ratelimitlimit,rateLimitRemaining:t.ratelimitremaining,rateLimitReset:Wa(t.ratelimitreset),concurrencyLimit:t.ratelimitconcurrencylimit,concurrencyRemaining:t.ratelimitconcurrencyremaining,concurrencyReset:Wa(t.ratelimitconcurrencyreset)}},$a=e=>{let{accountSecureId:t,service:n,resource:r,subResource:i,childResource:a,action:o,behaviours:s}=e??{};return[t,n,r,o].some(l.isMissing)?null:[t,n,r,i,a,o,...s??[]].filter(Boolean).join(`-`)},eo=(e,t=10,n=1)=>{let r=Date.now();return(0,l.isFutureUnixTimestamp)(e)||(0,l.isNumber)(e)?to(Number(e),r,t,n):Et(e)&&e!==``?no(e,r,t,n):n},to=(e,t,n=10,r=1)=>{if(e<n)return e;let i=bt(e);if(i>t){let e=Math.floor((i-t)/_t);return e>0&&e<n?e:r}return r},no=(e,t,n=10,r=1)=>{if(vt.test(e)){let t=parseFloat(e);return t>0&&t<n?t:r}let i=new Date(e);if(Number.isNaN(i.getTime()))return r;let a=i.getTime();if(a>t){let e=Math.floor((a-t)/_t);return e>0&&e<n?e:r}return r},ro=({axiosInstance:e,logger:t,requestConfig:n,context:r})=>async i=>{let{response:a,config:o}=i;if(o?.signal?.aborted)return Promise.reject(lt(`Request aborted`,o,`ERR_CANCELED`,a));let{status:s,retryAfter:c}=io(a,r,n,t);if(s===429&&(0,l.notMissing)(o)){let n=eo(c);if(o._retryCount>=5)return t?.warning({category:`http-transport`,message:`Max retries exceeded for ${o?.url}. Aborting.`,context:{...r??{},retryAfterHeader:c,retryAfterAsNumber:n}}),Promise.reject(i);let s=o._retryCount??0,u={...o,_retryCount:s+1},d=c?n*_t:(0,l.exponentialBackoffInMS)(u._retryCount);return t?.debug({category:`http-transport`,message:`Received 429 error from ${o?.url}`,context:{...r??{},retryAfterHeader:c,calculatedRetryAfter:d}}),await ut(d,o,a),e?.request(u)}return Promise.reject(i)},io=(e,t,n,r)=>{let{provider:i}=t??{},{status:a,headers:o,data:s}=e??{},{retryafter:c}=Za(o??{});if((0,l.isMissing)(i)||(0,l.isMissing)(e))return r?.warning({category:`http-transport`,message:`Invalid parameters for convertError`,context:{...t,responseIsMissing:(0,l.isMissing)(e),providerIsMissing:(0,l.isMissing)(i),status:e?.status??`undefined`,statusText:e?.statusText??`undefined`,retryafter:c??`undefined`}}),{status:a,retryAfter:c};let u=n?.rateLimits?.mappedRateLimitErrors;if((0,l.notMissing)(u)&&(0,l.notMissing)(s))for(let e of u){let{errorStatus:t,errorMessagePath:n,errorMessage:r,retryAfterPath:i,retryAfterUnit:u,retryAfterValue:d}=e;if(t!==a)continue;let f=n??`message`,p=ao((0,l.isObject)(s)?(0,g.JSONPath)({path:f,json:s})[0]:s,r);if(t===a&&p){let e=so(d??oo(o,i),u);return{status:429,retryAfter:c??e}}}return{status:a,retryAfter:c}},ao=(e,t)=>t instanceof RegExp?t.test(e??``):e?.includes(t)??!1,oo=(e,t)=>(0,l.notMissing)(t)&&(0,l.notMissing)(e)?(0,g.JSONPath)({path:t,json:e})[0]:null,so=(e,t=`seconds`)=>(0,l.notMissing)(e)?co(e,t):null,co=(e,t)=>{if(t===`seconds`)return typeof e==`string`?parseFloat(e):e;if(t===`milliseconds`)return(typeof e==`string`?parseFloat(e):e)/_t;if(t===`date`){let t=typeof e==`string`&&!isNaN(Number(e))?parseFloat(e):e,n=new Date(t);if(isNaN(n.getTime()))throw Error(`Invalid date value`);return n.getTime()}throw Error(`Invalid type`)},lo=`rateLimitErrorInterceptor`,uo=({axiosInstance:e,logger:t,requestConfig:n,context:r,concurrencyManager:i})=>async a=>{let{response:o,config:s}=a,c=s?.signal;if((0,l.isMissing)(r)||(0,l.isMissing)(s))return t?.warning({category:`HttpClient`,message:`No context or config for this response - that doesn't seem right.`,context:{interceptor:lo,...s,httpsAgent:void 0,headers:void 0,hasContext:(0,l.notMissing)(r),hasConfig:(0,l.notMissing)(s)},code:ct.InterceptorContextNotPresent}),Promise.reject(a);if((0,l.isMissing)(i))return t?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:lo,...s,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:(0,l.notMissing)(i)},code:ct.RateLimitOrConcurrencyManagerNotInitialized}),Promise.reject(a);let{requestId:u,targetConcurrencyKey:d,leaseSubscription:f,setRemovalSubscription:p}=s?.requestMetadata??{};if(!((0,l.notMissing)(u)&&(0,l.notMissing)(d)&&await i.releaseRequest(u,d))&&(0,l.notMissing)(s?.requestMetadata)&&t?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{...r,interceptor:lo,requestId:u,targetConcurrencyKey:d,leaseSubscription:f,setRemovalSubscription:p},code:ct.RateLimiterReleaseRequestFailed}),c?.aborted)return Promise.reject(lt(`Request aborted`,s,`ERR_CANCELED`,o));let{status:m,retryAfter:h}=io(o,r,n,t);if(m===429&&(0,l.notMissing)(s)){let n=eo(h);if(s._retryCount>=5)return t?.warning({category:`HttpClient`,message:`Max retries exceeded for ${s.url}. Aborting.`,context:{...r??{},...s.requestMetadata??{},retryAfterHeader:h,retryAfterAsNumber:n}}),Promise.reject(a);let i=s?._retryCount??0,c={...s,_retryCount:i+1},u=h?n*_t:(0,l.exponentialBackoffInMS)(c._retryCount);return t?.debug({category:`HttpClient`,message:`Received 429 error from ${s.url}`,context:{...r,retryAfterHeader:h,calculatedRetryAfter:u}}),await ut(u,s,o),e?.request(c)}return Promise.reject(a)},fo=`rateLimitResponseInterceptor`,po=({logger:e,context:t,concurrencyManager:n})=>async r=>{let i=r?.config,a=i?.signal;if((0,l.isMissing)(t))e?.warning({category:`HttpClient`,message:`No context for this response - that doesn't seem right.`,context:{interceptor:fo,...i,httpsAgent:void 0,headers:void 0}});else if((0,l.isMissing)(n))return e?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:fo,...i,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:(0,l.notMissing)(n)},code:ct.RateLimitOrConcurrencyManagerNotInitialized}),r;else if((0,l.notMissing)(t.provider)&&(0,l.notMissing)(t.accountSecureId)){let t=r?.headers;if((0,l.notMissing)(t)){let n=Qa(t);e?.debug({category:`HttpClient`,message:`Rate limit headers extracted`,context:{interceptor:fo,rateLimitHeaders:n}})}let{requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:u}=i?.requestMetadata??{};if(await n.releaseRequest(o,s)||e?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{interceptor:fo,requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:u},code:ct.RateLimiterReleaseRequestFailed}),a?.aborted)return Promise.reject(lt(`Request aborted`,i,`ERR_CANCELED`,r))}return r},mo=e=>(e.validateStatus??=e=>e>=200&&e<300,e),ho=[{onFulfilled:mo,onRejected:null,options:void 0}],go=[{onFulfilled:null,onRejected:ro},{onFulfilled:null,onRejected:it}],_o=[{onFulfilled:mo,onRejected:null,options:void 0},{onFulfilled:ft,onRejected:null,options:void 0}],vo=[{onFulfilled:po,onRejected:uo},{onFulfilled:null,onRejected:it}],yo=1,bo=1e3,xo=0,So=59,Co=.8,wo=500;var To=class extends _e{constructor(...e){super(...e),this.name=`RateLimitManager`}async additionalInitialization(){}getDynamicMaxWaitTime(e,t,n,r=59,i=.8,a=500){this.readyCheck();let o=e.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.rateLimit??e.mainRatelimit;if(o<=0)throw Error(`Requests per second (rps) must be greater than 0.`);let s=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.maxConcurrency??t.mainMaxConcurrency;if(s<=0)throw Error(`Concurrency must be greater than 0.`);let c=r*i,l=1/Math.min(o,s/(a/1e3)),u=Math.max(7.5,c*l);return Math.min(c,u)}async getWaitTime(e,t,n){this.readyCheck();let r=`rateLimit:${e}`,i=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.subPoolKey,a=(0,l.notMissing)(i)?`${r}-${i}`:r,{mainRatelimit:o,subPools:s}=t,c=[{key:r,rateLimit:o},...s?.map(e=>{let{subPoolKey:t,rateLimit:n}=e;return{key:`${r}-${t}`,rateLimit:n}})??[]],u=c.map(e=>e.key),d=c.map(e=>e.rateLimit);return await this.executeScript(st.incr,[a,...u],[o.toString(),...d.map(String)])??0}readyCheck(){if(!this.cacheClient||!this.scriptMap?.size)throw Error(`RateLimitManager not ready`)}isReady(){return!!this?.cacheClient&&!!this?.scriptMap?.size}close(){this.scriptMap?.clear(),this.reset()}},Z=class{static{this.instances=new Map}static async prepare(e,t,...n){if(!this.instances.has(e)){let t=new e;t.getSingleton=e=>{let t=this.instances.get(e);if((0,l.isMissing)(t))throw Error(`Singleton ${e.name} not prepared yet`);if(t.hasInitFailed?.())throw Error(`${e.name} initialization failed`);let n=t.getInstanceIfReady?.();if((0,l.notMissing)(n))return n;throw Error(`${e.name} not ready`)},this.instances.set(e,t)}let r=this.instances.get(e);try{return await r.getInstance(t,...n)}catch(t){throw r.hasInitFailed?.()&&this.instances.delete(e),t}}static getIfReady(e){return this.instances.get(e)?.getInstanceIfReady?.()??null}static reset(e){this.instances.get(e)?.reset?.(),this.instances.delete(e)}static cleanupFailed(){let e=0;for(let[t,n]of this.instances){let r=n;r?.hasInitFailed?.()&&(r?.reset?.(),this.instances.delete(t),e++)}return e}};let Eo=function(e){return e.HttpTransportInstanceCreateError=`HttpTransportInstanceCreateError`,e}({});const Do=async({logger:e,redisClientConfig:t,context:n,requestConfig:r,httpsAgentConfig:i}={})=>{let a,{NODE_ENV:o}=process.env,s=n?.behaviours??[`CONCURRENCY`,`RETRY`];try{if(a=s.includes(`RETRY`)?ko(e,n):Oo(e,n),(0,l.isMissing)(n?.service)||(0,l.isMissing)(n?.organizationId)||o===`test`||(0,l.isMissing)(t)||(0,l.isMissing)(e))return a;let c=Z.getIfReady(To)??void 0,u=Z.getIfReady(Ke)??void 0,d=c?.isReady(),f=u?.isRedisConfigured(),p=[],m=[];if(s.includes(`CONCURRENCY`)){if(!f)throw Error(`Concurrency Manager cannot connect to Redis. Cannot create advanced transport instance.`);if(!d)throw Error(`RateLimitManager is not ready. Cannot create advanced transport instance.`);p.push(..._o),m.push(...vo)}let h=$a(n);if((0,l.isMissing)(h))return e?.warning({category:`http-transport`,message:`Unable to create a key for transport instance - Invalid state. Using base default instance.`,context:{...n,defaultInstanceInitialized:(0,l.notMissing)(a)}}),a;let g=await rt.get(h);if((0,l.notMissing)(g))return g;let _={interceptors:{requestConfigs:p,responseConfigs:m},instanceConfig:{maxBodyLength:1/0},logger:e,context:n,requestConfig:r,httpsAgentConfig:i,concurrencyManager:u,rateLimitManager:c},v=et.createInstance(_);return e?.debug({category:`http-transport`,message:`Creating new Axios instance and caching it for key: [${h}]`,context:{...n}}),await rt.set(h,v),v}catch(t){return e?.error({category:`http-transport`,message:`Failed to create advanced transport instance. Using default instance.`,context:{...n,usingDefaultInstance:(0,l.notMissing)(a)},error:t,code:Eo.HttpTransportInstanceCreateError}),(0,l.notMissing)(a)?a:Ao()}},Oo=(e,t)=>{let n={instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return et.createInstance(n)??Ao()},ko=(e,t)=>{let n={interceptors:{requestConfigs:ho,responseConfigs:go},instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return et.createInstance(n)??Ao()},Ao=()=>f.default.create({maxBodyLength:1/0});var jo=class{#e;#t;#n;#r;#i;#a;constructor({transportFactory:e=Do,getRedisClient:t=fe,logger:n,redisClientConfig:r,errorMappingFn:i}={}){this.name=`HttpClient`,this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}#o({url:e,payload:t,method:n,context:r}){if(!r?.accountSecureId||r.accountSecureId.length<20||!e||!n)return null;let i=t?(0,l.getContentHash)(t):``;return`${r.accountSecureId}-${n.toUpperCase()}${i}-${e}`}async#s({url:e,payload:t,method:n,cacheTTL:r,context:i}){if(!this.#a||!r||r<=0)return null;let a=this.#o({url:e,payload:t,method:n,context:i});if(!a)return null;let o=await this.#a.getData(a);return o?(this.#n?.debug({category:this.name,message:`Cache hit for key [${a}].`}),o):(this.#n?.debug({category:this.name,message:`Cache miss for key [${a}].`}),null)}async#c({url:e,payload:t,method:n,cacheTTL:r,context:i,response:a}){if(!this.#a||!r||r<=0)return!1;let o=this.#o({url:e,payload:t,method:n,context:i});return o?(this.#n?.debug({category:this.name,message:`Caching result for key [${o}].`}),this.#a.setData({key:o,value:a,cacheTTL:r*60})):!1}async request({headers:e={},url:t,method:n=`get`,queryParams:r,maxRedirects:i=0,responseType:a,cacheTTL:o,context:s,traceId:c,payload:u,httpsAgent:d,httpAgent:f,requestConfig:p,httpsAgentConfig:m}){try{(0,l.notMissing)(this.#r)&&(0,l.isMissing)(this.#a)&&(this.#a=await this.#t(this.#r,this.#n,`HttpClient`));let h=this.#_(t,r),g=this.#l(e),_=this.#m(u,e),v=await this.#s({url:h,payload:_,method:n,cacheTTL:o,context:s});if(v)return{...v,responseTime:new Date};let y=nt.getInstance(),b=((0,l.notMissing)(c)?await y.get(c):null)?.signal,x=await(await this.#e({redisClientConfig:this.#r,logger:this.#n,context:s,requestConfig:p,httpsAgentConfig:m})).request({headers:g,url:h,method:n,maxRedirects:i,responseType:a,data:_,httpsAgent:d,httpAgent:f,signal:b}),S={data:x.data,status:x.status,body:_,method:n,headers:this.#u(x.headers),requestUrl:t,responseType:x?.config?.responseType,responseTime:new Date};return await this.#c({url:h,payload:_,method:n,cacheTTL:o,context:s,response:S}),S}catch(e){let r=e;r.url=(0,_.redactUrl)(t),this.#n?.warning({category:this.name,message:`Request error [${n?.toUpperCase()} ${r.url}]: ${r.message}.`,error:r});let i=this.#h(r);throw(0,l.notMissing)(i)?i:e}}async get({headers:e,url:t,queryParams:n,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s}){return this.request({url:t,method:`get`,queryParams:n,headers:e,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s})}async post({headers:e,url:t,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s}){return this.request({url:t,method:`post`,headers:e,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s})}#l(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n.toLowerCase()]=e[n]||``}),t}#u(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n]=e[n]||``}),t}#d(e){return e[`content-type`]===`application/x-www-form-urlencoded`}#f(e){return e[`content-type`]?.startsWith(`multipart/form-data`)??!1}#p(e){return(0,l.isMissing)(e)||typeof e!=`object`||!e?!1:`pipe`in e&&typeof e.pipe==`function`}#m(e,t){if(!((0,l.isMissing)(e)||(0,l.isObject)(e)&&Object.keys(e).length===0))return this.#f(t)||this.#p(e)?e:this.#d(t)?v.default.stringify(e):e}#h(e){if((0,f.isAxiosError)(e)&&this.#i)return this.#i(e)}#g(e){return typeof e==`object`&&!!e&&`value`in e&&(typeof e.value==`string`||Array.isArray(e.value))}#_(e,t){if((0,l.isMissing)(t)||Object.keys(t).length===0)return e;let n={},r={},i={},a={};for(let[e,o]of Object.entries(t))if(this.#g(o)){let t=o.arrayFormat,s=o.value;t===`repeat`?r[e]=Array.isArray(s)?s:[s]:t===`brackets`?i[e]=Array.isArray(s)?s:[s]:t===`comma`?a[e]=Array.isArray(s)?s:[s]:n[e]=s}else n[e]=o;let o=[];Object.keys(n).length>0&&o.push(v.default.stringify(n)),Object.keys(r).length>0&&o.push(v.default.stringify(r,{arrayFormat:`repeat`})),Object.keys(i).length>0&&o.push(v.default.stringify(i,{arrayFormat:`brackets`})),Object.keys(a).length>0&&o.push(v.default.stringify(a,{arrayFormat:`comma`}));let s=o.join(`&`);return(0,l.notMissing)(s)?`${e}?${s}`:e}};const Mo=(e,t,n)=>new jo({redisClientConfig:e,logger:t,errorMappingFn:n});var No=class{static{this.httpClientInstance=null}static async getInstance({redisClientConfig:e,logger:t,errorMappingFn:n,getHttpClient:r=Mo}){return this.httpClientInstance??=r(e,t,n),this.httpClientInstance}static resetInstance(){this.httpClientInstance=null}};const Po=[`get`,`post`,`put`,`delete`,`patch`],Fo={[O.rPush]:`
|
|
125
|
+
(function(n){"use strict";var r=2e3,i={s:1,n:0,d:1};function a(e,t){if(isNaN(e=parseInt(e,10)))throw h();return e*t}function o(e,t){if(t===0)throw m();var n=Object.create(p.prototype);n.s=e<0?-1:1,e=e<0?-e:e;var r=f(e,t);return n.n=e/r,n.d=t/r,n}function s(e){for(var t={},n=e,r=2,i=4;i<=n;){for(;n%r===0;)n/=r,t[r]=(t[r]||0)+1;i+=1+2*r++}return n===e?t[e]=(t[e]||0)+1:n>1&&(t[n]=(t[n]||0)+1),t}var c=function(e,t){var n=0,r=1,o=1,s=0,c=0,l=0,u=1,d=1,f=0,p=1,_=1,v=1,y=1e7,b;if(e!=null)if(t!==void 0){if(n=e,r=t,o=n*r,n%1!=0||r%1!=0)throw g()}else switch(typeof e){case`object`:if(`d`in e&&`n`in e)n=e.n,r=e.d,`s`in e&&(n*=e.s);else if(0 in e)n=e[0],1 in e&&(r=e[1]);else throw h();o=n*r;break;case`number`:if(e<0&&(o=e,e=-e),e%1==0)n=e;else if(e>0){for(e>=1&&(d=10**Math.floor(1+Math.log(e)/Math.LN10),e/=d);p<=y&&v<=y;)if(b=(f+_)/(p+v),e===b){p+v<=y?(n=f+_,r=p+v):v>p?(n=_,r=v):(n=f,r=p);break}else e>b?(f+=_,p+=v):(_+=f,v+=p),p>y?(n=_,r=v):(n=f,r=p);n*=d}else (isNaN(e)||isNaN(t))&&(r=n=NaN);break;case`string`:if(p=e.match(/\d+|./g),p===null)throw h();if(p[f]===`-`?(o=-1,f++):p[f]===`+`&&f++,p.length===f+1?c=a(p[f++],o):p[f+1]===`.`||p[f]===`.`?(p[f]!==`.`&&(s=a(p[f++],o)),f++,(f+1===p.length||p[f+1]===`(`&&p[f+3]===`)`||p[f+1]===`'`&&p[f+3]===`'`)&&(c=a(p[f],o),u=10**p[f].length,f++),(p[f]===`(`&&p[f+2]===`)`||p[f]===`'`&&p[f+2]===`'`)&&(l=a(p[f+1],o),d=10**p[f+1].length-1,f+=3)):p[f+1]===`/`||p[f+1]===`:`?(c=a(p[f],o),u=a(p[f+2],1),f+=3):p[f+3]===`/`&&p[f+1]===` `&&(s=a(p[f],o),c=a(p[f+2],o),u=a(p[f+4],1),f+=5),p.length<=f){r=u*d,o=n=l+r*s+d*c;break}default:throw h()}if(r===0)throw m();i.s=o<0?-1:1,i.n=Math.abs(n),i.d=Math.abs(r)};function l(e,t,n){for(var r=1;t>0;e=e*e%n,t>>=1)t&1&&(r=r*e%n);return r}function u(e,t){for(;t%2==0;t/=2);for(;t%5==0;t/=5);if(t===1)return 0;for(var n=10%t,i=1;n!==1;i++)if(n=n*10%t,i>r)return 0;return i}function d(e,t,n){for(var r=1,i=l(10,n,t),a=0;a<300;a++){if(r===i)return a;r=r*10%t,i=i*10%t}return 0}function f(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function p(e,t){if(c(e,t),this instanceof p)e=f(i.d,i.n),this.s=i.s,this.n=i.n/e,this.d=i.d/e;else return o(i.s*i.n,i.d)}var m=function(){return Error(`Division by Zero`)},h=function(){return Error(`Invalid argument`)},g=function(){return Error(`Parameters must be integer`)};p.prototype={s:1,n:0,d:1,abs:function(){return o(this.n,this.d)},neg:function(){return o(-this.s*this.n,this.d)},add:function(e,t){return c(e,t),o(this.s*this.n*i.d+i.s*this.d*i.n,this.d*i.d)},sub:function(e,t){return c(e,t),o(this.s*this.n*i.d-i.s*this.d*i.n,this.d*i.d)},mul:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.n,this.d*i.d)},div:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.d,this.d*i.n)},clone:function(){return o(this.s*this.n,this.d)},mod:function(e,t){if(isNaN(this.n)||isNaN(this.d))return new p(NaN);if(e===void 0)return o(this.s*this.n%this.d,1);if(c(e,t),i.n===0&&this.d===0)throw m();return o(this.s*(i.d*this.n)%(i.n*this.d),i.d*this.d)},gcd:function(e,t){return c(e,t),o(f(i.n,this.n)*f(i.d,this.d),i.d*this.d)},lcm:function(e,t){return c(e,t),i.n===0&&this.n===0?o(0,1):o(i.n*this.n,f(i.n,this.n)*f(i.d,this.d))},ceil:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.ceil(e*this.s*this.n/this.d),e)},floor:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.floor(e*this.s*this.n/this.d),e)},round:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.round(e*this.s*this.n/this.d),e)},inverse:function(){return o(this.s*this.d,this.n)},pow:function(e,t){if(c(e,t),i.d===1)return i.s<0?o((this.s*this.d)**+i.n,this.n**+i.n):o((this.s*this.n)**+i.n,this.d**+i.n);if(this.s<0)return null;var n=s(this.n),r=s(this.d),a=1,l=1;for(var u in n)if(u!==`1`){if(u===`0`){a=0;break}if(n[u]*=i.n,n[u]%i.d===0)n[u]/=i.d;else return null;a*=u**+n[u]}for(var u in r)if(u!==`1`){if(r[u]*=i.n,r[u]%i.d===0)r[u]/=i.d;else return null;l*=u**+r[u]}return i.s<0?o(l,a):o(a,l)},equals:function(e,t){return c(e,t),this.s*this.n*i.d===i.s*i.n*this.d},compare:function(e,t){c(e,t);var n=this.s*this.n*i.d-i.s*i.n*this.d;return(0<n)-(n<0)},simplify:function(e){if(isNaN(this.n)||isNaN(this.d))return this;e||=.001;for(var t=this.abs(),n=t.toContinued(),r=1;r<n.length;r++){for(var i=o(n[r-1],1),a=r-2;a>=0;a--)i=i.inverse().add(n[a]);if(Math.abs(i.sub(t).valueOf())<e)return i.mul(this.s)}return this},divisible:function(e,t){return c(e,t),!(!(i.n*this.d)||this.n*i.d%(i.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,n+=` `,r%=i),n+=r,n+=`/`,n+=i),n},toLatex:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,r%=i),n+=`\\frac{`,n+=r,n+=`}{`,n+=i,n+=`}`),n},toContinued:function(){var e,t=this.n,n=this.d,r=[];if(isNaN(t)||isNaN(n))return r;do r.push(Math.floor(t/n)),e=t%n,t=n,n=e;while(t!==1);return r},toString:function(e){var t=this.n,n=this.d;if(isNaN(t)||isNaN(n))return`NaN`;e||=15;var r=u(t,n),i=d(t,n,r),a=this.s<0?`-`:``;if(a+=t/n|0,t%=n,t*=10,t&&(a+=`.`),r){for(var o=i;o--;)a+=t/n|0,t%=n,t*=10;a+=`(`;for(var o=r;o--;)a+=t/n|0,t%=n,t*=10;a+=`)`}else for(var o=e;t&&o--;)a+=t/n|0,t%=n,t*=10;return a}},typeof e==`object`?(Object.defineProperty(p,`__esModule`,{value:!0}),p.default=p,p.Fraction=p,t.exports=p):n.Fraction=p})(e)})),_a=c(ga(),1),va=`Fraction`,ya=[],ba=or(va,ya,()=>(Object.defineProperty(_a.default,`name`,{value:`Fraction`}),_a.default.prototype.constructor=_a.default,_a.default.prototype.type=`Fraction`,_a.default.prototype.isFraction=!0,_a.default.prototype.toJSON=function(){return{mathjs:`Fraction`,n:this.s*this.n,d:this.d}},_a.default.fromJSON=function(e){return new _a.default(e)},_a.default),{isClass:!0}),xa=`Matrix`,Sa=[],Ca=or(xa,Sa,()=>{function e(){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`)}return e.prototype.type=`Matrix`,e.prototype.isMatrix=!0,e.prototype.storage=function(){throw Error(`Cannot invoke storage on a Matrix interface`)},e.prototype.datatype=function(){throw Error(`Cannot invoke datatype on a Matrix interface`)},e.prototype.create=function(e,t){throw Error(`Cannot invoke create on a Matrix interface`)},e.prototype.subset=function(e,t,n){throw Error(`Cannot invoke subset on a Matrix interface`)},e.prototype.get=function(e){throw Error(`Cannot invoke get on a Matrix interface`)},e.prototype.set=function(e,t,n){throw Error(`Cannot invoke set on a Matrix interface`)},e.prototype.resize=function(e,t){throw Error(`Cannot invoke resize on a Matrix interface`)},e.prototype.reshape=function(e,t){throw Error(`Cannot invoke reshape on a Matrix interface`)},e.prototype.clone=function(){throw Error(`Cannot invoke clone on a Matrix interface`)},e.prototype.size=function(){throw Error(`Cannot invoke size on a Matrix interface`)},e.prototype.map=function(e,t){throw Error(`Cannot invoke map on a Matrix interface`)},e.prototype.forEach=function(e){throw Error(`Cannot invoke forEach on a Matrix interface`)},e.prototype[Symbol.iterator]=function(){throw Error(`Cannot iterate a Matrix interface`)},e.prototype.toArray=function(){throw Error(`Cannot invoke toArray on a Matrix interface`)},e.prototype.valueOf=function(){throw Error(`Cannot invoke valueOf on a Matrix interface`)},e.prototype.format=function(e){throw Error(`Cannot invoke format on a Matrix interface`)},e.prototype.toString=function(){throw Error(`Cannot invoke toString on a Matrix interface`)},e},{isClass:!0});function wa(e){return Object.keys(e.signatures||{}).reduce(function(e,t){var n=(t.match(/,/g)||[]).length+1;return Math.max(e,n)},-1)}var Ta=`DenseMatrix`,Ea=[`Matrix`],Da=or(Ta,Ea,e=>{var{Matrix:t}=e;function n(e,t){if(!(this instanceof n))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!Et(t))throw Error(`Invalid datatype: `+t);if(Dt(e))e.type===`DenseMatrix`?(this._data=sn(e._data),this._size=sn(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&M(e.data)&&M(e.size))this._data=e.data,this._size=e.size,Hn(this._data,this._size),this._datatype=t||e.datatype;else if(M(e))this._data=l(e),this._size=Bn(this._data),Hn(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+on(e)+`)`);else this._data=[],this._size=[0],this._datatype=t}n.prototype=new t,n.prototype.createDenseMatrix=function(e,t){return new n(e,t)},Object.defineProperty(n,`name`,{value:`DenseMatrix`}),n.prototype.constructor=n,n.prototype.type=`DenseMatrix`,n.prototype.isDenseMatrix=!0,n.prototype.getDataType=function(){return Qn(this._data,on)},n.prototype.storage=function(){return`dense`},n.prototype.datatype=function(){return this._datatype},n.prototype.create=function(e,t){return new n(e,t)},n.prototype.subset=function(e,t,n){switch(arguments.length){case 1:return r(this,e);case 2:case 3:return a(this,e,t,n);default:throw SyntaxError(`Wrong number of arguments`)}},n.prototype.get=function(e){if(!M(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new P(e.length,this._size.length);for(var t=0;t<e.length;t++)F(e[t],this._size[t]);for(var n=this._data,r=0,i=e.length;r<i;r++){var a=e[r];F(a,n.length),n=n[a]}return n},n.prototype.set=function(e,t,n){if(!M(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new P(e.length,this._size.length,`<`);var r,i,a,o=e.map(function(e){return e+1});c(this,o,n);var s=this._data;for(r=0,i=e.length-1;r<i;r++)a=e[r],F(a,s.length),s=s[a];return a=e[e.length-1],F(a,s.length),s[a]=t,this};function r(e,t){if(!Mt(t))throw TypeError(`Invalid index`);if(t.isScalar())return e.get(t.min());var r=t.size();if(r.length!==e._size.length)throw new P(r.length,e._size.length);for(var a=t.min(),o=t.max(),s=0,c=e._size.length;s<c;s++)F(a[s],e._size[s]),F(o[s],e._size[s]);return new n(i(e._data,t,r.length,0),e._datatype)}function i(e,t,n,r){var a=r===n-1,o=t.dimension(r);return a?o.map(function(t){return F(t,e.length),e[t]}).valueOf():o.map(function(a){F(a,e.length);var o=e[a];return i(o,t,n,r+1)}).valueOf()}function a(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Invalid index`);var i=t.size(),a=t.isScalar(),s;if(Dt(n)?(s=n.size(),n=n.valueOf()):s=Bn(n),a){if(s.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!ln(s,i))try{n=s.length===0?rr([n],i):rr(n,i),s=Bn(n)}catch{}if(i.length<e._size.length)throw new P(i.length,e._size.length,`<`);if(s.length<i.length){for(var l=0,u=0;i[l]===1&&s[l]===1;)l++;for(;i[l]===1;)u++,l++;n=Yn(n,i.length,u,s)}if(!ln(i,s))throw new P(i,s,`>`);c(e,t.max().map(function(e){return e+1}),r);var d=i.length;o(e._data,t,n,d,0)}return e}function o(e,t,n,r,i){var a=i===r-1,s=t.dimension(i);a?s.forEach(function(t,r){F(t),e[t]=n[r[0]]}):s.forEach(function(a,s){F(a),o(e[a],t,n[s[0]],r,i+1)})}n.prototype.resize=function(e,t,n){if(!Ot(e))throw TypeError(`Array or Matrix expected`);var r=e.valueOf().map(e=>Array.isArray(e)&&e.length===1?e[0]:e);return s(n?this.clone():this,r,t)};function s(e,t,n){if(t.length===0){for(var r=e._data;M(r);)r=r[0];return r}return e._size=t.slice(0),e._data=Un(e._data,e._size,n),e}n.prototype.reshape=function(e,t){var n=t?this.clone():this;return n._data=Gn(n._data,e),n._size=Kn(e,n._size.reduce((e,t)=>e*t)),n};function c(e,t,n){for(var r=e._size.slice(0),i=!1;r.length<t.length;)r.push(0),i=!0;for(var a=0,o=t.length;a<o;a++)t[a]>r[a]&&(r[a]=t[a],i=!0);i&&s(e,r,n)}n.prototype.clone=function(){return new n({data:sn(this._data),size:sn(this._size),datatype:this._datatype})},n.prototype.size=function(){return this._size.slice(0)},n.prototype.map=function(e){var t=this,r=wa(e),i=function n(i,a){return M(i)?i.map(function(e,t){return n(e,a.concat(t))}):r===1?e(i):r===2?e(i,a):e(i,a,t)}(this._data,[]);return new n(i,this._datatype===void 0?void 0:Qn(i,on))},n.prototype.forEach=function(e){var t=this;(function n(r,i){M(r)?r.forEach(function(e,t){n(e,i.concat(t))}):e(r,i,t)})(this._data,[])},n.prototype[Symbol.iterator]=function*(){yield*function*e(t,n){if(M(t))for(var r=0;r<t.length;r++)yield*e(t[r],n.concat(r));else yield{value:t,index:n}}(this._data,[])},n.prototype.rows=function(){var e=[];if(this.size().length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var t of this._data)e.push(new n([t],this._datatype));return e},n.prototype.columns=function(){var e=this,t=[],r=this.size();if(r.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var i=this._data,a=function(r){var a=i.map(e=>[e[r]]);t.push(new n(a,e._datatype))},o=0;o<r[1];o++)a(o);return t},n.prototype.toArray=function(){return sn(this._data)},n.prototype.valueOf=function(){return this._data},n.prototype.format=function(e){return Nn(this._data,e)},n.prototype.toString=function(){return Nn(this._data)},n.prototype.toJSON=function(){return{mathjs:`DenseMatrix`,data:this._data,size:this._size,datatype:this._datatype}},n.prototype.diagonal=function(e){if(e){if(j(e)&&(e=e.toNumber()),!A(e)||!N(e))throw TypeError(`The parameter k must be an integer number`)}else e=0;for(var t=e>0?e:0,r=e<0?-e:0,i=this._size[0],a=this._size[1],o=Math.min(i-r,a-t),s=[],c=0;c<o;c++)s[c]=this._data[c+r][c+t];return new n({data:s,size:[o],datatype:this._datatype})},n.diagonal=function(e,t,r,i){if(!M(e))throw TypeError(`Array expected, size parameter`);if(e.length!==2)throw Error(`Only two dimensions matrix are supported`);if(e=e.map(function(e){if(j(e)&&(e=e.toNumber()),!A(e)||!N(e)||e<1)throw Error(`Size values must be positive integers`);return e}),r){if(j(r)&&(r=r.toNumber()),!A(r)||!N(r))throw TypeError(`The parameter k must be an integer number`)}else r=0;var a=r>0?r:0,o=r<0?-r:0,s=e[0],c=e[1],l=Math.min(s-o,c-a),u;if(M(t)){if(t.length!==l)throw Error(`Invalid value array length`);u=function(e){return t[e]}}else if(Dt(t)){var d=t.size();if(d.length!==1||d[0]!==l)throw Error(`Invalid matrix length`);u=function(e){return t.get([e])}}else u=function(){return t};i||=j(u(0))?u(0).mul(0):0;var f=[];if(e.length>0){f=Un(f,e,i);for(var p=0;p<l;p++)f[p+o][p+a]=u(p)}return new n({data:f,size:[s,c]})},n.fromJSON=function(e){return new n(e)},n.prototype.swapRows=function(e,t){if(!A(e)||!N(e)||!A(t)||!N(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return F(e,this._size[0]),F(t,this._size[0]),n._swapRows(e,t,this._data),this},n._swapRows=function(e,t,n){var r=n[e];n[e]=n[t],n[t]=r};function l(e){return Dt(e)?l(e.valueOf()):M(e)?e.map(l):e}return n},{isClass:!0});function Oa(e,t,n){return e&&typeof e.map==`function`?e.map(function(e){return Oa(e,t,n)}):t(e)}var ka=`isNumeric`,Aa=[`typed`],ja=or(ka,Aa,e=>{var{typed:t}=e;return t(ka,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>Oa(t,e))})}),Ma=`hasNumericValue`,Na=[`typed`,`isNumeric`],Pa=or(Ma,Na,e=>{var{typed:t,isNumeric:n}=e;return t(Ma,{boolean:()=>!0,string:function(e){return e.trim().length>0&&!isNaN(Number(e))},any:function(e){return n(e)}})}),Fa=oa({config:hn}),Ia=ha({}),La=ba({}),Ra=Ca({}),za=Da({Matrix:Ra}),Ba=Cr({BigNumber:Fa,Complex:Ia,DenseMatrix:za,Fraction:La}),Va=ja({typed:Ba}),Ha=Pa({isNumeric:Va,typed:Ba});const Ua=e=>{let t=Number(e);return Number.isNaN(t)?!1:t>=120&&t<=36e4},Wa=e=>{let t=Number(e),n=Date.now();return Number.isNaN(t)?n+1e3:!Ua(t)&&(0,l.isFutureUnixTimestamp)(t)?bt(t):Ua(t)?n+t:n+t*_t},Ga=`ratelimitlimit`,Ka=`ratelimitremaining`,qa=`ratelimitreset`,Ja=`ratelimitconcurrencylimit`,Ya=`ratelimitconcurrencyremaining`,Xa=`ratelimitconcurrencyreset`,Za=e=>{let t={};for(let[n,r]of Object.entries(e)){let e=n.toLowerCase().replace(/^x-/,``).replace(/concurren.+-/g,`concurrency-`).replace(/-/g,``);t[e]=Ha(r)?Number(r):null}return t},Qa=e=>{let t=Za(e);return{rateLimitLimit:t.ratelimitlimit,rateLimitRemaining:t.ratelimitremaining,rateLimitReset:Wa(t.ratelimitreset),concurrencyLimit:t.ratelimitconcurrencylimit,concurrencyRemaining:t.ratelimitconcurrencyremaining,concurrencyReset:Wa(t.ratelimitconcurrencyreset)}},$a=e=>{let{accountSecureId:t,service:n,resource:r,subResource:i,childResource:a,action:o,behaviours:s}=e??{};return[t,n,r,o].some(l.isMissing)?null:[t,n,r,i,a,o,...s??[]].filter(Boolean).join(`-`)},eo=(e,t=10,n=1)=>{let r=Date.now();return(0,l.isFutureUnixTimestamp)(e)||(0,l.isNumber)(e)?to(Number(e),r,t,n):Et(e)&&e!==``?no(e,r,t,n):n},to=(e,t,n=10,r=1)=>{if(e<n)return e;let i=bt(e);if(i>t){let e=Math.floor((i-t)/_t);return e>0&&e<n?e:r}return r},no=(e,t,n=10,r=1)=>{if(vt.test(e)){let t=parseFloat(e);return t>0&&t<n?t:r}let i=new Date(e);if(Number.isNaN(i.getTime()))return r;let a=i.getTime();if(a>t){let e=Math.floor((a-t)/_t);return e>0&&e<n?e:r}return r},ro=({axiosInstance:e,logger:t,requestConfig:n,context:r})=>async i=>{let{response:a,config:o}=i;if(o?.signal?.aborted)return Promise.reject(lt(`Request aborted`,o,`ERR_CANCELED`,a));let{status:s,retryAfter:c}=io(a,r,n,t);if(s===429&&(0,l.notMissing)(o)){let n=eo(c);if(o._retryCount>=5)return t?.warning({category:`http-transport`,message:`Max retries exceeded for ${o?.url}. Aborting.`,context:{...r??{},retryAfterHeader:c,retryAfterAsNumber:n}}),Promise.reject(i);let s=o._retryCount??0,u={...o,_retryCount:s+1},d=c?n*_t:(0,l.exponentialBackoffInMS)(u._retryCount);return t?.debug({category:`http-transport`,message:`Received 429 error from ${o?.url}`,context:{...r??{},retryAfterHeader:c,calculatedRetryAfter:d}}),await ut(d,o,a),e?.request(u)}return Promise.reject(i)},io=(e,t,n,r)=>{let{provider:i}=t??{},{status:a,headers:o,data:s}=e??{},{retryafter:c}=Za(o??{});if((0,l.isMissing)(i)||(0,l.isMissing)(e))return r?.warning({category:`http-transport`,message:`Invalid parameters for convertError`,context:{...t,responseIsMissing:(0,l.isMissing)(e),providerIsMissing:(0,l.isMissing)(i),status:e?.status??`undefined`,statusText:e?.statusText??`undefined`,retryafter:c??`undefined`}}),{status:a,retryAfter:c};let u=n?.rateLimits?.mappedRateLimitErrors;if((0,l.notMissing)(u)&&(0,l.notMissing)(s))for(let e of u){let{errorStatus:t,errorMessagePath:n,errorMessage:r,retryAfterPath:i,retryAfterUnit:u,retryAfterValue:d}=e;if(t!==a)continue;let f=n??`message`,p=ao((0,l.isObject)(s)?(0,g.JSONPath)({path:f,json:s})[0]:s,r);if(t===a&&p){let e=so(d??oo(o,i),u);return{status:429,retryAfter:c??e}}}return{status:a,retryAfter:c}},ao=(e,t)=>t instanceof RegExp?t.test(e??``):e?.includes(t)??!1,oo=(e,t)=>(0,l.notMissing)(t)&&(0,l.notMissing)(e)?(0,g.JSONPath)({path:t,json:e})[0]:null,so=(e,t=`seconds`)=>(0,l.notMissing)(e)?co(e,t):null,co=(e,t)=>{if(t===`seconds`)return typeof e==`string`?parseFloat(e):e;if(t===`milliseconds`)return(typeof e==`string`?parseFloat(e):e)/_t;if(t===`date`){let t=typeof e==`string`&&!isNaN(Number(e))?parseFloat(e):e,n=new Date(t);if(isNaN(n.getTime()))throw Error(`Invalid date value`);return n.getTime()}throw Error(`Invalid type`)},lo=`rateLimitErrorInterceptor`,uo=({axiosInstance:e,logger:t,requestConfig:n,context:r,concurrencyManager:i})=>async a=>{let{response:o,config:s}=a,c=s?.signal;if((0,l.isMissing)(r)||(0,l.isMissing)(s))return t?.warning({category:`HttpClient`,message:`No context or config for this response - that doesn't seem right.`,context:{interceptor:lo,...s,httpsAgent:void 0,headers:void 0,hasContext:(0,l.notMissing)(r),hasConfig:(0,l.notMissing)(s)},code:ct.InterceptorContextNotPresent}),Promise.reject(a);if((0,l.isMissing)(i))return t?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:lo,...s,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:(0,l.notMissing)(i)},code:ct.RateLimitOrConcurrencyManagerNotInitialized}),Promise.reject(a);let{requestId:u,targetConcurrencyKey:d,leaseSubscription:f,setRemovalSubscription:p}=s?.requestMetadata??{};if(!((0,l.notMissing)(u)&&(0,l.notMissing)(d)&&await i.releaseRequest(u,d))&&(0,l.notMissing)(s?.requestMetadata)&&t?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{...r,interceptor:lo,requestId:u,targetConcurrencyKey:d,leaseSubscription:f,setRemovalSubscription:p},code:ct.RateLimiterReleaseRequestFailed}),c?.aborted)return Promise.reject(lt(`Request aborted`,s,`ERR_CANCELED`,o));let{status:m,retryAfter:h}=io(o,r,n,t);if(m===429&&(0,l.notMissing)(s)){let n=eo(h);if(s._retryCount>=5)return t?.warning({category:`HttpClient`,message:`Max retries exceeded for ${s.url}. Aborting.`,context:{...r??{},...s.requestMetadata??{},retryAfterHeader:h,retryAfterAsNumber:n}}),Promise.reject(a);let i=s?._retryCount??0,c={...s,_retryCount:i+1},u=h?n*_t:(0,l.exponentialBackoffInMS)(c._retryCount);return t?.debug({category:`HttpClient`,message:`Received 429 error from ${s.url}`,context:{...r,retryAfterHeader:h,calculatedRetryAfter:u}}),await ut(u,s,o),e?.request(c)}return Promise.reject(a)},fo=`rateLimitResponseInterceptor`,po=({logger:e,context:t,concurrencyManager:n})=>async r=>{let i=r?.config,a=i?.signal;if((0,l.isMissing)(t))e?.warning({category:`HttpClient`,message:`No context for this response - that doesn't seem right.`,context:{interceptor:fo,...i,httpsAgent:void 0,headers:void 0}});else if((0,l.isMissing)(n))return e?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:fo,...i,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:(0,l.notMissing)(n)},code:ct.RateLimitOrConcurrencyManagerNotInitialized}),r;else if((0,l.notMissing)(t.provider)&&(0,l.notMissing)(t.accountSecureId)){let t=r?.headers;if((0,l.notMissing)(t)){let n=Qa(t);e?.debug({category:`HttpClient`,message:`Rate limit headers extracted`,context:{interceptor:fo,rateLimitHeaders:n}})}let{requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:u}=i?.requestMetadata??{};if(await n.releaseRequest(o,s)||e?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{interceptor:fo,requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:u},code:ct.RateLimiterReleaseRequestFailed}),a?.aborted)return Promise.reject(lt(`Request aborted`,i,`ERR_CANCELED`,r))}return r},mo=e=>(e.validateStatus??=e=>e>=200&&e<300,e),ho=[{onFulfilled:mo,onRejected:null,options:void 0}],go=[{onFulfilled:null,onRejected:ro},{onFulfilled:null,onRejected:it}],_o=[{onFulfilled:mo,onRejected:null,options:void 0},{onFulfilled:ft,onRejected:null,options:void 0}],vo=[{onFulfilled:po,onRejected:uo},{onFulfilled:null,onRejected:it}],yo=1,bo=1e3,xo=0,So=59,Co=.8,wo=500;var To=class extends _e{constructor(...e){super(...e),this.name=`RateLimitManager`}async additionalInitialization(){}getDynamicMaxWaitTime(e,t,n,r=59,i=.8,a=500){this.readyCheck();let o=e.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.rateLimit??e.mainRatelimit;if(o<=0)throw Error(`Requests per second (rps) must be greater than 0.`);let s=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.maxConcurrency??t.mainMaxConcurrency;if(s<=0)throw Error(`Concurrency must be greater than 0.`);let c=r*i,l=1/Math.min(o,s/(a/1e3)),u=Math.max(7.5,c*l);return Math.min(c,u)}async getWaitTime(e,t,n){this.readyCheck();let r=`rateLimit:${e}`,i=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.subPoolKey,a=(0,l.notMissing)(i)?`${r}-${i}`:r,{mainRatelimit:o,subPools:s}=t,c=[{key:r,rateLimit:o},...s?.map(e=>{let{subPoolKey:t,rateLimit:n}=e;return{key:`${r}-${t}`,rateLimit:n}})??[]],u=c.map(e=>e.key),d=c.map(e=>e.rateLimit);return await this.executeScript(st.incr,[a,...u],[o.toString(),...d.map(String)])??0}readyCheck(){if(!this.cacheClient||!this.scriptMap?.size)throw Error(`RateLimitManager not ready`)}isReady(){return!!this?.cacheClient&&!!this?.scriptMap?.size}close(){this.scriptMap?.clear(),this.reset()}},Z=class{static{this.instances=new Map}static async prepare(e,t,...n){if(!this.instances.has(e)){let t=new e;t.getSingleton=e=>{let t=this.instances.get(e);if((0,l.isMissing)(t))throw Error(`Singleton ${e.name} not prepared yet`);if(t.hasInitFailed?.())throw Error(`${e.name} initialization failed`);let n=t.getInstanceIfReady?.();if((0,l.notMissing)(n))return n;throw Error(`${e.name} not ready`)},this.instances.set(e,t)}let r=this.instances.get(e);try{return await r.getInstance(t,...n)}catch(t){throw r.hasInitFailed?.()&&this.instances.delete(e),t}}static getIfReady(e){return this.instances.get(e)?.getInstanceIfReady?.()??null}static reset(e){this.instances.get(e)?.reset?.(),this.instances.delete(e)}static cleanupFailed(){let e=0;for(let[t,n]of this.instances){let r=n;r?.hasInitFailed?.()&&(r?.reset?.(),this.instances.delete(t),e++)}return e}};let Eo=function(e){return e.HttpTransportInstanceCreateError=`HttpTransportInstanceCreateError`,e}({});const Do=async({logger:e,redisClientConfig:t,context:n,requestConfig:r,httpsAgentConfig:i}={})=>{let a,{NODE_ENV:o}=process.env,s=n?.behaviours??[`CONCURRENCY`,`RETRY`];try{if(a=s.includes(`RETRY`)?ko(e,n):Oo(e,n),(0,l.isMissing)(n?.service)||(0,l.isMissing)(n?.organizationId)||o===`test`||(0,l.isMissing)(t)||(0,l.isMissing)(e))return a;let c=Z.getIfReady(To)??void 0,u=Z.getIfReady(Ke)??void 0,d=c?.isReady(),f=u?.isRedisConfigured(),p=[],m=[];if(s.includes(`CONCURRENCY`)){if(!f)throw Error(`Concurrency Manager cannot connect to Redis. Cannot create advanced transport instance.`);if(!d)throw Error(`RateLimitManager is not ready. Cannot create advanced transport instance.`);p.push(..._o),m.push(...vo)}let h=$a(n);if((0,l.isMissing)(h))return e?.warning({category:`http-transport`,message:`Unable to create a key for transport instance - Invalid state. Using base default instance.`,context:{...n,defaultInstanceInitialized:(0,l.notMissing)(a)}}),a;let g=await rt.get(h);if((0,l.notMissing)(g))return g;let _={interceptors:{requestConfigs:p,responseConfigs:m},instanceConfig:{maxBodyLength:1/0},logger:e,context:n,requestConfig:r,httpsAgentConfig:i,concurrencyManager:u,rateLimitManager:c},v=et.createInstance(_);return e?.debug({category:`http-transport`,message:`Creating new Axios instance and caching it for key: [${h}]`,context:{...n}}),await rt.set(h,v),v}catch(t){return e?.error({category:`http-transport`,message:`Failed to create advanced transport instance. Using default instance.`,context:{...n,usingDefaultInstance:(0,l.notMissing)(a)},error:t,code:Eo.HttpTransportInstanceCreateError}),(0,l.notMissing)(a)?a:Ao()}},Oo=(e,t)=>{let n={instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return et.createInstance(n)??Ao()},ko=(e,t)=>{let n={interceptors:{requestConfigs:ho,responseConfigs:go},instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return et.createInstance(n)??Ao()},Ao=()=>f.default.create({maxBodyLength:1/0});var jo=class{#e;#t;#n;#r;#i;#a;constructor({transportFactory:e=Do,getRedisClient:t=fe,logger:n,redisClientConfig:r,errorMappingFn:i}={}){this.name=`HttpClient`,this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}#o({url:e,payload:t,method:n,context:r}){if(!r?.accountSecureId||r.accountSecureId.length<20||!e||!n)return null;let i=t?(0,l.getContentHash)(t):``;return`${r.accountSecureId}-${n.toUpperCase()}${i}-${e}`}async#s({url:e,payload:t,method:n,cacheTTL:r,context:i}){if(!this.#a||!r||r<=0)return null;let a=this.#o({url:e,payload:t,method:n,context:i});if(!a)return null;let o=await this.#a.getData(a);return o?(this.#n?.debug({category:this.name,message:`Cache hit for key [${a}].`}),o):(this.#n?.debug({category:this.name,message:`Cache miss for key [${a}].`}),null)}async#c({url:e,payload:t,method:n,cacheTTL:r,context:i,response:a}){if(!this.#a||!r||r<=0)return!1;let o=this.#o({url:e,payload:t,method:n,context:i});return o?(this.#n?.debug({category:this.name,message:`Caching result for key [${o}].`}),this.#a.setData({key:o,value:a,cacheTTL:r*60})):!1}async request({headers:e={},url:t,method:n=`get`,queryParams:r,maxRedirects:i=0,responseType:a,cacheTTL:o,context:s,traceId:c,payload:u,httpsAgent:d,httpAgent:f,requestConfig:p,httpsAgentConfig:m}){try{(0,l.notMissing)(this.#r)&&(0,l.isMissing)(this.#a)&&(this.#a=await this.#t(this.#r,this.#n,`HttpClient`));let h=this.#_(t,r),g=this.#l(e),_=this.#m(u,e),v=await this.#s({url:h,payload:_,method:n,cacheTTL:o,context:s});if(v)return{...v,responseTime:new Date};let y=nt.getInstance(),b=((0,l.notMissing)(c)?await y.get(c):null)?.signal,x=await(await this.#e({redisClientConfig:this.#r,logger:this.#n,context:s,requestConfig:p,httpsAgentConfig:m})).request({headers:g,url:h,method:n,maxRedirects:i,responseType:a,data:_,httpsAgent:d,httpAgent:f,signal:b}),S={data:x.data,status:x.status,body:_,method:n,headers:this.#u(x.headers),requestUrl:t,responseType:x?.config?.responseType,responseTime:new Date};return await this.#c({url:h,payload:_,method:n,cacheTTL:o,context:s,response:S}),S}catch(e){let r=e;r.url=(0,_.redactUrl)(t),this.#n?.warning({category:this.name,message:`Request error [${n?.toUpperCase()} ${r.url}]: ${r.message}.`,error:r});let i=this.#h(r);throw(0,l.notMissing)(i)?i:e}}async get({headers:e,url:t,queryParams:n,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s}){return this.request({url:t,method:`get`,queryParams:n,headers:e,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s})}async post({headers:e,url:t,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s}){return this.request({url:t,method:`post`,headers:e,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s})}async requestStream({headers:e={},url:t,method:n=`get`,queryParams:r,maxRedirects:i=0,context:a,traceId:o,payload:s,httpsAgent:c,httpAgent:u,requestConfig:d,httpsAgentConfig:f}){try{let p=this.#_(t,r),m=this.#l(e),h=this.#m(s,e),g=nt.getInstance(),_=((0,l.notMissing)(o)?await g.get(o):null)?.signal,v=await(await this.#e({redisClientConfig:this.#r,logger:this.#n,context:a,requestConfig:d,httpsAgentConfig:f})).request({headers:m,url:p,method:n,maxRedirects:i,responseType:`stream`,data:h,httpsAgent:c,httpAgent:u,signal:_});return{status:v.status,headers:this.#u(v.headers),stream:v.data,requestUrl:t}}catch(e){let r=e;r.url=(0,_.redactUrl)(t),this.#n?.warning({category:this.name,message:`Stream request error [${n?.toUpperCase()} ${r.url}]: ${r.message}.`,error:r});let i=this.#h(r);throw(0,l.notMissing)(i)?i:e}}#l(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n.toLowerCase()]=e[n]||``}),t}#u(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n]=e[n]||``}),t}#d(e){return e[`content-type`]===`application/x-www-form-urlencoded`}#f(e){return e[`content-type`]?.startsWith(`multipart/form-data`)??!1}#p(e){return(0,l.isMissing)(e)||typeof e!=`object`||!e?!1:`pipe`in e&&typeof e.pipe==`function`}#m(e,t){if(!((0,l.isMissing)(e)||(0,l.isObject)(e)&&Object.keys(e).length===0))return this.#f(t)||this.#p(e)?e:this.#d(t)?v.default.stringify(e):e}#h(e){if((0,f.isAxiosError)(e)&&this.#i)return this.#i(e)}#g(e){return typeof e==`object`&&!!e&&`value`in e&&(typeof e.value==`string`||Array.isArray(e.value))}#_(e,t){if((0,l.isMissing)(t)||Object.keys(t).length===0)return e;let n={},r={},i={},a={};for(let[e,o]of Object.entries(t))if(this.#g(o)){let t=o.arrayFormat,s=o.value;t===`repeat`?r[e]=Array.isArray(s)?s:[s]:t===`brackets`?i[e]=Array.isArray(s)?s:[s]:t===`comma`?a[e]=Array.isArray(s)?s:[s]:n[e]=s}else n[e]=o;let o=[];Object.keys(n).length>0&&o.push(v.default.stringify(n)),Object.keys(r).length>0&&o.push(v.default.stringify(r,{arrayFormat:`repeat`})),Object.keys(i).length>0&&o.push(v.default.stringify(i,{arrayFormat:`brackets`})),Object.keys(a).length>0&&o.push(v.default.stringify(a,{arrayFormat:`comma`}));let s=o.join(`&`);return(0,l.notMissing)(s)?`${e}?${s}`:e}};const Mo=(e,t,n)=>new jo({redisClientConfig:e,logger:t,errorMappingFn:n});var No=class{static{this.httpClientInstance=null}static async getInstance({redisClientConfig:e,logger:t,errorMappingFn:n,getHttpClient:r=Mo}){return this.httpClientInstance??=r(e,t,n),this.httpClientInstance}static resetInstance(){this.httpClientInstance=null}};const Po=[`get`,`post`,`put`,`delete`,`patch`],Fo={[O.rPush]:`
|
|
126
126
|
local queueLength = redis.call('RPUSH', KEYS[1], ARGV[1])
|
|
127
127
|
|
|
128
128
|
redis.call('PEXPIRE', KEYS[1], ARGV[2])
|
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,7 @@ import * as redis from "redis";
|
|
|
2
2
|
import { AxiosInstance, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
|
|
3
3
|
import http, { AgentOptions } from "node:http";
|
|
4
4
|
import https from "node:https";
|
|
5
|
+
import { Readable } from "node:stream";
|
|
5
6
|
import { z } from "@stackone/utils";
|
|
6
7
|
|
|
7
8
|
//#region src/authorization/types.d.ts
|
|
@@ -399,6 +400,12 @@ type HttpResponse<T = any> = {
|
|
|
399
400
|
responseTime?: Date;
|
|
400
401
|
message?: string;
|
|
401
402
|
};
|
|
403
|
+
type StreamHttpResponse = {
|
|
404
|
+
status: number;
|
|
405
|
+
headers: HttpHeaders;
|
|
406
|
+
stream: Readable;
|
|
407
|
+
requestUrl: string;
|
|
408
|
+
};
|
|
402
409
|
type HttpParameters = {
|
|
403
410
|
query: HttpQueryParams;
|
|
404
411
|
body: Record<string, unknown> | unknown[];
|
|
@@ -468,6 +475,33 @@ interface IHttpClient {
|
|
|
468
475
|
payload?: P;
|
|
469
476
|
requestConfig?: RequestConfig;
|
|
470
477
|
}): Promise<HttpResponse<T>>;
|
|
478
|
+
requestStream({
|
|
479
|
+
headers,
|
|
480
|
+
url,
|
|
481
|
+
method,
|
|
482
|
+
queryParams,
|
|
483
|
+
maxRedirects,
|
|
484
|
+
context,
|
|
485
|
+
traceId,
|
|
486
|
+
payload,
|
|
487
|
+
httpsAgent,
|
|
488
|
+
httpAgent,
|
|
489
|
+
requestConfig,
|
|
490
|
+
httpsAgentConfig
|
|
491
|
+
}: {
|
|
492
|
+
headers?: HttpHeaders;
|
|
493
|
+
url: string;
|
|
494
|
+
method?: HttpMethod;
|
|
495
|
+
queryParams?: HttpQueryParams;
|
|
496
|
+
maxRedirects?: number;
|
|
497
|
+
context?: RequestContext;
|
|
498
|
+
traceId?: string;
|
|
499
|
+
payload?: unknown;
|
|
500
|
+
httpsAgent?: https.Agent;
|
|
501
|
+
httpAgent?: http.Agent;
|
|
502
|
+
requestConfig?: RequestConfig;
|
|
503
|
+
httpsAgentConfig?: https.AgentOptions;
|
|
504
|
+
}): Promise<StreamHttpResponse>;
|
|
471
505
|
}
|
|
472
506
|
interface OperationSetting {
|
|
473
507
|
url?: string;
|
|
@@ -703,6 +737,33 @@ declare class HttpClient<TError extends Error = Error> implements IHttpClient {
|
|
|
703
737
|
payload?: P;
|
|
704
738
|
requestConfig?: RequestConfig;
|
|
705
739
|
}): Promise<HttpResponse<T>>;
|
|
740
|
+
requestStream({
|
|
741
|
+
headers,
|
|
742
|
+
url,
|
|
743
|
+
method,
|
|
744
|
+
queryParams,
|
|
745
|
+
maxRedirects,
|
|
746
|
+
context,
|
|
747
|
+
traceId,
|
|
748
|
+
payload,
|
|
749
|
+
httpsAgent,
|
|
750
|
+
httpAgent,
|
|
751
|
+
requestConfig,
|
|
752
|
+
httpsAgentConfig
|
|
753
|
+
}: {
|
|
754
|
+
headers?: HttpHeaders;
|
|
755
|
+
url: string;
|
|
756
|
+
method?: HttpMethod;
|
|
757
|
+
queryParams?: HttpQueryParams;
|
|
758
|
+
maxRedirects?: number;
|
|
759
|
+
context?: RequestContext;
|
|
760
|
+
traceId?: string;
|
|
761
|
+
payload?: unknown;
|
|
762
|
+
httpsAgent?: https.Agent;
|
|
763
|
+
httpAgent?: http.Agent;
|
|
764
|
+
requestConfig?: RequestConfig;
|
|
765
|
+
httpsAgentConfig?: https.AgentOptions;
|
|
766
|
+
}): Promise<StreamHttpResponse>;
|
|
706
767
|
}
|
|
707
768
|
//#endregion
|
|
708
769
|
//#region src/httpClient/httpClientManager.d.ts
|
|
@@ -942,4 +1003,4 @@ type LockEntry = {
|
|
|
942
1003
|
unlock: Unlock;
|
|
943
1004
|
};
|
|
944
1005
|
//#endregion
|
|
945
|
-
export { CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, createAuthorizationHeaders, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, translateCustomError };
|
|
1006
|
+
export { CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, type StreamHttpResponse, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, createAuthorizationHeaders, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, translateCustomError };
|
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,7 @@ import * as redis from "redis";
|
|
|
3
3
|
import { AxiosInstance, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
|
|
4
4
|
import https from "node:https";
|
|
5
5
|
import http, { AgentOptions } from "node:http";
|
|
6
|
+
import { Readable } from "node:stream";
|
|
6
7
|
|
|
7
8
|
//#region src/authorization/types.d.ts
|
|
8
9
|
type NoAuthorizationParams = {
|
|
@@ -399,6 +400,12 @@ type HttpResponse<T = any> = {
|
|
|
399
400
|
responseTime?: Date;
|
|
400
401
|
message?: string;
|
|
401
402
|
};
|
|
403
|
+
type StreamHttpResponse = {
|
|
404
|
+
status: number;
|
|
405
|
+
headers: HttpHeaders;
|
|
406
|
+
stream: Readable;
|
|
407
|
+
requestUrl: string;
|
|
408
|
+
};
|
|
402
409
|
type HttpParameters = {
|
|
403
410
|
query: HttpQueryParams;
|
|
404
411
|
body: Record<string, unknown> | unknown[];
|
|
@@ -468,6 +475,33 @@ interface IHttpClient {
|
|
|
468
475
|
payload?: P;
|
|
469
476
|
requestConfig?: RequestConfig;
|
|
470
477
|
}): Promise<HttpResponse<T>>;
|
|
478
|
+
requestStream({
|
|
479
|
+
headers,
|
|
480
|
+
url,
|
|
481
|
+
method,
|
|
482
|
+
queryParams,
|
|
483
|
+
maxRedirects,
|
|
484
|
+
context,
|
|
485
|
+
traceId,
|
|
486
|
+
payload,
|
|
487
|
+
httpsAgent,
|
|
488
|
+
httpAgent,
|
|
489
|
+
requestConfig,
|
|
490
|
+
httpsAgentConfig
|
|
491
|
+
}: {
|
|
492
|
+
headers?: HttpHeaders;
|
|
493
|
+
url: string;
|
|
494
|
+
method?: HttpMethod;
|
|
495
|
+
queryParams?: HttpQueryParams;
|
|
496
|
+
maxRedirects?: number;
|
|
497
|
+
context?: RequestContext;
|
|
498
|
+
traceId?: string;
|
|
499
|
+
payload?: unknown;
|
|
500
|
+
httpsAgent?: https.Agent;
|
|
501
|
+
httpAgent?: http.Agent;
|
|
502
|
+
requestConfig?: RequestConfig;
|
|
503
|
+
httpsAgentConfig?: https.AgentOptions;
|
|
504
|
+
}): Promise<StreamHttpResponse>;
|
|
471
505
|
}
|
|
472
506
|
interface OperationSetting {
|
|
473
507
|
url?: string;
|
|
@@ -703,6 +737,33 @@ declare class HttpClient<TError extends Error = Error> implements IHttpClient {
|
|
|
703
737
|
payload?: P;
|
|
704
738
|
requestConfig?: RequestConfig;
|
|
705
739
|
}): Promise<HttpResponse<T>>;
|
|
740
|
+
requestStream({
|
|
741
|
+
headers,
|
|
742
|
+
url,
|
|
743
|
+
method,
|
|
744
|
+
queryParams,
|
|
745
|
+
maxRedirects,
|
|
746
|
+
context,
|
|
747
|
+
traceId,
|
|
748
|
+
payload,
|
|
749
|
+
httpsAgent,
|
|
750
|
+
httpAgent,
|
|
751
|
+
requestConfig,
|
|
752
|
+
httpsAgentConfig
|
|
753
|
+
}: {
|
|
754
|
+
headers?: HttpHeaders;
|
|
755
|
+
url: string;
|
|
756
|
+
method?: HttpMethod;
|
|
757
|
+
queryParams?: HttpQueryParams;
|
|
758
|
+
maxRedirects?: number;
|
|
759
|
+
context?: RequestContext;
|
|
760
|
+
traceId?: string;
|
|
761
|
+
payload?: unknown;
|
|
762
|
+
httpsAgent?: https.Agent;
|
|
763
|
+
httpAgent?: http.Agent;
|
|
764
|
+
requestConfig?: RequestConfig;
|
|
765
|
+
httpsAgentConfig?: https.AgentOptions;
|
|
766
|
+
}): Promise<StreamHttpResponse>;
|
|
706
767
|
}
|
|
707
768
|
//#endregion
|
|
708
769
|
//#region src/httpClient/httpClientManager.d.ts
|
|
@@ -942,4 +1003,4 @@ type LockEntry = {
|
|
|
942
1003
|
unlock: Unlock;
|
|
943
1004
|
};
|
|
944
1005
|
//#endregion
|
|
945
|
-
export { CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, createAuthorizationHeaders, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, translateCustomError };
|
|
1006
|
+
export { CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, type StreamHttpResponse, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, createAuthorizationHeaders, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, translateCustomError };
|
package/dist/index.mjs
CHANGED
|
@@ -122,7 +122,7 @@ var cr=9e15,lr=1e9,ur=`0123456789abcdef`,dr=`2.302585092994045684017991454684364
|
|
|
122
122
|
* Copyright (c) 2023, Robert Eisele (robert@raw.org)
|
|
123
123
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
124
124
|
**/
|
|
125
|
-
(function(n){var r=2e3,i={s:1,n:0,d:1};function a(e,t){if(isNaN(e=parseInt(e,10)))throw h();return e*t}function o(e,t){if(t===0)throw m();var n=Object.create(p.prototype);n.s=e<0?-1:1,e=e<0?-e:e;var r=f(e,t);return n.n=e/r,n.d=t/r,n}function s(e){for(var t={},n=e,r=2,i=4;i<=n;){for(;n%r===0;)n/=r,t[r]=(t[r]||0)+1;i+=1+2*r++}return n===e?t[e]=(t[e]||0)+1:n>1&&(t[n]=(t[n]||0)+1),t}var c=function(e,t){var n=0,r=1,o=1,s=0,c=0,l=0,u=1,d=1,f=0,p=1,_=1,v=1,y=1e7,b;if(e!=null)if(t!==void 0){if(n=e,r=t,o=n*r,n%1!=0||r%1!=0)throw g()}else switch(typeof e){case`object`:if(`d`in e&&`n`in e)n=e.n,r=e.d,`s`in e&&(n*=e.s);else if(0 in e)n=e[0],1 in e&&(r=e[1]);else throw h();o=n*r;break;case`number`:if(e<0&&(o=e,e=-e),e%1==0)n=e;else if(e>0){for(e>=1&&(d=10**Math.floor(1+Math.log(e)/Math.LN10),e/=d);p<=y&&v<=y;)if(b=(f+_)/(p+v),e===b){p+v<=y?(n=f+_,r=p+v):v>p?(n=_,r=v):(n=f,r=p);break}else e>b?(f+=_,p+=v):(_+=f,v+=p),p>y?(n=_,r=v):(n=f,r=p);n*=d}else (isNaN(e)||isNaN(t))&&(r=n=NaN);break;case`string`:if(p=e.match(/\d+|./g),p===null)throw h();if(p[f]===`-`?(o=-1,f++):p[f]===`+`&&f++,p.length===f+1?c=a(p[f++],o):p[f+1]===`.`||p[f]===`.`?(p[f]!==`.`&&(s=a(p[f++],o)),f++,(f+1===p.length||p[f+1]===`(`&&p[f+3]===`)`||p[f+1]===`'`&&p[f+3]===`'`)&&(c=a(p[f],o),u=10**p[f].length,f++),(p[f]===`(`&&p[f+2]===`)`||p[f]===`'`&&p[f+2]===`'`)&&(l=a(p[f+1],o),d=10**p[f+1].length-1,f+=3)):p[f+1]===`/`||p[f+1]===`:`?(c=a(p[f],o),u=a(p[f+2],1),f+=3):p[f+3]===`/`&&p[f+1]===` `&&(s=a(p[f],o),c=a(p[f+2],o),u=a(p[f+4],1),f+=5),p.length<=f){r=u*d,o=n=l+r*s+d*c;break}default:throw h()}if(r===0)throw m();i.s=o<0?-1:1,i.n=Math.abs(n),i.d=Math.abs(r)};function l(e,t,n){for(var r=1;t>0;e=e*e%n,t>>=1)t&1&&(r=r*e%n);return r}function u(e,t){for(;t%2==0;t/=2);for(;t%5==0;t/=5);if(t===1)return 0;for(var n=10%t,i=1;n!==1;i++)if(n=n*10%t,i>r)return 0;return i}function d(e,t,n){for(var r=1,i=l(10,n,t),a=0;a<300;a++){if(r===i)return a;r=r*10%t,i=i*10%t}return 0}function f(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function p(e,t){if(c(e,t),this instanceof p)e=f(i.d,i.n),this.s=i.s,this.n=i.n/e,this.d=i.d/e;else return o(i.s*i.n,i.d)}var m=function(){return Error(`Division by Zero`)},h=function(){return Error(`Invalid argument`)},g=function(){return Error(`Parameters must be integer`)};p.prototype={s:1,n:0,d:1,abs:function(){return o(this.n,this.d)},neg:function(){return o(-this.s*this.n,this.d)},add:function(e,t){return c(e,t),o(this.s*this.n*i.d+i.s*this.d*i.n,this.d*i.d)},sub:function(e,t){return c(e,t),o(this.s*this.n*i.d-i.s*this.d*i.n,this.d*i.d)},mul:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.n,this.d*i.d)},div:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.d,this.d*i.n)},clone:function(){return o(this.s*this.n,this.d)},mod:function(e,t){if(isNaN(this.n)||isNaN(this.d))return new p(NaN);if(e===void 0)return o(this.s*this.n%this.d,1);if(c(e,t),i.n===0&&this.d===0)throw m();return o(this.s*(i.d*this.n)%(i.n*this.d),i.d*this.d)},gcd:function(e,t){return c(e,t),o(f(i.n,this.n)*f(i.d,this.d),i.d*this.d)},lcm:function(e,t){return c(e,t),i.n===0&&this.n===0?o(0,1):o(i.n*this.n,f(i.n,this.n)*f(i.d,this.d))},ceil:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.ceil(e*this.s*this.n/this.d),e)},floor:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.floor(e*this.s*this.n/this.d),e)},round:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.round(e*this.s*this.n/this.d),e)},inverse:function(){return o(this.s*this.d,this.n)},pow:function(e,t){if(c(e,t),i.d===1)return i.s<0?o((this.s*this.d)**+i.n,this.n**+i.n):o((this.s*this.n)**+i.n,this.d**+i.n);if(this.s<0)return null;var n=s(this.n),r=s(this.d),a=1,l=1;for(var u in n)if(u!==`1`){if(u===`0`){a=0;break}if(n[u]*=i.n,n[u]%i.d===0)n[u]/=i.d;else return null;a*=u**+n[u]}for(var u in r)if(u!==`1`){if(r[u]*=i.n,r[u]%i.d===0)r[u]/=i.d;else return null;l*=u**+r[u]}return i.s<0?o(l,a):o(a,l)},equals:function(e,t){return c(e,t),this.s*this.n*i.d===i.s*i.n*this.d},compare:function(e,t){c(e,t);var n=this.s*this.n*i.d-i.s*i.n*this.d;return(0<n)-(n<0)},simplify:function(e){if(isNaN(this.n)||isNaN(this.d))return this;e||=.001;for(var t=this.abs(),n=t.toContinued(),r=1;r<n.length;r++){for(var i=o(n[r-1],1),a=r-2;a>=0;a--)i=i.inverse().add(n[a]);if(Math.abs(i.sub(t).valueOf())<e)return i.mul(this.s)}return this},divisible:function(e,t){return c(e,t),!(!(i.n*this.d)||this.n*i.d%(i.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,n+=` `,r%=i),n+=r,n+=`/`,n+=i),n},toLatex:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,r%=i),n+=`\\frac{`,n+=r,n+=`}{`,n+=i,n+=`}`),n},toContinued:function(){var e,t=this.n,n=this.d,r=[];if(isNaN(t)||isNaN(n))return r;do r.push(Math.floor(t/n)),e=t%n,t=n,n=e;while(t!==1);return r},toString:function(e){var t=this.n,n=this.d;if(isNaN(t)||isNaN(n))return`NaN`;e||=15;var r=u(t,n),i=d(t,n,r),a=this.s<0?`-`:``;if(a+=t/n|0,t%=n,t*=10,t&&(a+=`.`),r){for(var o=i;o--;)a+=t/n|0,t%=n,t*=10;a+=`(`;for(var o=r;o--;)a+=t/n|0,t%=n,t*=10;a+=`)`}else for(var o=e;t&&o--;)a+=t/n|0,t%=n,t*=10;return a}},typeof e==`object`?(Object.defineProperty(p,`__esModule`,{value:!0}),p.default=p,p.Fraction=p,t.exports=p):n.Fraction=p})(e)}))(),1),qi=Vn(`Fraction`,[],()=>(Object.defineProperty(Ki.default,`name`,{value:`Fraction`}),Ki.default.prototype.constructor=Ki.default,Ki.default.prototype.type=`Fraction`,Ki.default.prototype.isFraction=!0,Ki.default.prototype.toJSON=function(){return{mathjs:`Fraction`,n:this.s*this.n,d:this.d}},Ki.default.fromJSON=function(e){return new Ki.default(e)},Ki.default),{isClass:!0}),Ji=Vn(`Matrix`,[],()=>{function e(){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`)}return e.prototype.type=`Matrix`,e.prototype.isMatrix=!0,e.prototype.storage=function(){throw Error(`Cannot invoke storage on a Matrix interface`)},e.prototype.datatype=function(){throw Error(`Cannot invoke datatype on a Matrix interface`)},e.prototype.create=function(e,t){throw Error(`Cannot invoke create on a Matrix interface`)},e.prototype.subset=function(e,t,n){throw Error(`Cannot invoke subset on a Matrix interface`)},e.prototype.get=function(e){throw Error(`Cannot invoke get on a Matrix interface`)},e.prototype.set=function(e,t,n){throw Error(`Cannot invoke set on a Matrix interface`)},e.prototype.resize=function(e,t){throw Error(`Cannot invoke resize on a Matrix interface`)},e.prototype.reshape=function(e,t){throw Error(`Cannot invoke reshape on a Matrix interface`)},e.prototype.clone=function(){throw Error(`Cannot invoke clone on a Matrix interface`)},e.prototype.size=function(){throw Error(`Cannot invoke size on a Matrix interface`)},e.prototype.map=function(e,t){throw Error(`Cannot invoke map on a Matrix interface`)},e.prototype.forEach=function(e){throw Error(`Cannot invoke forEach on a Matrix interface`)},e.prototype[Symbol.iterator]=function(){throw Error(`Cannot iterate a Matrix interface`)},e.prototype.toArray=function(){throw Error(`Cannot invoke toArray on a Matrix interface`)},e.prototype.valueOf=function(){throw Error(`Cannot invoke valueOf on a Matrix interface`)},e.prototype.format=function(e){throw Error(`Cannot invoke format on a Matrix interface`)},e.prototype.toString=function(){throw Error(`Cannot invoke toString on a Matrix interface`)},e},{isClass:!0});function Yi(e){return Object.keys(e.signatures||{}).reduce(function(e,t){var n=(t.match(/,/g)||[]).length+1;return Math.max(e,n)},-1)}var Xi=Vn(`DenseMatrix`,[`Matrix`],e=>{var{Matrix:t}=e;function n(e,t){if(!(this instanceof n))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!ct(t))throw Error(`Invalid datatype: `+t);if(lt(e))e.type===`DenseMatrix`?(this._data=Ht(e._data),this._size=Ht(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&M(e.data)&&M(e.size))this._data=e.data,this._size=e.size,Cn(this._data,this._size),this._datatype=t||e.datatype;else if(M(e))this._data=l(e),this._size=xn(this._data),Cn(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+Vt(e)+`)`);else this._data=[],this._size=[0],this._datatype=t}n.prototype=new t,n.prototype.createDenseMatrix=function(e,t){return new n(e,t)},Object.defineProperty(n,`name`,{value:`DenseMatrix`}),n.prototype.constructor=n,n.prototype.type=`DenseMatrix`,n.prototype.isDenseMatrix=!0,n.prototype.getDataType=function(){return Nn(this._data,Vt)},n.prototype.storage=function(){return`dense`},n.prototype.datatype=function(){return this._datatype},n.prototype.create=function(e,t){return new n(e,t)},n.prototype.subset=function(e,t,n){switch(arguments.length){case 1:return r(this,e);case 2:case 3:return a(this,e,t,n);default:throw SyntaxError(`Wrong number of arguments`)}},n.prototype.get=function(e){if(!M(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new P(e.length,this._size.length);for(var t=0;t<e.length;t++)F(e[t],this._size[t]);for(var n=this._data,r=0,i=e.length;r<i;r++){var a=e[r];F(a,n.length),n=n[a]}return n},n.prototype.set=function(e,t,n){if(!M(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new P(e.length,this._size.length,`<`);var r,i,a,o=e.map(function(e){return e+1});c(this,o,n);var s=this._data;for(r=0,i=e.length-1;r<i;r++)a=e[r],F(a,s.length),s=s[a];return a=e[e.length-1],F(a,s.length),s[a]=t,this};function r(e,t){if(!mt(t))throw TypeError(`Invalid index`);if(t.isScalar())return e.get(t.min());var r=t.size();if(r.length!==e._size.length)throw new P(r.length,e._size.length);for(var a=t.min(),o=t.max(),s=0,c=e._size.length;s<c;s++)F(a[s],e._size[s]),F(o[s],e._size[s]);return new n(i(e._data,t,r.length,0),e._datatype)}function i(e,t,n,r){var a=r===n-1,o=t.dimension(r);return a?o.map(function(t){return F(t,e.length),e[t]}).valueOf():o.map(function(a){F(a,e.length);var o=e[a];return i(o,t,n,r+1)}).valueOf()}function a(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Invalid index`);var i=t.size(),a=t.isScalar(),s;if(lt(n)?(s=n.size(),n=n.valueOf()):s=xn(n),a){if(s.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!Wt(s,i))try{n=s.length===0?Rn([n],i):Rn(n,i),s=xn(n)}catch{}if(i.length<e._size.length)throw new P(i.length,e._size.length,`<`);if(s.length<i.length){for(var l=0,u=0;i[l]===1&&s[l]===1;)l++;for(;i[l]===1;)u++,l++;n=An(n,i.length,u,s)}if(!Wt(i,s))throw new P(i,s,`>`);c(e,t.max().map(function(e){return e+1}),r);var d=i.length;o(e._data,t,n,d,0)}return e}function o(e,t,n,r,i){var a=i===r-1,s=t.dimension(i);a?s.forEach(function(t,r){F(t),e[t]=n[r[0]]}):s.forEach(function(a,s){F(a),o(e[a],t,n[s[0]],r,i+1)})}n.prototype.resize=function(e,t,n){if(!ut(e))throw TypeError(`Array or Matrix expected`);var r=e.valueOf().map(e=>Array.isArray(e)&&e.length===1?e[0]:e);return s(n?this.clone():this,r,t)};function s(e,t,n){if(t.length===0){for(var r=e._data;M(r);)r=r[0];return r}return e._size=t.slice(0),e._data=wn(e._data,e._size,n),e}n.prototype.reshape=function(e,t){var n=t?this.clone():this;return n._data=En(n._data,e),n._size=Dn(e,n._size.reduce((e,t)=>e*t)),n};function c(e,t,n){for(var r=e._size.slice(0),i=!1;r.length<t.length;)r.push(0),i=!0;for(var a=0,o=t.length;a<o;a++)t[a]>r[a]&&(r[a]=t[a],i=!0);i&&s(e,r,n)}n.prototype.clone=function(){return new n({data:Ht(this._data),size:Ht(this._size),datatype:this._datatype})},n.prototype.size=function(){return this._size.slice(0)},n.prototype.map=function(e){var t=this,r=Yi(e),i=function n(i,a){return M(i)?i.map(function(e,t){return n(e,a.concat(t))}):r===1?e(i):r===2?e(i,a):e(i,a,t)}(this._data,[]);return new n(i,this._datatype===void 0?void 0:Nn(i,Vt))},n.prototype.forEach=function(e){var t=this;(function n(r,i){M(r)?r.forEach(function(e,t){n(e,i.concat(t))}):e(r,i,t)})(this._data,[])},n.prototype[Symbol.iterator]=function*(){yield*function*e(t,n){if(M(t))for(var r=0;r<t.length;r++)yield*e(t[r],n.concat(r));else yield{value:t,index:n}}(this._data,[])},n.prototype.rows=function(){var e=[];if(this.size().length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var t of this._data)e.push(new n([t],this._datatype));return e},n.prototype.columns=function(){var e=this,t=[],r=this.size();if(r.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var i=this._data,a=function(r){var a=i.map(e=>[e[r]]);t.push(new n(a,e._datatype))},o=0;o<r[1];o++)a(o);return t},n.prototype.toArray=function(){return Ht(this._data)},n.prototype.valueOf=function(){return this._data},n.prototype.format=function(e){return mn(this._data,e)},n.prototype.toString=function(){return mn(this._data)},n.prototype.toJSON=function(){return{mathjs:`DenseMatrix`,data:this._data,size:this._size,datatype:this._datatype}},n.prototype.diagonal=function(e){if(e){if(it(e)&&(e=e.toNumber()),!j(e)||!N(e))throw TypeError(`The parameter k must be an integer number`)}else e=0;for(var t=e>0?e:0,r=e<0?-e:0,i=this._size[0],a=this._size[1],o=Math.min(i-r,a-t),s=[],c=0;c<o;c++)s[c]=this._data[c+r][c+t];return new n({data:s,size:[o],datatype:this._datatype})},n.diagonal=function(e,t,r,i){if(!M(e))throw TypeError(`Array expected, size parameter`);if(e.length!==2)throw Error(`Only two dimensions matrix are supported`);if(e=e.map(function(e){if(it(e)&&(e=e.toNumber()),!j(e)||!N(e)||e<1)throw Error(`Size values must be positive integers`);return e}),r){if(it(r)&&(r=r.toNumber()),!j(r)||!N(r))throw TypeError(`The parameter k must be an integer number`)}else r=0;var a=r>0?r:0,o=r<0?-r:0,s=e[0],c=e[1],l=Math.min(s-o,c-a),u;if(M(t)){if(t.length!==l)throw Error(`Invalid value array length`);u=function(e){return t[e]}}else if(lt(t)){var d=t.size();if(d.length!==1||d[0]!==l)throw Error(`Invalid matrix length`);u=function(e){return t.get([e])}}else u=function(){return t};i||=it(u(0))?u(0).mul(0):0;var f=[];if(e.length>0){f=wn(f,e,i);for(var p=0;p<l;p++)f[p+o][p+a]=u(p)}return new n({data:f,size:[s,c]})},n.fromJSON=function(e){return new n(e)},n.prototype.swapRows=function(e,t){if(!j(e)||!N(e)||!j(t)||!N(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return F(e,this._size[0]),F(t,this._size[0]),n._swapRows(e,t,this._data),this},n._swapRows=function(e,t,n){var r=n[e];n[e]=n[t],n[t]=r};function l(e){return lt(e)?l(e.valueOf()):M(e)?e.map(l):e}return n},{isClass:!0});function Zi(e,t,n){return e&&typeof e.map==`function`?e.map(function(e){return Zi(e,t,n)}):t(e)}var Qi=`isNumeric`,$i=Vn(Qi,[`typed`],e=>{var{typed:t}=e;return t(Qi,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>Zi(t,e))})}),ea=`hasNumericValue`,ta=Vn(ea,[`typed`,`isNumeric`],e=>{var{typed:t,isNumeric:n}=e;return t(ea,{boolean:()=>!0,string:function(e){return e.trim().length>0&&!isNaN(Number(e))},any:function(e){return n(e)}})}),na=rr({BigNumber:Ri({config:Xt}),Complex:Gi({}),DenseMatrix:Xi({Matrix:Ji({})}),Fraction:qi({})}),ra=ta({isNumeric:$i({typed:na}),typed:na});const ia=e=>{let t=Number(e);return Number.isNaN(t)?!1:t>=120&&t<=36e4},aa=e=>{let t=Number(e),n=Date.now();return Number.isNaN(t)?n+1e3:!ia(t)&&a(t)?tt(t):ia(t)?n+t:n+t*$e},oa=e=>{let t={};for(let[n,r]of Object.entries(e)){let e=n.toLowerCase().replace(/^x-/,``).replace(/concurren.+-/g,`concurrency-`).replace(/-/g,``);t[e]=ra(r)?Number(r):null}return t},sa=e=>{let t=oa(e);return{rateLimitLimit:t.ratelimitlimit,rateLimitRemaining:t.ratelimitremaining,rateLimitReset:aa(t.ratelimitreset),concurrencyLimit:t.ratelimitconcurrencylimit,concurrencyRemaining:t.ratelimitconcurrencyremaining,concurrencyReset:aa(t.ratelimitconcurrencyreset)}},ca=e=>{let{accountSecureId:t,service:n,resource:r,subResource:i,childResource:a,action:s,behaviours:c}=e??{};return[t,n,r,s].some(o)?null:[t,n,r,i,a,s,...c??[]].filter(Boolean).join(`-`)},la=(e,t=10,n=1)=>{let r=Date.now();return a(e)||s(e)?ua(Number(e),r,t,n):ct(e)&&e!==``?da(e,r,t,n):n},ua=(e,t,n=10,r=1)=>{if(e<n)return e;let i=tt(e);if(i>t){let e=Math.floor((i-t)/$e);return e>0&&e<n?e:r}return r},da=(e,t,n=10,r=1)=>{if(et.test(e)){let t=parseFloat(e);return t>0&&t<n?t:r}let i=new Date(e);if(Number.isNaN(i.getTime()))return r;let a=i.getTime();if(a>t){let e=Math.floor((a-t)/$e);return e>0&&e<n?e:r}return r},fa=({axiosInstance:e,logger:n,requestConfig:r,context:i})=>async a=>{let{response:o,config:s}=a;if(s?.signal?.aborted)return Promise.reject(Ye(`Request aborted`,s,`ERR_CANCELED`,o));let{status:c,retryAfter:l}=pa(o,i,r,n);if(c===429&&u(s)){let r=la(l);if(s._retryCount>=5)return n?.warning({category:`http-transport`,message:`Max retries exceeded for ${s?.url}. Aborting.`,context:{...i??{},retryAfterHeader:l,retryAfterAsNumber:r}}),Promise.reject(a);let c=s._retryCount??0,u={...s,_retryCount:c+1},d=l?r*$e:t(u._retryCount);return n?.debug({category:`http-transport`,message:`Received 429 error from ${s?.url}`,context:{...i??{},retryAfterHeader:l,calculatedRetryAfter:d}}),await Xe(d,s,o),e?.request(u)}return Promise.reject(a)},pa=(e,t,n,r)=>{let{provider:i}=t??{},{status:a,headers:s,data:l}=e??{},{retryafter:d}=oa(s??{});if(o(i)||o(e))return r?.warning({category:`http-transport`,message:`Invalid parameters for convertError`,context:{...t,responseIsMissing:o(e),providerIsMissing:o(i),status:e?.status??`undefined`,statusText:e?.statusText??`undefined`,retryafter:d??`undefined`}}),{status:a,retryAfter:d};let f=n?.rateLimits?.mappedRateLimitErrors;if(u(f)&&u(l))for(let e of f){let{errorStatus:t,errorMessagePath:n,errorMessage:r,retryAfterPath:i,retryAfterUnit:o,retryAfterValue:u}=e;if(t!==a)continue;let f=n??`message`,p=ma(c(l)?x({path:f,json:l})[0]:l,r);if(t===a&&p){let e=ga(u??ha(s,i),o);return{status:429,retryAfter:d??e}}}return{status:a,retryAfter:d}},ma=(e,t)=>t instanceof RegExp?t.test(e??``):e?.includes(t)??!1,ha=(e,t)=>u(t)&&u(e)?x({path:t,json:e})[0]:null,ga=(e,t=`seconds`)=>u(e)?_a(e,t):null,_a=(e,t)=>{if(t===`seconds`)return typeof e==`string`?parseFloat(e):e;if(t===`milliseconds`)return(typeof e==`string`?parseFloat(e):e)/$e;if(t===`date`){let t=typeof e==`string`&&!isNaN(Number(e))?parseFloat(e):e,n=new Date(t);if(isNaN(n.getTime()))throw Error(`Invalid date value`);return n.getTime()}throw Error(`Invalid type`)},va=`rateLimitErrorInterceptor`,ya=({axiosInstance:e,logger:n,requestConfig:r,context:i,concurrencyManager:a})=>async s=>{let{response:c,config:l}=s,d=l?.signal;if(o(i)||o(l))return n?.warning({category:`HttpClient`,message:`No context or config for this response - that doesn't seem right.`,context:{interceptor:va,...l,httpsAgent:void 0,headers:void 0,hasContext:u(i),hasConfig:u(l)},code:Je.InterceptorContextNotPresent}),Promise.reject(s);if(o(a))return n?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:va,...l,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:u(a)},code:Je.RateLimitOrConcurrencyManagerNotInitialized}),Promise.reject(s);let{requestId:f,targetConcurrencyKey:p,leaseSubscription:m,setRemovalSubscription:h}=l?.requestMetadata??{};if(!(u(f)&&u(p)&&await a.releaseRequest(f,p))&&u(l?.requestMetadata)&&n?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{...i,interceptor:va,requestId:f,targetConcurrencyKey:p,leaseSubscription:m,setRemovalSubscription:h},code:Je.RateLimiterReleaseRequestFailed}),d?.aborted)return Promise.reject(Ye(`Request aborted`,l,`ERR_CANCELED`,c));let{status:g,retryAfter:_}=pa(c,i,r,n);if(g===429&&u(l)){let r=la(_);if(l._retryCount>=5)return n?.warning({category:`HttpClient`,message:`Max retries exceeded for ${l.url}. Aborting.`,context:{...i??{},...l.requestMetadata??{},retryAfterHeader:_,retryAfterAsNumber:r}}),Promise.reject(s);let a=l?._retryCount??0,o={...l,_retryCount:a+1},u=_?r*$e:t(o._retryCount);return n?.debug({category:`HttpClient`,message:`Received 429 error from ${l.url}`,context:{...i,retryAfterHeader:_,calculatedRetryAfter:u}}),await Xe(u,l,c),e?.request(o)}return Promise.reject(s)},ba=`rateLimitResponseInterceptor`,xa=({logger:e,context:t,concurrencyManager:n})=>async r=>{let i=r?.config,a=i?.signal;if(o(t))e?.warning({category:`HttpClient`,message:`No context for this response - that doesn't seem right.`,context:{interceptor:ba,...i,httpsAgent:void 0,headers:void 0}});else if(o(n))return e?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:ba,...i,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:u(n)},code:Je.RateLimitOrConcurrencyManagerNotInitialized}),r;else if(u(t.provider)&&u(t.accountSecureId)){let t=r?.headers;if(u(t)){let n=sa(t);e?.debug({category:`HttpClient`,message:`Rate limit headers extracted`,context:{interceptor:ba,rateLimitHeaders:n}})}let{requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:l}=i?.requestMetadata??{};if(await n.releaseRequest(o,s)||e?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{interceptor:ba,requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:l},code:Je.RateLimiterReleaseRequestFailed}),a?.aborted)return Promise.reject(Ye(`Request aborted`,i,`ERR_CANCELED`,r))}return r},Sa=e=>(e.validateStatus??=e=>e>=200&&e<300,e),Ca=[{onFulfilled:Sa,onRejected:null,options:void 0}],wa=[{onFulfilled:null,onRejected:fa},{onFulfilled:null,onRejected:Ge}],Ta=[{onFulfilled:Sa,onRejected:null,options:void 0},{onFulfilled:Qe,onRejected:null,options:void 0}],Ea=[{onFulfilled:xa,onRejected:ya},{onFulfilled:null,onRejected:Ge}];var Da=class extends _e{constructor(...e){super(...e),this.name=`RateLimitManager`}async additionalInitialization(){}getDynamicMaxWaitTime(e,t,n,r=59,i=.8,a=500){this.readyCheck();let o=e.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.rateLimit??e.mainRatelimit;if(o<=0)throw Error(`Requests per second (rps) must be greater than 0.`);let s=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.maxConcurrency??t.mainMaxConcurrency;if(s<=0)throw Error(`Concurrency must be greater than 0.`);let c=r*i,l=1/Math.min(o,s/(a/1e3)),u=Math.max(7.5,c*l);return Math.min(c,u)}async getWaitTime(e,t,n){this.readyCheck();let r=`rateLimit:${e}`,i=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.subPoolKey,a=u(i)?`${r}-${i}`:r,{mainRatelimit:o,subPools:s}=t,c=[{key:r,rateLimit:o},...s?.map(e=>{let{subPoolKey:t,rateLimit:n}=e;return{key:`${r}-${t}`,rateLimit:n}})??[]],l=c.map(e=>e.key),d=c.map(e=>e.rateLimit);return await this.executeScript(qe.incr,[a,...l],[o.toString(),...d.map(String)])??0}readyCheck(){if(!this.cacheClient||!this.scriptMap?.size)throw Error(`RateLimitManager not ready`)}isReady(){return!!this?.cacheClient&&!!this?.scriptMap?.size}close(){this.scriptMap?.clear(),this.reset()}},Z=class{static{this.instances=new Map}static async prepare(e,t,...n){if(!this.instances.has(e)){let t=new e;t.getSingleton=e=>{let t=this.instances.get(e);if(o(t))throw Error(`Singleton ${e.name} not prepared yet`);if(t.hasInitFailed?.())throw Error(`${e.name} initialization failed`);let n=t.getInstanceIfReady?.();if(u(n))return n;throw Error(`${e.name} not ready`)},this.instances.set(e,t)}let r=this.instances.get(e);try{return await r.getInstance(t,...n)}catch(t){throw r.hasInitFailed?.()&&this.instances.delete(e),t}}static getIfReady(e){return this.instances.get(e)?.getInstanceIfReady?.()??null}static reset(e){this.instances.get(e)?.reset?.(),this.instances.delete(e)}static cleanupFailed(){let e=0;for(let[t,n]of this.instances){let r=n;r?.hasInitFailed?.()&&(r?.reset?.(),this.instances.delete(t),e++)}return e}};let Oa=function(e){return e.HttpTransportInstanceCreateError=`HttpTransportInstanceCreateError`,e}({});const ka=async({logger:e,redisClientConfig:t,context:n,requestConfig:r,httpsAgentConfig:i}={})=>{let a,{NODE_ENV:s}=process.env,c=n?.behaviours??[`CONCURRENCY`,`RETRY`];try{if(a=c.includes(`RETRY`)?ja(e,n):Aa(e,n),o(n?.service)||o(n?.organizationId)||s===`test`||o(t)||o(e))return a;let l=Z.getIfReady(Da)??void 0,d=Z.getIfReady(Pe)??void 0,f=l?.isReady(),p=d?.isRedisConfigured(),m=[],h=[];if(c.includes(`CONCURRENCY`)){if(!p)throw Error(`Concurrency Manager cannot connect to Redis. Cannot create advanced transport instance.`);if(!f)throw Error(`RateLimitManager is not ready. Cannot create advanced transport instance.`);m.push(...Ta),h.push(...Ea)}let g=ca(n);if(o(g))return e?.warning({category:`http-transport`,message:`Unable to create a key for transport instance - Invalid state. Using base default instance.`,context:{...n,defaultInstanceInitialized:u(a)}}),a;let _=await We.get(g);if(u(_))return _;let v={interceptors:{requestConfigs:m,responseConfigs:h},instanceConfig:{maxBodyLength:1/0},logger:e,context:n,requestConfig:r,httpsAgentConfig:i,concurrencyManager:d,rateLimitManager:l},y=He.createInstance(v);return e?.debug({category:`http-transport`,message:`Creating new Axios instance and caching it for key: [${g}]`,context:{...n}}),await We.set(g,y),y}catch(t){return e?.error({category:`http-transport`,message:`Failed to create advanced transport instance. Using default instance.`,context:{...n,usingDefaultInstance:u(a)},error:t,code:Oa.HttpTransportInstanceCreateError}),u(a)?a:Ma()}},Aa=(e,t)=>{let n={instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return He.createInstance(n)??Ma()},ja=(e,t)=>{let n={interceptors:{requestConfigs:Ca,responseConfigs:wa},instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return He.createInstance(n)??Ma()},Ma=()=>g.create({maxBodyLength:1/0});var Na=class{#e;#t;#n;#r;#i;#a;constructor({transportFactory:e=ka,getRedisClient:t=fe,logger:n,redisClientConfig:r,errorMappingFn:i}={}){this.name=`HttpClient`,this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}#o({url:e,payload:t,method:n,context:i}){if(!i?.accountSecureId||i.accountSecureId.length<20||!e||!n)return null;let a=t?r(t):``;return`${i.accountSecureId}-${n.toUpperCase()}${a}-${e}`}async#s({url:e,payload:t,method:n,cacheTTL:r,context:i}){if(!this.#a||!r||r<=0)return null;let a=this.#o({url:e,payload:t,method:n,context:i});if(!a)return null;let o=await this.#a.getData(a);return o?(this.#n?.debug({category:this.name,message:`Cache hit for key [${a}].`}),o):(this.#n?.debug({category:this.name,message:`Cache miss for key [${a}].`}),null)}async#c({url:e,payload:t,method:n,cacheTTL:r,context:i,response:a}){if(!this.#a||!r||r<=0)return!1;let o=this.#o({url:e,payload:t,method:n,context:i});return o?(this.#n?.debug({category:this.name,message:`Caching result for key [${o}].`}),this.#a.setData({key:o,value:a,cacheTTL:r*60})):!1}async request({headers:e={},url:t,method:n=`get`,queryParams:r,maxRedirects:i=0,responseType:a,cacheTTL:s,context:c,traceId:l,payload:d,httpsAgent:f,httpAgent:p,requestConfig:m,httpsAgentConfig:h}){try{u(this.#r)&&o(this.#a)&&(this.#a=await this.#t(this.#r,this.#n,`HttpClient`));let g=this.#_(t,r),_=this.#l(e),v=this.#m(d,e),y=await this.#s({url:g,payload:v,method:n,cacheTTL:s,context:c});if(y)return{...y,responseTime:new Date};let b=Ue.getInstance(),x=(u(l)?await b.get(l):null)?.signal,S=await(await this.#e({redisClientConfig:this.#r,logger:this.#n,context:c,requestConfig:m,httpsAgentConfig:h})).request({headers:_,url:g,method:n,maxRedirects:i,responseType:a,data:v,httpsAgent:f,httpAgent:p,signal:x}),C={data:S.data,status:S.status,body:v,method:n,headers:this.#u(S.headers),requestUrl:t,responseType:S?.config?.responseType,responseTime:new Date};return await this.#c({url:g,payload:v,method:n,cacheTTL:s,context:c,response:C}),C}catch(e){let r=e;r.url=S(t),this.#n?.warning({category:this.name,message:`Request error [${n?.toUpperCase()} ${r.url}]: ${r.message}.`,error:r});let i=this.#h(r);throw u(i)?i:e}}async get({headers:e,url:t,queryParams:n,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s}){return this.request({url:t,method:`get`,queryParams:n,headers:e,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s})}async post({headers:e,url:t,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s}){return this.request({url:t,method:`post`,headers:e,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s})}#l(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n.toLowerCase()]=e[n]||``}),t}#u(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n]=e[n]||``}),t}#d(e){return e[`content-type`]===`application/x-www-form-urlencoded`}#f(e){return e[`content-type`]?.startsWith(`multipart/form-data`)??!1}#p(e){return o(e)||typeof e!=`object`||!e?!1:`pipe`in e&&typeof e.pipe==`function`}#m(e,t){if(!(o(e)||c(e)&&Object.keys(e).length===0))return this.#f(t)||this.#p(e)?e:this.#d(t)?C.stringify(e):e}#h(e){if(_(e)&&this.#i)return this.#i(e)}#g(e){return typeof e==`object`&&!!e&&`value`in e&&(typeof e.value==`string`||Array.isArray(e.value))}#_(e,t){if(o(t)||Object.keys(t).length===0)return e;let n={},r={},i={},a={};for(let[e,o]of Object.entries(t))if(this.#g(o)){let t=o.arrayFormat,s=o.value;t===`repeat`?r[e]=Array.isArray(s)?s:[s]:t===`brackets`?i[e]=Array.isArray(s)?s:[s]:t===`comma`?a[e]=Array.isArray(s)?s:[s]:n[e]=s}else n[e]=o;let s=[];Object.keys(n).length>0&&s.push(C.stringify(n)),Object.keys(r).length>0&&s.push(C.stringify(r,{arrayFormat:`repeat`})),Object.keys(i).length>0&&s.push(C.stringify(i,{arrayFormat:`brackets`})),Object.keys(a).length>0&&s.push(C.stringify(a,{arrayFormat:`comma`}));let c=s.join(`&`);return u(c)?`${e}?${c}`:e}};const Pa=(e,t,n)=>new Na({redisClientConfig:e,logger:t,errorMappingFn:n});var Fa=class{static{this.httpClientInstance=null}static async getInstance({redisClientConfig:e,logger:t,errorMappingFn:n,getHttpClient:r=Pa}){return this.httpClientInstance??=r(e,t,n),this.httpClientInstance}static resetInstance(){this.httpClientInstance=null}};const Ia=[`get`,`post`,`put`,`delete`,`patch`],La={[Se.rPush]:`
|
|
125
|
+
(function(n){var r=2e3,i={s:1,n:0,d:1};function a(e,t){if(isNaN(e=parseInt(e,10)))throw h();return e*t}function o(e,t){if(t===0)throw m();var n=Object.create(p.prototype);n.s=e<0?-1:1,e=e<0?-e:e;var r=f(e,t);return n.n=e/r,n.d=t/r,n}function s(e){for(var t={},n=e,r=2,i=4;i<=n;){for(;n%r===0;)n/=r,t[r]=(t[r]||0)+1;i+=1+2*r++}return n===e?t[e]=(t[e]||0)+1:n>1&&(t[n]=(t[n]||0)+1),t}var c=function(e,t){var n=0,r=1,o=1,s=0,c=0,l=0,u=1,d=1,f=0,p=1,_=1,v=1,y=1e7,b;if(e!=null)if(t!==void 0){if(n=e,r=t,o=n*r,n%1!=0||r%1!=0)throw g()}else switch(typeof e){case`object`:if(`d`in e&&`n`in e)n=e.n,r=e.d,`s`in e&&(n*=e.s);else if(0 in e)n=e[0],1 in e&&(r=e[1]);else throw h();o=n*r;break;case`number`:if(e<0&&(o=e,e=-e),e%1==0)n=e;else if(e>0){for(e>=1&&(d=10**Math.floor(1+Math.log(e)/Math.LN10),e/=d);p<=y&&v<=y;)if(b=(f+_)/(p+v),e===b){p+v<=y?(n=f+_,r=p+v):v>p?(n=_,r=v):(n=f,r=p);break}else e>b?(f+=_,p+=v):(_+=f,v+=p),p>y?(n=_,r=v):(n=f,r=p);n*=d}else (isNaN(e)||isNaN(t))&&(r=n=NaN);break;case`string`:if(p=e.match(/\d+|./g),p===null)throw h();if(p[f]===`-`?(o=-1,f++):p[f]===`+`&&f++,p.length===f+1?c=a(p[f++],o):p[f+1]===`.`||p[f]===`.`?(p[f]!==`.`&&(s=a(p[f++],o)),f++,(f+1===p.length||p[f+1]===`(`&&p[f+3]===`)`||p[f+1]===`'`&&p[f+3]===`'`)&&(c=a(p[f],o),u=10**p[f].length,f++),(p[f]===`(`&&p[f+2]===`)`||p[f]===`'`&&p[f+2]===`'`)&&(l=a(p[f+1],o),d=10**p[f+1].length-1,f+=3)):p[f+1]===`/`||p[f+1]===`:`?(c=a(p[f],o),u=a(p[f+2],1),f+=3):p[f+3]===`/`&&p[f+1]===` `&&(s=a(p[f],o),c=a(p[f+2],o),u=a(p[f+4],1),f+=5),p.length<=f){r=u*d,o=n=l+r*s+d*c;break}default:throw h()}if(r===0)throw m();i.s=o<0?-1:1,i.n=Math.abs(n),i.d=Math.abs(r)};function l(e,t,n){for(var r=1;t>0;e=e*e%n,t>>=1)t&1&&(r=r*e%n);return r}function u(e,t){for(;t%2==0;t/=2);for(;t%5==0;t/=5);if(t===1)return 0;for(var n=10%t,i=1;n!==1;i++)if(n=n*10%t,i>r)return 0;return i}function d(e,t,n){for(var r=1,i=l(10,n,t),a=0;a<300;a++){if(r===i)return a;r=r*10%t,i=i*10%t}return 0}function f(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function p(e,t){if(c(e,t),this instanceof p)e=f(i.d,i.n),this.s=i.s,this.n=i.n/e,this.d=i.d/e;else return o(i.s*i.n,i.d)}var m=function(){return Error(`Division by Zero`)},h=function(){return Error(`Invalid argument`)},g=function(){return Error(`Parameters must be integer`)};p.prototype={s:1,n:0,d:1,abs:function(){return o(this.n,this.d)},neg:function(){return o(-this.s*this.n,this.d)},add:function(e,t){return c(e,t),o(this.s*this.n*i.d+i.s*this.d*i.n,this.d*i.d)},sub:function(e,t){return c(e,t),o(this.s*this.n*i.d-i.s*this.d*i.n,this.d*i.d)},mul:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.n,this.d*i.d)},div:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.d,this.d*i.n)},clone:function(){return o(this.s*this.n,this.d)},mod:function(e,t){if(isNaN(this.n)||isNaN(this.d))return new p(NaN);if(e===void 0)return o(this.s*this.n%this.d,1);if(c(e,t),i.n===0&&this.d===0)throw m();return o(this.s*(i.d*this.n)%(i.n*this.d),i.d*this.d)},gcd:function(e,t){return c(e,t),o(f(i.n,this.n)*f(i.d,this.d),i.d*this.d)},lcm:function(e,t){return c(e,t),i.n===0&&this.n===0?o(0,1):o(i.n*this.n,f(i.n,this.n)*f(i.d,this.d))},ceil:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.ceil(e*this.s*this.n/this.d),e)},floor:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.floor(e*this.s*this.n/this.d),e)},round:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.round(e*this.s*this.n/this.d),e)},inverse:function(){return o(this.s*this.d,this.n)},pow:function(e,t){if(c(e,t),i.d===1)return i.s<0?o((this.s*this.d)**+i.n,this.n**+i.n):o((this.s*this.n)**+i.n,this.d**+i.n);if(this.s<0)return null;var n=s(this.n),r=s(this.d),a=1,l=1;for(var u in n)if(u!==`1`){if(u===`0`){a=0;break}if(n[u]*=i.n,n[u]%i.d===0)n[u]/=i.d;else return null;a*=u**+n[u]}for(var u in r)if(u!==`1`){if(r[u]*=i.n,r[u]%i.d===0)r[u]/=i.d;else return null;l*=u**+r[u]}return i.s<0?o(l,a):o(a,l)},equals:function(e,t){return c(e,t),this.s*this.n*i.d===i.s*i.n*this.d},compare:function(e,t){c(e,t);var n=this.s*this.n*i.d-i.s*i.n*this.d;return(0<n)-(n<0)},simplify:function(e){if(isNaN(this.n)||isNaN(this.d))return this;e||=.001;for(var t=this.abs(),n=t.toContinued(),r=1;r<n.length;r++){for(var i=o(n[r-1],1),a=r-2;a>=0;a--)i=i.inverse().add(n[a]);if(Math.abs(i.sub(t).valueOf())<e)return i.mul(this.s)}return this},divisible:function(e,t){return c(e,t),!(!(i.n*this.d)||this.n*i.d%(i.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,n+=` `,r%=i),n+=r,n+=`/`,n+=i),n},toLatex:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,r%=i),n+=`\\frac{`,n+=r,n+=`}{`,n+=i,n+=`}`),n},toContinued:function(){var e,t=this.n,n=this.d,r=[];if(isNaN(t)||isNaN(n))return r;do r.push(Math.floor(t/n)),e=t%n,t=n,n=e;while(t!==1);return r},toString:function(e){var t=this.n,n=this.d;if(isNaN(t)||isNaN(n))return`NaN`;e||=15;var r=u(t,n),i=d(t,n,r),a=this.s<0?`-`:``;if(a+=t/n|0,t%=n,t*=10,t&&(a+=`.`),r){for(var o=i;o--;)a+=t/n|0,t%=n,t*=10;a+=`(`;for(var o=r;o--;)a+=t/n|0,t%=n,t*=10;a+=`)`}else for(var o=e;t&&o--;)a+=t/n|0,t%=n,t*=10;return a}},typeof e==`object`?(Object.defineProperty(p,`__esModule`,{value:!0}),p.default=p,p.Fraction=p,t.exports=p):n.Fraction=p})(e)}))(),1),qi=Vn(`Fraction`,[],()=>(Object.defineProperty(Ki.default,`name`,{value:`Fraction`}),Ki.default.prototype.constructor=Ki.default,Ki.default.prototype.type=`Fraction`,Ki.default.prototype.isFraction=!0,Ki.default.prototype.toJSON=function(){return{mathjs:`Fraction`,n:this.s*this.n,d:this.d}},Ki.default.fromJSON=function(e){return new Ki.default(e)},Ki.default),{isClass:!0}),Ji=Vn(`Matrix`,[],()=>{function e(){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`)}return e.prototype.type=`Matrix`,e.prototype.isMatrix=!0,e.prototype.storage=function(){throw Error(`Cannot invoke storage on a Matrix interface`)},e.prototype.datatype=function(){throw Error(`Cannot invoke datatype on a Matrix interface`)},e.prototype.create=function(e,t){throw Error(`Cannot invoke create on a Matrix interface`)},e.prototype.subset=function(e,t,n){throw Error(`Cannot invoke subset on a Matrix interface`)},e.prototype.get=function(e){throw Error(`Cannot invoke get on a Matrix interface`)},e.prototype.set=function(e,t,n){throw Error(`Cannot invoke set on a Matrix interface`)},e.prototype.resize=function(e,t){throw Error(`Cannot invoke resize on a Matrix interface`)},e.prototype.reshape=function(e,t){throw Error(`Cannot invoke reshape on a Matrix interface`)},e.prototype.clone=function(){throw Error(`Cannot invoke clone on a Matrix interface`)},e.prototype.size=function(){throw Error(`Cannot invoke size on a Matrix interface`)},e.prototype.map=function(e,t){throw Error(`Cannot invoke map on a Matrix interface`)},e.prototype.forEach=function(e){throw Error(`Cannot invoke forEach on a Matrix interface`)},e.prototype[Symbol.iterator]=function(){throw Error(`Cannot iterate a Matrix interface`)},e.prototype.toArray=function(){throw Error(`Cannot invoke toArray on a Matrix interface`)},e.prototype.valueOf=function(){throw Error(`Cannot invoke valueOf on a Matrix interface`)},e.prototype.format=function(e){throw Error(`Cannot invoke format on a Matrix interface`)},e.prototype.toString=function(){throw Error(`Cannot invoke toString on a Matrix interface`)},e},{isClass:!0});function Yi(e){return Object.keys(e.signatures||{}).reduce(function(e,t){var n=(t.match(/,/g)||[]).length+1;return Math.max(e,n)},-1)}var Xi=Vn(`DenseMatrix`,[`Matrix`],e=>{var{Matrix:t}=e;function n(e,t){if(!(this instanceof n))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!ct(t))throw Error(`Invalid datatype: `+t);if(lt(e))e.type===`DenseMatrix`?(this._data=Ht(e._data),this._size=Ht(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&M(e.data)&&M(e.size))this._data=e.data,this._size=e.size,Cn(this._data,this._size),this._datatype=t||e.datatype;else if(M(e))this._data=l(e),this._size=xn(this._data),Cn(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+Vt(e)+`)`);else this._data=[],this._size=[0],this._datatype=t}n.prototype=new t,n.prototype.createDenseMatrix=function(e,t){return new n(e,t)},Object.defineProperty(n,`name`,{value:`DenseMatrix`}),n.prototype.constructor=n,n.prototype.type=`DenseMatrix`,n.prototype.isDenseMatrix=!0,n.prototype.getDataType=function(){return Nn(this._data,Vt)},n.prototype.storage=function(){return`dense`},n.prototype.datatype=function(){return this._datatype},n.prototype.create=function(e,t){return new n(e,t)},n.prototype.subset=function(e,t,n){switch(arguments.length){case 1:return r(this,e);case 2:case 3:return a(this,e,t,n);default:throw SyntaxError(`Wrong number of arguments`)}},n.prototype.get=function(e){if(!M(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new P(e.length,this._size.length);for(var t=0;t<e.length;t++)F(e[t],this._size[t]);for(var n=this._data,r=0,i=e.length;r<i;r++){var a=e[r];F(a,n.length),n=n[a]}return n},n.prototype.set=function(e,t,n){if(!M(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new P(e.length,this._size.length,`<`);var r,i,a,o=e.map(function(e){return e+1});c(this,o,n);var s=this._data;for(r=0,i=e.length-1;r<i;r++)a=e[r],F(a,s.length),s=s[a];return a=e[e.length-1],F(a,s.length),s[a]=t,this};function r(e,t){if(!mt(t))throw TypeError(`Invalid index`);if(t.isScalar())return e.get(t.min());var r=t.size();if(r.length!==e._size.length)throw new P(r.length,e._size.length);for(var a=t.min(),o=t.max(),s=0,c=e._size.length;s<c;s++)F(a[s],e._size[s]),F(o[s],e._size[s]);return new n(i(e._data,t,r.length,0),e._datatype)}function i(e,t,n,r){var a=r===n-1,o=t.dimension(r);return a?o.map(function(t){return F(t,e.length),e[t]}).valueOf():o.map(function(a){F(a,e.length);var o=e[a];return i(o,t,n,r+1)}).valueOf()}function a(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Invalid index`);var i=t.size(),a=t.isScalar(),s;if(lt(n)?(s=n.size(),n=n.valueOf()):s=xn(n),a){if(s.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!Wt(s,i))try{n=s.length===0?Rn([n],i):Rn(n,i),s=xn(n)}catch{}if(i.length<e._size.length)throw new P(i.length,e._size.length,`<`);if(s.length<i.length){for(var l=0,u=0;i[l]===1&&s[l]===1;)l++;for(;i[l]===1;)u++,l++;n=An(n,i.length,u,s)}if(!Wt(i,s))throw new P(i,s,`>`);c(e,t.max().map(function(e){return e+1}),r);var d=i.length;o(e._data,t,n,d,0)}return e}function o(e,t,n,r,i){var a=i===r-1,s=t.dimension(i);a?s.forEach(function(t,r){F(t),e[t]=n[r[0]]}):s.forEach(function(a,s){F(a),o(e[a],t,n[s[0]],r,i+1)})}n.prototype.resize=function(e,t,n){if(!ut(e))throw TypeError(`Array or Matrix expected`);var r=e.valueOf().map(e=>Array.isArray(e)&&e.length===1?e[0]:e);return s(n?this.clone():this,r,t)};function s(e,t,n){if(t.length===0){for(var r=e._data;M(r);)r=r[0];return r}return e._size=t.slice(0),e._data=wn(e._data,e._size,n),e}n.prototype.reshape=function(e,t){var n=t?this.clone():this;return n._data=En(n._data,e),n._size=Dn(e,n._size.reduce((e,t)=>e*t)),n};function c(e,t,n){for(var r=e._size.slice(0),i=!1;r.length<t.length;)r.push(0),i=!0;for(var a=0,o=t.length;a<o;a++)t[a]>r[a]&&(r[a]=t[a],i=!0);i&&s(e,r,n)}n.prototype.clone=function(){return new n({data:Ht(this._data),size:Ht(this._size),datatype:this._datatype})},n.prototype.size=function(){return this._size.slice(0)},n.prototype.map=function(e){var t=this,r=Yi(e),i=function n(i,a){return M(i)?i.map(function(e,t){return n(e,a.concat(t))}):r===1?e(i):r===2?e(i,a):e(i,a,t)}(this._data,[]);return new n(i,this._datatype===void 0?void 0:Nn(i,Vt))},n.prototype.forEach=function(e){var t=this;(function n(r,i){M(r)?r.forEach(function(e,t){n(e,i.concat(t))}):e(r,i,t)})(this._data,[])},n.prototype[Symbol.iterator]=function*(){yield*function*e(t,n){if(M(t))for(var r=0;r<t.length;r++)yield*e(t[r],n.concat(r));else yield{value:t,index:n}}(this._data,[])},n.prototype.rows=function(){var e=[];if(this.size().length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var t of this._data)e.push(new n([t],this._datatype));return e},n.prototype.columns=function(){var e=this,t=[],r=this.size();if(r.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var i=this._data,a=function(r){var a=i.map(e=>[e[r]]);t.push(new n(a,e._datatype))},o=0;o<r[1];o++)a(o);return t},n.prototype.toArray=function(){return Ht(this._data)},n.prototype.valueOf=function(){return this._data},n.prototype.format=function(e){return mn(this._data,e)},n.prototype.toString=function(){return mn(this._data)},n.prototype.toJSON=function(){return{mathjs:`DenseMatrix`,data:this._data,size:this._size,datatype:this._datatype}},n.prototype.diagonal=function(e){if(e){if(it(e)&&(e=e.toNumber()),!j(e)||!N(e))throw TypeError(`The parameter k must be an integer number`)}else e=0;for(var t=e>0?e:0,r=e<0?-e:0,i=this._size[0],a=this._size[1],o=Math.min(i-r,a-t),s=[],c=0;c<o;c++)s[c]=this._data[c+r][c+t];return new n({data:s,size:[o],datatype:this._datatype})},n.diagonal=function(e,t,r,i){if(!M(e))throw TypeError(`Array expected, size parameter`);if(e.length!==2)throw Error(`Only two dimensions matrix are supported`);if(e=e.map(function(e){if(it(e)&&(e=e.toNumber()),!j(e)||!N(e)||e<1)throw Error(`Size values must be positive integers`);return e}),r){if(it(r)&&(r=r.toNumber()),!j(r)||!N(r))throw TypeError(`The parameter k must be an integer number`)}else r=0;var a=r>0?r:0,o=r<0?-r:0,s=e[0],c=e[1],l=Math.min(s-o,c-a),u;if(M(t)){if(t.length!==l)throw Error(`Invalid value array length`);u=function(e){return t[e]}}else if(lt(t)){var d=t.size();if(d.length!==1||d[0]!==l)throw Error(`Invalid matrix length`);u=function(e){return t.get([e])}}else u=function(){return t};i||=it(u(0))?u(0).mul(0):0;var f=[];if(e.length>0){f=wn(f,e,i);for(var p=0;p<l;p++)f[p+o][p+a]=u(p)}return new n({data:f,size:[s,c]})},n.fromJSON=function(e){return new n(e)},n.prototype.swapRows=function(e,t){if(!j(e)||!N(e)||!j(t)||!N(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return F(e,this._size[0]),F(t,this._size[0]),n._swapRows(e,t,this._data),this},n._swapRows=function(e,t,n){var r=n[e];n[e]=n[t],n[t]=r};function l(e){return lt(e)?l(e.valueOf()):M(e)?e.map(l):e}return n},{isClass:!0});function Zi(e,t,n){return e&&typeof e.map==`function`?e.map(function(e){return Zi(e,t,n)}):t(e)}var Qi=`isNumeric`,$i=Vn(Qi,[`typed`],e=>{var{typed:t}=e;return t(Qi,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>Zi(t,e))})}),ea=`hasNumericValue`,ta=Vn(ea,[`typed`,`isNumeric`],e=>{var{typed:t,isNumeric:n}=e;return t(ea,{boolean:()=>!0,string:function(e){return e.trim().length>0&&!isNaN(Number(e))},any:function(e){return n(e)}})}),na=rr({BigNumber:Ri({config:Xt}),Complex:Gi({}),DenseMatrix:Xi({Matrix:Ji({})}),Fraction:qi({})}),ra=ta({isNumeric:$i({typed:na}),typed:na});const ia=e=>{let t=Number(e);return Number.isNaN(t)?!1:t>=120&&t<=36e4},aa=e=>{let t=Number(e),n=Date.now();return Number.isNaN(t)?n+1e3:!ia(t)&&a(t)?tt(t):ia(t)?n+t:n+t*$e},oa=e=>{let t={};for(let[n,r]of Object.entries(e)){let e=n.toLowerCase().replace(/^x-/,``).replace(/concurren.+-/g,`concurrency-`).replace(/-/g,``);t[e]=ra(r)?Number(r):null}return t},sa=e=>{let t=oa(e);return{rateLimitLimit:t.ratelimitlimit,rateLimitRemaining:t.ratelimitremaining,rateLimitReset:aa(t.ratelimitreset),concurrencyLimit:t.ratelimitconcurrencylimit,concurrencyRemaining:t.ratelimitconcurrencyremaining,concurrencyReset:aa(t.ratelimitconcurrencyreset)}},ca=e=>{let{accountSecureId:t,service:n,resource:r,subResource:i,childResource:a,action:s,behaviours:c}=e??{};return[t,n,r,s].some(o)?null:[t,n,r,i,a,s,...c??[]].filter(Boolean).join(`-`)},la=(e,t=10,n=1)=>{let r=Date.now();return a(e)||s(e)?ua(Number(e),r,t,n):ct(e)&&e!==``?da(e,r,t,n):n},ua=(e,t,n=10,r=1)=>{if(e<n)return e;let i=tt(e);if(i>t){let e=Math.floor((i-t)/$e);return e>0&&e<n?e:r}return r},da=(e,t,n=10,r=1)=>{if(et.test(e)){let t=parseFloat(e);return t>0&&t<n?t:r}let i=new Date(e);if(Number.isNaN(i.getTime()))return r;let a=i.getTime();if(a>t){let e=Math.floor((a-t)/$e);return e>0&&e<n?e:r}return r},fa=({axiosInstance:e,logger:n,requestConfig:r,context:i})=>async a=>{let{response:o,config:s}=a;if(s?.signal?.aborted)return Promise.reject(Ye(`Request aborted`,s,`ERR_CANCELED`,o));let{status:c,retryAfter:l}=pa(o,i,r,n);if(c===429&&u(s)){let r=la(l);if(s._retryCount>=5)return n?.warning({category:`http-transport`,message:`Max retries exceeded for ${s?.url}. Aborting.`,context:{...i??{},retryAfterHeader:l,retryAfterAsNumber:r}}),Promise.reject(a);let c=s._retryCount??0,u={...s,_retryCount:c+1},d=l?r*$e:t(u._retryCount);return n?.debug({category:`http-transport`,message:`Received 429 error from ${s?.url}`,context:{...i??{},retryAfterHeader:l,calculatedRetryAfter:d}}),await Xe(d,s,o),e?.request(u)}return Promise.reject(a)},pa=(e,t,n,r)=>{let{provider:i}=t??{},{status:a,headers:s,data:l}=e??{},{retryafter:d}=oa(s??{});if(o(i)||o(e))return r?.warning({category:`http-transport`,message:`Invalid parameters for convertError`,context:{...t,responseIsMissing:o(e),providerIsMissing:o(i),status:e?.status??`undefined`,statusText:e?.statusText??`undefined`,retryafter:d??`undefined`}}),{status:a,retryAfter:d};let f=n?.rateLimits?.mappedRateLimitErrors;if(u(f)&&u(l))for(let e of f){let{errorStatus:t,errorMessagePath:n,errorMessage:r,retryAfterPath:i,retryAfterUnit:o,retryAfterValue:u}=e;if(t!==a)continue;let f=n??`message`,p=ma(c(l)?x({path:f,json:l})[0]:l,r);if(t===a&&p){let e=ga(u??ha(s,i),o);return{status:429,retryAfter:d??e}}}return{status:a,retryAfter:d}},ma=(e,t)=>t instanceof RegExp?t.test(e??``):e?.includes(t)??!1,ha=(e,t)=>u(t)&&u(e)?x({path:t,json:e})[0]:null,ga=(e,t=`seconds`)=>u(e)?_a(e,t):null,_a=(e,t)=>{if(t===`seconds`)return typeof e==`string`?parseFloat(e):e;if(t===`milliseconds`)return(typeof e==`string`?parseFloat(e):e)/$e;if(t===`date`){let t=typeof e==`string`&&!isNaN(Number(e))?parseFloat(e):e,n=new Date(t);if(isNaN(n.getTime()))throw Error(`Invalid date value`);return n.getTime()}throw Error(`Invalid type`)},va=`rateLimitErrorInterceptor`,ya=({axiosInstance:e,logger:n,requestConfig:r,context:i,concurrencyManager:a})=>async s=>{let{response:c,config:l}=s,d=l?.signal;if(o(i)||o(l))return n?.warning({category:`HttpClient`,message:`No context or config for this response - that doesn't seem right.`,context:{interceptor:va,...l,httpsAgent:void 0,headers:void 0,hasContext:u(i),hasConfig:u(l)},code:Je.InterceptorContextNotPresent}),Promise.reject(s);if(o(a))return n?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:va,...l,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:u(a)},code:Je.RateLimitOrConcurrencyManagerNotInitialized}),Promise.reject(s);let{requestId:f,targetConcurrencyKey:p,leaseSubscription:m,setRemovalSubscription:h}=l?.requestMetadata??{};if(!(u(f)&&u(p)&&await a.releaseRequest(f,p))&&u(l?.requestMetadata)&&n?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{...i,interceptor:va,requestId:f,targetConcurrencyKey:p,leaseSubscription:m,setRemovalSubscription:h},code:Je.RateLimiterReleaseRequestFailed}),d?.aborted)return Promise.reject(Ye(`Request aborted`,l,`ERR_CANCELED`,c));let{status:g,retryAfter:_}=pa(c,i,r,n);if(g===429&&u(l)){let r=la(_);if(l._retryCount>=5)return n?.warning({category:`HttpClient`,message:`Max retries exceeded for ${l.url}. Aborting.`,context:{...i??{},...l.requestMetadata??{},retryAfterHeader:_,retryAfterAsNumber:r}}),Promise.reject(s);let a=l?._retryCount??0,o={...l,_retryCount:a+1},u=_?r*$e:t(o._retryCount);return n?.debug({category:`HttpClient`,message:`Received 429 error from ${l.url}`,context:{...i,retryAfterHeader:_,calculatedRetryAfter:u}}),await Xe(u,l,c),e?.request(o)}return Promise.reject(s)},ba=`rateLimitResponseInterceptor`,xa=({logger:e,context:t,concurrencyManager:n})=>async r=>{let i=r?.config,a=i?.signal;if(o(t))e?.warning({category:`HttpClient`,message:`No context for this response - that doesn't seem right.`,context:{interceptor:ba,...i,httpsAgent:void 0,headers:void 0}});else if(o(n))return e?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:ba,...i,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:u(n)},code:Je.RateLimitOrConcurrencyManagerNotInitialized}),r;else if(u(t.provider)&&u(t.accountSecureId)){let t=r?.headers;if(u(t)){let n=sa(t);e?.debug({category:`HttpClient`,message:`Rate limit headers extracted`,context:{interceptor:ba,rateLimitHeaders:n}})}let{requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:l}=i?.requestMetadata??{};if(await n.releaseRequest(o,s)||e?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{interceptor:ba,requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:l},code:Je.RateLimiterReleaseRequestFailed}),a?.aborted)return Promise.reject(Ye(`Request aborted`,i,`ERR_CANCELED`,r))}return r},Sa=e=>(e.validateStatus??=e=>e>=200&&e<300,e),Ca=[{onFulfilled:Sa,onRejected:null,options:void 0}],wa=[{onFulfilled:null,onRejected:fa},{onFulfilled:null,onRejected:Ge}],Ta=[{onFulfilled:Sa,onRejected:null,options:void 0},{onFulfilled:Qe,onRejected:null,options:void 0}],Ea=[{onFulfilled:xa,onRejected:ya},{onFulfilled:null,onRejected:Ge}];var Da=class extends _e{constructor(...e){super(...e),this.name=`RateLimitManager`}async additionalInitialization(){}getDynamicMaxWaitTime(e,t,n,r=59,i=.8,a=500){this.readyCheck();let o=e.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.rateLimit??e.mainRatelimit;if(o<=0)throw Error(`Requests per second (rps) must be greater than 0.`);let s=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.maxConcurrency??t.mainMaxConcurrency;if(s<=0)throw Error(`Concurrency must be greater than 0.`);let c=r*i,l=1/Math.min(o,s/(a/1e3)),u=Math.max(7.5,c*l);return Math.min(c,u)}async getWaitTime(e,t,n){this.readyCheck();let r=`rateLimit:${e}`,i=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.subPoolKey,a=u(i)?`${r}-${i}`:r,{mainRatelimit:o,subPools:s}=t,c=[{key:r,rateLimit:o},...s?.map(e=>{let{subPoolKey:t,rateLimit:n}=e;return{key:`${r}-${t}`,rateLimit:n}})??[]],l=c.map(e=>e.key),d=c.map(e=>e.rateLimit);return await this.executeScript(qe.incr,[a,...l],[o.toString(),...d.map(String)])??0}readyCheck(){if(!this.cacheClient||!this.scriptMap?.size)throw Error(`RateLimitManager not ready`)}isReady(){return!!this?.cacheClient&&!!this?.scriptMap?.size}close(){this.scriptMap?.clear(),this.reset()}},Z=class{static{this.instances=new Map}static async prepare(e,t,...n){if(!this.instances.has(e)){let t=new e;t.getSingleton=e=>{let t=this.instances.get(e);if(o(t))throw Error(`Singleton ${e.name} not prepared yet`);if(t.hasInitFailed?.())throw Error(`${e.name} initialization failed`);let n=t.getInstanceIfReady?.();if(u(n))return n;throw Error(`${e.name} not ready`)},this.instances.set(e,t)}let r=this.instances.get(e);try{return await r.getInstance(t,...n)}catch(t){throw r.hasInitFailed?.()&&this.instances.delete(e),t}}static getIfReady(e){return this.instances.get(e)?.getInstanceIfReady?.()??null}static reset(e){this.instances.get(e)?.reset?.(),this.instances.delete(e)}static cleanupFailed(){let e=0;for(let[t,n]of this.instances){let r=n;r?.hasInitFailed?.()&&(r?.reset?.(),this.instances.delete(t),e++)}return e}};let Oa=function(e){return e.HttpTransportInstanceCreateError=`HttpTransportInstanceCreateError`,e}({});const ka=async({logger:e,redisClientConfig:t,context:n,requestConfig:r,httpsAgentConfig:i}={})=>{let a,{NODE_ENV:s}=process.env,c=n?.behaviours??[`CONCURRENCY`,`RETRY`];try{if(a=c.includes(`RETRY`)?ja(e,n):Aa(e,n),o(n?.service)||o(n?.organizationId)||s===`test`||o(t)||o(e))return a;let l=Z.getIfReady(Da)??void 0,d=Z.getIfReady(Pe)??void 0,f=l?.isReady(),p=d?.isRedisConfigured(),m=[],h=[];if(c.includes(`CONCURRENCY`)){if(!p)throw Error(`Concurrency Manager cannot connect to Redis. Cannot create advanced transport instance.`);if(!f)throw Error(`RateLimitManager is not ready. Cannot create advanced transport instance.`);m.push(...Ta),h.push(...Ea)}let g=ca(n);if(o(g))return e?.warning({category:`http-transport`,message:`Unable to create a key for transport instance - Invalid state. Using base default instance.`,context:{...n,defaultInstanceInitialized:u(a)}}),a;let _=await We.get(g);if(u(_))return _;let v={interceptors:{requestConfigs:m,responseConfigs:h},instanceConfig:{maxBodyLength:1/0},logger:e,context:n,requestConfig:r,httpsAgentConfig:i,concurrencyManager:d,rateLimitManager:l},y=He.createInstance(v);return e?.debug({category:`http-transport`,message:`Creating new Axios instance and caching it for key: [${g}]`,context:{...n}}),await We.set(g,y),y}catch(t){return e?.error({category:`http-transport`,message:`Failed to create advanced transport instance. Using default instance.`,context:{...n,usingDefaultInstance:u(a)},error:t,code:Oa.HttpTransportInstanceCreateError}),u(a)?a:Ma()}},Aa=(e,t)=>{let n={instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return He.createInstance(n)??Ma()},ja=(e,t)=>{let n={interceptors:{requestConfigs:Ca,responseConfigs:wa},instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return He.createInstance(n)??Ma()},Ma=()=>g.create({maxBodyLength:1/0});var Na=class{#e;#t;#n;#r;#i;#a;constructor({transportFactory:e=ka,getRedisClient:t=fe,logger:n,redisClientConfig:r,errorMappingFn:i}={}){this.name=`HttpClient`,this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}#o({url:e,payload:t,method:n,context:i}){if(!i?.accountSecureId||i.accountSecureId.length<20||!e||!n)return null;let a=t?r(t):``;return`${i.accountSecureId}-${n.toUpperCase()}${a}-${e}`}async#s({url:e,payload:t,method:n,cacheTTL:r,context:i}){if(!this.#a||!r||r<=0)return null;let a=this.#o({url:e,payload:t,method:n,context:i});if(!a)return null;let o=await this.#a.getData(a);return o?(this.#n?.debug({category:this.name,message:`Cache hit for key [${a}].`}),o):(this.#n?.debug({category:this.name,message:`Cache miss for key [${a}].`}),null)}async#c({url:e,payload:t,method:n,cacheTTL:r,context:i,response:a}){if(!this.#a||!r||r<=0)return!1;let o=this.#o({url:e,payload:t,method:n,context:i});return o?(this.#n?.debug({category:this.name,message:`Caching result for key [${o}].`}),this.#a.setData({key:o,value:a,cacheTTL:r*60})):!1}async request({headers:e={},url:t,method:n=`get`,queryParams:r,maxRedirects:i=0,responseType:a,cacheTTL:s,context:c,traceId:l,payload:d,httpsAgent:f,httpAgent:p,requestConfig:m,httpsAgentConfig:h}){try{u(this.#r)&&o(this.#a)&&(this.#a=await this.#t(this.#r,this.#n,`HttpClient`));let g=this.#_(t,r),_=this.#l(e),v=this.#m(d,e),y=await this.#s({url:g,payload:v,method:n,cacheTTL:s,context:c});if(y)return{...y,responseTime:new Date};let b=Ue.getInstance(),x=(u(l)?await b.get(l):null)?.signal,S=await(await this.#e({redisClientConfig:this.#r,logger:this.#n,context:c,requestConfig:m,httpsAgentConfig:h})).request({headers:_,url:g,method:n,maxRedirects:i,responseType:a,data:v,httpsAgent:f,httpAgent:p,signal:x}),C={data:S.data,status:S.status,body:v,method:n,headers:this.#u(S.headers),requestUrl:t,responseType:S?.config?.responseType,responseTime:new Date};return await this.#c({url:g,payload:v,method:n,cacheTTL:s,context:c,response:C}),C}catch(e){let r=e;r.url=S(t),this.#n?.warning({category:this.name,message:`Request error [${n?.toUpperCase()} ${r.url}]: ${r.message}.`,error:r});let i=this.#h(r);throw u(i)?i:e}}async get({headers:e,url:t,queryParams:n,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s}){return this.request({url:t,method:`get`,queryParams:n,headers:e,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s})}async post({headers:e,url:t,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s}){return this.request({url:t,method:`post`,headers:e,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s})}async requestStream({headers:e={},url:t,method:n=`get`,queryParams:r,maxRedirects:i=0,context:a,traceId:o,payload:s,httpsAgent:c,httpAgent:l,requestConfig:d,httpsAgentConfig:f}){try{let p=this.#_(t,r),m=this.#l(e),h=this.#m(s,e),g=Ue.getInstance(),_=(u(o)?await g.get(o):null)?.signal,v=await(await this.#e({redisClientConfig:this.#r,logger:this.#n,context:a,requestConfig:d,httpsAgentConfig:f})).request({headers:m,url:p,method:n,maxRedirects:i,responseType:`stream`,data:h,httpsAgent:c,httpAgent:l,signal:_});return{status:v.status,headers:this.#u(v.headers),stream:v.data,requestUrl:t}}catch(e){let r=e;r.url=S(t),this.#n?.warning({category:this.name,message:`Stream request error [${n?.toUpperCase()} ${r.url}]: ${r.message}.`,error:r});let i=this.#h(r);throw u(i)?i:e}}#l(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n.toLowerCase()]=e[n]||``}),t}#u(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n]=e[n]||``}),t}#d(e){return e[`content-type`]===`application/x-www-form-urlencoded`}#f(e){return e[`content-type`]?.startsWith(`multipart/form-data`)??!1}#p(e){return o(e)||typeof e!=`object`||!e?!1:`pipe`in e&&typeof e.pipe==`function`}#m(e,t){if(!(o(e)||c(e)&&Object.keys(e).length===0))return this.#f(t)||this.#p(e)?e:this.#d(t)?C.stringify(e):e}#h(e){if(_(e)&&this.#i)return this.#i(e)}#g(e){return typeof e==`object`&&!!e&&`value`in e&&(typeof e.value==`string`||Array.isArray(e.value))}#_(e,t){if(o(t)||Object.keys(t).length===0)return e;let n={},r={},i={},a={};for(let[e,o]of Object.entries(t))if(this.#g(o)){let t=o.arrayFormat,s=o.value;t===`repeat`?r[e]=Array.isArray(s)?s:[s]:t===`brackets`?i[e]=Array.isArray(s)?s:[s]:t===`comma`?a[e]=Array.isArray(s)?s:[s]:n[e]=s}else n[e]=o;let s=[];Object.keys(n).length>0&&s.push(C.stringify(n)),Object.keys(r).length>0&&s.push(C.stringify(r,{arrayFormat:`repeat`})),Object.keys(i).length>0&&s.push(C.stringify(i,{arrayFormat:`brackets`})),Object.keys(a).length>0&&s.push(C.stringify(a,{arrayFormat:`comma`}));let c=s.join(`&`);return u(c)?`${e}?${c}`:e}};const Pa=(e,t,n)=>new Na({redisClientConfig:e,logger:t,errorMappingFn:n});var Fa=class{static{this.httpClientInstance=null}static async getInstance({redisClientConfig:e,logger:t,errorMappingFn:n,getHttpClient:r=Pa}){return this.httpClientInstance??=r(e,t,n),this.httpClientInstance}static resetInstance(){this.httpClientInstance=null}};const Ia=[`get`,`post`,`put`,`delete`,`patch`],La={[Se.rPush]:`
|
|
126
126
|
local queueLength = redis.call('RPUSH', KEYS[1], ARGV[1])
|
|
127
127
|
|
|
128
128
|
redis.call('PEXPIRE', KEYS[1], ARGV[2])
|