mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-01-25 02:08:24 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a746bbc4c9 | ||
|
|
0e248cb393 |
4
app.js
4
app.js
@@ -22,14 +22,14 @@ const {
|
||||
listCalls,
|
||||
purgeCalls,
|
||||
retrieveSet
|
||||
} = require('jambonz-realtimedb-helpers')({
|
||||
} = require('@jambonz/realtimedb-helpers')({
|
||||
host: process.env.JAMBONES_REDIS_HOST || 'localhost',
|
||||
port: process.env.JAMBONES_REDIS_PORT || 6379
|
||||
}, logger);
|
||||
const {
|
||||
lookupAppBySid,
|
||||
lookupAccountBySid
|
||||
} = require('jambonz-db-helpers')({
|
||||
} = require('@jambonz/db-helpers')({
|
||||
host: process.env.JAMBONES_MYSQL_HOST,
|
||||
user: process.env.JAMBONES_MYSQL_USER,
|
||||
password: process.env.JAMBONES_MYSQL_PASSWORD,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* SQLEditor (MySQL (2))*/
|
||||
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
|
||||
DROP TABLE IF EXISTS call_routes;
|
||||
|
||||
@@ -7,10 +8,10 @@ DROP TABLE IF EXISTS lcr_carrier_set_entry;
|
||||
|
||||
DROP TABLE IF EXISTS lcr_routes;
|
||||
|
||||
DROP TABLE IF EXISTS ms_teams_tenants;
|
||||
|
||||
DROP TABLE IF EXISTS api_keys;
|
||||
|
||||
DROP TABLE IF EXISTS ms_teams_tenants;
|
||||
|
||||
DROP TABLE IF EXISTS sbc_addresses;
|
||||
|
||||
DROP TABLE IF EXISTS users;
|
||||
@@ -48,16 +49,6 @@ priority INTEGER NOT NULL UNIQUE COMMENT 'lower priority routes are attempted f
|
||||
PRIMARY KEY (lcr_route_sid)
|
||||
) COMMENT='Least cost routing table';
|
||||
|
||||
CREATE TABLE ms_teams_tenants
|
||||
(
|
||||
ms_teams_tenant_sid CHAR(36) NOT NULL UNIQUE ,
|
||||
service_provider_sid CHAR(36) NOT NULL,
|
||||
account_sid CHAR(36),
|
||||
application_sid CHAR(36),
|
||||
tenant_fqdn VARCHAR(255) NOT NULL UNIQUE ,
|
||||
PRIMARY KEY (ms_teams_tenant_sid)
|
||||
) COMMENT='A Microsoft Teams customer tenant';
|
||||
|
||||
CREATE TABLE api_keys
|
||||
(
|
||||
api_key_sid CHAR(36) NOT NULL UNIQUE ,
|
||||
@@ -68,6 +59,16 @@ expires_at TIMESTAMP,
|
||||
PRIMARY KEY (api_key_sid)
|
||||
) ENGINE=InnoDB COMMENT='An authorization token that is used to access the REST api';
|
||||
|
||||
CREATE TABLE ms_teams_tenants
|
||||
(
|
||||
ms_teams_tenant_sid CHAR(36) NOT NULL UNIQUE ,
|
||||
service_provider_sid CHAR(36) NOT NULL,
|
||||
account_sid CHAR(36) NOT NULL,
|
||||
application_sid CHAR(36),
|
||||
tenant_fqdn VARCHAR(255) NOT NULL UNIQUE ,
|
||||
PRIMARY KEY (ms_teams_tenant_sid)
|
||||
) COMMENT='A Microsoft Teams customer tenant';
|
||||
|
||||
CREATE TABLE sbc_addresses
|
||||
(
|
||||
sbc_address_sid CHAR(36) NOT NULL UNIQUE ,
|
||||
@@ -182,21 +183,21 @@ ALTER TABLE call_routes ADD FOREIGN KEY account_sid_idxfk (account_sid) REFERENC
|
||||
|
||||
ALTER TABLE call_routes ADD FOREIGN KEY application_sid_idxfk (application_sid) REFERENCES applications (application_sid);
|
||||
|
||||
CREATE INDEX ms_teams_tenant_sid_idx ON ms_teams_tenants (ms_teams_tenant_sid);
|
||||
ALTER TABLE ms_teams_tenants ADD FOREIGN KEY service_provider_sid_idxfk (service_provider_sid) REFERENCES service_providers (service_provider_sid);
|
||||
CREATE INDEX api_key_sid_idx ON api_keys (api_key_sid);
|
||||
CREATE INDEX account_sid_idx ON api_keys (account_sid);
|
||||
ALTER TABLE api_keys ADD FOREIGN KEY account_sid_idxfk_1 (account_sid) REFERENCES accounts (account_sid);
|
||||
|
||||
ALTER TABLE ms_teams_tenants ADD FOREIGN KEY account_sid_idxfk_1 (account_sid) REFERENCES accounts (account_sid);
|
||||
CREATE INDEX service_provider_sid_idx ON api_keys (service_provider_sid);
|
||||
ALTER TABLE api_keys ADD FOREIGN KEY service_provider_sid_idxfk (service_provider_sid) REFERENCES service_providers (service_provider_sid);
|
||||
|
||||
CREATE INDEX ms_teams_tenant_sid_idx ON ms_teams_tenants (ms_teams_tenant_sid);
|
||||
ALTER TABLE ms_teams_tenants ADD FOREIGN KEY service_provider_sid_idxfk_1 (service_provider_sid) REFERENCES service_providers (service_provider_sid);
|
||||
|
||||
ALTER TABLE ms_teams_tenants ADD FOREIGN KEY account_sid_idxfk_2 (account_sid) REFERENCES accounts (account_sid);
|
||||
|
||||
ALTER TABLE ms_teams_tenants ADD FOREIGN KEY application_sid_idxfk_1 (application_sid) REFERENCES applications (application_sid);
|
||||
|
||||
CREATE INDEX tenant_fqdn_idx ON ms_teams_tenants (tenant_fqdn);
|
||||
CREATE INDEX api_key_sid_idx ON api_keys (api_key_sid);
|
||||
CREATE INDEX account_sid_idx ON api_keys (account_sid);
|
||||
ALTER TABLE api_keys ADD FOREIGN KEY account_sid_idxfk_2 (account_sid) REFERENCES accounts (account_sid);
|
||||
|
||||
CREATE INDEX service_provider_sid_idx ON api_keys (service_provider_sid);
|
||||
ALTER TABLE api_keys ADD FOREIGN KEY service_provider_sid_idxfk_1 (service_provider_sid) REFERENCES service_providers (service_provider_sid);
|
||||
|
||||
CREATE INDEX sbc_addresses_idx_host_port ON sbc_addresses (ipv4,port);
|
||||
|
||||
CREATE INDEX sbc_address_sid_idx ON sbc_addresses (sbc_address_sid);
|
||||
@@ -251,3 +252,5 @@ ALTER TABLE accounts ADD FOREIGN KEY service_provider_sid_idxfk_3 (service_provi
|
||||
ALTER TABLE accounts ADD FOREIGN KEY registration_hook_sid_idxfk_1 (registration_hook_sid) REFERENCES webhooks (webhook_sid);
|
||||
|
||||
ALTER TABLE accounts ADD FOREIGN KEY device_calling_application_sid_idxfk (device_calling_application_sid) REFERENCES applications (application_sid);
|
||||
|
||||
SET FOREIGN_KEY_CHECKS=1;
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<notNull><![CDATA[1]]></notNull>
|
||||
<uid><![CDATA[57655C0C-9427-4CC7-9502-24ACF56AAECF]]></uid>
|
||||
</SQLField>
|
||||
<labelWindowIndex><![CDATA[1]]></labelWindowIndex>
|
||||
<labelWindowIndex><![CDATA[3]]></labelWindowIndex>
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
<uid><![CDATA[2A735FAB-592C-42E5-9C8B-06B109314799]]></uid>
|
||||
</SQLTable>
|
||||
@@ -119,7 +119,7 @@
|
||||
<objectComment><![CDATA[If provided, all incoming calls from this source will be routed to the associated application]]></objectComment>
|
||||
<uid><![CDATA[B6545E2E-7F55-4082-AEFA-29F50C137D64]]></uid>
|
||||
</SQLField>
|
||||
<labelWindowIndex><![CDATA[6]]></labelWindowIndex>
|
||||
<labelWindowIndex><![CDATA[8]]></labelWindowIndex>
|
||||
<objectComment><![CDATA[A Carrier or customer PBX that can send or receive calls]]></objectComment>
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
<uid><![CDATA[3D3136A7-AFC0-4A70-AEC3-68577955CA2E]]></uid>
|
||||
@@ -189,7 +189,7 @@
|
||||
<type><![CDATA[TIMESTAMP]]></type>
|
||||
<uid><![CDATA[DE86BC18-858E-4D7E-9B83-891DB2861434]]></uid>
|
||||
</SQLField>
|
||||
<labelWindowIndex><![CDATA[11]]></labelWindowIndex>
|
||||
<labelWindowIndex><![CDATA[13]]></labelWindowIndex>
|
||||
<objectComment><![CDATA[An authorization token that is used to access the REST api]]></objectComment>
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
<uid><![CDATA[3EDF89A0-FD38-4DF9-BB65-E0FCD0A678BE]]></uid>
|
||||
@@ -240,7 +240,7 @@
|
||||
<type><![CDATA[VARCHAR(255)]]></type>
|
||||
<uid><![CDATA[04BB457A-D532-4780-8A58-5900094171EC]]></uid>
|
||||
</SQLField>
|
||||
<labelWindowIndex><![CDATA[2]]></labelWindowIndex>
|
||||
<labelWindowIndex><![CDATA[4]]></labelWindowIndex>
|
||||
<objectComment><![CDATA[An HTTP callback]]></objectComment>
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
<uid><![CDATA[64D64CB9-0990-4C68-BE71-F9FD43C2BE19]]></uid>
|
||||
@@ -311,7 +311,7 @@
|
||||
<uid><![CDATA[9B4208B5-9E3B-4B76-B7F7-4E5D36B99BF2]]></uid>
|
||||
<unsigned><![CDATA[0]]></unsigned>
|
||||
</SQLField>
|
||||
<labelWindowIndex><![CDATA[10]]></labelWindowIndex>
|
||||
<labelWindowIndex><![CDATA[12]]></labelWindowIndex>
|
||||
<objectComment><![CDATA[a regex-based pattern match for call routing]]></objectComment>
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
<uid><![CDATA[78584D93-2CD7-4495-9C5E-893C7B869133]]></uid>
|
||||
@@ -364,6 +364,7 @@
|
||||
<destinationCardinality>2</destinationCardinality>
|
||||
<referencesFieldUID><![CDATA[1342FAFA-C15C-429B-809B-C6C55F9FA5B6]]></referencesFieldUID>
|
||||
<referencesTableUID><![CDATA[985D6997-B1A7-4AB3-80F4-4D59B45480C8]]></referencesTableUID>
|
||||
<notNull><![CDATA[1]]></notNull>
|
||||
<uid><![CDATA[EB48F39F-9D5F-43E0-BE8A-34A5C1304A76]]></uid>
|
||||
</SQLField>
|
||||
<SQLField>
|
||||
@@ -388,7 +389,9 @@
|
||||
<uid><![CDATA[1DDAD1A1-942D-4487-89C8-D496B7F82274]]></uid>
|
||||
<unique><![CDATA[1]]></unique>
|
||||
</SQLField>
|
||||
<labelWindowIndex><![CDATA[2]]></labelWindowIndex>
|
||||
<objectComment><![CDATA[A Microsoft Teams customer tenant]]></objectComment>
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
<uid><![CDATA[92FD042A-5AEC-4D8F-AB94-C73C0F566F75]]></uid>
|
||||
</SQLTable>
|
||||
<SQLTable>
|
||||
@@ -455,7 +458,7 @@
|
||||
<objectComment><![CDATA[lower priority carriers are attempted first]]></objectComment>
|
||||
<uid><![CDATA[01F61C68-799B-49B0-9E6A-0E2162EE5A54]]></uid>
|
||||
</SQLField>
|
||||
<labelWindowIndex><![CDATA[5]]></labelWindowIndex>
|
||||
<labelWindowIndex><![CDATA[7]]></labelWindowIndex>
|
||||
<objectComment><![CDATA[An entry in the LCR routing list]]></objectComment>
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
<uid><![CDATA[956025F5-0798-47F7-B76C-457814C7B52E]]></uid>
|
||||
@@ -553,7 +556,7 @@
|
||||
<notNull><![CDATA[1]]></notNull>
|
||||
<uid><![CDATA[C7130A90-DBB4-424D-A9A9-CB203C32350C]]></uid>
|
||||
</SQLField>
|
||||
<labelWindowIndex><![CDATA[9]]></labelWindowIndex>
|
||||
<labelWindowIndex><![CDATA[11]]></labelWindowIndex>
|
||||
<objectComment><![CDATA[An enterprise that uses the platform for comm services]]></objectComment>
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
<uid><![CDATA[985D6997-B1A7-4AB3-80F4-4D59B45480C8]]></uid>
|
||||
@@ -635,7 +638,7 @@
|
||||
<uid><![CDATA[962CB80A-54CB-4C6A-9591-9BFC644CF80F]]></uid>
|
||||
<unsigned><![CDATA[0]]></unsigned>
|
||||
</SQLField>
|
||||
<labelWindowIndex><![CDATA[8]]></labelWindowIndex>
|
||||
<labelWindowIndex><![CDATA[10]]></labelWindowIndex>
|
||||
<objectComment><![CDATA[A phone number that has been assigned to an account]]></objectComment>
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
<uid><![CDATA[BA650DDC-AC7B-4DFE-A5E5-828C75607807]]></uid>
|
||||
@@ -727,7 +730,7 @@
|
||||
<indexType><![CDATA[UNIQUE]]></indexType>
|
||||
<uid><![CDATA[1C744DE3-39BD-4EC6-B427-7EB2DD258771]]></uid>
|
||||
</SQLIndex>
|
||||
<labelWindowIndex><![CDATA[4]]></labelWindowIndex>
|
||||
<labelWindowIndex><![CDATA[6]]></labelWindowIndex>
|
||||
<objectComment><![CDATA[A whitelisted sip gateway used for origination/termination]]></objectComment>
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
<uid><![CDATA[D8A564E2-DA41-4217-8ACE-06CF77E9BEC1]]></uid>
|
||||
@@ -860,7 +863,7 @@
|
||||
<indexType><![CDATA[UNIQUE]]></indexType>
|
||||
<uid><![CDATA[3FDDDF3B-375D-4DE4-B759-514438845F7D]]></uid>
|
||||
</SQLIndex>
|
||||
<labelWindowIndex><![CDATA[7]]></labelWindowIndex>
|
||||
<labelWindowIndex><![CDATA[9]]></labelWindowIndex>
|
||||
<objectComment><![CDATA[A defined set of behaviors to be applied to phone calls ]]></objectComment>
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
<uid><![CDATA[E97EE4F0-7ED7-4E8C-862E-D98192D6EAE0]]></uid>
|
||||
@@ -930,6 +933,8 @@
|
||||
<indexed><![CDATA[1]]></indexed>
|
||||
<uid><![CDATA[6F249D1F-111F-45B4-B76C-8B5E6B9CB43F]]></uid>
|
||||
</SQLField>
|
||||
<labelWindowIndex><![CDATA[1]]></labelWindowIndex>
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
<uid><![CDATA[F0EE651E-DBF6-4CAC-A517-AC85BCC2D3AF]]></uid>
|
||||
</SQLTable>
|
||||
<SQLTable>
|
||||
@@ -973,7 +978,7 @@
|
||||
<uid><![CDATA[B73773BA-AB1B-47AA-B995-2D2FE006198F]]></uid>
|
||||
<unique><![CDATA[1]]></unique>
|
||||
</SQLField>
|
||||
<labelWindowIndex><![CDATA[3]]></labelWindowIndex>
|
||||
<labelWindowIndex><![CDATA[5]]></labelWindowIndex>
|
||||
<objectComment><![CDATA[Least cost routing table]]></objectComment>
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
<uid><![CDATA[F283D572-F670-4571-91FD-A665A9D3E15D]]></uid>
|
||||
@@ -1060,17 +1065,17 @@
|
||||
<overviewPanelHidden><![CDATA[0]]></overviewPanelHidden>
|
||||
<pageBoundariesVisible><![CDATA[0]]></pageBoundariesVisible>
|
||||
<PageGridVisible><![CDATA[0]]></PageGridVisible>
|
||||
<RightSidebarWidth><![CDATA[1753.000000]]></RightSidebarWidth>
|
||||
<RightSidebarWidth><![CDATA[1756.000000]]></RightSidebarWidth>
|
||||
<sidebarIndex><![CDATA[2]]></sidebarIndex>
|
||||
<snapToGrid><![CDATA[0]]></snapToGrid>
|
||||
<SourceSidebarWidth><![CDATA[0.000000]]></SourceSidebarWidth>
|
||||
<SQLEditorFileFormatVersion><![CDATA[4]]></SQLEditorFileFormatVersion>
|
||||
<uid><![CDATA[58C99A00-06C9-478C-A667-C63842E088F3]]></uid>
|
||||
<windowHeight><![CDATA[1298.000000]]></windowHeight>
|
||||
<windowLocationX><![CDATA[192.000000]]></windowLocationX>
|
||||
<windowLocationY><![CDATA[74.000000]]></windowLocationY>
|
||||
<windowScrollOrigin><![CDATA[{298.5, 2}]]></windowScrollOrigin>
|
||||
<windowWidth><![CDATA[2153.000000]]></windowWidth>
|
||||
<windowHeight><![CDATA[1337.000000]]></windowHeight>
|
||||
<windowLocationX><![CDATA[2625.000000]]></windowLocationX>
|
||||
<windowLocationY><![CDATA[80.000000]]></windowLocationY>
|
||||
<windowScrollOrigin><![CDATA[{0, 1}]]></windowScrollOrigin>
|
||||
<windowWidth><![CDATA[2033.000000]]></windowWidth>
|
||||
</SQLDocumentInfo>
|
||||
<AllowsIndexRenamingOnInsert><![CDATA[1]]></AllowsIndexRenamingOnInsert>
|
||||
<defaultLabelExpanded><![CDATA[1]]></defaultLabelExpanded>
|
||||
|
||||
@@ -10,6 +10,7 @@ function transmogrifyResults(results) {
|
||||
const obj = row.acc;
|
||||
if (row.rh && Object.keys(row.rh).length && row.rh.url !== null) {
|
||||
Object.assign(obj, {registration_hook: row.rh});
|
||||
delete obj.registration_hook.webhook_sid;
|
||||
}
|
||||
else obj.registration_hook = null;
|
||||
delete obj.registration_hook_sid;
|
||||
|
||||
@@ -1,9 +1,65 @@
|
||||
const Model = require('./model');
|
||||
const {getMysqlConnection} = require('../db');
|
||||
|
||||
const retrieveSql = `SELECT * from service_providers sp
|
||||
LEFT JOIN webhooks AS rh
|
||||
ON sp.registration_hook_sid = rh.webhook_sid`;
|
||||
|
||||
|
||||
function transmogrifyResults(results) {
|
||||
return results.map((row) => {
|
||||
const obj = row.sp;
|
||||
if (row.rh && Object.keys(row.rh).length && row.rh.url !== null) {
|
||||
Object.assign(obj, {registration_hook: row.rh});
|
||||
delete obj.registration_hook.webhook_sid;
|
||||
}
|
||||
else obj.registration_hook = null;
|
||||
delete obj.registration_hook_sid;
|
||||
return obj;
|
||||
});
|
||||
}
|
||||
|
||||
class ServiceProvider extends Model {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* list all service providers
|
||||
*/
|
||||
static retrieveAll() {
|
||||
const sql = retrieveSql;
|
||||
return new Promise((resolve, reject) => {
|
||||
getMysqlConnection((err, conn) => {
|
||||
if (err) return reject(err);
|
||||
conn.query({sql, nestTables: true}, [], (err, results, fields) => {
|
||||
conn.release();
|
||||
if (err) return reject(err);
|
||||
const r = transmogrifyResults(results);
|
||||
resolve(r);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve a service provider
|
||||
*/
|
||||
static retrieve(sid) {
|
||||
const args = [sid];
|
||||
const sql = `${retrieveSql} WHERE sp.service_provider_sid = ?`;
|
||||
return new Promise((resolve, reject) => {
|
||||
getMysqlConnection((err, conn) => {
|
||||
if (err) return reject(err);
|
||||
conn.query({sql, nestTables: true}, args, (err, results, fields) => {
|
||||
conn.release();
|
||||
if (err) return reject(err);
|
||||
const r = transmogrifyResults(results);
|
||||
resolve(r);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ServiceProvider.table = 'service_providers';
|
||||
@@ -27,7 +83,11 @@ ServiceProvider.fields = [
|
||||
type: 'string',
|
||||
},
|
||||
{
|
||||
name: 'registration_hook',
|
||||
name: 'registration_hook_sid',
|
||||
type: 'string',
|
||||
},
|
||||
{
|
||||
name: 'ms_teams_fqdn',
|
||||
type: 'string',
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ MsTeamsTenant.fields = [
|
||||
},
|
||||
{
|
||||
name: 'account_sid',
|
||||
type: 'string'
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
name: 'application_sid',
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
const router = require('express').Router();
|
||||
const {DbErrorUnprocessableRequest} = require('../../utils/errors');
|
||||
const Webhook = require('../../models/webhook');
|
||||
const ServiceProvider = require('../../models/service-provider');
|
||||
const sysError = require('./error');
|
||||
const decorate = require('./decorate');
|
||||
const preconditions = {
|
||||
'delete': noActiveAccounts
|
||||
@@ -12,6 +14,89 @@ async function noActiveAccounts(req, sid) {
|
||||
if (activeAccounts > 0) throw new DbErrorUnprocessableRequest('cannot delete service provider with active accounts');
|
||||
}
|
||||
|
||||
decorate(router, ServiceProvider, ['*'], preconditions);
|
||||
decorate(router, ServiceProvider, ['delete'], preconditions);
|
||||
|
||||
/* add */
|
||||
router.post('/', async(req, res) => {
|
||||
const logger = req.app.locals.logger;
|
||||
try {
|
||||
|
||||
// create webhooks if provided
|
||||
const obj = Object.assign({}, req.body);
|
||||
for (const prop of ['registration_hook']) {
|
||||
if (obj[prop]) {
|
||||
obj[`${prop}_sid`] = await Webhook.make(obj[prop]);
|
||||
delete obj[prop];
|
||||
}
|
||||
}
|
||||
|
||||
//logger.debug(`Attempting to add account ${JSON.stringify(obj)}`);
|
||||
const uuid = await ServiceProvider.make(obj);
|
||||
res.status(201).json({sid: uuid});
|
||||
} catch (err) {
|
||||
sysError(logger, res, err);
|
||||
}
|
||||
});
|
||||
|
||||
/* list */
|
||||
router.get('/', async(req, res) => {
|
||||
const logger = req.app.locals.logger;
|
||||
try {
|
||||
const results = await ServiceProvider.retrieveAll();
|
||||
res.status(200).json(results);
|
||||
} catch (err) {
|
||||
sysError(logger, res, err);
|
||||
}
|
||||
});
|
||||
|
||||
/* retrieve */
|
||||
router.get('/:sid', async(req, res) => {
|
||||
const logger = req.app.locals.logger;
|
||||
try {
|
||||
const results = await ServiceProvider.retrieve(req.params.sid);
|
||||
if (results.length === 0) return res.status(404).end();
|
||||
return res.status(200).json(results[0]);
|
||||
}
|
||||
catch (err) {
|
||||
sysError(logger, res, err);
|
||||
}
|
||||
});
|
||||
|
||||
/* update */
|
||||
router.put('/:sid', async(req, res) => {
|
||||
const sid = req.params.sid;
|
||||
const logger = req.app.locals.logger;
|
||||
try {
|
||||
// create webhooks if provided
|
||||
const obj = Object.assign({}, req.body);
|
||||
for (const prop of ['registration_hook']) {
|
||||
if (prop in obj && Object.keys(obj[prop]).length) {
|
||||
if ('webhook_sid' in obj[prop]) {
|
||||
const sid = obj[prop]['webhook_sid'];
|
||||
delete obj[prop]['webhook_sid'];
|
||||
await Webhook.update(sid, obj[prop]);
|
||||
}
|
||||
else {
|
||||
const sid = await Webhook.make(obj[prop]);
|
||||
obj[`${prop}_sid`] = sid;
|
||||
}
|
||||
}
|
||||
else {
|
||||
obj[`${prop}_sid`] = null;
|
||||
}
|
||||
delete obj[prop];
|
||||
}
|
||||
|
||||
const rowsAffected = await ServiceProvider.update(sid, obj);
|
||||
if (rowsAffected === 0) {
|
||||
return res.status(404).end();
|
||||
}
|
||||
res.status(204).end();
|
||||
} catch (err) {
|
||||
sysError(logger, res, err);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -687,16 +687,12 @@ paths:
|
||||
description: root domain for group of accounts that share a registration hook
|
||||
example: example.com
|
||||
registration_hook:
|
||||
type: string
|
||||
format: url
|
||||
$ref: '#/components/schemas/Webhook'
|
||||
description: authentication webhook for registration
|
||||
example: https://mycompany.com
|
||||
hook_basic_auth_user:
|
||||
ms_teams_fqdn:
|
||||
type: string
|
||||
description: username to use for http basic auth when calling hook
|
||||
hook_basic_auth_password:
|
||||
type: string
|
||||
description: password to use for http basic auth when calling hook
|
||||
description: SBC domain name for Microsoft Teams
|
||||
example: contoso.com
|
||||
required:
|
||||
- name
|
||||
responses:
|
||||
@@ -1599,12 +1595,9 @@ components:
|
||||
type: string
|
||||
root_domain:
|
||||
type: string
|
||||
hook_basic_auth_user:
|
||||
type: string
|
||||
format: url
|
||||
hook_basic_auth_password:
|
||||
type: string
|
||||
format: url
|
||||
registration_hook:
|
||||
$ref: '#/components/schemas/Webhook'
|
||||
description: authentication webhook for registration
|
||||
ms_teams_fqdn:
|
||||
type: string
|
||||
required:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jambonz-api-server",
|
||||
"version": "1.1.5",
|
||||
"version": "1.1.6",
|
||||
"description": "",
|
||||
"main": "app.js",
|
||||
"scripts": {
|
||||
@@ -17,8 +17,8 @@
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"jambonz-db-helpers": "^0.3.4",
|
||||
"jambonz-realtimedb-helpers": "0.2.4",
|
||||
"@jambonz/db-helpers": "^0.3.8",
|
||||
"@jambonz/realtimedb-helpers": "0.2.15",
|
||||
"mysql2": "^2.0.2",
|
||||
"passport": "^0.4.0",
|
||||
"passport-http-bearer": "^1.0.1",
|
||||
|
||||
@@ -45,7 +45,7 @@ test('account tests', async(t) => {
|
||||
});
|
||||
let regHook = result[0].registration_hook;
|
||||
t.ok(result.length === 1 &&
|
||||
Object.keys(regHook).length == 5, 'successfully queried all accounts');
|
||||
Object.keys(regHook).length == 4, 'successfully queried all accounts');
|
||||
|
||||
/* query one accounts */
|
||||
result = await request.get(`/Accounts/${sid}`, {
|
||||
@@ -74,7 +74,7 @@ test('account tests', async(t) => {
|
||||
json: true,
|
||||
});
|
||||
//console.log(`retrieved account after update: ${JSON.stringify(result)}`);
|
||||
t.ok(Object.keys(result.registration_hook).length === 5, 'successfully removed a hook from account');
|
||||
t.ok(Object.keys(result.registration_hook).length === 4, 'successfully removed a hook from account');
|
||||
|
||||
/* assign phone number to account */
|
||||
result = await request.put(`/PhoneNumbers/${phone_number_sid}`, {
|
||||
|
||||
@@ -4,7 +4,7 @@ const authAdmin = {bearer: ADMIN_TOKEN};
|
||||
const request = require('request-promise-native').defaults({
|
||||
baseUrl: 'http://127.0.0.1:3000/v1'
|
||||
});
|
||||
const {createServiceProvider, deleteObjectBySid} = require('./utils');
|
||||
const {createServiceProvider, createAccount, deleteObjectBySid} = require('./utils');
|
||||
|
||||
process.on('unhandledRejection', (reason, p) => {
|
||||
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
||||
@@ -16,6 +16,8 @@ test('sbc_addresses tests', async(t) => {
|
||||
try {
|
||||
let result;
|
||||
const service_provider_sid = await createServiceProvider(request);
|
||||
const account_sid = await createAccount(request, service_provider_sid);
|
||||
const account_sid2 = await createAccount(request, service_provider_sid, 'account2');
|
||||
|
||||
/* add a tenant */
|
||||
result = await request.post('/MicrosoftTeamsTenants', {
|
||||
@@ -24,6 +26,7 @@ test('sbc_addresses tests', async(t) => {
|
||||
json: true,
|
||||
body: {
|
||||
service_provider_sid,
|
||||
account_sid,
|
||||
tenant_fqdn: 'foo.bar.baz'
|
||||
}
|
||||
});
|
||||
@@ -37,6 +40,7 @@ test('sbc_addresses tests', async(t) => {
|
||||
json: true,
|
||||
body: {
|
||||
service_provider_sid,
|
||||
account_sid: account_sid2,
|
||||
tenant_fqdn: 'junk.bar.baz'
|
||||
}
|
||||
});
|
||||
@@ -50,8 +54,29 @@ test('sbc_addresses tests', async(t) => {
|
||||
});
|
||||
t.ok(result.body.length === 2, 'successfully retrieved tenants');
|
||||
|
||||
/* update tenant */
|
||||
result = await request.put(`/MicrosoftTeamsTenants/${sid1}`, {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
resolveWithFullResponse: true,
|
||||
body: {
|
||||
tenant_fqdn: 'foo.bar.bazzle'
|
||||
}
|
||||
});
|
||||
t.ok(result.statusCode === 204, 'successfully updated ms teams tenant');
|
||||
|
||||
/* get tenant */
|
||||
result = await request.get(`/MicrosoftTeamsTenants/${sid1}`, {
|
||||
auth: authAdmin,
|
||||
json: true
|
||||
});
|
||||
t.ok(result.tenant_fqdn === 'foo.bar.bazzle', 'successfully retrieved ms teams tenant');
|
||||
|
||||
|
||||
await deleteObjectBySid(request, '/MicrosoftTeamsTenants', sid1);
|
||||
await deleteObjectBySid(request, '/MicrosoftTeamsTenants', sid2);
|
||||
await deleteObjectBySid(request, '/Accounts', account_sid);
|
||||
await deleteObjectBySid(request, '/Accounts', account_sid2);
|
||||
await deleteObjectBySid(request, '/ServiceProviders', service_provider_sid);
|
||||
|
||||
t.end();
|
||||
|
||||
@@ -30,7 +30,8 @@ test('service provider tests', async(t) => {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
body: {
|
||||
name: 'daveh'
|
||||
name: 'daveh',
|
||||
ms_teams_fqdn: 'contoso.com'
|
||||
}
|
||||
});
|
||||
t.ok(result.statusCode === 201, 'successfully created service provider');
|
||||
@@ -43,7 +44,10 @@ test('service provider tests', async(t) => {
|
||||
json: true,
|
||||
body: {
|
||||
name: 'johndoe',
|
||||
root_domain: 'example.com'
|
||||
root_domain: 'example.com',
|
||||
registration_hook: {
|
||||
url: 'http://a.com'
|
||||
}
|
||||
}
|
||||
});
|
||||
t.ok(result.statusCode === 201, 'successfully created service provider with a root domain');
|
||||
@@ -84,11 +88,11 @@ test('service provider tests', async(t) => {
|
||||
t.ok(result.length === 2 , 'successfully queried all service providers');
|
||||
|
||||
/* query one service providers */
|
||||
result = await request.get(`/ServiceProviders/${sid}`, {
|
||||
result = await request.get(`/ServiceProviders/${sid2}`, {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
});
|
||||
t.ok(result.name === 'daveh' , 'successfully retrieved service provider by sid');
|
||||
t.ok(result.name === 'johndoe' && result.root_domain === 'example.com', 'successfully retrieved service provider by sid');
|
||||
|
||||
|
||||
/* update service providers */
|
||||
|
||||
Reference in New Issue
Block a user