n8n-nodes-idb2b 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # n8n-nodes-idb2b
2
+
3
+ This is an n8n community node for IDB2B API integration.
4
+
5
+ [n8n](https://n8n.io/) is a workflow automation platform.
6
+
7
+ ## Installation
8
+
9
+ Follow the [installation guide](https://docs.n8n.io/integrations/community-nodes/installation/) in the n8n documentation.
10
+
11
+ ## Credentials
12
+
13
+ Configure the following credentials in n8n:
14
+
15
+ - **API Token**: Your IDB2B API token
16
+ - **Base URL**: Your IDB2B API base URL (default: `https://api.idb2b.com`)
17
+
18
+ ## Operations
19
+
20
+ The node currently supports custom API requests with:
21
+
22
+ - GET requests
23
+ - POST requests
24
+ - PUT requests
25
+ - DELETE requests
26
+
27
+ You can specify:
28
+ - Custom endpoints
29
+ - Query parameters
30
+ - JSON body for POST/PUT requests
31
+
32
+ ## Development
33
+
34
+ ```bash
35
+ npm install
36
+ npm run build
37
+ ```
38
+
39
+ ## License
40
+
41
+ MIT
@@ -0,0 +1,9 @@
1
+ import { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow';
2
+ export declare class IDB2BApi implements ICredentialType {
3
+ name: string;
4
+ displayName: string;
5
+ documentationUrl: string;
6
+ properties: INodeProperties[];
7
+ authenticate: IAuthenticateGeneric;
8
+ test: ICredentialTestRequest;
9
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IDB2BApi = void 0;
4
+ class IDB2BApi {
5
+ constructor() {
6
+ this.name = 'idb2bApi';
7
+ this.displayName = 'IDB2B API';
8
+ this.documentationUrl = 'https://docs.idb2b.com';
9
+ this.properties = [
10
+ {
11
+ displayName: 'API Token',
12
+ name: 'apiToken',
13
+ type: 'string',
14
+ typeOptions: { password: true },
15
+ default: '',
16
+ required: true,
17
+ },
18
+ {
19
+ displayName: 'Base URL',
20
+ name: 'baseUrl',
21
+ type: 'string',
22
+ default: 'https://api.idb2b.com',
23
+ required: true,
24
+ },
25
+ ];
26
+ this.authenticate = {
27
+ type: 'generic',
28
+ properties: {
29
+ headers: {
30
+ Authorization: '={{"Bearer " + $credentials.apiToken}}',
31
+ },
32
+ },
33
+ };
34
+ this.test = {
35
+ request: {
36
+ baseURL: '={{$credentials.baseUrl}}',
37
+ url: '/api/v1/health',
38
+ },
39
+ };
40
+ }
41
+ }
42
+ exports.IDB2BApi = IDB2BApi;
@@ -0,0 +1,5 @@
1
+ import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
2
+ export declare class IDB2B implements INodeType {
3
+ description: INodeTypeDescription;
4
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
+ }
@@ -0,0 +1,385 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IDB2B = void 0;
4
+ class IDB2B {
5
+ constructor() {
6
+ this.description = {
7
+ displayName: 'IDB2B',
8
+ name: 'idb2b',
9
+ icon: 'file:idb2b.svg',
10
+ group: ['transform'],
11
+ version: 1,
12
+ subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
13
+ description: 'Interact with IDB2B API',
14
+ defaults: {
15
+ name: 'IDB2B',
16
+ },
17
+ inputs: ['main'],
18
+ outputs: ['main'],
19
+ credentials: [
20
+ {
21
+ name: 'idb2bApi',
22
+ required: true,
23
+ },
24
+ ],
25
+ requestDefaults: {
26
+ baseURL: '={{$credentials.baseUrl}}',
27
+ headers: {
28
+ Accept: 'application/json',
29
+ 'Content-Type': 'application/json',
30
+ },
31
+ },
32
+ properties: [
33
+ {
34
+ displayName: 'Resource',
35
+ name: 'resource',
36
+ type: 'options',
37
+ noDataExpression: true,
38
+ options: [
39
+ {
40
+ name: 'Contact',
41
+ value: 'contact',
42
+ },
43
+ {
44
+ name: 'Custom',
45
+ value: 'custom',
46
+ },
47
+ ],
48
+ default: 'contact',
49
+ },
50
+ {
51
+ displayName: 'Operation',
52
+ name: 'operation',
53
+ type: 'options',
54
+ noDataExpression: true,
55
+ displayOptions: {
56
+ show: {
57
+ resource: ['contact'],
58
+ },
59
+ },
60
+ options: [
61
+ {
62
+ name: 'Get All',
63
+ value: 'getAll',
64
+ action: 'Get all contacts',
65
+ description: 'Retrieve all contacts',
66
+ },
67
+ {
68
+ name: 'Create',
69
+ value: 'create',
70
+ action: 'Create a contact',
71
+ description: 'Create a new contact',
72
+ },
73
+ ],
74
+ default: 'getAll',
75
+ },
76
+ {
77
+ displayName: 'Operation',
78
+ name: 'operation',
79
+ type: 'options',
80
+ noDataExpression: true,
81
+ displayOptions: {
82
+ show: {
83
+ resource: ['custom'],
84
+ },
85
+ },
86
+ options: [
87
+ {
88
+ name: 'GET Request',
89
+ value: 'get',
90
+ action: 'Execute a GET request',
91
+ routing: {
92
+ request: {
93
+ method: 'GET',
94
+ },
95
+ },
96
+ },
97
+ {
98
+ name: 'POST Request',
99
+ value: 'post',
100
+ action: 'Execute a POST request',
101
+ routing: {
102
+ request: {
103
+ method: 'POST',
104
+ },
105
+ },
106
+ },
107
+ {
108
+ name: 'PUT Request',
109
+ value: 'put',
110
+ action: 'Execute a PUT request',
111
+ routing: {
112
+ request: {
113
+ method: 'PUT',
114
+ },
115
+ },
116
+ },
117
+ {
118
+ name: 'DELETE Request',
119
+ value: 'delete',
120
+ action: 'Execute a DELETE request',
121
+ routing: {
122
+ request: {
123
+ method: 'DELETE',
124
+ },
125
+ },
126
+ },
127
+ ],
128
+ default: 'get',
129
+ },
130
+ {
131
+ displayName: 'Name',
132
+ name: 'name',
133
+ type: 'string',
134
+ default: '',
135
+ required: true,
136
+ displayOptions: {
137
+ show: {
138
+ resource: ['contact'],
139
+ operation: ['create'],
140
+ },
141
+ },
142
+ description: 'Contact name',
143
+ },
144
+ {
145
+ displayName: 'Email',
146
+ name: 'email',
147
+ type: 'string',
148
+ default: '',
149
+ required: true,
150
+ displayOptions: {
151
+ show: {
152
+ resource: ['contact'],
153
+ operation: ['create'],
154
+ },
155
+ },
156
+ description: 'Contact email',
157
+ },
158
+ {
159
+ displayName: 'Phone',
160
+ name: 'phone',
161
+ type: 'string',
162
+ default: '',
163
+ displayOptions: {
164
+ show: {
165
+ resource: ['contact'],
166
+ operation: ['create'],
167
+ },
168
+ },
169
+ description: 'Contact phone number',
170
+ },
171
+ {
172
+ displayName: 'Additional Fields',
173
+ name: 'additionalFields',
174
+ type: 'collection',
175
+ placeholder: 'Add Field',
176
+ default: {},
177
+ displayOptions: {
178
+ show: {
179
+ resource: ['contact'],
180
+ operation: ['create'],
181
+ },
182
+ },
183
+ options: [
184
+ {
185
+ displayName: 'Company',
186
+ name: 'company',
187
+ type: 'string',
188
+ default: '',
189
+ },
190
+ {
191
+ displayName: 'Address',
192
+ name: 'address',
193
+ type: 'string',
194
+ default: '',
195
+ },
196
+ ],
197
+ },
198
+ {
199
+ displayName: 'Endpoint',
200
+ name: 'endpoint',
201
+ type: 'string',
202
+ default: '/api/v1/',
203
+ placeholder: '/api/v1/resource',
204
+ description: 'The endpoint to call',
205
+ displayOptions: {
206
+ show: {
207
+ resource: ['custom'],
208
+ },
209
+ },
210
+ routing: {
211
+ request: {
212
+ url: '={{$value}}',
213
+ },
214
+ },
215
+ },
216
+ {
217
+ displayName: 'JSON Body',
218
+ name: 'jsonBody',
219
+ type: 'json',
220
+ default: '{}',
221
+ description: 'JSON body for POST/PUT requests',
222
+ displayOptions: {
223
+ show: {
224
+ operation: ['post', 'put'],
225
+ resource: ['custom'],
226
+ },
227
+ },
228
+ routing: {
229
+ request: {
230
+ body: '={{JSON.parse($value)}}',
231
+ },
232
+ },
233
+ },
234
+ {
235
+ displayName: 'Query Parameters',
236
+ name: 'queryParameters',
237
+ type: 'fixedCollection',
238
+ typeOptions: {
239
+ multipleValues: true,
240
+ },
241
+ default: {},
242
+ placeholder: 'Add Parameter',
243
+ displayOptions: {
244
+ show: {
245
+ resource: ['contact'],
246
+ operation: ['getAll'],
247
+ },
248
+ },
249
+ options: [
250
+ {
251
+ name: 'parameter',
252
+ displayName: 'Parameter',
253
+ values: [
254
+ {
255
+ displayName: 'Name',
256
+ name: 'name',
257
+ type: 'string',
258
+ default: '',
259
+ },
260
+ {
261
+ displayName: 'Value',
262
+ name: 'value',
263
+ type: 'string',
264
+ default: '',
265
+ },
266
+ ],
267
+ },
268
+ ],
269
+ },
270
+ {
271
+ displayName: 'Query Parameters',
272
+ name: 'queryParameters',
273
+ type: 'fixedCollection',
274
+ typeOptions: {
275
+ multipleValues: true,
276
+ },
277
+ default: {},
278
+ placeholder: 'Add Parameter',
279
+ displayOptions: {
280
+ show: {
281
+ resource: ['custom'],
282
+ },
283
+ },
284
+ options: [
285
+ {
286
+ name: 'parameter',
287
+ displayName: 'Parameter',
288
+ values: [
289
+ {
290
+ displayName: 'Name',
291
+ name: 'name',
292
+ type: 'string',
293
+ default: '',
294
+ },
295
+ {
296
+ displayName: 'Value',
297
+ name: 'value',
298
+ type: 'string',
299
+ default: '',
300
+ },
301
+ ],
302
+ },
303
+ ],
304
+ },
305
+ ],
306
+ };
307
+ }
308
+ async execute() {
309
+ const items = this.getInputData();
310
+ const returnData = [];
311
+ for (let i = 0; i < items.length; i++) {
312
+ try {
313
+ const resource = this.getNodeParameter('resource', i);
314
+ const operation = this.getNodeParameter('operation', i);
315
+ const credentials = await this.getCredentials('idb2bApi');
316
+ let method = 'GET';
317
+ let endpoint = '';
318
+ let body = undefined;
319
+ let qs = {};
320
+ if (resource === 'contact') {
321
+ if (operation === 'getAll') {
322
+ method = 'GET';
323
+ endpoint = '/contacts';
324
+ const queryParameters = this.getNodeParameter('queryParameters', i, {});
325
+ if (queryParameters.parameter) {
326
+ qs = queryParameters.parameter.reduce((acc, param) => {
327
+ acc[param.name] = param.value;
328
+ return acc;
329
+ }, {});
330
+ }
331
+ }
332
+ else if (operation === 'create') {
333
+ method = 'POST';
334
+ endpoint = '/contacts';
335
+ const name = this.getNodeParameter('name', i);
336
+ const email = this.getNodeParameter('email', i);
337
+ const phone = this.getNodeParameter('phone', i, '');
338
+ const additionalFields = this.getNodeParameter('additionalFields', i, {});
339
+ body = Object.assign(Object.assign({ name,
340
+ email }, (phone && { phone })), additionalFields);
341
+ }
342
+ }
343
+ else if (resource === 'custom') {
344
+ endpoint = this.getNodeParameter('endpoint', i);
345
+ method = operation.toUpperCase();
346
+ if (['post', 'put'].includes(operation)) {
347
+ const jsonBody = this.getNodeParameter('jsonBody', i);
348
+ body = JSON.parse(jsonBody);
349
+ }
350
+ const queryParameters = this.getNodeParameter('queryParameters', i, {});
351
+ if (queryParameters.parameter) {
352
+ qs = queryParameters.parameter.reduce((acc, param) => {
353
+ acc[param.name] = param.value;
354
+ return acc;
355
+ }, {});
356
+ }
357
+ }
358
+ const response = await this.helpers.httpRequestWithAuthentication.call(this, 'idb2bApi', {
359
+ method,
360
+ url: `${credentials.baseUrl}${endpoint}`,
361
+ body,
362
+ qs,
363
+ json: true,
364
+ });
365
+ returnData.push({
366
+ json: response,
367
+ pairedItem: { item: i },
368
+ });
369
+ }
370
+ catch (error) {
371
+ if (this.continueOnFail()) {
372
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
373
+ returnData.push({
374
+ json: { error: errorMessage },
375
+ pairedItem: { item: i },
376
+ });
377
+ continue;
378
+ }
379
+ throw error;
380
+ }
381
+ }
382
+ return [returnData];
383
+ }
384
+ }
385
+ exports.IDB2B = IDB2B;
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
2
+ <rect width="100" height="100" rx="15" fill="#4A90E2"/>
3
+ <text x="50" y="65" font-family="Arial, sans-serif" font-size="48" font-weight="bold" fill="white" text-anchor="middle">IDB</text>
4
+ </svg>
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "n8n-nodes-idb2b",
3
+ "version": "1.0.0",
4
+ "description": "n8n community node for IDB2B API",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "build": "tsc && gulp build:icons",
8
+ "dev": "tsc --watch",
9
+ "format": "prettier nodes credentials --write",
10
+ "lint": "eslint nodes/**/*.ts credentials/**/*.ts",
11
+ "lintfix": "eslint nodes/**/*.ts credentials/**/*.ts --fix",
12
+ "prepublishOnly": "npm run build"
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "n8n": {
18
+ "n8nNodesApiVersion": 1,
19
+ "credentials": [
20
+ "dist/credentials/IDB2BApi.credentials.js"
21
+ ],
22
+ "nodes": [
23
+ "dist/nodes/IDB2B/IDB2B.node.js"
24
+ ]
25
+ },
26
+ "keywords": [
27
+ "n8n-community-node-package",
28
+ "n8n",
29
+ "idb2b",
30
+ "api"
31
+ ],
32
+ "author": "",
33
+ "license": "MIT",
34
+ "devDependencies": {
35
+ "@typescript-eslint/parser": "^5.0.0",
36
+ "eslint-plugin-n8n-nodes-base": "^1.11.0",
37
+ "gulp": "^4.0.2",
38
+ "n8n-workflow": "*",
39
+ "prettier": "^2.7.1",
40
+ "typescript": "^4.8.4"
41
+ },
42
+ "peerDependencies": {
43
+ "n8n-workflow": "*"
44
+ }
45
+ }