11import { AsyncLocalStorage } from "node:async_hooks" ;
2- import { type sql , WorkspaceClient } from "@databricks/sdk-experimental" ;
2+ import {
3+ type ClientOptions ,
4+ type ConfigOptions ,
5+ type sql ,
6+ WorkspaceClient ,
7+ } from "@databricks/sdk-experimental" ;
38import type express from "express" ;
9+ import { version } from "../../package.json" ;
410
511export type RequestContext = {
612 userDatabricksClient ?: WorkspaceClient ;
@@ -14,9 +20,17 @@ export type RequestContext = {
1420
1521const asyncLocalStorage = new AsyncLocalStorage < RequestContext > ( ) ;
1622
17- export async function databricksClientMiddleware ( ) : Promise < express . RequestHandler > {
18- const serviceDatabricksClient = new WorkspaceClient ( { } ) ;
23+ function getClientOptions ( ) : ClientOptions {
24+ const isDev = process . env . NODE_ENV === "development" ;
25+ return {
26+ product : "appkit" ,
27+ productVersion : version as ClientOptions [ "productVersion" ] ,
28+ ...( isDev && { userAgentExtra : { mode : "dev" } } ) ,
29+ } ;
30+ }
1931
32+ export async function databricksClientMiddleware ( ) : Promise < express . RequestHandler > {
33+ const serviceDatabricksClient = new WorkspaceClient ( { } , getClientOptions ( ) ) ;
2034 const warehouseId = getWarehouseId ( serviceDatabricksClient ) ;
2135 const workspaceId = getWorkspaceId ( serviceDatabricksClient ) ;
2236 const serviceUserId = ( await serviceDatabricksClient . currentUser . me ( ) ) . id ;
@@ -34,11 +48,14 @@ export async function databricksClientMiddleware(): Promise<express.RequestHandl
3448 let userDatabricksClient : WorkspaceClient | undefined ;
3549 const host = process . env . DATABRICKS_HOST ;
3650 if ( userToken && host ) {
37- userDatabricksClient = new WorkspaceClient ( {
38- token : userToken ,
39- host,
40- authType : "pat" ,
41- } ) ;
51+ userDatabricksClient = new WorkspaceClient (
52+ {
53+ token : userToken ,
54+ host,
55+ authType : "pat" ,
56+ } ,
57+ getClientOptions ( ) ,
58+ ) ;
4259 } else if ( process . env . NODE_ENV === "development" ) {
4360 // in local development service and no user token are the same
4461 // TODO: use `databricks apps run-local` to fix this
0 commit comments