@webhooks-cc/sdk 0.6.0 → 1.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.
- package/README.md +316 -140
- package/dist/chunk-7IMPSHQY.mjs +236 -0
- package/dist/diff-Dn4j4B_n.d.mts +701 -0
- package/dist/diff-Dn4j4B_n.d.ts +701 -0
- package/dist/index.d.mts +137 -340
- package/dist/index.d.ts +137 -340
- package/dist/index.js +1776 -168
- package/dist/index.mjs +1661 -291
- package/dist/testing.d.mts +30 -0
- package/dist/testing.d.ts +30 -0
- package/dist/testing.js +360 -0
- package/dist/testing.mjs +124 -0
- package/package.json +9 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,341 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Create endpoints via the dashboard or SDK to receive webhooks.
|
|
4
|
-
*/
|
|
5
|
-
interface Endpoint {
|
|
6
|
-
/** Unique identifier for this endpoint */
|
|
7
|
-
id: string;
|
|
8
|
-
/** URL-safe identifier used in webhook URLs (/w/{slug}) */
|
|
9
|
-
slug: string;
|
|
10
|
-
/** Display name for the endpoint */
|
|
11
|
-
name?: string;
|
|
12
|
-
/** Full URL where webhooks should be sent (undefined if server is misconfigured) */
|
|
13
|
-
url?: string;
|
|
14
|
-
/** Unix timestamp (ms) when the endpoint was created */
|
|
15
|
-
createdAt: number;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* A captured webhook request with full HTTP details.
|
|
19
|
-
* Stored when a webhook arrives at an endpoint.
|
|
20
|
-
*/
|
|
21
|
-
interface Request {
|
|
22
|
-
/** Unique identifier for this request */
|
|
23
|
-
id: string;
|
|
24
|
-
/** Endpoint that received this request */
|
|
25
|
-
endpointId: string;
|
|
26
|
-
/** HTTP method (GET, POST, PUT, etc.) */
|
|
27
|
-
method: string;
|
|
28
|
-
/** Request path after the endpoint slug */
|
|
29
|
-
path: string;
|
|
30
|
-
/** HTTP headers from the original request */
|
|
31
|
-
headers: Record<string, string>;
|
|
32
|
-
/** Request body, if present */
|
|
33
|
-
body?: string;
|
|
34
|
-
/** URL query parameters */
|
|
35
|
-
queryParams: Record<string, string>;
|
|
36
|
-
/** Content-Type header value, if present */
|
|
37
|
-
contentType?: string;
|
|
38
|
-
/** Client IP address */
|
|
39
|
-
ip: string;
|
|
40
|
-
/** Request body size in bytes */
|
|
41
|
-
size: number;
|
|
42
|
-
/** Unix timestamp (ms) when the request arrived */
|
|
43
|
-
receivedAt: number;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Options for creating a new endpoint.
|
|
47
|
-
*/
|
|
48
|
-
interface CreateEndpointOptions {
|
|
49
|
-
/** Display name for the endpoint */
|
|
50
|
-
name?: string;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Options for updating an existing endpoint.
|
|
54
|
-
*/
|
|
55
|
-
interface UpdateEndpointOptions {
|
|
56
|
-
/** New display name */
|
|
57
|
-
name?: string;
|
|
58
|
-
/** Mock response config, or null to clear */
|
|
59
|
-
mockResponse?: {
|
|
60
|
-
status: number;
|
|
61
|
-
body: string;
|
|
62
|
-
headers: Record<string, string>;
|
|
63
|
-
} | null;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Options for sending a test webhook to an endpoint.
|
|
67
|
-
*/
|
|
68
|
-
interface SendOptions {
|
|
69
|
-
/** HTTP method (default: "POST") */
|
|
70
|
-
method?: string;
|
|
71
|
-
/** HTTP headers to include */
|
|
72
|
-
headers?: Record<string, string>;
|
|
73
|
-
/** Request body (will be JSON-serialized if not a string) */
|
|
74
|
-
body?: unknown;
|
|
75
|
-
}
|
|
76
|
-
type TemplateProvider = "stripe" | "github" | "shopify" | "twilio" | "standard-webhooks";
|
|
77
|
-
/**
|
|
78
|
-
* Options for sending a provider template webhook with signed headers.
|
|
79
|
-
*/
|
|
80
|
-
interface SendTemplateOptions {
|
|
81
|
-
/** Provider template to use */
|
|
82
|
-
provider: TemplateProvider;
|
|
83
|
-
/** Provider-specific template preset (uses provider default if omitted) */
|
|
84
|
-
template?: string;
|
|
85
|
-
/** Shared secret used for provider signature generation */
|
|
86
|
-
secret: string;
|
|
87
|
-
/** Provider event/topic name (provider default used if omitted) */
|
|
88
|
-
event?: string;
|
|
89
|
-
/** HTTP method override (default: "POST") */
|
|
90
|
-
method?: string;
|
|
91
|
-
/** Additional headers merged after template headers */
|
|
92
|
-
headers?: Record<string, string>;
|
|
93
|
-
/** Body override; if omitted a provider-specific template body is generated */
|
|
94
|
-
body?: unknown;
|
|
95
|
-
/** Unix timestamp (seconds) override for deterministic signatures in tests */
|
|
96
|
-
timestamp?: number;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Options for listing captured requests.
|
|
100
|
-
*/
|
|
101
|
-
interface ListRequestsOptions {
|
|
102
|
-
/** Maximum number of requests to return */
|
|
103
|
-
limit?: number;
|
|
104
|
-
/** Only return requests received after this timestamp (ms) */
|
|
105
|
-
since?: number;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Options for waitFor() polling behavior.
|
|
109
|
-
*/
|
|
110
|
-
interface WaitForOptions {
|
|
111
|
-
/** Maximum time to wait (ms or duration string like "30s", "5m") (default: 30000) */
|
|
112
|
-
timeout?: number | string;
|
|
113
|
-
/** Interval between polls (ms or duration string) (default: 500, min: 10, max: 60000) */
|
|
114
|
-
pollInterval?: number | string;
|
|
115
|
-
/** Filter function to match specific requests */
|
|
116
|
-
match?: (request: Request) => boolean;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Options for subscribe() SSE streaming.
|
|
120
|
-
*/
|
|
121
|
-
interface SubscribeOptions {
|
|
122
|
-
/** AbortSignal to cancel the subscription */
|
|
123
|
-
signal?: AbortSignal;
|
|
124
|
-
/** Maximum time to stream (ms or duration string like "30m") */
|
|
125
|
-
timeout?: number | string;
|
|
126
|
-
}
|
|
127
|
-
/** Info passed to the onRequest hook before a request is sent. */
|
|
128
|
-
interface RequestHookInfo {
|
|
129
|
-
method: string;
|
|
130
|
-
url: string;
|
|
131
|
-
}
|
|
132
|
-
/** Info passed to the onResponse hook after a successful response. */
|
|
133
|
-
interface ResponseHookInfo {
|
|
134
|
-
method: string;
|
|
135
|
-
url: string;
|
|
136
|
-
status: number;
|
|
137
|
-
durationMs: number;
|
|
138
|
-
}
|
|
139
|
-
/** Info passed to the onError hook when a request fails. */
|
|
140
|
-
interface ErrorHookInfo {
|
|
141
|
-
method: string;
|
|
142
|
-
url: string;
|
|
143
|
-
error: Error;
|
|
144
|
-
durationMs: number;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Lifecycle hooks for observability and telemetry integration.
|
|
148
|
-
* All hooks are optional and are called synchronously (fire-and-forget).
|
|
149
|
-
*/
|
|
150
|
-
interface ClientHooks {
|
|
151
|
-
onRequest?: (info: RequestHookInfo) => void;
|
|
152
|
-
onResponse?: (info: ResponseHookInfo) => void;
|
|
153
|
-
onError?: (info: ErrorHookInfo) => void;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Configuration options for the WebhooksCC client.
|
|
157
|
-
*/
|
|
158
|
-
interface ClientOptions {
|
|
159
|
-
/** API key for authentication (format: whcc_...) */
|
|
160
|
-
apiKey: string;
|
|
161
|
-
/** Base URL for the API (default: https://webhooks.cc) */
|
|
162
|
-
baseUrl?: string;
|
|
163
|
-
/** Base URL for sending webhooks (default: https://go.webhooks.cc) */
|
|
164
|
-
webhookUrl?: string;
|
|
165
|
-
/** Request timeout in milliseconds (default: 30000) */
|
|
166
|
-
timeout?: number;
|
|
167
|
-
/** Lifecycle hooks for observability */
|
|
168
|
-
hooks?: ClientHooks;
|
|
169
|
-
}
|
|
170
|
-
/** Description of a single SDK operation. */
|
|
171
|
-
interface OperationDescription {
|
|
172
|
-
description: string;
|
|
173
|
-
params: Record<string, string>;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Options for sending a webhook directly to an arbitrary URL.
|
|
177
|
-
* Supports optional provider signing (Standard Webhooks, Stripe, etc.).
|
|
178
|
-
*/
|
|
179
|
-
interface SendToOptions {
|
|
180
|
-
/** Provider template for signing (optional). When set, secret is required. */
|
|
181
|
-
provider?: TemplateProvider;
|
|
182
|
-
/** Provider-specific template preset (e.g. "checkout.session.completed" for Stripe) */
|
|
183
|
-
template?: string;
|
|
184
|
-
/** Secret for provider signature generation (required when provider is set) */
|
|
185
|
-
secret?: string;
|
|
186
|
-
/** Event name for provider headers */
|
|
187
|
-
event?: string;
|
|
188
|
-
/** HTTP method (default: "POST") */
|
|
189
|
-
method?: string;
|
|
190
|
-
/** HTTP headers to include */
|
|
191
|
-
headers?: Record<string, string>;
|
|
192
|
-
/** Request body (will be JSON-serialized if not a string) */
|
|
193
|
-
body?: unknown;
|
|
194
|
-
/** Unix timestamp (seconds) override for deterministic signatures in tests */
|
|
195
|
-
timestamp?: number;
|
|
196
|
-
}
|
|
197
|
-
/** Self-describing schema returned by client.describe(). */
|
|
198
|
-
interface SDKDescription {
|
|
199
|
-
version: string;
|
|
200
|
-
endpoints: Record<string, OperationDescription>;
|
|
201
|
-
sendTo: OperationDescription;
|
|
202
|
-
buildRequest: OperationDescription;
|
|
203
|
-
requests: Record<string, OperationDescription>;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Base error class for all webhooks.cc SDK errors.
|
|
208
|
-
* Extends the standard Error with an HTTP status code.
|
|
209
|
-
*/
|
|
210
|
-
declare class WebhooksCCError extends Error {
|
|
211
|
-
readonly statusCode: number;
|
|
212
|
-
constructor(statusCode: number, message: string);
|
|
213
|
-
}
|
|
214
|
-
/** Thrown when the API key is invalid or missing (401). */
|
|
215
|
-
declare class UnauthorizedError extends WebhooksCCError {
|
|
216
|
-
constructor(message?: string);
|
|
217
|
-
}
|
|
218
|
-
/** Thrown when the requested resource does not exist (404). */
|
|
219
|
-
declare class NotFoundError extends WebhooksCCError {
|
|
220
|
-
constructor(message?: string);
|
|
221
|
-
}
|
|
222
|
-
/** Thrown when the request times out. */
|
|
223
|
-
declare class TimeoutError extends WebhooksCCError {
|
|
224
|
-
constructor(timeoutMs: number);
|
|
225
|
-
}
|
|
226
|
-
/** Thrown when the API returns 429 Too Many Requests. */
|
|
227
|
-
declare class RateLimitError extends WebhooksCCError {
|
|
228
|
-
/** Seconds until the rate limit resets, if provided by the server. */
|
|
229
|
-
readonly retryAfter?: number;
|
|
230
|
-
constructor(retryAfter?: number);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* @fileoverview webhooks.cc SDK client for programmatic webhook management.
|
|
235
|
-
*
|
|
236
|
-
* @example
|
|
237
|
-
* ```typescript
|
|
238
|
-
* import { WebhooksCC, matchMethod } from '@webhooks-cc/sdk';
|
|
239
|
-
*
|
|
240
|
-
* const client = new WebhooksCC({ apiKey: 'whcc_...' });
|
|
241
|
-
* const endpoint = await client.endpoints.create({ name: 'My Webhook' });
|
|
242
|
-
* const request = await client.requests.waitFor(endpoint.slug, {
|
|
243
|
-
* timeout: '30s',
|
|
244
|
-
* match: matchMethod('POST'),
|
|
245
|
-
* });
|
|
246
|
-
* ```
|
|
247
|
-
*/
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* @deprecated Use {@link WebhooksCCError} instead. Kept for backward compatibility.
|
|
251
|
-
*/
|
|
252
|
-
declare const ApiError: typeof WebhooksCCError;
|
|
253
|
-
/**
|
|
254
|
-
* Client for the webhooks.cc API.
|
|
255
|
-
*
|
|
256
|
-
* Provides methods to create endpoints, list captured requests, and wait
|
|
257
|
-
* for incoming webhooks. Handles authentication, request signing, and
|
|
258
|
-
* response validation.
|
|
259
|
-
*/
|
|
260
|
-
declare class WebhooksCC {
|
|
261
|
-
private readonly apiKey;
|
|
262
|
-
private readonly baseUrl;
|
|
263
|
-
private readonly webhookUrl;
|
|
264
|
-
private readonly timeout;
|
|
265
|
-
private readonly hooks;
|
|
266
|
-
constructor(options: ClientOptions);
|
|
267
|
-
private request;
|
|
268
|
-
/** Returns a static description of all SDK operations (no API call). */
|
|
269
|
-
describe(): SDKDescription;
|
|
270
|
-
endpoints: {
|
|
271
|
-
create: (options?: CreateEndpointOptions) => Promise<Endpoint>;
|
|
272
|
-
list: () => Promise<Endpoint[]>;
|
|
273
|
-
get: (slug: string) => Promise<Endpoint>;
|
|
274
|
-
update: (slug: string, options: UpdateEndpointOptions) => Promise<Endpoint>;
|
|
275
|
-
delete: (slug: string) => Promise<void>;
|
|
276
|
-
send: (slug: string, options?: SendOptions) => Promise<Response>;
|
|
277
|
-
sendTemplate: (slug: string, options: SendTemplateOptions) => Promise<Response>;
|
|
278
|
-
};
|
|
279
|
-
/**
|
|
280
|
-
* Build a request without sending it. Returns the computed method, URL,
|
|
281
|
-
* headers, and body — including any provider signatures. Useful for
|
|
282
|
-
* debugging what sendTo would actually send.
|
|
283
|
-
*
|
|
284
|
-
* @param url - Target URL (http or https)
|
|
285
|
-
* @param options - Same options as sendTo
|
|
286
|
-
* @returns The computed request details
|
|
287
|
-
*/
|
|
288
|
-
buildRequest: (url: string, options?: SendToOptions) => Promise<{
|
|
289
|
-
url: string;
|
|
290
|
-
method: string;
|
|
291
|
-
headers: Record<string, string>;
|
|
292
|
-
body?: string;
|
|
293
|
-
}>;
|
|
294
|
-
/**
|
|
295
|
-
* Send a webhook directly to any URL with optional provider signing.
|
|
296
|
-
* Use this for local integration testing — send properly signed webhooks
|
|
297
|
-
* to localhost handlers without routing through webhooks.cc infrastructure.
|
|
298
|
-
*
|
|
299
|
-
* @param url - Target URL to send the webhook to (http or https)
|
|
300
|
-
* @param options - Method, headers, body, and optional provider signing
|
|
301
|
-
* @returns Raw fetch Response from the target
|
|
302
|
-
*/
|
|
303
|
-
sendTo: (url: string, options?: SendToOptions) => Promise<Response>;
|
|
304
|
-
requests: {
|
|
305
|
-
list: (endpointSlug: string, options?: ListRequestsOptions) => Promise<Request[]>;
|
|
306
|
-
get: (requestId: string) => Promise<Request>;
|
|
307
|
-
/**
|
|
308
|
-
* Polls for incoming requests until one matches or timeout expires.
|
|
309
|
-
*
|
|
310
|
-
* Fetches requests that arrived since the last successful check. On API
|
|
311
|
-
* errors, continues polling without updating the timestamp to avoid
|
|
312
|
-
* missing requests during transient failures.
|
|
313
|
-
*
|
|
314
|
-
* @param endpointSlug - Endpoint to monitor
|
|
315
|
-
* @param options - Timeout, poll interval, and optional match filter
|
|
316
|
-
* @returns First matching request, or first request if no match filter
|
|
317
|
-
* @throws Error if timeout expires or max iterations (10000) reached
|
|
318
|
-
*/
|
|
319
|
-
waitFor: (endpointSlug: string, options?: WaitForOptions) => Promise<Request>;
|
|
320
|
-
/**
|
|
321
|
-
* Replay a captured request to a target URL.
|
|
322
|
-
*
|
|
323
|
-
* Fetches the original request by ID and re-sends it to the specified URL
|
|
324
|
-
* with the original method, headers, and body. Hop-by-hop headers are stripped.
|
|
325
|
-
*/
|
|
326
|
-
replay: (requestId: string, targetUrl: string) => Promise<Response>;
|
|
327
|
-
/**
|
|
328
|
-
* Stream incoming requests via SSE as an async iterator.
|
|
329
|
-
*
|
|
330
|
-
* Connects to the SSE endpoint and yields Request objects as they arrive.
|
|
331
|
-
* The connection is closed when the iterator is broken, the signal is aborted,
|
|
332
|
-
* or the timeout expires.
|
|
333
|
-
*
|
|
334
|
-
* No automatic reconnection — if the connection drops, the iterator ends.
|
|
335
|
-
*/
|
|
336
|
-
subscribe: (slug: string, options?: SubscribeOptions) => AsyncIterable<Request>;
|
|
337
|
-
};
|
|
338
|
-
}
|
|
1
|
+
import { R as Request, P as ParsedBody, a as ParsedFormBody, S as SearchResult, V as VerifySignatureOptions, b as SignatureVerificationResult } from './diff-Dn4j4B_n.js';
|
|
2
|
+
export { A as ApiError, B as BodyDiff, C as ClearRequestsOptions, c as ClientHooks, d as ClientOptions, e as CreateEndpointOptions, f as CurlExport, D as DiffRequestsOptions, g as DiffResult, E as Endpoint, h as ErrorHookInfo, i as ExportRequestsOptions, F as FormBodyValue, H as HarExport, j as HeaderDiff, J as JsonBodyDiff, L as ListPaginatedRequestsOptions, k as ListRequestsOptions, M as MockResponse, N as NotFoundError, O as OperationDescription, l as PaginatedResult, m as RateLimitError, n as RequestDifferences, o as RequestHookInfo, p as RequestsExport, q as ResponseHookInfo, r as RetryOptions, s as SDKDescription, t as SearchFilters, u as SendOptions, v as SendTemplateOptions, w as SendToOptions, x as SubscribeOptions, T as TemplateProvider, y as TemplateProviderInfo, z as TextBodyDiff, G as TimeoutError, U as UnauthorizedError, I as UpdateEndpointOptions, K as UsageInfo, Q as ValueDifference, W as VerifyProvider, X as WaitForAllOptions, Y as WaitForOptions, Z as WebhookFlowBuilder, _ as WebhookFlowResult, $ as WebhookFlowVerifyOptions, a0 as WebhooksCC, a1 as WebhooksCCError, a2 as diffRequests } from './diff-Dn4j4B_n.js';
|
|
339
3
|
|
|
340
4
|
/**
|
|
341
5
|
* Safely parse a JSON request body.
|
|
@@ -364,6 +28,21 @@ declare function isGitHubWebhook(request: Request): boolean;
|
|
|
364
28
|
* ```
|
|
365
29
|
*/
|
|
366
30
|
declare function matchJsonField(field: string, value: unknown): (request: Request) => boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Parse an application/x-www-form-urlencoded request body.
|
|
33
|
+
* Repeated keys are returned as string arrays.
|
|
34
|
+
*/
|
|
35
|
+
declare function parseFormBody(request: Request): ParsedFormBody | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Parse the request body based on content-type.
|
|
38
|
+
* JSON and urlencoded bodies are decoded; other bodies are returned as raw text.
|
|
39
|
+
*/
|
|
40
|
+
declare function parseBody(request: Request): ParsedBody;
|
|
41
|
+
/**
|
|
42
|
+
* Extract a nested JSON field from the request body using dot notation.
|
|
43
|
+
* Returns undefined if the body is missing, invalid JSON, or the path is absent.
|
|
44
|
+
*/
|
|
45
|
+
declare function extractJsonField<T>(request: Request, path: string): T | undefined;
|
|
367
46
|
/** Check if a request looks like a Shopify webhook. */
|
|
368
47
|
declare function isShopifyWebhook(request: Request): boolean;
|
|
369
48
|
/** Check if a request looks like a Slack webhook. */
|
|
@@ -374,6 +53,8 @@ declare function isTwilioWebhook(request: Request): boolean;
|
|
|
374
53
|
declare function isPaddleWebhook(request: Request): boolean;
|
|
375
54
|
/** Check if a request looks like a Linear webhook. */
|
|
376
55
|
declare function isLinearWebhook(request: Request): boolean;
|
|
56
|
+
/** Check if a request looks like a Discord interaction webhook. */
|
|
57
|
+
declare function isDiscordWebhook(request: Request): boolean;
|
|
377
58
|
/**
|
|
378
59
|
* Check if a request looks like a Standard Webhooks request.
|
|
379
60
|
* Matches on the presence of all three Standard Webhooks headers:
|
|
@@ -385,6 +66,10 @@ declare function isStandardWebhook(request: Request): boolean;
|
|
|
385
66
|
declare function matchMethod(method: string): (request: Request) => boolean;
|
|
386
67
|
/** Match requests that have a specific header, optionally with a specific value. Header names are matched case-insensitively; values are matched with exact (case-sensitive) equality. */
|
|
387
68
|
declare function matchHeader(name: string, value?: string): (request: Request) => boolean;
|
|
69
|
+
/** Match request paths using glob-style wildcards. Supports `*` and `**`. */
|
|
70
|
+
declare function matchPath(pattern: string): (request: Request) => boolean;
|
|
71
|
+
/** Match query parameter presence or a specific query parameter value. */
|
|
72
|
+
declare function matchQueryParam(key: string, value?: string): (request: Request) => boolean;
|
|
388
73
|
/**
|
|
389
74
|
* Match requests by a dot-notation path into the JSON body.
|
|
390
75
|
* Supports array indexing with numeric path segments (e.g., `"items.0.id"`).
|
|
@@ -397,6 +82,10 @@ declare function matchHeader(name: string, value?: string): (request: Request) =
|
|
|
397
82
|
* ```
|
|
398
83
|
*/
|
|
399
84
|
declare function matchBodyPath(path: string, value: unknown): (request: Request) => boolean;
|
|
85
|
+
/** Match a deep partial subset of the parsed JSON body. */
|
|
86
|
+
declare function matchBodySubset(subset: Record<string, unknown>): (request: Request) => boolean;
|
|
87
|
+
/** Match the request content type, ignoring charset parameters. */
|
|
88
|
+
declare function matchContentType(type: string): (request: Request) => boolean;
|
|
400
89
|
/** Match when ALL matchers return true. Requires at least one matcher. */
|
|
401
90
|
declare function matchAll(first: (request: Request) => boolean, ...rest: Array<(request: Request) => boolean>): (request: Request) => boolean;
|
|
402
91
|
/** Match when ANY matcher returns true. Requires at least one matcher. */
|
|
@@ -408,7 +97,7 @@ declare function matchAny(first: (request: Request) => boolean, ...rest: Array<(
|
|
|
408
97
|
* Accepts:
|
|
409
98
|
* - Numbers: passed through as-is (treated as milliseconds)
|
|
410
99
|
* - Numeric strings: `"500"` → 500
|
|
411
|
-
* - Duration strings: `"30s"` → 30000, `"5m"` → 300000, `"1.5s"` → 1500, `"500ms"` → 500
|
|
100
|
+
* - Duration strings: `"30s"` → 30000, `"5m"` → 300000, `"1.5s"` → 1500, `"500ms"` → 500, `"7d"` → 604800000
|
|
412
101
|
*
|
|
413
102
|
* @throws {Error} If the input string is not a valid duration format
|
|
414
103
|
*/
|
|
@@ -431,4 +120,112 @@ interface SSEFrame {
|
|
|
431
120
|
*/
|
|
432
121
|
declare function parseSSE(stream: ReadableStream<Uint8Array>): AsyncGenerator<SSEFrame, void, undefined>;
|
|
433
122
|
|
|
434
|
-
|
|
123
|
+
declare const TEMPLATE_METADATA: Readonly<{
|
|
124
|
+
stripe: Readonly<{
|
|
125
|
+
provider: "stripe";
|
|
126
|
+
templates: readonly ("payment_intent.succeeded" | "checkout.session.completed" | "invoice.paid")[];
|
|
127
|
+
defaultTemplate: "payment_intent.succeeded";
|
|
128
|
+
secretRequired: true;
|
|
129
|
+
signatureHeader: "stripe-signature";
|
|
130
|
+
signatureAlgorithm: "hmac-sha256";
|
|
131
|
+
}>;
|
|
132
|
+
github: Readonly<{
|
|
133
|
+
provider: "github";
|
|
134
|
+
templates: readonly ("push" | "pull_request.opened" | "ping")[];
|
|
135
|
+
defaultTemplate: "push";
|
|
136
|
+
secretRequired: true;
|
|
137
|
+
signatureHeader: "x-hub-signature-256";
|
|
138
|
+
signatureAlgorithm: "hmac-sha256";
|
|
139
|
+
}>;
|
|
140
|
+
shopify: Readonly<{
|
|
141
|
+
provider: "shopify";
|
|
142
|
+
templates: readonly ("orders/create" | "orders/paid" | "products/update" | "app/uninstalled")[];
|
|
143
|
+
defaultTemplate: "orders/create";
|
|
144
|
+
secretRequired: true;
|
|
145
|
+
signatureHeader: "x-shopify-hmac-sha256";
|
|
146
|
+
signatureAlgorithm: "hmac-sha256";
|
|
147
|
+
}>;
|
|
148
|
+
twilio: Readonly<{
|
|
149
|
+
provider: "twilio";
|
|
150
|
+
templates: readonly ("messaging.inbound" | "messaging.status_callback" | "voice.incoming_call")[];
|
|
151
|
+
defaultTemplate: "messaging.inbound";
|
|
152
|
+
secretRequired: true;
|
|
153
|
+
signatureHeader: "x-twilio-signature";
|
|
154
|
+
signatureAlgorithm: "hmac-sha1";
|
|
155
|
+
}>;
|
|
156
|
+
slack: Readonly<{
|
|
157
|
+
provider: "slack";
|
|
158
|
+
templates: readonly ("event_callback" | "slash_command" | "url_verification")[];
|
|
159
|
+
defaultTemplate: "event_callback";
|
|
160
|
+
secretRequired: true;
|
|
161
|
+
signatureHeader: "x-slack-signature";
|
|
162
|
+
signatureAlgorithm: "hmac-sha256";
|
|
163
|
+
}>;
|
|
164
|
+
paddle: Readonly<{
|
|
165
|
+
provider: "paddle";
|
|
166
|
+
templates: readonly ("transaction.completed" | "subscription.created" | "subscription.updated")[];
|
|
167
|
+
defaultTemplate: "transaction.completed";
|
|
168
|
+
secretRequired: true;
|
|
169
|
+
signatureHeader: "paddle-signature";
|
|
170
|
+
signatureAlgorithm: "hmac-sha256";
|
|
171
|
+
}>;
|
|
172
|
+
linear: Readonly<{
|
|
173
|
+
provider: "linear";
|
|
174
|
+
templates: readonly ("issue.create" | "issue.update" | "comment.create")[];
|
|
175
|
+
defaultTemplate: "issue.create";
|
|
176
|
+
secretRequired: true;
|
|
177
|
+
signatureHeader: "linear-signature";
|
|
178
|
+
signatureAlgorithm: "hmac-sha256";
|
|
179
|
+
}>;
|
|
180
|
+
"standard-webhooks": Readonly<{
|
|
181
|
+
provider: "standard-webhooks";
|
|
182
|
+
templates: readonly never[];
|
|
183
|
+
secretRequired: true;
|
|
184
|
+
signatureHeader: "webhook-signature";
|
|
185
|
+
signatureAlgorithm: "hmac-sha256";
|
|
186
|
+
}>;
|
|
187
|
+
}>;
|
|
188
|
+
|
|
189
|
+
type VerifyableRequest = Pick<Request, "body" | "headers"> | Pick<SearchResult, "body" | "headers">;
|
|
190
|
+
/**
|
|
191
|
+
* Verify a Stripe webhook signature header against the raw request body.
|
|
192
|
+
*/
|
|
193
|
+
declare function verifyStripeSignature(body: string | undefined, signatureHeader: string | null | undefined, secret: string): Promise<boolean>;
|
|
194
|
+
/**
|
|
195
|
+
* Verify a GitHub webhook signature header against the raw request body.
|
|
196
|
+
*/
|
|
197
|
+
declare function verifyGitHubSignature(body: string | undefined, signatureHeader: string | null | undefined, secret: string): Promise<boolean>;
|
|
198
|
+
/**
|
|
199
|
+
* Verify a Shopify webhook signature header against the raw request body.
|
|
200
|
+
*/
|
|
201
|
+
declare function verifyShopifySignature(body: string | undefined, signatureHeader: string | null | undefined, secret: string): Promise<boolean>;
|
|
202
|
+
/**
|
|
203
|
+
* Verify a Twilio webhook signature against the signed URL and form body.
|
|
204
|
+
*/
|
|
205
|
+
declare function verifyTwilioSignature(url: string, body: string | Record<string, string> | undefined, signatureHeader: string | null | undefined, secret: string): Promise<boolean>;
|
|
206
|
+
/**
|
|
207
|
+
* Verify a Slack webhook signature from x-slack-signature and x-slack-request-timestamp headers.
|
|
208
|
+
*/
|
|
209
|
+
declare function verifySlackSignature(body: string | undefined, headers: Record<string, string>, secret: string): Promise<boolean>;
|
|
210
|
+
/**
|
|
211
|
+
* Verify a Paddle webhook signature from the paddle-signature header.
|
|
212
|
+
*/
|
|
213
|
+
declare function verifyPaddleSignature(body: string | undefined, signatureHeader: string | null | undefined, secret: string): Promise<boolean>;
|
|
214
|
+
/**
|
|
215
|
+
* Verify a Linear webhook signature against the raw request body.
|
|
216
|
+
*/
|
|
217
|
+
declare function verifyLinearSignature(body: string | undefined, signatureHeader: string | null | undefined, secret: string): Promise<boolean>;
|
|
218
|
+
/**
|
|
219
|
+
* Verify a Discord interaction signature using the application's Ed25519 public key.
|
|
220
|
+
*/
|
|
221
|
+
declare function verifyDiscordSignature(body: string | undefined, headers: Record<string, string>, publicKey: string): Promise<boolean>;
|
|
222
|
+
/**
|
|
223
|
+
* Verify a Standard Webhooks signature from webhook-id/timestamp/signature headers.
|
|
224
|
+
*/
|
|
225
|
+
declare function verifyStandardWebhookSignature(body: string | undefined, headers: Record<string, string>, secret: string): Promise<boolean>;
|
|
226
|
+
/**
|
|
227
|
+
* Verify a captured request using the provider-specific signature scheme.
|
|
228
|
+
*/
|
|
229
|
+
declare function verifySignature(request: VerifyableRequest, options: VerifySignatureOptions): Promise<SignatureVerificationResult>;
|
|
230
|
+
|
|
231
|
+
export { ParsedBody, ParsedFormBody, Request, type SSEFrame, SearchResult, SignatureVerificationResult, TEMPLATE_METADATA, VerifySignatureOptions, extractJsonField, isDiscordWebhook, isGitHubWebhook, isLinearWebhook, isPaddleWebhook, isShopifyWebhook, isSlackWebhook, isStandardWebhook, isStripeWebhook, isTwilioWebhook, matchAll, matchAny, matchBodyPath, matchBodySubset, matchContentType, matchHeader, matchJsonField, matchMethod, matchPath, matchQueryParam, parseBody, parseDuration, parseFormBody, parseJsonBody, parseSSE, verifyDiscordSignature, verifyGitHubSignature, verifyLinearSignature, verifyPaddleSignature, verifyShopifySignature, verifySignature, verifySlackSignature, verifyStandardWebhookSignature, verifyStripeSignature, verifyTwilioSignature };
|