resend 2.0.0 → 2.0.1-canary.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 +353 -0
- package/dist/index.d.ts +353 -0
- package/dist/index.js +300 -0
- package/dist/index.mjs +276 -0
- package/package.json +19 -5
- package/build/package.json +0 -50
- package/build/src/__snapshots__/resend.spec.js.snap +0 -3
- package/build/src/api-keys/api-keys.d.ts +0 -9
- package/build/src/api-keys/api-keys.js +0 -36
- package/build/src/api-keys/api-keys.spec.d.ts +0 -1
- package/build/src/api-keys/api-keys.spec.js +0 -349
- package/build/src/api-keys/interfaces/create-api-key-options.interface.d.ts +0 -17
- package/build/src/api-keys/interfaces/create-api-key-options.interface.js +0 -2
- package/build/src/api-keys/interfaces/index.d.ts +0 -3
- package/build/src/api-keys/interfaces/index.js +0 -19
- package/build/src/api-keys/interfaces/list-api-keys.interface.d.ts +0 -10
- package/build/src/api-keys/interfaces/list-api-keys.interface.js +0 -2
- package/build/src/api-keys/interfaces/remove-api-keys.interface.d.ts +0 -8
- package/build/src/api-keys/interfaces/remove-api-keys.interface.js +0 -2
- package/build/src/batch/batch.d.ts +0 -8
- package/build/src/batch/batch.js +0 -36
- package/build/src/batch/batch.spec.d.ts +0 -1
- package/build/src/batch/batch.spec.js +0 -122
- package/build/src/batch/interfaces/create-batch-options.interface.d.ts +0 -16
- package/build/src/batch/interfaces/create-batch-options.interface.js +0 -2
- package/build/src/batch/interfaces/index.d.ts +0 -1
- package/build/src/batch/interfaces/index.js +0 -17
- package/build/src/common/interfaces/get-option.interface.d.ts +0 -3
- package/build/src/common/interfaces/get-option.interface.js +0 -2
- package/build/src/common/interfaces/index.d.ts +0 -4
- package/build/src/common/interfaces/index.js +0 -20
- package/build/src/common/interfaces/list-option.interface.d.ts +0 -4
- package/build/src/common/interfaces/list-option.interface.js +0 -2
- package/build/src/common/interfaces/post-option.interface.d.ts +0 -5
- package/build/src/common/interfaces/post-option.interface.js +0 -2
- package/build/src/common/interfaces/put-option.interface.d.ts +0 -5
- package/build/src/common/interfaces/put-option.interface.js +0 -2
- package/build/src/domains/domains.d.ts +0 -11
- package/build/src/domains/domains.js +0 -48
- package/build/src/domains/domains.spec.d.ts +0 -1
- package/build/src/domains/domains.spec.js +0 -496
- package/build/src/domains/interfaces/create-domain-options.interface.d.ts +0 -16
- package/build/src/domains/interfaces/create-domain-options.interface.js +0 -2
- package/build/src/domains/interfaces/domain.d.ts +0 -33
- package/build/src/domains/interfaces/domain.js +0 -2
- package/build/src/domains/interfaces/get-domain.interface.d.ts +0 -10
- package/build/src/domains/interfaces/get-domain.interface.js +0 -2
- package/build/src/domains/interfaces/index.d.ts +0 -5
- package/build/src/domains/interfaces/index.js +0 -21
- package/build/src/domains/interfaces/list-domains.interface.d.ts +0 -7
- package/build/src/domains/interfaces/list-domains.interface.js +0 -2
- package/build/src/domains/interfaces/remove-domain.interface.d.ts +0 -7
- package/build/src/domains/interfaces/remove-domain.interface.js +0 -2
- package/build/src/domains/interfaces/verify-domain.interface.d.ts +0 -7
- package/build/src/domains/interfaces/verify-domain.interface.js +0 -2
- package/build/src/emails/emails.d.ts +0 -9
- package/build/src/emails/emails.js +0 -40
- package/build/src/emails/emails.spec.d.ts +0 -1
- package/build/src/emails/emails.spec.js +0 -190
- package/build/src/emails/interfaces/create-email-options.interface.d.ts +0 -113
- package/build/src/emails/interfaces/create-email-options.interface.js +0 -2
- package/build/src/emails/interfaces/get-email-options.interface.d.ts +0 -19
- package/build/src/emails/interfaces/get-email-options.interface.js +0 -2
- package/build/src/emails/interfaces/index.d.ts +0 -2
- package/build/src/emails/interfaces/index.js +0 -18
- package/build/src/error.d.ts +0 -7
- package/build/src/error.js +0 -21
- package/build/src/guards.d.ts +0 -9
- package/build/src/guards.js +0 -36
- package/build/src/index.d.ts +0 -2
- package/build/src/index.js +0 -5
- package/build/src/interfaces.d.ts +0 -24
- package/build/src/interfaces.js +0 -18
- package/build/src/resend.d.ts +0 -35
- package/build/src/resend.js +0 -83
- package/build/src/resend.spec.d.ts +0 -1
- package/build/src/resend.spec.js +0 -267
|
@@ -1,36 +0,0 @@
|
|
|
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.ApiKeys = void 0;
|
|
13
|
-
class ApiKeys {
|
|
14
|
-
constructor(resend) {
|
|
15
|
-
this.resend = resend;
|
|
16
|
-
}
|
|
17
|
-
create(payload, options = {}) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
const data = yield this.resend.post('/api-keys', payload, options);
|
|
20
|
-
return data;
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
list() {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
const data = yield this.resend.get('/api-keys');
|
|
26
|
-
return data;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
remove(id) {
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
const data = yield this.resend.delete(`/api-keys/${id}`);
|
|
32
|
-
return data;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.ApiKeys = ApiKeys;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,349 +0,0 @@
|
|
|
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
|
-
describe('API Keys', () => {
|
|
16
|
-
afterEach(() => fetchMock.resetMocks());
|
|
17
|
-
describe('create', () => {
|
|
18
|
-
it('creates an api key', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
-
fetchMock.mockOnce(JSON.stringify({
|
|
20
|
-
data: {
|
|
21
|
-
token: 're_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk',
|
|
22
|
-
id: '430eed87-632a-4ea6-90db-0aace67ec228',
|
|
23
|
-
},
|
|
24
|
-
error: null,
|
|
25
|
-
}), {
|
|
26
|
-
status: 201,
|
|
27
|
-
headers: {
|
|
28
|
-
'content-type': 'application/json',
|
|
29
|
-
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
33
|
-
yield expect(resend.apiKeys.create({ name: 'Test' })).resolves
|
|
34
|
-
.toMatchInlineSnapshot(`
|
|
35
|
-
{
|
|
36
|
-
"data": {
|
|
37
|
-
"data": {
|
|
38
|
-
"id": "430eed87-632a-4ea6-90db-0aace67ec228",
|
|
39
|
-
"token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
|
|
40
|
-
},
|
|
41
|
-
"error": null,
|
|
42
|
-
},
|
|
43
|
-
"error": null,
|
|
44
|
-
}
|
|
45
|
-
`);
|
|
46
|
-
}));
|
|
47
|
-
it('throws error when missing name', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
-
const errorResponse = {
|
|
49
|
-
name: 'missing_required_field',
|
|
50
|
-
message: 'Missing "name" field',
|
|
51
|
-
};
|
|
52
|
-
fetchMock.mockOnce(JSON.stringify(errorResponse), {
|
|
53
|
-
status: 422,
|
|
54
|
-
headers: {
|
|
55
|
-
'content-type': 'application/json',
|
|
56
|
-
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
60
|
-
const result = resend.apiKeys.create({ name: '' });
|
|
61
|
-
yield expect(result).resolves.toMatchInlineSnapshot(`
|
|
62
|
-
{
|
|
63
|
-
"data": null,
|
|
64
|
-
"error": {
|
|
65
|
-
"message": "Missing "name" field",
|
|
66
|
-
"name": "missing_required_field",
|
|
67
|
-
},
|
|
68
|
-
}
|
|
69
|
-
`);
|
|
70
|
-
}));
|
|
71
|
-
describe('with access', () => {
|
|
72
|
-
it('creates api key with access `full_access`', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
-
fetchMock.mockOnce(JSON.stringify({
|
|
74
|
-
data: {
|
|
75
|
-
token: 're_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk',
|
|
76
|
-
id: '430eed87-632a-4ea6-90db-0aace67ec228',
|
|
77
|
-
},
|
|
78
|
-
error: null,
|
|
79
|
-
}), {
|
|
80
|
-
status: 201,
|
|
81
|
-
headers: {
|
|
82
|
-
'content-type': 'application/json',
|
|
83
|
-
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
87
|
-
yield expect(resend.apiKeys.create({ name: 'Test', permission: 'full_access' })).resolves.toMatchInlineSnapshot(`
|
|
88
|
-
{
|
|
89
|
-
"data": {
|
|
90
|
-
"data": {
|
|
91
|
-
"id": "430eed87-632a-4ea6-90db-0aace67ec228",
|
|
92
|
-
"token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
|
|
93
|
-
},
|
|
94
|
-
"error": null,
|
|
95
|
-
},
|
|
96
|
-
"error": null,
|
|
97
|
-
}
|
|
98
|
-
`);
|
|
99
|
-
}));
|
|
100
|
-
it('creates api key with access `sending_access`', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
-
fetchMock.mockOnce(JSON.stringify({
|
|
102
|
-
data: {
|
|
103
|
-
token: 're_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk',
|
|
104
|
-
id: '430eed87-632a-4ea6-90db-0aace67ec228',
|
|
105
|
-
},
|
|
106
|
-
error: null,
|
|
107
|
-
}), {
|
|
108
|
-
status: 201,
|
|
109
|
-
headers: {
|
|
110
|
-
'content-type': 'application/json',
|
|
111
|
-
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
115
|
-
yield expect(resend.apiKeys.create({
|
|
116
|
-
name: 'Test',
|
|
117
|
-
permission: 'sending_access',
|
|
118
|
-
})).resolves.toMatchInlineSnapshot(`
|
|
119
|
-
{
|
|
120
|
-
"data": {
|
|
121
|
-
"data": {
|
|
122
|
-
"id": "430eed87-632a-4ea6-90db-0aace67ec228",
|
|
123
|
-
"token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
|
|
124
|
-
},
|
|
125
|
-
"error": null,
|
|
126
|
-
},
|
|
127
|
-
"error": null,
|
|
128
|
-
}
|
|
129
|
-
`);
|
|
130
|
-
}));
|
|
131
|
-
it('throws error with wrong access', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
132
|
-
const errorResponse = {
|
|
133
|
-
name: 'invalid_access',
|
|
134
|
-
message: 'Access must be "full_access" | "sending_access"',
|
|
135
|
-
};
|
|
136
|
-
fetchMock.mockOnce(JSON.stringify(errorResponse), {
|
|
137
|
-
status: 422,
|
|
138
|
-
headers: {
|
|
139
|
-
'content-type': 'application/json',
|
|
140
|
-
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
144
|
-
yield expect(resend.apiKeys.create({
|
|
145
|
-
name: 'Test',
|
|
146
|
-
permission: 'wrong_access',
|
|
147
|
-
})).resolves.toMatchInlineSnapshot(`
|
|
148
|
-
{
|
|
149
|
-
"data": null,
|
|
150
|
-
"error": {
|
|
151
|
-
"message": "Access must be "full_access" | "sending_access"",
|
|
152
|
-
"name": "invalid_access",
|
|
153
|
-
},
|
|
154
|
-
}
|
|
155
|
-
`);
|
|
156
|
-
}));
|
|
157
|
-
});
|
|
158
|
-
// describe('restricted by domain', () => {
|
|
159
|
-
// it('creates api key restricted by domain', async () => {
|
|
160
|
-
// fetchMock.mockOnce(
|
|
161
|
-
// JSON.stringify({
|
|
162
|
-
// data: {
|
|
163
|
-
// token: 're_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk',
|
|
164
|
-
// id: '430eed87-632a-4ea6-90db-0aace67ec228',
|
|
165
|
-
// },
|
|
166
|
-
// error: null,
|
|
167
|
-
// }),
|
|
168
|
-
// {
|
|
169
|
-
// status: 201,
|
|
170
|
-
// headers: {
|
|
171
|
-
// 'content-type': 'application/json',
|
|
172
|
-
// Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
173
|
-
// },
|
|
174
|
-
// },
|
|
175
|
-
// );
|
|
176
|
-
// const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
177
|
-
// await expect(
|
|
178
|
-
// resend.apiKeys.create({
|
|
179
|
-
// name: 'Test',
|
|
180
|
-
// permission: 'sending_access',
|
|
181
|
-
// domain_id: '7dfcf219-9900-4169-86f3-801e6d9b935e',
|
|
182
|
-
// }),
|
|
183
|
-
// ).resolves.toMatchInlineSnapshot(`
|
|
184
|
-
// {
|
|
185
|
-
// "id": "430eed87-632a-4ea6-90db-0aace67ec228",
|
|
186
|
-
// "token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
|
|
187
|
-
// }
|
|
188
|
-
// `);
|
|
189
|
-
// });
|
|
190
|
-
// it('throws error with wrong access', async () => {
|
|
191
|
-
// const errorResponse: ErrorResponse = {
|
|
192
|
-
// name: 'application_error',
|
|
193
|
-
// message: 'Something went wrong',
|
|
194
|
-
//
|
|
195
|
-
// };
|
|
196
|
-
// fetchMock.mockOnce(
|
|
197
|
-
// JSON.stringify(errorResponse),
|
|
198
|
-
// {
|
|
199
|
-
// status: 500,
|
|
200
|
-
// headers: {
|
|
201
|
-
// 'content-type': 'application/json',
|
|
202
|
-
// Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
203
|
-
// },
|
|
204
|
-
// },
|
|
205
|
-
// );
|
|
206
|
-
// const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
207
|
-
// await expect(
|
|
208
|
-
// resend.apiKeys.create({
|
|
209
|
-
// name: 'Test',
|
|
210
|
-
// permission: 'sending_access',
|
|
211
|
-
// domain_id: '1234',
|
|
212
|
-
// }),
|
|
213
|
-
// ).resolves.toMatchInlineSnapshot(
|
|
214
|
-
// `
|
|
215
|
-
// {
|
|
216
|
-
// "error": {
|
|
217
|
-
// "message": "Something went wrong",
|
|
218
|
-
// "name": "application_error",
|
|
219
|
-
// "statusCode": 500,
|
|
220
|
-
// },
|
|
221
|
-
// }
|
|
222
|
-
// `,
|
|
223
|
-
// );
|
|
224
|
-
// });
|
|
225
|
-
// });
|
|
226
|
-
});
|
|
227
|
-
describe('list', () => {
|
|
228
|
-
it('lists api keys', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
229
|
-
fetchMock.mockOnce(JSON.stringify({
|
|
230
|
-
data: [
|
|
231
|
-
{
|
|
232
|
-
id: '5262504e-8ed7-4fac-bd16-0d4be94bc9f2',
|
|
233
|
-
name: 'My API Key 1',
|
|
234
|
-
created_at: '2023-04-07T20:29:10.666968+00:00',
|
|
235
|
-
},
|
|
236
|
-
{
|
|
237
|
-
id: '98c37b35-1473-4afe-a627-78e975a36fab',
|
|
238
|
-
name: 'My API Key 2',
|
|
239
|
-
created_at: '2023-04-06T23:09:49.093947+00:00',
|
|
240
|
-
},
|
|
241
|
-
],
|
|
242
|
-
error: null,
|
|
243
|
-
}), {
|
|
244
|
-
status: 200,
|
|
245
|
-
headers: {
|
|
246
|
-
'content-type': 'application/json',
|
|
247
|
-
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
248
|
-
},
|
|
249
|
-
});
|
|
250
|
-
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
251
|
-
yield expect(resend.apiKeys.list()).resolves.toMatchInlineSnapshot(`
|
|
252
|
-
{
|
|
253
|
-
"data": {
|
|
254
|
-
"data": [
|
|
255
|
-
{
|
|
256
|
-
"created_at": "2023-04-07T20:29:10.666968+00:00",
|
|
257
|
-
"id": "5262504e-8ed7-4fac-bd16-0d4be94bc9f2",
|
|
258
|
-
"name": "My API Key 1",
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
"created_at": "2023-04-06T23:09:49.093947+00:00",
|
|
262
|
-
"id": "98c37b35-1473-4afe-a627-78e975a36fab",
|
|
263
|
-
"name": "My API Key 2",
|
|
264
|
-
},
|
|
265
|
-
],
|
|
266
|
-
"error": null,
|
|
267
|
-
},
|
|
268
|
-
"error": null,
|
|
269
|
-
}
|
|
270
|
-
`);
|
|
271
|
-
}));
|
|
272
|
-
});
|
|
273
|
-
describe('remove', () => {
|
|
274
|
-
it('removes an api key', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
275
|
-
fetchMock.mockOnce(JSON.stringify({
|
|
276
|
-
data: {
|
|
277
|
-
id: '5262504e-8ed7-4fac-bd16-0d4be94bc9f2',
|
|
278
|
-
},
|
|
279
|
-
error: null,
|
|
280
|
-
}), {
|
|
281
|
-
status: 200,
|
|
282
|
-
headers: {
|
|
283
|
-
'content-type': 'application/json',
|
|
284
|
-
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
285
|
-
},
|
|
286
|
-
});
|
|
287
|
-
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
288
|
-
yield expect(resend.apiKeys.remove('5262504e-8ed7-4fac-bd16-0d4be94bc9f2')).resolves.toMatchInlineSnapshot(`
|
|
289
|
-
{
|
|
290
|
-
"data": {
|
|
291
|
-
"data": {
|
|
292
|
-
"id": "5262504e-8ed7-4fac-bd16-0d4be94bc9f2",
|
|
293
|
-
},
|
|
294
|
-
"error": null,
|
|
295
|
-
},
|
|
296
|
-
"error": null,
|
|
297
|
-
}
|
|
298
|
-
`);
|
|
299
|
-
}));
|
|
300
|
-
it('throws error when missing id', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
301
|
-
const errorResponse = {
|
|
302
|
-
name: 'application_error',
|
|
303
|
-
message: 'Something went wrong',
|
|
304
|
-
};
|
|
305
|
-
fetchMock.mockOnce(JSON.stringify(errorResponse), {
|
|
306
|
-
status: 500,
|
|
307
|
-
headers: {
|
|
308
|
-
'content-type': 'application/json',
|
|
309
|
-
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
310
|
-
},
|
|
311
|
-
});
|
|
312
|
-
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
313
|
-
const result = resend.apiKeys.remove('');
|
|
314
|
-
yield expect(result).resolves.toMatchInlineSnapshot(`
|
|
315
|
-
{
|
|
316
|
-
"data": null,
|
|
317
|
-
"error": {
|
|
318
|
-
"message": "Something went wrong",
|
|
319
|
-
"name": "application_error",
|
|
320
|
-
},
|
|
321
|
-
}
|
|
322
|
-
`);
|
|
323
|
-
}));
|
|
324
|
-
it('throws error when wrong id', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
325
|
-
const errorResponse = {
|
|
326
|
-
name: 'not_found',
|
|
327
|
-
message: 'API key not found',
|
|
328
|
-
};
|
|
329
|
-
fetchMock.mockOnce(JSON.stringify(errorResponse), {
|
|
330
|
-
status: 404,
|
|
331
|
-
headers: {
|
|
332
|
-
'content-type': 'application/json',
|
|
333
|
-
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
334
|
-
},
|
|
335
|
-
});
|
|
336
|
-
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
337
|
-
const result = resend.apiKeys.remove('34bd250e-615a-400c-be11-5912572ee15b');
|
|
338
|
-
yield expect(result).resolves.toMatchInlineSnapshot(`
|
|
339
|
-
{
|
|
340
|
-
"data": null,
|
|
341
|
-
"error": {
|
|
342
|
-
"message": "API key not found",
|
|
343
|
-
"name": "not_found",
|
|
344
|
-
},
|
|
345
|
-
}
|
|
346
|
-
`);
|
|
347
|
-
}));
|
|
348
|
-
});
|
|
349
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { PostOptions } from '../../common/interfaces';
|
|
2
|
-
import { ErrorResponse } from '../../interfaces';
|
|
3
|
-
export interface CreateApiKeyOptions {
|
|
4
|
-
name: string;
|
|
5
|
-
permission?: 'full_access' | 'sending_access';
|
|
6
|
-
domain_id?: string;
|
|
7
|
-
}
|
|
8
|
-
export interface CreateApiKeyRequestOptions extends PostOptions {
|
|
9
|
-
}
|
|
10
|
-
export interface CreateApiKeyResponseSuccess {
|
|
11
|
-
token: string;
|
|
12
|
-
id: string;
|
|
13
|
-
}
|
|
14
|
-
export interface CreateApiKeyResponse {
|
|
15
|
-
data: CreateApiKeyResponseSuccess | null;
|
|
16
|
-
error: ErrorResponse | null;
|
|
17
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
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-api-key-options.interface"), exports);
|
|
18
|
-
__exportStar(require("./list-api-keys.interface"), exports);
|
|
19
|
-
__exportStar(require("./remove-api-keys.interface"), exports);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ErrorResponse } from '../../interfaces';
|
|
2
|
-
export interface ListApiKeysResponseSuccess {
|
|
3
|
-
name: string;
|
|
4
|
-
id: string;
|
|
5
|
-
created_at: string;
|
|
6
|
-
}
|
|
7
|
-
export interface ListApiKeysResponse {
|
|
8
|
-
data: ListApiKeysResponseSuccess[] | null;
|
|
9
|
-
error: ErrorResponse | null;
|
|
10
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Resend } from '../resend';
|
|
2
|
-
import { CreateBatchOptions, CreateBatchRequestOptions, CreateBatchResponse } from './interfaces';
|
|
3
|
-
export declare class Batch {
|
|
4
|
-
private readonly resend;
|
|
5
|
-
constructor(resend: Resend);
|
|
6
|
-
send(payload: CreateBatchOptions, options?: CreateBatchRequestOptions): Promise<CreateBatchResponse>;
|
|
7
|
-
create(payload: CreateBatchOptions, options?: CreateBatchRequestOptions): Promise<CreateBatchResponse>;
|
|
8
|
-
}
|
package/build/src/batch/batch.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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.Batch = void 0;
|
|
13
|
-
const render_1 = require("@react-email/render");
|
|
14
|
-
class Batch {
|
|
15
|
-
constructor(resend) {
|
|
16
|
-
this.resend = resend;
|
|
17
|
-
}
|
|
18
|
-
send(payload, options = {}) {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
return this.create(payload, options);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
create(payload, options = {}) {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
for (const email of payload) {
|
|
26
|
-
if (email.react) {
|
|
27
|
-
email.html = yield (0, render_1.renderAsync)(email.react);
|
|
28
|
-
delete email.react;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const data = yield this.resend.post('/emails/batch', payload, options);
|
|
32
|
-
return data;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.Batch = Batch;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,122 +0,0 @@
|
|
|
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('Batch', () => {
|
|
17
|
-
afterEach(() => fetchMock.resetMocks());
|
|
18
|
-
describe('create', () => {
|
|
19
|
-
it('sends multiple emails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
const payload = [
|
|
21
|
-
{
|
|
22
|
-
from: 'bu@resend.com',
|
|
23
|
-
to: 'zeno@resend.com',
|
|
24
|
-
subject: 'Hello World',
|
|
25
|
-
html: '<h1>Hello world</h1>',
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
from: 'vitor@resend.com',
|
|
29
|
-
to: 'zeno@resend.com',
|
|
30
|
-
subject: 'Olá mundo',
|
|
31
|
-
html: '<h1>olá mundo</h1>',
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
from: 'bu@resend.com',
|
|
35
|
-
to: 'vitor@resend.com',
|
|
36
|
-
subject: 'Hi there',
|
|
37
|
-
html: '<h1>Hi there</h1>',
|
|
38
|
-
},
|
|
39
|
-
];
|
|
40
|
-
fetchMock.mockOnce(JSON.stringify({
|
|
41
|
-
data: [{ id: '1234' }, { id: '4567' }, { id: '4242' }],
|
|
42
|
-
}), {
|
|
43
|
-
status: 200,
|
|
44
|
-
headers: {
|
|
45
|
-
'content-type': 'application/json',
|
|
46
|
-
Authorization: 'Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop',
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
const data = yield resend.batch.create(payload);
|
|
50
|
-
expect(data).toMatchInlineSnapshot(`
|
|
51
|
-
{
|
|
52
|
-
"data": {
|
|
53
|
-
"data": [
|
|
54
|
-
{
|
|
55
|
-
"id": "1234",
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
"id": "4567",
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
"id": "4242",
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
},
|
|
65
|
-
"error": null,
|
|
66
|
-
}
|
|
67
|
-
`);
|
|
68
|
-
}));
|
|
69
|
-
});
|
|
70
|
-
describe('send', () => {
|
|
71
|
-
it('sends multiple emails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
-
const payload = [
|
|
73
|
-
{
|
|
74
|
-
from: 'bu@resend.com',
|
|
75
|
-
to: 'zeno@resend.com',
|
|
76
|
-
subject: 'Hello World',
|
|
77
|
-
html: '<h1>Hello world</h1>',
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
from: 'vitor@resend.com',
|
|
81
|
-
to: 'zeno@resend.com',
|
|
82
|
-
subject: 'Olá mundo',
|
|
83
|
-
html: '<h1>olá mundo</h1>',
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
from: 'bu@resend.com',
|
|
87
|
-
to: 'vitor@resend.com',
|
|
88
|
-
subject: 'Hi there',
|
|
89
|
-
html: '<h1>Hi there</h1>',
|
|
90
|
-
},
|
|
91
|
-
];
|
|
92
|
-
fetchMock.mockOnce(JSON.stringify({
|
|
93
|
-
data: [{ id: '1234' }, { id: '4567' }, { id: '4242' }],
|
|
94
|
-
}), {
|
|
95
|
-
status: 200,
|
|
96
|
-
headers: {
|
|
97
|
-
'content-type': 'application/json',
|
|
98
|
-
Authorization: 'Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop',
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
const data = yield resend.batch.send(payload);
|
|
102
|
-
expect(data).toMatchInlineSnapshot(`
|
|
103
|
-
{
|
|
104
|
-
"data": {
|
|
105
|
-
"data": [
|
|
106
|
-
{
|
|
107
|
-
"id": "1234",
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
"id": "4567",
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
"id": "4242",
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
},
|
|
117
|
-
"error": null,
|
|
118
|
-
}
|
|
119
|
-
`);
|
|
120
|
-
}));
|
|
121
|
-
});
|
|
122
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { PostOptions } from '../../common/interfaces';
|
|
2
|
-
import { CreateEmailOptions } from '../../emails/interfaces/create-email-options.interface';
|
|
3
|
-
import { ErrorResponse } from '../../interfaces';
|
|
4
|
-
export type CreateBatchOptions = CreateEmailOptions[];
|
|
5
|
-
export interface CreateBatchRequestOptions extends PostOptions {
|
|
6
|
-
}
|
|
7
|
-
export interface CreateBatchSuccessResponse {
|
|
8
|
-
data: {
|
|
9
|
-
/** The ID of the newly created email. */
|
|
10
|
-
id: string;
|
|
11
|
-
}[];
|
|
12
|
-
}
|
|
13
|
-
export interface CreateBatchResponse {
|
|
14
|
-
data: CreateBatchSuccessResponse | null;
|
|
15
|
-
error: ErrorResponse | null;
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './create-batch-options.interface';
|