export type CreateApiV1TokensArgs = {body: {refresh_token: string, grant_type: string}}; export type CreateApiV1TokensOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Refresh an access token * * POST /v1/tokens# */ export const createApiV1Tokens = async (args: CreateApiV1TokensArgs, options?: CreateApiV1TokensOptions) => { const {baseUrl = "https://api.zenoti.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/plain") const url = `${baseUrl.replace(/\/+$/, '')}/v1/tokens#${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.text() };