@octokit/webhooks 11.0.0-beta.7 → 11.0.0-beta.8
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.
- package/README.md +62 -62
- package/dist-node/index.js +417 -96
- package/dist-node/index.js.map +7 -1
- package/dist-src/createLogger.js +11 -6
- package/dist-src/event-handler/index.js +23 -16
- package/dist-src/event-handler/on.js +31 -22
- package/dist-src/event-handler/receive.js +51 -49
- package/dist-src/event-handler/remove-listener.js +18 -15
- package/dist-src/event-handler/wrap-error-handler.js +17 -18
- package/dist-src/generated/webhook-names.js +262 -259
- package/dist-src/index.js +26 -22
- package/dist-src/middleware/node/get-missing-headers.js +8 -6
- package/dist-src/middleware/node/get-payload.js +21 -24
- package/dist-src/middleware/node/index.js +11 -5
- package/dist-src/middleware/node/middleware.js +87 -87
- package/dist-src/middleware/node/on-unhandled-request-default.js +12 -7
- package/dist-src/verify-and-receive.js +22 -12
- package/dist-types/event-handler/on.d.ts +1 -1
- package/dist-types/event-handler/remove-listener.d.ts +1 -1
- package/dist-types/generated/webhook-names.d.ts +1 -1
- package/dist-types/index.d.ts +2 -2
- package/dist-types/middleware/node/index.d.ts +2 -2
- package/dist-types/middleware/node/middleware.d.ts +2 -2
- package/dist-types/middleware/node/types.d.ts +1 -1
- package/dist-types/types.d.ts +2 -2
- package/dist-types/verify-and-receive.d.ts +1 -1
- package/dist-web/index.js +565 -541
- package/dist-web/index.js.map +7 -1
- package/package.json +19 -21
- package/dist-src/middleware/node/types.js +0 -1
- package/dist-src/types.js +0 -1
package/dist-node/index.js
CHANGED
|
@@ -1,24 +1,316 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
6
29
|
|
|
7
|
-
|
|
8
|
-
var
|
|
30
|
+
// pkg/dist-src/index.js
|
|
31
|
+
var dist_src_exports = {};
|
|
32
|
+
__export(dist_src_exports, {
|
|
33
|
+
Webhooks: () => Webhooks,
|
|
34
|
+
createEventHandler: () => createEventHandler,
|
|
35
|
+
createNodeMiddleware: () => createNodeMiddleware,
|
|
36
|
+
emitterEventNames: () => emitterEventNames
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(dist_src_exports);
|
|
9
39
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
40
|
+
// pkg/dist-src/createLogger.js
|
|
41
|
+
var createLogger = (logger) => ({
|
|
42
|
+
debug: () => {
|
|
43
|
+
},
|
|
44
|
+
info: () => {
|
|
45
|
+
},
|
|
13
46
|
warn: console.warn.bind(console),
|
|
14
47
|
error: console.error.bind(console),
|
|
15
48
|
...logger
|
|
16
49
|
});
|
|
17
50
|
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
51
|
+
// pkg/dist-src/generated/webhook-names.js
|
|
52
|
+
var emitterEventNames = [
|
|
53
|
+
"branch_protection_rule",
|
|
54
|
+
"branch_protection_rule.created",
|
|
55
|
+
"branch_protection_rule.deleted",
|
|
56
|
+
"branch_protection_rule.edited",
|
|
57
|
+
"check_run",
|
|
58
|
+
"check_run.completed",
|
|
59
|
+
"check_run.created",
|
|
60
|
+
"check_run.requested_action",
|
|
61
|
+
"check_run.rerequested",
|
|
62
|
+
"check_suite",
|
|
63
|
+
"check_suite.completed",
|
|
64
|
+
"check_suite.requested",
|
|
65
|
+
"check_suite.rerequested",
|
|
66
|
+
"code_scanning_alert",
|
|
67
|
+
"code_scanning_alert.appeared_in_branch",
|
|
68
|
+
"code_scanning_alert.closed_by_user",
|
|
69
|
+
"code_scanning_alert.created",
|
|
70
|
+
"code_scanning_alert.fixed",
|
|
71
|
+
"code_scanning_alert.reopened",
|
|
72
|
+
"code_scanning_alert.reopened_by_user",
|
|
73
|
+
"commit_comment",
|
|
74
|
+
"commit_comment.created",
|
|
75
|
+
"create",
|
|
76
|
+
"delete",
|
|
77
|
+
"dependabot_alert",
|
|
78
|
+
"dependabot_alert.created",
|
|
79
|
+
"dependabot_alert.dismissed",
|
|
80
|
+
"dependabot_alert.fixed",
|
|
81
|
+
"dependabot_alert.reintroduced",
|
|
82
|
+
"dependabot_alert.reopened",
|
|
83
|
+
"deploy_key",
|
|
84
|
+
"deploy_key.created",
|
|
85
|
+
"deploy_key.deleted",
|
|
86
|
+
"deployment",
|
|
87
|
+
"deployment.created",
|
|
88
|
+
"deployment_status",
|
|
89
|
+
"deployment_status.created",
|
|
90
|
+
"discussion",
|
|
91
|
+
"discussion.answered",
|
|
92
|
+
"discussion.category_changed",
|
|
93
|
+
"discussion.created",
|
|
94
|
+
"discussion.deleted",
|
|
95
|
+
"discussion.edited",
|
|
96
|
+
"discussion.labeled",
|
|
97
|
+
"discussion.locked",
|
|
98
|
+
"discussion.pinned",
|
|
99
|
+
"discussion.transferred",
|
|
100
|
+
"discussion.unanswered",
|
|
101
|
+
"discussion.unlabeled",
|
|
102
|
+
"discussion.unlocked",
|
|
103
|
+
"discussion.unpinned",
|
|
104
|
+
"discussion_comment",
|
|
105
|
+
"discussion_comment.created",
|
|
106
|
+
"discussion_comment.deleted",
|
|
107
|
+
"discussion_comment.edited",
|
|
108
|
+
"fork",
|
|
109
|
+
"github_app_authorization",
|
|
110
|
+
"github_app_authorization.revoked",
|
|
111
|
+
"gollum",
|
|
112
|
+
"installation",
|
|
113
|
+
"installation.created",
|
|
114
|
+
"installation.deleted",
|
|
115
|
+
"installation.new_permissions_accepted",
|
|
116
|
+
"installation.suspend",
|
|
117
|
+
"installation.unsuspend",
|
|
118
|
+
"installation_repositories",
|
|
119
|
+
"installation_repositories.added",
|
|
120
|
+
"installation_repositories.removed",
|
|
121
|
+
"installation_target",
|
|
122
|
+
"installation_target.renamed",
|
|
123
|
+
"issue_comment",
|
|
124
|
+
"issue_comment.created",
|
|
125
|
+
"issue_comment.deleted",
|
|
126
|
+
"issue_comment.edited",
|
|
127
|
+
"issues",
|
|
128
|
+
"issues.assigned",
|
|
129
|
+
"issues.closed",
|
|
130
|
+
"issues.deleted",
|
|
131
|
+
"issues.demilestoned",
|
|
132
|
+
"issues.edited",
|
|
133
|
+
"issues.labeled",
|
|
134
|
+
"issues.locked",
|
|
135
|
+
"issues.milestoned",
|
|
136
|
+
"issues.opened",
|
|
137
|
+
"issues.pinned",
|
|
138
|
+
"issues.reopened",
|
|
139
|
+
"issues.transferred",
|
|
140
|
+
"issues.unassigned",
|
|
141
|
+
"issues.unlabeled",
|
|
142
|
+
"issues.unlocked",
|
|
143
|
+
"issues.unpinned",
|
|
144
|
+
"label",
|
|
145
|
+
"label.created",
|
|
146
|
+
"label.deleted",
|
|
147
|
+
"label.edited",
|
|
148
|
+
"marketplace_purchase",
|
|
149
|
+
"marketplace_purchase.cancelled",
|
|
150
|
+
"marketplace_purchase.changed",
|
|
151
|
+
"marketplace_purchase.pending_change",
|
|
152
|
+
"marketplace_purchase.pending_change_cancelled",
|
|
153
|
+
"marketplace_purchase.purchased",
|
|
154
|
+
"member",
|
|
155
|
+
"member.added",
|
|
156
|
+
"member.edited",
|
|
157
|
+
"member.removed",
|
|
158
|
+
"membership",
|
|
159
|
+
"membership.added",
|
|
160
|
+
"membership.removed",
|
|
161
|
+
"merge_group",
|
|
162
|
+
"merge_group.checks_requested",
|
|
163
|
+
"meta",
|
|
164
|
+
"meta.deleted",
|
|
165
|
+
"milestone",
|
|
166
|
+
"milestone.closed",
|
|
167
|
+
"milestone.created",
|
|
168
|
+
"milestone.deleted",
|
|
169
|
+
"milestone.edited",
|
|
170
|
+
"milestone.opened",
|
|
171
|
+
"org_block",
|
|
172
|
+
"org_block.blocked",
|
|
173
|
+
"org_block.unblocked",
|
|
174
|
+
"organization",
|
|
175
|
+
"organization.deleted",
|
|
176
|
+
"organization.member_added",
|
|
177
|
+
"organization.member_invited",
|
|
178
|
+
"organization.member_removed",
|
|
179
|
+
"organization.renamed",
|
|
180
|
+
"package",
|
|
181
|
+
"package.published",
|
|
182
|
+
"package.updated",
|
|
183
|
+
"page_build",
|
|
184
|
+
"ping",
|
|
185
|
+
"project",
|
|
186
|
+
"project.closed",
|
|
187
|
+
"project.created",
|
|
188
|
+
"project.deleted",
|
|
189
|
+
"project.edited",
|
|
190
|
+
"project.reopened",
|
|
191
|
+
"project_card",
|
|
192
|
+
"project_card.converted",
|
|
193
|
+
"project_card.created",
|
|
194
|
+
"project_card.deleted",
|
|
195
|
+
"project_card.edited",
|
|
196
|
+
"project_card.moved",
|
|
197
|
+
"project_column",
|
|
198
|
+
"project_column.created",
|
|
199
|
+
"project_column.deleted",
|
|
200
|
+
"project_column.edited",
|
|
201
|
+
"project_column.moved",
|
|
202
|
+
"projects_v2_item",
|
|
203
|
+
"projects_v2_item.archived",
|
|
204
|
+
"projects_v2_item.converted",
|
|
205
|
+
"projects_v2_item.created",
|
|
206
|
+
"projects_v2_item.deleted",
|
|
207
|
+
"projects_v2_item.edited",
|
|
208
|
+
"projects_v2_item.reordered",
|
|
209
|
+
"projects_v2_item.restored",
|
|
210
|
+
"public",
|
|
211
|
+
"pull_request",
|
|
212
|
+
"pull_request.assigned",
|
|
213
|
+
"pull_request.auto_merge_disabled",
|
|
214
|
+
"pull_request.auto_merge_enabled",
|
|
215
|
+
"pull_request.closed",
|
|
216
|
+
"pull_request.converted_to_draft",
|
|
217
|
+
"pull_request.demilestoned",
|
|
218
|
+
"pull_request.dequeued",
|
|
219
|
+
"pull_request.edited",
|
|
220
|
+
"pull_request.labeled",
|
|
221
|
+
"pull_request.locked",
|
|
222
|
+
"pull_request.milestoned",
|
|
223
|
+
"pull_request.opened",
|
|
224
|
+
"pull_request.queued",
|
|
225
|
+
"pull_request.ready_for_review",
|
|
226
|
+
"pull_request.reopened",
|
|
227
|
+
"pull_request.review_request_removed",
|
|
228
|
+
"pull_request.review_requested",
|
|
229
|
+
"pull_request.synchronize",
|
|
230
|
+
"pull_request.unassigned",
|
|
231
|
+
"pull_request.unlabeled",
|
|
232
|
+
"pull_request.unlocked",
|
|
233
|
+
"pull_request_review",
|
|
234
|
+
"pull_request_review.dismissed",
|
|
235
|
+
"pull_request_review.edited",
|
|
236
|
+
"pull_request_review.submitted",
|
|
237
|
+
"pull_request_review_comment",
|
|
238
|
+
"pull_request_review_comment.created",
|
|
239
|
+
"pull_request_review_comment.deleted",
|
|
240
|
+
"pull_request_review_comment.edited",
|
|
241
|
+
"pull_request_review_thread",
|
|
242
|
+
"pull_request_review_thread.resolved",
|
|
243
|
+
"pull_request_review_thread.unresolved",
|
|
244
|
+
"push",
|
|
245
|
+
"registry_package",
|
|
246
|
+
"registry_package.published",
|
|
247
|
+
"registry_package.updated",
|
|
248
|
+
"release",
|
|
249
|
+
"release.created",
|
|
250
|
+
"release.deleted",
|
|
251
|
+
"release.edited",
|
|
252
|
+
"release.prereleased",
|
|
253
|
+
"release.published",
|
|
254
|
+
"release.released",
|
|
255
|
+
"release.unpublished",
|
|
256
|
+
"repository",
|
|
257
|
+
"repository.archived",
|
|
258
|
+
"repository.created",
|
|
259
|
+
"repository.deleted",
|
|
260
|
+
"repository.edited",
|
|
261
|
+
"repository.privatized",
|
|
262
|
+
"repository.publicized",
|
|
263
|
+
"repository.renamed",
|
|
264
|
+
"repository.transferred",
|
|
265
|
+
"repository.unarchived",
|
|
266
|
+
"repository_dispatch",
|
|
267
|
+
"repository_import",
|
|
268
|
+
"repository_vulnerability_alert",
|
|
269
|
+
"repository_vulnerability_alert.create",
|
|
270
|
+
"repository_vulnerability_alert.dismiss",
|
|
271
|
+
"repository_vulnerability_alert.reopen",
|
|
272
|
+
"repository_vulnerability_alert.resolve",
|
|
273
|
+
"secret_scanning_alert",
|
|
274
|
+
"secret_scanning_alert.created",
|
|
275
|
+
"secret_scanning_alert.reopened",
|
|
276
|
+
"secret_scanning_alert.resolved",
|
|
277
|
+
"security_advisory",
|
|
278
|
+
"security_advisory.performed",
|
|
279
|
+
"security_advisory.published",
|
|
280
|
+
"security_advisory.updated",
|
|
281
|
+
"security_advisory.withdrawn",
|
|
282
|
+
"sponsorship",
|
|
283
|
+
"sponsorship.cancelled",
|
|
284
|
+
"sponsorship.created",
|
|
285
|
+
"sponsorship.edited",
|
|
286
|
+
"sponsorship.pending_cancellation",
|
|
287
|
+
"sponsorship.pending_tier_change",
|
|
288
|
+
"sponsorship.tier_changed",
|
|
289
|
+
"star",
|
|
290
|
+
"star.created",
|
|
291
|
+
"star.deleted",
|
|
292
|
+
"status",
|
|
293
|
+
"team",
|
|
294
|
+
"team.added_to_repository",
|
|
295
|
+
"team.created",
|
|
296
|
+
"team.deleted",
|
|
297
|
+
"team.edited",
|
|
298
|
+
"team.removed_from_repository",
|
|
299
|
+
"team_add",
|
|
300
|
+
"watch",
|
|
301
|
+
"watch.started",
|
|
302
|
+
"workflow_dispatch",
|
|
303
|
+
"workflow_job",
|
|
304
|
+
"workflow_job.completed",
|
|
305
|
+
"workflow_job.in_progress",
|
|
306
|
+
"workflow_job.queued",
|
|
307
|
+
"workflow_run",
|
|
308
|
+
"workflow_run.completed",
|
|
309
|
+
"workflow_run.in_progress",
|
|
310
|
+
"workflow_run.requested"
|
|
311
|
+
];
|
|
21
312
|
|
|
313
|
+
// pkg/dist-src/event-handler/on.js
|
|
22
314
|
function handleEventHandlers(state, webhookName, handler) {
|
|
23
315
|
if (!state.hooks[webhookName]) {
|
|
24
316
|
state.hooks[webhookName] = [];
|
|
@@ -27,7 +319,9 @@ function handleEventHandlers(state, webhookName, handler) {
|
|
|
27
319
|
}
|
|
28
320
|
function receiverOn(state, webhookNameOrNames, handler) {
|
|
29
321
|
if (Array.isArray(webhookNameOrNames)) {
|
|
30
|
-
webhookNameOrNames.forEach(
|
|
322
|
+
webhookNameOrNames.forEach(
|
|
323
|
+
(webhookName) => receiverOn(state, webhookName, handler)
|
|
324
|
+
);
|
|
31
325
|
return;
|
|
32
326
|
}
|
|
33
327
|
if (["*", "error"].includes(webhookNameOrNames)) {
|
|
@@ -36,7 +330,9 @@ function receiverOn(state, webhookNameOrNames, handler) {
|
|
|
36
330
|
throw new Error(message);
|
|
37
331
|
}
|
|
38
332
|
if (!emitterEventNames.includes(webhookNameOrNames)) {
|
|
39
|
-
state.log.warn(
|
|
333
|
+
state.log.warn(
|
|
334
|
+
`"${webhookNameOrNames}" is not a known webhook name (https://developer.github.com/v3/activity/events/types/)`
|
|
335
|
+
);
|
|
40
336
|
}
|
|
41
337
|
handleEventHandlers(state, webhookNameOrNames, handler);
|
|
42
338
|
}
|
|
@@ -47,26 +343,27 @@ function receiverOnError(state, handler) {
|
|
|
47
343
|
handleEventHandlers(state, "error", handler);
|
|
48
344
|
}
|
|
49
345
|
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
346
|
+
// pkg/dist-src/event-handler/receive.js
|
|
347
|
+
var import_aggregate_error = __toESM(require("aggregate-error"));
|
|
348
|
+
|
|
349
|
+
// pkg/dist-src/event-handler/wrap-error-handler.js
|
|
53
350
|
function wrapErrorHandler(handler, error) {
|
|
54
351
|
let returnValue;
|
|
55
352
|
try {
|
|
56
353
|
returnValue = handler(error);
|
|
57
|
-
} catch (
|
|
354
|
+
} catch (error2) {
|
|
58
355
|
console.log('FATAL: Error occurred in "error" event handler');
|
|
59
|
-
console.log(
|
|
356
|
+
console.log(error2);
|
|
60
357
|
}
|
|
61
358
|
if (returnValue && returnValue.catch) {
|
|
62
|
-
returnValue.catch(
|
|
359
|
+
returnValue.catch((error2) => {
|
|
63
360
|
console.log('FATAL: Error occurred in "error" event handler');
|
|
64
|
-
console.log(
|
|
361
|
+
console.log(error2);
|
|
65
362
|
});
|
|
66
363
|
}
|
|
67
364
|
}
|
|
68
365
|
|
|
69
|
-
//
|
|
366
|
+
// pkg/dist-src/event-handler/receive.js
|
|
70
367
|
function getHooks(state, eventPayloadAction, eventName) {
|
|
71
368
|
const hooks = [state.hooks[eventName], state.hooks["*"]];
|
|
72
369
|
if (eventPayloadAction) {
|
|
@@ -74,64 +371,65 @@ function getHooks(state, eventPayloadAction, eventName) {
|
|
|
74
371
|
}
|
|
75
372
|
return [].concat(...hooks.filter(Boolean));
|
|
76
373
|
}
|
|
77
|
-
// main handler function
|
|
78
374
|
function receiverHandle(state, event) {
|
|
79
375
|
const errorHandlers = state.hooks.error || [];
|
|
80
376
|
if (event instanceof Error) {
|
|
81
|
-
const error = Object.assign(new
|
|
377
|
+
const error = Object.assign(new import_aggregate_error.default([event]), {
|
|
82
378
|
event,
|
|
83
379
|
errors: [event]
|
|
84
380
|
});
|
|
85
|
-
errorHandlers.forEach(handler => wrapErrorHandler(handler, error));
|
|
381
|
+
errorHandlers.forEach((handler) => wrapErrorHandler(handler, error));
|
|
86
382
|
return Promise.reject(error);
|
|
87
383
|
}
|
|
88
384
|
if (!event || !event.name) {
|
|
89
|
-
throw new
|
|
385
|
+
throw new import_aggregate_error.default(["Event name not passed"]);
|
|
90
386
|
}
|
|
91
387
|
if (!event.payload) {
|
|
92
|
-
throw new
|
|
388
|
+
throw new import_aggregate_error.default(["Event payload not passed"]);
|
|
93
389
|
}
|
|
94
|
-
|
|
95
|
-
|
|
390
|
+
const hooks = getHooks(
|
|
391
|
+
state,
|
|
392
|
+
"action" in event.payload ? event.payload.action : null,
|
|
393
|
+
event.name
|
|
394
|
+
);
|
|
96
395
|
if (hooks.length === 0) {
|
|
97
396
|
return Promise.resolve();
|
|
98
397
|
}
|
|
99
398
|
const errors = [];
|
|
100
|
-
const promises = hooks.map(handler => {
|
|
399
|
+
const promises = hooks.map((handler) => {
|
|
101
400
|
let promise = Promise.resolve(event);
|
|
102
401
|
if (state.transform) {
|
|
103
402
|
promise = promise.then(state.transform);
|
|
104
403
|
}
|
|
105
|
-
return promise.then(
|
|
106
|
-
return handler(
|
|
107
|
-
}).catch(error => errors.push(Object.assign(error, {
|
|
108
|
-
event
|
|
109
|
-
})));
|
|
404
|
+
return promise.then((event2) => {
|
|
405
|
+
return handler(event2);
|
|
406
|
+
}).catch((error) => errors.push(Object.assign(error, { event })));
|
|
110
407
|
});
|
|
111
408
|
return Promise.all(promises).then(() => {
|
|
112
409
|
if (errors.length === 0) {
|
|
113
410
|
return;
|
|
114
411
|
}
|
|
115
|
-
const error = new
|
|
412
|
+
const error = new import_aggregate_error.default(errors);
|
|
116
413
|
Object.assign(error, {
|
|
117
414
|
event,
|
|
118
415
|
errors
|
|
119
416
|
});
|
|
120
|
-
errorHandlers.forEach(handler => wrapErrorHandler(handler, error));
|
|
417
|
+
errorHandlers.forEach((handler) => wrapErrorHandler(handler, error));
|
|
121
418
|
throw error;
|
|
122
419
|
});
|
|
123
420
|
}
|
|
124
421
|
|
|
422
|
+
// pkg/dist-src/event-handler/remove-listener.js
|
|
125
423
|
function removeListener(state, webhookNameOrNames, handler) {
|
|
126
424
|
if (Array.isArray(webhookNameOrNames)) {
|
|
127
|
-
webhookNameOrNames.forEach(
|
|
425
|
+
webhookNameOrNames.forEach(
|
|
426
|
+
(webhookName) => removeListener(state, webhookName, handler)
|
|
427
|
+
);
|
|
128
428
|
return;
|
|
129
429
|
}
|
|
130
430
|
if (!state.hooks[webhookNameOrNames]) {
|
|
131
431
|
return;
|
|
132
432
|
}
|
|
133
|
-
// remove last hook that has been added, that way
|
|
134
|
-
// it behaves the same as removeListener
|
|
135
433
|
for (let i = state.hooks[webhookNameOrNames].length - 1; i >= 0; i--) {
|
|
136
434
|
if (state.hooks[webhookNameOrNames][i] === handler) {
|
|
137
435
|
state.hooks[webhookNameOrNames].splice(i, 1);
|
|
@@ -140,6 +438,7 @@ function removeListener(state, webhookNameOrNames, handler) {
|
|
|
140
438
|
}
|
|
141
439
|
}
|
|
142
440
|
|
|
441
|
+
// pkg/dist-src/event-handler/index.js
|
|
143
442
|
function createEventHandler(options) {
|
|
144
443
|
const state = {
|
|
145
444
|
hooks: {},
|
|
@@ -157,15 +456,24 @@ function createEventHandler(options) {
|
|
|
157
456
|
};
|
|
158
457
|
}
|
|
159
458
|
|
|
459
|
+
// pkg/dist-src/index.js
|
|
460
|
+
var import_webhooks_methods2 = require("@octokit/webhooks-methods");
|
|
461
|
+
|
|
462
|
+
// pkg/dist-src/verify-and-receive.js
|
|
463
|
+
var import_webhooks_methods = require("@octokit/webhooks-methods");
|
|
160
464
|
async function verifyAndReceive(state, event) {
|
|
161
|
-
|
|
162
|
-
|
|
465
|
+
const matchesSignature = await (0, import_webhooks_methods.verify)(
|
|
466
|
+
state.secret,
|
|
467
|
+
event.payload,
|
|
468
|
+
event.signature
|
|
469
|
+
);
|
|
163
470
|
if (!matchesSignature) {
|
|
164
|
-
const error = new Error(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
471
|
+
const error = new Error(
|
|
472
|
+
"[@octokit/webhooks] signature does not match event payload and secret"
|
|
473
|
+
);
|
|
474
|
+
return state.eventHandler.receive(
|
|
475
|
+
Object.assign(error, { event, status: 400 })
|
|
476
|
+
);
|
|
169
477
|
}
|
|
170
478
|
return state.eventHandler.receive({
|
|
171
479
|
id: event.id,
|
|
@@ -174,46 +482,52 @@ async function verifyAndReceive(state, event) {
|
|
|
174
482
|
});
|
|
175
483
|
}
|
|
176
484
|
|
|
177
|
-
|
|
178
|
-
|
|
485
|
+
// pkg/dist-src/middleware/node/get-missing-headers.js
|
|
486
|
+
var WEBHOOK_HEADERS = [
|
|
487
|
+
"x-github-event",
|
|
488
|
+
"x-hub-signature-256",
|
|
489
|
+
"x-github-delivery"
|
|
490
|
+
];
|
|
179
491
|
function getMissingHeaders(request) {
|
|
180
|
-
return WEBHOOK_HEADERS.filter(header => !(header in request.headers));
|
|
492
|
+
return WEBHOOK_HEADERS.filter((header) => !(header in request.headers));
|
|
181
493
|
}
|
|
182
494
|
|
|
183
|
-
//
|
|
495
|
+
// pkg/dist-src/middleware/node/get-payload.js
|
|
496
|
+
var import_aggregate_error2 = __toESM(require("aggregate-error"));
|
|
184
497
|
function getPayload(request) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (request.body) return Promise.resolve(request.body);
|
|
498
|
+
if (request.body)
|
|
499
|
+
return Promise.resolve(request.body);
|
|
188
500
|
return new Promise((resolve, reject) => {
|
|
189
501
|
let data = "";
|
|
190
502
|
request.setEncoding("utf8");
|
|
191
|
-
|
|
192
|
-
request.on("
|
|
193
|
-
request.on("data", chunk => data += chunk);
|
|
503
|
+
request.on("error", (error) => reject(new import_aggregate_error2.default([error])));
|
|
504
|
+
request.on("data", (chunk) => data += chunk);
|
|
194
505
|
request.on("end", () => {
|
|
195
506
|
try {
|
|
196
|
-
// Call JSON.parse() only to check if the payload is valid JSON
|
|
197
507
|
JSON.parse(data);
|
|
198
508
|
resolve(data);
|
|
199
509
|
} catch (error) {
|
|
200
510
|
error.message = "Invalid JSON";
|
|
201
511
|
error.status = 400;
|
|
202
|
-
reject(new
|
|
512
|
+
reject(new import_aggregate_error2.default([error]));
|
|
203
513
|
}
|
|
204
514
|
});
|
|
205
515
|
});
|
|
206
516
|
}
|
|
207
517
|
|
|
518
|
+
// pkg/dist-src/middleware/node/on-unhandled-request-default.js
|
|
208
519
|
function onUnhandledRequestDefault(request, response) {
|
|
209
520
|
response.writeHead(404, {
|
|
210
521
|
"content-type": "application/json"
|
|
211
522
|
});
|
|
212
|
-
response.end(
|
|
213
|
-
|
|
214
|
-
|
|
523
|
+
response.end(
|
|
524
|
+
JSON.stringify({
|
|
525
|
+
error: `Unknown route: ${request.method} ${request.url}`
|
|
526
|
+
})
|
|
527
|
+
);
|
|
215
528
|
}
|
|
216
529
|
|
|
530
|
+
// pkg/dist-src/middleware/node/middleware.js
|
|
217
531
|
async function middleware(webhooks, options, request, response, next) {
|
|
218
532
|
let pathname;
|
|
219
533
|
try {
|
|
@@ -222,29 +536,30 @@ async function middleware(webhooks, options, request, response, next) {
|
|
|
222
536
|
response.writeHead(422, {
|
|
223
537
|
"content-type": "application/json"
|
|
224
538
|
});
|
|
225
|
-
response.end(
|
|
226
|
-
|
|
227
|
-
|
|
539
|
+
response.end(
|
|
540
|
+
JSON.stringify({
|
|
541
|
+
error: `Request URL could not be parsed: ${request.url}`
|
|
542
|
+
})
|
|
543
|
+
);
|
|
228
544
|
return true;
|
|
229
545
|
}
|
|
230
546
|
if (pathname !== options.path) {
|
|
231
|
-
next
|
|
547
|
+
next == null ? void 0 : next();
|
|
232
548
|
return false;
|
|
233
549
|
} else if (request.method !== "POST") {
|
|
234
550
|
onUnhandledRequestDefault(request, response);
|
|
235
551
|
return true;
|
|
236
552
|
}
|
|
237
|
-
// Check if the Content-Type header is `application/json` and allow for charset to be specified in it
|
|
238
|
-
// Otherwise, return a 415 Unsupported Media Type error
|
|
239
|
-
// See https://github.com/octokit/webhooks.js/issues/158
|
|
240
553
|
if (!request.headers["content-type"] || !request.headers["content-type"].startsWith("application/json")) {
|
|
241
554
|
response.writeHead(415, {
|
|
242
555
|
"content-type": "application/json",
|
|
243
556
|
accept: "application/json"
|
|
244
557
|
});
|
|
245
|
-
response.end(
|
|
246
|
-
|
|
247
|
-
|
|
558
|
+
response.end(
|
|
559
|
+
JSON.stringify({
|
|
560
|
+
error: `Unsupported "Content-Type" header value. Must be "application/json"`
|
|
561
|
+
})
|
|
562
|
+
);
|
|
248
563
|
return true;
|
|
249
564
|
}
|
|
250
565
|
const missingHeaders = getMissingHeaders(request).join(", ");
|
|
@@ -252,49 +567,54 @@ async function middleware(webhooks, options, request, response, next) {
|
|
|
252
567
|
response.writeHead(400, {
|
|
253
568
|
"content-type": "application/json"
|
|
254
569
|
});
|
|
255
|
-
response.end(
|
|
256
|
-
|
|
257
|
-
|
|
570
|
+
response.end(
|
|
571
|
+
JSON.stringify({
|
|
572
|
+
error: `Required headers missing: ${missingHeaders}`
|
|
573
|
+
})
|
|
574
|
+
);
|
|
258
575
|
return true;
|
|
259
576
|
}
|
|
260
577
|
const eventName = request.headers["x-github-event"];
|
|
261
578
|
const signatureSHA256 = request.headers["x-hub-signature-256"];
|
|
262
579
|
const id = request.headers["x-github-delivery"];
|
|
263
580
|
options.log.debug(`${eventName} event received (id: ${id})`);
|
|
264
|
-
// GitHub will abort the request if it does not receive a response within 10s
|
|
265
|
-
// See https://github.com/octokit/webhooks.js/issues/185
|
|
266
581
|
let didTimeout = false;
|
|
267
582
|
const timeout = setTimeout(() => {
|
|
268
583
|
didTimeout = true;
|
|
269
584
|
response.statusCode = 202;
|
|
270
585
|
response.end("still processing\n");
|
|
271
|
-
},
|
|
586
|
+
}, 9e3).unref();
|
|
272
587
|
try {
|
|
273
588
|
const payload = await getPayload(request);
|
|
274
589
|
await webhooks.verifyAndReceive({
|
|
275
|
-
id
|
|
590
|
+
id,
|
|
276
591
|
name: eventName,
|
|
277
592
|
payload,
|
|
278
593
|
signature: signatureSHA256
|
|
279
594
|
});
|
|
280
595
|
clearTimeout(timeout);
|
|
281
|
-
if (didTimeout)
|
|
596
|
+
if (didTimeout)
|
|
597
|
+
return true;
|
|
282
598
|
response.end("ok\n");
|
|
283
599
|
return true;
|
|
284
600
|
} catch (error) {
|
|
285
601
|
clearTimeout(timeout);
|
|
286
|
-
if (didTimeout)
|
|
602
|
+
if (didTimeout)
|
|
603
|
+
return true;
|
|
287
604
|
const err = Array.from(error)[0];
|
|
288
605
|
const errorMessage = err.message ? `${err.name}: ${err.message}` : "Error: An Unspecified error occurred";
|
|
289
606
|
response.statusCode = typeof err.status !== "undefined" ? err.status : 500;
|
|
290
607
|
options.log.error(error);
|
|
291
|
-
response.end(
|
|
292
|
-
|
|
293
|
-
|
|
608
|
+
response.end(
|
|
609
|
+
JSON.stringify({
|
|
610
|
+
error: errorMessage
|
|
611
|
+
})
|
|
612
|
+
);
|
|
294
613
|
return true;
|
|
295
614
|
}
|
|
296
615
|
}
|
|
297
616
|
|
|
617
|
+
// pkg/dist-src/middleware/node/index.js
|
|
298
618
|
function createNodeMiddleware(webhooks, {
|
|
299
619
|
path = "/api/github/webhooks",
|
|
300
620
|
log = createLogger()
|
|
@@ -305,8 +625,8 @@ function createNodeMiddleware(webhooks, {
|
|
|
305
625
|
});
|
|
306
626
|
}
|
|
307
627
|
|
|
308
|
-
//
|
|
309
|
-
|
|
628
|
+
// pkg/dist-src/index.js
|
|
629
|
+
var Webhooks = class {
|
|
310
630
|
constructor(options) {
|
|
311
631
|
if (!options || !options.secret) {
|
|
312
632
|
throw new Error("[@octokit/webhooks] options.secret required");
|
|
@@ -317,8 +637,8 @@ class Webhooks {
|
|
|
317
637
|
hooks: {},
|
|
318
638
|
log: createLogger(options.log)
|
|
319
639
|
};
|
|
320
|
-
this.sign =
|
|
321
|
-
this.verify =
|
|
640
|
+
this.sign = import_webhooks_methods2.sign.bind(null, options.secret);
|
|
641
|
+
this.verify = import_webhooks_methods2.verify.bind(null, options.secret);
|
|
322
642
|
this.on = state.eventHandler.on;
|
|
323
643
|
this.onAny = state.eventHandler.onAny;
|
|
324
644
|
this.onError = state.eventHandler.onError;
|
|
@@ -326,10 +646,11 @@ class Webhooks {
|
|
|
326
646
|
this.receive = state.eventHandler.receive;
|
|
327
647
|
this.verifyAndReceive = verifyAndReceive.bind(null, state);
|
|
328
648
|
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
exports
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
649
|
+
};
|
|
650
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
651
|
+
0 && (module.exports = {
|
|
652
|
+
Webhooks,
|
|
653
|
+
createEventHandler,
|
|
654
|
+
createNodeMiddleware,
|
|
655
|
+
emitterEventNames
|
|
656
|
+
});
|