Skip to content

Commit b474d7c

Browse files
authored
Release 0.37.0 (#213)
* fix online list request (#204) * fix online list request * add basic cmd ws test commands * update check cmd connections * add close * add socketCloseWatchdog * add remove session * on close logs debug * add repl service * update docker-file * add ping socket * update package * fix tcp send failed * update watchdogPingSocket * add logs * update addUserDeviceConnection * update submodule * changelog: v0.36.2 * Imp node clustering (#205) * update logs * sync activity cluster * update activity service * imp base clean node data * it can send offline status for died node users * refactoring * fix spec * update config * refactor PacketManager * it can clear destoyed node cache data * update clean node conditions * add reconnecting * add Node Clustering readme * it can close ws with code * reconnecty only ifWas opened * fix typo * start testing * add activty listening * update same-node / cross-node specs * add fixtures * update specs * it can connect with token * test reconnecting * update specs * update specs: add dummy data * update spec titles * update install docker * add hostname to stats * update cors header * add logs * add log * add logs * close cluster socket on delete * fix config * remove session with old node endpoint * add client cluster test * update testing clients cluster * add check last activity * add repl services * fix typo in env * fix env val * update * add netcat install to dockerfile * update addUserDeviceConnection * add keep alive * fix typo * update submodule * use res instead of res.fakeWsSessionKey * watchdogPingSocket ignore HTTP_DEVICE_ID * update * try fix listUserDevice * try fix listUserDevice * update listUserDevice * add to session service filterActualDevices * update addUserDeviceConnection and storeUserNodeData * update package * add logs * add log * it can block create_user/auth if account was blocked * update env * update @sama-communications/sdk * update requestTrackId in error response * add cluster env CLUSTER_ADVERTISE_IP * update workflows * add workflow_dispatch * update workflows tests * update env docker * formating * update submodule * update submodule to main branch
1 parent 690e4d9 commit b474d7c

86 files changed

Lines changed: 4105 additions & 818 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cluster-clients-mocharc.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"recursive": true,
3+
"sort": false,
4+
"color": true,
5+
"allow-uncaught": true,
6+
"parallel": false,
7+
"reporter": "list",
8+
"require": [
9+
"dotenv/config"
10+
],
11+
"exit": true,
12+
"spec": [
13+
"./test/cluster/cluster-clients.spec.js"
14+
],
15+
"exclude": "test/**/*.spec.js",
16+
"timeout": 120000
17+
}

.cluster-mocharc.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"recursive": true,
3+
"sort": false,
4+
"color": true,
5+
"allow-uncaught": true,
6+
"parallel": false,
7+
"reporter": "list",
8+
"require": [
9+
"dotenv/config",
10+
"./test/cluster/utils.js",
11+
"./test/cluster/fixtures.js"
12+
],
13+
"exit": true,
14+
"spec": [
15+
"./test/cluster/same-node.spec.js",
16+
"./test/cluster/cross-node.spec.js",
17+
"./test/cluster/multi-devices.spec.js",
18+
"./test/cluster/node-crash.spec.js"
19+
],
20+
"exclude": "test/**/*.spec.js",
21+
"timeout": 120000
22+
}

.env.docker

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
NODE_ENV=development
1+
NODE_ENV=testing
22

33
APP_PORT=9001
44

@@ -19,23 +19,38 @@ CONVERSATION_MAX_PARTICIPANTS=50
1919
CONVERSATION_PRELOAD_COUNT=30
2020
MESSAGE_PRELOAD_COUNT=30
2121
SEARCH_PRELOAD_COUNT=30
22+
2223
JWT_ACCESS_SECRET=4c09be6a35bec6d4089cde4be5ca57a6ee85da5739579cbecb0b8253f268eca2
2324
JWT_ACCESS_TOKEN_EXPIRES_IN=10800
2425
JWT_REFRESH_TOKEN_EXPIRES_IN=1209600
2526
JWT_REFRESH_SECRET=4c09be6a35bec6d4089cde4be5ca57a6ee85da5739579cbecb0b8253f268eca2
27+
2628
ENCRYPTION_MESSAGE_EXPIRED_IN=2592000 # 30 days
2729
ENCRYPTION_DEVICE_TOKEN_EXPIRES_IN=2592000 # 30 days
30+
ENCRYPTION_MESSAGE_EXPIRED_IN=2592000
31+
ENCRYPTION_DEVICE_TOKEN_EXPIRES_IN=2592000
32+
2833
OPERATIONS_LOG_EXPIRES_IN=1209600
29-
NODE_CLUSTER_DATA_EXPIRES_IN=30000
34+
NODE_CLUSTER_DATA_EXPIRES_IN=10000
35+
3036
FILE_UPLOAD_URL_EXPIRES_IN=3600
3137
FILE_DOWNLOAD_URL_EXPIRES_IN=604800
32-
ENCRYPTION_MESSAGE_EXPIRED_IN=2592000
33-
ENCRYPTION_DEVICE_TOKEN_EXPIRES_IN=2592000
38+
3439
SSL_KEY_FILE_NAME=
3540
SSL_CERT_FILE_NAME=
3641

3742
# set this env if you want to override the os.hostname() value
3843
HOSTNAME=NodeName
3944
CORS_ORIGIN=http://localhost:10000
4045
COOKIE_SECRET=4c09be6a35bec6d4089cde4be5ca57a6ee85da5739579cbecb0b8253f268eca2
46+
HTTP_ADMIN_API_KEY=docker-secret-key
47+
48+
# Testing
49+
RUN_NODE_1_CMD='APP_PORT=9001 APP_TCP_PORT=8001 CORS_ORIGIN=http://localhost:3001 npm start'
50+
RUN_NODE_2_CMD='APP_PORT=9002 APP_TCP_PORT=8002 CORS_ORIGIN=http://localhost:3002 npm start'
51+
52+
NODE_1_WS_ENDPOINT=ws://localhost:9001
53+
NODE_1_HTTP_ENDPOINT=http://localhost:9001
4154

55+
NODE_2_WS_ENDPOINT=ws://localhost:9002
56+
NODE_2_HTTP_ENDPOINT=http://localhost:9002

.env.example

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,19 @@ GOOGLE_GENERATIVE_AI_API_KEY=
101101
SERVICE_OTP_TOKEN_EXPIRES_IN=300000
102102
RESEND_SENDER="SAMASupport <onboarding@resend.dev>"
103103
RESEND_API_KEY=
104+
105+
106+
# Testing
107+
RUN_NODE_1_CMD='APP_PORT=9001 APP_TCP_PORT=8001 CORS_ORIGIN=http://localhost:3001 npm start'
108+
RUN_NODE_2_CMD='APP_PORT=9002 APP_TCP_PORT=8002 CORS_ORIGIN=http://localhost:3002 npm start'
109+
110+
NODE_1_WS_ENDPOINT=ws://localhost:9001
111+
NODE_1_HTTP_ENDPOINT=http://localhost:9001
112+
113+
NODE_2_WS_ENDPOINT=ws://localhost:9002
114+
NODE_2_HTTP_ENDPOINT=http://localhost:9002
115+
116+
TEST_CLIENTS_COUNT=10
117+
TEST_CLIENT_ORG_ID=683db99d3874471b4dd36c69
118+
TEST_CLIENT_WS_ENDPOINT=ws://localhost:9001
119+
TEST_CLIENT_HTTP_ENDPOINT=http://localhost:9001

.github/workflows/tests.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ on:
55
branches:
66
- main
77

8+
workflow_dispatch:
9+
810
jobs:
911
run_tests:
1012
runs-on: self-hosted
1113
steps:
1214
- uses: actions/checkout@v3
1315
- name: Build the SAMA resources
16+
env:
17+
NODE_ENV: testing
1418
run: docker compose -f docker-compose-full.yml up -d --build
1519

1620
- name: Run migrations
1721
run: docker compose exec sama-server sh -c "MONGODB_URL=mongodb://172.25.0.4/samatests npm run migrate-mongo-up"
1822

19-
- name: Run tests
23+
- name: Run tests single node
2024
run: docker compose exec sama-server sh -c "MONGODB_URL=mongodb://172.25.0.4/samatests npm run test"
2125

2226
- name: Stop the SAMA resources

.mocharc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"node-option": ["experimental-loader=./sama-loader.mjs", "import=dotenv/config"],
77
"exit": true,
88
"spec": "test/**/*.spec.js",
9+
"exclude": "test/cluster/*.spec.js",
910
"timeout": 60000
1011
}

APIs/JSON/controllers/http/activity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class HttpActivityController extends BaseHttpController {
1313
const response = new Response()
1414

1515
const HttpActivityOnlineListOperation = ServiceLocatorContainer.use("HttpActivityOnlineListOperation")
16-
const onlineListResponse = await HttpActivityOnlineListOperation.perform(res.fakeWsSessionKey, payload)
16+
const onlineListResponse = await HttpActivityOnlineListOperation.perform(res, payload)
1717

1818
const responsePayload = isCountRequest ? { count: onlineListResponse } : { users: onlineListResponse }
1919

APIs/JSON/controllers/http/auth.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class HttpAuthController extends BaseHttpController {
1616
const httpAuthOperation = ServiceLocatorContainer.use("HttpUserAuthOperation")
1717

1818
const { user, newAccessToken, accessTokenExpiredAt, newRefreshToken } = await httpAuthOperation.perform(
19-
res.fakeWsSessionKey,
19+
res,
2020
res.parsedHeaders,
2121
res.parsedSignedCookies,
2222
payload
@@ -43,7 +43,7 @@ class HttpAuthController extends BaseHttpController {
4343
async logout(res, req) {
4444
const httpLogoutOperation = ServiceLocatorContainer.use("HttpUserLogoutOperation")
4545

46-
const refreshTokenRecord = await httpLogoutOperation.perform(res.fakeWsSessionKey, res.parsedHeaders, res.parsedSignedCookies)
46+
const { refreshTokenRecord, isWasLastUserSession } = await httpLogoutOperation.perform(res, res.parsedHeaders, res.parsedSignedCookies)
4747

4848
const httpResponse = new HttpResponse(200, {}, { success: true }).addCookie("refresh_token", refreshTokenRecord.token, {
4949
maxAge: 0,
@@ -52,15 +52,19 @@ class HttpAuthController extends BaseHttpController {
5252
sameSite: "lax",
5353
})
5454

55-
return new Response()
56-
.setHttpResponse(httpResponse)
57-
.updateLastActivityStatus(
55+
const response = new Response().setHttpResponse(httpResponse)
56+
57+
if (isWasLastUserSession) {
58+
response.updateLastActivityStatus(
5859
new LastActivityStatusResponse(
5960
refreshTokenRecord.organization_id,
6061
refreshTokenRecord.user_id,
6162
MAIN_CONSTANTS.LAST_ACTIVITY_STATUS.OFFLINE
6263
)
6364
)
65+
}
66+
67+
return response
6468
}
6569
}
6670

APIs/JSON/controllers/http/message.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class HttpMessageController extends BaseHttpController {
2020
const response = new Response()
2121

2222
const httpMessageCreateOperation = ServiceLocatorContainer.use("HttpMessageCreateOperation")
23-
const createMessageResponse = await httpMessageCreateOperation.perform(res.fakeWsSessionKey, payload)
23+
const createMessageResponse = await httpMessageCreateOperation.perform(res, payload)
2424
const { organizationId, messageId, message, deliverMessages, cId, participantIds, modifiedFields, botMessage } = createMessageResponse
2525

2626
deliverMessages.forEach((event) => {
@@ -48,7 +48,7 @@ class HttpMessageController extends BaseHttpController {
4848
const payload = res.parsedBody
4949

5050
const messageSendSystemOperation = ServiceLocatorContainer.use("HttpMessageSendSystemOperation")
51-
const { organizationId, cId, recipientsIds, systemMessage } = await messageSendSystemOperation.perform(res.fakeWsSessionKey, payload)
51+
const { organizationId, cId, recipientsIds, systemMessage } = await messageSendSystemOperation.perform(res, payload)
5252

5353
const deliverMessage = new DeliverMessage(organizationId, new SystemMessageResponse(systemMessage), true)
5454
.setConversationDestination(cId)
@@ -63,7 +63,7 @@ class HttpMessageController extends BaseHttpController {
6363
const payload = res.parsedBody
6464

6565
const messageReadOperation = ServiceLocatorContainer.use("HttpMessageReadOperation")
66-
const { organizationId, readMessagesGroups } = await messageReadOperation.perform(res.fakeWsSessionKey, payload)
66+
const { organizationId, readMessagesGroups } = await messageReadOperation.perform(res, payload)
6767

6868
const response = new Response()
6969

@@ -79,7 +79,7 @@ class HttpMessageController extends BaseHttpController {
7979
const payload = res.parsedBody
8080

8181
const messageEditOperation = ServiceLocatorContainer.use("HttpMessageEditOperation")
82-
const { organizationId, cId, participantsIds, editedMessage } = await messageEditOperation.perform(res.fakeWsSessionKey, payload)
82+
const { organizationId, cId, participantsIds, editedMessage } = await messageEditOperation.perform(res, payload)
8383

8484
return new Response()
8585
.setHttpResponse(new HttpResponse(200, {}, { success: true }))
@@ -94,10 +94,7 @@ class HttpMessageController extends BaseHttpController {
9494
const payload = res.parsedBody
9595

9696
const messageReactionOperation = ServiceLocatorContainer.use("HttpMessageReactionOperation")
97-
const { organizationId, cId, participantsIds, messageReactionsUpdate } = await messageReactionOperation.perform(
98-
res.fakeWsSessionKey,
99-
payload
100-
)
97+
const { organizationId, cId, participantsIds, messageReactionsUpdate } = await messageReactionOperation.perform(res, payload)
10198

10299
return new Response()
103100
.setHttpResponse(new HttpResponse(200, {}, { success: true }))
@@ -112,7 +109,7 @@ class HttpMessageController extends BaseHttpController {
112109
const payload = res.parsedBody
113110

114111
const messageDeleteOperation = ServiceLocatorContainer.use("HttpMessageDeleteOperation")
115-
const { organizationId, cId, participantsIds, deletedMessages } = await messageDeleteOperation.perform(res.fakeWsSessionKey, payload)
112+
const { organizationId, cId, participantsIds, deletedMessages } = await messageDeleteOperation.perform(res, payload)
116113

117114
const response = new Response()
118115

APIs/JSON/controllers/http/organization.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class HttpOrganizationController extends BaseHttpController {
1212
const response = new Response()
1313

1414
const httpOrganizationCreateOperation = ServiceLocatorContainer.use("HttpOrganizationCreateOperation")
15-
const organization = await httpOrganizationCreateOperation.perform(res.fakeWsSessionKey, payload)
15+
const organization = await httpOrganizationCreateOperation.perform(res, payload)
1616

1717
return response.setHttpResponse(new HttpResponse(200, {}, { organization: organization.visibleParams() }))
1818
}

0 commit comments

Comments
 (0)