polfan-server-js-client 0.3.2 → 0.4.0
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/.gitmodules +3 -3
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_05_08_2026_17_28_[Changes]/shelved.patch +447 -0
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_05_08_2026_17_28_[Changes]1/shelved.patch +0 -0
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_05_08_2026_17_28__Changes_.xml +4 -0
- package/.idea/workspace.xml +228 -49
- package/CODE_OF_CONDUCT.md +76 -76
- package/README.md +44 -44
- package/babel.config.js +5 -5
- package/build/index.cjs.js +181 -15
- package/build/index.cjs.js.map +1 -1
- package/build/index.umd.js +1 -1
- package/build/index.umd.js.map +1 -1
- package/build/types/index.d.ts +2 -1
- package/build/types/types/src/index.d.ts +3 -3
- package/build/types/types/src/schemes/SessionData.d.ts +6 -0
- package/build/types/types/src/schemes/User.d.ts +15 -0
- package/build/types/types/src/schemes/UserData.d.ts +5 -0
- package/build/types/types/src/schemes/commands/SetSessionData.d.ts +9 -1
- package/build/types/types/src/schemes/commands/SetUserData.d.ts +1 -0
- package/jest.config.ts +199 -199
- package/package.json +43 -43
- package/scripts/getPackageJson.js +24 -24
- package/src/FilesClient.ts +42 -42
- package/src/index.ts +31 -29
- package/src/state-tracker/ChatStateTracker.ts +71 -71
- package/src/state-tracker/UsersManager.ts +51 -51
- package/src/state-tracker/functions.ts +28 -28
- package/src/types/src/index.ts +313 -311
- package/src/types/src/schemes/SessionData.ts +8 -1
- package/src/types/src/schemes/User.ts +17 -1
- package/src/types/src/schemes/UserData.ts +5 -0
- package/src/types/src/schemes/commands/SetSessionData.ts +11 -2
- package/src/types/src/schemes/commands/SetUserData.ts +1 -0
- package/tests/async-utils.test.ts +29 -29
- package/tests/space-roles.test.ts +42 -42
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_26_07_2026_21_26_[Changes]/shelved.patch +0 -174
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_26_07_2026_21_26__Changes_.xml +0 -4
- package/.idea/shelf/Uncommitted_changes_before_rebase_[Changes]/shelved.patch +0 -18
- package/.idea/shelf/Uncommitted_changes_before_rebase__Changes_.xml +0 -4
package/README.md
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
# pserv-js-client-library
|
|
2
|
-
TypeScript client library to handle connection with Devana (new Polfan) chat service.
|
|
3
|
-
|
|
4
|
-
## How to use?
|
|
5
|
-
|
|
6
|
-
```js
|
|
7
|
-
(async () => {
|
|
8
|
-
// Get access token by credentials
|
|
9
|
-
const token = await PServ.AuthClient.createToken('login', 'password');
|
|
10
|
-
|
|
11
|
-
// Create web api client (there is also WebSocket client available)
|
|
12
|
-
const client = new PServ.WebApiChatClient({
|
|
13
|
-
token: token.token, // Pass received token
|
|
14
|
-
url: 'https://pserv-api-address',
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// Call `GetSession` command which returns user session data
|
|
18
|
-
const session = await client.send('GetSession');
|
|
19
|
-
|
|
20
|
-
console.log("My nick:", session.user.nick);
|
|
21
|
-
console.log("The rooms you are in:", session.rooms);
|
|
22
|
-
console.log("The spaces you are in:", session.spaces);
|
|
23
|
-
console.log("The version of server you connected to:", session.serverVersion);
|
|
24
|
-
})();
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## State management
|
|
28
|
-
|
|
29
|
-
The library provides built-in state management for WebSocket client. To enable it, just pass `stateTracking`
|
|
30
|
-
option to the `WebSocketChatClient` constructor:
|
|
31
|
-
|
|
32
|
-
```js
|
|
33
|
-
const wsClient = new PServ.WebSocketChatClient({
|
|
34
|
-
token: 'your-access-token',
|
|
35
|
-
url: 'wss://pserv-websocket-address',
|
|
36
|
-
stateTracking: true, // Enable state tracking
|
|
37
|
-
});
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
With state tracking enabled, the client will automatically maintain the current state of rooms, users, and messages,
|
|
41
|
-
by handling incoming events from the server. Reactive data structures are available via `ObservableIndexedObjectCollection`
|
|
42
|
-
objects, which allows you to subscribe to changes.
|
|
43
|
-
|
|
44
|
-
**Important note:** you can cache these objects for the connection lifetime, but you should refetch them after reconnecting,
|
|
1
|
+
# pserv-js-client-library
|
|
2
|
+
TypeScript client library to handle connection with Devana (new Polfan) chat service.
|
|
3
|
+
|
|
4
|
+
## How to use?
|
|
5
|
+
|
|
6
|
+
```js
|
|
7
|
+
(async () => {
|
|
8
|
+
// Get access token by credentials
|
|
9
|
+
const token = await PServ.AuthClient.createToken('login', 'password');
|
|
10
|
+
|
|
11
|
+
// Create web api client (there is also WebSocket client available)
|
|
12
|
+
const client = new PServ.WebApiChatClient({
|
|
13
|
+
token: token.token, // Pass received token
|
|
14
|
+
url: 'https://pserv-api-address',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// Call `GetSession` command which returns user session data
|
|
18
|
+
const session = await client.send('GetSession');
|
|
19
|
+
|
|
20
|
+
console.log("My nick:", session.user.nick);
|
|
21
|
+
console.log("The rooms you are in:", session.rooms);
|
|
22
|
+
console.log("The spaces you are in:", session.spaces);
|
|
23
|
+
console.log("The version of server you connected to:", session.serverVersion);
|
|
24
|
+
})();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## State management
|
|
28
|
+
|
|
29
|
+
The library provides built-in state management for WebSocket client. To enable it, just pass `stateTracking`
|
|
30
|
+
option to the `WebSocketChatClient` constructor:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
const wsClient = new PServ.WebSocketChatClient({
|
|
34
|
+
token: 'your-access-token',
|
|
35
|
+
url: 'wss://pserv-websocket-address',
|
|
36
|
+
stateTracking: true, // Enable state tracking
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
With state tracking enabled, the client will automatically maintain the current state of rooms, users, and messages,
|
|
41
|
+
by handling incoming events from the server. Reactive data structures are available via `ObservableIndexedObjectCollection`
|
|
42
|
+
objects, which allows you to subscribe to changes.
|
|
43
|
+
|
|
44
|
+
**Important note:** you can cache these objects for the connection lifetime, but you should refetch them after reconnecting,
|
|
45
45
|
because some structures are rebuild from scratch on `Session` event.
|
package/babel.config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
presets: [
|
|
3
|
-
["@babel/preset-env"],
|
|
4
|
-
["@babel/preset-typescript", { allowDeclareFields: true }],
|
|
5
|
-
],
|
|
1
|
+
module.exports = {
|
|
2
|
+
presets: [
|
|
3
|
+
["@babel/preset-env"],
|
|
4
|
+
["@babel/preset-typescript", { allowDeclareFields: true }],
|
|
5
|
+
],
|
|
6
6
|
};
|
package/build/index.cjs.js
CHANGED
|
@@ -48,6 +48,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
48
48
|
ObservableIndexedObjectCollection: () => (/* reexport */ ObservableIndexedObjectCollection),
|
|
49
49
|
PermissionDefinition: () => (/* reexport */ PermissionDefinition),
|
|
50
50
|
Permissions: () => (/* reexport */ Permissions),
|
|
51
|
+
UserStatus: () => (/* reexport */ UserStatus),
|
|
51
52
|
WebApiChatClient: () => (/* reexport */ WebApiChatClient),
|
|
52
53
|
WebSocketChatClient: () => (/* reexport */ WebSocketChatClient),
|
|
53
54
|
extractUserFromMember: () => (/* reexport */ extractUserFromMember)
|
|
@@ -5022,8 +5023,8 @@ var UsersManager = /*#__PURE__*/function () {
|
|
|
5022
5023
|
});
|
|
5023
5024
|
}
|
|
5024
5025
|
|
|
5025
|
-
/**
|
|
5026
|
-
* Get all available (cached) user objects at once.
|
|
5026
|
+
/**
|
|
5027
|
+
* Get all available (cached) user objects at once.
|
|
5027
5028
|
*/
|
|
5028
5029
|
return UsersManager_createClass(UsersManager, [{
|
|
5029
5030
|
key: "getAvailable",
|
|
@@ -5061,7 +5062,7 @@ var UsersManager = /*#__PURE__*/function () {
|
|
|
5061
5062
|
_this$users;
|
|
5062
5063
|
users.forEach(function (newUser) {
|
|
5063
5064
|
var oldUser = _this2.users.get(newUser.id);
|
|
5064
|
-
if (oldUser && oldUser.
|
|
5065
|
+
if (oldUser && oldUser.status !== newUser.status) {
|
|
5065
5066
|
_this2.onlineStatus.emit('change', newUser);
|
|
5066
5067
|
}
|
|
5067
5068
|
});
|
|
@@ -5230,28 +5231,28 @@ var ChatStateTracker = /*#__PURE__*/function () {
|
|
|
5230
5231
|
var _this = this;
|
|
5231
5232
|
ChatStateTracker_classCallCheck(this, ChatStateTracker);
|
|
5232
5233
|
ChatStateTracker_defineProperty(this, "client", void 0);
|
|
5233
|
-
/**
|
|
5234
|
-
* State of your permissions.
|
|
5234
|
+
/**
|
|
5235
|
+
* State of your permissions.
|
|
5235
5236
|
*/
|
|
5236
5237
|
ChatStateTracker_defineProperty(this, "permissions", void 0);
|
|
5237
|
-
/**
|
|
5238
|
-
* State of the rooms you are in.
|
|
5238
|
+
/**
|
|
5239
|
+
* State of the rooms you are in.
|
|
5239
5240
|
*/
|
|
5240
5241
|
ChatStateTracker_defineProperty(this, "rooms", void 0);
|
|
5241
|
-
/**
|
|
5242
|
-
* State of the spaces you are in.
|
|
5242
|
+
/**
|
|
5243
|
+
* State of the spaces you are in.
|
|
5243
5244
|
*/
|
|
5244
5245
|
ChatStateTracker_defineProperty(this, "spaces", void 0);
|
|
5245
|
-
/**
|
|
5246
|
-
* State of the emoticons (global and space-related).
|
|
5246
|
+
/**
|
|
5247
|
+
* State of the emoticons (global and space-related).
|
|
5247
5248
|
*/
|
|
5248
5249
|
ChatStateTracker_defineProperty(this, "emoticons", void 0);
|
|
5249
|
-
/**
|
|
5250
|
-
* Users related state.
|
|
5250
|
+
/**
|
|
5251
|
+
* Users related state.
|
|
5251
5252
|
*/
|
|
5252
5253
|
ChatStateTracker_defineProperty(this, "users", void 0);
|
|
5253
|
-
/**
|
|
5254
|
-
* State of relationships with other users.
|
|
5254
|
+
/**
|
|
5255
|
+
* State of relationships with other users.
|
|
5255
5256
|
*/
|
|
5256
5257
|
ChatStateTracker_defineProperty(this, "relationships", void 0);
|
|
5257
5258
|
ChatStateTracker_defineProperty(this, "_me", null);
|
|
@@ -6047,6 +6048,170 @@ var FilesClient = /*#__PURE__*/function (_AbstractRestClient) {
|
|
|
6047
6048
|
}()
|
|
6048
6049
|
}]);
|
|
6049
6050
|
}(AbstractRestClient);
|
|
6051
|
+
;// ./src/types/src/schemes/User.ts
|
|
6052
|
+
/**
|
|
6053
|
+
* Availability of a user, aggregated over all of their sessions.
|
|
6054
|
+
*
|
|
6055
|
+
* - `Offline` - no session is connected and none can be reached asynchronously.
|
|
6056
|
+
* - `Online` - at least one session holds a live connection.
|
|
6057
|
+
* - `OnlineAsync` - no live connection, but a push-registered device was active
|
|
6058
|
+
* recently, so a message will still reach the user.
|
|
6059
|
+
*/
|
|
6060
|
+
var UserStatus = /*#__PURE__*/function (UserStatus) {
|
|
6061
|
+
UserStatus[UserStatus["Offline"] = 0] = "Offline";
|
|
6062
|
+
UserStatus[UserStatus["Online"] = 1] = "Online";
|
|
6063
|
+
UserStatus[UserStatus["OnlineAsync"] = 2] = "OnlineAsync";
|
|
6064
|
+
return UserStatus;
|
|
6065
|
+
}({});
|
|
6066
|
+
;// ./src/types/src/index.ts
|
|
6067
|
+
|
|
6068
|
+
|
|
6069
|
+
|
|
6070
|
+
|
|
6071
|
+
|
|
6072
|
+
|
|
6073
|
+
|
|
6074
|
+
|
|
6075
|
+
|
|
6076
|
+
|
|
6077
|
+
|
|
6078
|
+
|
|
6079
|
+
|
|
6080
|
+
|
|
6081
|
+
|
|
6082
|
+
|
|
6083
|
+
|
|
6084
|
+
|
|
6085
|
+
|
|
6086
|
+
|
|
6087
|
+
|
|
6088
|
+
|
|
6089
|
+
|
|
6090
|
+
|
|
6091
|
+
|
|
6092
|
+
|
|
6093
|
+
|
|
6094
|
+
|
|
6095
|
+
|
|
6096
|
+
|
|
6097
|
+
|
|
6098
|
+
|
|
6099
|
+
|
|
6100
|
+
|
|
6101
|
+
|
|
6102
|
+
|
|
6103
|
+
|
|
6104
|
+
|
|
6105
|
+
|
|
6106
|
+
|
|
6107
|
+
|
|
6108
|
+
|
|
6109
|
+
|
|
6110
|
+
|
|
6111
|
+
|
|
6112
|
+
|
|
6113
|
+
|
|
6114
|
+
|
|
6115
|
+
|
|
6116
|
+
|
|
6117
|
+
|
|
6118
|
+
|
|
6119
|
+
|
|
6120
|
+
|
|
6121
|
+
|
|
6122
|
+
|
|
6123
|
+
|
|
6124
|
+
|
|
6125
|
+
|
|
6126
|
+
|
|
6127
|
+
|
|
6128
|
+
|
|
6129
|
+
|
|
6130
|
+
|
|
6131
|
+
|
|
6132
|
+
|
|
6133
|
+
|
|
6134
|
+
|
|
6135
|
+
|
|
6136
|
+
|
|
6137
|
+
|
|
6138
|
+
|
|
6139
|
+
|
|
6140
|
+
|
|
6141
|
+
|
|
6142
|
+
|
|
6143
|
+
|
|
6144
|
+
|
|
6145
|
+
|
|
6146
|
+
|
|
6147
|
+
|
|
6148
|
+
|
|
6149
|
+
|
|
6150
|
+
|
|
6151
|
+
|
|
6152
|
+
|
|
6153
|
+
|
|
6154
|
+
|
|
6155
|
+
|
|
6156
|
+
|
|
6157
|
+
|
|
6158
|
+
|
|
6159
|
+
|
|
6160
|
+
|
|
6161
|
+
|
|
6162
|
+
|
|
6163
|
+
|
|
6164
|
+
|
|
6165
|
+
|
|
6166
|
+
|
|
6167
|
+
|
|
6168
|
+
|
|
6169
|
+
|
|
6170
|
+
|
|
6171
|
+
|
|
6172
|
+
|
|
6173
|
+
|
|
6174
|
+
|
|
6175
|
+
|
|
6176
|
+
|
|
6177
|
+
|
|
6178
|
+
|
|
6179
|
+
|
|
6180
|
+
|
|
6181
|
+
|
|
6182
|
+
|
|
6183
|
+
|
|
6184
|
+
|
|
6185
|
+
|
|
6186
|
+
|
|
6187
|
+
|
|
6188
|
+
|
|
6189
|
+
|
|
6190
|
+
|
|
6191
|
+
|
|
6192
|
+
|
|
6193
|
+
|
|
6194
|
+
|
|
6195
|
+
|
|
6196
|
+
|
|
6197
|
+
|
|
6198
|
+
|
|
6199
|
+
|
|
6200
|
+
|
|
6201
|
+
|
|
6202
|
+
|
|
6203
|
+
|
|
6204
|
+
|
|
6205
|
+
|
|
6206
|
+
|
|
6207
|
+
|
|
6208
|
+
|
|
6209
|
+
|
|
6210
|
+
|
|
6211
|
+
|
|
6212
|
+
|
|
6213
|
+
|
|
6214
|
+
|
|
6050
6215
|
;// ./src/index.ts
|
|
6051
6216
|
|
|
6052
6217
|
|
|
@@ -6056,6 +6221,7 @@ var FilesClient = /*#__PURE__*/function (_AbstractRestClient) {
|
|
|
6056
6221
|
|
|
6057
6222
|
|
|
6058
6223
|
|
|
6224
|
+
|
|
6059
6225
|
module.exports = __webpack_exports__;
|
|
6060
6226
|
/******/ })()
|
|
6061
6227
|
;
|