erlc-api 3.2.0 β 3.3.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 +76 -428
- package/README_ES.md +148 -0
- package/package.json +1 -1
- package/src/classes/client.js +6 -6
- package/src/functions/global/resetGlobalKey.js +4 -4
- package/src/functions/server/getBans.js +6 -12
- package/src/functions/server/getCommandLogs.js +6 -12
- package/src/functions/server/getJoinLogs.js +6 -12
- package/src/functions/server/getKillLogs.js +6 -12
- package/src/functions/server/getModcallLogs.js +6 -12
- package/src/functions/server/getPlayers.js +6 -12
- package/src/functions/server/getQueue.js +6 -12
- package/src/functions/server/getServer.js +6 -11
- package/src/functions/server/getStaff.js +6 -12
- package/src/functions/server/getVehicles.js +6 -12
- package/src/functions/server/runCommand.js +9 -15
- package/src/types/index.d.ts +1 -1
package/README.md
CHANGED
|
@@ -1,497 +1,145 @@
|
|
|
1
1
|
# π ER:LC API Wrapper
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/erlc-api)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.npmjs.com/package/erlc-api)
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
[πͺπΈ VersiΓ³n en EspaΓ±ol](README_ES.md)
|
|
8
|
+
|
|
9
|
+
A lightweight, complete, and **fully typed** library for interacting with the *Emergency Response: Liberty County* (ER:LC) API. Designed to provide the best development experience in both JavaScript and TypeScript.
|
|
10
|
+
|
|
11
|
+
---
|
|
7
12
|
|
|
8
13
|
## β¨ Features
|
|
9
14
|
|
|
10
|
-
- π― **
|
|
11
|
-
- π‘οΈ **
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
- π **Well Documented** - Extensive documentation and examples
|
|
16
|
-
- π **Easy to Use** - Simple, intuitive API design
|
|
15
|
+
- π― **Full Coverage**: Support for 100% of the API v1 endpoints.
|
|
16
|
+
- π‘οΈ **TypeScript Support**: Native type definitions included.
|
|
17
|
+
- β‘ **Lightweight & Fast**: No unnecessary heavy dependencies.
|
|
18
|
+
- π **Secure**: Robust token validation and error handling.
|
|
19
|
+
- π **Up-to-date**: Support for optional `GlobalToken` (v3.2.0+).
|
|
17
20
|
|
|
18
21
|
## π¦ Installation
|
|
19
22
|
|
|
20
23
|
```bash
|
|
21
24
|
npm install erlc-api
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
+
# or
|
|
25
26
|
bun add erlc-api
|
|
26
27
|
```
|
|
27
28
|
|
|
28
29
|
## π Quick Start
|
|
29
30
|
|
|
30
|
-
###
|
|
31
|
+
### Initialization
|
|
32
|
+
|
|
33
|
+
You can use the library with or without a `Global Token` (required only for large-scale applications).
|
|
31
34
|
|
|
35
|
+
**JavaScript**
|
|
32
36
|
```javascript
|
|
33
37
|
const erlc = require("erlc-api");
|
|
34
38
|
|
|
35
|
-
//
|
|
36
|
-
const client = new erlc.Client(
|
|
37
|
-
globalToken: "your-global-token-here", // Get this from ER:LC developers
|
|
38
|
-
});
|
|
39
|
+
// Simple initialization (Recommended for most users)
|
|
40
|
+
const client = new erlc.Client();
|
|
39
41
|
|
|
40
|
-
//
|
|
41
|
-
client.
|
|
42
|
+
// Or with Global Token (For Large Apps)
|
|
43
|
+
// const client = new erlc.Client({ globalToken: "..." });
|
|
42
44
|
```
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
**TypeScript**
|
|
46
47
|
```typescript
|
|
47
|
-
import
|
|
48
|
+
import { Client, getServer } from "erlc-api";
|
|
48
49
|
|
|
49
|
-
const client = new
|
|
50
|
-
globalToken: "your-global-token-here",
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
client.config();
|
|
50
|
+
const client = new Client();
|
|
54
51
|
```
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
### π₯οΈ Server Information
|
|
59
|
-
|
|
60
|
-
#### Get Server Details
|
|
61
|
-
|
|
62
|
-
```javascript
|
|
63
|
-
const getServerInfo = async () => {
|
|
64
|
-
try {
|
|
65
|
-
const serverToken = "your-server-api-key"; // From Server Settings
|
|
66
|
-
const server = await erlc.getServer(serverToken);
|
|
67
|
-
|
|
68
|
-
console.log(server);
|
|
69
|
-
/*
|
|
70
|
-
Expected Response:
|
|
71
|
-
{
|
|
72
|
-
Name: "Your Server Name",
|
|
73
|
-
OwnerUsername: "ServerOwner",
|
|
74
|
-
CoOwnerUsernames: ["CoOwner1", "CoOwner2"],
|
|
75
|
-
CurrentPlayers: 25,
|
|
76
|
-
MaxPlayers: 40,
|
|
77
|
-
JoinKey: "ABC123",
|
|
78
|
-
AccVerifiedReq: "Disabled", // "Email" | "Phone/ID"
|
|
79
|
-
TeamBalance: true,
|
|
80
|
-
VanityURL: "https://policeroleplay.community/join?code=ABC123"
|
|
81
|
-
}
|
|
82
|
-
*/
|
|
83
|
-
} catch (error) {
|
|
84
|
-
console.error("Error fetching server info:", error.message);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
#### Get Current Players
|
|
90
|
-
|
|
91
|
-
```javascript
|
|
92
|
-
const getCurrentPlayers = async () => {
|
|
93
|
-
try {
|
|
94
|
-
const players = await erlc.getPlayers(serverToken);
|
|
95
|
-
|
|
96
|
-
console.log(players);
|
|
97
|
-
/*
|
|
98
|
-
Expected Response:
|
|
99
|
-
[
|
|
100
|
-
{
|
|
101
|
-
Player: "PlayerName:123456789",
|
|
102
|
-
Permission: "Server Owner", // "Member" | "Moderator" | "Server Administrator"
|
|
103
|
-
Team: "Police" // "Civilian" | "Fire" | "Sheriff"
|
|
104
|
-
}
|
|
105
|
-
]
|
|
106
|
-
*/
|
|
107
|
-
} catch (error) {
|
|
108
|
-
console.error("Error fetching players:", error.message);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
```
|
|
53
|
+
---
|
|
112
54
|
|
|
113
|
-
|
|
55
|
+
## π Usage Examples
|
|
114
56
|
|
|
115
|
-
|
|
116
|
-
const getServerQueue = async () => {
|
|
117
|
-
try {
|
|
118
|
-
const queue = await erlc.getQueue(serverToken);
|
|
119
|
-
console.log(`Players in queue: ${queue.length}`);
|
|
120
|
-
} catch (error) {
|
|
121
|
-
console.error("Error fetching queue:", error.message);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
```
|
|
57
|
+
Make sure to have your `Server Key` ready (get it from your private server settings in ER:LC).
|
|
125
58
|
|
|
126
|
-
###
|
|
127
|
-
|
|
128
|
-
#### Get Staff Information
|
|
59
|
+
### π₯οΈ Server Information
|
|
129
60
|
|
|
130
61
|
```javascript
|
|
131
|
-
const
|
|
132
|
-
try {
|
|
133
|
-
const staff = await erlc.getStaff(serverToken);
|
|
134
|
-
|
|
135
|
-
console.log(staff);
|
|
136
|
-
/*
|
|
137
|
-
Expected Response:
|
|
138
|
-
{
|
|
139
|
-
CoOwners: [123456789, 987654321],
|
|
140
|
-
Admins: { "123456789": "AdminName" },
|
|
141
|
-
Mods: { "987654321": "ModName" }
|
|
142
|
-
}
|
|
143
|
-
*/
|
|
144
|
-
} catch (error) {
|
|
145
|
-
console.error("Error fetching staff:", error.message);
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
### π Server Logs
|
|
62
|
+
const serverToken = "your-server-key-here";
|
|
151
63
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const getJoinLogs = async () => {
|
|
156
|
-
try {
|
|
157
|
-
const logs = await erlc.getJoinLogs(serverToken);
|
|
158
|
-
|
|
159
|
-
logs.forEach((log) => {
|
|
160
|
-
const action = log.Join ? "joined" : "left";
|
|
161
|
-
console.log(
|
|
162
|
-
`${log.Player} ${action} at ${new Date(log.Timestamp * 1000)}`
|
|
163
|
-
);
|
|
164
|
-
});
|
|
165
|
-
} catch (error) {
|
|
166
|
-
console.error("Error fetching join logs:", error.message);
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
```
|
|
64
|
+
// Get server status
|
|
65
|
+
const server = await erlc.getServer(serverToken);
|
|
66
|
+
console.log(`Server: ${server.Name} | Players: ${server.CurrentPlayers}/${server.MaxPlayers}`);
|
|
170
67
|
|
|
171
|
-
|
|
68
|
+
// Get connected players
|
|
69
|
+
const players = await erlc.getPlayers(serverToken);
|
|
70
|
+
console.table(players); // Shows name, ID, permission, and team
|
|
172
71
|
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
try {
|
|
176
|
-
const kills = await erlc.getKillLogs(serverToken);
|
|
177
|
-
|
|
178
|
-
kills.forEach((kill) => {
|
|
179
|
-
console.log(
|
|
180
|
-
`${kill.Killer} killed ${kill.Killed} at ${new Date(
|
|
181
|
-
kill.Timestamp * 1000
|
|
182
|
-
)}`
|
|
183
|
-
);
|
|
184
|
-
});
|
|
185
|
-
} catch (error) {
|
|
186
|
-
console.error("Error fetching kill logs:", error.message);
|
|
187
|
-
}
|
|
188
|
-
};
|
|
72
|
+
// Get vehicles on the map
|
|
73
|
+
const vehicles = await erlc.getVehicles(serverToken);
|
|
189
74
|
```
|
|
190
75
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
```javascript
|
|
194
|
-
const getCommandLogs = async () => {
|
|
195
|
-
try {
|
|
196
|
-
const commands = await erlc.getCommandLogs(serverToken);
|
|
197
|
-
|
|
198
|
-
commands.forEach((cmd) => {
|
|
199
|
-
console.log(`${cmd.Player} executed: ${cmd.Command}`);
|
|
200
|
-
});
|
|
201
|
-
} catch (error) {
|
|
202
|
-
console.error("Error fetching command logs:", error.message);
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
```
|
|
76
|
+
### π Logs
|
|
206
77
|
|
|
207
|
-
|
|
78
|
+
Access your server's activity history:
|
|
208
79
|
|
|
209
80
|
```javascript
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const modcalls = await erlc.getModcallLogs(serverToken);
|
|
213
|
-
|
|
214
|
-
modcalls.forEach((call) => {
|
|
215
|
-
const status = call.Moderator
|
|
216
|
-
? `answered by ${call.Moderator}`
|
|
217
|
-
: "unanswered";
|
|
218
|
-
console.log(`${call.Caller} made a modcall - ${status}`);
|
|
219
|
-
});
|
|
220
|
-
} catch (error) {
|
|
221
|
-
console.error("Error fetching modcall logs:", error.message);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
```
|
|
81
|
+
// Join/Leave Logs
|
|
82
|
+
const joinLogs = await erlc.getJoinLogs(serverToken);
|
|
225
83
|
|
|
226
|
-
|
|
84
|
+
// Kill Logs (Killfeed)
|
|
85
|
+
const killLogs = await erlc.getKillLogs(serverToken);
|
|
227
86
|
|
|
228
|
-
|
|
87
|
+
// Command Logs
|
|
88
|
+
const commandLogs = await erlc.getCommandLogs(serverToken);
|
|
229
89
|
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
try {
|
|
233
|
-
const vehicles = await erlc.getVehicles(serverToken);
|
|
234
|
-
|
|
235
|
-
vehicles.forEach((vehicle) => {
|
|
236
|
-
console.log(
|
|
237
|
-
`${vehicle.Name} owned by ${vehicle.Owner} - Texture: ${
|
|
238
|
-
vehicle.Texture || "Default"
|
|
239
|
-
}`
|
|
240
|
-
);
|
|
241
|
-
});
|
|
242
|
-
} catch (error) {
|
|
243
|
-
console.error("Error fetching vehicles:", error.message);
|
|
244
|
-
}
|
|
245
|
-
};
|
|
90
|
+
// Mod Call Logs
|
|
91
|
+
const modCalls = await erlc.getModcallLogs(serverToken);
|
|
246
92
|
```
|
|
247
93
|
|
|
248
|
-
###
|
|
249
|
-
|
|
250
|
-
#### Execute Server Commands
|
|
94
|
+
### π οΈ Management & Administration
|
|
251
95
|
|
|
252
96
|
```javascript
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const success = await erlc.runCommand(
|
|
256
|
-
serverToken,
|
|
257
|
-
":h Welcome to our server!"
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
if (success) {
|
|
261
|
-
console.log("Command executed successfully!");
|
|
262
|
-
}
|
|
263
|
-
} catch (error) {
|
|
264
|
-
console.error("Error executing command:", error.message);
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
```
|
|
97
|
+
// Get Ban List
|
|
98
|
+
const bans = await erlc.getBans(serverToken);
|
|
268
99
|
|
|
269
|
-
|
|
100
|
+
// Get Server Staff
|
|
101
|
+
const staff = await erlc.getStaff(serverToken);
|
|
270
102
|
|
|
271
|
-
|
|
272
|
-
const
|
|
273
|
-
try {
|
|
274
|
-
const bans = await erlc.getBans(serverToken);
|
|
275
|
-
|
|
276
|
-
Object.entries(bans).forEach(([playerId, playerName]) => {
|
|
277
|
-
console.log(`${playerName} (${playerId}) is banned`);
|
|
278
|
-
});
|
|
279
|
-
} catch (error) {
|
|
280
|
-
console.error("Error fetching bans:", error.message);
|
|
281
|
-
}
|
|
282
|
-
};
|
|
103
|
+
// Get Queue
|
|
104
|
+
const queue = await erlc.getQueue(serverToken);
|
|
283
105
|
```
|
|
284
106
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
### Error Handling Best Practices
|
|
288
|
-
|
|
289
|
-
```javascript
|
|
290
|
-
const handleApiCall = async () => {
|
|
291
|
-
try {
|
|
292
|
-
const result = await erlc.getServer(serverToken);
|
|
293
|
-
return result;
|
|
294
|
-
} catch (error) {
|
|
295
|
-
// The error is now an ErlcError with detailed information
|
|
296
|
-
console.error(`Error ${error.code}: ${error.message}`);
|
|
297
|
-
console.error(`Category: ${error.category}, Severity: ${error.severity}`);
|
|
298
|
-
|
|
299
|
-
// Handle specific ERLC error codes
|
|
300
|
-
switch (error.code) {
|
|
301
|
-
case 2002:
|
|
302
|
-
console.error(
|
|
303
|
-
"Invalid server key - get a new one from server settings"
|
|
304
|
-
);
|
|
305
|
-
break;
|
|
306
|
-
case 4001:
|
|
307
|
-
console.error("Rate limited - reduce request frequency");
|
|
308
|
-
break;
|
|
309
|
-
case 3002:
|
|
310
|
-
console.error("Server offline - wait for players to join");
|
|
311
|
-
break;
|
|
312
|
-
case 9999:
|
|
313
|
-
console.error("Server module outdated - restart server");
|
|
314
|
-
break;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// Show suggested actions
|
|
318
|
-
if (error.suggestions) {
|
|
319
|
-
console.error("Suggested actions:");
|
|
320
|
-
error.suggestions.forEach((action) => console.error(`- ${action}`));
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// Check if error is retryable
|
|
324
|
-
if (error.retryable) {
|
|
325
|
-
console.error("This error might be resolved by retrying");
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
throw error; // Re-throw if needed
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
```
|
|
107
|
+
### β‘ Run Command
|
|
332
108
|
|
|
333
|
-
|
|
109
|
+
Execute commands directly from your code:
|
|
334
110
|
|
|
335
111
|
```javascript
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
// Execute multiple API calls concurrently
|
|
339
|
-
const [serverInfo, players, staff, vehicles] = await Promise.all([
|
|
340
|
-
erlc.getServer(serverToken),
|
|
341
|
-
erlc.getPlayers(serverToken),
|
|
342
|
-
erlc.getStaff(serverToken),
|
|
343
|
-
erlc.getVehicles(serverToken),
|
|
344
|
-
]);
|
|
345
|
-
|
|
346
|
-
return {
|
|
347
|
-
server: serverInfo,
|
|
348
|
-
playerCount: players.length,
|
|
349
|
-
staffCount:
|
|
350
|
-
Object.keys(staff.Admins).length + Object.keys(staff.Mods).length,
|
|
351
|
-
vehicleCount: vehicles.length,
|
|
352
|
-
};
|
|
353
|
-
} catch (error) {
|
|
354
|
-
console.error("Error getting server overview:", error.message);
|
|
355
|
-
throw error;
|
|
356
|
-
}
|
|
357
|
-
};
|
|
112
|
+
const command = await erlc.runCommand(serverToken, ":announce This is an API test!");
|
|
113
|
+
console.log(command); // Returns true if successful
|
|
358
114
|
```
|
|
359
115
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
### Getting Your Tokens
|
|
116
|
+
---
|
|
363
117
|
|
|
364
|
-
|
|
365
|
-
2. **Server Token**: Found in your server settings within ER:LC
|
|
118
|
+
## β οΈ Error Handling
|
|
366
119
|
|
|
367
|
-
|
|
120
|
+
The library throws descriptive errors. You should wrap your calls in `try/catch` blocks.
|
|
368
121
|
|
|
369
122
|
```javascript
|
|
370
|
-
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
// β
Use environment variables
|
|
376
|
-
const client = new erlc.Client({
|
|
377
|
-
globalToken: process.env.ERLC_GLOBAL_TOKEN,
|
|
378
|
-
});
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
## π TypeScript Support
|
|
382
|
-
|
|
383
|
-
The package includes comprehensive TypeScript definitions:
|
|
384
|
-
|
|
385
|
-
```typescript
|
|
386
|
-
import erlc, { ServerStatus, ServerPlayer, JoinLog } from "erlc-api";
|
|
387
|
-
|
|
388
|
-
const client = new erlc.Client({
|
|
389
|
-
globalToken: process.env.ERLC_GLOBAL_TOKEN!,
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
client.config();
|
|
393
|
-
|
|
394
|
-
// Fully typed responses
|
|
395
|
-
const server: ServerStatus = await erlc.getServer(serverToken);
|
|
396
|
-
const players: ServerPlayer[] = await erlc.getPlayers(serverToken);
|
|
397
|
-
const joinLogs: JoinLog[] = await erlc.getJoinLogs(serverToken);
|
|
123
|
+
try {
|
|
124
|
+
const data = await erlc.getServer("invalid-token");
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error(error.message); // e.g., "Forbidden: Access denied..."
|
|
127
|
+
}
|
|
398
128
|
```
|
|
399
129
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
## π Error Types
|
|
408
|
-
|
|
409
|
-
The wrapper provides comprehensive error handling with specific ERLC error codes:
|
|
130
|
+
| Error Code | Description |
|
|
131
|
+
|------------|-------------|
|
|
132
|
+
| `401` | Unauthorized (Invalid Token) |
|
|
133
|
+
| `403` | Forbidden (Permissions issue) |
|
|
134
|
+
| `429` | Rate Limit Exceeded |
|
|
135
|
+
| `500` | Internal Server Error |
|
|
410
136
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
| Code | Category | Description |
|
|
414
|
-
| ---- | -------------------- | -------------------------------------- |
|
|
415
|
-
| 0 | System Error | Unknown error occurred |
|
|
416
|
-
| 1001 | Communication Error | Error communicating with Roblox server |
|
|
417
|
-
| 1002 | System Error | Internal system error |
|
|
418
|
-
| 2000 | Authentication Error | Missing server key |
|
|
419
|
-
| 2001 | Authentication Error | Invalid server key format |
|
|
420
|
-
| 2002 | Authentication Error | Invalid or expired server key |
|
|
421
|
-
| 2003 | Authentication Error | Invalid global API key |
|
|
422
|
-
| 2004 | Authentication Error | Server key banned |
|
|
423
|
-
| 3001 | Request Error | Invalid command provided |
|
|
424
|
-
| 3002 | Request Error | Server offline (no players) |
|
|
425
|
-
| 4001 | Rate Limit Error | Rate limited |
|
|
426
|
-
| 4002 | Permission Error | Restricted command |
|
|
427
|
-
| 4003 | Content Error | Prohibited message |
|
|
428
|
-
| 9998 | Access Error | Restricted resource |
|
|
429
|
-
| 9999 | Version Error | Outdated server module |
|
|
430
|
-
|
|
431
|
-
### Error Properties
|
|
432
|
-
|
|
433
|
-
All errors are instances of `ErlcError` with these properties:
|
|
434
|
-
|
|
435
|
-
- `code`: ERLC error code or HTTP status
|
|
436
|
-
- `message`: Human-readable error message
|
|
437
|
-
- `category`: Error category (e.g., "AUTHENTICATION_ERROR")
|
|
438
|
-
- `severity`: Error severity ("LOW", "MEDIUM", "HIGH", "CRITICAL")
|
|
439
|
-
- `suggestions`: Array of suggested actions to resolve the error
|
|
440
|
-
- `retryable`: Boolean indicating if the error might be resolved by retrying
|
|
441
|
-
- `timestamp`: ISO timestamp when the error occurred
|
|
442
|
-
|
|
443
|
-
### Retry Logic Example
|
|
444
|
-
|
|
445
|
-
```javascript
|
|
446
|
-
async function withRetry(apiCall, maxRetries = 3) {
|
|
447
|
-
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
448
|
-
try {
|
|
449
|
-
return await apiCall();
|
|
450
|
-
} catch (error) {
|
|
451
|
-
if (!error.retryable || attempt === maxRetries) {
|
|
452
|
-
throw error;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
// Wait before retrying with exponential backoff
|
|
456
|
-
const delay = 1000 * Math.pow(2, attempt - 1);
|
|
457
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// Usage
|
|
463
|
-
const players = await withRetry(() => erlc.getPlayers(serverToken));
|
|
464
|
-
```
|
|
137
|
+
---
|
|
465
138
|
|
|
466
139
|
## π€ Contributing
|
|
467
140
|
|
|
468
|
-
|
|
141
|
+
Contributions are welcome! Feel free to submit a Pull Request.
|
|
469
142
|
|
|
470
143
|
## π License
|
|
471
144
|
|
|
472
|
-
This project is licensed under the MIT License
|
|
473
|
-
|
|
474
|
-
## π Links
|
|
475
|
-
|
|
476
|
-
- **Discord Bot**: [Invite to your server](https://discord.com/oauth2/authorize?client_id=1014990793280323624)
|
|
477
|
-
- **API Documentation**: [PRC API Docs](https://apidocs.policeroleplay.community/reference/api-reference)
|
|
478
|
-
- **Discord Support**: [Join PRC Discord](https://discord.gg/prc)
|
|
479
|
-
- **Custom Liveries**: [Browse Collection](https://github.com/Exodo0/ERLC-API/tree/main/Custom%20Liveries)
|
|
480
|
-
|
|
481
|
-
## π¨βπ» Credits
|
|
482
|
-
|
|
483
|
-
- **Library Development**: [Egologics](https://twitter.com/0Adexus0)
|
|
484
|
-
- **NPM Package**: [ERLC-API](https://www.npmjs.com/package/erlc-api)
|
|
485
|
-
- **API Development**: [Police Roleplay Community](https://twitter.com/PRC_Roblox)
|
|
486
|
-
- **Community Support**: [PRC Discord Community](https://discord.gg/prc)
|
|
487
|
-
|
|
488
|
-
---
|
|
489
|
-
|
|
490
|
-
<div align="center">
|
|
491
|
-
<p>Made with β€οΈ for the ER:LC community</p>
|
|
492
|
-
<p>
|
|
493
|
-
<a href="https://github.com/Exodo0/ERLC-API">β Star us on GitHub</a> β’
|
|
494
|
-
<a href="https://discord.gg/prc">π¬ Join our Discord</a> β’
|
|
495
|
-
<a href="https://twitter.com/0Adexus0">π¦ Follow on Twitter</a>
|
|
496
|
-
</p>
|
|
497
|
-
</div>
|
|
145
|
+
This project is licensed under the [MIT License](LICENSE).
|
package/README_ES.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# π ER:LC API Wrapper
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/erlc-api)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.npmjs.com/package/erlc-api)
|
|
6
|
+
|
|
7
|
+
[π¬π§ English Version](README.md)
|
|
8
|
+
|
|
9
|
+
Una librerΓa ligera, completa y **totalmente tipada** para interactuar con la API de *Emergency Response: Liberty County* (ER:LC). DiseΓ±ada para ofrecer la mejor experiencia de desarrollo tanto en JavaScript como en TypeScript.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## β¨ CaracterΓsticas
|
|
14
|
+
|
|
15
|
+
- π― **Cobertura Total**: Soporte para el 100% de los endpoints de la API v1.
|
|
16
|
+
- π‘οΈ **Tipado TypeScript**: Definiciones de tipos incluidas nativamente.
|
|
17
|
+
- β‘ **Ligero y RΓ‘pido**: Sin dependencias pesadas innecesarias.
|
|
18
|
+
- π **Seguro**: ValidaciΓ³n de tokens y manejo de errores robusto.
|
|
19
|
+
- π **Actualizado**: Soporte para `GlobalToken` opcional (v3.2.0+).
|
|
20
|
+
|
|
21
|
+
## π¦ InstalaciΓ³n
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install erlc-api
|
|
25
|
+
# o
|
|
26
|
+
bun add erlc-api
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## π Inicio RΓ‘pido
|
|
30
|
+
|
|
31
|
+
### InicializaciΓ³n
|
|
32
|
+
|
|
33
|
+
Puedes usar la librerΓa con o sin un `Global Token` (requerido solo para aplicaciones a gran escala).
|
|
34
|
+
|
|
35
|
+
**JavaScript**
|
|
36
|
+
```javascript
|
|
37
|
+
const erlc = require("erlc-api");
|
|
38
|
+
|
|
39
|
+
// InicializaciΓ³n simple (Recomendada para la mayorΓa)
|
|
40
|
+
const client = new erlc.Client();
|
|
41
|
+
|
|
42
|
+
// O con Global Token (Para Large Apps)
|
|
43
|
+
// const client = new erlc.Client({ globalToken: "..." });
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**TypeScript**
|
|
47
|
+
```typescript
|
|
48
|
+
import { Client, getServer } from "erlc-api";
|
|
49
|
+
|
|
50
|
+
const client = new Client();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## π Ejemplos de Uso
|
|
56
|
+
|
|
57
|
+
AsegΓΊrate de tener tu `Server Key` a mano (obtenla en los ajustes de tu servidor privado en ER:LC).
|
|
58
|
+
|
|
59
|
+
### π₯οΈ InformaciΓ³n del Servidor
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
const serverToken = "tu-server-key-aqui";
|
|
63
|
+
|
|
64
|
+
// Obtener estado del servidor
|
|
65
|
+
const server = await erlc.getServer(serverToken);
|
|
66
|
+
console.log(`Servidor: ${server.Name} | Jugadores: ${server.CurrentPlayers}/${server.MaxPlayers}`);
|
|
67
|
+
|
|
68
|
+
// Obtener jugadores conectados
|
|
69
|
+
const players = await erlc.getPlayers(serverToken);
|
|
70
|
+
console.table(players); // Muestra nombre, ID, permisos y equipo
|
|
71
|
+
|
|
72
|
+
// Obtener vehΓculos en el mapa
|
|
73
|
+
const vehicles = await erlc.getVehicles(serverToken);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### π Registros (Logs)
|
|
77
|
+
|
|
78
|
+
Accede a los historiales de actividad de tu servidor:
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
// Logs de Entradas/Salidas
|
|
82
|
+
const joinLogs = await erlc.getJoinLogs(serverToken);
|
|
83
|
+
|
|
84
|
+
// Logs de Muertes (Killfeed)
|
|
85
|
+
const killLogs = await erlc.getKillLogs(serverToken);
|
|
86
|
+
|
|
87
|
+
// Logs de Comandos ejecutados
|
|
88
|
+
const commandLogs = await erlc.getCommandLogs(serverToken);
|
|
89
|
+
|
|
90
|
+
// Logs de Llamadas a Moderadores
|
|
91
|
+
const modCalls = await erlc.getModcallLogs(serverToken);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### π οΈ GestiΓ³n y AdministraciΓ³n
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
// Ver lista de Baneos
|
|
98
|
+
const bans = await erlc.getBans(serverToken);
|
|
99
|
+
|
|
100
|
+
// Obtener Staff del servidor
|
|
101
|
+
const staff = await erlc.getStaff(serverToken);
|
|
102
|
+
|
|
103
|
+
// Ejecutar comando remoto (Ej: Anuncio)
|
|
104
|
+
await erlc.runCommand(serverToken, ":h Β‘Hola desde la API!");
|
|
105
|
+
|
|
106
|
+
// Resetear Global Key (Solo si tienes una configurada)
|
|
107
|
+
// await erlc.resetGlobalKey();
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## π¨ Manejo de Errores
|
|
113
|
+
|
|
114
|
+
La librerΓa lanza errores descriptivos (`ErlcError`) que facilitan la depuraciΓ³n.
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
try {
|
|
118
|
+
await erlc.getServer(serverToken);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error(`Error ${error.code}: ${error.message}`);
|
|
121
|
+
|
|
122
|
+
if (error.code === 4001) console.log("β³ Rate limit alcanzado, espera un momento.");
|
|
123
|
+
if (error.code === 2002) console.log("π La Server Key es invΓ‘lida o expirΓ³.");
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### CΓ³digos Comunes
|
|
128
|
+
|
|
129
|
+
| CΓ³digo | Significado | SoluciΓ³n |
|
|
130
|
+
|:---:|---|---|
|
|
131
|
+
| **2002** | Key InvΓ‘lida | Verifica tu `Server-Key` en el juego. |
|
|
132
|
+
| **3002** | Servidor Offline | El servidor no tiene jugadores o estΓ‘ apagado. |
|
|
133
|
+
| **4001** | Rate Limit | EstΓ‘s enviando muchas peticiones muy rΓ‘pido. |
|
|
134
|
+
| **403** | No Autorizado | Verifica tus permisos o tokens. |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## π Enlaces Γtiles
|
|
139
|
+
|
|
140
|
+
- [DocumentaciΓ³n Oficial de PRC](https://apidocs.policeroleplay.community/)
|
|
141
|
+
- [Discord de Soporte PRC](https://discord.gg/prc)
|
|
142
|
+
- [NPM Package](https://www.npmjs.com/package/erlc-api)
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
<div align="center">
|
|
147
|
+
<sub>Hecho con β€οΈ para la comunidad de ER:LC</sub>
|
|
148
|
+
</div>
|
package/package.json
CHANGED
package/src/classes/client.js
CHANGED
|
@@ -17,12 +17,12 @@ class Client {
|
|
|
17
17
|
* @constructor
|
|
18
18
|
* @param {ClientConfig} options - Client Options
|
|
19
19
|
*/
|
|
20
|
-
constructor(options) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
if (options && typeof options === "object") {
|
|
22
|
+
this.options = { ...options };
|
|
23
|
+
} else {
|
|
24
|
+
this.options = {};
|
|
25
|
+
}
|
|
26
26
|
this.config();
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -15,8 +15,8 @@ module.exports = () => {
|
|
|
15
15
|
if (!config?.globalToken) {
|
|
16
16
|
const error = await processError(
|
|
17
17
|
new Error(
|
|
18
|
-
"Global token not configured. Please initialize the client first."
|
|
19
|
-
)
|
|
18
|
+
"Global token not configured. Please initialize the client first."
|
|
19
|
+
)
|
|
20
20
|
);
|
|
21
21
|
return reject(error);
|
|
22
22
|
}
|
|
@@ -44,13 +44,13 @@ module.exports = () => {
|
|
|
44
44
|
// However, looking at other endpoints, they return data directly.
|
|
45
45
|
// Let's assume it returns a JSON with the key, or we can inspect the response content type.
|
|
46
46
|
// But for now, let's try to parse as JSON.
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
const data = await res.json();
|
|
49
49
|
// If data has a specific field for the key, we should return that.
|
|
50
50
|
// If the documentation doesn't specify, I'll return the whole data object or try to find the key.
|
|
51
51
|
// Based on "This will send a new key", it might be { "apiKey": "..." } or just the string if it's text/plain.
|
|
52
52
|
// Given other endpoints return JSON, this likely returns JSON.
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
resolve(data);
|
|
55
55
|
} catch (error) {
|
|
56
56
|
const processedError = await processError(error);
|
|
@@ -17,21 +17,15 @@ module.exports = (serverToken) => {
|
|
|
17
17
|
const fetch = await import("node-fetch");
|
|
18
18
|
const { config } = await import("../../erlc.js");
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
return reject(error);
|
|
20
|
+
const headers = {
|
|
21
|
+
"Server-Key": serverToken,
|
|
22
|
+
};
|
|
23
|
+
if (config?.globalToken) {
|
|
24
|
+
headers["Authorization"] = config.globalToken;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
const res = await fetch.default(`${BASEURL}/server/bans`, {
|
|
31
|
-
headers:
|
|
32
|
-
Authorization: config.globalToken,
|
|
33
|
-
"Server-Key": serverToken,
|
|
34
|
-
},
|
|
28
|
+
headers: headers,
|
|
35
29
|
timeout: 10000, // 10 second timeout
|
|
36
30
|
});
|
|
37
31
|
|
|
@@ -17,21 +17,15 @@ module.exports = (serverToken) => {
|
|
|
17
17
|
const fetch = await import("node-fetch");
|
|
18
18
|
const { config } = await import("../../erlc.js");
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
return reject(error);
|
|
20
|
+
const headers = {
|
|
21
|
+
"Server-Key": serverToken,
|
|
22
|
+
};
|
|
23
|
+
if (config?.globalToken) {
|
|
24
|
+
headers["Authorization"] = config.globalToken;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
const res = await fetch.default(`${BASEURL}/server/commandlogs`, {
|
|
31
|
-
headers:
|
|
32
|
-
Authorization: config.globalToken,
|
|
33
|
-
"Server-Key": serverToken,
|
|
34
|
-
},
|
|
28
|
+
headers: headers,
|
|
35
29
|
timeout: 10000, // 10 second timeout
|
|
36
30
|
});
|
|
37
31
|
|
|
@@ -17,21 +17,15 @@ module.exports = (serverToken) => {
|
|
|
17
17
|
const fetch = await import("node-fetch");
|
|
18
18
|
const { config } = await import("../../erlc.js");
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
return reject(error);
|
|
20
|
+
const headers = {
|
|
21
|
+
"Server-Key": serverToken,
|
|
22
|
+
};
|
|
23
|
+
if (config?.globalToken) {
|
|
24
|
+
headers["Authorization"] = config.globalToken;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
const res = await fetch.default(`${BASEURL}/server/joinlogs`, {
|
|
31
|
-
headers:
|
|
32
|
-
Authorization: config.globalToken,
|
|
33
|
-
"Server-Key": serverToken,
|
|
34
|
-
},
|
|
28
|
+
headers: headers,
|
|
35
29
|
timeout: 10000, // 10 second timeout
|
|
36
30
|
});
|
|
37
31
|
|
|
@@ -17,21 +17,15 @@ module.exports = (serverToken) => {
|
|
|
17
17
|
const fetch = await import("node-fetch");
|
|
18
18
|
const { config } = await import("../../erlc.js");
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
return reject(error);
|
|
20
|
+
const headers = {
|
|
21
|
+
"Server-Key": serverToken,
|
|
22
|
+
};
|
|
23
|
+
if (config?.globalToken) {
|
|
24
|
+
headers["Authorization"] = config.globalToken;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
const res = await fetch.default(`${BASEURL}/server/killlogs`, {
|
|
31
|
-
headers:
|
|
32
|
-
Authorization: config.globalToken,
|
|
33
|
-
"Server-Key": serverToken,
|
|
34
|
-
},
|
|
28
|
+
headers: headers,
|
|
35
29
|
timeout: 10000, // 10 second timeout
|
|
36
30
|
});
|
|
37
31
|
|
|
@@ -17,21 +17,15 @@ module.exports = (serverToken) => {
|
|
|
17
17
|
const fetch = await import("node-fetch");
|
|
18
18
|
const { config } = await import("../../erlc.js");
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
return reject(error);
|
|
20
|
+
const headers = {
|
|
21
|
+
"Server-Key": serverToken,
|
|
22
|
+
};
|
|
23
|
+
if (config?.globalToken) {
|
|
24
|
+
headers["Authorization"] = config.globalToken;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
const res = await fetch.default(`${BASEURL}/server/modcalls`, {
|
|
31
|
-
headers:
|
|
32
|
-
Authorization: config.globalToken,
|
|
33
|
-
"Server-Key": serverToken,
|
|
34
|
-
},
|
|
28
|
+
headers: headers,
|
|
35
29
|
timeout: 10000, // 10 second timeout
|
|
36
30
|
});
|
|
37
31
|
|
|
@@ -17,21 +17,15 @@ module.exports = (serverToken) => {
|
|
|
17
17
|
const fetch = await import("node-fetch");
|
|
18
18
|
const { config } = await import("../../erlc.js");
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
return reject(error);
|
|
20
|
+
const headers = {
|
|
21
|
+
"Server-Key": serverToken,
|
|
22
|
+
};
|
|
23
|
+
if (config?.globalToken) {
|
|
24
|
+
headers["Authorization"] = config.globalToken;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
const res = await fetch.default(`${BASEURL}/server/players`, {
|
|
31
|
-
headers:
|
|
32
|
-
Authorization: config.globalToken,
|
|
33
|
-
"Server-Key": serverToken,
|
|
34
|
-
},
|
|
28
|
+
headers: headers,
|
|
35
29
|
timeout: 10000, // 10 second timeout
|
|
36
30
|
});
|
|
37
31
|
|
|
@@ -17,21 +17,15 @@ module.exports = (serverToken) => {
|
|
|
17
17
|
const fetch = await import("node-fetch");
|
|
18
18
|
const { config } = await import("../../erlc.js");
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
return reject(error);
|
|
20
|
+
const headers = {
|
|
21
|
+
"Server-Key": serverToken,
|
|
22
|
+
};
|
|
23
|
+
if (config?.globalToken) {
|
|
24
|
+
headers["Authorization"] = config.globalToken;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
const res = await fetch.default(`${BASEURL}/server/queue`, {
|
|
31
|
-
headers:
|
|
32
|
-
Authorization: config.globalToken,
|
|
33
|
-
"Server-Key": serverToken,
|
|
34
|
-
},
|
|
28
|
+
headers: headers,
|
|
35
29
|
timeout: 10000, // 10 second timeout
|
|
36
30
|
});
|
|
37
31
|
|
|
@@ -12,20 +12,15 @@ module.exports = (serverToken) => {
|
|
|
12
12
|
const fetch = await import("node-fetch");
|
|
13
13
|
const { config } = await import("../../erlc.js");
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
21
|
-
);
|
|
15
|
+
const headers = {
|
|
16
|
+
"Server-Key": serverToken,
|
|
17
|
+
};
|
|
18
|
+
if (config?.globalToken) {
|
|
19
|
+
headers["Authorization"] = config.globalToken;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
const res = await fetch.default(`${BASEURL}/server`, {
|
|
25
|
-
headers:
|
|
26
|
-
Authorization: config?.globalToken,
|
|
27
|
-
"Server-Key": serverToken,
|
|
28
|
-
},
|
|
23
|
+
headers: headers,
|
|
29
24
|
timeout: 10000, // 10 second timeout
|
|
30
25
|
});
|
|
31
26
|
|
|
@@ -17,21 +17,15 @@ module.exports = (serverToken) => {
|
|
|
17
17
|
const fetch = await import("node-fetch");
|
|
18
18
|
const { config } = await import("../../erlc.js");
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
return reject(error);
|
|
20
|
+
const headers = {
|
|
21
|
+
"Server-Key": serverToken,
|
|
22
|
+
};
|
|
23
|
+
if (config?.globalToken) {
|
|
24
|
+
headers["Authorization"] = config.globalToken;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
const res = await fetch.default(`${BASEURL}/server/staff`, {
|
|
31
|
-
headers:
|
|
32
|
-
Authorization: config.globalToken,
|
|
33
|
-
"Server-Key": serverToken,
|
|
34
|
-
},
|
|
28
|
+
headers: headers,
|
|
35
29
|
timeout: 10000, // 10 second timeout
|
|
36
30
|
});
|
|
37
31
|
|
|
@@ -17,21 +17,15 @@ module.exports = (serverToken) => {
|
|
|
17
17
|
const fetch = await import("node-fetch");
|
|
18
18
|
const { config } = await import("../../erlc.js");
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
return reject(error);
|
|
20
|
+
const headers = {
|
|
21
|
+
"Server-Key": serverToken,
|
|
22
|
+
};
|
|
23
|
+
if (config?.globalToken) {
|
|
24
|
+
headers["Authorization"] = config.globalToken;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
const res = await fetch.default(`${BASEURL}/server/vehicles`, {
|
|
31
|
-
headers:
|
|
32
|
-
Authorization: config.globalToken,
|
|
33
|
-
"Server-Key": serverToken,
|
|
34
|
-
},
|
|
28
|
+
headers: headers,
|
|
35
29
|
timeout: 10000, // 10 second timeout
|
|
36
30
|
});
|
|
37
31
|
|
|
@@ -26,25 +26,19 @@ module.exports = (serverToken, command) => {
|
|
|
26
26
|
const fetch = await import("node-fetch");
|
|
27
27
|
const { config } = await import("../../erlc.js");
|
|
28
28
|
|
|
29
|
-
// Check if global token is configured
|
|
30
|
-
if (!config?.globalToken) {
|
|
31
|
-
const error = await processError(
|
|
32
|
-
new Error(
|
|
33
|
-
"Global token not configured. Please initialize the client first."
|
|
34
|
-
)
|
|
35
|
-
);
|
|
36
|
-
return reject(error);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
29
|
const requestBody = JSON.stringify({ command: command.trim() });
|
|
40
30
|
|
|
31
|
+
const headers = {
|
|
32
|
+
"Server-Key": serverToken,
|
|
33
|
+
"Content-Type": "application/json",
|
|
34
|
+
};
|
|
35
|
+
if (config?.globalToken) {
|
|
36
|
+
headers["Authorization"] = config.globalToken;
|
|
37
|
+
}
|
|
38
|
+
|
|
41
39
|
const res = await fetch.default(`${BASEURL}/server/command`, {
|
|
42
40
|
method: "POST",
|
|
43
|
-
headers:
|
|
44
|
-
Authorization: config.globalToken,
|
|
45
|
-
"Server-Key": serverToken,
|
|
46
|
-
"Content-Type": "application/json",
|
|
47
|
-
},
|
|
41
|
+
headers: headers,
|
|
48
42
|
body: requestBody,
|
|
49
43
|
timeout: 15000, // 15 second timeout for commands
|
|
50
44
|
});
|
package/src/types/index.d.ts
CHANGED