@atom8n/n8n-core 2.2.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 (352) hide show
  1. package/README.md +13 -0
  2. package/bin/common.js +19 -0
  3. package/bin/copy-static-files +24 -0
  4. package/bin/generate-metadata +75 -0
  5. package/bin/generate-translations +99 -0
  6. package/dist/binary-data/binary-data.config.d.ts +15 -0
  7. package/dist/binary-data/binary-data.config.js +62 -0
  8. package/dist/binary-data/binary-data.config.js.map +1 -0
  9. package/dist/binary-data/binary-data.service.d.ts +32 -0
  10. package/dist/binary-data/binary-data.service.js +243 -0
  11. package/dist/binary-data/binary-data.service.js.map +1 -0
  12. package/dist/binary-data/file-system.manager.d.ts +31 -0
  13. package/dist/binary-data/file-system.manager.js +154 -0
  14. package/dist/binary-data/file-system.manager.js.map +1 -0
  15. package/dist/binary-data/index.d.ts +5 -0
  16. package/dist/binary-data/index.js +27 -0
  17. package/dist/binary-data/index.js.map +1 -0
  18. package/dist/binary-data/object-store/object-store.config.d.ts +19 -0
  19. package/dist/binary-data/object-store/object-store.config.js +83 -0
  20. package/dist/binary-data/object-store/object-store.config.js.map +1 -0
  21. package/dist/binary-data/object-store/object-store.service.ee.d.ts +46 -0
  22. package/dist/binary-data/object-store/object-store.service.ee.js +235 -0
  23. package/dist/binary-data/object-store/object-store.service.ee.js.map +1 -0
  24. package/dist/binary-data/object-store/types.d.ts +8 -0
  25. package/dist/binary-data/object-store/types.js +3 -0
  26. package/dist/binary-data/object-store/types.js.map +1 -0
  27. package/dist/binary-data/object-store.manager.d.ts +23 -0
  28. package/dist/binary-data/object-store.manager.js +86 -0
  29. package/dist/binary-data/object-store.manager.js.map +1 -0
  30. package/dist/binary-data/types.d.ts +46 -0
  31. package/dist/binary-data/types.js +3 -0
  32. package/dist/binary-data/types.js.map +1 -0
  33. package/dist/binary-data/utils.d.ts +15 -0
  34. package/dist/binary-data/utils.js +66 -0
  35. package/dist/binary-data/utils.js.map +1 -0
  36. package/dist/build.tsbuildinfo +1 -0
  37. package/dist/constants.d.ts +19 -0
  38. package/dist/constants.js +23 -0
  39. package/dist/constants.js.map +1 -0
  40. package/dist/credentials.d.ts +12 -0
  41. package/dist/credentials.js +99 -0
  42. package/dist/credentials.js.map +1 -0
  43. package/dist/data-deduplication-service.d.ts +16 -0
  44. package/dist/data-deduplication-service.js +95 -0
  45. package/dist/data-deduplication-service.js.map +1 -0
  46. package/dist/encryption/cipher.d.ts +8 -0
  47. package/dist/encryption/cipher.js +57 -0
  48. package/dist/encryption/cipher.js.map +1 -0
  49. package/dist/encryption/index.d.ts +1 -0
  50. package/dist/encryption/index.js +6 -0
  51. package/dist/encryption/index.js.map +1 -0
  52. package/dist/errors/abstract/binary-data.error.d.ts +3 -0
  53. package/dist/errors/abstract/binary-data.error.js +8 -0
  54. package/dist/errors/abstract/binary-data.error.js.map +1 -0
  55. package/dist/errors/abstract/filesystem.error.d.ts +4 -0
  56. package/dist/errors/abstract/filesystem.error.js +11 -0
  57. package/dist/errors/abstract/filesystem.error.js.map +1 -0
  58. package/dist/errors/binary-data-file-not-found.error.d.ts +4 -0
  59. package/dist/errors/binary-data-file-not-found.error.js +11 -0
  60. package/dist/errors/binary-data-file-not-found.error.js.map +1 -0
  61. package/dist/errors/disallowed-filepath.error.d.ts +4 -0
  62. package/dist/errors/disallowed-filepath.error.js +11 -0
  63. package/dist/errors/disallowed-filepath.error.js.map +1 -0
  64. package/dist/errors/error-reporter.d.ts +35 -0
  65. package/dist/errors/error-reporter.js +256 -0
  66. package/dist/errors/error-reporter.js.map +1 -0
  67. package/dist/errors/file-not-found.error.d.ts +4 -0
  68. package/dist/errors/file-not-found.error.js +11 -0
  69. package/dist/errors/file-not-found.error.js.map +1 -0
  70. package/dist/errors/file-too-large.error.d.ts +9 -0
  71. package/dist/errors/file-too-large.error.js +13 -0
  72. package/dist/errors/file-too-large.error.js.map +1 -0
  73. package/dist/errors/index.d.ts +11 -0
  74. package/dist/errors/index.js +26 -0
  75. package/dist/errors/index.js.map +1 -0
  76. package/dist/errors/invalid-execution-metadata.error.d.ts +5 -0
  77. package/dist/errors/invalid-execution-metadata.error.js +12 -0
  78. package/dist/errors/invalid-execution-metadata.error.js.map +1 -0
  79. package/dist/errors/invalid-manager.error.d.ts +4 -0
  80. package/dist/errors/invalid-manager.error.js +11 -0
  81. package/dist/errors/invalid-manager.error.js.map +1 -0
  82. package/dist/errors/invalid-source-type.error.d.ts +4 -0
  83. package/dist/errors/invalid-source-type.error.js +11 -0
  84. package/dist/errors/invalid-source-type.error.js.map +1 -0
  85. package/dist/errors/missing-source-id.error.d.ts +4 -0
  86. package/dist/errors/missing-source-id.error.js +11 -0
  87. package/dist/errors/missing-source-id.error.js.map +1 -0
  88. package/dist/errors/unrecognized-credential-type.error.d.ts +4 -0
  89. package/dist/errors/unrecognized-credential-type.error.js +11 -0
  90. package/dist/errors/unrecognized-credential-type.error.js.map +1 -0
  91. package/dist/errors/unrecognized-node-type.error.d.ts +4 -0
  92. package/dist/errors/unrecognized-node-type.error.js +11 -0
  93. package/dist/errors/unrecognized-node-type.error.js.map +1 -0
  94. package/dist/errors/workflow-has-issues.error.d.ts +4 -0
  95. package/dist/errors/workflow-has-issues.error.js +11 -0
  96. package/dist/errors/workflow-has-issues.error.js.map +1 -0
  97. package/dist/execution-engine/active-workflows.d.ts +23 -0
  98. package/dist/execution-engine/active-workflows.js +153 -0
  99. package/dist/execution-engine/active-workflows.js.map +1 -0
  100. package/dist/execution-engine/execution-context-hook-registry.service.d.ts +12 -0
  101. package/dist/execution-engine/execution-context-hook-registry.service.js +69 -0
  102. package/dist/execution-engine/execution-context-hook-registry.service.js.map +1 -0
  103. package/dist/execution-engine/execution-context.d.ts +2 -0
  104. package/dist/execution-engine/execution-context.js +56 -0
  105. package/dist/execution-engine/execution-context.js.map +1 -0
  106. package/dist/execution-engine/execution-context.service.d.ts +17 -0
  107. package/dist/execution-engine/execution-context.service.js +108 -0
  108. package/dist/execution-engine/execution-context.service.js.map +1 -0
  109. package/dist/execution-engine/execution-lifecycle-hooks.d.ts +20 -0
  110. package/dist/execution-engine/execution-lifecycle-hooks.js +31 -0
  111. package/dist/execution-engine/execution-lifecycle-hooks.js.map +1 -0
  112. package/dist/execution-engine/external-secrets-proxy.d.ts +18 -0
  113. package/dist/execution-engine/external-secrets-proxy.js +38 -0
  114. package/dist/execution-engine/external-secrets-proxy.js.map +1 -0
  115. package/dist/execution-engine/index.d.ts +26 -0
  116. package/dist/execution-engine/index.js +31 -0
  117. package/dist/execution-engine/index.js.map +1 -0
  118. package/dist/execution-engine/interfaces.d.ts +7 -0
  119. package/dist/execution-engine/interfaces.js +3 -0
  120. package/dist/execution-engine/interfaces.js.map +1 -0
  121. package/dist/execution-engine/node-execution-context/base-execute-context.d.ts +47 -0
  122. package/dist/execution-engine/node-execution-context/base-execute-context.js +150 -0
  123. package/dist/execution-engine/node-execution-context/base-execute-context.js.map +1 -0
  124. package/dist/execution-engine/node-execution-context/credentials-test-context.d.ts +7 -0
  125. package/dist/execution-engine/node-execution-context/credentials-test-context.js +37 -0
  126. package/dist/execution-engine/node-execution-context/credentials-test-context.js.map +1 -0
  127. package/dist/execution-engine/node-execution-context/execute-context.d.ts +24 -0
  128. package/dist/execution-engine/node-execution-context/execute-context.js +108 -0
  129. package/dist/execution-engine/node-execution-context/execute-context.js.map +1 -0
  130. package/dist/execution-engine/node-execution-context/execute-single-context.d.ts +15 -0
  131. package/dist/execution-engine/node-execution-context/execute-single-context.js +53 -0
  132. package/dist/execution-engine/node-execution-context/execute-single-context.js.map +1 -0
  133. package/dist/execution-engine/node-execution-context/hook-context.d.ts +13 -0
  134. package/dist/execution-engine/node-execution-context/hook-context.js +35 -0
  135. package/dist/execution-engine/node-execution-context/hook-context.js.map +1 -0
  136. package/dist/execution-engine/node-execution-context/index.d.ts +17 -0
  137. package/dist/execution-engine/node-execution-context/index.js +51 -0
  138. package/dist/execution-engine/node-execution-context/index.js.map +1 -0
  139. package/dist/execution-engine/node-execution-context/load-options-context.d.ts +10 -0
  140. package/dist/execution-engine/node-execution-context/load-options-context.js +43 -0
  141. package/dist/execution-engine/node-execution-context/load-options-context.js.map +1 -0
  142. package/dist/execution-engine/node-execution-context/local-load-options-context.d.ts +10 -0
  143. package/dist/execution-engine/node-execution-context/local-load-options-context.js +51 -0
  144. package/dist/execution-engine/node-execution-context/local-load-options-context.js.map +1 -0
  145. package/dist/execution-engine/node-execution-context/node-execution-context.d.ts +68 -0
  146. package/dist/execution-engine/node-execution-context/node-execution-context.js +324 -0
  147. package/dist/execution-engine/node-execution-context/node-execution-context.js.map +1 -0
  148. package/dist/execution-engine/node-execution-context/poll-context.d.ts +11 -0
  149. package/dist/execution-engine/node-execution-context/poll-context.js +38 -0
  150. package/dist/execution-engine/node-execution-context/poll-context.js.map +1 -0
  151. package/dist/execution-engine/node-execution-context/supply-data-context.d.ts +26 -0
  152. package/dist/execution-engine/node-execution-context/supply-data-context.js +181 -0
  153. package/dist/execution-engine/node-execution-context/supply-data-context.js.map +1 -0
  154. package/dist/execution-engine/node-execution-context/trigger-context.d.ts +11 -0
  155. package/dist/execution-engine/node-execution-context/trigger-context.js +40 -0
  156. package/dist/execution-engine/node-execution-context/trigger-context.js.map +1 -0
  157. package/dist/execution-engine/node-execution-context/utils/binary-helper-functions.d.ts +10 -0
  158. package/dist/execution-engine/node-execution-context/utils/binary-helper-functions.js +213 -0
  159. package/dist/execution-engine/node-execution-context/utils/binary-helper-functions.js.map +1 -0
  160. package/dist/execution-engine/node-execution-context/utils/cleanup-parameter-data.d.ts +2 -0
  161. package/dist/execution-engine/node-execution-context/utils/cleanup-parameter-data.js +27 -0
  162. package/dist/execution-engine/node-execution-context/utils/cleanup-parameter-data.js.map +1 -0
  163. package/dist/execution-engine/node-execution-context/utils/construct-execution-metadata.d.ts +4 -0
  164. package/dist/execution-engine/node-execution-context/utils/construct-execution-metadata.js +11 -0
  165. package/dist/execution-engine/node-execution-context/utils/construct-execution-metadata.js.map +1 -0
  166. package/dist/execution-engine/node-execution-context/utils/copy-input-items.d.ts +2 -0
  167. package/dist/execution-engine/node-execution-context/utils/copy-input-items.js +19 -0
  168. package/dist/execution-engine/node-execution-context/utils/copy-input-items.js.map +1 -0
  169. package/dist/execution-engine/node-execution-context/utils/create-node-as-tool.d.ts +21 -0
  170. package/dist/execution-engine/node-execution-context/utils/create-node-as-tool.js +65 -0
  171. package/dist/execution-engine/node-execution-context/utils/create-node-as-tool.js.map +1 -0
  172. package/dist/execution-engine/node-execution-context/utils/data-table-helper-functions.d.ts +2 -0
  173. package/dist/execution-engine/node-execution-context/utils/data-table-helper-functions.js +13 -0
  174. package/dist/execution-engine/node-execution-context/utils/data-table-helper-functions.js.map +1 -0
  175. package/dist/execution-engine/node-execution-context/utils/deduplication-helper-functions.d.ts +2 -0
  176. package/dist/execution-engine/node-execution-context/utils/deduplication-helper-functions.js +38 -0
  177. package/dist/execution-engine/node-execution-context/utils/deduplication-helper-functions.js.map +1 -0
  178. package/dist/execution-engine/node-execution-context/utils/ensure-type.d.ts +6 -0
  179. package/dist/execution-engine/node-execution-context/utils/ensure-type.js +75 -0
  180. package/dist/execution-engine/node-execution-context/utils/ensure-type.js.map +1 -0
  181. package/dist/execution-engine/node-execution-context/utils/execution-metadata.d.ts +6 -0
  182. package/dist/execution-engine/node-execution-context/utils/execution-metadata.js +57 -0
  183. package/dist/execution-engine/node-execution-context/utils/execution-metadata.js.map +1 -0
  184. package/dist/execution-engine/node-execution-context/utils/extract-value.d.ts +2 -0
  185. package/dist/execution-engine/node-execution-context/utils/extract-value.js +135 -0
  186. package/dist/execution-engine/node-execution-context/utils/extract-value.js.map +1 -0
  187. package/dist/execution-engine/node-execution-context/utils/file-system-helper-functions.d.ts +2 -0
  188. package/dist/execution-engine/node-execution-context/utils/file-system-helper-functions.js +144 -0
  189. package/dist/execution-engine/node-execution-context/utils/file-system-helper-functions.js.map +1 -0
  190. package/dist/execution-engine/node-execution-context/utils/get-additional-keys.d.ts +4 -0
  191. package/dist/execution-engine/node-execution-context/utils/get-additional-keys.js +57 -0
  192. package/dist/execution-engine/node-execution-context/utils/get-additional-keys.js.map +1 -0
  193. package/dist/execution-engine/node-execution-context/utils/get-input-connection-data.d.ts +5 -0
  194. package/dist/execution-engine/node-execution-context/utils/get-input-connection-data.js +211 -0
  195. package/dist/execution-engine/node-execution-context/utils/get-input-connection-data.js.map +1 -0
  196. package/dist/execution-engine/node-execution-context/utils/get-secrets-proxy.d.ts +2 -0
  197. package/dist/execution-engine/node-execution-context/utils/get-secrets-proxy.js +68 -0
  198. package/dist/execution-engine/node-execution-context/utils/get-secrets-proxy.js.map +1 -0
  199. package/dist/execution-engine/node-execution-context/utils/normalize-items.d.ts +2 -0
  200. package/dist/execution-engine/node-execution-context/utils/normalize-items.js +36 -0
  201. package/dist/execution-engine/node-execution-context/utils/normalize-items.js.map +1 -0
  202. package/dist/execution-engine/node-execution-context/utils/parse-incoming-message.d.ts +16 -0
  203. package/dist/execution-engine/node-execution-context/utils/parse-incoming-message.js +57 -0
  204. package/dist/execution-engine/node-execution-context/utils/parse-incoming-message.js.map +1 -0
  205. package/dist/execution-engine/node-execution-context/utils/request-helper-functions.d.ts +18 -0
  206. package/dist/execution-engine/node-execution-context/utils/request-helper-functions.js +1213 -0
  207. package/dist/execution-engine/node-execution-context/utils/request-helper-functions.js.map +1 -0
  208. package/dist/execution-engine/node-execution-context/utils/return-json-array.d.ts +2 -0
  209. package/dist/execution-engine/node-execution-context/utils/return-json-array.js +19 -0
  210. package/dist/execution-engine/node-execution-context/utils/return-json-array.js.map +1 -0
  211. package/dist/execution-engine/node-execution-context/utils/scheduling-helper-functions.d.ts +2 -0
  212. package/dist/execution-engine/node-execution-context/utils/scheduling-helper-functions.js +22 -0
  213. package/dist/execution-engine/node-execution-context/utils/scheduling-helper-functions.js.map +1 -0
  214. package/dist/execution-engine/node-execution-context/utils/ssh-tunnel-helper-functions.d.ts +2 -0
  215. package/dist/execution-engine/node-execution-context/utils/ssh-tunnel-helper-functions.js +14 -0
  216. package/dist/execution-engine/node-execution-context/utils/ssh-tunnel-helper-functions.js.map +1 -0
  217. package/dist/execution-engine/node-execution-context/utils/validate-value-against-schema.d.ts +2 -0
  218. package/dist/execution-engine/node-execution-context/utils/validate-value-against-schema.js +132 -0
  219. package/dist/execution-engine/node-execution-context/utils/validate-value-against-schema.js.map +1 -0
  220. package/dist/execution-engine/node-execution-context/utils/webhook-helper-functions.d.ts +3 -0
  221. package/dist/execution-engine/node-execution-context/utils/webhook-helper-functions.js +31 -0
  222. package/dist/execution-engine/node-execution-context/utils/webhook-helper-functions.js.map +1 -0
  223. package/dist/execution-engine/node-execution-context/webhook-context.d.ts +21 -0
  224. package/dist/execution-engine/node-execution-context/webhook-context.js +87 -0
  225. package/dist/execution-engine/node-execution-context/webhook-context.js.map +1 -0
  226. package/dist/execution-engine/node-execution-context/workflow-node-context.d.ts +6 -0
  227. package/dist/execution-engine/node-execution-context/workflow-node-context.js +14 -0
  228. package/dist/execution-engine/node-execution-context/workflow-node-context.js.map +1 -0
  229. package/dist/execution-engine/partial-execution-utils/clean-run-data.d.ts +3 -0
  230. package/dist/execution-engine/partial-execution-utils/clean-run-data.js +28 -0
  231. package/dist/execution-engine/partial-execution-utils/clean-run-data.js.map +1 -0
  232. package/dist/execution-engine/partial-execution-utils/directed-graph.d.ts +65 -0
  233. package/dist/execution-engine/partial-execution-utils/directed-graph.js +370 -0
  234. package/dist/execution-engine/partial-execution-utils/directed-graph.js.map +1 -0
  235. package/dist/execution-engine/partial-execution-utils/filter-disabled-nodes.d.ts +2 -0
  236. package/dist/execution-engine/partial-execution-utils/filter-disabled-nodes.js +17 -0
  237. package/dist/execution-engine/partial-execution-utils/filter-disabled-nodes.js.map +1 -0
  238. package/dist/execution-engine/partial-execution-utils/find-start-nodes.d.ts +10 -0
  239. package/dist/execution-engine/partial-execution-utils/find-start-nodes.js +74 -0
  240. package/dist/execution-engine/partial-execution-utils/find-start-nodes.js.map +1 -0
  241. package/dist/execution-engine/partial-execution-utils/find-subgraph.d.ts +7 -0
  242. package/dist/execution-engine/partial-execution-utils/find-subgraph.js +59 -0
  243. package/dist/execution-engine/partial-execution-utils/find-subgraph.js.map +1 -0
  244. package/dist/execution-engine/partial-execution-utils/find-trigger-for-partial-execution.d.ts +4 -0
  245. package/dist/execution-engine/partial-execution-utils/find-trigger-for-partial-execution.js +102 -0
  246. package/dist/execution-engine/partial-execution-utils/find-trigger-for-partial-execution.js.map +1 -0
  247. package/dist/execution-engine/partial-execution-utils/get-incoming-data.d.ts +6 -0
  248. package/dist/execution-engine/partial-execution-utils/get-incoming-data.js +21 -0
  249. package/dist/execution-engine/partial-execution-utils/get-incoming-data.js.map +1 -0
  250. package/dist/execution-engine/partial-execution-utils/get-source-data-groups.d.ts +8 -0
  251. package/dist/execution-engine/partial-execution-utils/get-source-data-groups.js +65 -0
  252. package/dist/execution-engine/partial-execution-utils/get-source-data-groups.js.map +1 -0
  253. package/dist/execution-engine/partial-execution-utils/handle-cycles.d.ts +3 -0
  254. package/dist/execution-engine/partial-execution-utils/handle-cycles.js +60 -0
  255. package/dist/execution-engine/partial-execution-utils/handle-cycles.js.map +1 -0
  256. package/dist/execution-engine/partial-execution-utils/index.d.ts +10 -0
  257. package/dist/execution-engine/partial-execution-utils/index.js +25 -0
  258. package/dist/execution-engine/partial-execution-utils/index.js.map +1 -0
  259. package/dist/execution-engine/partial-execution-utils/recreate-node-execution-stack.d.ts +9 -0
  260. package/dist/execution-engine/partial-execution-utils/recreate-node-execution-stack.js +146 -0
  261. package/dist/execution-engine/partial-execution-utils/recreate-node-execution-stack.js.map +1 -0
  262. package/dist/execution-engine/partial-execution-utils/rewire-graph.d.ts +3 -0
  263. package/dist/execution-engine/partial-execution-utils/rewire-graph.js +72 -0
  264. package/dist/execution-engine/partial-execution-utils/rewire-graph.js.map +1 -0
  265. package/dist/execution-engine/partial-execution-utils/run-data-utils.d.ts +2 -0
  266. package/dist/execution-engine/partial-execution-utils/run-data-utils.js +15 -0
  267. package/dist/execution-engine/partial-execution-utils/run-data-utils.js.map +1 -0
  268. package/dist/execution-engine/requests-response.d.ts +23 -0
  269. package/dist/execution-engine/requests-response.js +128 -0
  270. package/dist/execution-engine/requests-response.js.map +1 -0
  271. package/dist/execution-engine/routing-node.d.ts +17 -0
  272. package/dist/execution-engine/routing-node.js +571 -0
  273. package/dist/execution-engine/routing-node.js.map +1 -0
  274. package/dist/execution-engine/scheduled-task-manager.d.ts +27 -0
  275. package/dist/execution-engine/scheduled-task-manager.js +140 -0
  276. package/dist/execution-engine/scheduled-task-manager.js.map +1 -0
  277. package/dist/execution-engine/ssh-clients-manager.d.ts +27 -0
  278. package/dist/execution-engine/ssh-clients-manager.js +170 -0
  279. package/dist/execution-engine/ssh-clients-manager.js.map +1 -0
  280. package/dist/execution-engine/triggers-and-pollers.d.ts +6 -0
  281. package/dist/execution-engine/triggers-and-pollers.js +66 -0
  282. package/dist/execution-engine/triggers-and-pollers.js.map +1 -0
  283. package/dist/execution-engine/workflow-execute.d.ts +46 -0
  284. package/dist/execution-engine/workflow-execute.js +1490 -0
  285. package/dist/execution-engine/workflow-execute.js.map +1 -0
  286. package/dist/html-sandbox.d.ts +3 -0
  287. package/dist/html-sandbox.js +19 -0
  288. package/dist/html-sandbox.js.map +1 -0
  289. package/dist/http-proxy.d.ts +6 -0
  290. package/dist/http-proxy.js +109 -0
  291. package/dist/http-proxy.js.map +1 -0
  292. package/dist/index.d.ts +17 -0
  293. package/dist/index.js +57 -0
  294. package/dist/index.js.map +1 -0
  295. package/dist/instance-settings/index.d.ts +1 -0
  296. package/dist/instance-settings/index.js +6 -0
  297. package/dist/instance-settings/index.js.map +1 -0
  298. package/dist/instance-settings/instance-settings.d.ts +49 -0
  299. package/dist/instance-settings/instance-settings.js +210 -0
  300. package/dist/instance-settings/instance-settings.js.map +1 -0
  301. package/dist/instance-settings/worker-missing-encryption-key.error.d.ts +4 -0
  302. package/dist/instance-settings/worker-missing-encryption-key.error.js +15 -0
  303. package/dist/instance-settings/worker-missing-encryption-key.error.js.map +1 -0
  304. package/dist/interfaces.d.ts +16 -0
  305. package/dist/interfaces.js +3 -0
  306. package/dist/interfaces.js.map +1 -0
  307. package/dist/node-execute-functions.d.ts +3 -0
  308. package/dist/node-execute-functions.js +12 -0
  309. package/dist/node-execute-functions.js.map +1 -0
  310. package/dist/nodes-loader/constants.d.ts +5 -0
  311. package/dist/nodes-loader/constants.js +106 -0
  312. package/dist/nodes-loader/constants.js.map +1 -0
  313. package/dist/nodes-loader/custom-directory-loader.d.ts +6 -0
  314. package/dist/nodes-loader/custom-directory-loader.js +34 -0
  315. package/dist/nodes-loader/custom-directory-loader.js.map +1 -0
  316. package/dist/nodes-loader/directory-loader.d.ts +41 -0
  317. package/dist/nodes-loader/directory-loader.js +371 -0
  318. package/dist/nodes-loader/directory-loader.js.map +1 -0
  319. package/dist/nodes-loader/index.d.ts +5 -0
  320. package/dist/nodes-loader/index.js +12 -0
  321. package/dist/nodes-loader/index.js.map +1 -0
  322. package/dist/nodes-loader/lazy-package-directory-loader.d.ts +4 -0
  323. package/dist/nodes-loader/lazy-package-directory-loader.js +42 -0
  324. package/dist/nodes-loader/lazy-package-directory-loader.js.map +1 -0
  325. package/dist/nodes-loader/load-class-in-isolation.d.ts +1 -0
  326. package/dist/nodes-loader/load-class-in-isolation.js +20 -0
  327. package/dist/nodes-loader/load-class-in-isolation.js.map +1 -0
  328. package/dist/nodes-loader/package-directory-loader.d.ts +12 -0
  329. package/dist/nodes-loader/package-directory-loader.js +86 -0
  330. package/dist/nodes-loader/package-directory-loader.js.map +1 -0
  331. package/dist/nodes-loader/types.d.ts +14 -0
  332. package/dist/nodes-loader/types.js +3 -0
  333. package/dist/nodes-loader/types.js.map +1 -0
  334. package/dist/utils/assertions.d.ts +2 -0
  335. package/dist/utils/assertions.js +16 -0
  336. package/dist/utils/assertions.js.map +1 -0
  337. package/dist/utils/deep-merge.d.ts +1 -0
  338. package/dist/utils/deep-merge.js +33 -0
  339. package/dist/utils/deep-merge.js.map +1 -0
  340. package/dist/utils/index.d.ts +2 -0
  341. package/dist/utils/index.js +19 -0
  342. package/dist/utils/index.js.map +1 -0
  343. package/dist/utils/is-json-compatible.d.ts +7 -0
  344. package/dist/utils/is-json-compatible.js +81 -0
  345. package/dist/utils/is-json-compatible.js.map +1 -0
  346. package/dist/utils/serialized-buffer.d.ts +6 -0
  347. package/dist/utils/serialized-buffer.js +16 -0
  348. package/dist/utils/serialized-buffer.js.map +1 -0
  349. package/dist/utils/signature-helpers.d.ts +2 -0
  350. package/dist/utils/signature-helpers.js +16 -0
  351. package/dist/utils/signature-helpers.js.map +1 -0
  352. package/package.json +81 -0
@@ -0,0 +1,1213 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getRequestHelperFunctions = exports.removeEmptyBody = exports.createFormDataObject = void 0;
40
+ exports.invokeAxios = invokeAxios;
41
+ exports.parseRequestObject = parseRequestObject;
42
+ exports.proxyRequestToAxios = proxyRequestToAxios;
43
+ exports.convertN8nRequestToAxios = convertN8nRequestToAxios;
44
+ exports.httpRequest = httpRequest;
45
+ exports.applyPaginationRequestData = applyPaginationRequestData;
46
+ exports.requestOAuth2 = requestOAuth2;
47
+ exports.requestOAuth1 = requestOAuth1;
48
+ exports.refreshOAuth2Token = refreshOAuth2Token;
49
+ exports.httpRequestWithAuthentication = httpRequestWithAuthentication;
50
+ exports.requestWithAuthentication = requestWithAuthentication;
51
+ const backend_common_1 = require("@n8n/backend-common");
52
+ const client_oauth2_1 = require("@n8n/client-oauth2");
53
+ const config_1 = require("@n8n/config");
54
+ const di_1 = require("@n8n/di");
55
+ const axios_1 = __importDefault(require("axios"));
56
+ const crypto_1 = __importStar(require("crypto"));
57
+ const form_data_1 = __importDefault(require("form-data"));
58
+ const http_1 = require("http");
59
+ const get_1 = __importDefault(require("lodash/get"));
60
+ const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
61
+ const merge_1 = __importDefault(require("lodash/merge"));
62
+ const pick_1 = __importDefault(require("lodash/pick"));
63
+ const n8n_workflow_1 = require("n8n-workflow");
64
+ const oauth_1_0a_1 = __importDefault(require("oauth-1.0a"));
65
+ const qs_1 = require("qs");
66
+ const stream_1 = require("stream");
67
+ const http_proxy_1 = require("../../../http-proxy");
68
+ const binary_helper_functions_1 = require("./binary-helper-functions");
69
+ const parse_incoming_message_1 = require("./parse-incoming-message");
70
+ axios_1.default.defaults.timeout = 300000;
71
+ axios_1.default.defaults.headers.post = {};
72
+ axios_1.default.defaults.headers.put = {};
73
+ axios_1.default.defaults.headers.patch = {};
74
+ axios_1.default.defaults.paramsSerializer = (params) => {
75
+ if (params instanceof URLSearchParams) {
76
+ return params.toString();
77
+ }
78
+ return (0, qs_1.stringify)(params, { arrayFormat: 'indices' });
79
+ };
80
+ axios_1.default.defaults.proxy = false;
81
+ function validateUrl(url) {
82
+ if (!url)
83
+ return false;
84
+ try {
85
+ new URL(url);
86
+ return true;
87
+ }
88
+ catch {
89
+ return false;
90
+ }
91
+ }
92
+ function getUrlFromProxyConfig(proxyConfig) {
93
+ if (typeof proxyConfig === 'string') {
94
+ return validateUrl(proxyConfig) ? proxyConfig : null;
95
+ }
96
+ if (!proxyConfig?.host)
97
+ return null;
98
+ const { protocol, host, port, auth } = proxyConfig;
99
+ const safeProtocol = protocol?.endsWith(':') ? protocol.slice(0, -1) : (protocol ?? 'http');
100
+ try {
101
+ const url = new URL(`${safeProtocol}://${host}`);
102
+ if (port !== undefined)
103
+ url.port = String(port);
104
+ if (auth?.username) {
105
+ url.username = auth.username;
106
+ url.password = auth.password ?? '';
107
+ }
108
+ return url.href;
109
+ }
110
+ catch {
111
+ return null;
112
+ }
113
+ }
114
+ function buildTargetUrl(url, baseURL) {
115
+ if (!url)
116
+ return undefined;
117
+ try {
118
+ return baseURL ? new URL(url, baseURL).href : url;
119
+ }
120
+ catch {
121
+ return undefined;
122
+ }
123
+ }
124
+ function setAxiosAgents(config, agentOptions, proxyConfig) {
125
+ if (config.httpAgent || config.httpsAgent)
126
+ return;
127
+ const customProxyUrl = getUrlFromProxyConfig(proxyConfig);
128
+ const targetUrl = buildTargetUrl(config.url, config.baseURL);
129
+ if (!targetUrl)
130
+ return;
131
+ config.httpAgent = (0, http_proxy_1.createHttpProxyAgent)(customProxyUrl, targetUrl, agentOptions);
132
+ config.httpsAgent = (0, http_proxy_1.createHttpsProxyAgent)(customProxyUrl, targetUrl, agentOptions);
133
+ }
134
+ function applyVendorHeaders(config) {
135
+ if ([config.url, config.baseURL].some((url) => url?.startsWith('https://api.openai.com/'))) {
136
+ config.headers = {
137
+ ...di_1.Container.get(config_1.AiConfig).openAiDefaultHeaders,
138
+ ...(config.headers || {}),
139
+ };
140
+ }
141
+ }
142
+ axios_1.default.interceptors.request.use((config) => {
143
+ if (config.data === undefined) {
144
+ config.headers.setContentType(false, false);
145
+ }
146
+ setAxiosAgents(config);
147
+ applyVendorHeaders(config);
148
+ return config;
149
+ });
150
+ function searchForHeader(config, headerName) {
151
+ if (config.headers === undefined) {
152
+ return undefined;
153
+ }
154
+ const headerNames = Object.keys(config.headers);
155
+ headerName = headerName.toLowerCase();
156
+ return headerNames.find((thisHeader) => thisHeader.toLowerCase() === headerName);
157
+ }
158
+ const getHostFromRequestObject = (requestObject) => {
159
+ try {
160
+ const url = (requestObject.url ?? requestObject.uri);
161
+ return new URL(url, requestObject.baseURL).hostname;
162
+ }
163
+ catch (error) {
164
+ return null;
165
+ }
166
+ };
167
+ const getBeforeRedirectFn = (agentOptions, axiosConfig, proxyConfig) => (redirectedRequest) => {
168
+ const redirectAgentOptions = {
169
+ ...agentOptions,
170
+ servername: redirectedRequest.hostname,
171
+ };
172
+ const customProxyUrl = getUrlFromProxyConfig(proxyConfig);
173
+ const targetUrl = redirectedRequest.href;
174
+ const httpAgent = (0, http_proxy_1.createHttpProxyAgent)(customProxyUrl, targetUrl, redirectAgentOptions);
175
+ const httpsAgent = (0, http_proxy_1.createHttpsProxyAgent)(customProxyUrl, targetUrl, redirectAgentOptions);
176
+ redirectedRequest.agent = redirectedRequest.href.startsWith('https://')
177
+ ? httpsAgent
178
+ : httpAgent;
179
+ redirectedRequest.agents = { http: httpAgent, https: httpsAgent };
180
+ if (axiosConfig.headers?.Authorization) {
181
+ redirectedRequest.headers.Authorization = axiosConfig.headers.Authorization;
182
+ }
183
+ if (axiosConfig.auth) {
184
+ redirectedRequest.auth = `${axiosConfig.auth.username}:${axiosConfig.auth.password}`;
185
+ }
186
+ };
187
+ function digestAuthAxiosConfig(axiosConfig, response, auth) {
188
+ const authDetails = response.headers['www-authenticate']
189
+ .split(',')
190
+ .map((v) => v.split('='));
191
+ if (authDetails) {
192
+ const nonceCount = '000000001';
193
+ const cnonce = crypto_1.default.randomBytes(24).toString('hex');
194
+ const realm = authDetails
195
+ .find((el) => el[0].toLowerCase().indexOf('realm') > -1)[1]
196
+ .replace(/"/g, '');
197
+ const opaqueKV = authDetails.find((el) => el[0].toLowerCase().indexOf('opaque') > -1);
198
+ const opaque = opaqueKV ? opaqueKV[1].replace(/"/g, '') : undefined;
199
+ const nonce = authDetails
200
+ .find((el) => el[0].toLowerCase().indexOf('nonce') > -1)[1]
201
+ .replace(/"/g, '');
202
+ const ha1 = crypto_1.default
203
+ .createHash('md5')
204
+ .update(`${auth?.username}:${realm}:${auth?.password}`)
205
+ .digest('hex');
206
+ const url = new URL(axios_1.default.getUri(axiosConfig));
207
+ const path = url.pathname + url.search;
208
+ const ha2 = crypto_1.default
209
+ .createHash('md5')
210
+ .update(`${axiosConfig.method ?? 'GET'}:${path}`)
211
+ .digest('hex');
212
+ const response = crypto_1.default
213
+ .createHash('md5')
214
+ .update(`${ha1}:${nonce}:${nonceCount}:${cnonce}:auth:${ha2}`)
215
+ .digest('hex');
216
+ let authorization = `Digest username="${auth?.username}",realm="${realm}",` +
217
+ `nonce="${nonce}",uri="${path}",qop="auth",algorithm="MD5",` +
218
+ `response="${response}",nc="${nonceCount}",cnonce="${cnonce}"`;
219
+ if (opaque) {
220
+ authorization += `,opaque="${opaque}"`;
221
+ }
222
+ if (axiosConfig.headers) {
223
+ axiosConfig.headers.authorization = authorization;
224
+ }
225
+ else {
226
+ axiosConfig.headers = { authorization };
227
+ }
228
+ }
229
+ return axiosConfig;
230
+ }
231
+ async function invokeAxios(axiosConfig, authOptions = {}) {
232
+ try {
233
+ return await (0, axios_1.default)(axiosConfig);
234
+ }
235
+ catch (error) {
236
+ if (authOptions.sendImmediately !== false || !(error instanceof axios_1.default.AxiosError))
237
+ throw error;
238
+ const { response } = error;
239
+ if (response?.status !== 401 || !response.headers['www-authenticate']?.includes('nonce')) {
240
+ throw error;
241
+ }
242
+ const { auth } = axiosConfig;
243
+ delete axiosConfig.auth;
244
+ axiosConfig = digestAuthAxiosConfig(axiosConfig, response, auth);
245
+ return await (0, axios_1.default)(axiosConfig);
246
+ }
247
+ }
248
+ const pushFormDataValue = (form, key, value) => {
249
+ if (value?.hasOwnProperty('value') && value.hasOwnProperty('options')) {
250
+ form.append(key, value.value, value.options);
251
+ }
252
+ else {
253
+ form.append(key, value);
254
+ }
255
+ };
256
+ const createFormDataObject = (data) => {
257
+ const formData = new form_data_1.default();
258
+ const keys = Object.keys(data);
259
+ keys.forEach((key) => {
260
+ const formField = data[key];
261
+ if (formField instanceof Array) {
262
+ formField.forEach((item) => {
263
+ pushFormDataValue(formData, key, item);
264
+ });
265
+ }
266
+ else {
267
+ pushFormDataValue(formData, key, formField);
268
+ }
269
+ });
270
+ return formData;
271
+ };
272
+ exports.createFormDataObject = createFormDataObject;
273
+ async function generateContentLengthHeader(config) {
274
+ if (!(config.data instanceof form_data_1.default)) {
275
+ return;
276
+ }
277
+ try {
278
+ const length = await new Promise((res, rej) => {
279
+ config.data.getLength((error, dataLength) => {
280
+ if (error)
281
+ rej(error);
282
+ else
283
+ res(dataLength);
284
+ });
285
+ });
286
+ config.headers = {
287
+ ...config.headers,
288
+ 'content-length': length,
289
+ };
290
+ }
291
+ catch (error) {
292
+ di_1.Container.get(backend_common_1.Logger).error('Unable to calculate form data length', { error });
293
+ }
294
+ }
295
+ async function parseRequestObject(requestObject) {
296
+ const axiosConfig = {};
297
+ if (requestObject.headers !== undefined) {
298
+ axiosConfig.headers = requestObject.headers;
299
+ }
300
+ const contentTypeHeaderKeyName = axiosConfig.headers &&
301
+ Object.keys(axiosConfig.headers).find((headerName) => headerName.toLowerCase() === 'content-type');
302
+ const contentType = contentTypeHeaderKeyName &&
303
+ axiosConfig.headers?.[contentTypeHeaderKeyName];
304
+ if (contentType === 'application/x-www-form-urlencoded' && requestObject.formData === undefined) {
305
+ if (typeof requestObject.body === 'string') {
306
+ axiosConfig.data = requestObject.body;
307
+ }
308
+ else {
309
+ const allData = Object.assign(requestObject.body || {}, requestObject.form || {});
310
+ if (requestObject.useQuerystring === true) {
311
+ axiosConfig.data = (0, qs_1.stringify)(allData, { arrayFormat: 'repeat' });
312
+ }
313
+ else {
314
+ axiosConfig.data = (0, qs_1.stringify)(allData);
315
+ }
316
+ }
317
+ }
318
+ else if (contentType?.includes('multipart/form-data')) {
319
+ if (requestObject.formData !== undefined && requestObject.formData instanceof form_data_1.default) {
320
+ axiosConfig.data = requestObject.formData;
321
+ }
322
+ else {
323
+ const allData = {
324
+ ...requestObject.body,
325
+ ...requestObject.formData,
326
+ };
327
+ axiosConfig.data = (0, exports.createFormDataObject)(allData);
328
+ }
329
+ delete axiosConfig.headers?.[contentTypeHeaderKeyName];
330
+ const headers = axiosConfig.data.getHeaders();
331
+ axiosConfig.headers = Object.assign(axiosConfig.headers || {}, headers);
332
+ await generateContentLengthHeader(axiosConfig);
333
+ }
334
+ else {
335
+ if (requestObject.form !== undefined && requestObject.body === undefined) {
336
+ axiosConfig.data =
337
+ typeof requestObject.form === 'string'
338
+ ? (0, qs_1.stringify)(requestObject.form, { format: 'RFC3986' })
339
+ : (0, qs_1.stringify)(requestObject.form).toString();
340
+ if (axiosConfig.headers !== undefined) {
341
+ const headerName = searchForHeader(axiosConfig, 'content-type');
342
+ if (headerName) {
343
+ delete axiosConfig.headers[headerName];
344
+ }
345
+ axiosConfig.headers['Content-Type'] = 'application/x-www-form-urlencoded';
346
+ }
347
+ else {
348
+ axiosConfig.headers = {
349
+ 'Content-Type': 'application/x-www-form-urlencoded',
350
+ };
351
+ }
352
+ }
353
+ else if (requestObject.formData !== undefined) {
354
+ if (axiosConfig.headers !== undefined) {
355
+ const headers = Object.keys(axiosConfig.headers);
356
+ headers.forEach((header) => {
357
+ if (header.toLowerCase() === 'content-type') {
358
+ delete axiosConfig.headers?.[header];
359
+ }
360
+ });
361
+ }
362
+ if (requestObject.formData instanceof form_data_1.default) {
363
+ axiosConfig.data = requestObject.formData;
364
+ }
365
+ else {
366
+ axiosConfig.data = (0, exports.createFormDataObject)(requestObject.formData);
367
+ }
368
+ const headers = axiosConfig.data.getHeaders();
369
+ axiosConfig.headers = Object.assign(axiosConfig.headers || {}, headers);
370
+ await generateContentLengthHeader(axiosConfig);
371
+ }
372
+ else if (requestObject.body !== undefined) {
373
+ if (requestObject.form !== undefined && requestObject.body) {
374
+ requestObject.body = Object.assign(requestObject.body, requestObject.form);
375
+ }
376
+ axiosConfig.data = requestObject.body;
377
+ }
378
+ }
379
+ if (requestObject.uri !== undefined) {
380
+ axiosConfig.url = requestObject.uri?.toString();
381
+ }
382
+ if (requestObject.url !== undefined) {
383
+ axiosConfig.url = requestObject.url?.toString();
384
+ }
385
+ if (requestObject.baseURL !== undefined) {
386
+ axiosConfig.baseURL = requestObject.baseURL?.toString();
387
+ }
388
+ if (requestObject.method !== undefined) {
389
+ axiosConfig.method = requestObject.method;
390
+ }
391
+ if (requestObject.qs !== undefined && Object.keys(requestObject.qs).length > 0) {
392
+ axiosConfig.params = requestObject.qs;
393
+ }
394
+ function hasArrayFormatOptions(arg) {
395
+ if (typeof arg.qsStringifyOptions === 'object' &&
396
+ arg.qsStringifyOptions !== null &&
397
+ !Array.isArray(arg.qsStringifyOptions) &&
398
+ 'arrayFormat' in arg.qsStringifyOptions) {
399
+ return true;
400
+ }
401
+ return false;
402
+ }
403
+ if (requestObject.useQuerystring === true ||
404
+ (hasArrayFormatOptions(requestObject) &&
405
+ requestObject.qsStringifyOptions.arrayFormat === 'repeat')) {
406
+ axiosConfig.paramsSerializer = (params) => {
407
+ return (0, qs_1.stringify)(params, { arrayFormat: 'repeat' });
408
+ };
409
+ }
410
+ else if (requestObject.useQuerystring === false) {
411
+ axiosConfig.paramsSerializer = (params) => {
412
+ return (0, qs_1.stringify)(params, { arrayFormat: 'indices' });
413
+ };
414
+ }
415
+ if (hasArrayFormatOptions(requestObject) &&
416
+ requestObject.qsStringifyOptions.arrayFormat === 'brackets') {
417
+ axiosConfig.paramsSerializer = (params) => {
418
+ return (0, qs_1.stringify)(params, { arrayFormat: 'brackets' });
419
+ };
420
+ }
421
+ if (requestObject.auth !== undefined) {
422
+ if (requestObject.auth.bearer !== undefined) {
423
+ axiosConfig.headers = Object.assign(axiosConfig.headers || {}, {
424
+ Authorization: `Bearer ${requestObject.auth.bearer}`,
425
+ });
426
+ }
427
+ else {
428
+ const authObj = requestObject.auth;
429
+ axiosConfig.auth = {
430
+ username: (authObj.user || authObj.username),
431
+ password: (authObj.password || authObj.pass),
432
+ };
433
+ }
434
+ }
435
+ if (requestObject.json === true) {
436
+ const acceptHeaderExists = axiosConfig.headers === undefined
437
+ ? false
438
+ : Object.keys(axiosConfig.headers)
439
+ .map((headerKey) => headerKey.toLowerCase())
440
+ .includes('accept');
441
+ if (!acceptHeaderExists) {
442
+ axiosConfig.headers = Object.assign(axiosConfig.headers || {}, {
443
+ Accept: 'application/json',
444
+ });
445
+ }
446
+ }
447
+ if (requestObject.json === false || requestObject.json === undefined) {
448
+ axiosConfig.transformResponse = (res) => res;
449
+ }
450
+ const { method } = requestObject;
451
+ if ((requestObject.followRedirect !== false &&
452
+ (!method || method === 'GET' || method === 'HEAD')) ||
453
+ requestObject.followAllRedirects) {
454
+ axiosConfig.maxRedirects = requestObject.maxRedirects;
455
+ }
456
+ else {
457
+ axiosConfig.maxRedirects = 0;
458
+ }
459
+ const host = getHostFromRequestObject(requestObject);
460
+ const agentOptions = { ...requestObject.agentOptions };
461
+ if (host) {
462
+ agentOptions.servername = host;
463
+ }
464
+ if (requestObject.rejectUnauthorized === false) {
465
+ agentOptions.rejectUnauthorized = false;
466
+ agentOptions.secureOptions = crypto_1.default.constants.SSL_OP_LEGACY_SERVER_CONNECT;
467
+ }
468
+ if (requestObject.timeout !== undefined) {
469
+ axiosConfig.timeout = requestObject.timeout;
470
+ }
471
+ setAxiosAgents(axiosConfig, agentOptions, requestObject.proxy);
472
+ axiosConfig.beforeRedirect = getBeforeRedirectFn(agentOptions, axiosConfig, requestObject.proxy);
473
+ if (requestObject.useStream) {
474
+ axiosConfig.responseType = 'stream';
475
+ }
476
+ else if (requestObject.encoding === null) {
477
+ axiosConfig.responseType = 'arraybuffer';
478
+ }
479
+ const allHeaders = axiosConfig.headers ? Object.keys(axiosConfig.headers) : [];
480
+ if (!allHeaders.some((headerKey) => headerKey.toLowerCase() === 'accept')) {
481
+ axiosConfig.headers = Object.assign(axiosConfig.headers || {}, { accept: '*/*' });
482
+ }
483
+ if (requestObject.json !== false &&
484
+ axiosConfig.data !== undefined &&
485
+ axiosConfig.data !== '' &&
486
+ !(axiosConfig.data instanceof Buffer) &&
487
+ !allHeaders.some((headerKey) => headerKey.toLowerCase() === 'content-type')) {
488
+ axiosConfig.headers = Object.assign(axiosConfig.headers || {}, {
489
+ 'content-type': 'application/json',
490
+ });
491
+ }
492
+ if (requestObject.simple === false) {
493
+ axiosConfig.validateStatus = () => true;
494
+ }
495
+ return axiosConfig;
496
+ }
497
+ async function proxyRequestToAxios(workflow, additionalData, node, uriOrObject, options) {
498
+ let axiosConfig = {
499
+ maxBodyLength: Infinity,
500
+ maxContentLength: Infinity,
501
+ };
502
+ let configObject;
503
+ if (typeof uriOrObject === 'string') {
504
+ configObject = { uri: uriOrObject, ...options };
505
+ }
506
+ else {
507
+ configObject = uriOrObject ?? {};
508
+ }
509
+ axiosConfig = Object.assign(axiosConfig, await parseRequestObject(configObject));
510
+ try {
511
+ const response = await invokeAxios(axiosConfig, configObject.auth);
512
+ let body = response.data;
513
+ if (body instanceof http_1.IncomingMessage && axiosConfig.responseType === 'stream') {
514
+ (0, parse_incoming_message_1.parseIncomingMessage)(body);
515
+ }
516
+ else if (body === '') {
517
+ body = axiosConfig.responseType === 'arraybuffer' ? Buffer.alloc(0) : undefined;
518
+ }
519
+ await additionalData?.hooks?.runHook('nodeFetchedData', [workflow?.id, node]);
520
+ return configObject.resolveWithFullResponse
521
+ ? {
522
+ body,
523
+ headers: { ...response.headers },
524
+ statusCode: response.status,
525
+ statusMessage: response.statusText,
526
+ request: response.request,
527
+ }
528
+ : body;
529
+ }
530
+ catch (error) {
531
+ const { config, response } = error;
532
+ if (error.isAxiosError) {
533
+ error.config = error.request = undefined;
534
+ error.options = (0, pick_1.default)(config ?? {}, ['url', 'method', 'data', 'headers']);
535
+ if (response) {
536
+ di_1.Container.get(backend_common_1.Logger).debug('Request proxied to Axios failed', { status: response.status });
537
+ let responseData = response.data;
538
+ if (Buffer.isBuffer(responseData) || responseData instanceof stream_1.Readable) {
539
+ responseData = await (0, binary_helper_functions_1.binaryToString)(responseData);
540
+ }
541
+ if (configObject.simple === false) {
542
+ if (configObject.resolveWithFullResponse) {
543
+ return {
544
+ body: responseData,
545
+ headers: response.headers,
546
+ statusCode: response.status,
547
+ statusMessage: response.statusText,
548
+ };
549
+ }
550
+ else {
551
+ return responseData;
552
+ }
553
+ }
554
+ error.message = `${response.status} - ${JSON.stringify(responseData)}`;
555
+ throw Object.assign(error, {
556
+ statusCode: response.status,
557
+ status: response.status,
558
+ error: responseData,
559
+ response: (0, pick_1.default)(response, ['headers', 'status', 'statusText']),
560
+ });
561
+ }
562
+ else if ('rejectUnauthorized' in configObject && error.code?.includes('CERT')) {
563
+ throw new n8n_workflow_1.NodeSslError(error);
564
+ }
565
+ }
566
+ throw error;
567
+ }
568
+ }
569
+ function convertN8nRequestToAxios(n8nRequest) {
570
+ const { headers, method, timeout, auth, proxy, url } = n8nRequest;
571
+ const axiosRequest = {
572
+ headers: headers ?? {},
573
+ method,
574
+ timeout,
575
+ auth,
576
+ url,
577
+ maxBodyLength: Infinity,
578
+ maxContentLength: Infinity,
579
+ };
580
+ axiosRequest.params = n8nRequest.qs;
581
+ if (n8nRequest.abortSignal) {
582
+ axiosRequest.signal = n8nRequest.abortSignal;
583
+ }
584
+ if (n8nRequest.baseURL !== undefined) {
585
+ axiosRequest.baseURL = n8nRequest.baseURL;
586
+ }
587
+ if (n8nRequest.disableFollowRedirect === true) {
588
+ axiosRequest.maxRedirects = 0;
589
+ }
590
+ if (n8nRequest.encoding !== undefined) {
591
+ axiosRequest.responseType = n8nRequest.encoding;
592
+ }
593
+ const host = getHostFromRequestObject(n8nRequest);
594
+ const agentOptions = {};
595
+ if (host) {
596
+ agentOptions.servername = host;
597
+ }
598
+ if (n8nRequest.skipSslCertificateValidation === true) {
599
+ agentOptions.rejectUnauthorized = false;
600
+ }
601
+ setAxiosAgents(axiosRequest, agentOptions, proxy);
602
+ axiosRequest.beforeRedirect = getBeforeRedirectFn(agentOptions, axiosRequest, n8nRequest.proxy);
603
+ if (n8nRequest.arrayFormat !== undefined) {
604
+ axiosRequest.paramsSerializer = (params) => {
605
+ return (0, qs_1.stringify)(params, { arrayFormat: n8nRequest.arrayFormat });
606
+ };
607
+ }
608
+ const { body } = n8nRequest;
609
+ if (body) {
610
+ const existingContentTypeHeaderKey = searchForHeader(axiosRequest, 'content-type');
611
+ if (existingContentTypeHeaderKey === undefined) {
612
+ axiosRequest.headers = axiosRequest.headers || {};
613
+ if (body instanceof form_data_1.default) {
614
+ axiosRequest.headers = {
615
+ ...axiosRequest.headers,
616
+ ...body.getHeaders(),
617
+ };
618
+ }
619
+ else if (body instanceof URLSearchParams) {
620
+ axiosRequest.headers['Content-Type'] = 'application/x-www-form-urlencoded';
621
+ }
622
+ }
623
+ else if (axiosRequest.headers?.[existingContentTypeHeaderKey] === 'application/x-www-form-urlencoded') {
624
+ axiosRequest.data = new URLSearchParams(n8nRequest.body);
625
+ }
626
+ if (typeof body === 'string' || (typeof body === 'object' && !(0, n8n_workflow_1.isObjectEmpty)(body))) {
627
+ axiosRequest.data = body;
628
+ }
629
+ }
630
+ if (n8nRequest.json) {
631
+ const key = searchForHeader(axiosRequest, 'accept');
632
+ if (!key) {
633
+ axiosRequest.headers = {
634
+ ...axiosRequest.headers,
635
+ Accept: 'application/json',
636
+ };
637
+ }
638
+ }
639
+ const userAgentHeader = searchForHeader(axiosRequest, 'user-agent');
640
+ if (!userAgentHeader) {
641
+ axiosRequest.headers = {
642
+ ...axiosRequest.headers,
643
+ 'User-Agent': 'n8n',
644
+ };
645
+ }
646
+ if (n8nRequest.ignoreHttpStatusErrors) {
647
+ axiosRequest.validateStatus = () => true;
648
+ }
649
+ return axiosRequest;
650
+ }
651
+ const NoBodyHttpMethods = ['GET', 'HEAD', 'OPTIONS'];
652
+ const removeEmptyBody = (requestOptions) => {
653
+ const method = requestOptions.method || 'GET';
654
+ if (NoBodyHttpMethods.includes(method) && (0, isEmpty_1.default)(requestOptions.body)) {
655
+ delete requestOptions.body;
656
+ }
657
+ };
658
+ exports.removeEmptyBody = removeEmptyBody;
659
+ async function httpRequest(requestOptions) {
660
+ (0, exports.removeEmptyBody)(requestOptions);
661
+ const axiosRequest = convertN8nRequestToAxios(requestOptions);
662
+ if (axiosRequest.data === undefined ||
663
+ (axiosRequest.method !== undefined && axiosRequest.method.toUpperCase() === 'GET')) {
664
+ delete axiosRequest.data;
665
+ }
666
+ const result = await invokeAxios(axiosRequest, requestOptions.auth);
667
+ if (requestOptions.returnFullResponse) {
668
+ return {
669
+ body: result.data,
670
+ headers: result.headers,
671
+ statusCode: result.status,
672
+ statusMessage: result.statusText,
673
+ };
674
+ }
675
+ return result.data;
676
+ }
677
+ function applyPaginationRequestData(requestData, paginationRequestData) {
678
+ const preparedPaginationData = {
679
+ ...paginationRequestData,
680
+ uri: paginationRequestData.url,
681
+ };
682
+ if ('formData' in requestData) {
683
+ preparedPaginationData.formData = paginationRequestData.body;
684
+ delete preparedPaginationData.body;
685
+ }
686
+ else if ('form' in requestData) {
687
+ preparedPaginationData.form = paginationRequestData.body;
688
+ delete preparedPaginationData.body;
689
+ }
690
+ return (0, merge_1.default)({}, requestData, preparedPaginationData);
691
+ }
692
+ function createOAuth2Client(credentials) {
693
+ return new client_oauth2_1.ClientOAuth2({
694
+ clientId: credentials.clientId,
695
+ clientSecret: credentials.clientSecret,
696
+ accessTokenUri: credentials.accessTokenUrl,
697
+ scopes: (credentials.scope ?? '').split(' '),
698
+ ignoreSSLIssues: credentials.ignoreSSLIssues,
699
+ authentication: credentials.authentication ?? 'header',
700
+ ...(credentials.additionalBodyProperties && {
701
+ additionalBodyProperties: (0, n8n_workflow_1.jsonParse)(credentials.additionalBodyProperties, {
702
+ fallbackValue: {},
703
+ }),
704
+ }),
705
+ });
706
+ }
707
+ async function requestOAuth2(credentialsType, requestOptions, node, additionalData, oAuth2Options, isN8nRequest = false) {
708
+ (0, exports.removeEmptyBody)(requestOptions);
709
+ const credentials = (await this.getCredentials(credentialsType));
710
+ if (credentials.grantType === 'authorizationCode' && credentials.oauthTokenData === undefined) {
711
+ throw new n8n_workflow_1.ApplicationError('OAuth credentials not connected');
712
+ }
713
+ const oAuthClient = createOAuth2Client(credentials);
714
+ let oauthTokenData = credentials.oauthTokenData;
715
+ if (credentials.grantType === 'clientCredentials' &&
716
+ (oauthTokenData === undefined ||
717
+ Object.keys(oauthTokenData).length === 0 ||
718
+ oauthTokenData.access_token === '')) {
719
+ const { data } = await oAuthClient.credentials.getToken();
720
+ if (!node.credentials?.[credentialsType]) {
721
+ throw new n8n_workflow_1.ApplicationError('Node does not have credential type', {
722
+ extra: { nodeName: node.name },
723
+ tags: { credentialType: credentialsType },
724
+ });
725
+ }
726
+ const nodeCredentials = node.credentials[credentialsType];
727
+ credentials.oauthTokenData = data;
728
+ await additionalData.credentialsHelper.updateCredentialsOauthTokenData(nodeCredentials, credentialsType, credentials, additionalData);
729
+ oauthTokenData = data;
730
+ }
731
+ const accessToken = (0, get_1.default)(oauthTokenData, oAuth2Options?.property) || oauthTokenData.accessToken;
732
+ const refreshToken = oauthTokenData.refreshToken;
733
+ const token = oAuthClient.createToken({
734
+ ...oauthTokenData,
735
+ ...(accessToken ? { access_token: accessToken } : {}),
736
+ ...(refreshToken ? { refresh_token: refreshToken } : {}),
737
+ }, oAuth2Options?.tokenType || oauthTokenData.tokenType);
738
+ requestOptions.rejectUnauthorized = !credentials.ignoreSSLIssues;
739
+ const newRequestOptions = token.sign(requestOptions);
740
+ const newRequestHeaders = (newRequestOptions.headers = newRequestOptions.headers ?? {});
741
+ if (oAuth2Options?.keepBearer === false && typeof newRequestHeaders.Authorization === 'string') {
742
+ newRequestHeaders.Authorization = newRequestHeaders.Authorization.split(' ')[1];
743
+ }
744
+ if (oAuth2Options?.keyToIncludeInAccessTokenHeader) {
745
+ Object.assign(newRequestHeaders, {
746
+ [oAuth2Options.keyToIncludeInAccessTokenHeader]: token.accessToken,
747
+ });
748
+ }
749
+ if (isN8nRequest) {
750
+ return await this.helpers.httpRequest(newRequestOptions).catch(async (error) => {
751
+ if (error.response?.status === 401) {
752
+ this.logger.debug(`OAuth2 token for "${credentialsType}" used by node "${node.name}" expired. Should revalidate.`);
753
+ const tokenRefreshOptions = {};
754
+ if (oAuth2Options?.includeCredentialsOnRefreshOnBody) {
755
+ const body = {
756
+ client_id: credentials.clientId,
757
+ ...(credentials.grantType === 'authorizationCode' && {
758
+ client_secret: credentials.clientSecret,
759
+ }),
760
+ };
761
+ tokenRefreshOptions.body = body;
762
+ tokenRefreshOptions.headers = {
763
+ Authorization: '',
764
+ };
765
+ }
766
+ let newToken;
767
+ this.logger.debug(`OAuth2 token for "${credentialsType}" used by node "${node.name}" has been renewed.`);
768
+ if (credentials.grantType === 'clientCredentials') {
769
+ newToken = await token.client.credentials.getToken();
770
+ }
771
+ else {
772
+ newToken = await token.refresh(tokenRefreshOptions);
773
+ }
774
+ this.logger.debug(`OAuth2 token for "${credentialsType}" used by node "${node.name}" has been renewed.`);
775
+ credentials.oauthTokenData = newToken.data;
776
+ if (!node.credentials?.[credentialsType]) {
777
+ throw new n8n_workflow_1.ApplicationError('Node does not have credential type', {
778
+ extra: { nodeName: node.name, credentialType: credentialsType },
779
+ });
780
+ }
781
+ const nodeCredentials = node.credentials[credentialsType];
782
+ await additionalData.credentialsHelper.updateCredentialsOauthTokenData(nodeCredentials, credentialsType, credentials, additionalData);
783
+ const refreshedRequestOption = newToken.sign(requestOptions);
784
+ if (oAuth2Options?.keyToIncludeInAccessTokenHeader) {
785
+ Object.assign(newRequestHeaders, {
786
+ [oAuth2Options.keyToIncludeInAccessTokenHeader]: token.accessToken,
787
+ });
788
+ }
789
+ return await this.helpers.httpRequest(refreshedRequestOption);
790
+ }
791
+ throw error;
792
+ });
793
+ }
794
+ const tokenExpiredStatusCode = oAuth2Options?.tokenExpiredStatusCode === undefined
795
+ ? 401
796
+ : oAuth2Options?.tokenExpiredStatusCode;
797
+ return await this.helpers
798
+ .request(newRequestOptions)
799
+ .then((response) => {
800
+ const requestOptions = newRequestOptions;
801
+ if (requestOptions.resolveWithFullResponse === true &&
802
+ requestOptions.simple === false &&
803
+ response.statusCode === tokenExpiredStatusCode) {
804
+ throw response;
805
+ }
806
+ return response;
807
+ })
808
+ .catch(async (error) => {
809
+ if (error.statusCode === tokenExpiredStatusCode) {
810
+ const tokenRefreshOptions = {};
811
+ if (oAuth2Options?.includeCredentialsOnRefreshOnBody) {
812
+ const body = {
813
+ client_id: credentials.clientId,
814
+ client_secret: credentials.clientSecret,
815
+ };
816
+ tokenRefreshOptions.body = body;
817
+ tokenRefreshOptions.headers = {
818
+ Authorization: '',
819
+ };
820
+ }
821
+ this.logger.debug(`OAuth2 token for "${credentialsType}" used by node "${node.name}" expired. Should revalidate.`);
822
+ let newToken;
823
+ if (credentials.grantType === 'clientCredentials') {
824
+ newToken = await token.client.credentials.getToken();
825
+ }
826
+ else {
827
+ newToken = await token.refresh(tokenRefreshOptions);
828
+ }
829
+ this.logger.debug(`OAuth2 token for "${credentialsType}" used by node "${node.name}" has been renewed.`);
830
+ credentials.oauthTokenData = newToken.data;
831
+ if (!node.credentials?.[credentialsType]) {
832
+ throw new n8n_workflow_1.ApplicationError('Node does not have credential type', {
833
+ tags: { credentialType: credentialsType },
834
+ extra: { nodeName: node.name },
835
+ });
836
+ }
837
+ const nodeCredentials = node.credentials[credentialsType];
838
+ await additionalData.credentialsHelper.updateCredentialsOauthTokenData(nodeCredentials, credentialsType, credentials, additionalData);
839
+ this.logger.debug(`OAuth2 token for "${credentialsType}" used by node "${node.name}" has been saved to database successfully.`);
840
+ const newRequestOptions = newToken.sign(requestOptions);
841
+ newRequestOptions.headers = newRequestOptions.headers ?? {};
842
+ if (oAuth2Options?.keyToIncludeInAccessTokenHeader) {
843
+ Object.assign(newRequestOptions.headers, {
844
+ [oAuth2Options.keyToIncludeInAccessTokenHeader]: token.accessToken,
845
+ });
846
+ }
847
+ return await this.helpers.request(newRequestOptions);
848
+ }
849
+ throw error;
850
+ });
851
+ }
852
+ async function requestOAuth1(credentialsType, requestOptions, isN8nRequest = false) {
853
+ (0, exports.removeEmptyBody)(requestOptions);
854
+ const credentials = await this.getCredentials(credentialsType);
855
+ if (credentials === undefined) {
856
+ throw new n8n_workflow_1.ApplicationError('No credentials were returned');
857
+ }
858
+ if (credentials.oauthTokenData === undefined) {
859
+ throw new n8n_workflow_1.ApplicationError('OAuth credentials not connected');
860
+ }
861
+ const oauth = new oauth_1_0a_1.default({
862
+ consumer: {
863
+ key: credentials.consumerKey,
864
+ secret: credentials.consumerSecret,
865
+ },
866
+ signature_method: credentials.signatureMethod,
867
+ hash_function(base, key) {
868
+ let algorithm;
869
+ switch (credentials.signatureMethod) {
870
+ case 'HMAC-SHA256':
871
+ algorithm = 'sha256';
872
+ break;
873
+ case 'HMAC-SHA512':
874
+ algorithm = 'sha512';
875
+ break;
876
+ default:
877
+ algorithm = 'sha1';
878
+ break;
879
+ }
880
+ return (0, crypto_1.createHmac)(algorithm, key).update(base).digest('base64');
881
+ },
882
+ });
883
+ const oauthTokenData = credentials.oauthTokenData;
884
+ const token = {
885
+ key: oauthTokenData.oauth_token,
886
+ secret: oauthTokenData.oauth_token_secret,
887
+ };
888
+ requestOptions.data = { ...requestOptions.qs, ...requestOptions.form };
889
+ if ('uri' in requestOptions && !requestOptions.url) {
890
+ requestOptions.url = requestOptions.uri;
891
+ delete requestOptions.uri;
892
+ }
893
+ requestOptions.headers = oauth.toHeader(oauth.authorize(requestOptions, token));
894
+ if (isN8nRequest) {
895
+ return await this.helpers.httpRequest(requestOptions);
896
+ }
897
+ return await this.helpers
898
+ .request(requestOptions)
899
+ .catch(async (error) => {
900
+ throw error;
901
+ });
902
+ }
903
+ async function refreshOAuth2Token(credentialsType, node, additionalData, oAuth2Options) {
904
+ const credentials = (await this.getCredentials(credentialsType));
905
+ if (credentials.grantType === 'authorizationCode' && credentials.oauthTokenData === undefined) {
906
+ throw new n8n_workflow_1.ApplicationError('OAuth credentials not connected');
907
+ }
908
+ const oAuthClient = createOAuth2Client(credentials);
909
+ const oauthTokenData = credentials.oauthTokenData;
910
+ const accessToken = (0, get_1.default)(oauthTokenData, oAuth2Options?.property) || oauthTokenData.accessToken;
911
+ const refreshToken = oauthTokenData.refreshToken;
912
+ const token = oAuthClient.createToken({
913
+ ...oauthTokenData,
914
+ ...(accessToken ? { access_token: accessToken } : {}),
915
+ ...(refreshToken ? { refresh_token: refreshToken } : {}),
916
+ }, oAuth2Options?.tokenType || oauthTokenData.tokenType);
917
+ const tokenRefreshOptions = {};
918
+ if (oAuth2Options?.includeCredentialsOnRefreshOnBody) {
919
+ const body = {
920
+ client_id: credentials.clientId,
921
+ ...(credentials.grantType === 'authorizationCode' && {
922
+ client_secret: credentials.clientSecret,
923
+ }),
924
+ };
925
+ tokenRefreshOptions.body = body;
926
+ tokenRefreshOptions.headers = {
927
+ Authorization: '',
928
+ };
929
+ }
930
+ this.logger.debug(`Refreshing the OAuth2 token for "${credentialsType}" used by node "${node.name}".`);
931
+ let newToken;
932
+ if (credentials.grantType === 'clientCredentials') {
933
+ newToken = await token.client.credentials.getToken();
934
+ }
935
+ else {
936
+ newToken = await token.refresh(tokenRefreshOptions);
937
+ }
938
+ this.logger.debug(`OAuth2 token for "${credentialsType}" used by node "${node.name}" has been renewed.`);
939
+ credentials.oauthTokenData = newToken.data;
940
+ if (!node.credentials?.[credentialsType]) {
941
+ throw new n8n_workflow_1.ApplicationError('Node does not have credential type', {
942
+ extra: { nodeName: node.name, credentialType: credentialsType },
943
+ });
944
+ }
945
+ const nodeCredentials = node.credentials[credentialsType];
946
+ await additionalData.credentialsHelper.updateCredentialsOauthTokenData(nodeCredentials, credentialsType, credentials, additionalData);
947
+ this.logger.debug(`OAuth2 token for "${credentialsType}" used by node "${node.name}" has been saved to database successfully.`);
948
+ return newToken.data;
949
+ }
950
+ async function httpRequestWithAuthentication(credentialsType, requestOptions, workflow, node, additionalData, additionalCredentialOptions) {
951
+ (0, exports.removeEmptyBody)(requestOptions);
952
+ if ('getExecutionCancelSignal' in this) {
953
+ requestOptions.abortSignal = this.getExecutionCancelSignal();
954
+ }
955
+ let credentialsDecrypted;
956
+ try {
957
+ const parentTypes = additionalData.credentialsHelper.getParentTypes(credentialsType);
958
+ if (parentTypes.includes('oAuth1Api')) {
959
+ return await requestOAuth1.call(this, credentialsType, requestOptions, true);
960
+ }
961
+ if (parentTypes.includes('oAuth2Api')) {
962
+ return await requestOAuth2.call(this, credentialsType, requestOptions, node, additionalData, additionalCredentialOptions?.oauth2, true);
963
+ }
964
+ if (additionalCredentialOptions?.credentialsDecrypted) {
965
+ credentialsDecrypted = additionalCredentialOptions.credentialsDecrypted.data;
966
+ }
967
+ else {
968
+ credentialsDecrypted =
969
+ await this.getCredentials(credentialsType);
970
+ }
971
+ if (credentialsDecrypted === undefined) {
972
+ throw new n8n_workflow_1.NodeOperationError(node, `Node "${node.name}" does not have any credentials of type "${credentialsType}" set`, { level: 'warning' });
973
+ }
974
+ const data = await additionalData.credentialsHelper.preAuthentication({ helpers: this.helpers }, credentialsDecrypted, credentialsType, node, false);
975
+ if (data) {
976
+ Object.assign(credentialsDecrypted, data);
977
+ }
978
+ requestOptions = await additionalData.credentialsHelper.authenticate(credentialsDecrypted, credentialsType, requestOptions, workflow, node);
979
+ return await httpRequest(requestOptions);
980
+ }
981
+ catch (error) {
982
+ if (error.response?.status === 401 &&
983
+ additionalData.credentialsHelper.preAuthentication !== undefined) {
984
+ try {
985
+ if (credentialsDecrypted !== undefined) {
986
+ const data = await additionalData.credentialsHelper.preAuthentication({ helpers: this.helpers }, credentialsDecrypted, credentialsType, node, true);
987
+ if (data) {
988
+ Object.assign(credentialsDecrypted, data);
989
+ }
990
+ requestOptions = await additionalData.credentialsHelper.authenticate(credentialsDecrypted, credentialsType, requestOptions, workflow, node);
991
+ }
992
+ return await httpRequest(requestOptions);
993
+ }
994
+ catch (error) {
995
+ throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
996
+ }
997
+ }
998
+ throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
999
+ }
1000
+ }
1001
+ async function requestWithAuthentication(credentialsType, requestOptions, workflow, node, additionalData, additionalCredentialOptions, itemIndex) {
1002
+ (0, exports.removeEmptyBody)(requestOptions);
1003
+ let credentialsDecrypted;
1004
+ try {
1005
+ const parentTypes = additionalData.credentialsHelper.getParentTypes(credentialsType);
1006
+ if (credentialsType === 'oAuth1Api' || parentTypes.includes('oAuth1Api')) {
1007
+ return await requestOAuth1.call(this, credentialsType, requestOptions, false);
1008
+ }
1009
+ if (credentialsType === 'oAuth2Api' || parentTypes.includes('oAuth2Api')) {
1010
+ return await requestOAuth2.call(this, credentialsType, requestOptions, node, additionalData, additionalCredentialOptions?.oauth2, false);
1011
+ }
1012
+ if (additionalCredentialOptions?.credentialsDecrypted) {
1013
+ credentialsDecrypted = additionalCredentialOptions.credentialsDecrypted.data;
1014
+ }
1015
+ else {
1016
+ credentialsDecrypted = await this.getCredentials(credentialsType, itemIndex);
1017
+ }
1018
+ if (credentialsDecrypted === undefined) {
1019
+ throw new n8n_workflow_1.NodeOperationError(node, `Node "${node.name}" does not have any credentials of type "${credentialsType}" set`, { level: 'warning' });
1020
+ }
1021
+ const data = await additionalData.credentialsHelper.preAuthentication({ helpers: this.helpers }, credentialsDecrypted, credentialsType, node, false);
1022
+ if (data) {
1023
+ Object.assign(credentialsDecrypted, data);
1024
+ }
1025
+ requestOptions = (await additionalData.credentialsHelper.authenticate(credentialsDecrypted, credentialsType, requestOptions, workflow, node));
1026
+ return await proxyRequestToAxios(workflow, additionalData, node, requestOptions);
1027
+ }
1028
+ catch (error) {
1029
+ try {
1030
+ if (credentialsDecrypted !== undefined) {
1031
+ const data = await additionalData.credentialsHelper.preAuthentication({ helpers: this.helpers }, credentialsDecrypted, credentialsType, node, true);
1032
+ if (data) {
1033
+ Object.assign(credentialsDecrypted, data);
1034
+ requestOptions = (await additionalData.credentialsHelper.authenticate(credentialsDecrypted, credentialsType, requestOptions, workflow, node));
1035
+ return await proxyRequestToAxios(workflow, additionalData, node, requestOptions);
1036
+ }
1037
+ }
1038
+ throw error;
1039
+ }
1040
+ catch (error) {
1041
+ if (error instanceof n8n_workflow_1.ExecutionBaseError)
1042
+ throw error;
1043
+ throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
1044
+ }
1045
+ }
1046
+ }
1047
+ const getRequestHelperFunctions = (workflow, node, additionalData, runExecutionData = null, connectionInputData = []) => {
1048
+ const getResolvedValue = (parameterValue, itemIndex, runIndex, executeData, additionalKeys, returnObjectAsString = false) => {
1049
+ const mode = 'internal';
1050
+ if (typeof parameterValue === 'object' ||
1051
+ (typeof parameterValue === 'string' && parameterValue.charAt(0) === '=')) {
1052
+ return workflow.expression.getParameterValue(parameterValue, runExecutionData, runIndex, itemIndex, node.name, connectionInputData, mode, additionalKeys ?? {}, executeData, returnObjectAsString);
1053
+ }
1054
+ return parameterValue;
1055
+ };
1056
+ async function requestWithAuthenticationPaginated(requestOptions, itemIndex, paginationOptions, credentialsType, additionalCredentialOptions) {
1057
+ const responseData = [];
1058
+ if (!requestOptions.qs) {
1059
+ requestOptions.qs = {};
1060
+ }
1061
+ requestOptions.resolveWithFullResponse = true;
1062
+ requestOptions.simple = false;
1063
+ let tempResponseData;
1064
+ let makeAdditionalRequest;
1065
+ let paginateRequestData;
1066
+ const runIndex = 0;
1067
+ const additionalKeys = {
1068
+ $request: requestOptions,
1069
+ $response: {},
1070
+ $version: node.typeVersion,
1071
+ $pageCount: 0,
1072
+ };
1073
+ const executeData = {
1074
+ data: {},
1075
+ node,
1076
+ source: null,
1077
+ };
1078
+ const hashData = {
1079
+ identicalCount: 0,
1080
+ previousLength: 0,
1081
+ previousHash: '',
1082
+ };
1083
+ do {
1084
+ paginateRequestData = getResolvedValue(paginationOptions.request, itemIndex, runIndex, executeData, additionalKeys, false);
1085
+ const tempRequestOptions = applyPaginationRequestData(requestOptions, paginateRequestData);
1086
+ if (!validateUrl(tempRequestOptions.uri)) {
1087
+ throw new n8n_workflow_1.NodeOperationError(node, `'${paginateRequestData.url}' is not a valid URL.`, {
1088
+ itemIndex,
1089
+ runIndex,
1090
+ type: 'invalid_url',
1091
+ });
1092
+ }
1093
+ if (credentialsType) {
1094
+ tempResponseData = await this.helpers.requestWithAuthentication.call(this, credentialsType, tempRequestOptions, additionalCredentialOptions);
1095
+ }
1096
+ else {
1097
+ tempResponseData = await this.helpers.request(tempRequestOptions);
1098
+ }
1099
+ const newResponse = Object.assign({
1100
+ body: {},
1101
+ headers: {},
1102
+ statusCode: 0,
1103
+ }, (0, pick_1.default)(tempResponseData, ['body', 'headers', 'statusCode']));
1104
+ let contentBody;
1105
+ if (newResponse.body instanceof stream_1.Readable && paginationOptions.binaryResult !== true) {
1106
+ contentBody = await (0, binary_helper_functions_1.binaryToString)(newResponse.body);
1107
+ const responseContentType = newResponse.headers['content-type']?.toString() ?? '';
1108
+ if (responseContentType.includes('application/json')) {
1109
+ newResponse.body = (0, n8n_workflow_1.jsonParse)(contentBody, { fallbackValue: {} });
1110
+ }
1111
+ else {
1112
+ newResponse.body = contentBody;
1113
+ }
1114
+ tempResponseData.__bodyResolved = true;
1115
+ tempResponseData.body = newResponse.body;
1116
+ }
1117
+ else {
1118
+ contentBody = newResponse.body;
1119
+ }
1120
+ if (paginationOptions.binaryResult !== true || tempResponseData.headers.etag) {
1121
+ let contentLength = 0;
1122
+ if ('content-length' in tempResponseData.headers) {
1123
+ contentLength = parseInt(tempResponseData.headers['content-length']) || 0;
1124
+ }
1125
+ if (hashData.previousLength === contentLength) {
1126
+ let hash;
1127
+ if (tempResponseData.headers.etag) {
1128
+ hash = tempResponseData.headers.etag;
1129
+ }
1130
+ else {
1131
+ if (typeof contentBody !== 'string') {
1132
+ contentBody = JSON.stringify(contentBody);
1133
+ }
1134
+ hash = crypto_1.default.createHash('md5').update(contentBody).digest('base64');
1135
+ }
1136
+ if (hashData.previousHash === hash) {
1137
+ hashData.identicalCount += 1;
1138
+ if (hashData.identicalCount > 2) {
1139
+ throw new n8n_workflow_1.NodeOperationError(node, 'The returned response was identical 5x, so requests got stopped', {
1140
+ itemIndex,
1141
+ description: 'Check if "Pagination Completed When" has been configured correctly.',
1142
+ });
1143
+ }
1144
+ }
1145
+ else {
1146
+ hashData.identicalCount = 0;
1147
+ }
1148
+ hashData.previousHash = hash;
1149
+ }
1150
+ else {
1151
+ hashData.identicalCount = 0;
1152
+ }
1153
+ hashData.previousLength = contentLength;
1154
+ }
1155
+ responseData.push(tempResponseData);
1156
+ additionalKeys.$response = newResponse;
1157
+ additionalKeys.$pageCount = (additionalKeys.$pageCount ?? 0) + 1;
1158
+ const maxRequests = getResolvedValue(paginationOptions.maxRequests, itemIndex, runIndex, executeData, additionalKeys, false);
1159
+ if (maxRequests && additionalKeys.$pageCount >= maxRequests) {
1160
+ break;
1161
+ }
1162
+ makeAdditionalRequest = getResolvedValue(paginationOptions.continue, itemIndex, runIndex, executeData, additionalKeys, false);
1163
+ if (makeAdditionalRequest) {
1164
+ if (paginationOptions.requestInterval) {
1165
+ const requestInterval = getResolvedValue(paginationOptions.requestInterval, itemIndex, runIndex, executeData, additionalKeys, false);
1166
+ await (0, n8n_workflow_1.sleep)(requestInterval);
1167
+ }
1168
+ if (tempResponseData.statusCode < 200 || tempResponseData.statusCode >= 300) {
1169
+ let data = tempResponseData.body;
1170
+ if (data instanceof stream_1.Readable && paginationOptions.binaryResult !== true) {
1171
+ data = await (0, binary_helper_functions_1.binaryToString)(data);
1172
+ }
1173
+ else if (typeof data === 'object') {
1174
+ data = JSON.stringify(data);
1175
+ }
1176
+ throw Object.assign(new Error(`${tempResponseData.statusCode} - "${data?.toString()}"`), {
1177
+ statusCode: tempResponseData.statusCode,
1178
+ error: data,
1179
+ isAxiosError: true,
1180
+ response: {
1181
+ headers: tempResponseData.headers,
1182
+ status: tempResponseData.statusCode,
1183
+ statusText: tempResponseData.statusMessage,
1184
+ },
1185
+ });
1186
+ }
1187
+ }
1188
+ } while (makeAdditionalRequest);
1189
+ return responseData;
1190
+ }
1191
+ return {
1192
+ httpRequest,
1193
+ requestWithAuthenticationPaginated,
1194
+ async httpRequestWithAuthentication(credentialsType, requestOptions, additionalCredentialOptions) {
1195
+ return await httpRequestWithAuthentication.call(this, credentialsType, requestOptions, workflow, node, additionalData, additionalCredentialOptions);
1196
+ },
1197
+ async refreshOAuth2Token(credentialsType, oAuth2Options) {
1198
+ return await refreshOAuth2Token.call(this, credentialsType, node, additionalData, oAuth2Options);
1199
+ },
1200
+ request: async (uriOrObject, options) => await proxyRequestToAxios(workflow, additionalData, node, uriOrObject, options),
1201
+ async requestWithAuthentication(credentialsType, requestOptions, additionalCredentialOptions, itemIndex) {
1202
+ return await requestWithAuthentication.call(this, credentialsType, requestOptions, workflow, node, additionalData, additionalCredentialOptions, itemIndex);
1203
+ },
1204
+ async requestOAuth1(credentialsType, requestOptions) {
1205
+ return await requestOAuth1.call(this, credentialsType, requestOptions);
1206
+ },
1207
+ async requestOAuth2(credentialsType, requestOptions, oAuth2Options) {
1208
+ return await requestOAuth2.call(this, credentialsType, requestOptions, node, additionalData, oAuth2Options);
1209
+ },
1210
+ };
1211
+ };
1212
+ exports.getRequestHelperFunctions = getRequestHelperFunctions;
1213
+ //# sourceMappingURL=request-helper-functions.js.map