UNPKG

@eleva-io/erp-sdk

Version:

SDK oficial para el ERP de Eleva

187 lines 6.37 kB
import { z } from 'zod'; import { ErrorKind } from './catalog_types'; /** * Generic HTTP-level error codes shared across all API domains. * Domain-specific codes live in `catalog_api.ts`. */ export var BASE_ERROR_CODES; (function (BASE_ERROR_CODES) { // >= 400 /** Input data failed schema or business-rule validation. */ BASE_ERROR_CODES["VALIDATION"] = "VALIDATION"; /** The request is malformed or contains invalid parameters. */ BASE_ERROR_CODES["BAD_REQUEST"] = "BAD_REQUEST"; /** Credentials are missing, expired, or invalid. */ BASE_ERROR_CODES["AUTHENTICATION"] = "AUTHENTICATION"; /** Authenticated but lacks the required permissions. */ BASE_ERROR_CODES["UNAUTHORIZED"] = "UNAUTHORIZED"; /** The requested resource does not exist. */ BASE_ERROR_CODES["NOT_FOUND"] = "NOT_FOUND"; /** Server cannot produce a response matching the `Accept` header. */ BASE_ERROR_CODES["NOT_ACCEPTABLE"] = "NOT_ACCEPTABLE"; /** Operation would violate a uniqueness or integrity constraint. */ BASE_ERROR_CODES["CONFLICT"] = "CONFLICT"; /** Resource existed but has been permanently removed (unlike 404, retrying is futile). */ BASE_ERROR_CODES["GONE"] = "GONE"; /** Request is syntactically valid but semantically unprocessable (e.g. invalid state transition). */ BASE_ERROR_CODES["UNPROCESSABLE_ENTITY"] = "UNPROCESSABLE_ENTITY"; /** A required field was omitted from the request. */ BASE_ERROR_CODES["MANDATORY_FIELD"] = "MANDATORY_FIELD"; // >= 500 /** Unexpected server-side error (`SYSTEM` — message sanitised before being sent to clients). */ BASE_ERROR_CODES["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR"; /** Upstream gateway received an invalid response from the origin server (`SYSTEM`). */ BASE_ERROR_CODES["BAD_GATEWAY"] = "BAD_GATEWAY"; /** Service is temporarily unavailable (`SYSTEM`). */ BASE_ERROR_CODES["SERVICE_UNAVAILABLE"] = "SERVICE_UNAVAILABLE"; })(BASE_ERROR_CODES || (BASE_ERROR_CODES = {})); /** Maps every `BASE_ERROR_CODES` member to its HTTP status, kind, default message, and details schema. */ export const BASE_ERRORS_CATALOG = { // >= 400 [BASE_ERROR_CODES.VALIDATION]: { kind: ErrorKind.DOMAIN, status: 400, details: z.object({ errors: z .object({ /** Dot-separated field path (e.g. `"address.zipCode"`) or `"root"` for top-level issues. */ validation: z.string(), /** Zod issue code (e.g. `"invalid_type"`, `"too_small"`). */ code: z.string(), message: z.string(), path: z.array(z.string()), }) .array(), }), message: 'Validation error', }, [BASE_ERROR_CODES.BAD_REQUEST]: { kind: ErrorKind.DOMAIN, status: 400, details: z .object({ field: z.string(), reason: z.string(), }) .partial(), message: 'Bad request', }, [BASE_ERROR_CODES.AUTHENTICATION]: { kind: ErrorKind.DOMAIN, status: 401, details: z .object({ /** Why authentication failed (e.g. `"token_expired"`). */ reason: z.string(), }) .partial(), message: 'Authentication failed', }, [BASE_ERROR_CODES.UNAUTHORIZED]: { kind: ErrorKind.DOMAIN, status: 403, details: z .object({ requiredScope: z.string(), resource: z.string(), }) .partial(), message: 'You do not have permission to perform this action', }, [BASE_ERROR_CODES.NOT_FOUND]: { kind: ErrorKind.DOMAIN, status: 404, details: z .object({ /** Entity type that was not found (e.g. `"Invoice"`). */ entity: z.string(), }) .partial(), message: 'Not found', }, [BASE_ERROR_CODES.NOT_ACCEPTABLE]: { kind: ErrorKind.DOMAIN, status: 406, details: z .object({ acceptedTypes: z.array(z.string()), }) .partial(), message: 'Not acceptable', }, /** Each item in the array identifies one conflicting field. */ [BASE_ERROR_CODES.CONFLICT]: { kind: ErrorKind.DOMAIN, status: 409, details: z .object({ key: z.string(), value: z.string(), cause: z.string(), }) .array(), message: 'Conflict', }, [BASE_ERROR_CODES.GONE]: { kind: ErrorKind.DOMAIN, status: 410, details: z .object({ /** ISO 8601 timestamp of when the resource was removed. */ since: z.string(), }) .partial(), message: 'Gone', }, [BASE_ERROR_CODES.UNPROCESSABLE_ENTITY]: { kind: ErrorKind.DOMAIN, status: 422, details: z .object({ field: z.string(), reason: z.string(), }) .partial(), message: 'Unprocessable entity', }, [BASE_ERROR_CODES.MANDATORY_FIELD]: { kind: ErrorKind.DOMAIN, status: 400, details: z.object({ field: z.string() }), message: 'Mandatory field is missing', }, // >= 500 [BASE_ERROR_CODES.INTERNAL_SERVER_ERROR]: { kind: ErrorKind.SYSTEM, status: 500, details: z .object({ reason: z.string(), }) .partial(), message: 'Internal server error', }, [BASE_ERROR_CODES.BAD_GATEWAY]: { kind: ErrorKind.SYSTEM, status: 502, details: z .object({ /** Name of the upstream service that returned the invalid response. */ upstream: z.string(), }) .partial(), message: 'Bad gateway', }, [BASE_ERROR_CODES.SERVICE_UNAVAILABLE]: { kind: ErrorKind.SYSTEM, status: 503, details: z .object({ /** Seconds the client should wait before retrying. */ retryAfter: z.number(), }) .partial(), message: 'Service unavailable', }, }; //# sourceMappingURL=catalog_base.js.map