Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/suspiciouslookingowl/saweria-webhook-express
A simple Express middleware to verify Saweria webhook request.
https://github.com/suspiciouslookingowl/saweria-webhook-express
Last synced: about 2 months ago
JSON representation
A simple Express middleware to verify Saweria webhook request.
- Host: GitHub
- URL: https://github.com/suspiciouslookingowl/saweria-webhook-express
- Owner: SuspiciousLookingOwl
- Created: 2021-11-17T12:59:24.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-17T13:15:43.000Z (about 3 years ago)
- Last Synced: 2024-05-01T16:20:21.648Z (8 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/saweria-webhook-express
- Size: 57.6 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Saweria Webhook Express
`saweria-webhook-express` is a simple Express middleware to verify Saweria webhook request using your stream key.
This middleware will checks whether the received request is a valid request from Saweria or not, it will:
- returns `403` if `Saweria-Callback-Signature` header isn't provided
- returns `401` if `Saweria-Callback-Signature` value isn't valid### Install
```
npm i saweria-webhook-express
```### Usage
```js
const express = require("express");
const { createMiddleware } = require("saweria-webhook-express");const app = express();
const verifySignature = createMiddleware("your-stream-key");
app.use(express.json()); // required since the middleware also reads the donation payload
app.post("/webhook", verifySignature, (req, res) => {
console.log("New verified request from Saweria!");
console.log(req.body); // donation payload
res.sendStatus(200);
});app.listen(8080);
````createMiddleware` also accepts 2nd parameter as options:
```js
const verifySignature = createMiddleware("your-stream-key", {
camelCase: true, // false by default
});
```This will convert the body payload (`req.body`) from `snake_case`:
```js
{
version: "2021.07",
created_at: "2021-01-01T12:00:00+00:00",
id: "00000000-0000-0000-0000-000000000000",
type: "donation",
amount_raw: 69420,
cut: 3471,
donator_name: "Someguy",
donator_email: "[email protected]",
message: "THIS IS A FAKE MESSAGE! HAVE A GOOD ONE",
}
```to `camelCase`:
```js
{
version: "2021.07",
createdAt: "2021-01-01T12:00:00+00:00",
id: "00000000-0000-0000-0000-000000000000",
type: "donation",
amountRaw: 69420,
cut: 3471,
donatorName: "Someguy",
donatorEmail: "[email protected]",
message: "THIS IS A FAKE MESSAGE! HAVE A GOOD ONE",
}
```