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
@@ -0,0 +1,62 @@
1
+ /* eslint-disable camelcase */
2
+ export interface MultipleValidationJob {
3
+ created_at: number;
4
+ download_url: {
5
+ csv: string;
6
+ json: string;
7
+ };
8
+ id: string;
9
+ quantity: number;
10
+ records_processed: number;
11
+ status: string;
12
+ summary: {
13
+ result: {
14
+ catch_all: number;
15
+ deliverable: number;
16
+ do_not_send: number;
17
+ undeliverable: number;
18
+ unknown: number;
19
+ };
20
+ risk: {
21
+ high: number;
22
+ low: number;
23
+ medium: number;
24
+ unknown: number;
25
+ }
26
+ }
27
+ }
28
+
29
+ export interface CreatedMultipleValidationJob {
30
+ id: string;
31
+ message: string;
32
+ }
33
+
34
+ export interface PagesList {
35
+ prev: string;
36
+ first: string;
37
+ last: string;
38
+ next: string;
39
+ }
40
+
41
+ export interface MultipleValidationJobsListResult {
42
+ jobs: MultipleValidationJob[];
43
+ paging: PagesList;
44
+ total: number;
45
+ }
46
+
47
+ export interface MultipleValidationJobsListResponse {
48
+ status: 200;
49
+ body: MultipleValidationJobsListResult
50
+ }
51
+
52
+ export interface CanceledMultipleValidationJob {
53
+ body: string;
54
+ status: number;
55
+ }
56
+
57
+ export interface IMultipleValidationClient {
58
+ list() : Promise<MultipleValidationJobsListResult>
59
+ get(listId: string) : Promise<MultipleValidationJob>
60
+ create(listId: string, file: any) : Promise<CreatedMultipleValidationJob>
61
+ destroy(listId: string) : Promise<CanceledMultipleValidationJob>
62
+ }
@@ -0,0 +1,15 @@
1
+ /* eslint-disable camelcase */
2
+
3
+ export interface ValidationResult {
4
+ address: string;
5
+ is_disposable_address: boolean;
6
+ is_role_address: boolean;
7
+ reason: string[];
8
+ result: string;
9
+ risk: string;
10
+ }
11
+
12
+ export interface ValidationResponse {
13
+ status: number;
14
+ body: ValidationResult;
15
+ }
@@ -9,7 +9,7 @@ export interface WebhookResponseBody {
9
9
  }
10
10
 
11
11
  export interface WebhookResponse {
12
- status: string;
12
+ status: number;
13
13
  body: WebhookResponseBody;
14
14
  }
15
15
 
@@ -23,3 +23,8 @@ export interface WebhooksQuery {
23
23
  limit?: number;
24
24
  skip?: number;
25
25
  }
26
+
27
+ export interface ValidationResponse {
28
+ code: number;
29
+ message: string;
30
+ }
@@ -0,0 +1,37 @@
1
+ import {
2
+ CanceledMultipleValidationJob,
3
+ CreatedMultipleValidationJob,
4
+ IMultipleValidationClient,
5
+ MultipleValidationJob,
6
+ MultipleValidationJobsListResult
7
+ }
8
+ from './interfaces/MultipleValidation';
9
+ import Request from './request';
10
+
11
+ export default class MultipleValidationClient implements IMultipleValidationClient {
12
+ request: Request;
13
+
14
+ constructor(request: Request) {
15
+ this.request = request;
16
+ }
17
+
18
+ list(): Promise<MultipleValidationJobsListResult> {
19
+ return this.request.get('/v4/address/validate/bulk')
20
+ .then((response) => response.body as MultipleValidationJobsListResult);
21
+ }
22
+
23
+ get(listId: string): Promise<MultipleValidationJob> {
24
+ return this.request.get(`/v4/address/validate/bulk/${listId}`)
25
+ .then((response) => response.body);
26
+ }
27
+
28
+ create(listId: string, file: any): Promise<CreatedMultipleValidationJob> {
29
+ return this.request.postWithFD(`/v4/address/validate/bulk/${listId}`, file)
30
+ .then((response) => response.body);
31
+ }
32
+
33
+ destroy(listId: string): Promise<CanceledMultipleValidationJob> {
34
+ return this.request.delete(`/v4/address/validate/bulk/${listId}`)
35
+ .then((response) => response);
36
+ }
37
+ }
package/lib/request.ts CHANGED
@@ -107,10 +107,12 @@ class Request {
107
107
  } as APIErrorOptions);
108
108
  }
109
109
 
110
- return {
110
+ const res = {
111
111
  body: await response?.json(),
112
112
  status: response?.status
113
113
  };
114
+
115
+ return res;
114
116
  }
115
117
 
116
118
  query(method: string, url: string, query: any, options?: any) : Promise<APIResponse> {
@@ -142,6 +144,9 @@ class Request {
142
144
  }
143
145
 
144
146
  postWithFD(url: string, data: any): Promise<APIResponse> {
147
+ if (!data) {
148
+ throw new Error('Please provide data object');
149
+ }
145
150
  const params: any = {
146
151
  headers: { 'Content-Type': null }
147
152
  };
@@ -150,6 +155,9 @@ class Request {
150
155
  }
151
156
 
152
157
  putWithFD(url: string, data: any): Promise<APIResponse> {
158
+ if (!data) {
159
+ throw new Error('Please provide data object');
160
+ }
153
161
  const params: any = {
154
162
  headers: { 'Content-Type': null }
155
163
  };
@@ -176,7 +184,7 @@ class Request {
176
184
  const formData: NodeFormData | FormData = Object.keys(data)
177
185
  .filter(function (key) { return data[key]; })
178
186
  .reduce((formDataAcc: NodeFormData | FormData, key) => {
179
- if (key === 'attachment' || key === 'inline') {
187
+ if (key === 'attachment' || key === 'inline' || key === 'file') {
180
188
  const obj = data[key];
181
189
 
182
190
  if (Array.isArray(obj)) {
package/lib/validate.ts CHANGED
@@ -1,14 +1,20 @@
1
+ import APIResponse from './interfaces/ApiResponse';
2
+ import { IMultipleValidationClient } from './interfaces/MultipleValidation';
3
+ import { ValidationResult, ValidationResponse } from './interfaces/Validate';
1
4
  import Request from './request';
2
5
 
3
6
  export default class ValidateClient {
7
+ public multipleValidation;
4
8
  request: Request;
5
9
 
6
- constructor(request: Request) {
10
+ constructor(request: Request, multipleValidationClient: IMultipleValidationClient) {
7
11
  this.request = request;
12
+ this.multipleValidation = multipleValidationClient;
8
13
  }
9
14
 
10
- get(address: string) {
11
- return this.request.get('/v3/address/validate', { address })
12
- .then((response) => response.body);
15
+ get(address: string): Promise<ValidationResult> {
16
+ return this.request.get('/v4/address/validate', { address })
17
+ .then((response : APIResponse) => response)
18
+ .then((res : ValidationResponse) => res.body as ValidationResult);
13
19
  }
14
20
  }
package/lib/webhooks.ts CHANGED
@@ -1,5 +1,11 @@
1
1
  import urljoin from 'url-join';
2
- import { WebhookList, WebhookResponse, WebhooksQuery } from './interfaces/Webhooks';
2
+
3
+ import {
4
+ ValidationResponse,
5
+ WebhookList,
6
+ WebhookResponse,
7
+ WebhooksQuery
8
+ } from './interfaces/Webhooks';
3
9
  import Request from './request';
4
10
 
5
11
  class Webhook {
@@ -13,7 +19,7 @@ class Webhook {
13
19
  }
14
20
 
15
21
  export default class WebhookClient {
16
- request: any;
22
+ request: Request;
17
23
 
18
24
  constructor(request: Request) {
19
25
  this.request = request;
@@ -36,36 +42,39 @@ export default class WebhookClient {
36
42
 
37
43
  _parseWebhookTest(response: { body: { code: number, message: string } })
38
44
  : {code: number, message:string} {
39
- return { code: response.body.code, message: response.body.message };
45
+ return { code: response.body.code, message: response.body.message } as ValidationResponse;
40
46
  }
41
47
 
42
48
  list(domain: string, query: WebhooksQuery): Promise<WebhookList> {
43
- return this.request.get(urljoin('/v2/domains', domain, 'webhooks'), query)
49
+ return this.request.get(urljoin('/v3/domains', domain, 'webhooks'), query)
44
50
  .then(this._parseWebhookList);
45
51
  }
46
52
 
47
53
  get(domain: string, id: string): Promise<Webhook> {
48
- return this.request.get(urljoin('/v2/domains', domain, 'webhooks', id))
54
+ return this.request.get(urljoin('/v3/domains', domain, 'webhooks', id))
49
55
  .then(this._parseWebhookWithID(id));
50
56
  }
51
57
 
52
- create(domain: string, id: string, url: string, test = false): Promise<Webhook> {
58
+ create(domain: string,
59
+ id: string,
60
+ url: string,
61
+ test = false): Promise<Webhook | ValidationResponse> {
53
62
  if (test) {
54
- return this.request.putWithFD(urljoin('/v2/domains', domain, 'webhooks', id, 'test'), { url })
63
+ return this.request.putWithFD(urljoin('/v3/domains', domain, 'webhooks', id, 'test'), { url })
55
64
  .then(this._parseWebhookTest);
56
65
  }
57
66
 
58
- return this.request.postWithFD(urljoin('/v2/domains', domain, 'webhooks'), { id, url })
67
+ return this.request.postWithFD(urljoin('/v3/domains', domain, 'webhooks'), { id, url })
59
68
  .then(this._parseWebhookWithID(id));
60
69
  }
61
70
 
62
71
  update(domain: string, id: string, url: string): Promise<Webhook> {
63
- return this.request.putWithFD(urljoin('/v2/domains', domain, 'webhooks', id), { url })
72
+ return this.request.putWithFD(urljoin('/v3/domains', domain, 'webhooks', id), { url })
64
73
  .then(this._parseWebhookWithID(id));
65
74
  }
66
75
 
67
76
  destroy(domain: string, id: string) : Promise<Webhook> {
68
- return this.request.delete(urljoin('/v2/domains', domain, 'webhooks', id))
77
+ return this.request.delete(urljoin('/v3/domains', domain, 'webhooks', id))
69
78
  .then(this._parseWebhookWithID(id));
70
79
  }
71
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mailgun.js",
3
- "version": "3.7.3",
3
+ "version": "4.0.0",
4
4
  "main": "dist/mailgun.node.js",
5
5
  "browser": "dist/mailgun.web.js",
6
6
  "types": "dist/index.d.ts",
@@ -105,8 +105,7 @@
105
105
  "commitUrlFormat": "https://github.com/mailgun/mailgun.js/commits/{{hash}}",
106
106
  "compareUrlFormat": "https://github.com/mailgun/mailgun.js/compare/{{previousTag}}...{{currentTag}}",
107
107
  "scripts": {
108
- "prerelease": "npm test && webpack --config ./webpack/webpack.release.config.js --progress --color && git add -A dist",
109
- "posttag": "git push && git push --tags && rm -rf build"
108
+ "prerelease": "npm test && webpack --config ./webpack/webpack.release.config.js --progress --color && git add -A dist"
110
109
  }
111
110
  }
112
111
  }
@@ -11,8 +11,12 @@ import SuppressionsClient from '../lib/suppressions';
11
11
  import MessagesClient from '../lib/messages';
12
12
  import RoutesClient from '../lib/routes';
13
13
  import ValidateClient from '../lib/validate';
14
- import ParseClient from '../lib/parse';
14
+
15
15
  import { InputFormData } from '../lib/interfaces/IFormData';
16
+ import StatsClient from '../lib/stats';
17
+ import ListsClient from '../lib/lists';
18
+ import IpPoolsClient from '../lib/ip-pools';
19
+ import IpsClient from '../lib/ips';
16
20
 
17
21
  describe('Client', function () {
18
22
  let client: any;
@@ -62,6 +66,10 @@ describe('Client', function () {
62
66
  client.suppressions.should.be.instanceOf(SuppressionsClient);
63
67
  });
64
68
 
69
+ it('creates stats client', function () {
70
+ client.stats.should.be.instanceOf(StatsClient);
71
+ });
72
+
65
73
  it('creates messages client', function () {
66
74
  client.messages.should.be.instanceOf(MessagesClient);
67
75
  });
@@ -70,11 +78,19 @@ describe('Client', function () {
70
78
  client.routes.should.be.instanceOf(RoutesClient);
71
79
  });
72
80
 
73
- it('creates address validate client', function () {
74
- client.validate.should.be.instanceOf(ValidateClient);
81
+ it('creates ips client', function () {
82
+ client.ips.should.be.instanceOf(IpsClient);
75
83
  });
76
84
 
77
- it('creates address parse client', function () {
78
- client.parse.should.be.instanceOf(ParseClient);
85
+ it('creates ip_pools client', function () {
86
+ client.ip_pools.should.be.instanceOf(IpPoolsClient);
87
+ });
88
+
89
+ it('creates lists client', function () {
90
+ client.lists.should.be.instanceOf(ListsClient);
91
+ });
92
+
93
+ it('creates address validate client', function () {
94
+ client.validate.should.be.instanceOf(ValidateClient);
79
95
  });
80
96
  });
@@ -0,0 +1,3 @@
1
+ email
2
+ 1testEmailAdressForCheck@test.com
3
+ 2testEmailAdressForCheck@test.com
@@ -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
+ });