@sidekickdb/webhooks 2.0.1 → 3.0.0

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.
@@ -1,19 +1,19 @@
1
1
 
2
- > @sidekickdb/webhooks@2.0.1 build /home/runner/work/sidekick/sidekick/client/packages/webhooks
2
+ > @sidekickdb/webhooks@3.0.0 build /home/runner/work/sidekick/sidekick/client/packages/webhooks
3
3
  > rm -rf dist; npm run build:tshy && npm run check-exports
4
4
 
5
5
  npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm. See `npm help npmrc` for supported config options.
6
6
 
7
- > @sidekickdb/webhooks@2.0.1 build:tshy
7
+ > @sidekickdb/webhooks@3.0.0 build:tshy
8
8
  > tshy
9
9
 
10
10
  npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm. See `npm help npmrc` for supported config options.
11
11
 
12
- > @sidekickdb/webhooks@2.0.1 check-exports
12
+ > @sidekickdb/webhooks@3.0.0 check-exports
13
13
  > attw --pack .
14
14
 
15
15
 
16
- @sidekickdb/webhooks v2.0.1
16
+ @sidekickdb/webhooks v3.0.0
17
17
 
18
18
  Build tools:
19
19
  - @arethetypeswrong/cli@^0.18.5
package/README.md CHANGED
@@ -20,15 +20,15 @@ The `Webhooks` class is re-exported from a few places. Use whichever fits your s
20
20
 
21
21
  ```ts
22
22
  import { init } from '@sidekickdb/admin';
23
- import schema from './instant.schema';
23
+ import schema from './sidekick.schema';
24
24
 
25
25
  // adminToken is optional if you're only using the SDK for the receiving side
26
26
  // of webhooks (processRequest / validate / etc.). Include it if you also want
27
27
  // to use db.webhooks.manager.* — or any other admin-SDK feature that requires
28
28
  // auth, like writes or impersonation.
29
29
  const db = init({
30
- appId: process.env.INSTANT_APP_ID!,
31
- apiURI: process.env.INSTANT_API_URI!,
30
+ appId: process.env.SIDEKICK_APP_ID!,
31
+ apiURI: process.env.SIDEKICK_API_URI!,
32
32
  schema,
33
33
  });
34
34
 
@@ -40,14 +40,14 @@ await db.webhooks.processRequest(handlers, req);
40
40
 
41
41
  ```ts
42
42
  import { PlatformApi } from '@sidekickdb/platform';
43
- import schema from './instant.schema';
43
+ import schema from './sidekick.schema';
44
44
 
45
45
  // Auth is optional if you're only using PlatformApi for the receiving side of
46
46
  // webhooks. Include it if you also want to use webhooks.manager.* (or any
47
47
  // other platform-SDK feature). When provided, the platform SDK refreshes the
48
48
  // OAuth token transparently for manager calls.
49
49
  const api = new PlatformApi({
50
- apiURI: process.env.INSTANT_API_URI!,
50
+ apiURI: process.env.SIDEKICK_API_URI!,
51
51
  auth: { token: accessToken },
52
52
  });
53
53
 
@@ -60,21 +60,21 @@ await webhooks.processRequest(handlers, req);
60
60
 
61
61
  ```ts
62
62
  import { Webhooks } from '@sidekickdb/webhooks';
63
- import schema from './instant.schema';
63
+ import schema from './sidekick.schema';
64
64
 
65
65
  // For receiving only (validate / processRequest / processPayload), the
66
66
  // adminToken is optional — you just need appId + schema for typed handlers.
67
67
  const webhooks = new Webhooks<typeof schema>({
68
- appId: process.env.INSTANT_APP_ID!,
69
- apiURI: process.env.INSTANT_API_URI!,
68
+ appId: process.env.SIDEKICK_APP_ID!,
69
+ apiURI: process.env.SIDEKICK_API_URI!,
70
70
  schema,
71
71
  });
72
72
 
73
73
  // To also manage webhooks (manager.create, manager.list, …) pass adminToken.
74
74
  const webhooksWithManager = new Webhooks<typeof schema>({
75
- appId: process.env.INSTANT_APP_ID!,
76
- apiURI: process.env.INSTANT_API_URI!,
77
- adminToken: process.env.INSTANT_APP_ADMIN_TOKEN!,
75
+ appId: process.env.SIDEKICK_APP_ID!,
76
+ apiURI: process.env.SIDEKICK_API_URI!,
77
+ adminToken: process.env.SIDEKICK_APP_ADMIN_TOKEN!,
78
78
  schema,
79
79
  });
80
80
  ```
@@ -95,20 +95,20 @@ The rest of this README uses `db.webhooks` in examples. The same methods exist o
95
95
 
96
96
  The one-liner for handling an incoming webhook. It:
97
97
 
98
- 1. Verifies the `Instant-Signature` header against the raw body.
98
+ 1. Verifies the `Sidekick-Signature` header against the raw body.
99
99
  2. Fetches the records via the short-lived `payloadUrl` + JWT in the body.
100
100
  3. Dispatches each record to the matching handler.
101
101
 
102
102
  Pass it a Web [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) (Next.js App Router, Cloudflare Workers, Deno, Bun, Hono, etc.):
103
103
 
104
104
  ```ts
105
- // app/api/instant-webhook/route.ts
105
+ // app/api/sidekick-webhook/route.ts
106
106
  import { init } from '@sidekickdb/admin';
107
- import schema from '@/instant.schema';
107
+ import schema from '@/sidekick.schema';
108
108
 
109
109
  const db = init({
110
- appId: process.env.INSTANT_APP_ID!,
111
- apiURI: process.env.INSTANT_API_URI!,
110
+ appId: process.env.SIDEKICK_APP_ID!,
111
+ apiURI: process.env.SIDEKICK_API_URI!,
112
112
  schema,
113
113
  });
114
114
 
@@ -134,8 +134,8 @@ export async function POST(req: Request) {
134
134
 
135
135
  Options:
136
136
 
137
- - `tolerance` — max signature age in seconds (default `300`). Protects against replays; raising this weakens that.
138
- - `receivedAt` — override the "now" used when checking signature age. Mostly useful in tests.
137
+ - `tolerance` — how far, in seconds, the signature timestamp may be before or after `receivedAt` (default `300`). Must be a finite number, `0` or more; anything else throws. Protects against replays; raising this weakens that.
138
+ - `receivedAt` — override the "now" used when checking the signature timestamp. Must be a valid `Date`; anything else throws, and leaving it out (or `null`) means now. Mostly useful in tests.
139
139
 
140
140
  Handler resolution is most-specific-wins: `namespace` + `action` → that namespace's `$default` → top-level `$default`. Records with no matching handler are skipped.
141
141
 
@@ -150,7 +150,7 @@ The adapter picks up the raw body from, in order: `opts.body`, `req.rawBody`, `r
150
150
  Next.js Pages Router:
151
151
 
152
152
  ```ts
153
- // pages/api/instant-webhook.ts
153
+ // pages/api/sidekick-webhook.ts
154
154
  import type { NextApiRequest, NextApiResponse } from 'next';
155
155
 
156
156
  export const config = { api: { bodyParser: false } };
@@ -172,7 +172,7 @@ Express (use `express.raw` on the webhook route only):
172
172
 
173
173
  ```ts
174
174
  app.post(
175
- '/webhooks/instant',
175
+ '/webhooks/sidekick',
176
176
  express.raw({ type: 'application/json' }),
177
177
  async (req, res) => {
178
178
  try {
@@ -188,7 +188,7 @@ app.post(
188
188
  Koa with `raw-body`:
189
189
 
190
190
  ```ts
191
- router.post('/webhooks/instant', async (ctx) => {
191
+ router.post('/webhooks/sidekick', async (ctx) => {
192
192
  await db.webhooks.processNodeRequest(handlers, ctx.req, {
193
193
  body: rawBody(ctx.req), // adapter awaits the Promise
194
194
  });
@@ -201,7 +201,7 @@ NestJS (Express adapter, with `NestFactory.create(AppModule, { rawBody: true })`
201
201
  ```ts
202
202
  @Controller('webhooks')
203
203
  export class WebhooksController {
204
- @Post('instant')
204
+ @Post('sidekick')
205
205
  @HttpCode(200)
206
206
  async handle(@Req() req: Request) {
207
207
  await db.webhooks.processNodeRequest(handlers, req);
@@ -225,7 +225,11 @@ Same resolution rules and concurrency model as `processRequest`: handlers run in
225
225
 
226
226
  ## `validate(signatureHeader, body, opts?)`
227
227
 
228
- Parses an `Instant-Signature` header, verifies it against the body, and returns the `{ payloadUrl, token }` you'd use to fetch the records. Throws if the signature doesn't validate, is older than `opts.tolerance` (default 300 seconds), or the body isn't the expected shape.
228
+ Parses a `Sidekick-Signature` header, verifies it against the body, and returns the `{ payloadUrl, token }` you'd use to fetch the records. Throws if the signature doesn't validate, its timestamp is not whole seconds or is more than `opts.tolerance` (default 300 seconds) before or after the time it was received, or the body isn't the expected shape.
229
+
230
+ <!-- SidekickDB: how signing keys are looked up. -->
231
+
232
+ The public signing keys come from your server's `/.well-known/webhooks/jwks.json`. A key is cached once it has been found there and checked against that set again 10 minutes after it was last confirmed: if the server no longer publishes it, it is dropped and the delivery is rejected. If the set cannot be fetched, the cached key keeps working for 6 hours after its last confirmation, then deliveries signed with it are rejected until a fetch succeeds. For a key id that is not cached, a key set fetched successfully in the last minute is reused, so after the server starts signing with a new key, deliveries signed with it can fail for up to a minute. SidekickDB retries a failed delivery after a minute or more, so the retry normally finds the new key. Fetches of the key set are limited per server; when the keys cannot be fetched (the server did not answer in time, or the limit was reached), validation throws an error ending in `try again later`, or the fetch error. In either case, answer with a non-2xx status other than `410` (a `410` stops deliveries to the webhook) and the delivery is retried.
229
233
 
230
234
  ```ts
231
235
  const { payloadUrl, token } = await db.webhooks.validate(
@@ -239,7 +243,7 @@ const { payloadUrl, token } = await db.webhooks.validate(
239
243
 
240
244
  ## `validateRequest(req, opts?)`
241
245
 
242
- Convenience wrapper around `validate`: pulls `instant-signature` and the body off a Web `Request` for you.
246
+ Convenience wrapper around `validate`: pulls `sidekick-signature` and the body off a Web `Request` for you.
243
247
 
244
248
  ```ts
245
249
  const { payloadUrl, token } = await db.webhooks.validateRequest(req);
@@ -292,7 +296,7 @@ Creates a webhook in the `active` state. It starts receiving matching events imm
292
296
 
293
297
  ```ts
294
298
  const webhook = await db.webhooks.manager.create({
295
- url: 'https://example.com/instant',
299
+ url: 'https://example.com/sidekick',
296
300
  namespaces: ['posts', 'comments'],
297
301
  actions: ['create', 'update'],
298
302
  });
@@ -362,7 +366,7 @@ Each event's `attempts` array records, per attempt: HTTP status, response body (
362
366
 
363
367
  ## `manager.getEvent(webhookId, isn)`
364
368
 
365
- Fetches a single event by its `isn` (Instant Sequence Number).
369
+ Fetches a single event by its `isn` (its sequence number).
366
370
 
367
371
  ```ts
368
372
  const event = await db.webhooks.manager.getEvent(webhook.id, isn);