@eleva-io/erp-sdk
Version:
SDK oficial para el ERP de Eleva
190 lines • 6.97 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BASE_ERRORS_CATALOG = exports.BASE_ERROR_CODES = void 0;
const zod_1 = require("zod");
const catalog_types_1 = require("./catalog_types");
/**
* Generic HTTP-level error codes shared across all API domains.
* Domain-specific codes live in `catalog_api.ts`.
*/
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 || (exports.BASE_ERROR_CODES = BASE_ERROR_CODES = {}));
/** Maps every `BASE_ERROR_CODES` member to its HTTP status, kind, default message, and details schema. */
exports.BASE_ERRORS_CATALOG = {
// >= 400
[]: {
kind: catalog_types_1.ErrorKind.DOMAIN,
status: 400,
details: zod_1.z.object({
errors: zod_1.z
.object({
/** Dot-separated field path (e.g. `"address.zipCode"`) or `"root"` for top-level issues. */
validation: zod_1.z.string(),
/** Zod issue code (e.g. `"invalid_type"`, `"too_small"`). */
code: zod_1.z.string(),
message: zod_1.z.string(),
path: zod_1.z.array(zod_1.z.string()),
})
.array(),
}),
message: 'Validation error',
},
[]: {
kind: catalog_types_1.ErrorKind.DOMAIN,
status: 400,
details: zod_1.z
.object({
field: zod_1.z.string(),
reason: zod_1.z.string(),
})
.partial(),
message: 'Bad request',
},
[]: {
kind: catalog_types_1.ErrorKind.DOMAIN,
status: 401,
details: zod_1.z
.object({
/** Why authentication failed (e.g. `"token_expired"`). */
reason: zod_1.z.string(),
})
.partial(),
message: 'Authentication failed',
},
[]: {
kind: catalog_types_1.ErrorKind.DOMAIN,
status: 403,
details: zod_1.z
.object({
requiredScope: zod_1.z.string(),
resource: zod_1.z.string(),
})
.partial(),
message: 'You do not have permission to perform this action',
},
[]: {
kind: catalog_types_1.ErrorKind.DOMAIN,
status: 404,
details: zod_1.z
.object({
/** Entity type that was not found (e.g. `"Invoice"`). */
entity: zod_1.z.string(),
})
.partial(),
message: 'Not found',
},
[]: {
kind: catalog_types_1.ErrorKind.DOMAIN,
status: 406,
details: zod_1.z
.object({
acceptedTypes: zod_1.z.array(zod_1.z.string()),
})
.partial(),
message: 'Not acceptable',
},
/** Each item in the array identifies one conflicting field. */
[]: {
kind: catalog_types_1.ErrorKind.DOMAIN,
status: 409,
details: zod_1.z
.object({
key: zod_1.z.string(),
value: zod_1.z.string(),
cause: zod_1.z.string(),
})
.array(),
message: 'Conflict',
},
[]: {
kind: catalog_types_1.ErrorKind.DOMAIN,
status: 410,
details: zod_1.z
.object({
/** ISO 8601 timestamp of when the resource was removed. */
since: zod_1.z.string(),
})
.partial(),
message: 'Gone',
},
[]: {
kind: catalog_types_1.ErrorKind.DOMAIN,
status: 422,
details: zod_1.z
.object({
field: zod_1.z.string(),
reason: zod_1.z.string(),
})
.partial(),
message: 'Unprocessable entity',
},
[]: {
kind: catalog_types_1.ErrorKind.DOMAIN,
status: 400,
details: zod_1.z.object({ field: zod_1.z.string() }),
message: 'Mandatory field is missing',
},
// >= 500
[]: {
kind: catalog_types_1.ErrorKind.SYSTEM,
status: 500,
details: zod_1.z
.object({
reason: zod_1.z.string(),
})
.partial(),
message: 'Internal server error',
},
[]: {
kind: catalog_types_1.ErrorKind.SYSTEM,
status: 502,
details: zod_1.z
.object({
/** Name of the upstream service that returned the invalid response. */
upstream: zod_1.z.string(),
})
.partial(),
message: 'Bad gateway',
},
[]: {
kind: catalog_types_1.ErrorKind.SYSTEM,
status: 503,
details: zod_1.z
.object({
/** Seconds the client should wait before retrying. */
retryAfter: zod_1.z.number(),
})
.partial(),
message: 'Service unavailable',
},
};
//# sourceMappingURL=catalog_base.js.map