n8n-nodes-tiendanube 0.1.2 → 0.1.4

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.
@@ -7,7 +7,7 @@ class Tiendanube {
7
7
  this.description = {
8
8
  displayName: 'Tiendanube',
9
9
  name: 'tiendanube',
10
- icon: 'file:tiendanube.svg',
10
+ icon: 'file:tiendanube.png',
11
11
  group: ['transform'],
12
12
  version: 1,
13
13
  subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
@@ -34,6 +34,26 @@ class Tiendanube {
34
34
  name: 'Product',
35
35
  value: 'product',
36
36
  },
37
+ {
38
+ name: 'Order',
39
+ value: 'order',
40
+ },
41
+ {
42
+ name: 'Customer',
43
+ value: 'customer',
44
+ },
45
+ {
46
+ name: 'Category',
47
+ value: 'category',
48
+ },
49
+ {
50
+ name: 'Coupon',
51
+ value: 'coupon',
52
+ },
53
+ {
54
+ name: 'Webhook',
55
+ value: 'webhook',
56
+ },
37
57
  ],
38
58
  default: 'product',
39
59
  },
@@ -93,7 +113,7 @@ class Tiendanube {
93
113
  },
94
114
  },
95
115
  default: '',
96
- description: 'ID of the product to retrieve',
116
+ description: 'ID of the product',
97
117
  },
98
118
  {
99
119
  displayName: 'Return All',
@@ -188,22 +208,6 @@ class Tiendanube {
188
208
  name: 'Updated At (Descending)',
189
209
  value: 'updated-at-descending',
190
210
  },
191
- {
192
- name: 'Name (Ascending)',
193
- value: 'name-ascending',
194
- },
195
- {
196
- name: 'Name (Descending)',
197
- value: 'name-descending',
198
- },
199
- {
200
- name: 'Price (Ascending)',
201
- value: 'price-ascending',
202
- },
203
- {
204
- name: 'Price (Descending)',
205
- value: 'price-descending',
206
- },
207
211
  ],
208
212
  default: 'created-at-descending',
209
213
  description: 'Sort products by field',
@@ -222,7 +226,7 @@ class Tiendanube {
222
226
  },
223
227
  },
224
228
  default: '',
225
- description: 'Product name (Spanish). For multilingual use JSON format: {"es": "Producto", "en": "Product"}',
229
+ description: 'Product name',
226
230
  },
227
231
  {
228
232
  displayName: 'Additional Fields',
@@ -241,137 +245,40 @@ class Tiendanube {
241
245
  displayName: 'Description',
242
246
  name: 'description',
243
247
  type: 'string',
244
- typeOptions: {
245
- rows: 4,
246
- },
248
+ typeOptions: { rows: 4 },
247
249
  default: '',
248
- description: 'Product description',
249
250
  },
250
251
  {
251
252
  displayName: 'Price',
252
253
  name: 'price',
253
254
  type: 'number',
254
- typeOptions: {
255
- numberPrecision: 2,
256
- },
257
- default: 0,
258
- description: 'Product price',
259
- },
260
- {
261
- displayName: 'Promotional Price',
262
- name: 'promotional_price',
263
- type: 'number',
264
- typeOptions: {
265
- numberPrecision: 2,
266
- },
267
- default: 0,
268
- description: 'Promotional price (if on sale)',
269
- },
270
- {
271
- displayName: 'Cost Price',
272
- name: 'cost_price',
273
- type: 'number',
274
- typeOptions: {
275
- numberPrecision: 2,
276
- },
255
+ typeOptions: { numberPrecision: 2 },
277
256
  default: 0,
278
- description: 'Cost price of the product',
279
257
  },
280
258
  {
281
259
  displayName: 'SKU',
282
260
  name: 'sku',
283
261
  type: 'string',
284
262
  default: '',
285
- description: 'Stock Keeping Unit',
286
263
  },
287
264
  {
288
265
  displayName: 'Stock',
289
266
  name: 'stock',
290
267
  type: 'number',
291
268
  default: 0,
292
- description: 'Available stock quantity',
293
269
  },
294
270
  {
295
271
  displayName: 'Published',
296
272
  name: 'published',
297
273
  type: 'boolean',
298
274
  default: true,
299
- description: 'Whether the product is published',
300
- },
301
- {
302
- displayName: 'Free Shipping',
303
- name: 'free_shipping',
304
- type: 'boolean',
305
- default: false,
306
- description: 'Whether the product has free shipping',
307
- },
308
- {
309
- displayName: 'Weight',
310
- name: 'weight',
311
- type: 'number',
312
- typeOptions: {
313
- numberPrecision: 2,
314
- },
315
- default: 0,
316
- description: 'Product weight in kg',
317
- },
318
- {
319
- displayName: 'Width',
320
- name: 'width',
321
- type: 'number',
322
- typeOptions: {
323
- numberPrecision: 2,
324
- },
325
- default: 0,
326
- description: 'Product width in cm',
327
- },
328
- {
329
- displayName: 'Height',
330
- name: 'height',
331
- type: 'number',
332
- typeOptions: {
333
- numberPrecision: 2,
334
- },
335
- default: 0,
336
- description: 'Product height in cm',
337
- },
338
- {
339
- displayName: 'Depth',
340
- name: 'depth',
341
- type: 'number',
342
- typeOptions: {
343
- numberPrecision: 2,
344
- },
345
- default: 0,
346
- description: 'Product depth in cm',
347
- },
348
- {
349
- displayName: 'Brand',
350
- name: 'brand',
351
- type: 'string',
352
- default: '',
353
- description: 'Product brand',
354
- },
355
- {
356
- displayName: 'Categories (JSON)',
357
- name: 'categories',
358
- type: 'string',
359
- default: '',
360
- description: 'Product categories as JSON array. Example: [{"id": 123}, {"id": 456}]',
361
275
  },
362
276
  {
363
277
  displayName: 'Images (JSON)',
364
278
  name: 'images',
365
279
  type: 'string',
366
280
  default: '',
367
- description: 'Product images as JSON array. Example: [{"src": "https://example.com/image.jpg"}]',
368
- },
369
- {
370
- displayName: 'Variants (JSON)',
371
- name: 'variants',
372
- type: 'string',
373
- default: '',
374
- description: 'Product variants as JSON array',
281
+ description: 'JSON array: [{"src": "https://..."}]',
375
282
  },
376
283
  ],
377
284
  },
@@ -387,7 +294,6 @@ class Tiendanube {
387
294
  },
388
295
  },
389
296
  default: '',
390
- description: 'ID of the product to update',
391
297
  },
392
298
  {
393
299
  displayName: 'Update Fields',
@@ -407,175 +313,917 @@ class Tiendanube {
407
313
  name: 'name',
408
314
  type: 'string',
409
315
  default: '',
410
- description: 'Product name',
411
316
  },
412
317
  {
413
318
  displayName: 'Description',
414
319
  name: 'description',
415
320
  type: 'string',
416
- typeOptions: {
417
- rows: 4,
418
- },
419
321
  default: '',
420
- description: 'Product description',
421
322
  },
422
323
  {
423
324
  displayName: 'Price',
424
325
  name: 'price',
425
326
  type: 'number',
426
- typeOptions: {
427
- numberPrecision: 2,
428
- },
429
- default: 0,
430
- description: 'Product price',
431
- },
432
- {
433
- displayName: 'Promotional Price',
434
- name: 'promotional_price',
435
- type: 'number',
436
- typeOptions: {
437
- numberPrecision: 2,
438
- },
327
+ typeOptions: { numberPrecision: 2 },
439
328
  default: 0,
440
- description: 'Promotional price',
441
- },
442
- {
443
- displayName: 'Cost Price',
444
- name: 'cost_price',
445
- type: 'number',
446
- typeOptions: {
447
- numberPrecision: 2,
448
- },
449
- default: 0,
450
- description: 'Cost price',
451
- },
452
- {
453
- displayName: 'SKU',
454
- name: 'sku',
455
- type: 'string',
456
- default: '',
457
- description: 'Stock Keeping Unit',
458
329
  },
459
330
  {
460
331
  displayName: 'Stock',
461
332
  name: 'stock',
462
333
  type: 'number',
463
334
  default: 0,
464
- description: 'Available stock',
465
335
  },
466
336
  {
467
337
  displayName: 'Published',
468
338
  name: 'published',
469
339
  type: 'boolean',
470
340
  default: true,
471
- description: 'Whether the product is published',
472
341
  },
342
+ ],
343
+ },
344
+ {
345
+ displayName: 'Operation',
346
+ name: 'operation',
347
+ type: 'options',
348
+ noDataExpression: true,
349
+ displayOptions: {
350
+ show: {
351
+ resource: ['order'],
352
+ },
353
+ },
354
+ options: [
473
355
  {
474
- displayName: 'Free Shipping',
475
- name: 'free_shipping',
476
- type: 'boolean',
477
- default: false,
478
- description: 'Whether the product has free shipping',
356
+ name: 'Get',
357
+ value: 'get',
358
+ description: 'Get an order by ID',
359
+ action: 'Get an order',
479
360
  },
480
361
  {
481
- displayName: 'Weight',
482
- name: 'weight',
483
- type: 'number',
484
- typeOptions: {
485
- numberPrecision: 2,
486
- },
487
- default: 0,
488
- description: 'Product weight in kg',
362
+ name: 'Get Many',
363
+ value: 'getAll',
364
+ description: 'Get many orders',
365
+ action: 'Get many orders',
489
366
  },
490
367
  {
491
- displayName: 'Width',
492
- name: 'width',
493
- type: 'number',
494
- typeOptions: {
495
- numberPrecision: 2,
496
- },
497
- default: 0,
498
- description: 'Product width in cm',
368
+ name: 'Update',
369
+ value: 'update',
370
+ description: 'Update an order',
371
+ action: 'Update an order',
499
372
  },
500
373
  {
501
- displayName: 'Height',
502
- name: 'height',
503
- type: 'number',
504
- typeOptions: {
505
- numberPrecision: 2,
506
- },
507
- default: 0,
508
- description: 'Product height in cm',
374
+ name: 'Cancel',
375
+ value: 'cancel',
376
+ description: 'Cancel an order',
377
+ action: 'Cancel an order',
378
+ },
379
+ ],
380
+ default: 'get',
381
+ },
382
+ {
383
+ displayName: 'Order ID',
384
+ name: 'orderId',
385
+ type: 'string',
386
+ required: true,
387
+ displayOptions: {
388
+ show: {
389
+ resource: ['order'],
390
+ operation: ['get', 'update', 'cancel'],
391
+ },
392
+ },
393
+ default: '',
394
+ description: 'ID of the order',
395
+ },
396
+ {
397
+ displayName: 'Return All',
398
+ name: 'returnAll',
399
+ type: 'boolean',
400
+ displayOptions: {
401
+ show: {
402
+ resource: ['order'],
403
+ operation: ['getAll'],
404
+ },
405
+ },
406
+ default: false,
407
+ },
408
+ {
409
+ displayName: 'Limit',
410
+ name: 'limit',
411
+ type: 'number',
412
+ displayOptions: {
413
+ show: {
414
+ resource: ['order'],
415
+ operation: ['getAll'],
416
+ returnAll: [false],
417
+ },
418
+ },
419
+ typeOptions: {
420
+ minValue: 1,
421
+ maxValue: 200,
422
+ },
423
+ default: 50,
424
+ },
425
+ {
426
+ displayName: 'Filters',
427
+ name: 'filters',
428
+ type: 'collection',
429
+ placeholder: 'Add Filter',
430
+ default: {},
431
+ displayOptions: {
432
+ show: {
433
+ resource: ['order'],
434
+ operation: ['getAll'],
509
435
  },
436
+ },
437
+ options: [
510
438
  {
511
- displayName: 'Depth',
512
- name: 'depth',
513
- type: 'number',
514
- typeOptions: {
515
- numberPrecision: 2,
516
- },
517
- default: 0,
518
- description: 'Product depth in cm',
439
+ displayName: 'Status',
440
+ name: 'status',
441
+ type: 'options',
442
+ options: [
443
+ { name: 'Open', value: 'open' },
444
+ { name: 'Closed', value: 'closed' },
445
+ { name: 'Cancelled', value: 'cancelled' },
446
+ ],
447
+ default: 'open',
519
448
  },
520
449
  {
521
- displayName: 'Brand',
522
- name: 'brand',
523
- type: 'string',
524
- default: '',
525
- description: 'Product brand',
450
+ displayName: 'Payment Status',
451
+ name: 'payment_status',
452
+ type: 'options',
453
+ options: [
454
+ { name: 'Pending', value: 'pending' },
455
+ { name: 'Authorized', value: 'authorized' },
456
+ { name: 'Paid', value: 'paid' },
457
+ { name: 'Voided', value: 'voided' },
458
+ { name: 'Refunded', value: 'refunded' },
459
+ ],
460
+ default: 'pending',
526
461
  },
527
462
  {
528
- displayName: 'Categories (JSON)',
529
- name: 'categories',
463
+ displayName: 'Shipping Status',
464
+ name: 'shipping_status',
465
+ type: 'options',
466
+ options: [
467
+ { name: 'Unpacked', value: 'unpacked' },
468
+ { name: 'Packed', value: 'packed' },
469
+ { name: 'Fulfilled', value: 'fulfilled' },
470
+ ],
471
+ default: 'unpacked',
472
+ },
473
+ {
474
+ displayName: 'Created At Min',
475
+ name: 'created_at_min',
530
476
  type: 'string',
531
477
  default: '',
532
- description: 'Categories as JSON array',
478
+ description: 'ISO 8601 date (e.g., 2025-01-01T00:00:00-03:00)',
533
479
  },
534
480
  {
535
- displayName: 'Images (JSON)',
536
- name: 'images',
481
+ displayName: 'Created At Max',
482
+ name: 'created_at_max',
537
483
  type: 'string',
538
484
  default: '',
539
- description: 'Images as JSON array',
485
+ description: 'ISO 8601 date',
486
+ },
487
+ ],
488
+ },
489
+ {
490
+ displayName: 'Update Fields',
491
+ name: 'updateFields',
492
+ type: 'collection',
493
+ placeholder: 'Add Field',
494
+ default: {},
495
+ displayOptions: {
496
+ show: {
497
+ resource: ['order'],
498
+ operation: ['update'],
499
+ },
500
+ },
501
+ options: [
502
+ {
503
+ displayName: 'Status',
504
+ name: 'status',
505
+ type: 'options',
506
+ options: [
507
+ { name: 'Open', value: 'open' },
508
+ { name: 'Closed', value: 'closed' },
509
+ ],
510
+ default: 'open',
511
+ },
512
+ {
513
+ displayName: 'Payment Status',
514
+ name: 'payment_status',
515
+ type: 'options',
516
+ options: [
517
+ { name: 'Pending', value: 'pending' },
518
+ { name: 'Authorized', value: 'authorized' },
519
+ { name: 'Paid', value: 'paid' },
520
+ ],
521
+ default: 'pending',
522
+ },
523
+ {
524
+ displayName: 'Shipping Status',
525
+ name: 'shipping_status',
526
+ type: 'options',
527
+ options: [
528
+ { name: 'Unpacked', value: 'unpacked' },
529
+ { name: 'Packed', value: 'packed' },
530
+ { name: 'Fulfilled', value: 'fulfilled' },
531
+ ],
532
+ default: 'unpacked',
540
533
  },
541
534
  {
542
- displayName: 'Variants (JSON)',
543
- name: 'variants',
535
+ displayName: 'Note',
536
+ name: 'note',
544
537
  type: 'string',
545
538
  default: '',
546
- description: 'Variants as JSON array',
547
539
  },
548
540
  ],
549
541
  },
550
- ],
551
- };
552
- }
553
- async execute() {
554
- const items = this.getInputData();
555
- const returnData = [];
556
- const resource = this.getNodeParameter('resource', 0);
557
- const operation = this.getNodeParameter('operation', 0);
558
- const credentials = await this.getCredentials('tiendanubeApi');
559
- const storeId = credentials.storeId;
560
- const accessToken = credentials.accessToken;
561
- const baseUrl = `https://api.tiendanube.com/v1/${storeId}`;
562
- const makeRequest = async (method, endpoint, body, qs) => {
563
- const options = {
564
- method,
565
- url: `${baseUrl}${endpoint}`,
566
- headers: {
567
- 'Authentication': `bearer ${accessToken}`,
568
- 'User-Agent': 'n8n-tiendanube-node',
569
- 'Content-Type': 'application/json',
542
+ {
543
+ displayName: 'Operation',
544
+ name: 'operation',
545
+ type: 'options',
546
+ noDataExpression: true,
547
+ displayOptions: {
548
+ show: {
549
+ resource: ['customer'],
550
+ },
551
+ },
552
+ options: [
553
+ {
554
+ name: 'Create',
555
+ value: 'create',
556
+ description: 'Create a customer',
557
+ action: 'Create a customer',
558
+ },
559
+ {
560
+ name: 'Delete',
561
+ value: 'delete',
562
+ description: 'Delete a customer',
563
+ action: 'Delete a customer',
564
+ },
565
+ {
566
+ name: 'Get',
567
+ value: 'get',
568
+ description: 'Get a customer',
569
+ action: 'Get a customer',
570
+ },
571
+ {
572
+ name: 'Get Many',
573
+ value: 'getAll',
574
+ description: 'Get many customers',
575
+ action: 'Get many customers',
576
+ },
577
+ {
578
+ name: 'Update',
579
+ value: 'update',
580
+ description: 'Update a customer',
581
+ action: 'Update a customer',
582
+ },
583
+ ],
584
+ default: 'get',
570
585
  },
571
- body,
572
- qs,
573
- json: true,
574
- };
575
- try {
576
- return await this.helpers.httpRequest(options);
577
- }
578
- catch (error) {
586
+ {
587
+ displayName: 'Customer ID',
588
+ name: 'customerId',
589
+ type: 'string',
590
+ required: true,
591
+ displayOptions: {
592
+ show: {
593
+ resource: ['customer'],
594
+ operation: ['get', 'delete', 'update'],
595
+ },
596
+ },
597
+ default: '',
598
+ },
599
+ {
600
+ displayName: 'Return All',
601
+ name: 'returnAll',
602
+ type: 'boolean',
603
+ displayOptions: {
604
+ show: {
605
+ resource: ['customer'],
606
+ operation: ['getAll'],
607
+ },
608
+ },
609
+ default: false,
610
+ },
611
+ {
612
+ displayName: 'Limit',
613
+ name: 'limit',
614
+ type: 'number',
615
+ displayOptions: {
616
+ show: {
617
+ resource: ['customer'],
618
+ operation: ['getAll'],
619
+ returnAll: [false],
620
+ },
621
+ },
622
+ typeOptions: {
623
+ minValue: 1,
624
+ maxValue: 200,
625
+ },
626
+ default: 50,
627
+ },
628
+ {
629
+ displayName: 'Filters',
630
+ name: 'filters',
631
+ type: 'collection',
632
+ placeholder: 'Add Filter',
633
+ default: {},
634
+ displayOptions: {
635
+ show: {
636
+ resource: ['customer'],
637
+ operation: ['getAll'],
638
+ },
639
+ },
640
+ options: [
641
+ {
642
+ displayName: 'Email',
643
+ name: 'email',
644
+ type: 'string',
645
+ default: '',
646
+ },
647
+ {
648
+ displayName: 'Name',
649
+ name: 'name',
650
+ type: 'string',
651
+ default: '',
652
+ },
653
+ ],
654
+ },
655
+ {
656
+ displayName: 'Email',
657
+ name: 'email',
658
+ type: 'string',
659
+ required: true,
660
+ displayOptions: {
661
+ show: {
662
+ resource: ['customer'],
663
+ operation: ['create'],
664
+ },
665
+ },
666
+ default: '',
667
+ },
668
+ {
669
+ displayName: 'Additional Fields',
670
+ name: 'additionalFields',
671
+ type: 'collection',
672
+ placeholder: 'Add Field',
673
+ default: {},
674
+ displayOptions: {
675
+ show: {
676
+ resource: ['customer'],
677
+ operation: ['create'],
678
+ },
679
+ },
680
+ options: [
681
+ {
682
+ displayName: 'Name',
683
+ name: 'name',
684
+ type: 'string',
685
+ default: '',
686
+ },
687
+ {
688
+ displayName: 'Phone',
689
+ name: 'phone',
690
+ type: 'string',
691
+ default: '',
692
+ },
693
+ {
694
+ displayName: 'Identification',
695
+ name: 'identification',
696
+ type: 'string',
697
+ default: '',
698
+ },
699
+ {
700
+ displayName: 'Note',
701
+ name: 'note',
702
+ type: 'string',
703
+ default: '',
704
+ },
705
+ ],
706
+ },
707
+ {
708
+ displayName: 'Update Fields',
709
+ name: 'updateFields',
710
+ type: 'collection',
711
+ placeholder: 'Add Field',
712
+ default: {},
713
+ displayOptions: {
714
+ show: {
715
+ resource: ['customer'],
716
+ operation: ['update'],
717
+ },
718
+ },
719
+ options: [
720
+ {
721
+ displayName: 'Email',
722
+ name: 'email',
723
+ type: 'string',
724
+ default: '',
725
+ },
726
+ {
727
+ displayName: 'Name',
728
+ name: 'name',
729
+ type: 'string',
730
+ default: '',
731
+ },
732
+ {
733
+ displayName: 'Phone',
734
+ name: 'phone',
735
+ type: 'string',
736
+ default: '',
737
+ },
738
+ {
739
+ displayName: 'Note',
740
+ name: 'note',
741
+ type: 'string',
742
+ default: '',
743
+ },
744
+ ],
745
+ },
746
+ {
747
+ displayName: 'Operation',
748
+ name: 'operation',
749
+ type: 'options',
750
+ noDataExpression: true,
751
+ displayOptions: {
752
+ show: {
753
+ resource: ['category'],
754
+ },
755
+ },
756
+ options: [
757
+ {
758
+ name: 'Create',
759
+ value: 'create',
760
+ action: 'Create a category',
761
+ },
762
+ {
763
+ name: 'Delete',
764
+ value: 'delete',
765
+ action: 'Delete a category',
766
+ },
767
+ {
768
+ name: 'Get',
769
+ value: 'get',
770
+ action: 'Get a category',
771
+ },
772
+ {
773
+ name: 'Get Many',
774
+ value: 'getAll',
775
+ action: 'Get many categories',
776
+ },
777
+ {
778
+ name: 'Update',
779
+ value: 'update',
780
+ action: 'Update a category',
781
+ },
782
+ ],
783
+ default: 'get',
784
+ },
785
+ {
786
+ displayName: 'Category ID',
787
+ name: 'categoryId',
788
+ type: 'string',
789
+ required: true,
790
+ displayOptions: {
791
+ show: {
792
+ resource: ['category'],
793
+ operation: ['get', 'delete', 'update'],
794
+ },
795
+ },
796
+ default: '',
797
+ },
798
+ {
799
+ displayName: 'Return All',
800
+ name: 'returnAll',
801
+ type: 'boolean',
802
+ displayOptions: {
803
+ show: {
804
+ resource: ['category'],
805
+ operation: ['getAll'],
806
+ },
807
+ },
808
+ default: false,
809
+ },
810
+ {
811
+ displayName: 'Limit',
812
+ name: 'limit',
813
+ type: 'number',
814
+ displayOptions: {
815
+ show: {
816
+ resource: ['category'],
817
+ operation: ['getAll'],
818
+ returnAll: [false],
819
+ },
820
+ },
821
+ typeOptions: {
822
+ minValue: 1,
823
+ maxValue: 200,
824
+ },
825
+ default: 50,
826
+ },
827
+ {
828
+ displayName: 'Name',
829
+ name: 'name',
830
+ type: 'string',
831
+ required: true,
832
+ displayOptions: {
833
+ show: {
834
+ resource: ['category'],
835
+ operation: ['create'],
836
+ },
837
+ },
838
+ default: '',
839
+ },
840
+ {
841
+ displayName: 'Additional Fields',
842
+ name: 'additionalFields',
843
+ type: 'collection',
844
+ placeholder: 'Add Field',
845
+ default: {},
846
+ displayOptions: {
847
+ show: {
848
+ resource: ['category'],
849
+ operation: ['create'],
850
+ },
851
+ },
852
+ options: [
853
+ {
854
+ displayName: 'Description',
855
+ name: 'description',
856
+ type: 'string',
857
+ default: '',
858
+ },
859
+ {
860
+ displayName: 'Parent ID',
861
+ name: 'parent',
862
+ type: 'string',
863
+ default: '',
864
+ },
865
+ ],
866
+ },
867
+ {
868
+ displayName: 'Update Fields',
869
+ name: 'updateFields',
870
+ type: 'collection',
871
+ placeholder: 'Add Field',
872
+ default: {},
873
+ displayOptions: {
874
+ show: {
875
+ resource: ['category'],
876
+ operation: ['update'],
877
+ },
878
+ },
879
+ options: [
880
+ {
881
+ displayName: 'Name',
882
+ name: 'name',
883
+ type: 'string',
884
+ default: '',
885
+ },
886
+ {
887
+ displayName: 'Description',
888
+ name: 'description',
889
+ type: 'string',
890
+ default: '',
891
+ },
892
+ ],
893
+ },
894
+ {
895
+ displayName: 'Operation',
896
+ name: 'operation',
897
+ type: 'options',
898
+ noDataExpression: true,
899
+ displayOptions: {
900
+ show: {
901
+ resource: ['coupon'],
902
+ },
903
+ },
904
+ options: [
905
+ {
906
+ name: 'Create',
907
+ value: 'create',
908
+ action: 'Create a coupon',
909
+ },
910
+ {
911
+ name: 'Delete',
912
+ value: 'delete',
913
+ action: 'Delete a coupon',
914
+ },
915
+ {
916
+ name: 'Get',
917
+ value: 'get',
918
+ action: 'Get a coupon',
919
+ },
920
+ {
921
+ name: 'Get Many',
922
+ value: 'getAll',
923
+ action: 'Get many coupons',
924
+ },
925
+ {
926
+ name: 'Update',
927
+ value: 'update',
928
+ action: 'Update a coupon',
929
+ },
930
+ ],
931
+ default: 'get',
932
+ },
933
+ {
934
+ displayName: 'Coupon ID',
935
+ name: 'couponId',
936
+ type: 'string',
937
+ required: true,
938
+ displayOptions: {
939
+ show: {
940
+ resource: ['coupon'],
941
+ operation: ['get', 'delete', 'update'],
942
+ },
943
+ },
944
+ default: '',
945
+ },
946
+ {
947
+ displayName: 'Return All',
948
+ name: 'returnAll',
949
+ type: 'boolean',
950
+ displayOptions: {
951
+ show: {
952
+ resource: ['coupon'],
953
+ operation: ['getAll'],
954
+ },
955
+ },
956
+ default: false,
957
+ },
958
+ {
959
+ displayName: 'Limit',
960
+ name: 'limit',
961
+ type: 'number',
962
+ displayOptions: {
963
+ show: {
964
+ resource: ['coupon'],
965
+ operation: ['getAll'],
966
+ returnAll: [false],
967
+ },
968
+ },
969
+ typeOptions: {
970
+ minValue: 1,
971
+ maxValue: 200,
972
+ },
973
+ default: 50,
974
+ },
975
+ {
976
+ displayName: 'Code',
977
+ name: 'code',
978
+ type: 'string',
979
+ required: true,
980
+ displayOptions: {
981
+ show: {
982
+ resource: ['coupon'],
983
+ operation: ['create'],
984
+ },
985
+ },
986
+ default: '',
987
+ },
988
+ {
989
+ displayName: 'Type',
990
+ name: 'type',
991
+ type: 'options',
992
+ required: true,
993
+ displayOptions: {
994
+ show: {
995
+ resource: ['coupon'],
996
+ operation: ['create'],
997
+ },
998
+ },
999
+ options: [
1000
+ { name: 'Percentage', value: 'percentage' },
1001
+ { name: 'Absolute', value: 'absolute' },
1002
+ { name: 'Shipping', value: 'shipping' },
1003
+ ],
1004
+ default: 'percentage',
1005
+ },
1006
+ {
1007
+ displayName: 'Value',
1008
+ name: 'value',
1009
+ type: 'number',
1010
+ required: true,
1011
+ displayOptions: {
1012
+ show: {
1013
+ resource: ['coupon'],
1014
+ operation: ['create'],
1015
+ },
1016
+ },
1017
+ default: 0,
1018
+ description: 'Discount value (percentage or absolute amount)',
1019
+ },
1020
+ {
1021
+ displayName: 'Additional Fields',
1022
+ name: 'additionalFields',
1023
+ type: 'collection',
1024
+ placeholder: 'Add Field',
1025
+ default: {},
1026
+ displayOptions: {
1027
+ show: {
1028
+ resource: ['coupon'],
1029
+ operation: ['create'],
1030
+ },
1031
+ },
1032
+ options: [
1033
+ {
1034
+ displayName: 'Valid From',
1035
+ name: 'valid_from',
1036
+ type: 'string',
1037
+ default: '',
1038
+ description: 'ISO 8601 date',
1039
+ },
1040
+ {
1041
+ displayName: 'Valid Until',
1042
+ name: 'valid_until',
1043
+ type: 'string',
1044
+ default: '',
1045
+ description: 'ISO 8601 date',
1046
+ },
1047
+ {
1048
+ displayName: 'Max Uses',
1049
+ name: 'max_uses',
1050
+ type: 'number',
1051
+ default: 0,
1052
+ },
1053
+ ],
1054
+ },
1055
+ {
1056
+ displayName: 'Update Fields',
1057
+ name: 'updateFields',
1058
+ type: 'collection',
1059
+ placeholder: 'Add Field',
1060
+ default: {},
1061
+ displayOptions: {
1062
+ show: {
1063
+ resource: ['coupon'],
1064
+ operation: ['update'],
1065
+ },
1066
+ },
1067
+ options: [
1068
+ {
1069
+ displayName: 'Value',
1070
+ name: 'value',
1071
+ type: 'number',
1072
+ default: 0,
1073
+ },
1074
+ {
1075
+ displayName: 'Valid Until',
1076
+ name: 'valid_until',
1077
+ type: 'string',
1078
+ default: '',
1079
+ },
1080
+ ],
1081
+ },
1082
+ {
1083
+ displayName: 'Operation',
1084
+ name: 'operation',
1085
+ type: 'options',
1086
+ noDataExpression: true,
1087
+ displayOptions: {
1088
+ show: {
1089
+ resource: ['webhook'],
1090
+ },
1091
+ },
1092
+ options: [
1093
+ {
1094
+ name: 'Create',
1095
+ value: 'create',
1096
+ action: 'Create a webhook',
1097
+ },
1098
+ {
1099
+ name: 'Delete',
1100
+ value: 'delete',
1101
+ action: 'Delete a webhook',
1102
+ },
1103
+ {
1104
+ name: 'Get',
1105
+ value: 'get',
1106
+ action: 'Get a webhook',
1107
+ },
1108
+ {
1109
+ name: 'Get Many',
1110
+ value: 'getAll',
1111
+ action: 'Get many webhooks',
1112
+ },
1113
+ ],
1114
+ default: 'get',
1115
+ },
1116
+ {
1117
+ displayName: 'Webhook ID',
1118
+ name: 'webhookId',
1119
+ type: 'string',
1120
+ required: true,
1121
+ displayOptions: {
1122
+ show: {
1123
+ resource: ['webhook'],
1124
+ operation: ['get', 'delete'],
1125
+ },
1126
+ },
1127
+ default: '',
1128
+ },
1129
+ {
1130
+ displayName: 'Return All',
1131
+ name: 'returnAll',
1132
+ type: 'boolean',
1133
+ displayOptions: {
1134
+ show: {
1135
+ resource: ['webhook'],
1136
+ operation: ['getAll'],
1137
+ },
1138
+ },
1139
+ default: false,
1140
+ },
1141
+ {
1142
+ displayName: 'Limit',
1143
+ name: 'limit',
1144
+ type: 'number',
1145
+ displayOptions: {
1146
+ show: {
1147
+ resource: ['webhook'],
1148
+ operation: ['getAll'],
1149
+ returnAll: [false],
1150
+ },
1151
+ },
1152
+ typeOptions: {
1153
+ minValue: 1,
1154
+ maxValue: 200,
1155
+ },
1156
+ default: 50,
1157
+ },
1158
+ {
1159
+ displayName: 'Event',
1160
+ name: 'event',
1161
+ type: 'options',
1162
+ required: true,
1163
+ displayOptions: {
1164
+ show: {
1165
+ resource: ['webhook'],
1166
+ operation: ['create'],
1167
+ },
1168
+ },
1169
+ options: [
1170
+ { name: 'Order Created', value: 'order/created' },
1171
+ { name: 'Order Updated', value: 'order/updated' },
1172
+ { name: 'Order Paid', value: 'order/paid' },
1173
+ { name: 'Order Packed', value: 'order/packed' },
1174
+ { name: 'Order Fulfilled', value: 'order/fulfilled' },
1175
+ { name: 'Order Cancelled', value: 'order/cancelled' },
1176
+ { name: 'Product Created', value: 'product/created' },
1177
+ { name: 'Product Updated', value: 'product/updated' },
1178
+ { name: 'Product Deleted', value: 'product/deleted' },
1179
+ { name: 'Customer Created', value: 'customer/created' },
1180
+ { name: 'Customer Updated', value: 'customer/updated' },
1181
+ ],
1182
+ default: 'order/created',
1183
+ },
1184
+ {
1185
+ displayName: 'URL',
1186
+ name: 'url',
1187
+ type: 'string',
1188
+ required: true,
1189
+ displayOptions: {
1190
+ show: {
1191
+ resource: ['webhook'],
1192
+ operation: ['create'],
1193
+ },
1194
+ },
1195
+ default: '',
1196
+ description: 'HTTPS URL to receive webhook events',
1197
+ },
1198
+ ],
1199
+ };
1200
+ }
1201
+ async execute() {
1202
+ const items = this.getInputData();
1203
+ const returnData = [];
1204
+ const resource = this.getNodeParameter('resource', 0);
1205
+ const operation = this.getNodeParameter('operation', 0);
1206
+ const credentials = await this.getCredentials('tiendanubeApi');
1207
+ const storeId = credentials.storeId;
1208
+ const accessToken = credentials.accessToken;
1209
+ const baseUrl = `https://api.tiendanube.com/v1/${storeId}`;
1210
+ const makeRequest = async (method, endpoint, body, qs) => {
1211
+ const options = {
1212
+ method,
1213
+ url: `${baseUrl}${endpoint}`,
1214
+ headers: {
1215
+ 'Authentication': `bearer ${accessToken}`,
1216
+ 'User-Agent': 'n8n-tiendanube-node',
1217
+ 'Content-Type': 'application/json',
1218
+ },
1219
+ body,
1220
+ qs,
1221
+ json: true,
1222
+ };
1223
+ try {
1224
+ return await this.helpers.httpRequest(options);
1225
+ }
1226
+ catch (error) {
579
1227
  throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
580
1228
  }
581
1229
  };
@@ -583,8 +1231,7 @@ class Tiendanube {
583
1231
  if (!value)
584
1232
  return value;
585
1233
  try {
586
- const parsed = JSON.parse(value);
587
- return parsed;
1234
+ return JSON.parse(value);
588
1235
  }
589
1236
  catch {
590
1237
  return { es: value };
@@ -600,6 +1247,26 @@ class Tiendanube {
600
1247
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid JSON format: ${value}`);
601
1248
  }
602
1249
  };
1250
+ const getAllPaginated = async (endpoint, qs) => {
1251
+ let results = [];
1252
+ let page = 1;
1253
+ let hasMore = true;
1254
+ while (hasMore) {
1255
+ qs.page = page;
1256
+ const response = await makeRequest('GET', endpoint, undefined, qs);
1257
+ if (Array.isArray(response) && response.length > 0) {
1258
+ results = results.concat(response);
1259
+ page++;
1260
+ if (response.length < (qs.per_page || 200)) {
1261
+ hasMore = false;
1262
+ }
1263
+ }
1264
+ else {
1265
+ hasMore = false;
1266
+ }
1267
+ }
1268
+ return results;
1269
+ };
603
1270
  for (let i = 0; i < items.length; i++) {
604
1271
  try {
605
1272
  if (resource === 'product') {
@@ -611,10 +1278,7 @@ class Tiendanube {
611
1278
  else if (operation === 'getAll') {
612
1279
  const returnAll = this.getNodeParameter('returnAll', i);
613
1280
  const additionalFields = this.getNodeParameter('additionalFields', i);
614
- let products = [];
615
- const qs = {
616
- per_page: 200,
617
- };
1281
+ const qs = { per_page: 200 };
618
1282
  if (additionalFields.published !== undefined) {
619
1283
  qs.published = additionalFields.published;
620
1284
  }
@@ -631,30 +1295,16 @@ class Tiendanube {
631
1295
  qs.sort_by = additionalFields.sort_by;
632
1296
  }
633
1297
  if (returnAll) {
634
- let page = 1;
635
- let hasMore = true;
636
- while (hasMore) {
637
- qs.page = page;
638
- const response = await makeRequest('GET', '/products', undefined, qs);
639
- if (Array.isArray(response) && response.length > 0) {
640
- products = products.concat(response);
641
- page++;
642
- if (response.length < 200) {
643
- hasMore = false;
644
- }
645
- }
646
- else {
647
- hasMore = false;
648
- }
649
- }
1298
+ const products = await getAllPaginated('/products', qs);
1299
+ returnData.push(...products);
650
1300
  }
651
1301
  else {
652
1302
  const limit = this.getNodeParameter('limit', i);
653
1303
  qs.per_page = limit;
654
1304
  const response = await makeRequest('GET', '/products', undefined, qs);
655
- products = Array.isArray(response) ? response : [response];
1305
+ const products = Array.isArray(response) ? response : [response];
1306
+ returnData.push(...products);
656
1307
  }
657
- returnData.push(...products);
658
1308
  }
659
1309
  else if (operation === 'create') {
660
1310
  const name = this.getNodeParameter('name', i);
@@ -665,51 +1315,17 @@ class Tiendanube {
665
1315
  if (additionalFields.description) {
666
1316
  body.description = parseMultilingualField(additionalFields.description);
667
1317
  }
668
- if (additionalFields.price !== undefined) {
1318
+ if (additionalFields.price !== undefined)
669
1319
  body.price = additionalFields.price;
670
- }
671
- if (additionalFields.promotional_price !== undefined) {
672
- body.promotional_price = additionalFields.promotional_price;
673
- }
674
- if (additionalFields.cost_price !== undefined) {
675
- body.cost_price = additionalFields.cost_price;
676
- }
677
- if (additionalFields.sku) {
1320
+ if (additionalFields.sku)
678
1321
  body.sku = additionalFields.sku;
679
- }
680
- if (additionalFields.stock !== undefined) {
1322
+ if (additionalFields.stock !== undefined)
681
1323
  body.stock = additionalFields.stock;
682
- }
683
- if (additionalFields.published !== undefined) {
1324
+ if (additionalFields.published !== undefined)
684
1325
  body.published = additionalFields.published;
685
- }
686
- if (additionalFields.free_shipping !== undefined) {
687
- body.free_shipping = additionalFields.free_shipping;
688
- }
689
- if (additionalFields.weight !== undefined) {
690
- body.weight = additionalFields.weight;
691
- }
692
- if (additionalFields.width !== undefined) {
693
- body.width = additionalFields.width;
694
- }
695
- if (additionalFields.height !== undefined) {
696
- body.height = additionalFields.height;
697
- }
698
- if (additionalFields.depth !== undefined) {
699
- body.depth = additionalFields.depth;
700
- }
701
- if (additionalFields.brand) {
702
- body.brand = additionalFields.brand;
703
- }
704
- if (additionalFields.categories) {
705
- body.categories = parseJsonField(additionalFields.categories);
706
- }
707
1326
  if (additionalFields.images) {
708
1327
  body.images = parseJsonField(additionalFields.images);
709
1328
  }
710
- if (additionalFields.variants) {
711
- body.variants = parseJsonField(additionalFields.variants);
712
- }
713
1329
  const response = await makeRequest('POST', '/products', body);
714
1330
  returnData.push(response);
715
1331
  }
@@ -723,58 +1339,275 @@ class Tiendanube {
723
1339
  if (updateFields.description) {
724
1340
  body.description = parseMultilingualField(updateFields.description);
725
1341
  }
726
- if (updateFields.price !== undefined) {
1342
+ if (updateFields.price !== undefined)
727
1343
  body.price = updateFields.price;
1344
+ if (updateFields.stock !== undefined)
1345
+ body.stock = updateFields.stock;
1346
+ if (updateFields.published !== undefined)
1347
+ body.published = updateFields.published;
1348
+ const response = await makeRequest('PUT', `/products/${productId}`, body);
1349
+ returnData.push(response);
1350
+ }
1351
+ else if (operation === 'delete') {
1352
+ const productId = this.getNodeParameter('productId', i);
1353
+ await makeRequest('DELETE', `/products/${productId}`);
1354
+ returnData.push({ success: true, id: productId });
1355
+ }
1356
+ }
1357
+ else if (resource === 'order') {
1358
+ if (operation === 'get') {
1359
+ const orderId = this.getNodeParameter('orderId', i);
1360
+ const response = await makeRequest('GET', `/orders/${orderId}`);
1361
+ returnData.push(response);
1362
+ }
1363
+ else if (operation === 'getAll') {
1364
+ const returnAll = this.getNodeParameter('returnAll', i);
1365
+ const filters = this.getNodeParameter('filters', i, {});
1366
+ const qs = { per_page: 200 };
1367
+ if (filters.status)
1368
+ qs.status = filters.status;
1369
+ if (filters.payment_status)
1370
+ qs.payment_status = filters.payment_status;
1371
+ if (filters.shipping_status)
1372
+ qs.shipping_status = filters.shipping_status;
1373
+ if (filters.created_at_min)
1374
+ qs.created_at_min = filters.created_at_min;
1375
+ if (filters.created_at_max)
1376
+ qs.created_at_max = filters.created_at_max;
1377
+ if (returnAll) {
1378
+ const orders = await getAllPaginated('/orders', qs);
1379
+ returnData.push(...orders);
728
1380
  }
729
- if (updateFields.promotional_price !== undefined) {
730
- body.promotional_price = updateFields.promotional_price;
731
- }
732
- if (updateFields.cost_price !== undefined) {
733
- body.cost_price = updateFields.cost_price;
734
- }
735
- if (updateFields.sku) {
736
- body.sku = updateFields.sku;
1381
+ else {
1382
+ const limit = this.getNodeParameter('limit', i);
1383
+ qs.per_page = limit;
1384
+ const response = await makeRequest('GET', '/orders', undefined, qs);
1385
+ const orders = Array.isArray(response) ? response : [response];
1386
+ returnData.push(...orders);
737
1387
  }
738
- if (updateFields.stock !== undefined) {
739
- body.stock = updateFields.stock;
1388
+ }
1389
+ else if (operation === 'update') {
1390
+ const orderId = this.getNodeParameter('orderId', i);
1391
+ const updateFields = this.getNodeParameter('updateFields', i);
1392
+ const body = {};
1393
+ if (updateFields.status)
1394
+ body.status = updateFields.status;
1395
+ if (updateFields.payment_status)
1396
+ body.payment_status = updateFields.payment_status;
1397
+ if (updateFields.shipping_status)
1398
+ body.shipping_status = updateFields.shipping_status;
1399
+ if (updateFields.note)
1400
+ body.note = updateFields.note;
1401
+ const response = await makeRequest('PUT', `/orders/${orderId}`, body);
1402
+ returnData.push(response);
1403
+ }
1404
+ else if (operation === 'cancel') {
1405
+ const orderId = this.getNodeParameter('orderId', i);
1406
+ const response = await makeRequest('POST', `/orders/${orderId}/cancel`);
1407
+ returnData.push(response);
1408
+ }
1409
+ }
1410
+ else if (resource === 'customer') {
1411
+ if (operation === 'get') {
1412
+ const customerId = this.getNodeParameter('customerId', i);
1413
+ const response = await makeRequest('GET', `/customers/${customerId}`);
1414
+ returnData.push(response);
1415
+ }
1416
+ else if (operation === 'getAll') {
1417
+ const returnAll = this.getNodeParameter('returnAll', i);
1418
+ const filters = this.getNodeParameter('filters', i, {});
1419
+ const qs = { per_page: 200 };
1420
+ if (filters.email)
1421
+ qs.email = filters.email;
1422
+ if (filters.name)
1423
+ qs.name = filters.name;
1424
+ if (returnAll) {
1425
+ const customers = await getAllPaginated('/customers', qs);
1426
+ returnData.push(...customers);
740
1427
  }
741
- if (updateFields.published !== undefined) {
742
- body.published = updateFields.published;
1428
+ else {
1429
+ const limit = this.getNodeParameter('limit', i);
1430
+ qs.per_page = limit;
1431
+ const response = await makeRequest('GET', '/customers', undefined, qs);
1432
+ const customers = Array.isArray(response) ? response : [response];
1433
+ returnData.push(...customers);
743
1434
  }
744
- if (updateFields.free_shipping !== undefined) {
745
- body.free_shipping = updateFields.free_shipping;
1435
+ }
1436
+ else if (operation === 'create') {
1437
+ const email = this.getNodeParameter('email', i);
1438
+ const additionalFields = this.getNodeParameter('additionalFields', i);
1439
+ const body = { email };
1440
+ if (additionalFields.name)
1441
+ body.name = additionalFields.name;
1442
+ if (additionalFields.phone)
1443
+ body.phone = additionalFields.phone;
1444
+ if (additionalFields.identification)
1445
+ body.identification = additionalFields.identification;
1446
+ if (additionalFields.note)
1447
+ body.note = additionalFields.note;
1448
+ const response = await makeRequest('POST', '/customers', body);
1449
+ returnData.push(response);
1450
+ }
1451
+ else if (operation === 'update') {
1452
+ const customerId = this.getNodeParameter('customerId', i);
1453
+ const updateFields = this.getNodeParameter('updateFields', i);
1454
+ const body = {};
1455
+ if (updateFields.email)
1456
+ body.email = updateFields.email;
1457
+ if (updateFields.name)
1458
+ body.name = updateFields.name;
1459
+ if (updateFields.phone)
1460
+ body.phone = updateFields.phone;
1461
+ if (updateFields.note)
1462
+ body.note = updateFields.note;
1463
+ const response = await makeRequest('PUT', `/customers/${customerId}`, body);
1464
+ returnData.push(response);
1465
+ }
1466
+ else if (operation === 'delete') {
1467
+ const customerId = this.getNodeParameter('customerId', i);
1468
+ await makeRequest('DELETE', `/customers/${customerId}`);
1469
+ returnData.push({ success: true, id: customerId });
1470
+ }
1471
+ }
1472
+ else if (resource === 'category') {
1473
+ if (operation === 'get') {
1474
+ const categoryId = this.getNodeParameter('categoryId', i);
1475
+ const response = await makeRequest('GET', `/categories/${categoryId}`);
1476
+ returnData.push(response);
1477
+ }
1478
+ else if (operation === 'getAll') {
1479
+ const returnAll = this.getNodeParameter('returnAll', i);
1480
+ const qs = { per_page: 200 };
1481
+ if (returnAll) {
1482
+ const categories = await getAllPaginated('/categories', qs);
1483
+ returnData.push(...categories);
746
1484
  }
747
- if (updateFields.weight !== undefined) {
748
- body.weight = updateFields.weight;
1485
+ else {
1486
+ const limit = this.getNodeParameter('limit', i);
1487
+ qs.per_page = limit;
1488
+ const response = await makeRequest('GET', '/categories', undefined, qs);
1489
+ const categories = Array.isArray(response) ? response : [response];
1490
+ returnData.push(...categories);
749
1491
  }
750
- if (updateFields.width !== undefined) {
751
- body.width = updateFields.width;
1492
+ }
1493
+ else if (operation === 'create') {
1494
+ const name = this.getNodeParameter('name', i);
1495
+ const additionalFields = this.getNodeParameter('additionalFields', i);
1496
+ const body = {
1497
+ name: parseMultilingualField(name),
1498
+ };
1499
+ if (additionalFields.description) {
1500
+ body.description = parseMultilingualField(additionalFields.description);
752
1501
  }
753
- if (updateFields.height !== undefined) {
754
- body.height = updateFields.height;
1502
+ if (additionalFields.parent)
1503
+ body.parent = additionalFields.parent;
1504
+ const response = await makeRequest('POST', '/categories', body);
1505
+ returnData.push(response);
1506
+ }
1507
+ else if (operation === 'update') {
1508
+ const categoryId = this.getNodeParameter('categoryId', i);
1509
+ const updateFields = this.getNodeParameter('updateFields', i);
1510
+ const body = {};
1511
+ if (updateFields.name) {
1512
+ body.name = parseMultilingualField(updateFields.name);
755
1513
  }
756
- if (updateFields.depth !== undefined) {
757
- body.depth = updateFields.depth;
1514
+ if (updateFields.description) {
1515
+ body.description = parseMultilingualField(updateFields.description);
758
1516
  }
759
- if (updateFields.brand) {
760
- body.brand = updateFields.brand;
1517
+ const response = await makeRequest('PUT', `/categories/${categoryId}`, body);
1518
+ returnData.push(response);
1519
+ }
1520
+ else if (operation === 'delete') {
1521
+ const categoryId = this.getNodeParameter('categoryId', i);
1522
+ await makeRequest('DELETE', `/categories/${categoryId}`);
1523
+ returnData.push({ success: true, id: categoryId });
1524
+ }
1525
+ }
1526
+ else if (resource === 'coupon') {
1527
+ if (operation === 'get') {
1528
+ const couponId = this.getNodeParameter('couponId', i);
1529
+ const response = await makeRequest('GET', `/coupons/${couponId}`);
1530
+ returnData.push(response);
1531
+ }
1532
+ else if (operation === 'getAll') {
1533
+ const returnAll = this.getNodeParameter('returnAll', i);
1534
+ const qs = { per_page: 200 };
1535
+ if (returnAll) {
1536
+ const coupons = await getAllPaginated('/coupons', qs);
1537
+ returnData.push(...coupons);
761
1538
  }
762
- if (updateFields.categories) {
763
- body.categories = parseJsonField(updateFields.categories);
1539
+ else {
1540
+ const limit = this.getNodeParameter('limit', i);
1541
+ qs.per_page = limit;
1542
+ const response = await makeRequest('GET', '/coupons', undefined, qs);
1543
+ const coupons = Array.isArray(response) ? response : [response];
1544
+ returnData.push(...coupons);
764
1545
  }
765
- if (updateFields.images) {
766
- body.images = parseJsonField(updateFields.images);
1546
+ }
1547
+ else if (operation === 'create') {
1548
+ const code = this.getNodeParameter('code', i);
1549
+ const type = this.getNodeParameter('type', i);
1550
+ const value = this.getNodeParameter('value', i);
1551
+ const additionalFields = this.getNodeParameter('additionalFields', i);
1552
+ const body = { code, type, value };
1553
+ if (additionalFields.valid_from)
1554
+ body.valid_from = additionalFields.valid_from;
1555
+ if (additionalFields.valid_until)
1556
+ body.valid_until = additionalFields.valid_until;
1557
+ if (additionalFields.max_uses)
1558
+ body.max_uses = additionalFields.max_uses;
1559
+ const response = await makeRequest('POST', '/coupons', body);
1560
+ returnData.push(response);
1561
+ }
1562
+ else if (operation === 'update') {
1563
+ const couponId = this.getNodeParameter('couponId', i);
1564
+ const updateFields = this.getNodeParameter('updateFields', i);
1565
+ const body = {};
1566
+ if (updateFields.value !== undefined)
1567
+ body.value = updateFields.value;
1568
+ if (updateFields.valid_until)
1569
+ body.valid_until = updateFields.valid_until;
1570
+ const response = await makeRequest('PUT', `/coupons/${couponId}`, body);
1571
+ returnData.push(response);
1572
+ }
1573
+ else if (operation === 'delete') {
1574
+ const couponId = this.getNodeParameter('couponId', i);
1575
+ await makeRequest('DELETE', `/coupons/${couponId}`);
1576
+ returnData.push({ success: true, id: couponId });
1577
+ }
1578
+ }
1579
+ else if (resource === 'webhook') {
1580
+ if (operation === 'get') {
1581
+ const webhookId = this.getNodeParameter('webhookId', i);
1582
+ const response = await makeRequest('GET', `/webhooks/${webhookId}`);
1583
+ returnData.push(response);
1584
+ }
1585
+ else if (operation === 'getAll') {
1586
+ const returnAll = this.getNodeParameter('returnAll', i);
1587
+ const qs = { per_page: 200 };
1588
+ if (returnAll) {
1589
+ const webhooks = await getAllPaginated('/webhooks', qs);
1590
+ returnData.push(...webhooks);
767
1591
  }
768
- if (updateFields.variants) {
769
- body.variants = parseJsonField(updateFields.variants);
1592
+ else {
1593
+ const limit = this.getNodeParameter('limit', i);
1594
+ qs.per_page = limit;
1595
+ const response = await makeRequest('GET', '/webhooks', undefined, qs);
1596
+ const webhooks = Array.isArray(response) ? response : [response];
1597
+ returnData.push(...webhooks);
770
1598
  }
771
- const response = await makeRequest('PUT', `/products/${productId}`, body);
1599
+ }
1600
+ else if (operation === 'create') {
1601
+ const event = this.getNodeParameter('event', i);
1602
+ const url = this.getNodeParameter('url', i);
1603
+ const body = { event, url };
1604
+ const response = await makeRequest('POST', '/webhooks', body);
772
1605
  returnData.push(response);
773
1606
  }
774
1607
  else if (operation === 'delete') {
775
- const productId = this.getNodeParameter('productId', i);
776
- await makeRequest('DELETE', `/products/${productId}`);
777
- returnData.push({ success: true, id: productId });
1608
+ const webhookId = this.getNodeParameter('webhookId', i);
1609
+ await makeRequest('DELETE', `/webhooks/${webhookId}`);
1610
+ returnData.push({ success: true, id: webhookId });
778
1611
  }
779
1612
  }
780
1613
  }