@unito/integration-cli
Version:
Integration CLI
81 lines (80 loc) • 3.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
const baseCommand_1 = require("../baseCommand");
const errors_1 = require("../errors");
const integrations_1 = require("../resources/integrations");
const GlobalConfiguration = tslib_1.__importStar(require("../resources/globalConfiguration"));
const IntegrationsPlatform = tslib_1.__importStar(require("../services/integrationsPlatform"));
const IntegrationConfiguration = tslib_1.__importStar(require("../resources/configuration"));
class Invite extends baseCommand_1.BaseCommand {
static description = 'Invite a user to become a developer of your integration';
static examples = ['<%= config.bin %> <%= command.id %>'];
static flags = {
environment: core_1.Flags.custom({
description: 'the environment of the platform',
options: Object.values(GlobalConfiguration.Environment),
default: GlobalConfiguration.Environment.Production,
})(),
};
async catch(error) {
/* istanbul ignore if */
if ((0, errors_1.handleError)(this, error)) {
this.exit(-1);
}
throw error;
}
async run() {
(0, integrations_1.validateIsIntegrationDirectory)();
const { flags } = await this.parse(Invite);
// Read the configurations.
const globalConfiguration = await GlobalConfiguration.read(this.config.configDir);
const environment = flags.environment ?? GlobalConfiguration.Environment.Production;
const integrationConfiguration = await IntegrationConfiguration.getConfiguration(environment);
// Choose the right API key for the environment.
let apiKey = undefined;
if (environment === GlobalConfiguration.Environment.Local) {
apiKey = globalConfiguration.apiKeyLocal;
}
else if (environment === GlobalConfiguration.Environment.Staging) {
apiKey = globalConfiguration.apiKeyStaging;
}
else {
apiKey = globalConfiguration.apiKey;
}
// Setup the platform client.
IntegrationsPlatform.setApiKey(apiKey);
IntegrationsPlatform.setEnvironment(environment);
const { email } = await inquirer_1.default.prompt([
{
name: 'email',
message: 'Type the email of the user you wish to invite:',
type: 'input',
},
]);
core_1.ux.action.start('Finding the integration', undefined, { stdout: true });
let integration;
try {
integration = await IntegrationsPlatform.getIntegrationByName(integrationConfiguration.name);
}
catch (error) {
if (error instanceof IntegrationsPlatform.HttpError && error.status === 403) {
core_1.ux.log(chalk_1.default.redBright(`Access Denied! You do not have access to this integration.`));
this.exit(-1);
}
else {
core_1.ux.log(chalk_1.default.redBright(`Integration not found! You can only invite users to a published integration.`));
this.exit(-1);
}
}
core_1.ux.action.stop();
core_1.ux.action.start('Inviting user', undefined, { stdout: true });
await IntegrationsPlatform.inviteUserToIntegration(integration.id, email);
core_1.ux.action.stop();
core_1.ux.log(`User successfully added! They should now be able to update and publish this integration.`);
}
}
exports.default = Invite;