UNPKG

n8n-nodes-placid

Version:

n8n node to interact with Placid API for creative generation

64 lines 2.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.execute = execute; const n8n_workflow_1 = require("n8n-workflow"); const config_1 = require("../../utils/config"); async function execute(index) { try { const returnAll = this.getNodeParameter('returnAll', index, false); const additionalFields = this.getNodeParameter('additionalFields', index, {}); let allTemplates = []; let nextUrl = null; const queryParams = new URLSearchParams(); if (additionalFields.collection_id) { queryParams.append('collection_id', additionalFields.collection_id); } const baseUrl = config_1.PlacidConfig.getRestUrl(config_1.PlacidConfig.ENDPOINTS.TEMPLATES); let currentUrl = queryParams.toString() ? `${baseUrl}?${queryParams.toString()}` : baseUrl; do { const options = { method: 'GET', url: currentUrl, headers: { 'Accept': config_1.PlacidConfig.HTTP.HEADERS.ACCEPT, 'Content-Type': config_1.PlacidConfig.HTTP.HEADERS.CONTENT_TYPE, 'x-placid-integration': config_1.PlacidConfig.HTTP.HEADERS.PLACID_INTEGRATION, }, }; const response = await this.helpers.httpRequestWithAuthentication.call(this, 'placidApi', options); let templates = []; if (response.data && Array.isArray(response.data)) { templates = response.data; } else if (Array.isArray(response)) { templates = response; } else { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Unexpected response format from Placid API', { itemIndex: index, }); } allTemplates = allTemplates.concat(templates); nextUrl = null; if (response.links && response.links.next) { nextUrl = response.links.next; } if (!returnAll) { break; } if (nextUrl) { currentUrl = nextUrl; } } while (nextUrl && returnAll); return allTemplates.map(template => ({ json: template, pairedItem: { item: index }, })); } catch (error) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to list templates: ${error.message}`, { itemIndex: index, }); } } //# sourceMappingURL=getMany.operation.js.map