Compare commits

...

8 Commits

Author SHA1 Message Date
Quan HL
08c1b8f708 feat: add metadata for create call 2023-05-07 09:45:36 +07:00
Dave Horton
02806a109c added schema changes for LCR (#150)
* added schema changes for LCR

* fix FK

* first draft

* force drop table

* add testcases

* swagger updated

* update code

* wip: add service provider LCR

* fix userpermission on lcr

* add lcr.is_active

* remove FK constraints on lcr

* wip

* wip

* wip

* fix: review comments

* fix: final review

* fix: final review

* fix: update database schema

* fix: update database schema

* fix: update database schema

* update schema

* fix: review comments

* lcr_routes.priority should not be unique

* fix review comments

---------

Co-authored-by: Quan HL <quan.luuhoang8@gmail.com>
2023-05-05 20:09:34 -04:00
Dave Horton
077c791e37 update integration test data with new twilio IP range 2023-05-04 13:14:28 -04:00
Hoan Luu Huu
4b70c6458a feat: system information (#162) 2023-05-04 13:12:29 -04:00
Paulo Telles
aadb0b15f2 change response text to avoid reveal user's data (#161)
* change response text to avoid reveal user's data

* include log into forgot password

---------

Co-authored-by: p.souza <p.souza@cognigy.com>
2023-05-04 08:39:04 -04:00
Anton Voylenko
3997f57365 update swagger docs (#157) 2023-05-01 10:50:22 -04:00
Dave Horton
c97874ed1f add tls_port and wss_port to sbc_addresses, update some deps (#160)
* add tls_port and wss_port to sbc_addresses, update some deps

* add system_information table
2023-05-01 10:45:19 -04:00
Markus Frindt
1dcc92a177 Fix bug in forgot-password req.user destruction (#159)
* Fix bug in forgot-password req.user destruction

* add test for forgot password

---------

Co-authored-by: Markus Frindt <m.frindt@cognigy.com>
2023-04-28 08:43:23 -04:00
31 changed files with 5902 additions and 3859 deletions

View File

@@ -16,6 +16,8 @@ DROP TABLE IF EXISTS call_routes;
DROP TABLE IF EXISTS dns_records;
DROP TABLE IF EXISTS lcr;
DROP TABLE IF EXISTS lcr_carrier_set_entry;
DROP TABLE IF EXISTS lcr_routes;
@@ -52,6 +54,8 @@ DROP TABLE IF EXISTS smpp_addresses;
DROP TABLE IF EXISTS speech_credentials;
DROP TABLE IF EXISTS system_information;
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS smpp_gateways;
@@ -136,11 +140,23 @@ PRIMARY KEY (dns_record_sid)
CREATE TABLE lcr_routes
(
lcr_route_sid CHAR(36),
lcr_sid CHAR(36) NOT NULL,
regex VARCHAR(32) NOT NULL COMMENT 'regex-based pattern match against dialed number, used for LCR routing of PSTN calls',
description VARCHAR(1024),
priority INTEGER NOT NULL UNIQUE COMMENT 'lower priority routes are attempted first',
priority INTEGER NOT NULL COMMENT 'lower priority routes are attempted first',
PRIMARY KEY (lcr_route_sid)
) COMMENT='Least cost routing table';
) COMMENT='An ordered list of digit patterns in an LCR table. The pat';
CREATE TABLE lcr
(
lcr_sid CHAR(36) NOT NULL UNIQUE ,
name VARCHAR(64) COMMENT 'User-assigned name for this LCR table',
is_active BOOLEAN NOT NULL DEFAULT 1,
default_carrier_set_entry_sid CHAR(36) COMMENT 'default carrier/route to use when no digit match based results are found.',
service_provider_sid CHAR(36),
account_sid CHAR(36),
PRIMARY KEY (lcr_sid)
) COMMENT='An LCR (least cost routing) table that is used by a service ';
CREATE TABLE password_settings
(
@@ -248,6 +264,8 @@ CREATE TABLE sbc_addresses
sbc_address_sid CHAR(36) NOT NULL UNIQUE ,
ipv4 VARCHAR(255) NOT NULL,
port INTEGER NOT NULL DEFAULT 5060,
tls_port INTEGER,
wss_port INTEGER,
service_provider_sid CHAR(36),
last_updated DATETIME,
PRIMARY KEY (sbc_address_sid)
@@ -308,6 +326,13 @@ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (speech_credential_sid)
);
CREATE TABLE system_information
(
domain_name VARCHAR(255),
sip_domain_name VARCHAR(255),
monitoring_domain_name VARCHAR(255)
);
CREATE TABLE users
(
user_sid CHAR(36) NOT NULL UNIQUE ,
@@ -504,6 +529,14 @@ ALTER TABLE call_routes ADD FOREIGN KEY application_sid_idxfk (application_sid)
CREATE INDEX dns_record_sid_idx ON dns_records (dns_record_sid);
ALTER TABLE dns_records ADD FOREIGN KEY account_sid_idxfk_4 (account_sid) REFERENCES accounts (account_sid);
CREATE INDEX lcr_sid_idx ON lcr_routes (lcr_sid);
ALTER TABLE lcr_routes ADD FOREIGN KEY lcr_sid_idxfk (lcr_sid) REFERENCES lcr (lcr_sid);
CREATE INDEX lcr_sid_idx ON lcr (lcr_sid);
ALTER TABLE lcr ADD FOREIGN KEY default_carrier_set_entry_sid_idxfk (default_carrier_set_entry_sid) REFERENCES lcr_carrier_set_entry (lcr_carrier_set_entry_sid);
CREATE INDEX service_provider_sid_idx ON lcr (service_provider_sid);
CREATE INDEX account_sid_idx ON lcr (account_sid);
CREATE INDEX permission_sid_idx ON permissions (permission_sid);
CREATE INDEX predefined_carrier_sid_idx ON predefined_carriers (predefined_carrier_sid);
CREATE INDEX predefined_sip_gateway_sid_idx ON predefined_sip_gateways (predefined_sip_gateway_sid);

View File

@@ -87,7 +87,7 @@
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[49E56AF4-4E40-49B6-BA88-4E378F1E6C18]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[9]]></labelWindowIndex>
<labelWindowIndex><![CDATA[10]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[0507BD46-ACAC-48A3-841E-4DEC2FEDCB72]]></uid>
</SQLTable>
@@ -148,7 +148,7 @@
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[6E651E52-F91E-4086-9A1E-FB3425476B2F]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[19]]></labelWindowIndex>
<labelWindowIndex><![CDATA[20]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[0A95311F-47FA-429F-BAF9-1442C6EE0C0E]]></uid>
</SQLTable>
@@ -225,7 +225,7 @@
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[D1019218-F1FC-4BC5-A890-F8DBB7153375]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[12]]></labelWindowIndex>
<labelWindowIndex><![CDATA[13]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[0AC2FD20-B22F-48DB-8611-801CEF6BFA12]]></uid>
</SQLTable>
@@ -279,7 +279,7 @@
<uid><![CDATA[755D10B0-F60D-4250-8971-C8E4FDB0E0CD]]></uid>
<unique><![CDATA[1]]></unique>
</SQLField>
<labelWindowIndex><![CDATA[16]]></labelWindowIndex>
<labelWindowIndex><![CDATA[17]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[16B9E383-E044-4D71-AB46-FEB86A46A298]]></uid>
</SQLTable>
@@ -287,8 +287,8 @@
<name><![CDATA[password_settings]]></name>
<schema><![CDATA[]]></schema>
<location>
<x>2690.00</x>
<y>260.00</y>
<x>2521.00</x>
<y>360.00</y>
</location>
<size>
<width>276.00</width>
@@ -316,7 +316,7 @@
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[C4EEBFF0-C3CB-4897-8720-12D14DBA93A5]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[3]]></labelWindowIndex>
<labelWindowIndex><![CDATA[4]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[1A80FB9B-419E-483A-86FF-B44A00A44D7F]]></uid>
</SQLTable>
@@ -471,7 +471,7 @@
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[601FA05B-78A5-4E7E-9983-39BB0E6D18EB]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[23]]></labelWindowIndex>
<labelWindowIndex><![CDATA[24]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[2A735FAB-592C-42E5-9C8B-06B109314799]]></uid>
</SQLTable>
@@ -537,7 +537,7 @@
<indexed><![CDATA[1]]></indexed>
<uid><![CDATA[365FB018-429D-4DA4-AC33-D9D106EA97E5]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[8]]></labelWindowIndex>
<labelWindowIndex><![CDATA[9]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[311D99B2-DC8B-4C4A-A1FC-4AFAA1F450F3]]></uid>
</SQLTable>
@@ -546,8 +546,8 @@
<schema><![CDATA[]]></schema>
<comment><![CDATA[A Carrier or customer PBX that can send or receive calls]]></comment>
<location>
<x>20.00</x>
<y>287.00</y>
<x>16.00</x>
<y>427.00</y>
</location>
<size>
<width>293.00</width>
@@ -737,7 +737,7 @@
<type><![CDATA[VARCHAR(4096)]]></type>
<uid><![CDATA[7C7DFE92-D7AC-4447-A1C2-E0F10C1EA26A]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[24]]></labelWindowIndex>
<labelWindowIndex><![CDATA[25]]></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>
@@ -819,7 +819,7 @@
<defaultValue><![CDATA[CURRENT_TIMESTAMP]]></defaultValue>
<uid><![CDATA[C84C9B6A-80B5-4B0B-8C14-EB02F7421BBE]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[33]]></labelWindowIndex>
<labelWindowIndex><![CDATA[34]]></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>
@@ -872,7 +872,7 @@
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[EA4C1A7E-68ED-41D5-9EE9-345DD61F00C7]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[5]]></labelWindowIndex>
<labelWindowIndex><![CDATA[6]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[4893A0F0-BE1B-4322-9034-644528E802DE]]></uid>
</SQLTable>
@@ -999,7 +999,7 @@
<indexType><![CDATA[UNIQUE]]></indexType>
<uid><![CDATA[554ABEC2-3E1B-41B1-BF07-25F403D5E3B4]]></uid>
</SQLIndex>
<labelWindowIndex><![CDATA[18]]></labelWindowIndex>
<labelWindowIndex><![CDATA[19]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[49A68E1C-DEE2-446C-A4EB-9850E16155CC]]></uid>
</SQLTable>
@@ -1007,8 +1007,8 @@
<name><![CDATA[schema_version]]></name>
<schema><![CDATA[]]></schema>
<location>
<x>2769.00</x>
<y>28.00</y>
<x>2519.00</x>
<y>192.00</y>
</location>
<size>
<width>159.00</width>
@@ -1020,7 +1020,7 @@
<type><![CDATA[VARCHAR(16)]]></type>
<uid><![CDATA[1EA572BD-FF6B-43CC-9EBB-33A735781429]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[6]]></labelWindowIndex>
<labelWindowIndex><![CDATA[7]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[518AC592-D3E6-4032-8A33-15A3DB72B060]]></uid>
</SQLTable>
@@ -1081,7 +1081,7 @@
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[6B2F726C-48A6-49D9-B7B1-8850DD6FB3EC]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[11]]></labelWindowIndex>
<labelWindowIndex><![CDATA[12]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[51A02EFE-AA51-46EF-8671-E8B2F1FC5F8D]]></uid>
</SQLTable>
@@ -1133,7 +1133,7 @@
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[2EA3A57F-7EF7-4958-B06B-62B0279BB87E]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[4]]></labelWindowIndex>
<labelWindowIndex><![CDATA[5]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[5784AC2F-BEBC-466F-9818-F9A7D227A5B5]]></uid>
</SQLTable>
@@ -1183,7 +1183,7 @@
<type><![CDATA[VARCHAR(255)]]></type>
<uid><![CDATA[04BB457A-D532-4780-8A58-5900094171EC]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[25]]></labelWindowIndex>
<labelWindowIndex><![CDATA[26]]></labelWindowIndex>
<objectComment><![CDATA[An HTTP callback]]></objectComment>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[64D64CB9-0990-4C68-BE71-F9FD43C2BE19]]></uid>
@@ -1283,7 +1283,7 @@
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[9A75A20B-1EFD-4E16-994A-5376C650EAB5]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[7]]></labelWindowIndex>
<labelWindowIndex><![CDATA[8]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[6511AF7D-91FD-40C7-9F73-B8E9E66DC249]]></uid>
</SQLTable>
@@ -1292,8 +1292,8 @@
<schema><![CDATA[]]></schema>
<comment><![CDATA[a regex-based pattern match for call routing]]></comment>
<location>
<x>18.00</x>
<y>864.00</y>
<x>31.00</x>
<y>983.00</y>
</location>
<size>
<width>254.00</width>
@@ -1352,7 +1352,7 @@
<uid><![CDATA[9B4208B5-9E3B-4B76-B7F7-4E5D36B99BF2]]></uid>
<unsigned><![CDATA[0]]></unsigned>
</SQLField>
<labelWindowIndex><![CDATA[32]]></labelWindowIndex>
<labelWindowIndex><![CDATA[33]]></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>
@@ -1361,8 +1361,8 @@
<name><![CDATA[signup_history]]></name>
<schema><![CDATA[]]></schema>
<location>
<x>2752.00</x>
<y>129.00</y>
<x>2519.00</x>
<y>259.00</y>
</location>
<size>
<width>215.00</width>
@@ -1389,7 +1389,7 @@
<noQuoteDefault><![CDATA[1]]></noQuoteDefault>
<uid><![CDATA[4D2F7B02-F183-4239-8CE8-3E98206708AE]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[10]]></labelWindowIndex>
<labelWindowIndex><![CDATA[11]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[86FAB0AB-DC68-4ADF-8A08-BBAF61BA1840]]></uid>
</SQLTable>
@@ -1427,7 +1427,7 @@
<type><![CDATA[VARCHAR(255)]]></type>
<uid><![CDATA[673137EA-B74C-4BA7-AD25-1B71360A2E26]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[2]]></labelWindowIndex>
<labelWindowIndex><![CDATA[3]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[87F254ED-D381-48E3-8E8F-C0F3D99CC01C]]></uid>
</SQLTable>
@@ -1459,7 +1459,7 @@
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[8998AAD6-A21C-4697-9660-8DC5005AED07]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[1]]></labelWindowIndex>
<labelWindowIndex><![CDATA[2]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[8E75DB2D-9078-40E6-88BF-7DDED5033362]]></uid>
</SQLTable>
@@ -1536,7 +1536,7 @@
<uid><![CDATA[1DDAD1A1-942D-4487-89C8-D496B7F82274]]></uid>
<unique><![CDATA[1]]></unique>
</SQLField>
<labelWindowIndex><![CDATA[22]]></labelWindowIndex>
<labelWindowIndex><![CDATA[23]]></labelWindowIndex>
<objectComment><![CDATA[A Microsoft Teams customer tenant]]></objectComment>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[92FD042A-5AEC-4D8F-AB94-C73C0F566F75]]></uid>
@@ -1547,7 +1547,7 @@
<comment><![CDATA[An entry in the LCR routing list]]></comment>
<location>
<x>22.00</x>
<y>155.00</y>
<y>296.00</y>
</location>
<size>
<width>259.00</width>
@@ -1558,6 +1558,7 @@
<name><![CDATA[lcr_carrier_set_entry_sid]]></name>
<type><![CDATA[CHAR(36)]]></type>
<primaryKey>1</primaryKey>
<forcedUnique><![CDATA[1]]></forcedUnique>
<uid><![CDATA[7F8F912B-6596-4068-8C4D-9C790A2DEC8C]]></uid>
</SQLField>
<SQLField>
@@ -1606,7 +1607,7 @@
<objectComment><![CDATA[lower priority carriers are attempted first]]></objectComment>
<uid><![CDATA[01F61C68-799B-49B0-9E6A-0E2162EE5A54]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[28]]></labelWindowIndex>
<labelWindowIndex><![CDATA[29]]></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>
@@ -1616,8 +1617,8 @@
<schema><![CDATA[]]></schema>
<comment><![CDATA[An enterprise that uses the platform for comm services]]></comment>
<location>
<x>827.00</x>
<y>327.00</y>
<x>838.00</x>
<y>368.00</y>
</location>
<size>
<width>318.00</width>
@@ -1799,7 +1800,7 @@
<referencesTableUID><![CDATA[E97EE4F0-7ED7-4E8C-862E-D98192D6EAE0]]></referencesTableUID>
<uid><![CDATA[4B8283B4-5E16-4846-A79D-12C6B2E73C86]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[30]]></labelWindowIndex>
<labelWindowIndex><![CDATA[31]]></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>
@@ -1838,7 +1839,7 @@
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[D0BF7D36-E40C-4385-9BA5-2099B49A1042]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[17]]></labelWindowIndex>
<labelWindowIndex><![CDATA[18]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[A8ED2178-3CC4-4174-A8FC-C2B58FD28214]]></uid>
</SQLTable>
@@ -1846,8 +1847,8 @@
<name><![CDATA[predefined_carriers]]></name>
<schema><![CDATA[]]></schema>
<location>
<x>35.00</x>
<y>1194.00</y>
<x>27.00</x>
<y>1370.00</y>
</location>
<size>
<width>302.00</width>
@@ -1930,10 +1931,81 @@
<type><![CDATA[VARCHAR(32)]]></type>
<uid><![CDATA[CE2015BC-8538-4FB0-B4D9-454436FAB1D9]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[13]]></labelWindowIndex>
<labelWindowIndex><![CDATA[14]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[AF34726D-EDFD-414E-9B44-5243DA9D9497]]></uid>
</SQLTable>
<SQLTable>
<name><![CDATA[lcr]]></name>
<schema><![CDATA[]]></schema>
<comment><![CDATA[An LCR (least cost routing) table that is used by a service provider or account to make decisions about routing outbound calls when multiple carriers are available.]]></comment>
<location>
<x>21.00</x>
<y>16.00</y>
</location>
<size>
<width>290.00</width>
<height>140.00</height>
</size>
<zorder>34</zorder>
<SQLField>
<name><![CDATA[lcr_sid]]></name>
<type><![CDATA[CHAR(36)]]></type>
<primaryKey>1</primaryKey>
<forcedUnique><![CDATA[1]]></forcedUnique>
<indexed><![CDATA[1]]></indexed>
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[35D5D70B-A42A-44FB-9897-458AE12C65DE]]></uid>
<unique><![CDATA[1]]></unique>
</SQLField>
<SQLField>
<name><![CDATA[name]]></name>
<type><![CDATA[VARCHAR(64)]]></type>
<objectComment><![CDATA[User-assigned name for this LCR table]]></objectComment>
<uid><![CDATA[36037B81-0FE7-4047-8352-554A5936357A]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[is_active]]></name>
<type><![CDATA[BOOLEAN]]></type>
<defaultValue><![CDATA[1]]></defaultValue>
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[958CAE39-99BB-42C1-9ACE-668A2FA2372E]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[default_carrier_set_entry_sid]]></name>
<type><![CDATA[CHAR(36)]]></type>
<referencesField>lcr_carrier_set_entry_sid</referencesField>
<referencesTable>lcr_carrier_set_entry</referencesTable>
<referencesField><![CDATA[lcr_carrier_set_entry_sid]]></referencesField>
<referencesTable><![CDATA[lcr_carrier_set_entry]]></referencesTable>
<sourceCardinality>4</sourceCardinality>
<destinationCardinality>1</destinationCardinality>
<referencesFieldUID><![CDATA[7F8F912B-6596-4068-8C4D-9C790A2DEC8C]]></referencesFieldUID>
<referencesTableUID><![CDATA[956025F5-0798-47F7-B76C-457814C7B52E]]></referencesTableUID>
<forcedUnique><![CDATA[0]]></forcedUnique>
<notNull><![CDATA[0]]></notNull>
<objectComment><![CDATA[default carrier/route to use when no digit match based results are found.]]></objectComment>
<uid><![CDATA[3029D066-4206-4058-B8B3-54652CA4DDE5]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[service_provider_sid]]></name>
<type><![CDATA[CHAR(36)]]></type>
<forcedUnique><![CDATA[0]]></forcedUnique>
<indexed><![CDATA[1]]></indexed>
<uid><![CDATA[0C8D97E1-19D7-48BC-B7E5-F0709F498E3F]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[account_sid]]></name>
<type><![CDATA[CHAR(36)]]></type>
<forcedUnique><![CDATA[0]]></forcedUnique>
<indexed><![CDATA[1]]></indexed>
<uid><![CDATA[EA936343-89D3-4E3F-BD92-9F8967DC27C4]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[1]]></labelWindowIndex>
<objectComment><![CDATA[An LCR (least cost routing) table that is used by a service provider or account to make decisions about routing outbound calls when multiple carriers are available.]]></objectComment>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[AFD51FD4-44C8-4442-94C2-0DFA93CD48AE]]></uid>
</SQLTable>
<SQLTable>
<name><![CDATA[dns_records]]></name>
<schema><![CDATA[]]></schema>
@@ -1981,7 +2053,7 @@
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[73092A7A-9F3F-4C49-8478-39CE5DAF5ADD]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[15]]></labelWindowIndex>
<labelWindowIndex><![CDATA[16]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[B10C0DE3-03CD-4C5A-B1FB-F9F81ED14A40]]></uid>
</SQLTable>
@@ -1990,8 +2062,8 @@
<schema><![CDATA[]]></schema>
<comment><![CDATA[A phone number that has been assigned to an account]]></comment>
<location>
<x>17.00</x>
<y>1010.00</y>
<x>16.00</x>
<y>1128.00</y>
</location>
<size>
<width>265.00</width>
@@ -2077,7 +2149,7 @@
<objectComment><![CDATA[if not null, this number is a test number for the associated service provider]]></objectComment>
<uid><![CDATA[D2D46B75-F9C7-42A5-8D8C-4A8412C75ECA]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[31]]></labelWindowIndex>
<labelWindowIndex><![CDATA[32]]></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>
@@ -2177,7 +2249,7 @@
<indexNamePrefix><![CDATA[sip_gateway]]></indexNamePrefix>
<uid><![CDATA[1C744DE3-39BD-4EC6-B427-7EB2DD258771]]></uid>
</SQLIndex>
<labelWindowIndex><![CDATA[27]]></labelWindowIndex>
<labelWindowIndex><![CDATA[28]]></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>
@@ -2351,7 +2423,7 @@
<indexType><![CDATA[UNIQUE]]></indexType>
<uid><![CDATA[3FDDDF3B-375D-4DE4-B759-514438845F7D]]></uid>
</SQLIndex>
<labelWindowIndex><![CDATA[29]]></labelWindowIndex>
<labelWindowIndex><![CDATA[30]]></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>
@@ -2459,10 +2531,39 @@
<type><![CDATA[VARBINARY(52)]]></type>
<uid><![CDATA[B4793720-635C-4E25-A306-62E7416541C4]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[14]]></labelWindowIndex>
<labelWindowIndex><![CDATA[15]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[EB4BC5F9-CC10-4C8C-AB31-6D942256AEFB]]></uid>
</SQLTable>
<SQLTable>
<name><![CDATA[system_information]]></name>
<schema><![CDATA[]]></schema>
<location>
<x>2552.00</x>
<y>61.00</y>
</location>
<size>
<width>266.00</width>
<height>80.00</height>
</size>
<zorder>35</zorder>
<SQLField>
<name><![CDATA[domain_name]]></name>
<type><![CDATA[VARCHAR(255)]]></type>
<uid><![CDATA[C7897324-FE6E-4534-B4BB-736070825D04]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[sip_domain_name]]></name>
<type><![CDATA[VARCHAR(255)]]></type>
<uid><![CDATA[ED76F31F-B9BF-497D-A862-5D5E8661965C]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[monitoring_domain_name]]></name>
<type><![CDATA[VARCHAR(255)]]></type>
<uid><![CDATA[0A8DB34E-76C9-4D40-9E31-786E0228DCEE]]></uid>
</SQLField>
<uid><![CDATA[F0C2DC80-CBA7-4BE7-8856-D10B062A7B17]]></uid>
</SQLTable>
<SQLTable>
<name><![CDATA[sbc_addresses]]></name>
<schema><![CDATA[]]></schema>
@@ -2472,7 +2573,7 @@
</location>
<size>
<width>281.00</width>
<height>140.00</height>
<height>180.00</height>
</size>
<zorder>13</zorder>
<SQLField>
@@ -2498,6 +2599,16 @@
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[707EF28F-F4AF-4B7E-AB04-C128C894ECE9]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[tls_port]]></name>
<type><![CDATA[INTEGER]]></type>
<uid><![CDATA[89D52E8F-73BF-4A40-8FBD-617C7BA6AB63]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[wss_port]]></name>
<type><![CDATA[INTEGER]]></type>
<uid><![CDATA[22B35E87-249A-4E4A-8FB0-CD37B7A19A9F]]></uid>
</SQLField>
<SQLIndex>
<name><![CDATA[sbc_addresses_idx_host_port]]></name>
<fieldName><![CDATA[ipv4]]></fieldName>
@@ -2534,21 +2645,21 @@
<type><![CDATA[DATETIME]]></type>
<uid><![CDATA[CD43B91B-F34E-4422-9C0F-A4B92E2E7B95]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[21]]></labelWindowIndex>
<labelWindowIndex><![CDATA[22]]></labelWindowIndex>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[F0EE651E-DBF6-4CAC-A517-AC85BCC2D3AF]]></uid>
</SQLTable>
<SQLTable>
<name><![CDATA[lcr_routes]]></name>
<schema><![CDATA[]]></schema>
<comment><![CDATA[Least cost routing table]]></comment>
<comment><![CDATA[An ordered list of digit patterns in an LCR table. The patterns are tested in sequence until one matches]]></comment>
<location>
<x>24.00</x>
<y>32.00</y>
<x>41.00</x>
<y>168.00</y>
</location>
<size>
<width>233.00</width>
<height>100.00</height>
<width>192.00</width>
<height>120.00</height>
</size>
<zorder>8</zorder>
<SQLField>
@@ -2559,6 +2670,21 @@
<indexed><![CDATA[0]]></indexed>
<uid><![CDATA[B558A3B9-2F3E-40E0-B78E-997350021A6B]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[lcr_sid]]></name>
<type><![CDATA[CHAR(36)]]></type>
<referencesField>lcr_sid</referencesField>
<referencesTable>lcr</referencesTable>
<referencesField><![CDATA[lcr_sid]]></referencesField>
<referencesTable><![CDATA[lcr]]></referencesTable>
<sourceCardinality>4</sourceCardinality>
<destinationCardinality>1</destinationCardinality>
<referencesFieldUID><![CDATA[35D5D70B-A42A-44FB-9897-458AE12C65DE]]></referencesFieldUID>
<referencesTableUID><![CDATA[AFD51FD4-44C8-4442-94C2-0DFA93CD48AE]]></referencesTableUID>
<indexed><![CDATA[1]]></indexed>
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[B2401824-B0C5-447A-A947-F696F764592B]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[regex]]></name>
<type><![CDATA[VARCHAR(32)]]></type>
@@ -2577,10 +2703,10 @@
<notNull><![CDATA[1]]></notNull>
<objectComment><![CDATA[lower priority routes are attempted first]]></objectComment>
<uid><![CDATA[B73773BA-AB1B-47AA-B995-2D2FE006198F]]></uid>
<unique><![CDATA[1]]></unique>
<unique><![CDATA[0]]></unique>
</SQLField>
<labelWindowIndex><![CDATA[26]]></labelWindowIndex>
<objectComment><![CDATA[Least cost routing table]]></objectComment>
<labelWindowIndex><![CDATA[27]]></labelWindowIndex>
<objectComment><![CDATA[An ordered list of digit patterns in an LCR table. The patterns are tested in sequence until one matches]]></objectComment>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[F283D572-F670-4571-91FD-A665A9D3E15D]]></uid>
</SQLTable>
@@ -2589,8 +2715,8 @@
<schema><![CDATA[]]></schema>
<comment><![CDATA[A partition of the platform used by one service provider]]></comment>
<location>
<x>837.00</x>
<y>160.00</y>
<x>838.00</x>
<y>207.00</y>
</location>
<size>
<width>293.00</width>
@@ -2646,7 +2772,7 @@
<type><![CDATA[VARCHAR(255)]]></type>
<uid><![CDATA[FA39B463-61C7-4654-BE9C-D1AC39AB1B97]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[20]]></labelWindowIndex>
<labelWindowIndex><![CDATA[21]]></labelWindowIndex>
<objectComment><![CDATA[A partition of the platform used by one service provider]]></objectComment>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[F294B51E-F867-47CA-BC1F-F70BDF8170FF]]></uid>
@@ -2720,17 +2846,17 @@
<overviewPanelHidden><![CDATA[0]]></overviewPanelHidden>
<pageBoundariesVisible><![CDATA[0]]></pageBoundariesVisible>
<PageGridVisible><![CDATA[0]]></PageGridVisible>
<RightSidebarWidth><![CDATA[1235.000000]]></RightSidebarWidth>
<RightSidebarWidth><![CDATA[2487.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[868.000000]]></windowHeight>
<windowLocationX><![CDATA[11.000000]]></windowLocationX>
<windowLocationY><![CDATA[54.000000]]></windowLocationY>
<windowScrollOrigin><![CDATA[{461, 0}]]></windowScrollOrigin>
<windowWidth><![CDATA[1512.000000]]></windowWidth>
<windowHeight><![CDATA[1001.000000]]></windowHeight>
<windowLocationX><![CDATA[-1642.000000]]></windowLocationX>
<windowLocationY><![CDATA[1036.000000]]></windowLocationY>
<windowScrollOrigin><![CDATA[{0, 0}]]></windowScrollOrigin>
<windowWidth><![CDATA[2764.000000]]></windowWidth>
</SQLDocumentInfo>
<AllowsIndexRenamingOnInsert><![CDATA[1]]></AllowsIndexRenamingOnInsert>
<defaultLabelExpanded><![CDATA[1]]></defaultLabelExpanded>

View File

@@ -87,6 +87,7 @@ VALUES
('81a0c8cb-a33e-42da-8f20-99083da6f02f', '7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', '54.252.254.64', 30, 5060, 1, 0),
('eeeef07a-46b8-4ffe-a4f2-04eb32ca889e', '7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', '54.169.127.128', 30, 5060, 1, 0),
('fbb6c194-4b68-4dff-9b42-52412be1c39e', '7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', '177.71.206.192', 30, 5060, 1, 0),
('973e7824-0cf3-4645-88e4-d2460ddb8577', '7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', '168.86.128.0', 18, 5060, 1, 0),
('3ed1dd12-e1a7-44ff-811a-3cc5dc13dc72', '7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', '<your-domain>.pstn.twilio.com', 32, 5060, 0, 1);
-- voxbone gateways

View File

@@ -76,6 +76,7 @@ VALUES
('81a0c8cb-a33e-42da-8f20-99083da6f02f', '7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', '54.252.254.64', 30, 5060, 1, 0),
('eeeef07a-46b8-4ffe-a4f2-04eb32ca889e', '7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', '54.169.127.128', 30, 5060, 1, 0),
('fbb6c194-4b68-4dff-9b42-52412be1c39e', '7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', '177.71.206.192', 30, 5060, 1, 0),
('973e7824-0cf3-4645-88e4-d2460ddb8577', '7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', '168.86.128.0', 18, 5060, 1, 0),
('3ed1dd12-e1a7-44ff-811a-3cc5dc13dc72', '7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', '<your-domain>.pstn.twilio.com', 32, 5060, 0, 1);
-- voxbone gateways

View File

@@ -53,6 +53,7 @@ VALUES
('81a0c8cb-a33e-42da-8f20-99083da6f02f', '7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', '54.252.254.64', 30, 5060, 1, 0),
('eeeef07a-46b8-4ffe-a4f2-04eb32ca889e', '7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', '54.169.127.128', 30, 5060, 1, 0),
('fbb6c194-4b68-4dff-9b42-52412be1c39e', '7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', '177.71.206.192', 30, 5060, 1, 0),
('973e7824-0cf3-4645-88e4-d2460ddb8577', '7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', '168.86.128.0', 18, 5060, 1, 0),
('3ed1dd12-e1a7-44ff-811a-3cc5dc13dc72', '7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', '<your-domain>.pstn.twilio.com', 32, 5060, 0, 1);
-- voxbone gateways

View File

@@ -91,6 +91,14 @@ const sql = {
8003: [
'ALTER TABLE `voip_carriers` ADD COLUMN `register_status` VARCHAR(4096)',
'ALTER TABLE `sbc_addresses` ADD COLUMN `last_updated` DATETIME',
'ALTER TABLE `sbc_addresses` ADD COLUMN `tls_port` INTEGER',
'ALTER TABLE `sbc_addresses` ADD COLUMN `wss_port` INTEGER',
`CREATE TABLE system_information
(
domain_name VARCHAR(255),
sip_domain_name VARCHAR(255),
monitoring_domain_name VARCHAR(255)
)`,
]
};
@@ -120,6 +128,7 @@ const doIt = async() => {
if (val < 7006) upgrades.push(...sql['7006']);
if (val < 7007) upgrades.push(...sql['7007']);
if (val < 8000) upgrades.push(...sql['8000']);
if (val < 8003) upgrades.push(...sql['8003']);
// perform all upgrades
logger.info({upgrades}, 'applying schema upgrades..');

View File

@@ -318,6 +318,10 @@ Account.fields = [
name: 'siprec_hook_sid',
type: 'string',
},
{
name: 'lcr_sid',
type: 'string'
}
];
module.exports = Account;

View File

@@ -0,0 +1,47 @@
const Model = require('./model');
const {promisePool} = require('../db');
class LcrCarrierSetEntry extends Model {
constructor() {
super();
}
static async retrieveAllByLcrRouteSid(sid) {
const sql = `SELECT * FROM ${this.table} WHERE lcr_route_sid = ? ORDER BY priority`;
const [rows] = await promisePool.query(sql, sid);
return rows;
}
static async deleteByLcrRouteSid(sid) {
const sql = `DELETE FROM ${this.table} WHERE lcr_route_sid = ?`;
const [rows] = await promisePool.query(sql, sid);
return rows.affectedRows;
}
}
LcrCarrierSetEntry.table = 'lcr_carrier_set_entry';
LcrCarrierSetEntry.fields = [
{
name: 'lcr_carrier_set_entry_sid',
type: 'string',
primaryKey: true
},
{
name: 'workload',
type: 'number'
},
{
name: 'lcr_route_sid',
type: 'string'
},
{
name: 'voip_carrier_sid',
type: 'string'
},
{
name: 'priority',
type: 'number'
}
];
module.exports = LcrCarrierSetEntry;

54
lib/models/lcr-route.js Normal file
View File

@@ -0,0 +1,54 @@
const Model = require('./model');
const {promisePool} = require('../db');
class LcrRoutes extends Model {
constructor() {
super();
}
static async retrieveAllByLcrSid(sid) {
const sql = `SELECT * FROM ${this.table} WHERE lcr_sid = ? ORDER BY priority`;
const [rows] = await promisePool.query(sql, sid);
return rows;
}
static async deleteByLcrSid(sid) {
const sql = `DELETE FROM ${this.table} WHERE lcr_sid = ?`;
const [rows] = await promisePool.query(sql, sid);
return rows.affectedRows;
}
static async countAllByLcrSid(sid) {
const sql = `SELECT COUNT(*) AS count FROM ${this.table} WHERE lcr_sid = ?`;
const [rows] = await promisePool.query(sql, sid);
return rows.length ? rows[0].count : 0;
}
}
LcrRoutes.table = 'lcr_routes';
LcrRoutes.fields = [
{
name: 'lcr_route_sid',
type: 'string',
primaryKey: true
},
{
name: 'lcr_sid',
type: 'string'
},
{
name: 'regex',
type: 'string'
},
{
name: 'description',
type: 'string'
},
{
name: 'priority',
type: 'number'
}
];
module.exports = LcrRoutes;

54
lib/models/lcr.js Normal file
View File

@@ -0,0 +1,54 @@
const Model = require('./model');
const {promisePool} = require('../db');
class Lcr extends Model {
constructor() {
super();
}
static async retrieveAllByAccountSid(account_sid) {
const sql = `SELECT * FROM ${this.table} WHERE account_sid = ?`;
const [rows] = await promisePool.query(sql, account_sid);
return rows;
}
static async retrieveAllByServiceProviderSid(sid) {
const sql = `SELECT * FROM ${this.table} WHERE service_provider_sid = ?`;
const [rows] = await promisePool.query(sql, sid);
return rows;
}
static async releaseDefaultEntry(sid) {
const sql = `UPDATE ${this.table} SET default_carrier_set_entry_sid = null WHERE lcr_sid = ?`;
const [rows] = await promisePool.query(sql, sid);
return rows;
}
}
Lcr.table = 'lcr';
Lcr.fields = [
{
name: 'lcr_sid',
type: 'string',
primaryKey: true
},
{
name: 'name',
type: 'string',
required: true
},
{
name: 'account_sid',
type: 'string'
},
{
name: 'service_provider_sid',
type: 'string'
},
{
name: 'default_carrier_set_entry_sid',
type: 'string'
}
];
module.exports = Lcr;

View File

@@ -89,6 +89,10 @@ ServiceProvider.fields = [
{
name: 'ms_teams_fqdn',
type: 'string',
},
{
name: 'lcr_sid',
type: 'string'
}
];

View File

@@ -0,0 +1,38 @@
const Model = require('./model');
const { promisePool } = require('../db');
class SystemInformation extends Model {
constructor() {
super();
}
static async add(body) {
let [sysInfo] = await this.retrieveAll();
if (sysInfo) {
const sql = `UPDATE ${this.table} SET ?`;
await promisePool.query(sql, body);
} else {
const sql = `INSERT INTO ${this.table} SET ?`;
await promisePool.query(sql, body);
}
[sysInfo] = await this.retrieveAll();
return sysInfo;
}
}
SystemInformation.table = 'system_information';
SystemInformation.fields = [
{
name: 'domain_name',
type: 'string',
},
{
name: 'sip_domain_name',
type: 'string',
},
{
name: 'monitoring_domain_name',
type: 'string',
},
];
module.exports = SystemInformation;

View File

@@ -46,7 +46,7 @@ function createResetEmailText(link) {
router.post('/', async(req, res) => {
const {logger, addKey} = req.app.locals;
const {email} = req.body;
const {user_sid} = req.user;
let obj;
try {
if (!email || !validateEmail(email)) {
@@ -55,11 +55,16 @@ router.post('/', async(req, res) => {
const [r] = await promisePool.query({sql, nestTables: true}, email);
if (0 === r.length) {
return res.status(400).json({error: 'email does not exist'});
logger.info('user not found');
return res.status(400).json({error: 'failed to reset your password'});
}
obj = r[0];
if (!obj.acc.is_active) {
return res.status(400).json({error: 'you may not reset the password of an inactive account'});
if (!obj.user.is_active) {
logger.info(obj.user.name, 'user is inactive');
return res.status(400).json({error: 'failed to reset your password'});
} else if (obj.acc.account_sid !== null && !obj.acc.is_active) {
logger.info(obj.acc.account_sid, 'account is inactive');
return res.status(400).json({error: 'failed to reset your password'});
}
res.sendStatus(204);
} catch (err) {
@@ -81,7 +86,7 @@ router.post('/', async(req, res) => {
emailSimpleText(logger, email, 'Reset password request', createResetEmailText(link));
}
const redisKey = cacheClient.generateRedisKey('jwt', user_sid, 'v2');
const redisKey = cacheClient.generateRedisKey('jwt', obj.user.user_sid, 'v2');
await cacheClient.delete(redisKey);
});

View File

@@ -16,6 +16,7 @@ const isAdminScope = (req, res, next) => {
// };
api.use('/BetaInviteCodes', isAdminScope, require('./beta-invite-codes'));
api.use('/SystemInformation', isAdminScope, require('./system-information'));
api.use('/ServiceProviders', require('./service-providers'));
api.use('/VoipCarriers', require('./voip-carriers'));
api.use('/Webhooks', require('./webhooks'));
@@ -45,6 +46,10 @@ api.use('/Invoices', require('./invoices'));
api.use('/InviteCodes', require('./invite-codes'));
api.use('/PredefinedCarriers', require('./predefined-carriers'));
api.use('/PasswordSettings', require('./password-settings'));
// Least Cost Routing
api.use('/Lcrs', require('./lcrs'));
api.use('/LcrRoutes', require('./lcr-routes'));
api.use('/LcrCarrierSetEntries', require('./lcr-carrier-set-entries'));
// messaging
api.use('/Smpps', require('./smpps')); // our smpp server info

View File

@@ -0,0 +1,65 @@
const router = require('express').Router();
const LcrCarrierSetEntry = require('../../models/lcr-carrier-set-entry');
const LcrRoute = require('../../models/lcr-route');
const decorate = require('./decorate');
const {DbErrorBadRequest} = require('../../utils/errors');
const sysError = require('../error');
const validateAdd = async(req) => {
const {lookupCarrierBySid} = req.app.locals;
if (!req.body.lcr_route_sid) {
throw new DbErrorBadRequest('missing lcr_route_sid');
}
// check lcr_route_sid is exist
const lcrRoute = await LcrRoute.retrieve(req.body.lcr_route_sid);
if (lcrRoute.length === 0) {
throw new DbErrorBadRequest('unknown lcr_route_sid');
}
// check voip_carrier_sid is exist
if (!req.body.voip_carrier_sid) {
throw new DbErrorBadRequest('missing voip_carrier_sid');
}
const carrier = await lookupCarrierBySid(req.body.voip_carrier_sid);
if (!carrier) {
throw new DbErrorBadRequest('unknown voip_carrier_sid');
}
};
const validateUpdate = async(req) => {
const {lookupCarrierBySid} = req.app.locals;
if (req.body.lcr_route_sid) {
const lcrRoute = await LcrRoute.retrieve(req.body.lcr_route_sid);
if (lcrRoute.length === 0) {
throw new DbErrorBadRequest('unknown lcr_route_sid');
}
}
// check voip_carrier_sid is exist
if (req.body.voip_carrier_sid) {
const carrier = await lookupCarrierBySid(req.body.voip_carrier_sid);
if (!carrier) {
throw new DbErrorBadRequest('unknown voip_carrier_sid');
}
}
};
const preconditions = {
add: validateAdd,
update: validateUpdate,
};
decorate(router, LcrCarrierSetEntry, ['add', 'retrieve', 'update', 'delete'], preconditions);
router.get('/', async(req, res) => {
const logger = req.app.locals.logger;
const lcr_route_sid = req.query.lcr_route_sid;
try {
const results = await LcrCarrierSetEntry.retrieveAllByLcrRouteSid(lcr_route_sid);
res.status(200).json(results);
} catch (err) {
sysError(logger, res, err);
}
});
module.exports = router;

View File

@@ -0,0 +1,96 @@
const router = require('express').Router();
const LcrRoute = require('../../models/lcr-route');
const Lcr = require('../../models/lcr');
const LcrCarrierSetEntry = require('../../models/lcr-carrier-set-entry');
const decorate = require('./decorate');
const {DbErrorBadRequest} = require('../../utils/errors');
const sysError = require('../error');
const validateAdd = async(req) => {
// check if lcr sid is available
if (!req.body.lcr_sid) {
throw new DbErrorBadRequest('missing parameter lcr_sid');
}
const lcr = await Lcr.retrieve(req.body.lcr_sid);
if (lcr.length === 0) {
throw new DbErrorBadRequest('unknown lcr_sid');
}
};
const validateUpdate = async(req) => {
if (req.body.lcr_sid) {
const lcr = await Lcr.retrieve(req.body.lcr_sid);
if (lcr.length === 0) {
throw new DbErrorBadRequest('unknown lcr_sid');
}
}
};
const validateDelete = async(req, sid) => {
// delete all lcr carrier set entries
await LcrCarrierSetEntry.deleteByLcrRouteSid(sid);
};
const checkUserScope = async(req, lcr_sid) => {
if (!lcr_sid) {
throw new DbErrorBadRequest('missing lcr_sid');
}
if (req.user.hasAdminAuth) return;
const lcrList = await Lcr.retrieve(lcr_sid);
if (lcrList.length === 0) throw new DbErrorBadRequest('unknown lcr_sid');
const lcr = lcrList[0];
if (req.user.hasAccountAuth) {
if (!lcr.account_sid || lcr.account_sid !== req.user.account_sid) {
throw new DbErrorBadRequest('unknown lcr_sid');
}
}
if (req.user.hasServiceProviderAuth) {
if (!lcr.service_provider_sid || lcr.service_provider_sid !== req.user.service_provider_sid) {
throw new DbErrorBadRequest('unknown lcr_sid');
}
}
};
const preconditions = {
add: validateAdd,
update: validateUpdate,
delete: validateDelete,
};
decorate(router, LcrRoute, ['add', 'update', 'delete'], preconditions);
router.get('/', async(req, res) => {
const logger = req.app.locals.logger;
const lcr_sid = req.query.lcr_sid;
try {
await checkUserScope(req, lcr_sid);
const results = await LcrRoute.retrieveAllByLcrSid(lcr_sid);
for (const r of results) {
r.lcr_carrier_set_entries = await LcrCarrierSetEntry.retrieveAllByLcrRouteSid(r.lcr_route_sid);
}
res.status(200).json(results);
} catch (err) {
sysError(logger, res, err);
}
});
router.get('/:sid', async(req, res) => {
const logger = req.app.locals.logger;
const lcr_route_sid = req.params.sid;
try {
const results = await LcrRoute.retrieve(lcr_route_sid);
if (results.length === 0) return res.sendStatus(404);
const route = results[0];
route.lcr_carrier_set_entries = await LcrCarrierSetEntry.retrieveAllByLcrRouteSid(route.lcr_route_sid);
res.status(200).json(route);
} catch (err) {
sysError(logger, res, err);
}
});
module.exports = router;

138
lib/routes/api/lcrs.js Normal file
View File

@@ -0,0 +1,138 @@
const router = require('express').Router();
const Lcr = require('../../models/lcr');
const LcrCarrierSetEntry = require('../../models/lcr-carrier-set-entry');
const LcrRoutes = require('../../models/lcr-route');
const decorate = require('./decorate');
const {DbErrorBadRequest} = require('../../utils/errors');
const sysError = require('../error');
const ServiceProvider = require('../../models/service-provider');
const validateAssociatedTarget = async(req, sid) => {
const {lookupAccountBySid} = req.app.locals;
if (req.body.account_sid) {
// Add only for account
req.body.service_provider_sid = null;
const account = await lookupAccountBySid(req.body.account_sid);
if (!account) throw new DbErrorBadRequest('unknown account_sid');
const lcr = await Lcr.retrieveAllByAccountSid(req.body.account_sid);
if (lcr.length > 0 && (!sid || sid !== lcr[0].lcr_sid)) {
throw new DbErrorBadRequest(`Account: ${account.name} already has an active call routing table.`);
}
} else if (req.body.service_provider_sid) {
const serviceProviders = await ServiceProvider.retrieve(req.body.service_provider_sid);
if (serviceProviders.length === 0) throw new DbErrorBadRequest('unknown service_provider_sid');
const serviceProvider = serviceProviders[0];
const lcr = await Lcr.retrieveAllByServiceProviderSid(req.body.service_provider_sid);
if (lcr.length > 0 && (!sid || sid !== lcr[0].lcr_sid)) {
throw new DbErrorBadRequest(`Service Provider: ${serviceProvider.name} already
has an active call routing table.`);
}
}
};
const validateAdd = async(req) => {
if (req.user.hasAccountAuth) {
// Account just create LCR for himself
req.body.account_sid = req.user.account_sid;
} else if (req.user.hasServiceProviderAuth) {
// SP just can create LCR for himself
req.body.service_provider_sid = req.user.service_provider_sid;
req.body.account_sid = null;
}
await validateAssociatedTarget(req);
// check if lcr_carrier_set_entry is available
if (req.body.lcr_carrier_set_entry) {
const e = await LcrCarrierSetEntry.retrieve(req.body.lcr_carrier_set_entry);
if (e.length === 0) throw new DbErrorBadRequest('unknown lcr_carrier_set_entry');
}
};
const validateUserPermissionForExistingEntity = async(req, sid) => {
const r = await Lcr.retrieve(sid);
if (r.length === 0) {
throw new DbErrorBadRequest('unknown lcr_sid');
}
const lcr = r[0];
if (req.user.hasAccountAuth) {
if (lcr.account_sid != req.user.account_sid) {
throw new DbErrorBadRequest('unknown lcr_sid');
}
} else if (req.user.hasServiceProviderAuth) {
if (lcr.service_provider_sid != req.user.service_provider_sid) {
throw new DbErrorBadRequest('unknown lcr_sid');
}
}
};
const validateUpdate = async(req, sid) => {
await validateUserPermissionForExistingEntity(req, sid);
await validateAssociatedTarget(req, sid);
};
const validateDelete = async(req, sid) => {
if (req.user.hasAccountAuth) {
/* can only delete Lcr for the user's account */
const r = await Lcr.retrieve(sid);
const lcr = r.length > 0 ? r[0] : null;
if (!lcr || (req.user.account_sid && lcr.account_sid != req.user.account_sid)) {
throw new DbErrorBadRequest('unknown lcr_sid');
}
}
await Lcr.releaseDefaultEntry(sid);
// fetch lcr route
const lcr_routes = await LcrRoutes.retrieveAllByLcrSid(sid);
// delete all lcr carrier set entries
for (const e of lcr_routes) {
await LcrCarrierSetEntry.deleteByLcrRouteSid(e.lcr_route_sid);
}
// delete all lcr routes
await LcrRoutes.deleteByLcrSid(sid);
};
const preconditions = {
add: validateAdd,
update: validateUpdate,
delete: validateDelete
};
decorate(router, Lcr, ['add', 'update', 'delete'], preconditions);
router.get('/', async(req, res) => {
const logger = req.app.locals.logger;
try {
const results = req.user.hasAdminAuth ?
await Lcr.retrieveAll() : req.user.hasAccountAuth ?
await Lcr.retrieveAllByAccountSid(req.user.hasAccountAuth ? req.user.account_sid : null) :
await Lcr.retrieveAllByServiceProviderSid(req.user.service_provider_sid);
for (const lcr of results) {
lcr.number_routes = await LcrRoutes.countAllByLcrSid(lcr.lcr_sid);
}
res.status(200).json(results);
} catch (err) {
sysError(logger, res, err);
}
});
router.get('/:sid', async(req, res) => {
const logger = req.app.locals.logger;
try {
const results = await Lcr.retrieve(req.params.sid);
if (results.length === 0) return res.sendStatus(404);
const lcr = results[0];
if (req.user.hasAccountAuth && lcr.account_sid !== req.user.account_sid) {
return res.sendStatus(404);
} else if (req.user.hasServiceProviderAuth && lcr.service_provider_sid !== req.user.service_provider_sid) {
return res.sendStatus(404);
}
lcr.number_routes = await LcrRoutes.countAllByLcrSid(lcr.lcr_sid);
return res.status(200).json(lcr);
} catch (err) {
sysError(logger, res, err);
}
});
module.exports = router;

View File

@@ -0,0 +1,14 @@
const router = require('express').Router();
const SystemInformation = require('../../models/system-information');
router.post('/', async(req, res) => {
const sysInfo = await SystemInformation.add(req.body);
res.status(201).json(sysInfo);
});
router.get('/', async(req, res) => {
const [sysInfo] = await SystemInformation.retrieveAll();
res.status(200).json(sysInfo);
});
module.exports = router;

View File

@@ -453,12 +453,12 @@ router.post('/', async(req, res) => {
if (name) {
logger.debug({payload}, 'user with this username already exists');
return res.status(422).json({msg: 'user with this username already exists'});
return res.status(422).json({msg: 'invalid username or email'});
}
if (email) {
logger.debug({payload}, 'user with this email already exists');
return res.status(422).json({msg: 'user with this email already exists'});
return res.status(422).json({msg: 'invalid username or email'});
}
if (req.user.hasAdminAuth) {

View File

@@ -234,6 +234,14 @@ const parseUserSid = (req) => {
}
};
const parseLcrSid = (req) => {
try {
return validateSid('Lcrs', req);
} catch (error) {
throw error;
}
};
const hasAccountPermissions = async(req, res, next) => {
try {
if (req.user.hasScope('admin')) {
@@ -446,6 +454,7 @@ module.exports = {
parseWebhookSid,
parseSipGatewaySid,
parseUserSid,
parseLcrSid,
hasAccountPermissions,
hasServiceProviderPermissions,
checkLimits,

View File

@@ -38,6 +38,12 @@ tags:
description: Webhooks operations
- name: Microsoft Teams Tenants
description: Microsoft Teams Tenants operations
- name: Lcrs
description: Least Cost Routing operations
- name: LcrRoutes
description: Least Cost Routing Routes operations
- name: LcrCarrierSetEntries
description: Least Cost Routing Carrier Set Entries operation
paths:
/BetaInviteCodes:
post:
@@ -2182,6 +2188,58 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
/ServiceProviders/{ServiceProviderSid}/Lcrs:
parameters:
- name: ServiceProviderSid
in: path
required: true
schema:
type: string
format: uuid
get:
tags:
- Service Providers
summary: get all Least Cost Routings for a service provider
operationId: getServiceProviderLcrs
responses:
200:
description: Least cost routing listing
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Lcr'
403:
description: unauthorized
404:
description: service provider not found
post:
tags:
- Service Providers
summary: create a Lest cost routing
operationId: createLcrForServiceProvider
requestBody:
content:
application/json:
schema:
type: object
properties:
name:
type: string
description: name or Least Cost Routing
example: twilioLcr
required:
- name
responses:
201:
description: service provider Lcr successfully created
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessfulAdd'
404:
description: service provider not found
/Accounts/{AccountSid}/Limits:
post:
tags:
@@ -3743,8 +3801,13 @@ paths:
type: string
format: uuid
description: The application to use to control this call. Either applicationSid or url is required.
answerOnBridge:
type: boolean
description: If set to true, the inbound call will ring until the number that was dialed answers the call, and at that point a 200 OK will be sent on the inbound leg. If false, the inbound call will be answered immediately as the outbound call is placed.
example: false
call_hook:
$ref: '#/components/schemas/Webhook'
example: {"url": "https://acme.com/callhook", "method": "POST"}
call_status_hook:
$ref: '#/components/schemas/Webhook'
example: {"url": "https://acme.com/status", "method": "POST"}
@@ -3758,15 +3821,27 @@ paths:
example: "blf.finotel.com"
timeout:
type: integer
description: the number of seconds to wait for call to be answered. Defaults to 60.
description: The number of seconds to wait for call to be answered. Defaults to 60.
example: 30
timeLimit:
type: integer
description: The max length of call in seconds
example: 60
tag:
type: object
description: initial set of customer-supplied metadata to associate with the call (see jambonz 'tag' verb)
description: Initial set of customer-supplied metadata to associate with the call (see jambonz 'tag' verb)
example: {"callCount": 10}
metadata:
type: object
description: Customer-supplied metadata to associate with the call that to be included in customerData for call_hook and call_status_hook.
example: {"customer": "jambonz"}
to:
$ref: '#/components/schemas/Target'
description: destination for call
description: Destination for call
headers:
type: object
description: The customer SIP headers to associate with the call
example: {"X-Custom-Header": "Hello"}
responses:
201:
description: call successfully created
@@ -3916,6 +3991,8 @@ paths:
properties:
call_hook:
$ref: '#/components/schemas/Webhook'
child_call_hook:
$ref: '#/components/schemas/Webhook'
call_status:
type: string
enum:
@@ -3935,6 +4012,7 @@ paths:
type: string
enum:
- pause
- silence
- resume
mute_status:
type: string
@@ -4072,12 +4150,445 @@ paths:
type: string
length:
type: string
/Lcrs:
post:
tags:
- Lcrs
summary: create a Least Cost Routing
operationId: createLcr
requestBody:
content:
application/json:
schema:
type: object
properties:
name:
type: string
description: name or Least Cost Routing
example: twilioLcr
required:
- name
responses:
201:
description: Least Cost Routing successfully created
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessfulAdd'
400:
description: bad request
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
422:
description: unprocessable entity
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
$ref: '#/components/schemas/GeneralError'
get:
tags:
- Lcrs
summary: list least cost routings
operationId: listLeastCostRoutings
responses:
200:
description: list of least cost routings
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Lcr'
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
/Lcrs/{LcrSid}:
parameters:
- name: LcrSid
in: path
required: true
style: simple
explode: false
schema:
type: string
delete:
tags:
- Lcrs
summary: delete a least cost routing
operationId: deleteLeastCostRouting
responses:
204:
description: least cost routing successfully deleted
404:
description: least cost routing not found
422:
description: unprocessable entity
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
example:
msg: a service provider with active accounts can not be deleted
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
get:
tags:
- Lcrs
summary: retrieve least cost routing
operationId: getLeastCostRouting
responses:
200:
description: least cost routing found
content:
application/json:
schema:
$ref: '#/components/schemas/Lcr'
404:
description: least cost routing not found
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
put:
tags:
- Lcrs
summary: update least cost routing
operationId: updateLeastCostRouting
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Lcr'
responses:
204:
description: least cost routing updated
content:
application/json:
schema:
$ref: '#/components/schemas/Lcr'
400:
description: bad request
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
404:
description: least cost routing not found
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
/LcrRoutes:
post:
tags:
- LcrRoutes
summary: create a Least Cost Routing Routes
operationId: createLcrRoutes
requestBody:
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/LcrRoute'
required:
- lcr_sid
- regex
- priority
responses:
201:
description: Least Cost Routing Route successfully created
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessfulAdd'
400:
description: bad request
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
422:
description: unprocessable entity
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
get:
tags:
- LcrRoutes
summary: list least cost routings routes
operationId: listLeastCostRoutingRoutes
responses:
200:
description: list of least cost routing routes
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/LcrRoute'
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
/LcrRoutes/{LcrRouteSid}:
parameters:
- name: LcrRouteSid
in: path
required: true
style: simple
explode: false
schema:
type: string
delete:
tags:
- LcrRoutes
summary: delete a least cost routing route
operationId: deleteLeastCostRoutingRoute
responses:
204:
description: least cost routing route successfully deleted
404:
description: least cost routing route not found
422:
description: unprocessable entity
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
example:
msg: a service provider with active accounts can not be deleted
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
get:
tags:
- LcrRoutes
summary: retrieve least cost routing route
operationId: getLeastCostRoutingRoute
responses:
200:
description: least cost routing route found
content:
application/json:
schema:
$ref: '#/components/schemas/LcrRoute'
404:
description: least cost routing route not found
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
put:
tags:
- LcrRoutes
summary: update least cost routing route
operationId: updateLeastCostRoutingRoute
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/LcrRoute'
responses:
204:
description: least cost routing route updated
content:
application/json:
schema:
$ref: '#/components/schemas/LcrRoute'
400:
description: bad request
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
404:
description: least cost routing route not found
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
/LcrCarrierSetEntries:
post:
tags:
- LcrCarrierSetEntries
summary: create a Least Cost Routing Carrier Set Entry
operationId: createLcrCarrierSetEntry
requestBody:
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/LcrCarrierSetEntry'
required:
- lcr_route_sid
- voip_carrier_sid
- priority
responses:
201:
description: Least Cost Routing Carrier Set Entry successfully created
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessfulAdd'
400:
description: bad request
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
422:
description: unprocessable entity
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
get:
tags:
- LcrCarrierSetEntries
summary: list least cost routings routes
operationId: listLeastCostRoutingCarrierSetEntries
responses:
200:
description: list of least cost routing carrier set entries
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/LcrCarrierSetEntry'
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
/LcrCarrierSetEntries/{LcrCarrierSetEntrySid}:
parameters:
- name: LcrCarrierSetEntrySid
in: path
required: true
style: simple
explode: false
schema:
type: string
delete:
tags:
- LcrCarrierSetEntries
summary: delete a least cost routing carrier set entry
operationId: deleteLeastCostRoutingCarrierSetEntry
responses:
204:
description: least cost routing carrier set entry successfully deleted
404:
description: least cost routing carrier set entry not found
422:
description: unprocessable entity
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
example:
msg: a service provider with active accounts can not be deleted
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
get:
tags:
- LcrCarrierSetEntries
summary: retrieve least cost routing carrier set entry
operationId: getLeastCostRoutingCarrierSetEntry
responses:
200:
description: least cost routing carrier set entry found
content:
application/json:
schema:
$ref: '#/components/schemas/LcrCarrierSetEntry'
404:
description: least cost routing carrier set entry not found
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
put:
tags:
- LcrCarrierSetEntries
summary: update least cost routing carrier set entry
operationId: updateLeastCostRoutingCarrierSetEntry
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/LcrCarrierSetEntry'
responses:
204:
description: least cost routing carrier set entry updated
content:
application/json:
schema:
$ref: '#/components/schemas/LcrCarrierSetEntry'
400:
description: bad request
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
404:
description: least cost routing carrier set entry not found
500:
description: system error
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
components:
securitySchemes:
bearerAuth:
@@ -4486,10 +4997,21 @@ components:
- phone
- sip
- user
- teams
number:
type: string
sipUri:
type: string
tenant:
type: string
description: Microsoft Teams customer tenant domain name
trunk:
type: string
vmail:
type: boolean
description: Dial directly into user's voicemail to leave a message
overrideTo:
type: string
name:
type: string
auth:
@@ -4974,6 +5496,57 @@ components:
- voice_call_session
- api_limit
- devices
Lcr:
type: object
properties:
name:
type: string
example: twilioLcr
default_carrier_set_entry_sid:
type: string
example: 3fa85f64-5717-4562-b3fc-2c963f66afa6
required:
- name
LcrRoute:
type: object
properties:
lcr_sid:
type: string
example: 3fa85f64-5717-4562-b3fc-2c963f66afa6
regex:
type: string
description: out going call Phone number regex
example: 1*
priority:
type: number
example: 1
description:
type: string
example: this is example description
required:
- lcr_sid
- regex
- priority
LcrCarrierSetEntry:
type: object
properties:
workload:
type: number
example: 90
description: traffic distribution value
lcr_route_sid:
type: string
example: 3fa85f64-5717-4562-b3fc-2c963f66afa6
voip_carrier_sid:
type: string
example: 3fa85f64-5717-4562-b3fc-2c963f66afa6
priority:
type: number
example: 1
required:
- lcr_route_sid
- voip_carrier_sid
- priority
security:
- bearerAuth: []

7620
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -22,11 +22,11 @@
"@aws-sdk/client-transcribe": "^3.290.0",
"@deepgram/sdk": "^1.10.2",
"@google-cloud/speech": "^5.1.0",
"@jambonz/db-helpers": "^0.7.3",
"@jambonz/db-helpers": "^0.7.8",
"@jambonz/realtimedb-helpers": "^0.7.1",
"@jambonz/speech-utils": "^0.0.8",
"@jambonz/speech-utils": "^0.0.12",
"@jambonz/time-series": "^0.2.5",
"@jambonz/verb-specifications": "^0.0.3",
"@jambonz/verb-specifications": "^0.0.17",
"@soniox/soniox-node": "^1.1.0",
"argon2": "^0.30.3",
"bent": "^7.3.12",
@@ -52,8 +52,8 @@
"yamljs": "^0.3.0"
},
"devDependencies": {
"eslint": "^7.32.0",
"eslint-plugin-promise": "^4.2.1",
"eslint": "^8.39.0",
"eslint-plugin-promise": "^6.1.1",
"husky": "7.0.4",
"nyc": "^15.1.0",
"request": "^2.88.2",

325
test/forgot-password.js Normal file
View File

@@ -0,0 +1,325 @@
const test = require('tape');
const request = require("request-promise-native").defaults({
baseUrl: "http://127.0.0.1:3000/v1",
});
let authAdmin;
let admin_user_sid;
let sp_sid;
let sp_user_sid;
let account_sid;
let account_sid2;
let account_user_sid;
let account_user_sid2;
const password = "12345foobar";
const adminEmail = "joe@foo.bar";
const emailInactiveAccount = 'inactive-account@example.com';
const emailInactiveUser = 'inactive-user@example.com';
test('forgot password - prepare', async (t) => {
/* login as admin to get a jwt */
let result = await request.post("/login", {
resolveWithFullResponse: true,
json: true,
body: {
username: "admin",
password: "admin",
},
});
t.ok(
result.statusCode === 200 && result.body.token,
"successfully logged in as admin"
);
authAdmin = { bearer: result.body.token };
admin_user_sid = result.body.user_sid;
/* add a service provider */
result = await request.post("/ServiceProviders", {
resolveWithFullResponse: true,
auth: authAdmin,
json: true,
body: {
name: "sp" + Date.now(),
},
});
t.ok(result.statusCode === 201, "successfully created service provider");
sp_sid = result.body.sid;
/* add service_provider user */
const randomNumber = Math.floor(Math.random() * 101);
result = await request.post(`/Users`, {
resolveWithFullResponse: true,
json: true,
auth: authAdmin,
body: {
name: "service_provider" + Date.now(),
email: `sp${randomNumber}@example.com`,
is_active: true,
force_change: true,
initial_password: password,
service_provider_sid: sp_sid,
},
});
t.ok(
result.statusCode === 201 && result.body.user_sid,
"service_provider scope user created"
);
sp_user_sid = result.body.user_sid;
/* add an account - inactive */
result = await request.post("/Accounts", {
resolveWithFullResponse: true,
auth: authAdmin,
json: true,
body: {
name: "sample_account inactive" + Date.now(),
service_provider_sid: sp_sid,
registration_hook: {
url: "http://example.com/reg",
method: "get",
},
is_active: false,
webhook_secret: "foobar",
},
});
t.ok(result.statusCode === 201, "successfully created account");
account_sid = result.body.sid;
/* add an account - inactive */
result = await request.post("/Accounts", {
resolveWithFullResponse: true,
auth: authAdmin,
json: true,
body: {
name: "sample_account active" + Date.now(),
service_provider_sid: sp_sid,
registration_hook: {
url: "http://example.com/reg",
method: "get",
},
is_active: true,
webhook_secret: "foobar",
},
});
t.ok(result.statusCode === 201, "successfully created account");
account_sid2 = result.body.sid;
/* add account user connected to an inactive account */
result = await request.post(`/Users`, {
resolveWithFullResponse: true,
json: true,
auth: authAdmin,
body: {
name: "account user active - inactive account" + randomNumber,
email: emailInactiveAccount,
is_active: true,
force_change: true,
initial_password: password,
service_provider_sid: sp_sid,
account_sid: account_sid,
},
});
t.ok(
result.statusCode === 201 && result.body.user_sid,
"account scope user created"
);
account_user_sid = result.body.user_sid;
/* add account user that is not active */
result = await request.post(`/Users`, {
resolveWithFullResponse: true,
json: true,
auth: authAdmin,
body: {
name: "account user inactive - active account" + randomNumber,
email: emailInactiveUser,
is_active: false,
force_change: true,
initial_password: password,
service_provider_sid: sp_sid,
account_sid: account_sid2,
},
});
t.ok(
result.statusCode === 201 && result.body.user_sid,
"account scope user created"
);
account_user_sid2 = result.body.user_sid;
});
test('forgot password with valid email', async (t) => {
const res = await request
.post('/forgot-password',
{
resolveWithFullResponse: true,
json: true,
auth: authAdmin,
body: { email: adminEmail }
});
t.equal(res.statusCode, 204, 'returns 204 status code');
t.end();
});
test('forgot password with invalid email', async (t) => {
const statusCode = 400;
const errorMessage = 'invalid or missing email';
const email = 'invalid-email';
try {
await request
.post('/forgot-password', {
resolveWithFullResponse: true,
json: true,
auth: authAdmin,
body: { email }
});
} catch (error) {
t.throws(
() => {
throw error;
},
{
name: "StatusCodeError",
statusCode,
message: `${statusCode} - {"error":"${errorMessage}"}`,
}
);
}
t.end();
});
test('forgot password with non-existent email', async (t) => {
const statusCode = 400;
const errorMessage = 'email does not exist';
const email = 'non-existent-email@example.com';
try {
await request
.post('/forgot-password', {
resolveWithFullResponse: true,
json: true,
auth: authAdmin,
body: { email }
});
} catch (error) {
t.throws(
() => {
throw error;
},
{
name: "StatusCodeError",
statusCode,
message: `${statusCode} - {"error":"${errorMessage}"}`,
}
);
}
t.end();
});
test('forgot password with inactive user', async (t) => {
const statusCode = 400;
const errorMessage = 'you may not reset the password of an inactive user';
try {
await request
.post('/forgot-password', {
resolveWithFullResponse: true,
json: true,
auth: authAdmin,
body: { email: emailInactiveUser }
});
} catch (error) {
t.throws(
() => {
throw error;
},
{
name: "StatusCodeError",
statusCode,
message: `${statusCode} - {"error":"${errorMessage}"}`,
}
);
}
t.end();
});
test('forgot password with inactive account', async (t) => {
const statusCode = 400;
const errorMessage = 'you may not reset the password of an inactive account';
try {
await request
.post('/forgot-password', {
resolveWithFullResponse: true,
json: true,
auth: authAdmin,
body: { email: emailInactiveAccount }
});
} catch (error) {
t.throws(
() => {
throw error;
},
{
name: "StatusCodeError",
statusCode,
message: `${statusCode} - {"error":"${errorMessage}"}`,
}
);
}
t.end();
});
test('cleanup', async (t) => {
/* login as admin to get a jwt */
let result = await request.post("/login", {
resolveWithFullResponse: true,
json: true,
body: {
username: "admin",
password: "admin",
},
});
t.ok(
result.statusCode === 200 && result.body.token,
"successfully logged in as admin"
);
authAdmin = { bearer: result.body.token };
/* list users */
result = await request.get(`/Users`, {
resolveWithFullResponse: true,
json: true,
auth: authAdmin,
});
const users = result.body;
/* delete all users except admin */
for (const user of users) {
if (user.user_sid === admin_user_sid) continue;
result = await request.delete(`/Users/${user.user_sid}`, {
resolveWithFullResponse: true,
json: true,
auth: authAdmin,
});
t.ok(result.statusCode === 204, "user deleted");
}
/* list accounts */
result = await request.get(`/Accounts`, {
resolveWithFullResponse: true,
json: true,
auth: authAdmin,
});
const accounts = result.body;
for (const acc of accounts) {
result = await request.delete(`/Accounts/${acc.account_sid}`, {
resolveWithFullResponse: true,
json: true,
auth: authAdmin,
});
t.ok(result.statusCode === 204, "acc deleted");
}
});

View File

@@ -19,4 +19,8 @@ require('./webapp_tests');
require('./call-test');
require('./password-settings');
require('./email_utils');
require('./system-information');
require('./lcr-carriers-set-entries');
require('./lcr-routes');
require('./lcrs');
require('./docker_stop');

View File

@@ -0,0 +1,103 @@
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'
});
const {createLcrRoute, createVoipCarrier} = require('./utils');
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
});
test('lcr carrier set entries test', async(t) => {
const app = require('../app');
let sid;
try {
let result;
const lcr_route = await createLcrRoute(request);
const voip_carrier_sid = await createVoipCarrier(request);
/* add new entity */
result = await request.post('/LcrCarrierSetEntries', {
resolveWithFullResponse: true,
auth: authAdmin,
json: true,
body: {
workload: 1,
lcr_route_sid: lcr_route.lcr_route_sid,
voip_carrier_sid,
priority: 1
}
});
t.ok(result.statusCode === 201, 'successfully created lcr carrier set entry ');
const sid = result.body.sid;
/* query all entity */
result = await request.get('/LcrCarrierSetEntries', {
qs: {lcr_route_sid: lcr_route.lcr_route_sid},
auth: authAdmin,
json: true,
});
t.ok(result.length === 1 , 'successfully queried all lcr carrier set entry');
/* query one entity */
result = await request.get(`/LcrCarrierSetEntries/${sid}`, {
auth: authAdmin,
json: true,
});
t.ok(result.workload === 1 , 'successfully retrieved lcr carrier set entry by sid');
/* update the entity */
result = await request.put(`/LcrCarrierSetEntries/${sid}`, {
auth: authAdmin,
json: true,
resolveWithFullResponse: true,
body: {
priority: 2
}
});
t.ok(result.statusCode === 204, 'successfully updated LcrCarrierSetEntries');
/* query one entity */
result = await request.get(`/LcrCarrierSetEntries/${sid}`, {
auth: authAdmin,
json: true,
});
t.ok(result.priority === 2 , 'successfully updated lcr carrier set entry by sid');
/* delete lcr carrier set entry */
result = await request.delete(`/LcrCarrierSetEntries/${sid}`, {
resolveWithFullResponse: true,
simple: false,
json: true,
auth: authAdmin
});
t.ok(result.statusCode === 204, 'successfully deleted LcrCarrierSetEntries');
/* delete lcr route */
result = await request.delete(`/LcrRoutes/${lcr_route.lcr_route_sid}`, {
resolveWithFullResponse: true,
simple: false,
json: true,
auth: authAdmin
});
t.ok(result.statusCode === 204, 'successfully deleted LcrRoutes');
/* delete lcr */
result = await request.delete(`/Lcrs/${lcr_route.lcr_sid}`, {
resolveWithFullResponse: true,
simple: false,
json: true,
auth: authAdmin
});
t.ok(result.statusCode === 204, 'successfully deleted Lcr');
t.end();
}
catch (err) {
console.error(err);
t.end(err);
}
});

93
test/lcr-routes.js Normal file
View File

@@ -0,0 +1,93 @@
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'
});
const {createLcr} = require('./utils');
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
});
test('lcr routes test', async(t) => {
const app = require('../app');
let sid;
try {
let result;
const lcr_sid = await createLcr(request);
/* add new entity */
result = await request.post('/LcrRoutes', {
resolveWithFullResponse: true,
auth: authAdmin,
json: true,
body: {
lcr_sid,
regex: '1*',
description: 'description',
priority: 1
}
});
t.ok(result.statusCode === 201, 'successfully created lcr route ');
const sid = result.body.sid;
/* query all entity */
result = await request.get('/LcrRoutes', {
qs: {lcr_sid},
auth: authAdmin,
json: true,
});
t.ok(result.length === 1 , 'successfully queried all lcr route');
/* query one entity */
result = await request.get(`/LcrRoutes/${sid}`, {
auth: authAdmin,
json: true,
});
t.ok(result.priority === 1 , 'successfully retrieved lcr route by sid');
/* update the entity */
result = await request.put(`/LcrRoutes/${sid}`, {
auth: authAdmin,
json: true,
resolveWithFullResponse: true,
body: {
priority: 2
}
});
t.ok(result.statusCode === 204, 'successfully updated Lcr Route');
/* query one entity */
result = await request.get(`/LcrRoutes/${sid}`, {
auth: authAdmin,
json: true,
});
t.ok(result.priority === 2 , 'successfully updated lcr Route by sid');
/* delete lcr Route */
result = await request.delete(`/LcrRoutes/${sid}`, {
resolveWithFullResponse: true,
simple: false,
json: true,
auth: authAdmin
});
t.ok(result.statusCode === 204, 'successfully deleted LcrRoutes');
/* delete lcr */
result = await request.delete(`/Lcrs/${lcr_sid}`, {
resolveWithFullResponse: true,
simple: false,
json: true,
auth: authAdmin
});
t.ok(result.statusCode === 204, 'successfully deleted Lcr');
t.end();
}
catch (err) {
console.error(err);
t.end(err);
}
});

76
test/lcrs.js Normal file
View File

@@ -0,0 +1,76 @@
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('lcr test', async(t) => {
const app = require('../app');
let sid;
try {
let result;
/* add new entity */
result = await request.post('/Lcrs', {
resolveWithFullResponse: true,
auth: authAdmin,
json: true,
body: {
name: 'name'
}
});
t.ok(result.statusCode === 201, 'successfully created lcr');
const sid = result.body.sid;
/* query all entity */
result = await request.get('/Lcrs', {
auth: authAdmin,
json: true,
});
t.ok(result.length === 1 , 'successfully queried all lcr');
/* query one entity */
result = await request.get(`/Lcrs/${sid}`, {
auth: authAdmin,
json: true,
});
t.ok(result.name === 'name' , 'successfully retrieved lcr by sid');
/* update the entity */
result = await request.put(`/Lcrs/${sid}`, {
auth: authAdmin,
json: true,
resolveWithFullResponse: true,
body: {
name: 'name2'
}
});
t.ok(result.statusCode === 204, 'successfully updated Lcr');
/* query one entity */
result = await request.get(`/Lcrs/${sid}`, {
auth: authAdmin,
json: true,
});
t.ok(result.name === 'name2' , 'successfully updated lcr by sid');
/* delete lcr Route */
result = await request.delete(`/Lcrs/${sid}`, {
resolveWithFullResponse: true,
simple: false,
json: true,
auth: authAdmin
});
t.ok(result.statusCode === 204, 'successfully deleted Lcrs');
t.end();
}
catch (err) {
console.error(err);
t.end(err);
}
});

View File

@@ -75,7 +75,7 @@ test('sip gateway tests', async(t) => {
await deleteObjectBySid(request, '/VoipCarriers', voip_carrier_sid);
//t.end();
t.end();
}
catch (err) {
console.error(err);

View File

@@ -0,0 +1,64 @@
const test = require('tape') ;
const jwt = require('jsonwebtoken');
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'
});
test('system information test', async(t) => {
const app = require('../app');
try {
let result = await request.post('/SystemInformation', {
resolveWithFullResponse: true,
auth: authAdmin,
json: true,
body: {
domain_name: 'test.com',
sip_domain_name: 'sip.test.com',
monitoring_domain_name: 'monitor.test.com'
}
});
t.ok(result.statusCode === 201, 'successfully created system information ');
let body = result.body;
t.ok(body.domain_name === 'test.com', 'added domain_name ok');
t.ok(body.sip_domain_name === 'sip.test.com', 'added sip_domain_name ok');
t.ok(body.monitoring_domain_name === 'monitor.test.com', 'added monitoring_domain_name ok');
result = await request.get('/SystemInformation', {
auth: authAdmin,
json: true,
});
t.ok(result.domain_name === 'test.com', 'get domain_name ok');
t.ok(result.sip_domain_name === 'sip.test.com', 'get sip_domain_name ok');
t.ok(result.monitoring_domain_name === 'monitor.test.com', 'get monitoring_domain_name ok');
result = await request.post('/SystemInformation', {
resolveWithFullResponse: true,
auth: authAdmin,
json: true,
body: {
domain_name: 'test1.com',
sip_domain_name: 'sip1.test.com',
monitoring_domain_name: 'monitor1.test.com'
}
});
t.ok(result.statusCode === 201, 'successfully updated system information ');
body = result.body;
t.ok(body.domain_name === 'test1.com', 'updated domain_name ok');
t.ok(body.sip_domain_name === 'sip1.test.com', 'updated sip_domain_name ok');
t.ok(body.monitoring_domain_name === 'monitor1.test.com', 'updated monitoring_domain_name ok');
result = await request.get('/SystemInformation', {
auth: authAdmin,
json: true,
});
t.ok(result.domain_name === 'test1.com', 'get domain_name ok');
t.ok(result.sip_domain_name === 'sip1.test.com', 'get sip_domain_name ok');
t.ok(result.monitoring_domain_name === 'monitor1.test.com', 'get monitoring_domain_name ok');
} catch(err) {
console.error(err);
t.end(err);
}
});

View File

@@ -29,6 +29,31 @@ async function createVoipCarrier(request, name = 'daveh') {
return result.sid;
}
async function createLcr(request, name = 'lcr') {
const result = await request.post('/Lcrs', {
auth: authAdmin,
json: true,
body: {
name
}
});
return result.sid;
}
async function createLcrRoute(request, lcr_name= 'lcr', lcr_route_regex = "1*", lcr_route_priority = 1) {
const lcr = await createLcr(request, lcr_name);
const result = await request.post('/LcrRoutes', {
auth: authAdmin,
json: true,
body: {
lcr_sid: lcr,
regex: lcr_route_regex,
priority: lcr_route_priority
}
});
return {lcr_sid: lcr, lcr_route_sid: result.sid};
}
async function createPhoneNumber(request, voip_carrier_sid, number = '15083333456') {
const result = await request.post('/PhoneNumbers', {
auth: authAdmin,
@@ -136,5 +161,7 @@ module.exports = {
createApiKey,
deleteObjectBySid,
createGoogleSpeechCredentials,
getLastRequestFromFeatureServer
getLastRequestFromFeatureServer,
createLcr,
createLcrRoute
};