mailtrap-client
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -5,3 +5,3 @@ "use strict"; | ||
Object.defineProperty(exports, "MailtrapClient", { enumerable: true, get: function () { return MailtrapClient_1.MailtrapClient; } }); | ||
var HttpClient_1 = require("./api/HttpClient"); | ||
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return HttpClient_1.HttpClient; } }); | ||
var FetchHttpProvider_1 = require("./http/FetchHttpProvider"); | ||
Object.defineProperty(exports, "FetchProvider", { enumerable: true, get: function () { return FetchHttpProvider_1.FetchProvider; } }); |
@@ -5,3 +5,3 @@ "use strict"; | ||
const MessagesEndpoint_1 = require("./api/MessagesEndpoint"); | ||
const HttpClient_1 = require("./api/HttpClient"); | ||
const HttpClient_1 = require("./http/HttpClient"); | ||
const UserEndpoint_1 = require("./api/UserEndpoint"); | ||
@@ -12,7 +12,8 @@ const CompaniesEndpoint_1 = require("./api/CompaniesEndpoint"); | ||
const CorsDomainsEndpoint_1 = require("./api/CorsDomainsEndpoint"); | ||
const FetchHttpProvider_1 = require("./http/FetchHttpProvider"); | ||
class MailtrapClient { | ||
constructor(apiKey, http = new HttpClient_1.HttpClient()) { | ||
constructor(apiKey, provider = FetchHttpProvider_1.FetchProvider) { | ||
this.apiKey = apiKey; | ||
const urlBase = 'https://mailtrap.io/api/v1'; | ||
http.setup(this.apiKey, urlBase); | ||
const http = new HttpClient_1.HttpClient(this.apiKey, urlBase, provider); | ||
this.user = new UserEndpoint_1.UserEndpoint(http); | ||
@@ -19,0 +20,0 @@ this.companies = new CompaniesEndpoint_1.CompaniesEndpoint(http); |
@@ -5,40 +5,13 @@ declare module 'mailtrap-client' { | ||
export type ResponseType = 'json' | 'text'; | ||
export type HttpMethod = HttpMethodWithoutBody | HttpMethodWithBody; | ||
export interface IHttpClient { | ||
setup(apiKey: string, urlBase: string): void; | ||
export type HttpProvider = ( | ||
method: HttpMethod, | ||
url: string, | ||
headers: Record<string, any>, | ||
responseType: ResponseType, | ||
data?: any | ||
) => Promise<any>; | ||
export const FetchProvider: HttpProvider; | ||
request<T>( | ||
method: HttpMethodWithoutBody, | ||
url: string, | ||
data?: RequestInit, | ||
responseType?: ResponseType | ||
): Promise<T>; | ||
request<T>( | ||
method: HttpMethodWithBody, | ||
url: string, | ||
data?: any, | ||
init?: RequestInit, | ||
responseType?: ResponseType | ||
): Promise<T>; | ||
} | ||
export class HttpClient implements IHttpClient { | ||
public setup(apiKey: string, urlBase: string): void; | ||
public request<T>( | ||
method: HttpMethodWithoutBody, | ||
url: string, | ||
data?: RequestInit, | ||
responseType?: ResponseType | ||
): Promise<T>; | ||
public request<T>( | ||
method: HttpMethodWithBody, | ||
url: string, | ||
data?: any, | ||
init?: RequestInit, | ||
responseType?: ResponseType | ||
): Promise<T>; | ||
} | ||
export class MailtrapClient { | ||
@@ -54,3 +27,3 @@ public readonly user: UserEndpoint; | ||
constructor(apiKey: string, httpClient?: IHttpClient); | ||
constructor(apiKey: string, httpClient?: HttpProvider); | ||
} | ||
@@ -57,0 +30,0 @@ |
{ | ||
"name": "mailtrap-client", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Mailtrap.io api client with some added features", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -37,7 +37,7 @@ # mailtrap-client | ||
|-------------------------| | ||
| user | | ||
| companies | | ||
| inboxes | | ||
| sharedInboxes | | ||
| messages | | ||
| corsDomains | | ||
| `user` | | ||
| `companies` | | ||
| `inboxes` | | ||
| `sharedInboxes` | | ||
| `messages` | | ||
| `corsDomains` | |
35865
15
824