@jmlq/auth 0.0.1-alpha.25 → 0.0.1-alpha.26
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.
- package/dist/domain/services/helpers/optional-non-empty-string.helper.d.ts +1 -1
- package/dist/domain/services/helpers/optional-non-empty-string.helper.js +2 -2
- package/dist/domain/services/normalize-jwt-payload.service.js +1 -1
- package/dist/shared/jwt-plugin/create-jwt-id.d.ts +6 -0
- package/dist/shared/jwt-plugin/create-jwt-id.js +30 -0
- package/dist/shared/jwt-plugin/index.d.ts +3 -0
- package/dist/shared/jwt-plugin/index.js +3 -0
- package/dist/shared/jwt-plugin/read-session-id.d.ts +11 -0
- package/dist/shared/jwt-plugin/read-session-id.js +17 -0
- package/dist/shared/jwt-plugin/to-date-from-unix-seconds.d.ts +7 -0
- package/dist/shared/jwt-plugin/to-date-from-unix-seconds.js +12 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function
|
|
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.
|
|
4
|
-
function
|
|
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.
|
|
37
|
+
const iss = (0, helpers_1.readNonEmptyString)(obj.iss);
|
|
38
38
|
/**
|
|
39
39
|
* Canonical audience rule (core):
|
|
40
40
|
* - string | string[] | undefined
|
|
@@ -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,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
|
+
}
|