@belvador/react 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 +27 -0
- package/README.md +58 -2
- package/dist/index.d.ts +25 -0
- package/dist/index.js +37 -0
- package/dist/internal.d.ts +2 -0
- package/dist/internal.js +6 -0
- package/package.json +52 -4
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,59 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @belvador/react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Error tracking for React 18 and 19 apps, sending to your [Belvador](https://belvador.dev) node.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @belvador/react
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { createRoot } from "react-dom/client";
|
|
11
|
+
import { ErrorBoundary, init, reactErrorHandler } from "@belvador/react";
|
|
12
|
+
|
|
13
|
+
init({
|
|
14
|
+
dsn: "https://<key>@ingest.belvador.dev/<project>",
|
|
15
|
+
release: import.meta.env.VITE_APP_VERSION,
|
|
16
|
+
environment: import.meta.env.MODE,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
createRoot(document.getElementById("root")!, {
|
|
20
|
+
// React 19: report errors React handles itself
|
|
21
|
+
onUncaughtError: reactErrorHandler(),
|
|
22
|
+
onCaughtError: reactErrorHandler(),
|
|
23
|
+
onRecoverableError: reactErrorHandler(),
|
|
24
|
+
}).render(
|
|
25
|
+
<ErrorBoundary fallback={<p>Something went wrong.</p>}>
|
|
26
|
+
<App />
|
|
27
|
+
</ErrorBoundary>,
|
|
28
|
+
);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`ErrorBoundary` reports a render error once (with the component stack) and shows `fallback`.
|
|
32
|
+
The report dialog of other SDKs is not available: it would load a script from the network.
|
|
33
|
+
Everything in `@belvador/browser` is exported here too.
|
|
34
|
+
|
|
35
|
+
## What it sends
|
|
36
|
+
|
|
37
|
+
Errors only (exceptions, messages, breadcrumbs you turn on, attachments if you enable them).
|
|
38
|
+
No tracing, session replay, logs or profiling — those items are dropped inside your app.
|
|
39
|
+
|
|
40
|
+
Before anything leaves your app the SDK removes `Authorization`, `Cookie` and `Set-Cookie`
|
|
41
|
+
headers, request bodies and cookies, client IP headers, and masks credentials in URLs, query
|
|
42
|
+
strings, tags, contexts, extra data and breadcrumbs (passwords, tokens, API keys, JWTs, card
|
|
43
|
+
numbers, e-mail addresses). Only `user.id` is kept from `setUser`. Your Belvador node scrubs
|
|
44
|
+
again on its own.
|
|
45
|
+
|
|
46
|
+
Sending never slows down or breaks your app: at most 30 envelopes / 1 MB wait to be sent,
|
|
47
|
+
each attempt times out after 10 s, failed sends retry at most 5 times, `429` rate limits are
|
|
48
|
+
respected, and a revoked key (`401`/`403`) stops sending for the life of the page or isolate.
|
|
49
|
+
Every public function catches its own errors.
|
|
50
|
+
|
|
51
|
+
## Status
|
|
52
|
+
|
|
53
|
+
`0.x` — used by Belvador's own apps first. The API may still change before `1.0`.
|
|
54
|
+
|
|
55
|
+
Built on the open-source [Sentry JavaScript SDK](https://github.com/getsentry/sentry-javascript)
|
|
56
|
+
(MIT), pinned to one audited version, with Belvador's privacy and sending rules. Events go only
|
|
57
|
+
to your Belvador DSN; no Sentry account is involved. Belvador is not affiliated with Sentry.
|
|
58
|
+
|
|
59
|
+
License: MIT · https://belvador.dev
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ErrorBoundaryProps as EngineErrorBoundaryProps } from "@sentry/react";
|
|
2
|
+
import { type ComponentType, type FC, type ReactElement } from "react";
|
|
3
|
+
import type { BrowserOptions } from "@belvador/browser/internal";
|
|
4
|
+
export type ReactOptions = BrowserOptions;
|
|
5
|
+
export type { FallbackRender } from "@sentry/react";
|
|
6
|
+
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";
|
|
7
|
+
/**
|
|
8
|
+
* Engine boundary props without the report dialog: it loads a script from
|
|
9
|
+
* the DSN host, which Belvador never does (spec 01 §3).
|
|
10
|
+
*/
|
|
11
|
+
export type ErrorBoundaryProps = Omit<EngineErrorBoundaryProps, "showDialog" | "dialogOptions">;
|
|
12
|
+
/** Starts error tracking for a React app; returns whether it is running. Never throws. */
|
|
13
|
+
export declare function init(options: ReactOptions): boolean;
|
|
14
|
+
/** Catches render errors in its subtree, reports them once, and shows `fallback`. */
|
|
15
|
+
export declare function ErrorBoundary(props: ErrorBoundaryProps): ReactElement;
|
|
16
|
+
export declare function withErrorBoundary<P extends Record<string, unknown>>(component: ComponentType<P>, options: ErrorBoundaryProps): FC<P>;
|
|
17
|
+
/**
|
|
18
|
+
* React 19 root error hooks: `createRoot(el, { onUncaughtError: reactErrorHandler(),
|
|
19
|
+
* onCaughtError: reactErrorHandler(), onRecoverableError: reactErrorHandler() })`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function reactErrorHandler(callback?: (error: unknown, errorInfo: {
|
|
22
|
+
componentStack?: string;
|
|
23
|
+
}, eventId: string) => void): (error: unknown, errorInfo: {
|
|
24
|
+
componentStack?: string;
|
|
25
|
+
}) => void;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// @belvador/react — errors from React 18/19 apps 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 { ErrorBoundary as EngineErrorBoundary, reactErrorHandler as engineReactErrorHandler, withErrorBoundary as engineWithErrorBoundary, } from "@sentry/react";
|
|
5
|
+
import { createElement } from "react";
|
|
6
|
+
import { initReact } from "./internal.js";
|
|
7
|
+
export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, lastEventId, setContext, setTag, setTags, setUser, withScope, } from "@belvador/core";
|
|
8
|
+
function withoutDialog(props) {
|
|
9
|
+
const { showDialog: _show, dialogOptions: _dialog, ...rest } = props;
|
|
10
|
+
return rest;
|
|
11
|
+
}
|
|
12
|
+
/** Starts error tracking for a React app; returns whether it is running. Never throws. */
|
|
13
|
+
export function init(options) {
|
|
14
|
+
return initReact(options, "react");
|
|
15
|
+
}
|
|
16
|
+
/** Catches render errors in its subtree, reports them once, and shows `fallback`. */
|
|
17
|
+
export function ErrorBoundary(props) {
|
|
18
|
+
return createElement(EngineErrorBoundary, withoutDialog(props));
|
|
19
|
+
}
|
|
20
|
+
export function withErrorBoundary(component, options) {
|
|
21
|
+
return engineWithErrorBoundary(component, withoutDialog(options));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* React 19 root error hooks: `createRoot(el, { onUncaughtError: reactErrorHandler(),
|
|
25
|
+
* onCaughtError: reactErrorHandler(), onRecoverableError: reactErrorHandler() })`.
|
|
26
|
+
*/
|
|
27
|
+
export function reactErrorHandler(callback) {
|
|
28
|
+
const handler = engineReactErrorHandler(callback);
|
|
29
|
+
return (error, errorInfo) => {
|
|
30
|
+
try {
|
|
31
|
+
handler(error, errorInfo);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
/* never let reporting break React's own error handling */
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Shared with @belvador/tanstack-start: React init under another SDK name. Not a public API.
|
|
2
|
+
import { init as engineInit } from "@sentry/react";
|
|
3
|
+
import { initWith } from "@belvador/browser/internal";
|
|
4
|
+
export function initReact(options, runtime) {
|
|
5
|
+
return initWith(engineInit, options, runtime);
|
|
6
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@belvador/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Belvador error tracking for React 18/19: ErrorBoundary and root error handlers, 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/browser": "0.1.0",
|
|
41
|
+
"@belvador/core": "0.1.0",
|
|
42
|
+
"@sentry/react": "10.76.2"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"tag": "latest"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsc -p tsconfig.json"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
53
|
+
}
|
|
54
|
+
}
|