@onboardbase/cli
Version:
[](https://www.npmjs.com/package/@onboardbase/cli) [](https://www.npmjs.com/package/@onboardbase/cli) [ • 1.87 kB
JavaScript
;
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;