Skip to content

Commit 60342e5

Browse files
committed
initial work
1 parent 3026c33 commit 60342e5

File tree

4 files changed

+88
-54
lines changed

4 files changed

+88
-54
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,9 @@ The node returns the raw JSON received from SearchApi.io. See the [official docs
107107
- **n8n Community Forum**[https://community.n8n.io](https://community.n8n.io)
108108
- **Community nodes installation** – [https://docs.n8n.io/integrations/community-nodes/installation/](https://docs.n8n.io/integrations/community-nodes/installation/)
109109

110+
## Contributing
111+
112+
1. Run `pnpm build && pnpm link` on the project root
113+
2. Run `pnpm link @searchapi/n8n-nodes-searchapi`
114+
115+
After that build the node on each change and it should be reflected in n8n local interface.

nodes/SearchApi/SearchApi.node.ts

Lines changed: 30 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { IDataObject, INodeType, INodeTypeDescription } from 'n8n-workflow';
1+
import { INodeType, INodeTypeDescription } from 'n8n-workflow';
2+
import { google } from './engines/google';
23

34
export class SearchApi implements INodeType {
45
description: INodeTypeDescription = {
@@ -17,7 +18,7 @@ export class SearchApi implements INodeType {
1718
credentials: [{ name: 'searchApi', required: true }],
1819
usableAsTool: true,
1920
requestDefaults: {
20-
baseURL: 'https://www.searchapi.io/api/v1',
21+
baseURL: 'http://localhost:3000/api/v1', // TODO: Change to https://www.searchapi.io/api/v1
2122
method: 'GET',
2223
url: '/search',
2324
headers: { Accept: 'application/json' },
@@ -34,65 +35,40 @@ export class SearchApi implements INodeType {
3435
},
3536
],
3637
properties: [
37-
{
38-
displayName: 'Engine (Engine)',
39-
name: 'engine',
40-
type: 'string',
41-
default: 'google',
42-
required: true,
43-
44-
description: 'Search engine to use for the query',
45-
hint: 'Check https://www.searchapi.io/docs/google for the available engines',
46-
routing: {
47-
request: {
48-
qs: {
49-
engine: '={{ $value }}',
50-
},
51-
},
52-
},
38+
{
39+
displayName: 'Resource',
40+
name: 'resource',
41+
type: 'options',
42+
description: 'The search engine to use',
43+
noDataExpression: true,
44+
options: [
45+
google.resource
46+
],
47+
default: '',
5348
},
5449
{
55-
displayName: 'Parameters',
56-
name: 'parameters',
57-
type: 'fixedCollection',
58-
typeOptions: { multipleValues: true },
59-
default: {},
60-
description: 'Add the parameters you want to use for the search, refer to the SearchAPI.io documentation for the available parameters for the selected engine',
50+
displayName: 'Operation Name',
51+
name: 'operation',
52+
type: 'options',
53+
noDataExpression: true,
6154
options: [
6255
{
63-
displayName: 'Parameter',
64-
name: 'parameter',
65-
values: [
66-
{
67-
displayName: 'Name',
68-
name: 'name',
69-
type: 'string',
70-
default: '',
71-
placeholder: 'q',
72-
},
73-
{
74-
displayName: 'Value',
75-
name: 'value',
76-
type: 'string',
77-
default: '',
78-
placeholder: 'pizza near me',
79-
},
80-
],
56+
name: 'Search',
57+
value: 'search',
58+
action: 'Search the web',
59+
description: 'Search using the engine specified in the resource',
60+
routing: {
61+
request: {
62+
qs: {
63+
engine: '={{ $parameter["resource"] }}'
64+
}
65+
}
66+
}
8167
},
8268
],
83-
/**
84-
* Build an object like { hl: 'en', gl: 'us' } out of
85-
* the collection entries and merge it into qs.
86-
*/
87-
routing: {
88-
request: {
89-
// We are doing this cast here because we need to
90-
// build an object out of the collection entries
91-
// and merge it into qs, but qs expects an object.
92-
qs: '={{ Object.fromEntries(($value.parameter ?? []).map(p => [p.name, p.value])) }}' as unknown as IDataObject,
93-
},
94-
},
69+
default: 'search',
9570
},
71+
...google.properties,
9672
],
9773
};
9874
}

nodes/SearchApi/engines/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Engines
2+
3+
The engines file should contain the resource and operation of the engine

nodes/SearchApi/engines/google.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { INodeProperties } from "n8n-workflow";
2+
3+
const resource = { name: 'Google', value: 'google' } as { name: 'Google'; value: 'google' };
4+
const properties: INodeProperties[] = [
5+
{
6+
displayName: 'Query',
7+
name: 'q',
8+
type: 'string',
9+
required: true,
10+
default: '',
11+
description: 'The query to search for',
12+
displayOptions: {
13+
show: {
14+
resource: ['google'],
15+
},
16+
},
17+
routing: {
18+
request: {
19+
qs: {
20+
q: '={{$value}}',
21+
},
22+
},
23+
},
24+
},
25+
{
26+
displayName: 'Number of Results',
27+
name: 'num',
28+
type: 'number',
29+
default: null,
30+
description: 'The number of results to return',
31+
displayOptions: {
32+
show: {
33+
resource: ['google'],
34+
},
35+
},
36+
routing: {
37+
request: {
38+
qs: {
39+
num: '={{$value}}',
40+
},
41+
},
42+
},
43+
},
44+
];
45+
46+
export const google = {
47+
resource,
48+
properties,
49+
};

0 commit comments

Comments
 (0)