n8n-core 1.21.1 → 1.22.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.
@@ -43,5 +43,5 @@ export declare function getExecuteFunctions(workflow: Workflow, runExecutionData
43
43
  export declare function getExecuteSingleFunctions(workflow: Workflow, runExecutionData: IRunExecutionData, runIndex: number, connectionInputData: INodeExecutionData[], inputData: ITaskDataConnections, node: INode, itemIndex: number, additionalData: IWorkflowExecuteAdditionalData, executeData: IExecuteData, mode: WorkflowExecuteMode, abortSignal?: AbortSignal): IExecuteSingleFunctions;
44
44
  export declare function getCredentialTestFunctions(): ICredentialTestFunctions;
45
45
  export declare function getLoadOptionsFunctions(workflow: Workflow, node: INode, path: string, additionalData: IWorkflowExecuteAdditionalData): ILoadOptionsFunctions;
46
- export declare function getExecuteHookFunctions(workflow: Workflow, node: INode, additionalData: IWorkflowExecuteAdditionalData, mode: WorkflowExecuteMode, activation: WorkflowActivateMode, isTest?: boolean, webhookData?: IWebhookData): IHookFunctions;
46
+ export declare function getExecuteHookFunctions(workflow: Workflow, node: INode, additionalData: IWorkflowExecuteAdditionalData, mode: WorkflowExecuteMode, activation: WorkflowActivateMode, webhookData?: IWebhookData): IHookFunctions;
47
47
  export declare function getExecuteWebhookFunctions(workflow: Workflow, node: INode, additionalData: IWorkflowExecuteAdditionalData, mode: WorkflowExecuteMode, webhookData: IWebhookData): IWebhookFunctions;
@@ -64,6 +64,12 @@ axios_1.default.defaults.paramsSerializer = (params) => {
64
64
  }
65
65
  return (0, qs_1.stringify)(params, { arrayFormat: 'indices' });
66
66
  };
67
+ axios_1.default.interceptors.request.use((config) => {
68
+ if (config.data === undefined) {
69
+ config.headers.setContentType(false, false);
70
+ }
71
+ return config;
72
+ });
67
73
  const pushFormDataValue = (form, key, value) => {
68
74
  if ((value === null || value === void 0 ? void 0 : value.hasOwnProperty('value')) && value.hasOwnProperty('options')) {
69
75
  form.append(key, value.value, value.options);
@@ -88,21 +94,21 @@ const createFormDataObject = (data) => {
88
94
  });
89
95
  return formData;
90
96
  };
91
- function searchForHeader(headers, headerName) {
92
- if (headers === undefined) {
97
+ function searchForHeader(config, headerName) {
98
+ if (config.headers === undefined) {
93
99
  return undefined;
94
100
  }
95
- const headerNames = Object.keys(headers);
101
+ const headerNames = Object.keys(config.headers);
96
102
  headerName = headerName.toLowerCase();
97
103
  return headerNames.find((thisHeader) => thisHeader.toLowerCase() === headerName);
98
104
  }
99
- async function generateContentLengthHeader(formData, headers) {
100
- if (!(formData === null || formData === void 0 ? void 0 : formData.getLength)) {
105
+ async function generateContentLengthHeader(config) {
106
+ if (!(config.data instanceof form_data_1.default)) {
101
107
  return;
102
108
  }
103
109
  try {
104
110
  const length = await new Promise((res, rej) => {
105
- formData.getLength((error, length) => {
111
+ config.data.getLength((error, length) => {
106
112
  if (error) {
107
113
  rej(error);
108
114
  return;
@@ -110,16 +116,17 @@ async function generateContentLengthHeader(formData, headers) {
110
116
  res(length);
111
117
  });
112
118
  });
113
- headers = Object.assign(headers, {
119
+ config.headers = {
120
+ ...config.headers,
114
121
  'content-length': length,
115
- });
122
+ };
116
123
  }
117
124
  catch (error) {
118
125
  n8n_workflow_1.LoggerProxy.error('Unable to calculate form data length', { error });
119
126
  }
120
127
  }
121
128
  async function parseRequestObject(requestObject) {
122
- var _a, _b, _c;
129
+ var _a, _b, _c, _d, _e;
123
130
  const axiosConfig = {};
124
131
  if (requestObject.headers !== undefined) {
125
132
  axiosConfig.headers = requestObject.headers;
@@ -127,7 +134,7 @@ async function parseRequestObject(requestObject) {
127
134
  const contentTypeHeaderKeyName = axiosConfig.headers &&
128
135
  Object.keys(axiosConfig.headers).find((headerName) => headerName.toLowerCase() === 'content-type');
129
136
  const contentType = contentTypeHeaderKeyName &&
130
- axiosConfig.headers[contentTypeHeaderKeyName];
137
+ ((_a = axiosConfig.headers) === null || _a === void 0 ? void 0 : _a[contentTypeHeaderKeyName]);
131
138
  if (contentType === 'application/x-www-form-urlencoded' && requestObject.formData === undefined) {
132
139
  if (typeof requestObject.body === 'string') {
133
140
  axiosConfig.data = requestObject.body;
@@ -142,7 +149,7 @@ async function parseRequestObject(requestObject) {
142
149
  }
143
150
  }
144
151
  }
145
- else if (contentType && contentType.includes('multipart/form-data') !== false) {
152
+ else if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('multipart/form-data')) {
146
153
  if (requestObject.formData !== undefined && requestObject.formData instanceof form_data_1.default) {
147
154
  axiosConfig.data = requestObject.formData;
148
155
  }
@@ -153,10 +160,10 @@ async function parseRequestObject(requestObject) {
153
160
  };
154
161
  axiosConfig.data = createFormDataObject(allData);
155
162
  }
156
- delete axiosConfig.headers[contentTypeHeaderKeyName];
163
+ (_b = axiosConfig.headers) === null || _b === void 0 ? true : delete _b[contentTypeHeaderKeyName];
157
164
  const headers = axiosConfig.data.getHeaders();
158
165
  axiosConfig.headers = Object.assign(axiosConfig.headers || {}, headers);
159
- await generateContentLengthHeader(axiosConfig.data, axiosConfig.headers);
166
+ await generateContentLengthHeader(axiosConfig);
160
167
  }
161
168
  else {
162
169
  if (requestObject.form !== undefined && requestObject.body === undefined) {
@@ -165,7 +172,7 @@ async function parseRequestObject(requestObject) {
165
172
  ? (0, qs_1.stringify)(requestObject.form, { format: 'RFC3986' })
166
173
  : (0, qs_1.stringify)(requestObject.form).toString();
167
174
  if (axiosConfig.headers !== undefined) {
168
- const headerName = searchForHeader(axiosConfig.headers, 'content-type');
175
+ const headerName = searchForHeader(axiosConfig, 'content-type');
169
176
  if (headerName) {
170
177
  delete axiosConfig.headers[headerName];
171
178
  }
@@ -180,7 +187,12 @@ async function parseRequestObject(requestObject) {
180
187
  else if (requestObject.formData !== undefined) {
181
188
  if (axiosConfig.headers !== undefined) {
182
189
  const headers = Object.keys(axiosConfig.headers);
183
- headers.forEach((header) => header.toLowerCase() === 'content-type' ? delete axiosConfig.headers[header] : null);
190
+ headers.forEach((header) => {
191
+ var _a;
192
+ if (header.toLowerCase() === 'content-type') {
193
+ (_a = axiosConfig.headers) === null || _a === void 0 ? true : delete _a[header];
194
+ }
195
+ });
184
196
  }
185
197
  if (requestObject.formData instanceof form_data_1.default) {
186
198
  axiosConfig.data = requestObject.formData;
@@ -190,7 +202,7 @@ async function parseRequestObject(requestObject) {
190
202
  }
191
203
  const headers = axiosConfig.data.getHeaders();
192
204
  axiosConfig.headers = Object.assign(axiosConfig.headers || {}, headers);
193
- await generateContentLengthHeader(axiosConfig.data, axiosConfig.headers);
205
+ await generateContentLengthHeader(axiosConfig);
194
206
  }
195
207
  else if (requestObject.body !== undefined) {
196
208
  if (requestObject.form !== undefined && requestObject.body) {
@@ -200,13 +212,13 @@ async function parseRequestObject(requestObject) {
200
212
  }
201
213
  }
202
214
  if (requestObject.uri !== undefined) {
203
- axiosConfig.url = (_a = requestObject.uri) === null || _a === void 0 ? void 0 : _a.toString();
215
+ axiosConfig.url = (_c = requestObject.uri) === null || _c === void 0 ? void 0 : _c.toString();
204
216
  }
205
217
  if (requestObject.url !== undefined) {
206
- axiosConfig.url = (_b = requestObject.url) === null || _b === void 0 ? void 0 : _b.toString();
218
+ axiosConfig.url = (_d = requestObject.url) === null || _d === void 0 ? void 0 : _d.toString();
207
219
  }
208
220
  if (requestObject.baseURL !== undefined) {
209
- axiosConfig.baseURL = (_c = requestObject.baseURL) === null || _c === void 0 ? void 0 : _c.toString();
221
+ axiosConfig.baseURL = (_e = requestObject.baseURL) === null || _e === void 0 ? void 0 : _e.toString();
210
222
  }
211
223
  if (requestObject.method !== undefined) {
212
224
  axiosConfig.method = requestObject.method;
@@ -524,7 +536,7 @@ async function proxyRequestToAxios(workflow, additionalData, node, uriOrObject,
524
536
  return configObject.resolveWithFullResponse
525
537
  ? {
526
538
  body,
527
- headers: response.headers,
539
+ headers: { ...response.headers },
528
540
  statusCode: response.status,
529
541
  statusMessage: response.statusText,
530
542
  request: response.request,
@@ -573,6 +585,7 @@ async function proxyRequestToAxios(workflow, additionalData, node, uriOrObject,
573
585
  }
574
586
  exports.proxyRequestToAxios = proxyRequestToAxios;
575
587
  function convertN8nRequestToAxios(n8nRequest) {
588
+ var _a;
576
589
  const { headers, method, timeout, auth, proxy, url } = n8nRequest;
577
590
  const axiosRequest = {
578
591
  headers: headers !== null && headers !== void 0 ? headers : {},
@@ -606,7 +619,7 @@ function convertN8nRequestToAxios(n8nRequest) {
606
619
  }
607
620
  const { body } = n8nRequest;
608
621
  if (body) {
609
- const existingContentTypeHeaderKey = searchForHeader(axiosRequest.headers, 'content-type');
622
+ const existingContentTypeHeaderKey = searchForHeader(axiosRequest, 'content-type');
610
623
  if (existingContentTypeHeaderKey === undefined) {
611
624
  axiosRequest.headers = axiosRequest.headers || {};
612
625
  if (body instanceof form_data_1.default) {
@@ -619,7 +632,7 @@ function convertN8nRequestToAxios(n8nRequest) {
619
632
  axiosRequest.headers['Content-Type'] = 'application/x-www-form-urlencoded';
620
633
  }
621
634
  }
622
- else if (axiosRequest.headers[existingContentTypeHeaderKey] === 'application/x-www-form-urlencoded') {
635
+ else if (((_a = axiosRequest.headers) === null || _a === void 0 ? void 0 : _a[existingContentTypeHeaderKey]) === 'application/x-www-form-urlencoded') {
623
636
  axiosRequest.data = new url_1.URLSearchParams(n8nRequest.body);
624
637
  }
625
638
  if (typeof body === 'string' || (typeof body === 'object' && !(0, n8n_workflow_1.isObjectEmpty)(body))) {
@@ -627,14 +640,20 @@ function convertN8nRequestToAxios(n8nRequest) {
627
640
  }
628
641
  }
629
642
  if (n8nRequest.json) {
630
- const key = searchForHeader(axiosRequest.headers, 'accept');
643
+ const key = searchForHeader(axiosRequest, 'accept');
631
644
  if (!key) {
632
- axiosRequest.headers.Accept = 'application/json';
645
+ axiosRequest.headers = {
646
+ ...axiosRequest.headers,
647
+ Accept: 'application/json',
648
+ };
633
649
  }
634
650
  }
635
- const userAgentHeader = searchForHeader(axiosRequest.headers, 'user-agent');
651
+ const userAgentHeader = searchForHeader(axiosRequest, 'user-agent');
636
652
  if (!userAgentHeader) {
637
- axiosRequest.headers['User-Agent'] = 'n8n';
653
+ axiosRequest.headers = {
654
+ ...axiosRequest.headers,
655
+ 'User-Agent': 'n8n',
656
+ };
638
657
  }
639
658
  if (n8nRequest.ignoreHttpStatusErrors) {
640
659
  axiosRequest.validateStatus = () => true;
@@ -2271,7 +2290,7 @@ function getLoadOptionsFunctions(workflow, node, path, additionalData) {
2271
2290
  })(workflow, node, path);
2272
2291
  }
2273
2292
  exports.getLoadOptionsFunctions = getLoadOptionsFunctions;
2274
- function getExecuteHookFunctions(workflow, node, additionalData, mode, activation, isTest, webhookData) {
2293
+ function getExecuteHookFunctions(workflow, node, additionalData, mode, activation, webhookData) {
2275
2294
  return ((workflow, node) => {
2276
2295
  return {
2277
2296
  ...getCommonWorkflowFunctions(workflow, node, additionalData),
@@ -2286,7 +2305,7 @@ function getExecuteHookFunctions(workflow, node, additionalData, mode, activatio
2286
2305
  return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, mode, getAdditionalKeys(additionalData, mode, runExecutionData), undefined, fallbackValue, options);
2287
2306
  },
2288
2307
  getNodeWebhookUrl: (name) => {
2289
- return getNodeWebhookUrl(name, workflow, node, additionalData, mode, getAdditionalKeys(additionalData, mode, null), isTest);
2308
+ return getNodeWebhookUrl(name, workflow, node, additionalData, mode, getAdditionalKeys(additionalData, mode, null), webhookData === null || webhookData === void 0 ? void 0 : webhookData.isTest);
2290
2309
  },
2291
2310
  getWebhookName() {
2292
2311
  if (webhookData === undefined) {