valtech-components 4.0.154 → 4.0.156

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.
@@ -43,7 +43,7 @@ export declare class RightsFooterComponent {
43
43
  /**
44
44
  * Computed helper for color prop in template.
45
45
  */
46
- propsColor: import("@angular/core").Signal<"success" | "medium" | "primary" | "secondary" | "tertiary" | "warning" | "danger" | "light" | "dark">;
46
+ propsColor: import("@angular/core").Signal<"medium" | "primary" | "secondary" | "tertiary" | "success" | "warning" | "danger" | "light" | "dark">;
47
47
  /**
48
48
  * Computed helper for withMargin prop in template.
49
49
  */
@@ -93,9 +93,9 @@ export declare class ArticleComponent implements OnInit {
93
93
  contentInterpolation?: Record<string, string | number>;
94
94
  icon?: import("valtech-components").IconMetada;
95
95
  shape?: "round";
96
- size?: "default" | "small" | "large";
96
+ size?: "small" | "large" | "default";
97
97
  fill?: "default" | "clear" | "outline" | "solid";
98
- type: "reset" | "submit" | "button";
98
+ type: "button" | "submit" | "reset";
99
99
  token?: string;
100
100
  ref?: any;
101
101
  handler?: (value: any) => any;
@@ -48,7 +48,7 @@ export declare class LoginComponent implements OnInit, OnDestroy {
48
48
  private _mfaVerifyFormState;
49
49
  private _mfaMethod;
50
50
  /** Método MFA pendiente — expuesto al template para gatear el link de backup (solo TOTP). */
51
- readonly mfaMethod: import("@angular/core").Signal<"EMAIL" | "SMS" | "TOTP">;
51
+ readonly mfaMethod: import("@angular/core").Signal<"TOTP" | "EMAIL" | "SMS">;
52
52
  /** A: el user togglea a "código de respaldo" (8 chars alfanuméricos) cuando perdió el 2º factor. */
53
53
  readonly mfaUseBackupCode: import("@angular/core").WritableSignal<boolean>;
54
54
  isMFAResetModalOpen: boolean;
@@ -65,6 +65,42 @@ export declare const guestGuard: CanActivateFn;
65
65
  * ```
66
66
  */
67
67
  export declare function permissionGuard(permissions: string | string[]): CanActivateFn;
68
+ /**
69
+ * Factory de guard RBAC parametrizable — defense-in-depth a nivel de RUTA.
70
+ *
71
+ * Variante ergonómica de {@link permissionGuard} con firma variádica
72
+ * (`rbacGuard('a:read', 'b:manage')` en vez de `permissionGuard(['a:read', 'b:manage'])`),
73
+ * pensada para gatear vistas administrativas montadas vía los `provideValtech*Routes`
74
+ * de la lib. Pasa si el usuario tiene **AL MENOS UNO** de los permisos (OR), igual que
75
+ * el resto del gating del factory (`*valHasPermission`, menú). El match de wildcards
76
+ * (`*:*`, `resource:*`, `*:action`) lo resuelve `AuthService.hasPermission`.
77
+ *
78
+ * Es una capa ADICIONAL al gating fino dentro de los componentes (botones por
79
+ * `*valHasPermission`) y al 403 del backend — no los reemplaza. Sin permiso redirige
80
+ * a `unauthorizedRoute` (mismo destino que `permissionGuard`).
81
+ *
82
+ * @param permissions - Uno o más permisos requeridos (OR)
83
+ * @returns Guard function
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * import { rbacGuard } from 'valtech-components';
88
+ *
89
+ * const routes: Routes = [
90
+ * {
91
+ * path: 'api-keys',
92
+ * canActivate: [rbacGuard('api-keys:read')],
93
+ * component: ApiKeysViewComponent,
94
+ * },
95
+ * {
96
+ * path: 'permissions',
97
+ * canActivate: [rbacGuard('roles:read', 'rbac:manage')],
98
+ * component: PermissionsViewComponent,
99
+ * },
100
+ * ];
101
+ * ```
102
+ */
103
+ export declare function rbacGuard(...permissions: string[]): CanActivateFn;
68
104
  /**
69
105
  * Guard que lee permisos desde route.data.
70
106
  * Permite configurar permisos directamente en la definición de rutas.
@@ -71,7 +71,7 @@
71
71
  export * from './types';
72
72
  export { VALTECH_AUTH_CONFIG, provideValtechAuth, provideValtechAuthInterceptor, DEFAULT_AUTH_CONFIG, } from './config';
73
73
  export { AuthService } from './auth.service';
74
- export { authGuard, guestGuard, permissionGuard, permissionGuardFromRoute, superAdminGuard, roleGuard, } from './guards';
74
+ export { authGuard, guestGuard, permissionGuard, permissionGuardFromRoute, rbacGuard, superAdminGuard, roleGuard, } from './guards';
75
75
  export { authInterceptor } from './interceptor';
76
76
  export { AuthStateService } from './auth-state.service';
77
77
  export { TokenService } from './token.service';
package/lib/version.d.ts CHANGED
@@ -2,4 +2,4 @@
2
2
  * Current version of valtech-components.
3
3
  * This is automatically updated during the publish process.
4
4
  */
5
- export declare const VERSION = "4.0.154";
5
+ export declare const VERSION = "4.0.156";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valtech-components",
3
- "version": "4.0.154",
3
+ "version": "4.0.156",
4
4
  "private": false,
5
5
  "bin": {
6
6
  "valtech-firebase-config": "./src/lib/services/firebase/scripts/generate-sw-config.js"
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Firebase Messaging Service Worker
3
+ *
4
+ * Service Worker estático para Firebase Cloud Messaging.
5
+ * Carga la configuración dinámicamente desde /firebase-config.js.
6
+ *
7
+ * CONFIGURACIÓN:
8
+ * 1. Crea firebase.config.json con tu configuración de Firebase
9
+ * 2. Ejecuta: npm run generate:firebase-config
10
+ * Esto genera /firebase-config.js con: self.FIREBASE_CONFIG = {...}
11
+ * 3. Agrega este SW y firebase-config.js a los assets de angular.json
12
+ *
13
+ * Ver README.md para documentación completa.
14
+ */
15
+
16
+ // Importar Firebase scripts
17
+ importScripts('https://www.gstatic.com/firebasejs/10.7.0/firebase-app-compat.js');
18
+ importScripts('https://www.gstatic.com/firebasejs/10.7.0/firebase-messaging-compat.js');
19
+
20
+ // Importar configuración desde archivo externo (generado en build)
21
+ // Este archivo define: self.FIREBASE_CONFIG = { ... }
22
+ try {
23
+ importScripts('/firebase-config.js');
24
+ } catch (e) {
25
+ console.error('[SW] No se pudo cargar firebase-config.js:', e);
26
+ }
27
+
28
+ // Verificar que la configuración existe
29
+ if (!self.FIREBASE_CONFIG) {
30
+ console.error('[SW] FIREBASE_CONFIG no está definido.');
31
+ console.error('[SW] Ejecuta: npm run generate:firebase-config');
32
+ } else {
33
+ // Inicializar Firebase
34
+ firebase.initializeApp(self.FIREBASE_CONFIG);
35
+
36
+ // Obtener instancia de messaging
37
+ const messaging = firebase.messaging();
38
+
39
+ /**
40
+ * Handler para mensajes en background.
41
+ */
42
+ messaging.onBackgroundMessage((payload) => {
43
+ console.log('[SW] Mensaje recibido en background:', payload);
44
+
45
+ // Web push usa mensajes data-only (sin bloque `notification`) para que el
46
+ // navegador NO auto-muestre una notificación duplicada — el SW es el único
47
+ // que la pinta. Title/body/icon llegan dentro de `data`. Se mantiene el
48
+ // fallback a `payload.notification` por compatibilidad con mensajes
49
+ // legacy o nativos que sí traen el bloque.
50
+ const data = payload.data || {};
51
+ const notificationTitle =
52
+ payload.notification?.title || data.title || 'Nueva notificación';
53
+ const notificationBody = payload.notification?.body || data.body || '';
54
+ const notificationIcon =
55
+ payload.notification?.icon || data.icon || '/assets/icon/favicon.ico';
56
+
57
+ const notificationOptions = {
58
+ body: notificationBody,
59
+ icon: notificationIcon,
60
+ image: payload.notification?.image,
61
+ badge: '/assets/icon/badge.png',
62
+ tag: payload.messageId || data.messageId || 'default',
63
+ data: {
64
+ ...data,
65
+ messageId: payload.messageId || data.messageId,
66
+ title: notificationTitle,
67
+ body: notificationBody,
68
+ },
69
+ vibrate: [200, 100, 200],
70
+ requireInteraction: data.require_interaction === 'true',
71
+ };
72
+
73
+ return self.registration.showNotification(notificationTitle, notificationOptions);
74
+ });
75
+
76
+ /**
77
+ * Handler para clicks en notificaciones.
78
+ */
79
+ self.addEventListener('notificationclick', (event) => {
80
+ console.log('[SW] Click en notificación:', event);
81
+ event.notification.close();
82
+
83
+ const data = event.notification.data || {};
84
+ let targetUrl = '/';
85
+
86
+ if (data.route) {
87
+ targetUrl = data.route;
88
+ } else if (data.url) {
89
+ targetUrl = data.url;
90
+ }
91
+
92
+ if (data.query_params) {
93
+ const separator = targetUrl.includes('?') ? '&' : '?';
94
+ targetUrl += separator + data.query_params;
95
+ }
96
+
97
+ const notificationPayload = {
98
+ type: 'NOTIFICATION_CLICK',
99
+ notification: {
100
+ title: data.title,
101
+ body: data.body,
102
+ data: data,
103
+ messageId: data.messageId,
104
+ },
105
+ };
106
+
107
+ event.waitUntil(
108
+ clients
109
+ .matchAll({ type: 'window', includeUncontrolled: true })
110
+ .then((clientList) => {
111
+ // Siempre enviar postMessage para que la app pueda reaccionar
112
+ for (const client of clientList) {
113
+ client.postMessage(notificationPayload);
114
+ }
115
+
116
+ // Navegar si hay route o url
117
+ if (targetUrl !== '/') {
118
+ for (const client of clientList) {
119
+ if ('navigate' in client) {
120
+ return client.navigate(targetUrl).then((c) => c?.focus());
121
+ }
122
+ }
123
+ // Si no hay cliente abierto, abrir nueva ventana
124
+ if (clients.openWindow) {
125
+ return clients.openWindow(targetUrl);
126
+ }
127
+ }
128
+
129
+ // Solo hacer focus si no hay navegación
130
+ for (const client of clientList) {
131
+ if ('focus' in client) {
132
+ return client.focus();
133
+ }
134
+ }
135
+ if (clients.openWindow) {
136
+ return clients.openWindow('/');
137
+ }
138
+ })
139
+ );
140
+ });
141
+
142
+ self.addEventListener('notificationclose', (event) => {
143
+ console.log('[SW] Notificación cerrada:', event.notification.tag);
144
+ });
145
+ }