feat: add webhooks (#334)

This commit is contained in:
KM Koushik
2026-01-18 20:50:54 +11:00
committed by GitHub
parent f40a311cc9
commit 8676965019
58 changed files with 5334 additions and 245 deletions
+23 -1
View File
@@ -3,6 +3,7 @@ import { Contacts } from "./contact";
import { Emails } from "./email";
import { Domains } from "./domain";
import { Campaigns } from "./campaign";
import { Webhooks } from "./webhooks";
const defaultBaseUrl = "https://app.usesend.com";
// eslint-disable-next-line turbo/no-undeclared-env-vars
@@ -19,7 +20,6 @@ type RequestOptions = {
export class UseSend {
private readonly baseHeaders: Headers;
// readonly domains = new Domains(this);
readonly emails = new Emails(this);
readonly domains = new Domains(this);
readonly contacts = new Contacts(this);
@@ -171,4 +171,26 @@ export class UseSend {
return this.fetchRequest<T>(path, requestOptions);
}
/**
* Creates a webhook handler with the given secret.
* Follows the Stripe pattern: `usesend.webhooks(secret).constructEvent(...)`
*
* @param secret - Webhook signing secret from your UseSend dashboard
* @returns Webhooks instance for verifying webhook events
*
* @example
* ```ts
* const usesend = new UseSend('us_xxx');
* const webhooks = usesend.webhooks('whsec_xxx');
*
* // In your webhook route
* const event = webhooks.constructEvent(req.body, {
* headers: req.headers
* });
* ```
*/
webhooks(secret: string): Webhooks {
return new Webhooks(secret);
}
}