UNPKG

@constructor-io/constructorio-connect-cli

Version:

CLI tool to enable users to interface with the Constructor Connect Ecosystem

44 lines (43 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.performDeploy = performDeploy; const axios_1 = require("axios"); const core_1 = require("@oclif/core"); const errors_1 = require("@oclif/core/errors"); const http_client_1 = require("./http-client"); /** * Calls the /templates endpoint of the Constructor API to deploy templates. */ async function performDeploy({ environment, config, templates, helpers, }) { const client = await (0, http_client_1.getHttpClient)(); try { await client.post(`/templates`, { environment, config_file: config, helpers, templates: templates.map(({ connectionIds, sourceCode }) => { return { connection_ids: connectionIds, source_code: sourceCode, }; }), }); } catch (error) { core_1.ux.action.stop("💥"); if (!(error instanceof axios_1.AxiosError)) { throw error; } if (error.response?.status === 400 && Array.isArray(error.response?.data?.message)) { throw new errors_1.CLIError(`💥 Some validations have failed :(`, { suggestions: error.response?.data?.message, }); } const responseBody = error.response?.data; const logData = responseBody ? JSON.stringify(responseBody, null, 2) : error; throw new errors_1.CLIError(`💥 Received the following error from the Constructor API: \n${logData}}\n`); } }