const { schema } = require('@bugsnag/core/config')
const { reduce } = require('@bugsnag/core/lib/es-utils')
const { stringWithLength } = require('@bugsnag/core/lib/validators')
const os = require('os')
const process = require('process')

module.exports = {
  projectRoot: {
    defaultValue: () => process.cwd(),
    validate: value => value === null || stringWithLength(value),
    message: 'should be string'
  },
  hostname: {
    defaultValue: () => os.hostname(),
    message: 'should be a string',
    validate: value => value === null || stringWithLength(value)
  },
  logger: {
    ...schema.logger,
    defaultValue: () => getPrefixedConsole()
  },
  releaseStage: {
    ...schema.releaseStage,
    defaultValue: () => process.env.NODE_ENV || 'production'
  },
  agent: {
    defaultValue: () => undefined,
    message: 'should be an HTTP(s) agent',
    validate: value => value === undefined || isObject(value)
  },
  onUncaughtException: {
    defaultValue: () => (err, report, logger) => {
      logger.error(`Reported an uncaught exception${getContext(report)}, the process will now terminate…\n${(err && err.stack) ? err.stack : err}`)
      process.exit(1)
    },
    message: 'should be a function',
    validate: value => typeof value === 'function'
  },
  onUnhandledRejection: {
    defaultValue: () => (err, report, logger) => {
      logger.error(`Reported an unhandled rejection${getContext(report)}…\n${(err && err.stack) ? err.stack : err}`)
    },
    message: 'should be a function',
    validate: value => typeof value === 'function'
  }
}

const getPrefixedConsole = () => {
  return reduce([ 'debug', 'info', 'warn', 'error' ], (accum, method) => {
    const consoleMethod = console[method] || console.log
    accum[method] = consoleMethod.bind(console, '[bugsnag]')
    return accum
  }, {})
}

const getContext = report =>
  report.request && Object.keys(report.request).length
    ? ` at ${report.request.httpMethod} ${report.request.path || report.request.url}`
    : ``

const isObject = value => typeof value === 'object' && value !== null

@@ -900,21 +900,20 @@
 ed %7C%7C is
-Objec
+Agen
 t(value)
@@ -2005,21 +2005,20 @@
 const is
-Objec
+Agen
 t = valu
@@ -2014,32 +2014,33 @@
 gent = value =%3E 
+(
 typeof value ===
@@ -2066,9 +2066,40 @@
 !== null
+) %7C%7C typeof value === 'boolean'
 %0A

Allow boolean values in `agent` config