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

43 lines (42 loc) 1.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DestroyCommandService = void 0; const chalk = require("chalk"); const base_service_1 = require("../common/base.service"); const inquirer = require("inquirer"); const unauthorized_error_1 = require("../common/errors/unauthorized.error"); class DestroyCommandService extends base_service_1.BaseService { async initialize() { const scopes = this.configManager.getFromGlobal("scoped"); 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 { option } = await inquirer.prompt({ type: "list", default: "No", choices: ["Yes", "No"], message: "Are you sure you want to destroy all onboardbase config files", name: "option", }); if (option === "Yes") { const tokens = []; Object.keys(scopes).map((key) => tokens.push({ token: scopes[key].token, project: key })); try { await Promise.all(tokens.map(async ({ token, project }) => { console.log(chalk.green(`Revoking auth token for ${chalk.bold.green(project)}...`)); await this.httpInstance.revokeAuthToken(token); this.configManager.setGlobal(`scoped.${project}`, undefined); })); } catch (error) { } this.configManager.destroy(); } else { console.log("Aborting..."); } } } exports.DestroyCommandService = DestroyCommandService;