validate()

in packages/rum-core/src/common/config-service.js [201:251]


  validate(properties = {}) {
    const requiredKeys = ['serviceName', 'serverUrl']
    const allKeys = Object.keys(this.config)
    const errors = {
      missing: [],
      invalid: [],
      unknown: []
    }
    /**
     * Check when required keys are missing or unknown keys found
     */
    Object.keys(properties).forEach(key => {
      if (requiredKeys.indexOf(key) !== -1 && !properties[key]) {
        errors.missing.push(key)
      }

      if (allKeys.indexOf(key) === -1) {
        errors.unknown.push(key)
      }
    })
    /**
     * Invalid values on the config
     */
    if (
      properties.serviceName &&
      !/^[a-zA-Z0-9 _-]+$/.test(properties.serviceName)
    ) {
      errors.invalid.push({
        key: 'serviceName',
        value: properties.serviceName,
        allowed: 'a-z, A-Z, 0-9, _, -, <space>'
      })
    }

    const sampleRate = properties.transactionSampleRate
    if (
      typeof sampleRate !== 'undefined' &&
      (typeof sampleRate !== 'number' ||
        isNaN(sampleRate) ||
        sampleRate < 0 ||
        sampleRate > 1)
    ) {
      errors.invalid.push({
        key: 'transactionSampleRate',
        value: sampleRate,
        allowed: 'Number between 0 and 1'
      })
    }

    return errors
  }