mailgun.js 9.2.1 → 9.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 CHANGED
@@ -2,6 +2,36 @@
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
+ ## [9.4.0](https://github.com/mailgun/mailgun.js/compare/v9.3.0...v9.4.0) (2023-12-13)
6
+
7
+
8
+ ### Features
9
+
10
+ * Add subaccounts ([3ca1d56](https://github.com/mailgun/mailgun.js/commits/3ca1d56955f7651bcba758c75cdbee3be48d5748))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **deps-dev:** bump @babel/traverse from 7.22.5 to 7.23.2 ([53f3e8f](https://github.com/mailgun/mailgun.js/commits/53f3e8fd673857b75ab0844bb1e04e016dad6ed5))
16
+ * **deps:** bump axios from 1.3.3 to 1.6.0 ([729032d](https://github.com/mailgun/mailgun.js/commits/729032d7a19ec307255c401bd698f5e7835925fb))
17
+
18
+
19
+ ### Other changes
20
+
21
+ * Update the formatting, merge headers to avoid overriding ([6e46eca](https://github.com/mailgun/mailgun.js/commits/6e46ecac1742660673931a99735988e4ffb046ce))
22
+
23
+ ## [9.3.0](https://github.com/mailgun/mailgun.js/compare/v9.2.1...v9.3.0) (2023-09-18)
24
+
25
+
26
+ ### Features
27
+
28
+ * Update webhook.update method to allow multiple URLs ([633bce9](https://github.com/mailgun/mailgun.js/commits/633bce9f2a7a704972251af16aeafdc73d5cbbde))
29
+
30
+
31
+ ### Other changes
32
+
33
+ * Update docs ([3a3b8d8](https://github.com/mailgun/mailgun.js/commits/3a3b8d8a9ced9f6a2d63ce42010980d20cfaf815))
34
+
5
35
  ### [9.2.1](https://github.com/mailgun/mailgun.js/compare/v9.2.0...v9.2.1) (2023-08-16)
6
36
 
7
37
 
@@ -1,6 +1,5 @@
1
- import { MailgunClientOptions } from '../Types/MailgunClient';
2
- import { InputFormData } from '../Types/Common';
3
- import { IDomainsClient, IWebHooksClient, IMailgunClient, IMailingListsClient, IEventClient, IStatsClient, ISuppressionClient, IMessagesClient, IRoutesClient, IValidationClient, IIPsClient, IIPPoolsClient } from '../Interfaces';
1
+ import { MailgunClientOptions, InputFormData } from '../Types';
2
+ import { IDomainsClient, IWebHooksClient, IMailgunClient, IMailingListsClient, IEventClient, IStatsClient, ISuppressionClient, IMessagesClient, IRoutesClient, IValidationClient, IIPsClient, IIPPoolsClient, ISubaccountsClient } from '../Interfaces';
4
3
  export default class MailgunClient implements IMailgunClient {
5
4
  private request;
6
5
  domains: IDomainsClient;
@@ -14,5 +13,8 @@ export default class MailgunClient implements IMailgunClient {
14
13
  ips: IIPsClient;
15
14
  ip_pools: IIPPoolsClient;
16
15
  lists: IMailingListsClient;
16
+ subaccounts: ISubaccountsClient;
17
17
  constructor(options: MailgunClientOptions, formData: InputFormData);
18
+ setSubaccount(subaccountId: string): void;
19
+ resetSubaccount(): void;
18
20
  }
@@ -1,4 +1,4 @@
1
- import { MailgunMessageData, MessagesSendAPIResponse, MessagesSendResult } from '../Types/Messages';
1
+ import { MailgunMessageData, MessagesSendAPIResponse, MessagesSendResult } from '../Types';
2
2
  import Request from './common/Request';
3
3
  import { IMessagesClient } from '../Interfaces';
4
4
  export default class MessagesClient implements IMessagesClient {
@@ -0,0 +1,13 @@
1
+ import Request from './common/Request';
2
+ import { ISubaccountsClient } from '../Interfaces';
3
+ import { SubaccountListResponseData, SubaccountResponseData, SubaccountsQuery } from '../Types';
4
+ export default class SubaccountsClient implements ISubaccountsClient {
5
+ request: Request;
6
+ static SUBACCOUNT_HEADER: string;
7
+ constructor(request: Request);
8
+ list(query?: SubaccountsQuery): Promise<SubaccountListResponseData>;
9
+ get(id: string): Promise<SubaccountResponseData>;
10
+ create(name: string): Promise<SubaccountResponseData>;
11
+ enable(id: string): Promise<SubaccountResponseData>;
12
+ disable(id: string): Promise<SubaccountResponseData>;
13
+ }
@@ -5,7 +5,8 @@ import Request from './common/Request';
5
5
  export declare class Webhook implements WebhookResult {
6
6
  id: string;
7
7
  url: string | undefined;
8
- constructor(id: string, url: string | undefined);
8
+ urls: string[];
9
+ constructor(id: string, url: string | undefined, urls: string[]);
9
10
  }
10
11
  export default class WebhooksClient implements IWebHooksClient {
11
12
  request: Request;
@@ -16,6 +17,6 @@ export default class WebhooksClient implements IWebHooksClient {
16
17
  list(domain: string, query: WebhooksQuery): Promise<WebhookList>;
17
18
  get(domain: string, id: WebhooksIds): Promise<WebhookResult>;
18
19
  create(domain: string, id: string, url: string, test?: boolean): Promise<WebhookResult | WebhookValidationResponse>;
19
- update(domain: string, id: string, url: string): Promise<WebhookResult>;
20
+ update(domain: string, id: string, urlValues: string | string[]): Promise<WebhookResult>;
20
21
  destroy(domain: string, id: string): Promise<WebhookResult>;
21
22
  }
@@ -1,6 +1,5 @@
1
1
  import * as NodeFormData from 'form-data';
2
- import { RequestOptions, InputFormData, APIResponse } from '../../Types/Common';
3
- import { IpPoolDeleteData } from '../../Types/IPPools';
2
+ import { RequestOptions, InputFormData, APIResponse, IpPoolDeleteData } from '../../Types';
4
3
  declare class Request {
5
4
  private username;
6
5
  private key;
@@ -14,6 +13,8 @@ declare class Request {
14
13
  private getResponseBody;
15
14
  private joinAndTransformHeaders;
16
15
  private makeHeadersFromObject;
16
+ setSubaccountHeader(subaccountId: string): void;
17
+ resetSubaccountHeader(): void;
17
18
  query(method: string, url: string, query?: Record<string, unknown> | Array<Array<string>>, options?: Record<string, unknown>): Promise<APIResponse>;
18
19
  command(method: string, url: string, data?: Record<string, unknown> | Record<string, unknown>[] | string | NodeFormData | FormData, options?: Record<string, unknown>, addDefaultHeaders?: boolean): Promise<APIResponse>;
19
20
  get(url: string, query?: Record<string, unknown> | Array<Array<string>>, options?: Record<string, unknown>): Promise<APIResponse>;
@@ -9,6 +9,7 @@ import { IValidationClient } from '../Validations';
9
9
  import { IIPsClient } from '../IPs';
10
10
  import { IIPPoolsClient } from '../IPPools';
11
11
  import { IMailingListsClient } from '../MailingLists';
12
+ import { ISubaccountsClient } from '../Subaccounts';
12
13
  export interface IMailgunClient {
13
14
  domains: IDomainsClient;
14
15
  webhooks: IWebHooksClient;
@@ -21,4 +22,7 @@ export interface IMailgunClient {
21
22
  ips: IIPsClient;
22
23
  ip_pools: IIPPoolsClient;
23
24
  lists: IMailingListsClient;
25
+ subaccounts: ISubaccountsClient;
26
+ setSubaccount(subaccountId: string): void;
27
+ resetSubaccount(): void;
24
28
  }
@@ -0,0 +1,8 @@
1
+ import { SubaccountListResponseData, SubaccountResponseData, SubaccountsQuery } from '../../Types';
2
+ export interface ISubaccountsClient {
3
+ list(query?: SubaccountsQuery): Promise<SubaccountListResponseData>;
4
+ get(id: string): Promise<SubaccountResponseData>;
5
+ create(name: string): Promise<SubaccountResponseData>;
6
+ disable(id: string): Promise<SubaccountResponseData>;
7
+ enable(id: string): Promise<SubaccountResponseData>;
8
+ }
@@ -0,0 +1 @@
1
+ export * from './ISubaccountsClient';
@@ -4,6 +4,6 @@ export interface IWebHooksClient {
4
4
  list(domain: string, query: WebhooksQuery): Promise<WebhookList>;
5
5
  get(domain: string, id: WebhooksIds): Promise<WebhookResult>;
6
6
  create(domain: string, id: string, url: string, test: boolean): Promise<WebhookResult | WebhookValidationResponse>;
7
- update(domain: string, id: string, url: string): Promise<WebhookResult>;
7
+ update(domain: string, id: string, url: string | string[]): Promise<WebhookResult>;
8
8
  destroy(domain: string, id: string): Promise<WebhookResult>;
9
9
  }
@@ -11,3 +11,4 @@ export * from './Messages';
11
11
  export * from './Routes';
12
12
  export * from './IPs';
13
13
  export * from './IPPools';
14
+ export * from './Subaccounts';
package/README.md CHANGED
@@ -10,6 +10,7 @@ __Table of Contents__
10
10
  - [Install](#install)
11
11
  - [Setup Client](#setup-client)
12
12
  - [Available Imports](#imports)
13
+ - [Using Subaccounts](#using-subaccounts)
13
14
  - [Types imports](#types-imports)
14
15
  - [Interfaces and Enums imports](#interfaces-and-enums-imports)
15
16
  - [Generated docs](#generated-docs)
@@ -56,6 +57,17 @@ Once the package is installed, you can import the library using `import` or `req
56
57
  const mailgun = new Mailgun(FormData);
57
58
  const mg = mailgun.client({username: 'api', key: process.env.MAILGUN_API_KEY || 'key-yourkeyhere'});
58
59
  ```
60
+ ### Using Subaccounts
61
+ Primary accounts can make API calls on behalf of their subaccounts. [API documentation](https://documentation.mailgun.com/en/latest/subaccounts.html#subaccounts)
62
+ ```js
63
+ import * as FormData from 'form-data';
64
+ import Mailgun from 'mailgun.js';
65
+ const mailgun = new Mailgun(FormData);
66
+ const mg = mailgun.client({username: 'api', key: process.env.MAILGUN_API_KEY || 'key-yourkeyhere'});
67
+ mg.setSubaccount('subaccount-id');
68
+ // then, if you need to reset it back to the primary account:
69
+ mg.resetSubaccount();
70
+ ```
59
71
  ### Types imports
60
72
  Starting from version **9.0.0.** Types can be includes as named import:
61
73
  ```TS
@@ -152,6 +164,12 @@ The following service methods are available to instantiated clients. The example
152
164
  - [createMembers](#createmembers)
153
165
  - [updateMember](#updatemember)
154
166
  - [destroyMember](#destroymember)
167
+ - [subaccounts](#subaccounts)
168
+ - [list](#list-6)
169
+ - [get](#get-8)
170
+ - [create](#create-7)
171
+ - [enable](#enable)
172
+ - [disable](#disable)
155
173
  - [Navigation thru lists](#navigation-thru-lists)
156
174
  - [Browser Demo](#browser-demo)
157
175
  - [Development](#development)
@@ -1335,7 +1353,7 @@ Method naming conventions:
1335
1353
 
1336
1354
  ```JS
1337
1355
  {
1338
- 'open': { 'url': 'http://requestb.in' }
1356
+ 'open': { 'url': 'http://requestb.in', 'urls': ['trackclick.com'] }
1339
1357
  }
1340
1358
  ```
1341
1359
 
@@ -1355,7 +1373,7 @@ Method naming conventions:
1355
1373
 
1356
1374
  ```JS
1357
1375
  {
1358
- 'open': { 'url': 'http://requestb.in' }
1376
+ 'open': { 'url': 'http://requestb.in', 'urls': ['http://requestb.in'] }
1359
1377
  }
1360
1378
  ```
1361
1379
 
@@ -1392,10 +1410,24 @@ Method naming conventions:
1392
1410
 
1393
1411
  ```JS
1394
1412
  {
1395
- 'open': { 'url': 'http://requestb.in' }
1413
+ 'open': { 'url': 'http://requestb.in', 'urls': ['http://requestb.in'] }
1396
1414
  }
1397
1415
  ```
1398
1416
 
1417
+ ```js
1418
+ mg.webhooks.update('foobar.example.com', 'open', ['http://requestb.in', 'http://requestb1.in' ]) // bounce, deliver, drop, spam, unsubscribe, click, open
1419
+ .then(msg => console.log(msg)) // logs response data
1420
+ .catch(err => console.error(err)); // logs any error
1421
+ ```
1422
+
1423
+ Promise returns:
1424
+ ```JS
1425
+ {
1426
+ 'open': { 'url': 'http://requestb.in', 'urls': ['http://requestb.in', 'http://requestb1.in'] }
1427
+ }
1428
+ ```
1429
+
1430
+
1399
1431
  - #### destroy
1400
1432
 
1401
1433
  `mg.webhooks.destroy(domain, id)`
@@ -1412,7 +1444,7 @@ Method naming conventions:
1412
1444
 
1413
1445
  ```JS
1414
1446
  {
1415
- 'open': { 'url': 'http://requestb.in' }
1447
+ 'open': { 'url': 'http://requestb.in', 'urls': ['http://requestb.in']}
1416
1448
  }
1417
1449
  ```
1418
1450
 
@@ -2030,6 +2062,115 @@ A client to manage members within a specific mailing list.
2030
2062
  message: 'Mailing list member has been deleted'
2031
2063
  }
2032
2064
  ```
2065
+ ### Subaccounts
2066
+
2067
+ A client to manage subaccounts.
2068
+
2069
+ - #### list
2070
+
2071
+ `mg.subaccounts.list(query)` - [api docs](https://documentation.mailgun.com/en/latest/subaccounts.html)
2072
+
2073
+ Example:
2074
+
2075
+ ```js
2076
+ mg.subaccounts.list()
2077
+ .then(subaccounts => console.log(subaccounts)) // logs array of subaccounts
2078
+ .catch(err => console.error(err)); // logs any error
2079
+ ```
2080
+
2081
+ Promise returns: array of Subaccounts instances
2082
+
2083
+ ```JS
2084
+ [
2085
+ { id: "XYZ", name: "test.subaccount1", status: "open" },
2086
+ { id: "YYY", name: "test.subaccount2", status: "open" }
2087
+ ]
2088
+ ```
2089
+
2090
+ Query data may have next properties:
2091
+
2092
+ | Property | Description |
2093
+ |:---------|:-----------------------------------------------------------------------|
2094
+ | limit | Maximum number of records to return. (10 by default) |
2095
+ | skip | Number of records to skip. (0 by default) |
2096
+ | sort | "asc" or "desc". |
2097
+ | enabled | Returns all enabled/disabled subaccounts. (Defaults to all if omitted) |
2098
+
2099
+ - #### get
2100
+
2101
+ `mg.subaccounts.get(subaccount_id)`
2102
+
2103
+ Example:
2104
+
2105
+ ```JS
2106
+ mg.subaccounts.get('123')
2107
+ .then(subaccount => console.log(subaccount)) // logs subaccount object
2108
+ .catch(err => console.error(err)); // logs any error
2109
+ ```
2110
+
2111
+ Promise returns: Subaccount instance
2112
+
2113
+ ```JS
2114
+ { id: "123", name: "test.subaccount1", status: "open" }
2115
+ ```
2116
+
2117
+ - #### create
2118
+
2119
+ `mg.subaccounts.create(name)`
2120
+
2121
+ Example:
2122
+
2123
+ ```js
2124
+ mg.subaccounts.create('foobar')
2125
+ .then(msg => console.log(msg)) // logs response data
2126
+ .catch(err => console.error(err)); // logs any error
2127
+ ```
2128
+
2129
+ Promise returns: Subaccount instance
2130
+
2131
+ ```JS
2132
+ { id: "123", name: "foobar", status: "open" }
2133
+ ```
2134
+
2135
+ Create method accepts data object with next properties:
2136
+
2137
+ | Parameter | Description |
2138
+ |-------------|-----------------------------------------------------------|
2139
+ | name | Name of the subaccount being created (ex. 'mysubaccount') |
2140
+
2141
+ - #### enable
2142
+
2143
+ `mg.subaccounts.enable(subaccount_id)`
2144
+
2145
+ Example:
2146
+
2147
+ ```js
2148
+ mg.subaccounts.enable('123')
2149
+ .then(msg => console.log(msg)) // logs response data
2150
+ .catch(err => console.error(err)); // logs any error
2151
+ ```
2152
+ Promise returns: Subaccount instance
2153
+
2154
+ ```JS
2155
+ { id: "123", name: "foobar", status: "open" }
2156
+ ```
2157
+
2158
+ - #### disable
2159
+
2160
+ `mg.subaccounts.disable(subaccount_id)`
2161
+
2162
+ Example:
2163
+
2164
+ ```js
2165
+ mg.subaccounts.disable('123')
2166
+ .then(msg => console.log(msg)) // logs response data
2167
+ .catch(err => console.error(err)); // logs any error
2168
+ ```
2169
+ Promise returns: Subaccount instance
2170
+
2171
+ ```JS
2172
+ { id: "123", name: "foobar", status: "disabled" }
2173
+ ```
2033
2174
 
2034
2175
  ## Navigation thru lists
2035
2176
  Most of the methods that return items in a list support pagination.
@@ -2197,7 +2338,6 @@ A client to manage members within a specific mailing list.
2197
2338
  );
2198
2339
  ```
2199
2340
 
2200
-
2201
2341
  ## Browser Demo
2202
2342
 
2203
2343
  ![image](https://cloud.githubusercontent.com/assets/399776/10718632/e8fe56e4-7b34-11e5-84c8-cfcfde978711.png)
@@ -0,0 +1,18 @@
1
+ export type SubaccountsQuery = {
2
+ enabled?: boolean;
3
+ limit?: number;
4
+ skip?: number;
5
+ sort?: 'asc' | 'desc';
6
+ };
7
+ export type SubaccountListItem = {
8
+ id: string;
9
+ name: string;
10
+ status: string;
11
+ };
12
+ export type SubaccountListResponseData = {
13
+ subaccounts: SubaccountListItem[];
14
+ total: number;
15
+ };
16
+ export type SubaccountResponseData = {
17
+ subaccount: SubaccountListItem;
18
+ };
@@ -0,0 +1 @@
1
+ export * from './Subaccounts';
@@ -25,5 +25,9 @@ export type WebhookValidationResponse = {
25
25
  };
26
26
  export type WebhookResult = {
27
27
  id: string;
28
+ /**
29
+ * @deprecated url property is deprecated. Use "urls" instead.
30
+ */
28
31
  url: string | undefined;
32
+ urls: string[];
29
33
  };
package/Types/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export * from './MailingLists';
8
8
  export * from './Messages';
9
9
  export * from './Routes';
10
10
  export * from './Stats';
11
+ export * from './Subaccounts';
11
12
  export * from './Suppressions';
12
13
  export * from './Validations';
13
14
  export * from './Webhooks';
package/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { IMailgunClient } from './Interfaces';
2
- import { InputFormData } from './Types/Common';
3
- import { MailgunClientOptions } from './Types/MailgunClient';
2
+ import { InputFormData, MailgunClientOptions } from './Types';
4
3
  export * as Enums from './Enums';
5
4
  export * from './Types';
6
5
  export * as Interfaces from './Interfaces';