UNPKG

@onboardbase/cli

Version:

[![Version](https://img.shields.io/npm/v/@onboardbase/cli.svg)](https://www.npmjs.com/package/@onboardbase/cli) [![Downloads/week](https://img.shields.io/npm/dw/@onboardbase/cli.svg)](https://www.npmjs.com/package/@onboardbase/cli) [![License](https://img

47 lines (46 loc) 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LogoutCommandService = void 0; const config_1 = require("../config"); const chalk = require("chalk"); const inquirer = require("inquirer"); const base_service_1 = require("../common/base.service"); const unauthorized_error_1 = require("../common/errors/unauthorized.error"); class LogoutCommandService extends base_service_1.BaseService { async initialize() { const choices = []; const scopes = this.configManager.getFromGlobal("scoped"); Object.keys(scopes).map((key) => choices.push(key)); const scopeWithTokens = Object.keys(scopes).filter((scope) => scopes[scope].token); if (!scopeWithTokens.length) { throw unauthorized_error_1.UnauthorizedError.from("You seem to be logged out already, please run " + chalk.bold.green("onboardbase login") + " to securely manage your secrets"); } const { project } = await inquirer.prompt({ type: "list", message: "Revoke auth token scoped to", choices, name: "project", }); const projectToken = this.configManager.getFromGlobal(`scoped.${project}.token`); const { shouldRevoke } = await inquirer.prompt({ type: "list", message: `Are you sure you want to revoke auth token scoped to (${project})`, choices: ["Yes", "No"], default: "No", name: "shouldRevoke", }); if (shouldRevoke === "Yes") { const tokenIsRefPath = scopes[project].token === config_1.REFPATH_VALUE; if (!tokenIsRefPath) await this.httpInstance.revokeAuthToken(projectToken); this.configManager.setGlobal(`scoped.${project}`, undefined); console.log(chalk.bold.green("√ Auth token has been revoked")); } if (shouldRevoke === "No") { console.log("Aborting..."); } } } exports.LogoutCommandService = LogoutCommandService;