Skip to content

feat(sdk): export getAnonymousVisitorId - #325

Open
egidijusj wants to merge 4 commits into
base44:mainfrom
egidijusj:sdk-server-error-capture
Open

egidijusj wants to merge 4 commits into
base44:mainfrom
egidijusj:sdk-server-error-capture

Conversation

@egidijusj

@egidijusj egidijusj commented Oct 13, 2026 •

Copy link
Copy Markdown

What

Exports getAnonymousVisitorId(): string | null from @base44/sdk. It returns the anonymous visitor id the SDK already sends as X-Base44-Anonymous-Id on requests made without a signed-in user. That's getAnalyticsSessionId(), stored under base44_analytics_session_id in localStorage. It returns null outside a browser, and null if anything throws. getAnalyticsSessionId, the storage key and the axios interceptor are unchanged.

Why

A TanStack Start app's server-function calls go through TanStack's own fetch, not the SDK's axios client, so they don't carry X-Base44-Anonymous-Id. Without it, Base44 can't tell which signed-out visitor a server error affected. The app template has to add the header itself, and this export lets it read the same id the SDK sends, instead of reaching into the SDK's storage key. Until a release includes it, the template reads base44_analytics_session_id directly, so nothing is blocked on this PR.

The tests pin that contract: getAnonymousVisitorId() returns the same value an unauthenticated client sends as X-Base44-Anonymous-Id.

What was dropped

This PR first added helpers that reported server errors in an X-B44-Function-Error response header: recordServerError, annotateServerResponse, serverErrorResponse, the header format, size budget, stack-frame parsing, a contract fixture, and an end-to-end TanStack app with its CI job. They're gone. The plan changed on 2026-10-14: a Cloudflare Tail Worker on the dispatch Workers now reads errors (decision 33), and the app template logs the error record from its own managed files (D13). So the SDK no longer holds any of it. See function-error-transport-alternatives.md (§4.7, and §11 rows D1, D11, D13) and the base44/javascript-sdk table in function-error-pr-dispositions.md.

The removed end-to-end app is recoverable at commit c185498. Its two findings now live in the apper template work:

  • TanStack passes serverFnMeta (name, filename, id), not functionId, to a function middleware.
  • Miniflare appends //# sourceURL=file:///… to each module, so frames show absolute local paths where a deployed Worker shows module names.

No version bump; the release workflow does that.

🤖 Generated with Claude Code

egidijusj and others added 4 commits October 13, 2026 10:14
Add recordServerError, annotateServerResponse, serverErrorResponse and
getAnonymousVisitorId. A full-stack (TanStack Start) app's Worker uses them,
through the app template's middleware, to report its server errors to Base44
in the X-B44-Function-Error response header (v2), only when serving asks with
X-B44-Capture-Errors: 1. No TanStack dependency and no new runtime dependency.

Tests: Vitest units, a contract fixture checked against apper's
read_function_error(version=2), and an end-to-end TanStack Start app built
with @cloudflare/vite-plugin and run in Miniflare and workerd.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'t fit

- The root .gitignore's lib/ rule had dropped the e2e app's
  src/lib/error-capture-middleware.js, so the app couldn't build.
- Escaping can grow a 500-byte message to 3,000 bytes (\u0001 per control
  character), so with name and fn the header could miss 3,072 bytes even
  without frames, and no report was written. Cut the message to the most
  code points that fit instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Server errors no longer travel in an X-B44-Function-Error response header: a
Tail Worker on the dispatch Workers reads them, and the app template logs the
error record itself. So the header helpers, their contract fixture and reader,
and the end-to-end app and its CI job go. getAnonymousVisitorId() stays, moved
next to getAnalyticsSessionId(), with its tests in the anonymous visitor
header suite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@egidijusj egidijusj changed the title feat(sdk): server error capture helpers for full-stack apps feat(sdk): export getAnonymousVisitorId Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant