@app-connect/core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +266 -0
- package/adapter/mock.js +77 -0
- package/adapter/registry.js +115 -0
- package/handlers/admin.js +60 -0
- package/handlers/auth.js +156 -0
- package/handlers/contact.js +275 -0
- package/handlers/disposition.js +194 -0
- package/handlers/log.js +586 -0
- package/handlers/user.js +102 -0
- package/index.js +1202 -0
- package/lib/analytics.js +53 -0
- package/lib/callLogComposer.js +452 -0
- package/lib/encode.js +30 -0
- package/lib/generalErrorMessage.js +42 -0
- package/lib/jwt.js +16 -0
- package/lib/oauth.js +85 -0
- package/lib/util.js +40 -0
- package/models/adminConfigModel.js +17 -0
- package/models/cacheModel.js +23 -0
- package/models/callLogModel.js +27 -0
- package/models/dynamo/lockSchema.js +25 -0
- package/models/messageLogModel.js +25 -0
- package/models/sequelize.js +17 -0
- package/models/userModel.js +38 -0
- package/package.json +58 -0
- package/releaseNotes.json +578 -0
package/lib/util.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
const tzlookup = require('tz-lookup');
|
|
3
|
+
const { State } = require('country-state-city');
|
|
4
|
+
const crypto = require('crypto');
|
|
5
|
+
|
|
6
|
+
function getTimeZone(countryCode, stateCode) {
|
|
7
|
+
const state = State.getStateByCodeAndCountry(stateCode, countryCode);
|
|
8
|
+
if (!state) {
|
|
9
|
+
return 'Unknown timezone';
|
|
10
|
+
}
|
|
11
|
+
const timezone = tzlookup(state.latitude, state.longitude);
|
|
12
|
+
return timezone;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
function getHashValue(string, secretKey) {
|
|
17
|
+
return crypto.createHash('sha256').update(
|
|
18
|
+
`${string}:${secretKey}`
|
|
19
|
+
).digest('hex');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function secondsToHoursMinutesSeconds(seconds) {
|
|
23
|
+
// If not a number, return the input directly
|
|
24
|
+
if (isNaN(seconds)) {
|
|
25
|
+
return seconds;
|
|
26
|
+
}
|
|
27
|
+
const hours = Math.floor(seconds / 3600);
|
|
28
|
+
const hoursString = hours > 0 ? `${hours} ${hours > 1 ? 'hours' : 'hour'}` : '';
|
|
29
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
30
|
+
const minutesString = minutes > 0 ? `${minutes} ${minutes > 1 ? 'minutes' : 'minute'}` : '';
|
|
31
|
+
const remainingSeconds = seconds % 60;
|
|
32
|
+
const secondsString = remainingSeconds > 0 ? `${remainingSeconds} ${remainingSeconds > 1 ? 'seconds' : 'second'}` : '';
|
|
33
|
+
const resultString = [hoursString, minutesString, secondsString].filter(Boolean).join(', ');
|
|
34
|
+
return resultString;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.getTimeZone = getTimeZone;
|
|
38
|
+
exports.getHashValue = getHashValue;
|
|
39
|
+
exports.secondsToHoursMinutesSeconds = secondsToHoursMinutesSeconds;
|
|
40
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const Sequelize = require('sequelize');
|
|
2
|
+
const { sequelize } = require('./sequelize');
|
|
3
|
+
|
|
4
|
+
// Model for User data
|
|
5
|
+
exports.AdminConfigModel = sequelize.define('adminConfigs', {
|
|
6
|
+
// hashed rc account ID
|
|
7
|
+
id: {
|
|
8
|
+
type: Sequelize.STRING,
|
|
9
|
+
primaryKey: true,
|
|
10
|
+
},
|
|
11
|
+
userSettings: {
|
|
12
|
+
type: Sequelize.JSON
|
|
13
|
+
},
|
|
14
|
+
customAdapter: {
|
|
15
|
+
type: Sequelize.JSON
|
|
16
|
+
}
|
|
17
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const Sequelize = require('sequelize');
|
|
2
|
+
const { sequelize } = require('./sequelize');
|
|
3
|
+
|
|
4
|
+
// Model for cache data
|
|
5
|
+
exports.CacheModel = sequelize.define('cache', {
|
|
6
|
+
// id = {userId}-{cacheKey}
|
|
7
|
+
id: {
|
|
8
|
+
type: Sequelize.STRING,
|
|
9
|
+
primaryKey: true,
|
|
10
|
+
},
|
|
11
|
+
status: {
|
|
12
|
+
type: Sequelize.STRING,
|
|
13
|
+
},
|
|
14
|
+
userId: {
|
|
15
|
+
type: Sequelize.STRING,
|
|
16
|
+
},
|
|
17
|
+
cacheKey: {
|
|
18
|
+
type: Sequelize.STRING,
|
|
19
|
+
},
|
|
20
|
+
expiry: {
|
|
21
|
+
type: Sequelize.DATE
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const Sequelize = require('sequelize');
|
|
2
|
+
const { sequelize } = require('./sequelize');
|
|
3
|
+
|
|
4
|
+
// Model for User data
|
|
5
|
+
exports.CallLogModel = sequelize.define('callLogs', {
|
|
6
|
+
// callId
|
|
7
|
+
id: {
|
|
8
|
+
type: Sequelize.STRING,
|
|
9
|
+
primaryKey: true,
|
|
10
|
+
},
|
|
11
|
+
sessionId: {
|
|
12
|
+
type: Sequelize.STRING,
|
|
13
|
+
primaryKey: true,
|
|
14
|
+
},
|
|
15
|
+
platform: {
|
|
16
|
+
type: Sequelize.STRING,
|
|
17
|
+
},
|
|
18
|
+
thirdPartyLogId: {
|
|
19
|
+
type: Sequelize.STRING,
|
|
20
|
+
},
|
|
21
|
+
userId: {
|
|
22
|
+
type: Sequelize.STRING,
|
|
23
|
+
},
|
|
24
|
+
contactId: {
|
|
25
|
+
type: Sequelize.STRING,
|
|
26
|
+
}
|
|
27
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const dynamoose = require('dynamoose');
|
|
2
|
+
|
|
3
|
+
const lockSchema = new dynamoose.Schema({
|
|
4
|
+
userId: {
|
|
5
|
+
type: String,
|
|
6
|
+
hashKey: true
|
|
7
|
+
},
|
|
8
|
+
ttl: {
|
|
9
|
+
type: Number
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const tableOptions = {
|
|
14
|
+
prefix: process.env.DYNAMODB_TABLE_PREFIX,
|
|
15
|
+
expires: 60 // 60 seconds
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
if (process.env.NODE_ENV === 'production') {
|
|
19
|
+
tableOptions.create = false;
|
|
20
|
+
tableOptions.waitForActive = false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const Lock = dynamoose.model('-token-refresh-lock', lockSchema, tableOptions);
|
|
24
|
+
|
|
25
|
+
exports.Lock = Lock;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const Sequelize = require('sequelize');
|
|
2
|
+
const { sequelize } = require('./sequelize');
|
|
3
|
+
|
|
4
|
+
// Model for User data
|
|
5
|
+
exports.MessageLogModel = sequelize.define('messageLogs', {
|
|
6
|
+
id: {
|
|
7
|
+
type: Sequelize.STRING,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
},
|
|
10
|
+
platform: {
|
|
11
|
+
type: Sequelize.STRING,
|
|
12
|
+
},
|
|
13
|
+
conversationId: {
|
|
14
|
+
type: Sequelize.STRING,
|
|
15
|
+
},
|
|
16
|
+
conversationLogId:{
|
|
17
|
+
type: Sequelize.STRING,
|
|
18
|
+
},
|
|
19
|
+
thirdPartyLogId: {
|
|
20
|
+
type: Sequelize.STRING,
|
|
21
|
+
},
|
|
22
|
+
userId: {
|
|
23
|
+
type: Sequelize.STRING,
|
|
24
|
+
}
|
|
25
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const { Sequelize } = require('sequelize');
|
|
2
|
+
|
|
3
|
+
const sequelize = new Sequelize(process.env.DATABASE_URL,
|
|
4
|
+
{
|
|
5
|
+
dialect: 'postgres',
|
|
6
|
+
protocol: 'postgres',
|
|
7
|
+
dialectOptions:{
|
|
8
|
+
ssl: {
|
|
9
|
+
rejectUnauthorized: false
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
logging: false
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
exports.sequelize = sequelize;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const Sequelize = require('sequelize');
|
|
2
|
+
const { sequelize } = require('./sequelize');
|
|
3
|
+
|
|
4
|
+
// Model for User data
|
|
5
|
+
exports.UserModel = sequelize.define('users', {
|
|
6
|
+
id: {
|
|
7
|
+
type: Sequelize.STRING,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
},
|
|
10
|
+
hostname: {
|
|
11
|
+
type: Sequelize.STRING,
|
|
12
|
+
},
|
|
13
|
+
timezoneName: {
|
|
14
|
+
type: Sequelize.STRING,
|
|
15
|
+
},
|
|
16
|
+
timezoneOffset: {
|
|
17
|
+
type: Sequelize.STRING,
|
|
18
|
+
},
|
|
19
|
+
platform: {
|
|
20
|
+
type: Sequelize.STRING,
|
|
21
|
+
},
|
|
22
|
+
// in apiKey auth, accessToken will be API key
|
|
23
|
+
accessToken: {
|
|
24
|
+
type: Sequelize.STRING(2000),
|
|
25
|
+
},
|
|
26
|
+
refreshToken: {
|
|
27
|
+
type: Sequelize.STRING(2000),
|
|
28
|
+
},
|
|
29
|
+
tokenExpiry: {
|
|
30
|
+
type: Sequelize.DATE
|
|
31
|
+
},
|
|
32
|
+
platformAdditionalInfo: {
|
|
33
|
+
type: Sequelize.JSON
|
|
34
|
+
},
|
|
35
|
+
userSettings: {
|
|
36
|
+
type: Sequelize.JSON
|
|
37
|
+
}
|
|
38
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@app-connect/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "RingCentral App Connect Core",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/ringcentral/rc-unified-crm-extension.git"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"RingCentral",
|
|
12
|
+
"App Connect"
|
|
13
|
+
],
|
|
14
|
+
"author": "RingCentral Labs",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"axios": "^1.1.2",
|
|
18
|
+
"express": "^4.18.2",
|
|
19
|
+
"pg": "^8.8.0",
|
|
20
|
+
"sequelize": "^6.25.0",
|
|
21
|
+
"moment": "^2.29.4",
|
|
22
|
+
"moment-timezone": "^0.5.39"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@aws-sdk/client-dynamodb": "^3.751.0",
|
|
26
|
+
"body-parser": "^1.20.1",
|
|
27
|
+
"client-oauth2": "^4.3.3",
|
|
28
|
+
"cors": "^2.8.5",
|
|
29
|
+
"country-state-city": "^3.2.1",
|
|
30
|
+
"dotenv": "^16.0.3",
|
|
31
|
+
"dynamoose": "^4.0.3",
|
|
32
|
+
"jsonwebtoken": "^8.5.1",
|
|
33
|
+
"mixpanel": "^0.18.0",
|
|
34
|
+
"shortid": "^2.2.16",
|
|
35
|
+
"tz-lookup": "^6.1.25",
|
|
36
|
+
"ua-parser-js": "^1.0.38"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@eslint/js": "^9.22.0",
|
|
40
|
+
"@octokit/rest": "^19.0.5",
|
|
41
|
+
"axios": "^1.1.2",
|
|
42
|
+
"express": "^4.18.2",
|
|
43
|
+
"eslint": "^9.22.0",
|
|
44
|
+
"globals": "^16.0.0",
|
|
45
|
+
"jest": "^29.3.1",
|
|
46
|
+
"moment": "^2.29.4",
|
|
47
|
+
"moment-timezone": "^0.5.39",
|
|
48
|
+
"nock": "^13.2.9",
|
|
49
|
+
"pg": "^8.8.0",
|
|
50
|
+
"sequelize": "^6.25.0",
|
|
51
|
+
"sqlite3": "^5.1.2",
|
|
52
|
+
"supertest": "^6.3.1"
|
|
53
|
+
},
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/ringcentral/rc-unified-crm-extension/issues"
|
|
56
|
+
},
|
|
57
|
+
"homepage": "https://github.com/ringcentral/rc-unified-crm-extension#readme"
|
|
58
|
+
}
|