Skip to content

Commit

Permalink
feat(typescript): definitions for .verify, .verifyAndReceive, .receiv…
Browse files Browse the repository at this point in the history
…e, .removeListener, .middleware methods (#55)
  • Loading branch information
wolfy1339 authored and gr2m committed Jan 26, 2019
1 parent 91ebccb commit 79fcec2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
37 changes: 35 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// DO NOT EDIT THIS FILE DIRECTLY
// make edits in scripts/generate-types.js

import http = require("http");

export type Options = {
secret: string;
path?: string;
transform?: (event: Webhooks.WebhookEvent<T>) => Webhooks.WebhookEvent<T> & { [key: string]: any };
transform?: (
event: Webhooks.WebhookEvent<T>
) => Webhooks.WebhookEvent<T> & { [key: string]: any };
};

export type WebhookPayloadWatchSender = {
Expand Down Expand Up @@ -3477,9 +3481,13 @@ export namespace Webhooks {

public on(event: "error", callback: (event: Error) => void): void;
public on(
event: "*" | string[],
event: "*" | string | string[],
callback: (event: Webhooks.WebhookEvent<any>) => void
): void;
public on(
event: "*" | string | string[],
callback: (event: Webhooks.WebhookEvent<any>) => Promise<void>
): void;

public on(
event:
Expand Down Expand Up @@ -3812,5 +3820,30 @@ export namespace Webhooks {
): void;

public sign(data: any): string;
public verify(eventPayload: any, signature: string): boolean;
public verifyAndReceive(options: {
id: string;
name: string;
payload: any;
signature: string;
}): Promise<void>;
public receive(options: {
id: string;
name: string;
payload: any;
}): Promise<void>;
public removeListener(
event: string | string[],
callback: (event: Webhooks.WebhookEvent<any>) => void
): void;
public removeListener(
event: string | string[],
callback: (event: Webhooks.WebhookEvent<any>) => Promise<void>
): void;
public middleware(
request: http.ClientRequest,
response: http.ServerResponse,
next: (err?: any) => void
): (request: http.IncomingMessage, response: http.ServerResponse) => void;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"pretest": "standard",
"test": "tap --100 --coverage 'test/**/*-test.js'",
"semantic-release": "semantic-release",
"generate-types": "node generate-types.js"
"generate-types": "node scripts/generate-types.js"
},
"repository": {
"type": "git",
Expand Down
11 changes: 10 additions & 1 deletion scripts/generate-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const definition = `
// DO NOT EDIT THIS FILE DIRECTLY
// make edits in scripts/generate-types.js
import http = require('http')
export type Options = {
secret: string
path?: string
Expand All @@ -53,10 +55,17 @@ export namespace Webhooks {
constructor (options: Options)
public on (event: 'error', callback: (event: Error) => void): void
public on (event: '*' | string[], callback: (event: Webhooks.WebhookEvent<any>) => void): void
public on (event: '*' | string | string[], callback: (event: Webhooks.WebhookEvent<any>) => void): void
public on (event: '*' | string | string[], callback: (event: Webhooks.WebhookEvent<any>) => Promise<void>): void
${signatures.join('\n')}
public sign (data: any): string
public verify (eventPayload: any, signature: string): boolean
public verifyAndReceive (options: { id: string, name: string, payload: any, signature: string }): Promise<void>
public receive (options: { id: string, name: string, payload: any }): Promise<void>
public removeListener (event: string | string[], callback: (event: Webhooks.WebhookEvent<any>) => void): void
public removeListener (event: string | string[], callback: (event: Webhooks.WebhookEvent<any>) => Promise<void>): void
public middleware (request: http.ClientRequest, response: http.ServerResponse, next: (err?: any) => void): (request: http.IncomingMessage, response: http.ServerResponse) => void
}
}
`
Expand Down

0 comments on commit 79fcec2

Please sign in to comment.