{"version":3,"file":"composite-guard.mjs","sources":["../../../../src/lib/routing/guards/composite-guard.ts"],"sourcesContent":["/**\n * @file Composite Guard\n * @description Combines multiple guards into a single guard with configurable\n * execution strategies. Enables complex access control scenarios.\n *\n * @module @/lib/routing/guards/composite-guard\n *\n * This module provides:\n * - Guard composition (AND/OR logic)\n * - Sequential and parallel execution\n * - Short-circuit evaluation\n * - Guard priority ordering\n * - Result aggregation\n *\n * @example\n * ```typescript\n * import { CompositeGuard, combineGuards, allGuards, anyGuard } from '@/lib/routing/guards/composite-guard';\n *\n * // All guards must pass\n * const restrictedGuard = allGuards([\n *   authGuard,\n *   roleGuard,\n *   featureGuard,\n * ]);\n *\n * // Any guard can pass\n * const flexibleGuard = anyGuard([\n *   adminGuard,\n *   ownerGuard,\n * ]);\n * ```\n */\n\nimport {\n  GuardResult,\n  type GuardContext,\n  type GuardResultObject,\n  type GuardTiming,\n  type RouteGuard,\n  type GuardExecutionResult,\n  mergeGuardResults,\n  getFirstRedirect,\n  getDenialReasons,\n} from './route-guard';\n\n// =============================================================================\n// Types\n// =============================================================================\n\n/**\n * Composite guard execution strategy\n */\nexport type CompositeStrategy =\n  | 'all' // All guards must pass (AND)\n  | 'any' // Any guard can pass (OR)\n  | 'first' // Use first guard result\n  | 'priority' // Execute in priority order\n  | 'sequential' // Execute all in sequence\n  | 'parallel'; // Execute all in parallel\n\n/**\n * Composite guard configuration\n */\nexport interface CompositeGuardConfig {\n  /** Guard name */\n  readonly name?: string;\n  /** Guards to combine */\n  readonly guards: readonly RouteGuard[];\n  /** Execution strategy */\n  readonly strategy?: CompositeStrategy;\n  /** Short-circuit on first failure (for 'all' strategy) */\n  readonly shortCircuit?: boolean;\n  /** Short-circuit on first success (for 'any' strategy) */\n  readonly shortCircuitSuccess?: boolean;\n  /** Custom result merger */\n  readonly mergeResults?: (results: readonly GuardResultObject[]) => GuardResultObject;\n  /** Timeout for parallel execution */\n  readonly timeout?: number;\n  /** Feature flag for this composite guard */\n  readonly featureFlag?: string;\n}\n\n/**\n * Composite guard execution result\n */\nexport interface CompositeExecutionResult {\n  /** Final result */\n  readonly result: GuardResultObject;\n  /** Individual guard results */\n  readonly guardResults: readonly GuardExecutionResult[];\n  /** Total execution time (ms) */\n  readonly totalDurationMs: number;\n  /** Guards that passed */\n  readonly passed: readonly string[];\n  /** Guards that failed */\n  readonly failed: readonly string[];\n  /** Guards that were skipped */\n  readonly skipped: readonly string[];\n  /** Strategy used */\n  readonly strategy: CompositeStrategy;\n}\n\n// =============================================================================\n// Constants\n// =============================================================================\n\n/**\n * Default composite guard configuration\n */\nexport const DEFAULT_COMPOSITE_CONFIG: Partial<CompositeGuardConfig> = {\n  name: 'composite',\n  strategy: 'all',\n  shortCircuit: true,\n  shortCircuitSuccess: true,\n  timeout: 30000,\n};\n\n// =============================================================================\n// CompositeGuard Class\n// =============================================================================\n\n/**\n * Combines multiple guards into one\n *\n * @example\n * ```typescript\n * const guard = new CompositeGuard({\n *   guards: [authGuard, roleGuard, featureGuard],\n *   strategy: 'all',\n *   shortCircuit: true,\n * });\n *\n * const result = await guard.execute('canActivate', context);\n * ```\n */\nexport class CompositeGuard implements RouteGuard {\n  readonly name: string;\n  readonly priority: number;\n  readonly enabled = true;\n  private readonly config: CompositeGuardConfig;\n  private readonly sortedGuards: readonly RouteGuard[];\n\n  constructor(config: CompositeGuardConfig) {\n    const mergedConfig = { ...DEFAULT_COMPOSITE_CONFIG, ...config };\n    this.config = mergedConfig;\n    this.name = mergedConfig.name ?? 'composite';\n    this.priority = Math.min(...config.guards.map((g) => g.priority ?? 100));\n\n    // Sort guards by priority\n    this.sortedGuards = [...config.guards].sort(\n      (a, b) => (a.priority ?? 100) - (b.priority ?? 100)\n    );\n  }\n\n  /**\n   * Execute the composite guard\n   */\n  async execute(timing: GuardTiming, context: GuardContext): Promise<GuardResultObject> {\n    const execResult = await this.executeWithDetails(timing, context);\n    return execResult.result;\n  }\n\n  /**\n   * Execute with detailed results\n   */\n  async executeWithDetails(\n    timing: GuardTiming,\n    context: GuardContext\n  ): Promise<CompositeExecutionResult> {\n    const strategy = this.config.strategy ?? 'all';\n    const startTime = Date.now();\n\n    switch (strategy) {\n      case 'all':\n        return this.executeAll(timing, context, startTime);\n      case 'any':\n        return this.executeAny(timing, context, startTime);\n      case 'first':\n        return this.executeFirst(timing, context, startTime);\n      case 'priority':\n        return this.executePriority(timing, context, startTime);\n      case 'sequential':\n        return this.executeSequential(timing, context, startTime);\n      case 'parallel':\n        return this.executeParallel(timing, context, startTime);\n      default:\n        return this.executeAll(timing, context, startTime);\n    }\n  }\n\n  /**\n   * Check if guard applies to a path\n   */\n  appliesTo(path: string): boolean {\n    return this.sortedGuards.some((g) => g.appliesTo(path));\n  }\n\n  /**\n   * Get all guards in this composite\n   */\n  getGuards(): readonly RouteGuard[] {\n    return this.sortedGuards;\n  }\n\n  /**\n   * Get strategy\n   */\n  getStrategy(): CompositeStrategy {\n    return this.config.strategy ?? 'all';\n  }\n\n  /**\n   * Execute all guards (AND logic)\n   */\n  private async executeAll(\n    timing: GuardTiming,\n    context: GuardContext,\n    startTime: number\n  ): Promise<CompositeExecutionResult> {\n    const guardResults: GuardExecutionResult[] = [];\n    const passed: string[] = [];\n    const failed: string[] = [];\n    const skipped: string[] = [];\n\n    for (const guard of this.sortedGuards) {\n      // Check if guard applies\n      if (!guard.appliesTo(context.path)) {\n        skipped.push(guard.name);\n        continue;\n      }\n\n      const execStart = Date.now();\n      try {\n        const result = await guard.execute(timing, context);\n        const durationMs = Date.now() - execStart;\n\n        guardResults.push({\n          guardName: guard.name,\n          result,\n          durationMs,\n          timedOut: false,\n        });\n\n        if (result.type === 'allow') {\n          passed.push(guard.name);\n        } else {\n          failed.push(guard.name);\n\n          // Short-circuit on failure\n          if (this.config.shortCircuit === true) {\n            return {\n              result,\n              guardResults,\n              totalDurationMs: Date.now() - startTime,\n              passed,\n              failed,\n              skipped: this.sortedGuards\n                .filter(\n                  (g) =>\n                    !passed.includes(g.name) &&\n                    !failed.includes(g.name) &&\n                    !skipped.includes(g.name)\n                )\n                .map((g) => g.name),\n              strategy: 'all',\n            };\n          }\n        }\n      } catch (error) {\n        failed.push(guard.name);\n        guardResults.push({\n          guardName: guard.name,\n          result: GuardResult.deny(`Guard error: ${(error as Error).message}`),\n          durationMs: Date.now() - execStart,\n          timedOut: false,\n          error: error as Error,\n        });\n\n        if (this.config.shortCircuit === true) {\n          return {\n            result: GuardResult.deny(`Guard \"${guard.name}\" failed`),\n            guardResults,\n            totalDurationMs: Date.now() - startTime,\n            passed,\n            failed,\n            skipped,\n            strategy: 'all',\n          };\n        }\n      }\n    }\n\n    // Merge results\n    const results = guardResults.map((gr) => gr.result);\n    const finalResult = this.config.mergeResults\n      ? this.config.mergeResults(results)\n      : mergeGuardResults(results);\n\n    return {\n      result: failed.length === 0 ? GuardResult.allow() : finalResult,\n      guardResults,\n      totalDurationMs: Date.now() - startTime,\n      passed,\n      failed,\n      skipped,\n      strategy: 'all',\n    };\n  }\n\n  /**\n   * Execute any guard (OR logic)\n   */\n  private async executeAny(\n    timing: GuardTiming,\n    context: GuardContext,\n    startTime: number\n  ): Promise<CompositeExecutionResult> {\n    const guardResults: GuardExecutionResult[] = [];\n    const passed: string[] = [];\n    const failed: string[] = [];\n    const skipped: string[] = [];\n\n    for (const guard of this.sortedGuards) {\n      if (!guard.appliesTo(context.path)) {\n        skipped.push(guard.name);\n        continue;\n      }\n\n      const execStart = Date.now();\n      try {\n        const result = await guard.execute(timing, context);\n        const durationMs = Date.now() - execStart;\n\n        guardResults.push({\n          guardName: guard.name,\n          result,\n          durationMs,\n          timedOut: false,\n        });\n\n        if (result.type === 'allow') {\n          passed.push(guard.name);\n\n          // Short-circuit on success\n          if (this.config.shortCircuitSuccess === true) {\n            return {\n              result: GuardResult.allow(),\n              guardResults,\n              totalDurationMs: Date.now() - startTime,\n              passed,\n              failed,\n              skipped: this.sortedGuards\n                .filter(\n                  (g) =>\n                    !passed.includes(g.name) &&\n                    !failed.includes(g.name) &&\n                    !skipped.includes(g.name)\n                )\n                .map((g) => g.name),\n              strategy: 'any',\n            };\n          }\n        } else {\n          failed.push(guard.name);\n        }\n      } catch (error) {\n        failed.push(guard.name);\n        guardResults.push({\n          guardName: guard.name,\n          result: GuardResult.deny(`Guard error: ${(error as Error).message}`),\n          durationMs: Date.now() - execStart,\n          timedOut: false,\n          error: error as Error,\n        });\n      }\n    }\n\n    // For 'any', allow if any passed\n    let finalResult: GuardResultObject;\n    if (passed.length > 0) {\n      finalResult = GuardResult.allow();\n    } else if (this.config.mergeResults) {\n      finalResult = this.config.mergeResults(guardResults.map((gr) => gr.result));\n    } else {\n      finalResult =\n        getFirstRedirect(guardResults.map((gr) => gr.result)) ??\n        GuardResult.deny(getDenialReasons(guardResults.map((gr) => gr.result)).join('; '));\n    }\n\n    return {\n      result: finalResult,\n      guardResults,\n      totalDurationMs: Date.now() - startTime,\n      passed,\n      failed,\n      skipped,\n      strategy: 'any',\n    };\n  }\n\n  /**\n   * Execute first matching guard\n   */\n  private async executeFirst(\n    timing: GuardTiming,\n    context: GuardContext,\n    startTime: number\n  ): Promise<CompositeExecutionResult> {\n    for (const guard of this.sortedGuards) {\n      if (!guard.appliesTo(context.path)) {\n        continue;\n      }\n\n      const execStart = Date.now();\n      const result = await guard.execute(timing, context);\n\n      return {\n        result,\n        guardResults: [\n          {\n            guardName: guard.name,\n            result,\n            durationMs: Date.now() - execStart,\n            timedOut: false,\n          },\n        ],\n        totalDurationMs: Date.now() - startTime,\n        passed: result.type === 'allow' ? [guard.name] : [],\n        failed: result.type !== 'allow' ? [guard.name] : [],\n        skipped: this.sortedGuards.filter((g) => g.name !== guard.name).map((g) => g.name),\n        strategy: 'first',\n      };\n    }\n\n    // No applicable guards\n    return {\n      result: GuardResult.allow(),\n      guardResults: [],\n      totalDurationMs: Date.now() - startTime,\n      passed: [],\n      failed: [],\n      skipped: this.sortedGuards.map((g) => g.name),\n      strategy: 'first',\n    };\n  }\n\n  /**\n   * Execute in priority order (same as sequential for sorted guards)\n   */\n  private async executePriority(\n    timing: GuardTiming,\n    context: GuardContext,\n    startTime: number\n  ): Promise<CompositeExecutionResult> {\n    return this.executeSequential(timing, context, startTime);\n  }\n\n  /**\n   * Execute all guards sequentially\n   */\n  private async executeSequential(\n    timing: GuardTiming,\n    context: GuardContext,\n    startTime: number\n  ): Promise<CompositeExecutionResult> {\n    const guardResults: GuardExecutionResult[] = [];\n    const passed: string[] = [];\n    const failed: string[] = [];\n    const skipped: string[] = [];\n\n    for (const guard of this.sortedGuards) {\n      if (!guard.appliesTo(context.path)) {\n        skipped.push(guard.name);\n        continue;\n      }\n\n      const execStart = Date.now();\n      try {\n        const result = await guard.execute(timing, context);\n        const durationMs = Date.now() - execStart;\n\n        guardResults.push({\n          guardName: guard.name,\n          result,\n          durationMs,\n          timedOut: false,\n        });\n\n        if (result.type === 'allow') {\n          passed.push(guard.name);\n        } else {\n          failed.push(guard.name);\n        }\n      } catch (error) {\n        failed.push(guard.name);\n        guardResults.push({\n          guardName: guard.name,\n          result: GuardResult.deny(`Guard error: ${(error as Error).message}`),\n          durationMs: Date.now() - execStart,\n          timedOut: false,\n          error: error as Error,\n        });\n      }\n    }\n\n    const results = guardResults.map((gr) => gr.result);\n    const finalResult = this.config.mergeResults\n      ? this.config.mergeResults(results)\n      : mergeGuardResults(results);\n\n    return {\n      result: finalResult,\n      guardResults,\n      totalDurationMs: Date.now() - startTime,\n      passed,\n      failed,\n      skipped,\n      strategy: 'sequential',\n    };\n  }\n\n  /**\n   * Execute all guards in parallel\n   */\n  private async executeParallel(\n    timing: GuardTiming,\n    context: GuardContext,\n    startTime: number\n  ): Promise<CompositeExecutionResult> {\n    const applicableGuards = this.sortedGuards.filter((g) => g.appliesTo(context.path));\n    const skipped = this.sortedGuards\n      .filter((g) => !applicableGuards.includes(g))\n      .map((g) => g.name);\n\n    const timeout = this.config.timeout ?? 30000;\n\n    const execPromises = applicableGuards.map(async (guard): Promise<GuardExecutionResult> => {\n      const execStart = Date.now();\n      try {\n        const result = await Promise.race([\n          guard.execute(timing, context),\n          new Promise<GuardResultObject>((_, reject) =>\n            setTimeout(() => reject(new Error('Timeout')), timeout)\n          ),\n        ]);\n\n        return {\n          guardName: guard.name,\n          result,\n          durationMs: Date.now() - execStart,\n          timedOut: false,\n        };\n      } catch (error) {\n        const isTimeout = (error as Error).message === 'Timeout';\n        return {\n          guardName: guard.name,\n          result: GuardResult.deny(isTimeout ? 'Guard timed out' : (error as Error).message),\n          durationMs: Date.now() - execStart,\n          timedOut: isTimeout,\n          error: error as Error,\n        };\n      }\n    });\n\n    const guardResults = await Promise.all(execPromises);\n    const passed = guardResults\n      .filter((gr) => gr.result.type === 'allow')\n      .map((gr) => gr.guardName);\n    const failed = guardResults\n      .filter((gr) => gr.result.type !== 'allow')\n      .map((gr) => gr.guardName);\n\n    const results = guardResults.map((gr) => gr.result);\n    const finalResult = this.config.mergeResults\n      ? this.config.mergeResults(results)\n      : mergeGuardResults(results);\n\n    return {\n      result: finalResult,\n      guardResults,\n      totalDurationMs: Date.now() - startTime,\n      passed,\n      failed,\n      skipped,\n      strategy: 'parallel',\n    };\n  }\n}\n\n// =============================================================================\n// Factory Functions\n// =============================================================================\n\n/**\n * Create a composite guard\n *\n * @param config - Composite guard configuration\n * @returns CompositeGuard instance\n */\nexport function createCompositeGuard(config: CompositeGuardConfig): CompositeGuard {\n  return new CompositeGuard(config);\n}\n\n/**\n * Combine guards with AND logic (all must pass)\n *\n * @param guards - Guards to combine\n * @param options - Additional options\n * @returns CompositeGuard instance\n */\nexport function allGuards(\n  guards: readonly RouteGuard[],\n  options: Partial<Omit<CompositeGuardConfig, 'guards' | 'strategy'>> = {}\n): CompositeGuard {\n  return new CompositeGuard({\n    ...options,\n    guards,\n    strategy: 'all',\n  });\n}\n\n/**\n * Combine guards with OR logic (any can pass)\n *\n * @param guards - Guards to combine\n * @param options - Additional options\n * @returns CompositeGuard instance\n */\nexport function anyGuard(\n  guards: readonly RouteGuard[],\n  options: Partial<Omit<CompositeGuardConfig, 'guards' | 'strategy'>> = {}\n): CompositeGuard {\n  return new CompositeGuard({\n    ...options,\n    guards,\n    strategy: 'any',\n  });\n}\n\n/**\n * Combine guards for sequential execution\n *\n * @param guards - Guards to execute in order\n * @param options - Additional options\n * @returns CompositeGuard instance\n */\nexport function sequentialGuards(\n  guards: readonly RouteGuard[],\n  options: Partial<Omit<CompositeGuardConfig, 'guards' | 'strategy'>> = {}\n): CompositeGuard {\n  return new CompositeGuard({\n    ...options,\n    guards,\n    strategy: 'sequential',\n  });\n}\n\n/**\n * Combine guards for parallel execution\n *\n * @param guards - Guards to execute in parallel\n * @param options - Additional options\n * @returns CompositeGuard instance\n */\nexport function parallelGuards(\n  guards: readonly RouteGuard[],\n  options: Partial<Omit<CompositeGuardConfig, 'guards' | 'strategy'>> = {}\n): CompositeGuard {\n  return new CompositeGuard({\n    ...options,\n    guards,\n    strategy: 'parallel',\n  });\n}\n\n/**\n * Alias for allGuards\n */\nexport const combineGuards = allGuards;\n\n// =============================================================================\n// Type Guards\n// =============================================================================\n\n/**\n * Type guard for CompositeGuard\n */\nexport function isCompositeGuard(value: unknown): value is CompositeGuard {\n  return value instanceof CompositeGuard;\n}\n\n/**\n * Type guard for CompositeExecutionResult\n */\nexport function isCompositeExecutionResult(value: unknown): value is CompositeExecutionResult {\n  return (\n    typeof value === 'object' &&\n    value !== null &&\n    'result' in value &&\n    'guardResults' in value &&\n    'strategy' in value &&\n    'passed' in value &&\n    'failed' in value\n  );\n}\n"],"names":["DEFAULT_COMPOSITE_CONFIG","CompositeGuard","config","mergedConfig","g","a","b","timing","context","strategy","startTime","path","guardResults","passed","failed","skipped","guard","execStart","result","durationMs","error","GuardResult","results","gr","finalResult","mergeGuardResults","getFirstRedirect","getDenialReasons","applicableGuards","timeout","execPromises","_","reject","isTimeout","createCompositeGuard","allGuards","guards","options","anyGuard","sequentialGuards","parallelGuards","combineGuards","isCompositeGuard","value","isCompositeExecutionResult"],"mappings":";AA6GO,MAAMA,IAA0D;AAA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