@supernovaio/cli
Version:
Supernova.io Command Line Interface
74 lines (72 loc) ⢠3.43 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]="a02834d3-1815-5c6c-85da-2de716666fac")}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 open from "open";
import pkceChallenge from "pkce-challenge";
import { z } from "zod";
import { AuthService, VaultService } from "../services/index.js";
import { commonFlags, getTargetEnv, SentryCommand } from "../types/index.js";
export default class Login extends SentryCommand {
static args = {};
static description = "Login to the Supernova";
static examples = ["<%= config.bin %> <%= command.id %>"];
static flags = commonFlags;
authService = new AuthService();
vaultService = new VaultService();
get commandId() {
return Login.id;
}
get configSchema() {
return z.object({});
}
async run() {
const env = getTargetEnv();
const { code_challenge: codeChallenge, code_verifier: codeVerifier } = await pkceChallenge();
this.log("\nš Authentication Process\n".green);
this.log("1. Opening browser for authentication...");
const { authorizeUrl, readKey } = await this.authService.getAuthUrlFromServer(env, codeChallenge);
await this.openBrowser(authorizeUrl);
this.log("2. Waiting for authentication to complete...");
const tokens = await this.authService.getTokensFromServer(env, codeVerifier, readKey);
if (tokens) {
this.log("3. Login successful!");
this.log("4. Storing tokens...");
await this.vaultService.storeTokensToVault(tokens, env);
this.log("5. You are now logged in".green);
}
else {
this.log("3. Login timed out".red);
}
}
async openBrowser(url) {
try {
await open(url);
}
catch {
this.log("Unable to open browser automatically - please visit the URL manually");
this.log(`\u001B[4m\u001B[34m${url}\u001B[0m\n`);
}
}
}
__decorate([
SentryTraced(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], Login.prototype, "run", null);
__decorate([
SentryTraced(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], Login.prototype, "openBrowser", null);
//# sourceMappingURL=login.js.map
//# debugId=a02834d3-1815-5c6c-85da-2de716666fac