@iaportafolio/nextjs 0.1.1 → 0.3.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.md +86 -8
- package/dist/chunk-I3FDJF4L.js +369 -0
- package/dist/client.cjs +365 -93
- package/dist/client.d.cts +191 -0
- package/dist/client.d.ts +191 -0
- package/dist/client.js +25 -5
- package/dist/index.cjs +354 -94
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +25 -5
- package/dist/server.cjs +1 -0
- package/dist/server.d.cts +42 -0
- package/dist/server.d.ts +42 -0
- package/package.json +61 -62
- package/src/browser-core.ts +394 -0
- package/src/browser-react.tsx +53 -0
- package/src/client.ts +63 -131
- package/dist/chunk-TYH3TMKC.js +0 -120
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Core RUM para navegador (interno de @iaportafolio/nextjs).
|
|
5
|
+
*
|
|
6
|
+
* Captura errores no manejados, Web Vitals, navegaciones y clicks como
|
|
7
|
+
* breadcrumbs, y envía todo en lotes a la API de ingesta usando
|
|
8
|
+
* sendBeacon cuando el tab se cierra (sin perder eventos).
|
|
9
|
+
*
|
|
10
|
+
* Este archivo no se exporta directamente al usuario; el entrypoint
|
|
11
|
+
* público es `@iaportafolio/nextjs/client`.
|
|
12
|
+
*/
|
|
13
|
+
type Severity = 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
|
|
14
|
+
interface FaroBrowserOptions {
|
|
15
|
+
endpoint: string;
|
|
16
|
+
token: string;
|
|
17
|
+
service: string;
|
|
18
|
+
environment?: string;
|
|
19
|
+
release?: string;
|
|
20
|
+
/** Atributos por defecto adjuntados a cada evento */
|
|
21
|
+
attributes?: Record<string, string | number | boolean>;
|
|
22
|
+
/** Cadencia de flush en ms (default 2000) */
|
|
23
|
+
flushIntervalMs?: number;
|
|
24
|
+
/** Tamaño máximo de batch por POST (default 100) */
|
|
25
|
+
maxBatchSize?: number;
|
|
26
|
+
/** Cola en memoria máxima (default 2000) */
|
|
27
|
+
maxQueueSize?: number;
|
|
28
|
+
/** Tamaño del ring buffer de breadcrumbs (default 30) */
|
|
29
|
+
maxBreadcrumbs?: number;
|
|
30
|
+
/** Capturar window.onerror + unhandledrejection (default true) */
|
|
31
|
+
captureUnhandled?: boolean;
|
|
32
|
+
/** Capturar console.error y console.warn (default false — puede meter ruido) */
|
|
33
|
+
captureConsole?: boolean;
|
|
34
|
+
/** Capturar Web Vitals LCP/CLS/INP/FID/TTFB (default true) */
|
|
35
|
+
captureWebVitals?: boolean;
|
|
36
|
+
/** Capturar clicks como breadcrumbs (default true) */
|
|
37
|
+
captureClicks?: boolean;
|
|
38
|
+
/** Capturar navegaciones SPA (history.pushState/popstate) (default true) */
|
|
39
|
+
captureNavigation?: boolean;
|
|
40
|
+
/** Hook para muestrear o redactar eventos antes de enviar; devolver null descarta */
|
|
41
|
+
beforeSend?: (event: WireEvent) => WireEvent | null;
|
|
42
|
+
}
|
|
43
|
+
interface UserContext {
|
|
44
|
+
id?: string;
|
|
45
|
+
email?: string;
|
|
46
|
+
username?: string;
|
|
47
|
+
[key: string]: string | undefined;
|
|
48
|
+
}
|
|
49
|
+
interface Breadcrumb {
|
|
50
|
+
category: 'click' | 'navigation' | 'console' | 'fetch' | 'custom';
|
|
51
|
+
message: string;
|
|
52
|
+
timestamp: number;
|
|
53
|
+
data?: Record<string, string | number | boolean | undefined>;
|
|
54
|
+
}
|
|
55
|
+
interface LogEntry {
|
|
56
|
+
level?: Severity;
|
|
57
|
+
message: string;
|
|
58
|
+
attributes?: Record<string, unknown>;
|
|
59
|
+
trace_id?: string;
|
|
60
|
+
span_id?: string;
|
|
61
|
+
}
|
|
62
|
+
interface WireEvent {
|
|
63
|
+
level: Severity;
|
|
64
|
+
message: string;
|
|
65
|
+
timestamp: string;
|
|
66
|
+
attributes: Record<string, string>;
|
|
67
|
+
trace_id?: string;
|
|
68
|
+
span_id?: string;
|
|
69
|
+
}
|
|
70
|
+
declare class FaroBrowser {
|
|
71
|
+
private opts;
|
|
72
|
+
private queue;
|
|
73
|
+
private breadcrumbs;
|
|
74
|
+
private user;
|
|
75
|
+
private timer;
|
|
76
|
+
private cleanup;
|
|
77
|
+
private closed;
|
|
78
|
+
constructor(opts: FaroBrowserOptions);
|
|
79
|
+
setUser(user: UserContext | null): void;
|
|
80
|
+
addBreadcrumb(crumb: Omit<Breadcrumb, 'timestamp'>): void;
|
|
81
|
+
log(entry: LogEntry): void;
|
|
82
|
+
info(message: string, attrs?: Record<string, unknown>): void;
|
|
83
|
+
warn(message: string, attrs?: Record<string, unknown>): void;
|
|
84
|
+
error(message: string, attrs?: Record<string, unknown>): void;
|
|
85
|
+
captureException(err: unknown, ctx?: {
|
|
86
|
+
tags?: Record<string, string>;
|
|
87
|
+
message?: string;
|
|
88
|
+
}): void;
|
|
89
|
+
flush(useBeacon?: boolean): Promise<void>;
|
|
90
|
+
close(): void;
|
|
91
|
+
private enqueue;
|
|
92
|
+
private composeAttributes;
|
|
93
|
+
private installErrorHandlers;
|
|
94
|
+
private installConsoleCapture;
|
|
95
|
+
private installWebVitals;
|
|
96
|
+
private installClickTracking;
|
|
97
|
+
private installNavigationTracking;
|
|
98
|
+
private installLifecycleHooks;
|
|
99
|
+
}
|
|
100
|
+
declare function getClient(): FaroBrowser;
|
|
101
|
+
declare function log(entry: LogEntry): void;
|
|
102
|
+
declare function info(msg: string, attrs?: Record<string, unknown>): void;
|
|
103
|
+
declare function warn(msg: string, attrs?: Record<string, unknown>): void;
|
|
104
|
+
declare function error(msg: string, attrs?: Record<string, unknown>): void;
|
|
105
|
+
declare function captureException(err: unknown, ctx?: {
|
|
106
|
+
tags?: Record<string, string>;
|
|
107
|
+
message?: string;
|
|
108
|
+
}): void;
|
|
109
|
+
declare function setUser(user: UserContext | null): void;
|
|
110
|
+
declare function addBreadcrumb(crumb: Omit<Breadcrumb, 'timestamp'>): void;
|
|
111
|
+
declare function flush(): Promise<void>;
|
|
112
|
+
declare function close(): void;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* React ErrorBoundary que reporta automáticamente a Faro.
|
|
116
|
+
* Importar desde `@iaportafolio/nextjs/client`.
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
interface FaroErrorBoundaryProps {
|
|
120
|
+
children: React.ReactNode;
|
|
121
|
+
/** Fallback UI cuando un hijo lanza. Recibe el error y un `reset` para reintentar. */
|
|
122
|
+
fallback?: React.ReactNode | ((args: {
|
|
123
|
+
error: Error;
|
|
124
|
+
reset: () => void;
|
|
125
|
+
}) => React.ReactNode);
|
|
126
|
+
/** Tags adicionales para el evento (ej. nombre del módulo) */
|
|
127
|
+
tags?: Record<string, string>;
|
|
128
|
+
/** Hook opcional cuando se captura un error (para tracking adicional) */
|
|
129
|
+
onError?: (error: Error, info: React.ErrorInfo) => void;
|
|
130
|
+
}
|
|
131
|
+
interface State {
|
|
132
|
+
error: Error | null;
|
|
133
|
+
}
|
|
134
|
+
declare class FaroErrorBoundary extends React.Component<FaroErrorBoundaryProps, State> {
|
|
135
|
+
state: State;
|
|
136
|
+
static getDerivedStateFromError(error: Error): State;
|
|
137
|
+
componentDidCatch(error: Error, info: React.ErrorInfo): void;
|
|
138
|
+
reset: () => void;
|
|
139
|
+
render(): React.ReactNode;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Faro para Next.js — lado cliente (corre en el navegador).
|
|
144
|
+
*
|
|
145
|
+
* Punto de entrada público para el RUM en Next.js:
|
|
146
|
+
* - captura de window.error / unhandledrejection
|
|
147
|
+
* - Web Vitals (LCP/CLS/INP/FCP/TTFB)
|
|
148
|
+
* - breadcrumbs de clicks y navegaciones (history.pushState/popstate)
|
|
149
|
+
* - sendBeacon en pagehide / visibilitychange=hidden (no se pierden eventos)
|
|
150
|
+
* - ErrorBoundary React (`<FaroErrorBoundary>`)
|
|
151
|
+
* - auto-detección de release desde env vars típicas de Vercel/Next
|
|
152
|
+
*
|
|
153
|
+
* Uso típico (App Router):
|
|
154
|
+
*
|
|
155
|
+
* // app/faro-client.tsx
|
|
156
|
+
* 'use client';
|
|
157
|
+
* import { useEffect } from 'react';
|
|
158
|
+
* import { usePathname, useSearchParams } from 'next/navigation';
|
|
159
|
+
* import { initFaroClient, addBreadcrumb } from '@iaportafolio/nextjs/client';
|
|
160
|
+
*
|
|
161
|
+
* export function FaroClient() {
|
|
162
|
+
* const pathname = usePathname();
|
|
163
|
+
* const search = useSearchParams();
|
|
164
|
+
*
|
|
165
|
+
* useEffect(() => {
|
|
166
|
+
* initFaroClient({
|
|
167
|
+
* endpoint: process.env.NEXT_PUBLIC_FARO_ENDPOINT!,
|
|
168
|
+
* token: process.env.NEXT_PUBLIC_FARO_TOKEN!,
|
|
169
|
+
* service: 'mi-next-app-web',
|
|
170
|
+
* });
|
|
171
|
+
* }, []);
|
|
172
|
+
*
|
|
173
|
+
* useEffect(() => {
|
|
174
|
+
* addBreadcrumb({ category: 'navigation', message: pathname, data: { pathname } });
|
|
175
|
+
* }, [pathname, search]);
|
|
176
|
+
*
|
|
177
|
+
* return null;
|
|
178
|
+
* }
|
|
179
|
+
*
|
|
180
|
+
* // app/layout.tsx
|
|
181
|
+
* import { FaroClient } from './faro-client';
|
|
182
|
+
* <body><FaroClient />{children}</body>
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Inicializa el RUM en el navegador. Seguro de llamar en SSR — si `typeof window === 'undefined'`
|
|
187
|
+
* el core no hace nada. Llámalo desde `useEffect` en un componente 'use client'.
|
|
188
|
+
*/
|
|
189
|
+
declare function initFaroClient(opts: FaroBrowserOptions): FaroBrowser;
|
|
190
|
+
|
|
191
|
+
export { type Breadcrumb, FaroBrowser, type FaroBrowserOptions, FaroErrorBoundary, type FaroErrorBoundaryProps, type LogEntry, type Severity, type UserContext, type WireEvent, addBreadcrumb, captureException, close, error, flush, getClient, info, initFaroClient, log, setUser, warn };
|
package/dist/client.js
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
FaroErrorBoundary,
|
|
3
|
+
addBreadcrumb,
|
|
4
|
+
captureException,
|
|
5
|
+
close,
|
|
6
|
+
error,
|
|
7
|
+
flush,
|
|
8
|
+
getClient,
|
|
9
|
+
info,
|
|
10
|
+
initFaroClient,
|
|
11
|
+
log,
|
|
12
|
+
setUser,
|
|
13
|
+
warn
|
|
14
|
+
} from "./chunk-I3FDJF4L.js";
|
|
5
15
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
16
|
+
FaroErrorBoundary,
|
|
17
|
+
addBreadcrumb,
|
|
18
|
+
captureException,
|
|
19
|
+
close,
|
|
20
|
+
error,
|
|
21
|
+
flush,
|
|
22
|
+
getClient,
|
|
23
|
+
info,
|
|
24
|
+
initFaroClient,
|
|
25
|
+
log,
|
|
26
|
+
setUser,
|
|
27
|
+
warn
|
|
8
28
|
};
|