valtech-components 2.0.475 → 2.0.477
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.service.mjs +199 -6
- package/esm2022/lib/services/auth/config.mjs +2 -1
- package/esm2022/lib/services/auth/index.mjs +19 -3
- package/esm2022/lib/services/auth/types.mjs +1 -1
- package/esm2022/lib/services/firebase/messaging.service.mjs +29 -17
- package/fesm2022/valtech-components.mjs +244 -22
- package/fesm2022/valtech-components.mjs.map +1 -1
- package/lib/services/auth/auth.service.d.ts +62 -5
- package/lib/services/auth/index.d.ts +18 -2
- package/lib/services/auth/types.d.ts +57 -0
- package/lib/services/firebase/messaging.service.d.ts +9 -5
- package/package.json +1 -1
|
@@ -6,8 +6,8 @@ import { AuthStateService } from './auth-state.service';
|
|
|
6
6
|
import { TokenService } from './token.service';
|
|
7
7
|
import { AuthStorageService } from './storage.service';
|
|
8
8
|
import { AuthSyncService } from './sync.service';
|
|
9
|
-
import { SigninRequest, SigninResponse, SignupRequest, SignupResponse, VerifyEmailRequest, VerifyEmailResponse, ResendCodeRequest, ResendCodeResponse, MFAVerifyResponse, RefreshResponse, GetPermissionsResponse, GetProfileResponse, UpdateProfileRequest, UpdateProfileResponse, MFASetupResponse, MFAConfirmResponse, MFADisableResponse, ForgotPasswordRequest, ForgotPasswordResponse, ResetPasswordRequest, ResetPasswordResponse, SwitchOrgResponse, MFAMethod, AuthError, ValtechAuthConfig } from './types';
|
|
10
|
-
import { FirebaseService } from '../firebase';
|
|
9
|
+
import { SigninRequest, SigninResponse, SignupRequest, SignupResponse, VerifyEmailRequest, VerifyEmailResponse, ResendCodeRequest, ResendCodeResponse, MFAVerifyResponse, RefreshResponse, GetPermissionsResponse, GetProfileResponse, UpdateProfileRequest, UpdateProfileResponse, MFASetupResponse, MFAConfirmResponse, MFADisableResponse, ForgotPasswordRequest, ForgotPasswordResponse, ResetPasswordRequest, ResetPasswordResponse, SwitchOrgResponse, MFAMethod, AuthError, ValtechAuthConfig, EnableNotificationsResult, NotificationPermissionState } from './types';
|
|
10
|
+
import { FirebaseService, MessagingService } from '../firebase';
|
|
11
11
|
import * as i0 from "@angular/core";
|
|
12
12
|
/**
|
|
13
13
|
* Servicio principal de autenticación.
|
|
@@ -40,9 +40,10 @@ export declare class AuthService implements OnDestroy {
|
|
|
40
40
|
private storageService;
|
|
41
41
|
private syncService;
|
|
42
42
|
private firebaseService;
|
|
43
|
+
private messagingService;
|
|
43
44
|
private refreshTimerId;
|
|
44
45
|
private syncSubscription;
|
|
45
|
-
constructor(config: ValtechAuthConfig, http: HttpClient, router: Router, stateService: AuthStateService, tokenService: TokenService, storageService: AuthStorageService, syncService: AuthSyncService, firebaseService: FirebaseService);
|
|
46
|
+
constructor(config: ValtechAuthConfig, http: HttpClient, router: Router, stateService: AuthStateService, tokenService: TokenService, storageService: AuthStorageService, syncService: AuthSyncService, firebaseService: FirebaseService, messagingService: MessagingService | null);
|
|
46
47
|
/** Estado completo de autenticación */
|
|
47
48
|
readonly state: import("@angular/core").Signal<import("./types").AuthState>;
|
|
48
49
|
/** Usuario está autenticado */
|
|
@@ -98,7 +99,7 @@ export declare class AuthService implements OnDestroy {
|
|
|
98
99
|
/**
|
|
99
100
|
* Cierra sesión.
|
|
100
101
|
*/
|
|
101
|
-
logout(): void
|
|
102
|
+
logout(): Promise<void>;
|
|
102
103
|
/**
|
|
103
104
|
* Configura MFA para el usuario.
|
|
104
105
|
*/
|
|
@@ -174,6 +175,62 @@ export declare class AuthService implements OnDestroy {
|
|
|
174
175
|
private handleAuthError;
|
|
175
176
|
private signInWithFirebase;
|
|
176
177
|
private signOutFirebase;
|
|
177
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Solicita permisos de notificación y registra el dispositivo.
|
|
180
|
+
* Usar cuando el usuario acepta recibir notificaciones.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* async onEnableNotifications() {
|
|
185
|
+
* const result = await this.auth.enableNotifications();
|
|
186
|
+
* if (result.granted) {
|
|
187
|
+
* console.log('Notificaciones habilitadas');
|
|
188
|
+
* }
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
enableNotifications(): Promise<EnableNotificationsResult>;
|
|
193
|
+
/**
|
|
194
|
+
* Desactiva las notificaciones para este dispositivo.
|
|
195
|
+
* Elimina el token del backend y de FCM.
|
|
196
|
+
* Usar desde un toggle de preferencias cuando el usuario desactiva notificaciones.
|
|
197
|
+
*
|
|
198
|
+
* NOTA: Esto NO revoca el permiso del navegador (el usuario debe hacerlo manualmente
|
|
199
|
+
* desde la configuración del navegador). Solo elimina el registro del dispositivo.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* async onToggleNotifications(enabled: boolean) {
|
|
204
|
+
* if (enabled) {
|
|
205
|
+
* await this.auth.enableNotifications();
|
|
206
|
+
* } else {
|
|
207
|
+
* await this.auth.disableNotifications();
|
|
208
|
+
* }
|
|
209
|
+
* }
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
disableNotifications(): Promise<{
|
|
213
|
+
disabled: boolean;
|
|
214
|
+
}>;
|
|
215
|
+
/**
|
|
216
|
+
* Retorna el estado actual de permisos de notificación.
|
|
217
|
+
*
|
|
218
|
+
* @returns 'granted' | 'denied' | 'default' | 'unsupported'
|
|
219
|
+
*/
|
|
220
|
+
getNotificationPermissionState(): NotificationPermissionState;
|
|
221
|
+
/**
|
|
222
|
+
* Registra el dispositivo en el backend si tiene permisos de notificación.
|
|
223
|
+
* Se llama automáticamente después de un login exitoso si enableDeviceRegistration=true.
|
|
224
|
+
*/
|
|
225
|
+
private registerDeviceIfNeeded;
|
|
226
|
+
/**
|
|
227
|
+
* Elimina el dispositivo del backend y borra el token FCM.
|
|
228
|
+
*/
|
|
229
|
+
private unregisterDevice;
|
|
230
|
+
/**
|
|
231
|
+
* Detecta información de la plataforma del dispositivo.
|
|
232
|
+
*/
|
|
233
|
+
private detectPlatformInfo;
|
|
234
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<AuthService, [null, null, null, null, null, null, null, null, { optional: true; }]>;
|
|
178
235
|
static ɵprov: i0.ɵɵInjectableDeclaration<AuthService>;
|
|
179
236
|
}
|
|
@@ -3,20 +3,23 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Servicio de autenticación reutilizable para aplicaciones Angular.
|
|
5
5
|
* Proporciona autenticación con AuthV2, MFA, sincronización entre pestañas,
|
|
6
|
-
*
|
|
6
|
+
* refresh proactivo de tokens, y registro automático de dispositivos para
|
|
7
|
+
* push notifications.
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
9
10
|
* ```typescript
|
|
10
11
|
* // En main.ts
|
|
11
12
|
* import { bootstrapApplication } from '@angular/platform-browser';
|
|
12
|
-
* import { provideValtechAuth } from 'valtech-components';
|
|
13
|
+
* import { provideValtechAuth, provideValtechFirebase } from 'valtech-components';
|
|
13
14
|
* import { environment } from './environments/environment';
|
|
14
15
|
*
|
|
15
16
|
* bootstrapApplication(AppComponent, {
|
|
16
17
|
* providers: [
|
|
18
|
+
* provideValtechFirebase(environment.firebase),
|
|
17
19
|
* provideValtechAuth({
|
|
18
20
|
* apiUrl: environment.apiUrl,
|
|
19
21
|
* enableFirebaseIntegration: true,
|
|
22
|
+
* enableDeviceRegistration: true, // Auto-registra dispositivos para push
|
|
20
23
|
* }),
|
|
21
24
|
* ],
|
|
22
25
|
* });
|
|
@@ -46,6 +49,19 @@
|
|
|
46
49
|
* }
|
|
47
50
|
* }
|
|
48
51
|
*
|
|
52
|
+
* // Habilitar notificaciones push (solicita permisos + registra dispositivo)
|
|
53
|
+
* async enableNotifications() {
|
|
54
|
+
* const result = await this.auth.enableNotifications();
|
|
55
|
+
* if (result.granted) {
|
|
56
|
+
* console.log('Notificaciones habilitadas');
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* // Verificar estado de permisos
|
|
61
|
+
* get canReceiveNotifications(): boolean {
|
|
62
|
+
* return this.auth.getNotificationPermissionState() === 'granted';
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
49
65
|
* // En template: usar signals directamente
|
|
50
66
|
* // {{ auth.user()?.email }}
|
|
51
67
|
* // @if (auth.hasPermission('templates:edit')) { ... }
|
|
@@ -24,6 +24,8 @@ export interface ValtechAuthConfig {
|
|
|
24
24
|
unauthorizedRoute?: string;
|
|
25
25
|
/** Habilitar integración con FirebaseService (default: false) */
|
|
26
26
|
enableFirebaseIntegration?: boolean;
|
|
27
|
+
/** Habilitar registro automático de device tokens para push notifications (default: false) */
|
|
28
|
+
enableDeviceRegistration?: boolean;
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* Estado completo de autenticación.
|
|
@@ -389,3 +391,58 @@ export interface StoredAuthState {
|
|
|
389
391
|
isSuperAdmin: boolean;
|
|
390
392
|
expiresAt?: number;
|
|
391
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* Plataformas soportadas para push notifications.
|
|
396
|
+
*/
|
|
397
|
+
export type DevicePlatform = 'web' | 'ios' | 'android';
|
|
398
|
+
/**
|
|
399
|
+
* Request para registrar un dispositivo.
|
|
400
|
+
*/
|
|
401
|
+
export interface RegisterDeviceRequest {
|
|
402
|
+
/** FCM token del dispositivo */
|
|
403
|
+
token: string;
|
|
404
|
+
/** Plataforma del dispositivo */
|
|
405
|
+
platform: DevicePlatform;
|
|
406
|
+
/** Navegador (solo web) */
|
|
407
|
+
browser?: string;
|
|
408
|
+
/** Sistema operativo */
|
|
409
|
+
os?: string;
|
|
410
|
+
/** Versión de la aplicación */
|
|
411
|
+
appVersion?: string;
|
|
412
|
+
/** Nombre amigable del dispositivo */
|
|
413
|
+
name?: string;
|
|
414
|
+
/** Metadata adicional */
|
|
415
|
+
metadata?: Record<string, string>;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Response de registro de dispositivo.
|
|
419
|
+
*/
|
|
420
|
+
export interface RegisterDeviceResponse {
|
|
421
|
+
operationId: string;
|
|
422
|
+
device: {
|
|
423
|
+
deviceId: string;
|
|
424
|
+
token: string;
|
|
425
|
+
platform: DevicePlatform;
|
|
426
|
+
browser?: string;
|
|
427
|
+
os?: string;
|
|
428
|
+
lastActive: string;
|
|
429
|
+
createdAt: string;
|
|
430
|
+
};
|
|
431
|
+
/** true si es un nuevo dispositivo, false si se actualizó uno existente */
|
|
432
|
+
isNew: boolean;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Resultado de habilitar notificaciones.
|
|
436
|
+
*/
|
|
437
|
+
export interface EnableNotificationsResult {
|
|
438
|
+
/** Si se otorgaron los permisos */
|
|
439
|
+
granted: boolean;
|
|
440
|
+
/** FCM token (solo si granted=true) */
|
|
441
|
+
token?: string;
|
|
442
|
+
/** Si el dispositivo fue registrado en el backend */
|
|
443
|
+
registered?: boolean;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Estado de permisos de notificación.
|
|
447
|
+
*/
|
|
448
|
+
export type NotificationPermissionState = 'granted' | 'denied' | 'default' | 'unsupported';
|
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
* Permite solicitar permisos, obtener tokens, escuchar mensajes y manejar
|
|
6
6
|
* navegación (deep linking) cuando el usuario toca una notificación.
|
|
7
7
|
*/
|
|
8
|
-
import { NgZone } from '@angular/core';
|
|
9
|
-
import { Messaging } from '@angular/fire/messaging';
|
|
8
|
+
import { Injector, NgZone } from '@angular/core';
|
|
10
9
|
import { Observable } from 'rxjs';
|
|
11
10
|
import { NotificationAction, NotificationClickEvent, NotificationPayload, NotificationPermission, ValtechFirebaseConfig } from './types';
|
|
12
11
|
import * as i0 from "@angular/core";
|
|
@@ -49,7 +48,7 @@ interface MessagingState {
|
|
|
49
48
|
* ```
|
|
50
49
|
*/
|
|
51
50
|
export declare class MessagingService {
|
|
52
|
-
private
|
|
51
|
+
private injector;
|
|
53
52
|
private config;
|
|
54
53
|
private platformId;
|
|
55
54
|
private ngZone;
|
|
@@ -57,7 +56,12 @@ export declare class MessagingService {
|
|
|
57
56
|
private notificationClickSubject;
|
|
58
57
|
private stateSubject;
|
|
59
58
|
private unsubscribeOnMessage?;
|
|
60
|
-
constructor(
|
|
59
|
+
constructor(injector: Injector, config: ValtechFirebaseConfig, platformId: Object, ngZone: NgZone);
|
|
60
|
+
/**
|
|
61
|
+
* Obtiene la instancia de Messaging de forma perezosa.
|
|
62
|
+
* Esto evita el error de APP_INITIALIZER de AngularFire.
|
|
63
|
+
*/
|
|
64
|
+
private getMessagingInstance;
|
|
61
65
|
/**
|
|
62
66
|
* Inicializa el servicio de messaging
|
|
63
67
|
*/
|
|
@@ -257,7 +261,7 @@ export declare class MessagingService {
|
|
|
257
261
|
* Parsea un query string en un objeto.
|
|
258
262
|
*/
|
|
259
263
|
private parseQueryString;
|
|
260
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<MessagingService,
|
|
264
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<MessagingService, never>;
|
|
261
265
|
static ɵprov: i0.ɵɵInjectableDeclaration<MessagingService>;
|
|
262
266
|
}
|
|
263
267
|
export {};
|