mailgun.js 3.5.9 → 3.7.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.
Files changed (75) hide show
  1. package/.eslintrc +27 -11
  2. package/CHANGELOG.md +30 -0
  3. package/commitlint.config.js +1 -2
  4. package/dist/index.d.ts +2 -2
  5. package/dist/lib/client.d.ts +2 -2
  6. package/dist/lib/events.d.ts +9 -25
  7. package/dist/lib/interfaces/APIErrorOptions.d.ts +2 -1
  8. package/dist/lib/interfaces/ApiResponse.d.ts +2 -1
  9. package/dist/lib/interfaces/Events.d.ts +24 -0
  10. package/dist/lib/interfaces/IFormData.d.ts +4 -12
  11. package/dist/lib/interfaces/IpPools.d.ts +12 -0
  12. package/dist/lib/interfaces/Options.d.ts +2 -1
  13. package/dist/lib/interfaces/RequestOptions.d.ts +2 -1
  14. package/dist/lib/interfaces/StatsOptions.d.ts +2 -1
  15. package/dist/lib/interfaces/mailListMembers.d.ts +6 -6
  16. package/dist/lib/ip-pools.d.ts +11 -14
  17. package/dist/lib/ips.d.ts +6 -6
  18. package/dist/lib/messages.d.ts +1 -1
  19. package/dist/lib/request.d.ts +4 -3
  20. package/dist/lib/suppressions.d.ts +1 -1
  21. package/dist/mailgun.node.js +3 -0
  22. package/dist/{mailgun.js.LICENSE.txt → mailgun.node.js.LICENSE.txt} +1 -1
  23. package/dist/mailgun.web.js +3 -0
  24. package/dist/mailgun.web.js.LICENSE.txt +7 -0
  25. package/examples/addresses.js +1 -0
  26. package/examples/list-domains.js +1 -0
  27. package/examples/send-email.js +1 -0
  28. package/index.ts +3 -3
  29. package/lib/client.ts +4 -3
  30. package/lib/events.ts +21 -19
  31. package/lib/interfaces/APIErrorOptions.ts +3 -1
  32. package/lib/interfaces/ApiResponse.ts +3 -1
  33. package/lib/interfaces/Events.ts +25 -0
  34. package/lib/interfaces/IFormData.ts +5 -14
  35. package/lib/interfaces/IpPools.ts +16 -1
  36. package/lib/interfaces/Ips.ts +1 -0
  37. package/lib/interfaces/Options.ts +5 -2
  38. package/lib/interfaces/RequestOptions.ts +4 -2
  39. package/lib/interfaces/StatsOptions.ts +4 -2
  40. package/lib/interfaces/Supressions.ts +1 -1
  41. package/lib/interfaces/lists.ts +1 -0
  42. package/lib/interfaces/mailListMembers.ts +18 -12
  43. package/lib/interfaces/routes.ts +1 -0
  44. package/lib/ip-pools.ts +8 -7
  45. package/lib/ips.ts +3 -3
  46. package/lib/lists.ts +1 -1
  47. package/lib/messages.ts +1 -1
  48. package/lib/parse.ts +4 -3
  49. package/lib/request.ts +18 -8
  50. package/lib/stats.ts +3 -2
  51. package/lib/suppressions.ts +16 -11
  52. package/lib/validate.ts +0 -1
  53. package/package.json +9 -9
  54. package/test/client.test.ts +9 -3
  55. package/test/domains.test.ts +2 -1
  56. package/test/events.test.ts +3 -3
  57. package/test/ips.test.ts +4 -2
  58. package/test/lists.test.ts +7 -8
  59. package/test/mailListMembers.test.ts +49 -44
  60. package/test/messageAttachment.test.ts +5 -5
  61. package/test/messages.test.ts +3 -2
  62. package/test/parse.test.ts +4 -3
  63. package/test/request.test.ts +6 -5
  64. package/test/routes.test.ts +3 -1
  65. package/test/stats.test.ts +3 -2
  66. package/test/suppressions.test.ts +14 -11
  67. package/test/validate.test.ts +3 -2
  68. package/test/webhooks.test.ts +3 -3
  69. package/tsconfig.webpack.json +1 -1
  70. package/webpack/webpack.common.config.js +47 -0
  71. package/webpack/webpack.dev.config.js +18 -0
  72. package/webpack/webpack.release.config.js +37 -0
  73. package/dist/mailgun.js +0 -3
  74. package/webpack.config.js +0 -49
  75. package/webpack.release.config.js +0 -29
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-console */
1
2
  const mailgun = require('../index');
2
3
 
3
4
  const mg = mailgun.client({
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-console */
1
2
  const mailgun = require('../index');
2
3
 
3
4
  const mg = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY || '' });
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-console */
1
2
  const fs = require('fs');
2
3
  const mailgun = require('../index');
3
4
 
package/index.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import Client from './lib/client';
2
+ import { InputFormData } from './lib/interfaces/IFormData';
2
3
  import Options from './lib/interfaces/Options';
3
- import IFormData from './lib/interfaces/IFormData';
4
4
 
5
5
  class Mailgun {
6
- private formData: new () => IFormData
6
+ private formData: InputFormData
7
7
 
8
- constructor(FormData: new (...args: any[]) => IFormData) {
8
+ constructor(FormData: InputFormData) {
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';
@@ -15,7 +16,7 @@ import IpsClient from './ips';
15
16
  import IpPoolsClient from './ip-pools';
16
17
  import ListsClient from './lists';
17
18
  import MailListsMembers from './mailListMembers';
18
- import IFormData from './interfaces/IFormData';
19
+ import { InputFormData } from './interfaces/IFormData';
19
20
 
20
21
  export default class Client {
21
22
  private request;
@@ -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: any[]) => IFormData) {
38
+ constructor(options: Options, formData: InputFormData) {
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
- const urljoin = require('url-join');
1
+ import urljoin from 'url-join';
2
+ import {
3
+ EventsList, EventsPage, EventsResponse, PagesList, PagesListAccumulator
4
+ } from './interfaces/Events';
2
5
 
3
- const MgRequest = require('./request');
6
+ import Request from './request';
4
7
 
5
8
  export default class EventClient {
6
- request: typeof MgRequest;
9
+ request: Request;
7
10
 
8
- constructor(request: typeof MgRequest) {
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: { body: { paging: any } }) {
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: any, entrie: [url: string, id: string]) => {
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: { body: { items: any, paging: any } }) {
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: any }) {
42
+ get(domain: string, query: { page: string }) : Promise<EventsList> {
40
43
  let url;
41
-
42
- if (query && query.page) {
43
- url = urljoin('/v2', domain, 'events', query.page);
44
- delete query.page;
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
- return this.request.get(url, query)
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
- export default interface APIErrorOptions {
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;
@@ -1,4 +1,6 @@
1
- export default interface APIResponse {
1
+ interface APIResponse {
2
2
  status: number;
3
3
  body: any;
4
4
  }
5
+
6
+ export default APIResponse;
@@ -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
+ }
@@ -1,18 +1,9 @@
1
- interface Headers {
2
- [key: string]: any;
3
- }
1
+ import NodeFormData from 'form-data';
4
2
 
5
- interface AppendOptions {
6
- header?: string | Headers;
7
- knownLength?: number;
8
- filename?: string;
9
- filepath?: string;
10
- contentType?: string;
3
+ export interface IFormDataOptions {
4
+ [key: string]: any;
11
5
  }
12
6
 
13
- export default abstract class IFormData {
14
- constructor(){ //description of type. Should not be used for creating objects
15
- }
16
-
17
- abstract append(key: string, value: any, options?: AppendOptions | string): void
7
+ export interface InputFormData {
8
+ new (options?: HTMLFormElement | IFormDataOptions): NodeFormData | FormData;
18
9
  }
@@ -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
+ }
@@ -1,3 +1,4 @@
1
+ /* eslint-disable camelcase */
1
2
  export interface IpsListResponseBody {
2
3
  assignable_to_pools: boolean;
3
4
  items: string[];
@@ -1,7 +1,10 @@
1
- export default interface Options {
1
+ /* eslint-disable camelcase */
2
+ interface Options {
2
3
  username: string;
3
4
  key: string;
4
5
  url?: string;
5
6
  public_key?: string;
6
7
  timeout?: number;
7
- }
8
+ }
9
+
10
+ export default Options;
@@ -1,6 +1,8 @@
1
1
  import Options from './Options';
2
2
 
3
- export default interface RequestOptions extends Options {
3
+ interface RequestOptions extends Options {
4
4
  headers: any;
5
5
  timeout: number;
6
- }
6
+ }
7
+
8
+ export default RequestOptions;
@@ -1,4 +1,4 @@
1
- export default interface StatsOptions {
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;
@@ -1,3 +1,4 @@
1
+ /* eslint-disable camelcase */
1
2
  export interface BounceData {
2
3
  address: string;
3
4
  code: number;
@@ -15,4 +16,3 @@ export interface UnsubscribeData {
15
16
  tags: any;
16
17
  created_at: string | Date;
17
18
  }
18
-
@@ -1,3 +1,4 @@
1
+ /* eslint-disable camelcase */
1
2
  export interface ListsQuery {
2
3
  address?: string;
3
4
  limit?: number;
@@ -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(mailListAddress: string, data: CreateUpdateMailListMembers): Promise<MailListMember>,
58
- createMembers(mailListAddress: string, data: MultipleMembersData): Promise<NewMultipleMembersResponse>,
59
- updateMember(address : string, memberAddress: string, data:CreateUpdateMailListMembers): Promise<MailListMember> ,
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
+ }
@@ -1,3 +1,4 @@
1
+ /* eslint-disable camelcase */
1
2
  export interface Route {
2
3
  actions: string[];
3
4
  created_at: string;
package/lib/ip-pools.ts CHANGED
@@ -1,17 +1,18 @@
1
- const MgRequest = require('./request');
1
+ /* eslint-disable camelcase */
2
+ import Request from './request';
2
3
 
3
- import { IpPool } from "./interfaces/IpPools";
4
+ import { IpPool, IpPoolListResponse, IpPoolUpdateData } from './interfaces/IpPools';
4
5
 
5
6
  export default class IpPoolsClient {
6
- request: typeof MgRequest;
7
+ request: Request;
7
8
 
8
- constructor(request: typeof MgRequest) {
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: { body: { ip_pools: IpPool, message: string } }) => this.parseIpPoolsResponse(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: { name: string, description: string, add_ip: string, remove_ip: string }) {
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
- const MgRequest = require('./request');
1
+ import MgRequest from './request';
2
2
  import { IpData, IpsListResponseBody } from './interfaces/Ips';
3
3
 
4
4
  export default class IpsClient {
5
- request: typeof MgRequest;
5
+ request: MgRequest;
6
6
 
7
- constructor(request: typeof MgRequest) {
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
@@ -1,4 +1,4 @@
1
- import Request from "./request";
1
+ import Request from './request';
2
2
 
3
3
  export default class MessagesClient {
4
4
  request: Request;
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/request.ts CHANGED
@@ -1,14 +1,20 @@
1
+ import NodeFormData from 'form-data';
1
2
  import base64 from 'base-64';
2
3
  import urljoin from 'url-join';
3
4
  import ky from 'ky-universal';
4
5
  import APIError from './error';
5
6
  import RequestOptions from './interfaces/RequestOptions';
6
7
  import APIErrorOptions from './interfaces/APIErrorOptions';
7
- import IFormData from './interfaces/IFormData';
8
+ import { InputFormData } from './interfaces/IFormData';
8
9
  import APIResponse from './interfaces/ApiResponse';
9
10
 
10
11
  const isStream = (attachment: any) => typeof attachment === 'object' && typeof attachment.pipe === 'function';
11
12
 
13
+ function isNodeFormData(formDataInstance: NodeFormData | FormData)
14
+ : formDataInstance is NodeFormData {
15
+ return (<NodeFormData>formDataInstance).getHeaders !== undefined;
16
+ }
17
+
12
18
  const getAttachmentOptions = (item: any): {
13
19
  filename?: string,
14
20
  contentType?: string,
@@ -44,9 +50,9 @@ class Request {
44
50
  private url: string;
45
51
  private timeout: number;
46
52
  private headers: any;
47
- private formData: new () => IFormData;
53
+ private formData: InputFormData;
48
54
 
49
- constructor(options: RequestOptions, formData: new () => IFormData) {
55
+ constructor(options: RequestOptions, formData: InputFormData) {
50
56
  this.username = options.username;
51
57
  this.key = options.key;
52
58
  this.url = options.url as string;
@@ -151,21 +157,25 @@ class Request {
151
157
  return this.command('put', url, formData, params);
152
158
  }
153
159
 
154
- createFormData(data: any): IFormData {
155
- const appendFileToFD = (key: string, obj : any, formDataInstance: IFormData): void => {
160
+ createFormData(data: any): NodeFormData | FormData {
161
+ const appendFileToFD = (
162
+ key: string,
163
+ obj: any,
164
+ formDataInstance: NodeFormData | FormData
165
+ ): void => {
156
166
  const isStreamData = isStream(obj);
157
167
  const objData = isStreamData ? obj : obj.data;
158
168
  const options = getAttachmentOptions(obj);
159
- if (isStreamData) {
169
+ if (isNodeFormData(formDataInstance)) {
160
170
  formDataInstance.append(key, objData, options);
161
171
  return;
162
172
  }
163
173
  formDataInstance.append(key, objData, options.filename);
164
174
  };
165
175
 
166
- const formData: IFormData = Object.keys(data)
176
+ const formData: NodeFormData | FormData = Object.keys(data)
167
177
  .filter(function (key) { return data[key]; })
168
- .reduce((formDataAcc, key) => {
178
+ .reduce((formDataAcc: NodeFormData | FormData, key) => {
169
179
  if (key === 'attachment' || key === 'inline') {
170
180
  const obj = data[key];
171
181
 
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
- stat.time = new Date(stat.time);
17
- return stat;
16
+ const res = { ...stat };
17
+ res.time = new Date(stat.time);
18
+ return res;
18
19
  });
19
20
  }
20
21
  }
@@ -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, url]: [url: string, id: string]) => {
88
- acc[id] = this._parsePage(id, url)
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
- data = [data];
129
+ postData = [data];
130
+ } else {
131
+ postData = { ...data };
127
132
  }
128
133
 
129
134
  return this.request
130
- .post(urljoin('v3', domain, type), data, createOptions)
131
- .then((response: { body: any }) => response.body);
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
- .delete(urljoin('v3', domain, type, encodeURIComponent(address)))
137
- .then((response: { body: any }) => response.body);
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
@@ -1,4 +1,3 @@
1
-
2
1
  import Request from './request';
3
2
 
4
3
  export default class ValidateClient {
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "mailgun.js",
3
- "version": "3.5.9",
4
- "main": "dist/mailgun.js",
3
+ "version": "3.7.1",
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",
@@ -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.27.0",
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": "^8.2.1",
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
  }