@jmlq/auth 0.0.1-alpha.31 → 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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { optionalAudience } from "./domain/services/helpers";
1
+ export { optionalAudience, assertJwtStructure, } from "./domain/services/helpers";
2
2
  export type { IAuthServiceContainer } from "./infrastructure/types";
3
3
  export { AuthServiceFactoryOptions } from "./application/types";
4
4
  /**
@@ -12,7 +12,7 @@ export { normalizeJwtPayload } from "./domain/services";
12
12
  * Aunque ya se exporta vía `export * from "./domain/errors"`,
13
13
  * se expone de forma directa para que el host/plugins lo consuman sin ambigüedad.
14
14
  */
15
- export { InvalidJwtPayloadError } from "./domain/errors";
15
+ export { InvalidJwtPayloadError, InvalidJwtEmptyError, InvalidJwtMalformedError, } from "./domain/errors";
16
16
  export * from "./domain/ports";
17
17
  export * from "./domain/entities";
18
18
  export { readNonEmptyString } from "./domain/services/helpers";
package/dist/index.js CHANGED
@@ -14,9 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.readNonEmptyString = exports.InvalidJwtPayloadError = exports.normalizeJwtPayload = exports.optionalAudience = void 0;
17
+ exports.readNonEmptyString = exports.InvalidJwtMalformedError = exports.InvalidJwtEmptyError = exports.InvalidJwtPayloadError = exports.normalizeJwtPayload = exports.assertJwtStructure = exports.optionalAudience = void 0;
18
18
  var helpers_1 = require("./domain/services/helpers");
19
19
  Object.defineProperty(exports, "optionalAudience", { enumerable: true, get: function () { return helpers_1.optionalAudience; } });
20
+ Object.defineProperty(exports, "assertJwtStructure", { enumerable: true, get: function () { return helpers_1.assertJwtStructure; } });
20
21
  /**
21
22
  * Contrato público (JWT payload):
22
23
  * - Los plugins devuelven payload verificado criptográficamente como unknown.
@@ -31,6 +32,8 @@ Object.defineProperty(exports, "normalizeJwtPayload", { enumerable: true, get: f
31
32
  */
32
33
  var errors_1 = require("./domain/errors");
33
34
  Object.defineProperty(exports, "InvalidJwtPayloadError", { enumerable: true, get: function () { return errors_1.InvalidJwtPayloadError; } });
35
+ Object.defineProperty(exports, "InvalidJwtEmptyError", { enumerable: true, get: function () { return errors_1.InvalidJwtEmptyError; } });
36
+ Object.defineProperty(exports, "InvalidJwtMalformedError", { enumerable: true, get: function () { return errors_1.InvalidJwtMalformedError; } });
34
37
  // Contratos (ports) + config
35
38
  __exportStar(require("./domain/ports"), exports);
36
39
  // Entities
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.31",
4
+ "version": "0.0.1-alpha.33",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {