Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partially override request options types #3739

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 29 additions & 32 deletions packages/workflow/src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,31 @@ export interface IAuthenticateRuleResponseSuccessBody extends IAuthenticateRuleB
};
}

export type IHttpRequestOptionsFromProperties = Omit<
IHttpRequestOptions,
'skipSslCertificateValidation'
> & {
skipSslCertificateValidation?: string | boolean;
};
type Override<A extends object, B extends object> = Omit<A, keyof B> & B;

export namespace ParamBased {
export type HttpRequestOptions = Override<
IHttpRequestOptions,
{ skipSslCertificateValidation?: string | boolean; url?: string }
>;

export type RequestOptions = {
maxResults?: number | string;
options: HttpRequestOptions;
paginate?: boolean | string;
preSend: PreSendAction[];
postReceive: Array<{
data: {
parameterValue: string | IDataObject | undefined;
};
actions: PostReceiveAction[];
}>;
requestOperations?: IN8nRequestOperations;
};
}

export interface ICredentialTestRequest {
request: IHttpRequestOptionsFromProperties;
request: ParamBased.HttpRequestOptions;
rules?: IAuthenticateRuleResponseCode[] | IAuthenticateRuleResponseSuccessBody[];
}

Expand Down Expand Up @@ -479,7 +496,7 @@ export interface IN8nRequestOperations {
| IN8nRequestOperationPaginationOffset
| ((
this: IExecutePaginationFunctions,
requestOptions: IRequestOptionsFromParameters,
requestOptions: ParamBased.RequestOptions,
) => Promise<INodeExecutionData[]>);
}

Expand Down Expand Up @@ -592,7 +609,7 @@ export interface IExecuteSingleFunctions {
export interface IExecutePaginationFunctions extends IExecuteSingleFunctions {
makeRoutingRequest(
this: IAllExecuteFunctions,
requestOptions: IRequestOptionsFromParameters,
requestOptions: ParamBased.RequestOptions,
): Promise<INodeExecutionData[]>;
}
export interface IExecuteWorkflowInfo {
Expand Down Expand Up @@ -881,7 +898,7 @@ export interface ILoadOptions {
routing?: {
operations?: IN8nRequestOperations;
output?: INodeRequestOutput;
request?: IHttpRequestOptionsFromParameters;
request?: ParamBased.HttpRequestOptions;
};
}

Expand Down Expand Up @@ -1060,7 +1077,7 @@ export interface INodeTypeBaseDescription {
export interface INodePropertyRouting {
operations?: IN8nRequestOperations; // Should be changed, does not sound right
output?: INodeRequestOutput;
request?: IHttpRequestOptionsFromParameters;
request?: ParamBased.HttpRequestOptions;
send?: INodeRequestSend;
}

Expand Down Expand Up @@ -1138,26 +1155,6 @@ export interface IPostReceiveSort extends IPostReceiveBase {
};
}

export interface IHttpRequestOptionsFromParameters
extends Partial<IHttpRequestOptionsFromProperties> {
url?: string;
skipSslCertificateValidation?: boolean | string;
}

export interface IRequestOptionsFromParameters {
maxResults?: number | string;
options: IHttpRequestOptionsFromParameters;
paginate?: boolean | string;
preSend: PreSendAction[];
postReceive: Array<{
data: {
parameterValue: string | IDataObject | undefined;
};
actions: PostReceiveAction[];
}>;
requestOperations?: IN8nRequestOperations;
}

export interface INodeTypeDescription extends INodeTypeBaseDescription {
version: number | number[];
defaults: INodeParameters;
Expand All @@ -1171,7 +1168,7 @@ export interface INodeTypeDescription extends INodeTypeBaseDescription {
credentials?: INodeCredentialDescription[];
maxNodes?: number; // How many nodes of that type can be created in a workflow
polling?: boolean;
requestDefaults?: IHttpRequestOptionsFromParameters;
requestDefaults?: ParamBased.HttpRequestOptions;
requestOperations?: IN8nRequestOperations;
hooks?: {
[key: string]: INodeHookDescription[] | undefined;
Expand Down
18 changes: 9 additions & 9 deletions packages/workflow/src/RoutingNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
INodeParameters,
INodePropertyOptions,
INodeType,
IRequestOptionsFromParameters,
ParamBased,
IRunExecutionData,
ITaskDataConnections,
IWorkflowDataProxyAdditionalKeys,
Expand Down Expand Up @@ -127,7 +127,7 @@ export class RoutingNode {
executeData,
this.mode,
);
const requestData: IRequestOptionsFromParameters = {
const requestData: ParamBased.RequestOptions = {
options: {
qs: {},
body: {},
Expand Down Expand Up @@ -214,8 +214,8 @@ export class RoutingNode {
}

mergeOptions(
destinationOptions: IRequestOptionsFromParameters,
sourceOptions?: IRequestOptionsFromParameters,
destinationOptions: ParamBased.RequestOptions,
sourceOptions?: ParamBased.RequestOptions,
): void {
if (sourceOptions) {
destinationOptions.paginate = destinationOptions.paginate ?? sourceOptions.paginate;
Expand Down Expand Up @@ -375,7 +375,7 @@ export class RoutingNode {

async rawRoutingRequest(
executeSingleFunctions: IExecuteSingleFunctions,
requestData: IRequestOptionsFromParameters,
requestData: ParamBased.RequestOptions,
itemIndex: number,
runIndex: number,
credentialType?: string,
Expand Down Expand Up @@ -434,7 +434,7 @@ export class RoutingNode {
}

async makeRoutingRequest(
requestData: IRequestOptionsFromParameters,
requestData: ParamBased.RequestOptions,
executeSingleFunctions: IExecuteSingleFunctions,
itemIndex: number,
runIndex: number,
Expand All @@ -452,7 +452,7 @@ export class RoutingNode {

const executePaginationFunctions = {
...executeSingleFunctions,
makeRoutingRequest: async (requestOptions: IRequestOptionsFromParameters) => {
makeRoutingRequest: async (requestOptions: ParamBased.RequestOptions) => {
return this.rawRoutingRequest(
executeSingleFunctions,
requestOptions,
Expand Down Expand Up @@ -591,8 +591,8 @@ export class RoutingNode {
runIndex: number,
path: string,
additionalKeys?: IWorkflowDataProxyAdditionalKeys,
): IRequestOptionsFromParameters | undefined {
const returnData: IRequestOptionsFromParameters = {
): ParamBased.RequestOptions | undefined {
const returnData: ParamBased.RequestOptions = {
options: {
qs: {},
body: {},
Expand Down
4 changes: 2 additions & 2 deletions packages/workflow/test/RoutingNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
INode,
INodeExecutionData,
INodeParameters,
IRequestOptionsFromParameters,
ParamBased,
IRunExecutionData,
RoutingNode,
Workflow,
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('RoutingNode', () => {
nodeParameters: INodeParameters;
nodeTypeProperties: INodeProperties;
};
output: IRequestOptionsFromParameters | undefined;
output: ParamBased.RequestOptions | undefined;
}> = [
{
description: 'single parameter, only send defined, fixed value',
Expand Down