UNPKG

fedapay-cli

Version:
103 lines (102 loc) 3.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 customers_1 = tslib_1.__importDefault(require("../customers")); const dataparse_1 = tslib_1.__importDefault(require("../../helpers/dataparse")); /** * CustomersList class extending the superClass Customers */ class CustomersList extends customers_1.default { async run() { /** * Get flags object from CustommersList * and use them to retrieve and list the custommers */ /** * @param object * get flags value */ const { flags } = this.parse(CustomersList); /** * @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); /** * @param number * store the number of customers to display */ const limit = flags.limit; /** * @param number * store the number of the page to display */ 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); try { cli_ux_1.cli.action.start('Getting the customers list'); const customers = await fedapay_1.Customer.all(Object.assign({ per_page: limit, page }, filters)); this.log(json_colorizer_1.default(JSON.stringify(customers, null, 2))); } catch (error) { this.error(error.message); } cli_ux_1.cli.action.stop(); } } exports.default = CustomersList; /** * @param string * Description of the command Custommers:list description */ CustomersList.description = 'List of the customer records.'; /** * @param object * Declaration of the command flags */ CustomersList.flags = Object.assign(Object.assign({}, customers_1.default.flags), { limit: command_1.flags.integer({ char: 'l', description: 'Limit of records to display.', default: 10, }), filters: command_1.flags.string({ char: 'f', description: 'Filter the list of customers.', multiple: true, }), page: command_1.flags.integer({ description: 'The page of the records to display.', char: 'p', default: 1 }), help: command_1.flags.help({ char: 'h', description: 'Help for customers:list' }) }); /** * @param string * Set the command usage for help */ CustomersList.usage = 'customers:list [options]'; /** * @param string[] * some examples of the custommers list use for help */ CustomersList.examples = [ 'customers:list', 'customers:list --api-key=[API-KEY] --environment=[env] --limit=20', 'customers:list --api-key=[API-KEY] --environment=[env] -p=2', ];