mailgun.js 3.7.2 → 4.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +2 -2
  3. package/dist/lib/client.d.ts +0 -4
  4. package/dist/lib/domains.d.ts +19 -13
  5. package/dist/lib/domainsCredentials.d.ts +14 -0
  6. package/dist/lib/events.d.ts +3 -3
  7. package/dist/lib/interfaces/DomainCredentials.d.ts +52 -0
  8. package/dist/lib/interfaces/DomainTracking.d.ts +4 -4
  9. package/dist/lib/interfaces/Domains.d.ts +53 -3
  10. package/dist/lib/interfaces/Events.d.ts +66 -2
  11. package/dist/lib/interfaces/MultipleValidation.d.ts +55 -0
  12. package/dist/lib/interfaces/Supressions.d.ts +6 -0
  13. package/dist/lib/interfaces/Validate.d.ts +12 -0
  14. package/dist/lib/interfaces/Webhooks.d.ts +5 -1
  15. package/dist/lib/multipleValidation.d.ts +10 -0
  16. package/dist/lib/parse.d.ts +0 -6
  17. package/dist/lib/request.d.ts +4 -1
  18. package/dist/lib/suppressions.d.ts +12 -3
  19. package/dist/lib/validate.d.ts +5 -2
  20. package/dist/lib/webhooks.d.ts +3 -3
  21. package/dist/mailgun.node.js +2 -2
  22. package/dist/mailgun.node.js.LICENSE.txt +1 -1
  23. package/dist/mailgun.web.js +2 -2
  24. package/dist/mailgun.web.js.LICENSE.txt +1 -1
  25. package/lib/client.ts +6 -12
  26. package/lib/domains.ts +82 -26
  27. package/lib/domainsCredentials.ts +88 -0
  28. package/lib/events.ts +6 -6
  29. package/lib/interfaces/DomainCredentials.ts +68 -0
  30. package/lib/interfaces/DomainTracking.ts +4 -4
  31. package/lib/interfaces/Domains.ts +65 -4
  32. package/lib/interfaces/Events.ts +66 -2
  33. package/lib/interfaces/MultipleValidation.ts +62 -0
  34. package/lib/interfaces/Supressions.ts +7 -0
  35. package/lib/interfaces/Validate.ts +15 -0
  36. package/lib/interfaces/Webhooks.ts +6 -1
  37. package/lib/multipleValidation.ts +37 -0
  38. package/lib/request.ts +75 -34
  39. package/lib/suppressions.ts +36 -5
  40. package/lib/validate.ts +10 -4
  41. package/lib/webhooks.ts +19 -10
  42. package/package.json +6 -6
  43. package/test/client.test.ts +21 -5
  44. package/test/data/emailsValidation1.csv +3 -0
  45. package/test/domains.test.ts +118 -15
  46. package/test/domainsCredentials.test.ts +97 -0
  47. package/test/events.test.ts +15 -24
  48. package/test/multipleValidation.test.ts +159 -0
  49. package/test/validate.test.ts +7 -4
  50. package/test/webhooks.test.ts +6 -6
  51. package/webpack/webpack.dev.config.js +10 -0
  52. package/lib/parse.ts +0 -27
  53. package/test/parse.test.ts +0 -75
@@ -3,17 +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
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';
9
17
 
10
18
  // TODO: fix types
11
19
  describe('DomainClient', function () {
12
- let client: any;
13
- let api: any;
20
+ let client: DomainClient;
21
+ let api: nock.Scope;
14
22
 
15
23
  beforeEach(function () {
16
- client = new DomainClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
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);
17
27
  api = nock('https://api.mailgun.net');
18
28
  });
19
29
 
@@ -36,11 +46,11 @@ describe('DomainClient', function () {
36
46
  require_tls: true
37
47
  }];
38
48
 
39
- api.get('/v2/domains').reply(200, {
49
+ api.get('/v3/domains').reply(200, {
40
50
  items: domains
41
51
  });
42
52
 
43
- return client.list().then(function (dm: any[]) {
53
+ return client.list().then(function (dm: Domain[]) {
44
54
  dm[0].should.eql({
45
55
  created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
46
56
  name: 'testing.example.com',
@@ -74,13 +84,13 @@ describe('DomainClient', function () {
74
84
  require_tls: true
75
85
  };
76
86
 
77
- api.get('/v2/domains/testing.example.com').reply(200, {
87
+ api.get('/v3/domains/testing.example.com').reply(200, {
78
88
  domain: domainData,
79
89
  receiving_dns_records: [],
80
90
  sending_dns_records: []
81
91
  });
82
92
 
83
- return client.get('testing.example.com').then(function (domain: any) {
93
+ return client.get('testing.example.com').then(function (domain: Domain) {
84
94
  domain.should.eql({
85
95
  created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
86
96
  name: 'testing.example.com',
@@ -114,13 +124,17 @@ describe('DomainClient', function () {
114
124
  require_tls: true
115
125
  };
116
126
 
117
- api.post('/v2/domains').reply(200, {
127
+ api.post('/v3/domains').reply(200, {
118
128
  domain: domainData,
119
129
  receiving_dns_records: [],
120
130
  sending_dns_records: []
121
131
  });
122
132
 
123
- return client.create({ name: 'another.example.com' }).then(function (domain: any) {
133
+ return client.create({
134
+ name: 'another.example.com',
135
+ smtp_password: 'smtp_password',
136
+ web_scheme: 'https'
137
+ }).then(function (domain: Domain) {
124
138
  domain.should.eql({
125
139
  created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
126
140
  name: 'another.example.com',
@@ -141,11 +155,11 @@ describe('DomainClient', function () {
141
155
 
142
156
  describe('destroy', function () {
143
157
  it('deletes a domain', function () {
144
- api.delete('/v2/domains/test.example.com').reply(200, {
158
+ api.delete('/v3/domains/test.example.com').reply(200, {
145
159
  message: 'domain deleted'
146
160
  });
147
161
 
148
- return client.destroy('test.example.com').then(function (data: any) {
162
+ return client.destroy('test.example.com').then(function (data: MessageResponse) {
149
163
  data.should.eql({
150
164
  message: 'domain deleted'
151
165
  });
@@ -153,9 +167,46 @@ describe('DomainClient', function () {
153
167
  });
154
168
  });
155
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
+
156
207
  describe('getTracking', function () {
157
208
  it('fetches all tracking settings', function () {
158
- api.get('/v2/domains/domain.com/tracking').reply(200, {
209
+ api.get('/v3/domains/domain.com/tracking').reply(200, {
159
210
  tracking: {
160
211
  open: { active: true },
161
212
  click: { active: true },
@@ -172,7 +223,7 @@ describe('DomainClient', function () {
172
223
  describe('updateTracking', function () {
173
224
  it('updates tracking settings', async function () {
174
225
  const open = { active: true };
175
- api.put('/v2/domains/domain.com/tracking/open').reply(200, {
226
+ api.put('/v3/domains/domain.com/tracking/open').reply(200, {
176
227
  message: 'Tracking settings have been updated',
177
228
  open
178
229
  });
@@ -191,11 +242,63 @@ describe('DomainClient', function () {
191
242
  describe('getIps', () => {
192
243
  it('should return list of dedicated ips', () => {
193
244
  const items = ['192.161.0.1', '192.168.0.2'];
194
- api.get('/v2/domains/domain.com/ips').reply(200, { items });
245
+ api.get('/v3/domains/domain.com/ips').reply(200, { items });
195
246
 
196
247
  return client.getIps('domain.com').then((response: string[]) => {
197
248
  response.should.eql(items);
198
249
  });
199
250
  });
200
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
+ });
201
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
+ });
@@ -5,10 +5,11 @@ import EventClient from '../lib/events';
5
5
  import MgRequest from '../lib/request';
6
6
  import RequestOptions from '../lib/interfaces/RequestOptions';
7
7
  import { InputFormData } from '../lib/interfaces/IFormData';
8
+ import { EventsList, EventsResponse } from '../lib/interfaces/Events';
8
9
 
9
10
  describe('EventsClient', function () {
10
- let client: any;
11
- let api: any;
11
+ let client: EventClient;
12
+ let api: nock.Scope;
12
13
 
13
14
  beforeEach(function () {
14
15
  client = new EventClient(new MgRequest({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
@@ -26,14 +27,12 @@ describe('EventsClient', function () {
26
27
  response = {
27
28
  items: [
28
29
  {
29
- type: 'accepted',
30
+ event: 'accepted',
30
31
  timestamp: 'Wed, 19 Nov 2014 18:32:57 GMT',
31
- gist: 'got it',
32
32
  content: { more: 'data' }
33
33
  }, {
34
- type: 'opened',
34
+ event: 'opened',
35
35
  timestamp: 'Tue, 18 Nov 2014 12:32:57 GMT',
36
- gist: 'sent',
37
36
  content: { more: 'data' }
38
37
  }
39
38
  ],
@@ -47,49 +46,41 @@ describe('EventsClient', function () {
47
46
  });
48
47
 
49
48
  it('fetches all events', function () {
50
- api.get('/v2/domain.com/events').reply(200, response);
49
+ api.get('/v3/domain.com/events').reply(200, response);
51
50
 
52
- return client.get('domain.com').then(function (data: any) {
51
+ return client.get('domain.com').then(function (data: EventsList) {
53
52
  let e;
54
53
 
55
54
  e = data.items[0];
56
- e.type.should.eql('accepted');
57
- e.gist.should.eql('got it');
55
+ e.event.should.eql('accepted');
58
56
  e.timestamp.should.eql('Wed, 19 Nov 2014 18:32:57 GMT');
59
- e.content.should.eql({ more: 'data' });
60
57
 
61
58
  e = data.items[1];
62
- e.type.should.eql('opened');
63
- e.gist.should.eql('sent');
59
+ e.event.should.eql('opened');
64
60
  e.timestamp.should.eql('Tue, 18 Nov 2014 12:32:57 GMT');
65
- e.content.should.eql({ more: 'data' });
66
61
  });
67
62
  });
68
63
 
69
64
  it('fetches single page', function () {
70
- api.get('/v2/domain.com/events/pageId').reply(200, response);
65
+ api.get('/v3/domain.com/events/pageId').reply(200, response);
71
66
 
72
- return client.get('domain.com', { page: 'pageId' }).then(function (data: any) {
67
+ return client.get('domain.com', { page: 'pageId' }).then(function (data: EventsList) {
73
68
  let e;
74
69
 
75
70
  e = data.items[0];
76
- e.type.should.eql('accepted');
77
- e.gist.should.eql('got it');
71
+ e.event.should.eql('accepted');
78
72
  e.timestamp.should.eql('Wed, 19 Nov 2014 18:32:57 GMT');
79
- e.content.should.eql({ more: 'data' });
80
73
 
81
74
  e = data.items[1];
82
- e.type.should.eql('opened');
83
- e.gist.should.eql('sent');
75
+ e.event.should.eql('opened');
84
76
  e.timestamp.should.eql('Tue, 18 Nov 2014 12:32:57 GMT');
85
- e.content.should.eql({ more: 'data' });
86
77
  });
87
78
  });
88
79
 
89
80
  it('parses page links', function () {
90
- api.get('/v2/domain.com/events').reply(200, response);
81
+ api.get('/v3/domain.com/events').reply(200, response);
91
82
 
92
- return client.get('domain.com').then(function (data: any) {
83
+ return client.get('domain.com').then(function (data: EventsList) {
93
84
  let page;
94
85
 
95
86
  page = data.pages.first;
@@ -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
+ });
@@ -5,13 +5,16 @@ import Request from '../lib/request';
5
5
  import ValidateClient from '../lib/validate';
6
6
  import RequestOptions from '../lib/interfaces/RequestOptions';
7
7
  import { InputFormData } from '../lib/interfaces/IFormData';
8
+ import MultipleValidationClient from '../lib/multipleValidation';
8
9
 
9
10
  describe('ValidateClient', function () {
10
- let client: any;
11
- let api: any;
11
+ let client: ValidateClient;
12
+ let api: nock.Scope;
12
13
 
13
14
  beforeEach(function () {
14
- client = new ValidateClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
15
+ const reqObject = new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData);
16
+ const multipleValidationClient = new MultipleValidationClient(reqObject);
17
+ client = new ValidateClient(reqObject, multipleValidationClient);
15
18
  api = nock('https://api.mailgun.net');
16
19
  });
17
20
 
@@ -28,7 +31,7 @@ describe('ValidateClient', function () {
28
31
  parts: { display_name: null, domain: null, local_part: null }
29
32
  };
30
33
 
31
- api.get('/v3/address/validate')
34
+ api.get('/v4/address/validate')
32
35
  .query({ address: 'foo@example.com' })
33
36
  .reply(200, data);
34
37
 
@@ -25,7 +25,7 @@ describe('WebhookClient', function () {
25
25
  };
26
26
 
27
27
  it('fetches all webhooks', function () {
28
- api.get('/v2/domains/domain.com/webhooks').reply(200, {
28
+ api.get('/v3/domains/domain.com/webhooks').reply(200, {
29
29
  webhooks: hooks
30
30
  });
31
31
 
@@ -37,7 +37,7 @@ describe('WebhookClient', function () {
37
37
 
38
38
  describe('get', function () {
39
39
  it('fetches single webhook', function () {
40
- api.get('/v2/domains/domain.com/webhooks/click').reply(200, {
40
+ api.get('/v3/domains/domain.com/webhooks/click').reply(200, {
41
41
  webhook: {
42
42
  url: 'trackclick.com'
43
43
  }
@@ -51,7 +51,7 @@ describe('WebhookClient', function () {
51
51
 
52
52
  describe('create', function () {
53
53
  it('creates webhook', function () {
54
- api.post('/v2/domains/domain.com/webhooks')
54
+ api.post('/v3/domains/domain.com/webhooks')
55
55
  .reply(200, {
56
56
  message: 'Webhook has been created',
57
57
  webhook: {
@@ -66,7 +66,7 @@ describe('WebhookClient', function () {
66
66
  });
67
67
 
68
68
  it('tests webhook', function () {
69
- api.put('/v2/domains/domain.com/webhooks/click/test')
69
+ api.put('/v3/domains/domain.com/webhooks/click/test')
70
70
  .reply(200, {
71
71
  code: '500',
72
72
  message: 'Hi!'
@@ -81,7 +81,7 @@ describe('WebhookClient', function () {
81
81
 
82
82
  describe('update', function () {
83
83
  it('updates webhook', function () {
84
- api.put('/v2/domains/domain.com/webhooks/click')
84
+ api.put('/v3/domains/domain.com/webhooks/click')
85
85
  .reply(200, {
86
86
  message: 'Webhook has been updated',
87
87
  webhook: {
@@ -97,7 +97,7 @@ describe('WebhookClient', function () {
97
97
 
98
98
  describe('destroy', function () {
99
99
  it('deletes webhook', function () {
100
- api.delete('/v2/domains/domain.com/webhooks/click').reply(200, {
100
+ api.delete('/v3/domains/domain.com/webhooks/click').reply(200, {
101
101
  message: 'Webhook has been deleted',
102
102
  webhook: {
103
103
  url: 'trackclick.com'
@@ -5,6 +5,11 @@ const nodeConf = merge(commonConfig, {
5
5
  target: 'node',
6
6
  output: {
7
7
  filename: 'mailgun.node.js'
8
+ },
9
+ watchOptions: {
10
+ aggregateTimeout: 300,
11
+ poll: 5000,
12
+ ignored: ['../**/dist/*', '**/node_modules']
8
13
  }
9
14
  });
10
15
 
@@ -12,6 +17,11 @@ const webConf = merge(commonConfig, {
12
17
  target: 'web',
13
18
  output: {
14
19
  filename: 'mailgun.web.js'
20
+ },
21
+ watchOptions: {
22
+ aggregateTimeout: 300,
23
+ poll: 5000,
24
+ ignored: ['../**/dist/*', '**/node_modules']
15
25
  }
16
26
  });
17
27