import accounts from "./accounts"; import createAuthedFetch from "./api/fake-fetch"; import fed from "./institutions"; import ping from "./ping"; import { INVALID_TOKEN_ERROR_MESSAGE } from "./constants"; import enrichment from "./enrichment"; import { Moov } from "./models"; import { plaid } from "./plaid"; import initializeDropWebComponents from "./drops"; import { drops } from "./drops"; import { isValidToken } from "./utils"; type MoovJS = (moovAccessToken: string) => Moov; declare global { interface Window { Moov?: MoovJS; } } declare const VERSION: string; initializeDropWebComponents(); const moovJSLoadedEvent = new CustomEvent("moov.moovJSLoaded"); setTimeout(() => document.dispatchEvent(moovJSLoadedEvent), 0); const Moov: MoovJS = (moovAccessToken) => { if (!isValidToken(moovAccessToken)) throw new Error(INVALID_TOKEN_ERROR_MESSAGE); const authedFetch = createAuthedFetch(moovAccessToken); return { ping: ping(authedFetch).ping, enrichment: { ...enrichment(authedFetch) }, institutions: { ...fed(authedFetch) }, accounts: { ...accounts(authedFetch) }, setToken: (newAccessToken: string) => Moov(newAccessToken), plaid: { ...plaid(authedFetch) }, drops: drops(moovAccessToken), version: VERSION, } }; export default Moov;