valtech-components 2.0.481 → 2.0.483
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/esm2022/lib/services/auth/auth-state.service.mjs +10 -1
- package/esm2022/lib/services/auth/auth.service.mjs +11 -2
- package/esm2022/lib/services/auth/storage.service.mjs +12 -1
- package/esm2022/lib/services/auth/types.mjs +1 -1
- package/esm2022/lib/services/firebase/index.mjs +3 -1
- package/esm2022/lib/services/firebase/messaging.service.mjs +25 -1
- package/esm2022/lib/services/firebase/notifications.service.mjs +207 -0
- package/esm2022/lib/services/firebase/types.mjs +1 -1
- package/fesm2022/valtech-components.mjs +438 -185
- package/fesm2022/valtech-components.mjs.map +1 -1
- package/lib/components/organisms/article/article.component.d.ts +1 -1
- package/lib/services/auth/auth-state.service.d.ts +4 -0
- package/lib/services/auth/auth.service.d.ts +2 -0
- package/lib/services/auth/storage.service.d.ts +4 -0
- package/lib/services/auth/types.d.ts +6 -0
- package/lib/services/firebase/index.d.ts +1 -0
- package/lib/services/firebase/messaging.service.d.ts +10 -0
- package/lib/services/firebase/notifications.service.d.ts +122 -0
- package/lib/services/firebase/types.d.ts +6 -0
- package/package.json +1 -1
|
@@ -90,7 +90,7 @@ export declare class ArticleComponent implements OnInit {
|
|
|
90
90
|
contentInterpolation?: Record<string, string | number>;
|
|
91
91
|
icon?: import("valtech-components").IconMetada;
|
|
92
92
|
shape?: "round";
|
|
93
|
-
size?: "
|
|
93
|
+
size?: "small" | "large" | "default";
|
|
94
94
|
fill?: "default" | "clear" | "outline" | "solid";
|
|
95
95
|
type: "button" | "submit" | "reset";
|
|
96
96
|
token?: string;
|
|
@@ -48,6 +48,10 @@ export declare class AuthStateService {
|
|
|
48
48
|
* Actualiza solo el access token (después de refresh).
|
|
49
49
|
*/
|
|
50
50
|
updateAccessToken(accessToken: string, expiresIn: number): void;
|
|
51
|
+
/**
|
|
52
|
+
* Actualiza el refresh token (token rotation).
|
|
53
|
+
*/
|
|
54
|
+
updateRefreshToken(refreshToken: string): void;
|
|
51
55
|
/**
|
|
52
56
|
* Actualiza los permisos.
|
|
53
57
|
*/
|
|
@@ -94,6 +94,8 @@ export declare class AuthService implements OnDestroy {
|
|
|
94
94
|
verifyMFA(code: string): Observable<MFAVerifyResponse>;
|
|
95
95
|
/**
|
|
96
96
|
* Refresca el token de acceso.
|
|
97
|
+
* Implementa token rotation: cada refresh genera un nuevo refresh token
|
|
98
|
+
* que el cliente debe guardar para el próximo refresh.
|
|
97
99
|
*/
|
|
98
100
|
refreshAccessToken(): Observable<RefreshResponse>;
|
|
99
101
|
/**
|
|
@@ -19,6 +19,10 @@ export declare class AuthStorageService {
|
|
|
19
19
|
* Guarda solo el access token.
|
|
20
20
|
*/
|
|
21
21
|
saveAccessToken(token: string, expiresAt?: number): void;
|
|
22
|
+
/**
|
|
23
|
+
* Guarda el refresh token (token rotation).
|
|
24
|
+
*/
|
|
25
|
+
saveRefreshToken(token: string): void;
|
|
22
26
|
/**
|
|
23
27
|
* Guarda los permisos actualizados.
|
|
24
28
|
*/
|
|
@@ -209,11 +209,16 @@ export interface RefreshRequest {
|
|
|
209
209
|
}
|
|
210
210
|
/**
|
|
211
211
|
* Response de refrescar token.
|
|
212
|
+
* Implementa token rotation: cada refresh genera un nuevo refresh token.
|
|
212
213
|
*/
|
|
213
214
|
export interface RefreshResponse {
|
|
214
215
|
operationId: string;
|
|
215
216
|
accessToken: string;
|
|
217
|
+
refreshToken: string;
|
|
216
218
|
expiresIn: number;
|
|
219
|
+
firebaseToken?: string;
|
|
220
|
+
roles?: string[];
|
|
221
|
+
permissions?: string[];
|
|
217
222
|
}
|
|
218
223
|
/**
|
|
219
224
|
* Request para logout.
|
|
@@ -361,6 +366,7 @@ export interface AuthSyncEvent {
|
|
|
361
366
|
timestamp: number;
|
|
362
367
|
payload?: {
|
|
363
368
|
accessToken?: string;
|
|
369
|
+
refreshToken?: string;
|
|
364
370
|
expiresAt?: number;
|
|
365
371
|
activeOrg?: string;
|
|
366
372
|
};
|
|
@@ -37,3 +37,4 @@ export { QueryBuilder, query } from './utils/query-builder';
|
|
|
37
37
|
export { buildPath, extractPathParams, getCollectionPath, getDocumentId, isCollectionPath, isDocumentPath, isValidPath, joinPath, } from './utils/path-builder';
|
|
38
38
|
export { StorageService } from './storage.service';
|
|
39
39
|
export { MessagingService } from './messaging.service';
|
|
40
|
+
export { NotificationDocument, NotificationsService } from './notifications.service';
|
|
@@ -56,6 +56,10 @@ export declare class MessagingService {
|
|
|
56
56
|
private notificationClickSubject;
|
|
57
57
|
private stateSubject;
|
|
58
58
|
private unsubscribeOnMessage?;
|
|
59
|
+
/** Flag para persistir mensajes FCM en localStorage (debugging) */
|
|
60
|
+
private readonly debugPersistence;
|
|
61
|
+
/** Key para localStorage de mensajes FCM (debugging) */
|
|
62
|
+
private readonly DEBUG_STORAGE_KEY;
|
|
59
63
|
constructor(injector: Injector, config: ValtechFirebaseConfig, platformId: Object, ngZone: NgZone);
|
|
60
64
|
/**
|
|
61
65
|
* Obtiene la instancia de Messaging de forma perezosa.
|
|
@@ -133,6 +137,12 @@ export declare class MessagingService {
|
|
|
133
137
|
* Configura el listener de mensajes en foreground
|
|
134
138
|
*/
|
|
135
139
|
private setupMessageListener;
|
|
140
|
+
/**
|
|
141
|
+
* Persiste un mensaje FCM en localStorage para debugging.
|
|
142
|
+
* Solo se usa cuando debugMessagePersistence está habilitado.
|
|
143
|
+
* Mantiene los últimos 50 mensajes.
|
|
144
|
+
*/
|
|
145
|
+
private persistMessageForDebug;
|
|
136
146
|
/**
|
|
137
147
|
* Obtiene el estado actual del permiso de notificaciones.
|
|
138
148
|
*
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notifications Service
|
|
3
|
+
*
|
|
4
|
+
* Servicio para leer notificaciones desde Firestore.
|
|
5
|
+
* El backend escribe las notificaciones, el frontend solo las lee y actualiza estado.
|
|
6
|
+
*
|
|
7
|
+
* Se auto-inicializa cuando AuthService tiene un usuario autenticado.
|
|
8
|
+
* También puede inicializarse manualmente con `initialize(userId)`.
|
|
9
|
+
*/
|
|
10
|
+
import { Injector } from '@angular/core';
|
|
11
|
+
import { Observable } from 'rxjs';
|
|
12
|
+
import { FirestoreCollectionFactory } from './firestore-collection';
|
|
13
|
+
import { FirestoreDocument, ValtechFirebaseConfig } from './types';
|
|
14
|
+
import * as i0 from "@angular/core";
|
|
15
|
+
/**
|
|
16
|
+
* Documento de notificación en Firestore.
|
|
17
|
+
* Estructura escrita por el backend.
|
|
18
|
+
*/
|
|
19
|
+
export interface NotificationDocument extends FirestoreDocument {
|
|
20
|
+
/** Título de la notificación */
|
|
21
|
+
title?: string;
|
|
22
|
+
/** Cuerpo del mensaje */
|
|
23
|
+
body?: string;
|
|
24
|
+
/** URL de imagen */
|
|
25
|
+
image?: string;
|
|
26
|
+
/** Datos personalizados (ej: route, actionType) */
|
|
27
|
+
data?: Record<string, string>;
|
|
28
|
+
/** Tipo de notificación */
|
|
29
|
+
type?: 'fcm' | 'system' | 'reminder' | string;
|
|
30
|
+
/** Si la notificación fue leída */
|
|
31
|
+
isRead: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Servicio para leer notificaciones desde Firestore.
|
|
35
|
+
*
|
|
36
|
+
* Se auto-inicializa cuando AuthService tiene un usuario autenticado.
|
|
37
|
+
* No requiere llamar a `initialize()` manualmente si AuthService está configurado.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // Con AuthService configurado: auto-inicialización
|
|
42
|
+
* // Solo inyectar y usar directamente
|
|
43
|
+
* private notifications = inject(NotificationsService);
|
|
44
|
+
*
|
|
45
|
+
* notifications$ = this.notifications.getAll();
|
|
46
|
+
* unreadCount$ = this.notifications.getUnreadCount();
|
|
47
|
+
*
|
|
48
|
+
* // Sin AuthService: inicialización manual
|
|
49
|
+
* this.notifications.initialize(userId);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare class NotificationsService {
|
|
53
|
+
private injector;
|
|
54
|
+
private collectionFactory;
|
|
55
|
+
private config;
|
|
56
|
+
private collection;
|
|
57
|
+
private currentUserId;
|
|
58
|
+
private authService;
|
|
59
|
+
constructor(injector: Injector, collectionFactory: FirestoreCollectionFactory, config: ValtechFirebaseConfig | null);
|
|
60
|
+
/**
|
|
61
|
+
* Configura auto-inicialización observando el estado de AuthService.
|
|
62
|
+
* Se ejecuta en el contexto del injector para poder usar effect().
|
|
63
|
+
*/
|
|
64
|
+
private setupAutoInitialization;
|
|
65
|
+
/**
|
|
66
|
+
* Inicializa el servicio para un usuario específico.
|
|
67
|
+
*
|
|
68
|
+
* NOTA: Se llama automáticamente si AuthService está configurado.
|
|
69
|
+
* Solo usar manualmente si AuthService no está disponible o se necesita
|
|
70
|
+
* un userId diferente al del usuario autenticado.
|
|
71
|
+
*/
|
|
72
|
+
initialize(userId: string): void;
|
|
73
|
+
/**
|
|
74
|
+
* Verifica si el servicio está inicializado.
|
|
75
|
+
*/
|
|
76
|
+
get isReady(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Obtiene el ID del usuario actual.
|
|
79
|
+
*/
|
|
80
|
+
get userId(): string | null;
|
|
81
|
+
/**
|
|
82
|
+
* Obtiene todas las notificaciones ordenadas por fecha descendente.
|
|
83
|
+
* Real-time: se actualiza automáticamente cuando cambian los datos.
|
|
84
|
+
*/
|
|
85
|
+
getAll(): Observable<NotificationDocument[]>;
|
|
86
|
+
/**
|
|
87
|
+
* Obtiene solo notificaciones no leídas.
|
|
88
|
+
*/
|
|
89
|
+
getUnread(): Observable<NotificationDocument[]>;
|
|
90
|
+
/**
|
|
91
|
+
* Cuenta notificaciones no leídas.
|
|
92
|
+
* Útil para badges en UI.
|
|
93
|
+
*/
|
|
94
|
+
getUnreadCount(): Observable<number>;
|
|
95
|
+
/**
|
|
96
|
+
* Obtiene una notificación por ID.
|
|
97
|
+
*/
|
|
98
|
+
getById(notificationId: string): Promise<NotificationDocument | null>;
|
|
99
|
+
/**
|
|
100
|
+
* Marca una notificación como leída.
|
|
101
|
+
*/
|
|
102
|
+
markAsRead(notificationId: string): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Marca todas las notificaciones como leídas.
|
|
105
|
+
*/
|
|
106
|
+
markAllAsRead(): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Elimina una notificación.
|
|
109
|
+
*/
|
|
110
|
+
delete(notificationId: string): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Elimina todas las notificaciones del usuario.
|
|
113
|
+
*/
|
|
114
|
+
deleteAll(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Limpia el estado del servicio.
|
|
117
|
+
* Útil para logout.
|
|
118
|
+
*/
|
|
119
|
+
reset(): void;
|
|
120
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NotificationsService, [null, { optional: true; }, { optional: true; }]>;
|
|
121
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<NotificationsService>;
|
|
122
|
+
}
|
|
@@ -66,6 +66,12 @@ export interface ValtechFirebaseConfig {
|
|
|
66
66
|
* Si no se proporciona, los paths quedan sin modificar (backward compatible).
|
|
67
67
|
*/
|
|
68
68
|
appId?: AppId;
|
|
69
|
+
/**
|
|
70
|
+
* Persiste mensajes FCM en localStorage para debugging.
|
|
71
|
+
* Solo para desarrollo, permite ver mensajes en DevTools.
|
|
72
|
+
* Default: false
|
|
73
|
+
*/
|
|
74
|
+
debugMessagePersistence?: boolean;
|
|
69
75
|
}
|
|
70
76
|
/**
|
|
71
77
|
* Interface base para todos los documentos de Firestore.
|