Skip to content

fix(appkit): obo logic and api usage#39

Merged
MarioCadenas merged 4 commits intomainfrom
rewrite-obo-logic
Jan 8, 2026
Merged

fix(appkit): obo logic and api usage#39
MarioCadenas merged 4 commits intomainfrom
rewrite-obo-logic

Conversation

@MarioCadenas
Copy link
Copy Markdown
Collaborator

@MarioCadenas MarioCadenas commented Dec 27, 2025

Summary

Introduces a clean asUser(req) API for executing Databricks operations with user credentials. Replaces the middleware-based context management with a declarative pattern.

What Changed

New: plugin.asUser(req).method()` pattern for user-scoped execution.

New: ServiceContext singleton initialized at app startup.

New: ExecutionContext using AsyncLocalStorage for transparent context propagation

Removed: databricksClientMiddleware (no longer needed)

Removed: requiresDatabricksClient plugin flag

Architecture

┌─────────────────────────────────────────────────────────────┐
│                      App Startup                            │
│  • createApp() → ServiceContext.initialize()                  │
│  • Creates service principal WorkspaceClient                │
│  • Fetches warehouseId, workspaceId                         │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                     Request Handling                        │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  Service Principal Path       User Context Path             │
│  ───────────────────────      ─────────────────────────     │
│                                                             │
│  analytics.query(...)         analytics.asUser(req)         │
│         │                            │                      │
│         ▼                            ▼                      │
│  ServiceContext.get()         Creates IUserContext from     │
│         │                     x-forwarded-access-token      │
│         ▼                            │                      │
│  Uses service principal       Returns Proxy that wraps      │
│  WorkspaceClient              methods in AsyncLocalStorage  │
│                                      │                      │
│                                      ▼                      │
│                               .query(...) executes with     │
│                               user's WorkspaceClient        │
│                                                             │
└─────────────────────────────────────────────────────────────┘

Usage

// Service principal (default)
const data = await analytics.query("SELECT ...");

// User context (on behalf of user)
const userData = await analytics.asUser(req).query("SELECT ...");

Frontend

Charts/tables now support asUser prop:

<LineChart queryKey="spend" parameters={params} asUser />

@MarioCadenas MarioCadenas marked this pull request as ready for review January 7, 2026 15:07
@MarioCadenas MarioCadenas requested review from ditadi and pkosiec January 7, 2026 15:07
Copy link
Copy Markdown
Member

@pkosiec pkosiec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - please see those small comments before merge. Thanks!

Comment thread apps/dev-playground/server/index.ts
Comment thread packages/appkit/src/context/service-context.ts Outdated
Comment thread packages/appkit/src/context/service-context.ts Outdated
Comment thread packages/appkit/src/context/service-context.ts Outdated
Comment thread packages/appkit/src/context/execution-context.ts
@MarioCadenas MarioCadenas force-pushed the rewrite-obo-logic branch 2 times, most recently from 428483f to 9c6637a Compare January 8, 2026 14:56
chore: fixup

chore: fixup

chore: fixup

chore: fixup

chore: fixup

chore: fixup
Comment thread packages/appkit/src/index.ts
@MarioCadenas MarioCadenas merged commit 4976b1a into main Jan 8, 2026
4 checks passed
@MarioCadenas MarioCadenas deleted the rewrite-obo-logic branch January 8, 2026 16:47
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.

2 participants