@jmlq/auth 0.0.1-alpha.32 → 0.0.1-alpha.33

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.
@@ -13,6 +13,18 @@ export declare abstract class AuthDomainError extends Error {
13
13
  code: AuthErrorCode;
14
14
  details: unknown;
15
15
  };
16
+ /**
17
+ * Guard estable para errores del core.
18
+ *
19
+ * - `instanceof` es el camino ideal, pero puede fallar si hay:
20
+ * - múltiples copias del paquete en runtime (resolución/hoisting),
21
+ * - bundles,
22
+ * - errores creados por hosts que replican forma (code/message).
23
+ *
24
+ * Regla:
25
+ * - Si tiene forma mínima { code: string, message: string }, lo tratamos como AuthDomainError.
26
+ * - El core sigue siendo el “owner” de los códigos y su significado.
27
+ */
16
28
  static isAuthError(e: unknown): e is AuthDomainError;
17
29
  }
18
30
  /** El token ya no es válido por exp (exp < now) */
@@ -1,6 +1,11 @@
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
+ function asAuthErrorLike(value) {
5
+ if (value && typeof value === "object")
6
+ return value;
7
+ return {};
8
+ }
4
9
  class AuthDomainError extends Error {
5
10
  constructor(message, code, details) {
6
11
  super(message);
@@ -8,7 +13,8 @@ class AuthDomainError extends Error {
8
13
  this.details = details;
9
14
  this.name = new.target.name;
10
15
  // Compatible con V8; ignora silenciosamente en otros engines
11
- if (typeof Error.captureStackTrace === "function") {
16
+ if (typeof Error
17
+ .captureStackTrace === "function") {
12
18
  Error.captureStackTrace(this, new.target);
13
19
  }
14
20
  }
@@ -20,8 +26,23 @@ class AuthDomainError extends Error {
20
26
  details: this.details,
21
27
  };
22
28
  }
29
+ /**
30
+ * Guard estable para errores del core.
31
+ *
32
+ * - `instanceof` es el camino ideal, pero puede fallar si hay:
33
+ * - múltiples copias del paquete en runtime (resolución/hoisting),
34
+ * - bundles,
35
+ * - errores creados por hosts que replican forma (code/message).
36
+ *
37
+ * Regla:
38
+ * - Si tiene forma mínima { code: string, message: string }, lo tratamos como AuthDomainError.
39
+ * - El core sigue siendo el “owner” de los códigos y su significado.
40
+ */
23
41
  static isAuthError(e) {
24
- return e instanceof AuthDomainError;
42
+ if (e instanceof AuthDomainError)
43
+ return true;
44
+ const like = asAuthErrorLike(e);
45
+ return typeof like.code === "string" && typeof like.message === "string";
25
46
  }
26
47
  }
27
48
  exports.AuthDomainError = AuthDomainError;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jmlq/auth",
3
3
  "description": "JWT authentication package with clean architecture",
4
- "version": "0.0.1-alpha.32",
4
+ "version": "0.0.1-alpha.33",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {