diff --git a/package.json b/package.json index 94c010e..3f90dbe 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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" } diff --git a/src/structs/Webhook.ts b/src/structs/Webhook.ts index d257ce8..06bfc16 100644 --- a/src/structs/Webhook.ts +++ b/src/structs/Webhook.ts @@ -1,4 +1,3 @@ -import getBody from "raw-body"; import { Request, Response, NextFunction } from "express"; import { WebhookPayload } from "../typings"; @@ -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); + } }); }