liveperson-functions-cli
Version:
LivePerson Functions CLI
100 lines • 4.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetController = void 0;
const errorCodes_1 = require("../shared/errorCodes");
const get_view_1 = require("../view/get.view");
const faasFactory_service_1 = require("../service/faasFactory.service");
class GetController {
constructor(
/* istanbul ignore next */ { getView = new get_view_1.GetView(), } = {}) {
this.getView = getView;
this.domains = ['functions', 'deployments', 'account', 'events'];
}
/**
* Returns the information about the passed domains.
* @param {IGetConfig} - Passed domains
* @returns {Promise<void>} - get view
* @memberof GetController
*/
async get(
/* istanbul ignore next */ { domains = [] } = {}) {
if (domains.length === 0) {
const prettyError = {
message: 'Please provide a domain (functions, deployments and/or account)',
suggestions: ['Functions, deployments, account or events.'],
ref: 'https://github.com/LivePersonInc/faas-cli#get',
code: errorCodes_1.CLIErrorCodes.DomainMissing,
};
this.getView.showErrorMessage(prettyError);
throw new Error('exit');
}
/* istanbul ignore else */
if (!domains.some((e) => this.domains.includes(e))) {
const prettyError = {
message: 'Unsupported domain found. Only functions, deployments and account are supported!',
suggestions: ['Functions, deployments, account or events.'],
ref: 'https://github.com/LivePersonInc/faas-cli#get',
code: errorCodes_1.CLIErrorCodes.UnsupportedDomain,
};
this.getView.showErrorMessage(prettyError);
throw new Error('exit');
}
const faasService = await faasFactory_service_1.factory.get();
try {
const allLambdas = await faasService.getAllLambdas();
/* istanbul ignore else */
if (allLambdas.length === 0) {
const prettyError = {
message: 'There are no functions created on your account!',
suggestions: [
'Use "lpf create:function exampleFunction" to create a function first.',
],
ref: 'https://github.com/LivePersonInc/faas-cli#get',
code: errorCodes_1.CLIErrorCodes.NoLambdasFound,
};
throw prettyError;
}
const updatedLambdas = allLambdas.map((func) => {
func.eventId = func.eventId ? func.eventId : 'No Event';
return func;
});
/* istanbul ignore else */
if (domains.includes('functions')) {
this.getView.printFunctions(updatedLambdas);
}
/* istanbul ignore else */
if (domains.includes('deployments')) {
const productiveLambdas = updatedLambdas
.filter((lambda) => lambda.state === 'Productive' || lambda.state === 'Modified')
.map((lambda) => ({
...lambda.lastDeployment,
name: lambda.name,
state: lambda.state === 'Productive' ? 'Up to date' : lambda.updatedAt,
}));
this.getView.printDeployments(productiveLambdas);
}
}
catch (error) {
this.getView.showErrorMessage(error);
throw new Error('exit');
}
try {
/* istanbul ignore else */
if (domains.includes('account')) {
const accountInfo = await faasService.getAccountStatistic();
this.getView.printAccountInformation(accountInfo);
}
/* istanbul ignore else */
if (domains.includes('events')) {
const events = await faasService.getEvents();
this.getView.printEvents(events);
}
}
catch (error) {
this.getView.showErrorMessage(error);
throw new Error('exit');
}
}
}
exports.GetController = GetController;
//# sourceMappingURL=get.controller.js.map