mailgun.js 5.0.0 → 5.0.1
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 +7 -0
- package/dist/mailgun.js.d.ts +79 -20
- 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/lib/domains.ts +1 -1
- package/lib/events.ts +4 -4
- package/lib/interfaces/Supressions.ts +61 -0
- package/lib/interfaces/Webhooks.ts +10 -0
- package/lib/stats.ts +3 -3
- package/lib/suppressions.ts +39 -18
- package/lib/webhooks.ts +7 -4
- package/package.json +1 -1
- package/tsconfig.json +2 -2
package/lib/domains.ts
CHANGED
|
@@ -208,7 +208,7 @@ export default class DomainClient {
|
|
|
208
208
|
|
|
209
209
|
updateDKIMAuthority(domain: string, data: DKIMAuthorityInfo): Promise<UpdatedDKIMAuthority> {
|
|
210
210
|
return this.request.put(`/v3/domains/${domain}/dkim_authority`, {}, { query: `self=${data.self}` })
|
|
211
|
-
.then((res : APIResponse) => res)
|
|
211
|
+
.then((res : APIResponse) => res as UpdatedDKIMAuthorityResponse)
|
|
212
212
|
.then((res : UpdatedDKIMAuthorityResponse) => res.body as UpdatedDKIMAuthority);
|
|
213
213
|
}
|
|
214
214
|
|
package/lib/events.ts
CHANGED
|
@@ -13,7 +13,7 @@ export default class EventClient {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
_parsePageNumber(url: string) : string {
|
|
16
|
-
return url.split('/').pop();
|
|
16
|
+
return url.split('/').pop() || '';
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
_parsePage(id: string, url: string) : EventsPage {
|
|
@@ -23,9 +23,9 @@ export default class EventClient {
|
|
|
23
23
|
_parsePageLinks(response: EventsResponse) : ParsedPagesList {
|
|
24
24
|
const pages = Object.entries(response.body.paging as PagesList);
|
|
25
25
|
return pages.reduce(
|
|
26
|
-
(acc: PagesListAccumulator,
|
|
27
|
-
const id =
|
|
28
|
-
const url =
|
|
26
|
+
(acc: PagesListAccumulator, pair: [url: string, id: string]) => {
|
|
27
|
+
const id = pair[0];
|
|
28
|
+
const url = pair[1];
|
|
29
29
|
acc[id] = this._parsePage(id, url);
|
|
30
30
|
return acc;
|
|
31
31
|
}, {}
|
|
@@ -23,3 +23,64 @@ export interface WhiteListData {
|
|
|
23
23
|
reason: string;
|
|
24
24
|
createdAt: string | Date;
|
|
25
25
|
}
|
|
26
|
+
|
|
27
|
+
export interface IBounce {
|
|
28
|
+
type: string;
|
|
29
|
+
address: string;
|
|
30
|
+
code: number;
|
|
31
|
+
error: string;
|
|
32
|
+
created_at: Date;
|
|
33
|
+
}
|
|
34
|
+
export interface IComplaint {
|
|
35
|
+
type: string;
|
|
36
|
+
address: any;
|
|
37
|
+
created_at: Date;
|
|
38
|
+
}
|
|
39
|
+
export interface IUnsubscribe {
|
|
40
|
+
type: string;
|
|
41
|
+
address: string;
|
|
42
|
+
tags: any;
|
|
43
|
+
created_at: Date;
|
|
44
|
+
}
|
|
45
|
+
export interface IWhiteList {
|
|
46
|
+
type: string;
|
|
47
|
+
value: string;
|
|
48
|
+
reason: string;
|
|
49
|
+
createdAt: Date;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ParsedPage {
|
|
53
|
+
id: string;
|
|
54
|
+
page: string | undefined;
|
|
55
|
+
address: string | undefined;
|
|
56
|
+
url: string
|
|
57
|
+
}
|
|
58
|
+
export interface ParsedPagesList {
|
|
59
|
+
previous: ParsedPage;
|
|
60
|
+
first: ParsedPage;
|
|
61
|
+
last: ParsedPage;
|
|
62
|
+
next: ParsedPage;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface SuppressionList {
|
|
66
|
+
items: IBounce[] | IComplaint[] | IUnsubscribe[] | IWhiteList[];
|
|
67
|
+
pages: ParsedPagesList;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface PagesList {
|
|
71
|
+
previous: string;
|
|
72
|
+
first: string;
|
|
73
|
+
last: string;
|
|
74
|
+
next: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export enum SuppressionModels {
|
|
78
|
+
BOUNCES = 'bounces',
|
|
79
|
+
COMPLAINTS = 'complaints',
|
|
80
|
+
UNSUBSCRIBES = 'unsubscribes',
|
|
81
|
+
WHITELISTS = 'whitelists'
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface PagesListAccumulator {
|
|
85
|
+
[index: string]: ParsedPage;
|
|
86
|
+
}
|
|
@@ -28,3 +28,13 @@ export interface ValidationResponse {
|
|
|
28
28
|
code: number;
|
|
29
29
|
message: string;
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
export enum WebhooksIds {
|
|
33
|
+
CLICKED = 'clicked',
|
|
34
|
+
COMPLAINED = 'complained',
|
|
35
|
+
DELIVERED = 'delivered',
|
|
36
|
+
OPENED = 'opened',
|
|
37
|
+
PERMANENT_FAIL = 'permanent_fail',
|
|
38
|
+
TEMPORARY_FAIL = 'temporary_fail',
|
|
39
|
+
UNSUBSCRIBED = 'unsubscribe',
|
|
40
|
+
}
|
package/lib/stats.ts
CHANGED
|
@@ -27,8 +27,8 @@ export default class StatsClient {
|
|
|
27
27
|
this.request = request;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
private prepareSearchParams(query: StatsQuery): Array<Array<string>> {
|
|
31
|
-
let searchParams = []
|
|
30
|
+
private prepareSearchParams(query: StatsQuery | undefined): Array<Array<string>> {
|
|
31
|
+
let searchParams = [] as Array<Array<string>>;
|
|
32
32
|
if (typeof query === 'object' && Object.keys(query).length) {
|
|
33
33
|
searchParams = Object.entries(query).reduce((arrayWithPairs, currentPair) => {
|
|
34
34
|
const [key, value] = currentPair;
|
|
@@ -38,7 +38,7 @@ export default class StatsClient {
|
|
|
38
38
|
}
|
|
39
39
|
arrayWithPairs.push([key, value]);
|
|
40
40
|
return arrayWithPairs;
|
|
41
|
-
}, []);
|
|
41
|
+
}, [] as Array<Array<string>>);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
return searchParams;
|
package/lib/suppressions.ts
CHANGED
|
@@ -6,6 +6,16 @@ import Request from './request';
|
|
|
6
6
|
import {
|
|
7
7
|
BounceData,
|
|
8
8
|
ComplaintData,
|
|
9
|
+
IBounce,
|
|
10
|
+
IComplaint,
|
|
11
|
+
IUnsubscribe,
|
|
12
|
+
IWhiteList,
|
|
13
|
+
PagesList,
|
|
14
|
+
PagesListAccumulator,
|
|
15
|
+
ParsedPage,
|
|
16
|
+
ParsedPagesList,
|
|
17
|
+
SuppressionList,
|
|
18
|
+
SuppressionModels,
|
|
9
19
|
UnsubscribeData,
|
|
10
20
|
WhiteListData
|
|
11
21
|
} from './interfaces/Supressions';
|
|
@@ -14,7 +24,7 @@ const createOptions = {
|
|
|
14
24
|
headers: { 'Content-Type': 'application/json' }
|
|
15
25
|
};
|
|
16
26
|
|
|
17
|
-
class Bounce {
|
|
27
|
+
class Bounce implements IBounce {
|
|
18
28
|
type: string;
|
|
19
29
|
address: string;
|
|
20
30
|
code: number;
|
|
@@ -30,7 +40,7 @@ class Bounce {
|
|
|
30
40
|
}
|
|
31
41
|
}
|
|
32
42
|
|
|
33
|
-
class Complaint {
|
|
43
|
+
class Complaint implements IComplaint {
|
|
34
44
|
type: string;
|
|
35
45
|
address: any;
|
|
36
46
|
created_at: Date;
|
|
@@ -42,7 +52,7 @@ class Complaint {
|
|
|
42
52
|
}
|
|
43
53
|
}
|
|
44
54
|
|
|
45
|
-
class Unsubscribe {
|
|
55
|
+
class Unsubscribe implements IUnsubscribe {
|
|
46
56
|
type: string;
|
|
47
57
|
address: string;
|
|
48
58
|
tags: any;
|
|
@@ -56,7 +66,7 @@ class Unsubscribe {
|
|
|
56
66
|
}
|
|
57
67
|
}
|
|
58
68
|
|
|
59
|
-
class WhiteList {
|
|
69
|
+
class WhiteList implements IWhiteList {
|
|
60
70
|
type: string;
|
|
61
71
|
value: string;
|
|
62
72
|
reason: string;
|
|
@@ -91,30 +101,34 @@ export default class SuppressionClient {
|
|
|
91
101
|
};
|
|
92
102
|
}
|
|
93
103
|
|
|
94
|
-
_parsePage(id: string, pageUrl: string) {
|
|
104
|
+
_parsePage(id: string, pageUrl: string) : ParsedPage {
|
|
95
105
|
const parsedUrl = url.parse(pageUrl, true);
|
|
96
106
|
const { query } = parsedUrl;
|
|
97
107
|
|
|
98
108
|
return {
|
|
99
109
|
id,
|
|
100
|
-
page: query.page,
|
|
101
|
-
address: query.address,
|
|
110
|
+
page: query.page as string,
|
|
111
|
+
address: query.address as string,
|
|
102
112
|
url: pageUrl
|
|
103
113
|
};
|
|
104
114
|
}
|
|
105
115
|
|
|
106
|
-
_parsePageLinks(response: { body: { paging: any } }) {
|
|
107
|
-
const pages = Object.entries(response.body.paging);
|
|
116
|
+
_parsePageLinks(response: { body: { paging: any } }): ParsedPagesList {
|
|
117
|
+
const pages = Object.entries(response.body.paging as PagesList);
|
|
108
118
|
return pages.reduce(
|
|
109
|
-
(acc:
|
|
119
|
+
(acc: PagesListAccumulator, pair: [pageUrl: string, id: string]) => {
|
|
120
|
+
const id = pair[0];
|
|
121
|
+
const pageUrl = pair[1];
|
|
110
122
|
acc[id] = this._parsePage(id, pageUrl);
|
|
111
123
|
return acc;
|
|
112
124
|
}, {}
|
|
113
|
-
);
|
|
125
|
+
) as unknown as ParsedPagesList;
|
|
114
126
|
}
|
|
115
127
|
|
|
116
|
-
_parseList(
|
|
117
|
-
|
|
128
|
+
_parseList(
|
|
129
|
+
response: { body: { items: any, paging: any } }, Model: TModel
|
|
130
|
+
): SuppressionList {
|
|
131
|
+
const data = {} as SuppressionList;
|
|
118
132
|
|
|
119
133
|
data.items = response.body.items.map((d: any) => new Model(d));
|
|
120
134
|
|
|
@@ -123,7 +137,10 @@ export default class SuppressionClient {
|
|
|
123
137
|
return data;
|
|
124
138
|
}
|
|
125
139
|
|
|
126
|
-
_parseItem(
|
|
140
|
+
_parseItem(
|
|
141
|
+
response: { body: any },
|
|
142
|
+
Model: TModel
|
|
143
|
+
): IBounce | IComplaint | IUnsubscribe | IWhiteList {
|
|
127
144
|
return new Model(response.body);
|
|
128
145
|
}
|
|
129
146
|
|
|
@@ -133,16 +150,20 @@ export default class SuppressionClient {
|
|
|
133
150
|
.then((response: { body: any }) => response.body);
|
|
134
151
|
}
|
|
135
152
|
|
|
136
|
-
list(domain: string, type:
|
|
137
|
-
const model = (this.models
|
|
153
|
+
list(domain: string, type: SuppressionModels, query: any) : Promise<SuppressionList> {
|
|
154
|
+
const model = (this.models)[type];
|
|
138
155
|
|
|
139
156
|
return this.request
|
|
140
157
|
.get(urljoin('v3', domain, type), query)
|
|
141
158
|
.then((response: { body: { items: any, paging: any } }) => this._parseList(response, model));
|
|
142
159
|
}
|
|
143
160
|
|
|
144
|
-
get(
|
|
145
|
-
|
|
161
|
+
get(
|
|
162
|
+
domain: string,
|
|
163
|
+
type: SuppressionModels,
|
|
164
|
+
address: string
|
|
165
|
+
): Promise<IBounce | IComplaint | IUnsubscribe | IWhiteList> {
|
|
166
|
+
const model = (this.models)[type];
|
|
146
167
|
|
|
147
168
|
return this.request
|
|
148
169
|
.get(urljoin('v3', domain, type, encodeURIComponent(address)))
|
package/lib/webhooks.ts
CHANGED
|
@@ -4,15 +4,16 @@ import {
|
|
|
4
4
|
ValidationResponse,
|
|
5
5
|
WebhookList,
|
|
6
6
|
WebhookResponse,
|
|
7
|
+
WebhooksIds,
|
|
7
8
|
WebhooksQuery
|
|
8
9
|
} from './interfaces/Webhooks';
|
|
9
10
|
import Request from './request';
|
|
10
11
|
|
|
11
12
|
class Webhook {
|
|
12
13
|
id: string;
|
|
13
|
-
url: string;
|
|
14
|
+
url: string | undefined;
|
|
14
15
|
|
|
15
|
-
constructor(id: string, url: string) {
|
|
16
|
+
constructor(id: string, url: string | undefined) {
|
|
16
17
|
this.id = id;
|
|
17
18
|
this.url = url;
|
|
18
19
|
}
|
|
@@ -34,7 +35,9 @@ export default class WebhookClient {
|
|
|
34
35
|
const webhookResponse = response?.body?.webhook;
|
|
35
36
|
let url = webhookResponse?.url;
|
|
36
37
|
if (!url) {
|
|
37
|
-
url = webhookResponse?.urls && webhookResponse.urls.length
|
|
38
|
+
url = webhookResponse?.urls && webhookResponse.urls.length
|
|
39
|
+
? webhookResponse.urls[0]
|
|
40
|
+
: undefined;
|
|
38
41
|
}
|
|
39
42
|
return new Webhook(id, url);
|
|
40
43
|
};
|
|
@@ -50,7 +53,7 @@ export default class WebhookClient {
|
|
|
50
53
|
.then(this._parseWebhookList);
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
get(domain: string, id:
|
|
56
|
+
get(domain: string, id: WebhooksIds): Promise<Webhook> {
|
|
54
57
|
return this.request.get(urljoin('/v3/domains', domain, 'webhooks', id))
|
|
55
58
|
.then(this._parseWebhookWithID(id));
|
|
56
59
|
}
|
package/package.json
CHANGED