export type GetApiOauthAuthorizeArgs = {client_id: number, redirect_uri: string, response_type: 'code' | 'token'}; export type GetApiOauthAuthorizeOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Authorize client * * GET /oauth/authorize */ export const getApiOauthAuthorize = async (args: GetApiOauthAuthorizeArgs, options?: GetApiOauthAuthorizeOptions) => { const {baseUrl = "http://api.gostarmartbus.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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.response_type != null) query.append("response_type", String(args.response_type)) const url = `${baseUrl.replace(/\/+$/, '')}/oauth/authorize${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 };