@pokash/n8n-nodes-optima-rest-api 1.1.12 → 1.1.21
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.
|
@@ -156,6 +156,25 @@ class OptimaRestApi {
|
|
|
156
156
|
default: 100,
|
|
157
157
|
description: 'Maximum number of records to return (for pagination)',
|
|
158
158
|
},
|
|
159
|
+
{
|
|
160
|
+
displayName: 'Output Mode',
|
|
161
|
+
name: 'outputMode',
|
|
162
|
+
type: 'options',
|
|
163
|
+
options: [
|
|
164
|
+
{
|
|
165
|
+
name: 'Multiple Items (Split)',
|
|
166
|
+
value: 'split',
|
|
167
|
+
description: 'Return each customer as a separate item',
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: 'Single Item (Array)',
|
|
171
|
+
value: 'array',
|
|
172
|
+
description: 'Return all customers in a single item as an array',
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
default: 'split',
|
|
176
|
+
description: 'How to return the results',
|
|
177
|
+
},
|
|
159
178
|
],
|
|
160
179
|
},
|
|
161
180
|
// Customer fields for create/update
|
|
@@ -218,6 +237,40 @@ class OptimaRestApi {
|
|
|
218
237
|
],
|
|
219
238
|
default: 'paymentMethods',
|
|
220
239
|
},
|
|
240
|
+
// Dictionary Options
|
|
241
|
+
{
|
|
242
|
+
displayName: 'Options',
|
|
243
|
+
name: 'options',
|
|
244
|
+
type: 'collection',
|
|
245
|
+
placeholder: 'Add Option',
|
|
246
|
+
default: {},
|
|
247
|
+
displayOptions: {
|
|
248
|
+
show: {
|
|
249
|
+
resource: ['dictionary'],
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
options: [
|
|
253
|
+
{
|
|
254
|
+
displayName: 'Output Mode',
|
|
255
|
+
name: 'outputMode',
|
|
256
|
+
type: 'options',
|
|
257
|
+
options: [
|
|
258
|
+
{
|
|
259
|
+
name: 'Single Item (Array)',
|
|
260
|
+
value: 'array',
|
|
261
|
+
description: 'Return all items in a single item as an array',
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
name: 'Multiple Items (Split)',
|
|
265
|
+
value: 'split',
|
|
266
|
+
description: 'Return each item as a separate item',
|
|
267
|
+
},
|
|
268
|
+
],
|
|
269
|
+
default: 'array',
|
|
270
|
+
description: 'How to return the results',
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
},
|
|
221
274
|
// Document Operations
|
|
222
275
|
{
|
|
223
276
|
displayName: 'Operation',
|
|
@@ -236,10 +289,16 @@ class OptimaRestApi {
|
|
|
236
289
|
description: 'Create a sales or purchase invoice',
|
|
237
290
|
action: 'Create an invoice',
|
|
238
291
|
},
|
|
292
|
+
{
|
|
293
|
+
name: 'Create Additional Record',
|
|
294
|
+
value: 'createAdditionalRecord',
|
|
295
|
+
description: 'Create additional purchase/sale record (expense/income)',
|
|
296
|
+
action: 'Create an additional record',
|
|
297
|
+
},
|
|
239
298
|
],
|
|
240
299
|
default: 'createInvoice',
|
|
241
300
|
},
|
|
242
|
-
// Document Type
|
|
301
|
+
// Document Type for Invoice
|
|
243
302
|
{
|
|
244
303
|
displayName: 'Document Type',
|
|
245
304
|
name: 'documentType',
|
|
@@ -262,7 +321,30 @@ class OptimaRestApi {
|
|
|
262
321
|
],
|
|
263
322
|
default: 'Sale',
|
|
264
323
|
},
|
|
265
|
-
//
|
|
324
|
+
// Record Type for Additional Record
|
|
325
|
+
{
|
|
326
|
+
displayName: 'Record Type',
|
|
327
|
+
name: 'recordType',
|
|
328
|
+
type: 'options',
|
|
329
|
+
displayOptions: {
|
|
330
|
+
show: {
|
|
331
|
+
resource: ['document'],
|
|
332
|
+
operation: ['createAdditionalRecord'],
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
options: [
|
|
336
|
+
{
|
|
337
|
+
name: 'Purchase (Expense)',
|
|
338
|
+
value: 'Purchase',
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
name: 'Sale (Income)',
|
|
342
|
+
value: 'Sale',
|
|
343
|
+
},
|
|
344
|
+
],
|
|
345
|
+
default: 'Purchase',
|
|
346
|
+
},
|
|
347
|
+
// Document Data for Invoice
|
|
266
348
|
{
|
|
267
349
|
displayName: 'Document Data',
|
|
268
350
|
name: 'documentData',
|
|
@@ -277,6 +359,21 @@ class OptimaRestApi {
|
|
|
277
359
|
default: '{\n "platnik": {\n "akronim": "KLIENT01"\n },\n "pozycje": [\n {\n "kod": "PROD01",\n "ilosc": 1,\n "cena": 100\n }\n ]\n}',
|
|
278
360
|
description: 'Document data in JSON format',
|
|
279
361
|
},
|
|
362
|
+
// Record Data for Additional Record
|
|
363
|
+
{
|
|
364
|
+
displayName: 'Record Data',
|
|
365
|
+
name: 'recordData',
|
|
366
|
+
type: 'json',
|
|
367
|
+
required: true,
|
|
368
|
+
displayOptions: {
|
|
369
|
+
show: {
|
|
370
|
+
resource: ['document'],
|
|
371
|
+
operation: ['createAdditionalRecord'],
|
|
372
|
+
},
|
|
373
|
+
},
|
|
374
|
+
default: '{\n "platnik": {\n "akronim": "KLIENT01"\n },\n "pozycje": [\n {\n "kod": "PROD01",\n "ilosc": 1,\n "cena": 100\n }\n ]\n}',
|
|
375
|
+
description: 'Additional record data in JSON format',
|
|
376
|
+
},
|
|
280
377
|
// Product Operations
|
|
281
378
|
{
|
|
282
379
|
displayName: 'Operation',
|
|
@@ -319,6 +416,41 @@ class OptimaRestApi {
|
|
|
319
416
|
default: 0,
|
|
320
417
|
description: 'The ID of the product',
|
|
321
418
|
},
|
|
419
|
+
// Product Options
|
|
420
|
+
{
|
|
421
|
+
displayName: 'Options',
|
|
422
|
+
name: 'options',
|
|
423
|
+
type: 'collection',
|
|
424
|
+
placeholder: 'Add Option',
|
|
425
|
+
default: {},
|
|
426
|
+
displayOptions: {
|
|
427
|
+
show: {
|
|
428
|
+
resource: ['product'],
|
|
429
|
+
operation: ['getAll'],
|
|
430
|
+
},
|
|
431
|
+
},
|
|
432
|
+
options: [
|
|
433
|
+
{
|
|
434
|
+
displayName: 'Output Mode',
|
|
435
|
+
name: 'outputMode',
|
|
436
|
+
type: 'options',
|
|
437
|
+
options: [
|
|
438
|
+
{
|
|
439
|
+
name: 'Multiple Items (Split)',
|
|
440
|
+
value: 'split',
|
|
441
|
+
description: 'Return each product as a separate item',
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
name: 'Single Item (Array)',
|
|
445
|
+
value: 'array',
|
|
446
|
+
description: 'Return all products in a single item as an array',
|
|
447
|
+
},
|
|
448
|
+
],
|
|
449
|
+
default: 'split',
|
|
450
|
+
description: 'How to return the results',
|
|
451
|
+
},
|
|
452
|
+
],
|
|
453
|
+
},
|
|
322
454
|
// Print Operations
|
|
323
455
|
{
|
|
324
456
|
displayName: 'Operation',
|
|
@@ -431,26 +563,40 @@ class OptimaRestApi {
|
|
|
431
563
|
// Extract customers array from response
|
|
432
564
|
if (responseData.Customers && Array.isArray(responseData.Customers)) {
|
|
433
565
|
const customers = responseData.Customers;
|
|
434
|
-
|
|
435
|
-
if (
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
});
|
|
445
|
-
});
|
|
566
|
+
const outputMode = options.outputMode || 'split';
|
|
567
|
+
if (outputMode === 'array') {
|
|
568
|
+
// Return entire response as single item
|
|
569
|
+
const result = {
|
|
570
|
+
json: responseData
|
|
571
|
+
};
|
|
572
|
+
if (items[i].binary) {
|
|
573
|
+
result.binary = items[i].binary;
|
|
574
|
+
}
|
|
575
|
+
returnData.push(result);
|
|
446
576
|
}
|
|
447
577
|
else {
|
|
448
|
-
//
|
|
449
|
-
|
|
578
|
+
// Split mode - return each customer as separate item
|
|
579
|
+
if (items[i].binary) {
|
|
580
|
+
// First item gets binary
|
|
450
581
|
returnData.push({
|
|
451
|
-
json:
|
|
582
|
+
json: customers[0] || {},
|
|
583
|
+
binary: items[i].binary
|
|
452
584
|
});
|
|
453
|
-
|
|
585
|
+
// Remaining items without binary
|
|
586
|
+
customers.slice(1).forEach((item) => {
|
|
587
|
+
returnData.push({
|
|
588
|
+
json: item
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
// No binary - just add all customers normally
|
|
594
|
+
customers.forEach((item) => {
|
|
595
|
+
returnData.push({
|
|
596
|
+
json: item
|
|
597
|
+
});
|
|
598
|
+
});
|
|
599
|
+
}
|
|
454
600
|
}
|
|
455
601
|
}
|
|
456
602
|
else if (responseData.Customers) {
|
|
@@ -555,8 +701,29 @@ class OptimaRestApi {
|
|
|
555
701
|
}
|
|
556
702
|
returnData.push(result);
|
|
557
703
|
}
|
|
704
|
+
else if (operation === 'createAdditionalRecord') {
|
|
705
|
+
const recordType = this.getNodeParameter('recordType', i);
|
|
706
|
+
const recordData = JSON.parse(this.getNodeParameter('recordData', i));
|
|
707
|
+
const response = await this.helpers.request({
|
|
708
|
+
method: 'POST',
|
|
709
|
+
url: `${gatewayUrl}/api/Documents/AdditionalRecords/${recordType}`,
|
|
710
|
+
headers: {
|
|
711
|
+
Authorization: `Bearer ${token}`,
|
|
712
|
+
},
|
|
713
|
+
body: recordData,
|
|
714
|
+
json: true,
|
|
715
|
+
});
|
|
716
|
+
const result = {
|
|
717
|
+
json: response
|
|
718
|
+
};
|
|
719
|
+
if (items[i].binary) {
|
|
720
|
+
result.binary = items[i].binary;
|
|
721
|
+
}
|
|
722
|
+
returnData.push(result);
|
|
723
|
+
}
|
|
558
724
|
}
|
|
559
725
|
else if (resource === 'dictionary') {
|
|
726
|
+
const options = this.getNodeParameter('options', i, {});
|
|
560
727
|
// Dictionary operations - map operation names to API endpoints
|
|
561
728
|
const dictionaryEndpoints = {
|
|
562
729
|
paymentMethods: { endpoint: 'Dictionary/PaymentMethods', dataKey: 'PaymentMethods' },
|
|
@@ -577,29 +744,43 @@ class OptimaRestApi {
|
|
|
577
744
|
});
|
|
578
745
|
// API returns { Success: true, [DataKey]: [...], TotalCount: ... }
|
|
579
746
|
const responseData = response;
|
|
747
|
+
const outputMode = options.outputMode || 'array';
|
|
580
748
|
// Extract dictionary array from response
|
|
581
749
|
if (responseData[dictConfig.dataKey] && Array.isArray(responseData[dictConfig.dataKey])) {
|
|
582
750
|
const dictItems = responseData[dictConfig.dataKey];
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
json:
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
json: item
|
|
593
|
-
});
|
|
594
|
-
});
|
|
751
|
+
if (outputMode === 'array') {
|
|
752
|
+
// Return entire response as single item
|
|
753
|
+
const result = {
|
|
754
|
+
json: responseData
|
|
755
|
+
};
|
|
756
|
+
if (items[i].binary) {
|
|
757
|
+
result.binary = items[i].binary;
|
|
758
|
+
}
|
|
759
|
+
returnData.push(result);
|
|
595
760
|
}
|
|
596
761
|
else {
|
|
597
|
-
//
|
|
598
|
-
|
|
762
|
+
// Split mode - return each item separately
|
|
763
|
+
if (items[i].binary) {
|
|
764
|
+
// First item gets binary
|
|
599
765
|
returnData.push({
|
|
600
|
-
json:
|
|
766
|
+
json: dictItems[0] || {},
|
|
767
|
+
binary: items[i].binary
|
|
601
768
|
});
|
|
602
|
-
|
|
769
|
+
// Remaining items without binary
|
|
770
|
+
dictItems.slice(1).forEach((item) => {
|
|
771
|
+
returnData.push({
|
|
772
|
+
json: item
|
|
773
|
+
});
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
else {
|
|
777
|
+
// No binary - just add all items normally
|
|
778
|
+
dictItems.forEach((item) => {
|
|
779
|
+
returnData.push({
|
|
780
|
+
json: item
|
|
781
|
+
});
|
|
782
|
+
});
|
|
783
|
+
}
|
|
603
784
|
}
|
|
604
785
|
}
|
|
605
786
|
else {
|
|
@@ -634,6 +815,7 @@ class OptimaRestApi {
|
|
|
634
815
|
returnData.push(result);
|
|
635
816
|
}
|
|
636
817
|
else if (operation === 'getAll') {
|
|
818
|
+
const options = this.getNodeParameter('options', i, {});
|
|
637
819
|
const response = await this.helpers.request({
|
|
638
820
|
method: 'GET',
|
|
639
821
|
url: `${gatewayUrl}/api/product`,
|
|
@@ -643,26 +825,40 @@ class OptimaRestApi {
|
|
|
643
825
|
json: true,
|
|
644
826
|
});
|
|
645
827
|
const products = response;
|
|
646
|
-
|
|
647
|
-
if (
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
});
|
|
657
|
-
});
|
|
828
|
+
const outputMode = options.outputMode || 'split';
|
|
829
|
+
if (outputMode === 'array') {
|
|
830
|
+
// Return all products as array in single item
|
|
831
|
+
const result = {
|
|
832
|
+
json: { Products: products, TotalCount: products.length }
|
|
833
|
+
};
|
|
834
|
+
if (items[i].binary) {
|
|
835
|
+
result.binary = items[i].binary;
|
|
836
|
+
}
|
|
837
|
+
returnData.push(result);
|
|
658
838
|
}
|
|
659
839
|
else {
|
|
660
|
-
//
|
|
661
|
-
|
|
840
|
+
// Split mode - return each product as separate item
|
|
841
|
+
if (items[i].binary) {
|
|
842
|
+
// First item gets binary
|
|
662
843
|
returnData.push({
|
|
663
|
-
json:
|
|
844
|
+
json: products[0] || {},
|
|
845
|
+
binary: items[i].binary
|
|
846
|
+
});
|
|
847
|
+
// Remaining items without binary
|
|
848
|
+
products.slice(1).forEach((item) => {
|
|
849
|
+
returnData.push({
|
|
850
|
+
json: item
|
|
851
|
+
});
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
else {
|
|
855
|
+
// No binary - just add all products normally
|
|
856
|
+
products.forEach((item) => {
|
|
857
|
+
returnData.push({
|
|
858
|
+
json: item
|
|
859
|
+
});
|
|
664
860
|
});
|
|
665
|
-
}
|
|
861
|
+
}
|
|
666
862
|
}
|
|
667
863
|
}
|
|
668
864
|
}
|