refactor: Improve typings for webhook methods (no-changelog) (#5713)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2023-03-17 12:25:31 +01:00 committed by GitHub
parent a28396ee91
commit 6a8c9b7ccc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 10 additions and 68 deletions

View file

@ -110,7 +110,6 @@ export class ActiveCampaignTrigger implements INodeType {
}, },
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -114,7 +114,6 @@ export class AcuitySchedulingTrigger implements INodeType {
], ],
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -152,7 +152,6 @@ export class AffinityTrigger implements INodeType {
], ],
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -112,7 +112,6 @@ export class AsanaTrigger implements INodeType {
}, },
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -80,7 +80,6 @@ export class AutopilotTrigger implements INodeType {
], ],
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -248,7 +248,6 @@ export class BitbucketTrigger implements INodeType {
}, },
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -256,7 +256,6 @@ export class BoxTrigger implements INodeType {
], ],
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -80,7 +80,6 @@ export class CalendlyTrigger implements INodeType {
], ],
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -490,7 +490,6 @@ export class CiscoWebexTrigger implements INodeType {
], ],
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -260,7 +260,6 @@ export class ClickUpTrigger implements INodeType {
}, },
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -237,7 +237,6 @@ export class ConvertKitTrigger implements INodeType {
}, },
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -100,7 +100,6 @@ export class CopperTrigger implements INodeType {
], ],
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -219,7 +219,6 @@ export class CustomerIoTrigger implements INodeType {
], ],
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -226,7 +226,6 @@ export class EventbriteTrigger implements INodeType {
}, },
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -170,7 +170,6 @@ export class FacebookTrigger implements INodeType {
}, },
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -92,7 +92,6 @@ export class FigmaTrigger implements INodeType {
], ],
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -91,7 +91,6 @@ export class FlowTrigger implements INodeType {
], ],
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -121,7 +121,6 @@ export class FormIoTrigger implements INodeType {
}, },
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -98,7 +98,6 @@ export class FormstackTrigger implements INodeType {
}, },
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -155,7 +155,6 @@ export class GetResponseTrigger implements INodeType {
}, },
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -174,7 +174,6 @@ export class GitlabTrigger implements INodeType {
], ],
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -83,7 +83,6 @@ export class GumroadTrigger implements INodeType {
], ],
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -99,7 +99,6 @@ export class HelpScoutTrigger implements INodeType {
], ],
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -287,7 +287,6 @@ export class HubspotTrigger implements INodeType {
}, },
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -116,7 +116,6 @@ export class InvoiceNinjaTrigger implements INodeType {
], ],
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -102,7 +102,6 @@ export class JotFormTrigger implements INodeType {
}, },
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -85,7 +85,6 @@ export class KeapTrigger implements INodeType {
}, },
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -89,7 +89,6 @@ export class LemlistTrigger implements INodeType {
}, },
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -123,7 +123,6 @@ export class LinearTrigger implements INodeType {
}, },
}; };
//@ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -183,7 +183,6 @@ export class MailchimpTrigger implements INodeType {
}, },
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -106,7 +106,6 @@ export class MailerLiteTrigger implements INodeType {
], ],
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -74,7 +74,6 @@ export class MailjetTrigger implements INodeType {
], ],
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -125,7 +125,6 @@ export class MauticTrigger implements INodeType {
}, },
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -48,7 +48,6 @@ export class PushcutTrigger implements INodeType {
], ],
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -201,7 +201,6 @@ export class SendInBlueTrigger implements INodeType {
], ],
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -119,7 +119,6 @@ export class StravaTrigger implements INodeType {
], ],
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -142,7 +142,6 @@ export class TaigaTrigger implements INodeType {
}, },
}; };
// @ts-ignore
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -32,7 +32,6 @@ export class TheHiveTrigger implements INodeType {
properties: [...eventsDescription], properties: [...eventsDescription],
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -56,7 +56,6 @@ export class TrelloTrigger implements INodeType {
], ],
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -153,7 +153,6 @@ export class TypeformTrigger implements INodeType {
}, },
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -121,7 +121,6 @@ export class WorkableTrigger implements INodeType {
}, },
}; };
// @ts-ignore (because of request)
webhookMethods = { webhookMethods = {
default: { default: {
async checkExists(this: IHookFunctions): Promise<boolean> { async checkExists(this: IHookFunctions): Promise<boolean> {

View file

@ -1163,6 +1163,8 @@ export interface ITriggerResponse {
manualTriggerResponse?: Promise<INodeExecutionData[][]>; manualTriggerResponse?: Promise<INodeExecutionData[][]>;
} }
export type WebhookSetupMethodNames = 'checkExists' | 'create' | 'delete';
export interface INodeType { export interface INodeType {
description: INodeTypeDescription; description: INodeTypeDescription;
execute?( execute?(
@ -1172,9 +1174,6 @@ export interface INodeType {
poll?(this: IPollFunctions): Promise<INodeExecutionData[][] | null>; poll?(this: IPollFunctions): Promise<INodeExecutionData[][] | null>;
trigger?(this: ITriggerFunctions): Promise<ITriggerResponse | undefined>; trigger?(this: ITriggerFunctions): Promise<ITriggerResponse | undefined>;
webhook?(this: IWebhookFunctions): Promise<IWebhookResponseData>; webhook?(this: IWebhookFunctions): Promise<IWebhookResponseData>;
hooks?: {
[key: string]: (this: IHookFunctions) => Promise<boolean>;
};
methods?: { methods?: {
loadOptions?: { loadOptions?: {
[key: string]: (this: ILoadOptionsFunctions) => Promise<INodePropertyOptions[]>; [key: string]: (this: ILoadOptionsFunctions) => Promise<INodePropertyOptions[]>;
@ -1192,7 +1191,9 @@ export interface INodeType {
}; };
}; };
webhookMethods?: { webhookMethods?: {
[key: string]: IWebhookSetupMethods; [name in IWebhookDescription['name']]?: {
[method in WebhookSetupMethodNames]: (this: IHookFunctions) => Promise<boolean>;
};
}; };
} }
@ -1213,15 +1214,6 @@ export interface INodeCredentialTestRequest {
credentials: ICredentialsDecrypted; credentials: ICredentialsDecrypted;
} }
export type WebhookSetupMethodNames = 'checkExists' | 'create' | 'delete';
export interface IWebhookSetupMethods {
[key: string]: ((this: IHookFunctions) => Promise<boolean>) | undefined;
checkExists?: (this: IHookFunctions) => Promise<boolean>;
create?: (this: IHookFunctions) => Promise<boolean>;
delete?: (this: IHookFunctions) => Promise<boolean>;
}
export interface INodeCredentialDescription { export interface INodeCredentialDescription {
name: string; name: string;
required?: boolean; required?: boolean;
@ -1436,7 +1428,7 @@ export interface IWebhookDescription {
[key: string]: WebhookHttpMethod | WebhookResponseMode | boolean | string | undefined; [key: string]: WebhookHttpMethod | WebhookResponseMode | boolean | string | undefined;
httpMethod: WebhookHttpMethod | string; httpMethod: WebhookHttpMethod | string;
isFullPath?: boolean; isFullPath?: boolean;
name: string; name: 'default' | 'setup';
path: string; path: string;
responseBinaryPropertyName?: string; responseBinaryPropertyName?: string;
responseContentType?: string; responseContentType?: string;

View file

@ -982,17 +982,8 @@ export class Workflow {
const node = this.getNode(webhookData.node) as INode; const node = this.getNode(webhookData.node) as INode;
const nodeType = this.nodeTypes.getByNameAndVersion(node.type, node.typeVersion); const nodeType = this.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
if (nodeType.webhookMethods === undefined) { const webhookFn = nodeType.webhookMethods?.[webhookData.webhookDescription.name]?.[method];
return; if (webhookFn === undefined) return;
}
if (nodeType.webhookMethods[webhookData.webhookDescription.name] === undefined) {
return;
}
if (nodeType.webhookMethods[webhookData.webhookDescription.name][method] === undefined) {
return;
}
const thisArgs = nodeExecuteFunctions.getExecuteHookFunctions( const thisArgs = nodeExecuteFunctions.getExecuteHookFunctions(
this, this,
@ -1003,8 +994,8 @@ export class Workflow {
isTest, isTest,
webhookData, webhookData,
); );
// eslint-disable-next-line consistent-return
return nodeType.webhookMethods[webhookData.webhookDescription.name][method]!.call(thisArgs); return webhookFn.call(thisArgs);
} }
/** /**