mailgun.js 10.3.0 → 10.4.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 +13 -0
- package/Classes/MailgunClient.d.ts +2 -0
- package/Classes/Metrics/MetricsClient.d.ts +14 -0
- package/Interfaces/MailgunClient/IMailgunClient.d.ts +2 -0
- package/Interfaces/Metrics/MetricsClient.d.ts +5 -0
- package/README.md +144 -2
- package/Types/Metrics/Metrics.d.ts +100 -0
- package/Types/Metrics/MetricsAPI.d.ts +20 -0
- package/Types/Metrics/index.d.ts +2 -0
- package/mailgun.node.js +2 -2
- package/mailgun.node.js.LICENSE.txt +1 -1
- package/mailgun.web.js +2 -2
- package/mailgun.web.js.LICENSE.txt +1 -1
- package/package.json +1 -1
- package/version.md +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [10.4.0](https://github.com/mailgun/mailgun.js/compare/v10.3.0...v10.4.0) (2024-12-30)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* Add support for metrics ([de16ccd](https://github.com/mailgun/mailgun.js/commits/de16ccd9b8dfdab5ab6e87fb8eba44cef80dd1a5))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Other changes
|
|
14
|
+
|
|
15
|
+
* Add tests ([78f9990](https://github.com/mailgun/mailgun.js/commits/78f9990fe6e6972f52df1af8ad1e720110890aa7))
|
|
16
|
+
* Update readme ([a724689](https://github.com/mailgun/mailgun.js/commits/a7246892a24f98393453c6a0e53e8bdf4ec64fd8))
|
|
17
|
+
|
|
5
18
|
## [10.3.0](https://github.com/mailgun/mailgun.js/compare/v10.2.4...v10.3.0) (2024-12-23)
|
|
6
19
|
|
|
7
20
|
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { MailgunClientOptions, InputFormData } from '../Types';
|
|
2
2
|
import { IDomainsClient, IWebHooksClient, IMailgunClient, IMailingListsClient, IEventClient, IStatsClient, ISuppressionClient, IMessagesClient, IRoutesClient, IValidationClient, IIPsClient, IIPPoolsClient, ISubaccountsClient, IInboxPlacementsClient } from '../Interfaces';
|
|
3
|
+
import { IMetricsClient } from '../Interfaces/Metrics/MetricsClient';
|
|
3
4
|
export default class MailgunClient implements IMailgunClient {
|
|
4
5
|
private request;
|
|
5
6
|
domains: IDomainsClient;
|
|
6
7
|
webhooks: IWebHooksClient;
|
|
7
8
|
events: IEventClient;
|
|
8
9
|
stats: IStatsClient;
|
|
10
|
+
metrics: IMetricsClient;
|
|
9
11
|
suppressions: ISuppressionClient;
|
|
10
12
|
messages: IMessagesClient;
|
|
11
13
|
routes: IRoutesClient;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Request from '../common/Request';
|
|
2
|
+
import { ILogger } from '../../Interfaces/Common';
|
|
3
|
+
import { IMetricsClient } from '../../Interfaces/Metrics/MetricsClient';
|
|
4
|
+
import { MetricsQuery, MetricsResult } from '../../Types/Metrics';
|
|
5
|
+
export default class MetricsClient implements IMetricsClient {
|
|
6
|
+
request: Request;
|
|
7
|
+
private logger;
|
|
8
|
+
constructor(request: Request, logger?: ILogger);
|
|
9
|
+
private convertDateToUTC;
|
|
10
|
+
private prepareQuery;
|
|
11
|
+
private handleResponse;
|
|
12
|
+
getAccount(query?: MetricsQuery): Promise<MetricsResult>;
|
|
13
|
+
getAccountUsage(query?: MetricsQuery): Promise<MetricsResult>;
|
|
14
|
+
}
|
|
@@ -11,11 +11,13 @@ import { IIPPoolsClient } from '../IPPools';
|
|
|
11
11
|
import { IMailingListsClient } from '../MailingLists';
|
|
12
12
|
import { ISubaccountsClient } from '../Subaccounts';
|
|
13
13
|
import { IInboxPlacementsClient } from '../InboxPlacements';
|
|
14
|
+
import { IMetricsClient } from '../Metrics/MetricsClient';
|
|
14
15
|
export interface IMailgunClient {
|
|
15
16
|
domains: IDomainsClient;
|
|
16
17
|
webhooks: IWebHooksClient;
|
|
17
18
|
events: IEventClient;
|
|
18
19
|
stats: IStatsClient;
|
|
20
|
+
metrics: IMetricsClient;
|
|
19
21
|
suppressions: ISuppressionClient;
|
|
20
22
|
messages: IMessagesClient;
|
|
21
23
|
routes: IRoutesClient;
|
package/README.md
CHANGED
|
@@ -136,8 +136,12 @@ The following service methods are available to instantiated clients. The example
|
|
|
136
136
|
- [get](#get-1)
|
|
137
137
|
- [Example with Date and *Filter field*](#example-with-date-and-filter-field)
|
|
138
138
|
- [stats](#stats)
|
|
139
|
+
- [Stats Options](#stats-options)
|
|
139
140
|
- [getDomain](#getdomain)
|
|
140
141
|
- [getAccount](#getaccount)
|
|
142
|
+
- [Metrics](#metrics)
|
|
143
|
+
- [getAccount](#getaccount-1)
|
|
144
|
+
- [getAccountUsage](#getaccountusage)
|
|
141
145
|
- [suppressions](#suppressions)
|
|
142
146
|
- [list](#list-1)
|
|
143
147
|
- [Bounces Example](#bounces-example)
|
|
@@ -1023,7 +1027,7 @@ The following service methods are available to instantiated clients. The example
|
|
|
1023
1027
|
```
|
|
1024
1028
|
|
|
1025
1029
|
### Stats
|
|
1026
|
-
|
|
1030
|
+
- #### Stats Options
|
|
1027
1031
|
|
|
1028
1032
|
| Parameter | Description |
|
|
1029
1033
|
|:-----------|:---------------------------------------------------------------------------------------------------------------------------|
|
|
@@ -1110,6 +1114,145 @@ The following service methods are available to instantiated clients. The example
|
|
|
1110
1114
|
}
|
|
1111
1115
|
```
|
|
1112
1116
|
|
|
1117
|
+
|
|
1118
|
+
```
|
|
1119
|
+
|
|
1120
|
+
### Metrics
|
|
1121
|
+
Mailgun collects many different events and generates event metrics which are available in your Control Panel. This data is also available via our analytics metrics [API endpoint](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Metrics/#tag/Metrics).
|
|
1122
|
+
|
|
1123
|
+
- #### getAccount
|
|
1124
|
+
Gets filtered metrics for an account
|
|
1125
|
+
|
|
1126
|
+
`mg.metrics.getAccount(MetricsQuery);`
|
|
1127
|
+
|
|
1128
|
+
Example:
|
|
1129
|
+
```JS
|
|
1130
|
+
mg.metrics.getAccount({
|
|
1131
|
+
start: '2024-12-16T10:47:51.661Z',
|
|
1132
|
+
end: '2024-12-23T10:47:51.661Z',
|
|
1133
|
+
resolution: 'hour',
|
|
1134
|
+
metrics: ['opened_count'],
|
|
1135
|
+
filter: {
|
|
1136
|
+
AND: [{
|
|
1137
|
+
attribute: 'domain',
|
|
1138
|
+
comparator: 'contains',
|
|
1139
|
+
values: [{
|
|
1140
|
+
value: 'mailgun'
|
|
1141
|
+
}]
|
|
1142
|
+
}]
|
|
1143
|
+
},
|
|
1144
|
+
include_subaccounts: true,
|
|
1145
|
+
include_aggregates: true
|
|
1146
|
+
})
|
|
1147
|
+
.then(data => console.log(data)) // logs response data
|
|
1148
|
+
.catch(err => console.error(err)); //logs any error
|
|
1149
|
+
```
|
|
1150
|
+
*getAccount* method accepts data object with next properties:
|
|
1151
|
+
| Property | Type |Description |
|
|
1152
|
+
|:--------------|:-----|:-----------------------------------------------------------------------------------------------------------------------------------|
|
|
1153
|
+
| start | String that contains date in RFC 2822 format: https://datatracker.ietf.org/doc/html/rfc2822.html#page-14 or JS Date object | A start date (default: 7 days before current time)|
|
|
1154
|
+
| end | String that contains date in RFC 2822 format: https://datatracker.ietf.org/doc/html/rfc2822.html#page-14 or JS Date object | An end date (default: current time)|
|
|
1155
|
+
| resolution | String | A resolution in the format of 'day' 'hour' 'month'. Default is day.|
|
|
1156
|
+
| duration | String | A duration in the format of '1d' '2h' '2m'. If duration is provided then it is calculated from the end date and overwrites the start date.|
|
|
1157
|
+
| dimensions | Array of strings | Attributes of the metric data such as 'subaccount'.|
|
|
1158
|
+
| metrics | Array of strings | Name of the metrics to receive the stats for such as 'processed_count'.|
|
|
1159
|
+
| filter | object | Filters to apply to the query. The 'AND' property is required and should contains array of filters objects. See this [document](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Metrics/#tag/Metrics/operation/api.(*MetricsAPI).PostMetricQuery-fm-3!path=filter&t=request) for an object shape. |
|
|
1160
|
+
| include_subaccounts | Boolean | Include stats from all subaccounts. |
|
|
1161
|
+
| include_aggregates | Boolean | Include top-level aggregate metrics.|
|
|
1162
|
+
|
|
1163
|
+
Promise returns: MetricsResult
|
|
1164
|
+
|
|
1165
|
+
```JS
|
|
1166
|
+
{
|
|
1167
|
+
start: new Date('2024-12-16T01:00:00.000Z'),
|
|
1168
|
+
end: new Date('2024-12-23T00:00:00.000Z'),
|
|
1169
|
+
resolution: 'hour',
|
|
1170
|
+
dimensions: [ 'time' ],
|
|
1171
|
+
pagination: { sort: '', skip: 0, limit: 1500, total: 1 },
|
|
1172
|
+
items: [
|
|
1173
|
+
{
|
|
1174
|
+
dimensions: [{
|
|
1175
|
+
{
|
|
1176
|
+
dimension: 'time',
|
|
1177
|
+
value: 'Sat, 21 Dec 2024 17:00:00 +0000',
|
|
1178
|
+
display_value: 'Sat, 21 Dec 2024 17:00:00 +0000'
|
|
1179
|
+
}
|
|
1180
|
+
}],
|
|
1181
|
+
metrics: { opened_count: 1 }
|
|
1182
|
+
},
|
|
1183
|
+
...
|
|
1184
|
+
],
|
|
1185
|
+
aggregates: { metrics: { opened_count: 1 } },
|
|
1186
|
+
status: 200
|
|
1187
|
+
}
|
|
1188
|
+
```
|
|
1189
|
+
|
|
1190
|
+
- #### getAccountUsage
|
|
1191
|
+
Gets filtered **usage metrics** for an account
|
|
1192
|
+
`mg.metrics.getAccountUsage(MetricsQuery);`
|
|
1193
|
+
|
|
1194
|
+
Example:
|
|
1195
|
+
```JS
|
|
1196
|
+
mg.metrics.getAccountUsage({
|
|
1197
|
+
start: '2024-12-16T10:47:51.661Z',
|
|
1198
|
+
end: '2024-12-23T10:47:51.661Z',
|
|
1199
|
+
resolution: 'hour',
|
|
1200
|
+
metrics: ['opened_count'],
|
|
1201
|
+
filter: {
|
|
1202
|
+
AND: [{
|
|
1203
|
+
attribute: 'domain',
|
|
1204
|
+
comparator: 'contains',
|
|
1205
|
+
values: [{
|
|
1206
|
+
value: 'mailgun'
|
|
1207
|
+
}]
|
|
1208
|
+
}]
|
|
1209
|
+
},
|
|
1210
|
+
include_subaccounts: true,
|
|
1211
|
+
include_aggregates: true
|
|
1212
|
+
})
|
|
1213
|
+
.then(data => console.log(data)) // logs response data
|
|
1214
|
+
.catch(err => console.error(err)); //logs any error
|
|
1215
|
+
```
|
|
1216
|
+
*getAccountUsage* method accepts data object with next properties:
|
|
1217
|
+
| Property | Type |Description |
|
|
1218
|
+
|:--------------|:-----|:-----------------------------------------------------------------------------------------------------------------------------------|
|
|
1219
|
+
| start | String that contains date in RFC 2822 format: https://datatracker.ietf.org/doc/html/rfc2822.html#page-14 or JS Date object | A start date (default: 7 days before current time)|
|
|
1220
|
+
| end | String that contains date in RFC 2822 format: https://datatracker.ietf.org/doc/html/rfc2822.html#page-14 or JS Date object | An end date (default: current time)|
|
|
1221
|
+
| resolution | String | A resolution in the format of 'day' 'hour' 'month'. Default is day.|
|
|
1222
|
+
| duration | String | A duration in the format of '1d' '2h' '2m'. If duration is provided then it is calculated from the end date and overwrites the start date.|
|
|
1223
|
+
| dimensions | Array of strings | Attributes of the metric data such as 'subaccount'.|
|
|
1224
|
+
| metrics | Array of strings | Name of the metrics to receive the stats for such as 'processed_count'.|
|
|
1225
|
+
| filter | object | Filters to apply to the query. The 'AND' property is required and should contains array of filters objects. See this [document](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Metrics/#tag/Metrics/operation/api.(*MetricsAPI).PostMetricQuery-fm-3!path=filter&t=request) for an object shape. |
|
|
1226
|
+
| include_subaccounts | Boolean | Include stats from all subaccounts. |
|
|
1227
|
+
| include_aggregates | Boolean | Include top-level aggregate metrics.|
|
|
1228
|
+
|
|
1229
|
+
Promise returns: MetricsResult
|
|
1230
|
+
|
|
1231
|
+
```JS
|
|
1232
|
+
{
|
|
1233
|
+
start: new Date('2024-12-16T01:00:00.000Z'),
|
|
1234
|
+
end: new Date('2024-12-23T00:00:00.000Z'),
|
|
1235
|
+
resolution: 'hour',
|
|
1236
|
+
dimensions: [ 'time' ],
|
|
1237
|
+
pagination: { sort: '', skip: 0, limit: 1500, total: 1 },
|
|
1238
|
+
items: [
|
|
1239
|
+
{
|
|
1240
|
+
dimensions: [{
|
|
1241
|
+
{
|
|
1242
|
+
dimension: 'time',
|
|
1243
|
+
value: 'Sat, 21 Dec 2024 17:00:00 +0000',
|
|
1244
|
+
display_value: 'Sat, 21 Dec 2024 17:00:00 +0000'
|
|
1245
|
+
}
|
|
1246
|
+
}],
|
|
1247
|
+
metrics: { opened_count: 1 }
|
|
1248
|
+
},
|
|
1249
|
+
...
|
|
1250
|
+
],
|
|
1251
|
+
aggregates: { metrics: { opened_count: 1 } },
|
|
1252
|
+
status: 200
|
|
1253
|
+
}
|
|
1254
|
+
```
|
|
1255
|
+
|
|
1113
1256
|
### Suppressions
|
|
1114
1257
|
|
|
1115
1258
|
- #### list
|
|
@@ -3165,7 +3308,6 @@ A client to manage members within a specific mailing list.
|
|
|
3165
3308
|
results: 'link to result page',
|
|
3166
3309
|
}
|
|
3167
3310
|
}
|
|
3168
|
-
```
|
|
3169
3311
|
|
|
3170
3312
|
## Navigation thru lists
|
|
3171
3313
|
Most of the methods that return items in a list support pagination.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Resolution } from '../../Enums';
|
|
2
|
+
export type MetricsFilterValue = {
|
|
3
|
+
label?: string;
|
|
4
|
+
value: string;
|
|
5
|
+
};
|
|
6
|
+
export type MetricsFilter = {
|
|
7
|
+
attribute: string;
|
|
8
|
+
comparator: string;
|
|
9
|
+
values: MetricsFilterValue[];
|
|
10
|
+
};
|
|
11
|
+
export type MetricsQuery = {
|
|
12
|
+
start?: Date | string;
|
|
13
|
+
end?: Date | string;
|
|
14
|
+
resolution?: Resolution;
|
|
15
|
+
duration?: string;
|
|
16
|
+
dimensions?: string[];
|
|
17
|
+
metrics?: string[];
|
|
18
|
+
filter?: {
|
|
19
|
+
AND: MetricsFilter[];
|
|
20
|
+
};
|
|
21
|
+
include_subaccounts?: boolean;
|
|
22
|
+
include_aggregates?: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type Metrics = {
|
|
25
|
+
accepted_outgoing_count?: number;
|
|
26
|
+
delivered_smtp_count?: number;
|
|
27
|
+
accepted_count?: number;
|
|
28
|
+
delivered_http_count?: number;
|
|
29
|
+
accepted_incoming_count?: number;
|
|
30
|
+
delivered_optimized_count?: number;
|
|
31
|
+
stored_count?: number;
|
|
32
|
+
delivered_count?: number;
|
|
33
|
+
processed_count?: number;
|
|
34
|
+
sent_count?: number;
|
|
35
|
+
opened_count?: number;
|
|
36
|
+
unique_opened_count?: number;
|
|
37
|
+
clicked_count?: number;
|
|
38
|
+
unique_clicked_count?: number;
|
|
39
|
+
complained_count?: number;
|
|
40
|
+
permanent_failed_count?: number;
|
|
41
|
+
failed_count?: number;
|
|
42
|
+
rate_limit_count?: number;
|
|
43
|
+
unsubscribed_count?: number;
|
|
44
|
+
temporary_failed_count?: number;
|
|
45
|
+
permanent_failed_optimized_count?: number;
|
|
46
|
+
bounced_count?: number;
|
|
47
|
+
esp_block_count?: number;
|
|
48
|
+
webhook_count?: number;
|
|
49
|
+
delayed_bounce_count?: number;
|
|
50
|
+
soft_bounces_count?: number;
|
|
51
|
+
permanent_failed_old_count?: number;
|
|
52
|
+
suppressed_bounces_count?: number;
|
|
53
|
+
delivered_subsequent_count?: number;
|
|
54
|
+
delivered_rate?: string;
|
|
55
|
+
delayed_first_attempt_count?: number;
|
|
56
|
+
unsubscribed_rate?: string;
|
|
57
|
+
delivered_first_attempt_count?: number;
|
|
58
|
+
opened_rate?: string;
|
|
59
|
+
suppressed_complaints_count?: number;
|
|
60
|
+
delivered_two_plus_attempts_count?: number;
|
|
61
|
+
hard_bounces_count?: number;
|
|
62
|
+
suppressed_unsubscribed_count?: number;
|
|
63
|
+
unique_opened_rate?: string;
|
|
64
|
+
fail_rate?: string;
|
|
65
|
+
complained_rate?: string;
|
|
66
|
+
clicked_rate?: string;
|
|
67
|
+
unique_clicked_rate?: string;
|
|
68
|
+
bounce_rate?: string;
|
|
69
|
+
delayed_rate?: string;
|
|
70
|
+
permanent_fail_rate?: string;
|
|
71
|
+
temporary_fail_rate?: string;
|
|
72
|
+
};
|
|
73
|
+
export type MetricsPagination = {
|
|
74
|
+
sort: string;
|
|
75
|
+
skip: number;
|
|
76
|
+
limit: number;
|
|
77
|
+
total: number;
|
|
78
|
+
};
|
|
79
|
+
export type MetricsDimension = {
|
|
80
|
+
dimension: string;
|
|
81
|
+
value: string;
|
|
82
|
+
display_value: string;
|
|
83
|
+
};
|
|
84
|
+
export type MetricsResponseItem = {
|
|
85
|
+
dimensions: MetricsDimension[];
|
|
86
|
+
metrics: Metrics;
|
|
87
|
+
};
|
|
88
|
+
export type MetricsResult = {
|
|
89
|
+
items: MetricsResponseItem[];
|
|
90
|
+
resolution: string;
|
|
91
|
+
start: Date | null;
|
|
92
|
+
aggregates: {
|
|
93
|
+
metrics: Metrics;
|
|
94
|
+
};
|
|
95
|
+
dimensions: string[];
|
|
96
|
+
pagination: MetricsPagination;
|
|
97
|
+
end: Date | null;
|
|
98
|
+
duration?: string;
|
|
99
|
+
status: number;
|
|
100
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Metrics, MetricsPagination, MetricsQuery, MetricsResponseItem } from './Metrics';
|
|
2
|
+
export type MetricsAPIQuery = Omit<MetricsQuery, 'start' | 'end'> & {
|
|
3
|
+
start?: string;
|
|
4
|
+
end?: string;
|
|
5
|
+
};
|
|
6
|
+
export type MetricsAPIResponse = {
|
|
7
|
+
status: number;
|
|
8
|
+
body: {
|
|
9
|
+
items: MetricsResponseItem[];
|
|
10
|
+
resolution: string;
|
|
11
|
+
start: string;
|
|
12
|
+
aggregates: {
|
|
13
|
+
metrics: Metrics;
|
|
14
|
+
};
|
|
15
|
+
dimensions: string[];
|
|
16
|
+
pagination: MetricsPagination;
|
|
17
|
+
end: string;
|
|
18
|
+
duration?: string;
|
|
19
|
+
};
|
|
20
|
+
};
|