@innertia-solutions/innertia-nuxt 0.1.86 → 0.1.87

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.
@@ -386,7 +386,8 @@ const loadDocx = async () => {
386
386
  }
387
387
  }
388
388
 
389
- watch(() => props.file?.id, () => {
389
+ // También al subir una versión nueva: el id no cambia, pero el contenido sí.
390
+ watch(() => [props.file?.id, props.file?.version], () => {
390
391
  textContent.value = null
391
392
  xlsxWorkbook.value = null
392
393
  xlsxActiveIdx.value = 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innertia-solutions/innertia-nuxt",
3
- "version": "0.1.86",
3
+ "version": "0.1.87",
4
4
  "description": "Innertia Solutions — Nuxt layer unificada: core, auth, multitenancy, theme y app contexts",
5
5
  "keywords": [
6
6
  "nuxt",
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect, vi } from 'vitest'
2
- import { decodeJwtPayload, shouldRefreshToken, createTokenRotator } from '../tokenRefresh'
2
+ import { decodeJwtPayload, isPlatformToken, shouldRefreshToken, createTokenRotator } from '../tokenRefresh'
3
3
 
4
4
  function jwt(payload: Record<string, unknown>): string {
5
5
  const b64 = (o: unknown) => Buffer.from(JSON.stringify(o)).toString('base64url')
@@ -30,8 +30,10 @@ describe('shouldRefreshToken', () => {
30
30
  it('no renueva un token ya vencido (Laravel no lo acepta)', () => {
31
31
  expect(shouldRefreshToken(ttl60(), iat + 3601)).toBe(false)
32
32
  })
33
- it('no renueva tokens de plataforma (identidad separada)', () => {
34
- expect(shouldRefreshToken(ttl60({ platform: true }), iat + 3500)).toBe(false)
33
+ it('renueva también tokens de plataforma (contra su propio endpoint)', () => {
34
+ expect(shouldRefreshToken(ttl60({ platform: true }), iat + 3500)).toBe(true)
35
+ expect(isPlatformToken(ttl60({ platform: true }))).toBe(true)
36
+ expect(isPlatformToken(ttl60())).toBe(false)
35
37
  })
36
38
  it('con TTL corto usa 1/3 de la vida como ventana (no renueva en cada request)', () => {
37
39
  const short = jwt({ iat, exp: iat + 300 }) // 5 min
@@ -3,7 +3,7 @@ import type { H3Event } from 'h3'
3
3
  import { readSession, writeSession } from './session'
4
4
  import type { SessionData } from './session'
5
5
  import { buildAuthHeaders, forwardClientHeaders } from './bff'
6
- import { createTokenRotator, shouldRefreshToken } from './tokenRefresh'
6
+ import { createTokenRotator, isPlatformToken, shouldRefreshToken } from './tokenRefresh'
7
7
 
8
8
  // Token de la sesión sellada con renovación deslizante (ver tokenRefresh.ts).
9
9
  // Un rotador por proceso Nitro: deduplica refrescos concurrentes del mismo token.
@@ -15,7 +15,10 @@ function getRotator() {
15
15
  refresh: async (token, ev) => {
16
16
  if (!ev) return null
17
17
  const config = useRuntimeConfig(ev)
18
- const path = String((config as any).authRefresh?.path || 'auth/refresh').replace(/^\/+/, '')
18
+ // La consola de plataforma renueva contra su propio endpoint: un backend sin
19
+ // esa ruta responde 404 y se sigue con el token actual (no cambia de identidad).
20
+ const cfg = (config as any).authRefresh || {}
21
+ const path = String(isPlatformToken(token) ? (cfg.platformPath || 'platform/auth/refresh') : (cfg.path || 'auth/refresh')).replace(/^\/+/, '')
19
22
  const res: any = await $fetch(`${String(config.apiInternalUrl).replace(/\/+$/, '')}/${path}`, {
20
23
  method: 'POST',
21
24
  // Un refresh colgado no debe bloquear el request del usuario: se sigue con el token actual.
@@ -32,20 +32,24 @@ export function decodeJwtPayload(token?: string | null): JwtPayload | null {
32
32
  }
33
33
  }
34
34
 
35
+ /** ¿El token es de la consola de plataforma (identidad separada)? */
36
+ export function isPlatformToken(token: string | null | undefined): boolean {
37
+ return Boolean(decodeJwtPayload(token)?.platform)
38
+ }
39
+
35
40
  /** Ventana máxima (segundos) antes del vencimiento en que se renueva. */
36
41
  export const REFRESH_WINDOW_SECONDS = 10 * 60
37
42
 
38
43
  /**
39
44
  * ¿Conviene renovar ahora? Sí cuando el token sigue vigente y le queda menos de
40
45
  * min(10 min, 1/3 de su vida). El tope por vida evita renovar en cada request si
41
- * el TTL configurado es corto. Los tokens de plataforma (claim `platform`) NO se
42
- * renuevan: auth/refresh de Laravel resuelve el usuario con el modelo de usuarios
43
- * del producto y no conserva el claim, así que emitiría un token de otra identidad.
46
+ * el TTL configurado es corto. Los tokens de plataforma (claim `platform`) también
47
+ * se renuevan, pero contra su propio endpoint (platform/auth/refresh, ver
48
+ * isPlatformToken): el auth/refresh normal de un backend antiguo no conserva el claim.
44
49
  */
45
50
  export function shouldRefreshToken(token: string | null | undefined, nowSeconds: number, windowSeconds = REFRESH_WINDOW_SECONDS): boolean {
46
51
  const payload = decodeJwtPayload(token)
47
52
  if (!payload || typeof payload.exp !== 'number') return false
48
- if (payload.platform) return false
49
53
  const remaining = payload.exp - nowSeconds
50
54
  if (remaining <= 0) return false
51
55
  const issuedAt = typeof payload.iat === 'number' ? payload.iat : (typeof payload.nbf === 'number' ? payload.nbf : null)