@octokit/webhooks 11.0.0-beta.1 → 11.0.0-beta.10
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 +68 -63
- package/dist-node/index.js +435 -150
- 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 -245
- package/dist-src/index.js +27 -24
- package/dist-src/middleware/node/get-missing-headers.js +8 -6
- package/dist-src/middleware/node/get-payload.js +21 -22
- package/dist-src/middleware/node/index.js +11 -5
- package/dist-src/middleware/node/middleware.js +87 -73
- package/dist-src/middleware/node/on-unhandled-request-default.js +12 -7
- package/dist-src/verify-and-receive.js +22 -17
- 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 +5 -5
- package/dist-types/middleware/node/get-missing-headers.d.ts +1 -1
- package/dist-types/middleware/node/get-payload.d.ts +2 -3
- package/dist-types/middleware/node/index.d.ts +2 -2
- package/dist-types/middleware/node/middleware.d.ts +4 -4
- package/dist-types/middleware/node/on-unhandled-request-default.d.ts +2 -2
- package/dist-types/middleware/node/types.d.ts +2 -2
- package/dist-types/types.d.ts +10 -13
- package/dist-types/verify-and-receive.d.ts +2 -2
- package/dist-web/index.js +564 -532
- package/dist-web/index.js.map +7 -1
- package/package.json +21 -23
- package/dist-src/middleware/node/types.js +0 -1
- package/dist-src/sign.js +0 -5
- package/dist-src/to-normalized-json-string.js +0 -9
- package/dist-src/types.js +0 -1
- package/dist-src/verify.js +0 -5
- package/dist-types/sign.d.ts +0 -1
- package/dist-types/to-normalized-json-string.d.ts +0 -4
- package/dist-types/verify.d.ts +0 -1
package/dist-node/index.js
CHANGED
|
@@ -1,48 +1,339 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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);
|
|
29
|
+
|
|
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);
|
|
39
|
+
|
|
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
|
-
|
|
21
|
-
|
|
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
|
+
];
|
|
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] = [];
|
|
25
317
|
}
|
|
26
|
-
|
|
27
318
|
state.hooks[webhookName].push(handler);
|
|
28
319
|
}
|
|
29
|
-
|
|
30
320
|
function receiverOn(state, webhookNameOrNames, handler) {
|
|
31
321
|
if (Array.isArray(webhookNameOrNames)) {
|
|
32
|
-
webhookNameOrNames.forEach(
|
|
322
|
+
webhookNameOrNames.forEach(
|
|
323
|
+
(webhookName) => receiverOn(state, webhookName, handler)
|
|
324
|
+
);
|
|
33
325
|
return;
|
|
34
326
|
}
|
|
35
|
-
|
|
36
327
|
if (["*", "error"].includes(webhookNameOrNames)) {
|
|
37
328
|
const webhookName = webhookNameOrNames === "*" ? "any" : webhookNameOrNames;
|
|
38
329
|
const message = `Using the "${webhookNameOrNames}" event with the regular Webhooks.on() function is not supported. Please use the Webhooks.on${webhookName.charAt(0).toUpperCase() + webhookName.slice(1)}() method instead`;
|
|
39
330
|
throw new Error(message);
|
|
40
331
|
}
|
|
41
|
-
|
|
42
332
|
if (!emitterEventNames.includes(webhookNameOrNames)) {
|
|
43
|
-
state.log.warn(
|
|
333
|
+
state.log.warn(
|
|
334
|
+
`"${webhookNameOrNames}" is not a known webhook name (https://developer.github.com/v3/activity/events/types/)`
|
|
335
|
+
);
|
|
44
336
|
}
|
|
45
|
-
|
|
46
337
|
handleEventHandlers(state, webhookNameOrNames, handler);
|
|
47
338
|
}
|
|
48
339
|
function receiverOnAny(state, handler) {
|
|
@@ -52,108 +343,93 @@ function receiverOnError(state, handler) {
|
|
|
52
343
|
handleEventHandlers(state, "error", handler);
|
|
53
344
|
}
|
|
54
345
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
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
|
|
58
350
|
function wrapErrorHandler(handler, error) {
|
|
59
351
|
let returnValue;
|
|
60
|
-
|
|
61
352
|
try {
|
|
62
353
|
returnValue = handler(error);
|
|
63
|
-
} catch (
|
|
354
|
+
} catch (error2) {
|
|
64
355
|
console.log('FATAL: Error occurred in "error" event handler');
|
|
65
|
-
console.log(
|
|
356
|
+
console.log(error2);
|
|
66
357
|
}
|
|
67
|
-
|
|
68
358
|
if (returnValue && returnValue.catch) {
|
|
69
|
-
returnValue.catch(
|
|
359
|
+
returnValue.catch((error2) => {
|
|
70
360
|
console.log('FATAL: Error occurred in "error" event handler');
|
|
71
|
-
console.log(
|
|
361
|
+
console.log(error2);
|
|
72
362
|
});
|
|
73
363
|
}
|
|
74
364
|
}
|
|
75
365
|
|
|
76
|
-
//
|
|
77
|
-
|
|
366
|
+
// pkg/dist-src/event-handler/receive.js
|
|
78
367
|
function getHooks(state, eventPayloadAction, eventName) {
|
|
79
368
|
const hooks = [state.hooks[eventName], state.hooks["*"]];
|
|
80
|
-
|
|
81
369
|
if (eventPayloadAction) {
|
|
82
370
|
hooks.unshift(state.hooks[`${eventName}.${eventPayloadAction}`]);
|
|
83
371
|
}
|
|
84
|
-
|
|
85
372
|
return [].concat(...hooks.filter(Boolean));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
373
|
+
}
|
|
89
374
|
function receiverHandle(state, event) {
|
|
90
375
|
const errorHandlers = state.hooks.error || [];
|
|
91
|
-
|
|
92
376
|
if (event instanceof Error) {
|
|
93
|
-
const error = Object.assign(new
|
|
377
|
+
const error = Object.assign(new import_aggregate_error.default([event]), {
|
|
94
378
|
event,
|
|
95
379
|
errors: [event]
|
|
96
380
|
});
|
|
97
|
-
errorHandlers.forEach(handler => wrapErrorHandler(handler, error));
|
|
381
|
+
errorHandlers.forEach((handler) => wrapErrorHandler(handler, error));
|
|
98
382
|
return Promise.reject(error);
|
|
99
383
|
}
|
|
100
|
-
|
|
101
384
|
if (!event || !event.name) {
|
|
102
|
-
throw new
|
|
385
|
+
throw new import_aggregate_error.default(["Event name not passed"]);
|
|
103
386
|
}
|
|
104
|
-
|
|
105
387
|
if (!event.payload) {
|
|
106
|
-
throw new
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
388
|
+
throw new import_aggregate_error.default(["Event payload not passed"]);
|
|
389
|
+
}
|
|
390
|
+
const hooks = getHooks(
|
|
391
|
+
state,
|
|
392
|
+
"action" in event.payload ? event.payload.action : null,
|
|
393
|
+
event.name
|
|
394
|
+
);
|
|
112
395
|
if (hooks.length === 0) {
|
|
113
396
|
return Promise.resolve();
|
|
114
397
|
}
|
|
115
|
-
|
|
116
398
|
const errors = [];
|
|
117
|
-
const promises = hooks.map(handler => {
|
|
399
|
+
const promises = hooks.map((handler) => {
|
|
118
400
|
let promise = Promise.resolve(event);
|
|
119
|
-
|
|
120
401
|
if (state.transform) {
|
|
121
402
|
promise = promise.then(state.transform);
|
|
122
403
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}).catch(error => errors.push(Object.assign(error, {
|
|
127
|
-
event
|
|
128
|
-
})));
|
|
404
|
+
return promise.then((event2) => {
|
|
405
|
+
return handler(event2);
|
|
406
|
+
}).catch((error) => errors.push(Object.assign(error, { event })));
|
|
129
407
|
});
|
|
130
408
|
return Promise.all(promises).then(() => {
|
|
131
409
|
if (errors.length === 0) {
|
|
132
410
|
return;
|
|
133
411
|
}
|
|
134
|
-
|
|
135
|
-
const error = new AggregateError(errors);
|
|
412
|
+
const error = new import_aggregate_error.default(errors);
|
|
136
413
|
Object.assign(error, {
|
|
137
414
|
event,
|
|
138
415
|
errors
|
|
139
416
|
});
|
|
140
|
-
errorHandlers.forEach(handler => wrapErrorHandler(handler, error));
|
|
417
|
+
errorHandlers.forEach((handler) => wrapErrorHandler(handler, error));
|
|
141
418
|
throw error;
|
|
142
419
|
});
|
|
143
420
|
}
|
|
144
421
|
|
|
422
|
+
// pkg/dist-src/event-handler/remove-listener.js
|
|
145
423
|
function removeListener(state, webhookNameOrNames, handler) {
|
|
146
424
|
if (Array.isArray(webhookNameOrNames)) {
|
|
147
|
-
webhookNameOrNames.forEach(
|
|
425
|
+
webhookNameOrNames.forEach(
|
|
426
|
+
(webhookName) => removeListener(state, webhookName, handler)
|
|
427
|
+
);
|
|
148
428
|
return;
|
|
149
429
|
}
|
|
150
|
-
|
|
151
430
|
if (!state.hooks[webhookNameOrNames]) {
|
|
152
431
|
return;
|
|
153
|
-
}
|
|
154
|
-
// it behaves the same as removeListener
|
|
155
|
-
|
|
156
|
-
|
|
432
|
+
}
|
|
157
433
|
for (let i = state.hooks[webhookNameOrNames].length - 1; i >= 0; i--) {
|
|
158
434
|
if (state.hooks[webhookNameOrNames][i] === handler) {
|
|
159
435
|
state.hooks[webhookNameOrNames].splice(i, 1);
|
|
@@ -162,16 +438,15 @@ function removeListener(state, webhookNameOrNames, handler) {
|
|
|
162
438
|
}
|
|
163
439
|
}
|
|
164
440
|
|
|
441
|
+
// pkg/dist-src/event-handler/index.js
|
|
165
442
|
function createEventHandler(options) {
|
|
166
443
|
const state = {
|
|
167
444
|
hooks: {},
|
|
168
445
|
log: createLogger(options && options.log)
|
|
169
446
|
};
|
|
170
|
-
|
|
171
447
|
if (options && options.transform) {
|
|
172
448
|
state.transform = options.transform;
|
|
173
449
|
}
|
|
174
|
-
|
|
175
450
|
return {
|
|
176
451
|
on: receiverOn.bind(null, state),
|
|
177
452
|
onAny: receiverOnAny.bind(null, state),
|
|
@@ -181,155 +456,165 @@ function createEventHandler(options) {
|
|
|
181
456
|
};
|
|
182
457
|
}
|
|
183
458
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
*/
|
|
187
|
-
function toNormalizedJsonString(payload) {
|
|
188
|
-
const payloadString = JSON.stringify(payload);
|
|
189
|
-
return payloadString.replace(/[^\\]\\u[\da-f]{4}/g, s => {
|
|
190
|
-
return s.substr(0, 3) + s.substr(3).toUpperCase();
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
async function sign(secret, payload) {
|
|
195
|
-
return webhooksMethods.sign(secret, typeof payload === "string" ? payload : toNormalizedJsonString(payload));
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async function verify(secret, payload, signature) {
|
|
199
|
-
return webhooksMethods.verify(secret, typeof payload === "string" ? payload : toNormalizedJsonString(payload), signature);
|
|
200
|
-
}
|
|
459
|
+
// pkg/dist-src/index.js
|
|
460
|
+
var import_webhooks_methods2 = require("@octokit/webhooks-methods");
|
|
201
461
|
|
|
462
|
+
// pkg/dist-src/verify-and-receive.js
|
|
463
|
+
var import_webhooks_methods = require("@octokit/webhooks-methods");
|
|
202
464
|
async function verifyAndReceive(state, event) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
465
|
+
const matchesSignature = await (0, import_webhooks_methods.verify)(
|
|
466
|
+
state.secret,
|
|
467
|
+
event.payload,
|
|
468
|
+
event.signature
|
|
469
|
+
);
|
|
206
470
|
if (!matchesSignature) {
|
|
207
|
-
const error = new Error(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
+
);
|
|
212
477
|
}
|
|
213
|
-
|
|
214
478
|
return state.eventHandler.receive({
|
|
215
479
|
id: event.id,
|
|
216
480
|
name: event.name,
|
|
217
|
-
payload:
|
|
481
|
+
payload: JSON.parse(event.payload)
|
|
218
482
|
});
|
|
219
483
|
}
|
|
220
484
|
|
|
221
|
-
|
|
222
|
-
|
|
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
|
+
];
|
|
223
491
|
function getMissingHeaders(request) {
|
|
224
|
-
return WEBHOOK_HEADERS.filter(header => !(header in request.headers));
|
|
492
|
+
return WEBHOOK_HEADERS.filter((header) => !(header in request.headers));
|
|
225
493
|
}
|
|
226
494
|
|
|
227
|
-
//
|
|
495
|
+
// pkg/dist-src/middleware/node/get-payload.js
|
|
496
|
+
var import_aggregate_error2 = __toESM(require("aggregate-error"));
|
|
228
497
|
function getPayload(request) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (request.body) return Promise.resolve(request.body);
|
|
498
|
+
if (request.body)
|
|
499
|
+
return Promise.resolve(request.body);
|
|
232
500
|
return new Promise((resolve, reject) => {
|
|
233
501
|
let data = "";
|
|
234
|
-
request.setEncoding("utf8");
|
|
235
|
-
|
|
236
|
-
request.on("
|
|
237
|
-
request.on("data", chunk => data += chunk);
|
|
502
|
+
request.setEncoding("utf8");
|
|
503
|
+
request.on("error", (error) => reject(new import_aggregate_error2.default([error])));
|
|
504
|
+
request.on("data", (chunk) => data += chunk);
|
|
238
505
|
request.on("end", () => {
|
|
239
506
|
try {
|
|
240
|
-
|
|
507
|
+
JSON.parse(data);
|
|
508
|
+
resolve(data);
|
|
241
509
|
} catch (error) {
|
|
242
510
|
error.message = "Invalid JSON";
|
|
243
511
|
error.status = 400;
|
|
244
|
-
reject(new
|
|
512
|
+
reject(new import_aggregate_error2.default([error]));
|
|
245
513
|
}
|
|
246
514
|
});
|
|
247
515
|
});
|
|
248
516
|
}
|
|
249
517
|
|
|
518
|
+
// pkg/dist-src/middleware/node/on-unhandled-request-default.js
|
|
250
519
|
function onUnhandledRequestDefault(request, response) {
|
|
251
520
|
response.writeHead(404, {
|
|
252
521
|
"content-type": "application/json"
|
|
253
522
|
});
|
|
254
|
-
response.end(
|
|
255
|
-
|
|
256
|
-
|
|
523
|
+
response.end(
|
|
524
|
+
JSON.stringify({
|
|
525
|
+
error: `Unknown route: ${request.method} ${request.url}`
|
|
526
|
+
})
|
|
527
|
+
);
|
|
257
528
|
}
|
|
258
529
|
|
|
530
|
+
// pkg/dist-src/middleware/node/middleware.js
|
|
259
531
|
async function middleware(webhooks, options, request, response, next) {
|
|
260
532
|
let pathname;
|
|
261
|
-
|
|
262
533
|
try {
|
|
263
534
|
pathname = new URL(request.url, "http://localhost").pathname;
|
|
264
535
|
} catch (error) {
|
|
265
536
|
response.writeHead(422, {
|
|
266
537
|
"content-type": "application/json"
|
|
267
538
|
});
|
|
268
|
-
response.end(
|
|
269
|
-
|
|
270
|
-
|
|
539
|
+
response.end(
|
|
540
|
+
JSON.stringify({
|
|
541
|
+
error: `Request URL could not be parsed: ${request.url}`
|
|
542
|
+
})
|
|
543
|
+
);
|
|
271
544
|
return true;
|
|
272
545
|
}
|
|
273
|
-
|
|
274
546
|
if (pathname !== options.path) {
|
|
275
|
-
next
|
|
547
|
+
next == null ? void 0 : next();
|
|
276
548
|
return false;
|
|
277
549
|
} else if (request.method !== "POST") {
|
|
278
550
|
onUnhandledRequestDefault(request, response);
|
|
279
551
|
return true;
|
|
280
552
|
}
|
|
281
|
-
|
|
553
|
+
if (!request.headers["content-type"] || !request.headers["content-type"].startsWith("application/json")) {
|
|
554
|
+
response.writeHead(415, {
|
|
555
|
+
"content-type": "application/json",
|
|
556
|
+
accept: "application/json"
|
|
557
|
+
});
|
|
558
|
+
response.end(
|
|
559
|
+
JSON.stringify({
|
|
560
|
+
error: `Unsupported "Content-Type" header value. Must be "application/json"`
|
|
561
|
+
})
|
|
562
|
+
);
|
|
563
|
+
return true;
|
|
564
|
+
}
|
|
282
565
|
const missingHeaders = getMissingHeaders(request).join(", ");
|
|
283
|
-
|
|
284
566
|
if (missingHeaders) {
|
|
285
567
|
response.writeHead(400, {
|
|
286
568
|
"content-type": "application/json"
|
|
287
569
|
});
|
|
288
|
-
response.end(
|
|
289
|
-
|
|
290
|
-
|
|
570
|
+
response.end(
|
|
571
|
+
JSON.stringify({
|
|
572
|
+
error: `Required headers missing: ${missingHeaders}`
|
|
573
|
+
})
|
|
574
|
+
);
|
|
291
575
|
return true;
|
|
292
576
|
}
|
|
293
|
-
|
|
294
577
|
const eventName = request.headers["x-github-event"];
|
|
295
578
|
const signatureSHA256 = request.headers["x-hub-signature-256"];
|
|
296
579
|
const id = request.headers["x-github-delivery"];
|
|
297
|
-
options.log.debug(`${eventName} event received (id: ${id})`);
|
|
298
|
-
// See https://github.com/octokit/webhooks.js/issues/185
|
|
299
|
-
|
|
580
|
+
options.log.debug(`${eventName} event received (id: ${id})`);
|
|
300
581
|
let didTimeout = false;
|
|
301
582
|
const timeout = setTimeout(() => {
|
|
302
583
|
didTimeout = true;
|
|
303
584
|
response.statusCode = 202;
|
|
304
585
|
response.end("still processing\n");
|
|
305
|
-
},
|
|
306
|
-
|
|
586
|
+
}, 9e3).unref();
|
|
307
587
|
try {
|
|
308
588
|
const payload = await getPayload(request);
|
|
309
589
|
await webhooks.verifyAndReceive({
|
|
310
|
-
id
|
|
590
|
+
id,
|
|
311
591
|
name: eventName,
|
|
312
|
-
payload
|
|
592
|
+
payload,
|
|
313
593
|
signature: signatureSHA256
|
|
314
594
|
});
|
|
315
595
|
clearTimeout(timeout);
|
|
316
|
-
if (didTimeout)
|
|
596
|
+
if (didTimeout)
|
|
597
|
+
return true;
|
|
317
598
|
response.end("ok\n");
|
|
318
599
|
return true;
|
|
319
600
|
} catch (error) {
|
|
320
601
|
clearTimeout(timeout);
|
|
321
|
-
if (didTimeout)
|
|
602
|
+
if (didTimeout)
|
|
603
|
+
return true;
|
|
322
604
|
const err = Array.from(error)[0];
|
|
323
605
|
const errorMessage = err.message ? `${err.name}: ${err.message}` : "Error: An Unspecified error occurred";
|
|
324
606
|
response.statusCode = typeof err.status !== "undefined" ? err.status : 500;
|
|
325
607
|
options.log.error(error);
|
|
326
|
-
response.end(
|
|
327
|
-
|
|
328
|
-
|
|
608
|
+
response.end(
|
|
609
|
+
JSON.stringify({
|
|
610
|
+
error: errorMessage
|
|
611
|
+
})
|
|
612
|
+
);
|
|
329
613
|
return true;
|
|
330
614
|
}
|
|
331
615
|
}
|
|
332
616
|
|
|
617
|
+
// pkg/dist-src/middleware/node/index.js
|
|
333
618
|
function createNodeMiddleware(webhooks, {
|
|
334
619
|
path = "/api/github/webhooks",
|
|
335
620
|
log = createLogger()
|
|
@@ -340,20 +625,20 @@ function createNodeMiddleware(webhooks, {
|
|
|
340
625
|
});
|
|
341
626
|
}
|
|
342
627
|
|
|
343
|
-
|
|
628
|
+
// pkg/dist-src/index.js
|
|
629
|
+
var Webhooks = class {
|
|
344
630
|
constructor(options) {
|
|
345
631
|
if (!options || !options.secret) {
|
|
346
632
|
throw new Error("[@octokit/webhooks] options.secret required");
|
|
347
633
|
}
|
|
348
|
-
|
|
349
634
|
const state = {
|
|
350
635
|
eventHandler: createEventHandler(options),
|
|
351
636
|
secret: options.secret,
|
|
352
637
|
hooks: {},
|
|
353
638
|
log: createLogger(options.log)
|
|
354
639
|
};
|
|
355
|
-
this.sign = sign.bind(null, options.secret);
|
|
356
|
-
this.verify = verify.bind(null, options.secret);
|
|
640
|
+
this.sign = import_webhooks_methods2.sign.bind(null, options.secret);
|
|
641
|
+
this.verify = import_webhooks_methods2.verify.bind(null, options.secret);
|
|
357
642
|
this.on = state.eventHandler.on;
|
|
358
643
|
this.onAny = state.eventHandler.onAny;
|
|
359
644
|
this.onError = state.eventHandler.onError;
|
|
@@ -361,11 +646,11 @@ class Webhooks {
|
|
|
361
646
|
this.receive = state.eventHandler.receive;
|
|
362
647
|
this.verifyAndReceive = verifyAndReceive.bind(null, state);
|
|
363
648
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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
|
+
});
|