Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @ts-ignore
import JsonGlobal from "safe-json-globals/get";
const state = isBrowser && JsonGlobal("state");
const apolloState = isBrowser && state.apolloState;
const apolloAnalyticsState = isBrowser && state.apolloAnalyticsState;
const apiGatewayUrl = isBrowser && state.base.apiGatewayUrl;
const webBpApiGatewayUrl = isBrowser && state.base.webBpApiGatewayUrl;
const analyticsApiGatewayUrl = isBrowser && state.base.analyticsApiGatewayUrl;
const csrfToken = isBrowser && state.base.csrfToken;
const apolloClientConfig = {
uri: apiGatewayUrl
};
const fetch = unfetch.bind(window);
const MAX_CONCURRENT_REQUEST = 5;
let availableCap = MAX_CONCURRENT_REQUEST;
setInterval(() => (availableCap = MAX_CONCURRENT_REQUEST), 1000); // Rate cap to 5 requests per second
const limitRateFetch = async (
req: RequestInfo,
opt?: RequestInit
): Promise => {
if (availableCap > 0) {
availableCap--;
return fetch(req, opt);
}
return new Promise(resolve =>
setTimeout(() => resolve(limitRateFetch(req, opt)), 100)