import {z} from 'zod' export type TerceroTipoDireccionPojo = {id?: number | undefined, nombre?: string | undefined}; export type UbicacionPaisPojo = {id?: number | undefined, nombre?: string | undefined, codigo?: string | undefined, codAlterno?: string | undefined}; export type UbicacionDepartamentoPojo = {id?: number | undefined, nombre?: string | undefined, codigo?: string | undefined, senSistema?: boolean | undefined, ubicacionPais?: UbicacionPaisPojo | undefined}; export type UbicacionCiudadPojo = {id?: number | undefined, ciudadNombre?: string | undefined, nombre?: string | undefined, codigo?: string | undefined, senSistema?: boolean | undefined, ubicacionDepartamento?: UbicacionDepartamentoPojo | undefined}; export type UbicacionBarrioPojo = {id?: number | undefined, nombre?: string | undefined, codigo?: string | undefined, ubicacionCiudad?: UbicacionCiudadPojo | undefined}; export type TerceroZonaPojo = {id?: number | undefined, nombre?: string | undefined, codigo?: string | undefined, senActivo?: boolean | undefined, folder?: boolean | undefined, borrador?: boolean | undefined}; export type TerceroDireccionPojo = {id?: number | undefined, nombre?: string | undefined, terceroTipoDireccion?: TerceroTipoDireccionPojo | undefined, direccion?: string | undefined, senPrincipal?: boolean | undefined, ubicacionCiudad?: UbicacionCiudadPojo | undefined, ubicacionBarrio?: UbicacionBarrioPojo | undefined, indicaciones?: string | undefined, telefonoPrincipal?: string | undefined, terceroZonaPojo?: TerceroZonaPojo | undefined, emailPrincipal?: string | undefined}; export type CrearTerceroAPIPojo = {id?: number | undefined, idTerceroTipoIdentificacion: number, identificacion: string, primerNombre: string, segundoNombre?: string | undefined, primerApellido?: string | undefined, segundoApellido?: string | undefined, idCiudad: number, codigo?: string | undefined, senActivo?: boolean | undefined, idTerceroTipos: Array, idTerceroTipoContribuyente: number, idClasificacionImpuestos: number, direccion: string, telefono: string, email: string, plazoDias: number, responsabilidadFiscal: Array, direcciones?: Array | undefined, idListaPrecioPredeterminada?: number | undefined, idTerceroVendedorPredeterminado?: number | undefined, idFormaPagoPredeterminada?: number | undefined, idLocal?: number | undefined, soloCrearDireccion?: boolean | undefined}; export type CreateApiApiV1TercerosCrearTerceroArgs = {body: CrearTerceroAPIPojo}; export type CreateApiApiV1TercerosCrearTerceroOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const terceroTipoIdentificacionPojo = z.object({id: z.number().int().optional(), abreviatura: z.string().optional(), nombre: z.string().optional(), codigo: z.string().optional(), senEsEmpresa: z.boolean().optional(), senManejaDV: z.boolean().optional()}); export const ubicacionPaisPojo = z.object({id: z.number().int().optional(), nombre: z.string().optional(), codigo: z.string().optional(), codAlterno: z.string().optional()}); export const ubicacionDepartamentoPojo = z.object({id: z.number().int().optional(), nombre: z.string().optional(), codigo: z.string().optional(), senSistema: z.boolean().optional(), ubicacionPais: ubicacionPaisPojo.optional()}); export const ubicacionCiudadPojo = z.object({id: z.number().int().optional(), ciudadNombre: z.string().optional(), nombre: z.string().optional(), codigo: z.string().optional(), senSistema: z.boolean().optional(), ubicacionDepartamento: ubicacionDepartamentoPojo.optional()}); export const terceroTipoPojo = z.object({id: z.number().int().optional(), codigo: z.string().optional(), nombre: z.string().optional()}); export const direccionPojo = z.object({id: z.number().int().optional(), direccion: z.string().optional(), ciudad: z.string().optional(), telefonoPrincipal: z.string().optional(), emailPrincipal: z.string().optional(), sucursal: z.string().optional(), senPrincipal: z.boolean().optional(), terceroTipoDireccionId: z.number().int().optional(), ciudadId: z.number().int().optional(), terceroTipoTelefonoId: z.number().int().optional(), numeroTelefonoPrincipal: z.string().optional()}); export const terceroPojo = z.object({id: z.number().int().optional(), terceroTipoIdentificacion: terceroTipoIdentificacionPojo.optional(), identificacion: z.string().optional(), digitoVerificacion: z.number().int().optional(), digitoVerificacionGenerado: z.boolean().optional(), primerNombre: z.string().optional(), segundoNombre: z.string().optional(), primerApellido: z.string().optional(), segundoApellido: z.string().optional(), nombreCompleto: z.string().optional(), nombreCompletoEmpleado: z.string().optional(), ciudad: ubicacionCiudadPojo.optional(), codigo: z.string().optional(), senActivo: z.boolean().optional(), senManejaNomina: z.boolean().optional(), atributos: z.boolean().optional(), tarifaICA: z.number().optional(), aplicaICAVentas: z.boolean().optional(), terceroTipos: z.array(terceroTipoPojo).optional(), tieneDirPrincipal: z.boolean().optional(), direccionPrincipal: direccionPojo.optional()}); export const responseAPITerceroPojo = z.object({status: z.enum(["100 CONTINUE", "101 SWITCHING_PROTOCOLS", "102 PROCESSING", "103 EARLY_HINTS", "103 CHECKPOINT", "200 OK", "201 CREATED", "202 ACCEPTED", "203 NON_AUTHORITATIVE_INFORMATION", "204 NO_CONTENT", "205 RESET_CONTENT", "206 PARTIAL_CONTENT", "207 MULTI_STATUS", "208 ALREADY_REPORTED", "226 IM_USED", "300 MULTIPLE_CHOICES", "301 MOVED_PERMANENTLY", "302 FOUND", "302 MOVED_TEMPORARILY", "303 SEE_OTHER", "304 NOT_MODIFIED", "305 USE_PROXY", "307 TEMPORARY_REDIRECT", "308 PERMANENT_REDIRECT", "400 BAD_REQUEST", "401 UNAUTHORIZED", "402 PAYMENT_REQUIRED", "403 FORBIDDEN", "404 NOT_FOUND", "405 METHOD_NOT_ALLOWED", "406 NOT_ACCEPTABLE", "407 PROXY_AUTHENTICATION_REQUIRED", "408 REQUEST_TIMEOUT", "409 CONFLICT", "410 GONE", "411 LENGTH_REQUIRED", "412 PRECONDITION_FAILED", "413 PAYLOAD_TOO_LARGE", "413 REQUEST_ENTITY_TOO_LARGE", "414 URI_TOO_LONG", "414 REQUEST_URI_TOO_LONG", "415 UNSUPPORTED_MEDIA_TYPE", "416 REQUESTED_RANGE_NOT_SATISFIABLE", "417 EXPECTATION_FAILED", "418 I_AM_A_TEAPOT", "419 INSUFFICIENT_SPACE_ON_RESOURCE", "420 METHOD_FAILURE", "421 DESTINATION_LOCKED", "422 UNPROCESSABLE_ENTITY", "423 LOCKED", "424 FAILED_DEPENDENCY", "425 TOO_EARLY", "426 UPGRADE_REQUIRED", "428 PRECONDITION_REQUIRED", "429 TOO_MANY_REQUESTS", "431 REQUEST_HEADER_FIELDS_TOO_LARGE", "451 UNAVAILABLE_FOR_LEGAL_REASONS", "500 INTERNAL_SERVER_ERROR", "501 NOT_IMPLEMENTED", "502 BAD_GATEWAY", "503 SERVICE_UNAVAILABLE", "504 GATEWAY_TIMEOUT", "505 HTTP_VERSION_NOT_SUPPORTED", "506 VARIANT_ALSO_NEGOTIATES", "507 INSUFFICIENT_STORAGE", "508 LOOP_DETECTED", "509 BANDWIDTH_LIMIT_EXCEEDED", "510 NOT_EXTENDED", "511 NETWORK_AUTHENTICATION_REQUIRED"]).optional(), userMessage: z.string().optional(), developerMessage: z.object({}).optional(), errorCode: z.string().optional(), moreInfo: z.string().optional(), data: terceroPojo.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 }; /** * Crear tercero * * POST /api/v1/terceros/crearTercero */ export const createApiApiV1TercerosCrearTercero = async (args: CreateApiApiV1TercerosCrearTerceroArgs, options?: CreateApiApiV1TercerosCrearTerceroOptions) => { const {baseUrl = "https://api.worldoffice.cloud", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/terceros/crearTercero${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(responseAPITerceroPojo, await res.json()) };