CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
initialConfigValidation.js38 linesDownload Raw Back to lib
1'use strict'2 3const validate = require('./configValidator')4const deepClone = require('rfdc')({ circles: true, proto: false })5const { FST_ERR_INIT_OPTS_INVALID } = require('./errors')6 7function validateInitialConfig (options) {8  const opts = deepClone(options)9 10  if (!validate(opts)) {11    const error = new FST_ERR_INIT_OPTS_INVALID(JSON.stringify(validate.errors.map(e => e.message)))12    error.errors = validate.errors13    throw error14  }15 16  return deepFreezeObject(opts)17}18 19function deepFreezeObject (object) {20  const properties = Object.getOwnPropertyNames(object)21 22  for (const name of properties) {23    const value = object[name]24 25    if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {26      continue27    }28 29    object[name] = value && typeof value === 'object' ? deepFreezeObject(value) : value30  }31 32  return Object.freeze(object)33}34 35module.exports = validateInitialConfig36module.exports.defaultInitOptions = validate.defaultInitOptions37module.exports.utils = { deepFreezeObject }38