UNPKG

hud-sdk

Version:

Hud's Node SDK

2 lines 22.7 kB
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(global,(()=>(()=>{"use strict";var e={2546:e=>{e.exports=require("./lib")},2702:function(e,t,r){var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,i)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return i(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.WorkerKeepaliveGuard=void 0;const s=n(r(2546)),a=r(8528),d=s.app_logger;t.WorkerKeepaliveGuard=class{worker;keepaliveGrace;timeoutId=void 0;eventHandler=this.keepalive.bind(this);constructor(e,t){this.worker=e,this.keepaliveGrace=t}keepalive(e){try{if(e.msg!==a.KeepAliveMessage.msg)return;this._restartTimeout()}catch(e){d.error("Error in keepalive",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}_restartTimeout(){const e=setTimeout((()=>{}),this.keepaliveGrace);clearTimeout(this.timeoutId),this.timeoutId=e}start(){this.stop(),this.worker.on("message",this.eventHandler).unref()}stop(){void 0!==this.timeoutId&&clearTimeout(this.timeoutId),this.worker.off("message",this.eventHandler),this.timeoutId=void 0}}},5119:function(e,t,r){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.init=void 0;const i=o(r(6281));t.init=i.default},5994:function(e,t,r){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.MainThread=void 0;const i=r(8167),n=r(2546),s=r(6281),a=o(r(7320));function d(){globalThis.hudDeclarationsFound&&(n.app_logger.warn("Found Declarations but no metrics"),n.customer_logger.log(n.UserErrorLogs.YesDeclarationsNoMetrics()))}t.MainThread=class{apiKey;service;startTime;messenger;constructor(e,t,r){this.apiKey=e,this.service=t,this.startTime=r}startFailed(e){e instanceof n.HudSessionThrottle?(n.customer_logger.info(n.UserLogs.InitIdleMode()),(0,s._detachAndTerminate)(!1,!1)):e instanceof n.HudInitNetworkError&&e.originalAxiosErrorCode?(n.customer_logger.log((0,n.getNetworkError)(e.originalAxiosErrorCode)),(0,s._detachAndTerminate)(!1,!1)):(n.app_logger.error("Failed to start worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0}),(0,n.setFirstError)(e.code),(0,s._detachAndTerminate)())}async start(){if(i.isMainThread)if(this.messenger=await this._createMessenger(),this.messenger.runningInsideLambda)this._start().catch(this.startFailed);else try{await this._start()}catch(e){throw this.startFailed(e),e}}async _start(){if(!this.messenger)throw new n.HudInitError("Messenger not initialized");try{await this.messenger.checkWorkerInitialized(n.hudConfig.workerTimeout),await this._initDynamicConfig(),globalThis.hudMetricsIndicator=setTimeout(d,n.hudConfig.timeoutOnMetrics),globalThis.hudMetricsIndicator.unref()}catch(e){const t=e instanceof Error?e.message:void 0;if(e instanceof n.HudSessionThrottle)throw e;throw n.app_logger.error("Failed to starting worker",{msg:t}),e}await this.messenger.start()}async _createMessenger(){const e=n.myRequire.resolve(`${n.SDK_MODULE_NAME}/worker`),t={...process.env};delete t.NODE_OPTIONS;const r=new i.Worker(e,{workerData:{apiKey:this.apiKey,service:this.service,startTime:this.startTime,shouldRunLambdaExtension:globalThis.hudRuningInsideLambda,shouldCreateDeclaraionWorker:globalThis.hudRuningInsideLambda,userConfig:n.hudConfig.userConfig},execArgv:[],env:t});let o;try{o=new a.default(r),await o.checkWorker(n.hudConfig.workerTimeout)}catch(e){if(e instanceof n.HudSessionThrottle)throw n.app_logger.info("Worker started in idle mode - session throttled"),e;throw n.app_logger.error("Worker failed to start",{msg:e instanceof Error?e.message:void 0}),e}finally{r.unref()}return o}async _initDynamicConfig(){const e=await(this.messenger?.getRemoteConfig());e?(n.app_logger.info("Remote configuration exists"),n.hudConfig.dynamicConfig=(0,n.updateDynamicConfig)(e,n.hudConfig,n.app_logger),(0,n.updateInvestigationRateLimitGlobals)(),n.app_logger.info("Current dynamic configuration:",{currentDynamicConfig:n.hudConfig.dynamicConfig})):n.app_logger.info("No remote configuration - falling back to default dynamic configuration",{defaultDynamicConfig:n.hudConfig.dynamicConfig})}async terminateMessenger(){await(this.messenger?.terminateWorker()),this.messenger?.stop(),this.messenger=void 0}}},6261:e=>{e.exports=require("events")},6281:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t._detachAndTerminate=t.isValidParam=void 0;const o=r(2546),i=r(5994),n=r(2546),s=r(8528),a=r(8269),d=r(2546),c=r(7274);let l;t.default=async function(e,t){try{if(!globalThis.hudRanOnRequire)return;if(globalThis.hudRunMutex)return void o.app_logger.warn("Already ran init!");if(globalThis.hudRunMutex=!0,(0,a.clearInitGuard)(),!o.app_logger.isValid())return(0,d.setFirstError)((new d.HudBadLoggerError).code),void u(!0,!0);(0,n.updateUserConfigFromInit)(e,t);const r=(0,a.validateAndGetUserInput)();if(!r)return;if(globalThis.hudRunningMode!==s.HudRunningMode.enabled)return;o.app_logger.info("Initializing hud",{userConfig:Object.entries(n.hudConfig.userConfig).filter((([e,t])=>"DEFAULT"!==t.source))}),l=new i.MainThread(r.apiKey,r.service,globalThis.hudStartTime),await l.start(),o.customer_logger.log(d.UserLogs.HudInitSuccess()),l.messenger&&(0,d.safeCall)(o.app_logger,l.messenger.handleLogsTask())}catch(e){try{if(e instanceof d.HudSessionThrottle)return;o.app_logger.error("Something went wrong in init",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}catch(e){o.app_logger.error("Something went wrong in init & e.stack raised an exception")}u()}},t.isValidParam=function(e){return null!=e&&""!==e&&"string"==typeof e};let g=!1;function u(e=!0,t=!1){(0,a.detachHud)(e,t),l&&(0,d.safeCall)(o.app_logger,l.terminateMessenger()),globalThis.hudExtensionId&&!g&&(g=!0,(0,d.safeCall)(o.app_logger,(0,o.nextLoopDummy)(globalThis.hudExtensionId))),(0,a.clearUserIndicatorsTimeouts)(),(0,c.resetCallers)()}t._detachAndTerminate=u},6460:e=>{e.exports=require("timers/promises")},7131:e=>{e.exports=require("./wrap")},7274:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.resetCallers=t.prepCalls=t._liftExceptions=void 0;const o=r(8269),i=r(2546);function n(e){const t={};for(const r in e)t[r]=[{count:e[r]}];return t}t._liftExceptions=n,t.prepCalls=function(e,t){const r=(new Date).toISOString(),s=[];return Object.entries(hudCalls).map((([o,a])=>{Object.entries(a).forEach((([a,d])=>{Object.entries(d).forEach((([d,c])=>{try{if(0===c.sampledCount)return;const i={function_id:o,wrapped_flow_id:d||void 0,wrapped_caller_id:a||void 0,timestamp:r,timeslice:e,exceptions:n(c.exceptions),count:c.count-c.lastSentCounter,sampled_count:c.sampledCount,sum_duration:c.sum,sum_squared_duration:c.squareSum,sketch:c.sketch?t.encode(c.sketch):void 0,is_linked_function:c.isLinkedFunction};s.push(i),function(e){e.lastSentCounter=e.count,e.sampledCount=0,e.sum=0,e.squareSum=0,e.sketch=null,e.exceptions={}}(c)}catch(e){i.app_logger.error("Failed preparing invocation, skipping",{func:o,wrappedCaller:a,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}))}))})),s.length>0&&globalThis.hudDeclarationsFound&&(0,o.clearMetricsIndicator)(),s},t.resetCallers=function(){for(const t in globalThis.hudCalls)for(const r in globalThis.hudCalls[t])for(const o in globalThis.hudCalls[t][r])(e=globalThis.hudCalls[t][r][o]).lastSentCounter-=e.count,e.count=0;var e}},7320:function(e,t,r){var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,i)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return i(t,e),t};Object.defineProperty(t,"__esModule",{value:!0});const s=n(r(2546)),a=n(r(6460)),d=r(2546),c=r(8528),l=r(2546),g=r(7131),u=r(8269),h=r(2546),f=r(7274),m=r(2702),p=r(8269),v=r(2546),k=r(6281),w=r(2546),y=r(6261),C=s.app_logger,b=h.safeCall.bind(h.safeCall,C);t.default=class{worker;runningInsideLambda=!1;tsNodeUpdated=!1;abortController;workerKeepaliveGuard;constructor(e){this.worker=e,this.abortController=new AbortController,(0,y.setMaxListeners)(20,this.abortController.signal),this.worker.on("error",this.handleWorkerError).unref(),this.workerKeepaliveGuard=new m.WorkerKeepaliveGuard(e,d.hudConfig.communicationKeepaliveGrace),this._updateTsNodeConfig()&&C.info("ts-node config updated from Messenger constructor")}handleWorkerError=e=>{try{e?.code===(new h.HudClientUnauthorizedError).code&&s.customer_logger.log(h.UserErrorLogs.ApiKeyDenied(d.hudConfig.userConfig.key?.source)),C.error("Error from worker, stopping hud",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0}),(0,h.setFirstError)(e?.code),this.stop(),(0,k._detachAndTerminate)()}catch(e){C.error("Error stopping hud",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}};stop(){this.abortWorker(),d.hudConfig.communicationKeepalive&&this.workerKeepaliveGuard.stop(),this.abortController.abort(),this.abortController=new AbortController,(0,u.resetGlobals)()}abortWorker(){this._sendObject("Abort",{})}async restart(e){this.stop(),globalThis.hudRunningMode=e,await this.start()}_sendArray(e,t){t.length>0&&(this._sendObject(e,t),C.debug("sent data to worker",{msg:e,size:t.length}))}_sendObject(e,t){const r={msg:e,content:t};this.worker.postMessage(r)}async checkWorker(e){const t=["startedNoExtension","extensionRegistered"];let r;try{r=await this.getMessageFromWorker(t,e,!0)}catch(o){if(!(o instanceof h.HudTimeoutError))throw o;r=await this.getMessageFromWorker(t,e/2,!1)}if(!r)throw new h.HudInitError("Worker not started");return"extensionRegistered"===r.msg&&(this.runningInsideLambda=!0,globalThis.hudExtensionId=r.content.extensionId),r}async checkWorkerInitialized(e){let t;const r=["initialized","throttled","networkError"];try{t=await this.getMessageFromWorker(r,e,!0)}catch(o){if(!(o instanceof h.HudTimeoutError))throw o;t=await this.getMessageFromWorker(r,e/10,!1)}if("throttled"===t?.msg)throw new h.HudSessionThrottle;if("networkError"===t?.msg)throw C.error("networkError",{error:t.content.error}),new h.HudInitNetworkError(t.content.message,t.content.originalMessage);if(!t||"initialized"!==t?.msg||void 0===t?.content)throw new h.HudInitError("Worker not initialized successfully");if(t?.content.status!==c.HudSessionInitStatus.success)throw new h.HudInitError("Worker not initialized successfully");return t}async start(){switch(d.hudConfig.communicationKeepalive&&this.workerKeepaliveGuard.start(),globalThis.hudRunningMode){case c.HudRunningMode.enabled:C.info("Enabled mode"),b(this.getMode()),b(this.startPeriodicTasks()),b(this.periodicSendInvocations()),b(this.periodicSendProcessedFiles()),b(this.periodicSendEndpoints()),b(this.periodicSendFlowMetrics()),b(this.periodicSendGarphQL()),b(this.periodicSendKafkaJS()),b(this.periodicSendSqs()),b(this.periodicSendInvestigations()),b(this.resetCallerCounters()),b(this.periodicResetGlobalInvestigationCounter()),b(this.periodicResetInvestigationDedupingCache()),b(this.sendLogsPeriodically(d.hudConfig.logsSendInterval)),b(this.sendRuntime()),b(this.sendPatchedModules()),b(this.sendPreloadedModules()),b(this.dumpModulesAfterWhile(6e4)),b((0,h.loopLogThreadPerformance)(C,d.hudConfig.logPerfInterval,this.abortController.signal));break;case c.HudRunningMode.disabled:C.info("Disabled mode"),b(this.getMode());break;case c.HudRunningMode.detached:C.info("Detached"),(0,k._detachAndTerminate)(!1,!1),this.stop();break;default:C.error("Running mode not handled")}}async getMessageFromWorker(e,t,r=!1,o){let i;e=Array.isArray(e)?e:[e];const n=new AbortController,s=()=>{n.abort()};this.abortController.signal.addEventListener("abort",s);const d=a.setTimeout(t,void 0,{signal:n.signal,ref:r}),c=t=>{try{e.includes(t.msg)&&(i=t,n.abort(),C.info("Received message from worker (canceling timeout)",t))}catch(e){C.error("Failed handling message from worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}};this.worker.on("message",c).unref(),o&&this.worker.postMessage(o);try{throw await d,C.warn("Timeout waiting for message from worker"),new h.HudTimeoutError}catch(e){if(!(0,h.isAbortError)(e))throw(0,h.setFirstError)(e.code),e}finally{this.abortController.signal.removeEventListener("abort",s),this.worker.off("message",c)}return i}async getMode(){for await(const e of(0,l.unrefSetInterval)(d.hudConfig.modeInterval,void 0,{signal:this.abortController.signal}))try{const e={msg:"GetMode",content:{startTime:globalThis.hudStartTime,runningMode:globalThis.hudRunningMode}},t=await this.getMessageFromWorker(e.msg,d.hudConfig.workerMessageTimeout,!1,e);if(t?.msg!==e.msg||void 0===t?.content.mode){C.error("Unexpected message from worker",t);continue}t.content.mode!==globalThis.hudRunningMode&&await this.restart(t?.content.mode)}catch(e){C.error("Failed getting mode from worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async getRemoteConfig(){const e="initDynamicConfig";try{const t=await this.getMessageFromWorker(e,d.hudConfig.workerMessageTimeout,!0);if(t?.msg!==e||void 0===t?.content)throw new Error(`Unexpected message from worker: ${t}`);return t?.content}catch(e){C.error("Failed getting remote configuration from worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async resetCallerCounters(){const e=d.hudConfig.callerResetInterval;for await(const t of(0,l.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))try{C.info("Resetting caller",{interval:e}),(0,f.resetCallers)()}catch(e){C.error("Failed reseting caller counters",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async periodicSendProcessedFiles(){const e=d.hudConfig.dynamicConfig.aggregationFirstSendTimeout,t=d.hudConfig.dynamicConfig.aggregationInterval;let r=!0;await this.setupPeriodicTask(e,t,(()=>{if(r){r=!1;try{this._updateTsNodeConfig()&&C.info("ts-node config updated from periodicSendProcessedFiles")}catch{return!1}}const e=function(){const e=globalThis.hudProcessedFiles;return globalThis.hudProcessedFiles=[],e}();return this._sendArray("ProcessedFiles",e),!0}),"periodicSendProcessedFiles")}async periodicSendInvocations(){const e=new g.SketchManager(d.hudConfig.huddBinWidth),t=d.hudConfig.dynamicConfig.aggregationFirstSendTimeout,r=d.hudConfig.dynamicConfig.aggregationInterval;await this.setupPeriodicTask(t,r,(t=>{const r=(0,f.prepCalls)(t,e);return this._sendArray("Invocations",r),!0}),"periodicSendInvocations")}async periodicSendFlowMetrics(){const e=d.hudConfig.dynamicConfig.flowMetricFirstSendTimeout,t=d.hudConfig.dynamicConfig.flowMetricInterval;await this.setupPeriodicTask(e,t,(e=>{const t=(0,u.getFlowMetrics)();return t.length>0&&this._sendObject("FlowMetrics",{timeslice:e,rawMetrics:t}),!0}),"periodicSendFlowMetrics")}async periodicSendGarphQL(){const e=d.hudConfig.dynamicConfig.aggregationFirstSendTimeout,t=d.hudConfig.dynamicConfig.aggregationInterval;await this.setupPeriodicTask(e,t,(()=>(this.sendGraphQLResolvers(),this.sendGraphQLDocuments(),!0)),"periodicSendGarphQL")}async periodicSendKafkaJS(){const e=d.hudConfig.dynamicConfig.aggregationFirstSendTimeout,t=d.hudConfig.dynamicConfig.aggregationInterval;await this.setupPeriodicTask(e,t,(()=>{const e=(0,p.getKafkaJSTopics)();return this._sendArray("KafkaJSTopics",e),!0}),"periodicSendKafkaJS")}async periodicSendSqs(){const e=d.hudConfig.dynamicConfig.aggregationFirstSendTimeout,t=d.hudConfig.dynamicConfig.aggregationInterval;await this.setupPeriodicTask(e,t,(()=>{const e=(0,p.getSqsQueues)();return e.length>0&&this._sendArray("SqsQueue",e),!0}),"periodicSendSqs")}async periodicSendInvestigations(){const e=d.hudConfig.dynamicConfig.aggregationInterval;for await(const t of(0,l.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))try{const e=(0,p.getClosedInvestigations)();this._sendArray("Investigations",e)}catch(e){C.error("Failed sending Investigations to worker, skipping",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}sendGraphQLResolvers(){try{const e=(0,p.getResolversDeclarations)().map((e=>({id:e.id,operation:e.operation,name:e.name})));this._sendArray("GraphQLResolvers",e)}catch(e){C.error("Failed sending resolvers to worker, skipping",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}sendGraphQLDocuments(){try{const e=(0,p.getDocumentsMetadata)().map((e=>({name:e.name,hash:e.hash,selection_names:e.selectionNames,time_took:e.timeTook})));this._sendArray("GraphQLDocuments",e)}catch(e){C.error("Failed sending documents to worker, skipping",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async periodicSendEndpoints(){const e=d.hudConfig.endpointsFirstSendWaitTime,t=d.hudConfig.endpointsInterval;await this.setupPeriodicTask(e,t,(()=>(this.sendEndpoints(),!0)),"periodicSendEndpoints")}sendEndpoints(){const e=(0,p.getExpressEndpointDeclarations)(),t=(0,u.getKoaEndpointDeclarationsFromStorage)(),r=e.concat(t).map((e=>({path:e.path,methods:e.methods,flow_id:e.flow_id,framework:e.framework,partial_path:e.partial_path})));this._sendArray("EndpointDeclaration",r)}async terminateWorker(){try{const e=(0,v.suppressTraces)(s.renewFileTransports),t=s.getSavedLogs(),r=e();await this.getMessageFromWorker("terminated",d.hudConfig.workerGrace,!1,{msg:"Terminate",content:{grace:d.hudConfig.workerGrace,logBuffers:t,logFiles:Array.from(r)}})}catch(e){if(!(e instanceof h.HudTimeoutError))throw C.error("Unexpected error, terminating worker"),await this.worker.terminate(),e;C.error("Grace period timeout, terminating worker"),await this.worker.terminate()}C.info("Worker terminated successfully.")}async sendRuntime(){const e={nodeVersion:process.version,nodeDependencyVersions:process.versions,platform:process.platform,architecture:process.arch,pid:process.pid,cwd:process.cwd(),execPath:process.execPath,execArgv:process.execArgv,argv:process.argv,uptime:process.uptime(),mainModulePath:r.c[r.s]?.filename};this._sendObject("Runtime",e)}async startPeriodicTasks(){this._sendObject("StartPeriodicTasks",{})}async sendPreloadedModules(){globalThis.hudLoadedModules?this._sendObject("PreInitLoadedModules",{modules:globalThis.hudLoadedModules}):C.warn("Didn't get module, weird....")}async dumpModulesAfterWhile(e){await(0,l.unrefSetTimeout)(e,void 0,{signal:this.abortController.signal});const t=Object.keys(v.myRequire.cache);this._sendObject("PostInitLoadedModules",{modules:t})}async sendPatchedModules(){if(!globalThis.hudPatched)return void C.error("Cant find patched modules");const e=Array.from(globalThis.hudPatched);this._sendObject("PatchedModules",{modules:e})}async handleLogsTask(){try{const e=(0,v.suppressTraces)(s.renewFileTransports),t=s.getSavedLogs();for(const e of t)try{this._sendObject("Logs",{logs:e})}catch(e){C.error("Failed send logs to worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}const r=e();r.size>0&&this._sendObject("LogFilename",{filenames:r})}catch(e){C.error("Failed send logs to worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async sendLogsPeriodically(e){for await(const t of(0,l.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))await this.handleLogsTask()}async setupPeriodicTask(e,t,r,o){function i(e){let t=!0;try{t=r(e)}catch(e){C.error("Failed in periodic task",{taskName:o,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t}if(await(0,l.unrefSetTimeout)(e,void 0,{signal:this.abortController.signal}),i(e)){for await(const e of(0,l.unrefSetInterval)(t,void 0,{signal:this.abortController.signal}))if(!i(t))return void C.warn("Periodic task failed, stopping task",{firstRun:!1,taskName:o})}else C.warn("Periodic task failed, stopping task",{firstRun:!0,taskName:o})}async periodicResetGlobalInvestigationCounter(){const e=d.hudConfig.dynamicConfig.investigationRateLimits.totalInvestigationTimeWindowMs;for await(const t of(0,l.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))try{C.info("Resetting global investigation counter",{interval:e}),(0,p.setGlobalInvestigationTracking)(0)}catch(e){C.error("Failed resetting global investigation counter",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async periodicResetInvestigationDedupingCache(){const e=d.hudConfig.dynamicConfig.investigationRateLimits.sameInvestigationTimeWindowMs;for await(const t of(0,l.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))try{C.info("Resetting investigation deduping cache",{interval:e}),(0,p.resetInvestigationDedupingCache)()}catch(e){C.error("Failed resetting investigation deduping cache",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}_updateTsNodeConfig(){if(this.tsNodeUpdated)return!1;try{const e=(0,w.getUserTsNodeConfig)();return!!e&&(this.tsNodeUpdated=!0,C.info("tsconfig found, sending config to worker"),this._sendObject("TsNodeConfig",{tsConfig:e}),!0)}catch(e){throw this.tsNodeUpdated=!0,this.stop(),e instanceof h.HudError&&(0,h.setFirstError)(e.code),(0,k._detachAndTerminate)(!1),e}}}},8167:e=>{e.exports=require("worker_threads")},8269:e=>{e.exports=require("./globalstate")},8528:e=>{e.exports=require("./dto")}},t={};function r(o){var i=t[o];if(void 0!==i)return i.exports;var n=t[o]={exports:{}};return e[o].call(n.exports,n,n.exports,r),n.exports}return r.c=t,r(r.s=5119)})())); //# sourceMappingURL=core.js.map