@stackone/transport 2.7.2 → 2.8.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.cjs CHANGED
@@ -1,4 +1,4 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let l=require(`@stackone/utils`),u=require(`redis`);u=c(u);let d=require(`@stackone/expressions`),f=require(`axios`);f=c(f);let p=require(`node:https`);p=c(p);let m=require(`crypto`),h=require(`node:timers`),g=require(`jsonpath-plus`),_=require(`@stackone/redaction`),v=require(`qs`);v=c(v);const y=e=>{switch(e.type){case`none`:return{};case`basic`:return b(e);case`bearer`:return x(e);case`oauth2`:return x(e);default:throw Error(`Invalid authentication type`)}},b=({username:e=``,password:t=``,encoding:n=`base64`})=>{let r=n;return{authorization:`Basic ${Buffer.from(`${e}:${t}`).toString(r)}`}},x=({token:e,includeBearer:t})=>({authorization:`${t?`Bearer `:``}${e}`});var S=class{constructor(){this.locks=new Map}async withLock(e,t){await this.lock(e);try{return t()}finally{this.unlock(e)}}async lock(e){let t,n=new Promise(e=>t=e),r=this.locks.has(e),i=this.locks.get(e);r&&i?(i.push({lock:n,unlock:t}),await i[i.length-2].lock):this.locks.set(e,[{lock:n,unlock:t}])}unlock(e){let t=this.locks.has(e),n=this.locks.get(e);if(t&&n&&n.length>0){let e=n.shift()?.unlock;e?.()}this.queueLength(e)===0&&this.locks.delete(e)}queueLength(e){return this.locks.get(e)?.length}close(){this.locks.clear()}};const ee=1e3,te=100,ne=60,C=6e4,w=60,re=C,ie=C*10,ae=100,T=10;let E=function(e){return e.MemoryStorePruneError=`MemoryStorePruneError`,e}({});var oe=class{constructor(e={}){this.lastAccessedAt=Date.now(),this.config=e,this.initialize(e)}initialize(e=this.config){this.instantiator=e?.instantiator??`Unknown`,this.logger=e?.logger,this.dataStore=e?.dataStore??new Map,this.lockManager=e?.lockManager??new S,this.expiryMap=e?.expiryMap??new Map,this.evictionFrequency=e?.evictionFrequency??6e4,this.staleDataThreshold=e?.staleDataThreshold??6e5,this.truncateThreshold=e?.truncateThreshold??100,this.truncationPercentage=e?.truncationPercentage??10,this.typeGuard=e?.typeGuard,this.dispose=e?.dispose,this.startEvictionTask()}async getData(e){return this.isReady()||this.initialize(),this.updateLastAccessedAt(),this.lockManager.withLock(e,async()=>this.dataStore.get(e)??null)}async setData({key:e,value:t,cacheTTL:n=60}){if(this.isReady()||this.initialize(),this.updateLastAccessedAt(),(0,l.notMissing)(this.typeGuard)&&!this.typeGuard(t))return!1;let r=n*1e3,i=Date.now()+r;return await this.lockManager.withLock(e,async()=>{((0,l.notMissing)(this.typeGuard)&&this.typeGuard(t)||(0,l.isMissing)(this.typeGuard)&&this.typeGuardBypass(t))&&this.dataStore.set(e,t),this.expiryMap.set(e,i)}),!0}typeGuardBypass(e){return this.logger?.debug({category:`MemoryStore`,message:`${this.instantiator} MemoryStore setting data without type guard - you should probably configure one`}),!0}async delete(e){return this.isReady()||this.initialize(),this.updateLastAccessedAt(),this.lockManager.withLock(e,async()=>{if(this.dispose){let t=this.dataStore.get(e);await this.dispose(e,t)}return this.dataStore.delete(e)})}async pruneExpiredKeys(){let e=this.dataStore.size,t=e>=this.truncateThreshold;if(e<=0)return;let n=[],r=0;return this.dataStore.forEach(async(e,i)=>{let a=Date.now(),o=this.expiryMap.get(i)??0,s=this.truncateThreshold*this.truncationPercentage/100;(o<=a||t&&r>=0&&r<=s)&&n.push(this.lockManager.withLock(i,async()=>(this.dispose&&await this.dispose(i,e),this.dataStore.delete(i)))),r++}),await Promise.all(n),{dataStoreSize:e,prunedDataStoreSize:this.dataStore.size}}startEvictionTask(){if((0,l.notMissing)(this.evictionInterval))return;let e=async()=>{let t;try{if(this.lastAccessedAt+this.staleDataThreshold<Date.now()){this.logger?.warning({message:`Closing the ${this.instantiator}'s MemoryStore instance - received no requests for a while.`,category:`MemoryStore`}),this.close();return}t=await this.pruneExpiredKeys(),this.evictionInterval=setTimeout(e,this.evictionFrequency)}catch(t){t instanceof Error&&this.logger?.error({message:`Error during pruning expired keys:`,category:`MemoryStore`,error:t,code:E.MemoryStorePruneError}),this.evictionInterval=setTimeout(e,this.evictionFrequency)}finally{if((0,l.notMissing)(t?.dataStoreSize)&&(0,l.notMissing)(t?.prunedDataStoreSize)){let{dataStoreSize:e,prunedDataStoreSize:n}=t,r=e-n;this.logger?.debug({message:`Pruned ${r} expired keys, ${n} remain, scheduling next prune.`,category:`MemoryStore`,context:{instantiator:this.instantiator}})}}};this.evictionInterval=setTimeout(e,this.evictionFrequency)}stopEvictionTask(){this.evictionInterval&&=(clearTimeout(this.evictionInterval),void 0)}updateLastAccessedAt(){this.lastAccessedAt=Date.now()}isReady(){return(0,l.notMissing)(this.evictionInterval)&&(0,l.notMissing)(this.dataStore)&&(0,l.notMissing)(this.expiryMap)&&(0,l.notMissing)(this.lockManager)}close(){this.stopEvictionTask(),this.dataStore.clear(),this.expiryMap.clear(),this.lockManager.close()}async listData({partialKey:e,cursor:t,limit:n}){let r=Array.from(this.dataStore.keys()).filter(t=>t.includes(e)),i=[],a=t?parseInt(t,10):0;for(let e=a;e<n+a;e++){let t=r[e];if(!t)break;let a=await this.getData(t);if(a&&i.push(a),i.length>=n)break}return{items:i,cursor:i.length<n?void 0:(a+n).toString()}}};const se=1e3,ce=6e4;let le=function(e){return e.EventClientResolveError=`EventClientResolveError`,e}({});var ue=class{constructor(e,t,n){this.executorMethodStore=null,this.promiseStore=null,this.eventClientConfig=null,this.executorMethodStoreConfig=null,this.pendingPromiseStoreConfig=null,this.eventClientConfig=e,this.executorMethodStoreConfig=t,this.pendingPromiseStoreConfig=n;let r=e?.instantiator?`${e?.instantiator}(${this.constructor.name})`:this.constructor.name,i={logger:this.logger,dispose:this.defaultExecutorMethodDispose,typeGuard:this.defaultExecutorMethodTypeGuard,...this.executorMethodStoreConfig??{},instantiator:r},a={logger:this.logger,dispose:this.defaultPendingPromiseDispose,typeGuard:this.defaultPendingPromiseTypeGuard,...this.pendingPromiseStoreConfig??{},instantiator:r};this.executorMethodStore=new oe(i),this.promiseStore=new oe(a)}async setPendingEvent(e,t){let n={resolve:void 0,reject:void 0},r=new Promise((e,t)=>{n.resolve=e,n.reject=t}),i=t/1e3;await this.executorMethodStore?.setData({key:e,value:n,cacheTTL:i}),await this.promiseStore?.setData({key:e,value:r,cacheTTL:i})}async waitForEvent(e,t){let n=await this.promiseStore?.getData(e);return(0,l.notMissing)(n)?n:(await this.setPendingEvent(e,t),this.getPendingEvent(e))}async getPendingEvent(e){return this.promiseStore?.getData(e)??null}async deleteEvent(e){return(await Promise.all([this.promiseStore?.delete(e),this.executorMethodStore?.delete(e)])).every(Boolean)}async resolveEvent(e,t){try{let n=await this.executorMethodStore?.getData(e);(0,l.isMissing)(n)&&(await this.setPendingEvent(e,this.eventClientConfig?.defaultTimeoutMS??6e4),n=await this.executorMethodStore?.getData(e)),n?.resolve?.(t)}catch(t){t instanceof Error&&this.logger.error({message:`Error handling event for key ${e}: ${t.message}`,category:this.constructor.name,context:{eventKey:e},error:t,code:le.EventClientResolveError})}}async defaultExecutorMethodDispose(e,t){(0,l.notMissing)(t?.resolve)?t.resolve(this.eventClientConfig?.timeoutResolveValue):(0,l.notMissing)(t?.reject)&&t.reject(Error(`Event key: ${e} was not resolved or the event was disposed`))}defaultExecutorMethodTypeGuard(e){return(0,l.isObject)(e)&&e.hasOwnProperty(`resolve`)&&e.hasOwnProperty(`reject`)}async defaultPendingPromiseDispose(e,t){t instanceof Promise&&t?.finally(()=>{})}defaultPendingPromiseTypeGuard(e){return e instanceof Promise}},de=class{constructor(){this.instance=null,this.initPromise=null,this.retryTimeout=null,this.status=`uninitialized`,this.initOptions=null,this.initArgs=[]}getRetryDelay(){return 5e3}getSingleton(e){throw Error(`getSingleton method not implemented`)}async getInstance(e,...t){return this.instance?this.instance:((0,l.isMissing)(this.initPromise)&&(this.initOptions=e??null,this.initArgs=t,this.initPromise=this.init(e??null,...t)),this.initPromise)}getInstanceIfReady(){return this.instance}isReady(){return this.status===`ready`}hasInitFailed(){return this.status===`failed`}async init(e,...t){try{let n=await this.initInstance(e,...t);return this.instance=n,this.status=`ready`,n}catch(e){throw this.status=`failed`,this.initPromise=null,(0,l.isMissing)(this.retryTimeout)&&(this.retryTimeout=setTimeout(()=>{this.retryTimeout=null,this.getInstance(this.initOptions,...this.initArgs).catch(()=>{})},this.getRetryDelay())),e}}reset(){this.instance=null,this.initPromise=null,this.initOptions=null,this.status=`uninitialized`,this.retryTimeout&&clearTimeout(this.retryTimeout),this.retryTimeout=null}};let D=function(e){return e.RedisClientError=`RedisClientError`,e.RedisClientCommandError=`RedisClientCommandError`,e.RedisClientDeleteError=`RedisClientDeleteError`,e.RedisClientInvalidTTL=`RedisClientInvalidTTL`,e.RedisClientListError=`RedisClientListError`,e.RedisClientNotInitialized=`RedisClientNotInitialized`,e.RedisClientPublishError=`RedisClientPublishError`,e.RedisClientReadError=`RedisClientReadError`,e.RedisClientRedisNotReady=`RedisClientRedisNotReady`,e.RedisClientScriptError=`RedisClientScriptError`,e.RedisClientScriptExecuteError=`RedisClientScriptExecuteError`,e.RedisClientScriptLoadError=`RedisClientScriptLoadError`,e.RedisClientSubscribeError=`RedisClientSubscribeError`,e.RedisClientUnsubscribeError=`RedisClientUnsubscribeError`,e.RedisClientWriteError=`RedisClientWriteError`,e}({});const fe=async(e,t,n)=>{try{return await pe.build(e,t,n)??void 0}catch(e){let r=e;t?.error({message:`Error building Cache Manager`,error:r,code:D.RedisClientError,category:n??`buildRedisClientInstance`});return}};var pe=class e{#e;#t;static async build({getRedisClient:t=u.createClient,host:n,port:r,tls:i,reconnect:a=!0,database:o},s,c){let l=new e;l.#t=s;try{l.#e=t({socket:{reconnectStrategy:a?e=>Math.min(e*20,5e3):!1,host:n,port:r,tls:i},database:o,disableOfflineQueue:!0});let e=he(c??`RedisClient`,l.#t);return me(l.#e,e),await l.#e.connect(),l}catch(e){let t=e;return l.#t?.error({message:`Error building Cache Manager.`,error:t,code:D.RedisClientError,category:c??`RedisClient`}),null}}#n(e){try{return JSON.parse(e)}catch{return e}}async getData(t){if(!this.#i())return null;try{let e=await this.#e.get(t);if(!e)return null;let n=this.#n(e);return(0,l.isString)(n)?e:n}catch(t){let n=t;return this.#t?.error({message:`Error getting data`,error:n,code:D.RedisClientReadError,category:e.name}),null}}async setData({key:t,value:n,cacheTTL:r,groupKey:i}){if(!this.#i())return!1;try{let e=(0,l.isString)(n)?n:JSON.stringify(n);return await this.#e.set(t,e,{EX:r}),(0,l.notMissing)(i)&&await this.#e.sAdd(i,[t]),!0}catch(t){let n=t;return this.#t?.error({message:`Error setting data`,error:n,code:D.RedisClientWriteError,category:e.name}),!1}}async executeScript({sha1:t,keys:n,args:r}){if(!this.#i())return null;try{return await this.#e.evalSha(t,{keys:n,arguments:r})}catch(t){let n=t;return this.#t?.error({message:`Error executing script`,error:n,code:D.RedisClientScriptExecuteError,category:e.name}),null}}async loadScript(t){if(!this.#i())return null;try{return await this.#e.scriptLoad(t)}catch(t){let n=t;return this.#t?.error({message:`Error loading script`,error:n,code:D.RedisClientScriptLoadError,category:e.name}),null}}async#r(t,n,r){if(!this.#i())return null;if(!Number.isFinite(r)||r<=0)return this.#t?.error({message:`Invalid cacheTTL parameter`,category:e.name,code:D.RedisClientInvalidTTL}),null;try{let e=[{args:[t,n]},{args:[`expire`,n,r.toString()]}],i=(await this.#e.multiExecutor(e))?.[0];return typeof i==`number`?i:null}catch(n){let r=n;return this.#t?.error({message:`Error executing ${t} operation`,error:r,code:D.RedisClientCommandError,category:e.name}),null}}async increment(e,t){return this.#r(`incr`,e,t)}async decrement(e,t){return this.#r(`decr`,e,t)}async subscribe(t,n){if(!this.#i())return!1;try{return await this.#e.pSubscribe(t,n),!0}catch(n){let r=n;return this.#t?.error({message:`Error subscribing to ${t}`,error:r,code:D.RedisClientSubscribeError,category:e.name}),!1}}async unsubscribe(t){if(!this.#i())return!1;try{return await this.#e.pUnsubscribe(t),!0}catch(n){let r=n;return this.#t?.error({message:`Error unsubscribing from ${t}`,error:r,code:D.RedisClientUnsubscribeError,category:e.name}),!1}}async publish(t,n){if(!this.#i())return null;try{let r=await this.#e.publish(t,n);return r===0&&this.#t?.debug({message:`No subscribers found for channel ${t}`,category:e.name}),r}catch(n){let r=n;return this.#t?.error({message:`Error publishing to ${t}`,error:r,code:D.RedisClientPublishError,category:e.name}),null}}getClient(){return this.#i()?this.#e:null}#i(){let t=this.#e.isReady&&this.#e.isOpen;return t||this.#t?.error({message:`Redis Client is not ready.`,category:e.name,code:D.RedisClientRedisNotReady}),t}async listData({partialKey:t,limit:n,cursor:r}){try{let e=r?parseInt(r,10):0,i=await this.#e.sScan(t,e,{COUNT:n}),a=[];for(let e of i.members){let t=await this.getData(e);(0,l.notMissing)(t)&&a.push(t)}return{items:a,cursor:i.cursor>0?i.cursor.toString():void 0}}catch(t){let n=t;return this.#t?.error({message:`Error listing data`,error:n,code:D.RedisClientListError,category:e.name}),{items:null}}}async deleteData(t){try{if(!this.#i())return!1;let n=await this.#e.del(t);return n===0&&this.#t?.debug({message:`No keys deleted for ${t}`,category:e.name}),n>0}catch(t){let n=t;return this.#t?.error({message:`Error deleting data`,error:n,code:D.RedisClientDeleteError,category:e.name}),!1}}};const me=(e,t)=>{t.forEach(({eventName:t,listener:n})=>{e.on(t,n)})},he=(e=`RedisClient`,t)=>[{eventName:`error`,listener:n=>{t?.error({message:`Redis client error ${n.message}`,error:n,code:D.RedisClientError,category:e})}},{eventName:`ready`,listener:()=>{t?.info({message:`Redis client ready`,category:e})}},{eventName:`connect`,listener:()=>{t?.info({message:`Redis client connected`,category:e})}},{eventName:`reconnecting`,listener:()=>{t?.info({message:`Redis client reconnecting`,category:e})}},{eventName:`end`,listener:()=>{t?.info({message:`Redis client disconnected`,category:e})}}];let ge=function(e){return e.ScriptManagerExecutionError=`ScriptManagerExecutionError`,e.ScriptManagerLoadingError=`ScriptManagerLoadingError`,e}({});var _e=class extends de{constructor(...e){super(...e),this.isInitialConnection=!0}async initInstance({redisClientConfig:e=this.redisClientConfig,cacheClient:t=this.cacheClient,scripts:n=this.scripts,scriptMap:r=this.scriptMap,logger:i=this.logger,additionalArgs:a=this.additionalArgs}){let o=t??await fe(e,i,this.name);if((0,l.isMissing)(o))throw Error(`Failed to build Redis client`);return this.redisClientConfig=e,this.logger=i,this.cacheClient=o,this.scripts=n,this.scriptMap=r??new Map,this.additionalArgs=a??[],await this.loadScripts(n,r),this.setupReconnectHandler(),await this.additionalInitialization(...a??[]),this}setupReconnectHandler(){let e=this.cacheClient?.getClient?.();(0,l.notMissing)(e)&&(e.on(`ready`,async()=>{this.isInitialConnection?this.isInitialConnection=!1:(this.logger?.info({message:`Redis reconnected - reloading scripts`,category:this.name}),await this.reloadScripts())}),e.on(`end`,()=>{this.logger?.info({message:`Redis connection closed`,category:this.name})}))}async reloadScripts(){(0,l.isMissing)(this.scripts)||Object.keys(this.scripts).length===0||(this.logger?.info({message:`Reloading ${Object.keys(this.scripts).length} scripts after Redis reconnection`,category:this.name}),this.scriptMap.clear(),await this.loadScripts(this.scripts))}async loadScripts(e,t){if((0,l.notMissing)(t))for(let[e,n]of t)this.scriptMap.set(e,n);for(let[t,n]of Object.entries(e)){let e=await this.cacheClient?.loadScript?.(n);(0,l.notMissing)(e)?this.scriptMap?.set(t,e):this.logger?.error({message:`Error loading script ${t}`,category:this.name,code:ge.ScriptManagerLoadingError})}}async executeScript(e,t,n){try{if(!this.isRedisReady())throw Error(`Redis client is not ready`);let r=this.scriptMap?.get(e);if((0,l.isMissing)(r))throw Error(`Script for ${e} not found`);try{return await this.cacheClient?.executeScript?.({sha1:r,keys:t,args:n})??null}catch(i){if(i instanceof Error&&i.message.includes(`NOSCRIPT`)){if(this.logger?.info({message:`Script ${e} not found in Redis, reloading scripts`,category:this.name}),await this.reloadScripts(),r=this.scriptMap?.get(e),(0,l.isMissing)(r))throw Error(`Script for ${e} could not be reloaded`);return await this.cacheClient?.executeScript?.({sha1:r,keys:t,args:n})??null}throw i}}catch(r){throw r instanceof Error&&this.logger?.error({message:`Error executing script ${e}: ${r.message}`,category:this.name,context:{keys:t,args:n},error:r,code:ge.ScriptManagerExecutionError}),r}}isRedisReady(){return this.isReady()&&(0,l.notMissing)(this.cacheClient)}},ve=class{constructor(e){this.options={getCacheClient:fe},this.subscriptionMap=null,this.subscriptionClient=null,this.name=`SubscriptionManager`,this.options={...this.options,...e}}async initialize(e=this.options){let{config:t,getCacheClient:n,logger:r}=e;if(this.logger=r,this.subscriptionMap=new oe({instantiator:`${e?.instantiator}(${this.name})`,evictionFrequency:e?.subscriptionTTL,staleDataThreshold:e?.staleSubscriptionsThreshold,truncateThreshold:e?.truncateThreshold,truncationPercentage:e?.truncationPercentage,typeGuard:e=>typeof e==`string`,dispose:async e=>{await this.subscriptionClient?.unsubscribe?.(e)}}),(0,l.notMissing)(t))this.subscriptionClient=await n?.(t,this.logger,e?.instantiator)??null,this.logger?.info({message:`${this.name} initialized for ${e.instantiator}.`,category:this.name});else throw Error(`SubscriptionManager requires a Redis client configuration.`)}async subscribe(e,t){this.isReady()||await this.initialize(this.options);let n=await this.subscriptionMap?.getData(e),r=(0,l.getContentHash)(t.toString());return await this.subscriptionMap?.setData({key:e,value:r}),n===r?!0:await this.subscriptionClient?.subscribe?.(e,t)??!1}async unsubscribe(e){return this.isReady()||await this.initialize(this.options),this.subscriptionClient?.unsubscribe?.(e)??!1}isReady(){return(0,l.notMissing)(this.subscriptionClient)&&(0,l.notMissing)(this.subscriptionMap)}close(){this.subscriptionMap?.close(),this.subscriptionMap=null,this.subscriptionClient=null}};const ye=6e4,be=15e3,xe=!1,Se=6e4,Ce=15e3,we=1e4,Te=1;let Ee=function(e){return e.QueueManagerInitializationError=`QueueManagerInitializationError`,e.QueueManagerJoinAndWaitTurnError=`QueueManagerJoinAndWaitTurnError`,e.QueueManagerLengthError=`QueueManagerLengthError`,e.QueueManagerPopError=`QueueManagerPopError`,e}({}),O=function(e){return e.rPush=`rPush`,e.lPush=`lPush`,e.lPop=`lPop`,e.llen=`llen`,e}({});var k=class extends _e{constructor(...e){super(...e),this.subscriptionManager=null,this.eventClient=null,this.name=`QueueManager`}async additionalInitialization(){if((0,l.isMissing)(this.redisClientConfig))throw Error(`Redis client configuration is required to initialize QueueManager.`);this.subscriptionManager=new ve({config:this.redisClientConfig,instantiator:this.name,subscriptionTTL:6e4,truncateThreshold:we,truncationPercentage:1}),await this.subscriptionManager?.initialize(),this.eventClient=new ue({instantiator:this.name,timeoutResolveValue:!1},{instantiator:this.name,evictionFrequency:Ce,truncateThreshold:we,truncationPercentage:1},{instantiator:this.name,evictionFrequency:Ce,truncateThreshold:we,truncationPercentage:1}),this.logger?.info({category:this.name,message:`QueueManager initialized.`})}async joinAndWaitTurn(e,t,n,r,i=!0){try{let a=`${e}:${t}`;await this.subscriptionManager?.subscribe(a,async(n,r)=>{if(r.includes(a)&&r.includes(t)){let t=`${e}:${n}`;return this.eventClient?.resolveEvent(t,!0)}});let o=await this.executeScript(n?O.lPush:O.rPush,[e],[t,`60000`])===1;return(!i||!o)&&await this.eventClient?.waitForEvent(a,15e3),await this.eventClient?.deleteEvent(a),await r(e,t)}catch(n){throw n instanceof Error&&this.logger?.error({message:`Error in joinAndWaitTurn`,category:this.name,error:n,code:Ee.QueueManagerJoinAndWaitTurnError,context:{queueName:e,value:t}}),n}}async pop(e){try{return await this.executeScript(O.lPop,[e],[])}catch(t){throw t instanceof Error&&this.logger?.error({message:`Error in pop`,category:this.name,error:t,code:Ee.QueueManagerPopError,context:{queueName:e}}),t}}async length(e){try{return await this.executeScript(O.llen,[e],[])}catch(t){throw t instanceof Error&&this.logger?.error({message:`Error in length`,category:this.name,error:t,code:Ee.QueueManagerLengthError,context:{queueName:e}}),t}}isReady(){return(0,l.notMissing)(this.subscriptionManager)&&(0,l.notMissing)(this.cacheClient)&&(0,l.notMissing)(this.scriptMap)&&this.scriptMap.size>0}close(){this.subscriptionManager?.close(),this.scriptMap?.clear()}};const De=5,Oe=12e4,ke=1e4,Ae=1,je=60,Me=90,Ne=`__keyevent@0__:`,Pe=`${Ne}set`,Fe=`${Ne}expire`,Ie=`${Ne}expired`,Le=`${Ne}srem`,Re=`config_check_test_key`,ze=[Pe,Fe,Ie],Be=1,Ve=2e4,He={mainMaxConcurrency:30};let Ue=function(e){return e.ConcurrencyManagerInitializationError=`ConcurrencyManagerInitializationError`,e.ConcurrencyManagerRedisEventsEmitError=`ConcurrencyManagerRedisEventsEmitError`,e.ConcurrencyManagerRegistrationFailed=`ConcurrencyManagerRegistrationFailed`,e}({}),We=function(e){return e.tryConcurrency=`tryConcurrency`,e.removeFromSet=`removeFromSet`,e.publishNextItem=`publishNextItem`,e}({});const Ge={[We.tryConcurrency]:`
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let l=require(`@stackone/utils`),u=require(`redis`);u=c(u);let d=require(`@stackone/expressions`),f=require(`axios`);f=c(f);let p=require(`node:https`);p=c(p);let m=require(`crypto`),h=require(`node:timers`),g=require(`jsonpath-plus`),_=require(`@stackone/redaction`),v=require(`qs`);v=c(v);const y=e=>{switch(e.type){case`none`:return{};case`basic`:return b(e);case`bearer`:return x(e);case`oauth2`:return x(e);default:throw Error(`Invalid authentication type`)}},b=({username:e=``,password:t=``,encoding:n=`base64`})=>{let r=n;return{authorization:`Basic ${Buffer.from(`${e}:${t}`).toString(r)}`}},x=({token:e,includeBearer:t})=>({authorization:`${t?`Bearer `:``}${e}`});var S=class{constructor(){this.locks=new Map}async withLock(e,t){await this.lock(e);try{return t()}finally{this.unlock(e)}}async lock(e){let t,n=new Promise(e=>t=e),r=this.locks.has(e),i=this.locks.get(e);r&&i?(i.push({lock:n,unlock:t}),await i[i.length-2].lock):this.locks.set(e,[{lock:n,unlock:t}])}unlock(e){let t=this.locks.has(e),n=this.locks.get(e);if(t&&n&&n.length>0){let e=n.shift()?.unlock;e?.()}this.queueLength(e)===0&&this.locks.delete(e)}queueLength(e){return this.locks.get(e)?.length}close(){this.locks.clear()}};const ee=1e3,te=100,ne=60,C=6e4,w=60,re=C,ie=C*10,ae=100,T=10;let E=function(e){return e.MemoryStorePruneError=`MemoryStorePruneError`,e}({});var oe=class{constructor(e={}){this.lastAccessedAt=Date.now(),this.config=e,this.initialize(e)}initialize(e=this.config){this.instantiator=e?.instantiator??`Unknown`,this.logger=e?.logger,this.dataStore=e?.dataStore??new Map,this.lockManager=e?.lockManager??new S,this.expiryMap=e?.expiryMap??new Map,this.evictionFrequency=e?.evictionFrequency??6e4,this.staleDataThreshold=e?.staleDataThreshold??6e5,this.truncateThreshold=e?.truncateThreshold??100,this.truncationPercentage=e?.truncationPercentage??10,this.typeGuard=e?.typeGuard,this.dispose=e?.dispose,this.startEvictionTask()}async getData(e){return this.isReady()||this.initialize(),this.updateLastAccessedAt(),this.lockManager.withLock(e,async()=>this.dataStore.get(e)??null)}async setData({key:e,value:t,cacheTTL:n=60}){if(this.isReady()||this.initialize(),this.updateLastAccessedAt(),(0,l.notMissing)(this.typeGuard)&&!this.typeGuard(t))return!1;let r=n*1e3,i=Date.now()+r;return await this.lockManager.withLock(e,async()=>{((0,l.notMissing)(this.typeGuard)&&this.typeGuard(t)||(0,l.isMissing)(this.typeGuard)&&this.typeGuardBypass(t))&&this.dataStore.set(e,t),this.expiryMap.set(e,i)}),!0}typeGuardBypass(e){return this.logger?.debug({category:`MemoryStore`,message:`${this.instantiator} MemoryStore setting data without type guard - you should probably configure one`}),!0}async delete(e){return this.isReady()||this.initialize(),this.updateLastAccessedAt(),this.lockManager.withLock(e,async()=>{if(this.dispose){let t=this.dataStore.get(e);await this.dispose(e,t)}return this.dataStore.delete(e)})}async pruneExpiredKeys(){let e=this.dataStore.size,t=e>=this.truncateThreshold;if(e<=0)return;let n=[],r=0;return this.dataStore.forEach(async(e,i)=>{let a=Date.now(),o=this.expiryMap.get(i)??0,s=this.truncateThreshold*this.truncationPercentage/100;(o<=a||t&&r>=0&&r<=s)&&n.push(this.lockManager.withLock(i,async()=>(this.dispose&&await this.dispose(i,e),this.dataStore.delete(i)))),r++}),await Promise.all(n),{dataStoreSize:e,prunedDataStoreSize:this.dataStore.size}}startEvictionTask(){if((0,l.notMissing)(this.evictionInterval))return;let e=async()=>{let t;try{if(this.lastAccessedAt+this.staleDataThreshold<Date.now()){this.logger?.warning({message:`Closing the ${this.instantiator}'s MemoryStore instance - received no requests for a while.`,category:`MemoryStore`}),this.close();return}t=await this.pruneExpiredKeys(),this.evictionInterval=setTimeout(e,this.evictionFrequency)}catch(t){t instanceof Error&&this.logger?.error({message:`Error during pruning expired keys:`,category:`MemoryStore`,error:t,code:E.MemoryStorePruneError}),this.evictionInterval=setTimeout(e,this.evictionFrequency)}finally{if((0,l.notMissing)(t?.dataStoreSize)&&(0,l.notMissing)(t?.prunedDataStoreSize)){let{dataStoreSize:e,prunedDataStoreSize:n}=t,r=e-n;this.logger?.debug({message:`Pruned ${r} expired keys, ${n} remain, scheduling next prune.`,category:`MemoryStore`,context:{instantiator:this.instantiator}})}}};this.evictionInterval=setTimeout(e,this.evictionFrequency)}stopEvictionTask(){this.evictionInterval&&=(clearTimeout(this.evictionInterval),void 0)}updateLastAccessedAt(){this.lastAccessedAt=Date.now()}isReady(){return(0,l.notMissing)(this.evictionInterval)&&(0,l.notMissing)(this.dataStore)&&(0,l.notMissing)(this.expiryMap)&&(0,l.notMissing)(this.lockManager)}close(){this.stopEvictionTask(),this.dataStore.clear(),this.expiryMap.clear(),this.lockManager.close()}async listData({partialKey:e,cursor:t,limit:n}){let r=Array.from(this.dataStore.keys()).filter(t=>t.includes(e)),i=[],a=t?parseInt(t,10):0;for(let e=a;e<n+a;e++){let t=r[e];if(!t)break;let a=await this.getData(t);if(a&&i.push(a),i.length>=n)break}return{items:i,cursor:i.length<n?void 0:(a+n).toString()}}};const se=1e3,ce=6e4;let le=function(e){return e.EventClientResolveError=`EventClientResolveError`,e}({});var ue=class{constructor(e,t,n){this.executorMethodStore=null,this.promiseStore=null,this.eventClientConfig=null,this.executorMethodStoreConfig=null,this.pendingPromiseStoreConfig=null,this.eventClientConfig=e,this.executorMethodStoreConfig=t,this.pendingPromiseStoreConfig=n;let r=e?.instantiator?`${e?.instantiator}(${this.constructor.name})`:this.constructor.name,i={logger:this.logger,dispose:this.defaultExecutorMethodDispose,typeGuard:this.defaultExecutorMethodTypeGuard,...this.executorMethodStoreConfig??{},instantiator:r},a={logger:this.logger,dispose:this.defaultPendingPromiseDispose,typeGuard:this.defaultPendingPromiseTypeGuard,...this.pendingPromiseStoreConfig??{},instantiator:r};this.executorMethodStore=new oe(i),this.promiseStore=new oe(a)}async setPendingEvent(e,t){let n={resolve:void 0,reject:void 0},r=new Promise((e,t)=>{n.resolve=e,n.reject=t}),i=t/1e3;await this.executorMethodStore?.setData({key:e,value:n,cacheTTL:i}),await this.promiseStore?.setData({key:e,value:r,cacheTTL:i})}async waitForEvent(e,t){let n=await this.promiseStore?.getData(e);return(0,l.notMissing)(n)?n:(await this.setPendingEvent(e,t),this.getPendingEvent(e))}async getPendingEvent(e){return this.promiseStore?.getData(e)??null}async deleteEvent(e){return(await Promise.all([this.promiseStore?.delete(e),this.executorMethodStore?.delete(e)])).every(Boolean)}async resolveEvent(e,t){try{let n=await this.executorMethodStore?.getData(e);(0,l.isMissing)(n)&&(await this.setPendingEvent(e,this.eventClientConfig?.defaultTimeoutMS??6e4),n=await this.executorMethodStore?.getData(e)),n?.resolve?.(t)}catch(t){t instanceof Error&&this.logger.error({message:`Error handling event for key ${e}: ${t.message}`,category:this.constructor.name,context:{eventKey:e},error:t,code:le.EventClientResolveError})}}async defaultExecutorMethodDispose(e,t){(0,l.notMissing)(t?.resolve)?t.resolve(this.eventClientConfig?.timeoutResolveValue):(0,l.notMissing)(t?.reject)&&t.reject(Error(`Event key: ${e} was not resolved or the event was disposed`))}defaultExecutorMethodTypeGuard(e){return(0,l.isObject)(e)&&e.hasOwnProperty(`resolve`)&&e.hasOwnProperty(`reject`)}async defaultPendingPromiseDispose(e,t){t instanceof Promise&&t?.finally(()=>{})}defaultPendingPromiseTypeGuard(e){return e instanceof Promise}},de=class{constructor(){this.instance=null,this.initPromise=null,this.retryTimeout=null,this.status=`uninitialized`,this.initOptions=null,this.initArgs=[]}getRetryDelay(){return 5e3}getSingleton(e){throw Error(`getSingleton method not implemented`)}async getInstance(e,...t){return this.instance?this.instance:((0,l.isMissing)(this.initPromise)&&(this.initOptions=e??null,this.initArgs=t,this.initPromise=this.init(e??null,...t)),this.initPromise)}getInstanceIfReady(){return this.instance}isReady(){return this.status===`ready`}hasInitFailed(){return this.status===`failed`}async init(e,...t){try{let n=await this.initInstance(e,...t);return this.instance=n,this.status=`ready`,n}catch(e){throw this.status=`failed`,this.initPromise=null,(0,l.isMissing)(this.retryTimeout)&&(this.retryTimeout=setTimeout(()=>{this.retryTimeout=null,this.getInstance(this.initOptions,...this.initArgs).catch(()=>{})},this.getRetryDelay())),e}}reset(){this.instance=null,this.initPromise=null,this.initOptions=null,this.status=`uninitialized`,this.retryTimeout&&clearTimeout(this.retryTimeout),this.retryTimeout=null}};let D=function(e){return e.RedisClientError=`RedisClientError`,e.RedisClientCommandError=`RedisClientCommandError`,e.RedisClientDeleteError=`RedisClientDeleteError`,e.RedisClientInvalidTTL=`RedisClientInvalidTTL`,e.RedisClientListError=`RedisClientListError`,e.RedisClientNotInitialized=`RedisClientNotInitialized`,e.RedisClientPublishError=`RedisClientPublishError`,e.RedisClientReadError=`RedisClientReadError`,e.RedisClientRedisNotReady=`RedisClientRedisNotReady`,e.RedisClientScriptError=`RedisClientScriptError`,e.RedisClientScriptExecuteError=`RedisClientScriptExecuteError`,e.RedisClientScriptLoadError=`RedisClientScriptLoadError`,e.RedisClientSubscribeError=`RedisClientSubscribeError`,e.RedisClientUnsubscribeError=`RedisClientUnsubscribeError`,e.RedisClientWriteError=`RedisClientWriteError`,e}({});const fe=async(e,t,n)=>{try{return await pe.build(e,t,n)??void 0}catch(e){let r=e;t?.error({message:`Error building Cache Manager`,error:r,code:D.RedisClientError,category:n??`buildRedisClientInstance`});return}};var pe=class e{#e;#t;static async build({getRedisClient:t=u.createClient,host:n,port:r,tls:i,reconnect:a=!0,database:o},s,c){let l=new e;l.#t=s;try{l.#e=t({socket:{reconnectStrategy:a?e=>Math.min(e*20,5e3):!1,host:n,port:r,tls:i},database:o,disableOfflineQueue:!0});let e=he(c??`RedisClient`,l.#t);return me(l.#e,e),await l.#e.connect(),l}catch(e){let t=e;return l.#t?.error({message:`Error building Cache Manager.`,error:t,code:D.RedisClientError,category:c??`RedisClient`}),null}}#n(e){try{return JSON.parse(e)}catch{return e}}async getData(t){if(!this.#i())return null;try{let e=await this.#e.get(t);if(!e)return null;let n=this.#n(e);return(0,l.isString)(n)?e:n}catch(t){let n=t;return this.#t?.error({message:`Error getting data`,error:n,code:D.RedisClientReadError,category:e.name}),null}}async setData({key:t,value:n,cacheTTL:r,groupKey:i}){if(!this.#i())return!1;try{let e=(0,l.isString)(n)?n:JSON.stringify(n);return await this.#e.set(t,e,{EX:r}),(0,l.notMissing)(i)&&await this.#e.sAdd(i,[t]),!0}catch(t){let n=t;return this.#t?.error({message:`Error setting data`,error:n,code:D.RedisClientWriteError,category:e.name}),!1}}async executeScript({sha1:t,keys:n,args:r}){if(!this.#i())return null;try{return await this.#e.evalSha(t,{keys:n,arguments:r})}catch(t){let n=t;return this.#t?.error({message:`Error executing script`,error:n,code:D.RedisClientScriptExecuteError,category:e.name}),null}}async loadScript(t){if(!this.#i())return null;try{return await this.#e.scriptLoad(t)}catch(t){let n=t;return this.#t?.error({message:`Error loading script`,error:n,code:D.RedisClientScriptLoadError,category:e.name}),null}}async#r(t,n,r){if(!this.#i())return null;if(!Number.isFinite(r)||r<=0)return this.#t?.error({message:`Invalid cacheTTL parameter`,category:e.name,code:D.RedisClientInvalidTTL}),null;try{let e=[{args:[t,n]},{args:[`expire`,n,r.toString()]}],i=(await this.#e.multiExecutor(e))?.[0];return typeof i==`number`?i:null}catch(n){let r=n;return this.#t?.error({message:`Error executing ${t} operation`,error:r,code:D.RedisClientCommandError,category:e.name}),null}}async increment(e,t){return this.#r(`incr`,e,t)}async decrement(e,t){return this.#r(`decr`,e,t)}async subscribe(t,n){if(!this.#i())return!1;try{return await this.#e.pSubscribe(t,n),!0}catch(n){let r=n;return this.#t?.error({message:`Error subscribing to ${t}`,error:r,code:D.RedisClientSubscribeError,category:e.name}),!1}}async unsubscribe(t){if(!this.#i())return!1;try{return await this.#e.pUnsubscribe(t),!0}catch(n){let r=n;return this.#t?.error({message:`Error unsubscribing from ${t}`,error:r,code:D.RedisClientUnsubscribeError,category:e.name}),!1}}async publish(t,n){if(!this.#i())return null;try{let r=await this.#e.publish(t,n);return r===0&&this.#t?.debug({message:`No subscribers found for channel ${t}`,category:e.name}),r}catch(n){let r=n;return this.#t?.error({message:`Error publishing to ${t}`,error:r,code:D.RedisClientPublishError,category:e.name}),null}}getClient(){return this.#i()?this.#e:null}#i(){let t=this.#e.isReady&&this.#e.isOpen;return t||this.#t?.error({message:`Redis Client is not ready.`,category:e.name,code:D.RedisClientRedisNotReady}),t}async listData({partialKey:t,limit:n,cursor:r}){try{let e=r?parseInt(r,10):0,i=await this.#e.sScan(t,e,{COUNT:n}),a=[];for(let e of i.members){let t=await this.getData(e);(0,l.notMissing)(t)&&a.push(t)}return{items:a,cursor:i.cursor>0?i.cursor.toString():void 0}}catch(t){let n=t;return this.#t?.error({message:`Error listing data`,error:n,code:D.RedisClientListError,category:e.name}),{items:null}}}async deleteData(t){try{if(!this.#i())return!1;let n=await this.#e.del(t);return n===0&&this.#t?.debug({message:`No keys deleted for ${t}`,category:e.name}),n>0}catch(t){let n=t;return this.#t?.error({message:`Error deleting data`,error:n,code:D.RedisClientDeleteError,category:e.name}),!1}}};const me=(e,t)=>{t.forEach(({eventName:t,listener:n})=>{e.on(t,n)})},he=(e=`RedisClient`,t)=>[{eventName:`error`,listener:n=>{t?.error({message:`Redis client error ${n.message}`,error:n,code:D.RedisClientError,category:e})}},{eventName:`ready`,listener:()=>{t?.info({message:`Redis client ready`,category:e})}},{eventName:`connect`,listener:()=>{t?.info({message:`Redis client connected`,category:e})}},{eventName:`reconnecting`,listener:()=>{t?.info({message:`Redis client reconnecting`,category:e})}},{eventName:`end`,listener:()=>{t?.info({message:`Redis client disconnected`,category:e})}}];let ge=function(e){return e.ScriptManagerExecutionError=`ScriptManagerExecutionError`,e.ScriptManagerLoadingError=`ScriptManagerLoadingError`,e.ScriptManagerReconnectionError=`ScriptManagerReconnectionError`,e}({});var _e=class extends de{constructor(...e){super(...e),this.isInitialConnection=!0}async initInstance({redisClientConfig:e=this.redisClientConfig,cacheClient:t=this.cacheClient,scripts:n=this.scripts,scriptMap:r=this.scriptMap,logger:i=this.logger,additionalArgs:a=this.additionalArgs}){let o=t??await fe(e,i,this.name);if((0,l.isMissing)(o))throw Error(`Failed to build Redis client`);return this.redisClientConfig=e,this.logger=i,this.cacheClient=o,this.scripts=n,this.scriptMap=r??new Map,this.additionalArgs=a??[],await this.loadScripts(n,r),this.setupReconnectHandler(),await this.additionalInitialization(...a??[]),this}setupReconnectHandler(){let e=this.cacheClient?.getClient?.();(0,l.notMissing)(e)&&(e.on(`ready`,async()=>{this.isInitialConnection?this.isInitialConnection=!1:(this.logger?.info({message:`Redis reconnected - reloading scripts`,category:this.name}),await this.reloadScripts())}),e.on(`end`,()=>{this.logger?.info({message:`Redis connection closed`,category:this.name})}))}async reloadScripts(){(0,l.isMissing)(this.scripts)||Object.keys(this.scripts).length===0||(this.logger?.info({message:`Reloading ${Object.keys(this.scripts).length} scripts after Redis reconnection`,category:this.name}),this.scriptMap.clear(),await this.loadScripts(this.scripts))}async loadScripts(e,t){if((0,l.notMissing)(t))for(let[e,n]of t)this.scriptMap.set(e,n);for(let[t,n]of Object.entries(e)){let e=await this.cacheClient?.loadScript?.(n);(0,l.notMissing)(e)?this.scriptMap?.set(t,e):this.logger?.error({message:`Error loading script ${t}`,category:this.name,code:ge.ScriptManagerLoadingError})}}async executeScript(e,t,n){try{if(!this.isRedisReady()){let e=this.cacheClient?.getClient?.();if((0,l.notMissing)(e)&&!e.isOpen){this.logger?.info({message:`Redis client is closed, attempting to reconnect`,category:this.name});try{e.isOpen||await e.connect(),await this.reloadScripts()}catch(t){if(e.isOpen)this.logger?.info({message:`Redis client reconnected during connect attempt`,category:this.name}),await this.reloadScripts();else throw t instanceof Error&&this.logger?.error({message:`Failed to reconnect to Redis: ${t.message}`,category:this.name,error:t,code:ge.ScriptManagerReconnectionError}),Error(`Redis reconnection failed: ${t instanceof Error?t.message:`Unknown error`}`)}}if(!this.isRedisReady())throw Error(`Redis client is not ready`)}let r=this.scriptMap?.get(e);if((0,l.isMissing)(r))throw Error(`Script for ${e} not found`);try{return await this.cacheClient?.executeScript?.({sha1:r,keys:t,args:n})??null}catch(i){if(i instanceof Error&&i.message.includes(`NOSCRIPT`)){if(this.logger?.info({message:`Script ${e} not found in Redis, reloading scripts`,category:this.name}),await this.reloadScripts(),r=this.scriptMap?.get(e),(0,l.isMissing)(r))throw Error(`Script for ${e} could not be reloaded`);return await this.cacheClient?.executeScript?.({sha1:r,keys:t,args:n})??null}throw i}}catch(r){throw r instanceof Error&&this.logger?.error({message:`Error executing script ${e}: ${r.message}`,category:this.name,context:{keys:t,args:n},error:r,code:ge.ScriptManagerExecutionError}),r}}isRedisReady(){let e=this.cacheClient?.getClient?.();if((0,l.notMissing)(this.cacheClient)&&(0,l.isMissing)(e))return this.logger?.warning({message:`Cache client exists but getClient() returned null - cannot verify Redis readiness`,category:this.name}),!1;let t=e?.isReady&&e?.isOpen;return this.isReady()&&(0,l.notMissing)(this.cacheClient)&&(t??!1)}},ve=class{constructor(e){this.options={getCacheClient:fe},this.subscriptionMap=null,this.subscriptionClient=null,this.name=`SubscriptionManager`,this.options={...this.options,...e}}async initialize(e=this.options){let{config:t,getCacheClient:n,logger:r}=e;if(this.logger=r,this.subscriptionMap=new oe({instantiator:`${e?.instantiator}(${this.name})`,evictionFrequency:e?.subscriptionTTL,staleDataThreshold:e?.staleSubscriptionsThreshold,truncateThreshold:e?.truncateThreshold,truncationPercentage:e?.truncationPercentage,typeGuard:e=>typeof e==`string`,dispose:async e=>{await this.subscriptionClient?.unsubscribe?.(e)}}),(0,l.notMissing)(t))this.subscriptionClient=await n?.(t,this.logger,e?.instantiator)??null,this.logger?.info({message:`${this.name} initialized for ${e.instantiator}.`,category:this.name});else throw Error(`SubscriptionManager requires a Redis client configuration.`)}async subscribe(e,t){this.isReady()||await this.initialize(this.options);let n=await this.subscriptionMap?.getData(e),r=(0,l.getContentHash)(t.toString());return await this.subscriptionMap?.setData({key:e,value:r}),n===r?!0:await this.subscriptionClient?.subscribe?.(e,t)??!1}async unsubscribe(e){return this.isReady()||await this.initialize(this.options),this.subscriptionClient?.unsubscribe?.(e)??!1}isReady(){return(0,l.notMissing)(this.subscriptionClient)&&(0,l.notMissing)(this.subscriptionMap)}close(){this.subscriptionMap?.close(),this.subscriptionMap=null,this.subscriptionClient=null}};const ye=6e4,be=15e3,xe=!1,Se=6e4,Ce=15e3,we=1e4,Te=1;let Ee=function(e){return e.QueueManagerInitializationError=`QueueManagerInitializationError`,e.QueueManagerJoinAndWaitTurnError=`QueueManagerJoinAndWaitTurnError`,e.QueueManagerLengthError=`QueueManagerLengthError`,e.QueueManagerPopError=`QueueManagerPopError`,e}({}),O=function(e){return e.rPush=`rPush`,e.lPush=`lPush`,e.lPop=`lPop`,e.llen=`llen`,e}({});var k=class extends _e{constructor(...e){super(...e),this.subscriptionManager=null,this.eventClient=null,this.name=`QueueManager`}async additionalInitialization(){if((0,l.isMissing)(this.redisClientConfig))throw Error(`Redis client configuration is required to initialize QueueManager.`);this.subscriptionManager=new ve({config:this.redisClientConfig,instantiator:this.name,subscriptionTTL:6e4,truncateThreshold:we,truncationPercentage:1}),await this.subscriptionManager?.initialize(),this.eventClient=new ue({instantiator:this.name,timeoutResolveValue:!1},{instantiator:this.name,evictionFrequency:Ce,truncateThreshold:we,truncationPercentage:1},{instantiator:this.name,evictionFrequency:Ce,truncateThreshold:we,truncationPercentage:1}),this.logger?.info({category:this.name,message:`QueueManager initialized.`})}async joinAndWaitTurn(e,t,n,r,i=!0){try{let a=`${e}:${t}`;await this.subscriptionManager?.subscribe(a,async(n,r)=>{if(r.includes(a)&&r.includes(t)){let t=`${e}:${n}`;return this.eventClient?.resolveEvent(t,!0)}});let o=await this.executeScript(n?O.lPush:O.rPush,[e],[t,`60000`])===1;return(!i||!o)&&await this.eventClient?.waitForEvent(a,15e3),await this.eventClient?.deleteEvent(a),await r(e,t)}catch(n){throw n instanceof Error&&this.logger?.error({message:`Error in joinAndWaitTurn`,category:this.name,error:n,code:Ee.QueueManagerJoinAndWaitTurnError,context:{queueName:e,value:t}}),n}}async pop(e){try{return await this.executeScript(O.lPop,[e],[])}catch(t){throw t instanceof Error&&this.logger?.error({message:`Error in pop`,category:this.name,error:t,code:Ee.QueueManagerPopError,context:{queueName:e}}),t}}async length(e){try{return await this.executeScript(O.llen,[e],[])}catch(t){throw t instanceof Error&&this.logger?.error({message:`Error in length`,category:this.name,error:t,code:Ee.QueueManagerLengthError,context:{queueName:e}}),t}}isReady(){return(0,l.notMissing)(this.subscriptionManager)&&(0,l.notMissing)(this.cacheClient)&&(0,l.notMissing)(this.scriptMap)&&this.scriptMap.size>0}close(){this.subscriptionManager?.close(),this.scriptMap?.clear()}};const De=5,Oe=12e4,ke=1e4,Ae=1,je=60,Me=90,Ne=`__keyevent@0__:`,Pe=`${Ne}set`,Fe=`${Ne}expire`,Ie=`${Ne}expired`,Le=`${Ne}srem`,Re=`config_check_test_key`,ze=[Pe,Fe,Ie],Be=1,Ve=2e4,He={mainMaxConcurrency:30};let Ue=function(e){return e.ConcurrencyManagerInitializationError=`ConcurrencyManagerInitializationError`,e.ConcurrencyManagerRedisEventsEmitError=`ConcurrencyManagerRedisEventsEmitError`,e.ConcurrencyManagerRegistrationFailed=`ConcurrencyManagerRegistrationFailed`,e}({}),We=function(e){return e.tryConcurrency=`tryConcurrency`,e.removeFromSet=`removeFromSet`,e.publishNextItem=`publishNextItem`,e}({});const Ge={[We.tryConcurrency]:`
2
2
  local requestId = KEYS[1]
3
3
  local targetKey = KEYS[2]
4
4
  local queueKey = KEYS[3]
@@ -122,7 +122,7 @@ var Or=9e15,kr=1e9,Ar=`0123456789abcdef`,jr=`2.302585092994045684017991454684364
122
122
  * Copyright (c) 2023, Robert Eisele (robert@raw.org)
123
123
  * Dual licensed under the MIT or GPL Version 2 licenses.
124
124
  **/
125
- (function(n){"use strict";var r=2e3,i={s:1,n:0,d:1};function a(e,t){if(isNaN(e=parseInt(e,10)))throw h();return e*t}function o(e,t){if(t===0)throw m();var n=Object.create(p.prototype);n.s=e<0?-1:1,e=e<0?-e:e;var r=f(e,t);return n.n=e/r,n.d=t/r,n}function s(e){for(var t={},n=e,r=2,i=4;i<=n;){for(;n%r===0;)n/=r,t[r]=(t[r]||0)+1;i+=1+2*r++}return n===e?t[e]=(t[e]||0)+1:n>1&&(t[n]=(t[n]||0)+1),t}var c=function(e,t){var n=0,r=1,o=1,s=0,c=0,l=0,u=1,d=1,f=0,p=1,_=1,v=1,y=1e7,b;if(e!=null)if(t!==void 0){if(n=e,r=t,o=n*r,n%1!=0||r%1!=0)throw g()}else switch(typeof e){case`object`:if(`d`in e&&`n`in e)n=e.n,r=e.d,`s`in e&&(n*=e.s);else if(0 in e)n=e[0],1 in e&&(r=e[1]);else throw h();o=n*r;break;case`number`:if(e<0&&(o=e,e=-e),e%1==0)n=e;else if(e>0){for(e>=1&&(d=10**Math.floor(1+Math.log(e)/Math.LN10),e/=d);p<=y&&v<=y;)if(b=(f+_)/(p+v),e===b){p+v<=y?(n=f+_,r=p+v):v>p?(n=_,r=v):(n=f,r=p);break}else e>b?(f+=_,p+=v):(_+=f,v+=p),p>y?(n=_,r=v):(n=f,r=p);n*=d}else (isNaN(e)||isNaN(t))&&(r=n=NaN);break;case`string`:if(p=e.match(/\d+|./g),p===null)throw h();if(p[f]===`-`?(o=-1,f++):p[f]===`+`&&f++,p.length===f+1?c=a(p[f++],o):p[f+1]===`.`||p[f]===`.`?(p[f]!==`.`&&(s=a(p[f++],o)),f++,(f+1===p.length||p[f+1]===`(`&&p[f+3]===`)`||p[f+1]===`'`&&p[f+3]===`'`)&&(c=a(p[f],o),u=10**p[f].length,f++),(p[f]===`(`&&p[f+2]===`)`||p[f]===`'`&&p[f+2]===`'`)&&(l=a(p[f+1],o),d=10**p[f+1].length-1,f+=3)):p[f+1]===`/`||p[f+1]===`:`?(c=a(p[f],o),u=a(p[f+2],1),f+=3):p[f+3]===`/`&&p[f+1]===` `&&(s=a(p[f],o),c=a(p[f+2],o),u=a(p[f+4],1),f+=5),p.length<=f){r=u*d,o=n=l+r*s+d*c;break}default:throw h()}if(r===0)throw m();i.s=o<0?-1:1,i.n=Math.abs(n),i.d=Math.abs(r)};function l(e,t,n){for(var r=1;t>0;e=e*e%n,t>>=1)t&1&&(r=r*e%n);return r}function u(e,t){for(;t%2==0;t/=2);for(;t%5==0;t/=5);if(t===1)return 0;for(var n=10%t,i=1;n!==1;i++)if(n=n*10%t,i>r)return 0;return i}function d(e,t,n){for(var r=1,i=l(10,n,t),a=0;a<300;a++){if(r===i)return a;r=r*10%t,i=i*10%t}return 0}function f(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function p(e,t){if(c(e,t),this instanceof p)e=f(i.d,i.n),this.s=i.s,this.n=i.n/e,this.d=i.d/e;else return o(i.s*i.n,i.d)}var m=function(){return Error(`Division by Zero`)},h=function(){return Error(`Invalid argument`)},g=function(){return Error(`Parameters must be integer`)};p.prototype={s:1,n:0,d:1,abs:function(){return o(this.n,this.d)},neg:function(){return o(-this.s*this.n,this.d)},add:function(e,t){return c(e,t),o(this.s*this.n*i.d+i.s*this.d*i.n,this.d*i.d)},sub:function(e,t){return c(e,t),o(this.s*this.n*i.d-i.s*this.d*i.n,this.d*i.d)},mul:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.n,this.d*i.d)},div:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.d,this.d*i.n)},clone:function(){return o(this.s*this.n,this.d)},mod:function(e,t){if(isNaN(this.n)||isNaN(this.d))return new p(NaN);if(e===void 0)return o(this.s*this.n%this.d,1);if(c(e,t),i.n===0&&this.d===0)throw m();return o(this.s*(i.d*this.n)%(i.n*this.d),i.d*this.d)},gcd:function(e,t){return c(e,t),o(f(i.n,this.n)*f(i.d,this.d),i.d*this.d)},lcm:function(e,t){return c(e,t),i.n===0&&this.n===0?o(0,1):o(i.n*this.n,f(i.n,this.n)*f(i.d,this.d))},ceil:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.ceil(e*this.s*this.n/this.d),e)},floor:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.floor(e*this.s*this.n/this.d),e)},round:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.round(e*this.s*this.n/this.d),e)},inverse:function(){return o(this.s*this.d,this.n)},pow:function(e,t){if(c(e,t),i.d===1)return i.s<0?o((this.s*this.d)**+i.n,this.n**+i.n):o((this.s*this.n)**+i.n,this.d**+i.n);if(this.s<0)return null;var n=s(this.n),r=s(this.d),a=1,l=1;for(var u in n)if(u!==`1`){if(u===`0`){a=0;break}if(n[u]*=i.n,n[u]%i.d===0)n[u]/=i.d;else return null;a*=u**+n[u]}for(var u in r)if(u!==`1`){if(r[u]*=i.n,r[u]%i.d===0)r[u]/=i.d;else return null;l*=u**+r[u]}return i.s<0?o(l,a):o(a,l)},equals:function(e,t){return c(e,t),this.s*this.n*i.d===i.s*i.n*this.d},compare:function(e,t){c(e,t);var n=this.s*this.n*i.d-i.s*i.n*this.d;return(0<n)-(n<0)},simplify:function(e){if(isNaN(this.n)||isNaN(this.d))return this;e||=.001;for(var t=this.abs(),n=t.toContinued(),r=1;r<n.length;r++){for(var i=o(n[r-1],1),a=r-2;a>=0;a--)i=i.inverse().add(n[a]);if(Math.abs(i.sub(t).valueOf())<e)return i.mul(this.s)}return this},divisible:function(e,t){return c(e,t),!(!(i.n*this.d)||this.n*i.d%(i.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,n+=` `,r%=i),n+=r,n+=`/`,n+=i),n},toLatex:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,r%=i),n+=`\\frac{`,n+=r,n+=`}{`,n+=i,n+=`}`),n},toContinued:function(){var e,t=this.n,n=this.d,r=[];if(isNaN(t)||isNaN(n))return r;do r.push(Math.floor(t/n)),e=t%n,t=n,n=e;while(t!==1);return r},toString:function(e){var t=this.n,n=this.d;if(isNaN(t)||isNaN(n))return`NaN`;e||=15;var r=u(t,n),i=d(t,n,r),a=this.s<0?`-`:``;if(a+=t/n|0,t%=n,t*=10,t&&(a+=`.`),r){for(var o=i;o--;)a+=t/n|0,t%=n,t*=10;a+=`(`;for(var o=r;o--;)a+=t/n|0,t%=n,t*=10;a+=`)`}else for(var o=e;t&&o--;)a+=t/n|0,t%=n,t*=10;return a}},typeof e==`object`?(Object.defineProperty(p,`__esModule`,{value:!0}),p.default=p,p.Fraction=p,t.exports=p):n.Fraction=p})(e)})),_a=c(ga(),1),va=`Fraction`,ya=[],ba=or(va,ya,()=>(Object.defineProperty(_a.default,`name`,{value:`Fraction`}),_a.default.prototype.constructor=_a.default,_a.default.prototype.type=`Fraction`,_a.default.prototype.isFraction=!0,_a.default.prototype.toJSON=function(){return{mathjs:`Fraction`,n:this.s*this.n,d:this.d}},_a.default.fromJSON=function(e){return new _a.default(e)},_a.default),{isClass:!0}),xa=`Matrix`,Sa=[],Ca=or(xa,Sa,()=>{function e(){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`)}return e.prototype.type=`Matrix`,e.prototype.isMatrix=!0,e.prototype.storage=function(){throw Error(`Cannot invoke storage on a Matrix interface`)},e.prototype.datatype=function(){throw Error(`Cannot invoke datatype on a Matrix interface`)},e.prototype.create=function(e,t){throw Error(`Cannot invoke create on a Matrix interface`)},e.prototype.subset=function(e,t,n){throw Error(`Cannot invoke subset on a Matrix interface`)},e.prototype.get=function(e){throw Error(`Cannot invoke get on a Matrix interface`)},e.prototype.set=function(e,t,n){throw Error(`Cannot invoke set on a Matrix interface`)},e.prototype.resize=function(e,t){throw Error(`Cannot invoke resize on a Matrix interface`)},e.prototype.reshape=function(e,t){throw Error(`Cannot invoke reshape on a Matrix interface`)},e.prototype.clone=function(){throw Error(`Cannot invoke clone on a Matrix interface`)},e.prototype.size=function(){throw Error(`Cannot invoke size on a Matrix interface`)},e.prototype.map=function(e,t){throw Error(`Cannot invoke map on a Matrix interface`)},e.prototype.forEach=function(e){throw Error(`Cannot invoke forEach on a Matrix interface`)},e.prototype[Symbol.iterator]=function(){throw Error(`Cannot iterate a Matrix interface`)},e.prototype.toArray=function(){throw Error(`Cannot invoke toArray on a Matrix interface`)},e.prototype.valueOf=function(){throw Error(`Cannot invoke valueOf on a Matrix interface`)},e.prototype.format=function(e){throw Error(`Cannot invoke format on a Matrix interface`)},e.prototype.toString=function(){throw Error(`Cannot invoke toString on a Matrix interface`)},e},{isClass:!0});function wa(e){return Object.keys(e.signatures||{}).reduce(function(e,t){var n=(t.match(/,/g)||[]).length+1;return Math.max(e,n)},-1)}var Ta=`DenseMatrix`,Ea=[`Matrix`],Da=or(Ta,Ea,e=>{var{Matrix:t}=e;function n(e,t){if(!(this instanceof n))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!Et(t))throw Error(`Invalid datatype: `+t);if(Dt(e))e.type===`DenseMatrix`?(this._data=sn(e._data),this._size=sn(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&M(e.data)&&M(e.size))this._data=e.data,this._size=e.size,Hn(this._data,this._size),this._datatype=t||e.datatype;else if(M(e))this._data=l(e),this._size=Bn(this._data),Hn(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+on(e)+`)`);else this._data=[],this._size=[0],this._datatype=t}n.prototype=new t,n.prototype.createDenseMatrix=function(e,t){return new n(e,t)},Object.defineProperty(n,`name`,{value:`DenseMatrix`}),n.prototype.constructor=n,n.prototype.type=`DenseMatrix`,n.prototype.isDenseMatrix=!0,n.prototype.getDataType=function(){return Qn(this._data,on)},n.prototype.storage=function(){return`dense`},n.prototype.datatype=function(){return this._datatype},n.prototype.create=function(e,t){return new n(e,t)},n.prototype.subset=function(e,t,n){switch(arguments.length){case 1:return r(this,e);case 2:case 3:return a(this,e,t,n);default:throw SyntaxError(`Wrong number of arguments`)}},n.prototype.get=function(e){if(!M(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new P(e.length,this._size.length);for(var t=0;t<e.length;t++)F(e[t],this._size[t]);for(var n=this._data,r=0,i=e.length;r<i;r++){var a=e[r];F(a,n.length),n=n[a]}return n},n.prototype.set=function(e,t,n){if(!M(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new P(e.length,this._size.length,`<`);var r,i,a,o=e.map(function(e){return e+1});c(this,o,n);var s=this._data;for(r=0,i=e.length-1;r<i;r++)a=e[r],F(a,s.length),s=s[a];return a=e[e.length-1],F(a,s.length),s[a]=t,this};function r(e,t){if(!Mt(t))throw TypeError(`Invalid index`);if(t.isScalar())return e.get(t.min());var r=t.size();if(r.length!==e._size.length)throw new P(r.length,e._size.length);for(var a=t.min(),o=t.max(),s=0,c=e._size.length;s<c;s++)F(a[s],e._size[s]),F(o[s],e._size[s]);return new n(i(e._data,t,r.length,0),e._datatype)}function i(e,t,n,r){var a=r===n-1,o=t.dimension(r);return a?o.map(function(t){return F(t,e.length),e[t]}).valueOf():o.map(function(a){F(a,e.length);var o=e[a];return i(o,t,n,r+1)}).valueOf()}function a(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Invalid index`);var i=t.size(),a=t.isScalar(),s;if(Dt(n)?(s=n.size(),n=n.valueOf()):s=Bn(n),a){if(s.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!ln(s,i))try{n=s.length===0?rr([n],i):rr(n,i),s=Bn(n)}catch{}if(i.length<e._size.length)throw new P(i.length,e._size.length,`<`);if(s.length<i.length){for(var l=0,u=0;i[l]===1&&s[l]===1;)l++;for(;i[l]===1;)u++,l++;n=Yn(n,i.length,u,s)}if(!ln(i,s))throw new P(i,s,`>`);c(e,t.max().map(function(e){return e+1}),r);var d=i.length;o(e._data,t,n,d,0)}return e}function o(e,t,n,r,i){var a=i===r-1,s=t.dimension(i);a?s.forEach(function(t,r){F(t),e[t]=n[r[0]]}):s.forEach(function(a,s){F(a),o(e[a],t,n[s[0]],r,i+1)})}n.prototype.resize=function(e,t,n){if(!Ot(e))throw TypeError(`Array or Matrix expected`);var r=e.valueOf().map(e=>Array.isArray(e)&&e.length===1?e[0]:e);return s(n?this.clone():this,r,t)};function s(e,t,n){if(t.length===0){for(var r=e._data;M(r);)r=r[0];return r}return e._size=t.slice(0),e._data=Un(e._data,e._size,n),e}n.prototype.reshape=function(e,t){var n=t?this.clone():this;return n._data=Gn(n._data,e),n._size=Kn(e,n._size.reduce((e,t)=>e*t)),n};function c(e,t,n){for(var r=e._size.slice(0),i=!1;r.length<t.length;)r.push(0),i=!0;for(var a=0,o=t.length;a<o;a++)t[a]>r[a]&&(r[a]=t[a],i=!0);i&&s(e,r,n)}n.prototype.clone=function(){return new n({data:sn(this._data),size:sn(this._size),datatype:this._datatype})},n.prototype.size=function(){return this._size.slice(0)},n.prototype.map=function(e){var t=this,r=wa(e),i=function n(i,a){return M(i)?i.map(function(e,t){return n(e,a.concat(t))}):r===1?e(i):r===2?e(i,a):e(i,a,t)}(this._data,[]);return new n(i,this._datatype===void 0?void 0:Qn(i,on))},n.prototype.forEach=function(e){var t=this;(function n(r,i){M(r)?r.forEach(function(e,t){n(e,i.concat(t))}):e(r,i,t)})(this._data,[])},n.prototype[Symbol.iterator]=function*(){yield*function*e(t,n){if(M(t))for(var r=0;r<t.length;r++)yield*e(t[r],n.concat(r));else yield{value:t,index:n}}(this._data,[])},n.prototype.rows=function(){var e=[];if(this.size().length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var t of this._data)e.push(new n([t],this._datatype));return e},n.prototype.columns=function(){var e=this,t=[],r=this.size();if(r.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var i=this._data,a=function(r){var a=i.map(e=>[e[r]]);t.push(new n(a,e._datatype))},o=0;o<r[1];o++)a(o);return t},n.prototype.toArray=function(){return sn(this._data)},n.prototype.valueOf=function(){return this._data},n.prototype.format=function(e){return Nn(this._data,e)},n.prototype.toString=function(){return Nn(this._data)},n.prototype.toJSON=function(){return{mathjs:`DenseMatrix`,data:this._data,size:this._size,datatype:this._datatype}},n.prototype.diagonal=function(e){if(e){if(j(e)&&(e=e.toNumber()),!A(e)||!N(e))throw TypeError(`The parameter k must be an integer number`)}else e=0;for(var t=e>0?e:0,r=e<0?-e:0,i=this._size[0],a=this._size[1],o=Math.min(i-r,a-t),s=[],c=0;c<o;c++)s[c]=this._data[c+r][c+t];return new n({data:s,size:[o],datatype:this._datatype})},n.diagonal=function(e,t,r,i){if(!M(e))throw TypeError(`Array expected, size parameter`);if(e.length!==2)throw Error(`Only two dimensions matrix are supported`);if(e=e.map(function(e){if(j(e)&&(e=e.toNumber()),!A(e)||!N(e)||e<1)throw Error(`Size values must be positive integers`);return e}),r){if(j(r)&&(r=r.toNumber()),!A(r)||!N(r))throw TypeError(`The parameter k must be an integer number`)}else r=0;var a=r>0?r:0,o=r<0?-r:0,s=e[0],c=e[1],l=Math.min(s-o,c-a),u;if(M(t)){if(t.length!==l)throw Error(`Invalid value array length`);u=function(e){return t[e]}}else if(Dt(t)){var d=t.size();if(d.length!==1||d[0]!==l)throw Error(`Invalid matrix length`);u=function(e){return t.get([e])}}else u=function(){return t};i||=j(u(0))?u(0).mul(0):0;var f=[];if(e.length>0){f=Un(f,e,i);for(var p=0;p<l;p++)f[p+o][p+a]=u(p)}return new n({data:f,size:[s,c]})},n.fromJSON=function(e){return new n(e)},n.prototype.swapRows=function(e,t){if(!A(e)||!N(e)||!A(t)||!N(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return F(e,this._size[0]),F(t,this._size[0]),n._swapRows(e,t,this._data),this},n._swapRows=function(e,t,n){var r=n[e];n[e]=n[t],n[t]=r};function l(e){return Dt(e)?l(e.valueOf()):M(e)?e.map(l):e}return n},{isClass:!0});function Oa(e,t,n){return e&&typeof e.map==`function`?e.map(function(e){return Oa(e,t,n)}):t(e)}var ka=`isNumeric`,Aa=[`typed`],ja=or(ka,Aa,e=>{var{typed:t}=e;return t(ka,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>Oa(t,e))})}),Ma=`hasNumericValue`,Na=[`typed`,`isNumeric`],Pa=or(Ma,Na,e=>{var{typed:t,isNumeric:n}=e;return t(Ma,{boolean:()=>!0,string:function(e){return e.trim().length>0&&!isNaN(Number(e))},any:function(e){return n(e)}})}),Fa=oa({config:hn}),Ia=ha({}),La=ba({}),Ra=Ca({}),za=Da({Matrix:Ra}),Ba=Cr({BigNumber:Fa,Complex:Ia,DenseMatrix:za,Fraction:La}),Va=ja({typed:Ba}),Ha=Pa({isNumeric:Va,typed:Ba});const Ua=e=>{let t=Number(e);return Number.isNaN(t)?!1:t>=120&&t<=36e4},Wa=e=>{let t=Number(e),n=Date.now();return Number.isNaN(t)?n+1e3:!Ua(t)&&(0,l.isFutureUnixTimestamp)(t)?bt(t):Ua(t)?n+t:n+t*_t},Ga=`ratelimitlimit`,Ka=`ratelimitremaining`,qa=`ratelimitreset`,Ja=`ratelimitconcurrencylimit`,Ya=`ratelimitconcurrencyremaining`,Xa=`ratelimitconcurrencyreset`,Za=e=>{let t={};for(let[n,r]of Object.entries(e)){let e=n.toLowerCase().replace(/^x-/,``).replace(/concurren.+-/g,`concurrency-`).replace(/-/g,``);t[e]=Ha(r)?Number(r):null}return t},Qa=e=>{let t=Za(e);return{rateLimitLimit:t.ratelimitlimit,rateLimitRemaining:t.ratelimitremaining,rateLimitReset:Wa(t.ratelimitreset),concurrencyLimit:t.ratelimitconcurrencylimit,concurrencyRemaining:t.ratelimitconcurrencyremaining,concurrencyReset:Wa(t.ratelimitconcurrencyreset)}},$a=e=>{let{accountSecureId:t,service:n,resource:r,subResource:i,childResource:a,action:o,behaviours:s}=e??{};return[t,n,r,o].some(l.isMissing)?null:[t,n,r,i,a,o,...s??[]].filter(Boolean).join(`-`)},eo=(e,t=10,n=1)=>{let r=Date.now();return(0,l.isFutureUnixTimestamp)(e)||(0,l.isNumber)(e)?to(Number(e),r,t,n):Et(e)&&e!==``?no(e,r,t,n):n},to=(e,t,n=10,r=1)=>{if(e<n)return e;let i=bt(e);if(i>t){let e=Math.floor((i-t)/_t);return e>0&&e<n?e:r}return r},no=(e,t,n=10,r=1)=>{if(vt.test(e)){let t=parseFloat(e);return t>0&&t<n?t:r}let i=new Date(e);if(Number.isNaN(i.getTime()))return r;let a=i.getTime();if(a>t){let e=Math.floor((a-t)/_t);return e>0&&e<n?e:r}return r},ro=({axiosInstance:e,logger:t,requestConfig:n,context:r})=>async i=>{let{response:a,config:o}=i;if(o?.signal?.aborted)return Promise.reject(lt(`Request aborted`,o,`ERR_CANCELED`,a));let{status:s,retryAfter:c}=io(a,r,n,t);if(s===429&&(0,l.notMissing)(o)){let n=eo(c);if(o._retryCount>=5)return t?.warning({category:`http-transport`,message:`Max retries exceeded for ${o?.url}. Aborting.`,context:{...r??{},retryAfterHeader:c,retryAfterAsNumber:n}}),Promise.reject(i);let s=o._retryCount??0,u={...o,_retryCount:s+1},d=c?n*_t:(0,l.exponentialBackoffInMS)(u._retryCount);return t?.debug({category:`http-transport`,message:`Received 429 error from ${o?.url}`,context:{...r??{},retryAfterHeader:c,calculatedRetryAfter:d}}),await ut(d,o,a),e?.request(u)}return Promise.reject(i)},io=(e,t,n,r)=>{let{provider:i}=t??{},{status:a,headers:o,data:s}=e??{},{retryafter:c}=Za(o??{});if((0,l.isMissing)(i)||(0,l.isMissing)(e))return r?.warning({category:`http-transport`,message:`Invalid parameters for convertError`,context:{...t,responseIsMissing:(0,l.isMissing)(e),providerIsMissing:(0,l.isMissing)(i),status:e?.status??`undefined`,statusText:e?.statusText??`undefined`,retryafter:c??`undefined`}}),{status:a,retryAfter:c};let u=n?.rateLimits?.mappedRateLimitErrors;if((0,l.notMissing)(u)&&(0,l.notMissing)(s))for(let e of u){let{errorStatus:t,errorMessagePath:n,errorMessage:r,retryAfterPath:i,retryAfterUnit:u,retryAfterValue:d}=e;if(t!==a)continue;let f=n??`message`,p=ao((0,l.isObject)(s)?(0,g.JSONPath)({path:f,json:s})[0]:s,r);if(t===a&&p){let e=so(d??oo(o,i),u);return{status:429,retryAfter:c??e}}}return{status:a,retryAfter:c}},ao=(e,t)=>t instanceof RegExp?t.test(e??``):e?.includes(t)??!1,oo=(e,t)=>(0,l.notMissing)(t)&&(0,l.notMissing)(e)?(0,g.JSONPath)({path:t,json:e})[0]:null,so=(e,t=`seconds`)=>(0,l.notMissing)(e)?co(e,t):null,co=(e,t)=>{if(t===`seconds`)return typeof e==`string`?parseFloat(e):e;if(t===`milliseconds`)return(typeof e==`string`?parseFloat(e):e)/_t;if(t===`date`){let t=typeof e==`string`&&!isNaN(Number(e))?parseFloat(e):e,n=new Date(t);if(isNaN(n.getTime()))throw Error(`Invalid date value`);return n.getTime()}throw Error(`Invalid type`)},lo=`rateLimitErrorInterceptor`,uo=({axiosInstance:e,logger:t,requestConfig:n,context:r,concurrencyManager:i})=>async a=>{let{response:o,config:s}=a,c=s?.signal;if((0,l.isMissing)(r)||(0,l.isMissing)(s))return t?.warning({category:`HttpClient`,message:`No context or config for this response - that doesn't seem right.`,context:{interceptor:lo,...s,httpsAgent:void 0,headers:void 0,hasContext:(0,l.notMissing)(r),hasConfig:(0,l.notMissing)(s)},code:ct.InterceptorContextNotPresent}),Promise.reject(a);if((0,l.isMissing)(i))return t?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:lo,...s,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:(0,l.notMissing)(i)},code:ct.RateLimitOrConcurrencyManagerNotInitialized}),Promise.reject(a);let{requestId:u,targetConcurrencyKey:d,leaseSubscription:f,setRemovalSubscription:p}=s?.requestMetadata??{};if(!((0,l.notMissing)(u)&&(0,l.notMissing)(d)&&await i.releaseRequest(u,d))&&(0,l.notMissing)(s?.requestMetadata)&&t?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{...r,interceptor:lo,requestId:u,targetConcurrencyKey:d,leaseSubscription:f,setRemovalSubscription:p},code:ct.RateLimiterReleaseRequestFailed}),c?.aborted)return Promise.reject(lt(`Request aborted`,s,`ERR_CANCELED`,o));let{status:m,retryAfter:h}=io(o,r,n,t);if(m===429&&(0,l.notMissing)(s)){let n=eo(h);if(s._retryCount>=5)return t?.warning({category:`HttpClient`,message:`Max retries exceeded for ${s.url}. Aborting.`,context:{...r??{},...s.requestMetadata??{},retryAfterHeader:h,retryAfterAsNumber:n}}),Promise.reject(a);let i=s?._retryCount??0,c={...s,_retryCount:i+1},u=h?n*_t:(0,l.exponentialBackoffInMS)(c._retryCount);return t?.debug({category:`HttpClient`,message:`Received 429 error from ${s.url}`,context:{...r,retryAfterHeader:h,calculatedRetryAfter:u}}),await ut(u,s,o),e?.request(c)}return Promise.reject(a)},fo=`rateLimitResponseInterceptor`,po=({logger:e,context:t,concurrencyManager:n})=>async r=>{let i=r?.config,a=i?.signal;if((0,l.isMissing)(t))e?.warning({category:`HttpClient`,message:`No context for this response - that doesn't seem right.`,context:{interceptor:fo,...i,httpsAgent:void 0,headers:void 0}});else if((0,l.isMissing)(n))return e?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:fo,...i,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:(0,l.notMissing)(n)},code:ct.RateLimitOrConcurrencyManagerNotInitialized}),r;else if((0,l.notMissing)(t.provider)&&(0,l.notMissing)(t.accountSecureId)){let t=r?.headers;if((0,l.notMissing)(t)){let n=Qa(t);e?.debug({category:`HttpClient`,message:`Rate limit headers extracted`,context:{interceptor:fo,rateLimitHeaders:n}})}let{requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:u}=i?.requestMetadata??{};if(await n.releaseRequest(o,s)||e?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{interceptor:fo,requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:u},code:ct.RateLimiterReleaseRequestFailed}),a?.aborted)return Promise.reject(lt(`Request aborted`,i,`ERR_CANCELED`,r))}return r},mo=e=>(e.validateStatus??=e=>e>=200&&e<300,e),ho=[{onFulfilled:mo,onRejected:null,options:void 0}],go=[{onFulfilled:null,onRejected:ro},{onFulfilled:null,onRejected:it}],_o=[{onFulfilled:mo,onRejected:null,options:void 0},{onFulfilled:ft,onRejected:null,options:void 0}],vo=[{onFulfilled:po,onRejected:uo},{onFulfilled:null,onRejected:it}],yo=1,bo=1e3,xo=0,So=59,Co=.8,wo=500;var To=class extends _e{constructor(...e){super(...e),this.name=`RateLimitManager`}async additionalInitialization(){}getDynamicMaxWaitTime(e,t,n,r=59,i=.8,a=500){this.readyCheck();let o=e.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.rateLimit??e.mainRatelimit;if(o<=0)throw Error(`Requests per second (rps) must be greater than 0.`);let s=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.maxConcurrency??t.mainMaxConcurrency;if(s<=0)throw Error(`Concurrency must be greater than 0.`);let c=r*i,l=1/Math.min(o,s/(a/1e3)),u=Math.max(7.5,c*l);return Math.min(c,u)}async getWaitTime(e,t,n){this.readyCheck();let r=`rateLimit:${e}`,i=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.subPoolKey,a=(0,l.notMissing)(i)?`${r}-${i}`:r,{mainRatelimit:o,subPools:s}=t,c=[{key:r,rateLimit:o},...s?.map(e=>{let{subPoolKey:t,rateLimit:n}=e;return{key:`${r}-${t}`,rateLimit:n}})??[]],u=c.map(e=>e.key),d=c.map(e=>e.rateLimit);return await this.executeScript(st.incr,[a,...u],[o.toString(),...d.map(String)])??0}readyCheck(){if(!this.cacheClient||!this.scriptMap?.size)throw Error(`RateLimitManager not ready`)}isReady(){return!!this?.cacheClient&&!!this?.scriptMap?.size}close(){this.scriptMap?.clear(),this.reset()}},Z=class{static{this.instances=new Map}static async prepare(e,t,...n){if(!this.instances.has(e)){let t=new e;t.getSingleton=e=>{let t=this.instances.get(e);if((0,l.isMissing)(t))throw Error(`Singleton ${e.name} not prepared yet`);if(t.hasInitFailed?.())throw Error(`${e.name} initialization failed`);let n=t.getInstanceIfReady?.();if((0,l.notMissing)(n))return n;throw Error(`${e.name} not ready`)},this.instances.set(e,t)}let r=this.instances.get(e);try{return await r.getInstance(t,...n)}catch(t){throw r.hasInitFailed?.()&&this.instances.delete(e),t}}static getIfReady(e){return this.instances.get(e)?.getInstanceIfReady?.()??null}static reset(e){this.instances.get(e)?.reset?.(),this.instances.delete(e)}static cleanupFailed(){let e=0;for(let[t,n]of this.instances){let r=n;r?.hasInitFailed?.()&&(r?.reset?.(),this.instances.delete(t),e++)}return e}};let Eo=function(e){return e.HttpTransportInstanceCreateError=`HttpTransportInstanceCreateError`,e}({});const Do=async({logger:e,redisClientConfig:t,context:n,requestConfig:r,httpsAgentConfig:i}={})=>{let a,{NODE_ENV:o}=process.env,s=n?.behaviours??[`CONCURRENCY`,`RETRY`];try{if(a=s.includes(`RETRY`)?ko(e,n):Oo(e,n),(0,l.isMissing)(n?.service)||(0,l.isMissing)(n?.organizationId)||o===`test`||(0,l.isMissing)(t)||(0,l.isMissing)(e))return a;let c=Z.getIfReady(To)??void 0,u=Z.getIfReady(Ke)??void 0,d=c?.isReady(),f=u?.isRedisConfigured(),p=[],m=[];if(s.includes(`CONCURRENCY`)){if(!f)throw Error(`Concurrency Manager cannot connect to Redis. Cannot create advanced transport instance.`);if(!d)throw Error(`RateLimitManager is not ready. Cannot create advanced transport instance.`);p.push(..._o),m.push(...vo)}let h=$a(n);if((0,l.isMissing)(h))return e?.warning({category:`http-transport`,message:`Unable to create a key for transport instance - Invalid state. Using base default instance.`,context:{...n,defaultInstanceInitialized:(0,l.notMissing)(a)}}),a;let g=await rt.get(h);if((0,l.notMissing)(g))return g;let _={interceptors:{requestConfigs:p,responseConfigs:m},instanceConfig:{maxBodyLength:1/0},logger:e,context:n,requestConfig:r,httpsAgentConfig:i,concurrencyManager:u,rateLimitManager:c},v=et.createInstance(_);return e?.debug({category:`http-transport`,message:`Creating new Axios instance and caching it for key: [${h}]`,context:{...n}}),await rt.set(h,v),v}catch(t){return e?.error({category:`http-transport`,message:`Failed to create advanced transport instance. Using default instance.`,context:{...n,usingDefaultInstance:(0,l.notMissing)(a)},error:t,code:Eo.HttpTransportInstanceCreateError}),(0,l.notMissing)(a)?a:Ao()}},Oo=(e,t)=>{let n={instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return et.createInstance(n)??Ao()},ko=(e,t)=>{let n={interceptors:{requestConfigs:ho,responseConfigs:go},instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return et.createInstance(n)??Ao()},Ao=()=>f.default.create({maxBodyLength:1/0});var jo=class{#e;#t;#n;#r;#i;#a;constructor({transportFactory:e=Do,getRedisClient:t=fe,logger:n,redisClientConfig:r,errorMappingFn:i}={}){this.name=`HttpClient`,this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}#o({url:e,payload:t,method:n,context:r}){if(!r?.accountSecureId||r.accountSecureId.length<20||!e||!n)return null;let i=t?(0,l.getContentHash)(t):``;return`${r.accountSecureId}-${n.toUpperCase()}${i}-${e}`}async#s({url:e,payload:t,method:n,cacheTTL:r,context:i}){if(!this.#a||!r||r<=0)return null;let a=this.#o({url:e,payload:t,method:n,context:i});if(!a)return null;let o=await this.#a.getData(a);return o?(this.#n?.debug({category:this.name,message:`Cache hit for key [${a}].`}),o):(this.#n?.debug({category:this.name,message:`Cache miss for key [${a}].`}),null)}async#c({url:e,payload:t,method:n,cacheTTL:r,context:i,response:a}){if(!this.#a||!r||r<=0)return!1;let o=this.#o({url:e,payload:t,method:n,context:i});return o?(this.#n?.debug({category:this.name,message:`Caching result for key [${o}].`}),this.#a.setData({key:o,value:a,cacheTTL:r*60})):!1}async request({headers:e={},url:t,method:n=`get`,queryParams:r,maxRedirects:i=0,responseType:a,cacheTTL:o,context:s,traceId:c,payload:u,httpsAgent:d,httpAgent:f,requestConfig:p,httpsAgentConfig:m}){try{(0,l.notMissing)(this.#r)&&(0,l.isMissing)(this.#a)&&(this.#a=await this.#t(this.#r,this.#n,`HttpClient`));let h=this.#_(t,r),g=this.#l(e),_=this.#m(u,e),v=await this.#s({url:h,payload:_,method:n,cacheTTL:o,context:s});if(v)return{...v,responseTime:new Date};let y=nt.getInstance(),b=((0,l.notMissing)(c)?await y.get(c):null)?.signal,x=await(await this.#e({redisClientConfig:this.#r,logger:this.#n,context:s,requestConfig:p,httpsAgentConfig:m})).request({headers:g,url:h,method:n,maxRedirects:i,responseType:a,data:_,httpsAgent:d,httpAgent:f,signal:b}),S={data:x.data,status:x.status,body:_,method:n,headers:this.#u(x.headers),requestUrl:t,responseType:x?.config?.responseType,responseTime:new Date};return await this.#c({url:h,payload:_,method:n,cacheTTL:o,context:s,response:S}),S}catch(e){let r=e;r.url=(0,_.redactUrl)(t),this.#n?.warning({category:this.name,message:`Request error [${n?.toUpperCase()} ${r.url}]: ${r.message}.`,error:r});let i=this.#h(r);throw(0,l.notMissing)(i)?i:e}}async get({headers:e,url:t,queryParams:n,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s}){return this.request({url:t,method:`get`,queryParams:n,headers:e,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s})}async post({headers:e,url:t,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s}){return this.request({url:t,method:`post`,headers:e,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s})}#l(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n.toLowerCase()]=e[n]||``}),t}#u(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n]=e[n]||``}),t}#d(e){return e[`content-type`]===`application/x-www-form-urlencoded`}#f(e){return e[`content-type`]?.startsWith(`multipart/form-data`)??!1}#p(e){return(0,l.isMissing)(e)||typeof e!=`object`||!e?!1:`pipe`in e&&typeof e.pipe==`function`}#m(e,t){if(!((0,l.isMissing)(e)||(0,l.isObject)(e)&&Object.keys(e).length===0))return this.#f(t)||this.#p(e)?e:this.#d(t)?v.default.stringify(e):e}#h(e){if((0,f.isAxiosError)(e)&&this.#i)return this.#i(e)}#g(e){return typeof e==`object`&&!!e&&`value`in e&&(typeof e.value==`string`||Array.isArray(e.value))}#_(e,t){if((0,l.isMissing)(t)||Object.keys(t).length===0)return e;let n={},r={},i={},a={};for(let[e,o]of Object.entries(t))if(this.#g(o)){let t=o.arrayFormat,s=o.value;t===`repeat`?r[e]=Array.isArray(s)?s:[s]:t===`brackets`?i[e]=Array.isArray(s)?s:[s]:t===`comma`?a[e]=Array.isArray(s)?s:[s]:n[e]=s}else n[e]=o;let o=[];Object.keys(n).length>0&&o.push(v.default.stringify(n)),Object.keys(r).length>0&&o.push(v.default.stringify(r,{arrayFormat:`repeat`})),Object.keys(i).length>0&&o.push(v.default.stringify(i,{arrayFormat:`brackets`})),Object.keys(a).length>0&&o.push(v.default.stringify(a,{arrayFormat:`comma`}));let s=o.join(`&`);return(0,l.notMissing)(s)?`${e}?${s}`:e}};const Mo=(e,t,n)=>new jo({redisClientConfig:e,logger:t,errorMappingFn:n});var No=class{static{this.httpClientInstance=null}static async getInstance({redisClientConfig:e,logger:t,errorMappingFn:n,getHttpClient:r=Mo}){return this.httpClientInstance??=r(e,t,n),this.httpClientInstance}static resetInstance(){this.httpClientInstance=null}};const Po=[`get`,`post`,`put`,`delete`,`patch`],Fo={[O.rPush]:`
125
+ (function(n){"use strict";var r=2e3,i={s:1,n:0,d:1};function a(e,t){if(isNaN(e=parseInt(e,10)))throw h();return e*t}function o(e,t){if(t===0)throw m();var n=Object.create(p.prototype);n.s=e<0?-1:1,e=e<0?-e:e;var r=f(e,t);return n.n=e/r,n.d=t/r,n}function s(e){for(var t={},n=e,r=2,i=4;i<=n;){for(;n%r===0;)n/=r,t[r]=(t[r]||0)+1;i+=1+2*r++}return n===e?t[e]=(t[e]||0)+1:n>1&&(t[n]=(t[n]||0)+1),t}var c=function(e,t){var n=0,r=1,o=1,s=0,c=0,l=0,u=1,d=1,f=0,p=1,_=1,v=1,y=1e7,b;if(e!=null)if(t!==void 0){if(n=e,r=t,o=n*r,n%1!=0||r%1!=0)throw g()}else switch(typeof e){case`object`:if(`d`in e&&`n`in e)n=e.n,r=e.d,`s`in e&&(n*=e.s);else if(0 in e)n=e[0],1 in e&&(r=e[1]);else throw h();o=n*r;break;case`number`:if(e<0&&(o=e,e=-e),e%1==0)n=e;else if(e>0){for(e>=1&&(d=10**Math.floor(1+Math.log(e)/Math.LN10),e/=d);p<=y&&v<=y;)if(b=(f+_)/(p+v),e===b){p+v<=y?(n=f+_,r=p+v):v>p?(n=_,r=v):(n=f,r=p);break}else e>b?(f+=_,p+=v):(_+=f,v+=p),p>y?(n=_,r=v):(n=f,r=p);n*=d}else (isNaN(e)||isNaN(t))&&(r=n=NaN);break;case`string`:if(p=e.match(/\d+|./g),p===null)throw h();if(p[f]===`-`?(o=-1,f++):p[f]===`+`&&f++,p.length===f+1?c=a(p[f++],o):p[f+1]===`.`||p[f]===`.`?(p[f]!==`.`&&(s=a(p[f++],o)),f++,(f+1===p.length||p[f+1]===`(`&&p[f+3]===`)`||p[f+1]===`'`&&p[f+3]===`'`)&&(c=a(p[f],o),u=10**p[f].length,f++),(p[f]===`(`&&p[f+2]===`)`||p[f]===`'`&&p[f+2]===`'`)&&(l=a(p[f+1],o),d=10**p[f+1].length-1,f+=3)):p[f+1]===`/`||p[f+1]===`:`?(c=a(p[f],o),u=a(p[f+2],1),f+=3):p[f+3]===`/`&&p[f+1]===` `&&(s=a(p[f],o),c=a(p[f+2],o),u=a(p[f+4],1),f+=5),p.length<=f){r=u*d,o=n=l+r*s+d*c;break}default:throw h()}if(r===0)throw m();i.s=o<0?-1:1,i.n=Math.abs(n),i.d=Math.abs(r)};function l(e,t,n){for(var r=1;t>0;e=e*e%n,t>>=1)t&1&&(r=r*e%n);return r}function u(e,t){for(;t%2==0;t/=2);for(;t%5==0;t/=5);if(t===1)return 0;for(var n=10%t,i=1;n!==1;i++)if(n=n*10%t,i>r)return 0;return i}function d(e,t,n){for(var r=1,i=l(10,n,t),a=0;a<300;a++){if(r===i)return a;r=r*10%t,i=i*10%t}return 0}function f(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function p(e,t){if(c(e,t),this instanceof p)e=f(i.d,i.n),this.s=i.s,this.n=i.n/e,this.d=i.d/e;else return o(i.s*i.n,i.d)}var m=function(){return Error(`Division by Zero`)},h=function(){return Error(`Invalid argument`)},g=function(){return Error(`Parameters must be integer`)};p.prototype={s:1,n:0,d:1,abs:function(){return o(this.n,this.d)},neg:function(){return o(-this.s*this.n,this.d)},add:function(e,t){return c(e,t),o(this.s*this.n*i.d+i.s*this.d*i.n,this.d*i.d)},sub:function(e,t){return c(e,t),o(this.s*this.n*i.d-i.s*this.d*i.n,this.d*i.d)},mul:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.n,this.d*i.d)},div:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.d,this.d*i.n)},clone:function(){return o(this.s*this.n,this.d)},mod:function(e,t){if(isNaN(this.n)||isNaN(this.d))return new p(NaN);if(e===void 0)return o(this.s*this.n%this.d,1);if(c(e,t),i.n===0&&this.d===0)throw m();return o(this.s*(i.d*this.n)%(i.n*this.d),i.d*this.d)},gcd:function(e,t){return c(e,t),o(f(i.n,this.n)*f(i.d,this.d),i.d*this.d)},lcm:function(e,t){return c(e,t),i.n===0&&this.n===0?o(0,1):o(i.n*this.n,f(i.n,this.n)*f(i.d,this.d))},ceil:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.ceil(e*this.s*this.n/this.d),e)},floor:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.floor(e*this.s*this.n/this.d),e)},round:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.round(e*this.s*this.n/this.d),e)},inverse:function(){return o(this.s*this.d,this.n)},pow:function(e,t){if(c(e,t),i.d===1)return i.s<0?o((this.s*this.d)**+i.n,this.n**+i.n):o((this.s*this.n)**+i.n,this.d**+i.n);if(this.s<0)return null;var n=s(this.n),r=s(this.d),a=1,l=1;for(var u in n)if(u!==`1`){if(u===`0`){a=0;break}if(n[u]*=i.n,n[u]%i.d===0)n[u]/=i.d;else return null;a*=u**+n[u]}for(var u in r)if(u!==`1`){if(r[u]*=i.n,r[u]%i.d===0)r[u]/=i.d;else return null;l*=u**+r[u]}return i.s<0?o(l,a):o(a,l)},equals:function(e,t){return c(e,t),this.s*this.n*i.d===i.s*i.n*this.d},compare:function(e,t){c(e,t);var n=this.s*this.n*i.d-i.s*i.n*this.d;return(0<n)-(n<0)},simplify:function(e){if(isNaN(this.n)||isNaN(this.d))return this;e||=.001;for(var t=this.abs(),n=t.toContinued(),r=1;r<n.length;r++){for(var i=o(n[r-1],1),a=r-2;a>=0;a--)i=i.inverse().add(n[a]);if(Math.abs(i.sub(t).valueOf())<e)return i.mul(this.s)}return this},divisible:function(e,t){return c(e,t),!(!(i.n*this.d)||this.n*i.d%(i.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,n+=` `,r%=i),n+=r,n+=`/`,n+=i),n},toLatex:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,r%=i),n+=`\\frac{`,n+=r,n+=`}{`,n+=i,n+=`}`),n},toContinued:function(){var e,t=this.n,n=this.d,r=[];if(isNaN(t)||isNaN(n))return r;do r.push(Math.floor(t/n)),e=t%n,t=n,n=e;while(t!==1);return r},toString:function(e){var t=this.n,n=this.d;if(isNaN(t)||isNaN(n))return`NaN`;e||=15;var r=u(t,n),i=d(t,n,r),a=this.s<0?`-`:``;if(a+=t/n|0,t%=n,t*=10,t&&(a+=`.`),r){for(var o=i;o--;)a+=t/n|0,t%=n,t*=10;a+=`(`;for(var o=r;o--;)a+=t/n|0,t%=n,t*=10;a+=`)`}else for(var o=e;t&&o--;)a+=t/n|0,t%=n,t*=10;return a}},typeof e==`object`?(Object.defineProperty(p,`__esModule`,{value:!0}),p.default=p,p.Fraction=p,t.exports=p):n.Fraction=p})(e)})),_a=c(ga(),1),va=`Fraction`,ya=[],ba=or(va,ya,()=>(Object.defineProperty(_a.default,`name`,{value:`Fraction`}),_a.default.prototype.constructor=_a.default,_a.default.prototype.type=`Fraction`,_a.default.prototype.isFraction=!0,_a.default.prototype.toJSON=function(){return{mathjs:`Fraction`,n:this.s*this.n,d:this.d}},_a.default.fromJSON=function(e){return new _a.default(e)},_a.default),{isClass:!0}),xa=`Matrix`,Sa=[],Ca=or(xa,Sa,()=>{function e(){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`)}return e.prototype.type=`Matrix`,e.prototype.isMatrix=!0,e.prototype.storage=function(){throw Error(`Cannot invoke storage on a Matrix interface`)},e.prototype.datatype=function(){throw Error(`Cannot invoke datatype on a Matrix interface`)},e.prototype.create=function(e,t){throw Error(`Cannot invoke create on a Matrix interface`)},e.prototype.subset=function(e,t,n){throw Error(`Cannot invoke subset on a Matrix interface`)},e.prototype.get=function(e){throw Error(`Cannot invoke get on a Matrix interface`)},e.prototype.set=function(e,t,n){throw Error(`Cannot invoke set on a Matrix interface`)},e.prototype.resize=function(e,t){throw Error(`Cannot invoke resize on a Matrix interface`)},e.prototype.reshape=function(e,t){throw Error(`Cannot invoke reshape on a Matrix interface`)},e.prototype.clone=function(){throw Error(`Cannot invoke clone on a Matrix interface`)},e.prototype.size=function(){throw Error(`Cannot invoke size on a Matrix interface`)},e.prototype.map=function(e,t){throw Error(`Cannot invoke map on a Matrix interface`)},e.prototype.forEach=function(e){throw Error(`Cannot invoke forEach on a Matrix interface`)},e.prototype[Symbol.iterator]=function(){throw Error(`Cannot iterate a Matrix interface`)},e.prototype.toArray=function(){throw Error(`Cannot invoke toArray on a Matrix interface`)},e.prototype.valueOf=function(){throw Error(`Cannot invoke valueOf on a Matrix interface`)},e.prototype.format=function(e){throw Error(`Cannot invoke format on a Matrix interface`)},e.prototype.toString=function(){throw Error(`Cannot invoke toString on a Matrix interface`)},e},{isClass:!0});function wa(e){return Object.keys(e.signatures||{}).reduce(function(e,t){var n=(t.match(/,/g)||[]).length+1;return Math.max(e,n)},-1)}var Ta=`DenseMatrix`,Ea=[`Matrix`],Da=or(Ta,Ea,e=>{var{Matrix:t}=e;function n(e,t){if(!(this instanceof n))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!Et(t))throw Error(`Invalid datatype: `+t);if(Dt(e))e.type===`DenseMatrix`?(this._data=sn(e._data),this._size=sn(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&M(e.data)&&M(e.size))this._data=e.data,this._size=e.size,Hn(this._data,this._size),this._datatype=t||e.datatype;else if(M(e))this._data=l(e),this._size=Bn(this._data),Hn(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+on(e)+`)`);else this._data=[],this._size=[0],this._datatype=t}n.prototype=new t,n.prototype.createDenseMatrix=function(e,t){return new n(e,t)},Object.defineProperty(n,`name`,{value:`DenseMatrix`}),n.prototype.constructor=n,n.prototype.type=`DenseMatrix`,n.prototype.isDenseMatrix=!0,n.prototype.getDataType=function(){return Qn(this._data,on)},n.prototype.storage=function(){return`dense`},n.prototype.datatype=function(){return this._datatype},n.prototype.create=function(e,t){return new n(e,t)},n.prototype.subset=function(e,t,n){switch(arguments.length){case 1:return r(this,e);case 2:case 3:return a(this,e,t,n);default:throw SyntaxError(`Wrong number of arguments`)}},n.prototype.get=function(e){if(!M(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new P(e.length,this._size.length);for(var t=0;t<e.length;t++)F(e[t],this._size[t]);for(var n=this._data,r=0,i=e.length;r<i;r++){var a=e[r];F(a,n.length),n=n[a]}return n},n.prototype.set=function(e,t,n){if(!M(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new P(e.length,this._size.length,`<`);var r,i,a,o=e.map(function(e){return e+1});c(this,o,n);var s=this._data;for(r=0,i=e.length-1;r<i;r++)a=e[r],F(a,s.length),s=s[a];return a=e[e.length-1],F(a,s.length),s[a]=t,this};function r(e,t){if(!Mt(t))throw TypeError(`Invalid index`);if(t.isScalar())return e.get(t.min());var r=t.size();if(r.length!==e._size.length)throw new P(r.length,e._size.length);for(var a=t.min(),o=t.max(),s=0,c=e._size.length;s<c;s++)F(a[s],e._size[s]),F(o[s],e._size[s]);return new n(i(e._data,t,r.length,0),e._datatype)}function i(e,t,n,r){var a=r===n-1,o=t.dimension(r);return a?o.map(function(t){return F(t,e.length),e[t]}).valueOf():o.map(function(a){F(a,e.length);var o=e[a];return i(o,t,n,r+1)}).valueOf()}function a(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Invalid index`);var i=t.size(),a=t.isScalar(),s;if(Dt(n)?(s=n.size(),n=n.valueOf()):s=Bn(n),a){if(s.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!ln(s,i))try{n=s.length===0?rr([n],i):rr(n,i),s=Bn(n)}catch{}if(i.length<e._size.length)throw new P(i.length,e._size.length,`<`);if(s.length<i.length){for(var l=0,u=0;i[l]===1&&s[l]===1;)l++;for(;i[l]===1;)u++,l++;n=Yn(n,i.length,u,s)}if(!ln(i,s))throw new P(i,s,`>`);c(e,t.max().map(function(e){return e+1}),r);var d=i.length;o(e._data,t,n,d,0)}return e}function o(e,t,n,r,i){var a=i===r-1,s=t.dimension(i);a?s.forEach(function(t,r){F(t),e[t]=n[r[0]]}):s.forEach(function(a,s){F(a),o(e[a],t,n[s[0]],r,i+1)})}n.prototype.resize=function(e,t,n){if(!Ot(e))throw TypeError(`Array or Matrix expected`);var r=e.valueOf().map(e=>Array.isArray(e)&&e.length===1?e[0]:e);return s(n?this.clone():this,r,t)};function s(e,t,n){if(t.length===0){for(var r=e._data;M(r);)r=r[0];return r}return e._size=t.slice(0),e._data=Un(e._data,e._size,n),e}n.prototype.reshape=function(e,t){var n=t?this.clone():this;return n._data=Gn(n._data,e),n._size=Kn(e,n._size.reduce((e,t)=>e*t)),n};function c(e,t,n){for(var r=e._size.slice(0),i=!1;r.length<t.length;)r.push(0),i=!0;for(var a=0,o=t.length;a<o;a++)t[a]>r[a]&&(r[a]=t[a],i=!0);i&&s(e,r,n)}n.prototype.clone=function(){return new n({data:sn(this._data),size:sn(this._size),datatype:this._datatype})},n.prototype.size=function(){return this._size.slice(0)},n.prototype.map=function(e){var t=this,r=wa(e),i=function n(i,a){return M(i)?i.map(function(e,t){return n(e,a.concat(t))}):r===1?e(i):r===2?e(i,a):e(i,a,t)}(this._data,[]);return new n(i,this._datatype===void 0?void 0:Qn(i,on))},n.prototype.forEach=function(e){var t=this;(function n(r,i){M(r)?r.forEach(function(e,t){n(e,i.concat(t))}):e(r,i,t)})(this._data,[])},n.prototype[Symbol.iterator]=function*(){yield*function*e(t,n){if(M(t))for(var r=0;r<t.length;r++)yield*e(t[r],n.concat(r));else yield{value:t,index:n}}(this._data,[])},n.prototype.rows=function(){var e=[];if(this.size().length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var t of this._data)e.push(new n([t],this._datatype));return e},n.prototype.columns=function(){var e=this,t=[],r=this.size();if(r.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var i=this._data,a=function(r){var a=i.map(e=>[e[r]]);t.push(new n(a,e._datatype))},o=0;o<r[1];o++)a(o);return t},n.prototype.toArray=function(){return sn(this._data)},n.prototype.valueOf=function(){return this._data},n.prototype.format=function(e){return Nn(this._data,e)},n.prototype.toString=function(){return Nn(this._data)},n.prototype.toJSON=function(){return{mathjs:`DenseMatrix`,data:this._data,size:this._size,datatype:this._datatype}},n.prototype.diagonal=function(e){if(e){if(j(e)&&(e=e.toNumber()),!A(e)||!N(e))throw TypeError(`The parameter k must be an integer number`)}else e=0;for(var t=e>0?e:0,r=e<0?-e:0,i=this._size[0],a=this._size[1],o=Math.min(i-r,a-t),s=[],c=0;c<o;c++)s[c]=this._data[c+r][c+t];return new n({data:s,size:[o],datatype:this._datatype})},n.diagonal=function(e,t,r,i){if(!M(e))throw TypeError(`Array expected, size parameter`);if(e.length!==2)throw Error(`Only two dimensions matrix are supported`);if(e=e.map(function(e){if(j(e)&&(e=e.toNumber()),!A(e)||!N(e)||e<1)throw Error(`Size values must be positive integers`);return e}),r){if(j(r)&&(r=r.toNumber()),!A(r)||!N(r))throw TypeError(`The parameter k must be an integer number`)}else r=0;var a=r>0?r:0,o=r<0?-r:0,s=e[0],c=e[1],l=Math.min(s-o,c-a),u;if(M(t)){if(t.length!==l)throw Error(`Invalid value array length`);u=function(e){return t[e]}}else if(Dt(t)){var d=t.size();if(d.length!==1||d[0]!==l)throw Error(`Invalid matrix length`);u=function(e){return t.get([e])}}else u=function(){return t};i||=j(u(0))?u(0).mul(0):0;var f=[];if(e.length>0){f=Un(f,e,i);for(var p=0;p<l;p++)f[p+o][p+a]=u(p)}return new n({data:f,size:[s,c]})},n.fromJSON=function(e){return new n(e)},n.prototype.swapRows=function(e,t){if(!A(e)||!N(e)||!A(t)||!N(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return F(e,this._size[0]),F(t,this._size[0]),n._swapRows(e,t,this._data),this},n._swapRows=function(e,t,n){var r=n[e];n[e]=n[t],n[t]=r};function l(e){return Dt(e)?l(e.valueOf()):M(e)?e.map(l):e}return n},{isClass:!0});function Oa(e,t,n){return e&&typeof e.map==`function`?e.map(function(e){return Oa(e,t,n)}):t(e)}var ka=`isNumeric`,Aa=[`typed`],ja=or(ka,Aa,e=>{var{typed:t}=e;return t(ka,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>Oa(t,e))})}),Ma=`hasNumericValue`,Na=[`typed`,`isNumeric`],Pa=or(Ma,Na,e=>{var{typed:t,isNumeric:n}=e;return t(Ma,{boolean:()=>!0,string:function(e){return e.trim().length>0&&!isNaN(Number(e))},any:function(e){return n(e)}})}),Fa=oa({config:hn}),Ia=ha({}),La=ba({}),Ra=Ca({}),za=Da({Matrix:Ra}),Ba=Cr({BigNumber:Fa,Complex:Ia,DenseMatrix:za,Fraction:La}),Va=ja({typed:Ba}),Ha=Pa({isNumeric:Va,typed:Ba});const Ua=e=>{let t=Number(e);return Number.isNaN(t)?!1:t>=120&&t<=36e4},Wa=e=>{let t=Number(e),n=Date.now();return Number.isNaN(t)?n+1e3:!Ua(t)&&(0,l.isFutureUnixTimestamp)(t)?bt(t):Ua(t)?n+t:n+t*_t},Ga=`ratelimitlimit`,Ka=`ratelimitremaining`,qa=`ratelimitreset`,Ja=`ratelimitconcurrencylimit`,Ya=`ratelimitconcurrencyremaining`,Xa=`ratelimitconcurrencyreset`,Za=e=>{let t={};for(let[n,r]of Object.entries(e)){let e=n.toLowerCase().replace(/^x-/,``).replace(/concurren.+-/g,`concurrency-`).replace(/-/g,``);t[e]=Ha(r)?Number(r):null}return t},Qa=e=>{let t=Za(e);return{rateLimitLimit:t.ratelimitlimit,rateLimitRemaining:t.ratelimitremaining,rateLimitReset:Wa(t.ratelimitreset),concurrencyLimit:t.ratelimitconcurrencylimit,concurrencyRemaining:t.ratelimitconcurrencyremaining,concurrencyReset:Wa(t.ratelimitconcurrencyreset)}},$a=e=>{let{accountSecureId:t,service:n,resource:r,subResource:i,childResource:a,action:o,behaviours:s}=e??{};return[t,n,r,o].some(l.isMissing)?null:[t,n,r,i,a,o,...s??[]].filter(Boolean).join(`-`)},eo=(e,t=10,n=1)=>{let r=Date.now();return(0,l.isFutureUnixTimestamp)(e)||(0,l.isNumber)(e)?to(Number(e),r,t,n):Et(e)&&e!==``?no(e,r,t,n):n},to=(e,t,n=10,r=1)=>{if(e<n)return e;let i=bt(e);if(i>t){let e=Math.floor((i-t)/_t);return e>0&&e<n?e:r}return r},no=(e,t,n=10,r=1)=>{if(vt.test(e)){let t=parseFloat(e);return t>0&&t<n?t:r}let i=new Date(e);if(Number.isNaN(i.getTime()))return r;let a=i.getTime();if(a>t){let e=Math.floor((a-t)/_t);return e>0&&e<n?e:r}return r},ro=({axiosInstance:e,logger:t,requestConfig:n,context:r})=>async i=>{let{response:a,config:o}=i;if(o?.signal?.aborted)return Promise.reject(lt(`Request aborted`,o,`ERR_CANCELED`,a));let{status:s,retryAfter:c}=io(a,r,n,t);if(s===429&&(0,l.notMissing)(o)){let n=eo(c);if(o._retryCount>=5)return t?.warning({category:`http-transport`,message:`Max retries exceeded for ${o?.url}. Aborting.`,context:{...r??{},retryAfterHeader:c,retryAfterAsNumber:n}}),Promise.reject(i);let s=o._retryCount??0,u={...o,_retryCount:s+1},d=c?n*_t:(0,l.exponentialBackoffInMS)(u._retryCount);return t?.debug({category:`http-transport`,message:`Received 429 error from ${o?.url}`,context:{...r??{},retryAfterHeader:c,calculatedRetryAfter:d}}),await ut(d,o,a),e?.request(u)}return Promise.reject(i)},io=(e,t,n,r)=>{let{provider:i}=t??{},{status:a,headers:o,data:s}=e??{},{retryafter:c}=Za(o??{});if((0,l.isMissing)(i)||(0,l.isMissing)(e))return r?.warning({category:`http-transport`,message:`Invalid parameters for convertError`,context:{...t,responseIsMissing:(0,l.isMissing)(e),providerIsMissing:(0,l.isMissing)(i),status:e?.status??`undefined`,statusText:e?.statusText??`undefined`,retryafter:c??`undefined`}}),{status:a,retryAfter:c};let u=n?.rateLimits?.mappedRateLimitErrors;if((0,l.notMissing)(u)&&(0,l.notMissing)(s))for(let e of u){let{errorStatus:t,errorMessagePath:n,errorMessage:r,retryAfterPath:i,retryAfterUnit:u,retryAfterValue:d}=e;if(t!==a)continue;let f=n??`message`,p=ao((0,l.isObject)(s)?(0,g.JSONPath)({path:f,json:s})[0]:s,r);if(t===a&&p){let e=so(d??oo(o,i),u);return{status:429,retryAfter:c??e}}}return{status:a,retryAfter:c}},ao=(e,t)=>t instanceof RegExp?t.test(e??``):e?.includes(t)??!1,oo=(e,t)=>(0,l.notMissing)(t)&&(0,l.notMissing)(e)?(0,g.JSONPath)({path:t,json:e})[0]:null,so=(e,t=`seconds`)=>(0,l.notMissing)(e)?co(e,t):null,co=(e,t)=>{if(t===`seconds`)return typeof e==`string`?parseFloat(e):e;if(t===`milliseconds`)return(typeof e==`string`?parseFloat(e):e)/_t;if(t===`date`){let t=typeof e==`string`&&!isNaN(Number(e))?parseFloat(e):e,n=new Date(t);if(isNaN(n.getTime()))throw Error(`Invalid date value`);return n.getTime()}throw Error(`Invalid type`)},lo=`rateLimitErrorInterceptor`,uo=({axiosInstance:e,logger:t,requestConfig:n,context:r,concurrencyManager:i})=>async a=>{let{response:o,config:s}=a,c=s?.signal;if((0,l.isMissing)(r)||(0,l.isMissing)(s))return t?.warning({category:`HttpClient`,message:`No context or config for this response - that doesn't seem right.`,context:{interceptor:lo,...s,httpsAgent:void 0,headers:void 0,hasContext:(0,l.notMissing)(r),hasConfig:(0,l.notMissing)(s)},code:ct.InterceptorContextNotPresent}),Promise.reject(a);if((0,l.isMissing)(i))return t?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:lo,...s,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:(0,l.notMissing)(i)},code:ct.RateLimitOrConcurrencyManagerNotInitialized}),Promise.reject(a);let{requestId:u,targetConcurrencyKey:d,leaseSubscription:f,setRemovalSubscription:p}=s?.requestMetadata??{};if(!((0,l.notMissing)(u)&&(0,l.notMissing)(d)&&await i.releaseRequest(u,d))&&(0,l.notMissing)(s?.requestMetadata)&&t?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{...r,interceptor:lo,requestId:u,targetConcurrencyKey:d,leaseSubscription:f,setRemovalSubscription:p},code:ct.RateLimiterReleaseRequestFailed}),c?.aborted)return Promise.reject(lt(`Request aborted`,s,`ERR_CANCELED`,o));let{status:m,retryAfter:h}=io(o,r,n,t);if(m===429&&(0,l.notMissing)(s)){let n=eo(h);if(s._retryCount>=5)return t?.warning({category:`HttpClient`,message:`Max retries exceeded for ${s.url}. Aborting.`,context:{...r??{},...s.requestMetadata??{},retryAfterHeader:h,retryAfterAsNumber:n}}),Promise.reject(a);let i=s?._retryCount??0,c={...s,_retryCount:i+1},u=h?n*_t:(0,l.exponentialBackoffInMS)(c._retryCount);return t?.debug({category:`HttpClient`,message:`Received 429 error from ${s.url}`,context:{...r,retryAfterHeader:h,calculatedRetryAfter:u}}),await ut(u,s,o),e?.request(c)}return Promise.reject(a)},fo=`rateLimitResponseInterceptor`,po=({logger:e,context:t,concurrencyManager:n})=>async r=>{let i=r?.config,a=i?.signal;if((0,l.isMissing)(t))e?.warning({category:`HttpClient`,message:`No context for this response - that doesn't seem right.`,context:{interceptor:fo,...i,httpsAgent:void 0,headers:void 0}});else if((0,l.isMissing)(n))return e?.error({category:`HttpClient`,message:`ConcurrencyManager is not initialized`,context:{interceptor:fo,...i,httpsAgent:void 0,headers:void 0,concurrencyManagerInitialized:(0,l.notMissing)(n)},code:ct.RateLimitOrConcurrencyManagerNotInitialized}),r;else if((0,l.notMissing)(t.provider)&&(0,l.notMissing)(t.accountSecureId)){let t=r?.headers;if((0,l.notMissing)(t)){let n=Qa(t);e?.debug({category:`HttpClient`,message:`Rate limit headers extracted`,context:{interceptor:fo,rateLimitHeaders:n}})}let{requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:u}=i?.requestMetadata??{};if(await n.releaseRequest(o,s)||e?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{interceptor:fo,requestId:o,targetConcurrencyKey:s,leaseSubscription:c,setRemovalSubscription:u},code:ct.RateLimiterReleaseRequestFailed}),a?.aborted)return Promise.reject(lt(`Request aborted`,i,`ERR_CANCELED`,r))}return r},mo=e=>(e.validateStatus??=e=>e>=200&&e<300,e),ho=[{onFulfilled:mo,onRejected:null,options:void 0}],go=[{onFulfilled:null,onRejected:ro},{onFulfilled:null,onRejected:it}],_o=[{onFulfilled:mo,onRejected:null,options:void 0},{onFulfilled:ft,onRejected:null,options:void 0}],vo=[{onFulfilled:po,onRejected:uo},{onFulfilled:null,onRejected:it}],yo=1,bo=1e3,xo=0,So=59,Co=.8,wo=500;var To=class extends _e{constructor(...e){super(...e),this.name=`RateLimitManager`}async additionalInitialization(){}getDynamicMaxWaitTime(e,t,n,r=59,i=.8,a=500){this.readyCheck();let o=e.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.rateLimit??e.mainRatelimit;if(o<=0)throw Error(`Requests per second (rps) must be greater than 0.`);let s=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.maxConcurrency??t.mainMaxConcurrency;if(s<=0)throw Error(`Concurrency must be greater than 0.`);let c=r*i,l=1/Math.min(o,s/(a/1e3)),u=Math.max(7.5,c*l);return Math.min(c,u)}async getWaitTime(e,t,n){this.readyCheck();let r=`rateLimit:${e}`,i=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.subPoolKey,a=(0,l.notMissing)(i)?`${r}-${i}`:r,{mainRatelimit:o,subPools:s}=t,c=[{key:r,rateLimit:o},...s?.map(e=>{let{subPoolKey:t,rateLimit:n}=e;return{key:`${r}-${t}`,rateLimit:n}})??[]],u=c.map(e=>e.key),d=c.map(e=>e.rateLimit);return await this.executeScript(st.incr,[a,...u],[o.toString(),...d.map(String)])??0}readyCheck(){if(!this.cacheClient||!this.scriptMap?.size)throw Error(`RateLimitManager not ready`)}isReady(){return!!this?.cacheClient&&!!this?.scriptMap?.size}close(){this.scriptMap?.clear(),this.reset()}},Z=class{static{this.instances=new Map}static async prepare(e,t,...n){if(!this.instances.has(e)){let t=new e;t.getSingleton=e=>{let t=this.instances.get(e);if((0,l.isMissing)(t))throw Error(`Singleton ${e.name} not prepared yet`);if(t.hasInitFailed?.())throw Error(`${e.name} initialization failed`);let n=t.getInstanceIfReady?.();if((0,l.notMissing)(n))return n;throw Error(`${e.name} not ready`)},this.instances.set(e,t)}let r=this.instances.get(e);try{return await r.getInstance(t,...n)}catch(t){throw r.hasInitFailed?.()&&this.instances.delete(e),t}}static getIfReady(e){return this.instances.get(e)?.getInstanceIfReady?.()??null}static reset(e){this.instances.get(e)?.reset?.(),this.instances.delete(e)}static cleanupFailed(){let e=0;for(let[t,n]of this.instances){let r=n;r?.hasInitFailed?.()&&(r?.reset?.(),this.instances.delete(t),e++)}return e}};let Eo=function(e){return e.HttpTransportInstanceCreateError=`HttpTransportInstanceCreateError`,e}({});const Do=async({logger:e,redisClientConfig:t,context:n,requestConfig:r,httpsAgentConfig:i}={})=>{let a,{NODE_ENV:o}=process.env,s=n?.behaviours??[`CONCURRENCY`,`RETRY`];try{if(a=s.includes(`RETRY`)?ko(e,n):Oo(e,n),(0,l.isMissing)(n?.service)||(0,l.isMissing)(n?.organizationId)||o===`test`||(0,l.isMissing)(t)||(0,l.isMissing)(e))return a;let c=Z.getIfReady(To)??void 0,u=Z.getIfReady(Ke)??void 0,d=c?.isReady(),f=u?.isRedisConfigured(),p=[],m=[];if(s.includes(`CONCURRENCY`)){if(!f)throw Error(`Concurrency Manager cannot connect to Redis. Cannot create advanced transport instance.`);if(!d)throw Error(`RateLimitManager is not ready. Cannot create advanced transport instance.`);p.push(..._o),m.push(...vo)}let h=$a(n);if((0,l.isMissing)(h))return e?.warning({category:`http-transport`,message:`Unable to create a key for transport instance - Invalid state. Using base default instance.`,context:{...n,defaultInstanceInitialized:(0,l.notMissing)(a)}}),a;let g=await rt.get(h);if((0,l.notMissing)(g))return g;let _={interceptors:{requestConfigs:p,responseConfigs:m},instanceConfig:{maxBodyLength:1/0},logger:e,context:n,requestConfig:r,httpsAgentConfig:i,concurrencyManager:u,rateLimitManager:c},v=et.createInstance(_);return e?.debug({category:`http-transport`,message:`Creating new Axios instance and caching it for key: [${h}]`,context:{...n}}),await rt.set(h,v),v}catch(t){return e?.error({category:`http-transport`,message:`Failed to create advanced transport instance. Using default instance.`,context:{...n,usingDefaultInstance:(0,l.notMissing)(a)},error:t,code:Eo.HttpTransportInstanceCreateError}),(0,l.notMissing)(a)?a:Ao()}},Oo=(e,t)=>{let n={instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return et.createInstance(n)??Ao()},ko=(e,t)=>{let n={interceptors:{requestConfigs:ho,responseConfigs:go},instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return et.createInstance(n)??Ao()},Ao=()=>f.default.create({maxBodyLength:1/0});var jo=class{#e;#t;#n;#r;#i;#a;constructor({transportFactory:e=Do,getRedisClient:t=fe,logger:n,redisClientConfig:r,errorMappingFn:i}={}){this.name=`HttpClient`,this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}#o({url:e,payload:t,method:n,context:r}){if(!r?.accountSecureId||r.accountSecureId.length<20||!e||!n)return null;let i=t?(0,l.getContentHash)(t):``;return`${r.accountSecureId}-${n.toUpperCase()}${i}-${e}`}async#s({url:e,payload:t,method:n,cacheTTL:r,context:i}){if(!this.#a||!r||r<=0)return null;let a=this.#o({url:e,payload:t,method:n,context:i});if(!a)return null;let o=await this.#a.getData(a);return o?(this.#n?.debug({category:this.name,message:`Cache hit for key [${a}].`}),o):(this.#n?.debug({category:this.name,message:`Cache miss for key [${a}].`}),null)}async#c({url:e,payload:t,method:n,cacheTTL:r,context:i,response:a}){if(!this.#a||!r||r<=0)return!1;let o=this.#o({url:e,payload:t,method:n,context:i});return o?(this.#n?.debug({category:this.name,message:`Caching result for key [${o}].`}),this.#a.setData({key:o,value:a,cacheTTL:r*60})):!1}async request({headers:e={},url:t,method:n=`get`,queryParams:r,maxRedirects:i=0,responseType:a,cacheTTL:o,context:s,traceId:c,payload:u,httpsAgent:d,httpAgent:f,requestConfig:p,httpsAgentConfig:m}){try{(0,l.notMissing)(this.#r)&&(0,l.isMissing)(this.#a)&&(this.#a=await this.#t(this.#r,this.#n,`HttpClient`));let h=this.#_(t,r),g=this.#l(e),_=this.#m(u,e),v=await this.#s({url:h,payload:_,method:n,cacheTTL:o,context:s});if(v)return{...v,responseTime:new Date};let y=nt.getInstance(),b=((0,l.notMissing)(c)?await y.get(c):null)?.signal,x=await(await this.#e({redisClientConfig:this.#r,logger:this.#n,context:s,requestConfig:p,httpsAgentConfig:m})).request({headers:g,url:h,method:n,maxRedirects:i,responseType:a,data:_,httpsAgent:d,httpAgent:f,signal:b}),S={data:x.data,status:x.status,body:_,method:n,headers:this.#u(x.headers),requestUrl:t,responseType:x?.config?.responseType,responseTime:new Date};return await this.#c({url:h,payload:_,method:n,cacheTTL:o,context:s,response:S}),S}catch(e){let r=e;r.url=(0,_.redactUrl)(t),this.#n?.warning({category:this.name,message:`Request error [${n?.toUpperCase()} ${r.url}]: ${r.message}.`,error:r});let i=this.#h(r);throw(0,l.notMissing)(i)?i:e}}async get({headers:e,url:t,queryParams:n,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s}){return this.request({url:t,method:`get`,queryParams:n,headers:e,maxRedirects:r,cacheTTL:i,context:a,traceId:o,requestConfig:s})}async post({headers:e,url:t,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s}){return this.request({url:t,method:`post`,headers:e,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s})}async requestStream({headers:e={},url:t,method:n=`get`,queryParams:r,maxRedirects:i=0,context:a,traceId:o,payload:s,httpsAgent:c,httpAgent:u,requestConfig:d,httpsAgentConfig:f}){try{let p=this.#_(t,r),m=this.#l(e),h=this.#m(s,e),g=nt.getInstance(),_=((0,l.notMissing)(o)?await g.get(o):null)?.signal,v=await(await this.#e({redisClientConfig:this.#r,logger:this.#n,context:a,requestConfig:d,httpsAgentConfig:f})).request({headers:m,url:p,method:n,maxRedirects:i,responseType:`stream`,data:h,httpsAgent:c,httpAgent:u,signal:_});return{status:v.status,headers:this.#u(v.headers),stream:v.data,requestUrl:t}}catch(e){let r=e;r.url=(0,_.redactUrl)(t),this.#n?.warning({category:this.name,message:`Stream request error [${n?.toUpperCase()} ${r.url}]: ${r.message}.`,error:r});let i=this.#h(r);throw(0,l.notMissing)(i)?i:e}}#l(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n.toLowerCase()]=e[n]||``}),t}#u(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n]=e[n]||``}),t}#d(e){return e[`content-type`]===`application/x-www-form-urlencoded`}#f(e){return e[`content-type`]?.startsWith(`multipart/form-data`)??!1}#p(e){return(0,l.isMissing)(e)||typeof e!=`object`||!e?!1:`pipe`in e&&typeof e.pipe==`function`}#m(e,t){if(!((0,l.isMissing)(e)||(0,l.isObject)(e)&&Object.keys(e).length===0))return this.#f(t)||this.#p(e)?e:this.#d(t)?v.default.stringify(e):e}#h(e){if((0,f.isAxiosError)(e)&&this.#i)return this.#i(e)}#g(e){return typeof e==`object`&&!!e&&`value`in e&&(typeof e.value==`string`||Array.isArray(e.value))}#_(e,t){if((0,l.isMissing)(t)||Object.keys(t).length===0)return e;let n={},r={},i={},a={};for(let[e,o]of Object.entries(t))if(this.#g(o)){let t=o.arrayFormat,s=o.value;t===`repeat`?r[e]=Array.isArray(s)?s:[s]:t===`brackets`?i[e]=Array.isArray(s)?s:[s]:t===`comma`?a[e]=Array.isArray(s)?s:[s]:n[e]=s}else n[e]=o;let o=[];Object.keys(n).length>0&&o.push(v.default.stringify(n)),Object.keys(r).length>0&&o.push(v.default.stringify(r,{arrayFormat:`repeat`})),Object.keys(i).length>0&&o.push(v.default.stringify(i,{arrayFormat:`brackets`})),Object.keys(a).length>0&&o.push(v.default.stringify(a,{arrayFormat:`comma`}));let s=o.join(`&`);return(0,l.notMissing)(s)?`${e}?${s}`:e}};const Mo=(e,t,n)=>new jo({redisClientConfig:e,logger:t,errorMappingFn:n});var No=class{static{this.httpClientInstance=null}static async getInstance({redisClientConfig:e,logger:t,errorMappingFn:n,getHttpClient:r=Mo}){return this.httpClientInstance??=r(e,t,n),this.httpClientInstance}static resetInstance(){this.httpClientInstance=null}};const Po=[`get`,`post`,`put`,`delete`,`patch`],Fo={[O.rPush]:`
126
126
  local queueLength = redis.call('RPUSH', KEYS[1], ARGV[1])
127
127
 
128
128
  redis.call('PEXPIRE', KEYS[1], ARGV[2])
package/dist/index.d.cts CHANGED
@@ -2,6 +2,7 @@ import * as redis from "redis";
2
2
  import { AxiosInstance, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
3
3
  import http, { AgentOptions } from "node:http";
4
4
  import https from "node:https";
5
+ import { Readable } from "node:stream";
5
6
  import { z } from "@stackone/utils";
6
7
 
7
8
  //#region src/authorization/types.d.ts
@@ -399,6 +400,12 @@ type HttpResponse<T = any> = {
399
400
  responseTime?: Date;
400
401
  message?: string;
401
402
  };
403
+ type StreamHttpResponse = {
404
+ status: number;
405
+ headers: HttpHeaders;
406
+ stream: Readable;
407
+ requestUrl: string;
408
+ };
402
409
  type HttpParameters = {
403
410
  query: HttpQueryParams;
404
411
  body: Record<string, unknown> | unknown[];
@@ -468,6 +475,33 @@ interface IHttpClient {
468
475
  payload?: P;
469
476
  requestConfig?: RequestConfig;
470
477
  }): Promise<HttpResponse<T>>;
478
+ requestStream({
479
+ headers,
480
+ url,
481
+ method,
482
+ queryParams,
483
+ maxRedirects,
484
+ context,
485
+ traceId,
486
+ payload,
487
+ httpsAgent,
488
+ httpAgent,
489
+ requestConfig,
490
+ httpsAgentConfig
491
+ }: {
492
+ headers?: HttpHeaders;
493
+ url: string;
494
+ method?: HttpMethod;
495
+ queryParams?: HttpQueryParams;
496
+ maxRedirects?: number;
497
+ context?: RequestContext;
498
+ traceId?: string;
499
+ payload?: unknown;
500
+ httpsAgent?: https.Agent;
501
+ httpAgent?: http.Agent;
502
+ requestConfig?: RequestConfig;
503
+ httpsAgentConfig?: https.AgentOptions;
504
+ }): Promise<StreamHttpResponse>;
471
505
  }
472
506
  interface OperationSetting {
473
507
  url?: string;
@@ -703,6 +737,33 @@ declare class HttpClient<TError extends Error = Error> implements IHttpClient {
703
737
  payload?: P;
704
738
  requestConfig?: RequestConfig;
705
739
  }): Promise<HttpResponse<T>>;
740
+ requestStream({
741
+ headers,
742
+ url,
743
+ method,
744
+ queryParams,
745
+ maxRedirects,
746
+ context,
747
+ traceId,
748
+ payload,
749
+ httpsAgent,
750
+ httpAgent,
751
+ requestConfig,
752
+ httpsAgentConfig
753
+ }: {
754
+ headers?: HttpHeaders;
755
+ url: string;
756
+ method?: HttpMethod;
757
+ queryParams?: HttpQueryParams;
758
+ maxRedirects?: number;
759
+ context?: RequestContext;
760
+ traceId?: string;
761
+ payload?: unknown;
762
+ httpsAgent?: https.Agent;
763
+ httpAgent?: http.Agent;
764
+ requestConfig?: RequestConfig;
765
+ httpsAgentConfig?: https.AgentOptions;
766
+ }): Promise<StreamHttpResponse>;
706
767
  }
707
768
  //#endregion
708
769
  //#region src/httpClient/httpClientManager.d.ts
@@ -942,4 +1003,4 @@ type LockEntry = {
942
1003
  unlock: Unlock;
943
1004
  };
944
1005
  //#endregion
945
- export { CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, createAuthorizationHeaders, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, translateCustomError };
1006
+ export { CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, type StreamHttpResponse, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, createAuthorizationHeaders, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, translateCustomError };
package/dist/index.d.mts CHANGED
@@ -3,6 +3,7 @@ import * as redis from "redis";
3
3
  import { AxiosInstance, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
4
4
  import https from "node:https";
5
5
  import http, { AgentOptions } from "node:http";
6
+ import { Readable } from "node:stream";
6
7
 
7
8
  //#region src/authorization/types.d.ts
8
9
  type NoAuthorizationParams = {
@@ -399,6 +400,12 @@ type HttpResponse<T = any> = {
399
400
  responseTime?: Date;
400
401
  message?: string;
401
402
  };
403
+ type StreamHttpResponse = {
404
+ status: number;
405
+ headers: HttpHeaders;
406
+ stream: Readable;
407
+ requestUrl: string;
408
+ };
402
409
  type HttpParameters = {
403
410
  query: HttpQueryParams;
404
411
  body: Record<string, unknown> | unknown[];
@@ -468,6 +475,33 @@ interface IHttpClient {
468
475
  payload?: P;
469
476
  requestConfig?: RequestConfig;
470
477
  }): Promise<HttpResponse<T>>;
478
+ requestStream({
479
+ headers,
480
+ url,
481
+ method,
482
+ queryParams,
483
+ maxRedirects,
484
+ context,
485
+ traceId,
486
+ payload,
487
+ httpsAgent,
488
+ httpAgent,
489
+ requestConfig,
490
+ httpsAgentConfig
491
+ }: {
492
+ headers?: HttpHeaders;
493
+ url: string;
494
+ method?: HttpMethod;
495
+ queryParams?: HttpQueryParams;
496
+ maxRedirects?: number;
497
+ context?: RequestContext;
498
+ traceId?: string;
499
+ payload?: unknown;
500
+ httpsAgent?: https.Agent;
501
+ httpAgent?: http.Agent;
502
+ requestConfig?: RequestConfig;
503
+ httpsAgentConfig?: https.AgentOptions;
504
+ }): Promise<StreamHttpResponse>;
471
505
  }
472
506
  interface OperationSetting {
473
507
  url?: string;
@@ -703,6 +737,33 @@ declare class HttpClient<TError extends Error = Error> implements IHttpClient {
703
737
  payload?: P;
704
738
  requestConfig?: RequestConfig;
705
739
  }): Promise<HttpResponse<T>>;
740
+ requestStream({
741
+ headers,
742
+ url,
743
+ method,
744
+ queryParams,
745
+ maxRedirects,
746
+ context,
747
+ traceId,
748
+ payload,
749
+ httpsAgent,
750
+ httpAgent,
751
+ requestConfig,
752
+ httpsAgentConfig
753
+ }: {
754
+ headers?: HttpHeaders;
755
+ url: string;
756
+ method?: HttpMethod;
757
+ queryParams?: HttpQueryParams;
758
+ maxRedirects?: number;
759
+ context?: RequestContext;
760
+ traceId?: string;
761
+ payload?: unknown;
762
+ httpsAgent?: https.Agent;
763
+ httpAgent?: http.Agent;
764
+ requestConfig?: RequestConfig;
765
+ httpsAgentConfig?: https.AgentOptions;
766
+ }): Promise<StreamHttpResponse>;
706
767
  }
707
768
  //#endregion
708
769
  //#region src/httpClient/httpClientManager.d.ts
@@ -942,4 +1003,4 @@ type LockEntry = {
942
1003
  unlock: Unlock;
943
1004
  };
944
1005
  //#endregion
945
- export { CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, createAuthorizationHeaders, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, translateCustomError };
1006
+ export { CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, type StreamHttpResponse, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, createAuthorizationHeaders, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, translateCustomError };