diff --git a/src/commands/login.ts b/src/commands/login.ts index a1e056e..6ce02cf 100644 --- a/src/commands/login.ts +++ b/src/commands/login.ts @@ -9,7 +9,7 @@ import { writeToken } from "../lib/token"; /** * @description Set the TagoIO deploy URL. */ -async function setTagoDeployUrl() { +async function setTagoDeployUrl(): Promise<{ urlAPI: string; urlSSE: string } | undefined> { const { tagoDeployUrl } = await prompts({ message: "Do you want to pass on the tagoDeploy URL?", type: "confirm", @@ -20,13 +20,15 @@ async function setTagoDeployUrl() { } const { urlAPI } = await prompts({ type: "text", name: "urlAPI", message: "Set the URL for the API service: " }); - if (urlAPI) { - process.env.TAGOIO_API = urlAPI; + if (!urlAPI) { + return; } - console.info(process.env.TAGOIO_API); + const urlSSE = urlAPI.replace("https://api.", "https://sse.").replace(".tago-io.net", ".tago-io.net/events"); + process.env.TAGOIO_API = urlAPI; + process.env.TAGOIO_SSE = urlSSE; - return urlAPI; + return { urlAPI, urlSSE }; } function writeCustomToken(environment: string, token: string) { @@ -39,6 +41,7 @@ interface LoginOptions { password?: string; token?: string; tagoDeployUrl?: string; + tagoDeploySse?: string; } /** @@ -91,8 +94,9 @@ async function loginWithEmailPassword(email: string, password: string) { } async function tagoLogin(environment: string, options: LoginOptions) { - const tagoDeployUrl = await setTagoDeployUrl(); - options.tagoDeployUrl = tagoDeployUrl; + const tagoDeploy = await setTagoDeployUrl(); + options.tagoDeployUrl = tagoDeploy?.urlAPI; + options.tagoDeploySse = tagoDeploy?.urlSSE; if (options.token) { return writeCustomToken(environment, options.token); diff --git a/src/commands/start-config.ts b/src/commands/start-config.ts index 3e2a817..4dba55a 100644 --- a/src/commands/start-config.ts +++ b/src/commands/start-config.ts @@ -34,10 +34,10 @@ async function createEnvironmentToken(environment: string) { } infoMSG(`You can create a token by running: ${highlightMSG("tagoio login")}`); - const options = { token: undefined, tagoDeployUrl: undefined }; + const options = { token: undefined, tagoDeployUrl: undefined, tagoDeploySse: undefined }; await tagoLogin(environment, options); - return { profileToken: options.token, tagoDeployUrl: options?.tagoDeployUrl }; + return { profileToken: options.token, tagoDeployUrl: options?.tagoDeployUrl, tagoDeploySse: options?.tagoDeploySse }; } /** @@ -155,6 +155,7 @@ async function startConfig(environment: string, { token }: ConfigOptions) { const data = await createEnvironmentToken(environment); token = data?.profileToken; configFile.tagoDeployUrl = data?.tagoDeployUrl || ""; + configFile.tagoDeploySse = data?.tagoDeploySse || ""; } } else { writeToken(token, environment); @@ -169,10 +170,6 @@ async function startConfig(environment: string, { token }: ConfigOptions) { configFile.buildPath = await promptTextToEnter(`Enter the path of your ${kleur.cyan("building")} folder (typescript): `, "./build"); } - if (!configFile.tagoDeploySse) { - configFile.tagoDeploySse = ""; - } - // Return if token is not found if (!token) { return;