UNPKG

1.62 kBTypeScriptView Raw
1import LoggerInterface from "./Interfaces/LoggerInterface";
2import RequestLimiter, { IRequestLimiterCallback } from "./RequestLimiter";
3export declare type RequestLimitConfig = {
4 run: (callable: IRequestLimiterCallback) => Promise<any>;
5 limiter: RequestLimiter;
6 method: string;
7 limiterKey: string;
8 endpoint: string;
9};
10export declare type RequestLimitProxyType = false | any;
11export declare type RequestLimitProxyTypes = RequestLimitProxyType[];
12export default class RequestLimitFactory {
13 private limiters;
14 private logger;
15 private enabledProxies;
16 private axiosClients;
17 /**
18 * Counts up to use proxies equally
19 */
20 private proxyCounter;
21 /**
22 * @param loggerInterface
23 * @param enabledProxies
24 */
25 constructor(loggerInterface: LoggerInterface, enabledProxies?: RequestLimitProxyTypes);
26 /**
27 * @param enabledProxies
28 */
29 setEnabledProxies(enabledProxies?: RequestLimitProxyTypes): void;
30 /**
31 * @param {string} endpoint
32 * @param {string} method
33 * @param {boolean} noProxy
34 * @returns {RequestLimitConfig}
35 */
36 create(endpoint: string, method?: string, noProxy?: boolean): RequestLimitConfig;
37 /**
38 * @param {string} limiterKey
39 * @returns {any}
40 */
41 getLimiter(limiterKey: string): RequestLimitConfig | false;
42 /**
43 * @param {string} limiterKey
44 * @returns {boolean}
45 */
46 removeLimiter(limiterKey: string): boolean;
47 getAllLimiters(): any;
48 clearLimiters(): void;
49 /**
50 * Returns a random index for the available proxies
51 */
52 private getProxyIndex;
53}