import {z} from 'zod' export type V1PackageUpdateRequest = {package?: ({updateMask?: string | undefined, shipTo?: ({name?: string | undefined, email?: string | undefined, phoneNumber?: string | undefined, federalTaxId?: string | undefined, address?: ({correios?: ({logradouro?: string | undefined, numero?: string | undefined, complemento?: string | undefined, bairro?: string | undefined, cep?: string | undefined, cidade?: string | undefined, uf?: string | undefined}) | undefined} | {lines?: ({addressLine1?: string | undefined, addressLine2?: string | undefined, postalCode?: string | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined}) | undefined}) | undefined}) | undefined, returnTo?: ({address?: ({correios?: ({logradouro?: string | undefined, numero?: string | undefined, complemento?: string | undefined, bairro?: string | undefined, cep?: string | undefined, cidade?: string | undefined, uf?: string | undefined}) | undefined} | {lines?: ({addressLine1?: string | undefined, addressLine2?: string | undefined, postalCode?: string | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined}) | undefined}) | undefined}) | undefined}) | undefined}; export type PatchApiV1CompaniesCompanyIdPackagesArgs = {company_id: string, loggi_key?: string | undefined, tracking_code?: string | undefined, body: V1PackageUpdateRequest}; export type PatchApiV1CompaniesCompanyIdPackagesOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const v1PackageUpdateResponse = z.object({warning_type: z.string().optional(), warning_message: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Atualizar dados de um pacote * * PATCH /v1/companies/{company_id}/packages */ export const patchApiV1CompaniesCompanyIdPackages = async (args: PatchApiV1CompaniesCompanyIdPackagesArgs, options?: PatchApiV1CompaniesCompanyIdPackagesOptions) => { const {baseUrl = "https://stg.api.loggi.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.loggi_key != null) query.append("loggi_key", String(args.loggi_key)) if (args.tracking_code != null) query.append("tracking_code", String(args.tracking_code)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/companies/${encodeURIComponent(String(args.company_id))}/packages${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(v1PackageUpdateResponse, await res.json()) };