resend 0.13.1 → 0.14.1
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 +4 -4
- package/build/src/emails/emails.d.ts +10 -0
- package/build/src/emails/emails.js +35 -0
- package/build/src/emails/interfaces/create-email-options.interface.d.ts +16 -0
- package/build/src/emails/interfaces/create-email-options.interface.js +2 -0
- package/build/src/emails/interfaces/get-email-options.interface.d.ts +11 -0
- package/build/src/emails/interfaces/get-email-options.interface.js +2 -0
- package/build/src/emails/interfaces/index.d.ts +1 -0
- package/build/src/emails/interfaces/index.js +17 -0
- package/build/src/interfaces.d.ts +14 -2
- package/build/src/interfaces.js +10 -0
- package/build/src/resend.d.ts +3 -1
- package/build/src/resend.js +2 -0
- package/build/src/resend.spec.js +10 -10
- package/package.json +4 -4
- package/readme.md +4 -4
package/build/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
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.
|
|
31
|
+
"axios": "1.4.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/jest": "29.5.1",
|
|
35
|
-
"@types/node": "18.
|
|
36
|
-
"@types/react": "18.0
|
|
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
|
+
bcc?: string | string[];
|
|
4
|
+
cc?: string | string[];
|
|
5
|
+
from: string;
|
|
6
|
+
html?: string;
|
|
7
|
+
reply_to?: string | string[];
|
|
8
|
+
subject: string;
|
|
9
|
+
text?: string;
|
|
10
|
+
to: string | string[];
|
|
11
|
+
}
|
|
12
|
+
export interface CreateEmailRequestOptions extends PostOptions {
|
|
13
|
+
}
|
|
14
|
+
export interface CreateEmailResponse {
|
|
15
|
+
id: string;
|
|
16
|
+
}
|
|
@@ -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:
|
|
61
|
-
type:
|
|
72
|
+
status: RESEND_ERROR_CODE_NUMBER;
|
|
73
|
+
type: RESEND_ERROR_CODE_KEY;
|
|
62
74
|
};
|
|
63
75
|
}
|
|
64
76
|
export type SendEmailResponse = EmailResponse | ErrorResponse;
|
package/build/src/interfaces.js
CHANGED
|
@@ -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
|
+
};
|
package/build/src/resend.d.ts
CHANGED
|
@@ -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<
|
|
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>;
|
package/build/src/resend.js
CHANGED
|
@@ -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/build/src/resend.spec.js
CHANGED
|
@@ -28,13 +28,13 @@ describe('Resend', () => {
|
|
|
28
28
|
to: 'zeno@resend.com',
|
|
29
29
|
subject: 'Hello World',
|
|
30
30
|
};
|
|
31
|
-
mock.onPost('/
|
|
31
|
+
mock.onPost('/emails', payload).replyOnce(200, {
|
|
32
32
|
id: '1234',
|
|
33
33
|
from: 'bu@resend.com',
|
|
34
34
|
to: 'zeno@resend.com',
|
|
35
35
|
created_at: '123',
|
|
36
36
|
});
|
|
37
|
-
const data = yield resend.
|
|
37
|
+
const data = yield resend.emails.send(payload);
|
|
38
38
|
expect(data).toMatchInlineSnapshot(`
|
|
39
39
|
{
|
|
40
40
|
"created_at": "123",
|
|
@@ -50,13 +50,13 @@ describe('Resend', () => {
|
|
|
50
50
|
to: ['bu@resend.com', 'zeno@resend.com'],
|
|
51
51
|
subject: 'Hello World',
|
|
52
52
|
};
|
|
53
|
-
mock.onPost('/
|
|
53
|
+
mock.onPost('/emails', payload).replyOnce(200, {
|
|
54
54
|
id: '1234',
|
|
55
55
|
from: 'admin@resend.com',
|
|
56
56
|
to: ['bu@resend.com', 'zeno@resend.com'],
|
|
57
57
|
created_at: '123',
|
|
58
58
|
});
|
|
59
|
-
const data = yield resend.
|
|
59
|
+
const data = yield resend.emails.send(payload);
|
|
60
60
|
expect(data).toMatchInlineSnapshot(`
|
|
61
61
|
{
|
|
62
62
|
"created_at": "123",
|
|
@@ -76,14 +76,14 @@ describe('Resend', () => {
|
|
|
76
76
|
bcc: ['foo@resend.com', 'bar@resend.com'],
|
|
77
77
|
subject: 'Hello World',
|
|
78
78
|
};
|
|
79
|
-
mock.onPost('/
|
|
79
|
+
mock.onPost('/emails', payload).replyOnce(200, {
|
|
80
80
|
id: '1234',
|
|
81
81
|
from: 'admin@resend.com',
|
|
82
82
|
to: 'bu@resend.com',
|
|
83
83
|
bcc: ['foo@resend.com', 'bar@resend.com'],
|
|
84
84
|
created_at: '123',
|
|
85
85
|
});
|
|
86
|
-
const data = yield resend.
|
|
86
|
+
const data = yield resend.emails.send(payload);
|
|
87
87
|
expect(data).toMatchInlineSnapshot(`
|
|
88
88
|
{
|
|
89
89
|
"bcc": [
|
|
@@ -104,14 +104,14 @@ describe('Resend', () => {
|
|
|
104
104
|
cc: ['foo@resend.com', 'bar@resend.com'],
|
|
105
105
|
subject: 'Hello World',
|
|
106
106
|
};
|
|
107
|
-
mock.onPost('/
|
|
107
|
+
mock.onPost('/emails', payload).replyOnce(200, {
|
|
108
108
|
id: '1234',
|
|
109
109
|
from: 'admin@resend.com',
|
|
110
110
|
to: 'bu@resend.com',
|
|
111
111
|
cc: ['foo@resend.com', 'bar@resend.com'],
|
|
112
112
|
created_at: '123',
|
|
113
113
|
});
|
|
114
|
-
const data = yield resend.
|
|
114
|
+
const data = yield resend.emails.send(payload);
|
|
115
115
|
expect(data).toMatchInlineSnapshot(`
|
|
116
116
|
{
|
|
117
117
|
"cc": [
|
|
@@ -132,7 +132,7 @@ describe('Resend', () => {
|
|
|
132
132
|
reply_to: ['foo@resend.com', 'bar@resend.com'],
|
|
133
133
|
subject: 'Hello World',
|
|
134
134
|
};
|
|
135
|
-
mock.onPost('/
|
|
135
|
+
mock.onPost('/emails', apiPayload).replyOnce(200, {
|
|
136
136
|
id: '1234',
|
|
137
137
|
from: 'admin@resend.com',
|
|
138
138
|
to: 'bu@resend.com',
|
|
@@ -145,7 +145,7 @@ describe('Resend', () => {
|
|
|
145
145
|
reply_to: ['foo@resend.com', 'bar@resend.com'],
|
|
146
146
|
subject: 'Hello World',
|
|
147
147
|
};
|
|
148
|
-
const data = yield resend.
|
|
148
|
+
const data = yield resend.emails.send(payload);
|
|
149
149
|
expect(data).toMatchInlineSnapshot(`
|
|
150
150
|
{
|
|
151
151
|
"created_at": "123",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
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.
|
|
31
|
+
"axios": "1.4.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/jest": "29.5.1",
|
|
35
|
-
"@types/node": "18.
|
|
36
|
-
"@types/react": "18.0
|
|
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",
|
package/readme.md
CHANGED
|
@@ -24,7 +24,7 @@ const resend = new Resend('re_123');
|
|
|
24
24
|
Send your first email:
|
|
25
25
|
|
|
26
26
|
```js
|
|
27
|
-
await resend.
|
|
27
|
+
await resend.emails.send({
|
|
28
28
|
from: 'you@example.com',
|
|
29
29
|
to: 'user@gmail.com',
|
|
30
30
|
subject: 'hello world',
|
|
@@ -37,7 +37,7 @@ await resend.sendEmail({
|
|
|
37
37
|
Send an email custom HTML content:
|
|
38
38
|
|
|
39
39
|
```js
|
|
40
|
-
await resend.
|
|
40
|
+
await resend.emails.send({
|
|
41
41
|
from: 'you@example.com',
|
|
42
42
|
to: 'user@gmail.com',
|
|
43
43
|
subject: 'hello world',
|
|
@@ -69,7 +69,7 @@ Then import the template component and pass it to the `react` property.
|
|
|
69
69
|
```jsx
|
|
70
70
|
import EmailTemplate from '../components/EmailTemplate'
|
|
71
71
|
|
|
72
|
-
await resend.
|
|
72
|
+
await resend.emails.send({
|
|
73
73
|
from: 'you@example.com',
|
|
74
74
|
to: 'user@gmail.com',
|
|
75
75
|
subject: 'hello world',
|
|
@@ -79,4 +79,4 @@ await resend.sendEmail({
|
|
|
79
79
|
|
|
80
80
|
## License
|
|
81
81
|
|
|
82
|
-
MIT License
|
|
82
|
+
MIT License
|