add batch email api (#149)
* add bulk email * add bulk email api * add batch email sdk changes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "unsend",
|
||||
"version": "1.4.2",
|
||||
"version": "1.5.0",
|
||||
"description": "",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
|
@@ -46,6 +46,27 @@ type CancelEmailResponse = {
|
||||
type CancelEmailResponseSuccess =
|
||||
paths["/v1/emails/{emailId}/cancel"]["post"]["responses"]["200"]["content"]["application/json"];
|
||||
|
||||
// Batch emails types
|
||||
/**
|
||||
* Payload for sending multiple emails in a single batch request.
|
||||
*/
|
||||
type BatchEmailPayload =
|
||||
paths["/v1/emails/batch"]["post"]["requestBody"]["content"]["application/json"];
|
||||
|
||||
/**
|
||||
* Successful response schema for batch email send.
|
||||
*/
|
||||
type BatchEmailResponseSuccess =
|
||||
paths["/v1/emails/batch"]["post"]["responses"]["200"]["content"]["application/json"];
|
||||
|
||||
/**
|
||||
* Response structure for the batch method.
|
||||
*/
|
||||
type BatchEmailResponse = {
|
||||
data: BatchEmailResponseSuccess["data"] | null;
|
||||
error: ErrorResponse | null;
|
||||
};
|
||||
|
||||
export class Emails {
|
||||
constructor(private readonly unsend: Unsend) {
|
||||
this.unsend = unsend;
|
||||
@@ -69,6 +90,24 @@ export class Emails {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send up to 100 emails in a single request.
|
||||
*
|
||||
* @param payload An array of email payloads. Max 100 emails.
|
||||
* @returns A promise that resolves to the list of created email IDs or an error.
|
||||
*/
|
||||
async batch(payload: BatchEmailPayload): Promise<BatchEmailResponse> {
|
||||
// Note: React element rendering is not supported in batch mode.
|
||||
const response = await this.unsend.post<BatchEmailResponseSuccess>(
|
||||
"/emails/batch",
|
||||
payload
|
||||
);
|
||||
return {
|
||||
data: response.data ? response.data.data : null,
|
||||
error: response.error,
|
||||
};
|
||||
}
|
||||
|
||||
async get(id: string): Promise<GetEmailResponse> {
|
||||
const data = await this.unsend.get<GetEmailResponseSuccess>(
|
||||
`/emails/${id}`
|
||||
|
50
packages/sdk/types/schema.d.ts
vendored
50
packages/sdk/types/schema.d.ts
vendored
@@ -109,7 +109,7 @@ export interface paths {
|
||||
put: {
|
||||
parameters: {
|
||||
path: {
|
||||
id: number;
|
||||
id: number | null;
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
@@ -192,6 +192,7 @@ export interface paths {
|
||||
content: {
|
||||
"application/json": {
|
||||
to: string | string[];
|
||||
/** Format: email */
|
||||
from: string;
|
||||
/** @description Optional when templateId is provided */
|
||||
subject?: string;
|
||||
@@ -203,8 +204,8 @@ export interface paths {
|
||||
replyTo?: string | string[];
|
||||
cc?: string | string[];
|
||||
bcc?: string | string[];
|
||||
text?: string;
|
||||
html?: string;
|
||||
text?: string | null;
|
||||
html?: string | null;
|
||||
attachments?: {
|
||||
filename: string;
|
||||
content: string;
|
||||
@@ -226,6 +227,49 @@ export interface paths {
|
||||
};
|
||||
};
|
||||
};
|
||||
"/v1/emails/batch": {
|
||||
post: {
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": ({
|
||||
to: string | string[];
|
||||
/** Format: email */
|
||||
from: string;
|
||||
/** @description Optional when templateId is provided */
|
||||
subject?: string;
|
||||
/** @description ID of a template from the dashboard */
|
||||
templateId?: string;
|
||||
variables?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
replyTo?: string | string[];
|
||||
cc?: string | string[];
|
||||
bcc?: string | string[];
|
||||
text?: string | null;
|
||||
html?: string | null;
|
||||
attachments?: {
|
||||
filename: string;
|
||||
content: string;
|
||||
}[];
|
||||
/** Format: date-time */
|
||||
scheduledAt?: string;
|
||||
})[];
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description List of successfully created email IDs */
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {
|
||||
data: {
|
||||
emailId: string;
|
||||
}[];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
"/v1/emails/{emailId}/cancel": {
|
||||
post: {
|
||||
parameters: {
|
||||
|
Reference in New Issue
Block a user