import type { Hook } from '@oclif/core'; import type { CartridgeMapping, FindCartridgesOptions } from '../operations/code/cartridges.js'; import type { B2CInstance } from '../instance/index.js'; /** * Extended options for cartridge discovery that includes instance context. */ export interface CartridgeDiscoveryOptions extends FindCartridgesOptions { /** Directory to search for cartridges */ directory: string; /** Code version being deployed to (if known) */ codeVersion?: string; /** B2C instance context (if available) */ instance?: B2CInstance; } /** * Provider interface for custom cartridge discovery. * * Plugins can implement this interface to provide cartridges from custom sources * such as remote Git repos, manifest files, or other locations. * * @example * ```typescript * const manifestProvider: CartridgeProvider = { * name: 'manifest-provider', * priority: 'before', * async findCartridges(options) { * const manifest = JSON.parse(await fs.readFile('cartridges.json', 'utf-8')); * return manifest.cartridges.map(c => ({ * name: c.name, * src: path.resolve(c.path), * dest: c.name, * })); * }, * }; * ``` */ export interface CartridgeProvider { /** Unique name for this provider (used for logging) */ readonly name: string; /** * Priority relative to default provider. * - 'before': Runs first, can provide cartridges that override defaults * - 'after': Runs after defaults, adds additional cartridges */ readonly priority: 'before' | 'after'; /** * Find cartridges from this provider. * * @param options - Discovery options including directory, filters, and instance context * @returns Array of cartridge mappings, or empty array if no cartridges available */ findCartridges(options: CartridgeDiscoveryOptions): Promise; } /** * Transformer interface for modifying cartridge mappings before deployment. * * Transformers run after all providers have contributed cartridges and can * modify paths, rename cartridges, or filter the final list. * * @example * ```typescript * const versioningTransformer: CartridgeTransformer = { * name: 'versioning-transformer', * async transform(cartridges, options) { * // Append version suffix to cartridge names * return cartridges.map(c => ({ * ...c, * dest: `${c.name}_v2`, * })); * }, * }; * ``` */ export interface CartridgeTransformer { /** Unique name for this transformer (used for logging) */ readonly name: string; /** * Transform cartridge mappings before deployment. * * Can modify paths, names, or filter cartridges. * * @param cartridges - Current list of cartridge mappings * @param options - Discovery options for context * @returns Transformed array of cartridge mappings */ transform(cartridges: CartridgeMapping[], options: CartridgeDiscoveryOptions): Promise; } /** * Options passed to the b2c:cartridge-providers hook. */ export interface CartridgeProvidersHookOptions { /** Directory being searched for cartridges */ directory: string; /** Command flags (for context) */ flags?: Record; /** Allow additional properties */ [key: string]: unknown; } /** * Result returned from the b2c:cartridge-providers hook. */ export interface CartridgeProvidersHookResult { /** Cartridge providers to register */ providers?: CartridgeProvider[]; /** Cartridge transformers to register */ transformers?: CartridgeTransformer[]; } /** * Type for the b2c:cartridge-providers hook function. */ export type CartridgeProvidersHook = Hook<'b2c:cartridge-providers'>; /** * Runner that manages cartridge providers and transformers. * * Collects providers from plugins and orchestrates discovery across * all sources with proper priority ordering and deduplication. */ export declare class CartridgeProviderRunner { private providers; private transformers; private logger?; constructor(logger?: { debug: (msg: string) => void; }); /** * Add providers and transformers to the runner. */ addProviders(providers: CartridgeProvider[]): void; /** * Add transformers to the runner. */ addTransformers(transformers: CartridgeTransformer[]): void; /** * Get count of registered providers. */ get providerCount(): number; /** * Get count of registered transformers. */ get transformerCount(): number; /** * Find cartridges using all registered providers and apply transformers. * * @param defaultCartridges - Cartridges from default discovery (SDK findCartridges) * @param options - Discovery options * @returns Final list of cartridge mappings */ findCartridges(defaultCartridges: CartridgeMapping[], options: CartridgeDiscoveryOptions): Promise; }