@jmlq/auth 0.0.1-alpha.32 → 0.0.1-alpha.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,4 +9,8 @@
|
|
|
9
9
|
* - Mantén este catálogo pequeño y estable.
|
|
10
10
|
* - Si agregas un error nuevo, agrega aquí su código.
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* ÚNICA fuente de verdad de los códigos.
|
|
14
|
+
*/
|
|
15
|
+
export declare const AUTH_ERROR_CODES: readonly ["TOKEN_INVALID", "TOKEN_EXPIRED", "TOKEN_MALFORMED", "SIGNATURE_INVALID", "AUTHENTICATION_FAILED", "JWT_ERROR", "KEY_MISMATCH", "KEY_NOT_FOUND", "KEY_MISMATCH", "CLAIMS_VALIDATION_ERROR", "JWT_PAYLOAD_INVALID", "TOKEN_NOT_YET_VALID", "JWT_EMPTY", "JWT_MALFORMED", "ALGORITHM_UNSUPPORTED", "KEY_MISMATCH", "KEY_NOT_FOUND", "INVALID_EMAIL", "INVALID_HASHED_PASSWORD", "PASSWORD_POLICY_VIOLATION", "PASSWORD_MISMATCH", "USER_NOT_FOUND", "USER_DISABLED", "EMAIL_ALREADY_IN_USE", "INVALID_PERMISSION", "INVALID_ROLE", "INVALID_ID", "LOGOUT_FAILED", "EMAIL_NOT_VERIFIED", "PASSWORD_RESET_TOKEN_INVALID", "PASSWORD_RESET_TOKEN_EXPIRED", "PASSWORD_RESET_TOKEN_ALREADY_USED"];
|
|
16
|
+
export type AuthErrorCode = (typeof AUTH_ERROR_CODES)[number];
|
|
@@ -1,2 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AUTH_ERROR_CODES = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Códigos canónicos de error del dominio de Auth.
|
|
6
|
+
*
|
|
7
|
+
* Objetivo:
|
|
8
|
+
* - Host / plugins NO deben depender de `error.name` o `message`.
|
|
9
|
+
* - Solo deben mapear por `code`.
|
|
10
|
+
*
|
|
11
|
+
* Nota:
|
|
12
|
+
* - Mantén este catálogo pequeño y estable.
|
|
13
|
+
* - Si agregas un error nuevo, agrega aquí su código.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* ÚNICA fuente de verdad de los códigos.
|
|
17
|
+
*/
|
|
18
|
+
exports.AUTH_ERROR_CODES = [
|
|
19
|
+
// JWT / sesión
|
|
20
|
+
"TOKEN_INVALID",
|
|
21
|
+
"TOKEN_EXPIRED",
|
|
22
|
+
"TOKEN_MALFORMED", // formato invalido (no header.payload.signature),
|
|
23
|
+
"SIGNATURE_INVALID",
|
|
24
|
+
"AUTHENTICATION_FAILED", // catch-all de autenticación,
|
|
25
|
+
"JWT_ERROR",
|
|
26
|
+
"KEY_MISMATCH",
|
|
27
|
+
"KEY_NOT_FOUND",
|
|
28
|
+
"KEY_MISMATCH",
|
|
29
|
+
"CLAIMS_VALIDATION_ERROR",
|
|
30
|
+
"JWT_PAYLOAD_INVALID",
|
|
31
|
+
"TOKEN_NOT_YET_VALID",
|
|
32
|
+
"JWT_EMPTY",
|
|
33
|
+
"JWT_MALFORMED",
|
|
34
|
+
// Refresh Token
|
|
35
|
+
"ALGORITHM_UNSUPPORTED",
|
|
36
|
+
"KEY_MISMATCH",
|
|
37
|
+
"KEY_NOT_FOUND",
|
|
38
|
+
// Identidad / login
|
|
39
|
+
"INVALID_EMAIL",
|
|
40
|
+
"INVALID_HASHED_PASSWORD",
|
|
41
|
+
"PASSWORD_POLICY_VIOLATION",
|
|
42
|
+
"PASSWORD_MISMATCH",
|
|
43
|
+
"USER_NOT_FOUND",
|
|
44
|
+
"USER_DISABLED",
|
|
45
|
+
"EMAIL_ALREADY_IN_USE",
|
|
46
|
+
"INVALID_PERMISSION",
|
|
47
|
+
"INVALID_ROLE",
|
|
48
|
+
"INVALID_ID",
|
|
49
|
+
"LOGOUT_FAILED",
|
|
50
|
+
"EMAIL_NOT_VERIFIED",
|
|
51
|
+
// Password reset
|
|
52
|
+
"PASSWORD_RESET_TOKEN_INVALID",
|
|
53
|
+
"PASSWORD_RESET_TOKEN_EXPIRED",
|
|
54
|
+
"PASSWORD_RESET_TOKEN_ALREADY_USED",
|
|
55
|
+
];
|
|
@@ -3,6 +3,7 @@ export interface ClaimsIssue {
|
|
|
3
3
|
path: string;
|
|
4
4
|
message: string;
|
|
5
5
|
}
|
|
6
|
+
export declare function isAuthErrorCode(value: unknown): value is AuthErrorCode;
|
|
6
7
|
export declare abstract class AuthDomainError extends Error {
|
|
7
8
|
readonly code: AuthErrorCode;
|
|
8
9
|
readonly details?: unknown;
|
|
@@ -10,9 +11,21 @@ export declare abstract class AuthDomainError extends Error {
|
|
|
10
11
|
toJSON(): {
|
|
11
12
|
name: string;
|
|
12
13
|
message: string;
|
|
13
|
-
code:
|
|
14
|
+
code: "TOKEN_INVALID" | "TOKEN_EXPIRED" | "TOKEN_MALFORMED" | "SIGNATURE_INVALID" | "AUTHENTICATION_FAILED" | "JWT_ERROR" | "KEY_MISMATCH" | "KEY_NOT_FOUND" | "CLAIMS_VALIDATION_ERROR" | "JWT_PAYLOAD_INVALID" | "TOKEN_NOT_YET_VALID" | "JWT_EMPTY" | "JWT_MALFORMED" | "ALGORITHM_UNSUPPORTED" | "INVALID_EMAIL" | "INVALID_HASHED_PASSWORD" | "PASSWORD_POLICY_VIOLATION" | "PASSWORD_MISMATCH" | "USER_NOT_FOUND" | "USER_DISABLED" | "EMAIL_ALREADY_IN_USE" | "INVALID_PERMISSION" | "INVALID_ROLE" | "INVALID_ID" | "LOGOUT_FAILED" | "EMAIL_NOT_VERIFIED" | "PASSWORD_RESET_TOKEN_INVALID" | "PASSWORD_RESET_TOKEN_EXPIRED" | "PASSWORD_RESET_TOKEN_ALREADY_USED";
|
|
14
15
|
details: unknown;
|
|
15
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Guard estable para errores del core.
|
|
19
|
+
*
|
|
20
|
+
* - `instanceof` es el camino ideal, pero puede fallar si hay:
|
|
21
|
+
* - múltiples copias del paquete en runtime (resolución/hoisting),
|
|
22
|
+
* - bundles,
|
|
23
|
+
* - errores creados por hosts que replican forma (code/message).
|
|
24
|
+
*
|
|
25
|
+
* Regla:
|
|
26
|
+
* - Si tiene forma mínima { code: string, message: string }, lo tratamos como AuthDomainError.
|
|
27
|
+
* - El core sigue siendo el “owner” de los códigos y su significado.
|
|
28
|
+
*/
|
|
16
29
|
static isAuthError(e: unknown): e is AuthDomainError;
|
|
17
30
|
}
|
|
18
31
|
/** El token ya no es válido por exp (exp < now) */
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EmailNotVerifiedError = exports.SessionAuthError = exports.AuthenticationError = exports.InvalidSignatureError = exports.InvalidTokenFormatError = exports.TokenExpiredError = exports.AuthDomainError = void 0;
|
|
4
|
+
exports.isAuthErrorCode = isAuthErrorCode;
|
|
5
|
+
const auth_error_code_1 = require("./auth-error-code");
|
|
6
|
+
function asAuthErrorLike(value) {
|
|
7
|
+
if (value && typeof value === "object")
|
|
8
|
+
return value;
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
const AUTH_ERROR_CODE_SET = new Set(auth_error_code_1.AUTH_ERROR_CODES);
|
|
12
|
+
function isAuthErrorCode(value) {
|
|
13
|
+
return typeof value === "string" && AUTH_ERROR_CODE_SET.has(value);
|
|
14
|
+
}
|
|
4
15
|
class AuthDomainError extends Error {
|
|
5
16
|
constructor(message, code, details) {
|
|
6
17
|
super(message);
|
|
@@ -8,7 +19,8 @@ class AuthDomainError extends Error {
|
|
|
8
19
|
this.details = details;
|
|
9
20
|
this.name = new.target.name;
|
|
10
21
|
// Compatible con V8; ignora silenciosamente en otros engines
|
|
11
|
-
if (typeof Error
|
|
22
|
+
if (typeof Error
|
|
23
|
+
.captureStackTrace === "function") {
|
|
12
24
|
Error.captureStackTrace(this, new.target);
|
|
13
25
|
}
|
|
14
26
|
}
|
|
@@ -20,8 +32,24 @@ class AuthDomainError extends Error {
|
|
|
20
32
|
details: this.details,
|
|
21
33
|
};
|
|
22
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Guard estable para errores del core.
|
|
37
|
+
*
|
|
38
|
+
* - `instanceof` es el camino ideal, pero puede fallar si hay:
|
|
39
|
+
* - múltiples copias del paquete en runtime (resolución/hoisting),
|
|
40
|
+
* - bundles,
|
|
41
|
+
* - errores creados por hosts que replican forma (code/message).
|
|
42
|
+
*
|
|
43
|
+
* Regla:
|
|
44
|
+
* - Si tiene forma mínima { code: string, message: string }, lo tratamos como AuthDomainError.
|
|
45
|
+
* - El core sigue siendo el “owner” de los códigos y su significado.
|
|
46
|
+
*/
|
|
23
47
|
static isAuthError(e) {
|
|
24
|
-
|
|
48
|
+
if (e instanceof AuthDomainError)
|
|
49
|
+
return true;
|
|
50
|
+
const like = asAuthErrorLike(e);
|
|
51
|
+
// Exigir que code sea uno de los canónicos del core
|
|
52
|
+
return isAuthErrorCode(like.code);
|
|
25
53
|
}
|
|
26
54
|
}
|
|
27
55
|
exports.AuthDomainError = AuthDomainError;
|