@fsai-flow/workflow 0.0.2 → 0.1.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.
Files changed (136) hide show
  1. package/dist/README.md +31 -0
  2. package/dist/package.json +42 -0
  3. package/dist/src/index.d.ts +22 -0
  4. package/dist/src/index.d.ts.map +1 -0
  5. package/dist/src/index.js +68 -0
  6. package/dist/src/index.js.map +1 -0
  7. package/dist/src/lib/Constants.d.ts +69 -0
  8. package/dist/src/lib/Constants.d.ts.map +1 -0
  9. package/dist/src/lib/Constants.js +106 -0
  10. package/dist/src/lib/Constants.js.map +1 -0
  11. package/dist/src/lib/DeferredPromise.d.ts +7 -0
  12. package/dist/src/lib/DeferredPromise.d.ts.map +1 -0
  13. package/dist/src/lib/DeferredPromise.js +11 -0
  14. package/dist/src/lib/DeferredPromise.js.map +1 -0
  15. package/dist/src/lib/Expression.d.ts +66 -0
  16. package/dist/src/lib/Expression.d.ts.map +1 -0
  17. package/dist/src/lib/Expression.js +247 -0
  18. package/dist/src/lib/Expression.js.map +1 -0
  19. package/dist/src/lib/Interfaces.d.ts +1623 -0
  20. package/dist/src/lib/Interfaces.d.ts.map +1 -0
  21. package/dist/src/lib/Interfaces.js +44 -0
  22. package/dist/src/lib/Interfaces.js.map +1 -0
  23. package/dist/src/lib/LoggerProxy.d.ts +10 -0
  24. package/dist/src/lib/LoggerProxy.d.ts.map +1 -0
  25. package/dist/src/lib/LoggerProxy.js +40 -0
  26. package/dist/src/lib/LoggerProxy.js.map +1 -0
  27. package/dist/src/lib/MetadataUtils.d.ts +5 -0
  28. package/dist/src/lib/MetadataUtils.d.ts.map +1 -0
  29. package/dist/src/lib/MetadataUtils.js +27 -0
  30. package/dist/src/lib/MetadataUtils.js.map +1 -0
  31. package/dist/src/lib/NodeErrors.d.ts +83 -0
  32. package/dist/src/lib/NodeErrors.d.ts.map +1 -0
  33. package/dist/src/lib/NodeErrors.js +284 -0
  34. package/dist/src/lib/NodeErrors.js.map +1 -0
  35. package/dist/src/lib/NodeHelpers.d.ts +199 -0
  36. package/dist/src/lib/NodeHelpers.d.ts.map +1 -0
  37. package/dist/src/lib/NodeHelpers.js +1335 -0
  38. package/dist/src/lib/NodeHelpers.js.map +1 -0
  39. package/dist/src/lib/ObservableObject.d.ts +6 -0
  40. package/dist/src/lib/ObservableObject.d.ts.map +1 -0
  41. package/dist/src/lib/ObservableObject.js +61 -0
  42. package/dist/src/lib/ObservableObject.js.map +1 -0
  43. package/dist/src/lib/RoutingNode.d.ts +24 -0
  44. package/dist/src/lib/RoutingNode.d.ts.map +1 -0
  45. package/dist/src/lib/RoutingNode.js +528 -0
  46. package/dist/src/lib/RoutingNode.js.map +1 -0
  47. package/dist/src/lib/TelemetryHelpers.d.ts +4 -0
  48. package/dist/src/lib/TelemetryHelpers.d.ts.map +1 -0
  49. package/dist/src/lib/TelemetryHelpers.js +67 -0
  50. package/dist/src/lib/TelemetryHelpers.js.map +1 -0
  51. package/dist/src/lib/TypeValidation.d.ts +22 -0
  52. package/dist/src/lib/TypeValidation.d.ts.map +1 -0
  53. package/dist/src/lib/TypeValidation.js +376 -0
  54. package/dist/src/lib/TypeValidation.js.map +1 -0
  55. package/dist/src/lib/VersionedNodeType.d.ts +10 -0
  56. package/dist/src/lib/VersionedNodeType.d.ts.map +1 -0
  57. package/dist/src/lib/VersionedNodeType.js +24 -0
  58. package/dist/src/lib/VersionedNodeType.js.map +1 -0
  59. package/dist/src/lib/Workflow.d.ts +249 -0
  60. package/dist/src/lib/Workflow.d.ts.map +1 -0
  61. package/dist/src/lib/Workflow.js +899 -0
  62. package/dist/src/lib/Workflow.js.map +1 -0
  63. package/dist/src/lib/WorkflowDataProxy.d.ts +88 -0
  64. package/dist/src/lib/WorkflowDataProxy.d.ts.map +1 -0
  65. package/dist/src/lib/WorkflowDataProxy.js +583 -0
  66. package/dist/src/lib/WorkflowDataProxy.js.map +1 -0
  67. package/dist/src/lib/WorkflowErrors.d.ts +10 -0
  68. package/dist/src/lib/WorkflowErrors.d.ts.map +1 -0
  69. package/dist/src/lib/WorkflowErrors.js +18 -0
  70. package/dist/src/lib/WorkflowErrors.js.map +1 -0
  71. package/dist/src/lib/WorkflowHooks.d.ts +12 -0
  72. package/dist/src/lib/WorkflowHooks.d.ts.map +1 -0
  73. package/dist/src/lib/WorkflowHooks.js +32 -0
  74. package/dist/src/lib/WorkflowHooks.js.map +1 -0
  75. package/dist/src/lib/errors/base/base.error.d.ts +30 -0
  76. package/dist/src/lib/errors/base/base.error.d.ts.map +1 -0
  77. package/dist/src/lib/errors/base/base.error.js +47 -0
  78. package/dist/src/lib/errors/base/base.error.js.map +1 -0
  79. package/dist/src/lib/errors/base/operational.error.d.ts +16 -0
  80. package/dist/src/lib/errors/base/operational.error.d.ts.map +1 -0
  81. package/dist/src/lib/errors/base/operational.error.js +19 -0
  82. package/dist/src/lib/errors/base/operational.error.js.map +1 -0
  83. package/dist/src/lib/errors/error.types.d.ts +14 -0
  84. package/dist/src/lib/errors/error.types.d.ts.map +1 -0
  85. package/dist/src/lib/errors/error.types.js +3 -0
  86. package/dist/src/lib/errors/error.types.js.map +1 -0
  87. package/dist/src/lib/errors/index.d.ts +2 -0
  88. package/dist/src/lib/errors/index.d.ts.map +1 -0
  89. package/dist/src/lib/errors/index.js +6 -0
  90. package/dist/src/lib/errors/index.js.map +1 -0
  91. package/dist/src/lib/result.d.ts +20 -0
  92. package/dist/src/lib/result.d.ts.map +1 -0
  93. package/dist/src/lib/result.js +36 -0
  94. package/dist/src/lib/result.js.map +1 -0
  95. package/dist/src/lib/utils.d.ts +51 -0
  96. package/dist/src/lib/utils.d.ts.map +1 -0
  97. package/dist/src/lib/utils.js +119 -0
  98. package/dist/src/lib/utils.js.map +1 -0
  99. package/package.json +49 -35
  100. package/.eslintrc.json +0 -33
  101. package/eslint.config.js +0 -19
  102. package/jest.config.ts +0 -10
  103. package/project.json +0 -19
  104. package/src/index.ts +0 -33
  105. package/src/lib/Constants.ts +0 -124
  106. package/src/lib/DeferredPromise.ts +0 -14
  107. package/src/lib/Expression.ts +0 -375
  108. package/src/lib/Interfaces.ts +0 -2262
  109. package/src/lib/LoggerProxy.ts +0 -43
  110. package/src/lib/MetadataUtils.ts +0 -34
  111. package/src/lib/NodeErrors.ts +0 -332
  112. package/src/lib/NodeHelpers.ts +0 -1666
  113. package/src/lib/ObservableObject.ts +0 -77
  114. package/src/lib/RoutingNode.ts +0 -862
  115. package/src/lib/TelemetryHelpers.ts +0 -86
  116. package/src/lib/TypeValidation.ts +0 -431
  117. package/src/lib/VersionedNodeType.ts +0 -30
  118. package/src/lib/Workflow.ts +0 -1270
  119. package/src/lib/WorkflowDataProxy.ts +0 -708
  120. package/src/lib/WorkflowErrors.ts +0 -18
  121. package/src/lib/WorkflowHooks.ts +0 -51
  122. package/src/lib/errors/base/base.error.ts +0 -68
  123. package/src/lib/errors/base/operational.error.ts +0 -21
  124. package/src/lib/errors/error.types.ts +0 -14
  125. package/src/lib/errors/index.ts +0 -1
  126. package/src/lib/result.ts +0 -34
  127. package/src/lib/utils.ts +0 -166
  128. package/tests/Helpers.ts +0 -667
  129. package/tests/NodeHelpers.test.ts +0 -3053
  130. package/tests/ObservableObject.test.ts +0 -171
  131. package/tests/RoutingNode.test.ts +0 -1680
  132. package/tests/Workflow.test.ts +0 -1284
  133. package/tests/WorkflowDataProxy.test.ts +0 -199
  134. package/tsconfig.json +0 -27
  135. package/tsconfig.lib.json +0 -11
  136. package/tsconfig.spec.json +0 -14
@@ -0,0 +1,1335 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cronNodeOptions = void 0;
4
+ exports.getConnectionTypes = getConnectionTypes;
5
+ exports.isSubNodeType = isSubNodeType;
6
+ exports.getSpecialNodeParameters = getSpecialNodeParameters;
7
+ exports.displayParameter = displayParameter;
8
+ exports.displayParameterPath = displayParameterPath;
9
+ exports.getContext = getContext;
10
+ exports.getParamterDependencies = getParamterDependencies;
11
+ exports.getParamterResolveOrder = getParamterResolveOrder;
12
+ exports.getNodeParameters = getNodeParameters;
13
+ exports.prepareOutputData = prepareOutputData;
14
+ exports.getNodeWebhooks = getNodeWebhooks;
15
+ exports.getNodeWebhooksBasic = getNodeWebhooksBasic;
16
+ exports.getNodeWebhookPath = getNodeWebhookPath;
17
+ exports.getNodeWebhookUrl = getNodeWebhookUrl;
18
+ exports.getNodeParametersIssues = getNodeParametersIssues;
19
+ exports.nodeIssuesToString = nodeIssuesToString;
20
+ exports.addToIssuesIfMissing = addToIssuesIfMissing;
21
+ exports.getParameterValueByPath = getParameterValueByPath;
22
+ exports.getParameterIssues = getParameterIssues;
23
+ exports.mergeIssues = mergeIssues;
24
+ exports.mergeNodeProperties = mergeNodeProperties;
25
+ exports.getVersionedNodeType = getVersionedNodeType;
26
+ exports.getVersionedNodeTypeAll = getVersionedNodeTypeAll;
27
+ exports.isNodeTypeVersioned = isNodeTypeVersioned;
28
+ exports.getParameterValue = getParameterValue;
29
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
30
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
31
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
32
+ /* eslint-disable no-console */
33
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
34
+ /* eslint-disable @typescript-eslint/no-use-before-define */
35
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
36
+ /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
37
+ /* eslint-disable no-param-reassign */
38
+ /* eslint-disable no-continue */
39
+ /* eslint-disable prefer-spread */
40
+ /* eslint-disable no-restricted-syntax */
41
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
42
+ /* eslint-disable import/no-cycle */
43
+ // eslint-disable-next-line import/no-extraneous-dependencies
44
+ const lodash_1 = require("lodash");
45
+ const Interfaces_1 = require("./Interfaces");
46
+ function getConnectionTypes(connections) {
47
+ return connections
48
+ .map((connection) => {
49
+ if (typeof connection === "string") {
50
+ return connection;
51
+ }
52
+ return connection.type;
53
+ })
54
+ .filter((connection) => connection !== undefined);
55
+ }
56
+ exports.cronNodeOptions = [
57
+ {
58
+ name: "item",
59
+ displayName: "Item",
60
+ values: [
61
+ {
62
+ displayName: "Mode",
63
+ name: "mode",
64
+ type: "options",
65
+ options: [
66
+ {
67
+ name: "Every Minute",
68
+ value: "everyMinute",
69
+ },
70
+ {
71
+ name: "Every Hour",
72
+ value: "everyHour",
73
+ },
74
+ {
75
+ name: "Every Day",
76
+ value: "everyDay",
77
+ },
78
+ {
79
+ name: "Every Week",
80
+ value: "everyWeek",
81
+ },
82
+ {
83
+ name: "Every Month",
84
+ value: "everyMonth",
85
+ },
86
+ {
87
+ name: "Every X",
88
+ value: "everyX",
89
+ },
90
+ {
91
+ name: "Custom",
92
+ value: "custom",
93
+ },
94
+ ],
95
+ default: "everyDay",
96
+ description: "How often to trigger.",
97
+ },
98
+ {
99
+ displayName: "Hour",
100
+ name: "hour",
101
+ type: "number",
102
+ typeOptions: {
103
+ minValue: 0,
104
+ maxValue: 23,
105
+ },
106
+ displayOptions: {
107
+ hide: {
108
+ mode: ["custom", "everyHour", "everyMinute", "everyX"],
109
+ },
110
+ },
111
+ default: 14,
112
+ description: "The hour of the day to trigger (24h format)",
113
+ },
114
+ {
115
+ displayName: "Minute",
116
+ name: "minute",
117
+ type: "number",
118
+ typeOptions: {
119
+ minValue: 0,
120
+ maxValue: 59,
121
+ },
122
+ displayOptions: {
123
+ hide: {
124
+ mode: ["custom", "everyMinute", "everyX"],
125
+ },
126
+ },
127
+ default: 0,
128
+ description: "The minute of the day to trigger",
129
+ },
130
+ {
131
+ displayName: "Day of Month",
132
+ name: "dayOfMonth",
133
+ type: "number",
134
+ displayOptions: {
135
+ show: {
136
+ mode: ["everyMonth"],
137
+ },
138
+ },
139
+ typeOptions: {
140
+ minValue: 1,
141
+ maxValue: 31,
142
+ },
143
+ default: 1,
144
+ description: "The day of the month to trigger",
145
+ },
146
+ {
147
+ displayName: "Weekday",
148
+ name: "weekday",
149
+ type: "options",
150
+ displayOptions: {
151
+ show: {
152
+ mode: ["everyWeek"],
153
+ },
154
+ },
155
+ options: [
156
+ {
157
+ name: "Monday",
158
+ value: "1",
159
+ },
160
+ {
161
+ name: "Tuesday",
162
+ value: "2",
163
+ },
164
+ {
165
+ name: "Wednesday",
166
+ value: "3",
167
+ },
168
+ {
169
+ name: "Thursday",
170
+ value: "4",
171
+ },
172
+ {
173
+ name: "Friday",
174
+ value: "5",
175
+ },
176
+ {
177
+ name: "Saturday",
178
+ value: "6",
179
+ },
180
+ {
181
+ name: "Sunday",
182
+ value: "0",
183
+ },
184
+ ],
185
+ default: "1",
186
+ description: "The weekday to trigger",
187
+ },
188
+ {
189
+ displayName: "Cron Expression",
190
+ name: "cronExpression",
191
+ type: "string",
192
+ displayOptions: {
193
+ show: {
194
+ mode: ["custom"],
195
+ },
196
+ },
197
+ default: "* * * * * *",
198
+ description: "Use custom cron expression. Values and ranges as follows:<ul><li>Seconds: 0-59</li><li>Minutes: 0 - 59</li><li>Hours: 0 - 23</li><li>Day of Month: 1 - 31</li><li>Months: 0 - 11 (Jan - Dec)</li><li>Day of Week: 0 - 6 (Sun - Sat)</li></ul>",
199
+ },
200
+ {
201
+ displayName: "Value",
202
+ name: "value",
203
+ type: "number",
204
+ typeOptions: {
205
+ minValue: 0,
206
+ maxValue: 1000,
207
+ },
208
+ displayOptions: {
209
+ show: {
210
+ mode: ["everyX"],
211
+ },
212
+ },
213
+ default: 2,
214
+ description: "All how many X minutes/hours it should trigger",
215
+ },
216
+ {
217
+ displayName: "Unit",
218
+ name: "unit",
219
+ type: "options",
220
+ displayOptions: {
221
+ show: {
222
+ mode: ["everyX"],
223
+ },
224
+ },
225
+ options: [
226
+ {
227
+ name: "Minutes",
228
+ value: "minutes",
229
+ },
230
+ {
231
+ name: "Hours",
232
+ value: "hours",
233
+ },
234
+ {
235
+ name: "Seconds",
236
+ value: "seconds",
237
+ },
238
+ ],
239
+ default: "hours",
240
+ description: "If it should trigger all X minutes or hours",
241
+ },
242
+ ],
243
+ },
244
+ ];
245
+ function isSubNodeType(typeDescription) {
246
+ if (!typeDescription?.outputs || typeof typeDescription.outputs === "string") {
247
+ return false;
248
+ }
249
+ const outputTypes = getConnectionTypes(typeDescription.outputs);
250
+ return outputTypes ? outputTypes.filter((output) => output !== Interfaces_1.NodeConnectionTypes.Main).length > 0 : false;
251
+ }
252
+ /**
253
+ * Gets special parameters which should be added to nodeTypes depending
254
+ * on their type or configuration
255
+ *
256
+ * @export
257
+ * @param {INodeType} nodeType
258
+ * @returns
259
+ */
260
+ function getSpecialNodeParameters(nodeType) {
261
+ if (nodeType.description.polling === true) {
262
+ return [
263
+ {
264
+ displayName: "Poll Times",
265
+ name: "pollTimes",
266
+ type: "fixedCollection",
267
+ typeOptions: {
268
+ multipleValues: true,
269
+ multipleValueButtonText: "Add Poll Time",
270
+ },
271
+ default: { item: [{ mode: "everyMinute" }] },
272
+ description: "Time at which polling should occur",
273
+ placeholder: "Add Poll Time",
274
+ options: [
275
+ {
276
+ name: "item",
277
+ displayName: "Item",
278
+ values: [
279
+ {
280
+ displayName: "Mode",
281
+ name: "mode",
282
+ type: "options",
283
+ options: [
284
+ {
285
+ name: "Every Minute",
286
+ value: "everyMinute",
287
+ },
288
+ {
289
+ name: "Every Hour",
290
+ value: "everyHour",
291
+ },
292
+ {
293
+ name: "Every Day",
294
+ value: "everyDay",
295
+ },
296
+ {
297
+ name: "Every Week",
298
+ value: "everyWeek",
299
+ },
300
+ {
301
+ name: "Every Month",
302
+ value: "everyMonth",
303
+ },
304
+ {
305
+ name: "Every X",
306
+ value: "everyX",
307
+ },
308
+ {
309
+ name: "Custom",
310
+ value: "custom",
311
+ },
312
+ ],
313
+ default: "everyDay",
314
+ description: "How often to trigger.",
315
+ },
316
+ {
317
+ displayName: "Hour",
318
+ name: "hour",
319
+ type: "number",
320
+ typeOptions: {
321
+ minValue: 0,
322
+ maxValue: 23,
323
+ },
324
+ displayOptions: {
325
+ hide: {
326
+ mode: ["custom", "everyHour", "everyMinute", "everyX"],
327
+ },
328
+ },
329
+ default: 14,
330
+ description: "The hour of the day to trigger (24h format)",
331
+ },
332
+ {
333
+ displayName: "Minute",
334
+ name: "minute",
335
+ type: "number",
336
+ typeOptions: {
337
+ minValue: 0,
338
+ maxValue: 59,
339
+ },
340
+ displayOptions: {
341
+ hide: {
342
+ mode: ["custom", "everyMinute", "everyX"],
343
+ },
344
+ },
345
+ default: 0,
346
+ description: "The minute of the day to trigger",
347
+ },
348
+ {
349
+ displayName: "Day of Month",
350
+ name: "dayOfMonth",
351
+ type: "number",
352
+ displayOptions: {
353
+ show: {
354
+ mode: ["everyMonth"],
355
+ },
356
+ },
357
+ typeOptions: {
358
+ minValue: 1,
359
+ maxValue: 31,
360
+ },
361
+ default: 1,
362
+ description: "The day of the month to trigger",
363
+ },
364
+ {
365
+ displayName: "Weekday",
366
+ name: "weekday",
367
+ type: "options",
368
+ displayOptions: {
369
+ show: {
370
+ mode: ["everyWeek"],
371
+ },
372
+ },
373
+ options: [
374
+ {
375
+ name: "Monday",
376
+ value: "1",
377
+ },
378
+ {
379
+ name: "Tuesday",
380
+ value: "2",
381
+ },
382
+ {
383
+ name: "Wednesday",
384
+ value: "3",
385
+ },
386
+ {
387
+ name: "Thursday",
388
+ value: "4",
389
+ },
390
+ {
391
+ name: "Friday",
392
+ value: "5",
393
+ },
394
+ {
395
+ name: "Saturday",
396
+ value: "6",
397
+ },
398
+ {
399
+ name: "Sunday",
400
+ value: "0",
401
+ },
402
+ ],
403
+ default: "1",
404
+ description: "The weekday to trigger",
405
+ },
406
+ {
407
+ displayName: "Cron Expression",
408
+ name: "cronExpression",
409
+ type: "string",
410
+ displayOptions: {
411
+ show: {
412
+ mode: ["custom"],
413
+ },
414
+ },
415
+ default: "* * * * * *",
416
+ description: "Use custom cron expression. Values and ranges as follows:<ul><li>Seconds: 0-59</li><li>Minutes: 0 - 59</li><li>Hours: 0 - 23</li><li>Day of Month: 1 - 31</li><li>Months: 0 - 11 (Jan - Dec)</li><li>Day of Week: 0 - 6 (Sun - Sat)</li></ul>",
417
+ },
418
+ {
419
+ displayName: "Value",
420
+ name: "value",
421
+ type: "number",
422
+ typeOptions: {
423
+ minValue: 0,
424
+ maxValue: 1000,
425
+ },
426
+ displayOptions: {
427
+ show: {
428
+ mode: ["everyX"],
429
+ },
430
+ },
431
+ default: 2,
432
+ description: "All how many X minutes/hours it should trigger",
433
+ },
434
+ {
435
+ displayName: "Unit",
436
+ name: "unit",
437
+ type: "options",
438
+ displayOptions: {
439
+ show: {
440
+ mode: ["everyX"],
441
+ },
442
+ },
443
+ options: [
444
+ {
445
+ name: "Minutes",
446
+ value: "minutes",
447
+ },
448
+ {
449
+ name: "Hours",
450
+ value: "hours",
451
+ },
452
+ {
453
+ name: "Seconds",
454
+ value: "seconds",
455
+ },
456
+ ],
457
+ default: "hours",
458
+ description: "If it should trigger all X minutes or hours",
459
+ },
460
+ ],
461
+ },
462
+ ],
463
+ },
464
+ ];
465
+ }
466
+ return [];
467
+ }
468
+ /**
469
+ * Returns if the parameter should be displayed or not
470
+ *
471
+ * @export
472
+ * @param {INodeParameters} nodeValues The data on the node which decides if the parameter
473
+ * should be displayed
474
+ * @param {(INodeProperties | INodeCredentialDescription)} parameter The parameter to check if it should be displayed
475
+ * @param {INodeParameters} [nodeValuesRoot] The root node-parameter-data
476
+ * @returns
477
+ */
478
+ function displayParameter(nodeValues, parameter, nodeValuesRoot) {
479
+ if (!parameter.displayOptions) {
480
+ return true;
481
+ }
482
+ nodeValuesRoot = nodeValuesRoot || nodeValues;
483
+ let value;
484
+ const values = [];
485
+ if (parameter.displayOptions.show) {
486
+ // All the defined rules have to match to display parameter
487
+ for (const propertyName of Object.keys(parameter.displayOptions.show)) {
488
+ if (propertyName.charAt(0) === "/") {
489
+ // Get the value from the root of the node
490
+ value = (0, lodash_1.get)(nodeValuesRoot, propertyName.slice(1));
491
+ }
492
+ else {
493
+ // Get the value from current level
494
+ value = (0, lodash_1.get)(nodeValues, propertyName);
495
+ }
496
+ values.length = 0;
497
+ if (!Array.isArray(value)) {
498
+ values.push(value);
499
+ }
500
+ else {
501
+ values.push.apply(values, value);
502
+ }
503
+ if (values.some((v) => typeof v === "string" && v.charAt(0) === "=")) {
504
+ return true;
505
+ }
506
+ if (values.length === 0 || !parameter.displayOptions.show[propertyName].some((v) => values.includes(v))) {
507
+ return false;
508
+ }
509
+ }
510
+ }
511
+ if (parameter.displayOptions.hide) {
512
+ // Any of the defined hide rules have to match to hide the parameter
513
+ for (const propertyName of Object.keys(parameter.displayOptions.hide)) {
514
+ if (propertyName.charAt(0) === "/") {
515
+ // Get the value from the root of the node
516
+ value = (0, lodash_1.get)(nodeValuesRoot, propertyName.slice(1));
517
+ }
518
+ else {
519
+ // Get the value from current level
520
+ value = (0, lodash_1.get)(nodeValues, propertyName);
521
+ }
522
+ values.length = 0;
523
+ if (!Array.isArray(value)) {
524
+ values.push(value);
525
+ }
526
+ else {
527
+ values.push.apply(values, value);
528
+ }
529
+ if (values.length !== 0 && parameter.displayOptions.hide[propertyName].some((v) => values.includes(v))) {
530
+ return false;
531
+ }
532
+ }
533
+ }
534
+ return true;
535
+ }
536
+ /**
537
+ * Returns if the given parameter should be displayed or not considering the path
538
+ * to the properties
539
+ *
540
+ * @export
541
+ * @param {INodeParameters} nodeValues The data on the node which decides if the parameter
542
+ * should be displayed
543
+ * @param {(INodeProperties | INodeCredentialDescription)} parameter The parameter to check if it should be displayed
544
+ * @param {string} path The path to the property
545
+ * @returns
546
+ */
547
+ function displayParameterPath(nodeValues, parameter, path) {
548
+ let resolvedNodeValues = nodeValues;
549
+ if (path !== "") {
550
+ resolvedNodeValues = (0, lodash_1.get)(nodeValues, path);
551
+ }
552
+ // Get the root parameter data
553
+ let nodeValuesRoot = nodeValues;
554
+ if (path && path.split(".").indexOf("parameters") === 0) {
555
+ nodeValuesRoot = (0, lodash_1.get)(nodeValues, "parameters");
556
+ }
557
+ return displayParameter(resolvedNodeValues, parameter, nodeValuesRoot);
558
+ }
559
+ /**
560
+ * Returns the context data
561
+ *
562
+ * @export
563
+ * @param {IRunExecutionData} runExecutionData The run execution data
564
+ * @param {string} type The data type. "node"/"flow"
565
+ * @param {INode} [node] If type "node" is set the node to return the context of has to be supplied
566
+ * @returns {IContextObject}
567
+ */
568
+ function getContext(runExecutionData, type, node) {
569
+ if (runExecutionData.executionData === undefined) {
570
+ // TODO: Should not happen leave it for test now
571
+ throw new Error('The "executionData" is not initialized!');
572
+ }
573
+ let key;
574
+ if (type === "flow") {
575
+ key = "flow";
576
+ }
577
+ else if (type === "node") {
578
+ if (node === undefined) {
579
+ throw new Error(`The request data of context type "node" the node parameter has to be set!`);
580
+ }
581
+ key = `node:${node.name}`;
582
+ }
583
+ else {
584
+ throw new Error(`The context type "${type}" is not know. Only "flow" and node" are supported!`);
585
+ }
586
+ if (runExecutionData.executionData.contextData[key] === undefined) {
587
+ // eslint-disable-next-line no-param-reassign
588
+ runExecutionData.executionData.contextData[key] = {};
589
+ }
590
+ return runExecutionData.executionData.contextData[key];
591
+ }
592
+ /**
593
+ * Returns which parameters are dependent on which
594
+ *
595
+ * @export
596
+ * @param {INodeProperties[]} nodePropertiesArray
597
+ * @returns {IParameterDependencies}
598
+ */
599
+ function getParamterDependencies(nodePropertiesArray) {
600
+ const dependencies = {};
601
+ let displayRule;
602
+ let parameterName;
603
+ for (const nodeProperties of nodePropertiesArray) {
604
+ if (dependencies[nodeProperties.name] === undefined) {
605
+ dependencies[nodeProperties.name] = [];
606
+ }
607
+ if (nodeProperties.displayOptions === undefined) {
608
+ // Does not have any dependencies
609
+ continue;
610
+ }
611
+ for (displayRule of Object.keys(nodeProperties.displayOptions)) {
612
+ // @ts-expect-error
613
+ for (parameterName of Object.keys(nodeProperties.displayOptions[displayRule])) {
614
+ if (!dependencies[nodeProperties.name].includes(parameterName)) {
615
+ dependencies[nodeProperties.name].push(parameterName);
616
+ }
617
+ }
618
+ }
619
+ }
620
+ return dependencies;
621
+ }
622
+ /**
623
+ * Returns in which order the parameters should be resolved
624
+ * to have the parameters available they depend on
625
+ *
626
+ * @export
627
+ * @param {INodeProperties[]} nodePropertiesArray
628
+ * @param {IParameterDependencies} parameterDependencies
629
+ * @returns {number[]}
630
+ */
631
+ function getParamterResolveOrder(nodePropertiesArray, parameterDependencies) {
632
+ const executionOrder = [];
633
+ const indexToResolve = Array.from({ length: nodePropertiesArray.length }, (_v, k) => k);
634
+ const resolvedParamters = [];
635
+ let index;
636
+ let property;
637
+ let lastIndexLength = indexToResolve.length;
638
+ let lastIndexReduction = -1;
639
+ let iterations = 0;
640
+ while (indexToResolve.length !== 0) {
641
+ iterations += 1;
642
+ index = indexToResolve.shift();
643
+ property = nodePropertiesArray[index];
644
+ if (parameterDependencies[property.name].length === 0) {
645
+ // Does not have any dependencies so simply add
646
+ executionOrder.push(index);
647
+ resolvedParamters.push(property.name);
648
+ continue;
649
+ }
650
+ // Parameter has dependencies
651
+ for (const dependency of parameterDependencies[property.name]) {
652
+ if (!resolvedParamters.includes(dependency)) {
653
+ if (dependency.charAt(0) === "/") {
654
+ // Assume that root level depenencies are resolved
655
+ continue;
656
+ }
657
+ // Dependencies for that paramter are still missing so
658
+ // try to add again later
659
+ indexToResolve.push(index);
660
+ }
661
+ }
662
+ // All dependencies got found so add
663
+ executionOrder.push(index);
664
+ resolvedParamters.push(property.name);
665
+ if (indexToResolve.length < lastIndexLength) {
666
+ lastIndexReduction = iterations;
667
+ }
668
+ if (iterations > lastIndexReduction + nodePropertiesArray.length) {
669
+ throw new Error("Could not resolve parameter depenencies. Max iterations reached! Hint: If `displayOptions` are specified in any child parameter of a parent `collection` or `fixedCollection`, remove the `displayOptions` from the child parameter.");
670
+ }
671
+ lastIndexLength = indexToResolve.length;
672
+ }
673
+ return executionOrder;
674
+ }
675
+ /**
676
+ * Returns the node parameter values. Depending on the settings it either just returns the none
677
+ * default values or it applies all the default values.
678
+ *
679
+ * @export
680
+ * @param {INodeProperties[]} nodePropertiesArray The properties which exist and their settings
681
+ * @param {INodeParameters} nodeValues The node parameter data
682
+ * @param {boolean} returnDefaults If default values get added or only none default values returned
683
+ * @param {boolean} returnNoneDisplayed If also values which should not be displayed should be returned
684
+ * @param {boolean} [onlySimpleTypes=false] If only simple types should be resolved
685
+ * @param {boolean} [dataIsResolved=false] If nodeValues are already fully resolved (so that all default values got added already)
686
+ * @param {INodeParameters} [nodeValuesRoot] The root node-parameter-data
687
+ * @returns {(INodeParameters | null)}
688
+ */
689
+ function getNodeParameters(nodePropertiesArray, nodeValues, returnDefaults, returnNoneDisplayed, onlySimpleTypes = false, dataIsResolved = false, nodeValuesRoot, parentType, parameterDependencies) {
690
+ if (parameterDependencies === undefined) {
691
+ parameterDependencies = getParamterDependencies(nodePropertiesArray);
692
+ }
693
+ // Get the parameter names which get used multiple times as for this
694
+ // ones we have to always check which ones get displayed and which ones not
695
+ const duplicateParameterNames = [];
696
+ const parameterNames = [];
697
+ for (const nodeProperties of nodePropertiesArray) {
698
+ if (parameterNames.includes(nodeProperties.name)) {
699
+ if (!duplicateParameterNames.includes(nodeProperties.name)) {
700
+ duplicateParameterNames.push(nodeProperties.name);
701
+ }
702
+ }
703
+ else {
704
+ parameterNames.push(nodeProperties.name);
705
+ }
706
+ }
707
+ const nodeParameters = {};
708
+ const nodeParametersFull = {};
709
+ let nodeValuesDisplayCheck = nodeParametersFull;
710
+ if (!dataIsResolved && !returnNoneDisplayed) {
711
+ nodeValuesDisplayCheck = getNodeParameters(nodePropertiesArray, nodeValues, true, true, true, true, nodeValuesRoot, parentType, parameterDependencies);
712
+ }
713
+ nodeValuesRoot = nodeValuesRoot || nodeValuesDisplayCheck;
714
+ // Go through the parameters in order of their dependencies
715
+ const parameterItterationOrderIndex = getParamterResolveOrder(nodePropertiesArray, parameterDependencies);
716
+ for (const parameterIndex of parameterItterationOrderIndex) {
717
+ const nodeProperties = nodePropertiesArray[parameterIndex];
718
+ if (nodeValues[nodeProperties.name] === undefined && (!returnDefaults || parentType === "collection")) {
719
+ // The value is not defined so go to the next
720
+ continue;
721
+ }
722
+ if (!returnNoneDisplayed && !displayParameter(nodeValuesDisplayCheck, nodeProperties, nodeValuesRoot)) {
723
+ if (!returnNoneDisplayed || !returnDefaults) {
724
+ continue;
725
+ }
726
+ }
727
+ if (!["collection", "fixedCollection"].includes(nodeProperties.type)) {
728
+ // Is a simple property so can be set as it is
729
+ if (duplicateParameterNames.includes(nodeProperties.name)) {
730
+ if (!displayParameter(nodeValuesDisplayCheck, nodeProperties, nodeValuesRoot)) {
731
+ continue;
732
+ }
733
+ }
734
+ if (returnDefaults) {
735
+ // Set also when it has the default value
736
+ if (["boolean", "number", "options"].includes(nodeProperties.type)) {
737
+ // Boolean, numbers and options are special as false and 0 are valid values
738
+ // and should not be replaced with default value
739
+ nodeParameters[nodeProperties.name] =
740
+ nodeValues[nodeProperties.name] !== undefined ? nodeValues[nodeProperties.name] : nodeProperties.default;
741
+ }
742
+ else {
743
+ nodeParameters[nodeProperties.name] = nodeValues[nodeProperties.name] || nodeProperties.default;
744
+ }
745
+ nodeParametersFull[nodeProperties.name] = nodeParameters[nodeProperties.name];
746
+ }
747
+ else if ((nodeValues[nodeProperties.name] !== nodeProperties.default &&
748
+ typeof nodeValues[nodeProperties.name] !== "object") ||
749
+ (typeof nodeValues[nodeProperties.name] === "object" &&
750
+ !(0, lodash_1.isEqual)(nodeValues[nodeProperties.name], nodeProperties.default)) ||
751
+ (nodeValues[nodeProperties.name] !== undefined && parentType === "collection")) {
752
+ // Set only if it is different to the default value
753
+ nodeParameters[nodeProperties.name] = nodeValues[nodeProperties.name];
754
+ nodeParametersFull[nodeProperties.name] = nodeParameters[nodeProperties.name];
755
+ continue;
756
+ }
757
+ }
758
+ if (onlySimpleTypes) {
759
+ // It is only supposed to resolve the simple types. So continue.
760
+ continue;
761
+ }
762
+ // Is a complex property so check lower levels
763
+ let tempValue;
764
+ if (nodeProperties.type === "collection") {
765
+ // Is collection
766
+ if (nodeProperties.typeOptions !== undefined && nodeProperties.typeOptions.multipleValues === true) {
767
+ // Multiple can be set so will be an array
768
+ // Return directly the values like they are
769
+ if (nodeValues[nodeProperties.name] !== undefined) {
770
+ nodeParameters[nodeProperties.name] = nodeValues[nodeProperties.name];
771
+ }
772
+ else if (returnDefaults) {
773
+ // Does not have values defined but defaults should be returned
774
+ if (Array.isArray(nodeProperties.default)) {
775
+ nodeParameters[nodeProperties.name] = JSON.parse(JSON.stringify(nodeProperties.default));
776
+ }
777
+ else {
778
+ // As it is probably wrong for many nodes, do we keep on returning an empty array if
779
+ // anything else than an array is set as default
780
+ nodeParameters[nodeProperties.name] = [];
781
+ }
782
+ }
783
+ nodeParametersFull[nodeProperties.name] = nodeParameters[nodeProperties.name];
784
+ }
785
+ else if (nodeValues[nodeProperties.name] !== undefined) {
786
+ // Has values defined so get them
787
+ const tempNodeParameters = getNodeParameters(nodeProperties.options, nodeValues[nodeProperties.name], returnDefaults, returnNoneDisplayed, false, false, nodeValuesRoot, nodeProperties.type);
788
+ if (tempNodeParameters !== null) {
789
+ nodeParameters[nodeProperties.name] = tempNodeParameters;
790
+ nodeParametersFull[nodeProperties.name] = nodeParameters[nodeProperties.name];
791
+ }
792
+ }
793
+ else if (returnDefaults) {
794
+ // Does not have values defined but defaults should be returned
795
+ nodeParameters[nodeProperties.name] = JSON.parse(JSON.stringify(nodeProperties.default));
796
+ nodeParametersFull[nodeProperties.name] = nodeParameters[nodeProperties.name];
797
+ }
798
+ }
799
+ else if (nodeProperties.type === "fixedCollection") {
800
+ // Is fixedCollection
801
+ const collectionValues = {};
802
+ let tempNodeParameters;
803
+ let tempNodePropertiesArray;
804
+ let nodePropertyOptions;
805
+ let propertyValues = nodeValues[nodeProperties.name];
806
+ if (returnDefaults) {
807
+ if (propertyValues === undefined) {
808
+ propertyValues = JSON.parse(JSON.stringify(nodeProperties.default));
809
+ }
810
+ }
811
+ // Iterate over all collections
812
+ for (const itemName of Object.keys(propertyValues || {})) {
813
+ if (nodeProperties.typeOptions !== undefined && nodeProperties.typeOptions.multipleValues === true) {
814
+ // Multiple can be set so will be an array
815
+ const tempArrayValue = [];
816
+ // Iterate over all items as it contains multiple ones
817
+ for (const nodeValue of propertyValues[itemName]) {
818
+ nodePropertyOptions = nodeProperties.options.find(
819
+ // eslint-disable-next-line @typescript-eslint/no-shadow
820
+ (nodePropertyOptions) => nodePropertyOptions.name === itemName);
821
+ if (nodePropertyOptions === undefined) {
822
+ throw new Error(`Could not find property option "${itemName}" for "${nodeProperties.name}"`);
823
+ }
824
+ tempNodePropertiesArray = nodePropertyOptions.values;
825
+ tempValue = getNodeParameters(tempNodePropertiesArray, nodeValue, returnDefaults, returnNoneDisplayed, false, false, nodeValuesRoot, nodeProperties.type);
826
+ if (tempValue !== null) {
827
+ tempArrayValue.push(tempValue);
828
+ }
829
+ }
830
+ collectionValues[itemName] = tempArrayValue;
831
+ }
832
+ else {
833
+ // Only one can be set so is an object of objects
834
+ tempNodeParameters = {};
835
+ // Get the options of the current item
836
+ // eslint-disable-next-line @typescript-eslint/no-shadow
837
+ const nodePropertyOptions = nodeProperties.options.find((data) => data.name === itemName);
838
+ if (nodePropertyOptions !== undefined) {
839
+ tempNodePropertiesArray = nodePropertyOptions.values;
840
+ tempValue = getNodeParameters(tempNodePropertiesArray, nodeValues[nodeProperties.name][itemName], returnDefaults, returnNoneDisplayed, false, false, nodeValuesRoot, nodeProperties.type);
841
+ if (tempValue !== null) {
842
+ Object.assign(tempNodeParameters, tempValue);
843
+ }
844
+ }
845
+ if (Object.keys(tempNodeParameters).length !== 0) {
846
+ collectionValues[itemName] = tempNodeParameters;
847
+ }
848
+ }
849
+ }
850
+ if (Object.keys(collectionValues).length !== 0 || returnDefaults) {
851
+ // Set only if value got found
852
+ if (returnDefaults) {
853
+ // Set also when it has the default value
854
+ if (collectionValues === undefined) {
855
+ nodeParameters[nodeProperties.name] = JSON.parse(JSON.stringify(nodeProperties.default));
856
+ }
857
+ else {
858
+ nodeParameters[nodeProperties.name] = collectionValues;
859
+ }
860
+ nodeParametersFull[nodeProperties.name] = nodeParameters[nodeProperties.name];
861
+ }
862
+ else if (collectionValues !== nodeProperties.default) {
863
+ // Set only if values got found and it is not the default
864
+ nodeParameters[nodeProperties.name] = collectionValues;
865
+ nodeParametersFull[nodeProperties.name] = nodeParameters[nodeProperties.name];
866
+ }
867
+ }
868
+ }
869
+ }
870
+ return nodeParameters;
871
+ }
872
+ /**
873
+ * Brings the output data in a format that can be returned from a node
874
+ *
875
+ * @export
876
+ * @param {INodeExecutionData[]} outputData
877
+ * @param {number} [outputIndex=0]
878
+ * @returns {Promise<INodeExecutionData[][]>}
879
+ */
880
+ async function prepareOutputData(outputData, outputIndex = 0) {
881
+ // TODO: Check if node has output with that index
882
+ const returnData = [];
883
+ for (let i = 0; i < outputIndex; i++) {
884
+ returnData.push([]);
885
+ }
886
+ returnData.push(outputData);
887
+ return returnData;
888
+ }
889
+ /**
890
+ * Returns all the webhooks which should be created for the give node
891
+ *
892
+ * @export
893
+ *
894
+ * @param {INode} node
895
+ * @returns {IWebhookData[]}
896
+ */
897
+ function getNodeWebhooks(workflow, node, additionalData, ignoreRestartWehbooks = false) {
898
+ if (node.disabled === true) {
899
+ // Node is disabled so webhooks will also not be enabled
900
+ return [];
901
+ }
902
+ const nodeType = workflow.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
903
+ if (nodeType.description.webhooks === undefined) {
904
+ // Node does not have any webhooks so return
905
+ return [];
906
+ }
907
+ const workflowId = workflow.id || "__UNSAVED__";
908
+ const mode = "internal";
909
+ const returnData = [];
910
+ for (const webhookDescription of nodeType.description.webhooks) {
911
+ if (ignoreRestartWehbooks && webhookDescription.restartWebhook === true) {
912
+ continue;
913
+ }
914
+ let nodeWebhookPath = workflow.expression.getSimpleParameterValue(node, webhookDescription.path, mode, {});
915
+ if (nodeWebhookPath === undefined) {
916
+ // TODO: Use a proper logger
917
+ console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflowId}".`);
918
+ continue;
919
+ }
920
+ nodeWebhookPath = nodeWebhookPath.toString();
921
+ if (nodeWebhookPath.startsWith("/")) {
922
+ nodeWebhookPath = nodeWebhookPath.slice(1);
923
+ }
924
+ if (nodeWebhookPath.endsWith("/")) {
925
+ nodeWebhookPath = nodeWebhookPath.slice(0, -1);
926
+ }
927
+ const isFullPath = workflow.expression.getSimpleParameterValue(node, webhookDescription.isFullPath, "internal", {}, false);
928
+ const restartWebhook = workflow.expression.getSimpleParameterValue(node, webhookDescription.restartWebhook, "internal", {}, false);
929
+ const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath, isFullPath, restartWebhook);
930
+ const httpMethod = workflow.expression.getSimpleParameterValue(node, webhookDescription.httpMethod, mode, {}, "GET");
931
+ if (httpMethod === undefined) {
932
+ // TODO: Use a proper logger
933
+ console.error(`The webhook "${path}" for node "${node.name}" in workflow "${workflowId}" could not be added because the httpMethod is not defined.`);
934
+ continue;
935
+ }
936
+ let webhookId;
937
+ if ((path.startsWith(":") || path.includes("/:")) && node.webhookId) {
938
+ webhookId = node.webhookId;
939
+ }
940
+ returnData.push({
941
+ httpMethod: httpMethod.toString(),
942
+ node: node.name,
943
+ path,
944
+ webhookDescription,
945
+ workflowId,
946
+ workflowExecuteAdditionalData: additionalData,
947
+ webhookId,
948
+ });
949
+ }
950
+ return returnData;
951
+ }
952
+ function getNodeWebhooksBasic(workflow, node) {
953
+ if (node.disabled === true) {
954
+ // Node is disabled so webhooks will also not be enabled
955
+ return [];
956
+ }
957
+ const nodeType = workflow.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
958
+ if (nodeType.description.webhooks === undefined) {
959
+ // Node does not have any webhooks so return
960
+ return [];
961
+ }
962
+ const workflowId = workflow.id || "__UNSAVED__";
963
+ const mode = "internal";
964
+ const returnData = [];
965
+ for (const webhookDescription of nodeType.description.webhooks) {
966
+ let nodeWebhookPath = workflow.expression.getSimpleParameterValue(node, webhookDescription.path, mode, {});
967
+ if (nodeWebhookPath === undefined) {
968
+ // TODO: Use a proper logger
969
+ console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflowId}".`);
970
+ continue;
971
+ }
972
+ nodeWebhookPath = nodeWebhookPath.toString();
973
+ if (nodeWebhookPath.startsWith("/")) {
974
+ nodeWebhookPath = nodeWebhookPath.slice(1);
975
+ }
976
+ if (nodeWebhookPath.endsWith("/")) {
977
+ nodeWebhookPath = nodeWebhookPath.slice(0, -1);
978
+ }
979
+ const isFullPath = workflow.expression.getSimpleParameterValue(node, webhookDescription.isFullPath, mode, {}, false);
980
+ const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath, isFullPath);
981
+ const httpMethod = workflow.expression.getSimpleParameterValue(node, webhookDescription.httpMethod, mode, {});
982
+ if (httpMethod === undefined) {
983
+ // TODO: Use a proper logger
984
+ console.error(`The webhook "${path}" for node "${node.name}" in workflow "${workflowId}" could not be added because the httpMethod is not defined.`);
985
+ continue;
986
+ }
987
+ // @ts-expect-error
988
+ returnData.push({
989
+ httpMethod: httpMethod.toString(),
990
+ node: node.name,
991
+ path,
992
+ webhookDescription,
993
+ workflowId,
994
+ });
995
+ }
996
+ return returnData;
997
+ }
998
+ /**
999
+ * Returns the webhook path
1000
+ *
1001
+ * @export
1002
+ * @param {string} workflowId
1003
+ * @param {string} nodeTypeName
1004
+ * @param {string} path
1005
+ * @returns {string}
1006
+ */
1007
+ function getNodeWebhookPath(workflowId, node, path, isFullPath, restartWebhook) {
1008
+ let webhookPath = "";
1009
+ if (restartWebhook === true) {
1010
+ return path;
1011
+ }
1012
+ if (node.webhookId === undefined) {
1013
+ webhookPath = `${workflowId}/${encodeURIComponent(node.name.toLowerCase())}/${path}`;
1014
+ }
1015
+ else {
1016
+ if (isFullPath === true) {
1017
+ return path;
1018
+ }
1019
+ webhookPath = `${node.webhookId}/${path}`;
1020
+ }
1021
+ return webhookPath;
1022
+ }
1023
+ /**
1024
+ * Returns the webhook URL
1025
+ *
1026
+ * @export
1027
+ * @param {string} baseUrl
1028
+ * @param {string} workflowId
1029
+ * @param {string} nodeTypeName
1030
+ * @param {string} path
1031
+ * @param {boolean} isFullPath
1032
+ * @returns {string}
1033
+ */
1034
+ function getNodeWebhookUrl(baseUrl, workflowId, node, path, isFullPath) {
1035
+ if ((path.startsWith(":") || path.includes("/:")) && node.webhookId) {
1036
+ // setting this to false to prefix the webhookId
1037
+ isFullPath = false;
1038
+ }
1039
+ if (path.startsWith("/")) {
1040
+ path = path.slice(1);
1041
+ }
1042
+ return `${baseUrl}/${getNodeWebhookPath(workflowId, node, path, isFullPath)}`;
1043
+ }
1044
+ /**
1045
+ * Returns all the parameter-issues of the node
1046
+ *
1047
+ * @export
1048
+ * @param {INodeProperties[]} nodePropertiesArray The properties of the node
1049
+ * @param {INode} node The data of the node
1050
+ * @returns {(INodeIssues | null)}
1051
+ */
1052
+ function getNodeParametersIssues(nodePropertiesArray, node) {
1053
+ const foundIssues = {};
1054
+ let propertyIssues;
1055
+ if (node.disabled === true) {
1056
+ // Ignore issues on disabled nodes
1057
+ return null;
1058
+ }
1059
+ for (const nodeProperty of nodePropertiesArray) {
1060
+ propertyIssues = getParameterIssues(nodeProperty, node.parameters, "");
1061
+ mergeIssues(foundIssues, propertyIssues);
1062
+ }
1063
+ if (Object.keys(foundIssues).length === 0) {
1064
+ return null;
1065
+ }
1066
+ return foundIssues;
1067
+ }
1068
+ /**
1069
+ * Returns the issues of the node as string
1070
+ *
1071
+ * @export
1072
+ * @param {INodeIssues} issues The issues of the node
1073
+ * @param {INode} node The node
1074
+ * @returns {string[]}
1075
+ */
1076
+ function nodeIssuesToString(issues, node) {
1077
+ const nodeIssues = [];
1078
+ if (issues.execution !== undefined) {
1079
+ nodeIssues.push("Execution Error.");
1080
+ }
1081
+ const objectProperties = ["parameters", "credentials"];
1082
+ let issueText;
1083
+ let parameterName;
1084
+ for (const propertyName of objectProperties) {
1085
+ if (issues[propertyName] !== undefined) {
1086
+ for (parameterName of Object.keys(issues[propertyName])) {
1087
+ for (issueText of issues[propertyName][parameterName]) {
1088
+ nodeIssues.push(issueText);
1089
+ }
1090
+ }
1091
+ }
1092
+ }
1093
+ if (issues.typeUnknown !== undefined) {
1094
+ if (node !== undefined) {
1095
+ nodeIssues.push(`Node Type "${node.type}" is not known.`);
1096
+ }
1097
+ else {
1098
+ nodeIssues.push("Node Type is not known.");
1099
+ }
1100
+ }
1101
+ return nodeIssues;
1102
+ }
1103
+ /**
1104
+ * Adds an issue if the parameter is not defined
1105
+ *
1106
+ * @export
1107
+ * @param {INodeIssues} foundIssues The already found issues
1108
+ * @param {INodeProperties} nodeProperties The properties of the node
1109
+ * @param {NodeParameterValue} value The value of the parameter
1110
+ */
1111
+ function addToIssuesIfMissing(foundIssues, nodeProperties, value) {
1112
+ // TODO: Check what it really has when undefined
1113
+ if ((nodeProperties.type === "string" && (value === "" || value === undefined)) ||
1114
+ (nodeProperties.type === "multiOptions" && Array.isArray(value) && value.length === 0) ||
1115
+ (nodeProperties.type === "dateTime" && value === undefined)) {
1116
+ // Parameter is requried but empty
1117
+ if (foundIssues.parameters === undefined) {
1118
+ foundIssues.parameters = {};
1119
+ }
1120
+ if (foundIssues.parameters[nodeProperties.name] === undefined) {
1121
+ foundIssues.parameters[nodeProperties.name] = [];
1122
+ }
1123
+ foundIssues.parameters[nodeProperties.name].push(`Parameter "${nodeProperties.displayName}" is required.`);
1124
+ }
1125
+ }
1126
+ /**
1127
+ * Returns the parameter value
1128
+ *
1129
+ * @export
1130
+ * @param {INodeParameters} nodeValues The values of the node
1131
+ * @param {string} parameterName The name of the parameter to return the value of
1132
+ * @param {string} path The path to the properties
1133
+ * @returns
1134
+ */
1135
+ function getParameterValueByPath(nodeValues, parameterName, path) {
1136
+ return (0, lodash_1.get)(nodeValues, path ? `${path}.${parameterName}` : parameterName);
1137
+ }
1138
+ /**
1139
+ * Returns all the issues with the given node-values
1140
+ *
1141
+ * @export
1142
+ * @param {INodeProperties} nodeProperties The properties of the node
1143
+ * @param {INodeParameters} nodeValues The values of the node
1144
+ * @param {string} path The path to the properties
1145
+ * @returns {INodeIssues}
1146
+ */
1147
+ function getParameterIssues(nodeProperties, nodeValues, path) {
1148
+ const foundIssues = {};
1149
+ let value;
1150
+ if (nodeProperties.required === true) {
1151
+ if (displayParameterPath(nodeValues, nodeProperties, path)) {
1152
+ value = getParameterValueByPath(nodeValues, nodeProperties.name, path);
1153
+ if (
1154
+ // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
1155
+ nodeProperties.typeOptions !== undefined &&
1156
+ nodeProperties.typeOptions.multipleValues !== undefined) {
1157
+ // Multiple can be set so will be an array
1158
+ if (Array.isArray(value)) {
1159
+ for (const singleValue of value) {
1160
+ addToIssuesIfMissing(foundIssues, nodeProperties, singleValue);
1161
+ }
1162
+ }
1163
+ }
1164
+ else {
1165
+ // Only one can be set so will be a single value
1166
+ addToIssuesIfMissing(foundIssues, nodeProperties, value);
1167
+ }
1168
+ }
1169
+ }
1170
+ // Check if there are any child parameters
1171
+ if (nodeProperties.options === undefined) {
1172
+ // There are none so nothing else to check
1173
+ return foundIssues;
1174
+ }
1175
+ // Check the child parameters
1176
+ // Important:
1177
+ // Checks the child properties only if the property is defined on current level.
1178
+ // That means that the required flag works only for the current level only. If
1179
+ // it is set on a lower level it means that the property is only required in case
1180
+ // the parent property got set.
1181
+ let basePath = path ? `${path}.` : "";
1182
+ const checkChildNodeProperties = [];
1183
+ // Collect all the properties to check
1184
+ if (nodeProperties.type === "collection") {
1185
+ for (const option of nodeProperties.options) {
1186
+ checkChildNodeProperties.push({
1187
+ basePath,
1188
+ data: option,
1189
+ });
1190
+ }
1191
+ }
1192
+ else if (nodeProperties.type === "fixedCollection") {
1193
+ basePath = basePath ? `${basePath}.` : `${nodeProperties.name}.`;
1194
+ let propertyOptions;
1195
+ for (propertyOptions of nodeProperties.options) {
1196
+ // Check if the option got set and if not skip it
1197
+ value = getParameterValueByPath(nodeValues, propertyOptions.name, basePath.slice(0, -1));
1198
+ if (value === undefined) {
1199
+ continue;
1200
+ }
1201
+ if (
1202
+ // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
1203
+ nodeProperties.typeOptions !== undefined &&
1204
+ nodeProperties.typeOptions.multipleValues !== undefined) {
1205
+ // Multiple can be set so will be an array of objects
1206
+ if (Array.isArray(value)) {
1207
+ for (let i = 0; i < value.length; i++) {
1208
+ for (const option of propertyOptions.values) {
1209
+ checkChildNodeProperties.push({
1210
+ basePath: `${basePath}${propertyOptions.name}[${i}]`,
1211
+ data: option,
1212
+ });
1213
+ }
1214
+ }
1215
+ }
1216
+ }
1217
+ else {
1218
+ // Only one can be set so will be an object
1219
+ for (const option of propertyOptions.values) {
1220
+ checkChildNodeProperties.push({
1221
+ basePath: basePath + propertyOptions.name,
1222
+ data: option,
1223
+ });
1224
+ }
1225
+ }
1226
+ }
1227
+ }
1228
+ else {
1229
+ // For all other types there is nothing to check so return
1230
+ return foundIssues;
1231
+ }
1232
+ let propertyIssues;
1233
+ for (const optionData of checkChildNodeProperties) {
1234
+ propertyIssues = getParameterIssues(optionData.data, nodeValues, optionData.basePath);
1235
+ mergeIssues(foundIssues, propertyIssues);
1236
+ }
1237
+ return foundIssues;
1238
+ }
1239
+ /**
1240
+ * Merges multiple NodeIssues together
1241
+ *
1242
+ * @export
1243
+ * @param {INodeIssues} destination The issues to merge into
1244
+ * @param {(INodeIssues | null)} source The issues to merge
1245
+ * @returns
1246
+ */
1247
+ function mergeIssues(destination, source) {
1248
+ if (source === null) {
1249
+ // Nothing to merge
1250
+ return;
1251
+ }
1252
+ if (source.execution === true) {
1253
+ destination.execution = true;
1254
+ }
1255
+ const objectProperties = ["parameters", "credentials"];
1256
+ let destinationProperty;
1257
+ for (const propertyName of objectProperties) {
1258
+ if (source[propertyName] !== undefined) {
1259
+ if (destination[propertyName] === undefined) {
1260
+ destination[propertyName] = {};
1261
+ }
1262
+ let parameterName;
1263
+ for (parameterName of Object.keys(source[propertyName])) {
1264
+ destinationProperty = destination[propertyName];
1265
+ if (destinationProperty[parameterName] === undefined) {
1266
+ destinationProperty[parameterName] = [];
1267
+ }
1268
+ destinationProperty[parameterName].push.apply(destinationProperty[parameterName], source[propertyName][parameterName]);
1269
+ }
1270
+ }
1271
+ }
1272
+ if (source.typeUnknown === true) {
1273
+ destination.typeUnknown = true;
1274
+ }
1275
+ }
1276
+ /**
1277
+ * Merges the given node properties
1278
+ *
1279
+ * @export
1280
+ * @param {INodeProperties[]} mainProperties
1281
+ * @param {INodeProperties[]} addProperties
1282
+ */
1283
+ function mergeNodeProperties(mainProperties, addProperties) {
1284
+ let existingIndex;
1285
+ for (const property of addProperties) {
1286
+ existingIndex = mainProperties.findIndex((element) => element.name === property.name);
1287
+ if (existingIndex === -1) {
1288
+ // Property does not exist yet, so add
1289
+ mainProperties.push(property);
1290
+ }
1291
+ else {
1292
+ // Property exists already, so overwrite
1293
+ mainProperties[existingIndex] = property;
1294
+ }
1295
+ }
1296
+ }
1297
+ function getVersionedNodeType(object, version) {
1298
+ if (isNodeTypeVersioned(object)) {
1299
+ return object.getNodeType(version);
1300
+ }
1301
+ return object;
1302
+ }
1303
+ function getVersionedNodeTypeAll(object) {
1304
+ if (isNodeTypeVersioned(object)) {
1305
+ return Object.values(object.nodeVersions).map((element) => {
1306
+ element.description.name = object.description.name;
1307
+ return element;
1308
+ });
1309
+ }
1310
+ return [object];
1311
+ }
1312
+ function isNodeTypeVersioned(object) {
1313
+ return !!("getNodeType" in object);
1314
+ }
1315
+ /**
1316
+ * Returns the parameter value from the node parameters
1317
+ *
1318
+ * @export
1319
+ * @param {INodeParameters} nodeParameters The node parameters
1320
+ * @param {string} parameterName The name of the parameter to get
1321
+ * @param {number} [index=0] The index of the parameter value if it's an array
1322
+ * @returns {NodeParameterValue | undefined} The parameter value
1323
+ */
1324
+ function getParameterValue(nodeParameters, parameterName, index = 0) {
1325
+ const value = nodeParameters[parameterName];
1326
+ if (value === undefined) {
1327
+ return undefined;
1328
+ }
1329
+ if (Array.isArray(value)) {
1330
+ const arrayValue = value[index];
1331
+ return typeof arrayValue === "object" ? undefined : arrayValue;
1332
+ }
1333
+ return typeof value === "object" ? undefined : value;
1334
+ }
1335
+ //# sourceMappingURL=NodeHelpers.js.map