@octokit/webhooks 9.26.0 → 9.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist-node/index.js +1 -1
  2. package/package.json +2 -2
  3. package/dist-node/index.js.map +0 -1
  4. package/dist-src/createLogger.js +0 -7
  5. package/dist-src/event-handler/index.js +0 -20
  6. package/dist-src/event-handler/on.js +0 -28
  7. package/dist-src/event-handler/receive.js +0 -57
  8. package/dist-src/event-handler/remove-listener.js +0 -17
  9. package/dist-src/event-handler/wrap-error-handler.js +0 -19
  10. package/dist-src/generated/webhook-names.js +0 -244
  11. package/dist-src/index.js +0 -30
  12. package/dist-src/middleware/node/get-missing-headers.js +0 -9
  13. package/dist-src/middleware/node/get-payload.js +0 -25
  14. package/dist-src/middleware/node/index.js +0 -10
  15. package/dist-src/middleware/node/middleware.js +0 -70
  16. package/dist-src/middleware/node/on-unhandled-request-default.js +0 -8
  17. package/dist-src/middleware/node/types.js +0 -1
  18. package/dist-src/sign.js +0 -5
  19. package/dist-src/to-normalized-json-string.js +0 -9
  20. package/dist-src/types.js +0 -1
  21. package/dist-src/verify-and-receive.js +0 -19
  22. package/dist-src/verify.js +0 -5
  23. package/dist-types/createLogger.d.ts +0 -7
  24. package/dist-types/event-handler/index.d.ts +0 -10
  25. package/dist-types/event-handler/on.d.ts +0 -4
  26. package/dist-types/event-handler/receive.d.ts +0 -2
  27. package/dist-types/event-handler/remove-listener.d.ts +0 -2
  28. package/dist-types/event-handler/wrap-error-handler.d.ts +0 -1
  29. package/dist-types/generated/webhook-names.d.ts +0 -1
  30. package/dist-types/index.d.ts +0 -18
  31. package/dist-types/middleware/node/get-missing-headers.d.ts +0 -3
  32. package/dist-types/middleware/node/get-payload.d.ts +0 -4
  33. package/dist-types/middleware/node/index.d.ts +0 -3
  34. package/dist-types/middleware/node/middleware.d.ts +0 -6
  35. package/dist-types/middleware/node/on-unhandled-request-default.d.ts +0 -4
  36. package/dist-types/middleware/node/types.d.ts +0 -9
  37. package/dist-types/sign.d.ts +0 -1
  38. package/dist-types/to-normalized-json-string.d.ts +0 -4
  39. package/dist-types/types.d.ts +0 -62
  40. package/dist-types/verify-and-receive.d.ts +0 -4
  41. package/dist-types/verify.d.ts +0 -1
  42. package/dist-web/index.js +0 -577
  43. package/dist-web/index.js.map +0 -1
@@ -1,70 +0,0 @@
1
- import { getMissingHeaders } from "./get-missing-headers";
2
- import { getPayload } from "./get-payload";
3
- export async function middleware(webhooks, options, request, response, next) {
4
- let pathname;
5
- try {
6
- pathname = new URL(request.url, "http://localhost").pathname;
7
- }
8
- catch (error) {
9
- response.writeHead(422, {
10
- "content-type": "application/json",
11
- });
12
- response.end(JSON.stringify({
13
- error: `Request URL could not be parsed: ${request.url}`,
14
- }));
15
- return;
16
- }
17
- const isUnknownRoute = request.method !== "POST" || pathname !== options.path;
18
- const isExpressMiddleware = typeof next === "function";
19
- if (isUnknownRoute) {
20
- if (isExpressMiddleware) {
21
- return next();
22
- }
23
- else {
24
- return options.onUnhandledRequest(request, response);
25
- }
26
- }
27
- const missingHeaders = getMissingHeaders(request).join(", ");
28
- if (missingHeaders) {
29
- response.writeHead(400, {
30
- "content-type": "application/json",
31
- });
32
- response.end(JSON.stringify({
33
- error: `Required headers missing: ${missingHeaders}`,
34
- }));
35
- return;
36
- }
37
- const eventName = request.headers["x-github-event"];
38
- const signatureSHA256 = request.headers["x-hub-signature-256"];
39
- const id = request.headers["x-github-delivery"];
40
- options.log.debug(`${eventName} event received (id: ${id})`);
41
- // GitHub will abort the request if it does not receive a response within 10s
42
- // See https://github.com/octokit/webhooks.js/issues/185
43
- let didTimeout = false;
44
- const timeout = setTimeout(() => {
45
- didTimeout = true;
46
- response.statusCode = 202;
47
- response.end("still processing\n");
48
- }, 9000).unref();
49
- try {
50
- const payload = await getPayload(request);
51
- await webhooks.verifyAndReceive({
52
- id: id,
53
- name: eventName,
54
- payload: payload,
55
- signature: signatureSHA256,
56
- });
57
- clearTimeout(timeout);
58
- if (didTimeout)
59
- return;
60
- response.end("ok\n");
61
- }
62
- catch (error) {
63
- clearTimeout(timeout);
64
- if (didTimeout)
65
- return;
66
- const statusCode = Array.from(error)[0].status;
67
- response.statusCode = typeof statusCode !== "undefined" ? statusCode : 500;
68
- response.end(String(error));
69
- }
70
- }
@@ -1,8 +0,0 @@
1
- export function onUnhandledRequestDefault(request, response) {
2
- response.writeHead(404, {
3
- "content-type": "application/json",
4
- });
5
- response.end(JSON.stringify({
6
- error: `Unknown route: ${request.method} ${request.url}`,
7
- }));
8
- }
@@ -1 +0,0 @@
1
- export {};
package/dist-src/sign.js DELETED
@@ -1,5 +0,0 @@
1
- import { sign as signMethod } from "@octokit/webhooks-methods";
2
- import { toNormalizedJsonString } from "./to-normalized-json-string";
3
- export async function sign(secret, payload) {
4
- return signMethod(secret, typeof payload === "string" ? payload : toNormalizedJsonString(payload));
5
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * GitHub sends its JSON with an indentation of 2 spaces and a line break at the end
3
- */
4
- export function toNormalizedJsonString(payload) {
5
- const payloadString = JSON.stringify(payload);
6
- return payloadString.replace(/[^\\]\\u[\da-f]{4}/g, (s) => {
7
- return s.substr(0, 3) + s.substr(3).toUpperCase();
8
- });
9
- }
package/dist-src/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,19 +0,0 @@
1
- import { verify } from "@octokit/webhooks-methods";
2
- import { toNormalizedJsonString } from "./to-normalized-json-string";
3
- export async function verifyAndReceive(state, event) {
4
- // verify will validate that the secret is not undefined
5
- const matchesSignature = await verify(state.secret, typeof event.payload === "object"
6
- ? toNormalizedJsonString(event.payload)
7
- : event.payload, event.signature);
8
- if (!matchesSignature) {
9
- const error = new Error("[@octokit/webhooks] signature does not match event payload and secret");
10
- return state.eventHandler.receive(Object.assign(error, { event, status: 400 }));
11
- }
12
- return state.eventHandler.receive({
13
- id: event.id,
14
- name: event.name,
15
- payload: typeof event.payload === "string"
16
- ? JSON.parse(event.payload)
17
- : event.payload,
18
- });
19
- }
@@ -1,5 +0,0 @@
1
- import { verify as verifyMethod } from "@octokit/webhooks-methods";
2
- import { toNormalizedJsonString } from "./to-normalized-json-string";
3
- export async function verify(secret, payload, signature) {
4
- return verifyMethod(secret, typeof payload === "string" ? payload : toNormalizedJsonString(payload), signature);
5
- }
@@ -1,7 +0,0 @@
1
- export interface Logger {
2
- debug: (...data: any[]) => void;
3
- info: (...data: any[]) => void;
4
- warn: (...data: any[]) => void;
5
- error: (...data: any[]) => void;
6
- }
7
- export declare const createLogger: (logger?: Partial<Logger> | undefined) => Logger;
@@ -1,10 +0,0 @@
1
- import type { EmitterWebhookEvent, EmitterWebhookEventName, HandlerFunction, Options, WebhookEventHandlerError } from "../types";
2
- interface EventHandler<TTransformed> {
3
- on<E extends EmitterWebhookEventName>(event: E | E[], callback: HandlerFunction<E, TTransformed>): void;
4
- onAny(handler: (event: EmitterWebhookEvent) => any): void;
5
- onError(handler: (event: WebhookEventHandlerError) => any): void;
6
- removeListener<E extends EmitterWebhookEventName>(event: E | E[], callback: HandlerFunction<E, TTransformed>): void;
7
- receive(event: EmitterWebhookEvent): Promise<void>;
8
- }
9
- export declare function createEventHandler<TTransformed>(options: Options<TTransformed>): EventHandler<TTransformed>;
10
- export {};
@@ -1,4 +0,0 @@
1
- import { EmitterWebhookEvent, EmitterWebhookEventName, State, WebhookEventHandlerError } from "../types";
2
- export declare function receiverOn(state: State, webhookNameOrNames: EmitterWebhookEventName | EmitterWebhookEventName[], handler: Function): void;
3
- export declare function receiverOnAny(state: State, handler: (event: EmitterWebhookEvent) => any): void;
4
- export declare function receiverOnError(state: State, handler: (event: WebhookEventHandlerError) => any): void;
@@ -1,2 +0,0 @@
1
- import type { EmitterWebhookEvent, State } from "../types";
2
- export declare function receiverHandle(state: State, event: EmitterWebhookEvent): Promise<void>;
@@ -1,2 +0,0 @@
1
- import { EmitterWebhookEventName, State } from "../types";
2
- export declare function removeListener(state: State, webhookNameOrNames: "*" | EmitterWebhookEventName | EmitterWebhookEventName[], handler: Function): void;
@@ -1 +0,0 @@
1
- export declare function wrapErrorHandler(handler: Function, error: Error): void;
@@ -1 +0,0 @@
1
- export declare const emitterEventNames: readonly ["branch_protection_rule", "branch_protection_rule.created", "branch_protection_rule.deleted", "branch_protection_rule.edited", "check_run", "check_run.completed", "check_run.created", "check_run.requested_action", "check_run.rerequested", "check_suite", "check_suite.completed", "check_suite.requested", "check_suite.rerequested", "code_scanning_alert", "code_scanning_alert.appeared_in_branch", "code_scanning_alert.closed_by_user", "code_scanning_alert.created", "code_scanning_alert.fixed", "code_scanning_alert.reopened", "code_scanning_alert.reopened_by_user", "commit_comment", "commit_comment.created", "create", "delete", "deploy_key", "deploy_key.created", "deploy_key.deleted", "deployment", "deployment.created", "deployment_status", "deployment_status.created", "discussion", "discussion.answered", "discussion.category_changed", "discussion.created", "discussion.deleted", "discussion.edited", "discussion.labeled", "discussion.locked", "discussion.pinned", "discussion.transferred", "discussion.unanswered", "discussion.unlabeled", "discussion.unlocked", "discussion.unpinned", "discussion_comment", "discussion_comment.created", "discussion_comment.deleted", "discussion_comment.edited", "fork", "github_app_authorization", "github_app_authorization.revoked", "gollum", "installation", "installation.created", "installation.deleted", "installation.new_permissions_accepted", "installation.suspend", "installation.unsuspend", "installation_repositories", "installation_repositories.added", "installation_repositories.removed", "issue_comment", "issue_comment.created", "issue_comment.deleted", "issue_comment.edited", "issues", "issues.assigned", "issues.closed", "issues.deleted", "issues.demilestoned", "issues.edited", "issues.labeled", "issues.locked", "issues.milestoned", "issues.opened", "issues.pinned", "issues.reopened", "issues.transferred", "issues.unassigned", "issues.unlabeled", "issues.unlocked", "issues.unpinned", "label", "label.created", "label.deleted", "label.edited", "marketplace_purchase", "marketplace_purchase.cancelled", "marketplace_purchase.changed", "marketplace_purchase.pending_change", "marketplace_purchase.pending_change_cancelled", "marketplace_purchase.purchased", "member", "member.added", "member.edited", "member.removed", "membership", "membership.added", "membership.removed", "meta", "meta.deleted", "milestone", "milestone.closed", "milestone.created", "milestone.deleted", "milestone.edited", "milestone.opened", "org_block", "org_block.blocked", "org_block.unblocked", "organization", "organization.deleted", "organization.member_added", "organization.member_invited", "organization.member_removed", "organization.renamed", "package", "package.published", "package.updated", "page_build", "ping", "project", "project.closed", "project.created", "project.deleted", "project.edited", "project.reopened", "project_card", "project_card.converted", "project_card.created", "project_card.deleted", "project_card.edited", "project_card.moved", "project_column", "project_column.created", "project_column.deleted", "project_column.edited", "project_column.moved", "projects_v2_item", "projects_v2_item.archived", "projects_v2_item.converted", "projects_v2_item.created", "projects_v2_item.deleted", "projects_v2_item.edited", "projects_v2_item.reordered", "projects_v2_item.restored", "public", "pull_request", "pull_request.assigned", "pull_request.auto_merge_disabled", "pull_request.auto_merge_enabled", "pull_request.closed", "pull_request.converted_to_draft", "pull_request.edited", "pull_request.labeled", "pull_request.locked", "pull_request.opened", "pull_request.ready_for_review", "pull_request.reopened", "pull_request.review_request_removed", "pull_request.review_requested", "pull_request.synchronize", "pull_request.unassigned", "pull_request.unlabeled", "pull_request.unlocked", "pull_request_review", "pull_request_review.dismissed", "pull_request_review.edited", "pull_request_review.submitted", "pull_request_review_comment", "pull_request_review_comment.created", "pull_request_review_comment.deleted", "pull_request_review_comment.edited", "pull_request_review_thread", "pull_request_review_thread.resolved", "pull_request_review_thread.unresolved", "push", "release", "release.created", "release.deleted", "release.edited", "release.prereleased", "release.published", "release.released", "release.unpublished", "repository", "repository.archived", "repository.created", "repository.deleted", "repository.edited", "repository.privatized", "repository.publicized", "repository.renamed", "repository.transferred", "repository.unarchived", "repository_dispatch", "repository_import", "repository_vulnerability_alert", "repository_vulnerability_alert.create", "repository_vulnerability_alert.dismiss", "repository_vulnerability_alert.reopen", "repository_vulnerability_alert.resolve", "secret_scanning_alert", "secret_scanning_alert.created", "secret_scanning_alert.reopened", "secret_scanning_alert.resolved", "security_advisory", "security_advisory.performed", "security_advisory.published", "security_advisory.updated", "security_advisory.withdrawn", "sponsorship", "sponsorship.cancelled", "sponsorship.created", "sponsorship.edited", "sponsorship.pending_cancellation", "sponsorship.pending_tier_change", "sponsorship.tier_changed", "star", "star.created", "star.deleted", "status", "team", "team.added_to_repository", "team.created", "team.deleted", "team.edited", "team.removed_from_repository", "team_add", "watch", "watch.started", "workflow_dispatch", "workflow_job", "workflow_job.completed", "workflow_job.in_progress", "workflow_job.queued", "workflow_run", "workflow_run.completed", "workflow_run.requested"];
@@ -1,18 +0,0 @@
1
- import { createEventHandler } from "./event-handler/index";
2
- import { EmitterWebhookEvent, EmitterWebhookEventName, HandlerFunction, RemoveHandlerFunction, Options, WebhookError, WebhookEventHandlerError, EmitterWebhookEventWithStringPayloadAndSignature, EmitterWebhookEventWithSignature } from "./types";
3
- export { createNodeMiddleware } from "./middleware/node/index";
4
- export { emitterEventNames } from "./generated/webhook-names";
5
- declare class Webhooks<TTransformed = unknown> {
6
- sign: (payload: string | object) => Promise<string>;
7
- verify: (eventPayload: string | object, signature: string) => Promise<boolean>;
8
- on: <E extends EmitterWebhookEventName>(event: E | E[], callback: HandlerFunction<E, TTransformed>) => void;
9
- onAny: (callback: (event: EmitterWebhookEvent) => any) => void;
10
- onError: (callback: (event: WebhookEventHandlerError) => any) => void;
11
- removeListener: <E extends EmitterWebhookEventName | "*">(event: E | E[], callback: RemoveHandlerFunction<E, TTransformed>) => void;
12
- receive: (event: EmitterWebhookEvent) => Promise<void>;
13
- verifyAndReceive: (options: EmitterWebhookEventWithStringPayloadAndSignature | EmitterWebhookEventWithSignature) => Promise<void>;
14
- constructor(options: Options<TTransformed> & {
15
- secret: string;
16
- });
17
- }
18
- export { createEventHandler, Webhooks, EmitterWebhookEvent, EmitterWebhookEventName, WebhookError, };
@@ -1,3 +0,0 @@
1
- declare type IncomingMessage = any;
2
- export declare function getMissingHeaders(request: IncomingMessage): string[];
3
- export {};
@@ -1,4 +0,0 @@
1
- import { WebhookEvent } from "@octokit/webhooks-types";
2
- declare type IncomingMessage = any;
3
- export declare function getPayload(request: IncomingMessage): Promise<WebhookEvent>;
4
- export {};
@@ -1,3 +0,0 @@
1
- import { Webhooks } from "../../index";
2
- import { MiddlewareOptions } from "./types";
3
- export declare function createNodeMiddleware(webhooks: Webhooks, { path, onUnhandledRequest, log, }?: MiddlewareOptions): (request: any, response: any, next?: Function | undefined) => Promise<any>;
@@ -1,6 +0,0 @@
1
- declare type IncomingMessage = any;
2
- declare type ServerResponse = any;
3
- import { Webhooks } from "../../index";
4
- import { MiddlewareOptions } from "./types";
5
- export declare function middleware(webhooks: Webhooks, options: Required<MiddlewareOptions>, request: IncomingMessage, response: ServerResponse, next?: Function): Promise<any>;
6
- export {};
@@ -1,4 +0,0 @@
1
- declare type IncomingMessage = any;
2
- declare type ServerResponse = any;
3
- export declare function onUnhandledRequestDefault(request: IncomingMessage, response: ServerResponse): void;
4
- export {};
@@ -1,9 +0,0 @@
1
- declare type IncomingMessage = any;
2
- declare type ServerResponse = any;
3
- import { Logger } from "../../createLogger";
4
- export declare type MiddlewareOptions = {
5
- path?: string;
6
- log?: Logger;
7
- onUnhandledRequest?: (request: IncomingMessage, response: ServerResponse) => void;
8
- };
9
- export {};
@@ -1 +0,0 @@
1
- export declare function sign(secret: string, payload: string | object): Promise<any>;
@@ -1,4 +0,0 @@
1
- /**
2
- * GitHub sends its JSON with an indentation of 2 spaces and a line break at the end
3
- */
4
- export declare function toNormalizedJsonString(payload: object): string;
@@ -1,62 +0,0 @@
1
- import { RequestError } from "@octokit/request-error";
2
- import type { WebhookEventMap, WebhookEventName } from "@octokit/webhooks-types";
3
- import { Logger } from "./createLogger";
4
- import type { emitterEventNames } from "./generated/webhook-names";
5
- export declare type EmitterWebhookEventName = typeof emitterEventNames[number];
6
- export declare type EmitterWebhookEvent<TEmitterEvent extends EmitterWebhookEventName = EmitterWebhookEventName> = TEmitterEvent extends `${infer TWebhookEvent}.${infer TAction}` ? BaseWebhookEvent<Extract<TWebhookEvent, WebhookEventName>> & {
7
- payload: {
8
- action: TAction;
9
- };
10
- } : BaseWebhookEvent<Extract<TEmitterEvent, WebhookEventName>>;
11
- export declare type EmitterWebhookEventWithStringPayloadAndSignature = {
12
- id: string;
13
- name: EmitterWebhookEventName;
14
- payload: string;
15
- signature: string;
16
- };
17
- export declare type EmitterWebhookEventWithSignature = EmitterWebhookEvent & {
18
- signature: string;
19
- };
20
- interface BaseWebhookEvent<TName extends WebhookEventName> {
21
- id: string;
22
- name: TName;
23
- payload: WebhookEventMap[TName];
24
- }
25
- export interface Options<TTransformed = unknown> {
26
- secret?: string;
27
- transform?: TransformMethod<TTransformed>;
28
- log?: Partial<Logger>;
29
- }
30
- declare type TransformMethod<T> = (event: EmitterWebhookEvent) => T | PromiseLike<T>;
31
- export declare type HandlerFunction<TName extends EmitterWebhookEventName, TTransformed> = (event: EmitterWebhookEvent<TName> & TTransformed) => any;
32
- export declare type RemoveHandlerFunction<TName extends EmitterWebhookEventName | "*", TTransformed> = (event: EmitterWebhookEvent<Exclude<TName, "*">> & TTransformed) => any;
33
- declare type Hooks = {
34
- [key: string]: Function[];
35
- };
36
- export interface State extends Options<any> {
37
- eventHandler?: any;
38
- hooks: Hooks;
39
- log: Logger;
40
- }
41
- /**
42
- * Error object with optional properties coming from `octokit.request` errors
43
- */
44
- export declare type WebhookError = Error & Partial<RequestError>;
45
- export interface WebhookEventHandlerError extends AggregateError<WebhookError> {
46
- event: EmitterWebhookEvent;
47
- }
48
- /**
49
- * Workaround for TypeScript incompatibility with types exported by aggregate-error.
50
- * Credit: https://git.io/JUEEr
51
- * @copyright Sindre Sorhus
52
- * @license MIT (https://git.io/JUEEK)
53
- * @see https://github.com/octokit/webhooks.js/pull/270/files
54
- */
55
- declare class AggregateError<T extends Error = Error> extends Error implements Iterable<T> {
56
- readonly name: "AggregateError";
57
- constructor(errors: ReadonlyArray<T | {
58
- [key: string]: any;
59
- } | string>);
60
- [Symbol.iterator](): IterableIterator<T>;
61
- }
62
- export {};
@@ -1,4 +0,0 @@
1
- import { EmitterWebhookEventWithStringPayloadAndSignature, EmitterWebhookEventWithSignature, State } from "./types";
2
- export declare function verifyAndReceive(state: State & {
3
- secret: string;
4
- }, event: EmitterWebhookEventWithStringPayloadAndSignature | EmitterWebhookEventWithSignature): Promise<any>;
@@ -1 +0,0 @@
1
- export declare function verify(secret: string, payload: string | object, signature: string): Promise<any>;