export type GetApiApiV2MeArgs = {Accept: string, Authorization: string, 'User-Agent': string}; export type GetApiApiV2MeOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Listar informações do usuário * * GET /api/v2/me */ export const getApiApiV2Me = async (args: GetApiApiV2MeArgs, options?: GetApiApiV2MeOptions) => { const {baseUrl = "https://sandbox.melhorenvio.com.br", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args['User-Agent'] != null) headers.set("User-Agent", String(args['User-Agent'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/me${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 (await res.json()) as unknown };