mailgun.js 3.5.8 → 3.7.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/.eslintrc +27 -11
- package/CHANGELOG.md +35 -0
- package/README.md +138 -50
- package/commitlint.config.js +1 -2
- package/dist/index.d.ts +1 -1
- package/dist/lib/client.d.ts +1 -1
- 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/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/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/suppressions.d.ts +1 -1
- package/dist/mailgun.node.js +3 -0
- package/dist/{mailgun.js.LICENSE.txt → mailgun.node.js.LICENSE.txt} +1 -1
- package/dist/mailgun.web.js +3 -0
- package/dist/mailgun.web.js.LICENSE.txt +7 -0
- package/examples/addresses.js +1 -0
- package/examples/list-domains.js +1 -0
- package/examples/send-email.js +1 -0
- package/index.ts +1 -1
- package/lib/client.ts +3 -2
- 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 +4 -3
- 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 +1 -0
- 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/stats.ts +3 -2
- package/lib/suppressions.ts +16 -11
- package/lib/validate.ts +0 -1
- package/package.json +10 -10
- package/test/client.test.ts +7 -2
- package/test/events.test.ts +1 -2
- package/test/ips.test.ts +2 -1
- package/test/lists.test.ts +5 -7
- package/test/mailListMembers.test.ts +47 -43
- package/test/messageAttachment.test.ts +3 -4
- package/test/messages.test.ts +1 -1
- package/test/parse.test.ts +2 -2
- package/test/routes.test.ts +1 -0
- package/test/stats.test.ts +1 -1
- package/test/suppressions.test.ts +12 -10
- package/test/validate.test.ts +1 -1
- package/test/webhooks.test.ts +1 -2
- package/tsconfig.webpack.json +1 -1
- package/webpack/webpack.common.config.js +47 -0
- package/webpack/webpack.dev.config.js +18 -0
- package/webpack/webpack.release.config.js +37 -0
- package/dist/mailgun.js +0 -3
- package/webpack.config.js +0 -49
- package/webpack.release.config.js +0 -29
package/examples/list-domains.js
CHANGED
package/examples/send-email.js
CHANGED
package/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import IFormData from './lib/interfaces/IFormData';
|
|
|
5
5
|
class Mailgun {
|
|
6
6
|
private formData: new () => IFormData
|
|
7
7
|
|
|
8
|
-
constructor(FormData: new (...args:
|
|
8
|
+
constructor(FormData: new (...args: unknown[]) => IFormData) {
|
|
9
9
|
this.formData = FormData;
|
|
10
10
|
}
|
|
11
11
|
|
package/lib/client.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
1
2
|
import Request from './request';
|
|
2
3
|
import Options from './interfaces/Options';
|
|
3
4
|
import RequestOptions from './interfaces/RequestOptions';
|
|
@@ -34,11 +35,11 @@ export default class Client {
|
|
|
34
35
|
public ip_pools;
|
|
35
36
|
public lists;
|
|
36
37
|
|
|
37
|
-
constructor(options: Options, formData: new (...args:
|
|
38
|
+
constructor(options: Options, formData: new (...args: unknown[]) => IFormData) {
|
|
38
39
|
const config: RequestOptions = { ...options } as RequestOptions;
|
|
39
40
|
|
|
40
41
|
if (!config.url) {
|
|
41
|
-
config.url = 'https://api.mailgun.net'
|
|
42
|
+
config.url = 'https://api.mailgun.net';
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
if (!config.username) {
|
package/lib/events.ts
CHANGED
|
@@ -1,52 +1,54 @@
|
|
|
1
|
-
|
|
1
|
+
import urljoin from 'url-join';
|
|
2
|
+
import {
|
|
3
|
+
EventsList, EventsPage, EventsResponse, PagesList, PagesListAccumulator
|
|
4
|
+
} from './interfaces/Events';
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
import Request from './request';
|
|
4
7
|
|
|
5
8
|
export default class EventClient {
|
|
6
|
-
request:
|
|
9
|
+
request: Request;
|
|
7
10
|
|
|
8
|
-
constructor(request:
|
|
11
|
+
constructor(request: Request) {
|
|
9
12
|
this.request = request;
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
_parsePageNumber(url: string) {
|
|
15
|
+
_parsePageNumber(url: string) : string {
|
|
13
16
|
return url.split('/').pop();
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
_parsePage(id: string, url: string) {
|
|
19
|
+
_parsePage(id: string, url: string) : EventsPage {
|
|
17
20
|
return { id, number: this._parsePageNumber(url), url };
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
_parsePageLinks(response:
|
|
21
|
-
const pages = Object.entries(response.body.paging);
|
|
23
|
+
_parsePageLinks(response: EventsResponse) : PagesList {
|
|
24
|
+
const pages = Object.entries(response.body.paging as PagesList);
|
|
22
25
|
return pages.reduce(
|
|
23
|
-
(acc:
|
|
26
|
+
(acc: PagesListAccumulator, entrie: [url: string, id: string]) => {
|
|
24
27
|
const id = entrie[0];
|
|
25
28
|
const url = entrie[1];
|
|
26
29
|
acc[id] = this._parsePage(id, url);
|
|
27
30
|
return acc;
|
|
28
31
|
}, {}
|
|
29
|
-
);
|
|
32
|
+
) as unknown as PagesList;
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
_parseEventList(response:
|
|
35
|
+
_parseEventList(response: EventsResponse) : EventsList {
|
|
33
36
|
return {
|
|
34
37
|
items: response.body.items,
|
|
35
38
|
pages: this._parsePageLinks(response)
|
|
36
39
|
};
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
get(domain: string, query: { page:
|
|
42
|
+
get(domain: string, query: { page: string }) : Promise<EventsList> {
|
|
40
43
|
let url;
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
url = urljoin('/v2', domain, 'events',
|
|
44
|
-
delete
|
|
44
|
+
const queryCopy = { ...query };
|
|
45
|
+
if (queryCopy && queryCopy.page) {
|
|
46
|
+
url = urljoin('/v2', domain, 'events', queryCopy.page);
|
|
47
|
+
delete queryCopy.page;
|
|
45
48
|
} else {
|
|
46
49
|
url = urljoin('/v2', domain, 'events');
|
|
47
50
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
.then((response: { body: { items: any, paging: any } }) => this._parseEventList(response));
|
|
51
|
+
return this.request.get(url, queryCopy)
|
|
52
|
+
.then((response: EventsResponse) => this._parseEventList(response));
|
|
51
53
|
}
|
|
52
54
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
interface APIErrorOptions {
|
|
2
2
|
headers: { [key: string]: any };
|
|
3
3
|
status: number | string;
|
|
4
4
|
message: string;
|
|
@@ -6,3 +6,5 @@ export default interface APIErrorOptions {
|
|
|
6
6
|
url: string;
|
|
7
7
|
statusText: string;
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
export default APIErrorOptions;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface EventsPage {
|
|
2
|
+
id: string;
|
|
3
|
+
number: string;
|
|
4
|
+
url: string;
|
|
5
|
+
}
|
|
6
|
+
export interface PagesList {
|
|
7
|
+
previous: string;
|
|
8
|
+
first: string;
|
|
9
|
+
last: string;
|
|
10
|
+
next: string;
|
|
11
|
+
}
|
|
12
|
+
export interface EventsResponse {
|
|
13
|
+
body: {
|
|
14
|
+
items: [];
|
|
15
|
+
paging: PagesList;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface EventsList {
|
|
20
|
+
items: [];
|
|
21
|
+
pages: PagesList;
|
|
22
|
+
}
|
|
23
|
+
export interface PagesListAccumulator {
|
|
24
|
+
[index: string]: EventsPage
|
|
25
|
+
}
|
|
@@ -11,8 +11,9 @@ interface AppendOptions {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export default abstract class IFormData {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
// eslint-disable-next-line no-useless-constructor
|
|
15
|
+
constructor() { // description of type. Should not be used for creating objects
|
|
16
|
+
}
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
abstract append(key: string, value: any, options?: AppendOptions | string): void
|
|
18
19
|
}
|
|
@@ -1,7 +1,22 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
1
2
|
export interface IpPool {
|
|
2
3
|
description: string;
|
|
3
4
|
ips: string[];
|
|
4
5
|
is_linked: boolean;
|
|
5
6
|
name: string;
|
|
6
7
|
pool_id: string;
|
|
7
|
-
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface IpPoolListResponse {
|
|
11
|
+
body: {
|
|
12
|
+
ip_pools: IpPool,
|
|
13
|
+
message: string
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface IpPoolUpdateData {
|
|
18
|
+
name: string,
|
|
19
|
+
description: string,
|
|
20
|
+
add_ip: string,
|
|
21
|
+
remove_ip: string
|
|
22
|
+
}
|
package/lib/interfaces/Ips.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
interface StatsOptions {
|
|
2
2
|
start: string | Date;
|
|
3
3
|
end: string | Date;
|
|
4
4
|
resolution: string;
|
|
@@ -10,4 +10,6 @@ export default interface StatsOptions {
|
|
|
10
10
|
total: number
|
|
11
11
|
}
|
|
12
12
|
}[];
|
|
13
|
-
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default StatsOptions;
|
package/lib/interfaces/lists.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import {MailingList} from './lists';
|
|
1
|
+
import { MailingList } from './lists';
|
|
2
2
|
|
|
3
|
+
export interface MailListMember {
|
|
4
|
+
address: string;
|
|
5
|
+
name: string;
|
|
6
|
+
subscribed: boolean,
|
|
7
|
+
vars: string | any;
|
|
8
|
+
}
|
|
3
9
|
export interface MailListMembersQuery {
|
|
4
10
|
subscribed?: 'yes' | 'no';
|
|
5
11
|
limit?: number;
|
|
@@ -31,13 +37,6 @@ export interface CreateUpdateMailListMembersReq {
|
|
|
31
37
|
upsert?: 'yes' | 'no';
|
|
32
38
|
}
|
|
33
39
|
|
|
34
|
-
export interface MailListMember {
|
|
35
|
-
address: string;
|
|
36
|
-
name: string;
|
|
37
|
-
subscribed: boolean,
|
|
38
|
-
vars: string | any;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
40
|
export interface DeletedMember {
|
|
42
41
|
member: {
|
|
43
42
|
address: string;
|
|
@@ -54,8 +53,15 @@ export interface NewMultipleMembersResponse {
|
|
|
54
53
|
export interface IMailListsMembers {
|
|
55
54
|
listMembers(mailListAddress: string, query?: MailListMembersQuery): Promise<MailListMember[]>;
|
|
56
55
|
getMember(address: string, memberAddress: string): Promise<MailListMember>,
|
|
57
|
-
createMember(
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
createMember(
|
|
57
|
+
mailListAddress: string,
|
|
58
|
+
data: CreateUpdateMailListMembers): Promise<MailListMember>,
|
|
59
|
+
createMembers(
|
|
60
|
+
mailListAddress: string,
|
|
61
|
+
data: MultipleMembersData): Promise<NewMultipleMembersResponse>,
|
|
62
|
+
updateMember(
|
|
63
|
+
address: string,
|
|
64
|
+
memberAddress: string,
|
|
65
|
+
data: CreateUpdateMailListMembers): Promise<MailListMember>,
|
|
60
66
|
destroyMember(address : string, memberAddress: string): Promise<DeletedMember>
|
|
61
|
-
}
|
|
67
|
+
}
|
package/lib/interfaces/routes.ts
CHANGED
package/lib/ip-pools.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
import Request from './request';
|
|
2
3
|
|
|
3
|
-
import { IpPool } from
|
|
4
|
+
import { IpPool, IpPoolListResponse, IpPoolUpdateData } from './interfaces/IpPools';
|
|
4
5
|
|
|
5
6
|
export default class IpPoolsClient {
|
|
6
|
-
request:
|
|
7
|
+
request: Request;
|
|
7
8
|
|
|
8
|
-
constructor(request:
|
|
9
|
+
constructor(request: Request) {
|
|
9
10
|
this.request = request;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
list(query: any): IpPool[] {
|
|
13
|
+
list(query: any): Promise<IpPool[]> {
|
|
13
14
|
return this.request.get('/v1/ip_pools', query)
|
|
14
|
-
.then((response:
|
|
15
|
+
.then((response: IpPoolListResponse) => this.parseIpPoolsResponse(response));
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
create(data: { name: string, description?: string, ips?: string[] }) {
|
|
@@ -19,7 +20,7 @@ export default class IpPoolsClient {
|
|
|
19
20
|
.then((response: { body: { message: string, pool_id: string } }) => response?.body);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
update(poolId: string, data:
|
|
23
|
+
update(poolId: string, data: IpPoolUpdateData) : Promise<any> {
|
|
23
24
|
return this.request.patch(`/v1/ip_pools/${poolId}`, data)
|
|
24
25
|
.then((response: { body: any }) => response?.body);
|
|
25
26
|
}
|
package/lib/ips.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import MgRequest from './request';
|
|
2
2
|
import { IpData, IpsListResponseBody } from './interfaces/Ips';
|
|
3
3
|
|
|
4
4
|
export default class IpsClient {
|
|
5
|
-
request:
|
|
5
|
+
request: MgRequest;
|
|
6
6
|
|
|
7
|
-
constructor(request:
|
|
7
|
+
constructor(request: MgRequest) {
|
|
8
8
|
this.request = request;
|
|
9
9
|
}
|
|
10
10
|
|
package/lib/lists.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
DestroyedList,
|
|
6
6
|
MailingList
|
|
7
7
|
} from './interfaces/lists';
|
|
8
|
-
import {IMailListsMembers} from './interfaces/mailListMembers';
|
|
8
|
+
import { IMailListsMembers } from './interfaces/mailListMembers';
|
|
9
9
|
|
|
10
10
|
export default class ListsClient {
|
|
11
11
|
baseRoute: string;
|
package/lib/messages.ts
CHANGED
package/lib/parse.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
1
2
|
import Request from './request';
|
|
2
3
|
|
|
3
4
|
export default class ParseClient {
|
|
@@ -11,11 +12,11 @@ export default class ParseClient {
|
|
|
11
12
|
const query = {} as { addresses: string, syntax_only: boolean };
|
|
12
13
|
|
|
13
14
|
if (Array.isArray(addresses)) {
|
|
14
|
-
addresses = addresses.join(',');
|
|
15
|
+
query.addresses = addresses.join(',');
|
|
16
|
+
} else {
|
|
17
|
+
query.addresses = addresses;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
query.addresses = addresses;
|
|
18
|
-
|
|
19
20
|
if (enableDnsEspChecks) {
|
|
20
21
|
query.syntax_only = false;
|
|
21
22
|
}
|
package/lib/stats.ts
CHANGED
|
@@ -13,8 +13,9 @@ class Stats {
|
|
|
13
13
|
this.end = new Date(data.end);
|
|
14
14
|
this.resolution = data.resolution;
|
|
15
15
|
this.stats = data.stats.map(function (stat: { time: string | Date }) {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const res = { ...stat };
|
|
17
|
+
res.time = new Date(stat.time);
|
|
18
|
+
return res;
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
21
|
}
|
package/lib/suppressions.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
1
2
|
import url from 'url';
|
|
2
3
|
import urljoin from 'url-join';
|
|
3
4
|
|
|
4
5
|
import Request from './request';
|
|
5
6
|
import { BounceData, ComplaintData, UnsubscribeData } from './interfaces/Supressions';
|
|
6
7
|
|
|
7
|
-
type TModel = typeof Bounce | typeof Complaint | typeof Unsubscribe;
|
|
8
|
-
|
|
9
8
|
const createOptions = {
|
|
10
9
|
headers: { 'Content-Type': 'application/json' }
|
|
11
10
|
};
|
|
@@ -52,6 +51,8 @@ class Unsubscribe {
|
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
|
|
54
|
+
type TModel = typeof Bounce | typeof Complaint | typeof Unsubscribe;
|
|
55
|
+
|
|
55
56
|
export default class SuppressionClient {
|
|
56
57
|
request: any;
|
|
57
58
|
models: {
|
|
@@ -84,10 +85,11 @@ export default class SuppressionClient {
|
|
|
84
85
|
_parsePageLinks(response: { body: { paging: any } }) {
|
|
85
86
|
const pages = Object.entries(response.body.paging);
|
|
86
87
|
return pages.reduce(
|
|
87
|
-
(acc: any, [id,
|
|
88
|
-
acc[id] = this._parsePage(id,
|
|
89
|
-
return acc
|
|
90
|
-
}, {}
|
|
88
|
+
(acc: any, [id, pageUrl]: [pageUrl: string, id: string]) => {
|
|
89
|
+
acc[id] = this._parsePage(id, pageUrl);
|
|
90
|
+
return acc;
|
|
91
|
+
}, {}
|
|
92
|
+
);
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
_parseList(response: { body: { items: any, paging: any } }, Model: TModel) {
|
|
@@ -122,19 +124,22 @@ export default class SuppressionClient {
|
|
|
122
124
|
|
|
123
125
|
create(domain: string, type: string, data: any) {
|
|
124
126
|
// supports adding multiple suppressions by default
|
|
127
|
+
let postData;
|
|
125
128
|
if (!Array.isArray(data)) {
|
|
126
|
-
|
|
129
|
+
postData = [data];
|
|
130
|
+
} else {
|
|
131
|
+
postData = { ...data };
|
|
127
132
|
}
|
|
128
133
|
|
|
129
134
|
return this.request
|
|
130
|
-
|
|
131
|
-
|
|
135
|
+
.post(urljoin('v3', domain, type), postData, createOptions)
|
|
136
|
+
.then((response: { body: any }) => response.body);
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
destroy(domain: string, type: string, address: string) {
|
|
135
140
|
return this.request
|
|
136
|
-
|
|
137
|
-
|
|
141
|
+
.delete(urljoin('v3', domain, type, encodeURIComponent(address)))
|
|
142
|
+
.then((response: { body: any }) => response.body);
|
|
138
143
|
}
|
|
139
144
|
}
|
|
140
145
|
|
package/lib/validate.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mailgun.js",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"main": "dist/mailgun.js",
|
|
3
|
+
"version": "3.7.0",
|
|
4
|
+
"main": "dist/mailgun.node.js",
|
|
5
|
+
"browser": "dist/mailgun.web.js",
|
|
5
6
|
"types": "dist/index.d.ts",
|
|
6
7
|
"author": "Mailgun",
|
|
7
8
|
"license": "MIT",
|
|
@@ -18,9 +19,9 @@
|
|
|
18
19
|
},
|
|
19
20
|
"homepage": "https://github.com/mailgun/mailgun-js#readme",
|
|
20
21
|
"scripts": {
|
|
21
|
-
"build": "webpack --config ./webpack.config.js --progress --color",
|
|
22
|
-
"build:release": "webpack --config ./webpack.release.config.js --progress --color",
|
|
23
|
-
"start": "webpack --watch --config ./webpack.config.js --progress --color",
|
|
22
|
+
"build": "webpack --config ./webpack/webpack.dev.config.js --progress --color",
|
|
23
|
+
"build:release": "webpack --config ./webpack/webpack.release.config.js --progress --color",
|
|
24
|
+
"start": "webpack --watch --config ./webpack/webpack.dev.config.js --progress --color",
|
|
24
25
|
"release": "standard-version -a",
|
|
25
26
|
"test": "multi='dot=- xunit=./results.xml' mocha -t 10000 -R mocha-multi -r ts-node/register test/*.test.ts",
|
|
26
27
|
"test-watch": "mocha -r ts-node/register -w -R dot test/*.test.ts",
|
|
@@ -41,7 +42,7 @@
|
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@babel/core": "^7.12.3",
|
|
43
44
|
"@babel/preset-env": "^7.12.1",
|
|
44
|
-
"@commitlint/cli": "^
|
|
45
|
+
"@commitlint/cli": "^13.1.0",
|
|
45
46
|
"@commitlint/config-conventional": "^12.1.4",
|
|
46
47
|
"@types/base-64": "^1.0.0",
|
|
47
48
|
"@types/chai": "^4.2.14",
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
"@typescript-eslint/parser": "^4.26.0",
|
|
52
53
|
"babel-loader": "^8.1.0",
|
|
53
54
|
"chai": "^4.2.0",
|
|
54
|
-
"eslint": "^7.
|
|
55
|
+
"eslint": "^7.32.0",
|
|
55
56
|
"eslint-config-airbnb-base": "^14.2.0",
|
|
56
57
|
"eslint-import-resolver-webpack": "^0.13.1",
|
|
57
58
|
"eslint-plugin-import": "^2.22.1",
|
|
@@ -59,11 +60,10 @@
|
|
|
59
60
|
"form-data": "^3.0.1",
|
|
60
61
|
"husky": "^7.0.1",
|
|
61
62
|
"json-loader": "^0.5.7",
|
|
62
|
-
"mocha": "^
|
|
63
|
+
"mocha": "^9.1.3",
|
|
63
64
|
"mocha-multi": "^1.1.3",
|
|
64
65
|
"nock": "^13.0.4",
|
|
65
66
|
"path-browserify": "^1.0.1",
|
|
66
|
-
"should": "^4.1.0",
|
|
67
67
|
"standard-version": "^9.3.1",
|
|
68
68
|
"terser-webpack-plugin": "^5.2.0",
|
|
69
69
|
"ts-loader": "^8.0.12",
|
|
@@ -105,7 +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.release.config.js --progress --color && git add -A dist",
|
|
108
|
+
"prerelease": "npm test && webpack --config ./webpack/webpack.release.config.js --progress --color && git add -A dist",
|
|
109
109
|
"posttag": "git push && git push --tags && rm -rf build"
|
|
110
110
|
}
|
|
111
111
|
}
|
package/test/client.test.ts
CHANGED
|
@@ -17,13 +17,18 @@ describe('Client', function () {
|
|
|
17
17
|
let client: any;
|
|
18
18
|
|
|
19
19
|
beforeEach(function () {
|
|
20
|
-
client = new Client({
|
|
20
|
+
client = new Client({
|
|
21
|
+
username: 'username',
|
|
22
|
+
key: 'key',
|
|
23
|
+
public_key: 'key',
|
|
24
|
+
timeout: 10000
|
|
25
|
+
}, formData);
|
|
21
26
|
});
|
|
22
27
|
|
|
23
28
|
it('raises error when username is not provided', function () {
|
|
24
29
|
expect(
|
|
25
30
|
function () {
|
|
26
|
-
return new Client({ key: 'key' } as any, formData)
|
|
31
|
+
return new Client({ key: 'key' } as any, formData);
|
|
27
32
|
}
|
|
28
33
|
).to.throw('Parameter "username" is required');
|
|
29
34
|
});
|
package/test/events.test.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
const formData = require('form-data'); // importing this way to not have type error in line 13
|
|
2
|
-
|
|
3
1
|
import nock from 'nock';
|
|
4
2
|
|
|
3
|
+
import formData from 'form-data';
|
|
5
4
|
import EventClient from '../lib/events';
|
|
6
5
|
import MgRequest from '../lib/request';
|
|
7
6
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
package/test/ips.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
const formData = require('form-data');
|
|
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';
|
package/test/lists.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const formData = require('form-data');
|
|
2
|
-
|
|
3
1
|
import nock from 'nock';
|
|
2
|
+
import formData from 'form-data';
|
|
3
|
+
|
|
4
4
|
import Request from '../lib/request';
|
|
5
5
|
import ListsClient from '../lib/lists';
|
|
6
6
|
import RequestOptions from '../lib/interfaces/RequestOptions';
|
|
@@ -25,7 +25,7 @@ describe('ListsClient', function () {
|
|
|
25
25
|
members_count: 1,
|
|
26
26
|
name: '123',
|
|
27
27
|
reply_preference: null
|
|
28
|
-
} as MailingList
|
|
28
|
+
} as MailingList;
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
afterEach(function () {
|
|
@@ -40,15 +40,14 @@ describe('ListsClient', function () {
|
|
|
40
40
|
items: lists
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
return client.list().then(function (
|
|
44
|
-
|
|
43
|
+
return client.list().then(function (listsRes: MailingList[]) {
|
|
44
|
+
listsRes[0].should.eql(defaultList);
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
describe('get', function () {
|
|
50
50
|
it('gets a specific mailing list', function () {
|
|
51
|
-
|
|
52
51
|
api.get('/v3/lists/testing.example.com').reply(200, {
|
|
53
52
|
list: defaultList
|
|
54
53
|
});
|
|
@@ -61,7 +60,6 @@ describe('ListsClient', function () {
|
|
|
61
60
|
|
|
62
61
|
describe('create', function () {
|
|
63
62
|
it('creates the list', function () {
|
|
64
|
-
|
|
65
63
|
api.post('/v3/lists').reply(200, {
|
|
66
64
|
list: defaultList
|
|
67
65
|
});
|