resend 3.3.0 → 3.4.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.d.mts CHANGED
@@ -231,6 +231,8 @@ interface Attachment {
231
231
  filename?: string | false | undefined;
232
232
  /** Path where the attachment file is hosted */
233
233
  path?: string;
234
+ /** Optional content type for the attachment, if not set will be derived from the filename property */
235
+ content_type?: string;
234
236
  }
235
237
  type Tag = {
236
238
  /**
package/dist/index.d.ts CHANGED
@@ -231,6 +231,8 @@ interface Attachment {
231
231
  filename?: string | false | undefined;
232
232
  /** Path where the attachment file is hosted */
233
233
  path?: string;
234
+ /** Optional content type for the attachment, if not set will be derived from the filename property */
235
+ content_type?: string;
234
236
  }
235
237
  type Tag = {
236
238
  /**
package/dist/index.js CHANGED
@@ -62,7 +62,7 @@ __export(src_exports, {
62
62
  module.exports = __toCommonJS(src_exports);
63
63
 
64
64
  // package.json
65
- var version = "3.3.0";
65
+ var version = "3.4.0";
66
66
 
67
67
  // src/api-keys/api-keys.ts
68
68
  var ApiKeys = class {
@@ -317,19 +317,6 @@ var Emails = class {
317
317
  }
318
318
  };
319
319
 
320
- // src/guards.ts
321
- var isResendErrorResponse = (response) => {
322
- if (typeof response !== "object" || response === null) {
323
- return false;
324
- }
325
- const error = response;
326
- if (typeof error !== "object" || error === null) {
327
- return false;
328
- }
329
- const { message, name } = error;
330
- return typeof message === "string" && typeof name === "string";
331
- };
332
-
333
320
  // src/resend.ts
334
321
  var defaultBaseUrl = "https://api.resend.com";
335
322
  var defaultUserAgent = `resend-node:${version}`;
@@ -362,27 +349,43 @@ var Resend = class {
362
349
  }
363
350
  fetchRequest(_0) {
364
351
  return __async(this, arguments, function* (path, options = {}) {
365
- const response = yield fetch(`${baseUrl}${path}`, options);
366
- if (!response.ok) {
367
- let error = {
368
- message: response.statusText,
369
- name: "application_error"
370
- };
371
- try {
372
- error = yield response.json();
373
- if (isResendErrorResponse(error)) {
352
+ try {
353
+ const response = yield fetch(`${baseUrl}${path}`, options);
354
+ if (!response.ok) {
355
+ try {
356
+ const rawError = yield response.text();
357
+ return { data: null, error: JSON.parse(rawError) };
358
+ } catch (err) {
359
+ if (err instanceof SyntaxError) {
360
+ return {
361
+ data: null,
362
+ error: {
363
+ name: "application_error",
364
+ message: "Internal server error. We are unable to process your request right now, please try again later."
365
+ }
366
+ };
367
+ }
368
+ const error = {
369
+ message: response.statusText,
370
+ name: "application_error"
371
+ };
372
+ if (err instanceof Error) {
373
+ return { data: null, error: __spreadProps(__spreadValues({}, error), { message: err.message }) };
374
+ }
374
375
  return { data: null, error };
375
376
  }
376
- return { data: null, error };
377
- } catch (err) {
378
- if (err instanceof Error) {
379
- return { data: null, error: __spreadProps(__spreadValues({}, error), { message: err.message }) };
380
- }
381
- return { data: null, error };
382
377
  }
378
+ const data = yield response.json();
379
+ return { data, error: null };
380
+ } catch (error) {
381
+ return {
382
+ data: null,
383
+ error: {
384
+ name: "application_error",
385
+ message: "Unable to fetch data. The request could not be resolved."
386
+ }
387
+ };
383
388
  }
384
- const data = yield response.json();
385
- return { data, error: null };
386
389
  });
387
390
  }
388
391
  post(_0, _1) {
package/dist/index.mjs CHANGED
@@ -39,7 +39,7 @@ var __async = (__this, __arguments, generator) => {
39
39
  };
40
40
 
41
41
  // package.json
42
- var version = "3.3.0";
42
+ var version = "3.4.0";
43
43
 
44
44
  // src/api-keys/api-keys.ts
45
45
  var ApiKeys = class {
@@ -294,19 +294,6 @@ var Emails = class {
294
294
  }
295
295
  };
296
296
 
297
- // src/guards.ts
298
- var isResendErrorResponse = (response) => {
299
- if (typeof response !== "object" || response === null) {
300
- return false;
301
- }
302
- const error = response;
303
- if (typeof error !== "object" || error === null) {
304
- return false;
305
- }
306
- const { message, name } = error;
307
- return typeof message === "string" && typeof name === "string";
308
- };
309
-
310
297
  // src/resend.ts
311
298
  var defaultBaseUrl = "https://api.resend.com";
312
299
  var defaultUserAgent = `resend-node:${version}`;
@@ -339,27 +326,43 @@ var Resend = class {
339
326
  }
340
327
  fetchRequest(_0) {
341
328
  return __async(this, arguments, function* (path, options = {}) {
342
- const response = yield fetch(`${baseUrl}${path}`, options);
343
- if (!response.ok) {
344
- let error = {
345
- message: response.statusText,
346
- name: "application_error"
347
- };
348
- try {
349
- error = yield response.json();
350
- if (isResendErrorResponse(error)) {
329
+ try {
330
+ const response = yield fetch(`${baseUrl}${path}`, options);
331
+ if (!response.ok) {
332
+ try {
333
+ const rawError = yield response.text();
334
+ return { data: null, error: JSON.parse(rawError) };
335
+ } catch (err) {
336
+ if (err instanceof SyntaxError) {
337
+ return {
338
+ data: null,
339
+ error: {
340
+ name: "application_error",
341
+ message: "Internal server error. We are unable to process your request right now, please try again later."
342
+ }
343
+ };
344
+ }
345
+ const error = {
346
+ message: response.statusText,
347
+ name: "application_error"
348
+ };
349
+ if (err instanceof Error) {
350
+ return { data: null, error: __spreadProps(__spreadValues({}, error), { message: err.message }) };
351
+ }
351
352
  return { data: null, error };
352
353
  }
353
- return { data: null, error };
354
- } catch (err) {
355
- if (err instanceof Error) {
356
- return { data: null, error: __spreadProps(__spreadValues({}, error), { message: err.message }) };
357
- }
358
- return { data: null, error };
359
354
  }
355
+ const data = yield response.json();
356
+ return { data, error: null };
357
+ } catch (error) {
358
+ return {
359
+ data: null,
360
+ error: {
361
+ name: "application_error",
362
+ message: "Unable to fetch data. The request could not be resolved."
363
+ }
364
+ };
360
365
  }
361
- const data = yield response.json();
362
- return { data, error: null };
363
366
  });
364
367
  }
365
368
  post(_0, _1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resend",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "Node.js library for the Resend API",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",