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
2020new 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
4040protected 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
5050protected 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
6060protected 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
7070protected 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
8080abstract 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
9090protected 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
100100name : 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
128116protected 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
138126protected 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
148136static 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
158146abortActiveOperations (): 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
178217protected 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
242281getEndpoints (): 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
262301injectRoutes (_ : 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
288327protected 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
309348protected 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
336375setup (): 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
356395validateEnv (): 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
0 commit comments