import { DetailKey } from '@mbc-cqrs-serverless/core'; import { ImportStatusEnum } from '../enum'; import { ZipImportSfnEvent } from '../event/zip-import.sfn.event'; /** * Aggregated row and failure counts from all CSV files in a ZIP import. */ export interface ZipFinalizationResults { totalRows: number; processedRows: number; /** Total number of failed *rows* across all CSV files (row-level granularity). */ failedRows: number; /** Number of CSV master jobs that completed with FAILED status (file-level granularity). * Use this field — not failedRows — to determine the final ZIP-level status. */ csvTaskFailureCount: number; } /** * Context passed to ZIP finalization hooks containing all relevant job information. */ export interface ZipFinalizationContext { /** The original Step Function event */ event: ZipImportSfnEvent; /** The key of the master ZIP job */ masterJobKey: DetailKey; /** Aggregated results from all CSV files */ results: ZipFinalizationResults; /** Final status of the job */ status: ImportStatusEnum; /** The original execution input from Step Functions */ executionInput: any; } /** * Interface for custom hooks that execute after ZIP import processing completes. * Implementations can perform post-processing tasks like moving files to backup, * sending notifications, or updating external systems. * * @example * ```typescript * @Injectable() * export class BackupToS3Hook implements IZipFinalizationHook { * constructor(private readonly s3Service: S3Service) {} * * async execute(context: ZipFinalizationContext): Promise { * const { executionInput } = context * const { bucket, key } = executionInput.parameters * * // Move file to backup location * const backupKey = `backup/${key}` * await this.s3Service.copyObject({ * sourceBucket: bucket, * sourceKey: key, * destinationBucket: bucket, * destinationKey: backupKey, * }) * } * } * ``` */ export interface IZipFinalizationHook { /** * Executes custom logic after ZIP import completes. * Hooks run in parallel and errors are logged without failing the job. * * @param context - Contains event data, masterJobKey, and aggregated results * @returns Promise that resolves when hook completes */ execute(context: ZipFinalizationContext): Promise; }