@cto.ai/ops-rc
Version:
💻 CTO.ai Ops - The CLI built for Teams 🚀
63 lines (62 loc) • 2.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const sdk_1 = require("@cto.ai/sdk");
const base_1 = tslib_1.__importStar(require("./../../base"));
const CustomErrors_1 = require("./../../errors/CustomErrors");
const utils_1 = require("./../../utils");
class AccountSignout extends base_1.default {
constructor() {
super(...arguments);
this.checkForAccessToken = async () => {
if (!this.accessToken) {
throw new CustomErrors_1.AlreadySignedOut();
}
};
this.startSpinner = () => {
this.log('');
sdk_1.ux.spinner.start(`${sdk_1.ux.colors.white('Signing out of ')}${sdk_1.ux.colors.actionBlue('CTO.ai ops')}`);
};
this.signUserOut = async () => {
try {
await this.clearConfig();
const { tokens } = await this.readConfig();
if (tokens && tokens.accessToken) {
throw new CustomErrors_1.SignOutError(null);
}
}
catch (err) {
throw new CustomErrors_1.SignOutError(err);
}
};
this.stopSpinner = () => {
sdk_1.ux.spinner.stop(`${sdk_1.ux.colors.green('Done!')}`);
this.log('');
};
this.logMessage = () => {
this.log(`${sdk_1.ux.colors.green('✓')} Signed out! Type \'ops ${sdk_1.ux.colors.actionBlue('account:signin')}\' to sign back into your account.\n`);
};
this.sendAnalytics = () => {
this.services.analytics.track('Ops CLI Signout', {
username: this.user.username,
}, this.state.config);
};
}
async run() {
this.parse(AccountSignout);
try {
const signoutPipeline = utils_1.asyncPipe(this.checkForAccessToken, this.startSpinner, this.signUserOut, this.stopSpinner, this.logMessage, this.sendAnalytics, this.invalidateKeycloakSession);
await signoutPipeline();
}
catch (err) {
sdk_1.ux.spinner.stop(`${sdk_1.ux.colors.errorRed('Failed!')}`);
this.debug('%O', err);
this.config.runHook('error', { err, accessToken: this.accessToken });
}
}
}
exports.default = AccountSignout;
AccountSignout.description = 'Log out from your account.';
AccountSignout.flags = {
help: base_1.flags.help({ char: 'h' }),
};