fedapay-cli
Version:
A command-line tool for FedaPay
92 lines (91 loc) • 3.13 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const command_1 = require("@oclif/command");
const cli_ux_1 = tslib_1.__importDefault(require("cli-ux"));
const fedapay_1 = require("fedapay");
const json_colorizer_1 = tslib_1.__importDefault(require("json-colorizer"));
const transactions_1 = tslib_1.__importDefault(require("../transactions"));
const dataparse_1 = tslib_1.__importDefault(require("../../helpers/dataparse"));
/**
* TransactionList class extending superClass Transactions
*/
class TransactionsList extends transactions_1.default {
async run() {
/**
* @param object
* get flags value
*/
const { flags } = this.parse(TransactionsList);
/**
* @param String
* your api's key
*/
const apiKey = this.userConfig.read('secret_key', flags['api-key']);
/**
* @param String
* environment or live
*/
const environment = this.userConfig.read('environment', flags.environment);
/**
* @param integer
* get the limit value
*/
const limit = flags.limit;
/**
* @param integer
* get the page number value
*/
const page = flags.page;
/**
* @param Object
* The filter flag
* TODO: Use filter for the list
*/
const filters = dataparse_1.default.transformFilters(flags.filters);
/**
* Set Apikey and environment to connect to fedapay
*/
fedapay_1.FedaPay.setApiKey(apiKey);
fedapay_1.FedaPay.setEnvironment(environment);
cli_ux_1.default.action.start('Getting the transactions list');
const transactions = await fedapay_1.Transaction.all(Object.assign({ per_page: limit, page }, filters));
this.log(json_colorizer_1.default(JSON.stringify(transactions, null, 2)));
cli_ux_1.default.action.stop();
}
}
exports.default = TransactionsList;
/**
* @params String
* Description of the command transactions:list
*/
TransactionsList.description = 'List of the transaction records.';
/**
* The command usage
* @var string
*/
TransactionsList.usage = 'transactions:list [options]';
/**
* @param object
* Declaration of the command flags
*/
TransactionsList.flags = Object.assign(Object.assign({}, transactions_1.default.flags), { limit: command_1.flags.integer({
description: 'Limit of records to display.',
char: 'l',
default: 10,
}), page: command_1.flags.integer({
description: 'The page of the records to display.',
char: 'p',
default: 1
}), filters: command_1.flags.string({
char: 'f',
description: 'Filter the list of transactions.',
multiple: true,
}), help: command_1.flags.help({ char: 'h', description: 'Help for transactions:list' }) });
/**
* @param Sting[]
* Some example of use of the transaction:list command
*/
TransactionsList.examples = [
'transactions:list --api-key=[api_key] --environment=environment --limit=15'
];