Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@top-gg/sdk",
"version": "3.1.6",
"version": "3.1.7",
"description": "Official Top.gg Node SDK",
"main": "./dist/index.js",
"scripts": {
Expand Down Expand Up @@ -44,8 +44,7 @@
"typescript": "^5.2.2"
},
"dependencies": {
"raw-body": "^2.5.2",
"undici": "^5.23.0"
"undici": "^6.13.0"
},
"types": "./dist/index.d.ts"
}
23 changes: 13 additions & 10 deletions src/structs/Webhook.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import getBody from "raw-body";
import { Request, Response, NextFunction } from "express";
import { WebhookPayload } from "../typings";

Expand Down Expand Up @@ -70,21 +69,25 @@ export class Webhook {
req.headers.authorization !== this.authorization
)
return res.status(403).json({ error: "Unauthorized" });
// parse json

// parse json
if (req.body) return resolve(this._formatIncoming(req.body));
getBody(req, {}, (error, body) => {
if (error) return res.status(422).json({ error: "Malformed request" });

try {
try {
const chunks: Uint8Array[] = [];

req.on("data", (d) => chunks.push(d));

req.on("end", () => {
const body = Buffer.concat(chunks);
const parsed = JSON.parse(body.toString("utf8"));

resolve(this._formatIncoming(parsed));
} catch (err) {
res.status(400).json({ error: "Invalid body" });
resolve(false);
}
});
});
} catch {
res.status(400).json({ error: "Invalid body" });
resolve(false);
}
});
}

Expand Down