Skip to content

Commit

Permalink
feature: Expose all types and rename type conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeSidSmith committed Aug 3, 2022
1 parent 249ceaf commit 6aee0e9
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 16 deletions.
5 changes: 3 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Client from './client';
import { InputFormData } from './types/IFormData';
import Options from './types/Options';
import { InputFormData, Options } from './types';

export * from './types';

export default class Mailgun {
static get default(): typeof Mailgun { return this; }
Expand Down
8 changes: 4 additions & 4 deletions lib/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
MailingList,
ValidationApiResponse,
StartValidationResult,
ValidationResult,
ListValidationResult,
CancelValidationResult,
MailingListResult,
MailingListApiResponse
Expand All @@ -27,14 +27,14 @@ export default class ListsClient
this.members = members;
}

private parseValidationResult(status: number, data: ValidationApiResponse): ValidationResult {
private parseValidationResult(status: number, data: ValidationApiResponse): ListValidationResult {
return {
status,
validationResult: {
...data,
created_at: new Date(data.created_at * 1000) // add millisecond to Unix timestamp
}
} as ValidationResult;
} as ListValidationResult;
}

protected parseList(response: MailingListApiResponse): MailingListResult {
Expand Down Expand Up @@ -80,7 +80,7 @@ export default class ListsClient
}) as StartValidationResult);
}

validationResult(mailListAddress: string): Promise<ValidationResult> {
validationResult(mailListAddress: string): Promise<ListValidationResult> {
return this.request.get(`${this.baseRoute}/${mailListAddress}/validate`)
.then(
(response) => this.parseValidationResult(
Expand Down
5 changes: 5 additions & 0 deletions lib/types/Suppressions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './Bounce';
export * from './Complaint';
export * from './Suppressions';
export * from './Unsubscribe';
export * from './WhiteList';
2 changes: 1 addition & 1 deletion lib/types/Webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type WebhooksQuery = {
skip?: number;
}

export interface ValidationResponse {
export interface WebhooksValidationResponse {
code: number;
message: string;
}
Expand Down
24 changes: 24 additions & 0 deletions lib/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export * from './APIErrorOptions';
export * from './ApiResponse';
export * from './DomainCredentials';
export * from './DomainTags';
export * from './DomainTemplates';
export * from './DomainTracking';
export * from './Domains';
export * from './Events';
export * from './IFormData';
export * from './IMailgunClient';
export * from './IpPools';
export * from './Ips';
export * from './Messages';
export * from './MultipleValidation';
export * from './NavigationThruPages';
export * from './Options';
export * from './RequestOptions';
export * from './StatsOptions';
export * from './Suppressions';
export * from './Validate';
export * from './Webhooks';
export * from './lists';
export * from './mailListMembers';
export * from './routes';
8 changes: 4 additions & 4 deletions lib/types/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface StartValidationResult {
message: string;
}

export interface ValidationResponse {
export interface ListValidationResponse {
status: string;
download_url: {
csv: string;
Expand All @@ -51,13 +51,13 @@ export interface ValidationResponse {
}
}
}
export interface ValidationApiResponse extends ValidationResponse{
export interface ValidationApiResponse extends ListValidationResponse{
created_at: number;
}
export interface ValidationResultData extends ValidationResponse{
export interface ValidationResultData extends ListValidationResponse{
created_at: Date;
}
export interface ValidationResult {
export interface ListValidationResult {
status: number;
validationResult: ValidationResultData;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/webhooks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import urljoin from 'url-join';

import {
ValidationResponse,
WebhooksValidationResponse,
WebhookList,
WebhookResponse,
WebhooksIds,
Expand Down Expand Up @@ -45,7 +45,7 @@ export default class WebhookClient {

_parseWebhookTest(response: { body: { code: number, message: string } })
: {code: number, message:string} {
return { code: response.body.code, message: response.body.message } as ValidationResponse;
return { code: response.body.code, message: response.body.message } as WebhooksValidationResponse;
}

list(domain: string, query: WebhooksQuery): Promise<WebhookList> {
Expand All @@ -61,7 +61,7 @@ export default class WebhookClient {
create(domain: string,
id: string,
url: string,
test = false): Promise<Webhook | ValidationResponse> {
test = false): Promise<Webhook | WebhooksValidationResponse> {
if (test) {
return this.request.putWithFD(urljoin('/v3/domains', domain, 'webhooks', id, 'test'), { url })
.then(this._parseWebhookTest);
Expand Down
4 changes: 2 additions & 2 deletions test/lists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
CancelValidationResult,
MailingList,
StartValidationResult,
ValidationResult
ListValidationResult
} from '../lib/types/lists';
import { InputFormData } from '../lib/types/IFormData';

Expand Down Expand Up @@ -179,7 +179,7 @@ describe('ListsClient', function () {
}
});

return client.validationResult('[email protected]').then(function (data: ValidationResult) {
return client.validationResult('[email protected]').then(function (data: ListValidationResult) {
data.should.eql({
status: 200,
validationResult: {
Expand Down

0 comments on commit 6aee0e9

Please sign in to comment.