Skip to content

Commit 163aa22

Browse files
committed
Update webhooks package to latest schema version
Update webhook JSON schema and TypeScript types to match the latest Plain API version. Update tests for new schema shape.
1 parent f2127db commit 163aa22

18 files changed

Lines changed: 413 additions & 53 deletions

CLAUDE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pnpm check # Format + lint with biome (auto-fix)
1717

1818
Per-package scripts (codegen, test, etc.) are run via `pnpm --filter <pkg> <script>`.
1919

20+
**Always run `pnpm check` after making any changes.** This auto-fixes formatting and linting issues. CI enforces both via `pnpm format:check` and `pnpm lint`, so unformatted or unlinted code will fail the build.
21+
2022
## Architecture
2123

2224
Four packages in a pnpm monorepo:
@@ -72,9 +74,7 @@ Edit files in `packages/sdk/src/`, export from `index.ts`, then `pnpm build`.
7274

7375
**Update the webhook schema:**
7476
```bash
75-
curl -o packages/webhooks/src/webhook-schema.json https://core-api.uk.plain.com/webhooks/schema/latest.json
76-
# Regenerate TypeScript types from the JSON schema (requires json-schema-to-typescript)
77-
npx json-schema-to-typescript --input packages/webhooks/src/webhook-schema.json --output packages/webhooks/src/webhook-schema.ts
77+
pnpm --filter @team-plain/webhooks codegen
7878
pnpm --filter @team-plain/webhooks build
7979
pnpm --filter @team-plain/webhooks test
8080
```

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Files prefixed with `_generated_` are auto-generated — don't edit them manuall
9090
| `pnpm --filter @team-plain/sdk build` | Build just the SDK |
9191
| `pnpm --filter @team-plain/ui-components build` | Build just ui-components |
9292
| `pnpm --filter @team-plain/ui-components test` | Test ui-components |
93+
| `pnpm --filter @team-plain/webhooks codegen` | Fetch + regenerate webhook schema types |
9394
| `pnpm --filter @team-plain/webhooks build` | Build just webhooks |
9495
| `pnpm --filter @team-plain/webhooks test` | Test webhooks |
9596
| `pnpm format` | Format with biome |
@@ -131,8 +132,7 @@ Edit files in `packages/sdk/src/`, export from `index.ts`, then `pnpm build`.
131132
### Update the webhook schema
132133

133134
```bash
134-
curl -o packages/webhooks/src/webhook-schema.json https://core-api.uk.plain.com/webhooks/schema/latest.json
135-
npx json-schema-to-typescript --input packages/webhooks/src/webhook-schema.json --output packages/webhooks/src/webhook-schema.ts
135+
pnpm --filter @team-plain/webhooks codegen
136136
pnpm --filter @team-plain/webhooks build
137137
pnpm --filter @team-plain/webhooks test
138138
```

packages/webhooks/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @team-plain/webhooks
22

3+
## 0.2.0
4+
5+
### Minor Changes
6+
7+
- af22f5f: Update webhooks parsing to latest webhook version.
8+
39
## 0.1.1
410

511
### Patch Changes

packages/webhooks/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@team-plain/webhooks",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"type": "module",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
@@ -18,14 +18,16 @@
1818
],
1919
"scripts": {
2020
"build": "tsc",
21-
"test": "vitest run"
21+
"test": "vitest run",
22+
"codegen": "sh ./scripts/codegen-webhooks.sh"
2223
},
2324
"dependencies": {
2425
"ajv": "^8.12.0",
2526
"ajv-formats": "^2.1.1"
2627
},
2728
"devDependencies": {
2829
"@types/node": "^25.0.0",
29-
"typescript": "^5.7.0"
30+
"typescript": "^5.7.0",
31+
"json-schema-to-typescript": "^13.1.2"
3032
}
3133
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
#!/bin/bash
3+
# Download the JSON schema
4+
curl https://core-api.uk.plain.com/webhooks/schema/latest.json -o ./src/webhook-schema.json
5+
6+
./node_modules/.bin/json2ts --input ./src/webhook-schema.json --output ./src/webhook-schema.ts

packages/webhooks/src/__tests__/verify-plain-webhook.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe("verifyPlainWebhook", () => {
4747
it("returns an error when the signature matches but the timestamp is too far in the past", () => {
4848
const result = verifyPlainWebhook(
4949
JSON.stringify(threadCreatedPayload),
50-
"ae0d54c966dea1056b6ced04d1bafc3358af592469b5fd55553dcb036b58a1ef",
50+
"41a425d490211cba1258f0c35dba59db36273ffae49052be0e6c13a518927fd1",
5151
"secret",
5252
);
5353

@@ -63,7 +63,7 @@ describe("verifyPlainWebhook", () => {
6363

6464
const result = verifyPlainWebhook(
6565
JSON.stringify(threadCreatedPayload),
66-
"ae0d54c966dea1056b6ced04d1bafc3358af592469b5fd55553dcb036b58a1ef",
66+
"41a425d490211cba1258f0c35dba59db36273ffae49052be0e6c13a518927fd1",
6767
"secret",
6868
);
6969

@@ -96,7 +96,7 @@ describe("verifyPlainWebhook", () => {
9696

9797
const result = verifyPlainWebhook(
9898
JSON.stringify(invalidPayload),
99-
"5656d05d265cea83d60afe94b440eff2ef403a8d77f6bf5483e5e83f3e5b1499",
99+
"9495c54afef3630ef0135dad8efc27b298926412827cc8d7f5108b7e737a6850",
100100
"secret",
101101
);
102102

packages/webhooks/src/__tests__/webhook-payloads/customer-created.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default {
3131
id: "pEv_01HD44FHDPMZ3YJB5GEB1EZKQV",
3232
webhookMetadata: {
3333
webhookTargetId: "whTarget_01HD4400VTDJQ646V6RY37SR7K",
34-
webhookTargetVersion: "2026-02-27",
34+
webhookTargetVersion: "2026-03-13",
3535
webhookDeliveryAttemptId: "whAttempt_01HD44FJ45FJKVFHM3MDVYPGRS",
3636
webhookDeliveryAttemptNumber: 1,
3737
webhookDeliveryAttemptTimestamp: "2023-10-19T14:12:25.861Z",

packages/webhooks/src/__tests__/webhook-payloads/email-received.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export default {
106106
id: "pEv_01HR9W91EMR655WS6VC2867D3C",
107107
webhookMetadata: {
108108
webhookTargetId: "whTarget_01HR9VYX2GYKX1XCTFXRG1K3MX",
109-
webhookTargetVersion: "2026-02-27",
109+
webhookTargetVersion: "2026-03-13",
110110
webhookDeliveryAttemptId: "whAttempt_01HR9W92RSJZA4011XDNHJ5VK7",
111111
webhookDeliveryAttemptNumber: 1,
112112
webhookDeliveryAttemptTimestamp: "2024-03-06T12:37:11.577Z",

packages/webhooks/src/__tests__/webhook-payloads/invalid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default {
4848
id: "pEv_01HR9W25SFVMS2Y4Q8W75M86G4",
4949
webhookMetadata: {
5050
webhookTargetId: "whTarget_01HR9VYX2GYKX1XCTFXRG1K3MX",
51-
webhookTargetVersion: "2026-02-27",
51+
webhookTargetVersion: "2026-03-13",
5252
webhookDeliveryAttemptId: "whAttempt_01HR9W26906XCJ64JQZG8RJCCQ",
5353
webhookDeliveryAttemptNumber: 1,
5454
webhookDeliveryAttemptTimestamp: "2024-03-06T12:33:25.792Z",

packages/webhooks/src/__tests__/webhook-payloads/thread-assignment-transitioned.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default {
3939
statusDetail: null,
4040
assignee: null,
4141
assignedAt: null,
42-
additionalAsignees: [],
42+
additionalAssignees: [],
4343
labels: [],
4444
firstInboundMessageInfo: {
4545
timestamp: "2024-03-06T12:32:05.710Z",
@@ -112,7 +112,7 @@ export default {
112112
deletedBy: null,
113113
},
114114
assignedAt: "2024-03-06T12:34:44.535Z",
115-
additionalAsignees: [],
115+
additionalAssignees: [],
116116
labels: [],
117117
firstInboundMessageInfo: {
118118
timestamp: "2024-03-06T12:32:05.710Z",
@@ -134,7 +134,7 @@ export default {
134134
id: "pEv_01HR9W4K5QEVAFQSYCKN2D8198",
135135
webhookMetadata: {
136136
webhookTargetId: "whTarget_01HR9VYX2GYKX1XCTFXRG1K3MX",
137-
webhookTargetVersion: "2026-02-27",
137+
webhookTargetVersion: "2026-03-13",
138138
webhookDeliveryAttemptId: "whAttempt_01HR9W4KV3RHX435FPZJ46P5WY",
139139
webhookDeliveryAttemptNumber: 1,
140140
webhookDeliveryAttemptTimestamp: "2024-03-06T12:34:45.219Z",

0 commit comments

Comments
 (0)