@superlayer/webhooks 1.0.67

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.
@@ -0,0 +1,588 @@
1
+ import { InstantSchemaDef, InstantUnknownSchema, ResolveAttrs } from '@superlayer/core';
2
+ type Config<Schema extends InstantSchemaDef<any, any, any>> = {
3
+ appId?: string | null | undefined;
4
+ adminToken?: string | null | undefined;
5
+ token?: string | null | undefined;
6
+ apiURI?: string | null | undefined;
7
+ schema?: Schema | null | undefined;
8
+ /**
9
+ * Optional hook used by {@link WebhooksManager} to obtain the bearer token
10
+ * for each management request. Lets callers (e.g. the platform SDK) wrap
11
+ * the operation in token-refresh / retry logic.
12
+ *
13
+ * If omitted, the manager uses the static `adminToken`/`token` from this
14
+ * config.
15
+ */
16
+ withAuth?: WithAuth;
17
+ };
18
+ type JsonFetch = (input: RequestInfo, init?: RequestInit | undefined) => Promise<any>;
19
+ /**
20
+ * Runs a webhook management operation that needs a bearer token. The runner
21
+ * is responsible for supplying the token, and may retry the operation with a
22
+ * fresh token if the first attempt fails with an auth error.
23
+ */
24
+ export type WithAuth = <T>(operation: (token: string) => Promise<T>) => Promise<T>;
25
+ export type WebhookBody = {
26
+ payloadUrl: string;
27
+ token: string;
28
+ };
29
+ export type WebhookEntity<Schema extends InstantSchemaDef<any, any, any>, NamespaceName extends keyof Schema['entities'] & string> = {
30
+ id: string;
31
+ } & ResolveAttrs<Schema['entities'], NamespaceName, false>;
32
+ export type WebhookPayloadRecord<Schema extends InstantSchemaDef<any, any, any>> = {
33
+ [NamespaceName in keyof Schema['entities'] & string]: {
34
+ namespace: NamespaceName;
35
+ id: string;
36
+ action: 'create';
37
+ before: null;
38
+ after: WebhookEntity<Schema, NamespaceName>;
39
+ idempotencyKey: string;
40
+ } | {
41
+ namespace: NamespaceName;
42
+ id: string;
43
+ action: 'update';
44
+ before: WebhookEntity<Schema, NamespaceName>;
45
+ after: WebhookEntity<Schema, NamespaceName>;
46
+ idempotencyKey: string;
47
+ } | {
48
+ namespace: NamespaceName;
49
+ id: string;
50
+ action: 'delete';
51
+ before: WebhookEntity<Schema, NamespaceName>;
52
+ after: null;
53
+ idempotencyKey: string;
54
+ };
55
+ }[keyof Schema['entities'] & string];
56
+ export type WebhookPayload<Schema extends InstantSchemaDef<any, any, any>> = {
57
+ data: WebhookPayloadRecord<Schema>[];
58
+ idempotencyKey: string;
59
+ };
60
+ export type WebhookAction = 'create' | 'update' | 'delete';
61
+ /**
62
+ * Whether Instant will currently deliver events for a webhook.
63
+ * `disabled` webhooks remain configured but no new events are queued.
64
+ */
65
+ export type WebhookStatus = 'active' | 'disabled';
66
+ /**
67
+ * Stage in the delivery lifecycle of a single webhook event.
68
+ *
69
+ * - `pending`: queued, not yet picked up for delivery
70
+ * - `processing`: a sender is actively attempting delivery
71
+ * - `success`: the receiver acknowledged with a 2xx response
72
+ * - `error`: an attempt failed; another retry is scheduled
73
+ * - `failed`: all retries exhausted; will not be retried automatically
74
+ * (use {@link WebhooksManager.resendEvent} to retry manually)
75
+ */
76
+ export type WebhookEventStatus = 'pending' | 'processing' | 'success' | 'error' | 'failed';
77
+ export type WebhookInfo = {
78
+ /** Unique identifier for the webhook. */
79
+ id: string;
80
+ /** Where Instant POSTs event payloads to. */
81
+ sink: {
82
+ /** HTTPS endpoint that Instant POSTs to. */
83
+ url: string;
84
+ };
85
+ /** The namespaces this webhook listens to. */
86
+ namespaces: string[];
87
+ /** Which write actions trigger delivery. */
88
+ actions: WebhookAction[];
89
+ /** Whether the webhook is currently delivering events. */
90
+ status: WebhookStatus;
91
+ /**
92
+ * Human-readable reason the webhook is disabled. Set automatically when
93
+ * Instant disables the webhook (e.g. after repeated delivery failures) or
94
+ * supplied by the caller via {@link WebhooksManager.disable}. `null` when
95
+ * `status` is `'active'`.
96
+ */
97
+ disabledReason: string | null;
98
+ /** When the webhook was created. */
99
+ createdAt: Date;
100
+ /** When the webhook's config was last changed. */
101
+ updatedAt: Date;
102
+ };
103
+ /**
104
+ * Record of a single HTTP delivery attempt for a webhook event.
105
+ * Stored in attempt order (oldest first) on the event's `attempts` array.
106
+ */
107
+ export type WebhookAttempt = {
108
+ /** When the attempt started. */
109
+ attemptAt: Date | null;
110
+ /** Time from request start to response received (or error), in milliseconds. */
111
+ durationMs: number | null;
112
+ /** `true` if the receiver returned a 2xx response. */
113
+ success: boolean | null;
114
+ /** HTTP status code returned by the receiver, if a response was received. */
115
+ statusCode: number | null;
116
+ /**
117
+ * First 256 bytes of the response body, for debugging. `null` if no
118
+ * response was received (e.g. on a network error).
119
+ */
120
+ responseText: string | null;
121
+ /**
122
+ * Short tag classifying a delivery failure. One of `timeout`, `dns`,
123
+ * `connect`, `tls`, `protocol`, `network`, or `unknown`. `null` on success.
124
+ */
125
+ errorType: string | null;
126
+ /** Free-form description of the failure. `null` on success. */
127
+ errorMessage: string | null;
128
+ };
129
+ export type WebhookEventInfo = {
130
+ /**
131
+ * Instant Sequence Number — a stable, totally ordered identifier for the
132
+ * event.
133
+ */
134
+ isn: string;
135
+ /** Current stage in the delivery lifecycle. */
136
+ status: WebhookEventStatus;
137
+ /**
138
+ * Per-attempt records, in attempt order (oldest first). `null` if the
139
+ * event has not been attempted yet.
140
+ */
141
+ attempts: WebhookAttempt[] | null;
142
+ /**
143
+ * The next retry will not happen before this time. `null` once the event
144
+ * reaches a terminal status (`success` or `failed`).
145
+ */
146
+ nextAttemptAfter: Date | null;
147
+ /** When the event was queued. */
148
+ createdAt: Date;
149
+ /** When the event last transitioned status. */
150
+ updatedAt: Date;
151
+ };
152
+ export type WebhookEventsPage = {
153
+ /** The events on this page, newest first. */
154
+ events: WebhookEventInfo[];
155
+ pageInfo: {
156
+ /** Cursor pointing to the first event on this page. */
157
+ startCursor: string | null;
158
+ /**
159
+ * Cursor pointing to the last event on this page. Pass as
160
+ * {@link WebhooksManager.listEvents}'s `after` option to fetch the next page.
161
+ */
162
+ endCursor: string | null;
163
+ /** Whether more events are available after `endCursor`. */
164
+ hasNextPage: boolean;
165
+ };
166
+ };
167
+ export type CreateWebhookParams<Schema extends InstantSchemaDef<any, any, any>> = {
168
+ /**
169
+ * HTTPS endpoint Instant will POST events to. Must use the `https` scheme
170
+ * and resolve to a public host.
171
+ */
172
+ url: string;
173
+ /**
174
+ * Namespaces the webhook will listen to. Must reference at least one entity
175
+ * in the app's schema.
176
+ */
177
+ namespaces: (keyof Schema['entities'] & string)[];
178
+ /** Write actions that should trigger delivery. Must contain at least one. */
179
+ actions: WebhookAction[];
180
+ };
181
+ export type UpdateWebhookParams<Schema extends InstantSchemaDef<any, any, any>> = {
182
+ /** New delivery URL. Omit to leave unchanged. */
183
+ url?: string;
184
+ /** New set of namespaces. Omit to leave unchanged. */
185
+ namespaces?: (keyof Schema['entities'] & string)[];
186
+ /** New set of actions. Omit to leave unchanged. */
187
+ actions?: WebhookAction[];
188
+ };
189
+ export type WebhookPayloadRecordFor<Schema extends InstantSchemaDef<any, any, any>, NamespaceName extends keyof Schema['entities'] & string, Action extends WebhookAction> = Action extends 'create' ? {
190
+ namespace: NamespaceName;
191
+ id: string;
192
+ action: 'create';
193
+ before: null;
194
+ after: WebhookEntity<Schema, NamespaceName>;
195
+ idempotencyKey: string;
196
+ } : Action extends 'update' ? {
197
+ namespace: NamespaceName;
198
+ id: string;
199
+ action: 'update';
200
+ before: WebhookEntity<Schema, NamespaceName>;
201
+ after: WebhookEntity<Schema, NamespaceName>;
202
+ idempotencyKey: string;
203
+ } : Action extends 'delete' ? {
204
+ namespace: NamespaceName;
205
+ id: string;
206
+ action: 'delete';
207
+ before: WebhookEntity<Schema, NamespaceName>;
208
+ after: null;
209
+ idempotencyKey: string;
210
+ } : never;
211
+ export type WebhookHandlerFn<Schema extends InstantSchemaDef<any, any, any>, NamespaceName extends keyof Schema['entities'] & string, Action extends WebhookAction, Result = any> = (record: WebhookPayloadRecordFor<Schema, NamespaceName, Action>) => Result | Promise<Result>;
212
+ export type DefaultKey = '$default';
213
+ export type ResolveHandlerAction<Action> = Action extends DefaultKey ? WebhookAction : Action extends WebhookAction ? Action : never;
214
+ export type WebhookHandlers<Schema extends InstantSchemaDef<any, any, any>> = {
215
+ [NamespaceName in keyof Schema['entities'] & string]?: {
216
+ [Action in WebhookAction | DefaultKey]?: WebhookHandlerFn<Schema, NamespaceName, ResolveHandlerAction<Action>, any>;
217
+ };
218
+ } & {
219
+ $default?: WebhookHandlerFn<Schema, keyof Schema['entities'] & string, WebhookAction, any>;
220
+ };
221
+ export type TypedHandlerEntry<Schema extends InstantSchemaDef<any, any, any>, NamespaceName extends keyof Schema['entities'] & string, Action extends WebhookAction | DefaultKey> = {
222
+ [N in NamespaceName]: {
223
+ [A in Action]: WebhookHandlerFn<Schema, NamespaceName, ResolveHandlerAction<Action>, any>;
224
+ };
225
+ };
226
+ export type TypedDefaultEntry<Schema extends InstantSchemaDef<any, any, any>> = {
227
+ $default: WebhookHandlerFn<Schema, keyof Schema['entities'] & string, WebhookAction, any>;
228
+ };
229
+ export type WebhookHelpers<Schema extends InstantSchemaDef<any, any, any>> = {
230
+ typedHandlers: {
231
+ (namespace: DefaultKey, handler: WebhookHandlerFn<Schema, keyof Schema['entities'] & string, WebhookAction, any>): TypedDefaultEntry<Schema>;
232
+ <NamespaceName extends keyof Schema['entities'] & string, Action extends WebhookAction | DefaultKey>(namespace: NamespaceName, action: Action, handler: WebhookHandlerFn<Schema, NamespaceName, ResolveHandlerAction<Action>, any>): TypedHandlerEntry<Schema, NamespaceName, Action>;
233
+ };
234
+ combineHandlers: (...entries: Array<TypedHandlerEntry<Schema, any, any> | TypedDefaultEntry<Schema> | WebhookHandlers<Schema>>) => WebhookHandlers<Schema>;
235
+ };
236
+ type ImportAlgorithm = AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams;
237
+ export declare class WebhooksManager<Schema extends InstantSchemaDef<any, any, any>> {
238
+ #private;
239
+ constructor(opts: {
240
+ appId: string | null | undefined;
241
+ apiURI: string;
242
+ token: string | null | undefined;
243
+ withAuth?: WithAuth;
244
+ jsonFetch: JsonFetch;
245
+ });
246
+ /**
247
+ * Returns every webhook configured on the app, newest first. Includes both
248
+ * active and disabled webhooks.
249
+ */
250
+ list(): Promise<WebhookInfo[]>;
251
+ /**
252
+ * Creates a new webhook. The webhook is created in the `active` state and
253
+ * starts receiving matching events immediately.
254
+ *
255
+ * The server rejects the request if `url` is not an HTTPS URL pointing at a
256
+ * public host, if `namespaces` doesn't reference any entity in the app's
257
+ * schema, if `actions` is empty, or if the app has hit its webhook limit.
258
+ *
259
+ * An app may have at most **100 active webhooks** at a time; {@link delete}
260
+ * a webhook to free up a slot before creating another.
261
+ *
262
+ * @example
263
+ * const webhook = await db.webhooks.manager.create({
264
+ * url: 'https://example.com/instant',
265
+ * namespaces: ['posts', 'comments'],
266
+ * actions: ['create', 'update'],
267
+ * });
268
+ */
269
+ create(params: CreateWebhookParams<Schema>): Promise<WebhookInfo>;
270
+ /**
271
+ * Updates a webhook's `url`, `namespaces`, and/or `actions`. Pass only the
272
+ * fields you want to change; omitted fields keep their current value.
273
+ *
274
+ * Does not affect the webhook's status — use {@link enable} or
275
+ * {@link disable} for that.
276
+ */
277
+ update(webhookId: string, params: UpdateWebhookParams<Schema>): Promise<WebhookInfo>;
278
+ /**
279
+ * Deletes a webhook. No further events will be queued for it. Returns the
280
+ * webhook as it looked just before deletion.
281
+ */
282
+ delete(webhookId: string): Promise<WebhookInfo>;
283
+ /**
284
+ * Re-enables a disabled webhook. Clears `disabledReason` and resumes
285
+ * delivery for new events. Has no effect if the webhook is already active.
286
+ *
287
+ * Events that occurred while the webhook was disabled are not retroactively
288
+ * delivered.
289
+ */
290
+ enable(webhookId: string): Promise<WebhookInfo>;
291
+ /**
292
+ * Disables a webhook. No new events will be queued until it is re-enabled
293
+ * via {@link enable}. In-flight events already being processed will still
294
+ * complete.
295
+ *
296
+ * @param opts.reason Optional human-readable note stored on the webhook
297
+ * and surfaced in the dashboard.
298
+ */
299
+ disable(webhookId: string, opts?: {
300
+ reason?: string | null | undefined;
301
+ } | null | undefined): Promise<WebhookInfo>;
302
+ /**
303
+ * Returns a page of events for a webhook, newest first.
304
+ *
305
+ * Events are retained for ~60 days. To paginate, pass the previous page's
306
+ * `pageInfo.endCursor` as `opts.after`; stop when `pageInfo.hasNextPage`
307
+ * is `false`.
308
+ */
309
+ listEvents(webhookId: string, opts?: {
310
+ after?: string | null | undefined;
311
+ } | null | undefined): Promise<WebhookEventsPage>;
312
+ /**
313
+ * Fetches a single webhook event by its `isn`.
314
+ */
315
+ getEvent(webhookId: string, isn: string): Promise<WebhookEventInfo>;
316
+ /** Returns the full payload for an event. */
317
+ getPayload(webhookId: string, isn: string): Promise<WebhookPayload<Schema>>;
318
+ /**
319
+ * Re-queues an event for delivery, regardless of its current status. Use
320
+ * this to retry a `failed` event or force a redelivery of a `success` one.
321
+ *
322
+ * The server rate-limits resends; if the event was queued or resent very
323
+ * recently the call will fail with a validation error asking you to try
324
+ * again in about a minute.
325
+ */
326
+ resendEvent(webhookId: string, isn: string): Promise<WebhookEventInfo>;
327
+ }
328
+ /**
329
+ * Verify incoming webhook requests from Instant, dispatch their records to
330
+ * typed handlers, and manage webhook subscriptions (via {@link manager}).
331
+ *
332
+ * Usually accessed as `db.webhooks` on the admin or platform SDK rather than
333
+ * constructed directly.
334
+ */
335
+ export declare class Webhooks<Schema extends InstantSchemaDef<any, any, any>> {
336
+ #private;
337
+ /** App this instance is bound to. */
338
+ appId: string | null | undefined;
339
+ /** Schema used to type webhook payloads and handler records. */
340
+ schema: Schema | null | undefined;
341
+ /** Base URL for the Instant API. */
342
+ apiURI: string;
343
+ /** Manage webhook subscriptions and inspect delivery events. */
344
+ manager: WebhooksManager<Schema>;
345
+ /**
346
+ * Schema-bound helpers for building typed handler maps.
347
+ *
348
+ * - `typedHandlers(namespace, action, handler)` builds a single typed entry.
349
+ * Pass `'$default'` for `namespace` to register a catch-all handler.
350
+ * - `combineHandlers(...entries)` merges entries into a
351
+ * {@link WebhookHandlers} object suitable for {@link processPayload} and
352
+ * {@link processRequest}.
353
+ *
354
+ * If you already have a {@link Webhooks} instance, prefer the instance
355
+ * form (`db.webhooks.helpers()`) — it infers `Schema` automatically.
356
+ *
357
+ * @example
358
+ * const { typedHandlers, combineHandlers } = Webhooks.helpers<typeof schema>();
359
+ * const handlers = combineHandlers(
360
+ * typedHandlers('posts', 'create', (record) => { ... }),
361
+ * typedHandlers('comments', '$default', (record) => { ... }),
362
+ * typedHandlers('$default', (record) => { ... }),
363
+ * );
364
+ */
365
+ static helpers<Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema>(): WebhookHelpers<Schema>;
366
+ /**
367
+ * Instance form of {@link Webhooks.helpers} that infers `Schema` from this
368
+ * instance — no `<typeof schema>` type argument required.
369
+ *
370
+ * @example
371
+ * const { typedHandlers, combineHandlers } = db.webhooks.helpers();
372
+ */
373
+ helpers(): WebhookHelpers<Schema>;
374
+ constructor(config: Config<Schema>, jsonFetch?: JsonFetch);
375
+ /** Fetches Instant's JWK set for verifying webhook signatures. */
376
+ fetchJwks(): Promise<any>;
377
+ /**
378
+ * Resolves a `kid` to an imported {@link CryptoKey}, hitting a
379
+ * process-wide cache on repeat calls. Falls back to {@link fetchJwks} if
380
+ * the key isn't already known.
381
+ */
382
+ keyOfKid(kid: string): Promise<{
383
+ alg: ImportAlgorithm;
384
+ key: CryptoKey;
385
+ }>;
386
+ /**
387
+ * Verifies an `Instant-Signature` header against a body and returns the
388
+ * parsed {@link WebhookBody} (containing the `payloadUrl` and a JWT
389
+ * `token` for fetching the records).
390
+ *
391
+ * Throws if the signature doesn't validate, the signature is older than
392
+ * `opts.tolerance` (default 300 seconds), or the body doesn't decode to
393
+ * the expected shape.
394
+ *
395
+ * @param body Either the raw body string, or a function returning it.
396
+ * Use a function to defer reading the body until after the
397
+ * header has been parsed.
398
+ */
399
+ validate(signatureHeader: string, body: string | (() => Promise<string>), opts?: {
400
+ receivedAt?: Date | null | undefined;
401
+ tolerance?: number | null | undefined;
402
+ } | null | undefined): Promise<WebhookBody>;
403
+ /**
404
+ * Pulls the `Instant-Signature` header and body from a `Request` and
405
+ * delegates to {@link validate}. Throws if the header is missing.
406
+ */
407
+ validateRequest(req: Request, opts?: {
408
+ tolerance?: number | null | undefined;
409
+ receivedAt?: Date | null | undefined;
410
+ } | null | undefined): Promise<WebhookBody>;
411
+ /**
412
+ * Fetches the records and `idempotencyKey` for a validated
413
+ * {@link WebhookBody}, authenticating with the JWT `token` it carries.
414
+ */
415
+ fetchPayloads({ payloadUrl, token, }: WebhookBody): Promise<WebhookPayload<Schema>>;
416
+ /**
417
+ * Dispatches each record in `payload` to its matching handler in
418
+ * `handlers`. Resolution order per record: exact `namespace` + `action` →
419
+ * `namespace`'s `$default` → top-level `$default`. Records with no matching
420
+ * handler are skipped.
421
+ *
422
+ * Handlers run concurrently. If any handler rejects, the call rejects so
423
+ * the caller (e.g. {@link processRequest}) can return a non-2xx response
424
+ * and let Instant retry the event.
425
+ */
426
+ processPayload(handlers: WebhookHandlers<Schema>, payload: WebhookPayload<Schema>): Promise<void>;
427
+ /**
428
+ * The one-liner for handling webhooks. Hand it your handlers and the
429
+ * incoming `Request` — it verifies the signature, fetches the records, and
430
+ * dispatches each one to your code.
431
+ *
432
+ * Async handlers are executed in parallel, the return promise will resolve once
433
+ * all handlers complete and will reject if any of the handlers fails.
434
+ *
435
+ * @example
436
+ * const { typedHandlers, combineHandlers } = db.webhooks.helpers();
437
+ *
438
+ * const handlers = combineHandlers(
439
+ * typedHandlers('posts', 'create', async (record) => {
440
+ * await sendNewPostEmail(record.after);
441
+ * }),
442
+ * typedHandlers('$default', (record) => {
443
+ * console.log('webhook event', record);
444
+ * }),
445
+ * );
446
+ *
447
+ * export async function POST(req: Request) {
448
+ * await db.webhooks.processRequest(handlers, req);
449
+ * return new Response('ok');
450
+ * }
451
+ */
452
+ processRequest(handlers: WebhookHandlers<Schema>, req: Request, opts?: {
453
+ tolerance?: number | null | undefined;
454
+ receivedAt?: Date | null | undefined;
455
+ } | null | undefined): Promise<void>;
456
+ /**
457
+ * Adapter for frameworks that hand you a Node-style `http.IncomingMessage`
458
+ * (Next.js Pages Router, Express, Koa, etc.) instead of a Web `Request`.
459
+ * Wraps the request in a Web `Request` and delegates to
460
+ * {@link processRequest}. You still send the HTTP response yourself.
461
+ *
462
+ * The raw body is required for signature verification. The adapter picks
463
+ * it up from one of:
464
+ *
465
+ * - `req.body` if it's a `Buffer` or `Uint8Array` (set by middleware like
466
+ * `express.raw({ type: 'application/json' })`)
467
+ * - `req.body` if it's a string (set by middleware like `express.text()`)
468
+ * - otherwise the unconsumed request stream
469
+ *
470
+ * Don't use a JSON body parser on this route — `express.json()` and
471
+ * `bodyParser: true` in Next.js both parse the body into an object,
472
+ * destroying the raw bytes the signature was computed over.
473
+ *
474
+ * @example
475
+ * // Next.js Pages Router (`pages/api/webhooks.ts`)
476
+ * import type { NextApiRequest, NextApiResponse } from 'next';
477
+ *
478
+ * export const config = { api: { bodyParser: false } };
479
+ *
480
+ * const { typedHandlers, combineHandlers } = db.webhooks.helpers();
481
+ *
482
+ * const handlers = combineHandlers(
483
+ * typedHandlers('posts', 'create', async (record) => {
484
+ * await sendNewPostEmail(record.after);
485
+ * }),
486
+ * typedHandlers('$default', (record) => {
487
+ * console.log('unhandled record', record);
488
+ * }),
489
+ * );
490
+ *
491
+ * export default async function handler(
492
+ * req: NextApiRequest,
493
+ * res: NextApiResponse,
494
+ * ) {
495
+ * try {
496
+ * await db.webhooks.processNodeRequest(handlers, req);
497
+ * res.status(200).end();
498
+ * } catch (e) {
499
+ * res.status(400).json({ error: String(e) });
500
+ * }
501
+ * }
502
+ *
503
+ * @example
504
+ * // Express — skip the JSON body parser on the webhook route and use
505
+ * // `express.raw()` so `req.body` arrives as a Buffer.
506
+ * import express from 'express';
507
+ *
508
+ * const app = express();
509
+ *
510
+ * app.use((req, res, next) => {
511
+ * if (req.originalUrl === '/webhooks/instant') return next();
512
+ * express.json()(req, res, next);
513
+ * });
514
+ *
515
+ * app.post(
516
+ * '/webhooks/instant',
517
+ * express.raw({ type: 'application/json' }),
518
+ * async (req, res) => {
519
+ * try {
520
+ * await db.webhooks.processNodeRequest(handlers, req);
521
+ * res.status(200).end();
522
+ * } catch (e) {
523
+ * res.status(400).json({ error: String(e) });
524
+ * }
525
+ * },
526
+ * );
527
+ *
528
+ * @example
529
+ * // Koa — `ctx.req` is the raw IncomingMessage. If `koa-bodyparser` (or
530
+ * // similar) runs on this route it consumes the stream, so either skip it
531
+ * // here or pull the raw body yourself and shim it onto the request:
532
+ * import Koa from 'koa';
533
+ * import Router from '@koa/router';
534
+ * import rawBody from 'raw-body';
535
+ *
536
+ * const router = new Router();
537
+ *
538
+ * router.post('/webhooks/instant', async (ctx) => {
539
+ * try {
540
+ * await db.webhooks.processNodeRequest(handlers, ctx.req, {
541
+ * body: rawBody(ctx.req), // adapter awaits the Promise
542
+ * });
543
+ * ctx.status = 200;
544
+ * } catch (e) {
545
+ * ctx.status = 400;
546
+ * ctx.body = { error: String(e) };
547
+ * }
548
+ * });
549
+ *
550
+ * @example
551
+ * // NestJS (Express adapter). With `rawBody: true` on the factory, Nest
552
+ * // populates `req.rawBody` itself — just pass `req`.
553
+ * import { Controller, Post, Req, HttpCode } from '@nestjs/common';
554
+ * import type { Request } from 'express';
555
+ *
556
+ * @Controller('webhooks')
557
+ * export class WebhooksController {
558
+ * @Post('instant')
559
+ * @HttpCode(200)
560
+ * async handle(@Req() req: Request) {
561
+ * await db.webhooks.processNodeRequest(handlers, req);
562
+ * }
563
+ * }
564
+ *
565
+ * // (Pair with `NestFactory.create(AppModule, { rawBody: true })` in main.ts.)
566
+ */
567
+ processNodeRequest(handlers: WebhookHandlers<Schema>, req: {
568
+ url?: string;
569
+ method?: string;
570
+ headers: Record<string, string | string[] | undefined>;
571
+ body?: unknown;
572
+ rawBody?: unknown;
573
+ [Symbol.asyncIterator]?: () => AsyncIterableIterator<Uint8Array | string>;
574
+ }, opts?: {
575
+ /**
576
+ * Raw body to use instead of reading from `req`. Useful for
577
+ * frameworks that hand you the body separately from the request
578
+ * object (e.g. NestJS `@RawBody()`, Koa with `raw-body`).
579
+ * Accepts a `Buffer` / `Uint8Array`, a string, or a Promise of
580
+ * either.
581
+ */
582
+ body?: unknown;
583
+ tolerance?: number | null | undefined;
584
+ receivedAt?: Date | null | undefined;
585
+ } | null | undefined): Promise<void>;
586
+ }
587
+ export {};
588
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,gBAAgB,EAChB,oBAAoB,EACpB,YAAY,EAEb,MAAM,kBAAkB,CAAC;AAE1B,KAAK,MAAM,CAAC,MAAM,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI;IAC5D,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAClC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACvC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnC;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF,KAAK,SAAS,GAAG,CACf,KAAK,EAAE,WAAW,EAClB,IAAI,CAAC,EAAE,WAAW,GAAG,SAAS,KAC3B,OAAO,CAAC,GAAG,CAAC,CAAC;AAElB;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,EACvB,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,KACrC,OAAO,CAAC,CAAC,CAAC,CAAC;AAEhB,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,EAAE,MAA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