@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.
Files changed (155) hide show
  1. package/dist/application/dtos/index.d.ts +1 -1
  2. package/dist/application/dtos/index.js +1 -1
  3. package/dist/application/dtos/request/change-password.request.d.ts +15 -0
  4. package/dist/application/dtos/request/index.d.ts +5 -0
  5. package/dist/application/dtos/request/index.js +5 -0
  6. package/dist/application/dtos/request/logout.request.d.ts +2 -1
  7. package/dist/application/dtos/request/me.request.d.ts +3 -0
  8. package/dist/application/dtos/request/me.request.js +2 -0
  9. package/dist/application/dtos/request/register-user.request.d.ts +1 -1
  10. package/dist/application/dtos/request/request-password-reset.request.d.ts +6 -0
  11. package/dist/application/dtos/request/request-password-reset.request.js +2 -0
  12. package/dist/application/dtos/request/reset-password.request.d.ts +14 -0
  13. package/dist/application/dtos/request/reset-password.request.js +2 -0
  14. package/dist/application/dtos/request/verify-email.request.d.ts +3 -0
  15. package/dist/application/dtos/request/verify-email.request.js +2 -0
  16. package/dist/application/dtos/response/change-password.response.d.ts +7 -0
  17. package/dist/application/dtos/response/change-password.response.js +2 -0
  18. package/dist/application/dtos/response/index.d.ts +5 -0
  19. package/dist/application/dtos/response/index.js +5 -0
  20. package/dist/application/dtos/response/login.response.d.ts +2 -1
  21. package/dist/application/dtos/response/me.response.d.ts +11 -0
  22. package/dist/application/dtos/response/me.response.js +2 -0
  23. package/dist/application/dtos/response/refresh-token.response.d.ts +1 -0
  24. package/dist/application/dtos/response/register-user.response.d.ts +9 -0
  25. package/dist/application/dtos/response/request-password-reset.response.d.ts +15 -0
  26. package/dist/application/dtos/response/request-password-reset.response.js +2 -0
  27. package/dist/application/dtos/response/reset-password.response.d.ts +7 -0
  28. package/dist/application/dtos/response/reset-password.response.js +2 -0
  29. package/dist/application/dtos/response/verify-email.response.d.ts +4 -0
  30. package/dist/application/dtos/response/verify-email.response.js +2 -0
  31. package/dist/application/dtos/types/user-role.type.js +2 -0
  32. package/dist/application/facades/auth.facade.d.ts +33 -0
  33. package/dist/application/facades/auth.facade.js +60 -0
  34. package/dist/application/facades/create-auth-facade.d.ts +22 -0
  35. package/dist/application/facades/create-auth-facade.js +9 -0
  36. package/dist/application/facades/index.d.ts +2 -0
  37. package/dist/application/facades/index.js +18 -0
  38. package/dist/application/factories/auth-service.factory.d.ts +4 -4
  39. package/dist/application/factories/auth-service.factory.js +16 -4
  40. package/dist/application/factories/index.js +1 -0
  41. package/dist/application/types/auth-service-factory-options.type.d.ts +44 -0
  42. package/dist/application/use-cases/change-password.use-case.d.ts +21 -0
  43. package/dist/application/use-cases/change-password.use-case.js +49 -0
  44. package/dist/application/use-cases/index.d.ts +5 -0
  45. package/dist/application/use-cases/index.js +5 -0
  46. package/dist/application/use-cases/internal/index.d.ts +1 -0
  47. package/dist/application/use-cases/internal/index.js +17 -0
  48. package/dist/application/use-cases/internal/password-assertions.d.ts +13 -0
  49. package/dist/application/use-cases/internal/password-assertions.js +26 -0
  50. package/dist/application/use-cases/login-with-password.use-case.js +5 -1
  51. package/dist/application/use-cases/logout.use-case.js +14 -2
  52. package/dist/application/use-cases/me.use-case.d.ts +7 -0
  53. package/dist/application/use-cases/me.use-case.js +28 -0
  54. package/dist/application/use-cases/refresh-token.use-case.d.ts +16 -2
  55. package/dist/application/use-cases/refresh-token.use-case.js +33 -5
  56. package/dist/application/use-cases/register-user.use-case.d.ts +6 -1
  57. package/dist/application/use-cases/register-user.use-case.js +16 -7
  58. package/dist/application/use-cases/request-password-reset.use-case.d.ts +19 -0
  59. package/dist/application/use-cases/request-password-reset.use-case.js +43 -0
  60. package/dist/application/use-cases/reset-password.use-case.d.ts +20 -0
  61. package/dist/application/use-cases/reset-password.use-case.js +59 -0
  62. package/dist/application/use-cases/verify-email.use-case.d.ts +8 -0
  63. package/dist/application/use-cases/verify-email.use-case.js +26 -0
  64. package/dist/domain/entities/credential.entity.d.ts +36 -11
  65. package/dist/domain/entities/credential.entity.js +41 -11
  66. package/dist/domain/entities/user.entity.d.ts +32 -1
  67. package/dist/domain/entities/user.entity.js +54 -1
  68. package/dist/domain/errors/Invalid-jwt-payload.error.d.ts +4 -0
  69. package/dist/domain/errors/Invalid-jwt-payload.error.js +10 -0
  70. package/dist/domain/errors/auth-error-code.d.ts +12 -0
  71. package/dist/domain/errors/auth-error-code.js +2 -0
  72. package/dist/domain/errors/auth.errors.d.ts +6 -7
  73. package/dist/domain/errors/auth.errors.js +11 -6
  74. package/dist/domain/errors/identity.errors.d.ts +17 -12
  75. package/dist/domain/errors/identity.errors.js +29 -25
  76. package/dist/domain/errors/index.d.ts +3 -0
  77. package/dist/domain/errors/index.js +3 -0
  78. package/dist/domain/errors/password-reset.errors.d.ts +14 -0
  79. package/dist/domain/errors/password-reset.errors.js +29 -0
  80. package/dist/domain/index.d.ts +1 -0
  81. package/dist/domain/index.js +1 -0
  82. package/dist/domain/object-values/id.js +3 -4
  83. package/dist/domain/ports/auth/email-verification-token.port.d.ts +19 -0
  84. package/dist/domain/ports/auth/email-verification-token.port.js +2 -0
  85. package/dist/domain/ports/auth/index.d.ts +2 -0
  86. package/dist/domain/ports/auth/index.js +2 -0
  87. package/dist/domain/ports/auth/password-reset-token.port.d.ts +36 -0
  88. package/dist/domain/ports/auth/password-reset-token.port.js +2 -0
  89. package/dist/domain/ports/jwt/payload/jwt-payload.port.d.ts +25 -3
  90. package/dist/domain/ports/repository/credential.repository.d.ts +55 -2
  91. package/dist/domain/ports/token/token-session.port.d.ts +2 -0
  92. package/dist/domain/props/entities/credential.props.d.ts +9 -1
  93. package/dist/domain/props/entities/user.props.d.ts +1 -0
  94. package/dist/domain/props/jwt/generate-access-token.props.d.ts +3 -2
  95. package/dist/domain/props/jwt/generate-refresh-token.props.d.ts +3 -2
  96. package/dist/domain/props/jwt/jwt-user.d.ts +11 -2
  97. package/dist/domain/services/helpers/index.d.ts +6 -0
  98. package/dist/domain/services/helpers/index.js +22 -0
  99. package/dist/domain/services/helpers/optional-audience.helper.d.ts +14 -0
  100. package/dist/domain/services/helpers/optional-audience.helper.js +49 -0
  101. package/dist/domain/services/helpers/optional-non-empty-string.helper.d.ts +1 -0
  102. package/dist/domain/services/helpers/optional-non-empty-string.helper.js +9 -0
  103. package/dist/domain/services/helpers/optional-record.helper.d.ts +1 -0
  104. package/dist/domain/services/helpers/optional-record.helper.js +15 -0
  105. package/dist/domain/services/helpers/optional-roles.helper.d.ts +3 -0
  106. package/dist/domain/services/helpers/optional-roles.helper.js +32 -0
  107. package/dist/domain/services/helpers/require-finite-number.helper.d.ts +1 -0
  108. package/dist/domain/services/helpers/require-finite-number.helper.js +12 -0
  109. package/dist/domain/services/helpers/require-non-empty-string.helper.d.ts +1 -0
  110. package/dist/domain/services/helpers/require-non-empty-string.helper.js +12 -0
  111. package/dist/domain/services/index.d.ts +1 -0
  112. package/dist/domain/services/index.js +1 -0
  113. package/dist/domain/services/normalize-jwt-payload.service.d.ts +19 -0
  114. package/dist/domain/services/normalize-jwt-payload.service.js +58 -0
  115. package/dist/domain/types/access-snapshot.type.d.ts +15 -0
  116. package/dist/domain/types/access-snapshot.type.js +2 -0
  117. package/dist/domain/types/index.d.ts +1 -0
  118. package/dist/domain/types/index.js +2 -0
  119. package/dist/in-memory/in-memory-credential.repository.d.ts +66 -3
  120. package/dist/in-memory/in-memory-credential.repository.js +174 -46
  121. package/dist/index.d.ts +20 -1
  122. package/dist/index.js +28 -6
  123. package/dist/infrastructure/index.d.ts +3 -0
  124. package/dist/infrastructure/index.js +18 -0
  125. package/dist/infrastructure/security/bcrypt-password-hasher.js +0 -1
  126. package/dist/infrastructure/services/token-session.service.d.ts +163 -8
  127. package/dist/infrastructure/services/token-session.service.js +290 -37
  128. package/dist/infrastructure/types/auth-service-container.d.ts +21 -2
  129. package/dist/shared/index.d.ts +1 -0
  130. package/dist/shared/index.js +1 -0
  131. package/dist/shared/jwt-plugin/create-jwt-id.d.ts +6 -0
  132. package/dist/shared/jwt-plugin/create-jwt-id.js +30 -0
  133. package/dist/shared/jwt-plugin/index.d.ts +9 -0
  134. package/dist/shared/jwt-plugin/index.js +25 -0
  135. package/dist/shared/jwt-plugin/is-retryable-auth-code.d.ts +8 -0
  136. package/dist/shared/jwt-plugin/is-retryable-auth-code.js +15 -0
  137. package/dist/shared/jwt-plugin/normalize-clock-skew-seconds.d.ts +14 -0
  138. package/dist/shared/jwt-plugin/normalize-clock-skew-seconds.js +23 -0
  139. package/dist/shared/jwt-plugin/normalize-default-expires-in.d.ts +16 -0
  140. package/dist/shared/jwt-plugin/normalize-default-expires-in.js +36 -0
  141. package/dist/shared/jwt-plugin/read-custom-claims.d.ts +12 -0
  142. package/dist/shared/jwt-plugin/read-custom-claims.js +21 -0
  143. package/dist/shared/jwt-plugin/read-expires-in.d.ts +12 -0
  144. package/dist/shared/jwt-plugin/read-expires-in.js +20 -0
  145. package/dist/shared/jwt-plugin/read-session-id.d.ts +11 -0
  146. package/dist/shared/jwt-plugin/read-session-id.js +17 -0
  147. package/dist/shared/jwt-plugin/resolve-expires-in.d.ts +14 -0
  148. package/dist/shared/jwt-plugin/resolve-expires-in.js +31 -0
  149. package/dist/shared/jwt-plugin/to-date-from-unix-seconds.d.ts +7 -0
  150. package/dist/shared/jwt-plugin/to-date-from-unix-seconds.js +12 -0
  151. package/package.json +5 -4
  152. /package/dist/application/dtos/{type/user-role.type.js → request/change-password.request.js} +0 -0
  153. /package/dist/application/dtos/{type → types}/index.d.ts +0 -0
  154. /package/dist/application/dtos/{type → types}/index.js +0 -0
  155. /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,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,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.3",
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"
File without changes