@pokash/n8n-nodes-optima-rest-api 1.1.3 → 1.1.5

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.

@@ -428,30 +428,38 @@ class OptimaRestApi {
428
428
  });
429
429
  // API returns { Success: true, Customers: [...], TotalCount: ... }
430
430
  const responseData = response;
431
- // Preserve binary data from input item
432
- const inputItem = items[i];
433
- const binaryData = inputItem.binary;
434
431
  // Extract customers array from response
435
432
  if (responseData.Customers && Array.isArray(responseData.Customers)) {
436
- const resultItems = responseData.Customers.map(item => ({
437
- json: item,
438
- binary: binaryData
439
- }));
440
- returnData.push(...resultItems);
433
+ // For arrays, only preserve binary on first item to avoid duplication
434
+ const customers = responseData.Customers;
435
+ const inputBinary = items[i].binary;
436
+ customers.forEach((item, index) => {
437
+ returnData.push({
438
+ json: item,
439
+ // Only preserve binary on first item when splitting 1 input into many outputs
440
+ ...(index === 0 && inputBinary ? { binary: inputBinary } : {})
441
+ });
442
+ });
441
443
  }
442
444
  else if (responseData.Customers) {
443
- // Single customer
444
- returnData.push({
445
- json: responseData.Customers,
446
- binary: binaryData
447
- });
445
+ // Single customer - preserve binary
446
+ const result = {
447
+ json: responseData.Customers
448
+ };
449
+ if (items[i].binary) {
450
+ result.binary = items[i].binary;
451
+ }
452
+ returnData.push(result);
448
453
  }
449
454
  else {
450
455
  // Fallback - return entire response if structure is unexpected
451
- returnData.push({
452
- json: responseData,
453
- binary: binaryData
454
- });
456
+ const result = {
457
+ json: responseData
458
+ };
459
+ if (items[i].binary) {
460
+ result.binary = items[i].binary;
461
+ }
462
+ returnData.push(result);
455
463
  }
456
464
  }
457
465
  else if (operation === 'create') {
@@ -465,10 +473,13 @@ class OptimaRestApi {
465
473
  body: customerData,
466
474
  json: true,
467
475
  });
468
- returnData.push({
469
- json: response,
470
- binary: items[i].binary
471
- });
476
+ const result = {
477
+ json: response
478
+ };
479
+ if (items[i].binary) {
480
+ result.binary = items[i].binary;
481
+ }
482
+ returnData.push(result);
472
483
  }
473
484
  else if (operation === 'update') {
474
485
  const customerId = this.getNodeParameter('customerId', i);
@@ -484,10 +495,13 @@ class OptimaRestApi {
484
495
  body: customerData,
485
496
  json: true,
486
497
  });
487
- returnData.push({
488
- json: response,
489
- binary: items[i].binary
490
- });
498
+ const result = {
499
+ json: response
500
+ };
501
+ if (items[i].binary) {
502
+ result.binary = items[i].binary;
503
+ }
504
+ returnData.push(result);
491
505
  }
492
506
  else if (operation === 'delete') {
493
507
  const customerId = this.getNodeParameter('customerId', i);
@@ -499,10 +513,13 @@ class OptimaRestApi {
499
513
  },
500
514
  json: true,
501
515
  });
502
- returnData.push({
503
- json: { success: true, id: customerId },
504
- binary: items[i].binary
505
- });
516
+ const result = {
517
+ json: { success: true, id: customerId }
518
+ };
519
+ if (items[i].binary) {
520
+ result.binary = items[i].binary;
521
+ }
522
+ returnData.push(result);
506
523
  }
507
524
  }
508
525
  else if (resource === 'document') {
@@ -518,10 +535,13 @@ class OptimaRestApi {
518
535
  body: documentData,
519
536
  json: true,
520
537
  });
521
- returnData.push({
522
- json: response,
523
- binary: items[i].binary
524
- });
538
+ const result = {
539
+ json: response
540
+ };
541
+ if (items[i].binary) {
542
+ result.binary = items[i].binary;
543
+ }
544
+ returnData.push(result);
525
545
  }
526
546
  }
527
547
  else if (resource === 'dictionary') {
@@ -545,22 +565,31 @@ class OptimaRestApi {
545
565
  });
546
566
  // API returns { Success: true, [DataKey]: [...], TotalCount: ... }
547
567
  const responseData = response;
548
- // Preserve binary data from input item
549
- const binaryData = items[i].binary;
550
568
  // Extract dictionary array from response
551
569
  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);
570
+ // For arrays, only preserve binary on first item to avoid duplication
571
+ const dictItems = responseData[dictConfig.dataKey];
572
+ const inputBinary = items[i].binary;
573
+ dictItems.forEach((item, index) => {
574
+ const result = {
575
+ json: item
576
+ };
577
+ // Only preserve binary on first item when splitting 1 input into many outputs
578
+ if (index === 0 && inputBinary) {
579
+ result.binary = inputBinary;
580
+ }
581
+ returnData.push(result);
582
+ });
557
583
  }
558
584
  else {
559
585
  // Fallback - return entire response if structure is unexpected
560
- returnData.push({
561
- json: responseData,
562
- binary: binaryData
563
- });
586
+ const result = {
587
+ json: responseData
588
+ };
589
+ if (items[i].binary) {
590
+ result.binary = items[i].binary;
591
+ }
592
+ returnData.push(result);
564
593
  }
565
594
  }
566
595
  }
@@ -575,10 +604,13 @@ class OptimaRestApi {
575
604
  },
576
605
  json: true,
577
606
  });
578
- returnData.push({
579
- json: response,
580
- binary: items[i].binary
581
- });
607
+ const result = {
608
+ json: response
609
+ };
610
+ if (items[i].binary) {
611
+ result.binary = items[i].binary;
612
+ }
613
+ returnData.push(result);
582
614
  }
583
615
  else if (operation === 'getAll') {
584
616
  const response = await this.helpers.request({
@@ -589,12 +621,19 @@ class OptimaRestApi {
589
621
  },
590
622
  json: true,
591
623
  });
592
- const binaryData = items[i].binary;
593
- const resultItems = response.map(item => ({
594
- json: item,
595
- binary: binaryData
596
- }));
597
- returnData.push(...resultItems);
624
+ // For arrays, only preserve binary on first item to avoid duplication
625
+ const products = response;
626
+ const inputBinary = items[i].binary;
627
+ products.forEach((item, index) => {
628
+ const result = {
629
+ json: item
630
+ };
631
+ // Only preserve binary on first item when splitting 1 input into many outputs
632
+ if (index === 0 && inputBinary) {
633
+ result.binary = inputBinary;
634
+ }
635
+ returnData.push(result);
636
+ });
598
637
  }
599
638
  }
600
639
  else if (resource === 'print') {
@@ -639,10 +678,13 @@ class OptimaRestApi {
639
678
  catch (error) {
640
679
  const errorMessage = error instanceof Error ? error.message : String(error);
641
680
  if (this.continueOnFail()) {
642
- returnData.push({
643
- json: { error: errorMessage },
644
- binary: items[i].binary
645
- });
681
+ const result = {
682
+ json: { error: errorMessage }
683
+ };
684
+ if (items[i].binary) {
685
+ result.binary = items[i].binary;
686
+ }
687
+ returnData.push(result);
646
688
  continue;
647
689
  }
648
690
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pokash/n8n-nodes-optima-rest-api",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "n8n node for Comarch Optima REST API integration",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",