@octokit/webhooks 10.7.0 → 10.7.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.
- package/dist-node/index.js +440 -106
- package/dist-node/index.js.map +6 -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 +260 -259
- package/dist-src/index.js +40 -32
- package/dist-src/middleware/node/get-missing-headers.js +8 -6
- package/dist-src/middleware/node/get-payload.js +26 -27
- package/dist-src/middleware/node/index.js +19 -10
- package/dist-src/middleware/node/middleware.js +86 -86
- package/dist-src/middleware/node/on-unhandled-request-default.js +12 -7
- package/dist-src/sign.js +8 -2
- package/dist-src/to-normalized-json-string.js +8 -8
- package/dist-src/verify-and-receive.js +22 -16
- package/dist-src/verify.js +9 -2
- package/dist-types/event-handler/on.d.ts +1 -1
- package/dist-types/event-handler/remove-listener.d.ts +1 -1
- package/dist-types/index.d.ts +2 -2
- package/dist-types/middleware/node/get-payload.d.ts +1 -1
- 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 +606 -571
- package/dist-web/index.js.map +6 -1
- package/package.json +17 -19
- 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,314 @@
|
|
|
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.dequeued",
|
|
218
|
+
"pull_request.edited",
|
|
219
|
+
"pull_request.labeled",
|
|
220
|
+
"pull_request.locked",
|
|
221
|
+
"pull_request.opened",
|
|
222
|
+
"pull_request.queued",
|
|
223
|
+
"pull_request.ready_for_review",
|
|
224
|
+
"pull_request.reopened",
|
|
225
|
+
"pull_request.review_request_removed",
|
|
226
|
+
"pull_request.review_requested",
|
|
227
|
+
"pull_request.synchronize",
|
|
228
|
+
"pull_request.unassigned",
|
|
229
|
+
"pull_request.unlabeled",
|
|
230
|
+
"pull_request.unlocked",
|
|
231
|
+
"pull_request_review",
|
|
232
|
+
"pull_request_review.dismissed",
|
|
233
|
+
"pull_request_review.edited",
|
|
234
|
+
"pull_request_review.submitted",
|
|
235
|
+
"pull_request_review_comment",
|
|
236
|
+
"pull_request_review_comment.created",
|
|
237
|
+
"pull_request_review_comment.deleted",
|
|
238
|
+
"pull_request_review_comment.edited",
|
|
239
|
+
"pull_request_review_thread",
|
|
240
|
+
"pull_request_review_thread.resolved",
|
|
241
|
+
"pull_request_review_thread.unresolved",
|
|
242
|
+
"push",
|
|
243
|
+
"registry_package",
|
|
244
|
+
"registry_package.published",
|
|
245
|
+
"registry_package.updated",
|
|
246
|
+
"release",
|
|
247
|
+
"release.created",
|
|
248
|
+
"release.deleted",
|
|
249
|
+
"release.edited",
|
|
250
|
+
"release.prereleased",
|
|
251
|
+
"release.published",
|
|
252
|
+
"release.released",
|
|
253
|
+
"release.unpublished",
|
|
254
|
+
"repository",
|
|
255
|
+
"repository.archived",
|
|
256
|
+
"repository.created",
|
|
257
|
+
"repository.deleted",
|
|
258
|
+
"repository.edited",
|
|
259
|
+
"repository.privatized",
|
|
260
|
+
"repository.publicized",
|
|
261
|
+
"repository.renamed",
|
|
262
|
+
"repository.transferred",
|
|
263
|
+
"repository.unarchived",
|
|
264
|
+
"repository_dispatch",
|
|
265
|
+
"repository_import",
|
|
266
|
+
"repository_vulnerability_alert",
|
|
267
|
+
"repository_vulnerability_alert.create",
|
|
268
|
+
"repository_vulnerability_alert.dismiss",
|
|
269
|
+
"repository_vulnerability_alert.reopen",
|
|
270
|
+
"repository_vulnerability_alert.resolve",
|
|
271
|
+
"secret_scanning_alert",
|
|
272
|
+
"secret_scanning_alert.created",
|
|
273
|
+
"secret_scanning_alert.reopened",
|
|
274
|
+
"secret_scanning_alert.resolved",
|
|
275
|
+
"security_advisory",
|
|
276
|
+
"security_advisory.performed",
|
|
277
|
+
"security_advisory.published",
|
|
278
|
+
"security_advisory.updated",
|
|
279
|
+
"security_advisory.withdrawn",
|
|
280
|
+
"sponsorship",
|
|
281
|
+
"sponsorship.cancelled",
|
|
282
|
+
"sponsorship.created",
|
|
283
|
+
"sponsorship.edited",
|
|
284
|
+
"sponsorship.pending_cancellation",
|
|
285
|
+
"sponsorship.pending_tier_change",
|
|
286
|
+
"sponsorship.tier_changed",
|
|
287
|
+
"star",
|
|
288
|
+
"star.created",
|
|
289
|
+
"star.deleted",
|
|
290
|
+
"status",
|
|
291
|
+
"team",
|
|
292
|
+
"team.added_to_repository",
|
|
293
|
+
"team.created",
|
|
294
|
+
"team.deleted",
|
|
295
|
+
"team.edited",
|
|
296
|
+
"team.removed_from_repository",
|
|
297
|
+
"team_add",
|
|
298
|
+
"watch",
|
|
299
|
+
"watch.started",
|
|
300
|
+
"workflow_dispatch",
|
|
301
|
+
"workflow_job",
|
|
302
|
+
"workflow_job.completed",
|
|
303
|
+
"workflow_job.in_progress",
|
|
304
|
+
"workflow_job.queued",
|
|
305
|
+
"workflow_run",
|
|
306
|
+
"workflow_run.completed",
|
|
307
|
+
"workflow_run.in_progress",
|
|
308
|
+
"workflow_run.requested"
|
|
309
|
+
];
|
|
21
310
|
|
|
311
|
+
// pkg/dist-src/event-handler/on.js
|
|
22
312
|
function handleEventHandlers(state, webhookName, handler) {
|
|
23
313
|
if (!state.hooks[webhookName]) {
|
|
24
314
|
state.hooks[webhookName] = [];
|
|
@@ -27,7 +317,9 @@ function handleEventHandlers(state, webhookName, handler) {
|
|
|
27
317
|
}
|
|
28
318
|
function receiverOn(state, webhookNameOrNames, handler) {
|
|
29
319
|
if (Array.isArray(webhookNameOrNames)) {
|
|
30
|
-
webhookNameOrNames.forEach(
|
|
320
|
+
webhookNameOrNames.forEach(
|
|
321
|
+
(webhookName) => receiverOn(state, webhookName, handler)
|
|
322
|
+
);
|
|
31
323
|
return;
|
|
32
324
|
}
|
|
33
325
|
if (["*", "error"].includes(webhookNameOrNames)) {
|
|
@@ -36,7 +328,9 @@ function receiverOn(state, webhookNameOrNames, handler) {
|
|
|
36
328
|
throw new Error(message);
|
|
37
329
|
}
|
|
38
330
|
if (!emitterEventNames.includes(webhookNameOrNames)) {
|
|
39
|
-
state.log.warn(
|
|
331
|
+
state.log.warn(
|
|
332
|
+
`"${webhookNameOrNames}" is not a known webhook name (https://developer.github.com/v3/activity/events/types/)`
|
|
333
|
+
);
|
|
40
334
|
}
|
|
41
335
|
handleEventHandlers(state, webhookNameOrNames, handler);
|
|
42
336
|
}
|
|
@@ -47,26 +341,27 @@ function receiverOnError(state, handler) {
|
|
|
47
341
|
handleEventHandlers(state, "error", handler);
|
|
48
342
|
}
|
|
49
343
|
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
344
|
+
// pkg/dist-src/event-handler/receive.js
|
|
345
|
+
var import_aggregate_error = __toESM(require("aggregate-error"));
|
|
346
|
+
|
|
347
|
+
// pkg/dist-src/event-handler/wrap-error-handler.js
|
|
53
348
|
function wrapErrorHandler(handler, error) {
|
|
54
349
|
let returnValue;
|
|
55
350
|
try {
|
|
56
351
|
returnValue = handler(error);
|
|
57
|
-
} catch (
|
|
352
|
+
} catch (error2) {
|
|
58
353
|
console.log('FATAL: Error occurred in "error" event handler');
|
|
59
|
-
console.log(
|
|
354
|
+
console.log(error2);
|
|
60
355
|
}
|
|
61
356
|
if (returnValue && returnValue.catch) {
|
|
62
|
-
returnValue.catch(
|
|
357
|
+
returnValue.catch((error2) => {
|
|
63
358
|
console.log('FATAL: Error occurred in "error" event handler');
|
|
64
|
-
console.log(
|
|
359
|
+
console.log(error2);
|
|
65
360
|
});
|
|
66
361
|
}
|
|
67
362
|
}
|
|
68
363
|
|
|
69
|
-
//
|
|
364
|
+
// pkg/dist-src/event-handler/receive.js
|
|
70
365
|
function getHooks(state, eventPayloadAction, eventName) {
|
|
71
366
|
const hooks = [state.hooks[eventName], state.hooks["*"]];
|
|
72
367
|
if (eventPayloadAction) {
|
|
@@ -74,64 +369,65 @@ function getHooks(state, eventPayloadAction, eventName) {
|
|
|
74
369
|
}
|
|
75
370
|
return [].concat(...hooks.filter(Boolean));
|
|
76
371
|
}
|
|
77
|
-
// main handler function
|
|
78
372
|
function receiverHandle(state, event) {
|
|
79
373
|
const errorHandlers = state.hooks.error || [];
|
|
80
374
|
if (event instanceof Error) {
|
|
81
|
-
const error = Object.assign(new
|
|
375
|
+
const error = Object.assign(new import_aggregate_error.default([event]), {
|
|
82
376
|
event,
|
|
83
377
|
errors: [event]
|
|
84
378
|
});
|
|
85
|
-
errorHandlers.forEach(handler => wrapErrorHandler(handler, error));
|
|
379
|
+
errorHandlers.forEach((handler) => wrapErrorHandler(handler, error));
|
|
86
380
|
return Promise.reject(error);
|
|
87
381
|
}
|
|
88
382
|
if (!event || !event.name) {
|
|
89
|
-
throw new
|
|
383
|
+
throw new import_aggregate_error.default(["Event name not passed"]);
|
|
90
384
|
}
|
|
91
385
|
if (!event.payload) {
|
|
92
|
-
throw new
|
|
386
|
+
throw new import_aggregate_error.default(["Event payload not passed"]);
|
|
93
387
|
}
|
|
94
|
-
|
|
95
|
-
|
|
388
|
+
const hooks = getHooks(
|
|
389
|
+
state,
|
|
390
|
+
"action" in event.payload ? event.payload.action : null,
|
|
391
|
+
event.name
|
|
392
|
+
);
|
|
96
393
|
if (hooks.length === 0) {
|
|
97
394
|
return Promise.resolve();
|
|
98
395
|
}
|
|
99
396
|
const errors = [];
|
|
100
|
-
const promises = hooks.map(handler => {
|
|
397
|
+
const promises = hooks.map((handler) => {
|
|
101
398
|
let promise = Promise.resolve(event);
|
|
102
399
|
if (state.transform) {
|
|
103
400
|
promise = promise.then(state.transform);
|
|
104
401
|
}
|
|
105
|
-
return promise.then(
|
|
106
|
-
return handler(
|
|
107
|
-
}).catch(error => errors.push(Object.assign(error, {
|
|
108
|
-
event
|
|
109
|
-
})));
|
|
402
|
+
return promise.then((event2) => {
|
|
403
|
+
return handler(event2);
|
|
404
|
+
}).catch((error) => errors.push(Object.assign(error, { event })));
|
|
110
405
|
});
|
|
111
406
|
return Promise.all(promises).then(() => {
|
|
112
407
|
if (errors.length === 0) {
|
|
113
408
|
return;
|
|
114
409
|
}
|
|
115
|
-
const error = new
|
|
410
|
+
const error = new import_aggregate_error.default(errors);
|
|
116
411
|
Object.assign(error, {
|
|
117
412
|
event,
|
|
118
413
|
errors
|
|
119
414
|
});
|
|
120
|
-
errorHandlers.forEach(handler => wrapErrorHandler(handler, error));
|
|
415
|
+
errorHandlers.forEach((handler) => wrapErrorHandler(handler, error));
|
|
121
416
|
throw error;
|
|
122
417
|
});
|
|
123
418
|
}
|
|
124
419
|
|
|
420
|
+
// pkg/dist-src/event-handler/remove-listener.js
|
|
125
421
|
function removeListener(state, webhookNameOrNames, handler) {
|
|
126
422
|
if (Array.isArray(webhookNameOrNames)) {
|
|
127
|
-
webhookNameOrNames.forEach(
|
|
423
|
+
webhookNameOrNames.forEach(
|
|
424
|
+
(webhookName) => removeListener(state, webhookName, handler)
|
|
425
|
+
);
|
|
128
426
|
return;
|
|
129
427
|
}
|
|
130
428
|
if (!state.hooks[webhookNameOrNames]) {
|
|
131
429
|
return;
|
|
132
430
|
}
|
|
133
|
-
// remove last hook that has been added, that way
|
|
134
|
-
// it behaves the same as removeListener
|
|
135
431
|
for (let i = state.hooks[webhookNameOrNames].length - 1; i >= 0; i--) {
|
|
136
432
|
if (state.hooks[webhookNameOrNames][i] === handler) {
|
|
137
433
|
state.hooks[webhookNameOrNames].splice(i, 1);
|
|
@@ -140,6 +436,7 @@ function removeListener(state, webhookNameOrNames, handler) {
|
|
|
140
436
|
}
|
|
141
437
|
}
|
|
142
438
|
|
|
439
|
+
// pkg/dist-src/event-handler/index.js
|
|
143
440
|
function createEventHandler(options) {
|
|
144
441
|
const state = {
|
|
145
442
|
hooks: {},
|
|
@@ -157,33 +454,50 @@ function createEventHandler(options) {
|
|
|
157
454
|
};
|
|
158
455
|
}
|
|
159
456
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
457
|
+
// pkg/dist-src/sign.js
|
|
458
|
+
var import_webhooks_methods = require("@octokit/webhooks-methods");
|
|
459
|
+
|
|
460
|
+
// pkg/dist-src/to-normalized-json-string.js
|
|
163
461
|
function toNormalizedJsonString(payload) {
|
|
164
462
|
const payloadString = JSON.stringify(payload);
|
|
165
|
-
return payloadString.replace(/[^\\]\\u[\da-f]{4}/g, s => {
|
|
463
|
+
return payloadString.replace(/[^\\]\\u[\da-f]{4}/g, (s) => {
|
|
166
464
|
return s.substr(0, 3) + s.substr(3).toUpperCase();
|
|
167
465
|
});
|
|
168
466
|
}
|
|
169
467
|
|
|
468
|
+
// pkg/dist-src/sign.js
|
|
170
469
|
async function sign(secret, payload) {
|
|
171
|
-
return
|
|
470
|
+
return (0, import_webhooks_methods.sign)(
|
|
471
|
+
secret,
|
|
472
|
+
typeof payload === "string" ? payload : toNormalizedJsonString(payload)
|
|
473
|
+
);
|
|
172
474
|
}
|
|
173
475
|
|
|
476
|
+
// pkg/dist-src/verify.js
|
|
477
|
+
var import_webhooks_methods2 = require("@octokit/webhooks-methods");
|
|
174
478
|
async function verify(secret, payload, signature) {
|
|
175
|
-
return
|
|
479
|
+
return (0, import_webhooks_methods2.verify)(
|
|
480
|
+
secret,
|
|
481
|
+
typeof payload === "string" ? payload : toNormalizedJsonString(payload),
|
|
482
|
+
signature
|
|
483
|
+
);
|
|
176
484
|
}
|
|
177
485
|
|
|
486
|
+
// pkg/dist-src/verify-and-receive.js
|
|
487
|
+
var import_webhooks_methods3 = require("@octokit/webhooks-methods");
|
|
178
488
|
async function verifyAndReceive(state, event) {
|
|
179
|
-
|
|
180
|
-
|
|
489
|
+
const matchesSignature = await (0, import_webhooks_methods3.verify)(
|
|
490
|
+
state.secret,
|
|
491
|
+
typeof event.payload === "object" ? toNormalizedJsonString(event.payload) : event.payload,
|
|
492
|
+
event.signature
|
|
493
|
+
);
|
|
181
494
|
if (!matchesSignature) {
|
|
182
|
-
const error = new Error(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
495
|
+
const error = new Error(
|
|
496
|
+
"[@octokit/webhooks] signature does not match event payload and secret"
|
|
497
|
+
);
|
|
498
|
+
return state.eventHandler.receive(
|
|
499
|
+
Object.assign(error, { event, status: 400 })
|
|
500
|
+
);
|
|
187
501
|
}
|
|
188
502
|
return state.eventHandler.receive({
|
|
189
503
|
id: event.id,
|
|
@@ -192,42 +506,46 @@ async function verifyAndReceive(state, event) {
|
|
|
192
506
|
});
|
|
193
507
|
}
|
|
194
508
|
|
|
195
|
-
|
|
196
|
-
|
|
509
|
+
// pkg/dist-src/middleware/node/get-missing-headers.js
|
|
510
|
+
var WEBHOOK_HEADERS = [
|
|
511
|
+
"x-github-event",
|
|
512
|
+
"x-hub-signature-256",
|
|
513
|
+
"x-github-delivery"
|
|
514
|
+
];
|
|
197
515
|
function getMissingHeaders(request) {
|
|
198
|
-
return WEBHOOK_HEADERS.filter(header => !(header in request.headers));
|
|
516
|
+
return WEBHOOK_HEADERS.filter((header) => !(header in request.headers));
|
|
199
517
|
}
|
|
200
518
|
|
|
201
|
-
//
|
|
519
|
+
// pkg/dist-src/middleware/node/get-payload.js
|
|
520
|
+
var import_aggregate_error2 = __toESM(require("aggregate-error"));
|
|
202
521
|
function getPayload(request) {
|
|
203
|
-
// If request.body already exists we can stop here
|
|
204
|
-
// See https://github.com/octokit/webhooks.js/pull/23
|
|
205
522
|
if (request.body) {
|
|
206
523
|
if (typeof request.body !== "string") {
|
|
207
|
-
console.warn(
|
|
524
|
+
console.warn(
|
|
525
|
+
"[@octokit/webhooks] Passing the payload as a JSON object in `request.body` is deprecated and will be removed in a future release of `@octokit/webhooks`, please pass it as a a `string` instead."
|
|
526
|
+
);
|
|
208
527
|
}
|
|
209
528
|
return Promise.resolve(request.body);
|
|
210
529
|
}
|
|
211
530
|
return new Promise((resolve, reject) => {
|
|
212
531
|
let data = "";
|
|
213
532
|
request.setEncoding("utf8");
|
|
214
|
-
|
|
215
|
-
request.on("
|
|
216
|
-
request.on("data", chunk => data += chunk);
|
|
533
|
+
request.on("error", (error) => reject(new import_aggregate_error2.default([error])));
|
|
534
|
+
request.on("data", (chunk) => data += chunk);
|
|
217
535
|
request.on("end", () => {
|
|
218
536
|
try {
|
|
219
|
-
// Call JSON.parse() only to check if the payload is valid JSON
|
|
220
537
|
JSON.parse(data);
|
|
221
538
|
resolve(data);
|
|
222
539
|
} catch (error) {
|
|
223
540
|
error.message = "Invalid JSON";
|
|
224
541
|
error.status = 400;
|
|
225
|
-
reject(new
|
|
542
|
+
reject(new import_aggregate_error2.default([error]));
|
|
226
543
|
}
|
|
227
544
|
});
|
|
228
545
|
});
|
|
229
546
|
}
|
|
230
547
|
|
|
548
|
+
// pkg/dist-src/middleware/node/middleware.js
|
|
231
549
|
async function middleware(webhooks, options, request, response, next) {
|
|
232
550
|
let pathname;
|
|
233
551
|
try {
|
|
@@ -236,9 +554,11 @@ async function middleware(webhooks, options, request, response, next) {
|
|
|
236
554
|
response.writeHead(422, {
|
|
237
555
|
"content-type": "application/json"
|
|
238
556
|
});
|
|
239
|
-
response.end(
|
|
240
|
-
|
|
241
|
-
|
|
557
|
+
response.end(
|
|
558
|
+
JSON.stringify({
|
|
559
|
+
error: `Request URL could not be parsed: ${request.url}`
|
|
560
|
+
})
|
|
561
|
+
);
|
|
242
562
|
return;
|
|
243
563
|
}
|
|
244
564
|
const isUnknownRoute = request.method !== "POST" || pathname !== options.path;
|
|
@@ -250,17 +570,16 @@ async function middleware(webhooks, options, request, response, next) {
|
|
|
250
570
|
return options.onUnhandledRequest(request, response);
|
|
251
571
|
}
|
|
252
572
|
}
|
|
253
|
-
// Check if the Content-Type header is `application/json` and allow for charset to be specified in it
|
|
254
|
-
// Otherwise, return a 415 Unsupported Media Type error
|
|
255
|
-
// See https://github.com/octokit/webhooks.js/issues/158
|
|
256
573
|
if (!request.headers["content-type"] || !request.headers["content-type"].startsWith("application/json")) {
|
|
257
574
|
response.writeHead(415, {
|
|
258
575
|
"content-type": "application/json",
|
|
259
576
|
accept: "application/json"
|
|
260
577
|
});
|
|
261
|
-
response.end(
|
|
262
|
-
|
|
263
|
-
|
|
578
|
+
response.end(
|
|
579
|
+
JSON.stringify({
|
|
580
|
+
error: `Unsupported "Content-Type" header value. Must be "application/json"`
|
|
581
|
+
})
|
|
582
|
+
);
|
|
264
583
|
return;
|
|
265
584
|
}
|
|
266
585
|
const missingHeaders = getMissingHeaders(request).join(", ");
|
|
@@ -268,63 +587,73 @@ async function middleware(webhooks, options, request, response, next) {
|
|
|
268
587
|
response.writeHead(400, {
|
|
269
588
|
"content-type": "application/json"
|
|
270
589
|
});
|
|
271
|
-
response.end(
|
|
272
|
-
|
|
273
|
-
|
|
590
|
+
response.end(
|
|
591
|
+
JSON.stringify({
|
|
592
|
+
error: `Required headers missing: ${missingHeaders}`
|
|
593
|
+
})
|
|
594
|
+
);
|
|
274
595
|
return;
|
|
275
596
|
}
|
|
276
597
|
const eventName = request.headers["x-github-event"];
|
|
277
598
|
const signatureSHA256 = request.headers["x-hub-signature-256"];
|
|
278
599
|
const id = request.headers["x-github-delivery"];
|
|
279
600
|
options.log.debug(`${eventName} event received (id: ${id})`);
|
|
280
|
-
// GitHub will abort the request if it does not receive a response within 10s
|
|
281
|
-
// See https://github.com/octokit/webhooks.js/issues/185
|
|
282
601
|
let didTimeout = false;
|
|
283
602
|
const timeout = setTimeout(() => {
|
|
284
603
|
didTimeout = true;
|
|
285
604
|
response.statusCode = 202;
|
|
286
605
|
response.end("still processing\n");
|
|
287
|
-
},
|
|
606
|
+
}, 9e3).unref();
|
|
288
607
|
try {
|
|
289
608
|
const payload = await getPayload(request);
|
|
290
609
|
await webhooks.verifyAndReceive({
|
|
291
|
-
id
|
|
610
|
+
id,
|
|
292
611
|
name: eventName,
|
|
293
|
-
payload
|
|
612
|
+
payload,
|
|
294
613
|
signature: signatureSHA256
|
|
295
614
|
});
|
|
296
615
|
clearTimeout(timeout);
|
|
297
|
-
if (didTimeout)
|
|
616
|
+
if (didTimeout)
|
|
617
|
+
return;
|
|
298
618
|
response.end("ok\n");
|
|
299
619
|
} catch (error) {
|
|
300
620
|
clearTimeout(timeout);
|
|
301
|
-
if (didTimeout)
|
|
621
|
+
if (didTimeout)
|
|
622
|
+
return;
|
|
302
623
|
const err = Array.from(error)[0];
|
|
303
624
|
const errorMessage = err.message ? `${err.name}: ${err.message}` : "Error: An Unspecified error occurred";
|
|
304
625
|
response.statusCode = typeof err.status !== "undefined" ? err.status : 500;
|
|
305
626
|
options.log.error(error);
|
|
306
|
-
response.end(
|
|
307
|
-
|
|
308
|
-
|
|
627
|
+
response.end(
|
|
628
|
+
JSON.stringify({
|
|
629
|
+
error: errorMessage
|
|
630
|
+
})
|
|
631
|
+
);
|
|
309
632
|
}
|
|
310
633
|
}
|
|
311
634
|
|
|
635
|
+
// pkg/dist-src/middleware/node/on-unhandled-request-default.js
|
|
312
636
|
function onUnhandledRequestDefault(request, response) {
|
|
313
637
|
response.writeHead(404, {
|
|
314
638
|
"content-type": "application/json"
|
|
315
639
|
});
|
|
316
|
-
response.end(
|
|
317
|
-
|
|
318
|
-
|
|
640
|
+
response.end(
|
|
641
|
+
JSON.stringify({
|
|
642
|
+
error: `Unknown route: ${request.method} ${request.url}`
|
|
643
|
+
})
|
|
644
|
+
);
|
|
319
645
|
}
|
|
320
646
|
|
|
647
|
+
// pkg/dist-src/middleware/node/index.js
|
|
321
648
|
function createNodeMiddleware(webhooks, {
|
|
322
649
|
path = "/api/github/webhooks",
|
|
323
650
|
onUnhandledRequest = onUnhandledRequestDefault,
|
|
324
651
|
log = createLogger()
|
|
325
652
|
} = {}) {
|
|
326
653
|
const deprecateOnUnhandledRequest = (request, response) => {
|
|
327
|
-
console.warn(
|
|
654
|
+
console.warn(
|
|
655
|
+
"[@octokit/webhooks] `onUnhandledRequest()` is deprecated and will be removed in a future release of `@octokit/webhooks`"
|
|
656
|
+
);
|
|
328
657
|
return onUnhandledRequest(request, response);
|
|
329
658
|
};
|
|
330
659
|
return middleware.bind(null, webhooks, {
|
|
@@ -334,8 +663,8 @@ function createNodeMiddleware(webhooks, {
|
|
|
334
663
|
});
|
|
335
664
|
}
|
|
336
665
|
|
|
337
|
-
//
|
|
338
|
-
|
|
666
|
+
// pkg/dist-src/index.js
|
|
667
|
+
var Webhooks = class {
|
|
339
668
|
constructor(options) {
|
|
340
669
|
if (!options || !options.secret) {
|
|
341
670
|
throw new Error("[@octokit/webhooks] options.secret required");
|
|
@@ -349,7 +678,9 @@ class Webhooks {
|
|
|
349
678
|
this.sign = sign.bind(null, options.secret);
|
|
350
679
|
this.verify = (eventPayload, signature) => {
|
|
351
680
|
if (typeof eventPayload === "object") {
|
|
352
|
-
console.warn(
|
|
681
|
+
console.warn(
|
|
682
|
+
"[@octokit/webhooks] Passing a JSON payload object to `verify()` is deprecated and the functionality will be removed in a future release of `@octokit/webhooks`"
|
|
683
|
+
);
|
|
353
684
|
}
|
|
354
685
|
return verify(options.secret, eventPayload, signature);
|
|
355
686
|
};
|
|
@@ -358,17 +689,20 @@ class Webhooks {
|
|
|
358
689
|
this.onError = state.eventHandler.onError;
|
|
359
690
|
this.removeListener = state.eventHandler.removeListener;
|
|
360
691
|
this.receive = state.eventHandler.receive;
|
|
361
|
-
this.verifyAndReceive =
|
|
362
|
-
if (typeof
|
|
363
|
-
console.warn(
|
|
692
|
+
this.verifyAndReceive = (options2) => {
|
|
693
|
+
if (typeof options2.payload === "object") {
|
|
694
|
+
console.warn(
|
|
695
|
+
"[@octokit/webhooks] Passing a JSON payload object to `verifyAndReceive()` is deprecated and the functionality will be removed in a future release of `@octokit/webhooks`"
|
|
696
|
+
);
|
|
364
697
|
}
|
|
365
|
-
return verifyAndReceive(state,
|
|
698
|
+
return verifyAndReceive(state, options2);
|
|
366
699
|
};
|
|
367
700
|
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
exports
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
701
|
+
};
|
|
702
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
703
|
+
0 && (module.exports = {
|
|
704
|
+
Webhooks,
|
|
705
|
+
createEventHandler,
|
|
706
|
+
createNodeMiddleware,
|
|
707
|
+
emitterEventNames
|
|
708
|
+
});
|