exaroton 1.10.0 → 1.11.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/.github/workflows/publish.yml +1 -1
- package/README.md +34 -2
- package/index.js +3 -1
- package/package.json +1 -1
- package/src/Billing/Pool/Pool.js +137 -0
- package/src/Billing/Pool/PoolMember.js +52 -0
- package/src/Client.js +23 -1
- package/src/Request/Billing/Pool/GetPoolMembersRequest.js +9 -0
- package/src/Request/Billing/Pool/GetPoolRequest.js +7 -0
- package/src/Request/Billing/Pool/GetPoolServersRequest.js +9 -0
- package/src/Request/Billing/Pool/GetPoolsRequest.js +9 -0
- package/src/Request/Billing/Pool/PoolRequest.js +15 -0
- package/src/Response/ArrayResponse.js +44 -0
- package/src/Response/PlayerListsResponse.js +5 -25
- package/src/Response/PoolMembersResponse.js +13 -0
- package/src/Response/PoolsResponse.js +13 -0
- package/src/Response/ServersResponse.js +5 -25
package/README.md
CHANGED
|
@@ -301,7 +301,7 @@ let file = server.getFile("server.properties");
|
|
|
301
301
|
let config = file.getConfig();
|
|
302
302
|
```
|
|
303
303
|
|
|
304
|
-
|
|
304
|
+
##### Get config file options
|
|
305
305
|
```js
|
|
306
306
|
let options = await config.getOptions();
|
|
307
307
|
for(let [key, option] of options) {
|
|
@@ -309,7 +309,7 @@ for(let [key, option] of options) {
|
|
|
309
309
|
}
|
|
310
310
|
```
|
|
311
311
|
|
|
312
|
-
|
|
312
|
+
##### Update config file options
|
|
313
313
|
```js
|
|
314
314
|
let options = await config.getOptions();
|
|
315
315
|
|
|
@@ -325,6 +325,38 @@ let options = await config.getOptions();
|
|
|
325
325
|
console.log(options.get("difficulty").getOptions());
|
|
326
326
|
```
|
|
327
327
|
|
|
328
|
+
#### Credit pools
|
|
329
|
+
Credit pools allow sharing the costs of a server between multiple users.
|
|
330
|
+
|
|
331
|
+
##### List credit pools
|
|
332
|
+
```js
|
|
333
|
+
let pools = await client.getPools();
|
|
334
|
+
console.log(pools);
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
##### Create a pool object by ID
|
|
338
|
+
```js
|
|
339
|
+
let server = client.pool(id);
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
##### Get pool information
|
|
343
|
+
```js
|
|
344
|
+
await pool.get();
|
|
345
|
+
console.log(pool.name + ": " + pool.credits);
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
##### Get pool members
|
|
349
|
+
```js
|
|
350
|
+
let members = await pool.getMembers();
|
|
351
|
+
console.log(members);
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
##### Get pool servers
|
|
355
|
+
```js
|
|
356
|
+
let servers = await pool.getServers();
|
|
357
|
+
console.log(servers);
|
|
358
|
+
```
|
|
359
|
+
|
|
328
360
|
### Websocket API
|
|
329
361
|
The websocket API allows a constant connection to our websocket service to receive
|
|
330
362
|
events in real time without polling (e.g. trying to get the server status every few seconds).
|
package/index.js
CHANGED
|
@@ -5,5 +5,7 @@ module.exports = {
|
|
|
5
5
|
ServerStatus: require('./src/Server/ServerStatus'),
|
|
6
6
|
Request: require('./src/Request/Request'),
|
|
7
7
|
Response: require('./src/Response/Response'),
|
|
8
|
-
ConfigOptionType: require('./src/Server/Config/ConfigOptionType')
|
|
8
|
+
ConfigOptionType: require('./src/Server/Config/ConfigOptionType'),
|
|
9
|
+
Pool: require('./src/Billing/Pool/Pool'),
|
|
10
|
+
PoolMember: require('./src/Billing/Pool/PoolMember')
|
|
9
11
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const GetPoolRequest = require("../../Request/Billing/Pool/GetPoolRequest.js");
|
|
2
|
+
const GetPoolMembersRequest = require("../../Request/Billing/Pool/GetPoolMembersRequest.js");
|
|
3
|
+
const GetPoolServersRequest = require("../../Request/Billing/Pool/GetPoolServersRequest.js");
|
|
4
|
+
|
|
5
|
+
class Pool {
|
|
6
|
+
/**
|
|
7
|
+
* @type {Client}
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
#client;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Pool ID
|
|
14
|
+
*
|
|
15
|
+
* @type {string}
|
|
16
|
+
*/
|
|
17
|
+
id;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Pool name
|
|
21
|
+
*
|
|
22
|
+
* @type {string}
|
|
23
|
+
*/
|
|
24
|
+
name;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Pool credit balance
|
|
28
|
+
*
|
|
29
|
+
* @type {number}
|
|
30
|
+
*/
|
|
31
|
+
credits;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Pool server count
|
|
35
|
+
*
|
|
36
|
+
* @type {number}
|
|
37
|
+
*/
|
|
38
|
+
servers;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Pool owner ID
|
|
42
|
+
*
|
|
43
|
+
* @type {string}
|
|
44
|
+
*/
|
|
45
|
+
owner;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Is pool owner
|
|
49
|
+
*
|
|
50
|
+
* @type {boolean}
|
|
51
|
+
*/
|
|
52
|
+
isOwner;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Pool member count
|
|
56
|
+
*
|
|
57
|
+
* @type {number}
|
|
58
|
+
*/
|
|
59
|
+
members;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Share of this pool owned by the current account
|
|
63
|
+
*
|
|
64
|
+
* @type {number}
|
|
65
|
+
*/
|
|
66
|
+
ownShare;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Credits in this pool owned by the current account
|
|
70
|
+
*
|
|
71
|
+
* @type {number}
|
|
72
|
+
*/
|
|
73
|
+
ownCredits;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Pool constructor
|
|
77
|
+
*
|
|
78
|
+
* @param {Client} client
|
|
79
|
+
* @param {string} id
|
|
80
|
+
*/
|
|
81
|
+
constructor(client, id) {
|
|
82
|
+
this.#client = client;
|
|
83
|
+
this.id = id;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param {{}} poolObject
|
|
88
|
+
* @return {this}
|
|
89
|
+
*/
|
|
90
|
+
setFromObject(poolObject) {
|
|
91
|
+
this.id = typeof poolObject.id !== "undefined" ? poolObject.id : null;
|
|
92
|
+
this.name = typeof poolObject.name !== "undefined" ? poolObject.name : null;
|
|
93
|
+
this.credits = typeof poolObject.credits !== "undefined" ? poolObject.credits : null;
|
|
94
|
+
this.servers = typeof poolObject.servers !== "undefined" ? poolObject.servers : null;
|
|
95
|
+
this.owner = typeof poolObject.owner !== "undefined" ? poolObject.owner : null;
|
|
96
|
+
this.isOwner = typeof poolObject.isOwner !== "undefined" ? poolObject.isOwner : null;
|
|
97
|
+
this.members = typeof poolObject.members !== "undefined" ? poolObject.members : null;
|
|
98
|
+
this.ownShare = typeof poolObject.ownShare !== "undefined" ? poolObject.ownShare : null;
|
|
99
|
+
this.ownCredits = typeof poolObject.ownCredits !== "undefined" ? poolObject.ownCredits : null;
|
|
100
|
+
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get credit pool info
|
|
106
|
+
*
|
|
107
|
+
* @return {this}
|
|
108
|
+
* @throws {RequestError}
|
|
109
|
+
*/
|
|
110
|
+
async get() {
|
|
111
|
+
let response = await this.#client.request(new GetPoolRequest(this.id));
|
|
112
|
+
this.setFromObject(response.getData());
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Get pool members
|
|
118
|
+
*
|
|
119
|
+
* @return {Promise<PoolMember[]>}
|
|
120
|
+
*/
|
|
121
|
+
async getMembers() {
|
|
122
|
+
let response = await this.#client.request(new GetPoolMembersRequest(this.id));
|
|
123
|
+
return response.getData();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Get pool servers
|
|
128
|
+
*
|
|
129
|
+
* @return {Promise<Server[]>}
|
|
130
|
+
*/
|
|
131
|
+
async getServers() {
|
|
132
|
+
let response = await this.#client.request(new GetPoolServersRequest(this.id));
|
|
133
|
+
return response.getData();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
module.exports = Pool;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
class PoolMember {
|
|
3
|
+
/**
|
|
4
|
+
* Pool member account ID
|
|
5
|
+
*
|
|
6
|
+
* @type {string}
|
|
7
|
+
*/
|
|
8
|
+
account;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Pool member name
|
|
12
|
+
*
|
|
13
|
+
* @type {string}
|
|
14
|
+
*/
|
|
15
|
+
name;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Pool member share
|
|
19
|
+
*
|
|
20
|
+
* @type {number}
|
|
21
|
+
*/
|
|
22
|
+
share;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Pool member credits
|
|
26
|
+
*
|
|
27
|
+
* @type {number}
|
|
28
|
+
*/
|
|
29
|
+
credits;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Is pool owner
|
|
33
|
+
*
|
|
34
|
+
* @type {boolean}
|
|
35
|
+
*/
|
|
36
|
+
isOwner;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Pool member constructor
|
|
40
|
+
*
|
|
41
|
+
* @param {{}} poolMemberObject
|
|
42
|
+
*/
|
|
43
|
+
constructor(poolMemberObject) {
|
|
44
|
+
this.account = typeof poolMemberObject.account !== "undefined" ? poolMemberObject.account : null;
|
|
45
|
+
this.name = typeof poolMemberObject.name !== "undefined" ? poolMemberObject.name : null;
|
|
46
|
+
this.share = typeof poolMemberObject.share !== "undefined" ? poolMemberObject.share : null;
|
|
47
|
+
this.credits = typeof poolMemberObject.credits !== "undefined" ? poolMemberObject.credits : null;
|
|
48
|
+
this.isOwner = typeof poolMemberObject.isOwner !== "undefined" ? poolMemberObject.isOwner : null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = PoolMember;
|
package/src/Client.js
CHANGED
|
@@ -6,8 +6,10 @@ const Account = require('./Account/Account');
|
|
|
6
6
|
const RequestStatusError = require('./Error/RequestStatusError');
|
|
7
7
|
const RequestBodyError = require('./Error/RequestBodyError');
|
|
8
8
|
const GetServersRequest = require('./Request/GetServersRequest');
|
|
9
|
+
const GetPoolsRequest = require('./Request/Billing/Pool/GetPoolsRequest');
|
|
9
10
|
|
|
10
11
|
const packageConfig = require('../package.json');
|
|
12
|
+
const Pool = require("./Billing/Pool/Pool.js");
|
|
11
13
|
|
|
12
14
|
class Client {
|
|
13
15
|
/**
|
|
@@ -175,6 +177,16 @@ class Client {
|
|
|
175
177
|
return (await this.request(new GetServersRequest)).getData();
|
|
176
178
|
}
|
|
177
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Get a list of all credit pools
|
|
182
|
+
*
|
|
183
|
+
* @return {Promise<Pool[]>}
|
|
184
|
+
* @throws {RequestError}
|
|
185
|
+
*/
|
|
186
|
+
async getPools() {
|
|
187
|
+
return (await this.request(new GetPoolsRequest)).getData();
|
|
188
|
+
}
|
|
189
|
+
|
|
178
190
|
/**
|
|
179
191
|
* Get account info for the current account
|
|
180
192
|
*
|
|
@@ -194,6 +206,16 @@ class Client {
|
|
|
194
206
|
server(id) {
|
|
195
207
|
return new Server(this, id);
|
|
196
208
|
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Initialize a new pool object
|
|
212
|
+
*
|
|
213
|
+
* @param {string} id
|
|
214
|
+
* @return {Pool}
|
|
215
|
+
*/
|
|
216
|
+
pool(id) {
|
|
217
|
+
return new Pool(this, id);
|
|
218
|
+
}
|
|
197
219
|
}
|
|
198
220
|
|
|
199
|
-
module.exports = Client;
|
|
221
|
+
module.exports = Client;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const PoolRequest = require("./PoolRequest.js");
|
|
2
|
+
const PoolMembersResponse = require("../../../Response/PoolMembersResponse.js");
|
|
3
|
+
|
|
4
|
+
class GetPoolMembersRequest extends PoolRequest {
|
|
5
|
+
endpoint = "billing/pools/{id}/members";
|
|
6
|
+
responseClass = PoolMembersResponse;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
module.exports = GetPoolMembersRequest;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const PoolRequest = require("./PoolRequest.js");
|
|
2
|
+
const ServersResponse = require("../../../Response/ServersResponse.js");
|
|
3
|
+
|
|
4
|
+
class GetPoolServersRequest extends PoolRequest {
|
|
5
|
+
endpoint = "billing/pools/{id}/servers";
|
|
6
|
+
responseClass = ServersResponse;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
module.exports = GetPoolServersRequest;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const Request = require('../../Request.js');
|
|
2
|
+
|
|
3
|
+
class PoolRequest extends Request {
|
|
4
|
+
/**
|
|
5
|
+
* Pool request constructor
|
|
6
|
+
*
|
|
7
|
+
* @param {string} id
|
|
8
|
+
*/
|
|
9
|
+
constructor(id) {
|
|
10
|
+
super();
|
|
11
|
+
this.setParameter("id", id);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = PoolRequest;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const Response = require('./Response');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @abstract
|
|
5
|
+
*/
|
|
6
|
+
class ArrayResponse extends Response {
|
|
7
|
+
/**
|
|
8
|
+
* @type {*[]}
|
|
9
|
+
*/
|
|
10
|
+
items = [];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @inheritDoc
|
|
14
|
+
*/
|
|
15
|
+
setBody(body) {
|
|
16
|
+
super.setBody(body);
|
|
17
|
+
|
|
18
|
+
if (!Array.isArray(body.data)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
for (let object of body.data) {
|
|
23
|
+
this.items.push(this.handleItem(object));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {*} item
|
|
29
|
+
* @return {*}
|
|
30
|
+
* @abstract
|
|
31
|
+
*/
|
|
32
|
+
handleItem(item) {
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @inheritDoc
|
|
38
|
+
*/
|
|
39
|
+
getData() {
|
|
40
|
+
return this.items;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = ArrayResponse;
|
|
@@ -1,32 +1,12 @@
|
|
|
1
1
|
const PlayerList = require('../Server/PlayerList');
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
class PlayerListsResponse extends Response {
|
|
5
|
-
/**
|
|
6
|
-
* @type {PlayerList[]}
|
|
7
|
-
*/
|
|
8
|
-
lists = [];
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @inheritDoc
|
|
12
|
-
*/
|
|
13
|
-
setBody(body) {
|
|
14
|
-
super.setBody(body);
|
|
15
|
-
|
|
16
|
-
if (!Array.isArray(body.data)) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
for (let playerListName of body.data) {
|
|
21
|
-
this.lists.push(new PlayerList(playerListName).setClient(this.request.client));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
2
|
+
const ArrayResponse = require("./ArrayResponse.js");
|
|
24
3
|
|
|
4
|
+
class PlayerListsResponse extends ArrayResponse {
|
|
25
5
|
/**
|
|
26
6
|
* @inheritDoc
|
|
27
7
|
*/
|
|
28
|
-
|
|
29
|
-
return this.
|
|
8
|
+
handleItem(item) {
|
|
9
|
+
return new PlayerList(item).setClient(this.request.client);
|
|
30
10
|
}
|
|
31
11
|
}
|
|
32
|
-
module.exports = PlayerListsResponse;
|
|
12
|
+
module.exports = PlayerListsResponse;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const ArrayResponse = require("./ArrayResponse.js");
|
|
2
|
+
const PoolMember = require("../Billing/Pool/PoolMember.js");
|
|
3
|
+
|
|
4
|
+
class PoolMembersResponse extends ArrayResponse {
|
|
5
|
+
/**
|
|
6
|
+
* @inheritDoc
|
|
7
|
+
*/
|
|
8
|
+
handleItem(item) {
|
|
9
|
+
return new PoolMember(item);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = PoolMembersResponse;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const Pool = require('../Billing/Pool/Pool.js');
|
|
2
|
+
const ArrayResponse = require("./ArrayResponse.js");
|
|
3
|
+
|
|
4
|
+
class PoolsResponse extends ArrayResponse {
|
|
5
|
+
/**
|
|
6
|
+
* @inheritDoc
|
|
7
|
+
*/
|
|
8
|
+
handleItem(item) {
|
|
9
|
+
return new Pool(this.request.client, item.id).setFromObject(item);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = PoolsResponse;
|
|
@@ -1,33 +1,13 @@
|
|
|
1
|
-
const Response = require('./Response');
|
|
2
1
|
const Server = require('../Server/Server');
|
|
2
|
+
const ArrayResponse = require("./ArrayResponse.js");
|
|
3
3
|
|
|
4
|
-
class ServersResponse extends
|
|
5
|
-
/**
|
|
6
|
-
* @type {Server[]}
|
|
7
|
-
*/
|
|
8
|
-
servers = [];
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @inheritDoc
|
|
12
|
-
*/
|
|
13
|
-
setBody(body) {
|
|
14
|
-
super.setBody(body);
|
|
15
|
-
|
|
16
|
-
if (!Array.isArray(body.data)) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
for (let serverObject of body.data) {
|
|
21
|
-
this.servers.push(new Server(this.request.client, serverObject.id).setFromObject(serverObject));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
4
|
+
class ServersResponse extends ArrayResponse {
|
|
25
5
|
/**
|
|
26
6
|
* @inheritDoc
|
|
27
7
|
*/
|
|
28
|
-
|
|
29
|
-
return this.
|
|
8
|
+
handleItem(item) {
|
|
9
|
+
return new Server(this.request.client, item.id).setFromObject(item);
|
|
30
10
|
}
|
|
31
11
|
}
|
|
32
12
|
|
|
33
|
-
module.exports = ServersResponse;
|
|
13
|
+
module.exports = ServersResponse;
|