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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "erlc-api",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "An ER:LC API wrapper for JS/TS",
5
5
  "main": "index.js",
6
6
  "types": "src/types/index.d.ts",
@@ -1,5 +1,5 @@
1
- const erlc = require('../erlc.js')
2
- const assert = require('../functions/assert.js')
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
- * @constructor
19
- * @param {ClientConfig} options - Client Options
20
- */
21
- constructor(options) {
22
- assert(typeof options === 'object', `Syntax error: object expected for "options", received ${typeof options}`);
23
- this.options = { ...options };
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
+ };
@@ -1,127 +1,127 @@
1
- declare module "erlc-api" {
2
- // Error handling types
3
- export class ErlcError extends Error {
4
- code: string | number;
5
- status?: number;
6
- category?: string;
7
- severity?: string;
8
- suggestions?: string[];
9
- retryable?: boolean;
10
- timestamp: string;
11
- originalError?: Error;
12
-
13
- constructor(
14
- message: string,
15
- code: string | number,
16
- status?: number,
17
- originalError?: Error
18
- );
19
- toJSON(): object;
20
- toString(): string;
21
- }
22
-
23
- export interface ErrorInfo {
24
- message: string;
25
- description: string;
26
- category: string;
27
- severity: string;
28
- code?: number;
29
- }
30
-
31
- export interface ClientConfig {
32
- globalToken: string; // The ER:LC global API token
33
- }
34
-
35
- export const BASEURL = "https://api.policeroleplay.community/v1";
36
-
37
- type PlayerId = string;
38
- type PlayerName = string;
39
- type TextureName = string;
40
- type CarName = string;
41
-
42
- export type ErlcPlayer = `${PlayerName}:${PlayerId}`; // Playername:UserID
43
- export type ErlcPlayerPermission =
44
- | "Normal"
45
- | "Server Administrator"
46
- | "Server Owner"
47
- | "Server Moderator";
48
-
49
- export interface ServerStatus {
50
- Name: string; // The server name
51
- OwnerUsername: string; // The username of the server owner
52
- CoOwnerUsernames: string[]; // The usernames of the server co owners
53
- CurrentPlayers: number; // The amount of people currently in-game
54
- MaxPlayers: number; // The amount of people who can join the server including server owner
55
- JoinKey: string; // The code used to join the private server
56
- AccVerifiedReq: "Disabled" | "Email" | "Phone/ID"; // The level of verification roblox accounts need to join the private server
57
- TeamBalance: boolean; // If team balance is enabled or not
58
- VanityURL: string; // The vanity URL to join the server
59
- }
60
-
61
- export interface ServerPlayer {
62
- Player: ErlcPlayer;
63
- Permission: ErlcPlayerPermission;
64
- }
65
-
66
- export interface JoinLog {
67
- Join: boolean; // True is join and False is leave
68
- Timestamp: number; // Timestamp in seconds
69
- Player: ErlcPlayer;
70
- }
71
-
72
- export interface KillLog {
73
- Killed: ErlcPlayer;
74
- Timestamp: number; // Timestamp in seconds
75
- Killer: ErlcPlayer;
76
- }
77
-
78
- export interface CommandLog {
79
- Player: ErlcPlayer;
80
- Timestamp: number; // Timestamp in seconds
81
- Command: string;
82
- }
83
-
84
- export interface ModcallLog {
85
- Caller: ErlcPlayer;
86
- Moderator?: ErlcPlayer; // If call is unanswered property is undefined
87
- Timestamp: number; // Timestamp in seconds
88
- }
89
-
90
- export type ServerBan = Record<PlayerId, PlayerName>;
91
-
92
- export interface VehiclesLog {
93
- Texture: string | null;
94
- Name: string;
95
- Owner: ErlcPlayer;
96
- }
97
-
98
- export interface ServerStaff {
99
- CoOwners: number[];
100
- Admins: Record<string, string>;
101
- Mods: Record<string, string>;
102
- }
103
-
104
- export interface VSMCommandBody {
105
- command: string; // ":h Hey everyone!"
106
- }
107
-
108
- export function getBans(serverToken: string): Promise<ServerBan>;
109
- export function getCommandLogs(serverToken: string): Promise<CommandLog[]>;
110
- export function getJoinLogs(serverToken: string): Promise<JoinLog[]>;
111
- export function getKillLogs(serverToken: string): Promise<KillLog[]>;
112
- export function getModcallLogs(serverToken: string): Promise<ModcallLog[]>;
113
- export function getPlayers(serverToken: string): Promise<ServerPlayer[]>;
114
- export function getQueue(serverToken: string): Promise<number[]>;
115
- export function getServer(serverToken: string): Promise<ServerStatus>;
116
- export function getStaff(serverToken: string): Promise<ServerStaff>;
117
- export function getVehicles(serverToken: string): Promise<VehiclesLog[]>;
118
- export function runCommand(
119
- serverToken: string,
120
- command: string
121
- ): Promise<boolean>;
122
-
123
- export class Client {
124
- constructor(options: ClientConfig);
125
- config(): ClientConfig;
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
  }