export type CreateApiV1Oauth2TokenArgs = {'Content-Type'?: string | undefined}; export type CreateApiV1Oauth2TokenOptions = {baseUrl: string, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * Refresh Token * * POST /v1/oauth2/token */ export const createApiV1Oauth2Token = async (args: CreateApiV1Oauth2TokenArgs, options: CreateApiV1Oauth2TokenOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/oauth2/token${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };