fix(HTTP Request Node): Support for dot notation in JSON body

This commit is contained in:
Michael Kret
2023-03-31 19:31:03 +03:00
committed by GitHub
parent d87736103d
commit b29cf9a249
4 changed files with 82 additions and 7 deletions

View File

@@ -1,6 +1,10 @@
import type { IDataObject, INodeExecutionData, IOAuth2Options } from 'n8n-workflow';
import type { OptionsWithUri } from 'request-promise-native';
import set from 'lodash.set';
export type BodyParameter = { name: string; value: string };
export type IAuthDataSanitizeKeys = {
[key: string]: string[];
};
@@ -130,3 +134,25 @@ export const binaryContentTypes = [
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/x-7z-compressed',
];
export type BodyParametersReducer = (
acc: IDataObject,
cur: { name: string; value: string },
) => IDataObject;
export const prepareRequestBody = (
parameters: BodyParameter[],
bodyType: string,
version: number,
defaultReducer: BodyParametersReducer,
) => {
if (bodyType === 'json' && version >= 4) {
return parameters.reduce((acc, entry) => {
const value = entry.value;
set(acc, entry.name, value);
return acc;
}, {} as IDataObject);
} else {
return parameters.reduce(defaultReducer, {});
}
};