fedapay-cli
Version:
A command-line tool for FedaPay
86 lines (85 loc) • 2.83 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const command_1 = require("@oclif/command");
const fedapay_1 = require("fedapay");
const json_colorizer_1 = tslib_1.__importDefault(require("json-colorizer"));
const cli_ux_1 = tslib_1.__importDefault(require("cli-ux"));
const webhooks_1 = tslib_1.__importDefault(require("../webhooks"));
const dataparse_1 = tslib_1.__importDefault(require("../../helpers/dataparse"));
/**
* WebhookUpdate extending the superClass Webhooks
*/
class WebhooksUpdate extends webhooks_1.default {
async run() {
/**
* @param object
* get flags value
*/
const { flags } = this.parse(WebhooksUpdate);
/**
* @param String
* your api's key
*/
const apiKey = this.userConfig.read('secret_key', flags['api-key']);
/**
* @param string
* environment type
*/
const environment = this.userConfig.read('environment', flags.environment);
/**
* Set Apikey and environment to connect to fedapay
*/
fedapay_1.FedaPay.setApiKey(apiKey);
fedapay_1.FedaPay.setEnvironment(environment);
try {
/**
* @param integer
* get the id of the webhook
*/
const id = flags.id;
/**
* @param Object
* The data obtained after transformation
*/
const data = dataparse_1.default.transform(flags.data);
cli_ux_1.default.action.start('Updating webhook');
const webhook = await fedapay_1.Webhook.update(id, data);
this.log(json_colorizer_1.default(JSON.stringify(webhook, null, 2)));
}
catch (error) {
this.error(error.message);
}
}
}
exports.default = WebhooksUpdate;
/**
* @params String
* Description of the command webhooks:update
*/
WebhooksUpdate.description = 'Update a webhook.';
/**
* The command usage
* @var string
*/
WebhooksUpdate.usage = 'webhooks:update [options]';
/**
* @param object
* Declaration of the command flags
*/
WebhooksUpdate.flags = Object.assign(Object.assign({}, webhooks_1.default.flags), { id: command_1.flags.integer({
required: true,
description: 'The webhook ID.'
}), data: command_1.flags.string({
description: 'Data for the API request.',
required: true,
multiple: true,
char: 'd',
}), help: command_1.flags.help({ char: 'h', description: 'Help for webhooks:update command.' }) });
/**
* @param Sting[]
* Some example of use of the webhook:update command
*/
WebhooksUpdate.examples = [
'webhooks:update --api-key=[API-KEY] --environment=[env] --id=[ID] -d url=https://example.com/webhooks',
];