Live video on the AT Protocol
at eli/fix-gitlab 36 lines 1.3 kB view raw
1import { Event, EventTarget } from "event-target-shim"; 2import { install as installRNQC } from "react-native-quick-crypto"; 3 4// Polyfill for the `throwIfAborted` method of the AbortController 5// used in @atproto/oauth-client 6import "abortcontroller-polyfill/dist/polyfill-patch-fetch"; 7 8// Polyfill for jose. It tries to detect whether it's been passed a CryptoKey 9// instance, and isn't willing to accept RNQC's equivalent. So, this ensures that 10// `key instanceof CryptoKey` will always be true. 11// @ts-ignore 12global.CryptoKey = Object; 13 14// This is needed to populate the `crypto` global for jose's export here 15// https://github.com/panva/jose/blob/1e8b430b08a18a18883a69e7991832c9c602ca1a/src/runtime/browser/webcrypto.ts#L1 16installRNQC(); 17 18// These two are needed for @atproto/oauth-client's `CustomEventTarget` to work. 19// @ts-ignore 20global.EventTarget = EventTarget; 21// @ts-ignore 22global.Event = Event; 23 24// And finally, this happens on React Native with every possible input: 25// URL.canParse("http://example.com") => false 26// I do not know why. Used in @atproto/oauth and @atproto/common-web 27if (!URL.canParse("http://example.com")) { 28 URL.canParse = (url: string | URL, base?: string) => { 29 try { 30 new URL(url, base); 31 return true; 32 } catch (e) { 33 return false; 34 } 35 }; 36}