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/request.test.ts
CHANGED
|
@@ -8,6 +8,7 @@ import Request from '../lib/request';
|
|
|
8
8
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
9
9
|
import APIError from '../lib/error';
|
|
10
10
|
import APIResponse from '../lib/interfaces/ApiResponse';
|
|
11
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
11
12
|
|
|
12
13
|
describe('Request', function () {
|
|
13
14
|
let headers: { [key: string]: string };
|
|
@@ -33,7 +34,7 @@ describe('Request', function () {
|
|
|
33
34
|
url: 'https://api.mailgun.com',
|
|
34
35
|
headers: { 'X-CSRF-Token': 'protectme' },
|
|
35
36
|
timeout: 10000
|
|
36
|
-
}, formData);
|
|
37
|
+
}, formData as InputFormData);
|
|
37
38
|
|
|
38
39
|
await req.request('get', '/v2/some/resource1', {
|
|
39
40
|
headers: { Test: 'Custom Header', 'X-CSRF-Token': 'protectme' },
|
|
@@ -46,7 +47,7 @@ describe('Request', function () {
|
|
|
46
47
|
.get('/v2/some/resource')
|
|
47
48
|
.reply(200, { id: 1, message: 'hello' });
|
|
48
49
|
|
|
49
|
-
const req = new Request({ username: 'api', key: 'key', url: 'https://api.mailgun.com' } as RequestOptions, formData);
|
|
50
|
+
const req = new Request({ username: 'api', key: 'key', url: 'https://api.mailgun.com' } as RequestOptions, formData as InputFormData);
|
|
50
51
|
const res = req.request('get', '/v2/some/resource')
|
|
51
52
|
.then(function (response: APIResponse) {
|
|
52
53
|
expect(response.status).to.eql(200);
|
|
@@ -61,7 +62,7 @@ describe('Request', function () {
|
|
|
61
62
|
.get('/v2/some/resource')
|
|
62
63
|
.reply(429, 'Too many requests');
|
|
63
64
|
|
|
64
|
-
const req = new Request({ username: 'api', key: 'key', url: 'https://api.mailgun.com' } as RequestOptions, formData);
|
|
65
|
+
const req = new Request({ username: 'api', key: 'key', url: 'https://api.mailgun.com' } as RequestOptions, formData as InputFormData);
|
|
65
66
|
const res = req.request('get', '/v2/some/resource').catch(function (error: APIError) {
|
|
66
67
|
expect(error.status).to.eql(429);
|
|
67
68
|
expect(error.details).to.eql('Too many requests');
|
|
@@ -80,7 +81,7 @@ describe('Request', function () {
|
|
|
80
81
|
.query(search)
|
|
81
82
|
.reply(200, {});
|
|
82
83
|
|
|
83
|
-
const req = new Request({ url: 'https://api.mailgun.com' } as RequestOptions, formData);
|
|
84
|
+
const req = new Request({ url: 'https://api.mailgun.com' } as RequestOptions, formData as InputFormData);
|
|
84
85
|
await req.query('get', '/v2/some/resource2', search);
|
|
85
86
|
});
|
|
86
87
|
});
|
|
@@ -93,7 +94,7 @@ describe('Request', function () {
|
|
|
93
94
|
.post('/v2/some/resource')
|
|
94
95
|
.reply(200, {});
|
|
95
96
|
|
|
96
|
-
const req = new Request({ url: 'https://api.mailgun.com' } as RequestOptions, formData);
|
|
97
|
+
const req = new Request({ url: 'https://api.mailgun.com' } as RequestOptions, formData as InputFormData);
|
|
97
98
|
const res = req.command('post', '/v2/some/resource', body);
|
|
98
99
|
|
|
99
100
|
return res;
|
package/test/routes.test.ts
CHANGED
|
@@ -4,6 +4,7 @@ import nock from 'nock';
|
|
|
4
4
|
import Request from '../lib/request';
|
|
5
5
|
import RoutesClient from '../lib/routes';
|
|
6
6
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
7
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
7
8
|
|
|
8
9
|
interface Data {
|
|
9
10
|
actions: string[],
|
|
@@ -19,7 +20,7 @@ describe('RoutesClient', function () {
|
|
|
19
20
|
let api: any;
|
|
20
21
|
|
|
21
22
|
beforeEach(function () {
|
|
22
|
-
client = new RoutesClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
|
|
23
|
+
client = new RoutesClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
|
|
23
24
|
api = nock('https://api.mailgun.net');
|
|
24
25
|
});
|
|
25
26
|
|
package/test/stats.test.ts
CHANGED
|
@@ -5,13 +5,14 @@ import Request from '../lib/request';
|
|
|
5
5
|
import StatsClient from '../lib/stats';
|
|
6
6
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
7
7
|
import StatsOptions from '../lib/interfaces/StatsOptions';
|
|
8
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
8
9
|
|
|
9
10
|
describe('StatsClient', function () {
|
|
10
11
|
let client: any;
|
|
11
12
|
let api: any;
|
|
12
13
|
|
|
13
14
|
beforeEach(function () {
|
|
14
|
-
client = new StatsClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
|
|
15
|
+
client = new StatsClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
|
|
15
16
|
api = nock('https://api.mailgun.net');
|
|
16
17
|
});
|
|
17
18
|
|
|
@@ -5,6 +5,7 @@ import nock from 'nock';
|
|
|
5
5
|
import Request from '../lib/request';
|
|
6
6
|
import SuppressionClient from '../lib/suppressions';
|
|
7
7
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
8
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
8
9
|
|
|
9
10
|
chai.should();
|
|
10
11
|
|
|
@@ -13,7 +14,7 @@ describe('SuppressionsClient', function () {
|
|
|
13
14
|
let api: any;
|
|
14
15
|
|
|
15
16
|
beforeEach(function () {
|
|
16
|
-
client = new SuppressionClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
|
|
17
|
+
client = new SuppressionClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
|
|
17
18
|
api = nock('https://api.mailgun.net');
|
|
18
19
|
});
|
|
19
20
|
|
package/test/validate.test.ts
CHANGED
|
@@ -4,13 +4,17 @@ import nock from 'nock';
|
|
|
4
4
|
import Request from '../lib/request';
|
|
5
5
|
import ValidateClient from '../lib/validate';
|
|
6
6
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
7
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
8
|
+
import MultipleValidationClient from '../lib/multipleValidation';
|
|
7
9
|
|
|
8
10
|
describe('ValidateClient', function () {
|
|
9
|
-
let client:
|
|
10
|
-
let api:
|
|
11
|
+
let client: ValidateClient;
|
|
12
|
+
let api: nock.Scope;
|
|
11
13
|
|
|
12
14
|
beforeEach(function () {
|
|
13
|
-
|
|
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);
|
|
14
18
|
api = nock('https://api.mailgun.net');
|
|
15
19
|
});
|
|
16
20
|
|
|
@@ -27,7 +31,7 @@ describe('ValidateClient', function () {
|
|
|
27
31
|
parts: { display_name: null, domain: null, local_part: null }
|
|
28
32
|
};
|
|
29
33
|
|
|
30
|
-
api.get('/
|
|
34
|
+
api.get('/v4/address/validate')
|
|
31
35
|
.query({ address: 'foo@example.com' })
|
|
32
36
|
.reply(200, data);
|
|
33
37
|
|
package/test/webhooks.test.ts
CHANGED
|
@@ -3,13 +3,14 @@ import nock from 'nock';
|
|
|
3
3
|
import Request from '../lib/request';
|
|
4
4
|
import WebhookClient from '../lib/webhooks';
|
|
5
5
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
6
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
6
7
|
|
|
7
8
|
describe('WebhookClient', function () {
|
|
8
9
|
let client: any;
|
|
9
10
|
let api: any;
|
|
10
11
|
|
|
11
12
|
beforeEach(function () {
|
|
12
|
-
client = new WebhookClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
|
|
13
|
+
client = new WebhookClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
|
|
13
14
|
api = nock('https://api.mailgun.net');
|
|
14
15
|
});
|
|
15
16
|
|
|
@@ -24,7 +25,7 @@ describe('WebhookClient', function () {
|
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
it('fetches all webhooks', function () {
|
|
27
|
-
api.get('/
|
|
28
|
+
api.get('/v3/domains/domain.com/webhooks').reply(200, {
|
|
28
29
|
webhooks: hooks
|
|
29
30
|
});
|
|
30
31
|
|
|
@@ -36,7 +37,7 @@ describe('WebhookClient', function () {
|
|
|
36
37
|
|
|
37
38
|
describe('get', function () {
|
|
38
39
|
it('fetches single webhook', function () {
|
|
39
|
-
api.get('/
|
|
40
|
+
api.get('/v3/domains/domain.com/webhooks/click').reply(200, {
|
|
40
41
|
webhook: {
|
|
41
42
|
url: 'trackclick.com'
|
|
42
43
|
}
|
|
@@ -50,7 +51,7 @@ describe('WebhookClient', function () {
|
|
|
50
51
|
|
|
51
52
|
describe('create', function () {
|
|
52
53
|
it('creates webhook', function () {
|
|
53
|
-
api.post('/
|
|
54
|
+
api.post('/v3/domains/domain.com/webhooks')
|
|
54
55
|
.reply(200, {
|
|
55
56
|
message: 'Webhook has been created',
|
|
56
57
|
webhook: {
|
|
@@ -65,7 +66,7 @@ describe('WebhookClient', function () {
|
|
|
65
66
|
});
|
|
66
67
|
|
|
67
68
|
it('tests webhook', function () {
|
|
68
|
-
api.put('/
|
|
69
|
+
api.put('/v3/domains/domain.com/webhooks/click/test')
|
|
69
70
|
.reply(200, {
|
|
70
71
|
code: '500',
|
|
71
72
|
message: 'Hi!'
|
|
@@ -80,7 +81,7 @@ describe('WebhookClient', function () {
|
|
|
80
81
|
|
|
81
82
|
describe('update', function () {
|
|
82
83
|
it('updates webhook', function () {
|
|
83
|
-
api.put('/
|
|
84
|
+
api.put('/v3/domains/domain.com/webhooks/click')
|
|
84
85
|
.reply(200, {
|
|
85
86
|
message: 'Webhook has been updated',
|
|
86
87
|
webhook: {
|
|
@@ -96,7 +97,7 @@ describe('WebhookClient', function () {
|
|
|
96
97
|
|
|
97
98
|
describe('destroy', function () {
|
|
98
99
|
it('deletes webhook', function () {
|
|
99
|
-
api.delete('/
|
|
100
|
+
api.delete('/v3/domains/domain.com/webhooks/click').reply(200, {
|
|
100
101
|
message: 'Webhook has been deleted',
|
|
101
102
|
webhook: {
|
|
102
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
|
-
}
|
package/test/parse.test.ts
DELETED
|
@@ -1,74 +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
|
-
|
|
10
|
-
interface Data {
|
|
11
|
-
parsed: string[],
|
|
12
|
-
unparseable: string[]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
describe('ParseClient', function () {
|
|
16
|
-
let client: any;
|
|
17
|
-
let api: any;
|
|
18
|
-
|
|
19
|
-
beforeEach(function () {
|
|
20
|
-
client = new ParseClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
|
|
21
|
-
api = nock('https://api.mailgun.net');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
afterEach(function () {
|
|
25
|
-
api.done();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('get', function () {
|
|
29
|
-
it('parses a single email addresses', function () {
|
|
30
|
-
const data: Data = {
|
|
31
|
-
parsed: ['foo@example.com'],
|
|
32
|
-
unparseable: []
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const query = new URLSearchParams({ addresses: data.parsed });
|
|
36
|
-
|
|
37
|
-
api.get('/v3/address/parse').query(query).reply(200, data);
|
|
38
|
-
|
|
39
|
-
return client.get('foo@example.com').then(function (response: Data) {
|
|
40
|
-
response.should.eql(data);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('parses an array email addresses', function () {
|
|
45
|
-
const data: Data = {
|
|
46
|
-
parsed: ['foo@example.com'],
|
|
47
|
-
unparseable: ['example.com']
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
api.get('/v3/address/parse')
|
|
51
|
-
.query({ addresses: 'foo@example.com,example.com' })
|
|
52
|
-
.reply(200, data);
|
|
53
|
-
|
|
54
|
-
return client.get(['foo@example.com', 'example.com']).then(function (response: Data) {
|
|
55
|
-
response.should.eql(data);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('parses email addresses with dns and esp checks', function () {
|
|
60
|
-
const data: Data = {
|
|
61
|
-
parsed: [],
|
|
62
|
-
unparseable: ['foo@example.com']
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
api.get('/v3/address/parse')
|
|
66
|
-
.query({ addresses: 'foo@example.com', syntax_only: false })
|
|
67
|
-
.reply(200, data);
|
|
68
|
-
|
|
69
|
-
return client.get('foo@example.com', true).then(function (response: Data) {
|
|
70
|
-
response.should.eql(data);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
});
|