UNPKG

liveperson-functions-cli

Version:
72 lines 3.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InvokeController = void 0; const path_1 = require("path"); const errorCodes_1 = require("../shared/errorCodes"); const file_service_1 = require("../service/file.service"); const faasFactory_service_1 = require("../service/faasFactory.service"); const invoke_view_1 = require("../view/invoke.view"); const faas_debugger_1 = require("../shared/faas-debugger"); const init_controller_1 = require("./init.controller"); class InvokeController { constructor({ invokeView = new invoke_view_1.InvokeView(), fileService = new file_service_1.FileService(), initController = new init_controller_1.InitController(), } = {}) { this.invokeView = invokeView; this.fileService = fileService; this.lambdaToInvoke = {}; this.initController = initController; } /** * Invokes the passed function remote or local depending on the --local flag. * @param {IInvokeConfig} - lambda function and flags * @returns {Promise<void>} - invocation local or remote * @memberof InvokeController */ async invoke({ lambdaFunctions, inputFlags, }) { try { if (this.fileService.needUpdateBinFolder()) { await this.initController.init({ update: true }); } const localLambdaInformation = this.fileService.collectLocalLambdaInformation(lambdaFunctions); [this.lambdaToInvoke] = localLambdaInformation; if (inputFlags === null || inputFlags === void 0 ? void 0 : inputFlags.local) { const indexPath = (0, path_1.join)(this.fileService.getPathToFunction(lambdaFunctions[0]), 'index.js'); const configPath = (0, path_1.join)(this.fileService.getPathToFunction(lambdaFunctions[0]), 'config.json'); const invocation = new faas_debugger_1.FaasDebugger({ indexPath, configPath, lambdaToInvoke: this.lambdaToInvoke.name, }); await invocation.runLocalInvocation(); } else { await this.invokeRemote(); } } catch (error) { this.invokeView.showErrorMessage(error.message || error.errorMsg); } } async invokeRemote() { const faasService = await faasFactory_service_1.factory.get(); const [currentLambda] = (await faasService.getLambdasByNames([ this.lambdaToInvoke.name, ])); /* istanbul ignore next */ if (!currentLambda) { const prettyError = { message: `Function ${this.lambdaToInvoke.name} were not found on the platform. Please make sure the function with the name ${this.lambdaToInvoke.name} was pushed to the LivePerson Functions platform`, suggestions: [ 'Use "lpf push exampleFunction" to push and "lpf deploy exampleFunction" to deploy a function', ], ref: 'https://github.com/LivePersonInc/faas-cli#invoke', code: errorCodes_1.CLIErrorCodes.NoLambdasFound, }; this.invokeView.showErrorMessage(prettyError); throw new Error('exit'); } const response = await faasService.invoke(currentLambda.uuid, this.lambdaToInvoke.input); this.invokeView.printConsoleLogs(response); } } exports.InvokeController = InvokeController; //# sourceMappingURL=invoke.controller.js.map