diff --git a/.eslintrc.json b/.eslintrc.json index d81ce6d5..cabb9306 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -8,7 +8,7 @@ "jsx": false, "modules": false }, - "ecmaVersion": 2017 + "ecmaVersion": 2018 }, "plugins": ["promise"], "rules": { diff --git a/lib/tasks/dial.js b/lib/tasks/dial.js index d4570474..60ef5c5b 100644 --- a/lib/tasks/dial.js +++ b/lib/tasks/dial.js @@ -328,6 +328,7 @@ class TaskDial extends Task { if (this.results.dialCallStatus !== CallStatus.Completed) { Object.assign(this.results, { dialCallStatus: obj.callStatus, + dialSipStatus: obj.sipStatus, dialCallSid: sd.callSid, }); } @@ -436,6 +437,7 @@ class TaskDial extends Task { Object.assign(this.results, { dialCallStatus: CallStatus.Completed, + dialSipStatus: 200, dialCallSid: sd.callSid, }); diff --git a/lib/utils/requestor.js b/lib/utils/requestor.js index 91a9edcc..a1a7e009 100644 --- a/lib/utils/requestor.js +++ b/lib/utils/requestor.js @@ -1,7 +1,7 @@ const bent = require('bent'); const parseUrl = require('parse-url'); const assert = require('assert'); -const snakeCaseKeys = require('snakecase-keys'); +const snakeCaseKeys = require('./snakecase-keys'); const toBase64 = (str) => Buffer.from(str || '', 'utf8').toString('base64'); function basicAuth(username, password) { @@ -62,7 +62,7 @@ class Requestor { * @param {object} [params] - request parameters */ async request(hook, params) { - const payload = params ? snakeCaseKeys(params, {exclude: ['customerData', 'sip']}) : null; + const payload = params ? snakeCaseKeys(params, ['customerData', 'sip']) : null; const url = hook.url || hook; const method = hook.method || 'POST'; const {username, password} = typeof hook === 'object' ? hook : {}; diff --git a/lib/utils/snakecase-keys.js b/lib/utils/snakecase-keys.js new file mode 100644 index 00000000..3ce9bc25 --- /dev/null +++ b/lib/utils/snakecase-keys.js @@ -0,0 +1,22 @@ +const snakeCase = require('to-snake-case'); + +const isObject = (value) => typeof value === 'object' && value !== null; + +const snakeObject = (obj, excludes) => { + const target = {}; + + for (const [key, value] of Object.entries(obj)) { + if (excludes.includes(key)) { + target[key] = value; + continue; + } + const newKey = snakeCase(key); + const newValue = isObject(value) ? snakeObject(value, excludes) : value; + target[newKey] = newValue; + } + return target; +}; + +module.exports = (obj, excludes = []) => { + return snakeObject(obj, excludes); +}; diff --git a/package-lock.json b/package-lock.json index 7392e173..fb086b56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,10 +21,11 @@ "drachtio-srf": "^4.4.48", "express": "^4.17.1", "ip": "^1.1.5", + "map-obj": "^4.2.1", "moment": "^2.29.1", "parse-url": "^5.0.2", "pino": "^6.11.1", - "snakecase-keys": "^3.2.1", + "to-snake-case": "^1.0.0", "uuid": "^8.3.2", "verify-aws-sns-signature": "^0.0.6", "xml2js": "^0.4.23" @@ -4269,18 +4270,6 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, - "node_modules/snakecase-keys": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/snakecase-keys/-/snakecase-keys-3.2.1.tgz", - "integrity": "sha512-CjU5pyRfwOtaOITYv5C8DzpZ8XA/ieRsDpr93HI2r6e3YInC6moZpSQbmUtg8cTk58tq2x3jcG2gv+p1IZGmMA==", - "dependencies": { - "map-obj": "^4.1.0", - "to-snake-case": "^1.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/sonic-boom": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-1.3.2.tgz", @@ -8691,15 +8680,6 @@ } } }, - "snakecase-keys": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/snakecase-keys/-/snakecase-keys-3.2.1.tgz", - "integrity": "sha512-CjU5pyRfwOtaOITYv5C8DzpZ8XA/ieRsDpr93HI2r6e3YInC6moZpSQbmUtg8cTk58tq2x3jcG2gv+p1IZGmMA==", - "requires": { - "map-obj": "^4.1.0", - "to-snake-case": "^1.0.0" - } - }, "sonic-boom": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-1.3.2.tgz", diff --git a/package.json b/package.json index a0bb3c42..c79907d4 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "moment": "^2.29.1", "parse-url": "^5.0.2", "pino": "^6.11.1", - "snakecase-keys": "^3.2.1", + "to-snake-case": "^1.0.0", "uuid": "^8.3.2", "verify-aws-sns-signature": "^0.0.6", "xml2js": "^0.4.23"