UNPKG

@commercelayer/cli

Version:
52 lines (51 loc) 2.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const base_1 = tslib_1.__importStar(require("../../base")); const config_1 = tslib_1.__importStar(require("../../config")); const cli_core_1 = require("@commercelayer/cli-core"); class ApplicationsLogout extends base_1.default { static description = 'remove an application from CLI local configuration'; static aliases = ['app:logout', 'app:remove', 'applications:remove', 'logout']; static flags = { revoke: base_1.Flags.boolean({ char: 'r', description: 'revoke current access token' }), force: base_1.Flags.boolean({ char: 'F', description: 'force application removal without user confirmation', hidden: true }) }; async run() { const { flags } = await this.parse(ApplicationsLogout); const app = this.appFilterEnabled(flags) ? await this.findApplication(flags) : (0, config_1.currentApplication)(); if (app && (0, config_1.configFileExists)(this.config, app)) { this.log(); const ok = flags.force || await base_1.cliux.ux.confirm(`>> Do you really want to remove application ${cli_core_1.clColor.api.application(app.name)} of ${cli_core_1.clColor.api.organization(app.organization)} from CLI configuration? ${cli_core_1.clColor.dim('[Yy/Nn]')}`); if (ok) { if ((0, config_1.tokenFileExists)(this.config, app)) { // Revoke current access token if (flags.revoke) { const configData = (0, config_1.readConfigFile)(this.config, app); const tokenData = (0, config_1.readTokenFile)(this.config, app); await cli_core_1.clToken.revokeAccessToken(configData, tokenData.accessToken); this.log('\nCurrent access token has been revoked'); } (0, config_1.deleteTokenFile)(this.config, app); if (cli_core_1.clApplication.appKeyMatch(app, (0, config_1.currentApplication)())) config_1.default.delete(config_1.ConfigParams.currentApplication); } (0, config_1.deleteConfigFile)(this.config, app); this.log(`\n${cli_core_1.clColor.msg.success('Successfully')} removed application ${cli_core_1.clColor.api.application(app.name)}`); } this.log(); } else this.error('Unable to find application to logout', { suggestions: [`Execute command ${cli_core_1.clColor.cli.command(`${this.config.bin} applications`)} to get a list of all the available active applications`], }); } } exports.default = ApplicationsLogout;