export type RefreshTokenView = {refreshToken?: string | undefined}; export type CreateApiAuthRefreshArgs = {'client-id': string, 'client-secret': string, body: RefreshTokenView}; export type CreateApiAuthRefreshOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Update the access token * * POST /auth/refresh */ export const createApiAuthRefresh = async (args: CreateApiAuthRefreshArgs, options?: CreateApiAuthRefreshOptions) => { const {baseUrl = "https://api.cloudally.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") if (args['client-id'] != null) headers.set("client-id", String(args['client-id'])) if (args['client-secret'] != null) headers.set("client-secret", String(args['client-secret'])) const url = `${baseUrl.replace(/\/+$/, '')}/auth/refresh${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };