@rpcbase/server 0.587.0 → 0.589.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.
@@ -8014,32 +8014,58 @@ var Resend = class {
8014
8014
  return this.fetchRequest(path, requestOptions);
8015
8015
  }
8016
8016
  };
8017
- const apiKey = process.env.RESEND_API_KEY;
8018
- const defaultFrom = process.env.RESEND_FROM || "hello@rpcbase.com";
8019
- const sendEmail = async (params) => {
8017
+ class EmailDeliveryError extends Error {
8018
+ code;
8019
+ constructor(code, message2, cause) {
8020
+ super(message2);
8021
+ this.name = "EmailDeliveryError";
8022
+ this.code = code;
8023
+ this.cause = cause;
8024
+ }
8025
+ }
8026
+ const getErrorMessage = (error) => error instanceof Error ? error.message : String(error);
8027
+ const sendEmail = async (params, options = {}) => {
8028
+ const apiKey = process.env.RESEND_API_KEY?.trim();
8020
8029
  if (!apiKey) {
8021
- console.warn("RESEND_API_KEY not set, skipping email");
8022
- return {
8023
- id: void 0,
8024
- skipped: true
8025
- };
8030
+ if (options.missingTransport === "skip") {
8031
+ console.warn("RESEND_API_KEY not set, skipping email");
8032
+ return {
8033
+ id: void 0,
8034
+ skipped: true,
8035
+ skippedReason: "missing_transport"
8036
+ };
8037
+ }
8038
+ throw new EmailDeliveryError("missing_transport", "RESEND_API_KEY is required to send email");
8026
8039
  }
8027
8040
  const resend = new Resend(apiKey);
8028
- const response = await resend.emails.send({
8029
- from: params.from || defaultFrom,
8030
- to: params.to,
8031
- subject: params.subject,
8032
- html: params.html,
8033
- text: params.text,
8034
- replyTo: params.replyTo
8035
- });
8041
+ const defaultFrom = process.env.RESEND_FROM?.trim() || "hello@rpcbase.com";
8042
+ let response;
8043
+ try {
8044
+ response = await resend.emails.send({
8045
+ from: params.from || defaultFrom,
8046
+ to: params.to,
8047
+ subject: params.subject,
8048
+ html: params.html,
8049
+ text: params.text,
8050
+ replyTo: params.replyTo
8051
+ });
8052
+ } catch (error) {
8053
+ throw new EmailDeliveryError("transport_error", `Email provider request failed: ${getErrorMessage(error)}`, error);
8054
+ }
8055
+ if (response.error) {
8056
+ throw new EmailDeliveryError("provider_rejected", `Email provider rejected the request: ${response.error.message}`, response.error);
8057
+ }
8058
+ const id = response.data?.id?.trim();
8059
+ if (!id) {
8060
+ throw new EmailDeliveryError("provider_unconfirmed", "Email provider did not confirm the request");
8061
+ }
8036
8062
  return {
8037
- id: response.data?.id,
8038
- error: response.error?.message,
8063
+ id,
8039
8064
  skipped: false
8040
8065
  };
8041
8066
  };
8042
8067
  export {
8068
+ EmailDeliveryError as E,
8043
8069
  sendEmail as s
8044
8070
  };
8045
- //# sourceMappingURL=email-BbPlSkbt.js.map
8071
+ //# sourceMappingURL=email-BCf24GmK.js.map