mailgun.js 12.3.0 → 12.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.
@@ -1,10 +1,11 @@
1
1
  import NavigationThruPages from './common/NavigationThruPages.js';
2
2
  import { EventsList, EventsQuery, EventsResponse } from '../Types/Events/index.js';
3
3
  import Request from './common/Request.js';
4
- import { IEventClient } from '../Interfaces/index.js';
4
+ import { IEventClient, ILogger } from '../Interfaces/index.js';
5
5
  export default class EventClient extends NavigationThruPages<EventsList> implements IEventClient {
6
6
  request: Request;
7
- constructor(request: Request);
7
+ private logger;
8
+ constructor(request: Request, logger?: ILogger);
8
9
  protected parseList(response: EventsResponse): EventsList;
9
10
  get(domain: string, query?: EventsQuery): Promise<EventsList>;
10
11
  }
@@ -0,0 +1,12 @@
1
+ import Request from '../common/Request.js';
2
+ import { LogsList, LogsQuery } from '../../Types/Logs/Logs.js';
3
+ import { ILogsClient } from '../../Interfaces/Logs/ILogsClient.js';
4
+ export default class LogsClient implements ILogsClient {
5
+ request: Request;
6
+ constructor(request: Request);
7
+ private parseListResponse;
8
+ private prepareDate;
9
+ private parseQuery;
10
+ private validateQuery;
11
+ list(queryData: LogsQuery): Promise<LogsList>;
12
+ }
@@ -1,6 +1,7 @@
1
1
  import Request from './common/Request.js';
2
2
  import { MailgunClientOptions, InputFormData } from '../Types/index.js';
3
3
  import { IDomainsClient, IWebHooksClient, IMailgunClient, IMailingListsClient, IEventClient, IStatsClient, ISuppressionClient, IMessagesClient, IRoutesClient, IValidationClient, IIPsClient, IIPPoolsClient, ISubaccountsClient, IInboxPlacementsClient, IMetricsClient } from '../Interfaces/index.js';
4
+ import { ILogsClient } from '../Interfaces/Logs/ILogsClient.js';
4
5
  export default class MailgunClient implements IMailgunClient {
5
6
  request: Request;
6
7
  domains: IDomainsClient;
@@ -17,6 +18,7 @@ export default class MailgunClient implements IMailgunClient {
17
18
  lists: IMailingListsClient;
18
19
  subaccounts: ISubaccountsClient;
19
20
  inboxPlacements: IInboxPlacementsClient;
21
+ logs: ILogsClient;
20
22
  constructor(options: MailgunClientOptions, formData: InputFormData);
21
23
  setSubaccount(subaccountId: string): void;
22
24
  resetSubaccount(): void;
@@ -0,0 +1,4 @@
1
+ import { LogsList, LogsQuery } from '../../Types/Logs/index.js';
2
+ export interface ILogsClient {
3
+ list(query: LogsQuery): Promise<LogsList>;
4
+ }
@@ -0,0 +1 @@
1
+ export * from './ILogsClient.js';
@@ -13,6 +13,7 @@ import { ISubaccountsClient } from '../Subaccounts/index.js';
13
13
  import { IInboxPlacementsClient } from '../InboxPlacements/index.js';
14
14
  import { IMetricsClient } from '../Metrics/MetricsClient.js';
15
15
  import type Request from '../../Classes/common/Request.js';
16
+ import { ILogsClient } from '../Logs/ILogsClient.js';
16
17
  export interface IMailgunClient {
17
18
  request: Request;
18
19
  domains: IDomainsClient;
@@ -31,4 +32,5 @@ export interface IMailgunClient {
31
32
  inboxPlacements: IInboxPlacementsClient;
32
33
  setSubaccount(subaccountId: string): void;
33
34
  resetSubaccount(): void;
35
+ logs: ILogsClient;
34
36
  }
@@ -10,6 +10,7 @@ import type { ValidationQuery } from '../Validations/index.js';
10
10
  import type { IpPoolDeleteData } from '../IPPools/index.js';
11
11
  import type { MetricsQuery } from '../Metrics/index.js';
12
12
  import type { FormDataInput } from './FormData.js';
13
+ import { LogsQuery } from '../Logs/Logs.js';
13
14
  export type OnCallEmptyHeaders = {
14
15
  [key: string]: undefined;
15
16
  };
@@ -36,7 +37,7 @@ export type GetQueryTypes = IPsListQuery | RoutesListQuery | SubaccountsQuery |
36
37
  searchParams?: Array<Array<string>>;
37
38
  } | ValidationQuery;
38
39
  export type DeleteQueryTypes = DeletedDomainKeysQuery;
39
- export type PostDataTypes = InboxPlacementsData | MetricsQuery | string;
40
+ export type PostDataTypes = InboxPlacementsData | MetricsQuery | LogsQuery | string;
40
41
  export type PutDataTypes = SeedsListsUpdatingData | object | FormDataInput | ConnectionSettings;
41
42
  export type RequestData = IpPoolDeleteData | PostDataTypes | PutDataTypes | NodeFormData | FormData;
42
43
  export type ContainsPrefix<T extends string> = `${T}${string}`;
@@ -0,0 +1,172 @@
1
+ export type LogsFilterValue = {
2
+ label: string;
3
+ value: string;
4
+ };
5
+ export type LogsFilter = {
6
+ AND: {
7
+ attribute: string;
8
+ comparator: string;
9
+ values: LogsFilterValue[];
10
+ }[];
11
+ };
12
+ export type LogsQuery = {
13
+ start?: Date;
14
+ end?: Date;
15
+ events?: string[];
16
+ 'metric_events'?: string[];
17
+ 'include_subaccounts'?: boolean;
18
+ 'include_totals'?: boolean;
19
+ pagination?: {
20
+ sort?: string;
21
+ token?: string;
22
+ limit?: number;
23
+ };
24
+ filter?: LogsFilter;
25
+ };
26
+ export type LogsParsedQuery = Omit<LogsQuery, 'start' | 'end'> & {
27
+ start?: string;
28
+ end?: string;
29
+ };
30
+ export type LogsDeliveryStatus = {
31
+ message?: string;
32
+ 'attempt-no'?: number;
33
+ 'code'?: number;
34
+ 'bounce-type'?: string;
35
+ description?: string;
36
+ 'session-seconds'?: number;
37
+ 'retry-seconds'?: number;
38
+ 'enhanced-code'?: string;
39
+ 'mx-host'?: string;
40
+ 'certificate-verified'?: boolean;
41
+ 'tls'?: boolean;
42
+ 'utf8'?: boolean;
43
+ 'first-delivery-attempt-seconds'?: number;
44
+ 'last-code'?: number;
45
+ 'last-message'?: string;
46
+ };
47
+ export type LogsEvent = {
48
+ id: string;
49
+ event: string;
50
+ '@timestamp': string;
51
+ account?: {
52
+ 'parent-id': string;
53
+ 'id': string;
54
+ };
55
+ campaigns?: {
56
+ id: string;
57
+ name: string;
58
+ }[];
59
+ tags?: string[];
60
+ method?: string;
61
+ 'originating-ip'?: string;
62
+ 'api-key-id'?: string;
63
+ 'delivery-status'?: LogsDeliveryStatus;
64
+ 'i-delivery-optimizer'?: string;
65
+ domain: {
66
+ name: string;
67
+ };
68
+ recipient?: string;
69
+ 'recipient-domain'?: string;
70
+ 'recipient-provider'?: string;
71
+ envelope?: {
72
+ sender?: string;
73
+ transport?: string;
74
+ 'sending-ip'?: string;
75
+ targets?: string;
76
+ 'i-ip-pool-id'?: string;
77
+ };
78
+ storage?: {
79
+ region?: string;
80
+ env?: string;
81
+ key?: string;
82
+ url?: string[];
83
+ };
84
+ template?: {
85
+ name?: string;
86
+ version?: string;
87
+ 'is-text'?: boolean;
88
+ };
89
+ 'log-level'?: string;
90
+ 'user-variables'?: string;
91
+ 'message'?: {
92
+ headers?: {
93
+ to: string;
94
+ 'message-id': string;
95
+ from: string;
96
+ subject: string;
97
+ };
98
+ attachments?: {
99
+ filename?: string;
100
+ 'content-type'?: string;
101
+ size?: number;
102
+ }[];
103
+ recipients?: string[];
104
+ size?: number;
105
+ 'scheduled-for'?: number;
106
+ };
107
+ flags?: {
108
+ 'is-authenticated': boolean;
109
+ 'is-system-test': boolean;
110
+ 'is-routed': boolean;
111
+ 'is-amp'?: boolean;
112
+ 'is-test-mode': boolean;
113
+ 'is-delayed-bounce': boolean;
114
+ 'is-callback': boolean;
115
+ 'is-encrypted': boolean;
116
+ };
117
+ 'primary-dkim'?: string;
118
+ ip?: string;
119
+ geolocation?: {
120
+ city?: string;
121
+ country?: string;
122
+ region?: string;
123
+ timezone?: string;
124
+ };
125
+ 'client-info'?: {
126
+ 'client-name'?: string;
127
+ 'client-os'?: string;
128
+ 'client-type'?: string;
129
+ 'device-type'?: string;
130
+ 'user-agent'?: string;
131
+ ip?: string;
132
+ bot?: string;
133
+ };
134
+ severity?: string;
135
+ reason?: string;
136
+ routes?: {
137
+ actions?: string;
138
+ description?: string;
139
+ expression?: string;
140
+ id?: string;
141
+ priority?: number;
142
+ match?: {
143
+ recipient?: string;
144
+ };
145
+ };
146
+ 'mailing-list'?: {
147
+ address?: string;
148
+ 'list-id'?: string;
149
+ sid?: string;
150
+ };
151
+ url?: string;
152
+ };
153
+ export type LogsEventItem = Omit<LogsEvent, '@timestamp'> & {
154
+ '@timestamp': Date;
155
+ };
156
+ export type LogsList = {
157
+ start: Date;
158
+ end: Date;
159
+ items: LogsEventItem[];
160
+ pagination: {
161
+ previous?: string;
162
+ first?: string;
163
+ last?: string;
164
+ next?: string;
165
+ total?: number;
166
+ };
167
+ aggregates: {
168
+ all: number;
169
+ metrics: object;
170
+ };
171
+ status: number;
172
+ };
@@ -0,0 +1 @@
1
+ export * from './Logs.js';
package/Types/index.js CHANGED
@@ -5216,9 +5216,11 @@ var NavigationThruPages = /** @class */ (function () {
5216
5216
 
5217
5217
  var EventClient = /** @class */ (function (_super) {
5218
5218
  __extends(EventClient, _super);
5219
- function EventClient(request) {
5219
+ function EventClient(request, logger) {
5220
+ if (logger === void 0) { logger = console; }
5220
5221
  var _this = _super.call(this, request) || this;
5221
5222
  _this.request = request;
5223
+ _this.logger = logger;
5222
5224
  return _this;
5223
5225
  }
5224
5226
  EventClient.prototype.parseList = function (response) {
@@ -5231,6 +5233,7 @@ var EventClient = /** @class */ (function (_super) {
5231
5233
  EventClient.prototype.get = function (domain, query) {
5232
5234
  return __awaiter(this, void 0, void 0, function () {
5233
5235
  return __generator(this, function (_a) {
5236
+ this.logger.warn('"events.get" method is deprecated. Please use "logs.list" instead');
5234
5237
  return [2 /*return*/, this.requestListWithPages(urljoin('/v3', domain, 'events'), query)];
5235
5238
  });
5236
5239
  });
@@ -7113,6 +7116,97 @@ var DomainKeysClient = /** @class */ (function (_super) {
7113
7116
  return DomainKeysClient;
7114
7117
  }(NavigationThruPages));
7115
7118
 
7119
+ var LogsClient = /** @class */ (function () {
7120
+ function LogsClient(request) {
7121
+ this.request = request;
7122
+ }
7123
+ LogsClient.prototype.parseListResponse = function (response) {
7124
+ var parsedResponse = {
7125
+ start: new Date(response.body.start),
7126
+ end: new Date(response.body.end),
7127
+ status: response.status,
7128
+ pagination: response.body.pagination,
7129
+ items: response.body.items.map(function (item) {
7130
+ var responseItem = __assign(__assign({}, item), { '@timestamp': new Date(item['@timestamp']) });
7131
+ return responseItem;
7132
+ }),
7133
+ aggregates: response.body.aggregates
7134
+ };
7135
+ return parsedResponse;
7136
+ };
7137
+ LogsClient.prototype.prepareDate = function (date) {
7138
+ // 'Wed, 03 Dec 2025 00:00:00 -0000'
7139
+ var formattedDate = "".concat(date.toUTCString().slice(0, 25), " -0000");
7140
+ return formattedDate;
7141
+ };
7142
+ LogsClient.prototype.parseQuery = function (queryData) {
7143
+ var res = __assign(__assign({}, queryData), { start: '', end: '' });
7144
+ if (queryData.start) {
7145
+ res.start = this.prepareDate(queryData.start);
7146
+ }
7147
+ if (queryData.end) {
7148
+ res.end = this.prepareDate(queryData.end);
7149
+ }
7150
+ return res;
7151
+ };
7152
+ LogsClient.prototype.validateQuery = function (queryData) {
7153
+ if (!queryData) {
7154
+ throw APIError.getUserDataError('Missed parameter "query"', '"logs.list": Query data is required');
7155
+ }
7156
+ if (queryData === null || queryData === void 0 ? void 0 : queryData.start) {
7157
+ if ((!((queryData === null || queryData === void 0 ? void 0 : queryData.start) instanceof Date) || Number.isNaN(queryData.start.getTime()))) {
7158
+ throw APIError.getUserDataError('Incorrect type', '"logs.list": Type of "start" must be valid JS Data object');
7159
+ }
7160
+ }
7161
+ else {
7162
+ throw APIError.getUserDataError('Missed property', '"logs.list": "start" property is required');
7163
+ }
7164
+ if (queryData === null || queryData === void 0 ? void 0 : queryData.end) {
7165
+ if ((!((queryData === null || queryData === void 0 ? void 0 : queryData.end) instanceof Date) || Number.isNaN(queryData.end.getTime()))) {
7166
+ throw APIError.getUserDataError('Incorrect type', '"logs.list": Type of "end" must be valid JS Data object');
7167
+ }
7168
+ }
7169
+ if (queryData.filter) {
7170
+ if (!queryData.filter.AND) {
7171
+ throw APIError.getUserDataError('Incorrect filter', '"logs.list": Logs filter must have AND operator');
7172
+ }
7173
+ if (!Array.isArray(queryData.filter.AND) || queryData.filter.AND.length === 0) {
7174
+ throw APIError.getUserDataError('Incorrect filter', '"logs.list": Logs filter AND operator must be an array');
7175
+ }
7176
+ queryData.filter.AND.forEach(function (condition) {
7177
+ if (!condition.attribute || !condition.comparator || !condition.values) {
7178
+ throw APIError.getUserDataError('Incorrect filter', '"logs.list": Each condition in Logs filter AND operator must have attribute, comparator and values');
7179
+ }
7180
+ if (!Array.isArray(condition.values) || condition.values.length === 0) {
7181
+ throw APIError.getUserDataError('Incorrect filter', '"logs.list": Values in each condition of Logs filter AND operator must be an array');
7182
+ }
7183
+ condition.values.forEach(function (value) {
7184
+ if (!value.label || !value.value) {
7185
+ throw APIError.getUserDataError('Incorrect filter', '"logs.list": Each value in Logs filter condition must have label and value');
7186
+ }
7187
+ });
7188
+ });
7189
+ }
7190
+ };
7191
+ LogsClient.prototype.list = function (queryData) {
7192
+ return __awaiter(this, void 0, void 0, function () {
7193
+ var preparedQuery, response;
7194
+ return __generator(this, function (_a) {
7195
+ switch (_a.label) {
7196
+ case 0:
7197
+ this.validateQuery(queryData);
7198
+ preparedQuery = this.parseQuery(queryData);
7199
+ return [4 /*yield*/, this.request.post(urljoin('/v1/analytics/logs'), preparedQuery)];
7200
+ case 1:
7201
+ response = _a.sent();
7202
+ return [2 /*return*/, this.parseListResponse(response)];
7203
+ }
7204
+ });
7205
+ });
7206
+ };
7207
+ return LogsClient;
7208
+ }());
7209
+
7116
7210
  var MailgunClient = /** @class */ (function () {
7117
7211
  function MailgunClient(options, formData) {
7118
7212
  var config = __assign({}, options);
@@ -7159,6 +7253,7 @@ var MailgunClient = /** @class */ (function () {
7159
7253
  this.validate = new ValidateClient(this.request, multipleValidationClient);
7160
7254
  this.subaccounts = new SubaccountsClient(this.request);
7161
7255
  this.inboxPlacements = new InboxPlacementsClient(this.request, seedsListsClient, inboxPlacementsResultsClient, inboxPlacementsProvidersClient);
7256
+ this.logs = new LogsClient(this.request);
7162
7257
  }
7163
7258
  MailgunClient.prototype.setSubaccount = function (subaccountId) {
7164
7259
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mailgun.js",
3
- "version": "12.3.0",
3
+ "version": "12.4.0",
4
4
  "author": "Mailgun",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/version.md CHANGED
@@ -1 +1 @@
1
- 12.3.0
1
+ 12.4.0