@belvador/tanstack-start 0.0.0-stage → 0.2.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,81 @@
1
- # Temporary Holding Version
1
+ # @belvador/tanstack-start
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 [TanStack Start](https://tanstack.com/start) apps on Cloudflare Workers
4
+ (including apps built with Lovable), sending to your [Belvador](https://belvador.dev) node.
5
+
6
+ ```sh
7
+ npm install @belvador/tanstack-start
8
+ ```
9
+
10
+ **Browser** — `src/router.tsx`:
11
+
12
+ ```ts
13
+ import { belvadorOnCatch, init } from "@belvador/tanstack-start/client";
14
+
15
+ if (typeof window !== "undefined") {
16
+ init({ dsn: "https://<key>@ingest.belvador.dev/<project>", release: import.meta.env.VITE_APP_VERSION });
17
+ }
18
+ // createRouter({ ..., defaultOnCatch: belvadorOnCatch })
19
+ ```
20
+
21
+ **Server** — `src/server.ts` (set `tanstackStart: { server: { entry: "server" } }` in `vite.config.ts`):
22
+
23
+ ```ts
24
+ import handler from "@tanstack/react-start/server-entry";
25
+ import { withBelvador } from "@belvador/tanstack-start/server";
26
+
27
+ export default withBelvador((env) => ({ release: env.BELVADOR_RELEASE }), {
28
+ fetch: (request, env, ctx) => handler.fetch(request, env, ctx),
29
+ });
30
+ ```
31
+
32
+ **Middleware** — `src/start.ts`, last in each list (closest to the handler):
33
+
34
+ ```ts
35
+ import { createStart } from "@tanstack/react-start";
36
+ import { belvadorFunctionMiddleware, belvadorRequestMiddleware } from "@belvador/tanstack-start";
37
+
38
+ export const startInstance = createStart(() => ({
39
+ requestMiddleware: [/* your middleware */ belvadorRequestMiddleware],
40
+ functionMiddleware: [/* your middleware */ belvadorFunctionMiddleware],
41
+ }));
42
+ ```
43
+
44
+ Server functions and server routes are reported with their server stack; redirects,
45
+ `notFound()`, errors with a status below 500 and requests the visitor cancelled (`AbortError`,
46
+ or a failure after the client disconnected — `captureAborted: true` reports them) are not.
47
+ Needs `nodejs_compat` and the `BELVADOR_DSN` secret on the server.
48
+
49
+ ## Check the connection
50
+
51
+ "No errors" is not proof that errors arrive. Call `verifyIntegration()` once from the browser
52
+ (`@belvador/tanstack-start/client`) and once from a server route (`@belvador/tanstack-start/server`):
53
+ each sends one marked test error (never an issue), reads it back and resolves to
54
+ `{ outcome: "verified" | "problem" | "unconfirmed", checks, docsUrl, … }`. It never throws. See
55
+ https://belvador.dev/docs/sdk/verify
56
+
57
+ ## What it sends
58
+
59
+ Errors only (exceptions, messages, breadcrumbs you turn on, attachments if you enable them).
60
+ No tracing, session replay, logs or profiling — those items are dropped inside your app.
61
+
62
+ Before anything leaves your app the SDK removes `Authorization`, `Cookie` and `Set-Cookie`
63
+ headers, request bodies and cookies, client IP headers, and masks credentials in URLs, query
64
+ strings, tags, contexts, extra data and breadcrumbs (passwords, tokens, API keys, JWTs, card
65
+ numbers, e-mail addresses). Only `user.id` is kept from `setUser`. Your Belvador node scrubs
66
+ again on its own.
67
+
68
+ Sending never slows down or breaks your app: at most 30 envelopes / 1 MB wait to be sent,
69
+ each attempt times out after 10 s, failed sends retry at most 5 times, `429` rate limits are
70
+ respected, and a revoked key (`401`/`403`) stops sending for the life of the page or isolate.
71
+ Every public function catches its own errors.
72
+
73
+ ## Status
74
+
75
+ `0.x` — used by Belvador's own apps first. The API may still change before `1.0`.
76
+
77
+ Built on the open-source [Sentry JavaScript SDK](https://github.com/getsentry/sentry-javascript)
78
+ (MIT), pinned to one audited version, with Belvador's privacy and sending rules. Events go only
79
+ to your Belvador DSN; no Sentry account is involved. Belvador is not affiliated with Sentry.
80
+
81
+ License: MIT · https://belvador.dev
@@ -0,0 +1,5 @@
1
+ import type { ReactOptions } from "@belvador/react";
2
+ export { ErrorBoundary, SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, getDiagnostics, lastEventId, reactErrorHandler, setContext, setTag, setTags, setUser, withErrorBoundary, withScope, verifyIntegration, type Diagnostic, type DiagnosticCode, type DiagnosticsSnapshot, type ErrorBoundaryProps, type ReactOptions, type VerificationResult, type VerifyOptions, } from "@belvador/react";
3
+ export { belvadorOnCatch } from "./index.js";
4
+ /** Starts error tracking in the browser; returns whether it is running. Never throws. */
5
+ export declare function init(options: ReactOptions): boolean;
package/dist/client.js ADDED
@@ -0,0 +1,7 @@
1
+ import { initReact } from "@belvador/react/internal";
2
+ export { ErrorBoundary, SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, getDiagnostics, lastEventId, reactErrorHandler, setContext, setTag, setTags, setUser, withErrorBoundary, withScope, verifyIntegration, } from "@belvador/react";
3
+ export { belvadorOnCatch } from "./index.js";
4
+ /** Starts error tracking in the browser; returns whether it is running. Never throws. */
5
+ export function init(options) {
6
+ return initReact(options, "tanstack-start");
7
+ }
@@ -0,0 +1,21 @@
1
+ export { SDK_VERSION } from "@belvador/core";
2
+ /**
3
+ * Control flow, not failures: redirects, not-found, thrown Responses and
4
+ * anything carrying an HTTP status below 500 (499 "client closed" included) are
5
+ * never reported. Client cancellations (AbortError, or a failure after the visitor
6
+ * disconnected) are dropped by the SDK itself unless `captureAborted` is on.
7
+ */
8
+ export declare function isExpectedError(error: unknown): boolean;
9
+ /**
10
+ * Request middleware: reports errors thrown by server routes and SSR, then
11
+ * re-throws so your own error handling runs unchanged. Put it LAST in
12
+ * `requestMiddleware` (closest to the handler) so it sees errors before an
13
+ * error-page middleware turns them into a response.
14
+ */
15
+ export declare const belvadorRequestMiddleware: import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, undefined>;
16
+ /** Server-function middleware: same contract, put it LAST in `functionMiddleware`. */
17
+ export declare const belvadorFunctionMiddleware: import("@tanstack/react-start").FunctionMiddlewareAfterServer<{}, unknown, undefined, undefined, undefined, undefined, undefined>;
18
+ /** For `createRouter({ defaultOnCatch: belvadorOnCatch })`: errors shown by a route's error boundary. */
19
+ export declare function belvadorOnCatch(error: Error, errorInfo?: {
20
+ componentStack?: string | null;
21
+ }): void;
package/dist/index.js ADDED
@@ -0,0 +1,76 @@
1
+ // @belvador/tanstack-start — shared (client + server) pieces: middleware for
2
+ // src/start.ts and the router's defaultOnCatch. Safe to import from both
3
+ // bundles: it only calls the runtime-neutral capture API.
4
+ import { isNotFound, isRedirect } from "@tanstack/react-router";
5
+ import { createMiddleware } from "@tanstack/react-start";
6
+ import { captureException, markHooked, noteClientAbort } from "@belvador/core";
7
+ export { SDK_VERSION } from "@belvador/core";
8
+ /**
9
+ * Control flow, not failures: redirects, not-found, thrown Responses and
10
+ * anything carrying an HTTP status below 500 (499 "client closed" included) are
11
+ * never reported. Client cancellations (AbortError, or a failure after the visitor
12
+ * disconnected) are dropped by the SDK itself unless `captureAborted` is on.
13
+ */
14
+ export function isExpectedError(error) {
15
+ try {
16
+ if (typeof Response !== "undefined" && error instanceof Response)
17
+ return error.status < 500;
18
+ if (isRedirect(error) || isNotFound(error))
19
+ return true;
20
+ if (error !== null && typeof error === "object") {
21
+ const e = error;
22
+ const status = typeof e.statusCode === "number" ? e.statusCode : e.status;
23
+ if (typeof status === "number" && status < 500)
24
+ return true;
25
+ }
26
+ }
27
+ catch {
28
+ /* fall through: report it */
29
+ }
30
+ return false;
31
+ }
32
+ function report(error, kind) {
33
+ if (isExpectedError(error))
34
+ return;
35
+ captureException(error, {
36
+ mechanism: { type: `auto.belvador.tanstack_start.${kind}`, handled: false },
37
+ });
38
+ }
39
+ /**
40
+ * Request middleware: reports errors thrown by server routes and SSR, then
41
+ * re-throws so your own error handling runs unchanged. Put it LAST in
42
+ * `requestMiddleware` (closest to the handler) so it sees errors before an
43
+ * error-page middleware turns them into a response.
44
+ */
45
+ export const belvadorRequestMiddleware = createMiddleware().server(async ({ next, request }) => {
46
+ markHooked("middleware");
47
+ try {
48
+ return await next();
49
+ }
50
+ catch (error) {
51
+ noteClientAbort(error, request?.signal);
52
+ report(error, "request");
53
+ throw error;
54
+ }
55
+ });
56
+ /** Server-function middleware: same contract, put it LAST in `functionMiddleware`. */
57
+ export const belvadorFunctionMiddleware = createMiddleware({ type: "function" }).server(async ({ next, signal }) => {
58
+ markHooked("middleware");
59
+ try {
60
+ return await next();
61
+ }
62
+ catch (error) {
63
+ noteClientAbort(error, signal);
64
+ report(error, "server_function");
65
+ throw error;
66
+ }
67
+ });
68
+ /** For `createRouter({ defaultOnCatch: belvadorOnCatch })`: errors shown by a route's error boundary. */
69
+ export function belvadorOnCatch(error, errorInfo) {
70
+ if (isExpectedError(error))
71
+ return;
72
+ captureException(error, {
73
+ mechanism: { type: "auto.belvador.tanstack_start.route", handled: true },
74
+ ...(errorInfo?.componentStack ? { data: { componentStack: errorInfo.componentStack } } : {}),
75
+ });
76
+ }
@@ -0,0 +1,16 @@
1
+ import { type WorkerOptions } from "@belvador/cloudflare";
2
+ import { type VerificationResult, type VerifyOptions } from "@belvador/core";
3
+ export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, flush, getDiagnostics, setContext, setTag, setTags, setUser, withScope, type BelvadorEnv, type Diagnostic, type DiagnosticCode, type DiagnosticsSnapshot, type WorkerOptions, } from "@belvador/cloudflare";
4
+ export type { VerificationResult, VerifyOptions } from "@belvador/core";
5
+ /**
6
+ * `export default withBelvador((env) => ({ release: env.BELVADOR_RELEASE }), { fetch })`:
7
+ * one client per request, errors reported and re-thrown, the response untouched.
8
+ */
9
+ export declare function withBelvador<Env, H>(optionsCallback: (env: Env) => WorkerOptions | undefined, handler: H): H;
10
+ /**
11
+ * Proves the server reports to Belvador. Call it inside a server function or server
12
+ * route (for example a temporary `/api/verify-belvador` route): it checks that the call
13
+ * runs inside belvadorRequestMiddleware/belvadorFunctionMiddleware, sends one
14
+ * verification error and reads it back. Never automatic; always resolves.
15
+ */
16
+ export declare function verifyIntegration(options?: VerifyOptions): Promise<VerificationResult>;
package/dist/server.js ADDED
@@ -0,0 +1,21 @@
1
+ // @belvador/tanstack-start/server — Workers side. Wrap the default export of
2
+ // src/server.ts; add the middleware from "@belvador/tanstack-start" to src/start.ts.
3
+ import { wrapHandler } from "@belvador/cloudflare";
4
+ import { currentHooks, runVerification, } from "@belvador/core";
5
+ export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, flush, getDiagnostics, setContext, setTag, setTags, setUser, withScope, } from "@belvador/cloudflare";
6
+ /**
7
+ * `export default withBelvador((env) => ({ release: env.BELVADOR_RELEASE }), { fetch })`:
8
+ * one client per request, errors reported and re-thrown, the response untouched.
9
+ */
10
+ export function withBelvador(optionsCallback, handler) {
11
+ return wrapHandler(optionsCallback, handler, "tanstack-start");
12
+ }
13
+ /**
14
+ * Proves the server reports to Belvador. Call it inside a server function or server
15
+ * route (for example a temporary `/api/verify-belvador` route): it checks that the call
16
+ * runs inside belvadorRequestMiddleware/belvadorFunctionMiddleware, sends one
17
+ * verification error and reads it back. Never automatic; always resolves.
18
+ */
19
+ export function verifyIntegration(options) {
20
+ return runVerification({ surface: "server", hook: () => ({ ok: currentHooks().has("middleware") }) }, options);
21
+ }
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@belvador/tanstack-start",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Belvador error tracking for TanStack Start on Cloudflare Workers: client, server entry and middleware.",
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
+ "./client": {
25
+ "types": "./dist/client.d.ts",
26
+ "import": "./dist/client.js",
27
+ "default": "./dist/client.js"
28
+ },
29
+ "./server": {
30
+ "types": "./dist/server.d.ts",
31
+ "import": "./dist/server.js",
32
+ "default": "./dist/server.js"
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "README.md",
39
+ "LICENSE"
40
+ ],
41
+ "engines": {
42
+ "node": ">=18"
43
+ },
44
+ "dependencies": {
45
+ "@belvador/cloudflare": "0.2.0",
46
+ "@belvador/core": "0.2.0",
47
+ "@belvador/react": "0.2.0"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public",
51
+ "tag": "latest"
52
+ },
53
+ "scripts": {
54
+ "build": "tsc -p tsconfig.json"
55
+ },
56
+ "peerDependencies": {
57
+ "@tanstack/react-router": "^1.168.0",
58
+ "@tanstack/react-start": "^1.168.0",
59
+ "react": "^18.0.0 || ^19.0.0"
60
+ }
61
+ }