fedapay-cli
Version:
A command-line tool for FedaPay
93 lines (92 loc) • 3.1 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 cli_ux_1 = tslib_1.__importDefault(require("cli-ux"));
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const webhooks_1 = tslib_1.__importDefault(require("../webhooks"));
/**
* WebhookDelete class extending super class Webhooks
*/
class WebhooksDelete extends webhooks_1.default {
async run() {
/**
* @param object
* get flags value
*/
const { flags } = this.parse(WebhooksDelete);
/**
* @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);
/**
* @param integer
* get the id of the webhook
*/
const id = flags.id;
try {
/**
* @param Webhook
* result of the retrieve
*/
cli_ux_1.default.action.start('Retrieving webhook');
const webhook = await fedapay_1.Webhook.retrieve(id);
const confirm = flags.confirm || await cli_ux_1.default.confirm('Are you sure to continue? [Y/n]');
if (confirm) {
cli_ux_1.default.action.start('Deleting webhook');
await webhook.delete();
this.log(chalk_1.default.green('Webhook deleted successfully.'));
}
else {
this.log(chalk_1.default.yellow('Deletion canceled.'));
}
}
catch (error) {
this.error(error.message);
}
cli_ux_1.default.action.stop();
}
}
exports.default = WebhooksDelete;
/**
* @params String
* Description of the command webhooks:delete
*/
WebhooksDelete.description = 'Delete a webhook.';
/**
* The command usage
* @var string
*/
WebhooksDelete.usage = 'webhooks:delete [options]';
/**
* @param object
* Declaration of the command flags
*/
WebhooksDelete.flags = Object.assign(Object.assign({}, webhooks_1.default.flags), { id: command_1.flags.integer({
description: 'The webhook ID.',
required: true,
}), confirm: command_1.flags.boolean({
description: 'Skip the warning prompt and automatically confirm the command being entered.',
default: false,
char: 'c'
}), help: command_1.flags.help({ char: 'h', description: 'Help for webhooks:delete.' }) });
/**
* @param String[]
* Some example of use of the delete command
*/
WebhooksDelete.examples = [
'webhooks:delete --api-key=[api_key] --environment=[env] --id=[ID]',
'webhooks:delete --api-key=[api_key] --environment=[env] --id=[ID] -c',
];