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
15 changes: 15 additions & 0 deletions src/endpoints/email.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,21 @@ describe('EmailEndpoint', () => {
});
});

it('should set reusable tags', () => {
const tags = [{ name: 'campaign', value: 'welcome-v2' }];
const result = emailEndpoint.tags(tags);

expect(result).toBe(emailEndpoint);

return emailEndpoint.send().then(() => {
expect(client.post).toHaveBeenCalledWith(
'/send',
expect.objectContaining({ tags }),
undefined
);
});
});

it('should send the email with all options', async () => {
// Set up a complete email
emailEndpoint
Expand Down
11 changes: 11 additions & 0 deletions src/endpoints/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,17 @@ export class EmailEndpoint extends Endpoint {
return this;
}

/**
* Set reusable name-value tags for the email.
*
* @param tags The tags to attach to the email
* @returns The current instance for chaining
*/
public tags(tags: NonNullable<EmailPayload['tags']>): this {
this.payload.tags = tags;
return this;
}

/**
* Send the composed email using the current payload
*
Expand Down
30 changes: 28 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export interface SendMailRequest {
"headers"?: Record<string, string>;
"metadata"?: Record<string, string>;
"tag"?: string | null;
"tags"?: {
"name": string;
"value": string;
}[];
"settings"?: {
"track_opens"?: boolean;
"track_clicks"?: boolean;
Expand All @@ -41,6 +45,10 @@ export type SendBatchMailRequest = {
"headers"?: Record<string, string>;
"metadata"?: Record<string, string>;
"tag"?: string | null;
"tags"?: {
"name": string;
"value": string;
}[];
"settings"?: {
"track_opens"?: boolean;
"track_clicks"?: boolean;
Expand Down Expand Up @@ -134,6 +142,10 @@ export interface MessageData {
"status": MessageStatus;
"status_changed_at": string | null;
"tag": string | null;
"tags": {
"name": string;
"value": string;
}[];
"from_email": string;
"from_name": string | null;
"reply_to": string[] | null;
Expand All @@ -152,6 +164,11 @@ export interface MessageData {
export interface MessageEventData {
"message_id": string;
"event": MessageEventType;
"tag": string | null;
"tags": {
"name": string;
"value": string;
}[];
"metadata": Record<string, unknown> | null;
"timestamp": string;
}
Expand All @@ -171,6 +188,10 @@ export interface MessageListData {
"bcc": MessageRecipientData[] | null;
"reply_to": string[] | null;
"tag": string | null;
"tags": {
"name": string;
"value": string;
}[];
"status_changed_at": string | null;
"created_at": string;
}
Expand Down Expand Up @@ -246,6 +267,7 @@ export interface RouteData {
"track_clicks"?: boolean;
"generate_plaintext_fallback"?: boolean;
"suppress_auto_responders"?: boolean;
"suppress_disposable_recipients"?: boolean;
"tls"?: TlsPolicy;
"redact_email_content"?: boolean;
"attachment_delivery"?: {
Expand Down Expand Up @@ -510,6 +532,7 @@ export interface UpdateRouteSettingsData {
"track_clicks"?: boolean | null;
"generate_plaintext_fallback"?: boolean | null;
"suppress_auto_responders"?: boolean | null;
"suppress_disposable_recipients"?: boolean | null;
"tls"?: TlsPolicy | null;
"disable_hosted_unsubscribe"?: boolean | null;
"redact_email_content"?: boolean | null;
Expand Down Expand Up @@ -655,12 +678,15 @@ export type MessageIndexResponse = {
export type MessageShowResponse = MessageData;
export type MessageEventsResponse = {
"data": MessageEventData[];
"links": string[];
"meta": {
"path": string | null;
"per_page": number;
"next_cursor": string | null;
"next_page_url": string | null;
"next_cursor_url": string | null;
"prev_cursor": string | null;
"prev_page_url": string | null;
"prev_cursor_url": string | null;
};
};
export type ProjectIndexResponse = {
"data": ProjectListData[];
Expand Down
Loading