n8n-nodes-brightdata
Version:
Community node to work with BrightData service for scraping purposes
48 lines (46 loc) • 1.95 kB
JavaScript
;
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="0fb4a1c9-a428-5d46-90c6-42b03ab554da")}catch(e){}}();
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.js.map
//# debugId=0fb4a1c9-a428-5d46-90c6-42b03ab554da