resend 0.13.1 → 0.14.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resend",
3
- "version": "0.13.1",
3
+ "version": "0.14.0",
4
4
  "description": "Node.js library for the Resend API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",
@@ -28,12 +28,12 @@
28
28
  "homepage": "https://github.com/resend-inc/resend-node#readme",
29
29
  "dependencies": {
30
30
  "@react-email/render": "0.0.7",
31
- "axios": "1.3.6"
31
+ "axios": "1.4.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/jest": "29.5.1",
35
- "@types/node": "18.15.6",
36
- "@types/react": "18.0.32",
35
+ "@types/node": "18.16.2",
36
+ "@types/react": "18.2.0",
37
37
  "axios-mock-adapter": "1.21.4",
38
38
  "jest": "29.5.0",
39
39
  "prettier": "2.8.8",
@@ -0,0 +1,10 @@
1
+ import { Resend } from '../resend';
2
+ import { CreateEmailOptions, CreateEmailRequestOptions, CreateEmailResponse } from './interfaces';
3
+ import { GetEmailResponse } from './interfaces/get-email-options.interface';
4
+ export declare class Emails {
5
+ private readonly resend;
6
+ constructor(resend: Resend);
7
+ send(payload: CreateEmailOptions, options?: CreateEmailRequestOptions): Promise<CreateEmailResponse>;
8
+ create(payload: CreateEmailOptions, options?: CreateEmailRequestOptions): Promise<CreateEmailResponse>;
9
+ get(id: string): Promise<GetEmailResponse>;
10
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Emails = void 0;
13
+ class Emails {
14
+ constructor(resend) {
15
+ this.resend = resend;
16
+ }
17
+ send(payload, options = {}) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ return this.create(payload, options);
20
+ });
21
+ }
22
+ create(payload, options = {}) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const data = yield this.resend.post('/emails', payload, options);
25
+ return data;
26
+ });
27
+ }
28
+ get(id) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const data = yield this.resend.get(`/emails/${id}`);
31
+ return data;
32
+ });
33
+ }
34
+ }
35
+ exports.Emails = Emails;
@@ -0,0 +1,16 @@
1
+ import { PostOptions } from '../../common/interfaces';
2
+ export interface CreateEmailOptions {
3
+ id: string;
4
+ bcc?: string[];
5
+ cc?: string[];
6
+ from: string;
7
+ html?: string;
8
+ text?: string;
9
+ to: string[];
10
+ subject: string;
11
+ }
12
+ export interface CreateEmailRequestOptions extends PostOptions {
13
+ }
14
+ export interface CreateEmailResponse {
15
+ id: string;
16
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ export interface GetEmailResponse {
2
+ bcc?: string[];
3
+ cc?: string[];
4
+ from: string;
5
+ html?: string;
6
+ id: string;
7
+ subject: string;
8
+ text?: string;
9
+ to: string[];
10
+ object: 'email';
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export * from './create-email-options.interface';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./create-email-options.interface"), exports);
@@ -50,6 +50,18 @@ export interface SendEmailRequest {
50
50
  /** Email tags */
51
51
  tags?: Tag[];
52
52
  }
53
+ export declare const RESEND_ERROR_CODES_BY_KEY: {
54
+ readonly missing_required_fields: 422;
55
+ readonly missing_api_key: 401;
56
+ readonly invalid_api_Key: 403;
57
+ readonly invalid_from_address: 403;
58
+ readonly not_found: 404;
59
+ readonly method_not_allowed: 405;
60
+ readonly internal_server_error: 500;
61
+ };
62
+ type ValueOf<TObj> = TObj[keyof TObj];
63
+ export type RESEND_ERROR_CODE_NUMBER = ValueOf<typeof RESEND_ERROR_CODES_BY_KEY>;
64
+ export type RESEND_ERROR_CODE_KEY = keyof typeof RESEND_ERROR_CODES_BY_KEY;
53
65
  interface EmailResponse extends Pick<SendEmailRequest, 'to' | 'from'> {
54
66
  id: string;
55
67
  created_at: string;
@@ -57,8 +69,8 @@ interface EmailResponse extends Pick<SendEmailRequest, 'to' | 'from'> {
57
69
  interface ErrorResponse {
58
70
  error: {
59
71
  message: string;
60
- status: number;
61
- type: string;
72
+ status: RESEND_ERROR_CODE_NUMBER;
73
+ type: RESEND_ERROR_CODE_KEY;
62
74
  };
63
75
  }
64
76
  export type SendEmailResponse = EmailResponse | ErrorResponse;
@@ -1,2 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RESEND_ERROR_CODES_BY_KEY = void 0;
4
+ exports.RESEND_ERROR_CODES_BY_KEY = {
5
+ missing_required_fields: 422,
6
+ missing_api_key: 401,
7
+ invalid_api_Key: 403,
8
+ invalid_from_address: 403,
9
+ not_found: 404,
10
+ method_not_allowed: 405,
11
+ internal_server_error: 500,
12
+ };
@@ -3,6 +3,7 @@ import { SendEmailData, SendEmailResponse } from './interfaces';
3
3
  import { GetOptions, PostOptions, PutOptions } from './common/interfaces';
4
4
  import { ApiKeys } from './api-keys/api-keys';
5
5
  import { Domains } from './domains/domains';
6
+ import { Emails } from './emails/emails';
6
7
  export declare class Resend {
7
8
  readonly key?: string | undefined;
8
9
  readonly baseUrl: string;
@@ -10,9 +11,10 @@ export declare class Resend {
10
11
  private readonly request;
11
12
  readonly apiKeys: ApiKeys;
12
13
  readonly domains: Domains;
14
+ readonly emails: Emails;
13
15
  constructor(key?: string | undefined);
14
16
  post<T>(path: string, entity?: any, options?: PostOptions): Promise<T>;
15
- get(path: string, options?: GetOptions): Promise<AxiosResponse>;
17
+ get<T>(path: string, options?: GetOptions): Promise<T>;
16
18
  put(path: string, entity: any, options?: PutOptions): Promise<AxiosResponse>;
17
19
  delete(path: string, query?: any): Promise<AxiosResponse>;
18
20
  sendEmail(data: SendEmailData): Promise<SendEmailResponse>;
@@ -18,11 +18,13 @@ const render_1 = require("@react-email/render");
18
18
  const package_json_1 = require("../package.json");
19
19
  const api_keys_1 = require("./api-keys/api-keys");
20
20
  const domains_1 = require("./domains/domains");
21
+ const emails_1 = require("./emails/emails");
21
22
  class Resend {
22
23
  constructor(key) {
23
24
  this.key = key;
24
25
  this.apiKeys = new api_keys_1.ApiKeys(this);
25
26
  this.domains = new domains_1.Domains(this);
27
+ this.emails = new emails_1.Emails(this);
26
28
  if (!key) {
27
29
  this.key = process.env.RESEND_API_KEY;
28
30
  if (!this.key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resend",
3
- "version": "0.13.1",
3
+ "version": "0.14.0",
4
4
  "description": "Node.js library for the Resend API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",
@@ -28,12 +28,12 @@
28
28
  "homepage": "https://github.com/resend-inc/resend-node#readme",
29
29
  "dependencies": {
30
30
  "@react-email/render": "0.0.7",
31
- "axios": "1.3.6"
31
+ "axios": "1.4.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/jest": "29.5.1",
35
- "@types/node": "18.15.6",
36
- "@types/react": "18.0.32",
35
+ "@types/node": "18.16.2",
36
+ "@types/react": "18.2.0",
37
37
  "axios-mock-adapter": "1.21.4",
38
38
  "jest": "29.5.0",
39
39
  "prettier": "2.8.8",