2022-07-15 09:30:14 -04:00
|
|
|
import validator from 'validator'
|
|
|
|
import { CONSTRAINTS_FIELDS } from '@server/initializers/constants'
|
|
|
|
import { ClientLogLevel, ServerLogLevel } from '@shared/models'
|
2019-04-10 09:26:33 -04:00
|
|
|
import { exists } from './misc'
|
|
|
|
|
2022-07-15 09:30:14 -04:00
|
|
|
const serverLogLevels: Set<ServerLogLevel> = new Set([ 'debug', 'info', 'warn', 'error' ])
|
|
|
|
const clientLogLevels: Set<ClientLogLevel> = new Set([ 'warn', 'error' ])
|
2019-04-10 09:26:33 -04:00
|
|
|
|
|
|
|
function isValidLogLevel (value: any) {
|
2022-07-15 09:30:14 -04:00
|
|
|
return exists(value) && serverLogLevels.has(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isValidClientLogMessage (value: any) {
|
|
|
|
return typeof value === 'string' && validator.isLength(value, CONSTRAINTS_FIELDS.LOGS.CLIENT_MESSAGE)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isValidClientLogLevel (value: any) {
|
|
|
|
return exists(value) && clientLogLevels.has(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isValidClientLogStackTrace (value: any) {
|
|
|
|
return typeof value === 'string' && validator.isLength(value, CONSTRAINTS_FIELDS.LOGS.CLIENT_STACK_TRACE)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isValidClientLogMeta (value: any) {
|
|
|
|
return typeof value === 'string' && validator.isLength(value, CONSTRAINTS_FIELDS.LOGS.CLIENT_META)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isValidClientLogUserAgent (value: any) {
|
|
|
|
return typeof value === 'string' && validator.isLength(value, CONSTRAINTS_FIELDS.LOGS.CLIENT_USER_AGENT)
|
2019-04-10 09:26:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2022-07-15 09:30:14 -04:00
|
|
|
isValidLogLevel,
|
|
|
|
isValidClientLogMessage,
|
|
|
|
isValidClientLogStackTrace,
|
|
|
|
isValidClientLogMeta,
|
|
|
|
isValidClientLogLevel,
|
|
|
|
isValidClientLogUserAgent
|
2019-04-10 09:26:33 -04:00
|
|
|
}
|