@theokit/gateway 0.24.0 → 0.25.0
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/CHANGELOG.md +8 -0
- package/dist/index.cjs +14 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +14 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.25.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a0b59f4: `ChannelWebhook.verify` may return a `Promise<boolean>`, and `createWebhookHandler` awaits it.
|
|
8
|
+
|
|
9
|
+
`ChannelWebhook.precheck` answers a request from its method, URL and headers before the body is read.
|
|
10
|
+
|
|
3
11
|
## 0.24.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
package/dist/index.cjs
CHANGED
|
@@ -2348,7 +2348,7 @@ function answerResponse(answer) {
|
|
|
2348
2348
|
return new Response(answer.body ?? null, { status: answer.status, headers });
|
|
2349
2349
|
}
|
|
2350
2350
|
async function runDefault(webhook, adapter, request) {
|
|
2351
|
-
if (!webhook.verify(adapter, request)) return plain(401);
|
|
2351
|
+
if (!await webhook.verify(adapter, request)) return plain(401);
|
|
2352
2352
|
let payload;
|
|
2353
2353
|
try {
|
|
2354
2354
|
payload = JSON.parse(request.rawBody);
|
|
@@ -2393,7 +2393,7 @@ function createWebhookHandler(options) {
|
|
|
2393
2393
|
const platform = channel.descriptor.platform;
|
|
2394
2394
|
if (!options.isStarted(platform)) return plain(503);
|
|
2395
2395
|
const webhook = channel.descriptor.webhook;
|
|
2396
|
-
const refused2 =
|
|
2396
|
+
const refused2 = refuseEarly(webhook, channel.adapter, request);
|
|
2397
2397
|
if (refused2 !== void 0) return refused2;
|
|
2398
2398
|
const rawBody = await readBody(request, max);
|
|
2399
2399
|
if (typeof rawBody !== "string") return rawBody;
|
|
@@ -2410,6 +2410,18 @@ function createWebhookHandler(options) {
|
|
|
2410
2410
|
}
|
|
2411
2411
|
};
|
|
2412
2412
|
}
|
|
2413
|
+
function refuseEarly(webhook, adapter, request) {
|
|
2414
|
+
return refuseMethod(webhook, request) ?? precheckAnswer(webhook, adapter, request);
|
|
2415
|
+
}
|
|
2416
|
+
function precheckAnswer(webhook, adapter, request) {
|
|
2417
|
+
if (webhook.precheck === void 0) return void 0;
|
|
2418
|
+
const answer = webhook.precheck(adapter, {
|
|
2419
|
+
headers: headersOf(request),
|
|
2420
|
+
method: request.method.toUpperCase(),
|
|
2421
|
+
url: request.url
|
|
2422
|
+
});
|
|
2423
|
+
return answer === void 0 ? void 0 : answerResponse(answer);
|
|
2424
|
+
}
|
|
2413
2425
|
function refuseMethod(webhook, request) {
|
|
2414
2426
|
const methods = webhook.methods ?? ["POST"];
|
|
2415
2427
|
const method = request.method.toUpperCase();
|