mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-01-25 02:08:24 +00:00
Compare commits
15 Commits
v0.7.5-rc1
...
fix-return
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
81def62a03 | ||
|
|
b60fd4bbc4 | ||
|
|
08163a31d0 | ||
|
|
1898ba501d | ||
|
|
6f52202deb | ||
|
|
0ceb79b568 | ||
|
|
1e396266a0 | ||
|
|
69f36f5a51 | ||
|
|
f83cc25098 | ||
|
|
1473c30d7b | ||
|
|
6088b99acf | ||
|
|
9aab716dc9 | ||
|
|
56b646b6db | ||
|
|
eeb23109dc | ||
|
|
17d1be4605 |
25
Dockerfile
25
Dockerfile
@@ -1,10 +1,23 @@
|
||||
FROM node:17
|
||||
FROM --platform=linux/amd64 node:18.6.0-alpine as base
|
||||
|
||||
RUN apk --update --no-cache add --virtual .builds-deps build-base python3
|
||||
|
||||
WORKDIR /opt/app/
|
||||
COPY package.json ./
|
||||
RUN npm install
|
||||
RUN npm prune
|
||||
COPY . /opt/app
|
||||
|
||||
FROM base as build
|
||||
|
||||
COPY package.json package-lock.json ./
|
||||
|
||||
RUN npm ci
|
||||
|
||||
COPY . .
|
||||
|
||||
FROM base
|
||||
|
||||
COPY --from=build /opt/app /opt/app/
|
||||
|
||||
ARG NODE_ENV
|
||||
|
||||
ENV NODE_ENV $NODE_ENV
|
||||
|
||||
CMD [ "npm", "start" ]
|
||||
CMD [ "node", "app.js" ]
|
||||
@@ -1,10 +1,23 @@
|
||||
FROM node:17
|
||||
FROM --platform=linux/amd64 node:18.6.0-alpine as base
|
||||
|
||||
RUN apk --update --no-cache add --virtual .builds-deps build-base python3
|
||||
|
||||
WORKDIR /opt/app/
|
||||
COPY package.json ./
|
||||
RUN npm install
|
||||
RUN npm prune
|
||||
COPY . /opt/app
|
||||
|
||||
FROM base as build
|
||||
|
||||
COPY package.json package-lock.json ./
|
||||
|
||||
RUN npm ci
|
||||
|
||||
COPY . .
|
||||
|
||||
FROM base
|
||||
|
||||
COPY --from=build /opt/app /opt/app/
|
||||
|
||||
ARG NODE_ENV
|
||||
|
||||
ENV NODE_ENV $NODE_ENV
|
||||
|
||||
CMD [ "npm", "run", "upgrade-db" ]
|
||||
@@ -365,7 +365,7 @@ CREATE TABLE webhooks
|
||||
(
|
||||
webhook_sid CHAR(36) NOT NULL UNIQUE ,
|
||||
url VARCHAR(1024) NOT NULL,
|
||||
method ENUM("GET","POST","WS") NOT NULL DEFAULT 'POST',
|
||||
method ENUM("GET","POST") NOT NULL DEFAULT 'POST',
|
||||
username VARCHAR(255),
|
||||
password VARCHAR(255),
|
||||
PRIMARY KEY (webhook_sid)
|
||||
@@ -422,6 +422,7 @@ subspace_client_id VARCHAR(255),
|
||||
subspace_client_secret VARCHAR(255),
|
||||
subspace_sip_teleport_id VARCHAR(255),
|
||||
subspace_sip_teleport_destinations VARCHAR(255),
|
||||
siprec_hook_sid CHAR(36),
|
||||
PRIMARY KEY (account_sid)
|
||||
) COMMENT='An enterprise that uses the platform for comm services';
|
||||
|
||||
@@ -576,4 +577,6 @@ ALTER TABLE accounts ADD FOREIGN KEY queue_event_hook_sid_idxfk (queue_event_hoo
|
||||
|
||||
ALTER TABLE accounts ADD FOREIGN KEY device_calling_application_sid_idxfk (device_calling_application_sid) REFERENCES applications (application_sid);
|
||||
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
ALTER TABLE accounts ADD FOREIGN KEY siprec_hook_sid_idxfk (siprec_hook_sid) REFERENCES applications (application_sid);
|
||||
|
||||
SET FOREIGN_KEY_CHECKS=1;
|
||||
|
||||
@@ -1412,7 +1412,7 @@
|
||||
</location>
|
||||
<size>
|
||||
<width>318.00</width>
|
||||
<height>420.00</height>
|
||||
<height>440.00</height>
|
||||
</size>
|
||||
<zorder>4</zorder>
|
||||
<SQLField>
|
||||
@@ -1577,6 +1577,19 @@
|
||||
<type><![CDATA[VARCHAR(255)]]></type>
|
||||
<uid><![CDATA[2A70CC94-123D-4AF1-9881-F876051D8CB5]]></uid>
|
||||
</SQLField>
|
||||
<SQLField>
|
||||
<name><![CDATA[siprec_hook_sid]]></name>
|
||||
<type><![CDATA[CHAR(36)]]></type>
|
||||
<referencesField>application_sid</referencesField>
|
||||
<referencesTable>applications</referencesTable>
|
||||
<referencesField><![CDATA[application_sid]]></referencesField>
|
||||
<referencesTable><![CDATA[applications]]></referencesTable>
|
||||
<sourceCardinality>4</sourceCardinality>
|
||||
<destinationCardinality>1</destinationCardinality>
|
||||
<referencesFieldUID><![CDATA[EF943D13-DCB0-43C1-B03F-550612E20F9D]]></referencesFieldUID>
|
||||
<referencesTableUID><![CDATA[E97EE4F0-7ED7-4E8C-862E-D98192D6EAE0]]></referencesTableUID>
|
||||
<uid><![CDATA[4B8283B4-5E16-4846-A79D-12C6B2E73C86]]></uid>
|
||||
</SQLField>
|
||||
<labelWindowIndex><![CDATA[25]]></labelWindowIndex>
|
||||
<objectComment><![CDATA[An enterprise that uses the platform for comm services]]></objectComment>
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
@@ -1855,7 +1868,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[25]]></labelWindowIndex>
|
||||
<labelWindowIndex><![CDATA[26]]></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>
|
||||
@@ -2433,17 +2446,17 @@
|
||||
<overviewPanelHidden><![CDATA[0]]></overviewPanelHidden>
|
||||
<pageBoundariesVisible><![CDATA[0]]></pageBoundariesVisible>
|
||||
<PageGridVisible><![CDATA[0]]></PageGridVisible>
|
||||
<RightSidebarWidth><![CDATA[2154.000000]]></RightSidebarWidth>
|
||||
<RightSidebarWidth><![CDATA[1235.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[977.000000]]></windowHeight>
|
||||
<windowLocationX><![CDATA[1230.000000]]></windowLocationX>
|
||||
<windowLocationY><![CDATA[80.000000]]></windowLocationY>
|
||||
<windowScrollOrigin><![CDATA[{0, 0}]]></windowScrollOrigin>
|
||||
<windowWidth><![CDATA[2431.000000]]></windowWidth>
|
||||
<windowHeight><![CDATA[833.000000]]></windowHeight>
|
||||
<windowLocationX><![CDATA[0.000000]]></windowLocationX>
|
||||
<windowLocationY><![CDATA[111.000000]]></windowLocationY>
|
||||
<windowScrollOrigin><![CDATA[{172, 109}]]></windowScrollOrigin>
|
||||
<windowWidth><![CDATA[1512.000000]]></windowWidth>
|
||||
</SQLDocumentInfo>
|
||||
<AllowsIndexRenamingOnInsert><![CDATA[1]]></AllowsIndexRenamingOnInsert>
|
||||
<defaultLabelExpanded><![CDATA[1]]></defaultLabelExpanded>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
|
||||
-- create one service provider
|
||||
insert into service_providers (service_provider_sid, name, description, root_domain)
|
||||
values ('2708b1b3-2736-40ea-b502-c53d8396247f', 'sip.jambonz.us', 'jambonz.us service provider', 'sip.jambonz.us');
|
||||
values ('2708b1b3-2736-40ea-b502-c53d8396247f', 'sip.jambonz.xyz', 'jambonz.xyz service provider', 'sip.jambonz.xyz');
|
||||
insert into api_keys (api_key_sid, token)
|
||||
values ('3f35518f-5a0d-4c2e-90a5-2407bb3b36f0', '38700987-c7a4-4685-a5bb-af378f9734de');
|
||||
|
||||
@@ -16,9 +18,9 @@ insert into predefined_carriers (predefined_carrier_sid, name, requires_static_i
|
||||
requires_register, register_username, register_password,
|
||||
register_sip_realm, tech_prefix, inbound_auth_username, inbound_auth_password, diversion)
|
||||
VALUES
|
||||
('17479288-bb9f-421a-89d1-f4ac57af1dca', 'TelecomsXChange', 0, 0, 0, NULL, NULL, NULL, 'your-tech-prefix', NULL, NULL, NULL),
|
||||
('7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', 'Twilio', 0, 1, 0, '<your-twilio-credential-username>', '<your-twilio-credential-password>', NULL, NULL, NULL, NULL, NULL),
|
||||
('032d90d5-39e8-41c0-b807-9c88cffba65c', 'Voxbone', 0, 1, 0, '<your-voxbone-outbound-username>', '<your-voxbone-outbound-password>', NULL, NULL, NULL, NULL, '<your-voxbone-DID>'),
|
||||
('17479288-bb9f-421a-89d1-f4ac57af1dca', 'TelecomsXChange', 0, 0, 0, NULL, NULL, NULL, 'your-tech-prefix', NULL, NULL, NULL),
|
||||
('e6fb301a-1af0-4fb8-a1f6-f65530c6e1c6', 'Simwood', 0, 1, 0, '<your-simwood-auth-trunk-username>', '<your-simwood-auth-trunk-password>', NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
-- TelecomXchange gateways
|
||||
@@ -69,3 +71,4 @@ VALUES
|
||||
('e7447e7e-2c7d-4738-ab53-097c187236ff', 'e6fb301a-1af0-4fb8-a1f6-f65530c6e1c6', '178.22.143.66', 32, 5060, 1, 0),
|
||||
('5f431d42-48e4-44ce-a311-d946f0b475b6', 'e6fb301a-1af0-4fb8-a1f6-f65530c6e1c6', 'out.simwood.com', 32, 5060, 0, 1);
|
||||
|
||||
SET FOREIGN_KEY_CHECKS=1;
|
||||
|
||||
@@ -22,6 +22,14 @@ const opts = {
|
||||
multipleStatements: true
|
||||
};
|
||||
|
||||
const sql = {
|
||||
'7006': [
|
||||
'ALTER TABLE `accounts` ADD COLUMN `siprec_hook_sid` CHAR(36)',
|
||||
// eslint-disable-next-line max-len
|
||||
'ALTER TABLE accounts ADD FOREIGN KEY siprec_hook_sid_idxfk (siprec_hook_sid) REFERENCES applications (application_sid)'
|
||||
]
|
||||
};
|
||||
|
||||
const doIt = async() => {
|
||||
let connection;
|
||||
try {
|
||||
@@ -35,10 +43,32 @@ const doIt = async() => {
|
||||
try {
|
||||
/* does the schema exist at all ? */
|
||||
const [r] = await connection.execute('SELECT version from schema_version');
|
||||
let errors = 0;
|
||||
if (r.length) {
|
||||
//TODO: check against desired version and perform upgrades
|
||||
logger.info(`current version is ${r[0].version}, no upgrade will be performed`);
|
||||
const {version} = r[0];
|
||||
const arr = /v?(\d+)\.(\d+)\.(\d+)/.exec(version);
|
||||
if (arr) {
|
||||
const upgrades = [];
|
||||
logger.info(`performing schema migration: ${version} => ${desiredVersion}`);
|
||||
const val = (1000 * arr[1]) + (100 * arr[2]) + arr[3];
|
||||
logger.info(`current schema value: ${val}`);
|
||||
|
||||
if (val < 7006) upgrades.push(...sql['7006']);
|
||||
|
||||
// perform all upgrades
|
||||
logger.info({upgrades}, 'applying schema upgrades..');
|
||||
for (const upgrade of upgrades) {
|
||||
try {
|
||||
await connection.execute(upgrade);
|
||||
} catch (err) {
|
||||
errors++;
|
||||
logger.info({statement:upgrade, err}, 'Error applying statement');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (errors === 0) await connection.execute(`UPDATE schema_version SET version = '${desiredVersion}'`);
|
||||
await connection.end();
|
||||
logger.info(`schema migration to ${desiredVersion} completed with ${errors} errors`);
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -70,5 +100,6 @@ const seedDatabase = async(connection) => {
|
||||
await connection.query(sql);
|
||||
};
|
||||
|
||||
|
||||
doIt();
|
||||
|
||||
|
||||
@@ -314,6 +314,10 @@ Account.fields = [
|
||||
name: 'subspace_sip_teleport_destinations',
|
||||
type: 'string',
|
||||
},
|
||||
{
|
||||
name: 'siprec_hook_sid',
|
||||
type: 'string',
|
||||
},
|
||||
];
|
||||
|
||||
module.exports = Account;
|
||||
|
||||
@@ -117,7 +117,8 @@ function validateUpdateCall(opts) {
|
||||
'conf_hold_status',
|
||||
'conf_mute_status',
|
||||
'mute_status',
|
||||
'sip_request'
|
||||
'sip_request',
|
||||
'record'
|
||||
]
|
||||
.reduce((acc, prop) => (opts[prop] ? ++acc : acc), 0);
|
||||
|
||||
@@ -156,6 +157,12 @@ function validateUpdateCall(opts) {
|
||||
(!opts.sip_request.method && !opts.sip_request.content_type || !opts.sip_request.content_type)) {
|
||||
throw new DbErrorBadRequest('sip_request requires content_type and content properties');
|
||||
}
|
||||
if (opts.record && !opts.record.action) {
|
||||
throw new DbErrorBadRequest('record requires action property');
|
||||
}
|
||||
if ('startCallRecording' === opts.record?.action && !opts.record.siprecServerURL) {
|
||||
throw new DbErrorBadRequest('record requires siprecServerURL property when starting recording');
|
||||
}
|
||||
}
|
||||
|
||||
function validateTo(to) {
|
||||
|
||||
@@ -104,7 +104,7 @@ router.get('/:sid', async(req, res) => {
|
||||
const account_sid = req.user.hasAccountAuth ? req.user.account_sid : null;
|
||||
const results = await Application.retrieve(req.params.sid, service_provider_sid, account_sid);
|
||||
if (results.length === 0) return res.status(404).end();
|
||||
return res.status(200).json(results);
|
||||
return res.status(200).json(results[0]);
|
||||
}
|
||||
catch (err) {
|
||||
sysError(logger, res, err);
|
||||
|
||||
@@ -1346,6 +1346,12 @@ paths:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
account_sid:
|
||||
type: string
|
||||
format: uuid
|
||||
application_sid:
|
||||
type: string
|
||||
format: uuid
|
||||
number:
|
||||
type: string
|
||||
description: telephone number
|
||||
@@ -3135,6 +3141,20 @@ paths:
|
||||
type: string
|
||||
headers:
|
||||
type: object
|
||||
record:
|
||||
type: object
|
||||
properties:
|
||||
action:
|
||||
type: string
|
||||
enum:
|
||||
- startCallRecording
|
||||
- stopCallRecording
|
||||
- pauseCallRecording
|
||||
- resumeCallRecording
|
||||
recordingID:
|
||||
type: string
|
||||
siprecServerURL:
|
||||
type: string
|
||||
responses:
|
||||
200:
|
||||
description: Accepted
|
||||
|
||||
4236
package-lock.json
generated
4236
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jambonz-api-server",
|
||||
"version": "v0.7.5",
|
||||
"version": "v0.7.6",
|
||||
"description": "",
|
||||
"main": "app.js",
|
||||
"scripts": {
|
||||
@@ -18,42 +18,39 @@
|
||||
"url": "https://github.com/jambonz/jambonz-api-server.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"@google-cloud/speech": "^4.10.0",
|
||||
"@google-cloud/speech": "^4.10.2",
|
||||
"@google-cloud/text-to-speech": "^3.4.0",
|
||||
"@jambonz/db-helpers": "^0.6.16",
|
||||
"@jambonz/realtimedb-helpers": "^0.4.24",
|
||||
"@jambonz/time-series": "^0.1.6",
|
||||
"@jambonz/db-helpers": "^0.6.18",
|
||||
"@jambonz/realtimedb-helpers": "^0.4.29",
|
||||
"@jambonz/time-series": "^0.1.9",
|
||||
"argon2-ffi": "^2.0.0",
|
||||
"aws-sdk": "^2.1073.0",
|
||||
"aws-sdk": "^2.1152.0",
|
||||
"bent": "^7.3.12",
|
||||
"cors": "^2.8.5",
|
||||
"debug": "^4.3.3",
|
||||
"express": "^4.17.2",
|
||||
"express-rate-limit": "^6.3.0",
|
||||
"debug": "^4.3.4",
|
||||
"express": "^4.18.1",
|
||||
"express-rate-limit": "^6.4.0",
|
||||
"form-data": "^2.5.1",
|
||||
"form-urlencoded": "^6.0.5",
|
||||
"helmet": "^5.0.2",
|
||||
"helmet": "^5.1.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mailgun.js": "^3.7.3",
|
||||
"microsoft-cognitiveservices-speech-sdk": "^1.19.0",
|
||||
"mysql2": "^2.3.3",
|
||||
"passport": "^0.5.2",
|
||||
"passport": "^0.6.0",
|
||||
"passport-http-bearer": "^1.0.1",
|
||||
"pino": "^5.17.0",
|
||||
"request-debug": "^0.2.0",
|
||||
"short-uuid": "^4.1.0",
|
||||
"stripe": "^8.196.0",
|
||||
"swagger-ui-express": "^4.3.0",
|
||||
"stripe": "^8.222.0",
|
||||
"swagger-ui-express": "^4.4.0",
|
||||
"uuid": "^8.3.2",
|
||||
"yamljs": "^0.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^7.17.0",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-plugin-promise": "^4.2.1",
|
||||
"husky": "7.0.4",
|
||||
"nyc": "^15.1.0",
|
||||
"request": "^2.88.2",
|
||||
"request-promise-native": "^1.0.9",
|
||||
"tape": "^5.2.2"
|
||||
"tape": "^5.5.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ test('application tests', async(t) => {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
});
|
||||
t.ok(result[0].name === 'daveh' , 'successfully retrieved application by sid');
|
||||
t.ok(result[0].messaging_hook.url === 'http://example.com/sms' , 'successfully retrieved messaging_hook from application');
|
||||
t.ok(result.name === 'daveh' , 'successfully retrieved application by sid');
|
||||
t.ok(result.messaging_hook.url === 'http://example.com/sms' , 'successfully retrieved messaging_hook from application');
|
||||
|
||||
/* update applications */
|
||||
result = await request.put(`/Applications/${sid}`, {
|
||||
@@ -84,7 +84,7 @@ test('application tests', async(t) => {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
});
|
||||
t.ok(result[0].messaging_hook.url === 'http://example2.com/mms' , 'successfully updated messaging_hook');
|
||||
t.ok(result.messaging_hook.url === 'http://example2.com/mms' , 'successfully updated messaging_hook');
|
||||
|
||||
/* assign phone number to application */
|
||||
result = await request.put(`/PhoneNumbers/${phone_number_sid}`, {
|
||||
|
||||
@@ -318,7 +318,7 @@ test('authentication tests', async(t) => {
|
||||
json: true
|
||||
});
|
||||
//console.log(`result: ${JSON.stringify(result)}`);
|
||||
t.ok(result.length === 1, 'using account token A1 we are able to retrieve application A1');
|
||||
t.ok(result.name === "A1-app", 'using account token A1 we are able to retrieve application A1');
|
||||
|
||||
/* cannot see app under another account using account token */
|
||||
result = await request.get(`/Applications/${appA2}`, {
|
||||
|
||||
Reference in New Issue
Block a user