UNPKG

@shipengine/connect

Version:

The official developer tooling for building ShipEngine connect apps

72 lines 2.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const base_command_1 = tslib_1.__importDefault(require("./base-command")); const api_client_1 = require("./core/api-client"); const login_1 = tslib_1.__importDefault(require("./commands/login")); const command_1 = require("@oclif/command"); const app_loader_1 = require("./core/app-loader"); const unauthenticated_error_1 = require("./core/unauthenticated-error"); /** * Base class for commands that operate on an existing app with a logged in user */ class AppBaseCommand extends base_command_1.default { static flags = { debug: command_1.flags.boolean({ char: 'd', description: 'Show network debugging information', default: false, hidden: true, }), }; client; platformApp; async init() { const { flags } = this.parse(this.constructor); if (isBaseAppFlagType(flags)) { try { await this.getCurrentUser(flags.debug); } catch (error) { if (error instanceof unauthenticated_error_1.UnauthenticatedError) { await login_1.default.run([]); } else { return this.error(error, { exit: 1, }); } } try { const pathToApp = process.cwd(); const app = await (0, app_loader_1.loadApp)(pathToApp); this.client = await this.apiClient(flags.debug); this.platformApp = await this.client.apps.getByIdOrName(app.manifest.name, app.manifest.appId); } catch (error) { switch (error.code) { case 'ERR_APP_ERROR': return this.error('Error loading your app - please make sure you are in an app directory', { exit: 1, }); case api_client_1.ApiClientErrors.NotFound: return this.error('This app has not been published yet', { exit: 1, }); default: return this.error(error, { exit: 1, }); } } } } } exports.default = AppBaseCommand; function isBaseAppFlagType(flags) { if (typeof flags === 'object' && flags && 'debug' in flags) { return true; } return false; } //# sourceMappingURL=base-app-command.js.map