Skip to content

Commit f1c163b

Browse files
Release 1.0.0-BETA.4 (#8)
- [BREAKING] Dropped support for all versions below Node.js v20.11.1 - While the api may still work on older versions, the app itself can't run on them anymore due to internal fs changes. - [BREAKING] Application register flow changed - New websocket connections now register on the upgrade request, not after the connection is established. - This simplifies the connection process and improves performance. - [BREAKING] Removed `isRegistered()` method from `ArunaClient` - This method became obsolete with the new registration flow. - [FEAT] Better docker support - Enforce port to 3000 inside the container, regardless of the configuration file. - This allows easier deployment and avoids port conflicts, allowing the user to map the port as needed in the docker itself.
2 parents 92c70db + af8f06c commit f1c163b

File tree

22 files changed

+1718
-1096
lines changed

22 files changed

+1718
-1096
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111

1212
strategy:
1313
matrix:
14-
node-version: [18, 20, 22]
14+
node-version: [20, 22, 24]
1515

1616
steps:
1717
- name: Checkout repository

CHANGELOG.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
# v1.0.0-BETA.3
1+
# ArunaCore Changelog
2+
3+
## v1.0.0-BETA.4
4+
5+
- [BREAKING] Dropped support for all versions below Node.js v20.11.1
6+
- While the api may still work on older versions, the app itself can't run on them anymore due to internal fs changes.
7+
8+
- [BREAKING] Application register flow changed
9+
- New websocket connections now register on the upgrade request, not after the connection is established.
10+
- This simplifies the connection process and improves performance.
11+
12+
- [BREAKING] Removed `isRegistered()` method from `ArunaClient`
13+
- This method became obsolete with the new registration flow.
14+
15+
- [FEAT] Better docker support
16+
- Enforce port to 3000 inside the container, regardless of the configuration file.
17+
- This allows easier deployment and avoids port conflicts, allowing the user to map the port as needed in the docker itself.
18+
19+
## v1.0.0-BETA.3
220

321
- [FIX] Dead WebSocket connections not being properly handled
422
- Now, when a connection is considered dead, all `'pong'` event listeners are removed and the promise resolves the correct state.
@@ -12,7 +30,7 @@
1230
- [NEW] Added typing for client-emitted events
1331
- This improves developer experience and type safety when handling events emitted by clients.
1432

15-
# v1.0.0-BETA.2
33+
## v1.0.0-BETA.2
1634

1735
- [BREAKING] Removed deprecated methods from `WebSocketParser`
1836
- These methods were deprecated in the previous version, so they were removed now.
@@ -22,7 +40,7 @@
2240

2341
- [DOCS] Updated important JSDoc comments
2442

25-
# v1.0.0-BETA.1
43+
## v1.0.0-BETA.1
2644

2745
- [BREAKING] Dropped support for all versions below Node.js v18.8.0
2846
- These versions are too old and can't be supported anymore.
@@ -33,9 +51,9 @@
3351

3452
- [CHORE] Updated dependencies
3553

36-
# v1.0.0-BETA.0
54+
## v1.0.0-BETA.0
3755

38-
## Yes, we are finally in beta! 🎉
56+
### Yes, we are finally in beta! 🎉
3957

4058
This release includes a lot of changes and improvements, so check the changelog to see what's new.
4159

@@ -100,7 +118,7 @@ This release includes a lot of changes and improvements, so check the changelog
100118
- [CHORE] Created a changelog file to keep track of changes
101119
- Probably includes all changes from previous versions.
102120

103-
# v1.0.0-ALPHA.3
121+
## v1.0.0-ALPHA.3
104122

105123
- [BREAKING] Switched to external log library
106124
- Now we use [@promisepending/logger.js](https://www.npmjs.com/package/@promisepending/logger.js) and no longer provide a custom logger.
@@ -111,7 +129,7 @@ This release includes a lot of changes and improvements, so check the changelog
111129

112130
- [CHORE] Updated dependencies
113131

114-
# v1.0.0-ALPHA.2
132+
## v1.0.0-ALPHA.2
115133

116134
- [NEW] Implemented secure mode
117135

@@ -127,7 +145,7 @@ This release includes a lot of changes and improvements, so check the changelog
127145

128146
- [CHORE] Updated dependencies
129147

130-
# v1.0.0-ALPHA.1
148+
## v1.0.0-ALPHA.1
131149

132150
- [FIXED] Some type errors
133151

@@ -139,6 +157,6 @@ This release includes a lot of changes and improvements, so check the changelog
139157

140158
- [CHORE] Updated dependencies
141159

142-
# v1.0.0-ALPHA.0
160+
## v1.0.0-ALPHA.0
143161

144162
- [NEW] Initial release

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ If you want to contribute to ArunaCore, please check our CONTRIBUTING.md file (*
8282

8383
## Authors
8484

85-
ArunaCore is developed with 💜 by <a href="https://github.com/LoboMetalurgico">Lobo Metalurgico</a> and <a href="https://github.com/emanuelfranklyn">Space_Interprise</a>.
85+
ArunaCore is developed with 💜 by <a href="https://github.com/LoboMetalurgico">Lobo Metalurgico</a> and <a href="https://github.com/SpaceFox1">SpaceFox</a>.
8686

8787
## License
8888

api/.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
*.tgz
3+
tests/

api/package-lock.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "arunacore-api",
3-
"version": "1.0.0-BETA.3",
3+
"version": "1.0.0-BETA.4",
44
"description": "ArunaCore is an open source websocket server made with nodejs for intercomunication between applications.",
55
"main": "build/src/index.js",
66
"types": "build/src/index.d.ts",
@@ -10,6 +10,7 @@
1010
"scripts": {
1111
"start": "npm run build && node build/",
1212
"build": "npx tsc -p .",
13+
"postbuild": "node ./scripts/postBuild.cjs",
1314
"prepack": "npm run build",
1415
"test": "echo \"Error: no test specified\" && exit 1"
1516
},
@@ -30,15 +31,15 @@
3031
],
3132
"homepage": "https://github.com/ArunaBot/ArunaCore#readme",
3233
"engines": {
33-
"node": ">=18.8.0"
34+
"node": ">=20.11.1"
3435
},
3536
"dependencies": {
3637
"@promisepending/logger.js": "^1.1.1",
37-
"ws": "^8.18.2"
38+
"ws": "^8.18.3"
3839
},
3940
"devDependencies": {
4041
"@types/ws": "^8.18.1",
4142
"ts-project-bundle": "^0.0.12",
42-
"typescript": "^5.8.3"
43+
"typescript": "^5.9.3"
4344
}
4445
}

api/scripts/postBuild.cjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
4+
const version = require('../package.json').version;
5+
6+
const dest = path.resolve(__dirname, '..', 'build', 'src', 'resources');
7+
8+
if (!fs.existsSync(dest)) {
9+
fs.mkdirSync(dest, { recursive: true });
10+
}
11+
12+
const versionFilePath = path.resolve(dest, 'version.js');
13+
const versionFileContent = fs.readFileSync(versionFilePath, 'utf-8').replace('REPLACE_ME', version);
14+
15+
fs.writeFileSync(versionFilePath, versionFileContent, 'utf-8');

api/src/resources/version.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const version = 'REPLACE_ME';

api/src/websocket/WebSocketClient.ts

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { IMessage, IWebsocketOptions } from '../interfaces';
22
import { Logger } from '@promisepending/logger.js';
3+
import { version } from '../resources/version';
34
import { WebSocketParser, utils } from '../';
45
import { EventEmitter } from 'events';
56
import ws from 'ws';
67

7-
88
interface ArunaEvents {
99
'ready': [];
1010
'message': [IMessage];
@@ -15,7 +15,6 @@ interface ArunaEvents {
1515
[command: string]: [...any];
1616
}
1717

18-
1918
/**
2019
* Main class for the api client
2120
* @class ArunaClient
@@ -42,7 +41,6 @@ interface ArunaEvents {
4241
export class ArunaClient extends EventEmitter<ArunaEvents> {
4342
private finishTimeout: ReturnType<typeof setTimeout> | null = null;
4443
private secureKey: string | null = null;
45-
private isRegistered = false;
4644
private ws: ws | null = null;
4745
private secureMode: boolean;
4846
private shardMode: boolean;
@@ -80,8 +78,14 @@ export class ArunaClient extends EventEmitter<ArunaEvents> {
8078
this.secureKey = secureKey;
8179
this.secureMode = true;
8280
}
81+
this.ws = new ws(`ws://${this.host}:${this.port}`, {
82+
headers: {
83+
'Authorization': this.secureKey ?? '',
84+
'ArunaCore-API-Version': version,
85+
'Client-ID': this.id,
86+
},
87+
});
8388

84-
this.ws = new ws(`ws://${this.host}:${this.port}`);
8589
return new Promise((resolve, reject) => {
8690
this.ws!.on('message', (message) => { this.onMessage(message.toString()); });
8791

@@ -91,15 +95,38 @@ export class ArunaClient extends EventEmitter<ArunaEvents> {
9195

9296
this.ws!.on('open', () => {
9397
this.logger.debug('Connected to server!');
94-
this.logger.debug('Registering client...');
95-
this.register();
98+
this.emit('ready');
9699
resolve();
97100
});
98101

99102
this.ws!.on('error', (err) => {
100103
this.logger.error(err);
101104
reject(err);
102105
});
106+
107+
this.ws!.on('unexpected-response', (req, res) => {
108+
if (res.statusCode === 401) {
109+
this.logger.error('Unauthorized: Invalid secure key!');
110+
this.ws?.close();
111+
reject(new Error('Unauthorized: Invalid secure key!'));
112+
} else if (res.statusCode === 409) {
113+
this.logger.warn('Conflict: Client ID already connected! Randomizing a new one...');
114+
this.id = this.id + utils.randomString(5);
115+
this.connect().then(() => {
116+
resolve();
117+
}).catch((err) => {
118+
reject(err);
119+
});
120+
} else if (res.statusCode === 412) {
121+
this.logger.error('Precondition Failed: Unsupported API version!');
122+
this.ws?.close();
123+
reject(new Error('Precondition Failed: Unsupported API version!'));
124+
} else {
125+
this.logger.error(`Unexpected response: ${res.statusCode}`);
126+
this.ws?.close();
127+
reject(new Error(`Unexpected response: ${res.statusCode}`));
128+
}
129+
});
103130
});
104131
}
105132

@@ -163,12 +190,7 @@ export class ArunaClient extends EventEmitter<ArunaEvents> {
163190

164191
switch (parsedMessage.command) {
165192
case '000':
166-
if (parsedMessage.content === 'register-success') {
167-
this.isRegistered = true;
168-
this.logger.debug('Client Registered!');
169-
this.emit('ready');
170-
} else if (parsedMessage.content === 'unregister-success') {
171-
this.isRegistered = false;
193+
if (parsedMessage.content === 'unregister-success') {
172194
this.logger.debug('Client Unregistered!');
173195
this.emit('finish');
174196
} else {
@@ -178,28 +200,13 @@ export class ArunaClient extends EventEmitter<ArunaEvents> {
178200
case '401':
179201
this.emit('unauthorized', parsedMessage);
180202
break;
181-
case '403':
182-
if (parsedMessage.type !== 'register') return;
183-
this.id = this.id + utils.randomString(5);
184-
this.register();
185-
break;
186203
default:
187204
this.emit('message', parsedMessage);
188205
if (parsedMessage.command) this.emit(parsedMessage.command, parsedMessage);
189206
break;
190207
}
191208
}
192209

193-
/**
194-
* Registers the client in the ArunaCore server
195-
* @returns {void}
196-
* @private
197-
*/
198-
private register(): void {
199-
if (this.isRegistered) return;
200-
this.send('request-register', { command: '000', type: 'register' });
201-
}
202-
203210
/**
204211
* Pings the ArunaCore server
205212
* @returns {Promise<boolean>}
@@ -230,14 +237,6 @@ export class ArunaClient extends EventEmitter<ArunaEvents> {
230237
return this.id;
231238
}
232239

233-
/**
234-
* Indicates if the client is registered in the ArunaCore server
235-
* @returns {boolean}
236-
*/
237-
public getIsRegistered(): boolean {
238-
return this.isRegistered;
239-
}
240-
241240
/**
242241
* Closes the connection to the ArunaCore server
243242
* @returns {Promise<void>}

0 commit comments

Comments
 (0)