export type GetApiV2OauthAuthorizeArgs = {client_id: string, realm?: ('customer' | 'contributor') | undefined, redirect_uri: string, response_type: 'code', scope?: string | undefined, state: string}; export type GetApiV2OauthAuthorizeOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Authorize applications * * GET /v2/oauth/authorize */ export const getApiV2OauthAuthorize = async (args: GetApiV2OauthAuthorizeArgs, options?: GetApiV2OauthAuthorizeOptions) => { const {baseUrl = "https://api.shutterstock.com", 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.realm != null) query.append("realm", String(args.realm)) 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)) if (args.scope != null) query.append("scope", String(args.scope)) if (args.state != null) query.append("state", String(args.state)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/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 };