The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import { isFunction } from '@sniptt/guards';
import { isDefined } from 'twenty-shared/utils';
import { resolvePolyfillWindow } from '@/polyfills/utils/resolvePolyfillWindow';
export const installFetchWindowAlias = (
globalScope: Record<string, unknown>,
): void => {
const delegateToCurrentGlobalFetch = (
input: RequestInfo | URL,
init?: RequestInit,
): Promise<Response> => {
const currentGlobalFetch = globalScope.fetch;
if (!isFunction(currentGlobalFetch)) {
return Promise.reject(
new TypeError('fetch is not available in this environment'),
);
}
return currentGlobalFetch.call(globalScope, input, init);
};
const polyfillWindow = resolvePolyfillWindow(globalScope);
if (isDefined(polyfillWindow) && !('fetch' in polyfillWindow)) {
polyfillWindow.fetch = delegateToCurrentGlobalFetch;
}
};