UNPKG

@contentstack/cli-auth

Version:

Contentstack CLI plugin for authentication activities

54 lines (53 loc) 2.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseCommand = void 0; const cli_command_1 = require("@contentstack/cli-command"); const cli_utilities_1 = require("@contentstack/cli-utilities"); class BaseCommand extends cli_command_1.Command { /** * The `init` function initializes the command by parsing arguments and flags, registering search * plugins, registering the configuration, and initializing the logger. */ async init() { await super.init(); this.contextDetails = Object.assign({}, this.createExportContext()); } /** * The catch function is used to handle errors from a command, either by adding custom logic or * returning the parent class error handling. * @param err - The `err` parameter is of type `Error & { exitCode?: number }`. This means that it is * an object that extends the `Error` class and may also have an optional property `exitCode` of type * `number`. * @returns The parent class error handling is being returned. */ async catch(err) { // add any custom logic to handle errors from the command // or simply return the parent class error handling return super.catch(err); } /** * The `finally` function is called after the `run` and `catch` functions, regardless of whether or not * an error occurred. * @param {Error | undefined} _ - The parameter "_" represents an error object or undefined. * @returns The `finally` method is returning the result of calling the `finally` method of the * superclass, which is a promise. */ async finally(_) { // called after run and catch regardless of whether or not the command errored return super.finally(_); } // Create export context object createExportContext(apiKey) { var _a, _b, _c; return { command: ((_b = (_a = this.context) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.command) || 'auth', module: '', userId: cli_utilities_1.configHandler.get('userUid') || '', email: cli_utilities_1.configHandler.get('email') || '', sessionId: (_c = this.context) === null || _c === void 0 ? void 0 : _c.sessionId, apiKey: apiKey || '', orgId: cli_utilities_1.configHandler.get('oauthOrgUid') || '', }; } } exports.BaseCommand = BaseCommand;