@rpcbase/server 0.600.0 → 0.601.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7162,7 +7162,49 @@ var EmailDeliveryError = class extends Error {
7162
7162
  }
7163
7163
  };
7164
7164
  var getErrorMessage = (error) => error instanceof Error ? error.message : String(error);
7165
+ var STORE_KEY = Symbol.for("@rpcbase/server/emailTransport");
7166
+ var getEmailTransportStore = () => {
7167
+ const globalStore = globalThis;
7168
+ const existing = globalStore[STORE_KEY];
7169
+ if (existing && typeof existing === "object") return existing;
7170
+ const created = {};
7171
+ globalStore[STORE_KEY] = created;
7172
+ return created;
7173
+ };
7174
+ var configureEmailTransport = (transport) => {
7175
+ const store = getEmailTransportStore();
7176
+ store.transport = transport ?? void 0;
7177
+ };
7178
+ var createResendEmailTransport = ({ apiKey, defaultFrom = "hello@rpcbase.com" }) => {
7179
+ const normalizedApiKey = apiKey.trim();
7180
+ if (!normalizedApiKey) throw new EmailDeliveryError("missing_transport", "RESEND_API_KEY is required to send email");
7181
+ const resend = new Resend(normalizedApiKey);
7182
+ return { send: async (params) => {
7183
+ let response;
7184
+ try {
7185
+ response = await resend.emails.send({
7186
+ from: params.from || defaultFrom,
7187
+ to: params.to,
7188
+ subject: params.subject,
7189
+ html: params.html,
7190
+ text: params.text,
7191
+ replyTo: params.replyTo
7192
+ });
7193
+ } catch (error) {
7194
+ throw new EmailDeliveryError("transport_error", `Email provider request failed: ${getErrorMessage(error)}`, error);
7195
+ }
7196
+ if (response.error) throw new EmailDeliveryError("provider_rejected", `Email provider rejected the request: ${response.error.message}`, response.error);
7197
+ const id = response.data?.id?.trim();
7198
+ if (!id) throw new EmailDeliveryError("provider_unconfirmed", "Email provider did not confirm the request");
7199
+ return {
7200
+ id,
7201
+ skipped: false
7202
+ };
7203
+ } };
7204
+ };
7165
7205
  var sendEmail = async (params, options = {}) => {
7206
+ const configuredTransport = getEmailTransportStore().transport;
7207
+ if (configuredTransport) return configuredTransport.send(params);
7166
7208
  const apiKey = process.env.RESEND_API_KEY?.trim();
7167
7209
  if (!apiKey) {
7168
7210
  if (options.missingTransport === "skip") {
@@ -7175,30 +7217,12 @@ var sendEmail = async (params, options = {}) => {
7175
7217
  }
7176
7218
  throw new EmailDeliveryError("missing_transport", "RESEND_API_KEY is required to send email");
7177
7219
  }
7178
- const resend = new Resend(apiKey);
7179
- const defaultFrom = process.env.RESEND_FROM?.trim() || "hello@rpcbase.com";
7180
- let response;
7181
- try {
7182
- response = await resend.emails.send({
7183
- from: params.from || defaultFrom,
7184
- to: params.to,
7185
- subject: params.subject,
7186
- html: params.html,
7187
- text: params.text,
7188
- replyTo: params.replyTo
7189
- });
7190
- } catch (error) {
7191
- throw new EmailDeliveryError("transport_error", `Email provider request failed: ${getErrorMessage(error)}`, error);
7192
- }
7193
- if (response.error) throw new EmailDeliveryError("provider_rejected", `Email provider rejected the request: ${response.error.message}`, response.error);
7194
- const id = response.data?.id?.trim();
7195
- if (!id) throw new EmailDeliveryError("provider_unconfirmed", "Email provider did not confirm the request");
7196
- return {
7197
- id,
7198
- skipped: false
7199
- };
7220
+ return createResendEmailTransport({
7221
+ apiKey,
7222
+ defaultFrom: process.env.RESEND_FROM?.trim() || "hello@rpcbase.com"
7223
+ }).send(params);
7200
7224
  };
7201
7225
  //#endregion
7202
- export { __toESM as i, sendEmail as n, __commonJSMin as r, EmailDeliveryError as t };
7226
+ export { __commonJSMin as a, sendEmail as i, configureEmailTransport as n, __toESM as o, createResendEmailTransport as r, EmailDeliveryError as t };
7203
7227
 
7204
- //# sourceMappingURL=email-Co1GNjlT.js.map
7228
+ //# sourceMappingURL=email-CK8NNDQY.js.map