@stackone/transport 2.12.0 → 2.13.1

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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as redis from "redis";
2
- import { AxiosError, AxiosInstance, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
2
+ import { AxiosError, AxiosInstance, AxiosInterceptorManager, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
3
3
  import http, { AgentOptions } from "node:http";
4
4
  import https from "node:https";
5
5
  import { Readable } from "node:stream";
@@ -378,6 +378,7 @@ type AxiosErrorWithRequestMetadata = AxiosErrorWithRetryCount & {
378
378
  type RequestInterceptor = (value: InternalAxiosRequestConfig<unknown>) => InternalAxiosRequestConfig<unknown> | Promise<InternalAxiosRequestConfig<unknown>>;
379
379
  type ResponseInterceptor = (value: AxiosResponse<unknown, unknown>) => AxiosResponse<unknown, unknown> | Promise<AxiosResponse<unknown, unknown>>;
380
380
  type ErrorInterceptor = (error: unknown) => unknown;
381
+ type OnFulfilledInterceptors = RequestInterceptor | ResponseInterceptor | null;
381
382
  type Interceptor = RequestInterceptor | ResponseInterceptor | ErrorInterceptor | null;
382
383
  interface InterceptorDependencies {
383
384
  axiosInstance?: AxiosInstance;
@@ -407,8 +408,9 @@ type RequestParameter = {
407
408
  };
408
409
  //#endregion
409
410
  //#region src/httpClient/types.d.ts
411
+ type HttpHeader = string | string[];
410
412
  type HttpHeaders = {
411
- [key: string]: string;
413
+ [key: string]: HttpHeader;
412
414
  };
413
415
  type HttpQueryParamValue = {
414
416
  value: string | string[];
@@ -419,7 +421,7 @@ type HttpQueryParams = {
419
421
  };
420
422
  declare const HttpMethods: readonly ["get", "post", "put", "delete", "patch"];
421
423
  type HttpMethod = (typeof HttpMethods)[number];
422
- type HttpResponse<T = any> = {
424
+ type HttpResponse<T = any, P = any> = {
423
425
  data: T;
424
426
  status: number;
425
427
  headers: HttpHeaders;
@@ -427,6 +429,7 @@ type HttpResponse<T = any> = {
427
429
  responseType?: string;
428
430
  responseTime?: Date;
429
431
  message?: string;
432
+ body?: P;
430
433
  };
431
434
  type StreamHttpResponse = {
432
435
  status: number;
@@ -813,6 +816,8 @@ declare class HttpClientManager {
813
816
  }
814
817
  //#endregion
815
818
  //#region src/httpTransportFactory/types.d.ts
819
+ type RequestInterceptorTuple = [RequestInterceptor | null, ErrorInterceptor | null, AxiosInterceptorOptions | undefined];
820
+ type ResponseInterceptorTuple = [ResponseInterceptor | null, ErrorInterceptor | null];
816
821
  type InterceptorDependencyInjector<T extends Interceptor> = (dependencies: InterceptorDependencies) => T;
817
822
  type RequestInterceptorConfig = {
818
823
  onFulfilled: InterceptorDependencyInjector<RequestInterceptor> | RequestInterceptor | null;
@@ -837,6 +842,10 @@ type HttpTransportInstanceConfig = {
837
842
  concurrencyManager?: ConcurrencyManager;
838
843
  rateLimitManager?: RateLimitManager;
839
844
  };
845
+ interface InterceptorManager<V> extends AxiosInterceptorManager<V> {
846
+ forEach(fn: (handler: any) => unknown): void;
847
+ handlers: [];
848
+ }
840
849
  //#endregion
841
850
  //#region src/httpTransportFactory/index.d.ts
842
851
  declare class HttpTransportFactory {
@@ -1044,4 +1053,4 @@ type LockEntry = {
1044
1053
  unlock: Unlock;
1045
1054
  };
1046
1055
  //#endregion
1047
- export { type AxiosErrorWithRequestMetadata, type AxiosErrorWithRetryCount, 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, convertError, createAuthorizationHeaders, getRetryAfterWaitTime, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, superNormalizeHeaders, translateCustomError };
1056
+ export { type AxiosErrorWithRequestMetadata, type AxiosErrorWithRetryCount, CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorInterceptor, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeader, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type HttpTransportInstanceConfig, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Interceptor, type InterceptorConfigs, type InterceptorDependencies, type InterceptorDependencyInjector, type InterceptorManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type OnFulfilledInterceptors, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestInterceptor, type RequestInterceptorConfig, type RequestInterceptorTuple, type RequestParameter, RequestParameterLocations, type ResponseInterceptor, type ResponseInterceptorConfig, type ResponseInterceptorTuple, ScriptManager, type StreamHttpResponse, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, convertError, createAuthorizationHeaders, getRetryAfterWaitTime, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, superNormalizeHeaders, translateCustomError };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { n as __name } from "./chunk-hhuvQGXm.mjs";
2
2
  import { z } from "@stackone/utils";
3
3
  import * as redis from "redis";
4
- import { AxiosError, AxiosInstance, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
4
+ import { AxiosError, AxiosInstance, AxiosInterceptorManager, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
5
5
  import https from "node:https";
6
6
  import http, { AgentOptions } from "node:http";
7
7
  import { Readable } from "node:stream";
@@ -377,6 +377,7 @@ type AxiosErrorWithRequestMetadata = AxiosErrorWithRetryCount & {
377
377
  type RequestInterceptor = (value: InternalAxiosRequestConfig<unknown>) => InternalAxiosRequestConfig<unknown> | Promise<InternalAxiosRequestConfig<unknown>>;
378
378
  type ResponseInterceptor = (value: AxiosResponse<unknown, unknown>) => AxiosResponse<unknown, unknown> | Promise<AxiosResponse<unknown, unknown>>;
379
379
  type ErrorInterceptor = (error: unknown) => unknown;
380
+ type OnFulfilledInterceptors = RequestInterceptor | ResponseInterceptor | null;
380
381
  type Interceptor = RequestInterceptor | ResponseInterceptor | ErrorInterceptor | null;
381
382
  interface InterceptorDependencies {
382
383
  axiosInstance?: AxiosInstance;
@@ -406,8 +407,9 @@ type RequestParameter = {
406
407
  };
407
408
  //#endregion
408
409
  //#region src/httpClient/types.d.ts
410
+ type HttpHeader = string | string[];
409
411
  type HttpHeaders = {
410
- [key: string]: string;
412
+ [key: string]: HttpHeader;
411
413
  };
412
414
  type HttpQueryParamValue = {
413
415
  value: string | string[];
@@ -418,7 +420,7 @@ type HttpQueryParams = {
418
420
  };
419
421
  declare const HttpMethods: readonly ["get", "post", "put", "delete", "patch"];
420
422
  type HttpMethod = (typeof HttpMethods)[number];
421
- type HttpResponse<T = any> = {
423
+ type HttpResponse<T = any, P = any> = {
422
424
  data: T;
423
425
  status: number;
424
426
  headers: HttpHeaders;
@@ -426,6 +428,7 @@ type HttpResponse<T = any> = {
426
428
  responseType?: string;
427
429
  responseTime?: Date;
428
430
  message?: string;
431
+ body?: P;
429
432
  };
430
433
  type StreamHttpResponse = {
431
434
  status: number;
@@ -812,6 +815,8 @@ declare class HttpClientManager {
812
815
  }
813
816
  //#endregion
814
817
  //#region src/httpTransportFactory/types.d.ts
818
+ type RequestInterceptorTuple = [RequestInterceptor | null, ErrorInterceptor | null, AxiosInterceptorOptions | undefined];
819
+ type ResponseInterceptorTuple = [ResponseInterceptor | null, ErrorInterceptor | null];
815
820
  type InterceptorDependencyInjector<T extends Interceptor> = (dependencies: InterceptorDependencies) => T;
816
821
  type RequestInterceptorConfig = {
817
822
  onFulfilled: InterceptorDependencyInjector<RequestInterceptor> | RequestInterceptor | null;
@@ -836,6 +841,10 @@ type HttpTransportInstanceConfig = {
836
841
  concurrencyManager?: ConcurrencyManager;
837
842
  rateLimitManager?: RateLimitManager;
838
843
  };
844
+ interface InterceptorManager<V> extends AxiosInterceptorManager<V> {
845
+ forEach(fn: (handler: any) => unknown): void;
846
+ handlers: [];
847
+ }
839
848
  //#endregion
840
849
  //#region src/httpTransportFactory/index.d.ts
841
850
  declare class HttpTransportFactory {
@@ -1043,4 +1052,4 @@ type LockEntry = {
1043
1052
  unlock: Unlock;
1044
1053
  };
1045
1054
  //#endregion
1046
- export { type AxiosErrorWithRequestMetadata, type AxiosErrorWithRetryCount, 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, convertError, createAuthorizationHeaders, getRetryAfterWaitTime, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, superNormalizeHeaders, translateCustomError };
1055
+ export { type AxiosErrorWithRequestMetadata, type AxiosErrorWithRetryCount, CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorInterceptor, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeader, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type HttpTransportInstanceConfig, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Interceptor, type InterceptorConfigs, type InterceptorDependencies, type InterceptorDependencyInjector, type InterceptorManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type OnFulfilledInterceptors, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestInterceptor, type RequestInterceptorConfig, type RequestInterceptorTuple, type RequestParameter, RequestParameterLocations, type ResponseInterceptor, type ResponseInterceptorConfig, type ResponseInterceptorTuple, ScriptManager, type StreamHttpResponse, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, convertError, createAuthorizationHeaders, getRetryAfterWaitTime, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, superNormalizeHeaders, translateCustomError };
package/dist/index.mjs CHANGED
@@ -110,7 +110,7 @@ Example:
110
110
  * Copyright (c) 2023, Robert Eisele (robert@raw.org)
111
111
  * Dual licensed under the MIT or GPL Version 2 licenses.
112
112
  **/
113
- (function(r){var i=2e3,a={s:1,n:0,d:1};function assign(e,t){if(isNaN(e=parseInt(e,10)))throw InvalidParameter();return e*t}function newFraction(e,t){if(t===0)throw DivisionByZero();var n=Object.create(Fraction$2.prototype);n.s=e<0?-1:1,e=e<0?-e:e;var r=gcd(e,t);return n.n=e/r,n.d=t/r,n}function factorize(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 o=e(function(e,t){var n=0,r=1,i=1,o=0,s=0,c=0,l=1,u=1,d=0,f=1,p=1,m=1,h=1e7,g;if(e!=null)if(t!==void 0){if(n=e,r=t,i=n*r,n%1!=0||r%1!=0)throw NonIntegerParameter()}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 InvalidParameter();i=n*r;break;case`number`:if(e<0&&(i=e,e=-e),e%1==0)n=e;else if(e>0){for(e>=1&&(u=10**Math.floor(1+Math.log(e)/Math.LN10),e/=u);f<=h&&m<=h;)if(g=(d+p)/(f+m),e===g){f+m<=h?(n=d+p,r=f+m):m>f?(n=p,r=m):(n=d,r=f);break}else e>g?(d+=p,f+=m):(p+=d,m+=f),f>h?(n=p,r=m):(n=d,r=f);n*=u}else (isNaN(e)||isNaN(t))&&(r=n=NaN);break;case`string`:if(f=e.match(/\d+|./g),f===null)throw InvalidParameter();if(f[d]===`-`?(i=-1,d++):f[d]===`+`&&d++,f.length===d+1?s=assign(f[d++],i):f[d+1]===`.`||f[d]===`.`?(f[d]!==`.`&&(o=assign(f[d++],i)),d++,(d+1===f.length||f[d+1]===`(`&&f[d+3]===`)`||f[d+1]===`'`&&f[d+3]===`'`)&&(s=assign(f[d],i),l=10**f[d].length,d++),(f[d]===`(`&&f[d+2]===`)`||f[d]===`'`&&f[d+2]===`'`)&&(c=assign(f[d+1],i),u=10**f[d+1].length-1,d+=3)):f[d+1]===`/`||f[d+1]===`:`?(s=assign(f[d],i),l=assign(f[d+2],1),d+=3):f[d+3]===`/`&&f[d+1]===` `&&(o=assign(f[d],i),s=assign(f[d+2],i),l=assign(f[d+4],1),d+=5),f.length<=d){r=l*u,i=n=c+r*o+u*s;break}default:throw InvalidParameter()}if(r===0)throw DivisionByZero();a.s=i<0?-1:1,a.n=Math.abs(n),a.d=Math.abs(r)},`parse`);function modpow(e,t,n){for(var r=1;t>0;e=e*e%n,t>>=1)t&1&&(r=r*e%n);return r}function cycleLen(e,t){for(;t%2==0;t/=2);for(;t%5==0;t/=5);if(t===1)return 0;for(var n=10%t,r=1;n!==1;r++)if(n=n*10%t,r>i)return 0;return r}function cycleStart(e,t,n){for(var r=1,i=modpow(10,n,t),a=0;a<300;a++){if(r===i)return a;r=r*10%t,i=i*10%t}return 0}function gcd(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function Fraction$2(e,t){if(o(e,t),this instanceof Fraction$2)e=gcd(a.d,a.n),this.s=a.s,this.n=a.n/e,this.d=a.d/e;else return newFraction(a.s*a.n,a.d)}e(Fraction$2,`Fraction`);var DivisionByZero=function(){return Error(`Division by Zero`)},InvalidParameter=function(){return Error(`Invalid argument`)},NonIntegerParameter=function(){return Error(`Parameters must be integer`)};Fraction$2.prototype={s:1,n:0,d:1,abs:function(){return newFraction(this.n,this.d)},neg:function(){return newFraction(-this.s*this.n,this.d)},add:function(e,t){return o(e,t),newFraction(this.s*this.n*a.d+a.s*this.d*a.n,this.d*a.d)},sub:function(e,t){return o(e,t),newFraction(this.s*this.n*a.d-a.s*this.d*a.n,this.d*a.d)},mul:function(e,t){return o(e,t),newFraction(this.s*a.s*this.n*a.n,this.d*a.d)},div:function(e,t){return o(e,t),newFraction(this.s*a.s*this.n*a.d,this.d*a.n)},clone:function(){return newFraction(this.s*this.n,this.d)},mod:function(e,t){if(isNaN(this.n)||isNaN(this.d))return new Fraction$2(NaN);if(e===void 0)return newFraction(this.s*this.n%this.d,1);if(o(e,t),a.n===0&&this.d===0)throw DivisionByZero();return newFraction(this.s*(a.d*this.n)%(a.n*this.d),a.d*this.d)},gcd:function(e,t){return o(e,t),newFraction(gcd(a.n,this.n)*gcd(a.d,this.d),a.d*this.d)},lcm:function(e,t){return o(e,t),a.n===0&&this.n===0?newFraction(0,1):newFraction(a.n*this.n,gcd(a.n,this.n)*gcd(a.d,this.d))},ceil:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new Fraction$2(NaN):newFraction(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 Fraction$2(NaN):newFraction(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 Fraction$2(NaN):newFraction(Math.round(e*this.s*this.n/this.d),e)},inverse:function(){return newFraction(this.s*this.d,this.n)},pow:function(e,t){if(o(e,t),a.d===1)return a.s<0?newFraction((this.s*this.d)**+a.n,this.n**+a.n):newFraction((this.s*this.n)**+a.n,this.d**+a.n);if(this.s<0)return null;var n=factorize(this.n),r=factorize(this.d),i=1,s=1;for(var c in n)if(c!==`1`){if(c===`0`){i=0;break}if(n[c]*=a.n,n[c]%a.d===0)n[c]/=a.d;else return null;i*=c**+n[c]}for(var c in r)if(c!==`1`){if(r[c]*=a.n,r[c]%a.d===0)r[c]/=a.d;else return null;s*=c**+r[c]}return a.s<0?newFraction(s,i):newFraction(i,s)},equals:function(e,t){return o(e,t),this.s*this.n*a.d===a.s*a.n*this.d},compare:function(e,t){o(e,t);var n=this.s*this.n*a.d-a.s*a.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=newFraction(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 o(e,t),!(!(a.n*this.d)||this.n*a.d%(a.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=cycleLen(t,n),i=cycleStart(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 t==`object`?(Object.defineProperty(Fraction$2,`__esModule`,{value:!0}),Fraction$2.default=Fraction$2,Fraction$2.Fraction=Fraction$2,n.exports=Fraction$2):r.Fraction=Fraction$2})(t)}))(),1),$e=factory(`Fraction`,[],()=>(Object.defineProperty($.default,`name`,{value:`Fraction`}),$.default.prototype.constructor=$.default,$.default.prototype.type=`Fraction`,$.default.prototype.isFraction=!0,$.default.prototype.toJSON=function(){return{mathjs:`Fraction`,n:this.s*this.n,d:this.d}},$.default.fromJSON=function(e){return new $.default(e)},$.default),{isClass:!0}),et=factory(`Matrix`,[],()=>{function Matrix$1(){if(!(this instanceof Matrix$1))throw SyntaxError(`Constructor must be called with the new operator`)}return e(Matrix$1,`Matrix`),Matrix$1.prototype.type=`Matrix`,Matrix$1.prototype.isMatrix=!0,Matrix$1.prototype.storage=function(){throw Error(`Cannot invoke storage on a Matrix interface`)},Matrix$1.prototype.datatype=function(){throw Error(`Cannot invoke datatype on a Matrix interface`)},Matrix$1.prototype.create=function(e,t){throw Error(`Cannot invoke create on a Matrix interface`)},Matrix$1.prototype.subset=function(e,t,n){throw Error(`Cannot invoke subset on a Matrix interface`)},Matrix$1.prototype.get=function(e){throw Error(`Cannot invoke get on a Matrix interface`)},Matrix$1.prototype.set=function(e,t,n){throw Error(`Cannot invoke set on a Matrix interface`)},Matrix$1.prototype.resize=function(e,t){throw Error(`Cannot invoke resize on a Matrix interface`)},Matrix$1.prototype.reshape=function(e,t){throw Error(`Cannot invoke reshape on a Matrix interface`)},Matrix$1.prototype.clone=function(){throw Error(`Cannot invoke clone on a Matrix interface`)},Matrix$1.prototype.size=function(){throw Error(`Cannot invoke size on a Matrix interface`)},Matrix$1.prototype.map=function(e,t){throw Error(`Cannot invoke map on a Matrix interface`)},Matrix$1.prototype.forEach=function(e){throw Error(`Cannot invoke forEach on a Matrix interface`)},Matrix$1.prototype[Symbol.iterator]=function(){throw Error(`Cannot iterate a Matrix interface`)},Matrix$1.prototype.toArray=function(){throw Error(`Cannot invoke toArray on a Matrix interface`)},Matrix$1.prototype.valueOf=function(){throw Error(`Cannot invoke valueOf on a Matrix interface`)},Matrix$1.prototype.format=function(e){throw Error(`Cannot invoke format on a Matrix interface`)},Matrix$1.prototype.toString=function(){throw Error(`Cannot invoke toString on a Matrix interface`)},Matrix$1},{isClass:!0});function maxArgumentCount(e){return Object.keys(e.signatures||{}).reduce(function(e,t){var n=(t.match(/,/g)||[]).length+1;return Math.max(e,n)},-1)}var tt=factory(`DenseMatrix`,[`Matrix`],t=>{var{Matrix:n}=t;function DenseMatrix$1(e,t){if(!(this instanceof DenseMatrix$1))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!isString$1(t))throw Error(`Invalid datatype: `+t);if(isMatrix(e))e.type===`DenseMatrix`?(this._data=clone$2(e._data),this._size=clone$2(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&L(e.data)&&L(e.size))this._data=e.data,this._size=e.size,validate$1(this._data,this._size),this._datatype=t||e.datatype;else if(L(e))this._data=preprocess(e),this._size=arraySize(this._data),validate$1(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+typeOf(e)+`)`);else this._data=[],this._size=[0],this._datatype=t}e(DenseMatrix$1,`DenseMatrix`),DenseMatrix$1.prototype=new n,DenseMatrix$1.prototype.createDenseMatrix=function(e,t){return new DenseMatrix$1(e,t)},Object.defineProperty(DenseMatrix$1,`name`,{value:`DenseMatrix`}),DenseMatrix$1.prototype.constructor=DenseMatrix$1,DenseMatrix$1.prototype.type=`DenseMatrix`,DenseMatrix$1.prototype.isDenseMatrix=!0,DenseMatrix$1.prototype.getDataType=function(){return getArrayDataType(this._data,typeOf)},DenseMatrix$1.prototype.storage=function(){return`dense`},DenseMatrix$1.prototype.datatype=function(){return this._datatype},DenseMatrix$1.prototype.create=function(e,t){return new DenseMatrix$1(e,t)},DenseMatrix$1.prototype.subset=function(e,t,n){switch(arguments.length){case 1:return _get(this,e);case 2:case 3:return _set(this,e,t,n);default:throw SyntaxError(`Wrong number of arguments`)}},DenseMatrix$1.prototype.get=function(e){if(!L(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new DimensionError(e.length,this._size.length);for(var t=0;t<e.length;t++)validateIndex(e[t],this._size[t]);for(var n=this._data,r=0,i=e.length;r<i;r++){var a=e[r];validateIndex(a,n.length),n=n[a]}return n},DenseMatrix$1.prototype.set=function(e,t,n){if(!L(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new DimensionError(e.length,this._size.length,`<`);var r,i,a,o=e.map(function(e){return e+1});_fit(this,o,n);var s=this._data;for(r=0,i=e.length-1;r<i;r++)a=e[r],validateIndex(a,s.length),s=s[a];return a=e[e.length-1],validateIndex(a,s.length),s[a]=t,this};function _get(e,t){if(!isIndex(t))throw TypeError(`Invalid index`);if(t.isScalar())return e.get(t.min());var n=t.size();if(n.length!==e._size.length)throw new DimensionError(n.length,e._size.length);for(var r=t.min(),i=t.max(),a=0,o=e._size.length;a<o;a++)validateIndex(r[a],e._size[a]),validateIndex(i[a],e._size[a]);return new DenseMatrix$1(_getSubmatrix(e._data,t,n.length,0),e._datatype)}function _getSubmatrix(e,t,n,r){var i=r===n-1,a=t.dimension(r);return i?a.map(function(t){return validateIndex(t,e.length),e[t]}).valueOf():a.map(function(i){validateIndex(i,e.length);var a=e[i];return _getSubmatrix(a,t,n,r+1)}).valueOf()}function _set(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Invalid index`);var i=t.size(),a=t.isScalar(),o;if(isMatrix(n)?(o=n.size(),n=n.valueOf()):o=arraySize(n),a){if(o.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!deepStrictEqual(o,i))try{n=o.length===0?broadcastTo([n],i):broadcastTo(n,i),o=arraySize(n)}catch{}if(i.length<e._size.length)throw new DimensionError(i.length,e._size.length,`<`);if(o.length<i.length){for(var s=0,c=0;i[s]===1&&o[s]===1;)s++;for(;i[s]===1;)c++,s++;n=unsqueeze(n,i.length,c,o)}if(!deepStrictEqual(i,o))throw new DimensionError(i,o,`>`);_fit(e,t.max().map(function(e){return e+1}),r);var l=i.length;_setSubmatrix(e._data,t,n,l,0)}return e}function _setSubmatrix(e,t,n,r,i){var a=i===r-1,o=t.dimension(i);a?o.forEach(function(t,r){validateIndex(t),e[t]=n[r[0]]}):o.forEach(function(a,o){validateIndex(a),_setSubmatrix(e[a],t,n[o[0]],r,i+1)})}DenseMatrix$1.prototype.resize=function(e,t,n){if(!isCollection(e))throw TypeError(`Array or Matrix expected`);var r=e.valueOf().map(e=>Array.isArray(e)&&e.length===1?e[0]:e);return _resize$1(n?this.clone():this,r,t)};function _resize$1(e,t,n){if(t.length===0){for(var r=e._data;L(r);)r=r[0];return r}return e._size=t.slice(0),e._data=resize(e._data,e._size,n),e}e(_resize$1,`_resize`),DenseMatrix$1.prototype.reshape=function(e,t){var n=t?this.clone():this;return n._data=reshape(n._data,e),n._size=processSizesWildcard(e,n._size.reduce((e,t)=>e*t)),n};function _fit(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&&_resize$1(e,r,n)}DenseMatrix$1.prototype.clone=function(){return new DenseMatrix$1({data:clone$2(this._data),size:clone$2(this._size),datatype:this._datatype})},DenseMatrix$1.prototype.size=function(){return this._size.slice(0)},DenseMatrix$1.prototype.map=function(e){var t=this,n=maxArgumentCount(e),r=function recurse(r,i){return L(r)?r.map(function(e,t){return recurse(e,i.concat(t))}):n===1?e(r):n===2?e(r,i):e(r,i,t)}(this._data,[]);return new DenseMatrix$1(r,this._datatype===void 0?void 0:getArrayDataType(r,typeOf))},DenseMatrix$1.prototype.forEach=function(e){var t=this;(function recurse(n,r){L(n)?n.forEach(function(e,t){recurse(e,r.concat(t))}):e(n,r,t)})(this._data,[])},DenseMatrix$1.prototype[Symbol.iterator]=function*(){yield*function*recurse(e,t){if(L(e))for(var n=0;n<e.length;n++)yield*recurse(e[n],t.concat(n));else yield{value:e,index:t}}(this._data,[])},DenseMatrix$1.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 DenseMatrix$1([t],this._datatype));return e},DenseMatrix$1.prototype.columns=function(){var e=this,t=[],n=this.size();if(n.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var r=this._data,i=function _loop$1(n){var i=r.map(e=>[e[n]]);t.push(new DenseMatrix$1(i,e._datatype))},a=0;a<n[1];a++)i(a);return t},DenseMatrix$1.prototype.toArray=function(){return clone$2(this._data)},DenseMatrix$1.prototype.valueOf=function(){return this._data},DenseMatrix$1.prototype.format=function(e){return format(this._data,e)},DenseMatrix$1.prototype.toString=function(){return format(this._data)},DenseMatrix$1.prototype.toJSON=function(){return{mathjs:`DenseMatrix`,data:this._data,size:this._size,datatype:this._datatype}},DenseMatrix$1.prototype.diagonal=function(e){if(e){if(isBigNumber(e)&&(e=e.toNumber()),!isNumber$1(e)||!isInteger(e))throw TypeError(`The parameter k must be an integer number`)}else e=0;for(var t=e>0?e:0,n=e<0?-e:0,r=this._size[0],i=this._size[1],a=Math.min(r-n,i-t),o=[],s=0;s<a;s++)o[s]=this._data[s+n][s+t];return new DenseMatrix$1({data:o,size:[a],datatype:this._datatype})},DenseMatrix$1.diagonal=function(e,t,n,r){if(!L(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(isBigNumber(e)&&(e=e.toNumber()),!isNumber$1(e)||!isInteger(e)||e<1)throw Error(`Size values must be positive integers`);return e}),n){if(isBigNumber(n)&&(n=n.toNumber()),!isNumber$1(n)||!isInteger(n))throw TypeError(`The parameter k must be an integer number`)}else n=0;var i=n>0?n:0,a=n<0?-n:0,o=e[0],s=e[1],c=Math.min(o-a,s-i),l;if(L(t)){if(t.length!==c)throw Error(`Invalid value array length`);l=function _value$1(e){return t[e]}}else if(isMatrix(t)){var u=t.size();if(u.length!==1||u[0]!==c)throw Error(`Invalid matrix length`);l=function _value$1(e){return t.get([e])}}else l=function _value$1(){return t};r||=isBigNumber(l(0))?l(0).mul(0):0;var d=[];if(e.length>0){d=resize(d,e,r);for(var f=0;f<c;f++)d[f+a][f+i]=l(f)}return new DenseMatrix$1({data:d,size:[o,s]})},DenseMatrix$1.fromJSON=function(e){return new DenseMatrix$1(e)},DenseMatrix$1.prototype.swapRows=function(e,t){if(!isNumber$1(e)||!isInteger(e)||!isNumber$1(t)||!isInteger(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return validateIndex(e,this._size[0]),validateIndex(t,this._size[0]),DenseMatrix$1._swapRows(e,t,this._data),this},DenseMatrix$1._swapRows=function(e,t,n){var r=n[e];n[e]=n[t],n[t]=r};function preprocess(e){return isMatrix(e)?preprocess(e.valueOf()):L(e)?e.map(preprocess):e}return DenseMatrix$1},{isClass:!0});function deepMap(e,t,n){return e&&typeof e.map==`function`?e.map(function(e){return deepMap(e,t,n)}):t(e)}var nt=`isNumeric`,rt=factory(nt,[`typed`],e=>{var{typed:t}=e;return t(nt,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>deepMap(t,e))})}),it=`hasNumericValue`,at=factory(it,[`typed`,`isNumeric`],e=>{var{typed:t,isNumeric:n}=e;return t(it,{boolean:()=>!0,string:function string(e){return e.trim().length>0&&!isNaN(Number(e))},any:function any(e){return n(e)}})}),ot=Ne({BigNumber:Xe({config:Ee}),Complex:Qe({}),DenseMatrix:tt({Matrix:et({})}),Fraction:$e({})}),st=at({isNumeric:rt({typed:ot}),typed:ot});const shortTimePeriodIsMilliseconds=e=>{let t=Number(e);return Number.isNaN(t)?!1:t>=120&&t<=36e4},resolveWaitTimeMs=e=>{let t=Number(e),n=Date.now();return Number.isNaN(t)?n+1e3:!shortTimePeriodIsMilliseconds(t)&&c(t)?adjustUnixTimestamp(t):shortTimePeriodIsMilliseconds(t)?n+t:n+t*I},superNormalizeHeaders=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]=st(r)?Number(r):null}return t},extractRateLimitHeaders=e=>{let t=superNormalizeHeaders(e);return{rateLimitLimit:t.ratelimitlimit,rateLimitRemaining:t.ratelimitremaining,rateLimitReset:resolveWaitTimeMs(t.ratelimitreset),concurrencyLimit:t.ratelimitconcurrencylimit,concurrencyRemaining:t.ratelimitconcurrencyremaining,concurrencyReset:resolveWaitTimeMs(t.ratelimitconcurrencyreset)}},generateRequestKey=e=>{let{accountSecureId:t,service:n,resource:r,subResource:i,childResource:a,action:o,behaviours:s}=e??{};return[t,n,r,o].some(l)?null:[t,n,r,i,a,o,...s??[]].filter(Boolean).join(`-`)},getRetryAfterWaitTime=(e,t=10,n=1)=>{let r=Date.now();return c(e)||u(e)?evaluateRetryAfterNumber(Number(e),r,t,n):isString$1(e)&&e!==``?evaluateRetryAfterString(e,r,t,n):n},evaluateRetryAfterNumber=(e,t,n=10,r=1)=>{if(e<n)return e;let i=adjustUnixTimestamp(e);if(i>t){let e=Math.floor((i-t)/I);return e>0&&e<n?e:r}return r},evaluateRetryAfterString=(e,t,n=10,r=1)=>{if(be.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)/I);return e>0&&e<n?e:r}return r},retryErrorInterceptor=({axiosInstance:t,logger:n,requestConfig:r,context:a})=>e(async e=>{let{response:o,config:s}=e;if(s?.signal?.aborted)return Promise.reject(createAxiosError(`Request aborted`,s,`ERR_CANCELED`,o));let{status:c,retryAfter:l}=convertError(o,a,r,n);if(c===429&&p(s)){let r=getRetryAfterWaitTime(l);if(s._retryCount>=5)return n?.warning({category:`http-transport`,message:`Max retries exceeded for ${s?.url}. Aborting.`,context:{...a??{},retryAfterHeader:l,retryAfterAsNumber:r}}),Promise.reject(e);let c=s._retryCount??0,u={...s,_retryCount:c+1},d=l?r*I:i(u._retryCount);return n?.debug({category:`http-transport`,message:`Received 429 error from ${s?.url}`,context:{...a??{},retryAfterHeader:l,calculatedRetryAfter:d}}),await abortableDelay(d,s,o),t?.request(u)}return Promise.reject(e)},`retryErrorInterceptor`),convertError=(e,t,n,r)=>{let{provider:i}=t??{},{status:a,headers:o,data:s}=e??{},{retryafter:c}=superNormalizeHeaders(o??{});if(l(i)||l(e))return r?.warning({category:`http-transport`,message:`Invalid parameters for convertError`,context:{...t,responseIsMissing:l(e),providerIsMissing:l(i),status:e?.status??`undefined`,statusText:e?.statusText??`undefined`,retryafter:c??`undefined`}}),{status:a,retryAfter:c};let u=n?.rateLimits?.mappedRateLimitErrors;if(p(u)&&p(s))for(let e of u){let{errorStatus:t,errorMessagePath:n,errorMessage:r,retryAfterPath:i,retryAfterUnit:l,retryAfterValue:u}=e;if(t!==a)continue;let f=n??`message`,p=testMessage(d(s)?w({path:f,json:s})[0]:s,r);if(t===a&&p){let e=convertRetryAfter(u??extractRetryAfter(o,i),l);return{status:429,retryAfter:c??e}}}return{status:a,retryAfter:c}},testMessage=(e,t)=>t instanceof RegExp?t.test(e??``):e?.includes(t)??!1,extractRetryAfter=(e,t)=>p(t)&&p(e)?w({path:t,json:e})[0]:null,convertRetryAfter=(e,t=`seconds`)=>p(e)?transformToSeconds(e,t):null,transformToSeconds=(e,t)=>{if(t===`seconds`)return typeof e==`string`?parseFloat(e):e;if(t===`milliseconds`)return(typeof e==`string`?parseFloat(e):e)/I;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`)},ct=`rateLimitErrorInterceptor`,rateLimitErrorInterceptor=({axiosInstance:t,logger:n,requestConfig:r,context:a,concurrencyManager:o})=>e(async e=>{let{response:s,config:c}=e,u=c?.signal;if(l(a)||l(c))return n?.warning({category:`HttpClient`,message:`No context or config for this response - that doesn't seem right.`,context:{interceptor:ct,...c,httpsAgent:void 0,headers:void 0,hasContext:p(a),hasConfig:p(c)},code:F.InterceptorContextNotPresent}),Promise.reject(e);if(l(o))return n?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:ct,...c,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:p(o)},code:F.RateLimitOrConcurrencyManagerNotInitialized}),Promise.reject(e);let{requestId:d,targetConcurrencyKey:f,leaseSubscription:m,setRemovalSubscription:h}=c?.requestMetadata??{};if(!(p(d)&&p(f)&&await o.releaseRequest(d,f))&&p(c?.requestMetadata)&&n?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{...a,interceptor:ct,requestId:d,targetConcurrencyKey:f,leaseSubscription:m,setRemovalSubscription:h},code:F.RateLimiterReleaseRequestFailed}),u?.aborted)return Promise.reject(createAxiosError(`Request aborted`,c,`ERR_CANCELED`,s));let{status:g,retryAfter:_}=convertError(s,a,r,n);if(g===429&&p(c)){let r=getRetryAfterWaitTime(_);if(c._retryCount>=5)return n?.warning({category:`HttpClient`,message:`Max retries exceeded for ${c.url}. Aborting.`,context:{...a??{},...c.requestMetadata??{},retryAfterHeader:_,retryAfterAsNumber:r}}),Promise.reject(e);let o=c?._retryCount??0,l={...c,_retryCount:o+1},u=_?r*I:i(l._retryCount);return n?.debug({category:`HttpClient`,message:`Received 429 error from ${c.url}`,context:{...a,retryAfterHeader:_,calculatedRetryAfter:u}}),await abortableDelay(u,c,s),t?.request(l)}return Promise.reject(e)},`rateLimitErrorInterceptor`),lt=`rateLimitResponseInterceptor`,rateLimitResponseInterceptor=({logger:t,context:n,concurrencyManager:r})=>e(async e=>{let i=e?.config,a=i?.signal;if(l(n))t?.warning({category:`HttpClient`,message:`No context for this response - that doesn't seem right.`,context:{interceptor:lt,...i,httpsAgent:void 0,headers:void 0}});else if(l(r))return t?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:lt,...i,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:p(r)},code:F.RateLimitOrConcurrencyManagerNotInitialized}),e;else if(p(n.provider)&&p(n.accountSecureId)){let n=e?.headers;if(p(n)){let e=extractRateLimitHeaders(n);t?.debug({category:`HttpClient`,message:`Rate limit headers extracted`,context:{interceptor:lt,rateLimitHeaders:e}})}let{requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:l}=i?.requestMetadata??{};if(await r.releaseRequest(o,s)||t?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{interceptor:lt,requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:l},code:F.RateLimiterReleaseRequestFailed}),a?.aborted)return Promise.reject(createAxiosError(`Request aborted`,i,`ERR_CANCELED`,e))}return e},`rateLimitResponseInterceptor`),validateRequestInterceptor=e=>(e.validateStatus??=e=>e>=200&&e<300,e),ut=[{onFulfilled:validateRequestInterceptor,onRejected:null,options:void 0}],dt=[{onFulfilled:null,onRejected:retryErrorInterceptor},{onFulfilled:null,onRejected:abortErrorInterceptor}],ft=[{onFulfilled:validateRequestInterceptor,onRejected:null,options:void 0},{onFulfilled:checkConcurrencyInterceptor,onRejected:null,options:void 0}],pt=[{onFulfilled:rateLimitResponseInterceptor,onRejected:rateLimitErrorInterceptor},{onFulfilled:null,onRejected:abortErrorInterceptor}];var RateLimitManager=class extends ScriptManager{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=p(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),u=c.map(e=>e.rateLimit);return await this.executeScript(ve.incr,[a,...l],[o.toString(),...u.map(String)])}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()}},SingletonManager=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(l(t))throw Error(`Singleton ${e.name} not prepared yet`);if(t.hasInitFailed?.())throw Error(`${e.name} initialization failed`);let n=t.getInstanceIfReady?.();if(p(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 mt=function(e){return e.HttpTransportInstanceCreateError=`HttpTransportInstanceCreateError`,e}({});const getTransportInstance=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`)?createDefaultRetryInstance(e,n):createDefaultInstance(e,n),l(n?.service)||l(n?.organizationId)||o===`test`||l(t)||l(e))return a;let c=SingletonManager.getIfReady(RateLimitManager)??void 0,u=SingletonManager.getIfReady(ConcurrencyManager)??void 0,d=c?.isReady(),f=u?.isRedisConfigured(),m=[],h=[];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.`);m.push(...ft),h.push(...pt)}let g=generateRequestKey(n);if(l(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:p(a)}}),a;let _=await ge.get(g);if(p(_))return _;let v={interceptors:{requestConfigs:m,responseConfigs:h},instanceConfig:{maxBodyLength:1/0},logger:e,context:n,requestConfig:r,httpsAgentConfig:i,concurrencyManager:u,rateLimitManager:c},y=HttpTransportFactory.createInstance(v);return e?.debug({category:`http-transport`,message:`Creating new Axios instance and caching it for key: [${g}]`,context:{...n}}),await ge.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:p(a)},error:t,code:mt.HttpTransportInstanceCreateError}),p(a)?a:createAxiosInstance()}},createDefaultInstance=(e,t)=>{let n={instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return HttpTransportFactory.createInstance(n)??createAxiosInstance()},createDefaultRetryInstance=(e,t)=>{let n={interceptors:{requestConfigs:ut,responseConfigs:dt},instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return HttpTransportFactory.createInstance(n)??createAxiosInstance()},createAxiosInstance=()=>y.create({maxBodyLength:1/0});var HttpClient=class{#e;#t;#n;#r;#i;#a;constructor({transportFactory:e=getTransportInstance,getRedisClient:t=buildRedisClientInstance,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?o(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:m,httpsAgentConfig:h}){try{p(this.#r)&&l(this.#a)&&(this.#a=await this.#t(this.#r,this.#n,`HttpClient`));let g=this.#_(t,r),_=this.#l(e),v=this.#m(u,e),y=await this.#s({url:g,payload:v,method:n,cacheTTL:o,context:s});if(y)return{...y,responseTime:new Date};let b=he.getInstance(),x=(p(c)?await b.get(c):null)?.signal,S=await(await this.#e({redisClientConfig:this.#r,logger:this.#n,context:s,requestConfig:m,httpsAgentConfig:h})).request({headers:_,url:g,method:n,maxRedirects:i,responseType:a,data:v,httpsAgent:d,httpAgent:f,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:o,context:s,response:C}),C}catch(e){let r=e;r.url=T(t),this.#n?.warning({category:this.name,message:`Request error [${n?.toUpperCase()} ${r.url}]: ${r.message}.`,error:r});let i=this.#h(r);throw p(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:u,httpsAgentConfig:d}){try{let f=this.#_(t,r),m=this.#l(e),h=this.#m(s,e),g=he.getInstance(),_=(p(o)?await g.get(o):null)?.signal,v=await(await this.#e({redisClientConfig:this.#r,logger:this.#n,context:a,requestConfig:u,httpsAgentConfig:d})).request({headers:m,url:f,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=T(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 p(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 l(e)||typeof e!=`object`||!e?!1:`pipe`in e&&typeof e.pipe==`function`}#m(e,t){if(!(l(e)||d(e)&&Object.keys(e).length===0))return this.#f(t)||this.#p(e)?e:this.#d(t)?E.stringify(e):e}#h(e){if(b(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(l(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(E.stringify(n)),Object.keys(r).length>0&&o.push(E.stringify(r,{arrayFormat:`repeat`})),Object.keys(i).length>0&&o.push(E.stringify(i,{arrayFormat:`brackets`})),Object.keys(a).length>0&&o.push(E.stringify(a,{arrayFormat:`comma`}));let s=o.join(`&`);return p(s)?`${e}?${s}`:e}};const buildHttpClientInstance=(e,t,n)=>new HttpClient({redisClientConfig:e,logger:t,errorMappingFn:n});var HttpClientManager=class{static{this.httpClientInstance=null}static async getInstance({redisClientConfig:e,logger:t,errorMappingFn:n,getHttpClient:r=buildHttpClientInstance}){return this.httpClientInstance??=r(e,t,n),this.httpClientInstance}static resetInstance(){this.httpClientInstance=null}};const ht=[`get`,`post`,`put`,`delete`,`patch`],gt={[A.rPush]:`
113
+ (function(r){var i=2e3,a={s:1,n:0,d:1};function assign(e,t){if(isNaN(e=parseInt(e,10)))throw InvalidParameter();return e*t}function newFraction(e,t){if(t===0)throw DivisionByZero();var n=Object.create(Fraction$2.prototype);n.s=e<0?-1:1,e=e<0?-e:e;var r=gcd(e,t);return n.n=e/r,n.d=t/r,n}function factorize(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 o=e(function(e,t){var n=0,r=1,i=1,o=0,s=0,c=0,l=1,u=1,d=0,f=1,p=1,m=1,h=1e7,g;if(e!=null)if(t!==void 0){if(n=e,r=t,i=n*r,n%1!=0||r%1!=0)throw NonIntegerParameter()}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 InvalidParameter();i=n*r;break;case`number`:if(e<0&&(i=e,e=-e),e%1==0)n=e;else if(e>0){for(e>=1&&(u=10**Math.floor(1+Math.log(e)/Math.LN10),e/=u);f<=h&&m<=h;)if(g=(d+p)/(f+m),e===g){f+m<=h?(n=d+p,r=f+m):m>f?(n=p,r=m):(n=d,r=f);break}else e>g?(d+=p,f+=m):(p+=d,m+=f),f>h?(n=p,r=m):(n=d,r=f);n*=u}else (isNaN(e)||isNaN(t))&&(r=n=NaN);break;case`string`:if(f=e.match(/\d+|./g),f===null)throw InvalidParameter();if(f[d]===`-`?(i=-1,d++):f[d]===`+`&&d++,f.length===d+1?s=assign(f[d++],i):f[d+1]===`.`||f[d]===`.`?(f[d]!==`.`&&(o=assign(f[d++],i)),d++,(d+1===f.length||f[d+1]===`(`&&f[d+3]===`)`||f[d+1]===`'`&&f[d+3]===`'`)&&(s=assign(f[d],i),l=10**f[d].length,d++),(f[d]===`(`&&f[d+2]===`)`||f[d]===`'`&&f[d+2]===`'`)&&(c=assign(f[d+1],i),u=10**f[d+1].length-1,d+=3)):f[d+1]===`/`||f[d+1]===`:`?(s=assign(f[d],i),l=assign(f[d+2],1),d+=3):f[d+3]===`/`&&f[d+1]===` `&&(o=assign(f[d],i),s=assign(f[d+2],i),l=assign(f[d+4],1),d+=5),f.length<=d){r=l*u,i=n=c+r*o+u*s;break}default:throw InvalidParameter()}if(r===0)throw DivisionByZero();a.s=i<0?-1:1,a.n=Math.abs(n),a.d=Math.abs(r)},`parse`);function modpow(e,t,n){for(var r=1;t>0;e=e*e%n,t>>=1)t&1&&(r=r*e%n);return r}function cycleLen(e,t){for(;t%2==0;t/=2);for(;t%5==0;t/=5);if(t===1)return 0;for(var n=10%t,r=1;n!==1;r++)if(n=n*10%t,r>i)return 0;return r}function cycleStart(e,t,n){for(var r=1,i=modpow(10,n,t),a=0;a<300;a++){if(r===i)return a;r=r*10%t,i=i*10%t}return 0}function gcd(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function Fraction$2(e,t){if(o(e,t),this instanceof Fraction$2)e=gcd(a.d,a.n),this.s=a.s,this.n=a.n/e,this.d=a.d/e;else return newFraction(a.s*a.n,a.d)}e(Fraction$2,`Fraction`);var DivisionByZero=function(){return Error(`Division by Zero`)},InvalidParameter=function(){return Error(`Invalid argument`)},NonIntegerParameter=function(){return Error(`Parameters must be integer`)};Fraction$2.prototype={s:1,n:0,d:1,abs:function(){return newFraction(this.n,this.d)},neg:function(){return newFraction(-this.s*this.n,this.d)},add:function(e,t){return o(e,t),newFraction(this.s*this.n*a.d+a.s*this.d*a.n,this.d*a.d)},sub:function(e,t){return o(e,t),newFraction(this.s*this.n*a.d-a.s*this.d*a.n,this.d*a.d)},mul:function(e,t){return o(e,t),newFraction(this.s*a.s*this.n*a.n,this.d*a.d)},div:function(e,t){return o(e,t),newFraction(this.s*a.s*this.n*a.d,this.d*a.n)},clone:function(){return newFraction(this.s*this.n,this.d)},mod:function(e,t){if(isNaN(this.n)||isNaN(this.d))return new Fraction$2(NaN);if(e===void 0)return newFraction(this.s*this.n%this.d,1);if(o(e,t),a.n===0&&this.d===0)throw DivisionByZero();return newFraction(this.s*(a.d*this.n)%(a.n*this.d),a.d*this.d)},gcd:function(e,t){return o(e,t),newFraction(gcd(a.n,this.n)*gcd(a.d,this.d),a.d*this.d)},lcm:function(e,t){return o(e,t),a.n===0&&this.n===0?newFraction(0,1):newFraction(a.n*this.n,gcd(a.n,this.n)*gcd(a.d,this.d))},ceil:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new Fraction$2(NaN):newFraction(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 Fraction$2(NaN):newFraction(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 Fraction$2(NaN):newFraction(Math.round(e*this.s*this.n/this.d),e)},inverse:function(){return newFraction(this.s*this.d,this.n)},pow:function(e,t){if(o(e,t),a.d===1)return a.s<0?newFraction((this.s*this.d)**+a.n,this.n**+a.n):newFraction((this.s*this.n)**+a.n,this.d**+a.n);if(this.s<0)return null;var n=factorize(this.n),r=factorize(this.d),i=1,s=1;for(var c in n)if(c!==`1`){if(c===`0`){i=0;break}if(n[c]*=a.n,n[c]%a.d===0)n[c]/=a.d;else return null;i*=c**+n[c]}for(var c in r)if(c!==`1`){if(r[c]*=a.n,r[c]%a.d===0)r[c]/=a.d;else return null;s*=c**+r[c]}return a.s<0?newFraction(s,i):newFraction(i,s)},equals:function(e,t){return o(e,t),this.s*this.n*a.d===a.s*a.n*this.d},compare:function(e,t){o(e,t);var n=this.s*this.n*a.d-a.s*a.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=newFraction(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 o(e,t),!(!(a.n*this.d)||this.n*a.d%(a.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=cycleLen(t,n),i=cycleStart(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 t==`object`?(Object.defineProperty(Fraction$2,`__esModule`,{value:!0}),Fraction$2.default=Fraction$2,Fraction$2.Fraction=Fraction$2,n.exports=Fraction$2):r.Fraction=Fraction$2})(t)}))(),1),$e=factory(`Fraction`,[],()=>(Object.defineProperty($.default,`name`,{value:`Fraction`}),$.default.prototype.constructor=$.default,$.default.prototype.type=`Fraction`,$.default.prototype.isFraction=!0,$.default.prototype.toJSON=function(){return{mathjs:`Fraction`,n:this.s*this.n,d:this.d}},$.default.fromJSON=function(e){return new $.default(e)},$.default),{isClass:!0}),et=factory(`Matrix`,[],()=>{function Matrix$1(){if(!(this instanceof Matrix$1))throw SyntaxError(`Constructor must be called with the new operator`)}return e(Matrix$1,`Matrix`),Matrix$1.prototype.type=`Matrix`,Matrix$1.prototype.isMatrix=!0,Matrix$1.prototype.storage=function(){throw Error(`Cannot invoke storage on a Matrix interface`)},Matrix$1.prototype.datatype=function(){throw Error(`Cannot invoke datatype on a Matrix interface`)},Matrix$1.prototype.create=function(e,t){throw Error(`Cannot invoke create on a Matrix interface`)},Matrix$1.prototype.subset=function(e,t,n){throw Error(`Cannot invoke subset on a Matrix interface`)},Matrix$1.prototype.get=function(e){throw Error(`Cannot invoke get on a Matrix interface`)},Matrix$1.prototype.set=function(e,t,n){throw Error(`Cannot invoke set on a Matrix interface`)},Matrix$1.prototype.resize=function(e,t){throw Error(`Cannot invoke resize on a Matrix interface`)},Matrix$1.prototype.reshape=function(e,t){throw Error(`Cannot invoke reshape on a Matrix interface`)},Matrix$1.prototype.clone=function(){throw Error(`Cannot invoke clone on a Matrix interface`)},Matrix$1.prototype.size=function(){throw Error(`Cannot invoke size on a Matrix interface`)},Matrix$1.prototype.map=function(e,t){throw Error(`Cannot invoke map on a Matrix interface`)},Matrix$1.prototype.forEach=function(e){throw Error(`Cannot invoke forEach on a Matrix interface`)},Matrix$1.prototype[Symbol.iterator]=function(){throw Error(`Cannot iterate a Matrix interface`)},Matrix$1.prototype.toArray=function(){throw Error(`Cannot invoke toArray on a Matrix interface`)},Matrix$1.prototype.valueOf=function(){throw Error(`Cannot invoke valueOf on a Matrix interface`)},Matrix$1.prototype.format=function(e){throw Error(`Cannot invoke format on a Matrix interface`)},Matrix$1.prototype.toString=function(){throw Error(`Cannot invoke toString on a Matrix interface`)},Matrix$1},{isClass:!0});function maxArgumentCount(e){return Object.keys(e.signatures||{}).reduce(function(e,t){var n=(t.match(/,/g)||[]).length+1;return Math.max(e,n)},-1)}var tt=factory(`DenseMatrix`,[`Matrix`],t=>{var{Matrix:n}=t;function DenseMatrix$1(e,t){if(!(this instanceof DenseMatrix$1))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!isString$1(t))throw Error(`Invalid datatype: `+t);if(isMatrix(e))e.type===`DenseMatrix`?(this._data=clone$2(e._data),this._size=clone$2(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&L(e.data)&&L(e.size))this._data=e.data,this._size=e.size,validate$1(this._data,this._size),this._datatype=t||e.datatype;else if(L(e))this._data=preprocess(e),this._size=arraySize(this._data),validate$1(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+typeOf(e)+`)`);else this._data=[],this._size=[0],this._datatype=t}e(DenseMatrix$1,`DenseMatrix`),DenseMatrix$1.prototype=new n,DenseMatrix$1.prototype.createDenseMatrix=function(e,t){return new DenseMatrix$1(e,t)},Object.defineProperty(DenseMatrix$1,`name`,{value:`DenseMatrix`}),DenseMatrix$1.prototype.constructor=DenseMatrix$1,DenseMatrix$1.prototype.type=`DenseMatrix`,DenseMatrix$1.prototype.isDenseMatrix=!0,DenseMatrix$1.prototype.getDataType=function(){return getArrayDataType(this._data,typeOf)},DenseMatrix$1.prototype.storage=function(){return`dense`},DenseMatrix$1.prototype.datatype=function(){return this._datatype},DenseMatrix$1.prototype.create=function(e,t){return new DenseMatrix$1(e,t)},DenseMatrix$1.prototype.subset=function(e,t,n){switch(arguments.length){case 1:return _get(this,e);case 2:case 3:return _set(this,e,t,n);default:throw SyntaxError(`Wrong number of arguments`)}},DenseMatrix$1.prototype.get=function(e){if(!L(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new DimensionError(e.length,this._size.length);for(var t=0;t<e.length;t++)validateIndex(e[t],this._size[t]);for(var n=this._data,r=0,i=e.length;r<i;r++){var a=e[r];validateIndex(a,n.length),n=n[a]}return n},DenseMatrix$1.prototype.set=function(e,t,n){if(!L(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new DimensionError(e.length,this._size.length,`<`);var r,i,a,o=e.map(function(e){return e+1});_fit(this,o,n);var s=this._data;for(r=0,i=e.length-1;r<i;r++)a=e[r],validateIndex(a,s.length),s=s[a];return a=e[e.length-1],validateIndex(a,s.length),s[a]=t,this};function _get(e,t){if(!isIndex(t))throw TypeError(`Invalid index`);if(t.isScalar())return e.get(t.min());var n=t.size();if(n.length!==e._size.length)throw new DimensionError(n.length,e._size.length);for(var r=t.min(),i=t.max(),a=0,o=e._size.length;a<o;a++)validateIndex(r[a],e._size[a]),validateIndex(i[a],e._size[a]);return new DenseMatrix$1(_getSubmatrix(e._data,t,n.length,0),e._datatype)}function _getSubmatrix(e,t,n,r){var i=r===n-1,a=t.dimension(r);return i?a.map(function(t){return validateIndex(t,e.length),e[t]}).valueOf():a.map(function(i){validateIndex(i,e.length);var a=e[i];return _getSubmatrix(a,t,n,r+1)}).valueOf()}function _set(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Invalid index`);var i=t.size(),a=t.isScalar(),o;if(isMatrix(n)?(o=n.size(),n=n.valueOf()):o=arraySize(n),a){if(o.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!deepStrictEqual(o,i))try{n=o.length===0?broadcastTo([n],i):broadcastTo(n,i),o=arraySize(n)}catch{}if(i.length<e._size.length)throw new DimensionError(i.length,e._size.length,`<`);if(o.length<i.length){for(var s=0,c=0;i[s]===1&&o[s]===1;)s++;for(;i[s]===1;)c++,s++;n=unsqueeze(n,i.length,c,o)}if(!deepStrictEqual(i,o))throw new DimensionError(i,o,`>`);_fit(e,t.max().map(function(e){return e+1}),r);var l=i.length;_setSubmatrix(e._data,t,n,l,0)}return e}function _setSubmatrix(e,t,n,r,i){var a=i===r-1,o=t.dimension(i);a?o.forEach(function(t,r){validateIndex(t),e[t]=n[r[0]]}):o.forEach(function(a,o){validateIndex(a),_setSubmatrix(e[a],t,n[o[0]],r,i+1)})}DenseMatrix$1.prototype.resize=function(e,t,n){if(!isCollection(e))throw TypeError(`Array or Matrix expected`);var r=e.valueOf().map(e=>Array.isArray(e)&&e.length===1?e[0]:e);return _resize$1(n?this.clone():this,r,t)};function _resize$1(e,t,n){if(t.length===0){for(var r=e._data;L(r);)r=r[0];return r}return e._size=t.slice(0),e._data=resize(e._data,e._size,n),e}e(_resize$1,`_resize`),DenseMatrix$1.prototype.reshape=function(e,t){var n=t?this.clone():this;return n._data=reshape(n._data,e),n._size=processSizesWildcard(e,n._size.reduce((e,t)=>e*t)),n};function _fit(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&&_resize$1(e,r,n)}DenseMatrix$1.prototype.clone=function(){return new DenseMatrix$1({data:clone$2(this._data),size:clone$2(this._size),datatype:this._datatype})},DenseMatrix$1.prototype.size=function(){return this._size.slice(0)},DenseMatrix$1.prototype.map=function(e){var t=this,n=maxArgumentCount(e),r=function recurse(r,i){return L(r)?r.map(function(e,t){return recurse(e,i.concat(t))}):n===1?e(r):n===2?e(r,i):e(r,i,t)}(this._data,[]);return new DenseMatrix$1(r,this._datatype===void 0?void 0:getArrayDataType(r,typeOf))},DenseMatrix$1.prototype.forEach=function(e){var t=this;(function recurse(n,r){L(n)?n.forEach(function(e,t){recurse(e,r.concat(t))}):e(n,r,t)})(this._data,[])},DenseMatrix$1.prototype[Symbol.iterator]=function*(){yield*function*recurse(e,t){if(L(e))for(var n=0;n<e.length;n++)yield*recurse(e[n],t.concat(n));else yield{value:e,index:t}}(this._data,[])},DenseMatrix$1.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 DenseMatrix$1([t],this._datatype));return e},DenseMatrix$1.prototype.columns=function(){var e=this,t=[],n=this.size();if(n.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var r=this._data,i=function _loop$1(n){var i=r.map(e=>[e[n]]);t.push(new DenseMatrix$1(i,e._datatype))},a=0;a<n[1];a++)i(a);return t},DenseMatrix$1.prototype.toArray=function(){return clone$2(this._data)},DenseMatrix$1.prototype.valueOf=function(){return this._data},DenseMatrix$1.prototype.format=function(e){return format(this._data,e)},DenseMatrix$1.prototype.toString=function(){return format(this._data)},DenseMatrix$1.prototype.toJSON=function(){return{mathjs:`DenseMatrix`,data:this._data,size:this._size,datatype:this._datatype}},DenseMatrix$1.prototype.diagonal=function(e){if(e){if(isBigNumber(e)&&(e=e.toNumber()),!isNumber$1(e)||!isInteger(e))throw TypeError(`The parameter k must be an integer number`)}else e=0;for(var t=e>0?e:0,n=e<0?-e:0,r=this._size[0],i=this._size[1],a=Math.min(r-n,i-t),o=[],s=0;s<a;s++)o[s]=this._data[s+n][s+t];return new DenseMatrix$1({data:o,size:[a],datatype:this._datatype})},DenseMatrix$1.diagonal=function(e,t,n,r){if(!L(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(isBigNumber(e)&&(e=e.toNumber()),!isNumber$1(e)||!isInteger(e)||e<1)throw Error(`Size values must be positive integers`);return e}),n){if(isBigNumber(n)&&(n=n.toNumber()),!isNumber$1(n)||!isInteger(n))throw TypeError(`The parameter k must be an integer number`)}else n=0;var i=n>0?n:0,a=n<0?-n:0,o=e[0],s=e[1],c=Math.min(o-a,s-i),l;if(L(t)){if(t.length!==c)throw Error(`Invalid value array length`);l=function _value$1(e){return t[e]}}else if(isMatrix(t)){var u=t.size();if(u.length!==1||u[0]!==c)throw Error(`Invalid matrix length`);l=function _value$1(e){return t.get([e])}}else l=function _value$1(){return t};r||=isBigNumber(l(0))?l(0).mul(0):0;var d=[];if(e.length>0){d=resize(d,e,r);for(var f=0;f<c;f++)d[f+a][f+i]=l(f)}return new DenseMatrix$1({data:d,size:[o,s]})},DenseMatrix$1.fromJSON=function(e){return new DenseMatrix$1(e)},DenseMatrix$1.prototype.swapRows=function(e,t){if(!isNumber$1(e)||!isInteger(e)||!isNumber$1(t)||!isInteger(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return validateIndex(e,this._size[0]),validateIndex(t,this._size[0]),DenseMatrix$1._swapRows(e,t,this._data),this},DenseMatrix$1._swapRows=function(e,t,n){var r=n[e];n[e]=n[t],n[t]=r};function preprocess(e){return isMatrix(e)?preprocess(e.valueOf()):L(e)?e.map(preprocess):e}return DenseMatrix$1},{isClass:!0});function deepMap(e,t,n){return e&&typeof e.map==`function`?e.map(function(e){return deepMap(e,t,n)}):t(e)}var nt=`isNumeric`,rt=factory(nt,[`typed`],e=>{var{typed:t}=e;return t(nt,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>deepMap(t,e))})}),it=`hasNumericValue`,at=factory(it,[`typed`,`isNumeric`],e=>{var{typed:t,isNumeric:n}=e;return t(it,{boolean:()=>!0,string:function string(e){return e.trim().length>0&&!isNaN(Number(e))},any:function any(e){return n(e)}})}),ot=Ne({BigNumber:Xe({config:Ee}),Complex:Qe({}),DenseMatrix:tt({Matrix:et({})}),Fraction:$e({})}),st=at({isNumeric:rt({typed:ot}),typed:ot});const shortTimePeriodIsMilliseconds=e=>{let t=Number(e);return Number.isNaN(t)?!1:t>=120&&t<=36e4},resolveWaitTimeMs=e=>{let t=Number(e),n=Date.now();return Number.isNaN(t)?n+1e3:!shortTimePeriodIsMilliseconds(t)&&c(t)?adjustUnixTimestamp(t):shortTimePeriodIsMilliseconds(t)?n+t:n+t*I},superNormalizeHeaders=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]=st(r)?Number(r):null}return t},extractRateLimitHeaders=e=>{let t=superNormalizeHeaders(e);return{rateLimitLimit:t.ratelimitlimit,rateLimitRemaining:t.ratelimitremaining,rateLimitReset:resolveWaitTimeMs(t.ratelimitreset),concurrencyLimit:t.ratelimitconcurrencylimit,concurrencyRemaining:t.ratelimitconcurrencyremaining,concurrencyReset:resolveWaitTimeMs(t.ratelimitconcurrencyreset)}},generateRequestKey=e=>{let{accountSecureId:t,service:n,resource:r,subResource:i,childResource:a,action:o,behaviours:s}=e??{};return[t,n,r,o].some(l)?null:[t,n,r,i,a,o,...s??[]].filter(Boolean).join(`-`)},getRetryAfterWaitTime=(e,t=10,n=1)=>{let r=Date.now();return c(e)||u(e)?evaluateRetryAfterNumber(Number(e),r,t,n):isString$1(e)&&e!==``?evaluateRetryAfterString(e,r,t,n):n},evaluateRetryAfterNumber=(e,t,n=10,r=1)=>{if(e<n)return e;let i=adjustUnixTimestamp(e);if(i>t){let e=Math.floor((i-t)/I);return e>0&&e<n?e:r}return r},evaluateRetryAfterString=(e,t,n=10,r=1)=>{if(be.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)/I);return e>0&&e<n?e:r}return r},retryErrorInterceptor=({axiosInstance:t,logger:n,requestConfig:r,context:a})=>e(async e=>{let{response:o,config:s}=e;if(s?.signal?.aborted)return Promise.reject(createAxiosError(`Request aborted`,s,`ERR_CANCELED`,o));let{status:c,retryAfter:l}=convertError(o,a,r,n);if(c===429&&p(s)){let r=getRetryAfterWaitTime(l);if(s._retryCount>=5)return n?.warning({category:`http-transport`,message:`Max retries exceeded for ${s?.url}. Aborting.`,context:{...a??{},retryAfterHeader:l,retryAfterAsNumber:r}}),Promise.reject(e);let c=s._retryCount??0,u={...s,_retryCount:c+1},d=l?r*I:i(u._retryCount);return n?.debug({category:`http-transport`,message:`Received 429 error from ${s?.url}`,context:{...a??{},retryAfterHeader:l,calculatedRetryAfter:d}}),await abortableDelay(d,s,o),t?.request(u)}return Promise.reject(e)},`retryErrorInterceptor`),convertError=(e,t,n,r)=>{let{provider:i}=t??{},{status:a,headers:o,data:s}=e??{},{retryafter:c}=superNormalizeHeaders(o??{});if(l(i)||l(e))return r?.warning({category:`http-transport`,message:`Invalid parameters for convertError`,context:{...t,responseIsMissing:l(e),providerIsMissing:l(i),status:e?.status??`undefined`,statusText:e?.statusText??`undefined`,retryafter:c??`undefined`}}),{status:a,retryAfter:c};let u=n?.rateLimits?.mappedRateLimitErrors;if(p(u)&&p(s))for(let e of u){let{errorStatus:t,errorMessagePath:n,errorMessage:r,retryAfterPath:i,retryAfterUnit:l,retryAfterValue:u}=e;if(t!==a)continue;let f=n??`message`,p=testMessage(d(s)?w({path:f,json:s})[0]:s,r);if(t===a&&p){let e=convertRetryAfter(u??extractRetryAfter(o,i),l);return{status:429,retryAfter:c??e}}}return{status:a,retryAfter:c}},testMessage=(e,t)=>t instanceof RegExp?t.test(e??``):e?.includes(t)??!1,extractRetryAfter=(e,t)=>p(t)&&p(e)?w({path:t,json:e})[0]:null,convertRetryAfter=(e,t=`seconds`)=>p(e)?transformToSeconds(e,t):null,transformToSeconds=(e,t)=>{if(t===`seconds`)return typeof e==`string`?parseFloat(e):e;if(t===`milliseconds`)return(typeof e==`string`?parseFloat(e):e)/I;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`)},ct=`rateLimitErrorInterceptor`,rateLimitErrorInterceptor=({axiosInstance:t,logger:n,requestConfig:r,context:a,concurrencyManager:o})=>e(async e=>{let{response:s,config:c}=e,u=c?.signal;if(l(a)||l(c))return n?.warning({category:`HttpClient`,message:`No context or config for this response - that doesn't seem right.`,context:{interceptor:ct,...c,httpsAgent:void 0,headers:void 0,hasContext:p(a),hasConfig:p(c)},code:F.InterceptorContextNotPresent}),Promise.reject(e);if(l(o))return n?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:ct,...c,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:p(o)},code:F.RateLimitOrConcurrencyManagerNotInitialized}),Promise.reject(e);let{requestId:d,targetConcurrencyKey:f,leaseSubscription:m,setRemovalSubscription:h}=c?.requestMetadata??{};if(!(p(d)&&p(f)&&await o.releaseRequest(d,f))&&p(c?.requestMetadata)&&n?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{...a,interceptor:ct,requestId:d,targetConcurrencyKey:f,leaseSubscription:m,setRemovalSubscription:h},code:F.RateLimiterReleaseRequestFailed}),u?.aborted)return Promise.reject(createAxiosError(`Request aborted`,c,`ERR_CANCELED`,s));let{status:g,retryAfter:_}=convertError(s,a,r,n);if(g===429&&p(c)){let r=getRetryAfterWaitTime(_);if(c._retryCount>=5)return n?.warning({category:`HttpClient`,message:`Max retries exceeded for ${c.url}. Aborting.`,context:{...a??{},...c.requestMetadata??{},retryAfterHeader:_,retryAfterAsNumber:r}}),Promise.reject(e);let o=c?._retryCount??0,l={...c,_retryCount:o+1},u=_?r*I:i(l._retryCount);return n?.debug({category:`HttpClient`,message:`Received 429 error from ${c.url}`,context:{...a,retryAfterHeader:_,calculatedRetryAfter:u}}),await abortableDelay(u,c,s),t?.request(l)}return Promise.reject(e)},`rateLimitErrorInterceptor`),lt=`rateLimitResponseInterceptor`,rateLimitResponseInterceptor=({logger:t,context:n,concurrencyManager:r})=>e(async e=>{let i=e?.config,a=i?.signal;if(l(n))t?.warning({category:`HttpClient`,message:`No context for this response - that doesn't seem right.`,context:{interceptor:lt,...i,httpsAgent:void 0,headers:void 0}});else if(l(r))return t?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:lt,...i,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:p(r)},code:F.RateLimitOrConcurrencyManagerNotInitialized}),e;else if(p(n.provider)&&p(n.accountSecureId)){let n=e?.headers;if(p(n)){let e=extractRateLimitHeaders(n);t?.debug({category:`HttpClient`,message:`Rate limit headers extracted`,context:{interceptor:lt,rateLimitHeaders:e}})}let{requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:l}=i?.requestMetadata??{};if(await r.releaseRequest(o,s)||t?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{interceptor:lt,requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:l},code:F.RateLimiterReleaseRequestFailed}),a?.aborted)return Promise.reject(createAxiosError(`Request aborted`,i,`ERR_CANCELED`,e))}return e},`rateLimitResponseInterceptor`),validateRequestInterceptor=e=>(e.validateStatus??=e=>e>=200&&e<300,e),ut=[{onFulfilled:validateRequestInterceptor,onRejected:null,options:void 0}],dt=[{onFulfilled:null,onRejected:retryErrorInterceptor},{onFulfilled:null,onRejected:abortErrorInterceptor}],ft=[{onFulfilled:validateRequestInterceptor,onRejected:null,options:void 0},{onFulfilled:checkConcurrencyInterceptor,onRejected:null,options:void 0}],pt=[{onFulfilled:rateLimitResponseInterceptor,onRejected:rateLimitErrorInterceptor},{onFulfilled:null,onRejected:abortErrorInterceptor}];var RateLimitManager=class extends ScriptManager{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=p(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),u=c.map(e=>e.rateLimit);return await this.executeScript(ve.incr,[a,...l],[o.toString(),...u.map(String)])}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()}},SingletonManager=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(l(t))throw Error(`Singleton ${e.name} not prepared yet`);if(t.hasInitFailed?.())throw Error(`${e.name} initialization failed`);let n=t.getInstanceIfReady?.();if(p(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 mt=function(e){return e.HttpTransportInstanceCreateError=`HttpTransportInstanceCreateError`,e}({});const getTransportInstance=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`)?createDefaultRetryInstance(e,n):createDefaultInstance(e,n),l(n?.service)||l(n?.organizationId)||o===`test`||l(t)||l(e))return a;let c=SingletonManager.getIfReady(RateLimitManager)??void 0,u=SingletonManager.getIfReady(ConcurrencyManager)??void 0,d=c?.isReady(),f=u?.isRedisConfigured(),m=[],h=[];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.`);m.push(...ft),h.push(...pt)}let g=generateRequestKey(n);if(l(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:p(a)}}),a;let _=await ge.get(g);if(p(_))return _;let v={interceptors:{requestConfigs:m,responseConfigs:h},instanceConfig:{maxBodyLength:1/0},logger:e,context:n,requestConfig:r,httpsAgentConfig:i,concurrencyManager:u,rateLimitManager:c},y=HttpTransportFactory.createInstance(v);return e?.debug({category:`http-transport`,message:`Creating new Axios instance and caching it for key: [${g}]`,context:{...n}}),await ge.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:p(a)},error:t,code:mt.HttpTransportInstanceCreateError}),p(a)?a:createAxiosInstance()}},createDefaultInstance=(e,t)=>{let n={instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return HttpTransportFactory.createInstance(n)??createAxiosInstance()},createDefaultRetryInstance=(e,t)=>{let n={interceptors:{requestConfigs:ut,responseConfigs:dt},instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return HttpTransportFactory.createInstance(n)??createAxiosInstance()},createAxiosInstance=()=>y.create({maxBodyLength:1/0});var HttpClient=class{#e;#t;#n;#r;#i;#a;constructor({transportFactory:e=getTransportInstance,getRedisClient:t=buildRedisClientInstance,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?o(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:m,httpsAgentConfig:h}){try{p(this.#r)&&l(this.#a)&&(this.#a=await this.#t(this.#r,this.#n,`HttpClient`));let g=this.#_(t,r),_=this.#l(e),v=this.#m(u,e),y=await this.#s({url:g,payload:v,method:n,cacheTTL:o,context:s});if(y)return{...y,responseTime:new Date};let b=he.getInstance(),x=(p(c)?await b.get(c):null)?.signal,S=await(await this.#e({redisClientConfig:this.#r,logger:this.#n,context:s,requestConfig:m,httpsAgentConfig:h})).request({headers:_,url:g,method:n,maxRedirects:i,responseType:a,data:v,httpsAgent:d,httpAgent:f,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:o,context:s,response:C}),C}catch(e){let r=e;r.url=T(t),this.#n?.warning({category:this.name,message:`Request error [${n?.toUpperCase()} ${r.url}]: ${r.message}.`,error:r});let i=this.#h(r);throw p(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:u,httpsAgentConfig:d}){try{let f=this.#_(t,r),m=this.#l(e),h=this.#m(s,e),g=he.getInstance(),_=(p(o)?await g.get(o):null)?.signal,v=await(await this.#e({redisClientConfig:this.#r,logger:this.#n,context:a,requestConfig:u,httpsAgentConfig:d})).request({headers:m,url:f,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=T(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 p(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 f(e[`content-type`])?e[`content-type`]?.startsWith(`multipart/form-data`)??!1:!1}#p(e){return l(e)||typeof e!=`object`||!e?!1:`pipe`in e&&typeof e.pipe==`function`}#m(e,t){if(!(l(e)||d(e)&&Object.keys(e).length===0))return this.#f(t)||this.#p(e)?e:this.#d(t)?E.stringify(e):e}#h(e){if(b(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(l(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(E.stringify(n)),Object.keys(r).length>0&&o.push(E.stringify(r,{arrayFormat:`repeat`})),Object.keys(i).length>0&&o.push(E.stringify(i,{arrayFormat:`brackets`})),Object.keys(a).length>0&&o.push(E.stringify(a,{arrayFormat:`comma`}));let s=o.join(`&`);return p(s)?`${e}?${s}`:e}};const buildHttpClientInstance=(e,t,n)=>new HttpClient({redisClientConfig:e,logger:t,errorMappingFn:n});var HttpClientManager=class{static{this.httpClientInstance=null}static async getInstance({redisClientConfig:e,logger:t,errorMappingFn:n,getHttpClient:r=buildHttpClientInstance}){return this.httpClientInstance??=r(e,t,n),this.httpClientInstance}static resetInstance(){this.httpClientInstance=null}};const ht=[`get`,`post`,`put`,`delete`,`patch`],gt={[A.rPush]:`
114
114
  local queueLength = redis.call('RPUSH', KEYS[1], ARGV[1])
115
115
 
116
116
  redis.call('PEXPIRE', KEYS[1], ARGV[2])
@@ -174,4 +174,4 @@ Example:
174
174
  `);let t=new XmlNode(`!xml`),n=t,r=``,i=``;for(let a=0;a<e.length;a++)if(e[a]===`<`)if(e[a+1]===`/`){let t=findClosingIndex(e,`>`,a,`Closing Tag is not closed.`),o=e.substring(a+2,t).trim();if(this.options.removeNSPrefix){let e=o.indexOf(`:`);e!==-1&&(o=o.substr(e+1))}this.options.transformTagName&&(o=this.options.transformTagName(o)),n&&(r=this.saveTextToParentTag(r,n,i));let s=i.substring(i.lastIndexOf(`.`)+1);if(o&&this.options.unpairedTags.indexOf(o)!==-1)throw Error(`Unpaired tag can not be used as closing tag: </${o}>`);let c=0;s&&this.options.unpairedTags.indexOf(s)!==-1?(c=i.lastIndexOf(`.`,i.lastIndexOf(`.`)-1),this.tagsNodeStack.pop()):c=i.lastIndexOf(`.`),i=i.substring(0,c),n=this.tagsNodeStack.pop(),r=``,a=t}else if(e[a+1]===`?`){let t=readTagExp(e,a,!1,`?>`);if(!t)throw Error(`Pi Tag is not closed.`);if(r=this.saveTextToParentTag(r,n,i),!(this.options.ignoreDeclaration&&t.tagName===`?xml`||this.options.ignorePiTags)){let e=new XmlNode(t.tagName);e.add(this.options.textNodeName,``),t.tagName!==t.tagExp&&t.attrExpPresent&&(e[`:@`]=this.buildAttributesMap(t.tagExp,i,t.tagName)),this.addChild(n,e,i,a)}a=t.closeIndex+1}else if(e.substr(a+1,3)===`!--`){let t=findClosingIndex(e,`-->`,a+4,`Comment is not closed.`);if(this.options.commentPropName){let o=e.substring(a+4,t-2);r=this.saveTextToParentTag(r,n,i),n.add(this.options.commentPropName,[{[this.options.textNodeName]:o}])}a=t}else if(e.substr(a+1,2)===`!D`){let t=readDocType(e,a);this.docTypeEntities=t.entities,a=t.i}else if(e.substr(a+1,2)===`![`){let t=findClosingIndex(e,`]]>`,a,`CDATA is not closed.`)-2,o=e.substring(a+9,t);r=this.saveTextToParentTag(r,n,i);let s=this.parseTextData(o,n.tagname,i,!0,!1,!0,!0);s??=``,this.options.cdataPropName?n.add(this.options.cdataPropName,[{[this.options.textNodeName]:o}]):n.add(this.options.textNodeName,s),a=t+2}else{let o=readTagExp(e,a,this.options.removeNSPrefix),s=o.tagName,c=o.rawTagName,l=o.tagExp,u=o.attrExpPresent,d=o.closeIndex;this.options.transformTagName&&(s=this.options.transformTagName(s)),n&&r&&n.tagname!==`!xml`&&(r=this.saveTextToParentTag(r,n,i,!1));let f=n;f&&this.options.unpairedTags.indexOf(f.tagname)!==-1&&(n=this.tagsNodeStack.pop(),i=i.substring(0,i.lastIndexOf(`.`))),s!==t.tagname&&(i+=i?`.`+s:s);let p=a;if(this.isItStopNode(this.options.stopNodes,i,s)){let t=``;if(l.length>0&&l.lastIndexOf(`/`)===l.length-1)s[s.length-1]===`/`?(s=s.substr(0,s.length-1),i=i.substr(0,i.length-1),l=s):l=l.substr(0,l.length-1),a=o.closeIndex;else if(this.options.unpairedTags.indexOf(s)!==-1)a=o.closeIndex;else{let n=this.readStopNodeData(e,c,d+1);if(!n)throw Error(`Unexpected end of ${c}`);a=n.i,t=n.tagContent}let r=new XmlNode(s);s!==l&&u&&(r[`:@`]=this.buildAttributesMap(l,i,s)),t&&=this.parseTextData(t,s,i,!0,u,!0,!0),i=i.substr(0,i.lastIndexOf(`.`)),r.add(this.options.textNodeName,t),this.addChild(n,r,i,p)}else{if(l.length>0&&l.lastIndexOf(`/`)===l.length-1){s[s.length-1]===`/`?(s=s.substr(0,s.length-1),i=i.substr(0,i.length-1),l=s):l=l.substr(0,l.length-1),this.options.transformTagName&&(s=this.options.transformTagName(s));let e=new XmlNode(s);s!==l&&u&&(e[`:@`]=this.buildAttributesMap(l,i,s)),this.addChild(n,e,i,p),i=i.substr(0,i.lastIndexOf(`.`))}else{let e=new XmlNode(s);this.tagsNodeStack.push(n),s!==l&&u&&(e[`:@`]=this.buildAttributesMap(l,i,s)),this.addChild(n,e,i,p),n=e}r=``,a=d}}else r+=e[a];return t.child};function addChild(e,t,n,r){this.options.captureMetaData||(r=void 0);let i=this.options.updateTag(t.tagname,n,t[`:@`]);i===!1||(typeof i==`string`&&(t.tagname=i),e.addChild(t,r))}const jt=e(function(e){if(this.options.processEntities){for(let t in this.docTypeEntities){let n=this.docTypeEntities[t];e=e.replace(n.regx,n.val)}for(let t in this.lastEntities){let n=this.lastEntities[t];e=e.replace(n.regex,n.val)}if(this.options.htmlEntities)for(let t in this.htmlEntities){let n=this.htmlEntities[t];e=e.replace(n.regex,n.val)}e=e.replace(this.ampEntity.regex,this.ampEntity.val)}return e},`replaceEntitiesValue`);function saveTextToParentTag(e,t,n,r){return e&&=(r===void 0&&(r=t.child.length===0),e=this.parseTextData(e,t.tagname,n,!1,t[`:@`]?Object.keys(t[`:@`]).length!==0:!1,r),e!==void 0&&e!==``&&t.add(this.options.textNodeName,e),``),e}function isItStopNode(e,t,n){let r=`*.`+n;for(let n in e){let i=e[n];if(r===i||t===i)return!0}return!1}function tagExpWithClosingIndex(e,t,n=`>`){let r,i=``;for(let a=t;a<e.length;a++){let t=e[a];if(r)t===r&&(r=``);else if(t===`"`||t===`'`)r=t;else if(t===n[0])if(n[1]){if(e[a+1]===n[1])return{data:i,index:a}}else return{data:i,index:a};else t===` `&&(t=` `);i+=t}}function findClosingIndex(e,t,n,r){let i=e.indexOf(t,n);if(i===-1)throw Error(r);return i+t.length-1}function readTagExp(e,t,n,r=`>`){let i=tagExpWithClosingIndex(e,t+1,r);if(!i)return;let a=i.data,o=i.index,s=a.search(/\s/),c=a,l=!0;s!==-1&&(c=a.substring(0,s),a=a.substring(s+1).trimStart());let u=c;if(n){let e=c.indexOf(`:`);e!==-1&&(c=c.substr(e+1),l=c!==i.data.substr(e+1))}return{tagName:c,tagExp:a,closeIndex:o,attrExpPresent:l,rawTagName:u}}function readStopNodeData(e,t,n){let r=n,i=1;for(;n<e.length;n++)if(e[n]===`<`)if(e[n+1]===`/`){let a=findClosingIndex(e,`>`,n,`${t} is not closed`);if(e.substring(n+2,a).trim()===t&&(i--,i===0))return{tagContent:e.substring(r,n),i:a};n=a}else if(e[n+1]===`?`)n=findClosingIndex(e,`?>`,n+1,`StopNode is not closed.`);else if(e.substr(n+1,3)===`!--`)n=findClosingIndex(e,`-->`,n+3,`StopNode is not closed.`);else if(e.substr(n+1,2)===`![`)n=findClosingIndex(e,`]]>`,n,`StopNode is not closed.`)-2;else{let r=readTagExp(e,n,`>`);r&&((r&&r.tagName)===t&&r.tagExp[r.tagExp.length-1]!==`/`&&i++,n=r.closeIndex)}}function parseValue(e,t,n){if(t&&typeof e==`string`){let t=e.trim();return t===`true`?!0:t===`false`?!1:toNumber(e,n)}else if(isExist(e))return e;else return``}const Mt=XmlNode.getMetaDataSymbol();function prettify(e,t){return compress(e,t)}function compress(e,t,n){let r,i={};for(let a=0;a<e.length;a++){let o=e[a],s=propName$1(o),c=``;if(c=n===void 0?s:n+`.`+s,s===t.textNodeName)r===void 0?r=o[s]:r+=``+o[s];else if(s===void 0)continue;else if(o[s]){let e=compress(o[s],t,c),n=isLeafTag(e,t);o[Mt]!==void 0&&(e[Mt]=o[Mt]),o[`:@`]?assignAttributes(e,o[`:@`],c,t):Object.keys(e).length===1&&e[t.textNodeName]!==void 0&&!t.alwaysCreateTextNode?e=e[t.textNodeName]:Object.keys(e).length===0&&(t.alwaysCreateTextNode?e[t.textNodeName]=``:e=``),i[s]!==void 0&&i.hasOwnProperty(s)?(Array.isArray(i[s])||(i[s]=[i[s]]),i[s].push(e)):t.isArray(s,c,n)?i[s]=[e]:i[s]=e}}return typeof r==`string`?r.length>0&&(i[t.textNodeName]=r):r!==void 0&&(i[t.textNodeName]=r),i}function propName$1(e){let t=Object.keys(e);for(let e=0;e<t.length;e++){let n=t[e];if(n!==`:@`)return n}}e(propName$1,`propName`);function assignAttributes(e,t,n,r){if(t){let i=Object.keys(t),a=i.length;for(let o=0;o<a;o++){let a=i[o];r.isArray(a,n+`.`+a,!0,!0)?e[a]=[t[a]]:e[a]=t[a]}}}function isLeafTag(e,t){let{textNodeName:n}=t,r=Object.keys(e).length;return!!(r===0||r===1&&(e[n]||typeof e[n]==`boolean`||e[n]===0))}var XMLParser=class{constructor(e){this.externalEntities={},this.options=buildOptions(e)}parse(e,t){if(typeof e!=`string`)if(e.toString)e=e.toString();else throw Error(`XML data is accepted in String or Bytes[] form.`);if(t){t===!0&&(t={});let n=validate(e,t);if(n!==!0)throw Error(`${n.err.msg}:${n.err.line}:${n.err.col}`)}let n=new OrderedObjParser(this.options);n.addExternalEntities(this.externalEntities);let r=n.parseXml(e);return this.options.preserveOrder||r===void 0?r:prettify(r,this.options)}addEntity(e,t){if(t.indexOf(`&`)!==-1)throw Error(`Entity value can't have '&'`);if(e.indexOf(`&`)!==-1||e.indexOf(`;`)!==-1)throw Error(`An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'`);if(t===`&`)throw Error(`An entity with value '&' is not permitted`);this.externalEntities[e]=t}static getMetaDataSymbol(){return XmlNode.getMetaDataSymbol()}};function toXml(e,t){let n=``;return t.format&&t.indentBy.length>0&&(n=`
175
175
  `),arrToStr(e,t,``,n)}function arrToStr(e,t,n,r){let i=``,a=!1;for(let o=0;o<e.length;o++){let s=e[o],c=propName(s);if(c===void 0)continue;let l=``;if(l=n.length===0?c:`${n}.${c}`,c===t.textNodeName){let e=s[c];isStopNode(l,t)||(e=t.tagValueProcessor(c,e),e=replaceEntitiesValue(e,t)),a&&(i+=r),i+=e,a=!1;continue}else if(c===t.cdataPropName){a&&(i+=r),i+=`<![CDATA[${s[c][0][t.textNodeName]}]]>`,a=!1;continue}else if(c===t.commentPropName){i+=r+`<!--${s[c][0][t.textNodeName]}-->`,a=!0;continue}else if(c[0]===`?`){let e=attr_to_str(s[`:@`],t),n=c===`?xml`?``:r,o=s[c][0][t.textNodeName];o=o.length===0?``:` `+o,i+=n+`<${c}${o}${e}?>`,a=!0;continue}let u=r;u!==``&&(u+=t.indentBy);let d=r+`<${c}${attr_to_str(s[`:@`],t)}`,f=arrToStr(s[c],t,l,u);t.unpairedTags.indexOf(c)===-1?(!f||f.length===0)&&t.suppressEmptyNode?i+=d+`/>`:f&&f.endsWith(`>`)?i+=d+`>${f}${r}</${c}>`:(i+=d+`>`,f&&r!==``&&(f.includes(`/>`)||f.includes(`</`))?i+=r+t.indentBy+f+r:i+=f,i+=`</${c}>`):t.suppressUnpairedNode?i+=d+`>`:i+=d+`/>`,a=!0}return i}function propName(e){let t=Object.keys(e);for(let n=0;n<t.length;n++){let r=t[n];if(e.hasOwnProperty(r)&&r!==`:@`)return r}}function attr_to_str(e,t){let n=``;if(e&&!t.ignoreAttributes)for(let r in e){if(!e.hasOwnProperty(r))continue;let i=t.attributeValueProcessor(r,e[r]);i=replaceEntitiesValue(i,t),i===!0&&t.suppressBooleanAttributes?n+=` ${r.substr(t.attributeNamePrefix.length)}`:n+=` ${r.substr(t.attributeNamePrefix.length)}="${i}"`}return n}function isStopNode(e,t){e=e.substr(0,e.length-t.textNodeName.length-1);let n=e.substr(e.lastIndexOf(`.`)+1);for(let r in t.stopNodes)if(t.stopNodes[r]===e||t.stopNodes[r]===`*.`+n)return!0;return!1}function replaceEntitiesValue(e,t){if(e&&e.length>0&&t.processEntities)for(let n=0;n<t.entities.length;n++){let r=t.entities[n];e=e.replace(r.regex,r.val)}return e}const Nt={attributeNamePrefix:`@_`,attributesGroupName:!1,textNodeName:`#text`,ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:` `,suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(e,t){return t},attributeValueProcessor:function(e,t){return t},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:RegExp(`&`,`g`),val:`&amp;`},{regex:RegExp(`>`,`g`),val:`&gt;`},{regex:RegExp(`<`,`g`),val:`&lt;`},{regex:RegExp(`'`,`g`),val:`&apos;`},{regex:RegExp(`"`,`g`),val:`&quot;`}],processEntities:!0,stopNodes:[],oneListGroup:!1};function Builder(e){this.options=Object.assign({},Nt,e),this.options.ignoreAttributes===!0||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.ignoreAttributesFn=getIgnoreAttributesFn(this.options.ignoreAttributes),this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=isAttribute),this.processTextOrObjNode=processTextOrObjNode,this.options.format?(this.indentate=indentate,this.tagEndChar=`>
176
176
  `,this.newLine=`
177
- `):(this.indentate=function(){return``},this.tagEndChar=`>`,this.newLine=``)}Builder.prototype.build=function(e){return this.options.preserveOrder?toXml(e,this.options):(Array.isArray(e)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(e={[this.options.arrayNodeName]:e}),this.j2x(e,0,[]).val)},Builder.prototype.j2x=function(e,t,n){let r=``,i=``,a=n.join(`.`);for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o))if(e[o]===void 0)this.isAttribute(o)&&(i+=``);else if(e[o]===null)this.isAttribute(o)||o===this.options.cdataPropName?i+=``:o[0]===`?`?i+=this.indentate(t)+`<`+o+`?`+this.tagEndChar:i+=this.indentate(t)+`<`+o+`/`+this.tagEndChar;else if(e[o]instanceof Date)i+=this.buildTextValNode(e[o],o,``,t);else if(typeof e[o]!=`object`){let n=this.isAttribute(o);if(n&&!this.ignoreAttributesFn(n,a))r+=this.buildAttrPairStr(n,``+e[o]);else if(!n)if(o===this.options.textNodeName){let t=this.options.tagValueProcessor(o,``+e[o]);i+=this.replaceEntitiesValue(t)}else i+=this.buildTextValNode(e[o],o,``,t)}else if(Array.isArray(e[o])){let r=e[o].length,a=``,s=``;for(let c=0;c<r;c++){let r=e[o][c];if(r!==void 0)if(r===null)o[0]===`?`?i+=this.indentate(t)+`<`+o+`?`+this.tagEndChar:i+=this.indentate(t)+`<`+o+`/`+this.tagEndChar;else if(typeof r==`object`)if(this.options.oneListGroup){let e=this.j2x(r,t+1,n.concat(o));a+=e.val,this.options.attributesGroupName&&r.hasOwnProperty(this.options.attributesGroupName)&&(s+=e.attrStr)}else a+=this.processTextOrObjNode(r,o,t,n);else if(this.options.oneListGroup){let e=this.options.tagValueProcessor(o,r);e=this.replaceEntitiesValue(e),a+=e}else a+=this.buildTextValNode(r,o,``,t)}this.options.oneListGroup&&(a=this.buildObjectNode(a,o,s,t)),i+=a}else if(this.options.attributesGroupName&&o===this.options.attributesGroupName){let t=Object.keys(e[o]),n=t.length;for(let i=0;i<n;i++)r+=this.buildAttrPairStr(t[i],``+e[o][t[i]])}else i+=this.processTextOrObjNode(e[o],o,t,n);return{attrStr:r,val:i}},Builder.prototype.buildAttrPairStr=function(e,t){return t=this.options.attributeValueProcessor(e,``+t),t=this.replaceEntitiesValue(t),this.options.suppressBooleanAttributes&&t===`true`?` `+e:` `+e+`="`+t+`"`};function processTextOrObjNode(e,t,n,r){let i=this.j2x(e,n+1,r.concat(t));return e[this.options.textNodeName]!==void 0&&Object.keys(e).length===1?this.buildTextValNode(e[this.options.textNodeName],t,i.attrStr,n):this.buildObjectNode(i.val,t,i.attrStr,n)}Builder.prototype.buildObjectNode=function(e,t,n,r){if(e===``)return t[0]===`?`?this.indentate(r)+`<`+t+n+`?`+this.tagEndChar:this.indentate(r)+`<`+t+n+this.closeTag(t)+this.tagEndChar;{let i=`</`+t+this.tagEndChar,a=``;return t[0]===`?`&&(a=`?`,i=``),(n||n===``)&&e.indexOf(`<`)===-1?this.indentate(r)+`<`+t+n+a+`>`+e+i:this.options.commentPropName!==!1&&t===this.options.commentPropName&&a.length===0?this.indentate(r)+`<!--${e}-->`+this.newLine:this.indentate(r)+`<`+t+n+a+this.tagEndChar+e+this.indentate(r)+i}},Builder.prototype.closeTag=function(e){let t=``;return this.options.unpairedTags.indexOf(e)===-1?t=this.options.suppressEmptyNode?`/`:`></${e}`:this.options.suppressUnpairedNode||(t=`/`),t},Builder.prototype.buildTextValNode=function(e,t,n,r){if(this.options.cdataPropName!==!1&&t===this.options.cdataPropName)return this.indentate(r)+`<![CDATA[${e}]]>`+this.newLine;if(this.options.commentPropName!==!1&&t===this.options.commentPropName)return this.indentate(r)+`<!--${e}-->`+this.newLine;if(t[0]===`?`)return this.indentate(r)+`<`+t+n+`?`+this.tagEndChar;{let i=this.options.tagValueProcessor(t,e);return i=this.replaceEntitiesValue(i),i===``?this.indentate(r)+`<`+t+n+this.closeTag(t)+this.tagEndChar:this.indentate(r)+`<`+t+n+`>`+i+`</`+t+this.tagEndChar}},Builder.prototype.replaceEntitiesValue=function(e){if(e&&e.length>0&&this.options.processEntities)for(let t=0;t<this.options.entities.length;t++){let n=this.options.entities[t];e=e.replace(n.regex,n.val)}return e};function indentate(e){return this.options.indentBy.repeat(e)}function isAttribute(e){return e.startsWith(this.options.attributeNamePrefix)&&e!==this.options.textNodeName?e.substr(this.attrPrefixLen):!1}const Pt={validate};var SoapClient=class{async performRequest({httpClient:e,url:t,method:n,headers:r,queryParams:i,body:a,customErrorConfigs:o,requestConfig:s}){let c;if(c=typeof s?.envelope==`string`?s.envelope:typeof s?.envelope==`object`?Ft.build(s.envelope):await buildEnvelope(a,s),Pt.validate(c,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);let u,d={...r,"Content-Type":`text/xml`};s?.soapAction&&(d.SOAPAction=s.soapAction);try{u=await e?.request({method:n,url:t,headers:d,queryParams:i,maxRedirects:0,payload:c,requestConfig:s})}catch(e){if(l(e?.response))throw e;u=e.response}let f=It.parse(u.data),p=f.Envelope||f,m=p.Body||p,h=m.Fault;if(h)throw new me({...u,status:500,data:h,message:h.faultstring??h.faultcode??`SOAP Fault`},h.faultstring??`SOAP Fault occurred`);u.data=m;let g=translateCustomError(u,o);if(isFailedStatusCode(g?.status))throw new me(g,g.message);return g}};const Ft=new Builder({attributeNamePrefix:`@_`,ignoreAttributes:!1,suppressBooleanAttributes:!1}),It=new XMLParser({ignoreAttributes:!1,attributeNamePrefix:`_`,removeNSPrefix:!0,numberParseOptions:{leadingZeros:!1,hex:!1}}),buildEnvelope=async(e,t)=>{if(p(t?.envelope)){let e=typeof t.envelope==`string`?t.envelope:Ft.build(t.envelope);if(Pt.validate(e,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return e}let n=await buildSoapEnvelope(t,e),r=Ft.build(n);if(Pt.validate(r,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return r},buildSoapEnvelope=async(e,t)=>{let n=await Promise.all((e?.namespaces||[]).map(async e=>({identifier:await _(e.namespaceIdentifier),namespace:await _(e.namespace)})));n.forEach(({identifier:e,namespace:t})=>{if(l(e)||l(t)||e===``||t===``)throw Error(`Invalid namespace config: both identifier and namespace are required`)});let r=n.reduce((e,{identifier:t,namespace:n})=>(e[`@_xmlns:${t}`]=n,e),{});return{"soapenv:Envelope":{"soapenv:Header":await buildSoapHeaders(t,e??{}),"soapenv:Body":await buildSoapBody(t,e?.soapOperation??``,n[0]?.identifier??``),"@_xmlns:soapenv":`http://schemas.xmlsoap.org/soap/envelope/`,...r}}},buildSoapHeaders=async(e,t)=>[await buildSoapSecurity(e,t)],buildSoapSecurity=async(e,t)=>{if(l(t.soapContext))return{};let{username:n,password:r}=t.soapContext;return{"wsse:Security":{"wsse:UsernameToken":{"wsse:Username":n,"wsse:Password":{"#text":r,"@_Type":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText`}},"@_soapenv:mustUnderstand":`1`,"@_xmlns:wsse":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd`,"@_xmlns:wsu":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd`}}},buildSoapBody=async(e,t,n)=>{if(l(t))throw Error(`Missing soapOperation in config`);let r=expandArrayAttributes({[t]:e});return(Array.isArray(r)?r:[r]).map(e=>applyNamespace(e,n))},expandArrayAttributes=e=>{if(typeof e!=`object`||!e)return e;if(Array.isArray(e)){if(e.length===1){let t=e[0];if(typeof t==`object`&&t&&!Array.isArray(t)){let e=Object.keys(t).filter(e=>!e.startsWith(`@_`));if(e.length===1){let n=e[0],r=t[n];if(typeof r==`object`&&r&&!Array.isArray(r)){let e=Object.keys(r),t=e.filter(e=>e.startsWith(`@_`)),i=e.filter(e=>!e.startsWith(`@_`)),a=t.find(e=>Array.isArray(r[e]));if(a&&i.length===0){let e=r[a],i=t.filter(e=>e!==a),o=e.map(e=>{let t={[a]:e};for(let e of i)t[e]=r[e];return t});return{[n]:o}}}}}}return e.map(e=>expandArrayAttributes(e))}let t={};for(let n of Object.keys(e)){let r=e[n];t[n]=expandArrayAttributes(r)}return t},applyNamespace=(e,t)=>{if(typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>applyNamespace(e,t));let n={};for(let r in e){let i=applyNamespaceToKey(r,t);n[i]=applyNamespace(e[r],t)}return n},applyNamespaceToKey=(e,t)=>{let n=e.split(`:`);return n.length>1&&n[0]||e.indexOf(`${t}:`)===0||e===`#text`?e:e.startsWith(`@_`)?`@_${t}:${e.slice(2)}`:`${t}:${e}`};var RequestClientFactory=class{static build(e=`rest`){if(e===`rest`)return new RestClient;if(e===`soap`)return new SoapClient;throw Error(`Unknown request client type: ${e}`)}};export{pe as CUSTOM_ERROR_CONFIG_SCHEMA,ConcurrencyManager,EventClient,HttpClient,HttpClientManager,fe as HttpErrorMessages,ht as HttpMethods,me as HttpResponseError,HttpTransportFactory,he as InstanceManager,LockManager,MemoryStore,yt as QueryArrayFormats,QueueManager,RateLimitManager,ee as RedisClient,RequestClientFactory,vt as RequestParameterLocations,ScriptManager,SubscriptionManager,buildHttpClientInstance,convertError,createAuthorizationHeaders,getRetryAfterWaitTime,getTransportInstance,getTransportManagers,initializeTransportSystem,isFailedStatusCode,isInfoStatusCode,isSuccessStatusCode,isTransportSystemReady,parseRequestParameters,serializeHttpResponseError,shutdownTransportSystem,superNormalizeHeaders,translateCustomError};
177
+ `):(this.indentate=function(){return``},this.tagEndChar=`>`,this.newLine=``)}Builder.prototype.build=function(e){return this.options.preserveOrder?toXml(e,this.options):(Array.isArray(e)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(e={[this.options.arrayNodeName]:e}),this.j2x(e,0,[]).val)},Builder.prototype.j2x=function(e,t,n){let r=``,i=``,a=n.join(`.`);for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o))if(e[o]===void 0)this.isAttribute(o)&&(i+=``);else if(e[o]===null)this.isAttribute(o)||o===this.options.cdataPropName?i+=``:o[0]===`?`?i+=this.indentate(t)+`<`+o+`?`+this.tagEndChar:i+=this.indentate(t)+`<`+o+`/`+this.tagEndChar;else if(e[o]instanceof Date)i+=this.buildTextValNode(e[o],o,``,t);else if(typeof e[o]!=`object`){let n=this.isAttribute(o);if(n&&!this.ignoreAttributesFn(n,a))r+=this.buildAttrPairStr(n,``+e[o]);else if(!n)if(o===this.options.textNodeName){let t=this.options.tagValueProcessor(o,``+e[o]);i+=this.replaceEntitiesValue(t)}else i+=this.buildTextValNode(e[o],o,``,t)}else if(Array.isArray(e[o])){let r=e[o].length,a=``,s=``;for(let c=0;c<r;c++){let r=e[o][c];if(r!==void 0)if(r===null)o[0]===`?`?i+=this.indentate(t)+`<`+o+`?`+this.tagEndChar:i+=this.indentate(t)+`<`+o+`/`+this.tagEndChar;else if(typeof r==`object`)if(this.options.oneListGroup){let e=this.j2x(r,t+1,n.concat(o));a+=e.val,this.options.attributesGroupName&&r.hasOwnProperty(this.options.attributesGroupName)&&(s+=e.attrStr)}else a+=this.processTextOrObjNode(r,o,t,n);else if(this.options.oneListGroup){let e=this.options.tagValueProcessor(o,r);e=this.replaceEntitiesValue(e),a+=e}else a+=this.buildTextValNode(r,o,``,t)}this.options.oneListGroup&&(a=this.buildObjectNode(a,o,s,t)),i+=a}else if(this.options.attributesGroupName&&o===this.options.attributesGroupName){let t=Object.keys(e[o]),n=t.length;for(let i=0;i<n;i++)r+=this.buildAttrPairStr(t[i],``+e[o][t[i]])}else i+=this.processTextOrObjNode(e[o],o,t,n);return{attrStr:r,val:i}},Builder.prototype.buildAttrPairStr=function(e,t){return t=this.options.attributeValueProcessor(e,``+t),t=this.replaceEntitiesValue(t),this.options.suppressBooleanAttributes&&t===`true`?` `+e:` `+e+`="`+t+`"`};function processTextOrObjNode(e,t,n,r){let i=this.j2x(e,n+1,r.concat(t));return e[this.options.textNodeName]!==void 0&&Object.keys(e).length===1?this.buildTextValNode(e[this.options.textNodeName],t,i.attrStr,n):this.buildObjectNode(i.val,t,i.attrStr,n)}Builder.prototype.buildObjectNode=function(e,t,n,r){if(e===``)return t[0]===`?`?this.indentate(r)+`<`+t+n+`?`+this.tagEndChar:this.indentate(r)+`<`+t+n+this.closeTag(t)+this.tagEndChar;{let i=`</`+t+this.tagEndChar,a=``;return t[0]===`?`&&(a=`?`,i=``),(n||n===``)&&e.indexOf(`<`)===-1?this.indentate(r)+`<`+t+n+a+`>`+e+i:this.options.commentPropName!==!1&&t===this.options.commentPropName&&a.length===0?this.indentate(r)+`<!--${e}-->`+this.newLine:this.indentate(r)+`<`+t+n+a+this.tagEndChar+e+this.indentate(r)+i}},Builder.prototype.closeTag=function(e){let t=``;return this.options.unpairedTags.indexOf(e)===-1?t=this.options.suppressEmptyNode?`/`:`></${e}`:this.options.suppressUnpairedNode||(t=`/`),t},Builder.prototype.buildTextValNode=function(e,t,n,r){if(this.options.cdataPropName!==!1&&t===this.options.cdataPropName)return this.indentate(r)+`<![CDATA[${e}]]>`+this.newLine;if(this.options.commentPropName!==!1&&t===this.options.commentPropName)return this.indentate(r)+`<!--${e}-->`+this.newLine;if(t[0]===`?`)return this.indentate(r)+`<`+t+n+`?`+this.tagEndChar;{let i=this.options.tagValueProcessor(t,e);return i=this.replaceEntitiesValue(i),i===``?this.indentate(r)+`<`+t+n+this.closeTag(t)+this.tagEndChar:this.indentate(r)+`<`+t+n+`>`+i+`</`+t+this.tagEndChar}},Builder.prototype.replaceEntitiesValue=function(e){if(e&&e.length>0&&this.options.processEntities)for(let t=0;t<this.options.entities.length;t++){let n=this.options.entities[t];e=e.replace(n.regex,n.val)}return e};function indentate(e){return this.options.indentBy.repeat(e)}function isAttribute(e){return e.startsWith(this.options.attributeNamePrefix)&&e!==this.options.textNodeName?e.substr(this.attrPrefixLen):!1}const Pt={validate};var SoapClient=class{async performRequest({httpClient:e,url:t,method:n,headers:r,queryParams:i,body:a,customErrorConfigs:o,requestConfig:s}){let c;if(c=typeof s?.envelope==`string`?s.envelope:typeof s?.envelope==`object`?Ft.build(s.envelope):await buildEnvelope(a,s),Pt.validate(c,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);let u,d={"Content-Type":`application/xml`,...r};s?.soapAction&&(d.SOAPAction=s.soapAction);try{u=await e?.request({method:n,url:t,headers:d,queryParams:i,maxRedirects:0,payload:c,requestConfig:s})}catch(e){if(l(e?.response))throw e;u=e.response}let f=It.parse(u.data),p=f.Envelope||f,m=p.Body||p,h=m.Fault;if(h)throw new me({...u,status:500,data:h,message:h.faultstring??h.faultcode??`SOAP Fault`},h.faultstring??`SOAP Fault occurred`);u.data=m;let g=translateCustomError(u,o);if(isFailedStatusCode(g?.status))throw new me(g,g.message);return g}};const Ft=new Builder({attributeNamePrefix:`@_`,ignoreAttributes:!1,suppressBooleanAttributes:!1}),It=new XMLParser({ignoreAttributes:!1,attributeNamePrefix:`_`,removeNSPrefix:!0,numberParseOptions:{leadingZeros:!1,hex:!1}}),buildEnvelope=async(e,t)=>{if(p(t?.envelope)){let e=typeof t.envelope==`string`?t.envelope:Ft.build(t.envelope);if(Pt.validate(e,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return e}let n=await buildSoapEnvelope(t,e),r=Ft.build(n);if(Pt.validate(r,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return r},buildSoapEnvelope=async(e,t)=>{let n=await Promise.all((e?.namespaces||[]).map(async e=>({identifier:await _(e.namespaceIdentifier),namespace:await _(e.namespace)})));n.forEach(({identifier:e,namespace:t})=>{if(l(e)||l(t)||e===``||t===``)throw Error(`Invalid namespace config: both identifier and namespace are required`)});let r=n.reduce((e,{identifier:t,namespace:n})=>(e[`@_xmlns:${t}`]=n,e),{});return{"soapenv:Envelope":{"soapenv:Header":await buildSoapHeaders(t,e??{}),"soapenv:Body":await buildSoapBody(t,e?.soapOperation??``,n[0]?.identifier??``),"@_xmlns:soapenv":`http://schemas.xmlsoap.org/soap/envelope/`,...r}}},buildSoapHeaders=async(e,t)=>[await buildSoapSecurity(e,t)],buildSoapSecurity=async(e,t)=>{if(l(t.soapContext))return{};let{username:n,password:r}=t.soapContext;return{"wsse:Security":{"wsse:UsernameToken":{"wsse:Username":n,"wsse:Password":{"#text":r,"@_Type":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText`}},"@_soapenv:mustUnderstand":`1`,"@_xmlns:wsse":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd`,"@_xmlns:wsu":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd`}}},buildSoapBody=async(e,t,n)=>{if(l(t))throw Error(`Missing soapOperation in config`);let r=expandArrayAttributes({[t]:e});return(Array.isArray(r)?r:[r]).map(e=>applyNamespace(e,n))},expandArrayAttributes=e=>{if(typeof e!=`object`||!e)return e;if(Array.isArray(e)){if(e.length===1){let t=e[0];if(typeof t==`object`&&t&&!Array.isArray(t)){let e=Object.keys(t).filter(e=>!e.startsWith(`@_`));if(e.length===1){let n=e[0],r=t[n];if(typeof r==`object`&&r&&!Array.isArray(r)){let e=Object.keys(r),t=e.filter(e=>e.startsWith(`@_`)),i=e.filter(e=>!e.startsWith(`@_`)),a=t.find(e=>Array.isArray(r[e]));if(a&&i.length===0){let e=r[a],i=t.filter(e=>e!==a),o=e.map(e=>{let t={[a]:e};for(let e of i)t[e]=r[e];return t});return{[n]:o}}}}}}return e.map(e=>expandArrayAttributes(e))}let t={};for(let n of Object.keys(e)){let r=e[n];t[n]=expandArrayAttributes(r)}return t},applyNamespace=(e,t)=>{if(typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>applyNamespace(e,t));let n={};for(let r in e){let i=applyNamespaceToKey(r,t);n[i]=applyNamespace(e[r],t)}return n},applyNamespaceToKey=(e,t)=>{let n=e.split(`:`);return n.length>1&&n[0]||e.indexOf(`${t}:`)===0||e===`#text`?e:e.startsWith(`@_`)?`@_${t}:${e.slice(2)}`:`${t}:${e}`};var RequestClientFactory=class{static build(e=`rest`){if(e===`rest`)return new RestClient;if(e===`soap`)return new SoapClient;throw Error(`Unknown request client type: ${e}`)}};export{pe as CUSTOM_ERROR_CONFIG_SCHEMA,ConcurrencyManager,EventClient,HttpClient,HttpClientManager,fe as HttpErrorMessages,ht as HttpMethods,me as HttpResponseError,HttpTransportFactory,he as InstanceManager,LockManager,MemoryStore,yt as QueryArrayFormats,QueueManager,RateLimitManager,ee as RedisClient,RequestClientFactory,vt as RequestParameterLocations,ScriptManager,SubscriptionManager,buildHttpClientInstance,convertError,createAuthorizationHeaders,getRetryAfterWaitTime,getTransportInstance,getTransportManagers,initializeTransportSystem,isFailedStatusCode,isInfoStatusCode,isSuccessStatusCode,isTransportSystemReady,parseRequestParameters,serializeHttpResponseError,shutdownTransportSystem,superNormalizeHeaders,translateCustomError};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackone/transport",
3
- "version": "2.12.0",
3
+ "version": "2.13.1",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",