n8n-workflow 0.83.0 → 0.87.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.
@@ -0,0 +1,1557 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const src_1 = require("../src");
23
+ const Helpers = __importStar(require("./Helpers"));
24
+ const postReceiveFunction1 = async function (items, response) {
25
+ items.forEach((item) => (item.json1 = { success: true }));
26
+ return items;
27
+ };
28
+ const preSendFunction1 = async function (requestOptions) {
29
+ requestOptions.headers = (requestOptions.headers || {});
30
+ requestOptions.headers.addedIn = 'preSendFunction1';
31
+ return requestOptions;
32
+ };
33
+ describe('RoutingNode', () => {
34
+ describe('getRequestOptionsFromParameters', () => {
35
+ const tests = [
36
+ {
37
+ description: 'single parameter, only send defined, fixed value',
38
+ input: {
39
+ nodeParameters: {},
40
+ nodeTypeProperties: {
41
+ displayName: 'Email',
42
+ name: 'email',
43
+ type: 'string',
44
+ routing: {
45
+ send: {
46
+ property: 'toEmail',
47
+ type: 'body',
48
+ value: 'fixedValue',
49
+ },
50
+ },
51
+ default: '',
52
+ },
53
+ },
54
+ output: {
55
+ options: {
56
+ qs: {},
57
+ body: {
58
+ toEmail: 'fixedValue',
59
+ },
60
+ },
61
+ preSend: [],
62
+ postReceive: [],
63
+ requestOperations: {},
64
+ },
65
+ },
66
+ {
67
+ description: 'single parameter, only send defined, using expression',
68
+ input: {
69
+ nodeParameters: {
70
+ email: 'test@test.com',
71
+ },
72
+ nodeTypeProperties: {
73
+ displayName: 'Email',
74
+ name: 'email',
75
+ type: 'string',
76
+ routing: {
77
+ send: {
78
+ property: 'toEmail',
79
+ type: 'body',
80
+ value: '={{$value.toUpperCase()}}',
81
+ },
82
+ },
83
+ default: '',
84
+ },
85
+ },
86
+ output: {
87
+ options: {
88
+ qs: {},
89
+ body: {
90
+ toEmail: 'TEST@TEST.COM',
91
+ },
92
+ },
93
+ preSend: [],
94
+ postReceive: [],
95
+ requestOperations: {},
96
+ },
97
+ },
98
+ {
99
+ description: 'single parameter, send and operations defined, fixed value',
100
+ input: {
101
+ nodeParameters: {},
102
+ nodeTypeProperties: {
103
+ displayName: 'Email',
104
+ name: 'email',
105
+ type: 'string',
106
+ routing: {
107
+ send: {
108
+ property: 'toEmail',
109
+ type: 'body',
110
+ value: 'fixedValue',
111
+ },
112
+ operations: {
113
+ pagination: {
114
+ type: 'offset',
115
+ properties: {
116
+ limitParameter: 'limit',
117
+ offsetParameter: 'offset',
118
+ pageSize: 10,
119
+ rootProperty: 'data',
120
+ type: 'body',
121
+ },
122
+ },
123
+ },
124
+ },
125
+ default: '',
126
+ },
127
+ },
128
+ output: {
129
+ options: {
130
+ qs: {},
131
+ body: {
132
+ toEmail: 'fixedValue',
133
+ },
134
+ },
135
+ preSend: [],
136
+ postReceive: [],
137
+ requestOperations: {
138
+ pagination: {
139
+ type: 'offset',
140
+ properties: {
141
+ limitParameter: 'limit',
142
+ offsetParameter: 'offset',
143
+ pageSize: 10,
144
+ rootProperty: 'data',
145
+ type: 'body',
146
+ },
147
+ },
148
+ },
149
+ },
150
+ },
151
+ {
152
+ description: 'mutliple parameters, complex example with everything',
153
+ input: {
154
+ nodeParameters: {
155
+ multipleFields: {
156
+ value1: 'v1',
157
+ value2: 'v2',
158
+ value3: 'v3',
159
+ value4: 4,
160
+ lowerLevel: {
161
+ lowLevelValue1: 1,
162
+ lowLevelValue2: 'llv2',
163
+ },
164
+ customPropertiesSingle1: {
165
+ property: {
166
+ name: 'cSName1',
167
+ value: 'cSValue1',
168
+ },
169
+ },
170
+ customPropertiesMulti: {
171
+ property0: [
172
+ {
173
+ name: 'cM0Name1',
174
+ value: 'cM0Value1',
175
+ },
176
+ {
177
+ name: 'cM0Name2',
178
+ value: 'cM0Value2',
179
+ },
180
+ ],
181
+ property1: [
182
+ {
183
+ name: 'cM1Name2',
184
+ value: 'cM1Value2',
185
+ },
186
+ {
187
+ name: 'cM1Name2',
188
+ value: 'cM1Value2',
189
+ },
190
+ ],
191
+ },
192
+ },
193
+ },
194
+ nodeTypeProperties: {
195
+ displayName: 'Multiple Fields',
196
+ name: 'multipleFields',
197
+ type: 'collection',
198
+ placeholder: 'Add Field',
199
+ routing: {
200
+ request: {
201
+ method: 'GET',
202
+ url: '/destination1',
203
+ },
204
+ operations: {
205
+ pagination: {
206
+ type: 'offset',
207
+ properties: {
208
+ limitParameter: 'limit1',
209
+ offsetParameter: 'offset1',
210
+ pageSize: 1,
211
+ rootProperty: 'data1',
212
+ type: 'body',
213
+ },
214
+ },
215
+ },
216
+ output: {
217
+ maxResults: 10,
218
+ postReceive: [postReceiveFunction1],
219
+ },
220
+ },
221
+ default: {},
222
+ options: [
223
+ {
224
+ displayName: 'Value 1',
225
+ name: 'value1',
226
+ type: 'string',
227
+ routing: {
228
+ send: {
229
+ property: 'value1',
230
+ type: 'body',
231
+ },
232
+ },
233
+ default: '',
234
+ },
235
+ {
236
+ displayName: 'Value 2',
237
+ name: 'value2',
238
+ type: 'string',
239
+ routing: {
240
+ send: {
241
+ property: 'topLevel.value2',
242
+ propertyInDotNotation: false,
243
+ type: 'body',
244
+ preSend: [preSendFunction1],
245
+ },
246
+ },
247
+ default: '',
248
+ },
249
+ {
250
+ displayName: 'Value 3',
251
+ name: 'value3',
252
+ type: 'string',
253
+ routing: {
254
+ send: {
255
+ property: 'lowerLevel.value3',
256
+ type: 'body',
257
+ },
258
+ },
259
+ default: '',
260
+ },
261
+ {
262
+ displayName: 'Value 4',
263
+ name: 'value4',
264
+ type: 'number',
265
+ default: 0,
266
+ routing: {
267
+ send: {
268
+ property: 'value4',
269
+ type: 'query',
270
+ },
271
+ output: {
272
+ maxResults: '={{$value}}',
273
+ },
274
+ operations: {
275
+ pagination: {
276
+ type: 'offset',
277
+ properties: {
278
+ limitParameter: 'limit100',
279
+ offsetParameter: 'offset100',
280
+ pageSize: 100,
281
+ rootProperty: 'data100',
282
+ type: 'query',
283
+ },
284
+ },
285
+ },
286
+ },
287
+ },
288
+ {
289
+ displayName: 'Value 5',
290
+ name: 'value5',
291
+ type: 'number',
292
+ displayOptions: {
293
+ show: {
294
+ value4: [1],
295
+ },
296
+ },
297
+ default: 5,
298
+ routing: {
299
+ send: {
300
+ property: 'value5',
301
+ type: 'query',
302
+ },
303
+ operations: {
304
+ pagination: {
305
+ type: 'offset',
306
+ properties: {
307
+ limitParameter: 'limit10',
308
+ offsetParameter: 'offset10',
309
+ pageSize: 10,
310
+ rootProperty: 'data10',
311
+ type: 'body',
312
+ },
313
+ },
314
+ },
315
+ },
316
+ },
317
+ {
318
+ displayName: 'Lower Level',
319
+ name: 'lowerLevel',
320
+ type: 'collection',
321
+ placeholder: 'Add Field',
322
+ default: {},
323
+ options: [
324
+ {
325
+ displayName: 'Low Level Value1',
326
+ name: 'lowLevelValue1',
327
+ type: 'number',
328
+ default: 0,
329
+ routing: {
330
+ send: {
331
+ property: 'llvalue1',
332
+ type: 'query',
333
+ },
334
+ },
335
+ },
336
+ {
337
+ displayName: 'Low Level Value2',
338
+ name: 'lowLevelValue2',
339
+ type: 'string',
340
+ default: '',
341
+ routing: {
342
+ send: {
343
+ property: 'llvalue2',
344
+ type: 'query',
345
+ preSend: [preSendFunction1],
346
+ },
347
+ output: {
348
+ postReceive: [
349
+ {
350
+ type: 'rootProperty',
351
+ properties: {
352
+ property: 'data',
353
+ },
354
+ },
355
+ ],
356
+ },
357
+ },
358
+ },
359
+ ],
360
+ },
361
+ {
362
+ displayName: 'Custom Properties1 (single)',
363
+ name: 'customPropertiesSingle1',
364
+ placeholder: 'Add Custom Property',
365
+ type: 'fixedCollection',
366
+ default: {},
367
+ options: [
368
+ {
369
+ name: 'property',
370
+ displayName: 'Property',
371
+ values: [
372
+ {
373
+ displayName: 'Property Name',
374
+ name: 'name',
375
+ type: 'string',
376
+ default: '',
377
+ routing: {
378
+ request: {
379
+ method: 'POST',
380
+ url: '=/{{$value}}',
381
+ },
382
+ send: {
383
+ property: 'single-customValues.name',
384
+ },
385
+ },
386
+ },
387
+ {
388
+ displayName: 'Property Value',
389
+ name: 'value',
390
+ type: 'string',
391
+ default: '',
392
+ routing: {
393
+ send: {
394
+ property: 'single-customValues.value',
395
+ },
396
+ },
397
+ },
398
+ ],
399
+ },
400
+ ],
401
+ },
402
+ {
403
+ displayName: 'Custom Properties (multi)',
404
+ name: 'customPropertiesMulti',
405
+ placeholder: 'Add Custom Property',
406
+ type: 'fixedCollection',
407
+ typeOptions: {
408
+ multipleValues: true,
409
+ },
410
+ default: {},
411
+ options: [
412
+ {
413
+ name: 'property0',
414
+ displayName: 'Property0',
415
+ values: [
416
+ {
417
+ displayName: 'Property Name',
418
+ name: 'name',
419
+ type: 'string',
420
+ default: '',
421
+ description: 'Name of the property to set.',
422
+ },
423
+ {
424
+ displayName: 'Property Value',
425
+ name: 'value',
426
+ type: 'string',
427
+ default: '',
428
+ routing: {
429
+ send: {
430
+ property: '=customMulti0.{{$parent.name}}',
431
+ type: 'body',
432
+ },
433
+ },
434
+ description: 'Value of the property to set.',
435
+ },
436
+ ],
437
+ },
438
+ {
439
+ name: 'property1',
440
+ displayName: 'Property1',
441
+ values: [
442
+ {
443
+ displayName: 'Property Name',
444
+ name: 'name',
445
+ type: 'string',
446
+ default: '',
447
+ routing: {
448
+ send: {
449
+ property: '=customMulti1[{{$index}}].name',
450
+ type: 'body',
451
+ },
452
+ },
453
+ },
454
+ {
455
+ displayName: 'Property Value',
456
+ name: 'value',
457
+ type: 'string',
458
+ default: '',
459
+ routing: {
460
+ send: {
461
+ property: '=customMulti1[{{$index}}].value',
462
+ type: 'body',
463
+ },
464
+ },
465
+ },
466
+ ],
467
+ },
468
+ ],
469
+ },
470
+ ],
471
+ },
472
+ },
473
+ output: {
474
+ maxResults: 4,
475
+ options: {
476
+ method: 'POST',
477
+ url: '/cSName1',
478
+ qs: {
479
+ value4: 4,
480
+ llvalue1: 1,
481
+ llvalue2: 'llv2',
482
+ 'single-customValues': {
483
+ name: 'cSName1',
484
+ value: 'cSValue1',
485
+ },
486
+ },
487
+ body: {
488
+ value1: 'v1',
489
+ 'topLevel.value2': 'v2',
490
+ lowerLevel: {
491
+ value3: 'v3',
492
+ },
493
+ customMulti0: {
494
+ cM0Name1: 'cM0Value1',
495
+ cM0Name2: 'cM0Value2',
496
+ },
497
+ customMulti1: [
498
+ {
499
+ name: 'cM1Name2',
500
+ value: 'cM1Value2',
501
+ },
502
+ {
503
+ name: 'cM1Name2',
504
+ value: 'cM1Value2',
505
+ },
506
+ ],
507
+ },
508
+ },
509
+ preSend: [preSendFunction1, preSendFunction1],
510
+ postReceive: [
511
+ {
512
+ actions: [postReceiveFunction1],
513
+ data: {
514
+ parameterValue: {
515
+ value1: 'v1',
516
+ value2: 'v2',
517
+ value3: 'v3',
518
+ value4: 4,
519
+ lowerLevel: {
520
+ lowLevelValue1: 1,
521
+ lowLevelValue2: 'llv2',
522
+ },
523
+ customPropertiesSingle1: {
524
+ property: {
525
+ name: 'cSName1',
526
+ value: 'cSValue1',
527
+ },
528
+ },
529
+ customPropertiesMulti: {
530
+ property0: [
531
+ {
532
+ name: 'cM0Name1',
533
+ value: 'cM0Value1',
534
+ },
535
+ {
536
+ name: 'cM0Name2',
537
+ value: 'cM0Value2',
538
+ },
539
+ ],
540
+ property1: [
541
+ {
542
+ name: 'cM1Name2',
543
+ value: 'cM1Value2',
544
+ },
545
+ {
546
+ name: 'cM1Name2',
547
+ value: 'cM1Value2',
548
+ },
549
+ ],
550
+ },
551
+ },
552
+ },
553
+ },
554
+ {
555
+ actions: [
556
+ {
557
+ type: 'rootProperty',
558
+ properties: {
559
+ property: 'data',
560
+ },
561
+ },
562
+ ],
563
+ data: {
564
+ parameterValue: 'llv2',
565
+ },
566
+ },
567
+ ],
568
+ requestOperations: {
569
+ pagination: {
570
+ type: 'offset',
571
+ properties: {
572
+ limitParameter: 'limit100',
573
+ offsetParameter: 'offset100',
574
+ pageSize: 100,
575
+ rootProperty: 'data100',
576
+ type: 'query',
577
+ },
578
+ },
579
+ },
580
+ },
581
+ },
582
+ ];
583
+ const nodeTypes = Helpers.NodeTypes();
584
+ const node = {
585
+ parameters: {},
586
+ name: 'test',
587
+ type: 'test.set',
588
+ typeVersion: 1,
589
+ position: [0, 0],
590
+ };
591
+ const mode = 'internal';
592
+ const runIndex = 0;
593
+ const itemIndex = 0;
594
+ const connectionInputData = [];
595
+ const runExecutionData = { resultData: { runData: {} } };
596
+ const additionalData = Helpers.WorkflowExecuteAdditionalData();
597
+ const path = '';
598
+ const nodeType = nodeTypes.getByName(node.type);
599
+ const workflowData = {
600
+ nodes: [node],
601
+ connections: {},
602
+ };
603
+ for (const testData of tests) {
604
+ test(testData.description, () => {
605
+ node.parameters = testData.input.nodeParameters;
606
+ nodeType.description.properties = [testData.input.nodeTypeProperties];
607
+ const workflow = new src_1.Workflow({
608
+ nodes: workflowData.nodes,
609
+ connections: workflowData.connections,
610
+ active: false,
611
+ nodeTypes,
612
+ });
613
+ const routingNode = new src_1.RoutingNode(workflow, node, connectionInputData, runExecutionData !== null && runExecutionData !== void 0 ? runExecutionData : null, additionalData, mode);
614
+ const executeSingleFunctions = Helpers.getExecuteSingleFunctions(workflow, runExecutionData, runIndex, connectionInputData, {}, node, itemIndex, additionalData, mode);
615
+ const result = routingNode.getRequestOptionsFromParameters(executeSingleFunctions, testData.input.nodeTypeProperties, itemIndex, runIndex, path, {});
616
+ expect(result).toEqual(testData.output);
617
+ });
618
+ }
619
+ });
620
+ describe('runNode', () => {
621
+ const tests = [
622
+ {
623
+ description: 'single parameter, only send defined, fixed value, using requestDefaults',
624
+ input: {
625
+ nodeType: {
626
+ requestDefaults: {
627
+ baseURL: 'http://127.0.0.1:5678',
628
+ url: '/test-url',
629
+ },
630
+ properties: [
631
+ {
632
+ displayName: 'Email',
633
+ name: 'email',
634
+ type: 'string',
635
+ routing: {
636
+ send: {
637
+ property: 'toEmail',
638
+ type: 'body',
639
+ value: 'fixedValue',
640
+ },
641
+ },
642
+ default: '',
643
+ },
644
+ ],
645
+ },
646
+ node: {
647
+ parameters: {},
648
+ },
649
+ },
650
+ output: [
651
+ [
652
+ {
653
+ json: {
654
+ headers: {},
655
+ statusCode: 200,
656
+ requestOptions: {
657
+ url: '/test-url',
658
+ qs: {},
659
+ body: {
660
+ toEmail: 'fixedValue',
661
+ },
662
+ baseURL: 'http://127.0.0.1:5678',
663
+ returnFullResponse: true,
664
+ },
665
+ },
666
+ },
667
+ ],
668
+ ],
669
+ },
670
+ {
671
+ description: 'single parameter, only send defined, fixed value, using requestDefaults',
672
+ input: {
673
+ nodeType: {
674
+ requestDefaults: {
675
+ baseURL: 'http://127.0.0.1:5678',
676
+ url: '/test-url',
677
+ },
678
+ properties: [
679
+ {
680
+ displayName: 'Email',
681
+ name: 'email',
682
+ type: 'string',
683
+ routing: {
684
+ send: {
685
+ property: 'toEmail',
686
+ type: 'body',
687
+ value: 'fixedValue',
688
+ },
689
+ },
690
+ default: '',
691
+ },
692
+ ],
693
+ },
694
+ node: {
695
+ parameters: {},
696
+ },
697
+ },
698
+ output: [
699
+ [
700
+ {
701
+ json: {
702
+ headers: {},
703
+ statusCode: 200,
704
+ requestOptions: {
705
+ url: '/test-url',
706
+ qs: {},
707
+ body: {
708
+ toEmail: 'fixedValue',
709
+ },
710
+ baseURL: 'http://127.0.0.1:5678',
711
+ returnFullResponse: true,
712
+ },
713
+ },
714
+ },
715
+ ],
716
+ ],
717
+ },
718
+ {
719
+ description: 'single parameter, only send defined, using expression, using requestDefaults with overwrite',
720
+ input: {
721
+ node: {
722
+ parameters: {
723
+ email: 'test@test.com',
724
+ },
725
+ },
726
+ nodeType: {
727
+ requestDefaults: {
728
+ baseURL: 'http://127.0.0.1:5678',
729
+ url: '/test-url',
730
+ },
731
+ properties: [
732
+ {
733
+ displayName: 'Email',
734
+ name: 'email',
735
+ type: 'string',
736
+ routing: {
737
+ send: {
738
+ property: 'toEmail',
739
+ type: 'body',
740
+ value: '={{$value.toUpperCase()}}',
741
+ },
742
+ request: {
743
+ url: '/overwritten',
744
+ },
745
+ },
746
+ default: '',
747
+ },
748
+ ],
749
+ },
750
+ },
751
+ output: [
752
+ [
753
+ {
754
+ json: {
755
+ headers: {},
756
+ statusCode: 200,
757
+ requestOptions: {
758
+ url: '/overwritten',
759
+ qs: {},
760
+ body: {
761
+ toEmail: 'TEST@TEST.COM',
762
+ },
763
+ baseURL: 'http://127.0.0.1:5678',
764
+ returnFullResponse: true,
765
+ },
766
+ },
767
+ },
768
+ ],
769
+ ],
770
+ },
771
+ {
772
+ description: 'single parameter, only send defined, using expression, using requestDefaults with overwrite and expressions',
773
+ input: {
774
+ node: {
775
+ parameters: {
776
+ endpoint: 'custom-overwritten',
777
+ },
778
+ },
779
+ nodeType: {
780
+ requestDefaults: {
781
+ baseURL: 'http://127.0.0.1:5678',
782
+ url: '/test-url',
783
+ },
784
+ properties: [
785
+ {
786
+ displayName: 'Endpoint',
787
+ name: 'endpoint',
788
+ type: 'string',
789
+ routing: {
790
+ send: {
791
+ property: '={{"theProperty"}}',
792
+ type: 'body',
793
+ value: '={{$value}}',
794
+ },
795
+ request: {
796
+ url: '=/{{$value}}',
797
+ },
798
+ },
799
+ default: '',
800
+ },
801
+ ],
802
+ },
803
+ },
804
+ output: [
805
+ [
806
+ {
807
+ json: {
808
+ headers: {},
809
+ statusCode: 200,
810
+ requestOptions: {
811
+ url: '/custom-overwritten',
812
+ qs: {},
813
+ body: {
814
+ theProperty: 'custom-overwritten',
815
+ },
816
+ baseURL: 'http://127.0.0.1:5678',
817
+ returnFullResponse: true,
818
+ },
819
+ },
820
+ },
821
+ ],
822
+ ],
823
+ },
824
+ {
825
+ description: 'single parameter, send and operations defined, fixed value with pagination',
826
+ input: {
827
+ node: {
828
+ parameters: {},
829
+ },
830
+ nodeType: {
831
+ properties: [
832
+ {
833
+ displayName: 'Email',
834
+ name: 'email',
835
+ type: 'string',
836
+ routing: {
837
+ send: {
838
+ property: 'toEmail',
839
+ type: 'body',
840
+ value: 'fixedValue',
841
+ paginate: true,
842
+ },
843
+ operations: {
844
+ pagination: {
845
+ type: 'offset',
846
+ properties: {
847
+ limitParameter: 'limit',
848
+ offsetParameter: 'offset',
849
+ pageSize: 10,
850
+ type: 'body',
851
+ },
852
+ },
853
+ },
854
+ },
855
+ default: '',
856
+ },
857
+ ],
858
+ },
859
+ },
860
+ output: [
861
+ [
862
+ {
863
+ json: {
864
+ headers: {},
865
+ statusCode: 200,
866
+ requestOptions: {
867
+ qs: {},
868
+ body: {
869
+ toEmail: 'fixedValue',
870
+ limit: 10,
871
+ offset: 10,
872
+ },
873
+ returnFullResponse: true,
874
+ },
875
+ },
876
+ },
877
+ ],
878
+ ],
879
+ },
880
+ {
881
+ description: 'mutliple parameters, complex example with everything',
882
+ input: {
883
+ node: {
884
+ parameters: {
885
+ multipleFields: {
886
+ value1: 'v1',
887
+ value2: 'v2',
888
+ value3: 'v3',
889
+ value4: 4,
890
+ lowerLevel: {
891
+ lowLevelValue1: 1,
892
+ lowLevelValue2: 'llv2',
893
+ },
894
+ customPropertiesSingle1: {
895
+ property: {
896
+ name: 'cSName1',
897
+ value: 'cSValue1',
898
+ },
899
+ },
900
+ customPropertiesMulti: {
901
+ property0: [
902
+ {
903
+ name: 'cM0Name1',
904
+ value: 'cM0Value1',
905
+ },
906
+ {
907
+ name: 'cM0Name2',
908
+ value: 'cM0Value2',
909
+ },
910
+ ],
911
+ property1: [
912
+ {
913
+ name: 'cM1Name2',
914
+ value: 'cM1Value2',
915
+ },
916
+ {
917
+ name: 'cM1Name2',
918
+ value: 'cM1Value2',
919
+ },
920
+ ],
921
+ },
922
+ },
923
+ },
924
+ },
925
+ nodeType: {
926
+ properties: [
927
+ {
928
+ displayName: 'Multiple Fields',
929
+ name: 'multipleFields',
930
+ type: 'collection',
931
+ placeholder: 'Add Field',
932
+ routing: {
933
+ request: {
934
+ method: 'GET',
935
+ url: '/destination1',
936
+ },
937
+ operations: {
938
+ pagination: {
939
+ type: 'offset',
940
+ properties: {
941
+ limitParameter: 'limit1',
942
+ offsetParameter: 'offset1',
943
+ pageSize: 1,
944
+ rootProperty: 'data1',
945
+ type: 'body',
946
+ },
947
+ },
948
+ },
949
+ output: {
950
+ maxResults: 10,
951
+ postReceive: [postReceiveFunction1],
952
+ },
953
+ },
954
+ default: {},
955
+ options: [
956
+ {
957
+ displayName: 'Value 1',
958
+ name: 'value1',
959
+ type: 'string',
960
+ routing: {
961
+ send: {
962
+ property: 'value1',
963
+ type: 'body',
964
+ },
965
+ },
966
+ default: '',
967
+ },
968
+ {
969
+ displayName: 'Value 2',
970
+ name: 'value2',
971
+ type: 'string',
972
+ routing: {
973
+ send: {
974
+ property: 'topLevel.value2',
975
+ propertyInDotNotation: false,
976
+ type: 'body',
977
+ preSend: [preSendFunction1],
978
+ },
979
+ },
980
+ default: '',
981
+ },
982
+ {
983
+ displayName: 'Value 3',
984
+ name: 'value3',
985
+ type: 'string',
986
+ routing: {
987
+ send: {
988
+ property: 'lowerLevel.value3',
989
+ type: 'body',
990
+ },
991
+ },
992
+ default: '',
993
+ },
994
+ {
995
+ displayName: 'Value 4',
996
+ name: 'value4',
997
+ type: 'number',
998
+ default: 0,
999
+ routing: {
1000
+ send: {
1001
+ property: 'value4',
1002
+ type: 'query',
1003
+ },
1004
+ output: {
1005
+ maxResults: '={{$value}}',
1006
+ },
1007
+ operations: {
1008
+ pagination: {
1009
+ type: 'offset',
1010
+ properties: {
1011
+ limitParameter: 'limit100',
1012
+ offsetParameter: 'offset100',
1013
+ pageSize: 100,
1014
+ rootProperty: 'data100',
1015
+ type: 'query',
1016
+ },
1017
+ },
1018
+ },
1019
+ },
1020
+ },
1021
+ {
1022
+ displayName: 'Value 5',
1023
+ name: 'value5',
1024
+ type: 'number',
1025
+ displayOptions: {
1026
+ show: {
1027
+ value4: [1],
1028
+ },
1029
+ },
1030
+ default: 5,
1031
+ routing: {
1032
+ send: {
1033
+ property: 'value5',
1034
+ type: 'query',
1035
+ },
1036
+ operations: {
1037
+ pagination: {
1038
+ type: 'offset',
1039
+ properties: {
1040
+ limitParameter: 'limit10',
1041
+ offsetParameter: 'offset10',
1042
+ pageSize: 10,
1043
+ rootProperty: 'data10',
1044
+ type: 'body',
1045
+ },
1046
+ },
1047
+ },
1048
+ },
1049
+ },
1050
+ {
1051
+ displayName: 'Lower Level',
1052
+ name: 'lowerLevel',
1053
+ type: 'collection',
1054
+ placeholder: 'Add Field',
1055
+ default: {},
1056
+ options: [
1057
+ {
1058
+ displayName: 'Low Level Value1',
1059
+ name: 'lowLevelValue1',
1060
+ type: 'number',
1061
+ default: 0,
1062
+ routing: {
1063
+ send: {
1064
+ property: 'llvalue1',
1065
+ type: 'query',
1066
+ },
1067
+ },
1068
+ },
1069
+ {
1070
+ displayName: 'Low Level Value2',
1071
+ name: 'lowLevelValue2',
1072
+ type: 'string',
1073
+ default: '',
1074
+ routing: {
1075
+ send: {
1076
+ property: 'llvalue2',
1077
+ type: 'query',
1078
+ preSend: [preSendFunction1],
1079
+ },
1080
+ output: {
1081
+ postReceive: [
1082
+ {
1083
+ type: 'rootProperty',
1084
+ properties: {
1085
+ property: 'requestOptions',
1086
+ },
1087
+ },
1088
+ ],
1089
+ },
1090
+ },
1091
+ },
1092
+ ],
1093
+ },
1094
+ {
1095
+ displayName: 'Custom Properties1 (single)',
1096
+ name: 'customPropertiesSingle1',
1097
+ placeholder: 'Add Custom Property',
1098
+ type: 'fixedCollection',
1099
+ default: {},
1100
+ options: [
1101
+ {
1102
+ name: 'property',
1103
+ displayName: 'Property',
1104
+ values: [
1105
+ {
1106
+ displayName: 'Property Name',
1107
+ name: 'name',
1108
+ type: 'string',
1109
+ default: '',
1110
+ routing: {
1111
+ request: {
1112
+ method: 'POST',
1113
+ url: '=/{{$value}}',
1114
+ },
1115
+ send: {
1116
+ property: 'single-customValues.name',
1117
+ },
1118
+ },
1119
+ },
1120
+ {
1121
+ displayName: 'Property Value',
1122
+ name: 'value',
1123
+ type: 'string',
1124
+ default: '',
1125
+ routing: {
1126
+ send: {
1127
+ property: 'single-customValues.value',
1128
+ },
1129
+ },
1130
+ },
1131
+ ],
1132
+ },
1133
+ ],
1134
+ },
1135
+ {
1136
+ displayName: 'Custom Properties (multi)',
1137
+ name: 'customPropertiesMulti',
1138
+ placeholder: 'Add Custom Property',
1139
+ type: 'fixedCollection',
1140
+ typeOptions: {
1141
+ multipleValues: true,
1142
+ },
1143
+ default: {},
1144
+ options: [
1145
+ {
1146
+ name: 'property0',
1147
+ displayName: 'Property0',
1148
+ values: [
1149
+ {
1150
+ displayName: 'Property Name',
1151
+ name: 'name',
1152
+ type: 'string',
1153
+ default: '',
1154
+ description: 'Name of the property to set.',
1155
+ },
1156
+ {
1157
+ displayName: 'Property Value',
1158
+ name: 'value',
1159
+ type: 'string',
1160
+ default: '',
1161
+ routing: {
1162
+ send: {
1163
+ property: '=customMulti0.{{$parent.name}}',
1164
+ type: 'body',
1165
+ },
1166
+ },
1167
+ description: 'Value of the property to set.',
1168
+ },
1169
+ ],
1170
+ },
1171
+ {
1172
+ name: 'property1',
1173
+ displayName: 'Property1',
1174
+ values: [
1175
+ {
1176
+ displayName: 'Property Name',
1177
+ name: 'name',
1178
+ type: 'string',
1179
+ default: '',
1180
+ routing: {
1181
+ send: {
1182
+ property: '=customMulti1[{{$index}}].name',
1183
+ type: 'body',
1184
+ },
1185
+ },
1186
+ },
1187
+ {
1188
+ displayName: 'Property Value',
1189
+ name: 'value',
1190
+ type: 'string',
1191
+ default: '',
1192
+ routing: {
1193
+ send: {
1194
+ property: '=customMulti1[{{$index}}].value',
1195
+ type: 'body',
1196
+ },
1197
+ },
1198
+ },
1199
+ ],
1200
+ },
1201
+ ],
1202
+ },
1203
+ ],
1204
+ },
1205
+ ],
1206
+ },
1207
+ },
1208
+ output: [
1209
+ [
1210
+ {
1211
+ json: {
1212
+ url: '/cSName1',
1213
+ qs: {
1214
+ value4: 4,
1215
+ llvalue1: 1,
1216
+ llvalue2: 'llv2',
1217
+ 'single-customValues': {
1218
+ name: 'cSName1',
1219
+ value: 'cSValue1',
1220
+ },
1221
+ },
1222
+ body: {
1223
+ value1: 'v1',
1224
+ 'topLevel.value2': 'v2',
1225
+ lowerLevel: {
1226
+ value3: 'v3',
1227
+ },
1228
+ customMulti0: {
1229
+ cM0Name1: 'cM0Value1',
1230
+ cM0Name2: 'cM0Value2',
1231
+ },
1232
+ customMulti1: [
1233
+ {
1234
+ name: 'cM1Name2',
1235
+ value: 'cM1Value2',
1236
+ },
1237
+ {
1238
+ name: 'cM1Name2',
1239
+ value: 'cM1Value2',
1240
+ },
1241
+ ],
1242
+ },
1243
+ method: 'POST',
1244
+ headers: {
1245
+ addedIn: 'preSendFunction1',
1246
+ },
1247
+ returnFullResponse: true,
1248
+ },
1249
+ },
1250
+ ],
1251
+ ],
1252
+ },
1253
+ {
1254
+ description: 'single parameter, postReceive: set',
1255
+ input: {
1256
+ nodeType: {
1257
+ requestDefaults: {
1258
+ baseURL: 'http://127.0.0.1:5678',
1259
+ url: '/test-url',
1260
+ },
1261
+ properties: [
1262
+ {
1263
+ displayName: 'JSON Data',
1264
+ name: 'jsonData',
1265
+ type: 'string',
1266
+ routing: {
1267
+ send: {
1268
+ property: 'jsonData',
1269
+ type: 'body',
1270
+ },
1271
+ output: {
1272
+ postReceive: [
1273
+ {
1274
+ type: 'set',
1275
+ properties: {
1276
+ value: '={{ { "value": $value, "response": $response } }}',
1277
+ },
1278
+ },
1279
+ ],
1280
+ },
1281
+ },
1282
+ default: '',
1283
+ },
1284
+ ],
1285
+ },
1286
+ node: {
1287
+ parameters: {
1288
+ jsonData: {
1289
+ root: [
1290
+ {
1291
+ name: 'Jim',
1292
+ age: 34,
1293
+ },
1294
+ {
1295
+ name: 'James',
1296
+ age: 44,
1297
+ },
1298
+ ],
1299
+ },
1300
+ },
1301
+ },
1302
+ },
1303
+ output: [
1304
+ [
1305
+ {
1306
+ json: {
1307
+ value: {
1308
+ root: [
1309
+ {
1310
+ name: 'Jim',
1311
+ age: 34,
1312
+ },
1313
+ {
1314
+ name: 'James',
1315
+ age: 44,
1316
+ },
1317
+ ],
1318
+ },
1319
+ response: {
1320
+ body: {
1321
+ headers: {},
1322
+ statusCode: 200,
1323
+ requestOptions: {
1324
+ qs: {},
1325
+ body: {
1326
+ jsonData: {
1327
+ root: [
1328
+ {
1329
+ name: 'Jim',
1330
+ age: 34,
1331
+ },
1332
+ {
1333
+ name: 'James',
1334
+ age: 44,
1335
+ },
1336
+ ],
1337
+ },
1338
+ },
1339
+ baseURL: 'http://127.0.0.1:5678',
1340
+ url: '/test-url',
1341
+ returnFullResponse: true,
1342
+ },
1343
+ },
1344
+ },
1345
+ },
1346
+ },
1347
+ ],
1348
+ ],
1349
+ },
1350
+ {
1351
+ description: 'single parameter, postReceive: rootProperty',
1352
+ input: {
1353
+ nodeType: {
1354
+ requestDefaults: {
1355
+ baseURL: 'http://127.0.0.1:5678',
1356
+ url: '/test-url',
1357
+ },
1358
+ properties: [
1359
+ {
1360
+ displayName: 'JSON Data',
1361
+ name: 'jsonData',
1362
+ type: 'string',
1363
+ routing: {
1364
+ send: {
1365
+ property: 'jsonData',
1366
+ type: 'body',
1367
+ },
1368
+ output: {
1369
+ postReceive: [
1370
+ {
1371
+ type: 'rootProperty',
1372
+ properties: {
1373
+ property: 'requestOptions',
1374
+ },
1375
+ },
1376
+ {
1377
+ type: 'rootProperty',
1378
+ properties: {
1379
+ property: 'body.jsonData.root',
1380
+ },
1381
+ },
1382
+ ],
1383
+ },
1384
+ },
1385
+ default: '',
1386
+ },
1387
+ ],
1388
+ },
1389
+ node: {
1390
+ parameters: {
1391
+ jsonData: {
1392
+ root: [
1393
+ {
1394
+ name: 'Jim',
1395
+ age: 34,
1396
+ },
1397
+ {
1398
+ name: 'James',
1399
+ age: 44,
1400
+ },
1401
+ ],
1402
+ },
1403
+ },
1404
+ },
1405
+ },
1406
+ output: [
1407
+ [
1408
+ {
1409
+ json: {
1410
+ name: 'Jim',
1411
+ age: 34,
1412
+ },
1413
+ },
1414
+ {
1415
+ json: {
1416
+ name: 'James',
1417
+ age: 44,
1418
+ },
1419
+ },
1420
+ ],
1421
+ ],
1422
+ },
1423
+ {
1424
+ description: 'single parameter, mutliple postReceive: rootProperty, setKeyValue, sort',
1425
+ input: {
1426
+ nodeType: {
1427
+ requestDefaults: {
1428
+ baseURL: 'http://127.0.0.1:5678',
1429
+ url: '/test-url',
1430
+ },
1431
+ properties: [
1432
+ {
1433
+ displayName: 'JSON Data',
1434
+ name: 'jsonData',
1435
+ type: 'string',
1436
+ routing: {
1437
+ send: {
1438
+ property: 'jsonData',
1439
+ type: 'body',
1440
+ },
1441
+ output: {
1442
+ postReceive: [
1443
+ {
1444
+ type: 'rootProperty',
1445
+ properties: {
1446
+ property: 'requestOptions.body.jsonData.root',
1447
+ },
1448
+ },
1449
+ {
1450
+ type: 'setKeyValue',
1451
+ properties: {
1452
+ display1: '={{$responseItem.name}} ({{$responseItem.age}})',
1453
+ display2: '={{$responseItem.name}} is {{$responseItem.age}}',
1454
+ },
1455
+ },
1456
+ {
1457
+ type: 'sort',
1458
+ properties: {
1459
+ key: 'display1',
1460
+ },
1461
+ },
1462
+ ],
1463
+ },
1464
+ },
1465
+ default: '',
1466
+ },
1467
+ ],
1468
+ },
1469
+ node: {
1470
+ parameters: {
1471
+ jsonData: {
1472
+ root: [
1473
+ {
1474
+ name: 'Jim',
1475
+ age: 34,
1476
+ },
1477
+ {
1478
+ name: 'James',
1479
+ age: 44,
1480
+ },
1481
+ ],
1482
+ },
1483
+ },
1484
+ },
1485
+ },
1486
+ output: [
1487
+ [
1488
+ {
1489
+ json: {
1490
+ display1: 'James (44)',
1491
+ display2: 'James is 44',
1492
+ },
1493
+ },
1494
+ {
1495
+ json: {
1496
+ display1: 'Jim (34)',
1497
+ display2: 'Jim is 34',
1498
+ },
1499
+ },
1500
+ ],
1501
+ ],
1502
+ },
1503
+ ];
1504
+ const nodeTypes = Helpers.NodeTypes();
1505
+ const baseNode = {
1506
+ parameters: {},
1507
+ name: 'test',
1508
+ type: 'test.set',
1509
+ typeVersion: 1,
1510
+ position: [0, 0],
1511
+ };
1512
+ const mode = 'internal';
1513
+ const runIndex = 0;
1514
+ const itemIndex = 0;
1515
+ const connectionInputData = [];
1516
+ const runExecutionData = { resultData: { runData: {} } };
1517
+ const additionalData = Helpers.WorkflowExecuteAdditionalData();
1518
+ const nodeType = nodeTypes.getByName(baseNode.type);
1519
+ const inputData = {
1520
+ main: [
1521
+ [
1522
+ {
1523
+ json: {},
1524
+ },
1525
+ ],
1526
+ ],
1527
+ };
1528
+ for (const testData of tests) {
1529
+ test(testData.description, async () => {
1530
+ const node = { ...baseNode, ...testData.input.node };
1531
+ const workflowData = {
1532
+ nodes: [node],
1533
+ connections: {},
1534
+ };
1535
+ nodeType.description = { ...testData.input.nodeType };
1536
+ const workflow = new src_1.Workflow({
1537
+ nodes: workflowData.nodes,
1538
+ connections: workflowData.connections,
1539
+ active: false,
1540
+ nodeTypes,
1541
+ });
1542
+ const routingNode = new src_1.RoutingNode(workflow, node, connectionInputData, runExecutionData !== null && runExecutionData !== void 0 ? runExecutionData : null, additionalData, mode);
1543
+ const nodeExecuteFunctions = {
1544
+ getExecuteFunctions: () => {
1545
+ return Helpers.getExecuteFunctions(workflow, runExecutionData, runIndex, connectionInputData, {}, node, itemIndex, additionalData, mode);
1546
+ },
1547
+ getExecuteSingleFunctions: () => {
1548
+ return Helpers.getExecuteSingleFunctions(workflow, runExecutionData, runIndex, connectionInputData, {}, node, itemIndex, additionalData, mode);
1549
+ },
1550
+ };
1551
+ const result = await routingNode.runNode(inputData, runIndex, nodeType, nodeExecuteFunctions);
1552
+ expect(result).toEqual(testData.output);
1553
+ });
1554
+ }
1555
+ });
1556
+ });
1557
+ //# sourceMappingURL=RoutingNode.test.js.map