UNPKG

@parkingboss/api

Version:
35 lines (34 loc) 1.07 kB
import { apiBase } from "./base"; import { session } from "./session"; import { queries } from "./queries"; function optsToSettings(opts) { const settings = { client: opts.client, user: null, apiBase: opts.apiBase || "TEMP_FAKE", }; if (!opts.apiBase) { const watcher = apiBase(); watcher.subscribe((newBase) => (settings.apiBase = newBase)); } return settings; } export function Api(opts) { const settings = optsToSettings(opts); const api = Object.assign({ settings }, session(settings), queries(settings)); if (!opts.skipUrlRewrite) { self.history.replaceState(null, "", urlWithoutToken()); } return api; } const removables = ["token", "access_token", "accessToken"]; function urlWithoutToken() { const url = new URL(location.toString()); const hash = new URLSearchParams(url.hash.replace(/^#/, "")); removables.forEach((key) => { url.searchParams.delete(key); hash.delete(key); }); url.hash = hash.toString(); return url.toString(); }