resend 1.1.0-canary.0 → 1.1.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/build/package.json +1 -3
- package/build/src/resend.d.ts +1 -3
- package/build/src/resend.js +21 -29
- package/package.json +1 -3
- 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 -92
- package/build/src/batch/interfaces/create-batch-options.interface.d.ts +0 -11
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resend",
|
|
3
|
-
"version": "1.1.0
|
|
3
|
+
"version": "1.1.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",
|
|
@@ -32,13 +32,11 @@
|
|
|
32
32
|
"homepage": "https://github.com/resendlabs/resend-node#readme",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@react-email/render": "0.0.7",
|
|
35
|
-
"node-fetch": "2.6.12",
|
|
36
35
|
"type-fest": "3.13.0"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
38
|
"@types/jest": "29.5.3",
|
|
40
39
|
"@types/node": "18.17.5",
|
|
41
|
-
"@types/node-fetch": "2.6.4",
|
|
42
40
|
"@types/react": "18.2.20",
|
|
43
41
|
"@typescript-eslint/eslint-plugin": "6.4.0",
|
|
44
42
|
"@typescript-eslint/parser": "6.4.0",
|
package/build/src/resend.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { ApiKeys } from './api-keys/api-keys';
|
|
2
|
-
import { Batch } from './batch/batch';
|
|
3
1
|
import { GetOptions, PostOptions, PutOptions } from './common/interfaces';
|
|
2
|
+
import { ApiKeys } from './api-keys/api-keys';
|
|
4
3
|
import { Domains } from './domains/domains';
|
|
5
4
|
import { Emails } from './emails/emails';
|
|
6
5
|
import { CreateEmailOptions, CreateEmailResponse } from './emails/interfaces';
|
|
@@ -10,7 +9,6 @@ export declare class Resend {
|
|
|
10
9
|
readonly apiKeys: ApiKeys;
|
|
11
10
|
readonly domains: Domains;
|
|
12
11
|
readonly emails: Emails;
|
|
13
|
-
readonly batch: Batch;
|
|
14
12
|
constructor(key?: string | undefined);
|
|
15
13
|
fetchRequest(path: string, options?: {}): Promise<any>;
|
|
16
14
|
post<T>(path: string, entity?: any, options?: PostOptions): Promise<T>;
|
package/build/src/resend.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -33,10 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
33
10
|
};
|
|
34
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
12
|
exports.Resend = void 0;
|
|
36
|
-
const
|
|
13
|
+
const render_1 = require("@react-email/render");
|
|
37
14
|
const package_json_1 = require("../package.json");
|
|
38
15
|
const api_keys_1 = require("./api-keys/api-keys");
|
|
39
|
-
const batch_1 = require("./batch/batch");
|
|
40
16
|
const domains_1 = require("./domains/domains");
|
|
41
17
|
const emails_1 = require("./emails/emails");
|
|
42
18
|
const baseUrl = process.env.RESEND_BASE_URL || 'https://api.resend.com';
|
|
@@ -47,14 +23,13 @@ class Resend {
|
|
|
47
23
|
this.apiKeys = new api_keys_1.ApiKeys(this);
|
|
48
24
|
this.domains = new domains_1.Domains(this);
|
|
49
25
|
this.emails = new emails_1.Emails(this);
|
|
50
|
-
this.batch = new batch_1.Batch(this);
|
|
51
26
|
if (!key) {
|
|
52
27
|
this.key = process.env.RESEND_API_KEY;
|
|
53
28
|
if (!this.key) {
|
|
54
29
|
throw new Error('Missing API key. Pass it to the constructor `new Resend("re_123")`');
|
|
55
30
|
}
|
|
56
31
|
}
|
|
57
|
-
this.headers = new
|
|
32
|
+
this.headers = new Headers({
|
|
58
33
|
Authorization: `Bearer ${this.key}`,
|
|
59
34
|
'User-Agent': userAgent,
|
|
60
35
|
'Content-Type': 'application/json',
|
|
@@ -62,7 +37,7 @@ class Resend {
|
|
|
62
37
|
}
|
|
63
38
|
fetchRequest(path, options = {}) {
|
|
64
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
const response = yield (
|
|
40
|
+
const response = yield fetch(`${baseUrl}${path}`, options);
|
|
66
41
|
if (!response.ok) {
|
|
67
42
|
const error = yield response.json();
|
|
68
43
|
return error;
|
|
@@ -100,7 +75,24 @@ class Resend {
|
|
|
100
75
|
}
|
|
101
76
|
sendEmail(data) {
|
|
102
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
|
|
78
|
+
const path = '/email';
|
|
79
|
+
if (data.react) {
|
|
80
|
+
data.html = (0, render_1.render)(data.react);
|
|
81
|
+
delete data.react;
|
|
82
|
+
}
|
|
83
|
+
const response = yield this.post(path, {
|
|
84
|
+
from: data.from,
|
|
85
|
+
to: data.to,
|
|
86
|
+
bcc: data.bcc,
|
|
87
|
+
cc: data.cc,
|
|
88
|
+
reply_to: data.reply_to,
|
|
89
|
+
subject: data.subject,
|
|
90
|
+
text: data.text,
|
|
91
|
+
html: data.html,
|
|
92
|
+
attachments: data.attachments,
|
|
93
|
+
tags: data.tags,
|
|
94
|
+
});
|
|
95
|
+
return response;
|
|
104
96
|
});
|
|
105
97
|
}
|
|
106
98
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resend",
|
|
3
|
-
"version": "1.1.0
|
|
3
|
+
"version": "1.1.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",
|
|
@@ -32,13 +32,11 @@
|
|
|
32
32
|
"homepage": "https://github.com/resendlabs/resend-node#readme",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@react-email/render": "0.0.7",
|
|
35
|
-
"node-fetch": "2.6.12",
|
|
36
35
|
"type-fest": "3.13.0"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
38
|
"@types/jest": "29.5.3",
|
|
40
39
|
"@types/node": "18.17.5",
|
|
41
|
-
"@types/node-fetch": "2.6.4",
|
|
42
40
|
"@types/react": "18.2.20",
|
|
43
41
|
"@typescript-eslint/eslint-plugin": "6.4.0",
|
|
44
42
|
"@typescript-eslint/parser": "6.4.0",
|
|
@@ -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 = (0, render_1.render)(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,92 +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).toMatchObject({
|
|
51
|
-
data: [{ id: '1234' }, { id: '4567' }, { id: '4242' }],
|
|
52
|
-
});
|
|
53
|
-
}));
|
|
54
|
-
});
|
|
55
|
-
describe('send', () => {
|
|
56
|
-
it('sends multiple emails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
-
const payload = [
|
|
58
|
-
{
|
|
59
|
-
from: 'bu@resend.com',
|
|
60
|
-
to: 'zeno@resend.com',
|
|
61
|
-
subject: 'Hello World',
|
|
62
|
-
html: '<h1>Hello world</h1>',
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
from: 'vitor@resend.com',
|
|
66
|
-
to: 'zeno@resend.com',
|
|
67
|
-
subject: 'Olá mundo',
|
|
68
|
-
html: '<h1>olá mundo</h1>',
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
from: 'bu@resend.com',
|
|
72
|
-
to: 'vitor@resend.com',
|
|
73
|
-
subject: 'Hi there',
|
|
74
|
-
html: '<h1>Hi there</h1>',
|
|
75
|
-
},
|
|
76
|
-
];
|
|
77
|
-
fetchMock.mockOnce(JSON.stringify({
|
|
78
|
-
data: [{ id: '1234' }, { id: '4567' }, { id: '4242' }],
|
|
79
|
-
}), {
|
|
80
|
-
status: 200,
|
|
81
|
-
headers: {
|
|
82
|
-
'content-type': 'application/json',
|
|
83
|
-
Authorization: 'Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop',
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
const data = yield resend.batch.send(payload);
|
|
87
|
-
expect(data).toMatchObject({
|
|
88
|
-
data: [{ id: '1234' }, { id: '4567' }, { id: '4242' }],
|
|
89
|
-
});
|
|
90
|
-
}));
|
|
91
|
-
});
|
|
92
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { PostOptions } from '../../common/interfaces';
|
|
2
|
-
import { CreateEmailOptions } from '../../emails/interfaces/create-email-options.interface';
|
|
3
|
-
export type CreateBatchOptions = CreateEmailOptions[];
|
|
4
|
-
export interface CreateBatchRequestOptions extends PostOptions {
|
|
5
|
-
}
|
|
6
|
-
export interface CreateBatchResponse {
|
|
7
|
-
data: {
|
|
8
|
-
/** The ID of the newly created email. */
|
|
9
|
-
id: string;
|
|
10
|
-
}[];
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './create-batch-options.interface';
|
|
@@ -1,17 +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-batch-options.interface"), exports);
|