export type GetApiProfileOAuth2RequestGrantArgs = {response_type: 'code', client_id: string, redirect_uri: string, scope?: ('rsu_api_read' | 'rsu_api_write' | 'rsu_api_read rsu_api_write') | undefined, state?: string | undefined, code_challenge?: string | undefined, code_challenge_method?: ('plain' | 'S256') | undefined}; export type GetApiProfileOAuth2RequestGrantOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Authorization Request Endpoint * * GET /Profile/OAuth2/RequestGrant */ export const getApiProfileOAuth2RequestGrant = async (args: GetApiProfileOAuth2RequestGrantArgs, options?: GetApiProfileOAuth2RequestGrantOptions) => { const {baseUrl = "https://api.runsignup.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.response_type != null) query.append("response_type", String(args.response_type)) if (args.client_id != null) query.append("client_id", String(args.client_id)) if (args.redirect_uri != null) query.append("redirect_uri", String(args.redirect_uri)) if (args.scope != null) query.append("scope", String(args.scope)) if (args.state != null) query.append("state", String(args.state)) if (args.code_challenge != null) query.append("code_challenge", String(args.code_challenge)) if (args.code_challenge_method != null) query.append("code_challenge_method", String(args.code_challenge_method)) const url = `${baseUrl.replace(/\/+$/, '')}/Profile/OAuth2/RequestGrant${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 };