export type GetApiV3Oauth2AuthorizeArgs = {clientId?: string | undefined, client_secret?: string | undefined, response_type: string, scope: string, redirect_uri?: string | undefined, state?: string | undefined}; export type GetApiV3Oauth2AuthorizeOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Request Authorization Code * * GET /v3/oauth2/authorize * * Also accepts auth: curedao_oauth2 */ export const getApiV3Oauth2Authorize = async (args: GetApiV3Oauth2AuthorizeArgs, options?: GetApiV3Oauth2AuthorizeOptions) => { const {baseUrl = "https://app.quantimo.do/api", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.clientId != null) query.append("clientId", String(args.clientId)) if (args.client_secret != null) query.append("client_secret", String(args.client_secret)) if (args.response_type != null) query.append("response_type", String(args.response_type)) if (args.scope != null) query.append("scope", String(args.scope)) if (args.redirect_uri != null) query.append("redirect_uri", String(args.redirect_uri)) if (args.state != null) query.append("state", String(args.state)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/oauth2/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 };