# Abstract Class: Plugin\<TConfig>

Base abstract class for creating AppKit plugins.

All plugins must declare a static `manifest` property with their metadata and resource requirements. The manifest defines:

* `required` resources: Always needed for the plugin to function
* `optional` resources: May be needed depending on plugin configuration

## Static vs Runtime Resource Requirements[​](#static-vs-runtime-resource-requirements "Direct link to Static vs Runtime Resource Requirements")

The manifest is static and doesn't know the plugin's runtime configuration. For resources that become required based on config options, plugins can implement a static `getResourceRequirements(config)` method.

At runtime, this method is called with the actual config to determine which "optional" resources should be treated as "required".

## Examples[​](#examples "Direct link to Examples")

```typescript
import { Plugin, toPlugin, PluginManifest, ResourceType } from '@databricks/appkit';

const myManifest: PluginManifest = {
  name: 'myPlugin',
  displayName: 'My Plugin',
  description: 'Does something awesome',
  resources: {
    required: [
      { type: ResourceType.SQL_WAREHOUSE, alias: 'warehouse', ... }
    ],
    optional: []
  }
};

class MyPlugin extends Plugin<MyConfig> {
  static manifest = myManifest;
  name = 'myPlugin';
}

```

```typescript
interface MyConfig extends BasePluginConfig {
  enableCaching?: boolean;
}

const myManifest: PluginManifest = {
  name: 'myPlugin',
  resources: {
    required: [
      { type: ResourceType.SQL_WAREHOUSE, alias: 'warehouse', ... }
    ],
    optional: [
      // Database is optional in the static manifest
      { type: ResourceType.DATABASE, alias: 'cache', description: 'Required if caching enabled', ... }
    ]
  }
};

class MyPlugin extends Plugin<MyConfig> {
  static manifest = myManifest;
  name = 'myPlugin';

  // Runtime method: converts optional resources to required based on config
  static getResourceRequirements(config: MyConfig) {
    const resources = [];
    if (config.enableCaching) {
      // When caching is enabled, Database becomes required
      resources.push({
        type: ResourceType.DATABASE,
        alias: 'cache',
        resourceKey: 'database',
        description: 'Cache storage for query results',
        permission: 'CAN_CONNECT_AND_CREATE',
        fields: {
          instance_name: { env: 'DATABRICKS_CACHE_INSTANCE' },
          database_name: { env: 'DATABRICKS_CACHE_DB' },
        },
        required: true  // Mark as required at runtime
      });
    }
    return resources;
  }
}

```

## Type Parameters[​](#type-parameters "Direct link to Type Parameters")

| Type Parameter                                                                                  | Default type                                                                |
| ----------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
| `TConfig` *extends* [`BasePluginConfig`](/appkit/docs/api/appkit/Interface.BasePluginConfig.md) | [`BasePluginConfig`](/appkit/docs/api/appkit/Interface.BasePluginConfig.md) |

## Implements[​](#implements "Direct link to Implements")

* `BasePlugin`

## Constructors[​](#constructors "Direct link to Constructors")

### Constructor[​](#constructor "Direct link to Constructor")

```ts
new Plugin<TConfig>(config: TConfig): Plugin<TConfig>;

```

#### Parameters[​](#parameters "Direct link to Parameters")

| Parameter | Type      |
| --------- | --------- |
| `config`  | `TConfig` |

#### Returns[​](#returns "Direct link to Returns")

`Plugin`<`TConfig`>

## Properties[​](#properties "Direct link to Properties")

### app[​](#app "Direct link to app")

```ts
protected app: AppManager;

```

***

### cache[​](#cache "Direct link to cache")

```ts
protected cache: CacheManager;

```

***

### config[​](#config "Direct link to config")

```ts
protected config: TConfig;

```

***

### devFileReader[​](#devfilereader "Direct link to devFileReader")

```ts
protected devFileReader: DevFileReader;

```

***

### isReady[​](#isready "Direct link to isReady")

```ts
protected isReady: boolean = false;

```

***

### name[​](#name "Direct link to name")

```ts
name: string;

```

Plugin name identifier.

#### Implementation of[​](#implementation-of "Direct link to Implementation of")

```ts
BasePlugin.name

```

***

### streamManager[​](#streammanager "Direct link to streamManager")

```ts
protected streamManager: StreamManager;

```

***

### telemetry[​](#telemetry "Direct link to telemetry")

```ts
protected telemetry: ITelemetry;

```

***

### phase[​](#phase "Direct link to phase")

```ts
static phase: PluginPhase = "normal";

```

Plugin initialization phase.

* 'core': Initialized first (e.g., config plugins)
* 'normal': Initialized second (most plugins)
* 'deferred': Initialized last (e.g., server plugin)

## Methods[​](#methods "Direct link to Methods")

### abortActiveOperations()[​](#abortactiveoperations "Direct link to abortActiveOperations()")

```ts
abortActiveOperations(): void;

```

#### Returns[​](#returns-1 "Direct link to Returns")

`void`

#### Implementation of[​](#implementation-of-1 "Direct link to Implementation of")

```ts
BasePlugin.abortActiveOperations

```

***

### asUser()[​](#asuser "Direct link to asUser()")

```ts
asUser(req: Request): this;

```

Execute operations using the user's identity from the request. Returns a proxy of this plugin where all method calls execute with the user's Databricks credentials instead of the service principal.

#### Parameters[​](#parameters-1 "Direct link to Parameters")

| Parameter | Type      | Description                                              |
| --------- | --------- | -------------------------------------------------------- |
| `req`     | `Request` | The Express request containing the user token in headers |

#### Returns[​](#returns-2 "Direct link to Returns")

`this`

A proxied plugin instance that executes as the user

#### Throws[​](#throws "Direct link to Throws")

Error if user token is not available in request headers

***

### execute()[​](#execute "Direct link to execute()")

```ts
protected execute<T>(
   fn: (signal?: AbortSignal) => Promise<T>, 
   options: PluginExecutionSettings, 
userKey?: string): Promise<T | undefined>;

```

#### Type Parameters[​](#type-parameters-1 "Direct link to Type Parameters")

| Type Parameter |
| -------------- |
| `T`            |

#### Parameters[​](#parameters-2 "Direct link to Parameters")

| Parameter  | Type                                         |
| ---------- | -------------------------------------------- |
| `fn`       | (`signal?`: `AbortSignal`) => `Promise`<`T`> |
| `options`  | `PluginExecutionSettings`                    |
| `userKey?` | `string`                                     |

#### Returns[​](#returns-3 "Direct link to Returns")

`Promise`<`T` | `undefined`>

***

### executeStream()[​](#executestream "Direct link to executeStream()")

```ts
protected executeStream<T>(
   res: IAppResponse, 
   fn: StreamExecuteHandler<T>, 
   options: StreamExecutionSettings, 
userKey?: string): Promise<void>;

```

#### Type Parameters[​](#type-parameters-2 "Direct link to Type Parameters")

| Type Parameter |
| -------------- |
| `T`            |

#### Parameters[​](#parameters-3 "Direct link to Parameters")

| Parameter  | Type                                                                                      |
| ---------- | ----------------------------------------------------------------------------------------- |
| `res`      | `IAppResponse`                                                                            |
| `fn`       | `StreamExecuteHandler`<`T`>                                                               |
| `options`  | [`StreamExecutionSettings`](/appkit/docs/api/appkit/Interface.StreamExecutionSettings.md) |
| `userKey?` | `string`                                                                                  |

#### Returns[​](#returns-4 "Direct link to Returns")

`Promise`<`void`>

***

### exports()[​](#exports "Direct link to exports()")

```ts
exports(): unknown;

```

Returns the public exports for this plugin. Override this to define a custom public API. By default, returns an empty object.

#### Returns[​](#returns-5 "Direct link to Returns")

`unknown`

#### Implementation of[​](#implementation-of-2 "Direct link to Implementation of")

```ts
BasePlugin.exports

```

***

### getEndpoints()[​](#getendpoints "Direct link to getEndpoints()")

```ts
getEndpoints(): PluginEndpointMap;

```

#### Returns[​](#returns-6 "Direct link to Returns")

`PluginEndpointMap`

#### Implementation of[​](#implementation-of-3 "Direct link to Implementation of")

```ts
BasePlugin.getEndpoints

```

***

### injectRoutes()[​](#injectroutes "Direct link to injectRoutes()")

```ts
injectRoutes(_: Router): void;

```

#### Parameters[​](#parameters-4 "Direct link to Parameters")

| Parameter | Type     |
| --------- | -------- |
| `_`       | `Router` |

#### Returns[​](#returns-7 "Direct link to Returns")

`void`

#### Implementation of[​](#implementation-of-4 "Direct link to Implementation of")

```ts
BasePlugin.injectRoutes

```

***

### registerEndpoint()[​](#registerendpoint "Direct link to registerEndpoint()")

```ts
protected registerEndpoint(name: string, path: string): void;

```

#### Parameters[​](#parameters-5 "Direct link to Parameters")

| Parameter | Type     |
| --------- | -------- |
| `name`    | `string` |
| `path`    | `string` |

#### Returns[​](#returns-8 "Direct link to Returns")

`void`

***

### route()[​](#route "Direct link to route()")

```ts
protected route<_TResponse>(router: Router, config: RouteConfig): void;

```

#### Type Parameters[​](#type-parameters-3 "Direct link to Type Parameters")

| Type Parameter |
| -------------- |
| `_TResponse`   |

#### Parameters[​](#parameters-6 "Direct link to Parameters")

| Parameter | Type          |
| --------- | ------------- |
| `router`  | `Router`      |
| `config`  | `RouteConfig` |

#### Returns[​](#returns-9 "Direct link to Returns")

`void`

***

### setup()[​](#setup "Direct link to setup()")

```ts
setup(): Promise<void>;

```

#### Returns[​](#returns-10 "Direct link to Returns")

`Promise`<`void`>

#### Implementation of[​](#implementation-of-5 "Direct link to Implementation of")

```ts
BasePlugin.setup

```
