@belvador/browser 0.1.0 → 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 CHANGED
@@ -32,7 +32,7 @@ Allow the ingest origin in your Content-Security-Policy: `connect-src https://in
32
32
  ## What it sends
33
33
 
34
34
  Errors only (exceptions, messages, breadcrumbs you turn on, attachments if you enable them).
35
- No tracing, session replay, logs or profiling — those items are dropped inside your app.
35
+ No spans, session replay, logs, profiling or check-ins — those items are dropped inside your app.
36
36
 
37
37
  Before anything leaves your app the SDK removes `Authorization`, `Cookie` and `Set-Cookie`
38
38
  headers, request bodies and cookies, client IP headers, and masks credentials in URLs, query
@@ -45,6 +45,24 @@ each attempt times out after 10 s, failed sends retry at most 5 times, `429` rat
45
45
  respected, and a revoked key (`401`/`403`) stops sending for the life of the page or isolate.
46
46
  Every public function catches its own errors.
47
47
 
48
+ ## Link requests with one trace
49
+
50
+ Off by default. `tracePropagation: { targets: [/^\/api\//, "https://api.example.com"] }` adds
51
+ `traceparent` and `sentry-trace` headers to `fetch` calls to those URLs (relative patterns
52
+ match same-origin paths), so a browser error and the server error behind the same request
53
+ share one trace id. The receiving API must allow these headers in CORS. No spans or
54
+ transactions are sent; `baggage` only with `baggage: true`. A View Transition the browser
55
+ skipped on purpose is not reported unless you set `captureViewTransitionSkips: true`.
56
+ See https://belvador.dev/docs/sdk/tracing
57
+
58
+ ## Check the connection
59
+
60
+ "No errors" is not proof that errors arrive. Call `verifyIntegration()` from `@belvador/browser` once after `init`:
61
+ it sends one marked test error (never an issue), reads it back and resolves to
62
+ `{ outcome: "verified" | "problem" | "unconfirmed", checks, docsUrl, … }`. It never throws.
63
+ Requests the visitor cancelled (`AbortError`) are not reported unless you set `captureAborted: true`.
64
+ See https://belvador.dev/docs/sdk/verify
65
+
48
66
  ## Status
49
67
 
50
68
  `0.x` — used by Belvador's own apps first. The API may still change before `1.0`.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,12 @@
1
+ import type { VerificationResult, VerifyOptions } from "@belvador/core";
1
2
  import { type BrowserOptions } from "./internal.js";
2
3
  export type { BrowserOptions } from "./internal.js";
3
- export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, lastEventId, setContext, setTag, setTags, setUser, withScope, type BelvadorBreadcrumb, type BelvadorEvent, type BelvadorEventHint, type Scope, type SeverityLevel, } from "@belvador/core";
4
+ export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, getDiagnostics, lastEventId, setContext, setTag, setTags, setUser, withScope, type BelvadorBreadcrumb, type BelvadorEvent, type BelvadorEventHint, type Diagnostic, type DiagnosticCode, type DiagnosticsSnapshot, type Scope, type SeverityLevel, type VerificationResult, type VerifyOptions, } from "@belvador/core";
4
5
  /** Starts error tracking; returns whether it is running. Never throws. */
5
6
  export declare function init(options: BrowserOptions): boolean;
7
+ /**
8
+ * Proves this page reports to Belvador: a captured and an uncaught verification error
9
+ * (the console shows one "expected" error), read back from Belvador. Run it once after
10
+ * setup or deploy; never automatic. Always resolves; prints one summary line.
11
+ */
12
+ export declare function verifyIntegration(options?: VerifyOptions): Promise<VerificationResult>;
package/dist/index.js CHANGED
@@ -2,9 +2,17 @@
2
2
  // Built on the open-source Sentry JavaScript SDK (MIT), with Belvador's
3
3
  // privacy and sending rules. Importing this module does nothing until init().
4
4
  import { init as engineInit } from "@sentry/browser";
5
- import { initWith } from "./internal.js";
6
- export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, lastEventId, setContext, setTag, setTags, setUser, withScope, } from "@belvador/core";
5
+ import { initWith, verifyBrowser } from "./internal.js";
6
+ export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, getDiagnostics, lastEventId, setContext, setTag, setTags, setUser, withScope, } from "@belvador/core";
7
7
  /** Starts error tracking; returns whether it is running. Never throws. */
8
8
  export function init(options) {
9
9
  return initWith(engineInit, options, "browser");
10
10
  }
11
+ /**
12
+ * Proves this page reports to Belvador: a captured and an uncaught verification error
13
+ * (the console shows one "expected" error), read back from Belvador. Run it once after
14
+ * setup or deploy; never automatic. Always resolves; prints one summary line.
15
+ */
16
+ export function verifyIntegration(options) {
17
+ return verifyBrowser(options);
18
+ }
@@ -1,5 +1,5 @@
1
1
  import type { BrowserOptions as EngineBrowserOptions } from "@sentry/browser";
2
- import { type BelvadorOptions, type RuntimeName } from "@belvador/core";
2
+ import { type BelvadorOptions, type RuntimeName, type VerificationResult, type VerifyOptions } from "@belvador/core";
3
3
  export type BrowserOptions = BelvadorOptions & {
4
4
  /** Breadcrumb sources, all off by default (each one patches a browser API). */
5
5
  instrument?: {
@@ -23,3 +23,8 @@ export declare function browserEngineOptions(options: BrowserOptions, runtime: E
23
23
  * replaced silently. Returns whether Belvador is running. Never throws.
24
24
  */
25
25
  export declare function initWith(engineInit: (options: EngineBrowserOptions) => unknown, options: BrowserOptions, runtime: Extract<RuntimeName, "browser" | "react" | "tanstack-start">): boolean;
26
+ /**
27
+ * Browser verification (integration-health spec 02 §3): the global error handler is
28
+ * installed, a captured verification arrives, and an uncaught one does too.
29
+ */
30
+ export declare function verifyBrowser(options?: VerifyOptions): Promise<VerificationResult>;
package/dist/internal.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // Shared by @belvador/browser, /react and /tanstack-start: browser engine
2
2
  // options and the idempotent init. Not a public API.
3
3
  import { breadcrumbsIntegration, browserApiErrorsIntegration, dedupeIntegration, eventFiltersIntegration, functionToStringIntegration, getClient, globalHandlersIntegration, httpContextIntegration, linkedErrorsIntegration, } from "@sentry/browser";
4
- import { BELVADOR_MARKER, buildEngineOptions, isActive, warnOnce, } from "@belvador/core";
4
+ import { BELVADOR_MARKER, TRACE_OPTION, buildEngineOptions, installTracePropagation, isActive, reportDiagnostic, runVerification, warnOnce, } from "@belvador/core";
5
5
  const EXTENSION_URLS = [
6
6
  /^chrome-extension:\/\//i,
7
7
  /^moz-extension:\/\//i,
@@ -52,6 +52,7 @@ export function initWith(engineInit, options, runtime) {
52
52
  const prev = existing.getOptions();
53
53
  if (prev[BELVADOR_MARKER] === true && prev["dsn"] === options?.dsn)
54
54
  return true;
55
+ reportDiagnostic("BLV_INIT_CONFLICT");
55
56
  warnOnce("init skipped: another error-tracking client is already running in this page. Remove the old init so errors are not captured twice.");
56
57
  return false;
57
58
  }
@@ -59,9 +60,29 @@ export function initWith(engineInit, options, runtime) {
59
60
  if (!engineOptions)
60
61
  return false;
61
62
  engineInit(engineOptions);
63
+ // Only when the app asked for it (spec 06 §5): fetch to its targets carries the trace.
64
+ if (engineOptions[TRACE_OPTION])
65
+ installTracePropagation();
62
66
  return isActive();
63
67
  }
64
68
  catch {
65
69
  return false;
66
70
  }
67
71
  }
72
+ /**
73
+ * Browser verification (integration-health spec 02 §3): the global error handler is
74
+ * installed, a captured verification arrives, and an uncaught one does too.
75
+ */
76
+ export function verifyBrowser(options) {
77
+ return runVerification({
78
+ surface: "browser",
79
+ hook: () => {
80
+ try {
81
+ return { ok: Boolean(getClient()?.getIntegrationByName("GlobalHandlers")) };
82
+ }
83
+ catch {
84
+ return { ok: false };
85
+ }
86
+ },
87
+ }, options);
88
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@belvador/browser",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Belvador error tracking for the browser: one init, errors only, private by default.",
5
5
  "license": "MIT",
6
6
  "author": "Belvador (https://belvador.dev)",
@@ -37,7 +37,7 @@
37
37
  "node": ">=18"
38
38
  },
39
39
  "dependencies": {
40
- "@belvador/core": "0.1.0",
40
+ "@belvador/core": "0.3.0",
41
41
  "@sentry/browser": "10.76.2"
42
42
  },
43
43
  "publishConfig": {