UNPKG

n8n-nodes-duckduckgo-search

Version:

A powerful and comprehensive n8n community node that seamlessly integrates DuckDuckGo search capabilities into your workflows. Search the web, find images, discover news, and explore videos - all with privacy-focused, reliable results.

72 lines (71 loc) 2.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setTelemetryEndpoint = exports.reportEvent = void 0; const https_1 = require("https"); const uuid_1 = require("uuid"); const DEFAULT_TELEMETRY_ENDPOINT = 'https://telemetry.example.com/collect'; async function reportEvent(executeFunctions, eventName, data) { try { const telemetryEnabled = executeFunctions.getNodeParameter('enableTelemetry', 0, false); if (!telemetryEnabled) { return; } const nodeStaticData = executeFunctions.getWorkflowStaticData('node'); if (!nodeStaticData.nodeRunId) { nodeStaticData.nodeRunId = (0, uuid_1.v4)(); } const payload = { eventName, timestamp: Date.now(), nodeRunId: nodeStaticData.nodeRunId, ...data, }; const telemetryEndpoint = nodeStaticData.telemetryEndpoint || DEFAULT_TELEMETRY_ENDPOINT; sendTelemetryData(telemetryEndpoint, payload) .catch(error => console.error('Telemetry error:', error)); } catch (error) { console.error('Telemetry reporting error:', error); } } exports.reportEvent = reportEvent; function sendTelemetryData(endpoint, data) { return new Promise((resolve, reject) => { try { const url = new URL(endpoint); const payload = JSON.stringify(data); const options = { hostname: url.hostname, port: url.port || (url.protocol === 'https:' ? 443 : 80), path: url.pathname, method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload), }, }; const req = (0, https_1.request)(options, (res) => { const statusCode = res.statusCode || 500; if (statusCode >= 200 && statusCode < 300) { resolve(); } else { reject(new Error(`HTTP error: ${statusCode}`)); } }); req.on('error', (error) => { reject(error); }); req.write(payload); req.end(); } catch (error) { reject(error); } }); } function setTelemetryEndpoint(executeFunctions, endpoint) { const nodeStaticData = executeFunctions.getWorkflowStaticData('node'); nodeStaticData.telemetryEndpoint = endpoint; } exports.setTelemetryEndpoint = setTelemetryEndpoint;