UNPKG

3.79 kBTypeScriptView Raw
1import { AxiosInstance } from "axios";
2import { ErrorHandler } from "./ErrorHandler";
3import { Callback, ClientOptions, FilteringParameters } from "./models";
4/**
5 * Base client class from which client classes can be implemented, in our case, AccountClient and ServerClient classes.
6 * This class is NOT intended to be instantiated directly.
7 */
8export default abstract class BaseClient {
9 /**
10 * Client connection configuration options.
11 * You may modify these values and new clients will use them.
12 * Any values provided to a Client constructor will override default options.
13 */
14 static DefaultOptions: ClientOptions.Configuration;
15 clientVersion: string;
16 readonly httpClient: AxiosInstance;
17 protected errorHandler: ErrorHandler;
18 private clientOptions;
19 private readonly authHeader;
20 private readonly token;
21 protected constructor(token: string, authHeader: string, configOptions?: ClientOptions.Configuration);
22 setClientOptions(configOptions: ClientOptions.Configuration): void;
23 getClientOptions(): ClientOptions.Configuration;
24 /**
25 * JSON object with default headers sent by HTTP request.
26 */
27 getComposedHttpRequestHeaders(): object;
28 /**
29 * Process http request with sending body - data.
30 *
31 * @see processRequest for more details.
32 */
33 protected processRequestWithBody<T>(method: ClientOptions.HttpMethod, path: string, body: (null | object), callback?: Callback<T>): Promise<T>;
34 /**
35 * Process http request without sending body - data.
36 *
37 * @see processRequest for more details.
38 */
39 protected processRequestWithoutBody<T>(method: ClientOptions.HttpMethod, path: string, queryParameters?: object, callback?: Callback<T>): Promise<T>;
40 /**
41 * Set default values for count and offset when doing filtering with API requests if they are not specified by filter.
42 */
43 protected setDefaultPaginationValues(filter: FilteringParameters): void;
44 /**
45 * Process request for Postmark ClientOptions.
46 *
47 * @param method - see processHttpRequest for details
48 * @param path - see processHttpRequest for details
49 * @param queryParameters - see processHttpRequest for details
50 * @param body - see processHttpRequest for details
51 * @param callback - callback function to be executed.
52 *
53 * @returns A promise that will complete when the API responds (or an error occurs).
54 */
55 private processRequest;
56 /**
57 * Process HTTP request.
58 *
59 * @param method - Which type of http request will be executed.
60 * @param path - API URL endpoint.
61 * @param queryParameters - Querystring parameters used for http request.
62 * @param body - Data sent with http request.
63 *
64 * @returns A promise that will complete when the API responds (or an error occurs).
65 */
66 private processHttpRequest;
67 /**
68 * Process callback function for HTTP request.
69 *
70 * @param httpRequest - HTTP request for which callback will be executed
71 * @param callback - callback function to be executed.
72 */
73 private processCallbackRequest;
74 /**
75 * Process http request.
76 *
77 * @param method - Which type of http request will be executed.
78 * @param path - API URL endpoint.
79 * @param queryParameters - Querystring parameters used for http request.
80 * @param body - Data sent with http request.
81 */
82 private httpRequest;
83 /**
84 * Create http client instance with default settings.
85 *
86 * @return {AxiosInstance}
87 */
88 private buildDefaultHttpClient;
89 private getRequestTimeoutInSeconds;
90 private getBaseHttpRequestURL;
91 /**
92 * Token can't be empty.
93 *
94 * @param {string} token - HTTP request token
95 */
96 private verifyToken;
97}