export type GetApiV1AuthTokenArgs = {'App-ID': string, 'Auth-Token': string}; export type GetApiV1AuthTokenOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Check if auth token valid * * GET /v1/auth/token/ */ export const getApiV1AuthToken = async (args: GetApiV1AuthTokenArgs, options: GetApiV1AuthTokenOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args['App-ID'] != null) headers.set("App-ID", String(args['App-ID'])) if (args['Auth-Token'] != null) headers.set("Auth-Token", String(args['Auth-Token'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/auth/token/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };