{"version":3,"file":"notification.mjs","sources":["../../src/services/notification.ts"],"sourcesContent":["import EventSource from 'eventsource';\nimport type { CLIContext, CloudCliConfig } from '../types';\n\ntype Event = {\n type: string;\n data: string;\n lastEventId: string;\n origin: string;\n};\n\nexport function notificationServiceFactory({ logger }: CLIContext) {\n return (url: string, token: string, cliConfig: CloudCliConfig) => {\n const CONN_TIMEOUT = Number(cliConfig.notificationsConnectionTimeout);\n\n const es = new EventSource(url, {\n headers: {\n Authorization: `Bearer ${token}`,\n },\n });\n let timeoutId: NodeJS.Timeout;\n\n const resetTimeout = () => {\n clearTimeout(timeoutId);\n timeoutId = setTimeout(() => {\n logger.log(\n 'We were unable to connect to the server at this time. This could be due to a temporary issue. Please try again in a moment.'\n );\n es.close();\n }, CONN_TIMEOUT); // 5 minutes\n };\n\n es.onopen = resetTimeout;\n es.onmessage = (event: Event) => {\n resetTimeout();\n const data = JSON.parse(event.data);\n\n if (data.message) {\n logger.log(data.message);\n }\n\n // Close connection when a specific event is received\n if (data.event === 'deploymentFinished' || data.event === 'deploymentFailed') {\n es.close();\n }\n };\n };\n}\n"],"names":["notificationServiceFactory","logger","url","token","cliConfig","CONN_TIMEOUT","Number","notificationsConnectionTimeout","es","EventSource","headers","Authorization","timeoutId","resetTimeout","clearTimeout","setTimeout","log","close","onopen","onmessage","event","data","JSON","parse","message"],"mappings":";;AAUO,SAASA,0BAAAA,CAA2B,EAAEC,MAAM,EAAc,EAAA;IAC/D,OAAO,CAACC,KAAaC,KAAeC,EAAAA,SAAAA,GAAAA;QAClC,MAAMC,YAAAA,GAAeC,MAAOF,CAAAA,SAAAA,CAAUG,8BAA8B,CAAA;QAEpE,MAAMC,EAAAA,GAAK,IAAIC,WAAAA,CAAYP,GAAK,EAAA;YAC9BQ,OAAS,EAAA;AACPC,gBAAAA,aAAAA,EAAe,CAAC,OAAO,EAAER,KAAAA,CAAM;AACjC;AACF,SAAA,CAAA;QACA,IAAIS,SAAAA;AAEJ,QAAA,MAAMC,YAAe,GAAA,IAAA;YACnBC,YAAaF,CAAAA,SAAAA,CAAAA;AACbA,YAAAA,SAAAA,GAAYG,UAAW,CAAA,IAAA;AACrBd,gBAAAA,MAAAA,CAAOe,GAAG,CACR,6HAAA,CAAA;AAEFR,gBAAAA,EAAAA,CAAGS,KAAK,EAAA;AACV,aAAA,EAAGZ;AACL,SAAA;AAEAG,QAAAA,EAAAA,CAAGU,MAAM,GAAGL,YAAAA;QACZL,EAAGW,CAAAA,SAAS,GAAG,CAACC,KAAAA,GAAAA;AACdP,YAAAA,YAAAA,EAAAA;AACA,YAAA,MAAMQ,IAAOC,GAAAA,IAAAA,CAAKC,KAAK,CAACH,MAAMC,IAAI,CAAA;YAElC,IAAIA,IAAAA,CAAKG,OAAO,EAAE;gBAChBvB,MAAOe,CAAAA,GAAG,CAACK,IAAAA,CAAKG,OAAO,CAAA;AACzB;;AAGA,YAAA,IAAIH,KAAKD,KAAK,KAAK,wBAAwBC,IAAKD,CAAAA,KAAK,KAAK,kBAAoB,EAAA;AAC5EZ,gBAAAA,EAAAA,CAAGS,KAAK,EAAA;AACV;AACF,SAAA;AACF,KAAA;AACF;;;;"}