Skip to content

Commit 4976b1a

Browse files
authored
fix(appkit): obo logic and api usage (#39)
1 parent d29a3d2 commit 4976b1a

50 files changed

Lines changed: 1159 additions & 751 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/dev-playground/client/src/routes/analytics.route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function AnalyticsRoute() {
6969
data: untaggedAppsData,
7070
loading: untaggedAppsLoading,
7171
error: untaggedAppsError,
72-
} = useAnalyticsQuery("untagged_apps", untaggedAppsParams);
72+
} = useAnalyticsQuery("untagged_apps", untaggedAppsParams, { asUser: true });
7373

7474
const metrics = useMemo(() => {
7575
if (!summaryDataRaw || summaryDataRaw.length === 0) {

apps/dev-playground/client/src/routes/arrow-analytics.route.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ function ArrowAnalyticsRoute() {
5454

5555
<main className="max-w-7xl mx-auto px-6 py-12">
5656
<div className="flex flex-col gap-6">
57-
{/* ============================================================ */}
58-
{/* UNIFIED CHARTS - FORMAT COMPARISON */}
59-
{/* ============================================================ */}
6057
<div>
6158
<h2 className="text-2xl font-bold mb-4">Unified Charts API</h2>
6259
<p className="text-muted-foreground mb-6">

apps/dev-playground/server/index.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,49 @@ import { reconnect } from "./reconnect-plugin";
33
import { telemetryExamples } from "./telemetry-example-plugin";
44

55
createApp({
6-
plugins: [server(), reconnect(), telemetryExamples(), analytics({})],
6+
plugins: [
7+
server({ autoStart: false }),
8+
reconnect(),
9+
telemetryExamples(),
10+
analytics({}),
11+
],
12+
}).then((appkit) => {
13+
appkit.server
14+
.extend((app) => {
15+
app.get("/sp", (_req, res) => {
16+
appkit.analytics
17+
.query("SELECT * FROM samples.nyctaxi.trips;")
18+
.then((result) => {
19+
console.log(result[0]);
20+
res.json(result);
21+
})
22+
.catch((error) => {
23+
console.error("Error:", error);
24+
res.status(500).json({
25+
error: error.message,
26+
errorCode: error.errorCode,
27+
statusCode: error.statusCode,
28+
});
29+
});
30+
});
31+
32+
app.get("/obo", (req, res) => {
33+
appkit.analytics
34+
.asUser(req)
35+
.query("SELECT * FROM samples.nyctaxi.trips;")
36+
.then((result) => {
37+
console.log(result[0]);
38+
res.json(result);
39+
})
40+
.catch((error) => {
41+
console.error("OBO Error:", error);
42+
res.status(500).json({
43+
error: error.message,
44+
errorCode: error.errorCode,
45+
statusCode: error.statusCode,
46+
});
47+
});
48+
});
49+
})
50+
.start();
751
});

docs/docs/api/appkit/Class.Plugin.md

Lines changed: 76 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Abstract Class: Plugin\<TConfig\>
22

3-
Defined in: [appkit/src/plugin/plugin.ts:33](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L33)
3+
Defined in: [appkit/src/plugin/plugin.ts:58](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L58)
44

55
## Type Parameters
66

@@ -20,7 +20,7 @@ Defined in: [appkit/src/plugin/plugin.ts:33](https://github.com/databricks/appki
2020
new Plugin<TConfig>(config: TConfig): Plugin<TConfig>;
2121
```
2222

23-
Defined in: [appkit/src/plugin/plugin.ts:54](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L54)
23+
Defined in: [appkit/src/plugin/plugin.ts:76](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L76)
2424

2525
#### Parameters
2626

@@ -40,7 +40,7 @@ Defined in: [appkit/src/plugin/plugin.ts:54](https://github.com/databricks/appki
4040
protected app: AppManager;
4141
```
4242

43-
Defined in: [appkit/src/plugin/plugin.ts:39](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L39)
43+
Defined in: [appkit/src/plugin/plugin.ts:64](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L64)
4444

4545
***
4646

@@ -50,7 +50,7 @@ Defined in: [appkit/src/plugin/plugin.ts:39](https://github.com/databricks/appki
5050
protected cache: CacheManager;
5151
```
5252

53-
Defined in: [appkit/src/plugin/plugin.ts:38](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L38)
53+
Defined in: [appkit/src/plugin/plugin.ts:63](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L63)
5454

5555
***
5656

@@ -60,7 +60,7 @@ Defined in: [appkit/src/plugin/plugin.ts:38](https://github.com/databricks/appki
6060
protected config: TConfig;
6161
```
6262

63-
Defined in: [appkit/src/plugin/plugin.ts:54](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L54)
63+
Defined in: [appkit/src/plugin/plugin.ts:76](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L76)
6464

6565
***
6666

@@ -70,7 +70,7 @@ Defined in: [appkit/src/plugin/plugin.ts:54](https://github.com/databricks/appki
7070
protected devFileReader: DevFileReader;
7171
```
7272

73-
Defined in: [appkit/src/plugin/plugin.ts:40](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L40)
73+
Defined in: [appkit/src/plugin/plugin.ts:65](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L65)
7474

7575
***
7676

@@ -80,7 +80,7 @@ Defined in: [appkit/src/plugin/plugin.ts:40](https://github.com/databricks/appki
8080
abstract protected envVars: string[];
8181
```
8282

83-
Defined in: [appkit/src/plugin/plugin.ts:43](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L43)
83+
Defined in: [appkit/src/plugin/plugin.ts:68](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L68)
8484

8585
***
8686

@@ -90,7 +90,7 @@ Defined in: [appkit/src/plugin/plugin.ts:43](https://github.com/databricks/appki
9090
protected isReady: boolean = false;
9191
```
9292

93-
Defined in: [appkit/src/plugin/plugin.ts:37](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L37)
93+
Defined in: [appkit/src/plugin/plugin.ts:62](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L62)
9494

9595
***
9696

@@ -100,7 +100,7 @@ Defined in: [appkit/src/plugin/plugin.ts:37](https://github.com/databricks/appki
100100
name: string;
101101
```
102102

103-
Defined in: [appkit/src/plugin/plugin.ts:52](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L52)
103+
Defined in: [appkit/src/plugin/plugin.ts:74](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L74)
104104

105105
#### Implementation of
106106

@@ -110,25 +110,13 @@ BasePlugin.name
110110

111111
***
112112

113-
### requiresDatabricksClient
114-
115-
```ts
116-
requiresDatabricksClient: boolean = false;
117-
```
118-
119-
Defined in: [appkit/src/plugin/plugin.ts:46](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L46)
120-
121-
If the plugin requires the Databricks client to be set in the request context
122-
123-
***
124-
125113
### streamManager
126114

127115
```ts
128116
protected streamManager: StreamManager;
129117
```
130118

131-
Defined in: [appkit/src/plugin/plugin.ts:41](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L41)
119+
Defined in: [appkit/src/plugin/plugin.ts:66](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L66)
132120

133121
***
134122

@@ -138,7 +126,7 @@ Defined in: [appkit/src/plugin/plugin.ts:41](https://github.com/databricks/appki
138126
protected telemetry: ITelemetry;
139127
```
140128

141-
Defined in: [appkit/src/plugin/plugin.ts:42](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L42)
129+
Defined in: [appkit/src/plugin/plugin.ts:67](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L67)
142130

143131
***
144132

@@ -148,7 +136,7 @@ Defined in: [appkit/src/plugin/plugin.ts:42](https://github.com/databricks/appki
148136
static phase: PluginPhase = "normal";
149137
```
150138

151-
Defined in: [appkit/src/plugin/plugin.ts:51](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L51)
139+
Defined in: [appkit/src/plugin/plugin.ts:73](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L73)
152140

153141
## Methods
154142

@@ -158,7 +146,7 @@ Defined in: [appkit/src/plugin/plugin.ts:51](https://github.com/databricks/appki
158146
abortActiveOperations(): void;
159147
```
160148

161-
Defined in: [appkit/src/plugin/plugin.ts:79](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L79)
149+
Defined in: [appkit/src/plugin/plugin.ts:101](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L101)
162150

163151
#### Returns
164152

@@ -172,16 +160,67 @@ BasePlugin.abortActiveOperations
172160

173161
***
174162

163+
### asUser()
164+
165+
```ts
166+
asUser(req: Request): this;
167+
```
168+
169+
Defined in: [appkit/src/plugin/plugin.ts:134](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L134)
170+
171+
Execute operations using the user's identity from the request.
172+
173+
Returns a scoped instance of this plugin where all method calls
174+
will execute with the user's Databricks credentials instead of
175+
the service principal.
176+
177+
#### Parameters
178+
179+
| Parameter | Type | Description |
180+
| ------ | ------ | ------ |
181+
| `req` | `Request` | The Express request containing the user token in headers |
182+
183+
#### Returns
184+
185+
`this`
186+
187+
A scoped plugin instance that executes as the user
188+
189+
#### Throws
190+
191+
Error if user token is not available in request headers
192+
193+
#### Example
194+
195+
```typescript
196+
// In route handler - execute query as the requesting user
197+
router.post('/users/me/query/:key', async (req, res) => {
198+
const result = await this.asUser(req).query(req.params.key)
199+
res.json(result)
200+
})
201+
202+
// Mixed execution in same handler
203+
router.post('/dashboard', async (req, res) => {
204+
const [systemData, userData] = await Promise.all([
205+
this.getSystemStats(), // Service principal
206+
this.asUser(req).getUserPreferences(), // User context
207+
])
208+
res.json({ systemData, userData })
209+
})
210+
```
211+
212+
***
213+
175214
### execute()
176215

177216
```ts
178217
protected execute<T>(
179218
fn: (signal?: AbortSignal) => Promise<T>,
180219
options: PluginExecutionSettings,
181-
userKey: string): Promise<T | undefined>;
220+
userKey?: string): Promise<T | undefined>;
182221
```
183222

184-
Defined in: [appkit/src/plugin/plugin.ts:143](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L143)
223+
Defined in: [appkit/src/plugin/plugin.ts:263](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L263)
185224

186225
#### Type Parameters
187226

@@ -195,7 +234,7 @@ Defined in: [appkit/src/plugin/plugin.ts:143](https://github.com/databricks/appk
195234
| ------ | ------ |
196235
| `fn` | (`signal?`: `AbortSignal`) => `Promise`\<`T`\> |
197236
| `options` | `PluginExecutionSettings` |
198-
| `userKey` | `string` |
237+
| `userKey?` | `string` |
199238

200239
#### Returns
201240

@@ -210,10 +249,10 @@ protected executeStream<T>(
210249
res: IAppResponse,
211250
fn: StreamExecuteHandler<T>,
212251
options: StreamExecutionSettings,
213-
userKey: string): Promise<void>;
252+
userKey?: string): Promise<void>;
214253
```
215254

216-
Defined in: [appkit/src/plugin/plugin.ts:84](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L84)
255+
Defined in: [appkit/src/plugin/plugin.ts:201](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L201)
217256

218257
#### Type Parameters
219258

@@ -228,7 +267,7 @@ Defined in: [appkit/src/plugin/plugin.ts:84](https://github.com/databricks/appki
228267
| `res` | `IAppResponse` |
229268
| `fn` | `StreamExecuteHandler`\<`T`\> |
230269
| `options` | [`StreamExecutionSettings`](Interface.StreamExecutionSettings.md) |
231-
| `userKey` | `string` |
270+
| `userKey?` | `string` |
232271

233272
#### Returns
234273

@@ -242,7 +281,7 @@ Defined in: [appkit/src/plugin/plugin.ts:84](https://github.com/databricks/appki
242281
getEndpoints(): PluginEndpointMap;
243282
```
244283

245-
Defined in: [appkit/src/plugin/plugin.ts:75](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L75)
284+
Defined in: [appkit/src/plugin/plugin.ts:97](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L97)
246285

247286
#### Returns
248287

@@ -262,7 +301,7 @@ BasePlugin.getEndpoints
262301
injectRoutes(_: Router): void;
263302
```
264303

265-
Defined in: [appkit/src/plugin/plugin.ts:69](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L69)
304+
Defined in: [appkit/src/plugin/plugin.ts:91](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L91)
266305

267306
#### Parameters
268307

@@ -288,7 +327,7 @@ BasePlugin.injectRoutes
288327
protected registerEndpoint(name: string, path: string): void;
289328
```
290329

291-
Defined in: [appkit/src/plugin/plugin.ts:165](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L165)
330+
Defined in: [appkit/src/plugin/plugin.ts:288](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L288)
292331

293332
#### Parameters
294333

@@ -309,7 +348,7 @@ Defined in: [appkit/src/plugin/plugin.ts:165](https://github.com/databricks/appk
309348
protected route<_TResponse>(router: Router, config: RouteConfig): void;
310349
```
311350

312-
Defined in: [appkit/src/plugin/plugin.ts:169](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L169)
351+
Defined in: [appkit/src/plugin/plugin.ts:292](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L292)
313352

314353
#### Type Parameters
315354

@@ -336,7 +375,7 @@ Defined in: [appkit/src/plugin/plugin.ts:169](https://github.com/databricks/appk
336375
setup(): Promise<void>;
337376
```
338377

339-
Defined in: [appkit/src/plugin/plugin.ts:73](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L73)
378+
Defined in: [appkit/src/plugin/plugin.ts:95](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L95)
340379

341380
#### Returns
342381

@@ -356,7 +395,7 @@ BasePlugin.setup
356395
validateEnv(): void;
357396
```
358397

359-
Defined in: [appkit/src/plugin/plugin.ts:65](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L65)
398+
Defined in: [appkit/src/plugin/plugin.ts:87](https://github.com/databricks/appkit/blob/main/packages/appkit/src/plugin/plugin.ts#L87)
360399

361400
#### Returns
362401

docs/docs/api/appkit/Function.createApp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function createApp<T>(config: {
88
}): Promise<PluginMap<T>>;
99
```
1010

11-
Defined in: [appkit/src/core/appkit.ts:127](https://github.com/databricks/appkit/blob/main/packages/appkit/src/core/appkit.ts#L127)
11+
Defined in: [appkit/src/core/appkit.ts:133](https://github.com/databricks/appkit/blob/main/packages/appkit/src/core/appkit.ts#L133)
1212

1313
Bootstraps AppKit with the provided configuration.
1414

docs/docs/api/appkit/Function.getRequestContext.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)