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.
84 lines (83 loc) • 2.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseApiError = exports.createLogEntry = exports.LogLevel = exports.formatDate = exports.decodeHtmlEntities = void 0;
const HTML_ENTITIES = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
''': "'",
' ': ' ',
'–': '–',
'—': '—',
'…': '…',
};
function decodeHtmlEntities(text) {
if (!text)
return null;
return text.replace(/&[#\w]+;/g, (entity) => {
return HTML_ENTITIES[entity] || entity;
});
}
exports.decodeHtmlEntities = decodeHtmlEntities;
function formatDate(timestamp) {
if (!timestamp)
return null;
try {
return new Date(timestamp * 1000).toISOString();
}
catch (error) {
return null;
}
}
exports.formatDate = formatDate;
var LogLevel;
(function (LogLevel) {
LogLevel["DEBUG"] = "debug";
LogLevel["INFO"] = "info";
LogLevel["WARN"] = "warn";
LogLevel["ERROR"] = "error";
})(LogLevel = exports.LogLevel || (exports.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;
}
exports.createLogEntry = createLogEntry;
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.`;
}
}
return `Error during ${operation}: ${error.message}`;
}
exports.parseApiError = parseApiError;