fedapay-cli
Version:
A command-line tool for FedaPay
66 lines (65 loc) • 2.38 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 base_1 = tslib_1.__importDefault(require("../base"));
const tail_util_1 = tslib_1.__importDefault(require("../helpers/tail-util"));
const dataparse_1 = tslib_1.__importDefault(require("../helpers/dataparse"));
/**
* The base class of events commands
*/
class Events extends base_1.default {
async run() {
const { flags } = this.parse(Events);
/**
* @param string
* api key value
*/
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);
const filters = dataparse_1.default.transform(flags.filters);
if (flags.tail) {
const queueOptions = await fedapay_1.Event.subscribe();
const mqUrl = this.userConfig.read('mq_url');
const tail = new tail_util_1.default(mqUrl, queueOptions);
const keys = flags.dump ? [] : ['name', 'object'];
tail.connect(filters, keys, (output) => {
this.log(output);
});
this.log('Waiting for events...');
}
else {
this._help();
}
}
}
exports.default = Events;
/**
* The command description
* @var string
*/
Events.description = 'Here you can manage events';
/**
* The command usage
* @var string
*/
Events.usage = 'events:<operation> [parameters...]';
/**
* The command flags
* @var Object
*/
Events.flags = Object.assign(Object.assign({}, base_1.default.flags), { tail: command_1.flags.boolean({ char: 't', description: 'Tail events', default: false }), dump: command_1.flags.boolean({ char: 'd', description: 'Dump event details', default: false }), filters: command_1.flags.string({
char: 'f',
description: 'Filter the list of event to tail.',
multiple: true,
}), help: command_1.flags.help({ char: 'h', description: 'Help for events command' }) });