mailgun.js
Advanced tools
Comparing version 3.7.3 to 4.0.0
@@ -5,2 +5,22 @@ # Changelog | ||
## [4.0.0](https://github.com/mailgun/mailgun.js/compare/v3.7.3...v4.0.0) (2021-11-18) | ||
### ⚠ BREAKING CHANGES | ||
* updated signature of unlinkIpPoll method | ||
* feature: Update events client to use v3 of API | ||
* feature: Update webhooks to use v3 of API | ||
* breaking: Update validation to use v4 of API | ||
* removed parse client functionality. | ||
Changed mg.validate.get response | ||
Added multiple email addresses validation | ||
* other: Update domain credentials responses to add status code | ||
* Update endpoints for service methods (#209) ([59f812d](https://github.com/mailgun/mailgun.js/commits/59f812dcf771a5d7ed812424bb5dfaef0f52ff62)), closes [#209](https://github.com/mailgun/mailgun.js/issues/209) | ||
### [3.7.3](https://github.com/mailgun/mailgun.js/compare/v3.7.2...v3.7.3) (2021-11-10) | ||
@@ -7,0 +27,0 @@ |
@@ -1,2 +0,1 @@ | ||
import Request from './request'; | ||
import Options from './interfaces/Options'; | ||
@@ -11,3 +10,2 @@ import DomainClient from './domains'; | ||
import ValidateClient from './validate'; | ||
import ParseClient from './parse'; | ||
import IpsClient from './ips'; | ||
@@ -26,5 +24,3 @@ import IpPoolsClient from './ip-pools'; | ||
routes: RoutesClient; | ||
public_request: Request; | ||
validate: ValidateClient; | ||
parse: ParseClient; | ||
ips: IpsClient; | ||
@@ -31,0 +27,0 @@ ip_pools: IpPoolsClient; |
@@ -1,6 +0,7 @@ | ||
import { DomainResponseData, DestroyedDomain, DestroyedDomainResponse, DomainsQuery, DomainInfo, DomainListResponseData, DomainShortData, DNSRecord } from './interfaces/Domains'; | ||
import { DomainsQuery, DomainInfo, DomainShortData, DNSRecord, ConnectionSettings, UpdatedConnectionSettings, DKIMAuthorityInfo, UpdatedDKIMAuthority, DKIMSelectorInfo, UpdatedDKIMSelectorResponse, WebPrefixInfo, UpdatedWebPrefixResponse, ReplacementForPool, MessageResponse } from './interfaces/Domains'; | ||
import APIResponse from './interfaces/ApiResponse'; | ||
import Request from './request'; | ||
import { DomainTrackingResponse, DomainTrackingData, OpenTrackingInfo, ClickTrackingInfo, UnsubscribeTrackingInfo, UpdateDomainTrackingResponse, UpdatedOpenTracking } from './interfaces/DomainTracking'; | ||
declare class Domain { | ||
import { DomainTrackingData, OpenTrackingInfo, ClickTrackingInfo, UnsubscribeTrackingInfo, UpdatedOpenTracking } from './interfaces/DomainTracking'; | ||
import DomainCredentialsClient from './domainsCredentials'; | ||
export declare class Domain { | ||
name: string; | ||
@@ -22,12 +23,15 @@ require_tls: boolean; | ||
request: Request; | ||
constructor(request: Request); | ||
_parseMessage(response: DestroyedDomainResponse): DestroyedDomain; | ||
_parseDomainList(response: DomainListResponseData): Domain[]; | ||
_parseDomain(response: DomainResponseData): Domain; | ||
_parseTrackingSettings(response: DomainTrackingResponse): DomainTrackingData; | ||
_parseTrackingUpdate(response: UpdateDomainTrackingResponse): UpdatedOpenTracking; | ||
list(query: DomainsQuery): Promise<Domain[]>; | ||
domainCredentials: DomainCredentialsClient; | ||
constructor(request: Request, domainCredentialsClient: DomainCredentialsClient); | ||
private _parseMessage; | ||
private _parseDomainList; | ||
private _parseDomain; | ||
private _parseTrackingSettings; | ||
private _parseTrackingUpdate; | ||
list(query?: DomainsQuery): Promise<Domain[]>; | ||
get(domain: string): Promise<Domain>; | ||
create(data: DomainInfo): Promise<Domain>; | ||
destroy(domain: string): Promise<DestroyedDomain>; | ||
destroy(domain: string): Promise<MessageResponse>; | ||
getConnection(domain: string): Promise<ConnectionSettings>; | ||
updateConnection(domain: string, data: ConnectionSettings): Promise<UpdatedConnectionSettings>; | ||
getTracking(domain: string): Promise<DomainTrackingData>; | ||
@@ -39,4 +43,6 @@ updateTracking(domain: string, type: string, data: OpenTrackingInfo | ClickTrackingInfo | UnsubscribeTrackingInfo): Promise<UpdatedOpenTracking>; | ||
linkIpPool(domain: string, pool_id: string): Promise<APIResponse>; | ||
unlinkIpPoll(domain: string, pool_id: string, ip: string): Promise<APIResponse>; | ||
unlinkIpPoll(domain: string, replacement: ReplacementForPool): Promise<APIResponse>; | ||
updateDKIMAuthority(domain: string, data: DKIMAuthorityInfo): Promise<UpdatedDKIMAuthority>; | ||
updateDKIMSelector(domain: string, data: DKIMSelectorInfo): Promise<UpdatedDKIMSelectorResponse>; | ||
updateWebPrefix(domain: string, data: WebPrefixInfo): Promise<UpdatedWebPrefixResponse>; | ||
} | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
import { EventsList, EventsPage, EventsResponse, PagesList } from './interfaces/Events'; | ||
import { EventsList, EventsPage, EventsResponse, ParsedPagesList } from './interfaces/Events'; | ||
import Request from './request'; | ||
@@ -8,7 +8,7 @@ export default class EventClient { | ||
_parsePage(id: string, url: string): EventsPage; | ||
_parsePageLinks(response: EventsResponse): PagesList; | ||
_parsePageLinks(response: EventsResponse): ParsedPagesList; | ||
_parseEventList(response: EventsResponse): EventsList; | ||
get(domain: string, query: { | ||
get(domain: string, query?: { | ||
page: string; | ||
}): Promise<EventsList>; | ||
} |
@@ -12,3 +12,3 @@ export interface DomainsQuery { | ||
wildcard?: boolean; | ||
force_dkim_authority?: true; | ||
force_dkim_authority?: boolean | 'true' | 'false'; | ||
dkim_key_size?: 1024 | 2048; | ||
@@ -64,3 +64,3 @@ ips?: ''; | ||
} | ||
export interface DestroyedDomain { | ||
export interface MessageResponse { | ||
message: string; | ||
@@ -70,5 +70,55 @@ } | ||
status: number; | ||
body: MessageResponse; | ||
} | ||
export interface ConnectionSettings { | ||
require_tls: boolean; | ||
skip_verification: boolean; | ||
} | ||
export interface ConnectionSettingsResponse { | ||
body: { | ||
message: string; | ||
connection: ConnectionSettings; | ||
}; | ||
status: number; | ||
} | ||
export interface UpdatedConnectionSettings { | ||
message: string; | ||
require_tls: boolean; | ||
skip_verification: boolean; | ||
} | ||
export interface UpdatedConnectionSettingsRes { | ||
body: UpdatedConnectionSettings; | ||
status: number; | ||
} | ||
export interface DKIMAuthorityInfo { | ||
self: boolean | 'yes' | 'no' | 'true' | 'false'; | ||
} | ||
export interface UpdatedDKIMAuthority { | ||
changed: boolean; | ||
message: string; | ||
sending_dns_records: DNSRecord[]; | ||
} | ||
export interface UpdatedDKIMAuthorityResponse { | ||
body: UpdatedDKIMAuthority; | ||
status: 200; | ||
} | ||
export interface DKIMSelectorInfo { | ||
dkimSelector: string; | ||
} | ||
export interface UpdatedDKIMSelectorResponse { | ||
body: MessageResponse; | ||
status: number; | ||
} | ||
export interface WebPrefixInfo { | ||
webPrefix: string; | ||
} | ||
export interface UpdatedWebPrefix { | ||
message: string; | ||
} | ||
export interface UpdatedWebPrefixResponse { | ||
body: MessageResponse; | ||
status: number; | ||
} | ||
export interface ReplacementForPool { | ||
pool_id?: string; | ||
ip?: string; | ||
} |
@@ -21,3 +21,3 @@ export interface DomainTrackingData { | ||
export interface UpdatedOpenTracking { | ||
message: 'Domain tracking settings have been updated'; | ||
message: string; | ||
open?: { | ||
@@ -40,11 +40,11 @@ active: boolean; | ||
export interface OpenTrackingInfo { | ||
active: 'yes' | 'no'; | ||
active: 'yes' | 'no' | 'true' | 'false'; | ||
} | ||
export interface ClickTrackingInfo { | ||
active: 'yes' | 'no' | 'htmlonly'; | ||
active: 'yes' | 'no' | 'true' | 'false' | 'htmlonly'; | ||
} | ||
export interface UnsubscribeTrackingInfo { | ||
active: boolean; | ||
active: 'yes' | 'no' | 'true' | 'false'; | ||
html_footer: string; | ||
text_footer: string; | ||
} |
@@ -18,5 +18,69 @@ export interface EventsPage { | ||
} | ||
export interface DomainEvent { | ||
severity: string; | ||
tags: string[]; | ||
storage: { | ||
url: string; | ||
key: string; | ||
}; | ||
'delivery-status': { | ||
tls: boolean; | ||
'mx-host': string; | ||
code: number; | ||
description: string; | ||
'session-seconds': number; | ||
utf8: boolean; | ||
'attempt-no': number; | ||
message: string; | ||
'certificate-verified': boolean; | ||
}; | ||
'recipient-domain': string; | ||
id: string; | ||
campaigns: []; | ||
reason: string; | ||
'user-variables': { | ||
[key: string]: any; | ||
}; | ||
flags: { | ||
'is-routed': boolean; | ||
'is-authenticated': boolean; | ||
'is-system-test': boolean; | ||
'is-test-mode': boolean; | ||
}; | ||
'log-level': string; | ||
template?: any; | ||
timestamp: number; | ||
envelope: { | ||
transport: string; | ||
sender: string; | ||
'sending-ip': string; | ||
targets: string; | ||
}; | ||
message: { | ||
headers: { | ||
to: string; | ||
'message-id': string; | ||
from: string; | ||
subject: string; | ||
}; | ||
attachments: []; | ||
size: 308; | ||
}; | ||
recipient: string; | ||
event: string; | ||
} | ||
export interface ParsedPage { | ||
id: string; | ||
number: string; | ||
url: string; | ||
} | ||
export interface ParsedPagesList { | ||
previous: ParsedPage; | ||
first: ParsedPage; | ||
last: ParsedPage; | ||
next: ParsedPage; | ||
} | ||
export interface EventsList { | ||
items: []; | ||
pages: PagesList; | ||
items: DomainEvent[]; | ||
pages: ParsedPagesList; | ||
} | ||
@@ -23,0 +87,0 @@ export interface PagesListAccumulator { |
@@ -10,3 +10,3 @@ export interface APIWebhook { | ||
export interface WebhookResponse { | ||
status: string; | ||
status: number; | ||
body: WebhookResponseBody; | ||
@@ -23,1 +23,5 @@ } | ||
} | ||
export interface ValidationResponse { | ||
code: number; | ||
message: string; | ||
} |
@@ -0,6 +1,9 @@ | ||
import { IMultipleValidationClient } from './interfaces/MultipleValidation'; | ||
import { ValidationResult } from './interfaces/Validate'; | ||
import Request from './request'; | ||
export default class ValidateClient { | ||
multipleValidation: IMultipleValidationClient; | ||
request: Request; | ||
constructor(request: Request); | ||
get(address: string): Promise<any>; | ||
constructor(request: Request, multipleValidationClient: IMultipleValidationClient); | ||
get(address: string): Promise<ValidationResult>; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { WebhookList, WebhookResponse, WebhooksQuery } from './interfaces/Webhooks'; | ||
import { ValidationResponse, WebhookList, WebhookResponse, WebhooksQuery } from './interfaces/Webhooks'; | ||
import Request from './request'; | ||
@@ -9,3 +9,3 @@ declare class Webhook { | ||
export default class WebhookClient { | ||
request: any; | ||
request: Request; | ||
constructor(request: Request); | ||
@@ -29,3 +29,3 @@ _parseWebhookList(response: { | ||
get(domain: string, id: string): Promise<Webhook>; | ||
create(domain: string, id: string, url: string, test?: boolean): Promise<Webhook>; | ||
create(domain: string, id: string, url: string, test?: boolean): Promise<Webhook | ValidationResponse>; | ||
update(domain: string, id: string, url: string): Promise<Webhook>; | ||
@@ -32,0 +32,0 @@ destroy(domain: string, id: string): Promise<Webhook>; |
@@ -5,2 +5,2 @@ /*! MIT License © Sindre Sorhus */ | ||
/*! mailgun.js v3.7.2 */ | ||
/*! mailgun.js v3.7.3 */ |
@@ -7,2 +7,2 @@ /*! MIT License © Sindre Sorhus */ | ||
/*! mailgun.js v3.7.2 */ | ||
/*! mailgun.js v3.7.3 */ |
@@ -14,3 +14,2 @@ /* eslint-disable camelcase */ | ||
import ValidateClient from './validate'; | ||
import ParseClient from './parse'; | ||
import IpsClient from './ips'; | ||
@@ -21,2 +20,4 @@ import IpPoolsClient from './ip-pools'; | ||
import { InputFormData } from './interfaces/IFormData'; | ||
import DomainCredentialsClient from './domainsCredentials'; | ||
import MultipleValidationClient from './multipleValidation'; | ||
@@ -33,5 +34,3 @@ export default class Client { | ||
public routes; | ||
public public_request; | ||
public validate; | ||
public parse; | ||
public ips; | ||
@@ -59,4 +58,6 @@ public ip_pools; | ||
const mailListsMembers = new MailListsMembers(this.request); | ||
const domainCredentialsClient = new DomainCredentialsClient(this.request); | ||
const multipleValidationClient = new MultipleValidationClient(this.request); | ||
this.domains = new DomainClient(this.request); | ||
this.domains = new DomainClient(this.request, domainCredentialsClient); | ||
this.webhooks = new WebhookClient(this.request); | ||
@@ -71,11 +72,4 @@ this.events = new EventClient(this.request); | ||
this.lists = new ListsClient(this.request, mailListsMembers); | ||
if (config.public_key) { | ||
config.key = config.public_key; | ||
this.public_request = new Request(config, formData); | ||
this.validate = new ValidateClient(this.public_request); | ||
this.parse = new ParseClient(this.public_request); | ||
} | ||
this.validate = new ValidateClient(this.request, multipleValidationClient); | ||
} | ||
} |
@@ -5,3 +5,2 @@ /* eslint-disable camelcase */ | ||
DomainResponseData, | ||
DestroyedDomain, | ||
DestroyedDomainResponse, | ||
@@ -12,3 +11,16 @@ DomainsQuery, | ||
DomainShortData, | ||
DNSRecord | ||
DNSRecord, | ||
ConnectionSettingsResponse, | ||
ConnectionSettings, | ||
UpdatedConnectionSettings, | ||
UpdatedConnectionSettingsRes, | ||
DKIMAuthorityInfo, | ||
UpdatedDKIMAuthority, | ||
UpdatedDKIMAuthorityResponse, | ||
DKIMSelectorInfo, | ||
UpdatedDKIMSelectorResponse, | ||
WebPrefixInfo, | ||
UpdatedWebPrefixResponse, | ||
ReplacementForPool, | ||
MessageResponse, | ||
} from './interfaces/Domains'; | ||
@@ -30,4 +42,5 @@ | ||
} from './interfaces/DomainTracking'; | ||
import DomainCredentialsClient from './domainsCredentials'; | ||
class Domain { | ||
export class Domain { | ||
name: string; | ||
@@ -65,12 +78,14 @@ require_tls: boolean; | ||
request: Request; | ||
public domainCredentials: DomainCredentialsClient; | ||
constructor(request: Request) { | ||
constructor(request: Request, domainCredentialsClient: DomainCredentialsClient) { | ||
this.request = request; | ||
this.domainCredentials = domainCredentialsClient; | ||
} | ||
_parseMessage(response: DestroyedDomainResponse) : DestroyedDomain { | ||
private _parseMessage(response: DestroyedDomainResponse) : MessageResponse { | ||
return response.body; | ||
} | ||
_parseDomainList(response: DomainListResponseData): Domain[] { | ||
private _parseDomainList(response: DomainListResponseData): Domain[] { | ||
return response.body.items.map(function (item) { | ||
@@ -81,3 +96,3 @@ return new Domain(item); | ||
_parseDomain(response: DomainResponseData): Domain { | ||
private _parseDomain(response: DomainResponseData): Domain { | ||
return new Domain( | ||
@@ -90,12 +105,12 @@ response.body.domain, | ||
_parseTrackingSettings(response: DomainTrackingResponse) : DomainTrackingData { | ||
private _parseTrackingSettings(response: DomainTrackingResponse) : DomainTrackingData { | ||
return response.body.tracking; | ||
} | ||
_parseTrackingUpdate(response: UpdateDomainTrackingResponse) :UpdatedOpenTracking { | ||
private _parseTrackingUpdate(response: UpdateDomainTrackingResponse) :UpdatedOpenTracking { | ||
return response.body; | ||
} | ||
list(query: DomainsQuery): Promise<Domain[]> { | ||
return this.request.get('/v2/domains', query) | ||
list(query?: DomainsQuery): Promise<Domain[]> { | ||
return this.request.get('/v3/domains', query) | ||
.then((res : APIResponse) => this._parseDomainList(res as DomainListResponseData)); | ||
@@ -105,3 +120,3 @@ } | ||
get(domain: string) : Promise<Domain> { | ||
return this.request.get(`/v2/domains/${domain}`) | ||
return this.request.get(`/v3/domains/${domain}`) | ||
.then((res : APIResponse) => this._parseDomain(res as DomainResponseData)); | ||
@@ -111,15 +126,32 @@ } | ||
create(data: DomainInfo) : Promise<Domain> { | ||
return this.request.postWithFD('/v2/domains', data) | ||
const postObj = { ...data }; | ||
if ('force_dkim_authority' in postObj && typeof postObj.force_dkim_authority === 'boolean') { | ||
postObj.force_dkim_authority = postObj.toString() === 'true' ? 'true' : 'false'; | ||
} | ||
return this.request.postWithFD('/v3/domains', postObj) | ||
.then((res : APIResponse) => this._parseDomain(res as DomainResponseData)); | ||
} | ||
destroy(domain: string): Promise<DestroyedDomain> { | ||
return this.request.delete(`/v2/domains/${domain}`) | ||
destroy(domain: string): Promise<MessageResponse> { | ||
return this.request.delete(`/v3/domains/${domain}`) | ||
.then((res : APIResponse) => this._parseMessage(res as DestroyedDomainResponse)); | ||
} | ||
getConnection(domain: string): Promise<ConnectionSettings> { | ||
return this.request.get(`/v3/domains/${domain}/connection`) | ||
.then((res : APIResponse) => res as ConnectionSettingsResponse) | ||
.then((res:ConnectionSettingsResponse) => res.body.connection as ConnectionSettings); | ||
} | ||
updateConnection(domain: string, data: ConnectionSettings): Promise<UpdatedConnectionSettings> { | ||
return this.request.put(`/v3/domains/${domain}/connection`, data) | ||
.then((res : APIResponse) => res as UpdatedConnectionSettingsRes) | ||
.then((res:UpdatedConnectionSettingsRes) => res.body as UpdatedConnectionSettings); | ||
} | ||
// Tracking | ||
getTracking(domain: string) : Promise<DomainTrackingData> { | ||
return this.request.get(urljoin('/v2/domains', domain, 'tracking')) | ||
return this.request.get(urljoin('/v3/domains', domain, 'tracking')) | ||
.then(this._parseTrackingSettings); | ||
@@ -133,7 +165,7 @@ } | ||
): Promise<UpdatedOpenTracking> { | ||
if (!('html_footer' in data) && !('text_footer' in data) && typeof data?.active === 'boolean') { | ||
throw new APIError({ status: 400, statusText: '', body: { message: 'Value "active" must contain string value.' } } as APIErrorOptions); | ||
if (typeof data?.active === 'boolean') { | ||
throw new APIError({ status: 400, statusText: '', body: { message: 'Property "active" must contain string value.' } } as APIErrorOptions); | ||
} | ||
return this.request.putWithFD(urljoin('/v2/domains', domain, 'tracking', type), data) | ||
.then(this._parseTrackingUpdate); | ||
return this.request.putWithFD(urljoin('/v3/domains', domain, 'tracking', type), data) | ||
.then((res : APIResponse) => this._parseTrackingUpdate(res as UpdateDomainTrackingResponse)); | ||
} | ||
@@ -144,3 +176,3 @@ | ||
getIps(domain: string): Promise<string[]> { | ||
return this.request.get(urljoin('/v2/domains', domain, 'ips')) | ||
return this.request.get(urljoin('/v3/domains', domain, 'ips')) | ||
.then((response: APIResponse) => response?.body?.items); | ||
@@ -150,16 +182,40 @@ } | ||
assignIp(domain: string, ip: string): Promise<APIResponse> { | ||
return this.request.postWithFD(urljoin('/v2/domains', domain, 'ips'), { ip }); | ||
return this.request.postWithFD(urljoin('/v3/domains', domain, 'ips'), { ip }); | ||
} | ||
deleteIp(domain: string, ip: string): Promise<APIResponse> { | ||
return this.request.delete(urljoin('/v2/domains', domain, 'ips', ip)); | ||
return this.request.delete(urljoin('/v3/domains', domain, 'ips', ip)); | ||
} | ||
linkIpPool(domain: string, pool_id: string): Promise<APIResponse> { | ||
return this.request.postWithFD(urljoin('/v2/domains', domain, 'ips'), { pool_id }); | ||
return this.request.postWithFD(urljoin('/v3/domains', domain, 'ips'), { pool_id }); | ||
} | ||
unlinkIpPoll(domain: string, pool_id: string, ip: string): Promise<APIResponse> { | ||
return this.request.delete(urljoin('/v2/domains', domain, 'ips', 'ip_pool'), { pool_id, ip }); | ||
unlinkIpPoll(domain: string, replacement: ReplacementForPool): Promise<APIResponse> { | ||
let searchParams = ''; | ||
if (replacement.pool_id && replacement.ip) { | ||
throw new APIError({ status: 400, statusText: '', body: { message: 'Please specify either pool_id or ip (not both)' } } as APIErrorOptions); | ||
} else if (replacement.pool_id) { | ||
searchParams = `?pool_id=${replacement.pool_id}`; | ||
} else if (replacement.ip) { | ||
searchParams = `?ip=${replacement.ip}`; | ||
} | ||
return this.request.delete(urljoin('/v3/domains', domain, 'ips', 'ip_pool', searchParams)); | ||
} | ||
updateDKIMAuthority(domain: string, data: DKIMAuthorityInfo): Promise<UpdatedDKIMAuthority> { | ||
return this.request.put(`/v3/domains/${domain}/dkim_authority`, {}, { query: `self=${data.self}` }) | ||
.then((res : APIResponse) => res) | ||
.then((res : UpdatedDKIMAuthorityResponse) => res.body as UpdatedDKIMAuthority); | ||
} | ||
updateDKIMSelector(domain: string, data: DKIMSelectorInfo): Promise<UpdatedDKIMSelectorResponse> { | ||
return this.request.put(`/v3/domains/${domain}/dkim_selector`, {}, { query: `dkim_selector=${data.dkimSelector}` }) | ||
.then((res : APIResponse) => res as UpdatedDKIMSelectorResponse); | ||
} | ||
updateWebPrefix(domain: string, data: WebPrefixInfo): Promise<UpdatedWebPrefixResponse> { | ||
return this.request.put(`/v3/domains/${domain}/web_prefix`, {}, { query: `web_prefix=${data.webPrefix}` }) | ||
.then((res : APIResponse) => res as UpdatedWebPrefixResponse); | ||
} | ||
} |
import urljoin from 'url-join'; | ||
import { | ||
EventsList, EventsPage, EventsResponse, PagesList, PagesListAccumulator | ||
EventsList, EventsPage, EventsResponse, PagesList, PagesListAccumulator, ParsedPagesList | ||
} from './interfaces/Events'; | ||
@@ -23,3 +23,3 @@ | ||
_parsePageLinks(response: EventsResponse) : PagesList { | ||
_parsePageLinks(response: EventsResponse) : ParsedPagesList { | ||
const pages = Object.entries(response.body.paging as PagesList); | ||
@@ -33,3 +33,3 @@ return pages.reduce( | ||
}, {} | ||
) as unknown as PagesList; | ||
) as unknown as ParsedPagesList; | ||
} | ||
@@ -44,10 +44,10 @@ | ||
get(domain: string, query: { page: string }) : Promise<EventsList> { | ||
get(domain: string, query?: { page: string }) : Promise<EventsList> { | ||
let url; | ||
const queryCopy = { ...query }; | ||
if (queryCopy && queryCopy.page) { | ||
url = urljoin('/v2', domain, 'events', queryCopy.page); | ||
url = urljoin('/v3', domain, 'events', queryCopy.page); | ||
delete queryCopy.page; | ||
} else { | ||
url = urljoin('/v2', domain, 'events'); | ||
url = urljoin('/v3', domain, 'events'); | ||
} | ||
@@ -54,0 +54,0 @@ return this.request.get(url, queryCopy) |
@@ -14,3 +14,3 @@ /* eslint-disable camelcase */ | ||
wildcard?: boolean; | ||
force_dkim_authority?: true; | ||
force_dkim_authority?: boolean | 'true' | 'false'; | ||
dkim_key_size?: 1024 | 2048; | ||
@@ -73,4 +73,4 @@ ips?: ''; | ||
export interface DestroyedDomain { | ||
message: string; | ||
export interface MessageResponse { | ||
message : string | ||
} | ||
@@ -80,5 +80,66 @@ | ||
status: number; | ||
body: MessageResponse | ||
} | ||
export interface ConnectionSettings { | ||
require_tls: boolean; | ||
skip_verification: boolean; | ||
} | ||
export interface ConnectionSettingsResponse { | ||
body: { | ||
message: string; | ||
connection: ConnectionSettings | ||
} | ||
status: number | ||
} | ||
export interface UpdatedConnectionSettings { | ||
message: string, | ||
require_tls: boolean, | ||
skip_verification: boolean | ||
} | ||
export interface UpdatedConnectionSettingsRes { | ||
body: UpdatedConnectionSettings, | ||
status: number | ||
} | ||
export interface DKIMAuthorityInfo { | ||
self: boolean | 'yes' | 'no' | 'true' |'false' | ||
} | ||
export interface UpdatedDKIMAuthority { | ||
changed: boolean, | ||
message: string, | ||
sending_dns_records: DNSRecord[] | ||
} | ||
export interface UpdatedDKIMAuthorityResponse { | ||
body: UpdatedDKIMAuthority, | ||
status: 200 | ||
} | ||
export interface DKIMSelectorInfo { | ||
dkimSelector: string | ||
} | ||
export interface UpdatedDKIMSelectorResponse { | ||
body:MessageResponse, | ||
status: number | ||
} | ||
export interface WebPrefixInfo { | ||
webPrefix: string | ||
} | ||
export interface UpdatedWebPrefix { | ||
message : string | ||
} | ||
export interface UpdatedWebPrefixResponse { | ||
body:MessageResponse, | ||
status: number | ||
} | ||
export interface ReplacementForPool { | ||
pool_id?: string; | ||
ip?: string; | ||
} |
@@ -21,3 +21,3 @@ /* eslint-disable camelcase */ | ||
export interface UpdatedOpenTracking { | ||
message: 'Domain tracking settings have been updated'; | ||
message: string; | ||
open?: { active: boolean }; | ||
@@ -38,12 +38,12 @@ click?: { active: boolean | 'htmlonly'}; | ||
export interface OpenTrackingInfo { | ||
active: 'yes' | 'no'; | ||
active: 'yes'| 'no' | 'true' | 'false'; | ||
} | ||
export interface ClickTrackingInfo { | ||
active: 'yes' | 'no' | 'htmlonly'; | ||
active: 'yes'| 'no' | 'true' | 'false' | 'htmlonly'; | ||
} | ||
export interface UnsubscribeTrackingInfo { | ||
active: boolean; | ||
active: 'yes'| 'no' | 'true' | 'false'; | ||
html_footer: string; | ||
text_footer: string; | ||
} |
@@ -18,6 +18,70 @@ export interface EventsPage { | ||
} | ||
export interface DomainEvent { | ||
severity: string; | ||
tags: string[]; | ||
storage: { | ||
url: string; | ||
key: string | ||
}; | ||
'delivery-status': { | ||
tls: boolean; | ||
'mx-host': string; | ||
code: number; | ||
description: string; | ||
'session-seconds': number; | ||
utf8: boolean; | ||
'attempt-no': number; | ||
message: string; | ||
'certificate-verified': boolean | ||
}; | ||
'recipient-domain': string; | ||
id: string; | ||
campaigns: []; | ||
reason: string; | ||
'user-variables': { | ||
[key: string]: any; | ||
}; | ||
flags: { | ||
'is-routed': boolean; | ||
'is-authenticated': boolean; | ||
'is-system-test': boolean; | ||
'is-test-mode': boolean | ||
}; | ||
'log-level' : string; | ||
template?: any; | ||
timestamp: number; | ||
envelope: { | ||
transport: string; | ||
sender: string; | ||
'sending-ip': string; | ||
targets: string | ||
}; | ||
message: { | ||
headers: { | ||
to: string; | ||
'message-id': string; | ||
from: string; | ||
subject: string | ||
}; | ||
attachments: []; | ||
size: 308 | ||
}; | ||
recipient: string; | ||
event: string; | ||
} | ||
export interface ParsedPage{ | ||
id: string; | ||
number: string; | ||
url: string | ||
} | ||
export interface ParsedPagesList { | ||
previous: ParsedPage; | ||
first: ParsedPage; | ||
last: ParsedPage; | ||
next: ParsedPage; | ||
} | ||
export interface EventsList { | ||
items: []; | ||
pages: PagesList; | ||
items: DomainEvent[]; | ||
pages: ParsedPagesList; | ||
} | ||
@@ -24,0 +88,0 @@ export interface PagesListAccumulator { |
@@ -12,3 +12,3 @@ export interface APIWebhook { | ||
export interface WebhookResponse { | ||
status: string; | ||
status: number; | ||
body: WebhookResponseBody; | ||
@@ -27,1 +27,6 @@ } | ||
} | ||
export interface ValidationResponse { | ||
code: number; | ||
message: string; | ||
} |
@@ -110,6 +110,8 @@ import NodeFormData from 'form-data'; | ||
return { | ||
const res = { | ||
body: await response?.json(), | ||
status: response?.status | ||
}; | ||
return res; | ||
} | ||
@@ -146,2 +148,5 @@ | ||
postWithFD(url: string, data: any): Promise<APIResponse> { | ||
if (!data) { | ||
throw new Error('Please provide data object'); | ||
} | ||
const params: any = { | ||
@@ -155,2 +160,5 @@ headers: { 'Content-Type': null } | ||
putWithFD(url: string, data: any): Promise<APIResponse> { | ||
if (!data) { | ||
throw new Error('Please provide data object'); | ||
} | ||
const params: any = { | ||
@@ -182,3 +190,3 @@ headers: { 'Content-Type': null } | ||
.reduce((formDataAcc: NodeFormData | FormData, key) => { | ||
if (key === 'attachment' || key === 'inline') { | ||
if (key === 'attachment' || key === 'inline' || key === 'file') { | ||
const obj = data[key]; | ||
@@ -185,0 +193,0 @@ |
@@ -0,14 +1,20 @@ | ||
import APIResponse from './interfaces/ApiResponse'; | ||
import { IMultipleValidationClient } from './interfaces/MultipleValidation'; | ||
import { ValidationResult, ValidationResponse } from './interfaces/Validate'; | ||
import Request from './request'; | ||
export default class ValidateClient { | ||
public multipleValidation; | ||
request: Request; | ||
constructor(request: Request) { | ||
constructor(request: Request, multipleValidationClient: IMultipleValidationClient) { | ||
this.request = request; | ||
this.multipleValidation = multipleValidationClient; | ||
} | ||
get(address: string) { | ||
return this.request.get('/v3/address/validate', { address }) | ||
.then((response) => response.body); | ||
get(address: string): Promise<ValidationResult> { | ||
return this.request.get('/v4/address/validate', { address }) | ||
.then((response : APIResponse) => response) | ||
.then((res : ValidationResponse) => res.body as ValidationResult); | ||
} | ||
} |
import urljoin from 'url-join'; | ||
import { WebhookList, WebhookResponse, WebhooksQuery } from './interfaces/Webhooks'; | ||
import { | ||
ValidationResponse, | ||
WebhookList, | ||
WebhookResponse, | ||
WebhooksQuery | ||
} from './interfaces/Webhooks'; | ||
import Request from './request'; | ||
@@ -16,3 +22,3 @@ | ||
export default class WebhookClient { | ||
request: any; | ||
request: Request; | ||
@@ -40,7 +46,7 @@ constructor(request: Request) { | ||
: {code: number, message:string} { | ||
return { code: response.body.code, message: response.body.message }; | ||
return { code: response.body.code, message: response.body.message } as ValidationResponse; | ||
} | ||
list(domain: string, query: WebhooksQuery): Promise<WebhookList> { | ||
return this.request.get(urljoin('/v2/domains', domain, 'webhooks'), query) | ||
return this.request.get(urljoin('/v3/domains', domain, 'webhooks'), query) | ||
.then(this._parseWebhookList); | ||
@@ -50,13 +56,16 @@ } | ||
get(domain: string, id: string): Promise<Webhook> { | ||
return this.request.get(urljoin('/v2/domains', domain, 'webhooks', id)) | ||
return this.request.get(urljoin('/v3/domains', domain, 'webhooks', id)) | ||
.then(this._parseWebhookWithID(id)); | ||
} | ||
create(domain: string, id: string, url: string, test = false): Promise<Webhook> { | ||
create(domain: string, | ||
id: string, | ||
url: string, | ||
test = false): Promise<Webhook | ValidationResponse> { | ||
if (test) { | ||
return this.request.putWithFD(urljoin('/v2/domains', domain, 'webhooks', id, 'test'), { url }) | ||
return this.request.putWithFD(urljoin('/v3/domains', domain, 'webhooks', id, 'test'), { url }) | ||
.then(this._parseWebhookTest); | ||
} | ||
return this.request.postWithFD(urljoin('/v2/domains', domain, 'webhooks'), { id, url }) | ||
return this.request.postWithFD(urljoin('/v3/domains', domain, 'webhooks'), { id, url }) | ||
.then(this._parseWebhookWithID(id)); | ||
@@ -66,3 +75,3 @@ } | ||
update(domain: string, id: string, url: string): Promise<Webhook> { | ||
return this.request.putWithFD(urljoin('/v2/domains', domain, 'webhooks', id), { url }) | ||
return this.request.putWithFD(urljoin('/v3/domains', domain, 'webhooks', id), { url }) | ||
.then(this._parseWebhookWithID(id)); | ||
@@ -72,5 +81,5 @@ } | ||
destroy(domain: string, id: string) : Promise<Webhook> { | ||
return this.request.delete(urljoin('/v2/domains', domain, 'webhooks', id)) | ||
return this.request.delete(urljoin('/v3/domains', domain, 'webhooks', id)) | ||
.then(this._parseWebhookWithID(id)); | ||
} | ||
} |
{ | ||
"name": "mailgun.js", | ||
"version": "3.7.3", | ||
"version": "4.0.0", | ||
"main": "dist/mailgun.node.js", | ||
@@ -108,6 +108,5 @@ "browser": "dist/mailgun.web.js", | ||
"scripts": { | ||
"prerelease": "npm test && webpack --config ./webpack/webpack.release.config.js --progress --color && git add -A dist", | ||
"posttag": "git push && git push --tags && rm -rf build" | ||
"prerelease": "npm test && webpack --config ./webpack/webpack.release.config.js --progress --color && git add -A dist" | ||
} | ||
} | ||
} |
@@ -1584,3 +1584,3 @@ # Mailgun.js [![Build Status](https://travis-ci.org/mailgun/mailgun-js.svg)](https://travis-ci.org/mailgun/mailgun-js) | ||
name: 'John Smith', // optional, modifiable on website | ||
vars: {hobby: "chess"}, // optional, modifiable on website | ||
vars: {hobby: "chess"}, // optional, modifiable on website | ||
subscribed: 'no', // optional, modifiable on website | ||
@@ -1762,5 +1762,5 @@ upsert: 'yes', // optional, choose yes to insert if not exist, or update it exist | ||
After that, ```run npm login``` and ```npm publish``` to publish changes on npm. | ||
After that, run ```npm login``` and ```npm publish``` to publish changes on npm. | ||
## TODO | ||
- add browser demo to heroku |
@@ -14,4 +14,8 @@ import formData from 'form-data'; | ||
import ValidateClient from '../lib/validate'; | ||
import ParseClient from '../lib/parse'; | ||
import { InputFormData } from '../lib/interfaces/IFormData'; | ||
import StatsClient from '../lib/stats'; | ||
import ListsClient from '../lib/lists'; | ||
import IpPoolsClient from '../lib/ip-pools'; | ||
import IpsClient from '../lib/ips'; | ||
@@ -66,2 +70,6 @@ describe('Client', function () { | ||
it('creates stats client', function () { | ||
client.stats.should.be.instanceOf(StatsClient); | ||
}); | ||
it('creates messages client', function () { | ||
@@ -75,9 +83,17 @@ client.messages.should.be.instanceOf(MessagesClient); | ||
it('creates ips client', function () { | ||
client.ips.should.be.instanceOf(IpsClient); | ||
}); | ||
it('creates ip_pools client', function () { | ||
client.ip_pools.should.be.instanceOf(IpPoolsClient); | ||
}); | ||
it('creates lists client', function () { | ||
client.lists.should.be.instanceOf(ListsClient); | ||
}); | ||
it('creates address validate client', function () { | ||
client.validate.should.be.instanceOf(ValidateClient); | ||
}); | ||
it('creates address parse client', function () { | ||
client.parse.should.be.instanceOf(ParseClient); | ||
}); | ||
}); |
@@ -6,13 +6,23 @@ import formData from 'form-data'; | ||
import Request from '../lib/request'; | ||
import DomainClient from '../lib/domains'; | ||
import DomainClient, { Domain } from '../lib/domains'; | ||
import RequestOptions from '../lib/interfaces/RequestOptions'; | ||
import { InputFormData } from '../lib/interfaces/IFormData'; | ||
import DomainCredentialsClient from '../lib/domainsCredentials'; | ||
import { | ||
ConnectionSettings, | ||
MessageResponse, | ||
UpdatedConnectionSettings, | ||
UpdatedDKIMAuthority, | ||
UpdatedDKIMSelectorResponse, UpdatedWebPrefixResponse | ||
} from '../lib/interfaces/Domains'; | ||
// TODO: fix types | ||
describe('DomainClient', function () { | ||
let client: any; | ||
let api: any; | ||
let client: DomainClient; | ||
let api: nock.Scope; | ||
beforeEach(function () { | ||
client = new DomainClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData)); | ||
const reqObject = new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData); | ||
const domainCredentialsClient = new DomainCredentialsClient(reqObject); | ||
client = new DomainClient(reqObject, domainCredentialsClient); | ||
api = nock('https://api.mailgun.net'); | ||
@@ -40,7 +50,7 @@ }); | ||
api.get('/v2/domains').reply(200, { | ||
api.get('/v3/domains').reply(200, { | ||
items: domains | ||
}); | ||
return client.list().then(function (dm: any[]) { | ||
return client.list().then(function (dm: Domain[]) { | ||
dm[0].should.eql({ | ||
@@ -79,3 +89,3 @@ created_at: 'Sun, 19 Oct 2014 18:49:36 GMT', | ||
api.get('/v2/domains/testing.example.com').reply(200, { | ||
api.get('/v3/domains/testing.example.com').reply(200, { | ||
domain: domainData, | ||
@@ -86,3 +96,3 @@ receiving_dns_records: [], | ||
return client.get('testing.example.com').then(function (domain: any) { | ||
return client.get('testing.example.com').then(function (domain: Domain) { | ||
domain.should.eql({ | ||
@@ -121,3 +131,3 @@ created_at: 'Sun, 19 Oct 2014 18:49:36 GMT', | ||
api.post('/v2/domains').reply(200, { | ||
api.post('/v3/domains').reply(200, { | ||
domain: domainData, | ||
@@ -128,3 +138,7 @@ receiving_dns_records: [], | ||
return client.create({ name: 'another.example.com' }).then(function (domain: any) { | ||
return client.create({ | ||
name: 'another.example.com', | ||
smtp_password: 'smtp_password', | ||
web_scheme: 'https' | ||
}).then(function (domain: Domain) { | ||
domain.should.eql({ | ||
@@ -150,7 +164,7 @@ created_at: 'Sun, 19 Oct 2014 18:49:36 GMT', | ||
it('deletes a domain', function () { | ||
api.delete('/v2/domains/test.example.com').reply(200, { | ||
api.delete('/v3/domains/test.example.com').reply(200, { | ||
message: 'domain deleted' | ||
}); | ||
return client.destroy('test.example.com').then(function (data: any) { | ||
return client.destroy('test.example.com').then(function (data: MessageResponse) { | ||
data.should.eql({ | ||
@@ -163,5 +177,42 @@ message: 'domain deleted' | ||
describe('getConnection', function () { | ||
it('returns connection settings for the defined domain', function () { | ||
api.get('/v3/domains/test.example.com/connection').reply(200, { | ||
connection: { require_tls: false, skip_verification: false } | ||
}); | ||
return client.getConnection('test.example.com').then(function (data: ConnectionSettings) { | ||
data.should.eql({ require_tls: false, skip_verification: false }); | ||
}); | ||
}); | ||
}); | ||
describe('updateConnection', function () { | ||
it('Updates the connection settings for the defined domain.', function () { | ||
api.put('/v3/domains/test.example.com/connection').reply(200, { | ||
connection: { | ||
message: 'Domain connection settings have been updated, may take 10 minutes to fully propagate', | ||
require_tls: false, | ||
skip_verification: false | ||
} | ||
}); | ||
return client.updateConnection('test.example.com', { | ||
require_tls: true, | ||
skip_verification: true | ||
}).then(function (data: UpdatedConnectionSettings) { | ||
data.should.eql({ | ||
connection: { | ||
message: 'Domain connection settings have been updated, may take 10 minutes to fully propagate', | ||
require_tls: false, | ||
skip_verification: false | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('getTracking', function () { | ||
it('fetches all tracking settings', function () { | ||
api.get('/v2/domains/domain.com/tracking').reply(200, { | ||
api.get('/v3/domains/domain.com/tracking').reply(200, { | ||
tracking: { | ||
@@ -183,3 +234,3 @@ open: { active: true }, | ||
const open = { active: true }; | ||
api.put('/v2/domains/domain.com/tracking/open').reply(200, { | ||
api.put('/v3/domains/domain.com/tracking/open').reply(200, { | ||
message: 'Tracking settings have been updated', | ||
@@ -203,3 +254,3 @@ open | ||
const items = ['192.161.0.1', '192.168.0.2']; | ||
api.get('/v2/domains/domain.com/ips').reply(200, { items }); | ||
api.get('/v3/domains/domain.com/ips').reply(200, { items }); | ||
@@ -211,2 +262,54 @@ return client.getIps('domain.com').then((response: string[]) => { | ||
}); | ||
describe('updateDKIMAuthority', () => { | ||
it('changes the DKIM authority for a domain.', () => { | ||
const expectedRes = { | ||
changed: true, | ||
message: 'Domain DKIM authority has been changed', | ||
sending_dns_records: [ | ||
{ | ||
cached: ['a'], | ||
name: 'test.example.com', | ||
record_type: 'record_type', | ||
valid: 'valid', | ||
value: 'value' | ||
} | ||
] | ||
}; | ||
api.put('/v3/domains/test.example.com/dkim_authority?self=true').reply(200, expectedRes); | ||
return client.updateDKIMAuthority('test.example.com', { self: 'true' }).then((response: UpdatedDKIMAuthority) => { | ||
response.should.eql(expectedRes); | ||
}); | ||
}); | ||
}); | ||
describe('updateDKIMSelector', () => { | ||
it('updates the DKIM selector for a domains', () => { | ||
api.put('/v3/domains/test.example.com/dkim_selector?dkim_selector=dkim_selector_value').reply(200, { message: 'Domain DKIM selector updated' }); | ||
return client.updateDKIMSelector('test.example.com', { dkimSelector: 'dkim_selector_value' }).then((response: UpdatedDKIMSelectorResponse) => { | ||
response.should.eql( | ||
{ | ||
body: { message: 'Domain DKIM selector updated' }, status: 200 | ||
} | ||
); | ||
}); | ||
}); | ||
}); | ||
describe('updateWebPrefix', () => { | ||
it('Update the CNAME used for tracking opens and clicks', () => { | ||
api.put('/v3/domains/test.example.com/web_prefix?web_prefix=webprefixvalue').reply(200, { message: 'Domain web prefix updated' }); | ||
return client.updateWebPrefix('test.example.com', { webPrefix: 'webprefixvalue' }).then((response: UpdatedWebPrefixResponse) => { | ||
response.should.eql( | ||
{ | ||
body: { message: 'Domain web prefix updated' }, status: 200 | ||
} | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -8,6 +8,7 @@ import nock from 'nock'; | ||
import { InputFormData } from '../lib/interfaces/IFormData'; | ||
import { EventsList, EventsResponse } from '../lib/interfaces/Events'; | ||
describe('EventsClient', function () { | ||
let client: any; | ||
let api: any; | ||
let client: EventClient; | ||
let api: nock.Scope; | ||
@@ -30,10 +31,8 @@ beforeEach(function () { | ||
{ | ||
type: 'accepted', | ||
event: 'accepted', | ||
timestamp: 'Wed, 19 Nov 2014 18:32:57 GMT', | ||
gist: 'got it', | ||
content: { more: 'data' } | ||
}, { | ||
type: 'opened', | ||
event: 'opened', | ||
timestamp: 'Tue, 18 Nov 2014 12:32:57 GMT', | ||
gist: 'sent', | ||
content: { more: 'data' } | ||
@@ -52,18 +51,14 @@ } | ||
it('fetches all events', function () { | ||
api.get('/v2/domain.com/events').reply(200, response); | ||
api.get('/v3/domain.com/events').reply(200, response); | ||
return client.get('domain.com').then(function (data: any) { | ||
return client.get('domain.com').then(function (data: EventsList) { | ||
let e; | ||
e = data.items[0]; | ||
e.type.should.eql('accepted'); | ||
e.gist.should.eql('got it'); | ||
e.event.should.eql('accepted'); | ||
e.timestamp.should.eql('Wed, 19 Nov 2014 18:32:57 GMT'); | ||
e.content.should.eql({ more: 'data' }); | ||
e = data.items[1]; | ||
e.type.should.eql('opened'); | ||
e.gist.should.eql('sent'); | ||
e.event.should.eql('opened'); | ||
e.timestamp.should.eql('Tue, 18 Nov 2014 12:32:57 GMT'); | ||
e.content.should.eql({ more: 'data' }); | ||
}); | ||
@@ -73,18 +68,14 @@ }); | ||
it('fetches single page', function () { | ||
api.get('/v2/domain.com/events/pageId').reply(200, response); | ||
api.get('/v3/domain.com/events/pageId').reply(200, response); | ||
return client.get('domain.com', { page: 'pageId' }).then(function (data: any) { | ||
return client.get('domain.com', { page: 'pageId' }).then(function (data: EventsList) { | ||
let e; | ||
e = data.items[0]; | ||
e.type.should.eql('accepted'); | ||
e.gist.should.eql('got it'); | ||
e.event.should.eql('accepted'); | ||
e.timestamp.should.eql('Wed, 19 Nov 2014 18:32:57 GMT'); | ||
e.content.should.eql({ more: 'data' }); | ||
e = data.items[1]; | ||
e.type.should.eql('opened'); | ||
e.gist.should.eql('sent'); | ||
e.event.should.eql('opened'); | ||
e.timestamp.should.eql('Tue, 18 Nov 2014 12:32:57 GMT'); | ||
e.content.should.eql({ more: 'data' }); | ||
}); | ||
@@ -94,5 +85,5 @@ }); | ||
it('parses page links', function () { | ||
api.get('/v2/domain.com/events').reply(200, response); | ||
api.get('/v3/domain.com/events').reply(200, response); | ||
return client.get('domain.com').then(function (data: any) { | ||
return client.get('domain.com').then(function (data: EventsList) { | ||
let page; | ||
@@ -99,0 +90,0 @@ |
@@ -8,9 +8,12 @@ import formData from 'form-data'; | ||
import { InputFormData } from '../lib/interfaces/IFormData'; | ||
import MultipleValidationClient from '../lib/multipleValidation'; | ||
describe('ValidateClient', function () { | ||
let client: any; | ||
let api: any; | ||
let client: ValidateClient; | ||
let api: nock.Scope; | ||
beforeEach(function () { | ||
client = new ValidateClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData)); | ||
const reqObject = new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData); | ||
const multipleValidationClient = new MultipleValidationClient(reqObject); | ||
client = new ValidateClient(reqObject, multipleValidationClient); | ||
api = nock('https://api.mailgun.net'); | ||
@@ -32,3 +35,3 @@ }); | ||
api.get('/v3/address/validate') | ||
api.get('/v4/address/validate') | ||
.query({ address: 'foo@example.com' }) | ||
@@ -35,0 +38,0 @@ .reply(200, data); |
@@ -28,3 +28,3 @@ import formData from 'form-data'; | ||
it('fetches all webhooks', function () { | ||
api.get('/v2/domains/domain.com/webhooks').reply(200, { | ||
api.get('/v3/domains/domain.com/webhooks').reply(200, { | ||
webhooks: hooks | ||
@@ -41,3 +41,3 @@ }); | ||
it('fetches single webhook', function () { | ||
api.get('/v2/domains/domain.com/webhooks/click').reply(200, { | ||
api.get('/v3/domains/domain.com/webhooks/click').reply(200, { | ||
webhook: { | ||
@@ -56,3 +56,3 @@ url: 'trackclick.com' | ||
it('creates webhook', function () { | ||
api.post('/v2/domains/domain.com/webhooks') | ||
api.post('/v3/domains/domain.com/webhooks') | ||
.reply(200, { | ||
@@ -72,3 +72,3 @@ message: 'Webhook has been created', | ||
it('tests webhook', function () { | ||
api.put('/v2/domains/domain.com/webhooks/click/test') | ||
api.put('/v3/domains/domain.com/webhooks/click/test') | ||
.reply(200, { | ||
@@ -88,3 +88,3 @@ code: '500', | ||
it('updates webhook', function () { | ||
api.put('/v2/domains/domain.com/webhooks/click') | ||
api.put('/v3/domains/domain.com/webhooks/click') | ||
.reply(200, { | ||
@@ -105,3 +105,3 @@ message: 'Webhook has been updated', | ||
it('deletes webhook', function () { | ||
api.delete('/v2/domains/domain.com/webhooks/click').reply(200, { | ||
api.delete('/v3/domains/domain.com/webhooks/click').reply(200, { | ||
message: 'Webhook has been deleted', | ||
@@ -108,0 +108,0 @@ webhook: { |
@@ -8,2 +8,7 @@ const { merge } = require('webpack-merge'); | ||
filename: 'mailgun.node.js' | ||
}, | ||
watchOptions: { | ||
aggregateTimeout: 300, | ||
poll: 5000, | ||
ignored: ['../**/dist/*', '**/node_modules'] | ||
} | ||
@@ -16,2 +21,7 @@ }); | ||
filename: 'mailgun.web.js' | ||
}, | ||
watchOptions: { | ||
aggregateTimeout: 300, | ||
poll: 5000, | ||
ignored: ['../**/dist/*', '**/node_modules'] | ||
} | ||
@@ -18,0 +28,0 @@ }); |
Sorry, the diff of this file is too big to display
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
2281646
174
5461