@microsoft/teams.apps
Version:
<p> <a href="https://www.npmjs.com/package/@microsoft/teams.apps" target="_blank"> <img src="https://img.shields.io/npm/v/@microsoft/teams.apps/latest" /> </a> <a href="https://www.npmjs.com/package/@microsoft/teams.apps?activeTab=code
84 lines (83 loc) • 3.37 kB
TypeScript
import { ILogger } from '@microsoft/teams.common';
import { IContainer } from './container';
import { IActivityEvent } from './events';
import { IPlugin, IPluginErrorEvent, IPluginStartEvent, PluginName } from './types';
import { DependencyMetadata } from './types/plugin/decorators/dependency';
import { EventMetadata } from './types/plugin/decorators/event';
export declare function getMetadata(plugin: IPlugin): {
dependencies: DependencyMetadata[];
events: EventMetadata[];
name: string;
version: string;
description?: string;
};
/**
* Hooks the {@link PluginManager} uses to reach back into the owning {@link App}
* when wiring plugin `@Event` handlers. Passing these in (rather than handing the
* manager a reference to `App`) keeps the manager decoupled from the app's
* private internals while preserving the existing event behavior.
*/
export interface IPluginManagerHandlers {
/** route a plugin `@Event('error')` emission into the app's error pipeline */
readonly onError: (event: IPluginErrorEvent) => void | Promise<void>;
/** route a plugin `@Event('activity')` emission into the app's activity pipeline */
readonly onActivity: (event: IActivityEvent) => unknown;
/** emit a plugin `@Event('custom')` event on the app's public event emitter */
readonly emit: (name: string, event: unknown) => void;
}
export interface IPluginManagerOptions {
readonly container: IContainer;
readonly log: ILogger;
readonly handlers: IPluginManagerHandlers;
}
/**
* Owns every plugin concern that used to be scattered across {@link App}:
* the plugin registry, duplicate-name validation, container registration,
* dependency/event injection, and the `onInit`/`onStart`/`onStop` lifecycle.
*
* `App` constructs a `PluginManager`, shares its {@link PluginManager.plugins}
* array with the other collaborators (e.g. `EventManager`, `ActivityProcessor`),
* and delegates lifecycle to it from `initialize`/`start`/`stop`.
*/
export declare class PluginManager<TPlugin extends IPlugin = IPlugin> {
private readonly _plugins;
private readonly container;
private readonly log;
private readonly handlers;
constructor(options: IPluginManagerOptions);
/**
* the registered plugins. Returned as the live array so collaborators that
* capture it (e.g. {@link EventManager}) observe plugins added later.
*/
get plugins(): ReadonlyArray<TPlugin>;
/**
* find the `http` plugin in a raw plugins list, if present. Used during app
* construction to support the deprecated `plugins: [new HttpPlugin()]` path.
*/
static findHttpPlugin<TPlugin extends IPlugin>(plugins: ReadonlyArray<TPlugin>): TPlugin | undefined;
/**
* register a plugin and make it injectable via the container
* @param plugin plugin to add
*/
add(plugin: TPlugin): void;
/**
* get a registered plugin by name
*/
get(name: PluginName): TPlugin | undefined;
/**
* initialize every plugin: inject its dependencies/events then call `onInit`
*/
init(): Promise<void>;
/**
* start every plugin via `onStart`
*/
start(event: IPluginStartEvent): Promise<void>;
/**
* stop every plugin via `onStop`
*/
stop(): Promise<void>;
/**
* inject fields/events into a plugin
*/
private inject;
}