resend 2.0.0 → 2.1.0-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/build/package.json +3 -3
- package/build/src/audiences/audiences.d.ts +10 -0
- package/build/src/audiences/audiences.js +42 -0
- package/build/src/audiences/audiences.spec.d.ts +1 -0
- package/build/src/audiences/audiences.spec.js +186 -0
- package/build/src/audiences/interfaces/audience.d.ts +5 -0
- package/build/src/audiences/interfaces/audience.js +2 -0
- package/build/src/audiences/interfaces/create-audience-options.interface.d.ts +14 -0
- package/build/src/audiences/interfaces/create-audience-options.interface.js +2 -0
- package/build/src/audiences/interfaces/get-audience.interface.d.ts +9 -0
- package/build/src/audiences/interfaces/get-audience.interface.js +2 -0
- package/build/src/audiences/interfaces/index.d.ts +4 -0
- package/build/src/audiences/interfaces/index.js +20 -0
- package/build/src/audiences/interfaces/list-audiences.interface.d.ts +7 -0
- package/build/src/audiences/interfaces/list-audiences.interface.js +2 -0
- package/build/src/audiences/interfaces/remove-audience.interface.d.ts +7 -0
- package/build/src/audiences/interfaces/remove-audience.interface.js +2 -0
- package/build/src/contacts/contacts.d.ts +18 -0
- package/build/src/contacts/contacts.js +42 -0
- package/build/src/contacts/contacts.spec.d.ts +1 -0
- package/build/src/contacts/contacts.spec.js +198 -0
- package/build/src/contacts/interfaces/contact.d.ts +5 -0
- package/build/src/contacts/interfaces/contact.js +2 -0
- package/build/src/contacts/interfaces/create-contact-options.interface.d.ts +18 -0
- package/build/src/contacts/interfaces/create-contact-options.interface.js +2 -0
- package/build/src/contacts/interfaces/get-contact.interface.d.ts +9 -0
- package/build/src/contacts/interfaces/get-contact.interface.js +2 -0
- package/build/src/contacts/interfaces/index.d.ts +4 -0
- package/build/src/contacts/interfaces/index.js +20 -0
- package/build/src/contacts/interfaces/list-contacts.interface.d.ts +7 -0
- package/build/src/contacts/interfaces/list-contacts.interface.js +2 -0
- package/build/src/contacts/interfaces/remove-contact.interface.d.ts +7 -0
- package/build/src/contacts/interfaces/remove-contact.interface.js +2 -0
- package/build/src/resend.d.ts +5 -1
- package/build/src/resend.js +5 -1
- package/package.json +3 -3
- package/build/src/__snapshots__/resend.spec.js.snap +0 -3
package/build/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resend",
|
|
3
|
-
"version": "2.0.0",
|
|
3
|
+
"version": "2.1.0-canary.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",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"@types/jest": "29.5.7",
|
|
38
38
|
"@types/node": "18.18.8",
|
|
39
39
|
"@types/react": "18.2.33",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
41
|
-
"@typescript-eslint/parser": "6.
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "6.10.0",
|
|
41
|
+
"@typescript-eslint/parser": "6.10.0",
|
|
42
42
|
"eslint": "8.52.0",
|
|
43
43
|
"jest": "29.7.0",
|
|
44
44
|
"jest-fetch-mock": "3.0.3",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Resend } from '../resend';
|
|
2
|
+
import { CreateAudienceOptions, CreateAudienceRequestOptions, CreateAudienceResponse, GetAudienceResponse, ListAudiencesResponse, RemoveAudiencesResponse } from './interfaces';
|
|
3
|
+
export declare class Audiences {
|
|
4
|
+
private readonly resend;
|
|
5
|
+
constructor(resend: Resend);
|
|
6
|
+
create(payload: CreateAudienceOptions, options?: CreateAudienceRequestOptions): Promise<CreateAudienceResponse>;
|
|
7
|
+
list(): Promise<ListAudiencesResponse>;
|
|
8
|
+
get(id: string): Promise<GetAudienceResponse>;
|
|
9
|
+
remove(id: string): Promise<RemoveAudiencesResponse>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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.Audiences = void 0;
|
|
13
|
+
class Audiences {
|
|
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('/audiences', 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('/audiences');
|
|
26
|
+
return data;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
get(id) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const data = yield this.resend.get(`/audiences/${id}`);
|
|
32
|
+
return data;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
remove(id) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const data = yield this.resend.delete(`/audiences/${id}`);
|
|
38
|
+
return data;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.Audiences = Audiences;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,186 @@
|
|
|
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('Audiences', () => {
|
|
16
|
+
afterEach(() => fetchMock.resetMocks());
|
|
17
|
+
describe('create', () => {
|
|
18
|
+
it('creates a audience', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
fetchMock.mockOnce(JSON.stringify({
|
|
20
|
+
id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
|
|
21
|
+
name: 'Resend',
|
|
22
|
+
created_at: '2023-04-07T22:48:33.420498+00:00',
|
|
23
|
+
}), {
|
|
24
|
+
status: 200,
|
|
25
|
+
headers: {
|
|
26
|
+
'content-type': 'application/json',
|
|
27
|
+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
31
|
+
yield expect(resend.audiences.create({ name: 'resend.com' })).resolves
|
|
32
|
+
.toMatchInlineSnapshot(`
|
|
33
|
+
{
|
|
34
|
+
"data": {
|
|
35
|
+
"created_at": "2023-04-07T22:48:33.420498+00:00",
|
|
36
|
+
"id": "3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222",
|
|
37
|
+
"name": "Resend",
|
|
38
|
+
},
|
|
39
|
+
"error": null,
|
|
40
|
+
}
|
|
41
|
+
`);
|
|
42
|
+
}));
|
|
43
|
+
it('throws error when missing name', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
const errorResponse = {
|
|
45
|
+
name: 'missing_required_field',
|
|
46
|
+
message: 'Missing "name" field',
|
|
47
|
+
};
|
|
48
|
+
fetchMock.mockOnce(JSON.stringify(errorResponse), {
|
|
49
|
+
status: 422,
|
|
50
|
+
headers: {
|
|
51
|
+
'content-type': 'application/json',
|
|
52
|
+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
56
|
+
const result = resend.audiences.create({ name: '' });
|
|
57
|
+
yield expect(result).resolves.toMatchInlineSnapshot(`
|
|
58
|
+
{
|
|
59
|
+
"data": null,
|
|
60
|
+
"error": {
|
|
61
|
+
"message": "Missing "name" field",
|
|
62
|
+
"name": "missing_required_field",
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
`);
|
|
66
|
+
}));
|
|
67
|
+
});
|
|
68
|
+
describe('list', () => {
|
|
69
|
+
it('lists audiences', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
fetchMock.mockOnce(JSON.stringify({
|
|
71
|
+
data: [
|
|
72
|
+
{
|
|
73
|
+
id: 'b6d24b8e-af0b-4c3c-be0c-359bbd97381e',
|
|
74
|
+
name: 'resend.com',
|
|
75
|
+
created_at: '2023-04-07T23:13:52.669661+00:00',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: 'ac7503ac-e027-4aea-94b3-b0acd46f65f9',
|
|
79
|
+
name: 'react.email',
|
|
80
|
+
created_at: '2023-04-07T23:13:20.417116+00:00',
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
}), {
|
|
84
|
+
status: 200,
|
|
85
|
+
headers: {
|
|
86
|
+
'content-type': 'application/json',
|
|
87
|
+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
91
|
+
yield expect(resend.audiences.list()).resolves.toMatchInlineSnapshot(`
|
|
92
|
+
{
|
|
93
|
+
"data": {
|
|
94
|
+
"data": [
|
|
95
|
+
{
|
|
96
|
+
"created_at": "2023-04-07T23:13:52.669661+00:00",
|
|
97
|
+
"id": "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
|
|
98
|
+
"name": "resend.com",
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"created_at": "2023-04-07T23:13:20.417116+00:00",
|
|
102
|
+
"id": "ac7503ac-e027-4aea-94b3-b0acd46f65f9",
|
|
103
|
+
"name": "react.email",
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
"error": null,
|
|
108
|
+
}
|
|
109
|
+
`);
|
|
110
|
+
}));
|
|
111
|
+
});
|
|
112
|
+
describe('get', () => {
|
|
113
|
+
describe('when audience not found', () => {
|
|
114
|
+
it('returns error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
115
|
+
const errorResponse = {
|
|
116
|
+
name: 'not_found',
|
|
117
|
+
message: 'Audience not found',
|
|
118
|
+
};
|
|
119
|
+
fetchMock.mockOnce(JSON.stringify(errorResponse), {
|
|
120
|
+
status: 404,
|
|
121
|
+
headers: {
|
|
122
|
+
'content-type': 'application/json',
|
|
123
|
+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
127
|
+
const result = resend.audiences.get('1234');
|
|
128
|
+
yield expect(result).resolves.toMatchInlineSnapshot(`
|
|
129
|
+
{
|
|
130
|
+
"data": null,
|
|
131
|
+
"error": {
|
|
132
|
+
"message": "Audience not found",
|
|
133
|
+
"name": "not_found",
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
`);
|
|
137
|
+
}));
|
|
138
|
+
});
|
|
139
|
+
it('get audience', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
+
const audience = {
|
|
141
|
+
object: 'audience',
|
|
142
|
+
id: 'fd61172c-cafc-40f5-b049-b45947779a29',
|
|
143
|
+
name: 'resend.com',
|
|
144
|
+
created_at: '2023-06-21T06:10:36.144Z',
|
|
145
|
+
};
|
|
146
|
+
fetchMock.mockOnce(JSON.stringify(audience), {
|
|
147
|
+
status: 200,
|
|
148
|
+
headers: {
|
|
149
|
+
'content-type': 'application/json',
|
|
150
|
+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
154
|
+
yield expect(resend.audiences.get('1234')).resolves
|
|
155
|
+
.toMatchInlineSnapshot(`
|
|
156
|
+
{
|
|
157
|
+
"data": {
|
|
158
|
+
"created_at": "2023-06-21T06:10:36.144Z",
|
|
159
|
+
"id": "fd61172c-cafc-40f5-b049-b45947779a29",
|
|
160
|
+
"name": "resend.com",
|
|
161
|
+
"object": "audience",
|
|
162
|
+
},
|
|
163
|
+
"error": null,
|
|
164
|
+
}
|
|
165
|
+
`);
|
|
166
|
+
}));
|
|
167
|
+
});
|
|
168
|
+
describe('remove', () => {
|
|
169
|
+
it('removes a audience', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
170
|
+
fetchMock.mockOnce(JSON.stringify({}), {
|
|
171
|
+
status: 200,
|
|
172
|
+
headers: {
|
|
173
|
+
'content-type': 'application/json',
|
|
174
|
+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
178
|
+
yield expect(resend.audiences.remove('5262504e-8ed7-4fac-bd16-0d4be94bc9f2')).resolves.toMatchInlineSnapshot(`
|
|
179
|
+
{
|
|
180
|
+
"data": {},
|
|
181
|
+
"error": null,
|
|
182
|
+
}
|
|
183
|
+
`);
|
|
184
|
+
}));
|
|
185
|
+
});
|
|
186
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PostOptions } from '../../common/interfaces';
|
|
2
|
+
import { ErrorResponse } from '../../interfaces';
|
|
3
|
+
import { Audience } from './audience';
|
|
4
|
+
export interface CreateAudienceOptions {
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CreateAudienceRequestOptions extends PostOptions {
|
|
8
|
+
}
|
|
9
|
+
export interface CreateAudienceResponseSuccess extends Pick<Audience, 'name' | 'id' | 'created_at'> {
|
|
10
|
+
}
|
|
11
|
+
export interface CreateAudienceResponse {
|
|
12
|
+
data: CreateAudienceResponseSuccess | null;
|
|
13
|
+
error: ErrorResponse | null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ErrorResponse } from '../../interfaces';
|
|
2
|
+
import { Audience } from './audience';
|
|
3
|
+
export interface GetAudienceResponseSuccess extends Pick<Audience, 'id' | 'name' | 'created_at'> {
|
|
4
|
+
object: 'audience';
|
|
5
|
+
}
|
|
6
|
+
export interface GetAudienceResponse {
|
|
7
|
+
data: GetAudienceResponseSuccess | null;
|
|
8
|
+
error: ErrorResponse | null;
|
|
9
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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-audience-options.interface"), exports);
|
|
18
|
+
__exportStar(require("./list-audiences.interface"), exports);
|
|
19
|
+
__exportStar(require("./get-audience.interface"), exports);
|
|
20
|
+
__exportStar(require("./remove-audience.interface"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ErrorResponse } from '../../interfaces';
|
|
2
|
+
import { Audience } from './audience';
|
|
3
|
+
export type ListAudiencesResponseSuccess = Audience[];
|
|
4
|
+
export interface ListAudiencesResponse {
|
|
5
|
+
data: ListAudiencesResponseSuccess | null;
|
|
6
|
+
error: ErrorResponse | null;
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ErrorResponse } from '../../interfaces';
|
|
2
|
+
import { Audience } from './audience';
|
|
3
|
+
export type RemoveAudiencesResponseSuccess = Pick<Audience, 'id'>;
|
|
4
|
+
export interface RemoveAudiencesResponse {
|
|
5
|
+
data: RemoveAudiencesResponseSuccess | null;
|
|
6
|
+
error: ErrorResponse | null;
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Resend } from '../resend';
|
|
2
|
+
import { CreateContactOptions, CreateContactRequestOptions, CreateContactResponse, GetContactResponse, ListContactsResponse, RemoveContactsResponse } from './interfaces';
|
|
3
|
+
export declare class Contacts {
|
|
4
|
+
private readonly resend;
|
|
5
|
+
constructor(resend: Resend);
|
|
6
|
+
create(payload: CreateContactOptions, options?: CreateContactRequestOptions): Promise<CreateContactResponse>;
|
|
7
|
+
list({ audience_id, }: {
|
|
8
|
+
audience_id: string;
|
|
9
|
+
}): Promise<ListContactsResponse>;
|
|
10
|
+
get({ audience_id, id, }: {
|
|
11
|
+
audience_id: string;
|
|
12
|
+
id: string;
|
|
13
|
+
}): Promise<GetContactResponse>;
|
|
14
|
+
remove({ audience_id, id, }: {
|
|
15
|
+
audience_id: string;
|
|
16
|
+
id: string;
|
|
17
|
+
}): Promise<RemoveContactsResponse>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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.Contacts = void 0;
|
|
13
|
+
class Contacts {
|
|
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(`/audiences/${payload.audience_id}/contacts`, payload, options);
|
|
20
|
+
return data;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
list({ audience_id, }) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const data = yield this.resend.get(`/audiences/${audience_id}/contacts`);
|
|
26
|
+
return data;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
get({ audience_id, id, }) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const data = yield this.resend.get(`/audiences/${audience_id}/contacts/${id}`);
|
|
32
|
+
return data;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
remove({ audience_id, id, }) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const data = yield this.resend.delete(`/audiences/${audience_id}/contacts/${id}`);
|
|
38
|
+
return data;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.Contacts = Contacts;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,198 @@
|
|
|
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('Contacts', () => {
|
|
16
|
+
afterEach(() => fetchMock.resetMocks());
|
|
17
|
+
describe('create', () => {
|
|
18
|
+
it('creates a contact', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
fetchMock.mockOnce(JSON.stringify({
|
|
20
|
+
id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
|
|
21
|
+
name: 'Resend',
|
|
22
|
+
created_at: '2023-04-07T22:48:33.420498+00:00',
|
|
23
|
+
}), {
|
|
24
|
+
status: 200,
|
|
25
|
+
headers: {
|
|
26
|
+
'content-type': 'application/json',
|
|
27
|
+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
31
|
+
yield expect(resend.contacts.create({
|
|
32
|
+
email: 'team@resend.com',
|
|
33
|
+
audience_id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
|
|
34
|
+
})).resolves.toMatchInlineSnapshot(`
|
|
35
|
+
{
|
|
36
|
+
"data": {
|
|
37
|
+
"created_at": "2023-04-07T22:48:33.420498+00:00",
|
|
38
|
+
"id": "3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222",
|
|
39
|
+
"name": "Resend",
|
|
40
|
+
},
|
|
41
|
+
"error": null,
|
|
42
|
+
}
|
|
43
|
+
`);
|
|
44
|
+
}));
|
|
45
|
+
it('throws error when missing name', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const errorResponse = {
|
|
47
|
+
name: 'missing_required_field',
|
|
48
|
+
message: 'Missing `email` field.',
|
|
49
|
+
};
|
|
50
|
+
fetchMock.mockOnce(JSON.stringify(errorResponse), {
|
|
51
|
+
status: 422,
|
|
52
|
+
headers: {
|
|
53
|
+
'content-type': 'application/json',
|
|
54
|
+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
58
|
+
const result = resend.contacts.create({ email: '', audience_id: '' });
|
|
59
|
+
yield expect(result).resolves.toMatchInlineSnapshot(`
|
|
60
|
+
{
|
|
61
|
+
"data": null,
|
|
62
|
+
"error": {
|
|
63
|
+
"message": "Missing \`email\` field.",
|
|
64
|
+
"name": "missing_required_field",
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
`);
|
|
68
|
+
}));
|
|
69
|
+
});
|
|
70
|
+
describe('list', () => {
|
|
71
|
+
it('lists contacts', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
fetchMock.mockOnce(JSON.stringify({
|
|
73
|
+
data: [
|
|
74
|
+
{
|
|
75
|
+
id: 'b6d24b8e-af0b-4c3c-be0c-359bbd97381e',
|
|
76
|
+
name: 'resend.com',
|
|
77
|
+
created_at: '2023-04-07T23:13:52.669661+00:00',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: 'ac7503ac-e027-4aea-94b3-b0acd46f65f9',
|
|
81
|
+
name: 'react.email',
|
|
82
|
+
created_at: '2023-04-07T23:13:20.417116+00:00',
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
}), {
|
|
86
|
+
status: 200,
|
|
87
|
+
headers: {
|
|
88
|
+
'content-type': 'application/json',
|
|
89
|
+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
93
|
+
yield expect(resend.contacts.list({
|
|
94
|
+
audience_id: 'b6d24b8e-af0b-4c3c-be0c-359bbd97381a',
|
|
95
|
+
})).resolves.toMatchInlineSnapshot(`
|
|
96
|
+
{
|
|
97
|
+
"data": {
|
|
98
|
+
"data": [
|
|
99
|
+
{
|
|
100
|
+
"created_at": "2023-04-07T23:13:52.669661+00:00",
|
|
101
|
+
"id": "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
|
|
102
|
+
"name": "resend.com",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"created_at": "2023-04-07T23:13:20.417116+00:00",
|
|
106
|
+
"id": "ac7503ac-e027-4aea-94b3-b0acd46f65f9",
|
|
107
|
+
"name": "react.email",
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
"error": null,
|
|
112
|
+
}
|
|
113
|
+
`);
|
|
114
|
+
}));
|
|
115
|
+
});
|
|
116
|
+
describe('get', () => {
|
|
117
|
+
describe('when contact not found', () => {
|
|
118
|
+
it('returns error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
119
|
+
const errorResponse = {
|
|
120
|
+
name: 'not_found',
|
|
121
|
+
message: 'Contact not found',
|
|
122
|
+
};
|
|
123
|
+
fetchMock.mockOnce(JSON.stringify(errorResponse), {
|
|
124
|
+
status: 404,
|
|
125
|
+
headers: {
|
|
126
|
+
'content-type': 'application/json',
|
|
127
|
+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
131
|
+
const result = resend.contacts.get({
|
|
132
|
+
id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87223',
|
|
133
|
+
audience_id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
|
|
134
|
+
});
|
|
135
|
+
yield expect(result).resolves.toMatchInlineSnapshot(`
|
|
136
|
+
{
|
|
137
|
+
"data": null,
|
|
138
|
+
"error": {
|
|
139
|
+
"message": "Contact not found",
|
|
140
|
+
"name": "not_found",
|
|
141
|
+
},
|
|
142
|
+
}
|
|
143
|
+
`);
|
|
144
|
+
}));
|
|
145
|
+
});
|
|
146
|
+
it('get contact', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
+
const contact = {
|
|
148
|
+
object: 'contact',
|
|
149
|
+
id: 'fd61172c-cafc-40f5-b049-b45947779a29',
|
|
150
|
+
name: 'resend.com',
|
|
151
|
+
created_at: '2023-06-21T06:10:36.144Z',
|
|
152
|
+
};
|
|
153
|
+
fetchMock.mockOnce(JSON.stringify(contact), {
|
|
154
|
+
status: 200,
|
|
155
|
+
headers: {
|
|
156
|
+
'content-type': 'application/json',
|
|
157
|
+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
161
|
+
yield expect(resend.contacts.get({
|
|
162
|
+
id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87223',
|
|
163
|
+
audience_id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
|
|
164
|
+
})).resolves.toMatchInlineSnapshot(`
|
|
165
|
+
{
|
|
166
|
+
"data": {
|
|
167
|
+
"created_at": "2023-06-21T06:10:36.144Z",
|
|
168
|
+
"id": "fd61172c-cafc-40f5-b049-b45947779a29",
|
|
169
|
+
"name": "resend.com",
|
|
170
|
+
"object": "contact",
|
|
171
|
+
},
|
|
172
|
+
"error": null,
|
|
173
|
+
}
|
|
174
|
+
`);
|
|
175
|
+
}));
|
|
176
|
+
});
|
|
177
|
+
describe('remove', () => {
|
|
178
|
+
it('removes a contact', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
179
|
+
fetchMock.mockOnce(JSON.stringify({}), {
|
|
180
|
+
status: 200,
|
|
181
|
+
headers: {
|
|
182
|
+
'content-type': 'application/json',
|
|
183
|
+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
const resend = new resend_1.Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
|
|
187
|
+
yield expect(resend.contacts.remove({
|
|
188
|
+
id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87223',
|
|
189
|
+
audience_id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
|
|
190
|
+
})).resolves.toMatchInlineSnapshot(`
|
|
191
|
+
{
|
|
192
|
+
"data": {},
|
|
193
|
+
"error": null,
|
|
194
|
+
}
|
|
195
|
+
`);
|
|
196
|
+
}));
|
|
197
|
+
});
|
|
198
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PostOptions } from '../../common/interfaces';
|
|
2
|
+
import { ErrorResponse } from '../../interfaces';
|
|
3
|
+
import { Contact } from './contact';
|
|
4
|
+
export interface CreateContactOptions {
|
|
5
|
+
audience_id: string;
|
|
6
|
+
email: string;
|
|
7
|
+
unsubscribed?: boolean;
|
|
8
|
+
first_name?: string;
|
|
9
|
+
last_name?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface CreateContactRequestOptions extends PostOptions {
|
|
12
|
+
}
|
|
13
|
+
export interface CreateContactResponseSuccess extends Pick<Contact, 'name' | 'id' | 'created_at'> {
|
|
14
|
+
}
|
|
15
|
+
export interface CreateContactResponse {
|
|
16
|
+
data: CreateContactResponseSuccess | null;
|
|
17
|
+
error: ErrorResponse | null;
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ErrorResponse } from '../../interfaces';
|
|
2
|
+
import { Contact } from './contact';
|
|
3
|
+
export interface GetContactResponseSuccess extends Pick<Contact, 'id' | 'name' | 'created_at'> {
|
|
4
|
+
object: 'contact';
|
|
5
|
+
}
|
|
6
|
+
export interface GetContactResponse {
|
|
7
|
+
data: GetContactResponseSuccess | null;
|
|
8
|
+
error: ErrorResponse | null;
|
|
9
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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-contact-options.interface"), exports);
|
|
18
|
+
__exportStar(require("./list-contacts.interface"), exports);
|
|
19
|
+
__exportStar(require("./get-contact.interface"), exports);
|
|
20
|
+
__exportStar(require("./remove-contact.interface"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ErrorResponse } from '../../interfaces';
|
|
2
|
+
import { Contact } from './contact';
|
|
3
|
+
export type RemoveContactsResponseSuccess = Pick<Contact, 'id'>;
|
|
4
|
+
export interface RemoveContactsResponse {
|
|
5
|
+
data: RemoveContactsResponseSuccess | null;
|
|
6
|
+
error: ErrorResponse | null;
|
|
7
|
+
}
|
package/build/src/resend.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ApiKeys } from './api-keys/api-keys';
|
|
2
|
+
import { Audiences } from './audiences/audiences';
|
|
2
3
|
import { Batch } from './batch/batch';
|
|
3
4
|
import { GetOptions, PostOptions, PutOptions } from './common/interfaces';
|
|
5
|
+
import { Contacts } from './contacts/contacts';
|
|
4
6
|
import { Domains } from './domains/domains';
|
|
5
7
|
import { Emails } from './emails/emails';
|
|
6
8
|
import { ErrorResponse } from './interfaces';
|
|
@@ -8,9 +10,11 @@ export declare class Resend {
|
|
|
8
10
|
readonly key?: string | undefined;
|
|
9
11
|
private readonly headers;
|
|
10
12
|
readonly apiKeys: ApiKeys;
|
|
13
|
+
readonly audiences: Audiences;
|
|
14
|
+
readonly batch: Batch;
|
|
15
|
+
readonly contacts: Contacts;
|
|
11
16
|
readonly domains: Domains;
|
|
12
17
|
readonly emails: Emails;
|
|
13
|
-
readonly batch: Batch;
|
|
14
18
|
constructor(key?: string | undefined);
|
|
15
19
|
fetchRequest<T>(path: string, options?: {}): Promise<{
|
|
16
20
|
data: T | null;
|
package/build/src/resend.js
CHANGED
|
@@ -12,7 +12,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.Resend = void 0;
|
|
13
13
|
const package_json_1 = require("../package.json");
|
|
14
14
|
const api_keys_1 = require("./api-keys/api-keys");
|
|
15
|
+
const audiences_1 = require("./audiences/audiences");
|
|
15
16
|
const batch_1 = require("./batch/batch");
|
|
17
|
+
const contacts_1 = require("./contacts/contacts");
|
|
16
18
|
const domains_1 = require("./domains/domains");
|
|
17
19
|
const emails_1 = require("./emails/emails");
|
|
18
20
|
const guards_1 = require("./guards");
|
|
@@ -22,9 +24,11 @@ class Resend {
|
|
|
22
24
|
constructor(key) {
|
|
23
25
|
this.key = key;
|
|
24
26
|
this.apiKeys = new api_keys_1.ApiKeys(this);
|
|
27
|
+
this.audiences = new audiences_1.Audiences(this);
|
|
28
|
+
this.batch = new batch_1.Batch(this);
|
|
29
|
+
this.contacts = new contacts_1.Contacts(this);
|
|
25
30
|
this.domains = new domains_1.Domains(this);
|
|
26
31
|
this.emails = new emails_1.Emails(this);
|
|
27
|
-
this.batch = new batch_1.Batch(this);
|
|
28
32
|
if (!key) {
|
|
29
33
|
this.key = process.env.RESEND_API_KEY;
|
|
30
34
|
if (!this.key) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resend",
|
|
3
|
-
"version": "2.0.0",
|
|
3
|
+
"version": "2.1.0-canary.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",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"@types/jest": "29.5.7",
|
|
38
38
|
"@types/node": "18.18.8",
|
|
39
39
|
"@types/react": "18.2.33",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
41
|
-
"@typescript-eslint/parser": "6.
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "6.10.0",
|
|
41
|
+
"@typescript-eslint/parser": "6.10.0",
|
|
42
42
|
"eslint": "8.52.0",
|
|
43
43
|
"jest": "29.7.0",
|
|
44
44
|
"jest-fetch-mock": "3.0.3",
|