fedapay-cli
Version:
A command-line tool for FedaPay
92 lines (91 loc) • 3.09 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 json_colorizer_1 = tslib_1.__importDefault(require("json-colorizer"));
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const cli_ux_1 = require("cli-ux");
const logs_1 = tslib_1.__importDefault(require("../logs"));
const dataparse_1 = tslib_1.__importDefault(require("../../helpers/dataparse"));
/**
* LogsList command class.
*/
class LogsList extends logs_1.default {
async run() {
/**
* @param object
* Get flags value.
*/
const { flags } = this.parse(LogsList);
/**
* @param string
* Api key value.
*/
const apiKey = flags['api-key'];
/**
* @param string
* Environment type.
*/
const environment = flags.environment;
/**
* @param number
* Store the number of logs to display.
*/
const limit = flags.limit;
const filter = dataparse_1.default.transformFiltersForES(flags.filter);
/**
* Set Apikey and environment to connect to fedapay
*/
fedapay_1.FedaPay.setApiKey(apiKey);
fedapay_1.FedaPay.setEnvironment(environment);
try {
cli_ux_1.cli.action.start('Getting the customers list');
if (typeof filter === 'object') {
const filterObject = Object.assign(Object.assign({ per_page: limit }, filter), { match: 'must' });
const Logs = await fedapay_1.Log.all(filterObject);
this.log(json_colorizer_1.default(JSON.stringify(Logs, null, 2)));
}
else {
this.error(chalk_1.default.red(filter));
}
}
catch (error) {
this.error(chalk_1.default.red(`${error.name} : ${error.message}`));
}
cli_ux_1.cli.action.stop();
}
}
exports.default = LogsList;
/**
* @param string
* Description of logs:list command.
*/
LogsList.description = 'List of the logs records.';
/**
* @param string
* Custom usage string for help
* This overrides the default usage
*/
LogsList.usage = 'logs:list [parameters...]';
/**
* @param object
* Declaration of the command flags.
*/
LogsList.flags = Object.assign(Object.assign({}, logs_1.default.flags), { limit: command_1.flags.integer({
char: 'l',
description: 'Limit of records to display.',
default: 10,
}), filter: command_1.flags.string({
char: 'f',
description: 'Filter the list of logs.',
multiple: true,
}), help: command_1.flags.help({ char: 'h', description: 'Help for logs:list' }) });
/**
* @param string[]
* Some examples of the logs:list use for help.
*/
LogsList.examples = [
'logs:list --api-key=[API-KEY] --environment=[ENVIRONMENT] -f method=POST',
'logs:list --api-key=[API-KEY] --environment=[ENVIRONMENT] -f status=400 -f method=GET -f status=200',
];