mailgun.js 3.6.1 → 3.7.3
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/.eslintrc +8 -6
- package/CHANGELOG.md +18 -0
- package/README.md +334 -0
- package/dist/index.d.ts +2 -2
- package/dist/lib/client.d.ts +2 -2
- package/dist/lib/events.d.ts +9 -25
- package/dist/lib/interfaces/APIErrorOptions.d.ts +2 -1
- package/dist/lib/interfaces/ApiResponse.d.ts +2 -1
- package/dist/lib/interfaces/Events.d.ts +24 -0
- package/dist/lib/interfaces/IFormData.d.ts +4 -12
- package/dist/lib/interfaces/IpPools.d.ts +12 -0
- package/dist/lib/interfaces/Options.d.ts +2 -1
- package/dist/lib/interfaces/RequestOptions.d.ts +2 -1
- package/dist/lib/interfaces/StatsOptions.d.ts +2 -1
- package/dist/lib/interfaces/lists.d.ts +1 -1
- package/dist/lib/interfaces/mailListMembers.d.ts +6 -6
- package/dist/lib/ip-pools.d.ts +11 -14
- package/dist/lib/ips.d.ts +6 -6
- package/dist/lib/messages.d.ts +1 -1
- package/dist/lib/request.d.ts +4 -3
- package/dist/lib/suppressions.d.ts +1 -1
- 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/examples/addresses.js +1 -0
- package/examples/list-domains.js +1 -0
- package/examples/send-email.js +1 -0
- package/index.ts +3 -3
- package/lib/client.ts +4 -3
- package/lib/events.ts +21 -19
- package/lib/interfaces/APIErrorOptions.ts +3 -1
- package/lib/interfaces/ApiResponse.ts +3 -1
- package/lib/interfaces/Events.ts +25 -0
- package/lib/interfaces/IFormData.ts +5 -14
- package/lib/interfaces/IpPools.ts +16 -1
- package/lib/interfaces/Ips.ts +1 -0
- package/lib/interfaces/Options.ts +5 -2
- package/lib/interfaces/RequestOptions.ts +4 -2
- package/lib/interfaces/StatsOptions.ts +4 -2
- package/lib/interfaces/Supressions.ts +1 -1
- package/lib/interfaces/lists.ts +2 -1
- package/lib/interfaces/mailListMembers.ts +18 -12
- package/lib/interfaces/routes.ts +1 -0
- package/lib/ip-pools.ts +8 -7
- package/lib/ips.ts +3 -3
- package/lib/lists.ts +1 -1
- package/lib/messages.ts +1 -1
- package/lib/parse.ts +4 -3
- package/lib/request.ts +18 -8
- package/lib/stats.ts +3 -2
- package/lib/suppressions.ts +16 -11
- package/lib/validate.ts +0 -1
- package/package.json +6 -6
- package/test/client.test.ts +9 -3
- package/test/domains.test.ts +2 -1
- package/test/events.test.ts +3 -2
- package/test/ips.test.ts +3 -2
- package/test/lists.test.ts +7 -7
- package/test/mailListMembers.test.ts +49 -43
- package/test/messageAttachment.test.ts +5 -4
- package/test/messages.test.ts +3 -2
- package/test/parse.test.ts +3 -2
- package/test/request.test.ts +6 -5
- package/test/routes.test.ts +3 -1
- package/test/stats.test.ts +2 -1
- package/test/suppressions.test.ts +6 -4
- package/test/validate.test.ts +2 -1
- package/test/webhooks.test.ts +2 -1
package/test/client.test.ts
CHANGED
|
@@ -12,18 +12,24 @@ import MessagesClient from '../lib/messages';
|
|
|
12
12
|
import RoutesClient from '../lib/routes';
|
|
13
13
|
import ValidateClient from '../lib/validate';
|
|
14
14
|
import ParseClient from '../lib/parse';
|
|
15
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
15
16
|
|
|
16
17
|
describe('Client', function () {
|
|
17
18
|
let client: any;
|
|
18
19
|
|
|
19
20
|
beforeEach(function () {
|
|
20
|
-
client = new Client({
|
|
21
|
+
client = new Client({
|
|
22
|
+
username: 'username',
|
|
23
|
+
key: 'key',
|
|
24
|
+
public_key: 'key',
|
|
25
|
+
timeout: 10000
|
|
26
|
+
}, formData as InputFormData);
|
|
21
27
|
});
|
|
22
28
|
|
|
23
29
|
it('raises error when username is not provided', function () {
|
|
24
30
|
expect(
|
|
25
31
|
function () {
|
|
26
|
-
return new Client({ key: 'key' } as any, formData)
|
|
32
|
+
return new Client({ key: 'key' } as any, formData as InputFormData);
|
|
27
33
|
}
|
|
28
34
|
).to.throw('Parameter "username" is required');
|
|
29
35
|
});
|
|
@@ -31,7 +37,7 @@ describe('Client', function () {
|
|
|
31
37
|
it('raises error when key is not provided', function () {
|
|
32
38
|
expect(
|
|
33
39
|
function () {
|
|
34
|
-
return new Client({ username: 'username' } as any, formData);
|
|
40
|
+
return new Client({ username: 'username' } as any, formData as InputFormData);
|
|
35
41
|
}
|
|
36
42
|
).to.throw('Parameter "key" is required');
|
|
37
43
|
});
|
package/test/domains.test.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { expect } from 'chai';
|
|
|
5
5
|
import Request from '../lib/request';
|
|
6
6
|
import DomainClient from '../lib/domains';
|
|
7
7
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
8
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
8
9
|
|
|
9
10
|
// TODO: fix types
|
|
10
11
|
describe('DomainClient', function () {
|
|
@@ -12,7 +13,7 @@ describe('DomainClient', function () {
|
|
|
12
13
|
let api: any;
|
|
13
14
|
|
|
14
15
|
beforeEach(function () {
|
|
15
|
-
client = new DomainClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
|
|
16
|
+
client = new DomainClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
|
|
16
17
|
api = nock('https://api.mailgun.net');
|
|
17
18
|
});
|
|
18
19
|
|
package/test/events.test.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import nock from 'nock';
|
|
2
2
|
|
|
3
|
-
import EventClient from '../lib/events';
|
|
4
3
|
import formData from 'form-data';
|
|
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';
|
|
7
8
|
|
|
8
9
|
describe('EventsClient', function () {
|
|
9
10
|
let client: any;
|
|
10
11
|
let api: any;
|
|
11
12
|
|
|
12
13
|
beforeEach(function () {
|
|
13
|
-
client = new EventClient(new MgRequest({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
|
|
14
|
+
client = new EventClient(new MgRequest({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
|
|
14
15
|
api = nock('https://api.mailgun.net');
|
|
15
16
|
});
|
|
16
17
|
|
package/test/ips.test.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// const formData = require('form-data');
|
|
2
2
|
|
|
3
3
|
import nock from 'nock';
|
|
4
|
+
import formData from 'form-data';
|
|
4
5
|
import Request from '../lib/request';
|
|
5
6
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
6
7
|
import IpsClient from '../lib/ips';
|
|
7
|
-
import formData from 'form-data';
|
|
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
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import nock from 'nock';
|
|
2
|
+
import formData from 'form-data';
|
|
3
|
+
|
|
2
4
|
import Request from '../lib/request';
|
|
3
5
|
import ListsClient from '../lib/lists';
|
|
4
6
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
5
7
|
import MailListMembers from '../lib/mailListMembers';
|
|
6
8
|
import { MailingList } from '../lib/interfaces/lists';
|
|
7
|
-
import
|
|
9
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
8
10
|
|
|
9
11
|
describe('ListsClient', function () {
|
|
10
12
|
let client: any;
|
|
@@ -12,7 +14,7 @@ describe('ListsClient', function () {
|
|
|
12
14
|
let defaultList : MailingList;
|
|
13
15
|
|
|
14
16
|
beforeEach(function () {
|
|
15
|
-
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);
|
|
16
18
|
const mailListMembers = new MailListMembers(reqObject);
|
|
17
19
|
client = new ListsClient(reqObject, mailListMembers);
|
|
18
20
|
api = nock('https://api.mailgun.net');
|
|
@@ -24,7 +26,7 @@ describe('ListsClient', function () {
|
|
|
24
26
|
members_count: 1,
|
|
25
27
|
name: '123',
|
|
26
28
|
reply_preference: null
|
|
27
|
-
} as MailingList
|
|
29
|
+
} as MailingList;
|
|
28
30
|
});
|
|
29
31
|
|
|
30
32
|
afterEach(function () {
|
|
@@ -39,15 +41,14 @@ describe('ListsClient', function () {
|
|
|
39
41
|
items: lists
|
|
40
42
|
});
|
|
41
43
|
|
|
42
|
-
return client.list().then(function (
|
|
43
|
-
|
|
44
|
+
return client.list().then(function (listsRes: MailingList[]) {
|
|
45
|
+
listsRes[0].should.eql(defaultList);
|
|
44
46
|
});
|
|
45
47
|
});
|
|
46
48
|
});
|
|
47
49
|
|
|
48
50
|
describe('get', function () {
|
|
49
51
|
it('gets a specific mailing list', function () {
|
|
50
|
-
|
|
51
52
|
api.get('/v3/lists/testing.example.com').reply(200, {
|
|
52
53
|
list: defaultList
|
|
53
54
|
});
|
|
@@ -60,7 +61,6 @@ describe('ListsClient', function () {
|
|
|
60
61
|
|
|
61
62
|
describe('create', function () {
|
|
62
63
|
it('creates the list', function () {
|
|
63
|
-
|
|
64
64
|
api.post('/v3/lists').reply(200, {
|
|
65
65
|
list: defaultList
|
|
66
66
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import nock from 'nock';
|
|
2
|
+
import formData from 'form-data';
|
|
2
3
|
import Request from '../lib/request';
|
|
3
4
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
4
5
|
import MailListMembers from '../lib/mailListMembers';
|
|
5
6
|
import { DeletedMember, MailListMember, NewMultipleMembersResponse } from '../lib/interfaces/mailListMembers';
|
|
6
|
-
import
|
|
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 = {
|
|
@@ -19,7 +20,7 @@ describe('mailListsMembersClient', function () {
|
|
|
19
20
|
name: 'test name',
|
|
20
21
|
subscribed: true,
|
|
21
22
|
vars: { gender: 'female', age: 0 }
|
|
22
|
-
} as MailListMember
|
|
23
|
+
} as MailListMember;
|
|
23
24
|
});
|
|
24
25
|
|
|
25
26
|
afterEach(function () {
|
|
@@ -57,7 +58,7 @@ describe('mailListsMembersClient', function () {
|
|
|
57
58
|
|
|
58
59
|
describe('createMember', function () {
|
|
59
60
|
it('adds list member to the mailing list ', function () {
|
|
60
|
-
const member:any = {...defaultListMember};
|
|
61
|
+
const member:any = { ...defaultListMember };
|
|
61
62
|
member.subscribed = true;
|
|
62
63
|
const mailingListAddress = 'testingMailingListAddress@example.com';
|
|
63
64
|
api.post(`/v3/lists/${mailingListAddress}/members`).reply(200, {
|
|
@@ -66,12 +67,12 @@ describe('mailListsMembersClient', function () {
|
|
|
66
67
|
|
|
67
68
|
return client.createMember(mailingListAddress, member).then(function (newListMember:any) {
|
|
68
69
|
newListMember.should.eql(member);
|
|
69
|
-
})
|
|
70
|
+
});
|
|
70
71
|
});
|
|
71
72
|
|
|
72
73
|
it('works with string value in subscribed field', function () {
|
|
73
|
-
const member:any = {...defaultListMember};
|
|
74
|
-
member.subscribed =
|
|
74
|
+
const member:any = { ...defaultListMember };
|
|
75
|
+
member.subscribed = 'yes';
|
|
75
76
|
const mailingListAddress = 'testingMailingListAddress@example.com';
|
|
76
77
|
api.post(`/v3/lists/${mailingListAddress}/members`).reply(200, {
|
|
77
78
|
member
|
|
@@ -79,13 +80,13 @@ describe('mailListsMembersClient', function () {
|
|
|
79
80
|
|
|
80
81
|
return client.createMember(mailingListAddress, member).then(function (newListMember:any) {
|
|
81
82
|
newListMember.should.eql(member);
|
|
82
|
-
})
|
|
83
|
+
});
|
|
83
84
|
});
|
|
84
85
|
});
|
|
85
86
|
|
|
86
87
|
describe('createMembers', function () {
|
|
87
|
-
const mailingListAddress
|
|
88
|
-
let
|
|
88
|
+
const mailingListAddress = 'testingMailingListAddress@example.com';
|
|
89
|
+
let response : NewMultipleMembersResponse;
|
|
89
90
|
|
|
90
91
|
beforeEach(function () {
|
|
91
92
|
response = {
|
|
@@ -105,55 +106,55 @@ describe('mailListsMembersClient', function () {
|
|
|
105
106
|
|
|
106
107
|
it('adds list of members to the mailing list', function () {
|
|
107
108
|
const newMembersListPlaceholder = new Array(5).fill(0);
|
|
108
|
-
const newMembersList = newMembersListPlaceholder.map((_, index)=>{
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
};
|
|
116
|
-
});
|
|
109
|
+
const newMembersList = newMembersListPlaceholder.map((_, index) => ({
|
|
110
|
+
address: `test${index}@example.com`,
|
|
111
|
+
name: `test name ${index}`,
|
|
112
|
+
vars: { gender: 'female', age: index },
|
|
113
|
+
subscribed: true,
|
|
114
|
+
upsert: 'yes'
|
|
115
|
+
}));
|
|
117
116
|
|
|
118
117
|
api.post(`/v3/lists/${mailingListAddress}/members.json`).reply(200, response);
|
|
119
118
|
|
|
120
119
|
return client.createMembers(mailingListAddress, {
|
|
121
120
|
members: newMembersList,
|
|
122
|
-
upsert:
|
|
121
|
+
upsert: 'yes'
|
|
123
122
|
}).then(function (result: NewMultipleMembersResponse) {
|
|
124
123
|
result.should.eql(response);
|
|
125
|
-
})
|
|
124
|
+
});
|
|
126
125
|
});
|
|
127
126
|
|
|
128
127
|
it('works with string value in members field', function () {
|
|
129
128
|
const newMembersListPlaceholder = new Array(5).fill(0);
|
|
130
|
-
const newMembersList = newMembersListPlaceholder.map((_, index)=>{
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
});
|
|
129
|
+
const newMembersList = newMembersListPlaceholder.map((_, index) => ({
|
|
130
|
+
address: `test${index}@example.com`,
|
|
131
|
+
name: `test name ${index}`,
|
|
132
|
+
vars: JSON.stringify({ gender: 'female', age: index }),
|
|
133
|
+
subscribed: true,
|
|
134
|
+
upsert: 'yes'
|
|
135
|
+
|
|
136
|
+
}));
|
|
139
137
|
api.post(`/v3/lists/${mailingListAddress}/members.json`).reply(200, response);
|
|
140
138
|
return client.createMembers(mailingListAddress, {
|
|
141
139
|
members: newMembersList,
|
|
142
|
-
upsert:
|
|
140
|
+
upsert: 'yes'
|
|
143
141
|
}).then(function (result: NewMultipleMembersResponse) {
|
|
144
142
|
result.should.eql(response);
|
|
145
|
-
})
|
|
143
|
+
});
|
|
146
144
|
});
|
|
147
|
-
|
|
148
145
|
});
|
|
149
146
|
|
|
150
147
|
describe('updateMember', function () {
|
|
151
148
|
it('updates list member in the mailing list ', function () {
|
|
152
149
|
const mailingListAddress = 'testingMailingListAddress@example.com';
|
|
153
150
|
const mailingListMemberAddress = 'testingMailingListMemberAddress@example.com';
|
|
154
|
-
api.put(`/v3/lists/${mailingListAddress}/members/${mailingListMemberAddress}`).reply(200, {member: defaultListMember});
|
|
151
|
+
api.put(`/v3/lists/${mailingListAddress}/members/${mailingListMemberAddress}`).reply(200, { member: defaultListMember });
|
|
155
152
|
|
|
156
|
-
return client.updateMember(
|
|
153
|
+
return client.updateMember(
|
|
154
|
+
mailingListAddress,
|
|
155
|
+
mailingListMemberAddress,
|
|
156
|
+
defaultListMember
|
|
157
|
+
).then(function (res: MailListMember) {
|
|
157
158
|
res.should.eql(defaultListMember);
|
|
158
159
|
});
|
|
159
160
|
});
|
|
@@ -161,32 +162,37 @@ describe('mailListsMembersClient', function () {
|
|
|
161
162
|
it('works with string value in subscribed field', function () {
|
|
162
163
|
const mailingListAddress = 'testingMailingListAddress@example.com';
|
|
163
164
|
const mailingListMemberAddress = 'testingMailingListMemberAddress@example.com';
|
|
164
|
-
const member:any = {...defaultListMember};
|
|
165
|
-
member.subscribed =
|
|
166
|
-
api.put(`/v3/lists/${mailingListAddress}/members/${mailingListMemberAddress}`).reply(200, {member: defaultListMember});
|
|
165
|
+
const member: any = { ...defaultListMember };
|
|
166
|
+
member.subscribed = 'yes';
|
|
167
|
+
api.put(`/v3/lists/${mailingListAddress}/members/${mailingListMemberAddress}`).reply(200, { member: defaultListMember });
|
|
167
168
|
|
|
168
|
-
return client.updateMember(
|
|
169
|
+
return client.updateMember(
|
|
170
|
+
mailingListAddress,
|
|
171
|
+
mailingListMemberAddress,
|
|
172
|
+
member
|
|
173
|
+
).then(function (res: MailListMember) {
|
|
169
174
|
res.should.eql(defaultListMember);
|
|
170
175
|
});
|
|
171
176
|
});
|
|
172
177
|
});
|
|
173
178
|
|
|
174
179
|
describe('destroyMember', function () {
|
|
175
|
-
|
|
176
180
|
it('deletes member from the list ', function () {
|
|
177
181
|
const mailingListAddress = 'testingMailingListAddress@example.com';
|
|
178
182
|
const mailingListMemberAddress = 'testingMailingListMemberAddress@example.com';
|
|
179
183
|
const res = {
|
|
180
184
|
member: defaultListMember,
|
|
181
|
-
message:
|
|
185
|
+
message: 'deleted'
|
|
182
186
|
} as DeletedMember;
|
|
183
187
|
|
|
184
188
|
api.delete(`/v3/lists/${mailingListAddress}/members/${mailingListMemberAddress}`).reply(200, res);
|
|
185
189
|
|
|
186
|
-
return client.destroyMember(
|
|
190
|
+
return client.destroyMember(
|
|
191
|
+
mailingListAddress,
|
|
192
|
+
mailingListMemberAddress
|
|
193
|
+
).then(function (deletedMemberRes: DeletedMember) {
|
|
187
194
|
deletedMemberRes.should.eql(res);
|
|
188
195
|
});
|
|
189
196
|
});
|
|
190
197
|
});
|
|
191
|
-
|
|
192
198
|
});
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import nock from 'nock';
|
|
3
|
+
import { expect } from 'chai';
|
|
4
|
+
import formData from 'form-data';
|
|
3
5
|
|
|
4
6
|
import Request from '../lib/request';
|
|
5
7
|
import MessagesClient from '../lib/messages';
|
|
6
8
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
7
|
-
import {
|
|
8
|
-
import formData from 'form-data';
|
|
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
|
|
|
@@ -41,7 +42,7 @@ describe('MessagesClient', function () {
|
|
|
41
42
|
filename: 'test-image',
|
|
42
43
|
data: mailgunLogo
|
|
43
44
|
}]
|
|
44
|
-
})
|
|
45
|
+
});
|
|
45
46
|
|
|
46
47
|
expect(res.message).to.eql('Queued. Thank you.');
|
|
47
48
|
});
|
package/test/messages.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import formData from 'form-data'; // importing this way to not have type error in line 13
|
|
2
2
|
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import nock from 'nock';
|
|
@@ -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
|
|
package/test/parse.test.ts
CHANGED
|
@@ -6,18 +6,19 @@ import Request from '../lib/request';
|
|
|
6
6
|
import ParseClient from '../lib/parse';
|
|
7
7
|
|
|
8
8
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
9
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
9
10
|
|
|
10
11
|
interface Data {
|
|
11
12
|
parsed: string[],
|
|
12
13
|
unparseable: string[]
|
|
13
|
-
}
|
|
14
|
+
}
|
|
14
15
|
|
|
15
16
|
describe('ParseClient', function () {
|
|
16
17
|
let client: any;
|
|
17
18
|
let api: any;
|
|
18
19
|
|
|
19
20
|
beforeEach(function () {
|
|
20
|
-
client = new ParseClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
|
|
21
|
+
client = new ParseClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
|
|
21
22
|
api = nock('https://api.mailgun.net');
|
|
22
23
|
});
|
|
23
24
|
|
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
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
1
2
|
import formData from 'form-data';
|
|
2
3
|
import nock from 'nock';
|
|
3
4
|
import Request from '../lib/request';
|
|
4
5
|
import RoutesClient from '../lib/routes';
|
|
5
6
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
7
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
6
8
|
|
|
7
9
|
interface Data {
|
|
8
10
|
actions: string[],
|
|
@@ -18,7 +20,7 @@ describe('RoutesClient', function () {
|
|
|
18
20
|
let api: any;
|
|
19
21
|
|
|
20
22
|
beforeEach(function () {
|
|
21
|
-
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));
|
|
22
24
|
api = nock('https://api.mailgun.net');
|
|
23
25
|
});
|
|
24
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
|
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import chai, { expect } from 'chai';
|
|
2
|
-
chai.should();
|
|
3
2
|
import formData from 'form-data';
|
|
4
|
-
|
|
5
3
|
import nock from 'nock';
|
|
4
|
+
|
|
6
5
|
import Request from '../lib/request';
|
|
7
6
|
import SuppressionClient from '../lib/suppressions';
|
|
8
7
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
8
|
+
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
9
|
+
|
|
10
|
+
chai.should();
|
|
9
11
|
|
|
10
12
|
describe('SuppressionsClient', function () {
|
|
11
13
|
let client: any;
|
|
12
14
|
let api: any;
|
|
13
15
|
|
|
14
16
|
beforeEach(function () {
|
|
15
|
-
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));
|
|
16
18
|
api = nock('https://api.mailgun.net');
|
|
17
19
|
});
|
|
18
20
|
|
|
@@ -81,7 +83,7 @@ describe('SuppressionsClient', function () {
|
|
|
81
83
|
api.get('/v3/domain.com/unsubscribes').reply(200, response);
|
|
82
84
|
|
|
83
85
|
return client.list('domain.com', 'unsubscribes')
|
|
84
|
-
|
|
86
|
+
.then(function (unsubscribes: { items: any }) {
|
|
85
87
|
let u;
|
|
86
88
|
|
|
87
89
|
u = unsubscribes.items[0];
|
package/test/validate.test.ts
CHANGED
|
@@ -4,13 +4,14 @@ 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';
|
|
7
8
|
|
|
8
9
|
describe('ValidateClient', function () {
|
|
9
10
|
let client: any;
|
|
10
11
|
let api: any;
|
|
11
12
|
|
|
12
13
|
beforeEach(function () {
|
|
13
|
-
client = new ValidateClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
|
|
14
|
+
client = new ValidateClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
|
|
14
15
|
api = nock('https://api.mailgun.net');
|
|
15
16
|
});
|
|
16
17
|
|
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
|
|