Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions javascript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
],
"license": "MIT",
"devDependencies": {
"@types/node": "^22.20.1",
"oxlint": "^1.77.0",
"tsup": "^8.0.0",
"typescript": "^7.0.2",
Expand Down
3 changes: 3 additions & 0 deletions javascript/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { resolveConfig, type CosmonerConfig, type ResolvedConfig } from "./config";
import { EmailService } from "./services/email";
import { WebhooksService } from "./services/webhooks";
import { Transport } from "./transport";

/**
Expand All @@ -27,6 +28,7 @@ export class Cosmoner {
private readonly transport: Transport;

readonly email: EmailService;
readonly webhooks: WebhooksService;

constructor(config: CosmonerConfig) {
this.config = resolveConfig(config);
Expand All @@ -39,5 +41,6 @@ export class Cosmoner {

this.transport = new Transport(this.config);
this.email = new EmailService(this.transport, this.config);
this.webhooks = new WebhooksService(this.transport, this.config);
}
}
14 changes: 14 additions & 0 deletions javascript/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ export class ServerError extends CosmonerError {
}
}

/**
* A received webhook could not be verified against its signing secret.
*
* Unlike the rest of the hierarchy this never comes from an API response — it
* is raised locally while checking an inbound request, so it carries no
* meaningful HTTP status.
*/
export class WebhookSignatureError extends CosmonerError {
constructor(message: string) {
super(0, "WEBHOOK_SIGNATURE_INVALID", message);
this.name = "WebhookSignatureError";
}
}

/** Shape of the API's error envelope. */
interface ErrorEnvelope {
success?: false;
Expand Down
35 changes: 35 additions & 0 deletions javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,47 @@ export {
RateLimitError,
ServerError,
ValidationError,
WebhookSignatureError,
} from "./errors";
export {
EmailService,
type SendEmailParams,
type SendEmailResponse,
} from "./services/email";
export {
WEBHOOK_EVENT_TYPES,
WebhooksService,
type CreateWebhookEndpointParams,
type CreateWebhookEndpointResponse,
type DeleteWebhookEndpointResponse,
type GetWebhookEndpointResponse,
type ListDeliveriesParams,
type ListWebhookDeliveriesResponse,
type ListWebhookEndpointsResponse,
type ReplayWebhookDeliveryResponse,
type ResumeWebhookEndpointResponse,
type RotateWebhookSecretResponse,
type TestWebhookEndpointResponse,
type UpdateWebhookEndpointParams,
type UpdateWebhookEndpointResponse,
type WebhookDelivery,
type WebhookDeliveryStatus,
type WebhookDisabledReason,
type WebhookEndpoint,
type WebhookEndpointStats,
type WebhookEndpointWithSecret,
type WebhookEventType,
} from "./services/webhooks";
export {
constructEvent,
DEFAULT_TOLERANCE_SECONDS,
DELIVERY_ID_HEADER,
EVENT_TYPE_HEADER,
SIGNATURE_HEADER,
verifyWebhookSignature,
type VerifyWebhookParams,
type WebhookEvent,
} from "./webhooks/signature";
export { VERSION } from "./version";

import { Cosmoner } from "./client";
Expand Down
Loading