UNPKG

@constructor-io/constructorio-connect-cli

Version:

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

26 lines (25 loc) 1.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.selectConnections = void 0; const get_connections_request_1 = require("../http/get-connections-request"); const ux_action_1 = require("../helpers/ux-action"); const get_connect_token_1 = require("../customer/get-connect-token"); const render_prompt_1 = require("../prompt-data/render-prompt"); const selectConnections = async (message = "Choose the connection") => { const connections = await (0, ux_action_1.uxAction)("📡 Reading your connections...", async () => { return await (0, get_connections_request_1.getConnections)({ showLogs: true }); })(); // Load the connect token to ensure we can authenticate with Constructor. // We do this here because the terminal output gets weird when there is a prompt during a ux action. await (0, get_connect_token_1.getConnectToken)(); const connectionId = await (0, render_prompt_1.renderPrompt)({ promptMessage: message, choices: connections.map((connection) => ({ name: `[${connection.environment}] - ${connection.name}`, value: connection.id, })), }); const selectedConnection = connections.find((connection) => connection.id === connectionId); return selectedConnection; }; exports.selectConnections = selectConnections;