liveperson-functions-cli
Version:
LivePerson Functions CLI
137 lines (136 loc) • 4.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetView = void 0;
const printer_1 = require("./printer");
const utils_1 = require("../shared/utils");
require('events').EventEmitter.defaultMaxListeners = 15;
class GetView {
constructor({ log = new printer_1.LogMessage(), error = new printer_1.ErrorMessage(), cliUx = printer_1.cliUX, } = {}) {
this.log = log;
this.error = error;
this.cliUx = cliUx;
}
/**
* Shows an error message
* @param {string|PrettyPrintableError} message - message
* @memberof GetView
*/
showErrorMessage(message) {
this.error.print(message);
}
/**
* Prints all functions (domain) as a table
* @param {ILambda[]} functions - functions
* @returns {void}
* @memberof GetView
*/
printFunctions(functions) {
this.log.print('');
this.cliUx.table(functions, {
name: {
minWidth: 30,
},
state: {
minWidth: 15,
},
updatedAt: {
minWidth: 40,
header: 'Last changed at',
get: (row) => (row.updatedAt ? (0, utils_1.formatDate)(row.updatedAt) : '-'),
},
updatedBy: {
minWidth: 40,
header: 'Last changed by',
get: (row) => row.updatedBy || '-',
},
eventId: {
minWidth: 40,
header: 'Event',
},
});
this.log.print('');
}
/**
* Prints all deployments (domain) as a table
* @param {any} functions - functions
* @returns {void}
* @memberof GetView
*/
printDeployments(functions) {
this.log.print('');
this.cliUx.table(functions, {
name: {
minWidth: 30,
},
state: {
minWidth: 30,
header: 'Undeployed changes from',
get: (row) => row.state === 'Up to date' ? 'Up to date' : (0, utils_1.formatDate)(row.state),
},
deployedAt: {
minWidth: 30,
header: 'Last successful deployment',
get: (row) => row.deployedAt ? (0, utils_1.formatDate)(row.deployedAt) : 'pending ...',
},
createdBy: {
minWidth: 30,
header: 'Deployed by',
},
deploymentState: {
minWidth: 30,
header: 'Deployment state',
get: (row) => row.deploymentState || '-',
},
});
this.log.print('');
}
/**
* Prints all account informations
* @param {*} accountInfo - account information
* @returns {void}
* @memberof GetView
*/
printAccountInformation(accountInfo) {
const totalInvocations = accountInfo.successfulInvocations + accountInfo.unsuccessfulInvocations;
const fairUseQuotaPercentage = Math.ceil((totalInvocations * 100) / accountInfo.invocationLimitPerMonth);
const date = new Date();
const firstDayOfMonth = new Date(date.getFullYear(), date.getMonth(), 1, 1);
const invocationDate = firstDayOfMonth.toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
});
this.log.print(`
${printer_1.chalk.bold('Total Functions:')} ${accountInfo.total} / ${accountInfo.limitTotalLambdas}
${printer_1.chalk.bold('Deployed Functions:')} ${accountInfo.deployed} / ${accountInfo.limitDeployedLambdas}
${printer_1.chalk.bold('Total Invocations:')} ${totalInvocations}
${printer_1.chalk.bold('Fair Use Quota:')} ${fairUseQuotaPercentage}% (Invocations since ${invocationDate})
${totalInvocations} / ${accountInfo.invocationLimitPerMonth}
`);
}
/**
* Prints the events with the mapped names
* @param {*} events - Events from the api
* @returns {void}
* @memberof GetView
*/
printEvents(events) {
this.log.print('');
this.cliUx.table(events, {
eventName: {
header: 'Event name',
minWidth: 40,
},
eventId: {
header: 'EventId',
minWidth: 40,
},
});
this.log.print('');
this.log.print('For further informations please have a look at');
this.log.print('https://developers.liveperson.com/liveperson-functions-event-sources-overview.html');
this.log.print('');
}
}
exports.GetView = GetView;
//# sourceMappingURL=get.view.js.map