mailgun.js 3.7.3 → 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.
Files changed (48) hide show
  1. package/CHANGELOG.md +20 -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/Validate.d.ts +12 -0
  13. package/dist/lib/interfaces/Webhooks.d.ts +5 -1
  14. package/dist/lib/multipleValidation.d.ts +10 -0
  15. package/dist/lib/parse.d.ts +0 -6
  16. package/dist/lib/validate.d.ts +5 -2
  17. package/dist/lib/webhooks.d.ts +3 -3
  18. package/dist/mailgun.node.js +2 -2
  19. package/dist/mailgun.node.js.LICENSE.txt +1 -1
  20. package/dist/mailgun.web.js +2 -2
  21. package/dist/mailgun.web.js.LICENSE.txt +1 -1
  22. package/lib/client.ts +6 -12
  23. package/lib/domains.ts +82 -26
  24. package/lib/domainsCredentials.ts +88 -0
  25. package/lib/events.ts +6 -6
  26. package/lib/interfaces/DomainCredentials.ts +68 -0
  27. package/lib/interfaces/DomainTracking.ts +4 -4
  28. package/lib/interfaces/Domains.ts +65 -4
  29. package/lib/interfaces/Events.ts +66 -2
  30. package/lib/interfaces/MultipleValidation.ts +62 -0
  31. package/lib/interfaces/Validate.ts +15 -0
  32. package/lib/interfaces/Webhooks.ts +6 -1
  33. package/lib/multipleValidation.ts +37 -0
  34. package/lib/request.ts +10 -2
  35. package/lib/validate.ts +10 -4
  36. package/lib/webhooks.ts +19 -10
  37. package/package.json +2 -3
  38. package/test/client.test.ts +21 -5
  39. package/test/data/emailsValidation1.csv +3 -0
  40. package/test/domains.test.ts +118 -15
  41. package/test/domainsCredentials.test.ts +97 -0
  42. package/test/events.test.ts +15 -24
  43. package/test/multipleValidation.test.ts +159 -0
  44. package/test/validate.test.ts +7 -4
  45. package/test/webhooks.test.ts +6 -6
  46. package/webpack/webpack.dev.config.js +10 -0
  47. package/lib/parse.ts +0 -27
  48. package/test/parse.test.ts +0 -75
@@ -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
 
package/lib/parse.ts DELETED
@@ -1,27 +0,0 @@
1
- /* eslint-disable camelcase */
2
- import Request from './request';
3
-
4
- export default class ParseClient {
5
- request: Request;
6
-
7
- constructor(request: Request) {
8
- this.request = request;
9
- }
10
-
11
- get(addresses: string[] | string, enableDnsEspChecks: boolean) {
12
- const query = {} as { addresses: string, syntax_only: boolean };
13
-
14
- if (Array.isArray(addresses)) {
15
- query.addresses = addresses.join(',');
16
- } else {
17
- query.addresses = addresses;
18
- }
19
-
20
- if (enableDnsEspChecks) {
21
- query.syntax_only = false;
22
- }
23
-
24
- return this.request.get('/v3/address/parse', query)
25
- .then((response) => response.body);
26
- }
27
- }
@@ -1,75 +0,0 @@
1
- import formData from 'form-data';
2
-
3
- import { URLSearchParams } from 'url';
4
- import nock from 'nock';
5
- import Request from '../lib/request';
6
- import ParseClient from '../lib/parse';
7
-
8
- import RequestOptions from '../lib/interfaces/RequestOptions';
9
- import { InputFormData } from '../lib/interfaces/IFormData';
10
-
11
- interface Data {
12
- parsed: string[],
13
- unparseable: string[]
14
- }
15
-
16
- describe('ParseClient', function () {
17
- let client: any;
18
- let api: any;
19
-
20
- beforeEach(function () {
21
- client = new ParseClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
22
- api = nock('https://api.mailgun.net');
23
- });
24
-
25
- afterEach(function () {
26
- api.done();
27
- });
28
-
29
- describe('get', function () {
30
- it('parses a single email addresses', function () {
31
- const data: Data = {
32
- parsed: ['foo@example.com'],
33
- unparseable: []
34
- };
35
-
36
- const query = new URLSearchParams({ addresses: data.parsed });
37
-
38
- api.get('/v3/address/parse').query(query).reply(200, data);
39
-
40
- return client.get('foo@example.com').then(function (response: Data) {
41
- response.should.eql(data);
42
- });
43
- });
44
-
45
- it('parses an array email addresses', function () {
46
- const data: Data = {
47
- parsed: ['foo@example.com'],
48
- unparseable: ['example.com']
49
- };
50
-
51
- api.get('/v3/address/parse')
52
- .query({ addresses: 'foo@example.com,example.com' })
53
- .reply(200, data);
54
-
55
- return client.get(['foo@example.com', 'example.com']).then(function (response: Data) {
56
- response.should.eql(data);
57
- });
58
- });
59
-
60
- it('parses email addresses with dns and esp checks', function () {
61
- const data: Data = {
62
- parsed: [],
63
- unparseable: ['foo@example.com']
64
- };
65
-
66
- api.get('/v3/address/parse')
67
- .query({ addresses: 'foo@example.com', syntax_only: false })
68
- .reply(200, data);
69
-
70
- return client.get('foo@example.com', true).then(function (response: Data) {
71
- response.should.eql(data);
72
- });
73
- });
74
- });
75
- });