@supernovaio/cli
Version:
Supernova.io Command Line Interface
68 lines (66 loc) • 3.57 kB
JavaScript
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="e882d651-9ed2-57b7-8758-17ac93858321")}catch(e){}}();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { SentryTraced } from "@sentry/nestjs";
import { RequestExecutorError, SupernovaApiClient } from "@supernova-studio/client";
import { z } from "zod";
import { VaultService } from "../services/vault.service.js";
import { apiHostForEnvironment, commonFlags, getTargetEnv, SentryCommand } from "../types/index.js";
export default class WhoAmICommand extends SentryCommand {
static args = {};
static description = "Print information about currently logged in user";
static examples = ["<%= config.bin %> <%= command.id %>"];
static flags = commonFlags;
get commandId() {
return WhoAmICommand.id;
}
get configSchema() {
return z.object({});
}
async run() {
const env = getTargetEnv();
const accessToken = await this.getAccessTokenOrExit(env);
const user = await this.getUserOrExit(env, accessToken);
this.log(`Logged in as ${user.email}`);
}
async getAccessTokenOrExit(env) {
const vaultService = new VaultService();
const tokens = await vaultService.tryGetTokensFromVault(env);
if (!tokens) {
this.error("No active user session found. To log in try one of the following:\n" +
" - run `supernova login` to authenticate in browser\n" +
" - provide SUPERNOVA_TOKEN variable with a personal access token (can be generated in user profile settings)");
}
return tokens.accessToken;
}
async getUserOrExit(env, accessToken) {
const apiClient = new SupernovaApiClient({ accessToken, host: apiHostForEnvironment(env) });
try {
const { user } = await apiClient.users.getMe();
return user;
}
catch (error) {
if (error instanceof RequestExecutorError && error.type === "ServerError") {
this.error("Current session has expired or has been revoked. To start a new session try one of the following:\n" +
" - run `supernova login` to authenticate in browser\n" +
" - provide SUPERNOVA_TOKEN variable with a personal access token (can be generated in user profile settings)");
}
throw error;
}
}
}
__decorate([
SentryTraced(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], WhoAmICommand.prototype, "run", null);
//# sourceMappingURL=whoami.js.map
//# debugId=e882d651-9ed2-57b7-8758-17ac93858321