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: 10 additions & 8 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ export const RESEND_ERROR_CODES_BY_KEY = {

export type RESEND_ERROR_CODE_KEY = keyof typeof RESEND_ERROR_CODES_BY_KEY;

export type RateLimitExceededErrorResponse = {
message: string;
name: Extract<RESEND_ERROR_CODE_KEY, 'rate_limit_exceeded'>;
/**
* Time in seconds.
*/
retryAfter: number;
};

export type ErrorResponse =
| {
message: string;
name: Exclude<RESEND_ERROR_CODE_KEY, 'rate_limit_exceeded'>;
}
| {
message: string;
name: Extract<RESEND_ERROR_CODE_KEY, 'rate_limit_exceeded'>;
/**
* Time in seconds.
*/
retryAfter: number;
};
| RateLimitExceededErrorResponse;

export type Response<Data> =
| {
Expand Down
8 changes: 3 additions & 5 deletions src/rate-limiting.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// @ts-expect-error: this is used in the jsdoc for `shouldResetAfter`
// biome-ignore lint/correctness/noUnusedImports: this is used in the jsdoc for `shouldResetAfter`
import type { Response } from './interfaces';
import type { RateLimitExceededErrorResponse } from './interfaces';

export type RateLimit = {
/**
* The maximum amount of requests that can be made in the time window of {@link shouldResetAfter}.
* The maximum amount of requests that can be made in the time window of {@link RateLimit.shouldResetAfter}.
*/
limit: number;
/**
Expand All @@ -18,7 +16,7 @@ export type RateLimit = {
* and {@link RateLimit.remainingRequests} goes back to the value of
* {@link RateLimit.limit}.
*
* @see {@link import('./interfaces').Response.retryAfter}
* @see {@link RateLimitExceededErrorResponse.retryAfter}
*/
shouldResetAfter: number;
};
Expand Down