UNPKG

@brightdata/n8n-nodes-brightdata

Version:
73 lines 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getActiveZones = getActiveZones; exports.getCountries = getCountries; exports.getDataSets = getDataSets; exports.ensureZoneExists = ensureZoneExists; async function getActiveZones() { await ensureZoneExists.call(this, 'n8n_unlocker'); await ensureZoneExists.call(this, 'n8n_serp', 'serp'); const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'brightdataApi', { method: 'GET', url: 'https://api.brightdata.com/zone/get_active_zones', json: true, }); const results = responseData.map((item) => ({ name: item.name, value: item.name, type: item.type, })); return { results }; } async function getCountries() { const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'brightdataApi', { method: 'GET', url: 'https://api.brightdata.com/countrieslist', json: true, }); const results = responseData.zone_type.DC_shared.country_codes.map((code) => ({ name: code, value: code, type: 'DC_shared', })); results.sort((a, b) => a.name.localeCompare(b.name)); return { results }; } async function getDataSets() { const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'brightdataApi', { method: 'GET', url: 'https://api.brightdata.com/datasets/list', json: true, }); const results = responseData.map((item) => ({ name: item.name, value: item.id, type: item.id, })); results.sort((a, b) => a.name.localeCompare(b.name)); return { results }; } async function ensureZoneExists(zoneName = 'n8n_unlocker', zoneType = 'unblocker') { try { const zones = await this.helpers.httpRequestWithAuthentication.call(this, 'brightdataApi', { method: 'GET', url: 'https://api.brightdata.com/zone/get_active_zones', json: true, }); const hasZone = zones.some((zone) => zone.name === zoneName); if (!hasZone) { await this.helpers.httpRequestWithAuthentication.call(this, 'brightdataApi', { method: 'POST', url: 'https://api.brightdata.com/zone', json: true, body: { zone: { name: zoneName, type: zoneType }, plan: zoneType === 'serp' ? { type: 'unblocker', serp: true } : { type: zoneType }, }, }); } } catch { } } //# sourceMappingURL=SearchFunctions.js.map