export type ApiTransactionalEmailAttachment = {fileName?: (string | null) | undefined, content?: (string | null) | undefined, mimeType?: (string | null) | undefined}; export type ApiTransactionalEmail = {toAddresses?: (Array | null) | undefined, ccAddresses?: (Array | null) | undefined, bccAddresses?: (Array | null) | undefined, subject?: (string | null) | undefined, fromAddress?: (string | null) | undefined, htmlContent?: (string | null) | undefined, plainTextContent?: (string | null) | undefined, tags?: (Array | null) | undefined, metadata?: (string | null) | undefined, attachments?: (Array | null) | undefined}; export type CreateApiV2EmailBatchArgs = {body: Array}; export type CreateApiV2EmailBatchOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Sends one or more transactional emails. If sending to multiple recipients, please separate addresses with a comma. * * POST /v2/email/batch */ export const createApiV2EmailBatch = async (args: CreateApiV2EmailBatchArgs, options?: CreateApiV2EmailBatchOptions) => { const {baseUrl = "https://api.dotdigital.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/octet-stream") const url = `${baseUrl.replace(/\/+$/, '')}/v2/email/batch${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };