UNPKG

@brightdata/n8n-nodes-brightdata

Version:
44 lines 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.brightdataApiRequest = brightdataApiRequest; exports.sendErrorPostReceive = sendErrorPostReceive; const n8n_workflow_1 = require("n8n-workflow"); async function brightdataApiRequest(method, endpoint, body, query, option = {}) { const options = { method, headers: { 'User-Agent': 'n8n', 'Content-Type': 'application/json', }, body, qs: query, url: 'https://api.brightdata.com', json: true, }; if (Object.keys(option).length !== 0) { Object.assign(options, option); } options.url += endpoint; try { console.log('Request to BrightData API:', JSON.stringify(options, null, 2)); const response = await this.helpers.requestWithAuthentication.call(this, 'brightdataApi', options); if (endpoint.indexOf("filter") !== -1) { console.log('Response from BrightData API:', response); } return response; } catch (error) { console.log('Error in brightdataApiRequest', error); return new n8n_workflow_1.NodeApiError(this.getNode(), { statusCode: error.httpCode, description: error.description, }); } } async function sendErrorPostReceive(data, response) { if (String(response.statusCode).startsWith('4') || String(response.statusCode).startsWith('5')) { throw new n8n_workflow_1.NodeApiError(this.getNode(), response); } return data; } //# sourceMappingURL=GenericFunctions.backup.js.map