|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
|
|
|
import rateLimit from 'axios-rate-limit';
|
|
|
|
|
import NodeCache from 'node-cache';
|
|
|
|
|
|
|
|
|
|
// 5 minute default TTL (in seconds)
|
|
|
|
@ -10,6 +11,10 @@ const DEFAULT_ROLLING_BUFFER = 10000;
|
|
|
|
|
interface ExternalAPIOptions {
|
|
|
|
|
nodeCache?: NodeCache;
|
|
|
|
|
headers?: Record<string, unknown>;
|
|
|
|
|
rateLimit?: {
|
|
|
|
|
maxRPS: number;
|
|
|
|
|
maxRequests: number;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ExternalAPI {
|
|
|
|
@ -31,6 +36,14 @@ class ExternalAPI {
|
|
|
|
|
...options.headers,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (options.rateLimit) {
|
|
|
|
|
this.axios = rateLimit(this.axios, {
|
|
|
|
|
maxRequests: options.rateLimit.maxRequests,
|
|
|
|
|
maxRPS: options.rateLimit.maxRPS,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.baseUrl = baseUrl;
|
|
|
|
|
this.cache = options.nodeCache;
|
|
|
|
|
}
|
|
|
|
|