@belvador/tanstack-start 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,72 @@
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()` and errors with a status below 500 are not. Needs `nodejs_compat` and the
46
+ `BELVADOR_DSN` secret on the server.
47
+
48
+ ## What it sends
49
+
50
+ Errors only (exceptions, messages, breadcrumbs you turn on, attachments if you enable them).
51
+ No tracing, session replay, logs or profiling — those items are dropped inside your app.
52
+
53
+ Before anything leaves your app the SDK removes `Authorization`, `Cookie` and `Set-Cookie`
54
+ headers, request bodies and cookies, client IP headers, and masks credentials in URLs, query
55
+ strings, tags, contexts, extra data and breadcrumbs (passwords, tokens, API keys, JWTs, card
56
+ numbers, e-mail addresses). Only `user.id` is kept from `setUser`. Your Belvador node scrubs
57
+ again on its own.
58
+
59
+ Sending never slows down or breaks your app: at most 30 envelopes / 1 MB wait to be sent,
60
+ each attempt times out after 10 s, failed sends retry at most 5 times, `429` rate limits are
61
+ respected, and a revoked key (`401`/`403`) stops sending for the life of the page or isolate.
62
+ Every public function catches its own errors.
63
+
64
+ ## Status
65
+
66
+ `0.x` — used by Belvador's own apps first. The API may still change before `1.0`.
67
+
68
+ Built on the open-source [Sentry JavaScript SDK](https://github.com/getsentry/sentry-javascript)
69
+ (MIT), pinned to one audited version, with Belvador's privacy and sending rules. Events go only
70
+ to your Belvador DSN; no Sentry account is involved. Belvador is not affiliated with Sentry.
71
+
72
+ 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, lastEventId, reactErrorHandler, setContext, setTag, setTags, setUser, withErrorBoundary, withScope, type ErrorBoundaryProps, type ReactOptions, } 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, lastEventId, reactErrorHandler, setContext, setTag, setTags, setUser, withErrorBoundary, withScope, } 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,19 @@
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 are never reported.
5
+ */
6
+ export declare function isExpectedError(error: unknown): boolean;
7
+ /**
8
+ * Request middleware: reports errors thrown by server routes and SSR, then
9
+ * re-throws so your own error handling runs unchanged. Put it LAST in
10
+ * `requestMiddleware` (closest to the handler) so it sees errors before an
11
+ * error-page middleware turns them into a response.
12
+ */
13
+ export declare const belvadorRequestMiddleware: import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, undefined>;
14
+ /** Server-function middleware: same contract, put it LAST in `functionMiddleware`. */
15
+ export declare const belvadorFunctionMiddleware: import("@tanstack/react-start").FunctionMiddlewareAfterServer<{}, unknown, undefined, undefined, undefined, undefined, undefined>;
16
+ /** For `createRouter({ defaultOnCatch: belvadorOnCatch })`: errors shown by a route's error boundary. */
17
+ export declare function belvadorOnCatch(error: Error, errorInfo?: {
18
+ componentStack?: string | null;
19
+ }): void;
package/dist/index.js ADDED
@@ -0,0 +1,70 @@
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 } 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 are never reported.
11
+ */
12
+ export function isExpectedError(error) {
13
+ try {
14
+ if (typeof Response !== "undefined" && error instanceof Response)
15
+ return error.status < 500;
16
+ if (isRedirect(error) || isNotFound(error))
17
+ return true;
18
+ if (error !== null && typeof error === "object") {
19
+ const e = error;
20
+ const status = typeof e.statusCode === "number" ? e.statusCode : e.status;
21
+ if (typeof status === "number" && status < 500)
22
+ return true;
23
+ }
24
+ }
25
+ catch {
26
+ /* fall through: report it */
27
+ }
28
+ return false;
29
+ }
30
+ function report(error, kind) {
31
+ if (isExpectedError(error))
32
+ return;
33
+ captureException(error, {
34
+ mechanism: { type: `auto.belvador.tanstack_start.${kind}`, handled: false },
35
+ });
36
+ }
37
+ /**
38
+ * Request middleware: reports errors thrown by server routes and SSR, then
39
+ * re-throws so your own error handling runs unchanged. Put it LAST in
40
+ * `requestMiddleware` (closest to the handler) so it sees errors before an
41
+ * error-page middleware turns them into a response.
42
+ */
43
+ export const belvadorRequestMiddleware = createMiddleware().server(async ({ next }) => {
44
+ try {
45
+ return await next();
46
+ }
47
+ catch (error) {
48
+ report(error, "request");
49
+ throw error;
50
+ }
51
+ });
52
+ /** Server-function middleware: same contract, put it LAST in `functionMiddleware`. */
53
+ export const belvadorFunctionMiddleware = createMiddleware({ type: "function" }).server(async ({ next }) => {
54
+ try {
55
+ return await next();
56
+ }
57
+ catch (error) {
58
+ report(error, "server_function");
59
+ throw error;
60
+ }
61
+ });
62
+ /** For `createRouter({ defaultOnCatch: belvadorOnCatch })`: errors shown by a route's error boundary. */
63
+ export function belvadorOnCatch(error, errorInfo) {
64
+ if (isExpectedError(error))
65
+ return;
66
+ captureException(error, {
67
+ mechanism: { type: "auto.belvador.tanstack_start.route", handled: true },
68
+ ...(errorInfo?.componentStack ? { data: { componentStack: errorInfo.componentStack } } : {}),
69
+ });
70
+ }
@@ -0,0 +1,7 @@
1
+ import { type WorkerOptions } from "@belvador/cloudflare";
2
+ export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, flush, setContext, setTag, setTags, setUser, withScope, type BelvadorEnv, type WorkerOptions, } from "@belvador/cloudflare";
3
+ /**
4
+ * `export default withBelvador((env) => ({ release: env.BELVADOR_RELEASE }), { fetch })`:
5
+ * one client per request, errors reported and re-thrown, the response untouched.
6
+ */
7
+ export declare function withBelvador<Env, H>(optionsCallback: (env: Env) => WorkerOptions | undefined, handler: H): H;
package/dist/server.js ADDED
@@ -0,0 +1,11 @@
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
+ export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, flush, setContext, setTag, setTags, setUser, withScope, } from "@belvador/cloudflare";
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 function withBelvador(optionsCallback, handler) {
10
+ return wrapHandler(optionsCallback, handler, "tanstack-start");
11
+ }
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.1.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.1.0",
46
+ "@belvador/core": "0.1.0",
47
+ "@belvador/react": "0.1.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
+ }