@team-plain/webhooks 0.1.0 → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +77 -0
- package/package.json +6 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Not Just Tickets Ltd.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @team-plain/webhooks
|
|
2
|
+
|
|
3
|
+
Webhook parsing and signature verification for [Plain](https://plain.com) webhooks. Standalone package — no dependency on `@team-plain/sdk`.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @team-plain/webhooks
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Verify and parse (recommended)
|
|
14
|
+
|
|
15
|
+
`verifyPlainWebhook` validates the HMAC-SHA256 signature, checks the timestamp to prevent replay attacks, and parses the payload against the webhook JSON schema.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { verifyPlainWebhook } from "@team-plain/webhooks";
|
|
19
|
+
|
|
20
|
+
const result = verifyPlainWebhook(
|
|
21
|
+
rawBody, // raw request body string
|
|
22
|
+
req.headers["plain-request-signature"], // signature header
|
|
23
|
+
process.env.PLAIN_WEBHOOK_SECRET, // your webhook signing secret
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
if (result.error) {
|
|
27
|
+
console.error(result.error.message);
|
|
28
|
+
} else {
|
|
29
|
+
const event = result.data;
|
|
30
|
+
console.log(event.eventType, event.payload);
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The optional fourth argument `tolerance` (default: `300` seconds) controls the maximum allowed age of the webhook timestamp.
|
|
35
|
+
|
|
36
|
+
### Parse only (no signature verification)
|
|
37
|
+
|
|
38
|
+
`parsePlainWebhook` validates the payload against the webhook JSON schema without checking the signature. Useful for development or when verification is handled elsewhere.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { parsePlainWebhook } from "@team-plain/webhooks";
|
|
42
|
+
|
|
43
|
+
const result = parsePlainWebhook(rawBody);
|
|
44
|
+
|
|
45
|
+
if (result.error) {
|
|
46
|
+
console.error(result.error.message);
|
|
47
|
+
} else {
|
|
48
|
+
const event = result.data;
|
|
49
|
+
console.log(event.eventType, event.payload);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Error types
|
|
54
|
+
|
|
55
|
+
All functions return a `Result<T, Error>` — either `{ data: T }` or `{ error: Error }`.
|
|
56
|
+
|
|
57
|
+
| Error class | When |
|
|
58
|
+
|------------|------|
|
|
59
|
+
| `PlainWebhookSignatureVerificationError` | Invalid signature, missing headers, or expired timestamp |
|
|
60
|
+
| `PlainWebhookPayloadError` | Payload fails JSON schema validation |
|
|
61
|
+
| `PlainWebhookVersionMismatchError` | Payload version doesn't match the schema version bundled in this package |
|
|
62
|
+
|
|
63
|
+
### Typed event payloads
|
|
64
|
+
|
|
65
|
+
All webhook payload types are exported for use in your handlers:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import type {
|
|
69
|
+
ThreadCreatedPublicEventPayload,
|
|
70
|
+
CustomerCreatedPublicEventPayload,
|
|
71
|
+
// ...
|
|
72
|
+
} from "@team-plain/webhooks";
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
[MIT](../../LICENSE)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@team-plain/webhooks",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -16,10 +16,6 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tsc",
|
|
21
|
-
"test": "vitest run"
|
|
22
|
-
},
|
|
23
19
|
"dependencies": {
|
|
24
20
|
"ajv": "^8.12.0",
|
|
25
21
|
"ajv-formats": "^2.1.1"
|
|
@@ -27,5 +23,9 @@
|
|
|
27
23
|
"devDependencies": {
|
|
28
24
|
"@types/node": "^25.0.0",
|
|
29
25
|
"typescript": "^5.7.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc",
|
|
29
|
+
"test": "vitest run"
|
|
30
30
|
}
|
|
31
|
-
}
|
|
31
|
+
}
|