valtech-components 2.0.451 → 2.0.453
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/components/organisms/tabbed-content/tabbed-content.component.mjs +170 -0
- package/esm2022/lib/components/organisms/tabbed-content/types.mjs +2 -0
- package/esm2022/lib/components/templates/page-content/page-content.component.mjs +11 -11
- package/esm2022/lib/components/templates/page-template/page-template.component.mjs +3 -5
- package/esm2022/lib/services/auth/auth-state.service.mjs +173 -0
- package/esm2022/lib/services/auth/auth.service.mjs +454 -0
- package/esm2022/lib/services/auth/config.mjs +76 -0
- package/esm2022/lib/services/auth/guards.mjs +194 -0
- package/esm2022/lib/services/auth/index.mjs +70 -0
- package/esm2022/lib/services/auth/interceptor.mjs +98 -0
- package/esm2022/lib/services/auth/storage.service.mjs +141 -0
- package/esm2022/lib/services/auth/sync.service.mjs +149 -0
- package/esm2022/lib/services/auth/token.service.mjs +113 -0
- package/esm2022/lib/services/auth/types.mjs +29 -0
- package/esm2022/lib/services/firebase/config.mjs +108 -0
- package/esm2022/lib/services/firebase/firebase.service.mjs +288 -0
- package/esm2022/lib/services/firebase/firestore-collection.mjs +254 -0
- package/esm2022/lib/services/firebase/firestore.service.mjs +509 -0
- package/esm2022/lib/services/firebase/index.mjs +49 -0
- package/esm2022/lib/services/firebase/messaging.service.mjs +512 -0
- package/esm2022/lib/services/firebase/shared-config.mjs +138 -0
- package/esm2022/lib/services/firebase/storage.service.mjs +422 -0
- package/esm2022/lib/services/firebase/types.mjs +8 -0
- package/esm2022/lib/services/firebase/utils/path-builder.mjs +195 -0
- package/esm2022/lib/services/firebase/utils/query-builder.mjs +302 -0
- package/esm2022/lib/services/link-processor.service.mjs +61 -43
- package/esm2022/lib/services/modal/modal.service.mjs +8 -9
- package/esm2022/lib/services/navigation.service.mjs +11 -11
- package/esm2022/public-api.mjs +23 -4
- package/fesm2022/valtech-components.mjs +4599 -102
- package/fesm2022/valtech-components.mjs.map +1 -1
- package/lib/components/organisms/tabbed-content/tabbed-content.component.d.ts +65 -0
- package/lib/components/organisms/tabbed-content/types.d.ts +53 -0
- package/lib/components/templates/page-content/page-content.component.d.ts +3 -0
- package/lib/services/auth/auth-state.service.d.ts +85 -0
- package/lib/services/auth/auth.service.d.ts +146 -0
- package/lib/services/auth/config.d.ts +38 -0
- package/lib/services/auth/guards.d.ts +123 -0
- package/lib/services/auth/index.d.ts +63 -0
- package/lib/services/auth/interceptor.d.ts +22 -0
- package/lib/services/auth/storage.service.d.ts +48 -0
- package/lib/services/auth/sync.service.d.ts +49 -0
- package/lib/services/auth/token.service.d.ts +51 -0
- package/lib/services/auth/types.d.ts +315 -0
- package/lib/services/firebase/config.d.ts +49 -0
- package/lib/services/firebase/firebase.service.d.ts +140 -0
- package/lib/services/firebase/firestore-collection.d.ts +175 -0
- package/lib/services/firebase/firestore.service.d.ts +304 -0
- package/lib/services/firebase/index.d.ts +39 -0
- package/lib/services/firebase/messaging.service.d.ts +263 -0
- package/lib/services/firebase/shared-config.d.ts +126 -0
- package/lib/services/firebase/storage.service.d.ts +206 -0
- package/lib/services/firebase/types.d.ts +281 -0
- package/lib/services/firebase/utils/path-builder.d.ts +132 -0
- package/lib/services/firebase/utils/query-builder.d.ts +210 -0
- package/lib/services/modal/modal.service.d.ts +2 -0
- package/lib/services/navigation.service.d.ts +4 -4
- package/package.json +3 -1
- package/public-api.d.ts +9 -0
- package/fesm2022/valtech-components-simple-modal-content.component-DQhEgUmS.mjs +0 -136
- package/fesm2022/valtech-components-simple-modal-content.component-DQhEgUmS.mjs.map +0 -1
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Messaging Service (FCM)
|
|
3
|
+
*
|
|
4
|
+
* Servicio para Firebase Cloud Messaging (Push Notifications).
|
|
5
|
+
* Permite solicitar permisos, obtener tokens, escuchar mensajes y manejar
|
|
6
|
+
* navegación (deep linking) cuando el usuario toca una notificación.
|
|
7
|
+
*/
|
|
8
|
+
import { NgZone } from '@angular/core';
|
|
9
|
+
import { Messaging } from '@angular/fire/messaging';
|
|
10
|
+
import { Observable } from 'rxjs';
|
|
11
|
+
import { NotificationAction, NotificationClickEvent, NotificationPayload, NotificationPermission, ValtechFirebaseConfig } from './types';
|
|
12
|
+
import * as i0 from "@angular/core";
|
|
13
|
+
/**
|
|
14
|
+
* Estado interno del servicio de messaging
|
|
15
|
+
*/
|
|
16
|
+
interface MessagingState {
|
|
17
|
+
token: string | null;
|
|
18
|
+
permission: NotificationPermission;
|
|
19
|
+
isSupported: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Servicio para Firebase Cloud Messaging (FCM).
|
|
23
|
+
*
|
|
24
|
+
* Permite recibir notificaciones push en la aplicación web.
|
|
25
|
+
* Requiere VAPID key configurada en ValtechFirebaseConfig.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* @Component({...})
|
|
30
|
+
* export class NotificationComponent {
|
|
31
|
+
* private messaging = inject(MessagingService);
|
|
32
|
+
*
|
|
33
|
+
* token = signal<string | null>(null);
|
|
34
|
+
*
|
|
35
|
+
* async enableNotifications() {
|
|
36
|
+
* // Solicitar permiso y obtener token
|
|
37
|
+
* const token = await this.messaging.requestPermission();
|
|
38
|
+
*
|
|
39
|
+
* if (token) {
|
|
40
|
+
* this.token.set(token);
|
|
41
|
+
* // Enviar token a tu backend para almacenarlo
|
|
42
|
+
* await this.backend.registerDeviceToken(token);
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* // Escuchar mensajes en foreground
|
|
47
|
+
* messages$ = this.messaging.onMessage();
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare class MessagingService {
|
|
52
|
+
private messaging;
|
|
53
|
+
private config;
|
|
54
|
+
private platformId;
|
|
55
|
+
private ngZone;
|
|
56
|
+
private messageSubject;
|
|
57
|
+
private notificationClickSubject;
|
|
58
|
+
private stateSubject;
|
|
59
|
+
private unsubscribeOnMessage?;
|
|
60
|
+
constructor(messaging: Messaging | null, config: ValtechFirebaseConfig, platformId: Object, ngZone: NgZone);
|
|
61
|
+
/**
|
|
62
|
+
* Inicializa el servicio de messaging
|
|
63
|
+
*/
|
|
64
|
+
private initializeMessaging;
|
|
65
|
+
/**
|
|
66
|
+
* Configura listener para mensajes del Service Worker.
|
|
67
|
+
* Recibe eventos cuando el usuario hace click en una notificación background.
|
|
68
|
+
*/
|
|
69
|
+
private setupServiceWorkerListener;
|
|
70
|
+
/**
|
|
71
|
+
* Verifica si FCM está soportado en el navegador actual
|
|
72
|
+
*/
|
|
73
|
+
private checkSupport;
|
|
74
|
+
/**
|
|
75
|
+
* Solicita permiso de notificaciones y obtiene el token FCM.
|
|
76
|
+
*
|
|
77
|
+
* @returns Token FCM si se otorgó permiso, null si se denegó
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const token = await messaging.requestPermission();
|
|
82
|
+
* if (token) {
|
|
83
|
+
* console.log('Token FCM:', token);
|
|
84
|
+
* // Enviar a backend
|
|
85
|
+
* } else {
|
|
86
|
+
* console.log('Permiso denegado o no soportado');
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
requestPermission(): Promise<string | null>;
|
|
91
|
+
/**
|
|
92
|
+
* Obtiene el token FCM actual (sin solicitar permiso).
|
|
93
|
+
*
|
|
94
|
+
* @returns Token FCM si está disponible, null si no
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const token = await messaging.getToken();
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
getToken(): Promise<string | null>;
|
|
102
|
+
/**
|
|
103
|
+
* Elimina el token FCM actual (unsubscribe de notificaciones).
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* await messaging.deleteToken();
|
|
108
|
+
* console.log('Token eliminado, no recibirá más notificaciones');
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
deleteToken(): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Observable de mensajes recibidos en foreground.
|
|
114
|
+
*
|
|
115
|
+
* IMPORTANTE: Los mensajes en background son manejados por el Service Worker.
|
|
116
|
+
*
|
|
117
|
+
* @returns Observable que emite cuando llega un mensaje en foreground
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* messaging.onMessage().subscribe(payload => {
|
|
122
|
+
* console.log('Mensaje recibido:', payload);
|
|
123
|
+
* // Mostrar notificación custom o actualizar UI
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
onMessage(): Observable<NotificationPayload>;
|
|
128
|
+
/**
|
|
129
|
+
* Configura el listener de mensajes en foreground
|
|
130
|
+
*/
|
|
131
|
+
private setupMessageListener;
|
|
132
|
+
/**
|
|
133
|
+
* Obtiene el estado actual del permiso de notificaciones.
|
|
134
|
+
*
|
|
135
|
+
* @returns 'granted' | 'denied' | 'default'
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const permission = messaging.getPermissionState();
|
|
140
|
+
* if (permission === 'granted') {
|
|
141
|
+
* // Ya tiene permiso
|
|
142
|
+
* } else if (permission === 'default') {
|
|
143
|
+
* // Puede solicitar permiso
|
|
144
|
+
* } else {
|
|
145
|
+
* // Denegado, debe habilitar manualmente
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
getPermissionState(): NotificationPermission;
|
|
150
|
+
/**
|
|
151
|
+
* Verifica si FCM está soportado en el navegador actual.
|
|
152
|
+
*
|
|
153
|
+
* @returns true si FCM está soportado
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* if (await messaging.isSupported()) {
|
|
158
|
+
* // Puede usar notificaciones push
|
|
159
|
+
* } else {
|
|
160
|
+
* // Navegador no soporta o no tiene Service Worker
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
isSupported(): Promise<boolean>;
|
|
165
|
+
/**
|
|
166
|
+
* Obtiene el token actual sin hacer request.
|
|
167
|
+
*
|
|
168
|
+
* @returns Token almacenado o null
|
|
169
|
+
*/
|
|
170
|
+
get currentToken(): string | null;
|
|
171
|
+
/**
|
|
172
|
+
* Observable del estado completo del servicio de messaging.
|
|
173
|
+
*/
|
|
174
|
+
get state$(): Observable<MessagingState>;
|
|
175
|
+
/**
|
|
176
|
+
* Verifica si el usuario ya otorgó permiso de notificaciones.
|
|
177
|
+
*/
|
|
178
|
+
get hasPermission(): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Observable de clicks en notificaciones.
|
|
181
|
+
*
|
|
182
|
+
* Emite cuando el usuario hace click en una notificación (foreground o background).
|
|
183
|
+
* Usa este observable para navegar a la página correspondiente.
|
|
184
|
+
*
|
|
185
|
+
* @returns Observable que emite NotificationClickEvent
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* @Component({...})
|
|
190
|
+
* export class AppComponent {
|
|
191
|
+
* private messaging = inject(MessagingService);
|
|
192
|
+
* private router = inject(Router);
|
|
193
|
+
*
|
|
194
|
+
* constructor() {
|
|
195
|
+
* this.messaging.onNotificationClick().subscribe(event => {
|
|
196
|
+
* if (event.action.route) {
|
|
197
|
+
* this.router.navigate([event.action.route], {
|
|
198
|
+
* queryParams: event.action.queryParams
|
|
199
|
+
* });
|
|
200
|
+
* }
|
|
201
|
+
* });
|
|
202
|
+
* }
|
|
203
|
+
* }
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
onNotificationClick(): Observable<NotificationClickEvent>;
|
|
207
|
+
/**
|
|
208
|
+
* Extrae la acción de navegación de los datos de una notificación.
|
|
209
|
+
*
|
|
210
|
+
* Busca campos específicos en el payload de datos:
|
|
211
|
+
* - `route`: Ruta interna de la app (ej: '/orders/123')
|
|
212
|
+
* - `url`: URL externa (ej: 'https://example.com')
|
|
213
|
+
* - `action_type`: Tipo de acción personalizada
|
|
214
|
+
* - Campos con prefijo `action_`: Datos adicionales
|
|
215
|
+
*
|
|
216
|
+
* @param data - Datos del payload de la notificación
|
|
217
|
+
* @returns Acción de navegación extraída
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* // Payload desde el backend:
|
|
222
|
+
* // { route: '/orders/123', action_type: 'view_order', action_orderId: '123' }
|
|
223
|
+
*
|
|
224
|
+
* const action = messaging.extractActionFromData(notification.data);
|
|
225
|
+
* // { route: '/orders/123', actionType: 'view_order', actionData: { orderId: '123' } }
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
extractActionFromData(data?: Record<string, string>): NotificationAction;
|
|
229
|
+
/**
|
|
230
|
+
* Emite manualmente un evento de click en notificación.
|
|
231
|
+
*
|
|
232
|
+
* Útil para manejar clicks en notificaciones foreground donde
|
|
233
|
+
* la app decide mostrar un banner custom.
|
|
234
|
+
*
|
|
235
|
+
* @param notification - Payload de la notificación
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* messaging.onMessage().subscribe(notification => {
|
|
240
|
+
* // Mostrar banner custom
|
|
241
|
+
* this.showBanner(notification, () => {
|
|
242
|
+
* // Usuario hizo click en el banner
|
|
243
|
+
* messaging.handleNotificationClick(notification);
|
|
244
|
+
* });
|
|
245
|
+
* });
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
handleNotificationClick(notification: NotificationPayload): void;
|
|
249
|
+
/**
|
|
250
|
+
* Verifica si una notificación tiene acción de navegación.
|
|
251
|
+
*
|
|
252
|
+
* @param data - Datos del payload
|
|
253
|
+
* @returns true si tiene route o url
|
|
254
|
+
*/
|
|
255
|
+
hasNavigationAction(data?: Record<string, string>): boolean;
|
|
256
|
+
/**
|
|
257
|
+
* Parsea un query string en un objeto.
|
|
258
|
+
*/
|
|
259
|
+
private parseQueryString;
|
|
260
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<MessagingService, [{ optional: true; }, null, null, null]>;
|
|
261
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<MessagingService>;
|
|
262
|
+
}
|
|
263
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Shared Configuration
|
|
3
|
+
*
|
|
4
|
+
* Configuración base de Firebase compartida entre todas las apps del monorepo.
|
|
5
|
+
* Los secrets (apiKey, appId) se inyectan en build time via environment.
|
|
6
|
+
*/
|
|
7
|
+
import { EmulatorConfig, FirebaseConfig, ValtechFirebaseConfig } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Identificadores de las apps del monorepo.
|
|
10
|
+
* Usados para namespacing de colecciones Firestore y paths de Storage.
|
|
11
|
+
*/
|
|
12
|
+
export type AppId = 'demo' | 'showcase' | 'admin-portal' | 'app';
|
|
13
|
+
export declare const APP_IDS: {
|
|
14
|
+
readonly DEMO: AppId;
|
|
15
|
+
readonly SHOWCASE: AppId;
|
|
16
|
+
readonly ADMIN_PORTAL: AppId;
|
|
17
|
+
readonly APP: AppId;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* IDs de los proyectos Firebase por ambiente.
|
|
21
|
+
* Deben coincidir con los proyectos creados en Firebase Console.
|
|
22
|
+
*/
|
|
23
|
+
export declare const FIREBASE_PROJECTS: {
|
|
24
|
+
readonly development: "myvaltech-dev";
|
|
25
|
+
readonly production: "myvaltech-prod";
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Configuración de emuladores compartida.
|
|
29
|
+
* Todos los puertos deben coincidir con frontend/firebase/firebase.json
|
|
30
|
+
*/
|
|
31
|
+
export declare const SHARED_EMULATOR_CONFIG: EmulatorConfig;
|
|
32
|
+
/**
|
|
33
|
+
* Genera paths de Storage con namespace por app.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // Path específico de la app
|
|
37
|
+
* storagePaths.forApp('showcase', 'uploads', 'image.jpg')
|
|
38
|
+
* // => 'showcase/uploads/image.jpg'
|
|
39
|
+
*
|
|
40
|
+
* // Path compartido
|
|
41
|
+
* storagePaths.shared.profilePhoto('user123', 'avatar.jpg')
|
|
42
|
+
* // => 'profile-photos/user123/avatar.jpg'
|
|
43
|
+
*/
|
|
44
|
+
export declare const storagePaths: {
|
|
45
|
+
/** Carpeta específica de la app: {appId}/{...paths} */
|
|
46
|
+
forApp: (appId: AppId, ...paths: string[]) => string;
|
|
47
|
+
/** Carpetas compartidas (sin namespace) */
|
|
48
|
+
shared: {
|
|
49
|
+
/** Foto de perfil de usuario */
|
|
50
|
+
profilePhoto: (userId: string, fileName: string) => string;
|
|
51
|
+
/** Archivos públicos accesibles sin autenticación */
|
|
52
|
+
public: (...paths: string[]) => string;
|
|
53
|
+
};
|
|
54
|
+
/** Carpetas de desarrollo (acceso libre en emuladores) */
|
|
55
|
+
demo: (...paths: string[]) => string;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Genera paths de colecciones con namespace por app.
|
|
59
|
+
*
|
|
60
|
+
* IMPORTANTE: La estructura es /apps/{appId}/{collection}/{docId}
|
|
61
|
+
* Firestore requiere número impar de segmentos para paths de colección.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // Colección específica de la app
|
|
65
|
+
* collections.forApp('showcase', 'items')
|
|
66
|
+
* // => 'apps/showcase/items'
|
|
67
|
+
*
|
|
68
|
+
* // Colección de desarrollo
|
|
69
|
+
* collections.forApp('demo', 'items')
|
|
70
|
+
* // => 'apps/demo/items'
|
|
71
|
+
*
|
|
72
|
+
* // Colección compartida
|
|
73
|
+
* collections.shared.users
|
|
74
|
+
* // => 'users'
|
|
75
|
+
*/
|
|
76
|
+
export declare const collections: {
|
|
77
|
+
/** Colección específica de la app: apps/{appId}/{collection} */
|
|
78
|
+
forApp: (appId: AppId, collectionName: string) => string;
|
|
79
|
+
/** Colecciones compartidas (sin namespace, nivel raíz) */
|
|
80
|
+
shared: {
|
|
81
|
+
/** Usuarios del sistema */
|
|
82
|
+
users: string;
|
|
83
|
+
/** Perfiles públicos */
|
|
84
|
+
profiles: string;
|
|
85
|
+
/** Notificaciones de usuarios */
|
|
86
|
+
notifications: string;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Opciones para crear la configuración de Firebase
|
|
91
|
+
*/
|
|
92
|
+
export interface CreateFirebaseConfigOptions {
|
|
93
|
+
/** Usar emuladores locales (para desarrollo) */
|
|
94
|
+
useEmulators?: boolean;
|
|
95
|
+
/** Habilitar persistencia offline de Firestore */
|
|
96
|
+
persistence?: boolean;
|
|
97
|
+
/** Habilitar Firebase Cloud Messaging */
|
|
98
|
+
enableMessaging?: boolean;
|
|
99
|
+
/** VAPID key para FCM (requerido si enableMessaging es true) */
|
|
100
|
+
messagingVapidKey?: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Crea la configuración completa de Firebase desde variables de entorno.
|
|
104
|
+
* Usa esto en el environment.ts de cada app.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* // environment.ts
|
|
108
|
+
* export const environment = {
|
|
109
|
+
* firebase: createFirebaseConfig(
|
|
110
|
+
* {
|
|
111
|
+
* apiKey: 'AIza...',
|
|
112
|
+
* authDomain: 'myvaltech-dev.firebaseapp.com',
|
|
113
|
+
* projectId: 'myvaltech-dev',
|
|
114
|
+
* storageBucket: 'myvaltech-dev.appspot.com',
|
|
115
|
+
* messagingSenderId: '123456789',
|
|
116
|
+
* appId: '1:123456789:web:abc123',
|
|
117
|
+
* },
|
|
118
|
+
* { useEmulators: true, persistence: true }
|
|
119
|
+
* ),
|
|
120
|
+
* };
|
|
121
|
+
*/
|
|
122
|
+
export declare function createFirebaseConfig(envConfig: FirebaseConfig, options?: CreateFirebaseConfigOptions): ValtechFirebaseConfig;
|
|
123
|
+
/**
|
|
124
|
+
* Verifica si la configuración tiene emuladores habilitados
|
|
125
|
+
*/
|
|
126
|
+
export declare function isEmulatorMode(config: ValtechFirebaseConfig): boolean;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { Storage } from '@angular/fire/storage';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { StorageListResult, StorageMetadata, UploadProgress, UploadResult } from './types';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
/**
|
|
6
|
+
* Servicio para Firebase Storage.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* @Component({...})
|
|
11
|
+
* export class FileUploadComponent {
|
|
12
|
+
* private storage = inject(StorageService);
|
|
13
|
+
*
|
|
14
|
+
* uploadProgress = signal<number>(0);
|
|
15
|
+
* downloadUrl = signal<string | null>(null);
|
|
16
|
+
*
|
|
17
|
+
* async onFileSelected(event: Event) {
|
|
18
|
+
* const file = (event.target as HTMLInputElement).files?.[0];
|
|
19
|
+
* if (!file) return;
|
|
20
|
+
*
|
|
21
|
+
* // Upload con progreso
|
|
22
|
+
* this.storage.upload(`uploads/${file.name}`, file).subscribe({
|
|
23
|
+
* next: (progress) => this.uploadProgress.set(progress.percentage),
|
|
24
|
+
* complete: async () => {
|
|
25
|
+
* const url = await this.storage.getDownloadUrl(`uploads/${file.name}`);
|
|
26
|
+
* this.downloadUrl.set(url);
|
|
27
|
+
* }
|
|
28
|
+
* });
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare class StorageService {
|
|
34
|
+
private storage;
|
|
35
|
+
constructor(storage: Storage);
|
|
36
|
+
/**
|
|
37
|
+
* Sube un archivo con tracking de progreso.
|
|
38
|
+
*
|
|
39
|
+
* @param path - Ruta en Storage donde guardar el archivo
|
|
40
|
+
* @param file - Archivo a subir (File o Blob)
|
|
41
|
+
* @param metadata - Metadata opcional (contentType, customMetadata)
|
|
42
|
+
* @returns Observable que emite el progreso y completa cuando termina
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // Upload básico
|
|
47
|
+
* storage.upload('images/photo.jpg', file).subscribe({
|
|
48
|
+
* next: (progress) => console.log(`${progress.percentage}%`),
|
|
49
|
+
* complete: () => console.log('Upload completado')
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* // Con metadata
|
|
53
|
+
* storage.upload('docs/report.pdf', file, {
|
|
54
|
+
* contentType: 'application/pdf',
|
|
55
|
+
* customMetadata: { uploadedBy: 'user123' }
|
|
56
|
+
* }).subscribe(...);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
upload(path: string, file: File | Blob, metadata?: StorageMetadata): Observable<UploadProgress>;
|
|
60
|
+
/**
|
|
61
|
+
* Sube un archivo y retorna la URL de descarga al completar.
|
|
62
|
+
*
|
|
63
|
+
* @param path - Ruta en Storage
|
|
64
|
+
* @param file - Archivo a subir
|
|
65
|
+
* @param metadata - Metadata opcional
|
|
66
|
+
* @returns Resultado del upload con URL de descarga
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const result = await storage.uploadAndGetUrl('avatars/user123.jpg', file);
|
|
71
|
+
* console.log('URL:', result.downloadUrl);
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
uploadAndGetUrl(path: string, file: File | Blob, metadata?: StorageMetadata): Promise<UploadResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Sube un archivo desde una Data URL (base64).
|
|
77
|
+
*
|
|
78
|
+
* @param path - Ruta en Storage
|
|
79
|
+
* @param dataUrl - Data URL (ej: 'data:image/png;base64,...')
|
|
80
|
+
* @param metadata - Metadata opcional
|
|
81
|
+
* @returns Resultado del upload
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* // Desde canvas
|
|
86
|
+
* const dataUrl = canvas.toDataURL('image/png');
|
|
87
|
+
* const result = await storage.uploadFromDataUrl('images/drawing.png', dataUrl);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
uploadFromDataUrl(path: string, dataUrl: string, metadata?: StorageMetadata): Promise<UploadResult>;
|
|
91
|
+
/**
|
|
92
|
+
* Obtiene la URL de descarga de un archivo.
|
|
93
|
+
*
|
|
94
|
+
* @param path - Ruta del archivo en Storage
|
|
95
|
+
* @returns URL de descarga
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const url = await storage.getDownloadUrl('images/photo.jpg');
|
|
100
|
+
* // Usar en <img [src]="url">
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
getDownloadUrl(path: string): Promise<string>;
|
|
104
|
+
/**
|
|
105
|
+
* Obtiene la metadata de un archivo.
|
|
106
|
+
*
|
|
107
|
+
* @param path - Ruta del archivo
|
|
108
|
+
* @returns Metadata del archivo
|
|
109
|
+
*/
|
|
110
|
+
getMetadata(path: string): Promise<StorageMetadata & {
|
|
111
|
+
size: number;
|
|
112
|
+
name: string;
|
|
113
|
+
}>;
|
|
114
|
+
/**
|
|
115
|
+
* Elimina un archivo.
|
|
116
|
+
*
|
|
117
|
+
* @param path - Ruta del archivo a eliminar
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* await storage.delete('images/old-photo.jpg');
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
delete(path: string): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Elimina múltiples archivos.
|
|
127
|
+
*
|
|
128
|
+
* @param paths - Array de rutas a eliminar
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* await storage.deleteMultiple([
|
|
133
|
+
* 'images/photo1.jpg',
|
|
134
|
+
* 'images/photo2.jpg'
|
|
135
|
+
* ]);
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
deleteMultiple(paths: string[]): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Lista archivos en un directorio.
|
|
141
|
+
*
|
|
142
|
+
* @param path - Ruta del directorio
|
|
143
|
+
* @returns Lista de rutas de archivos
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const result = await storage.list('images/');
|
|
148
|
+
* console.log(result.items); // ['images/photo1.jpg', 'images/photo2.jpg']
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
list(path: string): Promise<StorageListResult>;
|
|
152
|
+
/**
|
|
153
|
+
* Genera un nombre de archivo único con timestamp.
|
|
154
|
+
*
|
|
155
|
+
* @param originalName - Nombre original del archivo
|
|
156
|
+
* @param prefix - Prefijo opcional
|
|
157
|
+
* @returns Nombre único
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const uniqueName = storage.generateFileName('photo.jpg', 'user123');
|
|
162
|
+
* // => 'user123_1703091234567_photo.jpg'
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
generateFileName(originalName: string, prefix?: string): string;
|
|
166
|
+
/**
|
|
167
|
+
* Genera una ruta única para un archivo.
|
|
168
|
+
*
|
|
169
|
+
* @param directory - Directorio base
|
|
170
|
+
* @param originalName - Nombre original
|
|
171
|
+
* @param prefix - Prefijo opcional
|
|
172
|
+
* @returns Ruta completa única
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const path = storage.generatePath('uploads', 'photo.jpg', 'user123');
|
|
177
|
+
* // => 'uploads/user123_1703091234567_photo.jpg'
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
generatePath(directory: string, originalName: string, prefix?: string): string;
|
|
181
|
+
/**
|
|
182
|
+
* Obtiene la extensión de un archivo.
|
|
183
|
+
*
|
|
184
|
+
* @param filename - Nombre del archivo
|
|
185
|
+
* @returns Extensión (sin el punto)
|
|
186
|
+
*/
|
|
187
|
+
getExtension(filename: string): string;
|
|
188
|
+
/**
|
|
189
|
+
* Verifica si un archivo es una imagen basándose en su extensión.
|
|
190
|
+
*/
|
|
191
|
+
isImage(filename: string): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Verifica si un archivo es un documento.
|
|
194
|
+
*/
|
|
195
|
+
isDocument(filename: string): boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Mapea el estado de la tarea de upload
|
|
198
|
+
*/
|
|
199
|
+
private mapTaskState;
|
|
200
|
+
/**
|
|
201
|
+
* Convierte errores de Storage a mensajes en español
|
|
202
|
+
*/
|
|
203
|
+
private getErrorMessage;
|
|
204
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<StorageService, never>;
|
|
205
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<StorageService>;
|
|
206
|
+
}
|