UNPKG

fedapay-cli

Version:
87 lines (86 loc) 2.68 kB
"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 = require("cli-ux"); const base_1 = tslib_1.__importDefault(require("../../base")); /** * EventsTrigger class extending super class Events */ class EventsTrigger extends base_1.default { async run() { /** * @param object * get flags value */ const { flags } = this.parse(EventsTrigger); /** * @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 transaction */ const webhookId = flags.webhook; /** * @param integer * get the event to trigger */ const event = flags.event; try { cli_ux_1.cli.action.start('Retrieve webhook'); const webhook = await fedapay_1.Webhook.retrieve(webhookId); /** * @param Event * When we got a match the variable is filled up with a webhook object */ const data = await webhook.sendEvent({ event }); this.log('Event send'); } catch (error) { this.log(error.message); } } } exports.default = EventsTrigger; /** * @params String * Description of the command webhooks:token */ EventsTrigger.description = 'Trigger an event to a webhook.'; /** * The command usage * @var string */ EventsTrigger.usage = 'events:trigger [options]'; /** * @param object * Declaration of the command flags */ EventsTrigger.flags = Object.assign(Object.assign({}, base_1.default.flags), { webhook: command_1.flags.integer({ required: true, description: 'ID of the webhook.' }), event: command_1.flags.string({ required: true, description: 'The event name to trigger' }), help: command_1.flags.help({ char: 'h', description: 'Help for events:trigger command.' }) }); /** * @param String[] * Some example with the token command */ EventsTrigger.examples = [ 'events:token --api-key=[API-KEY] --environment=[env] --webhook=3 --event=transaction.approved', ];