mailgun.js
Advanced tools
Comparing version 3.5.3 to 3.5.4
@@ -5,2 +5,9 @@ # Changelog | ||
### [3.5.4](https://github.com/mailgun/mailgun-js/compare/v3.5.3...v3.5.4) (2021-08-04) | ||
### Bug Fixes | ||
* Error 400 on creating a webhook ([ed1719d](https://github.com/mailgun/mailgun-js/commits/ed1719da3225981c5fe56ae2d48fc4733eb2d7ae)) | ||
### [3.5.3](https://github.com/mailgun/mailgun-js/compare/v3.5.2...v3.5.3) (2021-08-03) | ||
@@ -7,0 +14,0 @@ |
@@ -0,1 +1,2 @@ | ||
import { WebhookList, WebhookResponse, WebhooksQuery } from './interfaces/Webhooks'; | ||
import Request from './request'; | ||
@@ -5,5 +6,3 @@ declare class Webhook { | ||
url: string; | ||
constructor(id: string, data: { | ||
url: string; | ||
}); | ||
constructor(id: string, url: string); | ||
} | ||
@@ -15,10 +14,6 @@ export default class WebhookClient { | ||
body: { | ||
webhooks: any; | ||
webhooks: WebhookList; | ||
}; | ||
}): any; | ||
_parseWebhookWithID(id: string): (response: { | ||
body: { | ||
webhook: any; | ||
}; | ||
}) => Webhook; | ||
}): WebhookList; | ||
_parseWebhookWithID(id: string): (response: WebhookResponse) => Webhook; | ||
_parseWebhookTest(response: { | ||
@@ -33,8 +28,8 @@ body: { | ||
}; | ||
list(domain: string, query: any): any; | ||
get(domain: string, id: string): any; | ||
create(domain: string, id: string, url: string, test: boolean): any; | ||
update(domain: string, id: string, url: string): any; | ||
destroy(domain: string, id: string): any; | ||
list(domain: string, query: WebhooksQuery): Promise<WebhookList>; | ||
get(domain: string, id: string): Promise<Webhook>; | ||
create(domain: string, id: string, url: string, test?: boolean): Promise<Webhook>; | ||
update(domain: string, id: string, url: string): Promise<Webhook>; | ||
destroy(domain: string, id: string): Promise<Webhook>; | ||
} | ||
export {}; |
@@ -5,2 +5,2 @@ /*! MIT License © Sindre Sorhus */ | ||
/*! mailgun.js v3.5.2 */ | ||
/*! mailgun.js v3.5.3 */ |
import urljoin from 'url-join'; | ||
import { WebhookList, WebhookResponse, WebhooksQuery } from './interfaces/Webhooks'; | ||
import Request from './request'; | ||
@@ -8,5 +9,5 @@ | ||
constructor(id: string, data: { url: string }) { | ||
constructor(id: string, url: string) { | ||
this.id = id; | ||
this.url = data.url; | ||
this.url = url; | ||
} | ||
@@ -22,3 +23,3 @@ } | ||
_parseWebhookList(response: { body: { webhooks: any } }) { | ||
_parseWebhookList(response: { body: { webhooks: WebhookList } }): WebhookList { | ||
return response.body.webhooks; | ||
@@ -28,12 +29,18 @@ } | ||
_parseWebhookWithID(id: string) { | ||
return function (response: { body: { webhook: any } }) { | ||
return new Webhook(id, response.body.webhook); | ||
return function (response: WebhookResponse): Webhook { | ||
const webhookResponse = response?.body?.webhook; | ||
let url = webhookResponse?.url; | ||
if (!url) { | ||
url = webhookResponse?.urls && webhookResponse.urls.length ? webhookResponse.urls[0] : null; | ||
} | ||
return new Webhook(id, url); | ||
}; | ||
} | ||
_parseWebhookTest(response: { body: { code: number, message: string } }) { | ||
_parseWebhookTest(response: { body: { code: number, message: string } }) | ||
: {code: number, message:string} { | ||
return { code: response.body.code, message: response.body.message }; | ||
} | ||
list(domain: string, query: any) { | ||
list(domain: string, query: WebhooksQuery): Promise<WebhookList> { | ||
return this.request.get(urljoin('/v2/domains', domain, 'webhooks'), query) | ||
@@ -43,3 +50,3 @@ .then(this._parseWebhookList); | ||
get(domain: string, id: string) { | ||
get(domain: string, id: string): Promise<Webhook> { | ||
return this.request.get(urljoin('/v2/domains', domain, 'webhooks', id)) | ||
@@ -49,18 +56,18 @@ .then(this._parseWebhookWithID(id)); | ||
create(domain: string, id: string, url: string, test: boolean) { | ||
create(domain: string, id: string, url: string, test = false): Promise<Webhook> { | ||
if (test) { | ||
return this.request.put(urljoin('/v2/domains', domain, 'webhooks', id, 'test'), { url }) | ||
return this.request.putWithFD(urljoin('/v2/domains', domain, 'webhooks', id, 'test'), { url }) | ||
.then(this._parseWebhookTest); | ||
} | ||
return this.request.post(urljoin('/v2/domains', domain, 'webhooks'), { id, url }) | ||
return this.request.postWithFD(urljoin('/v2/domains', domain, 'webhooks'), { id, url }) | ||
.then(this._parseWebhookWithID(id)); | ||
} | ||
update(domain: string, id: string, url: string,) { | ||
return this.request.put(urljoin('/v2/domains', domain, 'webhooks', id), { url }) | ||
update(domain: string, id: string, url: string): Promise<Webhook> { | ||
return this.request.putWithFD(urljoin('/v2/domains', domain, 'webhooks', id), { url }) | ||
.then(this._parseWebhookWithID(id)); | ||
} | ||
destroy(domain: string, id: string) { | ||
destroy(domain: string, id: string) : Promise<Webhook> { | ||
return this.request.delete(urljoin('/v2/domains', domain, 'webhooks', id)) | ||
@@ -67,0 +74,0 @@ .then(this._parseWebhookWithID(id)); |
{ | ||
"name": "mailgun.js", | ||
"version": "3.5.3", | ||
"version": "3.5.4", | ||
"main": "dist/mailgun.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1906676
155
3918