var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; // package.json var version = "4.8.0"; // src/api-keys/api-keys.ts var ApiKeys = class { constructor(resend) { this.resend = resend; } create(_0) { return __async(this, arguments, function* (payload, options = {}) { const data = yield this.resend.post( "/api-keys", payload, options ); return data; }); } list() { return __async(this, null, function* () { const data = yield this.resend.get("/api-keys"); return data; }); } remove(id) { return __async(this, null, function* () { const data = yield this.resend.delete( `/api-keys/${id}` ); return data; }); } }; // src/audiences/audiences.ts var Audiences = class { constructor(resend) { this.resend = resend; } create(_0) { return __async(this, arguments, function* (payload, options = {}) { const data = yield this.resend.post( "/audiences", payload, options ); return data; }); } list() { return __async(this, null, function* () { const data = yield this.resend.get("/audiences"); return data; }); } get(id) { return __async(this, null, function* () { const data = yield this.resend.get( `/audiences/${id}` ); return data; }); } remove(id) { return __async(this, null, function* () { const data = yield this.resend.delete( `/audiences/${id}` ); return data; }); } }; // src/common/utils/parse-email-to-api-options.ts function parseAttachments(attachments) { return attachments == null ? void 0 : attachments.map((attachment) => ({ content: attachment.content, filename: attachment.filename, path: attachment.path, content_type: attachment.contentType, inline_content_id: attachment.inlineContentId })); } function parseEmailToApiOptions(email) { return { attachments: parseAttachments(email.attachments), bcc: email.bcc, cc: email.cc, from: email.from, headers: email.headers, html: email.html, reply_to: email.replyTo, scheduled_at: email.scheduledAt, subject: email.subject, tags: email.tags, text: email.text, to: email.to }; } // src/batch/batch.ts var Batch = class { constructor(resend) { this.resend = resend; } send(_0) { return __async(this, arguments, function* (payload, options = {}) { return this.create(payload, options); }); } create(_0) { return __async(this, arguments, function* (payload, options = {}) { const emails = []; for (const email of payload) { if (email.react) { if (!this.renderAsync) { try { const { renderAsync } = yield import("@react-email/render"); this.renderAsync = renderAsync; } catch (error) { throw new Error( "Failed to render React component. Make sure to install `@react-email/render`" ); } } email.html = yield this.renderAsync(email.react); email.react = void 0; } emails.push(parseEmailToApiOptions(email)); } const data = yield this.resend.post( "/emails/batch", emails, options ); return data; }); } }; // src/broadcasts/broadcasts.ts var Broadcasts = class { constructor(resend) { this.resend = resend; } create(_0) { return __async(this, arguments, function* (payload, options = {}) { if (payload.react) { if (!this.renderAsync) { try { const { renderAsync } = yield import("@react-email/render"); this.renderAsync = renderAsync; } catch (error) { throw new Error( "Failed to render React component. Make sure to install `@react-email/render`" ); } } payload.html = yield this.renderAsync( payload.react ); } const data = yield this.resend.post( "/broadcasts", { name: payload.name, audience_id: payload.audienceId, preview_text: payload.previewText, from: payload.from, html: payload.html, reply_to: payload.replyTo, subject: payload.subject, text: payload.text }, options ); return data; }); } send(id, payload) { return __async(this, null, function* () { const data = yield this.resend.post( `/broadcasts/${id}/send`, { scheduled_at: payload == null ? void 0 : payload.scheduledAt } ); return data; }); } list() { return __async(this, null, function* () { const data = yield this.resend.get("/broadcasts"); return data; }); } get(id) { return __async(this, null, function* () { const data = yield this.resend.get( `/broadcasts/${id}` ); return data; }); } remove(id) { return __async(this, null, function* () { const data = yield this.resend.delete( `/broadcasts/${id}` ); return data; }); } update(id, payload) { return __async(this, null, function* () { const data = yield this.resend.patch( `/broadcasts/${id}`, { name: payload.name, audience_id: payload.audienceId, from: payload.from, html: payload.html, text: payload.text, subject: payload.subject, reply_to: payload.replyTo, preview_text: payload.previewText } ); return data; }); } }; // src/contacts/contacts.ts var Contacts = class { constructor(resend) { this.resend = resend; } create(_0) { return __async(this, arguments, function* (payload, options = {}) { const data = yield this.resend.post( `/audiences/${payload.audienceId}/contacts`, { unsubscribed: payload.unsubscribed, email: payload.email, first_name: payload.firstName, last_name: payload.lastName }, options ); return data; }); } list(options) { return __async(this, null, function* () { const data = yield this.resend.get( `/audiences/${options.audienceId}/contacts` ); return data; }); } get(options) { return __async(this, null, function* () { if (!options.id && !options.email) { return { data: null, error: { message: "Missing `id` or `email` field.", name: "missing_required_field" } }; } const data = yield this.resend.get( `/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}` ); return data; }); } update(payload) { return __async(this, null, function* () { if (!payload.id && !payload.email) { return { data: null, error: { message: "Missing `id` or `email` field.", name: "missing_required_field" } }; } const data = yield this.resend.patch( `/audiences/${payload.audienceId}/contacts/${(payload == null ? void 0 : payload.email) ? payload == null ? void 0 : payload.email : payload == null ? void 0 : payload.id}`, { unsubscribed: payload.unsubscribed, first_name: payload.firstName, last_name: payload.lastName } ); return data; }); } remove(payload) { return __async(this, null, function* () { if (!payload.id && !payload.email) { return { data: null, error: { message: "Missing `id` or `email` field.", name: "missing_required_field" } }; } const data = yield this.resend.delete( `/audiences/${payload.audienceId}/contacts/${(payload == null ? void 0 : payload.email) ? payload == null ? void 0 : payload.email : payload == null ? void 0 : payload.id}` ); return data; }); } }; // src/common/utils/parse-domain-to-api-options.ts function parseDomainToApiOptions(domain) { return { name: domain.name, region: domain.region, custom_return_path: domain.customReturnPath }; } // src/domains/domains.ts var Domains = class { constructor(resend) { this.resend = resend; } create(_0) { return __async(this, arguments, function* (payload, options = {}) { const data = yield this.resend.post( "/domains", parseDomainToApiOptions(payload), options ); return data; }); } list() { return __async(this, null, function* () { const data = yield this.resend.get("/domains"); return data; }); } get(id) { return __async(this, null, function* () { const data = yield this.resend.get( `/domains/${id}` ); return data; }); } update(payload) { return __async(this, null, function* () { const data = yield this.resend.patch( `/domains/${payload.id}`, { click_tracking: payload.clickTracking, open_tracking: payload.openTracking, tls: payload.tls } ); return data; }); } remove(id) { return __async(this, null, function* () { const data = yield this.resend.delete( `/domains/${id}` ); return data; }); } verify(id) { return __async(this, null, function* () { const data = yield this.resend.post( `/domains/${id}/verify` ); return data; }); } }; // src/emails/emails.ts var Emails = class { constructor(resend) { this.resend = resend; } send(_0) { return __async(this, arguments, function* (payload, options = {}) { return this.create(payload, options); }); } create(_0) { return __async(this, arguments, function* (payload, options = {}) { if (payload.react) { if (!this.renderAsync) { try { const { renderAsync } = yield import("@react-email/render"); this.renderAsync = renderAsync; } catch (error) { throw new Error( "Failed to render React component. Make sure to install `@react-email/render`" ); } } payload.html = yield this.renderAsync( payload.react ); } const data = yield this.resend.post( "/emails", parseEmailToApiOptions(payload), options ); return data; }); } get(id) { return __async(this, null, function* () { const data = yield this.resend.get( `/emails/${id}` ); return data; }); } update(payload) { return __async(this, null, function* () { const data = yield this.resend.patch( `/emails/${payload.id}`, { scheduled_at: payload.scheduledAt } ); return data; }); } cancel(id) { return __async(this, null, function* () { const data = yield this.resend.post( `/emails/${id}/cancel` ); return data; }); } }; // src/resend.ts var defaultBaseUrl = "https://api.resend.com"; var defaultUserAgent = `resend-node:${version}`; var baseUrl = typeof process !== "undefined" && process.env ? process.env.RESEND_BASE_URL || defaultBaseUrl : defaultBaseUrl; var userAgent = typeof process !== "undefined" && process.env ? process.env.RESEND_USER_AGENT || defaultUserAgent : defaultUserAgent; var Resend = class { constructor(key) { this.key = key; this.apiKeys = new ApiKeys(this); this.audiences = new Audiences(this); this.batch = new Batch(this); this.broadcasts = new Broadcasts(this); this.contacts = new Contacts(this); this.domains = new Domains(this); this.emails = new Emails(this); if (!key) { if (typeof process !== "undefined" && process.env) { this.key = process.env.RESEND_API_KEY; } if (!this.key) { throw new Error( 'Missing API key. Pass it to the constructor `new Resend("re_123")`' ); } } this.headers = new Headers({ Authorization: `Bearer ${this.key}`, "User-Agent": userAgent, "Content-Type": "application/json" }); } fetchRequest(_0) { return __async(this, arguments, function* (path, options = {}) { try { const response = yield fetch(`${baseUrl}${path}`, options); if (!response.ok) { try { const rawError = yield response.text(); return { data: null, error: JSON.parse(rawError) }; } catch (err) { if (err instanceof SyntaxError) { return { data: null, error: { name: "application_error", message: "Internal server error. We are unable to process your request right now, please try again later." } }; } const error = { message: response.statusText, name: "application_error" }; if (err instanceof Error) { return { data: null, error: __spreadProps(__spreadValues({}, error), { message: err.message }) }; } return { data: null, error }; } } const data = yield response.json(); return { data, error: null }; } catch (error) { return { data: null, error: { name: "application_error", message: "Unable to fetch data. The request could not be resolved." } }; } }); } post(_0, _1) { return __async(this, arguments, function* (path, entity, options = {}) { const headers = new Headers(this.headers); if (options.idempotencyKey) { headers.set("Idempotency-Key", options.idempotencyKey); } const requestOptions = __spreadValues({ method: "POST", headers, body: JSON.stringify(entity) }, options); return this.fetchRequest(path, requestOptions); }); } get(_0) { return __async(this, arguments, function* (path, options = {}) { const requestOptions = __spreadValues({ method: "GET", headers: this.headers }, options); return this.fetchRequest(path, requestOptions); }); } put(_0, _1) { return __async(this, arguments, function* (path, entity, options = {}) { const requestOptions = __spreadValues({ method: "PUT", headers: this.headers, body: JSON.stringify(entity) }, options); return this.fetchRequest(path, requestOptions); }); } patch(_0, _1) { return __async(this, arguments, function* (path, entity, options = {}) { const requestOptions = __spreadValues({ method: "PATCH", headers: this.headers, body: JSON.stringify(entity) }, options); return this.fetchRequest(path, requestOptions); }); } delete(path, query) { return __async(this, null, function* () { const requestOptions = { method: "DELETE", headers: this.headers, body: JSON.stringify(query) }; return this.fetchRequest(path, requestOptions); }); } }; export { Resend };