mailgun.js 3.7.0 → 4.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.
- package/CHANGELOG.md +31 -0
- package/README.md +335 -1
- package/dist/index.d.ts +2 -2
- package/dist/lib/client.d.ts +2 -6
- package/dist/lib/domains.d.ts +19 -13
- package/dist/lib/domainsCredentials.d.ts +14 -0
- package/dist/lib/events.d.ts +3 -3
- package/dist/lib/interfaces/DomainCredentials.d.ts +52 -0
- package/dist/lib/interfaces/DomainTracking.d.ts +4 -4
- package/dist/lib/interfaces/Domains.d.ts +53 -3
- package/dist/lib/interfaces/Events.d.ts +66 -2
- package/dist/lib/interfaces/IFormData.d.ts +4 -12
- package/dist/lib/interfaces/MultipleValidation.d.ts +55 -0
- package/dist/lib/interfaces/Validate.d.ts +12 -0
- package/dist/lib/interfaces/Webhooks.d.ts +5 -1
- package/dist/lib/interfaces/lists.d.ts +1 -1
- package/dist/lib/multipleValidation.d.ts +10 -0
- package/dist/lib/parse.d.ts +0 -6
- package/dist/lib/request.d.ts +4 -3
- package/dist/lib/validate.d.ts +5 -2
- package/dist/lib/webhooks.d.ts +3 -3
- package/dist/mailgun.node.js +2 -2
- package/dist/mailgun.node.js.LICENSE.txt +1 -1
- package/dist/mailgun.web.js +2 -2
- package/dist/mailgun.web.js.LICENSE.txt +1 -1
- package/index.ts +3 -3
- package/lib/client.ts +8 -14
- package/lib/domains.ts +82 -26
- package/lib/domainsCredentials.ts +88 -0
- package/lib/events.ts +6 -6
- package/lib/interfaces/DomainCredentials.ts +68 -0
- package/lib/interfaces/DomainTracking.ts +4 -4
- package/lib/interfaces/Domains.ts +65 -4
- package/lib/interfaces/Events.ts +66 -2
- package/lib/interfaces/IFormData.ts +5 -15
- package/lib/interfaces/MultipleValidation.ts +62 -0
- package/lib/interfaces/Validate.ts +15 -0
- package/lib/interfaces/Webhooks.ts +6 -1
- package/lib/interfaces/lists.ts +1 -1
- package/lib/multipleValidation.ts +37 -0
- package/lib/request.ts +28 -10
- package/lib/validate.ts +10 -4
- package/lib/webhooks.ts +19 -10
- package/package.json +7 -8
- package/test/client.test.ts +25 -8
- package/test/data/emailsValidation1.csv +3 -0
- package/test/domains.test.ts +119 -15
- package/test/domainsCredentials.test.ts +97 -0
- package/test/events.test.ts +17 -25
- package/test/ips.test.ts +2 -1
- package/test/lists.test.ts +2 -1
- package/test/mailListMembers.test.ts +2 -1
- package/test/messageAttachment.test.ts +2 -1
- package/test/messages.test.ts +2 -1
- package/test/multipleValidation.test.ts +159 -0
- package/test/request.test.ts +6 -5
- package/test/routes.test.ts +2 -1
- package/test/stats.test.ts +2 -1
- package/test/suppressions.test.ts +2 -1
- package/test/validate.test.ts +8 -4
- package/test/webhooks.test.ts +8 -7
- package/webpack/webpack.dev.config.js +10 -0
- package/lib/parse.ts +0 -27
- package/test/parse.test.ts +0 -74
package/test/domains.test.ts
CHANGED
|
@@ -3,16 +3,27 @@ import formData from 'form-data';
|
|
|
3
3
|
import nock from 'nock';
|
|
4
4
|
import { expect } from 'chai';
|
|
5
5
|
import Request from '../lib/request';
|
|
6
|
-
import DomainClient from '../lib/domains';
|
|
6
|
+
import DomainClient, { Domain } from '../lib/domains';
|
|
7
7
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
8
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
9
|
+
import DomainCredentialsClient from '../lib/domainsCredentials';
|
|
10
|
+
import {
|
|
11
|
+
ConnectionSettings,
|
|
12
|
+
MessageResponse,
|
|
13
|
+
UpdatedConnectionSettings,
|
|
14
|
+
UpdatedDKIMAuthority,
|
|
15
|
+
UpdatedDKIMSelectorResponse, UpdatedWebPrefixResponse
|
|
16
|
+
} from '../lib/interfaces/Domains';
|
|
8
17
|
|
|
9
18
|
// TODO: fix types
|
|
10
19
|
describe('DomainClient', function () {
|
|
11
|
-
let client:
|
|
12
|
-
let api:
|
|
20
|
+
let client: DomainClient;
|
|
21
|
+
let api: nock.Scope;
|
|
13
22
|
|
|
14
23
|
beforeEach(function () {
|
|
15
|
-
|
|
24
|
+
const reqObject = new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData);
|
|
25
|
+
const domainCredentialsClient = new DomainCredentialsClient(reqObject);
|
|
26
|
+
client = new DomainClient(reqObject, domainCredentialsClient);
|
|
16
27
|
api = nock('https://api.mailgun.net');
|
|
17
28
|
});
|
|
18
29
|
|
|
@@ -35,11 +46,11 @@ describe('DomainClient', function () {
|
|
|
35
46
|
require_tls: true
|
|
36
47
|
}];
|
|
37
48
|
|
|
38
|
-
api.get('/
|
|
49
|
+
api.get('/v3/domains').reply(200, {
|
|
39
50
|
items: domains
|
|
40
51
|
});
|
|
41
52
|
|
|
42
|
-
return client.list().then(function (dm:
|
|
53
|
+
return client.list().then(function (dm: Domain[]) {
|
|
43
54
|
dm[0].should.eql({
|
|
44
55
|
created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
|
|
45
56
|
name: 'testing.example.com',
|
|
@@ -73,13 +84,13 @@ describe('DomainClient', function () {
|
|
|
73
84
|
require_tls: true
|
|
74
85
|
};
|
|
75
86
|
|
|
76
|
-
api.get('/
|
|
87
|
+
api.get('/v3/domains/testing.example.com').reply(200, {
|
|
77
88
|
domain: domainData,
|
|
78
89
|
receiving_dns_records: [],
|
|
79
90
|
sending_dns_records: []
|
|
80
91
|
});
|
|
81
92
|
|
|
82
|
-
return client.get('testing.example.com').then(function (domain:
|
|
93
|
+
return client.get('testing.example.com').then(function (domain: Domain) {
|
|
83
94
|
domain.should.eql({
|
|
84
95
|
created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
|
|
85
96
|
name: 'testing.example.com',
|
|
@@ -113,13 +124,17 @@ describe('DomainClient', function () {
|
|
|
113
124
|
require_tls: true
|
|
114
125
|
};
|
|
115
126
|
|
|
116
|
-
api.post('/
|
|
127
|
+
api.post('/v3/domains').reply(200, {
|
|
117
128
|
domain: domainData,
|
|
118
129
|
receiving_dns_records: [],
|
|
119
130
|
sending_dns_records: []
|
|
120
131
|
});
|
|
121
132
|
|
|
122
|
-
return client.create({
|
|
133
|
+
return client.create({
|
|
134
|
+
name: 'another.example.com',
|
|
135
|
+
smtp_password: 'smtp_password',
|
|
136
|
+
web_scheme: 'https'
|
|
137
|
+
}).then(function (domain: Domain) {
|
|
123
138
|
domain.should.eql({
|
|
124
139
|
created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
|
|
125
140
|
name: 'another.example.com',
|
|
@@ -140,11 +155,11 @@ describe('DomainClient', function () {
|
|
|
140
155
|
|
|
141
156
|
describe('destroy', function () {
|
|
142
157
|
it('deletes a domain', function () {
|
|
143
|
-
api.delete('/
|
|
158
|
+
api.delete('/v3/domains/test.example.com').reply(200, {
|
|
144
159
|
message: 'domain deleted'
|
|
145
160
|
});
|
|
146
161
|
|
|
147
|
-
return client.destroy('test.example.com').then(function (data:
|
|
162
|
+
return client.destroy('test.example.com').then(function (data: MessageResponse) {
|
|
148
163
|
data.should.eql({
|
|
149
164
|
message: 'domain deleted'
|
|
150
165
|
});
|
|
@@ -152,9 +167,46 @@ describe('DomainClient', function () {
|
|
|
152
167
|
});
|
|
153
168
|
});
|
|
154
169
|
|
|
170
|
+
describe('getConnection', function () {
|
|
171
|
+
it('returns connection settings for the defined domain', function () {
|
|
172
|
+
api.get('/v3/domains/test.example.com/connection').reply(200, {
|
|
173
|
+
connection: { require_tls: false, skip_verification: false }
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
return client.getConnection('test.example.com').then(function (data: ConnectionSettings) {
|
|
177
|
+
data.should.eql({ require_tls: false, skip_verification: false });
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe('updateConnection', function () {
|
|
183
|
+
it('Updates the connection settings for the defined domain.', function () {
|
|
184
|
+
api.put('/v3/domains/test.example.com/connection').reply(200, {
|
|
185
|
+
connection: {
|
|
186
|
+
message: 'Domain connection settings have been updated, may take 10 minutes to fully propagate',
|
|
187
|
+
require_tls: false,
|
|
188
|
+
skip_verification: false
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
return client.updateConnection('test.example.com', {
|
|
193
|
+
require_tls: true,
|
|
194
|
+
skip_verification: true
|
|
195
|
+
}).then(function (data: UpdatedConnectionSettings) {
|
|
196
|
+
data.should.eql({
|
|
197
|
+
connection: {
|
|
198
|
+
message: 'Domain connection settings have been updated, may take 10 minutes to fully propagate',
|
|
199
|
+
require_tls: false,
|
|
200
|
+
skip_verification: false
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
155
207
|
describe('getTracking', function () {
|
|
156
208
|
it('fetches all tracking settings', function () {
|
|
157
|
-
api.get('/
|
|
209
|
+
api.get('/v3/domains/domain.com/tracking').reply(200, {
|
|
158
210
|
tracking: {
|
|
159
211
|
open: { active: true },
|
|
160
212
|
click: { active: true },
|
|
@@ -171,7 +223,7 @@ describe('DomainClient', function () {
|
|
|
171
223
|
describe('updateTracking', function () {
|
|
172
224
|
it('updates tracking settings', async function () {
|
|
173
225
|
const open = { active: true };
|
|
174
|
-
api.put('/
|
|
226
|
+
api.put('/v3/domains/domain.com/tracking/open').reply(200, {
|
|
175
227
|
message: 'Tracking settings have been updated',
|
|
176
228
|
open
|
|
177
229
|
});
|
|
@@ -190,11 +242,63 @@ describe('DomainClient', function () {
|
|
|
190
242
|
describe('getIps', () => {
|
|
191
243
|
it('should return list of dedicated ips', () => {
|
|
192
244
|
const items = ['192.161.0.1', '192.168.0.2'];
|
|
193
|
-
api.get('/
|
|
245
|
+
api.get('/v3/domains/domain.com/ips').reply(200, { items });
|
|
194
246
|
|
|
195
247
|
return client.getIps('domain.com').then((response: string[]) => {
|
|
196
248
|
response.should.eql(items);
|
|
197
249
|
});
|
|
198
250
|
});
|
|
199
251
|
});
|
|
252
|
+
|
|
253
|
+
describe('updateDKIMAuthority', () => {
|
|
254
|
+
it('changes the DKIM authority for a domain.', () => {
|
|
255
|
+
const expectedRes = {
|
|
256
|
+
changed: true,
|
|
257
|
+
message: 'Domain DKIM authority has been changed',
|
|
258
|
+
sending_dns_records: [
|
|
259
|
+
{
|
|
260
|
+
cached: ['a'],
|
|
261
|
+
name: 'test.example.com',
|
|
262
|
+
record_type: 'record_type',
|
|
263
|
+
valid: 'valid',
|
|
264
|
+
value: 'value'
|
|
265
|
+
}
|
|
266
|
+
]
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
api.put('/v3/domains/test.example.com/dkim_authority?self=true').reply(200, expectedRes);
|
|
270
|
+
|
|
271
|
+
return client.updateDKIMAuthority('test.example.com', { self: 'true' }).then((response: UpdatedDKIMAuthority) => {
|
|
272
|
+
response.should.eql(expectedRes);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
describe('updateDKIMSelector', () => {
|
|
278
|
+
it('updates the DKIM selector for a domains', () => {
|
|
279
|
+
api.put('/v3/domains/test.example.com/dkim_selector?dkim_selector=dkim_selector_value').reply(200, { message: 'Domain DKIM selector updated' });
|
|
280
|
+
|
|
281
|
+
return client.updateDKIMSelector('test.example.com', { dkimSelector: 'dkim_selector_value' }).then((response: UpdatedDKIMSelectorResponse) => {
|
|
282
|
+
response.should.eql(
|
|
283
|
+
{
|
|
284
|
+
body: { message: 'Domain DKIM selector updated' }, status: 200
|
|
285
|
+
}
|
|
286
|
+
);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
describe('updateWebPrefix', () => {
|
|
292
|
+
it('Update the CNAME used for tracking opens and clicks', () => {
|
|
293
|
+
api.put('/v3/domains/test.example.com/web_prefix?web_prefix=webprefixvalue').reply(200, { message: 'Domain web prefix updated' });
|
|
294
|
+
|
|
295
|
+
return client.updateWebPrefix('test.example.com', { webPrefix: 'webprefixvalue' }).then((response: UpdatedWebPrefixResponse) => {
|
|
296
|
+
response.should.eql(
|
|
297
|
+
{
|
|
298
|
+
body: { message: 'Domain web prefix updated' }, status: 200
|
|
299
|
+
}
|
|
300
|
+
);
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
});
|
|
200
304
|
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import formData from 'form-data';
|
|
2
|
+
|
|
3
|
+
import nock from 'nock';
|
|
4
|
+
import Request from '../lib/request';
|
|
5
|
+
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
6
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
7
|
+
import DomainCredentialsClient from '../lib/domainsCredentials';
|
|
8
|
+
import { DomainCredentialsList, DomainCredentialsResult } from '../lib/interfaces/DomainCredentials';
|
|
9
|
+
|
|
10
|
+
// TODO: fix types
|
|
11
|
+
describe('DomainsCredentialsClient', function () {
|
|
12
|
+
let client: DomainCredentialsClient;
|
|
13
|
+
let api: nock.Scope;
|
|
14
|
+
|
|
15
|
+
beforeEach(function () {
|
|
16
|
+
const reqObject = new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData);
|
|
17
|
+
client = new DomainCredentialsClient(reqObject);
|
|
18
|
+
api = nock('https://api.mailgun.net');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(function () {
|
|
22
|
+
api.done();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('list', function () {
|
|
26
|
+
it('fetches all domain credentials', function () {
|
|
27
|
+
api.get('/v3/domains/testDomain/credentials').reply(200, {
|
|
28
|
+
items: [{
|
|
29
|
+
created_at: 'Mon, 11 Oct 2021 17:30:06 -0000',
|
|
30
|
+
login: 'testLogin@testing.example.com',
|
|
31
|
+
mailbox: 'test@testing.example.com',
|
|
32
|
+
size_bytes: null
|
|
33
|
+
}],
|
|
34
|
+
total_count: 1
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return client.list('testDomain').then(function (credentialsList: DomainCredentialsList) {
|
|
38
|
+
credentialsList.should.be.an('object').to.have.property('items');
|
|
39
|
+
credentialsList.items.should.be.an('array').to.have.property('length').to.be.equal(1);
|
|
40
|
+
credentialsList.items[0].should.eql({
|
|
41
|
+
created_at: 'Mon, 11 Oct 2021 17:30:06 -0000',
|
|
42
|
+
login: 'testLogin@testing.example.com',
|
|
43
|
+
mailbox: 'test@testing.example.com',
|
|
44
|
+
size_bytes: null
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('create', function () {
|
|
51
|
+
it('creates domain credentials', function () {
|
|
52
|
+
const domainCredentialsData = {
|
|
53
|
+
login: 'testLogin',
|
|
54
|
+
password: 'testPassword'
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
api.post('/v3/domains/testDomain/credentials').reply(200, {
|
|
58
|
+
message: 'Created 1 credentials pair(s)'
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return client.create('testDomain', domainCredentialsData).then(function (res: DomainCredentialsResult) {
|
|
62
|
+
res.should.eql({ message: 'Created 1 credentials pair(s)', status: 200 });
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('update', function () {
|
|
68
|
+
it('updates domain credentials', function () {
|
|
69
|
+
api.put('/v3/domains/testDomain/credentials/testLogin').reply(200, {
|
|
70
|
+
message: 'Password changed'
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return client.update('testDomain', 'testLogin', {
|
|
74
|
+
password: 'testPassword1'
|
|
75
|
+
}).then(function (res: DomainCredentialsResult) {
|
|
76
|
+
res.should.eql({ message: 'Password changed', status: 200 });
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('destroy', function () {
|
|
82
|
+
it('deletes a domain credentials', function () {
|
|
83
|
+
api.delete('/v3/domains/testDomain/credentials/testLogin').reply(200, {
|
|
84
|
+
message: 'domain deleted',
|
|
85
|
+
spec: 'testDomain'
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return client.destroy('testDomain', 'testLogin').then(function (data: DomainCredentialsResult) {
|
|
89
|
+
data.should.eql({
|
|
90
|
+
message: 'domain deleted',
|
|
91
|
+
spec: 'testDomain',
|
|
92
|
+
status: 200
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
package/test/events.test.ts
CHANGED
|
@@ -4,13 +4,15 @@ import formData from 'form-data';
|
|
|
4
4
|
import EventClient from '../lib/events';
|
|
5
5
|
import MgRequest from '../lib/request';
|
|
6
6
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
7
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
8
|
+
import { EventsList, EventsResponse } from '../lib/interfaces/Events';
|
|
7
9
|
|
|
8
10
|
describe('EventsClient', function () {
|
|
9
|
-
let client:
|
|
10
|
-
let api:
|
|
11
|
+
let client: EventClient;
|
|
12
|
+
let api: nock.Scope;
|
|
11
13
|
|
|
12
14
|
beforeEach(function () {
|
|
13
|
-
client = new EventClient(new MgRequest({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
|
|
15
|
+
client = new EventClient(new MgRequest({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
|
|
14
16
|
api = nock('https://api.mailgun.net');
|
|
15
17
|
});
|
|
16
18
|
|
|
@@ -25,14 +27,12 @@ describe('EventsClient', function () {
|
|
|
25
27
|
response = {
|
|
26
28
|
items: [
|
|
27
29
|
{
|
|
28
|
-
|
|
30
|
+
event: 'accepted',
|
|
29
31
|
timestamp: 'Wed, 19 Nov 2014 18:32:57 GMT',
|
|
30
|
-
gist: 'got it',
|
|
31
32
|
content: { more: 'data' }
|
|
32
33
|
}, {
|
|
33
|
-
|
|
34
|
+
event: 'opened',
|
|
34
35
|
timestamp: 'Tue, 18 Nov 2014 12:32:57 GMT',
|
|
35
|
-
gist: 'sent',
|
|
36
36
|
content: { more: 'data' }
|
|
37
37
|
}
|
|
38
38
|
],
|
|
@@ -46,49 +46,41 @@ describe('EventsClient', function () {
|
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
it('fetches all events', function () {
|
|
49
|
-
api.get('/
|
|
49
|
+
api.get('/v3/domain.com/events').reply(200, response);
|
|
50
50
|
|
|
51
|
-
return client.get('domain.com').then(function (data:
|
|
51
|
+
return client.get('domain.com').then(function (data: EventsList) {
|
|
52
52
|
let e;
|
|
53
53
|
|
|
54
54
|
e = data.items[0];
|
|
55
|
-
e.
|
|
56
|
-
e.gist.should.eql('got it');
|
|
55
|
+
e.event.should.eql('accepted');
|
|
57
56
|
e.timestamp.should.eql('Wed, 19 Nov 2014 18:32:57 GMT');
|
|
58
|
-
e.content.should.eql({ more: 'data' });
|
|
59
57
|
|
|
60
58
|
e = data.items[1];
|
|
61
|
-
e.
|
|
62
|
-
e.gist.should.eql('sent');
|
|
59
|
+
e.event.should.eql('opened');
|
|
63
60
|
e.timestamp.should.eql('Tue, 18 Nov 2014 12:32:57 GMT');
|
|
64
|
-
e.content.should.eql({ more: 'data' });
|
|
65
61
|
});
|
|
66
62
|
});
|
|
67
63
|
|
|
68
64
|
it('fetches single page', function () {
|
|
69
|
-
api.get('/
|
|
65
|
+
api.get('/v3/domain.com/events/pageId').reply(200, response);
|
|
70
66
|
|
|
71
|
-
return client.get('domain.com', { page: 'pageId' }).then(function (data:
|
|
67
|
+
return client.get('domain.com', { page: 'pageId' }).then(function (data: EventsList) {
|
|
72
68
|
let e;
|
|
73
69
|
|
|
74
70
|
e = data.items[0];
|
|
75
|
-
e.
|
|
76
|
-
e.gist.should.eql('got it');
|
|
71
|
+
e.event.should.eql('accepted');
|
|
77
72
|
e.timestamp.should.eql('Wed, 19 Nov 2014 18:32:57 GMT');
|
|
78
|
-
e.content.should.eql({ more: 'data' });
|
|
79
73
|
|
|
80
74
|
e = data.items[1];
|
|
81
|
-
e.
|
|
82
|
-
e.gist.should.eql('sent');
|
|
75
|
+
e.event.should.eql('opened');
|
|
83
76
|
e.timestamp.should.eql('Tue, 18 Nov 2014 12:32:57 GMT');
|
|
84
|
-
e.content.should.eql({ more: 'data' });
|
|
85
77
|
});
|
|
86
78
|
});
|
|
87
79
|
|
|
88
80
|
it('parses page links', function () {
|
|
89
|
-
api.get('/
|
|
81
|
+
api.get('/v3/domain.com/events').reply(200, response);
|
|
90
82
|
|
|
91
|
-
return client.get('domain.com').then(function (data:
|
|
83
|
+
return client.get('domain.com').then(function (data: EventsList) {
|
|
92
84
|
let page;
|
|
93
85
|
|
|
94
86
|
page = data.pages.first;
|
package/test/ips.test.ts
CHANGED
|
@@ -7,6 +7,7 @@ import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
|
7
7
|
import IpsClient from '../lib/ips';
|
|
8
8
|
|
|
9
9
|
import { IpData, IpsListResponseBody } from '../lib/interfaces/Ips';
|
|
10
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
10
11
|
|
|
11
12
|
// TODO: fix types
|
|
12
13
|
describe('DomainClient', function () {
|
|
@@ -14,7 +15,7 @@ describe('DomainClient', function () {
|
|
|
14
15
|
let api: any;
|
|
15
16
|
|
|
16
17
|
beforeEach(function () {
|
|
17
|
-
client = new IpsClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
|
|
18
|
+
client = new IpsClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
|
|
18
19
|
api = nock('https://api.mailgun.net');
|
|
19
20
|
});
|
|
20
21
|
|
package/test/lists.test.ts
CHANGED
|
@@ -6,6 +6,7 @@ import ListsClient from '../lib/lists';
|
|
|
6
6
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
7
7
|
import MailListMembers from '../lib/mailListMembers';
|
|
8
8
|
import { MailingList } from '../lib/interfaces/lists';
|
|
9
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
9
10
|
|
|
10
11
|
describe('ListsClient', function () {
|
|
11
12
|
let client: any;
|
|
@@ -13,7 +14,7 @@ describe('ListsClient', function () {
|
|
|
13
14
|
let defaultList : MailingList;
|
|
14
15
|
|
|
15
16
|
beforeEach(function () {
|
|
16
|
-
const reqObject = new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData);
|
|
17
|
+
const reqObject = new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData);
|
|
17
18
|
const mailListMembers = new MailListMembers(reqObject);
|
|
18
19
|
client = new ListsClient(reqObject, mailListMembers);
|
|
19
20
|
api = nock('https://api.mailgun.net');
|
|
@@ -4,6 +4,7 @@ import Request from '../lib/request';
|
|
|
4
4
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
5
5
|
import MailListMembers from '../lib/mailListMembers';
|
|
6
6
|
import { DeletedMember, MailListMember, NewMultipleMembersResponse } from '../lib/interfaces/mailListMembers';
|
|
7
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
7
8
|
|
|
8
9
|
describe('mailListsMembersClient', function () {
|
|
9
10
|
let client: any;
|
|
@@ -11,7 +12,7 @@ describe('mailListsMembersClient', function () {
|
|
|
11
12
|
let defaultListMember : MailListMember;
|
|
12
13
|
|
|
13
14
|
beforeEach(function () {
|
|
14
|
-
const reqObject = new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData);
|
|
15
|
+
const reqObject = new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData);
|
|
15
16
|
client = new MailListMembers(reqObject);
|
|
16
17
|
api = nock('https://api.mailgun.net');
|
|
17
18
|
defaultListMember = {
|
|
@@ -6,6 +6,7 @@ import formData from 'form-data';
|
|
|
6
6
|
import Request from '../lib/request';
|
|
7
7
|
import MessagesClient from '../lib/messages';
|
|
8
8
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
9
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
9
10
|
|
|
10
11
|
const mailgunLogo = fs.createReadStream(`${__dirname}/img/mailgun.png`);
|
|
11
12
|
|
|
@@ -14,7 +15,7 @@ describe('MessagesClient', function () {
|
|
|
14
15
|
let api: any;
|
|
15
16
|
|
|
16
17
|
beforeEach(function () {
|
|
17
|
-
client = new MessagesClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
|
|
18
|
+
client = new MessagesClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
|
|
18
19
|
api = nock('https://api.mailgun.net');
|
|
19
20
|
});
|
|
20
21
|
|
package/test/messages.test.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { expect } from 'chai';
|
|
|
7
7
|
import Request from '../lib/request';
|
|
8
8
|
import MessagesClient from '../lib/messages';
|
|
9
9
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
10
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
10
11
|
|
|
11
12
|
const mailgunLogo = fs.createReadStream(`${__dirname}/img/mailgun.png`);
|
|
12
13
|
|
|
@@ -15,7 +16,7 @@ describe('MessagesClient', function () {
|
|
|
15
16
|
let api: any;
|
|
16
17
|
|
|
17
18
|
beforeEach(function () {
|
|
18
|
-
client = new MessagesClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
|
|
19
|
+
client = new MessagesClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
|
|
19
20
|
api = nock('https://api.mailgun.net');
|
|
20
21
|
});
|
|
21
22
|
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import formData from 'form-data';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
import nock from 'nock';
|
|
6
|
+
import Request from '../lib/request';
|
|
7
|
+
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
8
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
9
|
+
import MultipleValidationClient from '../lib/multipleValidation';
|
|
10
|
+
import {
|
|
11
|
+
CanceledMultipleValidationJob,
|
|
12
|
+
CreatedMultipleValidationJob,
|
|
13
|
+
MultipleValidationJob,
|
|
14
|
+
MultipleValidationJobsListResult
|
|
15
|
+
} from '../lib/interfaces/MultipleValidation';
|
|
16
|
+
|
|
17
|
+
const filepath = path.resolve(__dirname, './data/emailsValidation1.csv');
|
|
18
|
+
|
|
19
|
+
describe('ValidateClient', function () {
|
|
20
|
+
const fsPromises = fs.promises;
|
|
21
|
+
let client: MultipleValidationClient;
|
|
22
|
+
let api: nock.Scope;
|
|
23
|
+
|
|
24
|
+
beforeEach(function () {
|
|
25
|
+
const reqObject = new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData);
|
|
26
|
+
client = new MultipleValidationClient(reqObject);
|
|
27
|
+
api = nock('https://api.mailgun.net');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
afterEach(function () {
|
|
31
|
+
api.done();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('List', function () {
|
|
35
|
+
it('should provide list of all bulk validation jobs', function () {
|
|
36
|
+
const data = {
|
|
37
|
+
jobs: [
|
|
38
|
+
{
|
|
39
|
+
created_at: 1636716764,
|
|
40
|
+
download_url: {
|
|
41
|
+
csv: 'csv-url',
|
|
42
|
+
json: 'json-url'
|
|
43
|
+
},
|
|
44
|
+
id: 'testValidationList',
|
|
45
|
+
quantity: 40,
|
|
46
|
+
records_processed: 40,
|
|
47
|
+
status: 'uploaded',
|
|
48
|
+
summary: {
|
|
49
|
+
result: {
|
|
50
|
+
catch_all: 0,
|
|
51
|
+
deliverable: 2,
|
|
52
|
+
do_not_send: 0,
|
|
53
|
+
undeliverable: 16,
|
|
54
|
+
unknown: 22
|
|
55
|
+
},
|
|
56
|
+
risk: {
|
|
57
|
+
high: 16,
|
|
58
|
+
low: 2,
|
|
59
|
+
medium: 0,
|
|
60
|
+
unknown: 22
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
paging: {
|
|
66
|
+
first: 'https://api.mailgun.net/v4/address/validate/bulk?limit=100&page=first&pivot=',
|
|
67
|
+
last: 'https://api.mailgun.net/v4/address/validate/bulk?limit=100&page=last&pivot=',
|
|
68
|
+
next: 'https://api.mailgun.net/v4/address/validate/bulk?limit=100&page=next&pivot=',
|
|
69
|
+
prev: 'https://api.mailgun.net/v4/address/validate/bulk?limit=100&page=prev&pivot='
|
|
70
|
+
},
|
|
71
|
+
total: 1
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
api.get('/v4/address/validate/bulk')
|
|
75
|
+
.reply(200, data);
|
|
76
|
+
|
|
77
|
+
return client.list().then(function (response: MultipleValidationJobsListResult) {
|
|
78
|
+
response.should.eql(data);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('get', function () {
|
|
84
|
+
it('should returns status of a bulk validation job.', function () {
|
|
85
|
+
const listId = 'testValidationList';
|
|
86
|
+
const data = {
|
|
87
|
+
created_at: 1636716764,
|
|
88
|
+
download_url: {
|
|
89
|
+
csv: 'csv-url',
|
|
90
|
+
json: 'json-url'
|
|
91
|
+
},
|
|
92
|
+
id: listId,
|
|
93
|
+
quantity: 40,
|
|
94
|
+
records_processed: 40,
|
|
95
|
+
status: 'uploaded',
|
|
96
|
+
summary: {
|
|
97
|
+
result: {
|
|
98
|
+
catch_all: 0,
|
|
99
|
+
deliverable: 2,
|
|
100
|
+
do_not_send: 0,
|
|
101
|
+
undeliverable: 16,
|
|
102
|
+
unknown: 22
|
|
103
|
+
},
|
|
104
|
+
risk: {
|
|
105
|
+
high: 16,
|
|
106
|
+
low: 2,
|
|
107
|
+
medium: 0,
|
|
108
|
+
unknown: 22
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
api.get(`/v4/address/validate/bulk/${listId}`)
|
|
114
|
+
.reply(200, data);
|
|
115
|
+
|
|
116
|
+
return client.get(listId).then(function (response: MultipleValidationJob) {
|
|
117
|
+
response.should.eql(data);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('create', function () {
|
|
123
|
+
it('Creates a bulk validation job.', async function () {
|
|
124
|
+
const listId = 'testValidationList';
|
|
125
|
+
const data = {
|
|
126
|
+
id: 'testValidationList',
|
|
127
|
+
message: 'The validation job was submitted.'
|
|
128
|
+
};
|
|
129
|
+
const file = {
|
|
130
|
+
filename: 'test.jpg',
|
|
131
|
+
data: await fsPromises.readFile(filepath)
|
|
132
|
+
};
|
|
133
|
+
api.post(`/v4/address/validate/bulk/${listId}`)
|
|
134
|
+
.reply(200, data);
|
|
135
|
+
|
|
136
|
+
return client.create(listId, { file })
|
|
137
|
+
.then(function (response: CreatedMultipleValidationJob) {
|
|
138
|
+
response.should.eql(data);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe('destroy', function () {
|
|
144
|
+
it('should cancel current running bulk validation job.', async function () {
|
|
145
|
+
const listId = 'testValidationList';
|
|
146
|
+
const data = {
|
|
147
|
+
body: { message: 'Validation job canceled.' },
|
|
148
|
+
status: 200
|
|
149
|
+
};
|
|
150
|
+
api.delete(`/v4/address/validate/bulk/${listId}`)
|
|
151
|
+
.reply(200, { message: 'Validation job canceled.' });
|
|
152
|
+
|
|
153
|
+
return client.destroy(listId)
|
|
154
|
+
.then(function (response: CanceledMultipleValidationJob) {
|
|
155
|
+
response.should.eql(data);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
});
|