UNPKG

fedapay-cli

Version:
79 lines (78 loc) 2.42 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 json_colorizer_1 = tslib_1.__importDefault(require("json-colorizer")); const cli_ux_1 = require("cli-ux"); const base_1 = tslib_1.__importDefault(require("../../base")); /** * EventsStubEvent class extending super class Events */ class EventsStub extends base_1.default { async run() { /** * @param object * get flags value */ const { flags } = this.parse(EventsStub); /** * @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 event to stub */ const event = flags.event; try { cli_ux_1.cli.action.start('Loading'); /** * @param Event * When we got a match the variable is filled up with a webhook object */ const data = await fedapay_1.Webhook.stubEvent({ event }); this.log(json_colorizer_1.default(JSON.stringify(data, null, 2))); } catch (error) { this.log(error.message); } } } exports.default = EventsStub; /** * @params String * Description of the command events:stub */ EventsStub.description = 'Generate a fake event'; /** * The command usage * @var string */ EventsStub.usage = 'events:stub [options]'; /** * @param object * Declaration of the command flags */ EventsStub.flags = Object.assign(Object.assign({}, base_1.default.flags), { event: command_1.flags.string({ required: true, description: 'The event name to stub' }), help: command_1.flags.help({ char: 'h', description: 'Help for events:stub command.' }) }); /** * @param String[] * Some example with the token command */ EventsStub.examples = [ 'events:stub --api-key=[API-KEY] --environment=[env] --event=[ressource.name]', ];