dev beta
This commit is contained in:
parent
523576ce96
commit
666d4eb4c2
6 changed files with 10467 additions and 30 deletions
10435
package-lock.json
generated
Normal file
10435
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -25,7 +25,9 @@
|
||||||
"url": "https://github.com/developtheweb/n8n-tavily-nodes/issues"
|
"url": "https://github.com/developtheweb/n8n-tavily-nodes/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.6.0"
|
"axios": "^1.6.0",
|
||||||
|
"n8n-core": "^1.14.1",
|
||||||
|
"n8n-workflow": "^1.14.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^18.0.0",
|
"@types/node": "^18.0.0",
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
import { IExecuteFunctions } from 'n8n-core';
|
|
||||||
import {
|
import {
|
||||||
|
IExecuteFunctions,
|
||||||
|
NodeApiError,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
NodeApiError,
|
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
// REMOVED import { IExecuteFunctions } from 'n8n-core';
|
||||||
|
|
||||||
import { tavilyApiRequest } from './tavilyApi.utils';
|
import { tavilyApiRequest } from './tavilyApi.utils';
|
||||||
|
|
||||||
|
|
@ -87,7 +88,7 @@ export class TavilyExtract implements INodeType {
|
||||||
|
|
||||||
const credentials = await this.getCredentials('tavilyApi');
|
const credentials = await this.getCredentials('tavilyApi');
|
||||||
if (!credentials?.apiKey) {
|
if (!credentials?.apiKey) {
|
||||||
throw new NodeApiError(this.getNode(), new Error('Missing Tavily API key in credentials.'));
|
throw new NodeApiError(this.getNode(), { message: 'Missing Tavily API key in credentials.' });
|
||||||
}
|
}
|
||||||
const apiKey = credentials.apiKey as string;
|
const apiKey = credentials.apiKey as string;
|
||||||
|
|
||||||
|
|
@ -97,9 +98,8 @@ export class TavilyExtract implements INodeType {
|
||||||
const includeImages = this.getNodeParameter('includeImages', i) as boolean;
|
const includeImages = this.getNodeParameter('includeImages', i) as boolean;
|
||||||
const extractDepth = this.getNodeParameter('extractDepth', i) as string;
|
const extractDepth = this.getNodeParameter('extractDepth', i) as string;
|
||||||
|
|
||||||
// Validate input parameters
|
|
||||||
if (!Array.isArray(urls) || urls.length === 0) {
|
if (!Array.isArray(urls) || urls.length === 0) {
|
||||||
throw new NodeApiError(this.getNode(), new Error('At least one URL is required.'));
|
throw new NodeApiError(this.getNode(), { message: 'At least one URL is required.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
|
|
@ -121,7 +121,7 @@ export class TavilyExtract implements INodeType {
|
||||||
if (error instanceof NodeApiError) {
|
if (error instanceof NodeApiError) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
throw new NodeApiError(this.getNode(), error as Error);
|
throw new NodeApiError(this.getNode(), { message: String(error) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
import { IExecuteFunctions } from 'n8n-core';
|
|
||||||
import {
|
import {
|
||||||
|
IExecuteFunctions,
|
||||||
|
NodeApiError,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
NodeApiError,
|
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
// REMOVED import { IExecuteFunctions } from 'n8n-core';
|
||||||
|
|
||||||
import { tavilyApiRequest } from './tavilyApi.utils';
|
import { tavilyApiRequest } from './tavilyApi.utils';
|
||||||
|
|
||||||
// NEW: maintain a constant array for valid time ranges
|
// For older n8n usage, ALLOWED_TIME_RANGES is fine here
|
||||||
const ALLOWED_TIME_RANGES = ['', 'day', 'week', 'month', 'year', 'd', 'w', 'm', 'y'];
|
const ALLOWED_TIME_RANGES = ['', 'day', 'week', 'month', 'year', 'd', 'w', 'm', 'y'];
|
||||||
|
|
||||||
export class TavilySearch implements INodeType {
|
export class TavilySearch implements INodeType {
|
||||||
|
|
@ -205,8 +206,7 @@ export class TavilySearch implements INodeType {
|
||||||
|
|
||||||
const credentials = await this.getCredentials('tavilyApi');
|
const credentials = await this.getCredentials('tavilyApi');
|
||||||
if (!credentials?.apiKey) {
|
if (!credentials?.apiKey) {
|
||||||
// Standardize NodeApiError usage
|
throw new NodeApiError(this.getNode(), { message: 'Missing Tavily API key in credentials.' });
|
||||||
throw new NodeApiError(this.getNode(), new Error('Missing Tavily API key in credentials.'));
|
|
||||||
}
|
}
|
||||||
const apiKey = credentials.apiKey as string;
|
const apiKey = credentials.apiKey as string;
|
||||||
|
|
||||||
|
|
@ -225,21 +225,21 @@ export class TavilySearch implements INodeType {
|
||||||
const includeDomains = this.getNodeParameter('includeDomains', i, []) as string[];
|
const includeDomains = this.getNodeParameter('includeDomains', i, []) as string[];
|
||||||
const excludeDomains = this.getNodeParameter('excludeDomains', i, []) as string[];
|
const excludeDomains = this.getNodeParameter('excludeDomains', i, []) as string[];
|
||||||
|
|
||||||
// --- Validate input parameters ---
|
// Validate parameters
|
||||||
if (!query?.trim()) {
|
if (!query?.trim()) {
|
||||||
throw new NodeApiError(this.getNode(), new Error('Query parameter cannot be empty.'));
|
throw new NodeApiError(this.getNode(), { message: 'Query parameter cannot be empty.' });
|
||||||
}
|
}
|
||||||
if (maxResults < 0 || maxResults > 20) {
|
if (maxResults < 0 || maxResults > 20) {
|
||||||
throw new NodeApiError(this.getNode(), new Error('Max Results must be between 0 and 20.'));
|
throw new NodeApiError(this.getNode(), { message: 'Max Results must be between 0 and 20.' });
|
||||||
}
|
}
|
||||||
// Use ALLOWED_TIME_RANGES constant
|
|
||||||
if (!ALLOWED_TIME_RANGES.includes(timeRange)) {
|
if (!ALLOWED_TIME_RANGES.includes(timeRange)) {
|
||||||
throw new NodeApiError(this.getNode(), new Error(`Invalid timeRange value. Allowed: ${ALLOWED_TIME_RANGES.join(', ')}`));
|
throw new NodeApiError(this.getNode(), {
|
||||||
|
message: `Invalid timeRange value. Allowed: ${ALLOWED_TIME_RANGES.join(', ')}`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (topic === 'news' && days < 0) {
|
if (topic === 'news' && days < 0) {
|
||||||
throw new NodeApiError(this.getNode(), new Error('Days must be >= 0 when topic is "news".'));
|
throw new NodeApiError(this.getNode(), { message: 'Days must be >= 0 when topic is "news".' });
|
||||||
}
|
}
|
||||||
// ----------------------------------
|
|
||||||
|
|
||||||
const body: Record<string, any> = {
|
const body: Record<string, any> = {
|
||||||
query,
|
query,
|
||||||
|
|
@ -267,7 +267,6 @@ export class TavilySearch implements INodeType {
|
||||||
body.exclude_domains = excludeDomains;
|
body.exclude_domains = excludeDomains;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make request via the shared utility
|
|
||||||
const result = await tavilyApiRequest.call(
|
const result = await tavilyApiRequest.call(
|
||||||
this,
|
this,
|
||||||
'POST',
|
'POST',
|
||||||
|
|
@ -278,11 +277,10 @@ export class TavilySearch implements INodeType {
|
||||||
|
|
||||||
returnData.push({ json: result });
|
returnData.push({ json: result });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Ensure consistent error wrapping
|
|
||||||
if (error instanceof NodeApiError) {
|
if (error instanceof NodeApiError) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
throw new NodeApiError(this.getNode(), error as Error);
|
throw new NodeApiError(this.getNode(), { message: String(error) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import axios, { AxiosError, AxiosResponse } from 'axios';
|
import axios, { AxiosError, AxiosResponse } from 'axios';
|
||||||
import { NodeApiError } from 'n8n-workflow';
|
import { NodeApiError, IExecuteFunctions } from 'n8n-workflow'; // CHANGED
|
||||||
import { IExecuteFunctions } from 'n8n-core';
|
// import { IExecuteFunctions } from 'n8n-core'; // REMOVED
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common function to call the Tavily API.
|
* Common function to call the Tavily API.
|
||||||
|
|
@ -30,6 +30,7 @@ export async function tavilyApiRequest(
|
||||||
if (axios.isAxiosError(error)) {
|
if (axios.isAxiosError(error)) {
|
||||||
const status = error.response?.status;
|
const status = error.response?.status;
|
||||||
let message = `Tavily API error: ${error.message}`;
|
let message = `Tavily API error: ${error.message}`;
|
||||||
|
|
||||||
if (status) {
|
if (status) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 400:
|
case 400:
|
||||||
|
|
@ -65,21 +66,21 @@ export async function tavilyApiRequest(
|
||||||
additionalMsgParts.push(`error_message: ${data.error_message}`);
|
additionalMsgParts.push(`error_message: ${data.error_message}`);
|
||||||
}
|
}
|
||||||
if (!data.error_code && !data.error_message) {
|
if (!data.error_code && !data.error_message) {
|
||||||
// Fall back to a full JSON dump if no known fields
|
|
||||||
additionalMsgParts.push(JSON.stringify(data));
|
additionalMsgParts.push(JSON.stringify(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append to main message
|
|
||||||
if (additionalMsgParts.length > 0) {
|
if (additionalMsgParts.length > 0) {
|
||||||
message += ` | ${additionalMsgParts.join(' | ')}`;
|
message += ` | ${additionalMsgParts.join(' | ')}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NodeApiError(this.getNode(), new Error(message));
|
// PASS A JsonObject
|
||||||
|
throw new NodeApiError(this.getNode(), { message });
|
||||||
} else {
|
} else {
|
||||||
throw new NodeApiError(this.getNode(), error as Error);
|
// If not an AxiosError, wrap it
|
||||||
|
throw new NodeApiError(this.getNode(), { message: String(error) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"forceConsistentCasingInFileNames": true
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"useUnknownInCatchVariables": false
|
||||||
},
|
},
|
||||||
"include": ["src/**/*.ts"],
|
"include": ["src/**/*.ts"],
|
||||||
"exclude": ["node_modules", "dist"]
|
"exclude": ["node_modules", "dist"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue