@jmlq/auth-plugin-jose 0.0.1-alpha.1
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/README.md +228 -0
- package/dist/application/factories/create-jose-token-service.d.ts +28 -0
- package/dist/application/factories/create-jose-token-service.js +76 -0
- package/dist/application/factories/index.d.ts +1 -0
- package/dist/application/factories/index.js +17 -0
- package/dist/application/factories/internal/assert.util.d.ts +9 -0
- package/dist/application/factories/internal/assert.util.js +16 -0
- package/dist/application/factories/internal/clock-skew-normalizer.util.d.ts +14 -0
- package/dist/application/factories/internal/clock-skew-normalizer.util.js +24 -0
- package/dist/application/factories/internal/expires-in.util.d.ts +21 -0
- package/dist/application/factories/internal/expires-in.util.js +31 -0
- package/dist/application/factories/internal/index.d.ts +5 -0
- package/dist/application/factories/internal/index.js +21 -0
- package/dist/application/factories/internal/key-material.validator.d.ts +15 -0
- package/dist/application/factories/internal/key-material.validator.js +26 -0
- package/dist/application/factories/internal/string-normalizers.util.d.ts +18 -0
- package/dist/application/factories/internal/string-normalizers.util.js +31 -0
- package/dist/application/types/expires-in.types.d.ts +33 -0
- package/dist/application/types/expires-in.types.js +3 -0
- package/dist/application/types/index.d.ts +2 -0
- package/dist/application/types/index.js +18 -0
- package/dist/application/types/jose-token-service.options.d.ts +81 -0
- package/dist/application/types/jose-token-service.options.js +9 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +9 -0
- package/dist/infrastructure/mappers/index.d.ts +1 -0
- package/dist/infrastructure/mappers/index.js +17 -0
- package/dist/infrastructure/mappers/jose-error.mapper.d.ts +35 -0
- package/dist/infrastructure/mappers/jose-error.mapper.js +219 -0
- package/dist/infrastructure/mappers/types/index.d.ts +4 -0
- package/dist/infrastructure/mappers/types/index.js +20 -0
- package/dist/infrastructure/mappers/types/jose-error-context.type.d.ts +32 -0
- package/dist/infrastructure/mappers/types/jose-error-context.type.js +3 -0
- package/dist/infrastructure/mappers/types/mapped-auth-error.type.d.ts +24 -0
- package/dist/infrastructure/mappers/types/mapped-auth-error.type.js +3 -0
- package/dist/infrastructure/mappers/types/token-kind.type.d.ts +7 -0
- package/dist/infrastructure/mappers/types/token-kind.type.js +3 -0
- package/dist/infrastructure/mappers/types/token-operation.type.d.ts +7 -0
- package/dist/infrastructure/mappers/types/token-operation.type.js +3 -0
- package/dist/infrastructure/services/index.d.ts +1 -0
- package/dist/infrastructure/services/index.js +17 -0
- package/dist/infrastructure/services/internal/expires-in.util.d.ts +21 -0
- package/dist/infrastructure/services/internal/expires-in.util.js +35 -0
- package/dist/infrastructure/services/internal/index.d.ts +7 -0
- package/dist/infrastructure/services/internal/index.js +23 -0
- package/dist/infrastructure/services/internal/jose-context.util.d.ts +35 -0
- package/dist/infrastructure/services/internal/jose-context.util.js +51 -0
- package/dist/infrastructure/services/internal/jose-error.util.d.ts +16 -0
- package/dist/infrastructure/services/internal/jose-error.util.js +27 -0
- package/dist/infrastructure/services/internal/jose-keys.normalizer.d.ts +25 -0
- package/dist/infrastructure/services/internal/jose-keys.normalizer.js +35 -0
- package/dist/infrastructure/services/internal/jti.util.d.ts +8 -0
- package/dist/infrastructure/services/internal/jti.util.js +25 -0
- package/dist/infrastructure/services/internal/jwt-expiration-reader.d.ts +9 -0
- package/dist/infrastructure/services/internal/jwt-expiration-reader.js +23 -0
- package/dist/infrastructure/services/internal/jwt-payload.normalizer.d.ts +11 -0
- package/dist/infrastructure/services/internal/jwt-payload.normalizer.js +56 -0
- package/dist/infrastructure/services/jose-token.service.d.ts +192 -0
- package/dist/infrastructure/services/jose-token.service.js +309 -0
- package/dist/infrastructure/services/types/create-auth-error-fn.type.d.ts +27 -0
- package/dist/infrastructure/services/types/create-auth-error-fn.type.js +2 -0
- package/dist/infrastructure/services/types/index.d.ts +1 -0
- package/dist/infrastructure/services/types/index.js +17 -0
- package/package.json +48 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/infrastructure/services/jose-token.service.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.JoseTokenService = void 0;
|
|
5
|
+
const jose_1 = require("jose");
|
|
6
|
+
const mappers_1 = require("../mappers");
|
|
7
|
+
const internal_1 = require("./internal");
|
|
8
|
+
// -----------------------------------------------------------------------------
|
|
9
|
+
// Class
|
|
10
|
+
// -----------------------------------------------------------------------------
|
|
11
|
+
/**
|
|
12
|
+
* Implementación de `ITokenServicePort` usando la librería `jose`.
|
|
13
|
+
*
|
|
14
|
+
* ### ¿Qué hace esta clase?
|
|
15
|
+
* Orquesta operaciones de JWT para el core:
|
|
16
|
+
* - Generar tokens (access/refresh)
|
|
17
|
+
* - Verificar tokens (access/refresh)
|
|
18
|
+
* - Obtener expiración (exp) con política "verify-first"
|
|
19
|
+
*
|
|
20
|
+
* ### ¿Qué NO hace esta clase?
|
|
21
|
+
* - No contiene lógica de negocio (usuarios, sesiones, permisos, etc.)
|
|
22
|
+
* - No define errores propios del plugin
|
|
23
|
+
*
|
|
24
|
+
* ### Claims relevantes (explicación simple)
|
|
25
|
+
* - `sub`: Subject. Aquí se usa como `user.id`.
|
|
26
|
+
* - `jti`: Token ID. Identificador único del token.
|
|
27
|
+
* - `iat`: Issued At. Momento de creación del token (segundos Unix).
|
|
28
|
+
* - `exp`: Expiration. Momento de expiración (segundos Unix).
|
|
29
|
+
* - `iss`: Issuer. Emisor (opcional, configurable).
|
|
30
|
+
* - `aud`: Audience. Audiencia (opcional, configurable).
|
|
31
|
+
*
|
|
32
|
+
* ### Manejo de errores
|
|
33
|
+
* Cualquier error técnico de `jose` se captura y traduce a un error del core
|
|
34
|
+
* mediante `createAuthError` + el mapper `toAuthDomainError`.
|
|
35
|
+
*
|
|
36
|
+
* @template TAuthError Tipo concreto de Error del core.
|
|
37
|
+
*/
|
|
38
|
+
class JoseTokenService {
|
|
39
|
+
/**
|
|
40
|
+
* Crea el servicio.
|
|
41
|
+
*
|
|
42
|
+
* @param options Configuración del plugin (keys/issuer/audience/clockSkew).
|
|
43
|
+
* @param createAuthError Función para construir errores del core.
|
|
44
|
+
*/
|
|
45
|
+
constructor(options, createAuthError) {
|
|
46
|
+
this.options = options;
|
|
47
|
+
this.createAuthError = createAuthError;
|
|
48
|
+
}
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Public API
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
/**
|
|
53
|
+
* Genera un Access Token.
|
|
54
|
+
*
|
|
55
|
+
* @param props Props definidos por el core:
|
|
56
|
+
* - user.id se asigna al claim `sub`
|
|
57
|
+
* - user.roles se incluye en el payload
|
|
58
|
+
* - customClaims opcional en payload (si el core lo define en props)
|
|
59
|
+
* - expiresIn opcional (si se incluye, sobreescribe defaultExpiresIn)
|
|
60
|
+
* @returns JWT compacto (string: "header.payload.signature")
|
|
61
|
+
*/
|
|
62
|
+
async generateAccessToken(props) {
|
|
63
|
+
return this.generateToken("access", "generateAccessToken", props);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Genera un Refresh Token.
|
|
67
|
+
*
|
|
68
|
+
* @param props Props definidos por el core:
|
|
69
|
+
* - user.id se asigna al claim `sub`
|
|
70
|
+
* - user.roles se incluye en el payload
|
|
71
|
+
* - customClaims opcional en payload (si el core lo define en props)
|
|
72
|
+
* - expiresIn opcional (si se incluye, sobreescribe defaultExpiresIn)
|
|
73
|
+
* @returns JWT compacto (string: "header.payload.signature")
|
|
74
|
+
*/
|
|
75
|
+
async generateRefreshToken(props) {
|
|
76
|
+
return this.generateToken("refresh", "generateRefreshToken", props);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Verifica un Access Token.
|
|
80
|
+
*
|
|
81
|
+
* Verificación incluye:
|
|
82
|
+
* - Firma válida según keys + algoritmo
|
|
83
|
+
* - `iss` y `aud` si están configurados
|
|
84
|
+
* - `exp` y `nbf` (si existe) considerando clockSkew
|
|
85
|
+
*
|
|
86
|
+
* @param token JWT compacto (string).
|
|
87
|
+
* @returns Payload normalizado al tipo `IJWTPayload` del core.
|
|
88
|
+
*/
|
|
89
|
+
async verifyAccessToken(token) {
|
|
90
|
+
return this.verifyToken("access", "verifyAccessToken", token);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Verifica un Refresh Token.
|
|
94
|
+
*
|
|
95
|
+
* @param token JWT compacto (string).
|
|
96
|
+
* @returns Payload normalizado al tipo `IJWTPayload` del core.
|
|
97
|
+
*/
|
|
98
|
+
async verifyRefreshToken(token) {
|
|
99
|
+
return this.verifyToken("refresh", "verifyRefreshToken", token);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Devuelve la fecha de expiración (`exp`) del token.
|
|
103
|
+
*
|
|
104
|
+
* Política aplicada: **verify-first** (obligatoria en este proyecto)
|
|
105
|
+
*
|
|
106
|
+
* Estrategia práctica:
|
|
107
|
+
* 1) Intenta verificar como access:
|
|
108
|
+
* - Si verifica, devuelve `payload.exp`.
|
|
109
|
+
* - Si falla y el error es "retryable", intenta refresh.
|
|
110
|
+
* - Si falla por expiración, intenta leer `exp` por decode (sin verificar firma).
|
|
111
|
+
*
|
|
112
|
+
* 2) Intenta verificar como refresh:
|
|
113
|
+
* - Mismo comportamiento para el caso expirado.
|
|
114
|
+
*
|
|
115
|
+
* @param token JWT compacto (string).
|
|
116
|
+
* @returns Date correspondiente a `exp`.
|
|
117
|
+
* @throws Error del core (TAuthError) cuando no se puede determinar la expiración.
|
|
118
|
+
*/
|
|
119
|
+
async getTokenExpiration(token) {
|
|
120
|
+
const policy = this.options.getExpirationPolicy ?? "verify-first";
|
|
121
|
+
// Contrato del proyecto: solo soportamos verify-first en el plugin.
|
|
122
|
+
if (policy !== "verify-first") {
|
|
123
|
+
throw this.createAuthError({
|
|
124
|
+
code: "JWT_ERROR",
|
|
125
|
+
message: "Unsupported expiration policy",
|
|
126
|
+
meta: { operation: "getTokenExpiration", tokenKind: "unknown" },
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
// A1: Intentar access primero (por convención suele ser lo más común).
|
|
130
|
+
try {
|
|
131
|
+
const payload = await this.verifyToken("access", "getTokenExpiration", token);
|
|
132
|
+
return (0, internal_1.toDateFromUnixSeconds)(payload.exp);
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
// Cuando el token expiró, el verify falla. Aun así, exp está dentro del token.
|
|
136
|
+
// Decodificar (sin verificar) permite devolver la fecha de expiración.
|
|
137
|
+
const exp = (0, internal_1.tryReadExpByDecode)(token);
|
|
138
|
+
const mapped = (0, mappers_1.mapJoseErrorToAuthError)(e, this.ctx("getTokenExpiration", "access"));
|
|
139
|
+
// Caso especial: token expirado y exp disponible por decode.
|
|
140
|
+
if (mapped.code === "TOKEN_EXPIRED" && exp !== null) {
|
|
141
|
+
return (0, internal_1.toDateFromUnixSeconds)(exp);
|
|
142
|
+
}
|
|
143
|
+
// Si el error no es "retryable", no tiene sentido probar refresh.
|
|
144
|
+
if (!(0, internal_1.isRetryableMappedCode)(mapped.code)) {
|
|
145
|
+
throw e;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Fallback: intentar refresh
|
|
149
|
+
try {
|
|
150
|
+
const payload = await this.verifyToken("refresh", "getTokenExpiration", token);
|
|
151
|
+
return (0, internal_1.toDateFromUnixSeconds)(payload.exp);
|
|
152
|
+
}
|
|
153
|
+
catch (e) {
|
|
154
|
+
const exp = (0, internal_1.tryReadExpByDecode)(token);
|
|
155
|
+
const mapped = (0, mappers_1.mapJoseErrorToAuthError)(e, this.ctx("getTokenExpiration", "refresh"));
|
|
156
|
+
if (mapped.code === "TOKEN_EXPIRED" && exp !== null) {
|
|
157
|
+
return (0, internal_1.toDateFromUnixSeconds)(exp);
|
|
158
|
+
}
|
|
159
|
+
throw e;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
// Internals - ctx + error wrapper
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
/**
|
|
166
|
+
* Construye un contexto técnico para mapear errores.
|
|
167
|
+
*
|
|
168
|
+
* El contexto agrega información útil:
|
|
169
|
+
* - operación (generate/verify/getExpiration)
|
|
170
|
+
* - tipo de token (access/refresh)
|
|
171
|
+
* - issuer/audience/alg efectivos
|
|
172
|
+
*
|
|
173
|
+
* Esto permite que el mapper traduzca un error de `jose` a un código del core.
|
|
174
|
+
*
|
|
175
|
+
* @param operation Operación que se está ejecutando.
|
|
176
|
+
* @param kind Tipo de token al que aplica la operación.
|
|
177
|
+
* @returns Contexto técnico para el mapper de errores.
|
|
178
|
+
*/
|
|
179
|
+
ctx(operation, kind) {
|
|
180
|
+
if (kind === "unknown") {
|
|
181
|
+
return (0, internal_1.buildJoseCtx)(operation, "unknown", {
|
|
182
|
+
issuer: undefined,
|
|
183
|
+
audience: undefined,
|
|
184
|
+
alg: undefined,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
const eff = (0, internal_1.getEffectiveConfig)(this.options, kind);
|
|
188
|
+
return (0, internal_1.buildJoseCtx)(operation, kind, eff);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Wrapper de errores: captura errores técnicos y los convierte a errores del core.
|
|
192
|
+
*
|
|
193
|
+
* Esta función garantiza que la API pública del plugin nunca “escape” errores de jose.
|
|
194
|
+
*
|
|
195
|
+
* @param operation Operación actual (para el contexto de error).
|
|
196
|
+
* @param kind Tipo de token (access/refresh).
|
|
197
|
+
* @param fn Función async que ejecuta la operación real.
|
|
198
|
+
* @returns Resultado de la operación si todo sale bien.
|
|
199
|
+
* @throws Error del core (TAuthError) si algo falla.
|
|
200
|
+
*/
|
|
201
|
+
async withAuthError(operation, kind, fn) {
|
|
202
|
+
try {
|
|
203
|
+
return await fn();
|
|
204
|
+
}
|
|
205
|
+
catch (e) {
|
|
206
|
+
// Convierte el error técnico a un AuthDomainError (core) usando el mapper.
|
|
207
|
+
throw (0, mappers_1.toAuthDomainError)(this.createAuthError, e, this.ctx(operation, kind));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// ---------------------------------------------------------------------------
|
|
211
|
+
// Internals - keys
|
|
212
|
+
// ---------------------------------------------------------------------------
|
|
213
|
+
/**
|
|
214
|
+
* Obtiene las keys normalizadas para firmar/verificar tokens.
|
|
215
|
+
*
|
|
216
|
+
* La normalización sucede una sola vez (lazy) para evitar:
|
|
217
|
+
* - importación repetida de PEM
|
|
218
|
+
* - creación repetida de Uint8Array para HS256
|
|
219
|
+
*
|
|
220
|
+
* @param kind Tipo de token (access/refresh).
|
|
221
|
+
* @returns Keys normalizadas según algoritmo.
|
|
222
|
+
*/
|
|
223
|
+
getNormalizedKeys(kind) {
|
|
224
|
+
if (kind === "access") {
|
|
225
|
+
// Cache lazy: la primera vez normaliza, luego reutiliza.
|
|
226
|
+
this.accessKeysPromise ?? (this.accessKeysPromise = (0, internal_1.normalizeKeyMaterial)(this.options.access.keys));
|
|
227
|
+
return this.accessKeysPromise;
|
|
228
|
+
}
|
|
229
|
+
this.refreshKeysPromise ?? (this.refreshKeysPromise = (0, internal_1.normalizeKeyMaterial)(this.options.refresh.keys));
|
|
230
|
+
return this.refreshKeysPromise;
|
|
231
|
+
}
|
|
232
|
+
// ---------------------------------------------------------------------------
|
|
233
|
+
// Internals - token ops
|
|
234
|
+
// ---------------------------------------------------------------------------
|
|
235
|
+
/**
|
|
236
|
+
* Genera un token JWT (access o refresh).
|
|
237
|
+
*
|
|
238
|
+
* Qué hace internamente (explicación simple):
|
|
239
|
+
* - Calcula config efectiva (issuer/audience/clockSkew/alg)
|
|
240
|
+
* - Resuelve expiresIn (props o default)
|
|
241
|
+
* - Construye payload con roles + customClaims
|
|
242
|
+
* - Establece claims estándar: sub, jti, iat, exp, iss, aud
|
|
243
|
+
* - Firma el token con:
|
|
244
|
+
* - HS256: secret
|
|
245
|
+
* - RS256/ES256: privateKey
|
|
246
|
+
*
|
|
247
|
+
* @param kind Tipo de token a generar.
|
|
248
|
+
* @param operation Nombre lógico de operación (para errores).
|
|
249
|
+
* @param props Props del core para generación de token.
|
|
250
|
+
* @returns JWT compacto firmado.
|
|
251
|
+
*/
|
|
252
|
+
async generateToken(kind, operation, props) {
|
|
253
|
+
return this.withAuthError(operation, kind, async () => {
|
|
254
|
+
const eff = (0, internal_1.getEffectiveConfig)(this.options, kind);
|
|
255
|
+
// expiresIn puede venir en props o en defaultExpiresIn de options.
|
|
256
|
+
const expiresIn = (0, internal_1.resolveExpiresIn)(props.expiresIn, this.options[kind].defaultExpiresIn, operation);
|
|
257
|
+
const { alg, secret, privateKey } = await this.getNormalizedKeys(kind);
|
|
258
|
+
// roles y customClaims se guardan en el payload (cuerpo) del token.
|
|
259
|
+
const roles = props.user.roles ?? [];
|
|
260
|
+
const customClaims = props.customClaims ?? {};
|
|
261
|
+
// SignJWT crea un JWT y lo firma.
|
|
262
|
+
const jwt = new jose_1.SignJWT({ roles, customClaims })
|
|
263
|
+
.setProtectedHeader({ alg }) // cabecera: define algoritmo
|
|
264
|
+
.setSubject(props.user.id) // claim sub
|
|
265
|
+
.setJti((0, internal_1.createJti)()) // claim jti (id único)
|
|
266
|
+
.setIssuedAt() // claim iat (ahora)
|
|
267
|
+
.setExpirationTime(expiresIn); // claim exp basado en expiresIn
|
|
268
|
+
// iss/aud solo se establecen si están configurados.
|
|
269
|
+
if (eff.issuer)
|
|
270
|
+
jwt.setIssuer(eff.issuer);
|
|
271
|
+
if (eff.audience)
|
|
272
|
+
jwt.setAudience(eff.audience);
|
|
273
|
+
// Firma según algoritmo.
|
|
274
|
+
return alg === "HS256" ? jwt.sign(secret) : jwt.sign(privateKey);
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Verifica un token JWT (access o refresh) y normaliza el payload al tipo del core.
|
|
279
|
+
*
|
|
280
|
+
* Qué valida `jwtVerify`:
|
|
281
|
+
* - Firma correcta según key + algoritmo
|
|
282
|
+
* - exp/nbf/iat (según reglas estándar)
|
|
283
|
+
* - issuer/audience si se configuran
|
|
284
|
+
* - clockTolerance para tolerar pequeños desajustes de reloj
|
|
285
|
+
*
|
|
286
|
+
* @param kind Tipo de token esperado (access/refresh).
|
|
287
|
+
* @param operation Operación lógica (para contexto de error).
|
|
288
|
+
* @param token JWT compacto (string).
|
|
289
|
+
* @returns Payload normalizado (IJWTPayload).
|
|
290
|
+
*/
|
|
291
|
+
async verifyToken(kind, operation, token) {
|
|
292
|
+
return this.withAuthError(operation, kind, async () => {
|
|
293
|
+
const eff = (0, internal_1.getEffectiveConfig)(this.options, kind);
|
|
294
|
+
const { alg, secret, publicKey } = await this.getNormalizedKeys(kind);
|
|
295
|
+
// Key según algoritmo:
|
|
296
|
+
// - HS256 usa secret
|
|
297
|
+
// - RS256/ES256 usan publicKey
|
|
298
|
+
const key = alg === "HS256" ? secret : publicKey;
|
|
299
|
+
const result = await (0, jose_1.jwtVerify)(token, key, {
|
|
300
|
+
issuer: eff.issuer,
|
|
301
|
+
audience: eff.audience,
|
|
302
|
+
clockTolerance: eff.clockSkewSeconds,
|
|
303
|
+
});
|
|
304
|
+
// Normalización: asegura claims mínimos y tipos esperados por el core.
|
|
305
|
+
return (0, internal_1.normalizeJwtPayload)(result.payload, eff.issuer, eff.audience);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
exports.JoseTokenService = JoseTokenService;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { mapJoseErrorToAuthError } from "src/infrastructure/mappers";
|
|
2
|
+
/**
|
|
3
|
+
* Función que crea errores del dominio (core) a partir de datos técnicos.
|
|
4
|
+
*
|
|
5
|
+
* Esto permite que el plugin NO exponga errores propios, y siempre entregue
|
|
6
|
+
* errores consistentes definidos por el core (@jmlq/auth).
|
|
7
|
+
*
|
|
8
|
+
* @template TAuthError Tipo concreto de Error del core.
|
|
9
|
+
*/
|
|
10
|
+
export type CreateAuthErrorFn<TAuthError extends Error> = (args: {
|
|
11
|
+
/**
|
|
12
|
+
* Código de error del core. Se obtiene mapeando el error original de jose.
|
|
13
|
+
*/
|
|
14
|
+
code: ReturnType<typeof mapJoseErrorToAuthError>["code"];
|
|
15
|
+
/**
|
|
16
|
+
* Mensaje humano y útil para debugging / logging.
|
|
17
|
+
*/
|
|
18
|
+
message: string;
|
|
19
|
+
/**
|
|
20
|
+
* Error original (de jose u otro). Se conserva para trazabilidad.
|
|
21
|
+
*/
|
|
22
|
+
cause?: unknown;
|
|
23
|
+
/**
|
|
24
|
+
* Metadatos técnicos opcionales para depuración (issuer, audience, alg, etc.).
|
|
25
|
+
*/
|
|
26
|
+
meta?: Record<string, unknown>;
|
|
27
|
+
}) => TAuthError;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./create-auth-error-fn.type";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./create-auth-error-fn.type"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jmlq/auth-plugin-jose",
|
|
3
|
+
"description": "Infrastructure plugin that integrates the jose library with @jmlq/auth, providing JWT token generation and verification following Clean Architecture principles.",
|
|
4
|
+
"version": "0.0.1-alpha.1",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "rimraf dist && mkdir dist && tsc -p tsconfig.json",
|
|
9
|
+
"build": "rimraf dist && mkdir dist && tsc -p tsconfig.build.json",
|
|
10
|
+
"prepublishOnly": "npm run build",
|
|
11
|
+
"test": "jest --passWithNoTests",
|
|
12
|
+
"test:watch": "jest --watch",
|
|
13
|
+
"test:coverage": "jest --coverage",
|
|
14
|
+
"example:services": "tsx examples/index.example.ts services",
|
|
15
|
+
"example:service-helpers": "tsx examples/index.example.ts service-helpers",
|
|
16
|
+
"example:factories": "tsx examples/index.example.ts factories",
|
|
17
|
+
"example:factory-helpers": "tsx examples/index.example.ts factory-helpers",
|
|
18
|
+
"example:help": "tsx examples/index.example.ts help",
|
|
19
|
+
"example:all": "tsx examples/index.example.ts"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"jwt",
|
|
23
|
+
"jose",
|
|
24
|
+
"authentication",
|
|
25
|
+
"clean-architecture",
|
|
26
|
+
"typescript"
|
|
27
|
+
],
|
|
28
|
+
"author": "MLahuasi",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@jmlq/auth": "^0.0.1-alpha.2",
|
|
32
|
+
"jose": "^6.1.3",
|
|
33
|
+
"rimraf": "^6.1.2"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@swc/core": "^1.3.95",
|
|
37
|
+
"@swc/jest": "^0.2.29",
|
|
38
|
+
"@types/bcryptjs": "^2.4.5",
|
|
39
|
+
"@types/jest": "^29.5.8",
|
|
40
|
+
"@types/node": "^20.8.10",
|
|
41
|
+
"jest": "^29.7.0",
|
|
42
|
+
"tsx": "^4.1.4",
|
|
43
|
+
"typescript": "^5.2.2"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist"
|
|
47
|
+
]
|
|
48
|
+
}
|