@jmlq/auth 0.0.1-alpha.25 → 0.0.1-alpha.27

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.
@@ -1 +1 @@
1
- export declare function optionalNonEmptyString(value: unknown): string | undefined;
1
+ export declare function readNonEmptyString(value: unknown): string | undefined;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.optionalNonEmptyString = optionalNonEmptyString;
4
- function optionalNonEmptyString(value) {
3
+ exports.readNonEmptyString = readNonEmptyString;
4
+ function readNonEmptyString(value) {
5
5
  if (typeof value !== "string")
6
6
  return undefined;
7
7
  const v = value.trim();
@@ -34,7 +34,7 @@ function normalizeJwtPayload(input) {
34
34
  const iat = (0, helpers_1.requireFiniteNumber)(obj.iat, "iat");
35
35
  const exp = (0, helpers_1.requireFiniteNumber)(obj.exp, "exp");
36
36
  // Optional
37
- const iss = (0, helpers_1.optionalNonEmptyString)(obj.iss);
37
+ const iss = (0, helpers_1.readNonEmptyString)(obj.iss);
38
38
  /**
39
39
  * Canonical audience rule (core):
40
40
  * - string | string[] | undefined
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export { normalizeJwtPayload } from "./domain/services";
14
14
  export { InvalidJwtPayloadError } from "./domain/errors";
15
15
  export * from "./domain/ports";
16
16
  export * from "./domain/entities";
17
+ export { readNonEmptyString } from "./domain/services/helpers";
17
18
  export * from "./domain/object-values";
18
19
  export * from "./domain/props";
19
20
  export * from "./domain/errors";
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ 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.InvalidJwtPayloadError = exports.normalizeJwtPayload = void 0;
17
+ exports.readNonEmptyString = exports.InvalidJwtPayloadError = exports.normalizeJwtPayload = void 0;
18
18
  /**
19
19
  * Contrato público (JWT payload):
20
20
  * - Los plugins devuelven payload verificado criptográficamente como unknown.
@@ -33,6 +33,9 @@ Object.defineProperty(exports, "InvalidJwtPayloadError", { enumerable: true, get
33
33
  __exportStar(require("./domain/ports"), exports);
34
34
  // Entities
35
35
  __exportStar(require("./domain/entities"), exports);
36
+ // Helpers
37
+ var helpers_1 = require("./domain/services/helpers");
38
+ Object.defineProperty(exports, "readNonEmptyString", { enumerable: true, get: function () { return helpers_1.readNonEmptyString; } });
36
39
  // VOs
37
40
  __exportStar(require("./domain/object-values"), exports);
38
41
  // Props (JWT generation inputs, etc.)
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Genera un identificador único para el claim `jti`.
3
+ * - Usa crypto.randomUUID cuando está disponible.
4
+ * - Fallback no-crypto para entornos legacy/dev.
5
+ */
6
+ export declare function createJwtId(): string;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createJwtId = createJwtId;
4
+ /**
5
+ * Obtiene el tiempo actual en segundos Unix.
6
+ *
7
+ * @returns Timestamp Unix (segundos).
8
+ */
9
+ function nowUnixSeconds() {
10
+ return Math.floor(Date.now() / 1000);
11
+ }
12
+ /**
13
+ * Genera un identificador único para el claim `jti`.
14
+ * - Usa crypto.randomUUID cuando está disponible.
15
+ * - Fallback no-crypto para entornos legacy/dev.
16
+ */
17
+ function createJwtId() {
18
+ if (hasCryptoRandomUUID(globalThis)) {
19
+ return globalThis.crypto.randomUUID();
20
+ }
21
+ return `jti_${nowUnixSeconds()}_${Math.random().toString(16).slice(2)}`;
22
+ }
23
+ function hasCryptoRandomUUID(value) {
24
+ return (typeof value === "object" &&
25
+ value !== null &&
26
+ "crypto" in value &&
27
+ typeof value.crypto === "object" &&
28
+ typeof value.crypto
29
+ ?.randomUUID === "function");
30
+ }
@@ -4,3 +4,6 @@ export * from "./read-expires-in";
4
4
  export * from "./read-custom-claims";
5
5
  export * from "./resolve-expires-in";
6
6
  export * from "./is-retryable-auth-code";
7
+ export * from "./read-session-id";
8
+ export * from "./to-date-from-unix-seconds";
9
+ export * from "./create-jwt-id";
@@ -20,3 +20,6 @@ __exportStar(require("./read-expires-in"), exports);
20
20
  __exportStar(require("./read-custom-claims"), exports);
21
21
  __exportStar(require("./resolve-expires-in"), exports);
22
22
  __exportStar(require("./is-retryable-auth-code"), exports);
23
+ __exportStar(require("./read-session-id"), exports);
24
+ __exportStar(require("./to-date-from-unix-seconds"), exports);
25
+ __exportStar(require("./create-jwt-id"), exports);
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Lee y valida `sessionId`.
3
+ *
4
+ * Regla de dominio:
5
+ * - sessionId es obligatorio para soporte multi-sesión
6
+ *
7
+ * NOTA:
8
+ * - NO lanza Error genérico
9
+ * - La decisión del error final se delega al core
10
+ */
11
+ export declare function readSessionId(value: unknown): string | undefined;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readSessionId = readSessionId;
4
+ const helpers_1 = require("../../domain/services/helpers");
5
+ /**
6
+ * Lee y valida `sessionId`.
7
+ *
8
+ * Regla de dominio:
9
+ * - sessionId es obligatorio para soporte multi-sesión
10
+ *
11
+ * NOTA:
12
+ * - NO lanza Error genérico
13
+ * - La decisión del error final se delega al core
14
+ */
15
+ function readSessionId(value) {
16
+ return (0, helpers_1.readNonEmptyString)(value);
17
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Convierte segundos Unix a Date.
3
+ *
4
+ * @param expSeconds `exp` en segundos Unix.
5
+ * @returns Date correspondiente.
6
+ */
7
+ export declare function toDateFromUnixSeconds(expSeconds: number): Date;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toDateFromUnixSeconds = toDateFromUnixSeconds;
4
+ /**
5
+ * Convierte segundos Unix a Date.
6
+ *
7
+ * @param expSeconds `exp` en segundos Unix.
8
+ * @returns Date correspondiente.
9
+ */
10
+ function toDateFromUnixSeconds(expSeconds) {
11
+ return new Date(expSeconds * 1000);
12
+ }
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.25",
4
+ "version": "0.0.1-alpha.27",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {