emailr 1.10.0 → 1.12.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.
package/dist/index.js CHANGED
@@ -158,7 +158,8 @@ var HttpClient = class {
158
158
  } catch {
159
159
  errorData = { error: response.statusText || "Unknown error" };
160
160
  }
161
- const message = errorData.error || "An error occurred";
161
+ const rawError = errorData.error;
162
+ const message = typeof rawError === "string" ? rawError : rawError?.message || JSON.stringify(rawError) || "An error occurred";
162
163
  switch (response.status) {
163
164
  case 400:
164
165
  throw new ValidationError(message, errorData.details, requestId);
@@ -225,7 +226,12 @@ var EmailsResource = class {
225
226
  * Send an email to one or multiple recipients
226
227
  */
227
228
  async send(data) {
228
- return this.http.post("/v1/emails/send", data);
229
+ const payload = { ...data };
230
+ if (payload.from_name && payload.from && !payload.from.includes("<")) {
231
+ payload.from = `${payload.from_name} <${payload.from}>`;
232
+ }
233
+ delete payload.from_name;
234
+ return this.http.post("/v1/emails/send", payload);
229
235
  }
230
236
  /**
231
237
  * Get email by ID
package/dist/index.mjs CHANGED
@@ -125,7 +125,8 @@ var HttpClient = class {
125
125
  } catch {
126
126
  errorData = { error: response.statusText || "Unknown error" };
127
127
  }
128
- const message = errorData.error || "An error occurred";
128
+ const rawError = errorData.error;
129
+ const message = typeof rawError === "string" ? rawError : rawError?.message || JSON.stringify(rawError) || "An error occurred";
129
130
  switch (response.status) {
130
131
  case 400:
131
132
  throw new ValidationError(message, errorData.details, requestId);
@@ -192,7 +193,12 @@ var EmailsResource = class {
192
193
  * Send an email to one or multiple recipients
193
194
  */
194
195
  async send(data) {
195
- return this.http.post("/v1/emails/send", data);
196
+ const payload = { ...data };
197
+ if (payload.from_name && payload.from && !payload.from.includes("<")) {
198
+ payload.from = `${payload.from_name} <${payload.from}>`;
199
+ }
200
+ delete payload.from_name;
201
+ return this.http.post("/v1/emails/send", payload);
196
202
  }
197
203
  /**
198
204
  * Get email by ID
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emailr",
3
- "version": "1.10.0",
3
+ "version": "1.12.0",
4
4
  "description": "Official Emailr API SDK for TypeScript/JavaScript",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",