export type GetApiCepCepZipArgs = {cep_zip: string}; export type GetApiCepCepZipOptions = {baseUrl: string, APIKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Download CEP ZIP file * * GET /cep/{cep_zip} */ export const getApiCepCepZip = async (args: GetApiCepCepZipArgs, options: GetApiCepCepZipOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/zip") if (APIKeyAuth !== undefined) headers.set("X-API-Key", APIKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/cep/${encodeURIComponent(String(args.cep_zip))}${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 res.blob() };