@pokash/n8n-nodes-optima-rest-api 1.1.1 → 1.1.3
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.
|
@@ -34,6 +34,10 @@ class OptimaRestApi {
|
|
|
34
34
|
name: 'Customer',
|
|
35
35
|
value: 'customer',
|
|
36
36
|
},
|
|
37
|
+
{
|
|
38
|
+
name: 'Dictionary',
|
|
39
|
+
value: 'dictionary',
|
|
40
|
+
},
|
|
37
41
|
{
|
|
38
42
|
name: 'Document',
|
|
39
43
|
value: 'document',
|
|
@@ -169,6 +173,51 @@ class OptimaRestApi {
|
|
|
169
173
|
default: '{\n "akronim": "KLIENT01",\n "nazwa": "Firma Example",\n "nip": "1234567890"\n}',
|
|
170
174
|
description: 'Customer data in JSON format',
|
|
171
175
|
},
|
|
176
|
+
// Dictionary Operations
|
|
177
|
+
{
|
|
178
|
+
displayName: 'Dictionary Type',
|
|
179
|
+
name: 'operation',
|
|
180
|
+
type: 'options',
|
|
181
|
+
noDataExpression: true,
|
|
182
|
+
displayOptions: {
|
|
183
|
+
show: {
|
|
184
|
+
resource: ['dictionary'],
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
options: [
|
|
188
|
+
{
|
|
189
|
+
name: 'Payment Methods',
|
|
190
|
+
value: 'paymentMethods',
|
|
191
|
+
description: 'Get payment methods dictionary',
|
|
192
|
+
action: 'Get payment methods',
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: 'Warehouses',
|
|
196
|
+
value: 'warehouses',
|
|
197
|
+
description: 'Get warehouses dictionary',
|
|
198
|
+
action: 'Get warehouses',
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
name: 'Currencies',
|
|
202
|
+
value: 'currencies',
|
|
203
|
+
description: 'Get currencies dictionary',
|
|
204
|
+
action: 'Get currencies',
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
name: 'Document Definitions',
|
|
208
|
+
value: 'documentDefinitions',
|
|
209
|
+
description: 'Get document definitions dictionary',
|
|
210
|
+
action: 'Get document definitions',
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: 'Accounting Categories',
|
|
214
|
+
value: 'accountingCategories',
|
|
215
|
+
description: 'Get accounting categories dictionary',
|
|
216
|
+
action: 'Get accounting categories',
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
default: 'paymentMethods',
|
|
220
|
+
},
|
|
172
221
|
// Document Operations
|
|
173
222
|
{
|
|
174
223
|
displayName: 'Operation',
|
|
@@ -379,18 +428,30 @@ class OptimaRestApi {
|
|
|
379
428
|
});
|
|
380
429
|
// API returns { Success: true, Customers: [...], TotalCount: ... }
|
|
381
430
|
const responseData = response;
|
|
431
|
+
// Preserve binary data from input item
|
|
432
|
+
const inputItem = items[i];
|
|
433
|
+
const binaryData = inputItem.binary;
|
|
382
434
|
// Extract customers array from response
|
|
383
435
|
if (responseData.Customers && Array.isArray(responseData.Customers)) {
|
|
384
|
-
const
|
|
385
|
-
|
|
436
|
+
const resultItems = responseData.Customers.map(item => ({
|
|
437
|
+
json: item,
|
|
438
|
+
binary: binaryData
|
|
439
|
+
}));
|
|
440
|
+
returnData.push(...resultItems);
|
|
386
441
|
}
|
|
387
442
|
else if (responseData.Customers) {
|
|
388
443
|
// Single customer
|
|
389
|
-
returnData.push({
|
|
444
|
+
returnData.push({
|
|
445
|
+
json: responseData.Customers,
|
|
446
|
+
binary: binaryData
|
|
447
|
+
});
|
|
390
448
|
}
|
|
391
449
|
else {
|
|
392
450
|
// Fallback - return entire response if structure is unexpected
|
|
393
|
-
returnData.push({
|
|
451
|
+
returnData.push({
|
|
452
|
+
json: responseData,
|
|
453
|
+
binary: binaryData
|
|
454
|
+
});
|
|
394
455
|
}
|
|
395
456
|
}
|
|
396
457
|
else if (operation === 'create') {
|
|
@@ -404,7 +465,10 @@ class OptimaRestApi {
|
|
|
404
465
|
body: customerData,
|
|
405
466
|
json: true,
|
|
406
467
|
});
|
|
407
|
-
returnData.push({
|
|
468
|
+
returnData.push({
|
|
469
|
+
json: response,
|
|
470
|
+
binary: items[i].binary
|
|
471
|
+
});
|
|
408
472
|
}
|
|
409
473
|
else if (operation === 'update') {
|
|
410
474
|
const customerId = this.getNodeParameter('customerId', i);
|
|
@@ -420,7 +484,10 @@ class OptimaRestApi {
|
|
|
420
484
|
body: customerData,
|
|
421
485
|
json: true,
|
|
422
486
|
});
|
|
423
|
-
returnData.push({
|
|
487
|
+
returnData.push({
|
|
488
|
+
json: response,
|
|
489
|
+
binary: items[i].binary
|
|
490
|
+
});
|
|
424
491
|
}
|
|
425
492
|
else if (operation === 'delete') {
|
|
426
493
|
const customerId = this.getNodeParameter('customerId', i);
|
|
@@ -432,7 +499,10 @@ class OptimaRestApi {
|
|
|
432
499
|
},
|
|
433
500
|
json: true,
|
|
434
501
|
});
|
|
435
|
-
returnData.push({
|
|
502
|
+
returnData.push({
|
|
503
|
+
json: { success: true, id: customerId },
|
|
504
|
+
binary: items[i].binary
|
|
505
|
+
});
|
|
436
506
|
}
|
|
437
507
|
}
|
|
438
508
|
else if (resource === 'document') {
|
|
@@ -448,7 +518,50 @@ class OptimaRestApi {
|
|
|
448
518
|
body: documentData,
|
|
449
519
|
json: true,
|
|
450
520
|
});
|
|
451
|
-
returnData.push({
|
|
521
|
+
returnData.push({
|
|
522
|
+
json: response,
|
|
523
|
+
binary: items[i].binary
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
else if (resource === 'dictionary') {
|
|
528
|
+
// Dictionary operations - map operation names to API endpoints
|
|
529
|
+
const dictionaryEndpoints = {
|
|
530
|
+
paymentMethods: { endpoint: 'Dictionary/PaymentMethods', dataKey: 'PaymentMethods' },
|
|
531
|
+
warehouses: { endpoint: 'Dictionary/Warehouses', dataKey: 'Warehouses' },
|
|
532
|
+
currencies: { endpoint: 'Dictionary/Currencies', dataKey: 'Currencies' },
|
|
533
|
+
documentDefinitions: { endpoint: 'Dictionary/DocumentDefinitions', dataKey: 'DocumentDefinitions' },
|
|
534
|
+
accountingCategories: { endpoint: 'Dictionary/AccountingCategories', dataKey: 'AccountingCategories' },
|
|
535
|
+
};
|
|
536
|
+
const dictConfig = dictionaryEndpoints[operation];
|
|
537
|
+
if (dictConfig) {
|
|
538
|
+
const response = await this.helpers.request({
|
|
539
|
+
method: 'GET',
|
|
540
|
+
url: `${gatewayUrl}/api/${dictConfig.endpoint}`,
|
|
541
|
+
headers: {
|
|
542
|
+
Authorization: `Bearer ${token}`,
|
|
543
|
+
},
|
|
544
|
+
json: true,
|
|
545
|
+
});
|
|
546
|
+
// API returns { Success: true, [DataKey]: [...], TotalCount: ... }
|
|
547
|
+
const responseData = response;
|
|
548
|
+
// Preserve binary data from input item
|
|
549
|
+
const binaryData = items[i].binary;
|
|
550
|
+
// Extract dictionary array from response
|
|
551
|
+
if (responseData[dictConfig.dataKey] && Array.isArray(responseData[dictConfig.dataKey])) {
|
|
552
|
+
const resultItems = responseData[dictConfig.dataKey].map(item => ({
|
|
553
|
+
json: item,
|
|
554
|
+
binary: binaryData
|
|
555
|
+
}));
|
|
556
|
+
returnData.push(...resultItems);
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
// Fallback - return entire response if structure is unexpected
|
|
560
|
+
returnData.push({
|
|
561
|
+
json: responseData,
|
|
562
|
+
binary: binaryData
|
|
563
|
+
});
|
|
564
|
+
}
|
|
452
565
|
}
|
|
453
566
|
}
|
|
454
567
|
else if (resource === 'product') {
|
|
@@ -462,7 +575,10 @@ class OptimaRestApi {
|
|
|
462
575
|
},
|
|
463
576
|
json: true,
|
|
464
577
|
});
|
|
465
|
-
returnData.push({
|
|
578
|
+
returnData.push({
|
|
579
|
+
json: response,
|
|
580
|
+
binary: items[i].binary
|
|
581
|
+
});
|
|
466
582
|
}
|
|
467
583
|
else if (operation === 'getAll') {
|
|
468
584
|
const response = await this.helpers.request({
|
|
@@ -473,8 +589,12 @@ class OptimaRestApi {
|
|
|
473
589
|
},
|
|
474
590
|
json: true,
|
|
475
591
|
});
|
|
476
|
-
const
|
|
477
|
-
|
|
592
|
+
const binaryData = items[i].binary;
|
|
593
|
+
const resultItems = response.map(item => ({
|
|
594
|
+
json: item,
|
|
595
|
+
binary: binaryData
|
|
596
|
+
}));
|
|
597
|
+
returnData.push(...resultItems);
|
|
478
598
|
}
|
|
479
599
|
}
|
|
480
600
|
else if (resource === 'print') {
|
|
@@ -519,7 +639,10 @@ class OptimaRestApi {
|
|
|
519
639
|
catch (error) {
|
|
520
640
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
521
641
|
if (this.continueOnFail()) {
|
|
522
|
-
returnData.push({
|
|
642
|
+
returnData.push({
|
|
643
|
+
json: { error: errorMessage },
|
|
644
|
+
binary: items[i].binary
|
|
645
|
+
});
|
|
523
646
|
continue;
|
|
524
647
|
}
|
|
525
648
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|