1 | import { MagicalClass } from 'js-magic';
|
2 | import { AxiosInstance } from 'axios';
|
3 | import { IRequestResponse, APIHandlerConfig } from './types/http-request-handler';
|
4 | import { HttpRequestHandler } from './http-request-handler';
|
5 | /**
|
6 | * Handles dispatching of API requests
|
7 | */
|
8 | export declare class ApiHandler implements MagicalClass {
|
9 | /**
|
10 | * TS Index signature
|
11 | */
|
12 | [x: string]: any;
|
13 | /**
|
14 | * Api Url
|
15 | *
|
16 | * @memberof ApiHandler
|
17 | */
|
18 | apiUrl: string;
|
19 | /**
|
20 | * @var httpRequestHandler Request Wrapper Instance
|
21 | */
|
22 | httpRequestHandler: HttpRequestHandler;
|
23 | /**
|
24 | * Endpoints
|
25 | *
|
26 | * @memberof ApiHandler
|
27 | */
|
28 | apiEndpoints: Record<string, any>;
|
29 | /**
|
30 | * Logger
|
31 | *
|
32 | * @memberof ApiHandler
|
33 | */
|
34 | logger: any;
|
35 | /**
|
36 | * Creates an instance of API Handler
|
37 | *
|
38 | * @param {string} apiUrl Base URL for all API calls
|
39 | * @param {number} timeout Request timeout
|
40 | * @param {string} strategy Error Handling Strategy
|
41 | * @param {string} flattenResponse Whether to flatten response "data" object within "data" one
|
42 | * @param {*} logger Instance of Logger Class
|
43 | * @param {*} httpRequestErrorService Instance of Error Service Class
|
44 | *
|
45 | * @memberof ApiHandler
|
46 | */
|
47 | constructor({ apiUrl, apiEndpoints, timeout, strategy, flattenResponse, logger, httpRequestErrorService, ...config }: APIHandlerConfig);
|
48 | /**
|
49 | * Get Provider Instance
|
50 | *
|
51 | * @returns {AxiosInstance} Provider's instance
|
52 | * ApiHandler
|
53 | */
|
54 | getInstance(): AxiosInstance;
|
55 | /**
|
56 | * Maps all API requests
|
57 | *
|
58 | * @param {*} prop Caller
|
59 | * @returns {Function} Tailored request function
|
60 | * @memberof ApiHandler
|
61 | */
|
62 | __get(prop: any): any;
|
63 | /**
|
64 | * Handle Single API Request
|
65 | *
|
66 | * @param {*} args Arguments
|
67 | * @returns {Promise} Resolvable API provider promise
|
68 | * @memberof ApiHandler
|
69 | */
|
70 | handleRequest(...args: any): Promise<IRequestResponse>;
|
71 | /**
|
72 | * Triggered when trying to use non-existent endpoints
|
73 | * @param prop Method Name
|
74 | * @returns {Promise}
|
75 | * @memberof ApiHandler
|
76 | */
|
77 | protected handleNonImplemented(prop: string): Promise<any>;
|
78 | }
|
79 | export declare const createApiFetcher: (options: APIHandlerConfig) => ApiHandler;
|