import type { Logger } from '../logger.js' /** Scoped database access for plugins -- queries are restricted to plugin-owned tables. */ export interface ScopedDatabase { execute(query: unknown): Promise query(tableName: string): unknown } /** Scoped AT Protocol operations (only available if plugin has pds:read or pds:write permission). */ export interface ScopedAtProto { getRecord(did: string, collection: string, rkey: string): Promise putRecord(did: string, collection: string, rkey: string, record: unknown): Promise deleteRecord(did: string, collection: string, rkey: string): Promise } /** Scoped Valkey cache -- keys are auto-prefixed with plugin:: */ export interface ScopedCache { get(key: string): Promise set(key: string, value: string, ttlSeconds?: number): Promise del(key: string): Promise } /** Scoped HTTP client (only available if plugin has http:outbound permission). */ export interface ScopedHttp { fetch(url: string, init?: RequestInit): Promise } /** Read-only access to plugin settings configured by the community admin. */ export interface PluginSettings { get(key: string): unknown getAll(): Record } /** The sandbox API surface provided to every plugin. */ export interface PluginContext { readonly pluginName: string readonly pluginVersion: string readonly db: ScopedDatabase readonly settings: PluginSettings readonly atproto?: ScopedAtProto readonly cache?: ScopedCache readonly http?: ScopedHttp readonly logger: Logger readonly communityDid: string } /** Lifecycle hooks that a plugin can implement. */ export interface PluginHooks { onInstall?(ctx: PluginContext): Promise onUninstall?(ctx: PluginContext): Promise onEnable?(ctx: PluginContext): Promise onDisable?(ctx: PluginContext): Promise onProfileSync?(ctx: PluginContext, userDid: string): Promise } /** A validated plugin ready for initialization. */ export interface LoadedPlugin { name: string displayName: string version: string description: string source: 'core' | 'official' | 'community' | 'experimental' category: string manifest: Record packagePath: string hooks?: PluginHooks routesPath?: string migrationsPath?: string } /** Thrown when a plugin attempts an operation it lacks permission for. */ export class PluginPermissionError extends Error { constructor(pluginName: string, operation: string) { super(`Plugin "${pluginName}" does not have permission for: ${operation}`) this.name = 'PluginPermissionError' } }