import { i18n } from '@kbn/i18n' ; import { cryptoFactory , LevelLogger } from '../../lib' ; export const decryptJobHeaders = async ( encryptionKey , headers , logger ) : Promise < Record < string , string > > => { try { if ( typeof headers !== 'string' ) { throw new Error ( i18n . translate ( 'xpack.reporting.exportTypes.common.missingJobHeadersErrorMessage' , { defaultMessage : 'Job headers are missing' , } ) ) ; } const crypto = cryptoFactory ( encryptionKey ) ; const decryptedHeaders = ( await crypto . decrypt ( headers ) ) as Record < string , string > ; return decryptedHeaders ; } catch ( err ) { logger . error ( err ) ; throw new Error ( i18n . translate ( 'xpack.reporting.exportTypes.common.failedToDecryptReportJobDataErrorMessage' , { defaultMessage : 'Failed to decrypt report job data. Please ensure that {encryptionKey} is set and re-generate this report. {err}' , values : { encryptionKey : 'xpack.reporting.encryptionKey' , err : err . toString ( ) } , } ) ) ; } } ;