@iaportafolio/nextjs 0.2.2 → 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/dist/client.d.ts CHANGED
@@ -1,15 +1,154 @@
1
- import { FaroBrowserOptions, FaroBrowser } from '@iaportafolio/browser';
2
- export { Breadcrumb, FaroBrowserOptions, LogEntry, Severity, UserContext, WireEvent, addBreadcrumb, captureException, close, error, flush, getClient, info, log, setUser, warn } from '@iaportafolio/browser';
3
- export { FaroErrorBoundary, FaroErrorBoundaryProps } from '@iaportafolio/browser/react';
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
+ }
4
141
 
5
142
  /**
6
143
  * Faro para Next.js — lado cliente (corre en el navegador).
7
144
  *
8
- * Es un wrapper fino sobre @iaportafolio/browser. El core (captura de
9
- * window.error, Web Vitals, breadcrumbs, batching, sendBeacon en pagehide,
10
- * ErrorBoundary React) vive en el paquete browser. Aquí sólo añadimos:
11
- * - auto-detección de la release desde env vars típicas de Vercel/Next
12
- * - re-exports para que sea ergonómico (`import {...} from '@iaportafolio/nextjs/client'`)
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
13
152
  *
14
153
  * Uso típico (App Router):
15
154
  *
@@ -31,8 +170,6 @@ export { FaroErrorBoundary, FaroErrorBoundaryProps } from '@iaportafolio/browser
31
170
  * });
32
171
  * }, []);
33
172
  *
34
- * // (opcional) breadcrumb explícito en cada route change con el pathname limpio.
35
- * // El SDK ya captura pushState, esto sólo es más legible en el dashboard.
36
173
  * useEffect(() => {
37
174
  * addBreadcrumb({ category: 'navigation', message: pathname, data: { pathname } });
38
175
  * }, [pathname, search]);
@@ -43,17 +180,12 @@ export { FaroErrorBoundary, FaroErrorBoundaryProps } from '@iaportafolio/browser
43
180
  * // app/layout.tsx
44
181
  * import { FaroClient } from './faro-client';
45
182
  * <body><FaroClient />{children}</body>
46
- *
47
- * Y opcionalmente envuelve secciones críticas con ErrorBoundary:
48
- *
49
- * import { FaroErrorBoundary } from '@iaportafolio/nextjs/client';
50
- * <FaroErrorBoundary fallback={...}><Checkout /></FaroErrorBoundary>
51
183
  */
52
184
 
53
185
  /**
54
- * Inicializa el SDK browser. Seguro de llamar en SSR — si `typeof window === 'undefined'`
55
- * el SDK subyacente no hace nada. Llámalo desde `useEffect` en un componente 'use client'.
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'.
56
188
  */
57
189
  declare function initFaroClient(opts: FaroBrowserOptions): FaroBrowser;
58
190
 
59
- export { initFaroClient };
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
@@ -11,7 +11,7 @@ import {
11
11
  log,
12
12
  setUser,
13
13
  warn
14
- } from "./chunk-YWAGEOOH.js";
14
+ } from "./chunk-I3FDJF4L.js";
15
15
  export {
16
16
  FaroErrorBoundary,
17
17
  addBreadcrumb,
package/dist/index.cjs CHANGED
@@ -30,21 +30,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- FaroErrorBoundary: () => import_react.FaroErrorBoundary,
34
- addBreadcrumb: () => import_browser2.addBreadcrumb,
35
- captureException: () => import_browser2.captureException,
33
+ FaroErrorBoundary: () => FaroErrorBoundary,
34
+ addBreadcrumb: () => addBreadcrumb,
35
+ captureException: () => captureException2,
36
36
  captureRequestError: () => captureRequestError,
37
- close: () => import_browser2.close,
38
- error: () => import_browser2.error,
37
+ close: () => close,
38
+ error: () => error,
39
39
  faro: () => faro,
40
- flush: () => import_browser2.flush,
41
- getClient: () => import_browser2.getClient,
42
- info: () => import_browser2.info,
40
+ flush: () => flush,
41
+ getClient: () => getClient,
42
+ info: () => info,
43
43
  initFaroClient: () => initFaroClient,
44
- log: () => import_browser2.log,
44
+ log: () => log,
45
45
  registerFaro: () => registerFaro,
46
- setUser: () => import_browser2.setUser,
47
- warn: () => import_browser2.warn
46
+ setUser: () => setUser,
47
+ warn: () => warn
48
48
  });
49
49
  module.exports = __toCommonJS(index_exports);
50
50
 
@@ -70,16 +70,359 @@ function captureRequestError(err, request) {
70
70
  });
71
71
  }
72
72
 
73
+ // src/browser-core.ts
74
+ var FaroBrowser = class {
75
+ constructor(opts) {
76
+ this.queue = [];
77
+ this.breadcrumbs = [];
78
+ this.user = null;
79
+ this.timer = null;
80
+ this.cleanup = [];
81
+ this.closed = false;
82
+ this.opts = {
83
+ endpoint: opts.endpoint.replace(/\/$/, ""),
84
+ token: opts.token,
85
+ service: opts.service,
86
+ environment: opts.environment,
87
+ release: opts.release,
88
+ attributes: opts.attributes,
89
+ flushIntervalMs: opts.flushIntervalMs ?? 2e3,
90
+ maxBatchSize: opts.maxBatchSize ?? 100,
91
+ maxQueueSize: opts.maxQueueSize ?? 2e3,
92
+ maxBreadcrumbs: opts.maxBreadcrumbs ?? 30,
93
+ captureUnhandled: opts.captureUnhandled ?? true,
94
+ captureConsole: opts.captureConsole ?? false,
95
+ captureWebVitals: opts.captureWebVitals ?? true,
96
+ captureClicks: opts.captureClicks ?? true,
97
+ captureNavigation: opts.captureNavigation ?? true,
98
+ beforeSend: opts.beforeSend
99
+ };
100
+ if (typeof window === "undefined") {
101
+ return;
102
+ }
103
+ this.timer = setInterval(() => void this.flush(), this.opts.flushIntervalMs);
104
+ if (this.opts.captureUnhandled) this.installErrorHandlers();
105
+ if (this.opts.captureConsole) this.installConsoleCapture();
106
+ if (this.opts.captureWebVitals) this.installWebVitals();
107
+ if (this.opts.captureClicks) this.installClickTracking();
108
+ if (this.opts.captureNavigation) this.installNavigationTracking();
109
+ this.installLifecycleHooks();
110
+ }
111
+ setUser(user) {
112
+ this.user = user;
113
+ }
114
+ addBreadcrumb(crumb) {
115
+ if (this.breadcrumbs.length >= this.opts.maxBreadcrumbs) {
116
+ this.breadcrumbs.shift();
117
+ }
118
+ this.breadcrumbs.push({ ...crumb, timestamp: Date.now() });
119
+ }
120
+ log(entry) {
121
+ if (this.closed) return;
122
+ const attrs = this.composeAttributes(entry.attributes);
123
+ const evt = {
124
+ level: entry.level ?? "INFO",
125
+ message: entry.message,
126
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
127
+ attributes: attrs,
128
+ trace_id: entry.trace_id,
129
+ span_id: entry.span_id
130
+ };
131
+ this.enqueue(evt);
132
+ }
133
+ info(message, attrs) {
134
+ this.log({ level: "INFO", message, attributes: attrs });
135
+ }
136
+ warn(message, attrs) {
137
+ this.log({ level: "WARN", message, attributes: attrs });
138
+ }
139
+ error(message, attrs) {
140
+ this.log({ level: "ERROR", message, attributes: attrs });
141
+ }
142
+ captureException(err, ctx) {
143
+ const e = toError(err);
144
+ this.log({
145
+ level: "ERROR",
146
+ message: ctx?.message ?? `${e.name}: ${e.message}`,
147
+ attributes: {
148
+ "exception.type": e.name,
149
+ "exception.message": e.message,
150
+ "exception.stacktrace": e.stack ?? "",
151
+ ...ctx?.tags ?? {}
152
+ }
153
+ });
154
+ }
155
+ async flush(useBeacon = false) {
156
+ if (this.queue.length === 0) return;
157
+ const batch = this.queue.splice(0, this.opts.maxBatchSize);
158
+ const body = JSON.stringify({ service: this.opts.service, logs: batch });
159
+ const url = `${this.opts.endpoint}/api/v1/ingest/logs`;
160
+ if (useBeacon && typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
161
+ const beaconUrl = `${url}?_token=${encodeURIComponent(this.opts.token)}`;
162
+ const ok = navigator.sendBeacon(beaconUrl, new Blob([body], { type: "application/json" }));
163
+ if (ok) return;
164
+ }
165
+ try {
166
+ const res = await fetch(url, {
167
+ method: "POST",
168
+ keepalive: true,
169
+ headers: {
170
+ "Authorization": `Bearer ${this.opts.token}`,
171
+ "Content-Type": "application/json"
172
+ },
173
+ body
174
+ });
175
+ if (!res.ok && res.status >= 500) {
176
+ this.queue.unshift(...batch);
177
+ }
178
+ } catch {
179
+ this.queue.unshift(...batch);
180
+ }
181
+ }
182
+ close() {
183
+ if (this.closed) return;
184
+ this.closed = true;
185
+ if (this.timer) clearInterval(this.timer);
186
+ this.timer = null;
187
+ for (const fn of this.cleanup) fn();
188
+ this.cleanup = [];
189
+ void this.flush(true);
190
+ }
191
+ enqueue(evt) {
192
+ const processed = this.opts.beforeSend ? this.opts.beforeSend(evt) : evt;
193
+ if (!processed) return;
194
+ if (this.queue.length >= this.opts.maxQueueSize) return;
195
+ this.queue.push(processed);
196
+ }
197
+ composeAttributes(extra) {
198
+ const attrs = {};
199
+ if (this.opts.attributes) {
200
+ for (const [k, v] of Object.entries(this.opts.attributes)) attrs[k] = String(v);
201
+ }
202
+ if (this.opts.environment) attrs["deployment.environment"] = this.opts.environment;
203
+ if (this.opts.release) attrs["service.version"] = this.opts.release;
204
+ if (typeof window !== "undefined") {
205
+ attrs["browser.url"] = window.location.href;
206
+ attrs["browser.userAgent"] = navigator.userAgent;
207
+ }
208
+ if (this.user) {
209
+ if (this.user.id) attrs["user.id"] = this.user.id;
210
+ if (this.user.email) attrs["user.email"] = this.user.email;
211
+ if (this.user.username) attrs["user.name"] = this.user.username;
212
+ }
213
+ if (this.breadcrumbs.length > 0) {
214
+ attrs["breadcrumbs"] = JSON.stringify(this.breadcrumbs.slice(-this.opts.maxBreadcrumbs));
215
+ }
216
+ if (extra) {
217
+ for (const [k, v] of Object.entries(extra)) {
218
+ attrs[k] = typeof v === "string" ? v : JSON.stringify(v);
219
+ }
220
+ }
221
+ return attrs;
222
+ }
223
+ installErrorHandlers() {
224
+ const onError = (ev) => {
225
+ this.captureException(ev.error ?? ev.message, {
226
+ tags: { origin: "window.error", "source.file": ev.filename ?? "", "source.line": String(ev.lineno ?? 0) }
227
+ });
228
+ };
229
+ const onRejection = (ev) => {
230
+ this.captureException(ev.reason, { tags: { origin: "unhandledrejection" } });
231
+ };
232
+ window.addEventListener("error", onError);
233
+ window.addEventListener("unhandledrejection", onRejection);
234
+ this.cleanup.push(() => window.removeEventListener("error", onError));
235
+ this.cleanup.push(() => window.removeEventListener("unhandledrejection", onRejection));
236
+ }
237
+ installConsoleCapture() {
238
+ const orig = { error: console.error, warn: console.warn };
239
+ console.error = (...args) => {
240
+ this.addBreadcrumb({ category: "console", message: String(args[0] ?? ""), data: { level: "error" } });
241
+ this.log({ level: "ERROR", message: stringifyArgs(args), attributes: { "console.method": "error" } });
242
+ orig.error.apply(console, args);
243
+ };
244
+ console.warn = (...args) => {
245
+ this.addBreadcrumb({ category: "console", message: String(args[0] ?? ""), data: { level: "warn" } });
246
+ orig.warn.apply(console, args);
247
+ };
248
+ this.cleanup.push(() => {
249
+ console.error = orig.error;
250
+ console.warn = orig.warn;
251
+ });
252
+ }
253
+ installWebVitals() {
254
+ void import("web-vitals").then(({ onLCP, onCLS, onINP, onFCP, onTTFB }) => {
255
+ const report = (name) => (m) => {
256
+ this.log({
257
+ level: "INFO",
258
+ message: `web-vital ${name}`,
259
+ attributes: {
260
+ "metric.name": name,
261
+ "metric.value": m.value,
262
+ "metric.rating": m.rating,
263
+ "metric.id": m.id
264
+ }
265
+ });
266
+ };
267
+ onLCP(report("LCP"));
268
+ onCLS(report("CLS"));
269
+ onINP(report("INP"));
270
+ onFCP(report("FCP"));
271
+ onTTFB(report("TTFB"));
272
+ }).catch(() => {
273
+ });
274
+ }
275
+ installClickTracking() {
276
+ const onClick = (ev) => {
277
+ const target = ev.target;
278
+ if (!target) return;
279
+ const tag = target.tagName?.toLowerCase() ?? "";
280
+ const id = target.id;
281
+ const text = (target.textContent ?? "").trim().slice(0, 60);
282
+ const data = { tag };
283
+ if (id) data.id = id;
284
+ if (text) data.text = text;
285
+ this.addBreadcrumb({ category: "click", message: `${tag}${id ? "#" + id : ""}`, data });
286
+ };
287
+ window.addEventListener("click", onClick, { capture: true, passive: true });
288
+ this.cleanup.push(() => window.removeEventListener("click", onClick, { capture: true }));
289
+ }
290
+ installNavigationTracking() {
291
+ const log2 = (from, to, method) => {
292
+ if (from === to) return;
293
+ this.addBreadcrumb({ category: "navigation", message: `${from} \u2192 ${to}`, data: { method, to } });
294
+ };
295
+ const origPush = history.pushState;
296
+ const origReplace = history.replaceState;
297
+ history.pushState = function(...args) {
298
+ const from = location.href;
299
+ const ret = origPush.apply(this, args);
300
+ log2(from, location.href, "pushState");
301
+ return ret;
302
+ };
303
+ history.replaceState = function(...args) {
304
+ const from = location.href;
305
+ const ret = origReplace.apply(this, args);
306
+ log2(from, location.href, "replaceState");
307
+ return ret;
308
+ };
309
+ const onPop = () => log2("", location.href, "popstate");
310
+ window.addEventListener("popstate", onPop);
311
+ this.cleanup.push(() => {
312
+ history.pushState = origPush;
313
+ history.replaceState = origReplace;
314
+ window.removeEventListener("popstate", onPop);
315
+ });
316
+ }
317
+ installLifecycleHooks() {
318
+ const onHide = () => {
319
+ if (document.visibilityState === "hidden") void this.flush(true);
320
+ };
321
+ const onPageHide = () => void this.flush(true);
322
+ document.addEventListener("visibilitychange", onHide);
323
+ window.addEventListener("pagehide", onPageHide);
324
+ this.cleanup.push(() => document.removeEventListener("visibilitychange", onHide));
325
+ this.cleanup.push(() => window.removeEventListener("pagehide", onPageHide));
326
+ }
327
+ };
328
+ function toError(err) {
329
+ if (err instanceof Error) return err;
330
+ if (typeof err === "string") return new Error(err);
331
+ try {
332
+ return new Error(JSON.stringify(err));
333
+ } catch {
334
+ return new Error(String(err));
335
+ }
336
+ }
337
+ function stringifyArgs(args) {
338
+ return args.map((a) => typeof a === "string" ? a : a instanceof Error ? a.stack ?? a.message : safeJson(a)).join(" ");
339
+ }
340
+ function safeJson(v) {
341
+ try {
342
+ return JSON.stringify(v);
343
+ } catch {
344
+ return String(v);
345
+ }
346
+ }
347
+ var singleton = null;
348
+ function init2(opts) {
349
+ if (singleton) singleton.close();
350
+ singleton = new FaroBrowser(opts);
351
+ return singleton;
352
+ }
353
+ function getClient() {
354
+ if (!singleton) throw new Error("faro: init() must be called before use");
355
+ return singleton;
356
+ }
357
+ function log(entry) {
358
+ getClient().log(entry);
359
+ }
360
+ function info(msg, attrs) {
361
+ getClient().info(msg, attrs);
362
+ }
363
+ function warn(msg, attrs) {
364
+ getClient().warn(msg, attrs);
365
+ }
366
+ function error(msg, attrs) {
367
+ getClient().error(msg, attrs);
368
+ }
369
+ function captureException2(err, ctx) {
370
+ getClient().captureException(err, ctx);
371
+ }
372
+ function setUser(user) {
373
+ getClient().setUser(user);
374
+ }
375
+ function addBreadcrumb(crumb) {
376
+ getClient().addBreadcrumb(crumb);
377
+ }
378
+ function flush() {
379
+ return getClient().flush();
380
+ }
381
+ function close() {
382
+ getClient().close();
383
+ }
384
+
385
+ // src/browser-react.tsx
386
+ var React = __toESM(require("react"), 1);
387
+ var FaroErrorBoundary = class extends React.Component {
388
+ constructor() {
389
+ super(...arguments);
390
+ this.state = { error: null };
391
+ this.reset = () => {
392
+ this.setState({ error: null });
393
+ };
394
+ }
395
+ static getDerivedStateFromError(error2) {
396
+ return { error: error2 };
397
+ }
398
+ componentDidCatch(error2, info2) {
399
+ captureException2(error2, {
400
+ tags: {
401
+ origin: "react.error-boundary",
402
+ ...this.props.tags ?? {}
403
+ },
404
+ message: error2.message
405
+ });
406
+ this.props.onError?.(error2, info2);
407
+ }
408
+ render() {
409
+ if (this.state.error) {
410
+ const fb = this.props.fallback;
411
+ if (typeof fb === "function") return fb({ error: this.state.error, reset: this.reset });
412
+ if (fb !== void 0) return fb;
413
+ return null;
414
+ }
415
+ return this.props.children;
416
+ }
417
+ };
418
+
73
419
  // src/client.ts
74
- var import_browser = require("@iaportafolio/browser");
75
- var import_browser2 = require("@iaportafolio/browser");
76
- var import_react = require("@iaportafolio/browser/react");
77
420
  function initFaroClient(opts) {
78
421
  let release = opts.release;
79
422
  if (!release && typeof process !== "undefined" && process.env) {
80
423
  release = process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA || process.env.NEXT_PUBLIC_GIT_COMMIT_SHA || process.env.NEXT_PUBLIC_VERSION || void 0;
81
424
  }
82
- return (0, import_browser.init)({ ...opts, release });
425
+ return init2({ ...opts, release });
83
426
  }
84
427
  // Annotate the CommonJS export names for ESM import in node:
85
428
  0 && (module.exports = {
package/dist/index.d.cts CHANGED
@@ -1,6 +1,5 @@
1
1
  export { ServerOptions, captureRequestError, registerFaro } from './server.cjs';
2
- export { initFaroClient } from './client.cjs';
3
- export { Breadcrumb, FaroBrowserOptions, LogEntry, Severity, UserContext, WireEvent, addBreadcrumb, captureException, close, error, flush, getClient, info, log, setUser, warn } from '@iaportafolio/browser';
4
- export { FaroErrorBoundary, FaroErrorBoundaryProps } from '@iaportafolio/browser/react';
2
+ export { Breadcrumb, FaroBrowser, FaroBrowserOptions, FaroErrorBoundary, FaroErrorBoundaryProps, LogEntry, Severity, UserContext, WireEvent, addBreadcrumb, captureException, close, error, flush, getClient, info, initFaroClient, log, setUser, warn } from './client.cjs';
5
3
  import * as faro from '@iaportafolio/node';
6
4
  export { faro };
5
+ import 'react';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export { ServerOptions, captureRequestError, registerFaro } from './server.js';
2
- export { initFaroClient } from './client.js';
3
- export { Breadcrumb, FaroBrowserOptions, LogEntry, Severity, UserContext, WireEvent, addBreadcrumb, captureException, close, error, flush, getClient, info, log, setUser, warn } from '@iaportafolio/browser';
4
- export { FaroErrorBoundary, FaroErrorBoundaryProps } from '@iaportafolio/browser/react';
2
+ export { Breadcrumb, FaroBrowser, FaroBrowserOptions, FaroErrorBoundary, FaroErrorBoundaryProps, LogEntry, Severity, UserContext, WireEvent, addBreadcrumb, captureException, close, error, flush, getClient, info, initFaroClient, log, setUser, warn } from './client.js';
5
3
  import * as faro from '@iaportafolio/node';
6
4
  export { faro };
5
+ import 'react';
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  log,
12
12
  setUser,
13
13
  warn
14
- } from "./chunk-YWAGEOOH.js";
14
+ } from "./chunk-I3FDJF4L.js";
15
15
  import {
16
16
  captureRequestError,
17
17
  faro,