Compare commits

...

17 Commits

Author SHA1 Message Date
Dave Horton
6db73ea5a3 bump version 2023-01-12 16:15:40 -05:00
Dave Horton
a805eaed32 update jsonwebtoken 2022-12-28 11:20:28 -06:00
Dave Horton
4eab0e412c bump version 2022-12-24 12:04:39 -06:00
Dave Horton
f4f1827019 minor change in limits enum 2022-11-27 15:29:23 -05:00
Dave Horton
8263b46fff update limits enum again 2022-11-26 12:56:18 -05:00
Dave Horton
b6699a37c3 add limits license_count and voice_call_minutes 2022-11-25 11:03:20 -05:00
Guilherme Rauen
0fc3c95cc5 update node image to the latest and most secure (#81)
Co-authored-by: Guilherme Rauen <g.rauen@cognigy.com>
2022-11-11 17:44:40 -05:00
Dave Horton
aeebf6aee0 add real testing of microsoft stt 2022-11-10 18:11:04 -05:00
Dave Horton
8026f45467 update deps 2022-11-05 10:44:19 -04:00
Dave Horton
505884e68e update deps 2022-11-04 08:31:41 -04:00
Dave Horton
9e4d6eb88b update deps 2022-11-02 13:39:33 -04:00
Dave Horton
e1cfbe5010 update db-helpers 2022-11-01 21:21:38 -04:00
Dave Horton
b8dc0b2f05 update google speech libs 2022-10-31 11:15:40 -04:00
Dave Horton
110c4ed0d8 allow fromHost in createCall REST API 2022-10-25 13:22:30 -04:00
Dave Horton
7890de8c8f update deps 2022-10-23 15:22:36 -04:00
Dave Horton
b65dc7080c Dh password settings (#72)
* update package-lock.json

* Feat: password settings for account (#65)

* feat: password settings for account

* feat: password settings for account

* fix: review comments

* fix: review comments

* fix: review comments

* return empty json

* fix: after review

Co-authored-by: xquanluu <110280845+xquanluu@users.noreply.github.com>
2022-10-23 14:11:00 -04:00
Markus Frindt
9d0be0f8e1 [snyk] Fix vulnerabilities (#70)
Co-authored-by: Markus Frindt <m.frindt@cognigy.com>
2022-10-20 21:34:07 -04:00
16 changed files with 2752 additions and 2044 deletions

1
.gitignore vendored
View File

@@ -1,6 +1,7 @@
# Logs
logs
*.log
run-tests.sh
# Runtime data
pids

View File

@@ -1,4 +1,4 @@
FROM --platform=linux/amd64 node:18.8.0-alpine as base
FROM --platform=linux/amd64 node:18.12.1-alpine3.16 as base
RUN apk --update --no-cache add --virtual .builds-deps build-base python3

View File

@@ -1,4 +1,4 @@
FROM --platform=linux/amd64 node:18.8.0-alpine as base
FROM --platform=linux/amd64 node:18.9.0-alpine3.16 as base
RUN apk --update --no-cache add --virtual .builds-deps build-base python3

View File

@@ -79,7 +79,7 @@ CREATE TABLE account_limits
(
account_limits_sid CHAR(36) NOT NULL UNIQUE ,
account_sid CHAR(36) NOT NULL,
category ENUM('api_rate','voice_call_session', 'device') NOT NULL,
category ENUM('api_rate','voice_call_session', 'device','voice_call_minutes','voice_call_session_license', 'voice_call_minutes_license') NOT NULL,
quantity INTEGER NOT NULL,
PRIMARY KEY (account_limits_sid)
);
@@ -254,7 +254,7 @@ CREATE TABLE service_provider_limits
(
service_provider_limits_sid CHAR(36) NOT NULL UNIQUE ,
service_provider_sid CHAR(36) NOT NULL,
category ENUM('api_rate','voice_call_session', 'device') NOT NULL,
category ENUM('api_rate','voice_call_session', 'device','voice_call_minutes','voice_call_session_license', 'voice_call_minutes_license') NOT NULL,
quantity INTEGER NOT NULL,
PRIMARY KEY (service_provider_limits_sid)
);

View File

@@ -826,7 +826,7 @@
<y>325.00</y>
</location>
<size>
<width>352.00</width>
<width>770.00</width>
<height>100.00</height>
</size>
<zorder>30</zorder>
@@ -856,7 +856,7 @@
</SQLField>
<SQLField>
<name><![CDATA[category]]></name>
<type><![CDATA[ENUM('api_rate','voice_call_session', 'device')]]></type>
<type><![CDATA[ENUM('api_rate','voice_call_session', 'device','voice_call_minutes','voice_call_session_license', 'voice_call_minutes_license')]]></type>
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[9724C27F-3B51-453A-99B8-313480D4A63A]]></uid>
</SQLField>
@@ -1087,7 +1087,7 @@
<y>205.00</y>
</location>
<size>
<width>352.00</width>
<width>770.00</width>
<height>100.00</height>
</size>
<zorder>29</zorder>
@@ -1117,7 +1117,7 @@
</SQLField>
<SQLField>
<name><![CDATA[category]]></name>
<type><![CDATA[ENUM('api_rate','voice_call_session', 'device')]]></type>
<type><![CDATA[ENUM('api_rate','voice_call_session', 'device','voice_call_minutes','voice_call_session_license', 'voice_call_minutes_license')]]></type>
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[72BFA408-371D-4B21-8DA0-A56644FCD92C]]></uid>
</SQLField>
@@ -2617,10 +2617,10 @@
<SourceSidebarWidth><![CDATA[0.000000]]></SourceSidebarWidth>
<SQLEditorFileFormatVersion><![CDATA[4]]></SQLEditorFileFormatVersion>
<uid><![CDATA[58C99A00-06C9-478C-A667-C63842E088F3]]></uid>
<windowHeight><![CDATA[833.000000]]></windowHeight>
<windowHeight><![CDATA[871.000000]]></windowHeight>
<windowLocationX><![CDATA[0.000000]]></windowLocationX>
<windowLocationY><![CDATA[110.000000]]></windowLocationY>
<windowScrollOrigin><![CDATA[{0, 81}]]></windowScrollOrigin>
<windowLocationY><![CDATA[73.000000]]></windowLocationY>
<windowScrollOrigin><![CDATA[{0, 0}]]></windowScrollOrigin>
<windowWidth><![CDATA[1512.000000]]></windowWidth>
</SQLDocumentInfo>
<AllowsIndexRenamingOnInsert><![CDATA[1]]></AllowsIndexRenamingOnInsert>

View File

@@ -0,0 +1,70 @@
const {promisePool} = require('../db');
class PasswordSettings {
/**
* Retrieve object from database
*/
static async retrieve() {
const [r] = await promisePool.execute(`SELECT * FROM ${this.table}`);
return r;
}
/**
* Update object into the database
*/
static async update(obj) {
let sql = `UPDATE ${this.table} SET `;
const values = [];
const keys = Object.keys(obj);
this.fields.forEach(({name}) => {
if (keys.includes(name)) {
sql = sql + `${name} = ?,`;
values.push(obj[name]);
}
});
if (values.length) {
sql = sql.slice(0, -1);
await promisePool.execute(sql, values);
}
}
/**
* insert object into the database
*/
static async make(obj) {
let params = '', marks = '';
const values = [];
const keys = Object.keys(obj);
this.fields.forEach(({name}) => {
if (keys.includes(name)) {
params = params + `${name},`;
marks = marks + '?,';
values.push(obj[name]);
}
});
if (values.length) {
params = `(${params.slice(0, -1)})`;
marks = `values(${marks.slice(0, -1)})`;
return await promisePool.execute(`INSERT into ${this.table} ${params} ${marks}`, values);
}
}
}
PasswordSettings.table = 'password_settings';
PasswordSettings.fields = [
{
name: 'min_password_length',
type: 'number'
},
{
name: 'require_digit',
type: 'number'
},
{
name: 'require_special_character',
type: 'number'
}
];
module.exports = PasswordSettings;

View File

@@ -44,6 +44,7 @@ api.use('/Subscriptions', require('./subscriptions'));
api.use('/Invoices', require('./invoices'));
api.use('/InviteCodes', require('./invite-codes'));
api.use('/PredefinedCarriers', require('./predefined-carriers'));
api.use('/PasswordSettings', isAdminScope, require('./password-settings'));
// messaging
api.use('/Smpps', require('./smpps')); // our smpp server info

View File

@@ -0,0 +1,42 @@
const router = require('express').Router();
const sysError = require('../error');
const PasswordSettings = require('../../models/password-settings');
const { DbErrorBadRequest } = require('../../utils/errors');
const validate = (obj) => {
if (obj.min_password_length && (
obj.min_password_length < 8 ||
obj.min_password_length > 20
)) {
throw new DbErrorBadRequest('invalid min_password_length property: should be between 8-20');
}
};
router.post('/', async(req, res) => {
const logger = req.app.locals.logger;
try {
validate(req.body);
const [existing] = (await PasswordSettings.retrieve() || []);
if (existing) {
await PasswordSettings.update(req.body);
} else {
await PasswordSettings.make(req.body);
}
res.status(201).json({});
}
catch (err) {
sysError(logger, res, err);
}
});
router.get('/', async(req, res) => {
const logger = req.app.locals.logger;
try {
const [results] = (await PasswordSettings.retrieve() || []);
return res.status(200).json(results || {min_password_length: 8});
}
catch (err) {
sysError(logger, res, err);
}
});
module.exports = router;

View File

@@ -3419,6 +3419,10 @@ paths:
type: string
description: The calling party number
example: "16172375089"
fromHost:
type: string
description: The hostname to put in the SIP From header of the INVITE
example: "blf.finotel.com"
timeout:
type: integer
description: the number of seconds to wait for call to be answered. Defaults to 60.

View File

@@ -2,6 +2,8 @@ const ttsGoogle = require('@google-cloud/text-to-speech');
const sttGoogle = require('@google-cloud/speech').v1p1beta1;
const Polly = require('aws-sdk/clients/polly');
const AWS = require('aws-sdk');
const { Deepgram } = require('@deepgram/sdk');
const sdk = require('microsoft-cognitiveservices-speech-sdk');
const bent = require('bent');
const fs = require('fs');
@@ -32,6 +34,65 @@ const testGoogleStt = async(logger, credentials) => {
}
};
const testDeepgramStt = async(logger, credentials) => {
const {api_key} = credentials;
const deepgram = new Deepgram(api_key);
const mimetype = 'audio/wav';
const source = {
buffer: fs.readFileSync(`${__dirname}/../../data/test_audio.wav`),
mimetype: mimetype
};
return new Promise((resolve, reject) => {
// Send the audio to Deepgram and get the response
deepgram.transcription
.preRecorded(source, {punctuate: true})
.then((response) => {
//logger.debug({response}, 'got transcript');
if (response?.results?.channels[0]?.alternatives?.length > 0) resolve(response);
else reject(new Error('no transcript returned'));
return;
})
.catch((err) => {
logger.info({err}, 'failed to get deepgram transcript');
reject(err);
});
});
};
const testMicrosoftStt = async(logger, credentials) => {
const {api_key, region} = credentials;
const speechConfig = sdk.SpeechConfig.fromSubscription(api_key, region);
const audioConfig = sdk.AudioConfig.fromWavFileInput(fs.readFileSync(`${__dirname}/../../data/test_audio.wav`));
speechConfig.speechRecognitionLanguage = 'en-US';
const speechRecognizer = new sdk.SpeechRecognizer(speechConfig, audioConfig);
return new Promise((resolve, reject) => {
speechRecognizer.recognizeOnceAsync((result) => {
switch (result.reason) {
case sdk.ResultReason.RecognizedSpeech:
resolve();
break;
case sdk.ResultReason.NoMatch:
reject('Speech could not be recognized.');
break;
case sdk.ResultReason.Canceled:
const cancellation = sdk.CancellationDetails.fromResult(result);
logger.info(`CANCELED: Reason=${cancellation.reason}`);
if (cancellation.reason == sdk.CancellationReason.Error) {
logger.info(`CANCELED: ErrorCode=${cancellation.ErrorCode}`);
logger.info(`CANCELED: ErrorDetails=${cancellation.errorDetails}`);
}
reject(cancellation.reason);
break;
}
speechRecognizer.close();
});
});
};
const testAwsTts = (logger, credentials) => {
const polly = new Polly(credentials);
return new Promise((resolve, reject) => {
@@ -89,11 +150,6 @@ const testMicrosoftTts = async(logger, credentials) => {
}
};
const testMicrosoftStt = async(logger, credentials) => {
//TODO
return true;
};
const testWellSaidTts = async(logger, credentials) => {
const {api_key} = credentials;
try {
@@ -127,4 +183,5 @@ module.exports = {
testMicrosoftTts,
testMicrosoftStt,
testWellSaidStt,
testDeepgramStt
};

4446
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "jambonz-api-server",
"version": "v0.7.7",
"version": "v0.7.9",
"description": "",
"main": "app.js",
"scripts": {
@@ -18,10 +18,11 @@
"url": "https://github.com/jambonz/jambonz-api-server.git"
},
"dependencies": {
"@google-cloud/speech": "^4.10.2",
"@google-cloud/text-to-speech": "^3.4.0",
"@jambonz/db-helpers": "^0.6.18",
"@jambonz/realtimedb-helpers": "^0.4.29",
"@deepgram/sdk": "^1.10.2",
"@google-cloud/speech": "^5.1.0",
"@google-cloud/text-to-speech": "^4.0.3",
"@jambonz/db-helpers": "^0.7.3",
"@jambonz/realtimedb-helpers": "^0.5.9",
"@jambonz/time-series": "^0.2.5",
"argon2-ffi": "^2.0.0",
"aws-sdk": "^2.1152.0",
@@ -33,8 +34,9 @@
"form-data": "^2.5.1",
"form-urlencoded": "^6.1.0",
"helmet": "^5.1.0",
"jsonwebtoken": "^8.5.1",
"jsonwebtoken": "^9.0.0",
"mailgun.js": "^3.7.3",
"microsoft-cognitiveservices-speech-sdk": "^1.24.1",
"mysql2": "^2.3.3",
"passport": "^0.6.0",
"passport-http-bearer": "^1.0.1",

View File

@@ -232,7 +232,7 @@ test('account tests', async(t) => {
auth: authAdmin,
json: true,
});
//console.log(result);
// console.log(result);
t.ok(result.length === 1 && result[0].quantity === 205, 'successfully queried account limits by category');
/* delete call session limits for a service provider */

View File

@@ -15,4 +15,5 @@ require('./recent-calls');
require('./webapp_tests');
// require('./homer');
require('./call-test');
require('./password-settings');
require('./docker_stop');

71
test/password-settings.js Normal file
View File

@@ -0,0 +1,71 @@
const test = require('tape') ;
const ADMIN_TOKEN = '38700987-c7a4-4685-a5bb-af378f9734de';
const authAdmin = {bearer: ADMIN_TOKEN};
const request = require('request-promise-native').defaults({
baseUrl: 'http://127.0.0.1:3000/v1'
});
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
});
test('password settings tests', async(t) => {
/* Check Default Password Settings */
result = await request.get('/PasswordSettings', {
auth: authAdmin,
json: true,
});
t.ok(result.min_password_length == 8 &&
!result.require_digit &&
!result.require_special_character, "default password settings is correct!")
/* Post New Password settings*/
result = await request.post('/PasswordSettings', {
auth: authAdmin,
json: true,
resolveWithFullResponse: true,
body: {
min_password_length: 15,
require_digit: 1,
require_special_character: 1
}
});
t.ok(result.statusCode === 201, 'successfully added a password settings');
/* Check Password Settings*/
result = await request.get('/PasswordSettings', {
auth: authAdmin,
json: true,
});
t.ok(result.min_password_length === 15 &&
result.require_digit === 1 &&
result.require_special_character === 1, 'successfully queried password settings');
/* Update Password settings*/
result = await request.post('/PasswordSettings', {
auth: authAdmin,
json: true,
resolveWithFullResponse: true,
body: {
min_password_length: 10,
require_special_character: 0
}
});
t.ok(result.statusCode === 201, 'successfully updated a password settings');
/* Check Password Settings After update*/
result = await request.get('/PasswordSettings', {
auth: authAdmin,
json: true,
});
t.ok(result.min_password_length === 10 &&
result.require_digit === 1 &&
result.require_special_character === 0, 'successfully queried password settings after updated');
});

View File

@@ -30,7 +30,9 @@ test('speech credentials tests', async(t) => {
json: true,
body: {
vendor: 'google',
service_key: jsonKey
service_key: jsonKey,
use_for_tts: true,
use_for_stt: true
}
});
t.ok(result.statusCode === 201, 'successfully added a speech credential to service provider');
@@ -61,7 +63,9 @@ test('speech credentials tests', async(t) => {
json: true,
body: {
vendor: 'google',
service_key: jsonKey
service_key: jsonKey,
use_for_tts: true,
use_for_stt: true
}
});
t.ok(result.statusCode === 201, 'successfully added speech credential');
@@ -110,20 +114,20 @@ test('speech credentials tests', async(t) => {
});
t.ok(result.statusCode === 204, 'successfully deleted speech credential');
/* add a credential for microsoft */
if (process.env.MICROSOFT_API_KEY && process.env.MICROSOFT_REGION) {
/* add / test a credential for google */
if (process.env.GCP_JSON_KEY) {
result = await request.post(`/Accounts/${account_sid}/SpeechCredentials`, {
resolveWithFullResponse: true,
auth: authUser,
json: true,
body: {
vendor: 'microsoft',
vendor: 'google',
use_for_tts: true,
api_key: process.env.MICROSOFT_API_KEY,
region: process.env.MICROSOFT_REGION
use_for_stt: true,
service_key: process.env.GCP_JSON_KEY
}
});
t.ok(result.statusCode === 201, 'successfully added speech credential');
t.ok(result.statusCode === 201, 'successfully added speech credential for google');
const ms_sid = result.body.sid;
/* test the speech credential */
@@ -132,7 +136,37 @@ test('speech credentials tests', async(t) => {
auth: authUser,
json: true,
});
console.log(JSON.stringify(result));
//console.log(JSON.stringify(result));
t.ok(result.statusCode === 200 && result.body.tts.status === 'ok', 'successfully tested speech credential for google tts');
t.ok(result.statusCode === 200 && result.body.stt.status === 'ok', 'successfully tested speech credential for google stt');
}
/* add / test a credential for microsoft */
if (process.env.MICROSOFT_API_KEY && process.env.MICROSOFT_REGION) {
result = await request.post(`/Accounts/${account_sid}/SpeechCredentials`, {
resolveWithFullResponse: true,
auth: authUser,
json: true,
body: {
vendor: 'microsoft',
use_for_tts: true,
use_for_stt: true,
api_key: process.env.MICROSOFT_API_KEY,
region: process.env.MICROSOFT_REGION
}
});
t.ok(result.statusCode === 201, 'successfully added speech credential for microsoft');
const ms_sid = result.body.sid;
/* test the speech credential */
result = await request.get(`/Accounts/${account_sid}/SpeechCredentials/${ms_sid}/test`, {
resolveWithFullResponse: true,
auth: authUser,
json: true,
});
//console.log(JSON.stringify(result));
t.ok(result.statusCode === 200 && result.body.tts.status === 'ok', 'successfully tested speech credential for microsoft tts');
t.ok(result.statusCode === 200 && result.body.stt.status === 'ok', 'successfully tested speech credential for microsoft stt');
}
/* add a credential for wellsaid */
@@ -156,7 +190,8 @@ test('speech credentials tests', async(t) => {
auth: authUser,
json: true,
});
console.log(JSON.stringify(result));
//console.log(JSON.stringify(result));
t.ok(result.statusCode === 200 && result.body.tts.status === 'ok', 'successfully tested speech credential for wellsaid');
/* delete the credential */
result = await request.delete(`/Accounts/${account_sid}/SpeechCredentials/${ms_sid}`, {