erlc-api 3.1.0 → 3.2.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/package.json +1 -1
- package/src/classes/client.js +23 -20
- package/src/erlc.js +1 -0
- package/src/functions/global/resetGlobalKey.js +60 -0
- package/src/types/index.d.ts +126 -126
package/package.json
CHANGED
package/src/classes/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const erlc = require(
|
|
2
|
-
const assert = require(
|
|
1
|
+
const erlc = require("../erlc.js");
|
|
2
|
+
const assert = require("../functions/assert.js");
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {Object} ClientConfig
|
|
@@ -13,24 +13,27 @@ const assert = require('../functions/assert.js')
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
class Client {
|
|
16
|
+
/**
|
|
17
|
+
* @constructor
|
|
18
|
+
* @param {ClientConfig} options - Client Options
|
|
19
|
+
*/
|
|
20
|
+
constructor(options) {
|
|
21
|
+
assert(
|
|
22
|
+
typeof options === "object",
|
|
23
|
+
`Syntax error: object expected for "options", received ${typeof options}`,
|
|
24
|
+
);
|
|
25
|
+
this.options = { ...options };
|
|
26
|
+
this.config();
|
|
27
|
+
}
|
|
16
28
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Updates and returns the client configurationg
|
|
28
|
-
* @returns {ClientConfig} The client configuration.
|
|
29
|
-
*/
|
|
30
|
-
config() {
|
|
31
|
-
erlc.config = this.options
|
|
32
|
-
return erlc.config
|
|
33
|
-
}
|
|
29
|
+
/**
|
|
30
|
+
* Updates and returns the client configurationg
|
|
31
|
+
* @returns {ClientConfig} The client configuration.
|
|
32
|
+
*/
|
|
33
|
+
config() {
|
|
34
|
+
erlc.config = this.options;
|
|
35
|
+
return erlc.config;
|
|
36
|
+
}
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
module.exports = Client
|
|
39
|
+
module.exports = Client;
|
package/src/erlc.js
CHANGED
|
@@ -11,5 +11,6 @@ exports.getQueue = require("./functions/server/getQueue.js");
|
|
|
11
11
|
exports.runCommand = require("./functions/server/runCommand.js");
|
|
12
12
|
exports.getVehicles = require("./functions/server/getVehicles.js");
|
|
13
13
|
exports.getStaff = require("./functions/server/getStaff.js");
|
|
14
|
+
exports.resetGlobalKey = require("./functions/global/resetGlobalKey.js");
|
|
14
15
|
|
|
15
16
|
exports.Client = require("./classes/client.js");
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const { BASEURL } = require("../../constants.js");
|
|
2
|
+
const { processError } = require("../../utils/errorHandler.js");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Resets the global API key
|
|
6
|
+
* @returns {Promise<string>} Promise that resolves to the new global API key
|
|
7
|
+
*/
|
|
8
|
+
module.exports = () => {
|
|
9
|
+
return new Promise(async (resolve, reject) => {
|
|
10
|
+
try {
|
|
11
|
+
const fetch = await import("node-fetch");
|
|
12
|
+
const { config } = await import("../../erlc.js");
|
|
13
|
+
|
|
14
|
+
// Check if global token is configured
|
|
15
|
+
if (!config?.globalToken) {
|
|
16
|
+
const error = await processError(
|
|
17
|
+
new Error(
|
|
18
|
+
"Global token not configured. Please initialize the client first.",
|
|
19
|
+
),
|
|
20
|
+
);
|
|
21
|
+
return reject(error);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const res = await fetch.default(`${BASEURL}/api-key/reset`, {
|
|
25
|
+
method: "POST",
|
|
26
|
+
headers: {
|
|
27
|
+
Authorization: config.globalToken,
|
|
28
|
+
},
|
|
29
|
+
timeout: 10000, // 10 second timeout
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
const errorData = await res
|
|
34
|
+
.json()
|
|
35
|
+
.catch(() => ({ error: "Unknown API error" }));
|
|
36
|
+
const error = await processError(res, errorData);
|
|
37
|
+
return reject(error);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// The response is likely a JSON with the new key, or just the key string?
|
|
41
|
+
// Docs say: "This will send a new key which can only be viewed once."
|
|
42
|
+
// Let's assume it returns a JSON object or just the string.
|
|
43
|
+
// Usually these APIs return a JSON object like { "key": "..." } or similar.
|
|
44
|
+
// However, looking at other endpoints, they return data directly.
|
|
45
|
+
// Let's assume it returns a JSON with the key, or we can inspect the response content type.
|
|
46
|
+
// But for now, let's try to parse as JSON.
|
|
47
|
+
|
|
48
|
+
const data = await res.json();
|
|
49
|
+
// If data has a specific field for the key, we should return that.
|
|
50
|
+
// If the documentation doesn't specify, I'll return the whole data object or try to find the key.
|
|
51
|
+
// Based on "This will send a new key", it might be { "apiKey": "..." } or just the string if it's text/plain.
|
|
52
|
+
// Given other endpoints return JSON, this likely returns JSON.
|
|
53
|
+
|
|
54
|
+
resolve(data);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
const processedError = await processError(error);
|
|
57
|
+
reject(processedError);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
package/src/types/index.d.ts
CHANGED
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
1
|
+
// Error handling types
|
|
2
|
+
export class ErlcError extends Error {
|
|
3
|
+
code: string | number;
|
|
4
|
+
status?: number;
|
|
5
|
+
category?: string;
|
|
6
|
+
severity?: string;
|
|
7
|
+
suggestions?: string[];
|
|
8
|
+
retryable?: boolean;
|
|
9
|
+
timestamp: string;
|
|
10
|
+
originalError?: Error;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
message: string,
|
|
14
|
+
code: string | number,
|
|
15
|
+
status?: number,
|
|
16
|
+
originalError?: Error,
|
|
17
|
+
);
|
|
18
|
+
toJSON(): object;
|
|
19
|
+
toString(): string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ErrorInfo {
|
|
23
|
+
message: string;
|
|
24
|
+
description: string;
|
|
25
|
+
category: string;
|
|
26
|
+
severity: string;
|
|
27
|
+
code?: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ClientConfig {
|
|
31
|
+
globalToken: string; // The ER:LC global API token
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const BASEURL = "https://api.policeroleplay.community/v1";
|
|
35
|
+
|
|
36
|
+
type PlayerId = string;
|
|
37
|
+
type PlayerName = string;
|
|
38
|
+
type TextureName = string;
|
|
39
|
+
type CarName = string;
|
|
40
|
+
|
|
41
|
+
export type ErlcPlayer = `${PlayerName}:${PlayerId}`; // Playername:UserID
|
|
42
|
+
export type ErlcPlayerPermission =
|
|
43
|
+
| "Normal"
|
|
44
|
+
| "Server Administrator"
|
|
45
|
+
| "Server Owner"
|
|
46
|
+
| "Server Moderator";
|
|
47
|
+
|
|
48
|
+
export interface ServerStatus {
|
|
49
|
+
Name: string; // The server name
|
|
50
|
+
OwnerUsername: string; // The username of the server owner
|
|
51
|
+
CoOwnerUsernames: string[]; // The usernames of the server co owners
|
|
52
|
+
CurrentPlayers: number; // The amount of people currently in-game
|
|
53
|
+
MaxPlayers: number; // The amount of people who can join the server including server owner
|
|
54
|
+
JoinKey: string; // The code used to join the private server
|
|
55
|
+
AccVerifiedReq: "Disabled" | "Email" | "Phone/ID"; // The level of verification roblox accounts need to join the private server
|
|
56
|
+
TeamBalance: boolean; // If team balance is enabled or not
|
|
57
|
+
VanityURL: string; // The vanity URL to join the server
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface ServerPlayer {
|
|
61
|
+
Player: ErlcPlayer;
|
|
62
|
+
Permission: ErlcPlayerPermission;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface JoinLog {
|
|
66
|
+
Join: boolean; // True is join and False is leave
|
|
67
|
+
Timestamp: number; // Timestamp in seconds
|
|
68
|
+
Player: ErlcPlayer;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface KillLog {
|
|
72
|
+
Killed: ErlcPlayer;
|
|
73
|
+
Timestamp: number; // Timestamp in seconds
|
|
74
|
+
Killer: ErlcPlayer;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface CommandLog {
|
|
78
|
+
Player: ErlcPlayer;
|
|
79
|
+
Timestamp: number; // Timestamp in seconds
|
|
80
|
+
Command: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface ModcallLog {
|
|
84
|
+
Caller: ErlcPlayer;
|
|
85
|
+
Moderator?: ErlcPlayer; // If call is unanswered property is undefined
|
|
86
|
+
Timestamp: number; // Timestamp in seconds
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type ServerBan = Record<PlayerId, PlayerName>;
|
|
90
|
+
|
|
91
|
+
export interface VehiclesLog {
|
|
92
|
+
Texture: string | null;
|
|
93
|
+
Name: string;
|
|
94
|
+
Owner: ErlcPlayer;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface ServerStaff {
|
|
98
|
+
CoOwners: number[];
|
|
99
|
+
Admins: Record<string, string>;
|
|
100
|
+
Mods: Record<string, string>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface VSMCommandBody {
|
|
104
|
+
command: string; // ":h Hey everyone!"
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function getBans(serverToken: string): Promise<ServerBan>;
|
|
108
|
+
export function getCommandLogs(serverToken: string): Promise<CommandLog[]>;
|
|
109
|
+
export function getJoinLogs(serverToken: string): Promise<JoinLog[]>;
|
|
110
|
+
export function getKillLogs(serverToken: string): Promise<KillLog[]>;
|
|
111
|
+
export function getModcallLogs(serverToken: string): Promise<ModcallLog[]>;
|
|
112
|
+
export function getPlayers(serverToken: string): Promise<ServerPlayer[]>;
|
|
113
|
+
export function getQueue(serverToken: string): Promise<number[]>;
|
|
114
|
+
export function getServer(serverToken: string): Promise<ServerStatus>;
|
|
115
|
+
export function getStaff(serverToken: string): Promise<ServerStaff>;
|
|
116
|
+
export function getVehicles(serverToken: string): Promise<VehiclesLog[]>;
|
|
117
|
+
export function runCommand(
|
|
118
|
+
serverToken: string,
|
|
119
|
+
command: string,
|
|
120
|
+
): Promise<boolean>;
|
|
121
|
+
|
|
122
|
+
export function resetGlobalKey(): Promise<any>;
|
|
123
|
+
|
|
124
|
+
export class Client {
|
|
125
|
+
constructor(options: ClientConfig);
|
|
126
|
+
config(): ClientConfig;
|
|
127
127
|
}
|