valtech-components 2.0.839 → 2.0.840

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.
@@ -49,7 +49,6 @@ export declare class ChangePasswordModalComponent {
49
49
  /** Modo actual — `loading` mientras se consulta `checkHasPassword()`. */
50
50
  readonly mode: import("@angular/core").Signal<PasswordModalMode>;
51
51
  private readonly _formState;
52
- constructor();
53
52
  /** Traduce una clave del namespace `_auth`. */
54
53
  t(key: string): string;
55
54
  readonly formProps: import("@angular/core").Signal<FormMetadata>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Error interpretation helpers.
3
+ *
4
+ * `interpretError` normaliza cualquier error (HttpErrorResponse crudo,
5
+ * AuthError aplanado, Error de JS, o un valor arbitrario) a un
6
+ * `InterpretedError` con forma estable. Función pura, sin Angular DI.
7
+ */
8
+ export { interpretError } from './interpret-error';
9
+ export type { InterpretedError } from './interpret-error';
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Error interpretation helper for the Valtech factory.
3
+ *
4
+ * Todos los frontends del factory consumen la misma API (backend Go) y la misma
5
+ * librería. La lógica de interpretar errores debe vivir una sola vez, acá.
6
+ *
7
+ * El backend Go (`apperrors`) SIEMPRE devuelve errores como JSON:
8
+ * { "code": string, "message": string, "operationId": string }
9
+ * donde `message` ya viene en español y es user-friendly.
10
+ *
11
+ * En Angular un error HTTP llega como `HttpErrorResponse` (body en `.error`).
12
+ * Un fallo de red es un `HttpErrorResponse` con `status === 0`.
13
+ *
14
+ * Además `AuthService.handleAuthError` aplana el `HttpErrorResponse` a un
15
+ * `AuthError { code, message }` (code/message al nivel superior). Por eso este
16
+ * helper acepta AMBAS formas — el crudo y el aplanado.
17
+ */
18
+ /**
19
+ * Resultado normalizado de cualquier error. Garantiza una forma estable y
20
+ * predecible para que las webapps no tengan que hacer narrowing manual.
21
+ */
22
+ export interface InterpretedError {
23
+ /** Código del backend, o el sentinel `'NETWORK'` / `'UNKNOWN'`. */
24
+ code: string;
25
+ /** Mensaje del backend (español, user-friendly) o un genérico en español. */
26
+ message: string;
27
+ /** `operationId` del backend, si vino. Útil para soporte / tracing. */
28
+ operationId?: string;
29
+ /** HTTP status, si aplica (`0` para fallos de red). */
30
+ status?: number;
31
+ /** `true` si fue un fallo de red (status 0 / sin respuesta). */
32
+ isNetwork: boolean;
33
+ }
34
+ /**
35
+ * Normaliza CUALQUIER error a un `InterpretedError`.
36
+ *
37
+ * Función pura — sin dependencias de Angular DI, testeable y usable desde
38
+ * cualquier lado (componentes, servicios, interceptores, scripts).
39
+ *
40
+ * Nunca lanza: siempre devuelve un `InterpretedError` válido.
41
+ *
42
+ * Casos cubiertos:
43
+ * - `HttpErrorResponse` con `status === 0` (o sin respuesta) → fallo de red.
44
+ * - `HttpErrorResponse` con body `{ code, message, operationId }` del backend.
45
+ * - `AuthError` aplanado `{ code, message }` (code/message top-level).
46
+ * - `Error` plano de JS → `code: 'UNKNOWN'`, `message: err.message`.
47
+ * - Cualquier otra cosa (string, null, undefined, objeto raro) → genérico.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * try {
52
+ * await firstValueFrom(this.http.get(url));
53
+ * } catch (err) {
54
+ * const e = interpretError(err);
55
+ * if (e.isNetwork) {
56
+ * this.toast.show({ message: e.message, color: 'dark' });
57
+ * } else {
58
+ * this.errorCode.set(e.code);
59
+ * }
60
+ * }
61
+ * ```
62
+ */
63
+ export declare function interpretError(err: unknown): InterpretedError;
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 = "2.0.839";
5
+ export declare const VERSION = "2.0.840";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valtech-components",
3
- "version": "2.0.839",
3
+ "version": "2.0.840",
4
4
  "private": false,
5
5
  "bin": {
6
6
  "valtech-firebase-config": "./src/lib/services/firebase/scripts/generate-sw-config.js"
package/public-api.d.ts CHANGED
@@ -255,6 +255,7 @@ export * from './lib/services/navigation';
255
255
  export * from './lib/services/theme.service';
256
256
  export * from './lib/services/toast.service';
257
257
  export * from './lib/services/types';
258
+ export * from './lib/services/errors';
258
259
  export * from './lib/services/confirmation-dialog/confirmation-dialog.service';
259
260
  export * from './lib/services/confirmation-dialog/types';
260
261
  export * from './lib/services/qr-generator/qr-generator.service';