@webhooks-cc/sdk 0.5.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 -324
- package/dist/index.d.ts +137 -324
- package/dist/index.js +1846 -163
- package/dist/index.mjs +1731 -286
- 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,325 +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
|
-
requests: Record<string, OperationDescription>;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Base error class for all webhooks.cc SDK errors.
|
|
207
|
-
* Extends the standard Error with an HTTP status code.
|
|
208
|
-
*/
|
|
209
|
-
declare class WebhooksCCError extends Error {
|
|
210
|
-
readonly statusCode: number;
|
|
211
|
-
constructor(statusCode: number, message: string);
|
|
212
|
-
}
|
|
213
|
-
/** Thrown when the API key is invalid or missing (401). */
|
|
214
|
-
declare class UnauthorizedError extends WebhooksCCError {
|
|
215
|
-
constructor(message?: string);
|
|
216
|
-
}
|
|
217
|
-
/** Thrown when the requested resource does not exist (404). */
|
|
218
|
-
declare class NotFoundError extends WebhooksCCError {
|
|
219
|
-
constructor(message?: string);
|
|
220
|
-
}
|
|
221
|
-
/** Thrown when the request times out. */
|
|
222
|
-
declare class TimeoutError extends WebhooksCCError {
|
|
223
|
-
constructor(timeoutMs: number);
|
|
224
|
-
}
|
|
225
|
-
/** Thrown when the API returns 429 Too Many Requests. */
|
|
226
|
-
declare class RateLimitError extends WebhooksCCError {
|
|
227
|
-
/** Seconds until the rate limit resets, if provided by the server. */
|
|
228
|
-
readonly retryAfter?: number;
|
|
229
|
-
constructor(retryAfter?: number);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* @fileoverview webhooks.cc SDK client for programmatic webhook management.
|
|
234
|
-
*
|
|
235
|
-
* @example
|
|
236
|
-
* ```typescript
|
|
237
|
-
* import { WebhooksCC, matchMethod } from '@webhooks-cc/sdk';
|
|
238
|
-
*
|
|
239
|
-
* const client = new WebhooksCC({ apiKey: 'whcc_...' });
|
|
240
|
-
* const endpoint = await client.endpoints.create({ name: 'My Webhook' });
|
|
241
|
-
* const request = await client.requests.waitFor(endpoint.slug, {
|
|
242
|
-
* timeout: '30s',
|
|
243
|
-
* match: matchMethod('POST'),
|
|
244
|
-
* });
|
|
245
|
-
* ```
|
|
246
|
-
*/
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* @deprecated Use {@link WebhooksCCError} instead. Kept for backward compatibility.
|
|
250
|
-
*/
|
|
251
|
-
declare const ApiError: typeof WebhooksCCError;
|
|
252
|
-
/**
|
|
253
|
-
* Client for the webhooks.cc API.
|
|
254
|
-
*
|
|
255
|
-
* Provides methods to create endpoints, list captured requests, and wait
|
|
256
|
-
* for incoming webhooks. Handles authentication, request signing, and
|
|
257
|
-
* response validation.
|
|
258
|
-
*/
|
|
259
|
-
declare class WebhooksCC {
|
|
260
|
-
private readonly apiKey;
|
|
261
|
-
private readonly baseUrl;
|
|
262
|
-
private readonly webhookUrl;
|
|
263
|
-
private readonly timeout;
|
|
264
|
-
private readonly hooks;
|
|
265
|
-
constructor(options: ClientOptions);
|
|
266
|
-
private request;
|
|
267
|
-
/** Returns a static description of all SDK operations (no API call). */
|
|
268
|
-
describe(): SDKDescription;
|
|
269
|
-
endpoints: {
|
|
270
|
-
create: (options?: CreateEndpointOptions) => Promise<Endpoint>;
|
|
271
|
-
list: () => Promise<Endpoint[]>;
|
|
272
|
-
get: (slug: string) => Promise<Endpoint>;
|
|
273
|
-
update: (slug: string, options: UpdateEndpointOptions) => Promise<Endpoint>;
|
|
274
|
-
delete: (slug: string) => Promise<void>;
|
|
275
|
-
send: (slug: string, options?: SendOptions) => Promise<Response>;
|
|
276
|
-
sendTemplate: (slug: string, options: SendTemplateOptions) => Promise<Response>;
|
|
277
|
-
};
|
|
278
|
-
/**
|
|
279
|
-
* Send a webhook directly to any URL with optional provider signing.
|
|
280
|
-
* Use this for local integration testing — send properly signed webhooks
|
|
281
|
-
* to localhost handlers without routing through webhooks.cc infrastructure.
|
|
282
|
-
*
|
|
283
|
-
* @param url - Target URL to send the webhook to (http or https)
|
|
284
|
-
* @param options - Method, headers, body, and optional provider signing
|
|
285
|
-
* @returns Raw fetch Response from the target
|
|
286
|
-
*/
|
|
287
|
-
sendTo: (url: string, options?: SendToOptions) => Promise<Response>;
|
|
288
|
-
requests: {
|
|
289
|
-
list: (endpointSlug: string, options?: ListRequestsOptions) => Promise<Request[]>;
|
|
290
|
-
get: (requestId: string) => Promise<Request>;
|
|
291
|
-
/**
|
|
292
|
-
* Polls for incoming requests until one matches or timeout expires.
|
|
293
|
-
*
|
|
294
|
-
* Fetches requests that arrived since the last successful check. On API
|
|
295
|
-
* errors, continues polling without updating the timestamp to avoid
|
|
296
|
-
* missing requests during transient failures.
|
|
297
|
-
*
|
|
298
|
-
* @param endpointSlug - Endpoint to monitor
|
|
299
|
-
* @param options - Timeout, poll interval, and optional match filter
|
|
300
|
-
* @returns First matching request, or first request if no match filter
|
|
301
|
-
* @throws Error if timeout expires or max iterations (10000) reached
|
|
302
|
-
*/
|
|
303
|
-
waitFor: (endpointSlug: string, options?: WaitForOptions) => Promise<Request>;
|
|
304
|
-
/**
|
|
305
|
-
* Replay a captured request to a target URL.
|
|
306
|
-
*
|
|
307
|
-
* Fetches the original request by ID and re-sends it to the specified URL
|
|
308
|
-
* with the original method, headers, and body. Hop-by-hop headers are stripped.
|
|
309
|
-
*/
|
|
310
|
-
replay: (requestId: string, targetUrl: string) => Promise<Response>;
|
|
311
|
-
/**
|
|
312
|
-
* Stream incoming requests via SSE as an async iterator.
|
|
313
|
-
*
|
|
314
|
-
* Connects to the SSE endpoint and yields Request objects as they arrive.
|
|
315
|
-
* The connection is closed when the iterator is broken, the signal is aborted,
|
|
316
|
-
* or the timeout expires.
|
|
317
|
-
*
|
|
318
|
-
* No automatic reconnection — if the connection drops, the iterator ends.
|
|
319
|
-
*/
|
|
320
|
-
subscribe: (slug: string, options?: SubscribeOptions) => AsyncIterable<Request>;
|
|
321
|
-
};
|
|
322
|
-
}
|
|
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';
|
|
323
3
|
|
|
324
4
|
/**
|
|
325
5
|
* Safely parse a JSON request body.
|
|
@@ -348,6 +28,21 @@ declare function isGitHubWebhook(request: Request): boolean;
|
|
|
348
28
|
* ```
|
|
349
29
|
*/
|
|
350
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;
|
|
351
46
|
/** Check if a request looks like a Shopify webhook. */
|
|
352
47
|
declare function isShopifyWebhook(request: Request): boolean;
|
|
353
48
|
/** Check if a request looks like a Slack webhook. */
|
|
@@ -358,6 +53,8 @@ declare function isTwilioWebhook(request: Request): boolean;
|
|
|
358
53
|
declare function isPaddleWebhook(request: Request): boolean;
|
|
359
54
|
/** Check if a request looks like a Linear webhook. */
|
|
360
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;
|
|
361
58
|
/**
|
|
362
59
|
* Check if a request looks like a Standard Webhooks request.
|
|
363
60
|
* Matches on the presence of all three Standard Webhooks headers:
|
|
@@ -369,6 +66,10 @@ declare function isStandardWebhook(request: Request): boolean;
|
|
|
369
66
|
declare function matchMethod(method: string): (request: Request) => boolean;
|
|
370
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. */
|
|
371
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;
|
|
372
73
|
/**
|
|
373
74
|
* Match requests by a dot-notation path into the JSON body.
|
|
374
75
|
* Supports array indexing with numeric path segments (e.g., `"items.0.id"`).
|
|
@@ -381,6 +82,10 @@ declare function matchHeader(name: string, value?: string): (request: Request) =
|
|
|
381
82
|
* ```
|
|
382
83
|
*/
|
|
383
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;
|
|
384
89
|
/** Match when ALL matchers return true. Requires at least one matcher. */
|
|
385
90
|
declare function matchAll(first: (request: Request) => boolean, ...rest: Array<(request: Request) => boolean>): (request: Request) => boolean;
|
|
386
91
|
/** Match when ANY matcher returns true. Requires at least one matcher. */
|
|
@@ -392,7 +97,7 @@ declare function matchAny(first: (request: Request) => boolean, ...rest: Array<(
|
|
|
392
97
|
* Accepts:
|
|
393
98
|
* - Numbers: passed through as-is (treated as milliseconds)
|
|
394
99
|
* - Numeric strings: `"500"` → 500
|
|
395
|
-
* - 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
|
|
396
101
|
*
|
|
397
102
|
* @throws {Error} If the input string is not a valid duration format
|
|
398
103
|
*/
|
|
@@ -415,4 +120,112 @@ interface SSEFrame {
|
|
|
415
120
|
*/
|
|
416
121
|
declare function parseSSE(stream: ReadableStream<Uint8Array>): AsyncGenerator<SSEFrame, void, undefined>;
|
|
417
122
|
|
|
418
|
-
|
|
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 };
|