@angular-helpers/browser-web-apis 21.0.1 → 21.1.0
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/README.es.md +156 -0
- package/README.md +19 -26
- package/fesm2022/angular-helpers-browser-web-apis.mjs +1504 -0
- package/package.json +1 -6
- package/types/angular-helpers-browser-web-apis.d.ts +537 -0
package/README.es.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# @angular-helpers/browser-web-apis
|
|
2
|
+
|
|
3
|
+
Paquete de servicios Angular para acceder de forma estructurada y segura a Browser Web APIs.
|
|
4
|
+
|
|
5
|
+
🌐 **Documentación y Demo**: https://gaspar1992.github.io/angular-helpers/
|
|
6
|
+
|
|
7
|
+
[Read in English](./README.md)
|
|
8
|
+
|
|
9
|
+
## Caracteristicas
|
|
10
|
+
|
|
11
|
+
- Seguridad integrada con prevencion de ReDoS usando Web Workers
|
|
12
|
+
- Acceso unificado a APIs del navegador mediante servicios tipados
|
|
13
|
+
- Arquitectura tree-shakable
|
|
14
|
+
- Configuracion modular para habilitar solo lo necesario
|
|
15
|
+
- APIs reactivas con signals y observables
|
|
16
|
+
- Integracion segura con el ciclo de vida usando `destroyRef`
|
|
17
|
+
|
|
18
|
+
## Servicios disponibles
|
|
19
|
+
|
|
20
|
+
### APIs de medios y dispositivo
|
|
21
|
+
|
|
22
|
+
- `CameraService` - Acceso a camara con gestion de permisos
|
|
23
|
+
- `MediaDevicesService` - Enumeracion y gestion de dispositivos multimedia
|
|
24
|
+
- `GeolocationService` - Acceso a la API de geolocalizacion
|
|
25
|
+
- `NotificationService` - API de notificaciones del navegador
|
|
26
|
+
|
|
27
|
+
### Web APIs
|
|
28
|
+
|
|
29
|
+
- `WebWorkerService` - Gestion de Web Workers
|
|
30
|
+
- `WebSocketService` - Gestion de conexiones WebSocket
|
|
31
|
+
- `WebStorageService` - Helpers para LocalStorage y SessionStorage
|
|
32
|
+
- `WebShareService` - Soporte para Web Share API nativa
|
|
33
|
+
- `ClipboardService` - Acceso al portapapeles del sistema
|
|
34
|
+
|
|
35
|
+
### Seguridad y capacidades
|
|
36
|
+
|
|
37
|
+
- `PermissionsService` - Gestion centralizada de permisos del navegador
|
|
38
|
+
- `BrowserCapabilityService` - Deteccion de soporte de APIs del navegador
|
|
39
|
+
|
|
40
|
+
### Utilidades
|
|
41
|
+
|
|
42
|
+
- `BrowserApiBaseService` - Clase base compartida para servicios de Browser APIs
|
|
43
|
+
|
|
44
|
+
## Instalacion
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install @angular-helpers/browser-web-apis
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Configuracion rapida
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { provideBrowserWebApis } from '@angular-helpers/browser-web-apis';
|
|
54
|
+
|
|
55
|
+
bootstrapApplication(AppComponent, {
|
|
56
|
+
providers: [
|
|
57
|
+
provideBrowserWebApis({
|
|
58
|
+
enableCamera: true,
|
|
59
|
+
enableGeolocation: true,
|
|
60
|
+
enableNotifications: true,
|
|
61
|
+
}),
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Uso por servicio
|
|
67
|
+
|
|
68
|
+
### CameraService
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { CameraService } from '@angular-helpers/browser-web-apis';
|
|
72
|
+
|
|
73
|
+
export class PhotoComponent {
|
|
74
|
+
private cameraService = inject(CameraService);
|
|
75
|
+
|
|
76
|
+
async takePhoto() {
|
|
77
|
+
try {
|
|
78
|
+
const stream = await this.cameraService.startCamera({
|
|
79
|
+
video: true,
|
|
80
|
+
audio: false,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Usa el stream para captura de foto o video
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error('Error accessing camera:', error);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async stopCamera() {
|
|
90
|
+
await this.cameraService.stopCamera();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### BrowserCapabilityService
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { BrowserCapabilityService } from '@angular-helpers/browser-web-apis';
|
|
99
|
+
|
|
100
|
+
export class MyComponent {
|
|
101
|
+
private capability = inject(BrowserCapabilityService);
|
|
102
|
+
|
|
103
|
+
ngOnInit() {
|
|
104
|
+
if (this.capability.isSupported('geolocation')) {
|
|
105
|
+
console.log('La geolocalizacion esta disponible');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
> Para prevención de ReDoS, usa el paquete `@angular-helpers/security`.
|
|
112
|
+
|
|
113
|
+
### GeolocationService
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { GeolocationService } from '@angular-helpers/browser-web-apis';
|
|
117
|
+
|
|
118
|
+
export class LocationComponent {
|
|
119
|
+
private geolocation = inject(GeolocationService);
|
|
120
|
+
|
|
121
|
+
async getCurrentLocation() {
|
|
122
|
+
try {
|
|
123
|
+
const position = await this.geolocation.getCurrentPosition({
|
|
124
|
+
enableHighAccuracy: true,
|
|
125
|
+
timeout: 10000,
|
|
126
|
+
maximumAge: 60000,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
console.log('Position:', position.coords);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
console.error('Error getting location:', error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Soporte de navegadores
|
|
138
|
+
|
|
139
|
+
Los servicios validan automaticamente el soporte del navegador y el manejo de rutas no soportadas:
|
|
140
|
+
|
|
141
|
+
- Chrome: soporte completo
|
|
142
|
+
- Firefox: soporte completo
|
|
143
|
+
- Safari: soporte parcial
|
|
144
|
+
- Edge: soporte completo
|
|
145
|
+
- Navegadores moviles: depende de plataforma y API
|
|
146
|
+
|
|
147
|
+
## Notas
|
|
148
|
+
|
|
149
|
+
- Varias APIs requieren contexto seguro (HTTPS)
|
|
150
|
+
- Algunas APIs requieren interaccion explicita del usuario
|
|
151
|
+
- El comportamiento de permisos varia segun el navegador
|
|
152
|
+
- Implementa siempre manejo de errores y fallback
|
|
153
|
+
|
|
154
|
+
## Licencia
|
|
155
|
+
|
|
156
|
+
MIT
|
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Angular services package for a structured and secure access layer over browser Web APIs.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
🌐 **Documentation & Demo**: https://gaspar1992.github.io/angular-helpers/
|
|
6
|
+
|
|
7
|
+
[Leer en español](./README.es.md)
|
|
6
8
|
|
|
7
9
|
## Features
|
|
8
10
|
|
|
@@ -16,26 +18,28 @@ Angular services package for a structured and secure access layer over browser W
|
|
|
16
18
|
## Available Services
|
|
17
19
|
|
|
18
20
|
### Media and Device APIs
|
|
21
|
+
|
|
19
22
|
- `CameraService` - Camera access with permission handling
|
|
20
23
|
- `MediaDevicesService` - Media device listing and management
|
|
21
24
|
- `GeolocationService` - Geolocation API access
|
|
22
25
|
- `NotificationService` - Browser notifications API
|
|
23
26
|
|
|
24
27
|
### Web APIs
|
|
28
|
+
|
|
25
29
|
- `WebWorkerService` - Web Worker management
|
|
26
30
|
- `WebSocketService` - WebSocket connection handling
|
|
27
31
|
- `WebStorageService` - LocalStorage and SessionStorage helpers
|
|
28
32
|
- `WebShareService` - Native Web Share API support
|
|
29
33
|
- `ClipboardService` - System clipboard access
|
|
30
34
|
|
|
31
|
-
### Security
|
|
32
|
-
|
|
35
|
+
### Security & Capabilities
|
|
36
|
+
|
|
33
37
|
- `PermissionsService` - Centralized browser permissions handling
|
|
38
|
+
- `BrowserCapabilityService` - Feature-detection for browser API availability
|
|
34
39
|
|
|
35
40
|
### Utilities
|
|
36
|
-
|
|
41
|
+
|
|
37
42
|
- `BrowserApiBaseService` - Shared base class for browser API services
|
|
38
|
-
- `MediaDeviceBaseService` - Shared base class for media device services
|
|
39
43
|
|
|
40
44
|
## Installation
|
|
41
45
|
|
|
@@ -53,7 +57,7 @@ bootstrapApplication(AppComponent, {
|
|
|
53
57
|
provideBrowserWebApis({
|
|
54
58
|
enableCamera: true,
|
|
55
59
|
enableGeolocation: true,
|
|
56
|
-
|
|
60
|
+
enableNotifications: true,
|
|
57
61
|
}),
|
|
58
62
|
],
|
|
59
63
|
});
|
|
@@ -67,7 +71,7 @@ bootstrapApplication(AppComponent, {
|
|
|
67
71
|
import { CameraService } from '@angular-helpers/browser-web-apis';
|
|
68
72
|
|
|
69
73
|
export class PhotoComponent {
|
|
70
|
-
|
|
74
|
+
private cameraService = inject(CameraService);
|
|
71
75
|
|
|
72
76
|
async takePhoto() {
|
|
73
77
|
try {
|
|
@@ -88,28 +92,17 @@ export class PhotoComponent {
|
|
|
88
92
|
}
|
|
89
93
|
```
|
|
90
94
|
|
|
91
|
-
###
|
|
95
|
+
### BrowserCapabilityService
|
|
92
96
|
|
|
93
97
|
```typescript
|
|
94
|
-
import {
|
|
98
|
+
import { BrowserCapabilityService } from '@angular-helpers/browser-web-apis';
|
|
95
99
|
|
|
96
|
-
export class
|
|
97
|
-
|
|
100
|
+
export class MyComponent {
|
|
101
|
+
private capability = inject(BrowserCapabilityService);
|
|
98
102
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
const result = await this.regexSecurity.testRegex(pattern, text, {
|
|
105
|
-
timeout: 5000,
|
|
106
|
-
safeMode: true,
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
console.log('Match:', result.match);
|
|
110
|
-
console.log('Execution time:', result.executionTime);
|
|
111
|
-
} catch (error) {
|
|
112
|
-
console.error('Regex test failed:', error);
|
|
103
|
+
ngOnInit() {
|
|
104
|
+
if (this.capability.isSupported('geolocation')) {
|
|
105
|
+
console.log('Geolocation is available');
|
|
113
106
|
}
|
|
114
107
|
}
|
|
115
108
|
}
|
|
@@ -121,7 +114,7 @@ export class SecurityComponent {
|
|
|
121
114
|
import { GeolocationService } from '@angular-helpers/browser-web-apis';
|
|
122
115
|
|
|
123
116
|
export class LocationComponent {
|
|
124
|
-
|
|
117
|
+
private geolocation = inject(GeolocationService);
|
|
125
118
|
|
|
126
119
|
async getCurrentLocation() {
|
|
127
120
|
try {
|