@baqhub/sdk-react-native
Version:
The official React Native SDK for the BAQ federated app platform.
27 lines (26 loc) • 899 B
JavaScript
// We don't actually want to polyfill "fetch".
// It was more complicated to manually polyfill one by one.
const originalFetch = global.fetch;
const originalHeaders = global.Headers;
const originalRequest = global.Request;
const originalResponse = global.Response;
// Polyfill for URL, btoa/atob, ReadableStream,
// fetch, TextEncoder/TextDecoder, crypto.getRandomValues()
import "react-native-polyfill-globals/auto";
const polyFetch = global.fetch;
global.fetch = originalFetch;
global.Headers = originalHeaders;
global.Request = originalRequest;
global.Response = originalResponse;
const eventSourceFetch = (input, init) => {
return polyFetch(input, {
...init,
reactNative: { textStreaming: true },
});
};
import { setHttpApi } from "@baqhub/sdk";
setHttpApi({
fetch: originalFetch,
eventSourceFetch: eventSourceFetch,
});
export * from "./asyncStorageAdapter.js";