UNPKG

@net3/queuer

Version:

77 lines (76 loc) 2.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAllPieces = getAllPieces; exports.getPieceActions = getPieceActions; exports.getAllMCPPieces = getAllMCPPieces; exports.getPieceConnections = getPieceConnections; const pieces_common_1 = require("@activepieces/pieces-common"); /** * Fetch all pieces from the platform API. */ async function getAllPieces(config) { try { const response = await pieces_common_1.httpClient.sendRequest({ method: pieces_common_1.HttpMethod.GET, url: `${config.baseUrl}/api/v1/pieces`, headers: { Authorization: `Bearer ${config.apiKey}`, 'Content-Type': 'application/json', }, }); return response.body || []; } catch (error) { console.error('Failed to fetch pieces:', error); return []; } } /** * Return the actions map for a particular piece. */ async function getPieceActions(pieceName, config) { const pieces = await getAllPieces(config); const piece = pieces.find((p) => p.name === pieceName); return piece?.actions || {}; } /** * Fetch all MCP pieces from the platform API. */ async function getAllMCPPieces(config) { try { const response = await pieces_common_1.httpClient.sendRequest({ method: pieces_common_1.HttpMethod.GET, url: `${config.baseUrl}/api/v1/mcp-pieces`, headers: { Authorization: `Bearer ${config.apiKey}`, 'Content-Type': 'application/json', }, }); return response.body || []; } catch (error) { console.error('Failed to fetch MCP pieces:', error); return []; } } /** * Fetch connections for a given piece. */ async function getPieceConnections(pieceName, config) { try { const response = await pieces_common_1.httpClient.sendRequest({ method: pieces_common_1.HttpMethod.GET, url: `${config.baseUrl}/api/v1/connections?pieceName=${pieceName}`, headers: { Authorization: `Bearer ${config.apiKey}`, 'Content-Type': 'application/json', }, }); const connections = response.body || []; return connections.filter((c) => c.pieceName === pieceName); } catch (error) { console.error('Failed to fetch connections:', error); return []; } }