@jmlq/auth 0.0.1-alpha.3 → 0.0.1-alpha.30
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/application/dtos/index.d.ts +1 -1
- package/dist/application/dtos/index.js +1 -1
- package/dist/application/dtos/request/change-password.request.d.ts +15 -0
- package/dist/application/dtos/request/index.d.ts +5 -0
- package/dist/application/dtos/request/index.js +5 -0
- package/dist/application/dtos/request/logout.request.d.ts +2 -1
- package/dist/application/dtos/request/me.request.d.ts +3 -0
- package/dist/application/dtos/request/me.request.js +2 -0
- package/dist/application/dtos/request/register-user.request.d.ts +1 -1
- package/dist/application/dtos/request/request-password-reset.request.d.ts +6 -0
- package/dist/application/dtos/request/request-password-reset.request.js +2 -0
- package/dist/application/dtos/request/reset-password.request.d.ts +14 -0
- package/dist/application/dtos/request/reset-password.request.js +2 -0
- package/dist/application/dtos/request/verify-email.request.d.ts +3 -0
- package/dist/application/dtos/request/verify-email.request.js +2 -0
- package/dist/application/dtos/response/change-password.response.d.ts +7 -0
- package/dist/application/dtos/response/change-password.response.js +2 -0
- package/dist/application/dtos/response/index.d.ts +5 -0
- package/dist/application/dtos/response/index.js +5 -0
- package/dist/application/dtos/response/login.response.d.ts +2 -1
- package/dist/application/dtos/response/me.response.d.ts +11 -0
- package/dist/application/dtos/response/me.response.js +2 -0
- package/dist/application/dtos/response/refresh-token.response.d.ts +1 -0
- package/dist/application/dtos/response/register-user.response.d.ts +9 -0
- package/dist/application/dtos/response/request-password-reset.response.d.ts +15 -0
- package/dist/application/dtos/response/request-password-reset.response.js +2 -0
- package/dist/application/dtos/response/reset-password.response.d.ts +7 -0
- package/dist/application/dtos/response/reset-password.response.js +2 -0
- package/dist/application/dtos/response/verify-email.response.d.ts +4 -0
- package/dist/application/dtos/response/verify-email.response.js +2 -0
- package/dist/application/dtos/types/user-role.type.js +2 -0
- package/dist/application/facades/auth.facade.d.ts +33 -0
- package/dist/application/facades/auth.facade.js +60 -0
- package/dist/application/facades/create-auth-facade.d.ts +22 -0
- package/dist/application/facades/create-auth-facade.js +9 -0
- package/dist/application/facades/index.d.ts +2 -0
- package/dist/application/facades/index.js +18 -0
- package/dist/application/factories/auth-service.factory.d.ts +4 -4
- package/dist/application/factories/auth-service.factory.js +16 -4
- package/dist/application/factories/index.js +1 -0
- package/dist/application/types/auth-service-factory-options.type.d.ts +44 -0
- package/dist/application/use-cases/change-password.use-case.d.ts +21 -0
- package/dist/application/use-cases/change-password.use-case.js +49 -0
- package/dist/application/use-cases/index.d.ts +5 -0
- package/dist/application/use-cases/index.js +5 -0
- package/dist/application/use-cases/internal/index.d.ts +1 -0
- package/dist/application/use-cases/internal/index.js +17 -0
- package/dist/application/use-cases/internal/password-assertions.d.ts +13 -0
- package/dist/application/use-cases/internal/password-assertions.js +26 -0
- package/dist/application/use-cases/login-with-password.use-case.js +5 -1
- package/dist/application/use-cases/logout.use-case.js +14 -2
- package/dist/application/use-cases/me.use-case.d.ts +7 -0
- package/dist/application/use-cases/me.use-case.js +28 -0
- package/dist/application/use-cases/refresh-token.use-case.d.ts +16 -2
- package/dist/application/use-cases/refresh-token.use-case.js +33 -5
- package/dist/application/use-cases/register-user.use-case.d.ts +6 -1
- package/dist/application/use-cases/register-user.use-case.js +16 -7
- package/dist/application/use-cases/request-password-reset.use-case.d.ts +19 -0
- package/dist/application/use-cases/request-password-reset.use-case.js +43 -0
- package/dist/application/use-cases/reset-password.use-case.d.ts +20 -0
- package/dist/application/use-cases/reset-password.use-case.js +59 -0
- package/dist/application/use-cases/verify-email.use-case.d.ts +8 -0
- package/dist/application/use-cases/verify-email.use-case.js +26 -0
- package/dist/domain/entities/credential.entity.d.ts +36 -11
- package/dist/domain/entities/credential.entity.js +41 -11
- package/dist/domain/entities/user.entity.d.ts +32 -1
- package/dist/domain/entities/user.entity.js +54 -1
- package/dist/domain/errors/Invalid-jwt-payload.error.d.ts +4 -0
- package/dist/domain/errors/Invalid-jwt-payload.error.js +10 -0
- package/dist/domain/errors/auth-error-code.d.ts +12 -0
- package/dist/domain/errors/auth-error-code.js +2 -0
- package/dist/domain/errors/auth.errors.d.ts +6 -7
- package/dist/domain/errors/auth.errors.js +11 -6
- package/dist/domain/errors/identity.errors.d.ts +17 -12
- package/dist/domain/errors/identity.errors.js +29 -25
- package/dist/domain/errors/index.d.ts +3 -0
- package/dist/domain/errors/index.js +3 -0
- package/dist/domain/errors/password-reset.errors.d.ts +14 -0
- package/dist/domain/errors/password-reset.errors.js +29 -0
- package/dist/domain/index.d.ts +1 -0
- package/dist/domain/index.js +1 -0
- package/dist/domain/object-values/id.js +3 -4
- package/dist/domain/ports/auth/email-verification-token.port.d.ts +19 -0
- package/dist/domain/ports/auth/email-verification-token.port.js +2 -0
- package/dist/domain/ports/auth/index.d.ts +2 -0
- package/dist/domain/ports/auth/index.js +2 -0
- package/dist/domain/ports/auth/password-reset-token.port.d.ts +36 -0
- package/dist/domain/ports/auth/password-reset-token.port.js +2 -0
- package/dist/domain/ports/jwt/payload/jwt-payload.port.d.ts +25 -3
- package/dist/domain/ports/repository/credential.repository.d.ts +55 -2
- package/dist/domain/ports/token/token-session.port.d.ts +2 -0
- package/dist/domain/props/entities/credential.props.d.ts +9 -1
- package/dist/domain/props/entities/user.props.d.ts +1 -0
- package/dist/domain/props/jwt/generate-access-token.props.d.ts +3 -2
- package/dist/domain/props/jwt/generate-refresh-token.props.d.ts +3 -2
- package/dist/domain/props/jwt/jwt-user.d.ts +11 -2
- package/dist/domain/services/helpers/index.d.ts +6 -0
- package/dist/domain/services/helpers/index.js +22 -0
- package/dist/domain/services/helpers/optional-audience.helper.d.ts +14 -0
- package/dist/domain/services/helpers/optional-audience.helper.js +49 -0
- package/dist/domain/services/helpers/optional-non-empty-string.helper.d.ts +1 -0
- package/dist/domain/services/helpers/optional-non-empty-string.helper.js +9 -0
- package/dist/domain/services/helpers/optional-record.helper.d.ts +1 -0
- package/dist/domain/services/helpers/optional-record.helper.js +15 -0
- package/dist/domain/services/helpers/optional-roles.helper.d.ts +3 -0
- package/dist/domain/services/helpers/optional-roles.helper.js +32 -0
- package/dist/domain/services/helpers/require-finite-number.helper.d.ts +1 -0
- package/dist/domain/services/helpers/require-finite-number.helper.js +12 -0
- package/dist/domain/services/helpers/require-non-empty-string.helper.d.ts +1 -0
- package/dist/domain/services/helpers/require-non-empty-string.helper.js +12 -0
- package/dist/domain/services/index.d.ts +1 -0
- package/dist/domain/services/index.js +1 -0
- package/dist/domain/services/normalize-jwt-payload.service.d.ts +19 -0
- package/dist/domain/services/normalize-jwt-payload.service.js +58 -0
- package/dist/domain/types/access-snapshot.type.d.ts +15 -0
- package/dist/domain/types/access-snapshot.type.js +2 -0
- package/dist/domain/types/index.d.ts +1 -0
- package/dist/domain/types/index.js +2 -0
- package/dist/in-memory/in-memory-credential.repository.d.ts +66 -3
- package/dist/in-memory/in-memory-credential.repository.js +174 -46
- package/dist/index.d.ts +20 -1
- package/dist/index.js +28 -6
- package/dist/infrastructure/index.d.ts +3 -0
- package/dist/infrastructure/index.js +18 -0
- package/dist/infrastructure/security/bcrypt-password-hasher.js +0 -1
- package/dist/infrastructure/services/token-session.service.d.ts +163 -8
- package/dist/infrastructure/services/token-session.service.js +290 -37
- package/dist/infrastructure/types/auth-service-container.d.ts +21 -2
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +1 -0
- 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 +9 -0
- package/dist/shared/jwt-plugin/index.js +25 -0
- package/dist/shared/jwt-plugin/is-retryable-auth-code.d.ts +8 -0
- package/dist/shared/jwt-plugin/is-retryable-auth-code.js +15 -0
- package/dist/shared/jwt-plugin/normalize-clock-skew-seconds.d.ts +14 -0
- package/dist/shared/jwt-plugin/normalize-clock-skew-seconds.js +23 -0
- package/dist/shared/jwt-plugin/normalize-default-expires-in.d.ts +16 -0
- package/dist/shared/jwt-plugin/normalize-default-expires-in.js +36 -0
- package/dist/shared/jwt-plugin/read-custom-claims.d.ts +12 -0
- package/dist/shared/jwt-plugin/read-custom-claims.js +21 -0
- package/dist/shared/jwt-plugin/read-expires-in.d.ts +12 -0
- package/dist/shared/jwt-plugin/read-expires-in.js +20 -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/resolve-expires-in.d.ts +14 -0
- package/dist/shared/jwt-plugin/resolve-expires-in.js +31 -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 +5 -4
- /package/dist/application/dtos/{type/user-role.type.js → request/change-password.request.js} +0 -0
- /package/dist/application/dtos/{type → types}/index.d.ts +0 -0
- /package/dist/application/dtos/{type → types}/index.js +0 -0
- /package/dist/application/dtos/{type → types}/user-role.type.d.ts +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readExpiresIn = readExpiresIn;
|
|
4
|
+
/**
|
|
5
|
+
* Lee `expiresIn` desde unknown.
|
|
6
|
+
*
|
|
7
|
+
* Responsabilidad única:
|
|
8
|
+
* - Normalizar un valor desconocido a `string | undefined`
|
|
9
|
+
*
|
|
10
|
+
* Reglas:
|
|
11
|
+
* - no string => undefined
|
|
12
|
+
* - string vacío => undefined
|
|
13
|
+
* - string con espacios => trim()
|
|
14
|
+
*/
|
|
15
|
+
function readExpiresIn(value) {
|
|
16
|
+
if (typeof value !== "string")
|
|
17
|
+
return undefined;
|
|
18
|
+
const trimmed = value.trim();
|
|
19
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
20
|
+
}
|
|
@@ -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,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resuelve `expiresIn` para generación de tokens (regla canónica para plugins).
|
|
3
|
+
*
|
|
4
|
+
* Responsabilidad única:
|
|
5
|
+
* - Aplicar precedencia:
|
|
6
|
+
* 1) expiresIn provisto por props
|
|
7
|
+
* 2) defaultExpiresIn del plugin por tokenKind
|
|
8
|
+
* - Si ninguno existe: lanzar InvalidJwtPayloadError (error canónico del core)
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveExpiresIn(args: {
|
|
11
|
+
expiresInFromProps?: string;
|
|
12
|
+
defaultExpiresIn?: string;
|
|
13
|
+
operation: "generateAccessToken" | "generateRefreshToken";
|
|
14
|
+
}): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveExpiresIn = resolveExpiresIn;
|
|
4
|
+
const errors_1 = require("../../domain/errors");
|
|
5
|
+
/**
|
|
6
|
+
* Resuelve `expiresIn` para generación de tokens (regla canónica para plugins).
|
|
7
|
+
*
|
|
8
|
+
* Responsabilidad única:
|
|
9
|
+
* - Aplicar precedencia:
|
|
10
|
+
* 1) expiresIn provisto por props
|
|
11
|
+
* 2) defaultExpiresIn del plugin por tokenKind
|
|
12
|
+
* - Si ninguno existe: lanzar InvalidJwtPayloadError (error canónico del core)
|
|
13
|
+
*/
|
|
14
|
+
function resolveExpiresIn(args) {
|
|
15
|
+
const fromProps = normalizeOptionalNonEmptyString(args.expiresInFromProps);
|
|
16
|
+
if (fromProps)
|
|
17
|
+
return fromProps;
|
|
18
|
+
const fromDefault = normalizeOptionalNonEmptyString(args.defaultExpiresIn);
|
|
19
|
+
if (fromDefault)
|
|
20
|
+
return fromDefault;
|
|
21
|
+
throw new errors_1.InvalidJwtPayloadError("expiresIn is required", {
|
|
22
|
+
field: "expiresIn",
|
|
23
|
+
operation: args.operation,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function normalizeOptionalNonEmptyString(value) {
|
|
27
|
+
if (typeof value !== "string")
|
|
28
|
+
return undefined;
|
|
29
|
+
const v = value.trim();
|
|
30
|
+
return v.length > 0 ? v : undefined;
|
|
31
|
+
}
|
|
@@ -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,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jmlq/auth",
|
|
3
3
|
"description": "JWT authentication package with clean architecture",
|
|
4
|
-
"version": "0.0.1-alpha.
|
|
4
|
+
"version": "0.0.1-alpha.30",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"dev": "rimraf dist && mkdir dist && tsc -p tsconfig.json",
|
|
9
9
|
"build": "rimraf dist && mkdir dist && tsc -p tsconfig.build.json",
|
|
10
|
+
"package:script": "node scripts/package-script.mjs",
|
|
10
11
|
"prepublishOnly": "npm run build",
|
|
11
12
|
"test": "jest --passWithNoTests",
|
|
12
13
|
"test:watch": "jest --watch",
|
|
@@ -26,8 +27,7 @@
|
|
|
26
27
|
"author": "MLahuasi",
|
|
27
28
|
"license": "MIT",
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"bcryptjs": "^2.4.3"
|
|
30
|
-
"rimraf": "^6.1.2"
|
|
30
|
+
"bcryptjs": "^2.4.3"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@swc/core": "^1.3.95",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"@types/node": "^20.8.10",
|
|
38
38
|
"jest": "^29.7.0",
|
|
39
39
|
"tsx": "^4.1.4",
|
|
40
|
-
"typescript": "^5.2.2"
|
|
40
|
+
"typescript": "^5.2.2",
|
|
41
|
+
"rimraf": "^6.1.2"
|
|
41
42
|
},
|
|
42
43
|
"files": [
|
|
43
44
|
"dist"
|
/package/dist/application/dtos/{type/user-role.type.js → request/change-password.request.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|