import { ByteSizeValue } from '@kbn/config-schema' ; import { i18n } from '@kbn/i18n' ; import { IUiSettingsClient } from 'kibana/server' ; import { createEscapeValue } from '../../../../../../../src/plugins/data/common' ; import { ReportingConfig } from '../../../' ; import { CSV_BOM_CHARS , UI_SETTINGS_CSV_QUOTE_VALUES , UI_SETTINGS_CSV_SEPARATOR , UI_SETTINGS_DATEFORMAT_TZ , UI_SETTINGS_SEARCH_INCLUDE_FROZEN , } from '../../../../common/constants' ; import { LevelLogger } from '../../../lib' ; export interface CsvExportSettings { timezone : string ; scroll : { size : number ; duration : string ; } ; bom : string ; separator : string ; maxSizeBytes : number | ByteSizeValue ; checkForFormulas : boolean ; escapeFormulaValues : boolean ; escapeValue : ( value : string ) => string ; includeFrozen : boolean ; } export const getExportSettings = async ( client , config , timezone , logger ) : Promise < CsvExportSettings > => { let setTimezone ; if ( timezone ) { setTimezone = timezone ; } else { setTimezone = await client . get ( UI_SETTINGS_DATEFORMAT_TZ ) ; if ( setTimezone === 'Browser' ) { logger . warn ( i18n . translate ( 'xpack.reporting.exportTypes.csv.executeJob.dateFormateSetting' , { defaultMessage : 'Kibana Advanced Setting "{dateFormatTimezone}" is set to "Browser". Dates will be formatted as UTC to avoid ambiguity.' , values : { dateFormatTimezone : 'dateFormat:tz' } , } ) ) ; setTimezone = 'UTC' ; } } const [ includeFrozen , separator , quoteValues ] = await Promise . all ( [ client . get ( UI_SETTINGS_SEARCH_INCLUDE_FROZEN ) , client . get ( UI_SETTINGS_CSV_SEPARATOR ) , client . get ( UI_SETTINGS_CSV_QUOTE_VALUES ) , ] ) ; const escapeFormulaValues = config . get ( 'csv' , 'escapeFormulaValues' ) ; const escapeValue = createEscapeValue ( quoteValues , escapeFormulaValues ) ; const bom = config . get ( 'csv' , 'useByteOrderMarkEncoding' ) ? CSV_BOM_CHARS : '' ; return { timezone : setTimezone , scroll : { size : config . get ( 'csv' , 'scroll' , 'size' ) , duration : config . get ( 'csv' , 'scroll' , 'duration' ) , } , bom , includeFrozen , separator , maxSizeBytes : config . get ( 'csv' , 'maxSizeBytes' ) , checkForFormulas : config . get ( 'csv' , 'checkForFormulas' ) , escapeFormulaValues , escapeValue , } ; } ;