UNPKG

reactotron-react-native

Version:

A development tool to explore, inspect, and diagnose your React Native apps.

55 lines 2.8 kB
/** * Intercepts the global `fetch` when it is Expo's expo/fetch implementation * (the default `globalThis.fetch` on Expo SDK 56+). expo/fetch is backed by a * native module and bypasses `XMLHttpRequest`, so it is invisible to * `XHRInterceptor`. This wraps it so the networking plugin can report * expo/fetch traffic the same way it reports XHR traffic. * * The shape mirrors ./xhr-interceptor (set*Callback / enableInterception / * disableInterception) so `networking.ts` can wire Reactotron into it the same * way. On platforms/SDKs where the global fetch is not expo/fetch (e.g. RN's * XHR-backed fetch, which is already covered by `XHRInterceptor`), this is a * no-op. */ export type FetchHeaders = Record<string, string> | null; type FetchInterceptorOpenCallback = (method: string, url: string, headers: FetchHeaders, data: string | null, id: number) => void; /** * Invoked synchronously as soon as the response resolves, BEFORE the response * is returned to the caller. To read the body, clone `response` synchronously * inside the callback (do not `await` before cloning) so the caller's copy is * left intact and streaming responses are not blocked. `response` is null when * the request rejected (network error); `error` then holds the rejection. */ type FetchInterceptorResponseCallback = (id: number, status: number, headers: FetchHeaders, response: Response | null, error: unknown) => void; /** * A network interceptor for Expo's expo/fetch. Mirrors `XHRInterceptor` so the * networking plugin can register callbacks and enable/disable it identically. */ export declare const FetchInterceptor: { /** * Invoked synchronously before the wrapped fetch is sent. */ setOpenCallback(callback: FetchInterceptorOpenCallback): void; /** * Invoked synchronously when the response resolves (or rejects). See the * callback type for the body-cloning contract. */ setResponseCallback(callback: FetchInterceptorResponseCallback): void; isInterceptorEnabled(): boolean; /** * Wraps the global fetch and reassigns `globalThis.fetch`. * * With no argument, only expo/fetch is wrapped (detected by the * `expo.builtin` symbol). RN's XHR-backed fetch is already covered by * `XHRInterceptor`, and wrapping it here too would double-report. * * Pass `fetchToWrap` to skip the detection and wrap that function instead — * for runtimes where the expo/fetch global has been re-wrapped and lost the * symbol (e.g. expo-router's window.location polyfill). The caller is * asserting the function does not go through XMLHttpRequest. */ enableInterception(fetchToWrap?: typeof fetch): void; disableInterception(): void; }; export {}; //# sourceMappingURL=fetch-interceptor.d.ts.map