@belvador/browser 0.0.0-stage → 0.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/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Belvador
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ This software depends on the Sentry JavaScript SDK (https://github.com/getsentry/sentry-javascript),
26
+ which is distributed under its own MIT License (Copyright (c) Functional Software, Inc. dba Sentry)
27
+ in each of its npm packages. Belvador is not affiliated with or endorsed by Sentry.
package/README.md CHANGED
@@ -1,3 +1,56 @@
1
- # Temporary Holding Version
1
+ # @belvador/browser
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Error tracking for browser apps, sending to your [Belvador](https://belvador.dev) node.
4
+
5
+ ```sh
6
+ npm install @belvador/browser
7
+ ```
8
+
9
+ ```ts
10
+ import { init, captureException } from "@belvador/browser";
11
+
12
+ init({
13
+ dsn: "https://<key>@ingest.belvador.dev/<project>", // Project settings → DSN
14
+ release: import.meta.env.VITE_APP_VERSION, // your build or commit id
15
+ environment: import.meta.env.MODE,
16
+ });
17
+
18
+ try {
19
+ risky();
20
+ } catch (error) {
21
+ captureException(error);
22
+ }
23
+ ```
24
+
25
+ Uncaught errors and unhandled promise rejections are captured automatically. Only
26
+ `window.onerror` and `onunhandledrejection` are hooked by default; breadcrumbs from
27
+ `console`, `fetch`, `xhr`, DOM clicks and history are opt-in:
28
+ `init({ dsn, instrument: { fetch: true, console: true } })`.
29
+
30
+ Allow the ingest origin in your Content-Security-Policy: `connect-src https://ingest.belvador.dev`.
31
+
32
+ ## What it sends
33
+
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.
36
+
37
+ Before anything leaves your app the SDK removes `Authorization`, `Cookie` and `Set-Cookie`
38
+ headers, request bodies and cookies, client IP headers, and masks credentials in URLs, query
39
+ strings, tags, contexts, extra data and breadcrumbs (passwords, tokens, API keys, JWTs, card
40
+ numbers, e-mail addresses). Only `user.id` is kept from `setUser`. Your Belvador node scrubs
41
+ again on its own.
42
+
43
+ Sending never slows down or breaks your app: at most 30 envelopes / 1 MB wait to be sent,
44
+ each attempt times out after 10 s, failed sends retry at most 5 times, `429` rate limits are
45
+ respected, and a revoked key (`401`/`403`) stops sending for the life of the page or isolate.
46
+ Every public function catches its own errors.
47
+
48
+ ## Status
49
+
50
+ `0.x` — used by Belvador's own apps first. The API may still change before `1.0`.
51
+
52
+ Built on the open-source [Sentry JavaScript SDK](https://github.com/getsentry/sentry-javascript)
53
+ (MIT), pinned to one audited version, with Belvador's privacy and sending rules. Events go only
54
+ to your Belvador DSN; no Sentry account is involved. Belvador is not affiliated with Sentry.
55
+
56
+ License: MIT · https://belvador.dev
@@ -0,0 +1,5 @@
1
+ import { type BrowserOptions } from "./internal.js";
2
+ 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
+ /** Starts error tracking; returns whether it is running. Never throws. */
5
+ export declare function init(options: BrowserOptions): boolean;
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ // @belvador/browser — errors from the browser to your Belvador node.
2
+ // Built on the open-source Sentry JavaScript SDK (MIT), with Belvador's
3
+ // privacy and sending rules. Importing this module does nothing until init().
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";
7
+ /** Starts error tracking; returns whether it is running. Never throws. */
8
+ export function init(options) {
9
+ return initWith(engineInit, options, "browser");
10
+ }
@@ -0,0 +1,25 @@
1
+ import type { BrowserOptions as EngineBrowserOptions } from "@sentry/browser";
2
+ import { type BelvadorOptions, type RuntimeName } from "@belvador/core";
3
+ export type BrowserOptions = BelvadorOptions & {
4
+ /** Breadcrumb sources, all off by default (each one patches a browser API). */
5
+ instrument?: {
6
+ console?: boolean;
7
+ dom?: boolean;
8
+ fetch?: boolean;
9
+ xhr?: boolean;
10
+ history?: boolean;
11
+ };
12
+ /** Wrap setTimeout/addEventListener/requestAnimationFrame for better stacks. Default false. */
13
+ wrapBrowserApis?: boolean;
14
+ allowUrls?: Array<string | RegExp>;
15
+ /** Added to the built-in browser-extension filter. */
16
+ denyUrls?: Array<string | RegExp>;
17
+ };
18
+ /** Engine options for a browser runtime, or null when the SDK must stay off. */
19
+ export declare function browserEngineOptions(options: BrowserOptions, runtime: Extract<RuntimeName, "browser" | "react" | "tanstack-start">): EngineBrowserOptions | null;
20
+ /**
21
+ * Idempotent init: a second call with the same DSN keeps the running client
22
+ * (HMR, StrictMode); a different DSN or another SDK's client is never
23
+ * replaced silently. Returns whether Belvador is running. Never throws.
24
+ */
25
+ export declare function initWith(engineInit: (options: EngineBrowserOptions) => unknown, options: BrowserOptions, runtime: Extract<RuntimeName, "browser" | "react" | "tanstack-start">): boolean;
@@ -0,0 +1,67 @@
1
+ // Shared by @belvador/browser, /react and /tanstack-start: browser engine
2
+ // options and the idempotent init. Not a public API.
3
+ import { breadcrumbsIntegration, browserApiErrorsIntegration, dedupeIntegration, eventFiltersIntegration, functionToStringIntegration, getClient, globalHandlersIntegration, httpContextIntegration, linkedErrorsIntegration, } from "@sentry/browser";
4
+ import { BELVADOR_MARKER, buildEngineOptions, isActive, warnOnce, } from "@belvador/core";
5
+ const EXTENSION_URLS = [
6
+ /^chrome-extension:\/\//i,
7
+ /^moz-extension:\/\//i,
8
+ /^safari-(web-)?extension:\/\//i,
9
+ ];
10
+ /** Engine options for a browser runtime, or null when the SDK must stay off. */
11
+ export function browserEngineOptions(options, runtime) {
12
+ const base = buildEngineOptions(options, runtime, { browser: true });
13
+ if (!base)
14
+ return null;
15
+ const i = options.instrument ?? {};
16
+ const crumbs = {
17
+ console: i.console === true,
18
+ dom: i.dom === true,
19
+ fetch: i.fetch === true,
20
+ xhr: i.xhr === true,
21
+ history: i.history === true,
22
+ sentry: false,
23
+ };
24
+ // Only window.onerror and onunhandledrejection by default (t4 §A).
25
+ const integrations = [
26
+ eventFiltersIntegration(),
27
+ linkedErrorsIntegration(),
28
+ dedupeIntegration(),
29
+ globalHandlersIntegration({ onerror: true, onunhandledrejection: true }),
30
+ httpContextIntegration(),
31
+ ];
32
+ if (crumbs.console || crumbs.dom || crumbs.fetch || crumbs.xhr || crumbs.history)
33
+ integrations.push(breadcrumbsIntegration(crumbs));
34
+ if (options.wrapBrowserApis === true)
35
+ integrations.push(functionToStringIntegration(), browserApiErrorsIntegration());
36
+ return {
37
+ ...base,
38
+ integrations,
39
+ ...(Array.isArray(options.allowUrls) ? { allowUrls: options.allowUrls } : {}),
40
+ denyUrls: [...EXTENSION_URLS, ...(Array.isArray(options.denyUrls) ? options.denyUrls : [])],
41
+ };
42
+ }
43
+ /**
44
+ * Idempotent init: a second call with the same DSN keeps the running client
45
+ * (HMR, StrictMode); a different DSN or another SDK's client is never
46
+ * replaced silently. Returns whether Belvador is running. Never throws.
47
+ */
48
+ export function initWith(engineInit, options, runtime) {
49
+ try {
50
+ const existing = getClient();
51
+ if (existing) {
52
+ const prev = existing.getOptions();
53
+ if (prev[BELVADOR_MARKER] === true && prev["dsn"] === options?.dsn)
54
+ return true;
55
+ warnOnce("init skipped: another error-tracking client is already running in this page. Remove the old init so errors are not captured twice.");
56
+ return false;
57
+ }
58
+ const engineOptions = browserEngineOptions(options, runtime);
59
+ if (!engineOptions)
60
+ return false;
61
+ engineInit(engineOptions);
62
+ return isActive();
63
+ }
64
+ catch {
65
+ return false;
66
+ }
67
+ }
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "@belvador/browser",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Belvador error tracking for the browser: one init, errors only, private by default.",
5
+ "license": "MIT",
6
+ "author": "Belvador (https://belvador.dev)",
7
+ "homepage": "https://belvador.dev",
8
+ "keywords": [
9
+ "belvador",
10
+ "error-tracking",
11
+ "errors",
12
+ "monitoring"
13
+ ],
14
+ "type": "module",
15
+ "sideEffects": false,
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js",
22
+ "default": "./dist/index.js"
23
+ },
24
+ "./internal": {
25
+ "types": "./dist/internal.d.ts",
26
+ "import": "./dist/internal.js",
27
+ "default": "./dist/internal.js"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "README.md",
34
+ "LICENSE"
35
+ ],
36
+ "engines": {
37
+ "node": ">=18"
38
+ },
39
+ "dependencies": {
40
+ "@belvador/core": "0.1.0",
41
+ "@sentry/browser": "10.76.2"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public",
45
+ "tag": "latest"
46
+ },
47
+ "scripts": {
48
+ "build": "tsc -p tsconfig.json"
49
+ }
50
+ }