fedapay-cli
Version:
A command-line tool for FedaPay
86 lines (85 loc) • 2.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const command_1 = require("@oclif/command");
const cli_ux_1 = tslib_1.__importDefault(require("cli-ux"));
const fedapay_1 = require("fedapay");
const json_colorizer_1 = tslib_1.__importDefault(require("json-colorizer"));
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const webhooks_1 = tslib_1.__importDefault(require("../webhooks"));
const dataparse_1 = tslib_1.__importDefault(require("../../helpers/dataparse"));
/*
* WebhookCreate Class extending the superClass Webhooks
*/
class WebhooksCreate extends webhooks_1.default {
async run() {
/**
* @param object
* get flags value
*/
const { flags } = this.parse(WebhooksCreate);
/**
* @param String
* your api's key
*/
const apiKey = this.userConfig.read('secret_key', flags['api-key']);
/**
* @param String
* sandbox or live
*/
const environment = this.userConfig.read('environment', flags.environment);
/**
* @param Object
* The data obtained after transformation
*/
const data = dataparse_1.default.transform(flags.data);
/**
* Set Apikey and environment to connect to fedapay
*/
fedapay_1.FedaPay.setApiKey(apiKey);
fedapay_1.FedaPay.setEnvironment(environment);
try {
/**
* @param Webhook
* Created webhook
*/
cli_ux_1.default.action.start('Retrieve webhook');
const webhook = await fedapay_1.Webhook.create(data);
this.log(chalk_1.default.green('Webhook created successfully!'));
this.log(json_colorizer_1.default(JSON.stringify(webhook, null, 2)));
}
catch (error) {
this.log('Oups something occured');
this.error(error.message);
}
cli_ux_1.default.action.stop();
}
}
exports.default = WebhooksCreate;
/**
* @params String
* Description of the command webhooks:create
*/
WebhooksCreate.description = 'Create a new webhook.';
/**
* The command usage
* @var string
*/
WebhooksCreate.usage = 'webhooks:create [options]';
/**
* @params Object
* Insertion of the different commands flags
*/
WebhooksCreate.flags = Object.assign(Object.assign({}, webhooks_1.default.flags), { data: command_1.flags.string({
char: 'd',
description: 'Data for the API request.',
required: true,
multiple: true,
}), help: command_1.flags.help({ char: 'h', description: 'Help for webhooks:create.' }) });
/**
* @param Sting[]
* Some example of use of the webhook:create command
*/
WebhooksCreate.examples = [
'webhooks:create --api-key=[API-KEY] --environment=[env] -d url=https://example.com/webhooks',
];