export type CreateApiOauthAuthorizeArgs = {response_type: string, client_id: string, redirect_uri?: string | undefined, scope?: string | undefined, state?: string | undefined}; export type CreateApiOauthAuthorizeOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * OAuth Authorization Request * * POST /oauth/authorize * * Also accepts auth: X-PriceFx-jwt */ export const createApiOauthAuthorize = async (args: CreateApiOauthAuthorizeArgs, options?: CreateApiOauthAuthorizeOptions) => { const {baseUrl = "https://companynode.pricefx.com/pricefx/companypartition", fetch: fetchFn = fetch, basic} = 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 (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/oauth/authorize${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 };