import {z} from 'zod' export type CarrierUpdate = {transportista_tipo_documento?: (string | null) | undefined, transportista_denominacion: string, transportista_numero_documento?: (string | null) | undefined, transportista_email?: (string | string | null) | undefined, transportista_telefono?: (string | null) | undefined, transportista_distrito_id?: (string | null) | undefined, transportista_direccion?: (string | null) | undefined, user_id?: (number | null) | undefined, company_id?: (number | null) | undefined}; export type UpdateApiCarriersCarrierIdArgs = {carrier_id: number, 'X-Company-Token': string, body: CarrierUpdate}; export type UpdateApiCarriersCarrierIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const carrierOut = z.object({transportista_tipo_documento: z.string().nullable().optional(), transportista_denominacion: z.string(), transportista_numero_documento: z.string().nullable().optional(), transportista_email: z.union([z.string(), z.string()]).nullable().optional(), transportista_telefono: z.string().nullable().optional(), transportista_distrito_id: z.string().nullable().optional(), transportista_direccion: z.string().nullable().optional(), document_type_code: z.union([z.number().int(), z.string()]).nullable().optional(), id: z.number().int().nullable().optional(), user_id: z.number().int().nullable().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 }; /** * Update * * PUT /carriers/{carrier_id} */ export const updateApiCarriersCarrierId = async (args: UpdateApiCarriersCarrierIdArgs, options: UpdateApiCarriersCarrierIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Company-Token'] != null) headers.set("X-Company-Token", String(args['X-Company-Token'])) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/carriers/${encodeURIComponent(String(args.carrier_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(carrierOut, await res.json()) };