UNPKG

@constructor-io/constructorio-connect-cli

Version:

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

33 lines (32 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendTemplateExecuteRequest = sendTemplateExecuteRequest; const axios_1 = require("axios"); const errors_1 = require("@oclif/core/errors"); const ux_action_1 = require("../helpers/ux-action"); const http_client_1 = require("./http-client"); async function sendTemplateExecuteRequest({ template, helpers, data, external, connectionId, templateType, showLogs = true, }) { const client = await (0, http_client_1.getHttpClient)(); const httpRequest = async () => { return (await client.patch("templates/standalone/execute", { helpers, raw_template: template, data, external, connection_id: connectionId, template_type: templateType, })).data; }; try { if (showLogs) { return await (0, ux_action_1.uxAction)("📟 Executing your template", httpRequest)(); } return await httpRequest(); } catch (error) { if ((0, axios_1.isAxiosError)(error) && error.response) { throw new errors_1.CLIError(`Something went wrong while executing your template: ${JSON.stringify(error.response.data)}`); } throw error; } }