@pokash/n8n-nodes-optima-rest-api 1.0.5 → 1.1.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.
Potentially problematic release.
This version of @pokash/n8n-nodes-optima-rest-api might be problematic. Click here for more details.
|
@@ -103,12 +103,57 @@ class OptimaRestApi {
|
|
|
103
103
|
displayOptions: {
|
|
104
104
|
show: {
|
|
105
105
|
resource: ['customer'],
|
|
106
|
-
operation: ['
|
|
106
|
+
operation: ['update', 'delete'],
|
|
107
107
|
},
|
|
108
108
|
},
|
|
109
109
|
default: 0,
|
|
110
110
|
description: 'The ID of the customer',
|
|
111
111
|
},
|
|
112
|
+
// Customer Get/GetAll - Filter options
|
|
113
|
+
{
|
|
114
|
+
displayName: 'Options',
|
|
115
|
+
name: 'options',
|
|
116
|
+
type: 'collection',
|
|
117
|
+
placeholder: 'Add Option',
|
|
118
|
+
default: {},
|
|
119
|
+
displayOptions: {
|
|
120
|
+
show: {
|
|
121
|
+
resource: ['customer'],
|
|
122
|
+
operation: ['get', 'getAll'],
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
options: [
|
|
126
|
+
{
|
|
127
|
+
displayName: 'Customer ID',
|
|
128
|
+
name: 'id',
|
|
129
|
+
type: 'number',
|
|
130
|
+
default: 0,
|
|
131
|
+
description: 'Specific customer ID to retrieve',
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
displayName: 'Filter',
|
|
135
|
+
name: 'filter',
|
|
136
|
+
type: 'string',
|
|
137
|
+
default: '',
|
|
138
|
+
placeholder: 'Knt_Kod = \'TEST\'',
|
|
139
|
+
description: 'SQL-like filter string for searching customers (e.g., Knt_Kod = \'ACME\' or Knt_Nip = \'1234567890\')',
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
displayName: 'Skip',
|
|
143
|
+
name: 'skip',
|
|
144
|
+
type: 'number',
|
|
145
|
+
default: 0,
|
|
146
|
+
description: 'Number of records to skip (for pagination)',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
displayName: 'Take',
|
|
150
|
+
name: 'take',
|
|
151
|
+
type: 'number',
|
|
152
|
+
default: 100,
|
|
153
|
+
description: 'Maximum number of records to return (for pagination)',
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
},
|
|
112
157
|
// Customer fields for create/update
|
|
113
158
|
{
|
|
114
159
|
displayName: 'Customer Data',
|
|
@@ -304,28 +349,42 @@ class OptimaRestApi {
|
|
|
304
349
|
for (let i = 0; i < items.length; i++) {
|
|
305
350
|
try {
|
|
306
351
|
if (resource === 'customer') {
|
|
307
|
-
if (operation === 'get') {
|
|
308
|
-
const
|
|
352
|
+
if (operation === 'get' || operation === 'getAll') {
|
|
353
|
+
const options = this.getNodeParameter('options', i, {});
|
|
354
|
+
// Build query parameters
|
|
355
|
+
const queryParams = new URLSearchParams();
|
|
356
|
+
if (options.id) {
|
|
357
|
+
queryParams.append('id', String(options.id));
|
|
358
|
+
}
|
|
359
|
+
if (options.filter) {
|
|
360
|
+
queryParams.append('filter', String(options.filter));
|
|
361
|
+
}
|
|
362
|
+
if (options.skip) {
|
|
363
|
+
queryParams.append('skip', String(options.skip));
|
|
364
|
+
}
|
|
365
|
+
if (options.take) {
|
|
366
|
+
queryParams.append('take', String(options.take));
|
|
367
|
+
}
|
|
368
|
+
const queryString = queryParams.toString();
|
|
369
|
+
const url = queryString
|
|
370
|
+
? `${gatewayUrl}/api/customer?${queryString}`
|
|
371
|
+
: `${gatewayUrl}/api/customer`;
|
|
309
372
|
const response = await this.helpers.request({
|
|
310
373
|
method: 'GET',
|
|
311
|
-
url
|
|
374
|
+
url,
|
|
312
375
|
headers: {
|
|
313
376
|
Authorization: `Bearer ${token}`,
|
|
314
377
|
},
|
|
315
378
|
json: true,
|
|
316
379
|
});
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
},
|
|
326
|
-
json: true,
|
|
327
|
-
});
|
|
328
|
-
returnData.push(...response);
|
|
380
|
+
// Handle both single customer and array of customers
|
|
381
|
+
if (Array.isArray(response)) {
|
|
382
|
+
const items = response.map(item => ({ json: item }));
|
|
383
|
+
returnData.push(...items);
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
returnData.push({ json: response });
|
|
387
|
+
}
|
|
329
388
|
}
|
|
330
389
|
else if (operation === 'create') {
|
|
331
390
|
const customerData = JSON.parse(this.getNodeParameter('customerData', i));
|
|
@@ -338,7 +397,7 @@ class OptimaRestApi {
|
|
|
338
397
|
body: customerData,
|
|
339
398
|
json: true,
|
|
340
399
|
});
|
|
341
|
-
returnData.push(response);
|
|
400
|
+
returnData.push({ json: response });
|
|
342
401
|
}
|
|
343
402
|
else if (operation === 'update') {
|
|
344
403
|
const customerId = this.getNodeParameter('customerId', i);
|
|
@@ -354,7 +413,7 @@ class OptimaRestApi {
|
|
|
354
413
|
body: customerData,
|
|
355
414
|
json: true,
|
|
356
415
|
});
|
|
357
|
-
returnData.push(response);
|
|
416
|
+
returnData.push({ json: response });
|
|
358
417
|
}
|
|
359
418
|
else if (operation === 'delete') {
|
|
360
419
|
const customerId = this.getNodeParameter('customerId', i);
|
|
@@ -366,7 +425,7 @@ class OptimaRestApi {
|
|
|
366
425
|
},
|
|
367
426
|
json: true,
|
|
368
427
|
});
|
|
369
|
-
returnData.push({ success: true, id: customerId });
|
|
428
|
+
returnData.push({ json: { success: true, id: customerId } });
|
|
370
429
|
}
|
|
371
430
|
}
|
|
372
431
|
else if (resource === 'document') {
|
|
@@ -382,7 +441,7 @@ class OptimaRestApi {
|
|
|
382
441
|
body: documentData,
|
|
383
442
|
json: true,
|
|
384
443
|
});
|
|
385
|
-
returnData.push(response);
|
|
444
|
+
returnData.push({ json: response });
|
|
386
445
|
}
|
|
387
446
|
}
|
|
388
447
|
else if (resource === 'product') {
|
|
@@ -396,7 +455,7 @@ class OptimaRestApi {
|
|
|
396
455
|
},
|
|
397
456
|
json: true,
|
|
398
457
|
});
|
|
399
|
-
returnData.push(response);
|
|
458
|
+
returnData.push({ json: response });
|
|
400
459
|
}
|
|
401
460
|
else if (operation === 'getAll') {
|
|
402
461
|
const response = await this.helpers.request({
|
|
@@ -407,7 +466,8 @@ class OptimaRestApi {
|
|
|
407
466
|
},
|
|
408
467
|
json: true,
|
|
409
468
|
});
|
|
410
|
-
|
|
469
|
+
const items = response.map(item => ({ json: item }));
|
|
470
|
+
returnData.push(...items);
|
|
411
471
|
}
|
|
412
472
|
}
|
|
413
473
|
else if (resource === 'print') {
|
|
@@ -432,12 +492,18 @@ class OptimaRestApi {
|
|
|
432
492
|
const buffer = Buffer.isBuffer(response)
|
|
433
493
|
? response
|
|
434
494
|
: Buffer.from(response);
|
|
495
|
+
const fileName = `document_${Date.now()}.pdf`;
|
|
435
496
|
returnData.push({
|
|
436
|
-
|
|
497
|
+
json: {
|
|
498
|
+
success: true,
|
|
499
|
+
fileName: fileName,
|
|
500
|
+
},
|
|
437
501
|
binary: {
|
|
438
|
-
data:
|
|
439
|
-
|
|
440
|
-
|
|
502
|
+
data: {
|
|
503
|
+
data: buffer.toString('base64'),
|
|
504
|
+
mimeType: 'application/pdf',
|
|
505
|
+
fileName: fileName,
|
|
506
|
+
},
|
|
441
507
|
},
|
|
442
508
|
});
|
|
443
509
|
}
|
|
@@ -446,13 +512,13 @@ class OptimaRestApi {
|
|
|
446
512
|
catch (error) {
|
|
447
513
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
448
514
|
if (this.continueOnFail()) {
|
|
449
|
-
returnData.push({ error: errorMessage });
|
|
515
|
+
returnData.push({ json: { error: errorMessage } });
|
|
450
516
|
continue;
|
|
451
517
|
}
|
|
452
518
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
453
519
|
}
|
|
454
520
|
}
|
|
455
|
-
return [
|
|
521
|
+
return [returnData];
|
|
456
522
|
}
|
|
457
523
|
}
|
|
458
524
|
exports.OptimaRestApi = OptimaRestApi;
|