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