UNPKG

n8n-nodes-duckduckgo-search

Version:

AI Agent-ready n8n community node for DuckDuckGo search. Search the web, images, news, and videos with no API key required and no outbound telemetry. Optionally fetch and extract the main text of result pages or any URL, and get DuckDuckGo Instant Answers

87 lines (86 loc) 2.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LogLevel = void 0; exports.decodeHtmlEntities = decodeHtmlEntities; exports.formatDate = formatDate; exports.createLogEntry = createLogEntry; exports.parseApiError = parseApiError; const HTML_ENTITIES = { '&amp;': '&', '&lt;': '<', '&gt;': '>', '&quot;': '"', '&#39;': "'", '&nbsp;': ' ', '&ndash;': '–', '&mdash;': '—', '&hellip;': '…', }; function decodeHtmlEntities(text) { if (!text) return null; return text.replace(/&[#\w]+;/g, (entity) => { return HTML_ENTITIES[entity] || entity; }); } function formatDate(timestamp) { if (!timestamp) return null; try { return new Date(timestamp * 1000).toISOString(); } catch (error) { return null; } } var LogLevel; (function (LogLevel) { LogLevel["DEBUG"] = "debug"; LogLevel["INFO"] = "info"; LogLevel["WARN"] = "warn"; LogLevel["ERROR"] = "error"; })(LogLevel || (exports.LogLevel = LogLevel = {})); function createLogEntry(level, message, operation, data, error) { const logEntry = { level, message, timestamp: new Date().toISOString(), }; if (operation) { logEntry.operation = operation; } if (data) { logEntry.data = data; } if (error) { logEntry.error = { message: error.message, stack: error.stack, name: error.name, }; } return logEntry; } function parseApiError(error, operation) { if (error.message.includes('ECONNREFUSED') || error.message.includes('ENOTFOUND')) { return `Unable to connect to DuckDuckGo servers. Please check your internet connection and try again.`; } if (error.message.includes('timeout') || error.message.includes('ETIMEDOUT')) { return `The request to DuckDuckGo timed out. Please try again later.`; } if (error.message.includes('429') || error.message.includes('too many requests')) { return `DuckDuckGo rate limit reached. Please wait before making more requests.`; } if (operation.includes('search')) { if (error.message.includes('400')) { return `Invalid search query or parameters. Please check your input and try again.`; } if (error.message.includes('403')) { return `Access denied. DuckDuckGo may have detected unusual search patterns.`; } } if (error.message === 'A server error occurred!') { return `DuckDuckGo returned a server error during ${operation}. This may be a temporary DuckDuckGo issue, rate limit, or upstream scraper failure. Try again later or reduce request frequency.`; } return `Error during ${operation}: ${error.message}`; }