resend 0.18.0-canary.1 → 1.0.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.18.0-canary.1",
3
+ "version": "1.0.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",
@@ -1,6 +1,5 @@
1
1
  import { Resend } from '../resend';
2
- import { CreateEmailOptions, CreateEmailRequestOptions, CreateEmailResponse } from './interfaces';
3
- import { GetEmailResponse } from './interfaces/get-email-options.interface';
2
+ import { CreateEmailOptions, CreateEmailRequestOptions, CreateEmailResponse, GetEmailResponse } from './interfaces';
4
3
  export declare class Emails {
5
4
  private readonly resend;
6
5
  constructor(resend: Resend);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,179 @@
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
+ const jest_fetch_mock_1 = require("jest-fetch-mock");
13
+ const resend_1 = require("../resend");
14
+ (0, jest_fetch_mock_1.enableFetchMocks)();
15
+ const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
16
+ describe('Emails', () => {
17
+ afterEach(() => fetchMock.resetMocks());
18
+ describe('create', () => {
19
+ it('sends email', () => __awaiter(void 0, void 0, void 0, function* () {
20
+ const payload = {
21
+ from: 'bu@resend.com',
22
+ to: 'zeno@resend.com',
23
+ subject: 'Hello World',
24
+ html: '<h1>Hello world</h1>',
25
+ };
26
+ fetchMock.mockOnce(JSON.stringify({
27
+ id: '1234',
28
+ }), {
29
+ status: 200,
30
+ headers: {
31
+ 'content-type': 'application/json',
32
+ Authorization: 'Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop',
33
+ },
34
+ });
35
+ const data = yield resend.emails.create(payload);
36
+ expect(data).toMatchInlineSnapshot(`
37
+ {
38
+ "id": "1234",
39
+ }
40
+ `);
41
+ }));
42
+ });
43
+ describe('send', () => {
44
+ it('sends email', () => __awaiter(void 0, void 0, void 0, function* () {
45
+ const payload = {
46
+ from: 'bu@resend.com',
47
+ to: 'zeno@resend.com',
48
+ subject: 'Hello World',
49
+ html: '<h1>Hello world</h1>',
50
+ };
51
+ fetchMock.mockOnce(JSON.stringify({
52
+ id: '1234',
53
+ }), {
54
+ status: 200,
55
+ headers: {
56
+ 'content-type': 'application/json',
57
+ Authorization: 'Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop',
58
+ },
59
+ });
60
+ const data = yield resend.emails.send(payload);
61
+ expect(data).toMatchInlineSnapshot(`
62
+ {
63
+ "id": "1234",
64
+ }
65
+ `);
66
+ }));
67
+ });
68
+ describe('get', () => {
69
+ describe('when email not found', () => {
70
+ it('returns error', () => __awaiter(void 0, void 0, void 0, function* () {
71
+ fetchMock.mockOnce(JSON.stringify({
72
+ name: 'not_found',
73
+ message: 'Email not found',
74
+ statusCode: 404,
75
+ }), {
76
+ status: 404,
77
+ headers: {
78
+ 'content-type': 'application/json',
79
+ Authorization: 'Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop',
80
+ },
81
+ });
82
+ yield expect(resend.emails.get('1234')).resolves.toMatchInlineSnapshot(`
83
+ {
84
+ "message": "Email not found",
85
+ "name": "not_found",
86
+ "statusCode": 404,
87
+ }
88
+ `);
89
+ }));
90
+ });
91
+ describe('when email found', () => {
92
+ it('returns emails with only to', () => __awaiter(void 0, void 0, void 0, function* () {
93
+ const response = {
94
+ object: 'email',
95
+ id: '123',
96
+ to: ['zeno@resend.com'],
97
+ from: 'bu@resend.com',
98
+ created_at: '321',
99
+ subject: 'Test email',
100
+ html: '<p>hello hello</p>',
101
+ text: null,
102
+ bcc: null,
103
+ cc: null,
104
+ reply_to: null,
105
+ last_event: 'sent',
106
+ };
107
+ fetchMock.mockOnce(JSON.stringify(response), {
108
+ status: 200,
109
+ headers: {
110
+ 'content-type': 'application/json',
111
+ Authorization: 'Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop',
112
+ },
113
+ });
114
+ yield expect(resend.emails.get('1234')).resolves.toMatchInlineSnapshot(`
115
+ {
116
+ "bcc": null,
117
+ "cc": null,
118
+ "created_at": "321",
119
+ "from": "bu@resend.com",
120
+ "html": "<p>hello hello</p>",
121
+ "id": "123",
122
+ "last_event": "sent",
123
+ "object": "email",
124
+ "reply_to": null,
125
+ "subject": "Test email",
126
+ "text": null,
127
+ "to": [
128
+ "zeno@resend.com",
129
+ ],
130
+ }
131
+ `);
132
+ }));
133
+ it('returns emails with to and multiple cc', () => __awaiter(void 0, void 0, void 0, function* () {
134
+ const response = {
135
+ object: 'email',
136
+ id: '123',
137
+ to: ['zeno@resend.com'],
138
+ from: 'bu@resend.com',
139
+ created_at: '321',
140
+ subject: 'Test email',
141
+ html: '<p>hello hello</p>',
142
+ text: null,
143
+ bcc: null,
144
+ cc: ['zeno@resend.com', 'bu@resend.com'],
145
+ reply_to: null,
146
+ last_event: 'sent',
147
+ };
148
+ fetchMock.mockOnce(JSON.stringify(response), {
149
+ status: 200,
150
+ headers: {
151
+ 'content-type': 'application/json',
152
+ Authorization: 'Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop',
153
+ },
154
+ });
155
+ yield expect(resend.emails.get('1234')).resolves.toMatchInlineSnapshot(`
156
+ {
157
+ "bcc": null,
158
+ "cc": [
159
+ "zeno@resend.com",
160
+ "bu@resend.com",
161
+ ],
162
+ "created_at": "321",
163
+ "from": "bu@resend.com",
164
+ "html": "<p>hello hello</p>",
165
+ "id": "123",
166
+ "last_event": "sent",
167
+ "object": "email",
168
+ "reply_to": null,
169
+ "subject": "Test email",
170
+ "text": null,
171
+ "to": [
172
+ "zeno@resend.com",
173
+ ],
174
+ }
175
+ `);
176
+ }));
177
+ });
178
+ });
179
+ });
@@ -1,11 +1,14 @@
1
1
  export interface GetEmailResponse {
2
- bcc?: string[];
3
- cc?: string[];
2
+ bcc: string[] | null;
3
+ cc: string[] | null;
4
+ created_at: string;
4
5
  from: string;
5
- html?: string;
6
+ html: string | null;
6
7
  id: string;
8
+ last_event: string;
9
+ reply_to: string[] | null;
7
10
  subject: string;
8
- text?: string;
11
+ text: string | null;
9
12
  to: string[];
10
13
  object: 'email';
11
14
  }
@@ -1 +1,2 @@
1
1
  export * from './create-email-options.interface';
2
+ export * from './get-email-options.interface';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./create-email-options.interface"), exports);
18
+ __exportStar(require("./get-email-options.interface"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resend",
3
- "version": "0.18.0-canary.1",
3
+ "version": "1.0.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",