UNPKG

1.9 kBTypeScriptView Raw
1import type { RequestError } from "@octokit/request-error";
2import type { EventNames } from "./generated/event-names";
3import { GetWebhookPayloadTypeFromEvent } from "./generated/get-webhook-payload-type-from-event";
4export interface WebhookEvent<T = any> {
5 id: string;
6 name: EventNames.StringNames;
7 payload: T;
8}
9export interface Options<T extends WebhookEvent> {
10 path?: string;
11 secret?: string;
12 transform?: TransformMethod<T>;
13}
14declare type TransformMethod<T extends WebhookEvent> = (event: WebhookEvent) => T | PromiseLike<T>;
15export declare type HandlerFunction<E, T> = (event: GetWebhookPayloadTypeFromEvent<E, T>) => any;
16declare type Hooks = {
17 [key: string]: Function[];
18};
19export interface State extends Options<any> {
20 eventHandler?: any;
21 hooks: Hooks;
22}
23/**
24 * Error object with optional poperties coming from `octokit.request` errors
25 */
26export declare type WebhookError = Error & Partial<RequestError> & {
27 /**
28 * @deprecated `error.event` is deprecated. Use the `.event` property on the aggregated error instance
29 */
30 event: WebhookEvent;
31};
32export interface WebhookEventHandlerError extends AggregateError<WebhookError> {
33 event: WebhookEvent;
34 /**
35 * @deprecated `error.errors` is deprecated. Use `Array.from(error)`. See https://npm.im/aggregate-error
36 */
37 errors: WebhookError[];
38}
39/**
40 * Workaround for TypeScript incompatibility with types exported by aggregate-error.
41 * Credit: https://git.io/JUEEr
42 * @copyright Sindre Sorhus
43 * @license MIT (https://git.io/JUEEK)
44 * @see https://github.com/octokit/webhooks.js/pull/270/files
45 */
46declare class AggregateError<T extends Error = Error> extends Error implements Iterable<T> {
47 readonly name: "AggregateError";
48 constructor(errors: ReadonlyArray<T | {
49 [key: string]: any;
50 } | string>);
51 [Symbol.iterator](): IterableIterator<T>;
52}
53export {};