Skip to content

Commit

Permalink
feat: Add update email (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
bukinoshita authored Aug 10, 2024
1 parent 2ecf9df commit ed62e54
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "resend",
"version": "3.6.0-canary.0",
"version": "3.6.0-canary.2",
"description": "Node.js library for the Resend API",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
15 changes: 15 additions & 0 deletions src/emails/emails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import type {
GetEmailResponse,
GetEmailResponseSuccess,
} from './interfaces/get-email-options.interface';
import type {
UpdateEmailOptions,
UpdateEmailResponse,
UpdateEmailResponseSuccess,
} from './interfaces/update-email-options.interface';

export class Emails {
constructor(private readonly resend: Resend) {}
Expand Down Expand Up @@ -52,6 +57,16 @@ export class Emails {
return data;
}

async update(payload: UpdateEmailOptions): Promise<UpdateEmailResponse> {
const data = await this.resend.patch<UpdateEmailResponseSuccess>(
`/emails/${payload.id}`,
{
scheduled_at: payload.scheduledAt,
},
);
return data;
}

async cancel(id: string): Promise<CancelEmailResponse> {
const data = await this.resend.post<CancelEmailResponseSuccess>(
`/emails/${id}/cancel`,
Expand Down
2 changes: 1 addition & 1 deletion src/emails/interfaces/create-email-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ interface CreateEmailBaseOptions {
*
* @link https://resend.com/docs/api-reference/emails/send-email#body-parameters
*/
scheduled_at: string;
scheduledAt: string;
}

export type CreateEmailOptions = RequireAtLeastOne<EmailRenderOptions> &
Expand Down
16 changes: 16 additions & 0 deletions src/emails/interfaces/update-email-options.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { ErrorResponse } from '../../interfaces';

export interface UpdateEmailOptions {
id: string;
scheduledAt: string;
}

export interface UpdateEmailResponseSuccess {
id: string;
object: 'email';
}

export interface UpdateEmailResponse {
data: UpdateEmailResponseSuccess | null;
error: ErrorResponse | null;
}

0 comments on commit ed62e54

Please sign in to comment.