erlc-api 3.3.1 → 3.3.2-a

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 CHANGED
@@ -12,11 +12,11 @@ A lightweight, complete, and **fully typed** library for interacting with the *E
12
12
 
13
13
  ## ✨ Features
14
14
 
15
- - 🎯 **Full Coverage**: Support for 100% of the API v1 endpoints.
15
+ - 🎯 **Current API Support**: Uses `https://api.erlc.gg/v2` where available.
16
16
  - 🛡️ **TypeScript Support**: Native type definitions included.
17
17
  - ⚡ **Lightweight & Fast**: No unnecessary heavy dependencies.
18
18
  - 🔒 **Secure**: Robust token validation and error handling.
19
- - 🆕 **Up-to-date**: Support for optional `GlobalToken` (v3.2.0+).
19
+ - 🆕 **Up-to-date**: Supports optional global API keys for large-scale apps.
20
20
 
21
21
  ## 📦 Installation
22
22
 
@@ -71,6 +71,16 @@ console.table(players); // Shows name, ID, permission, and team
71
71
 
72
72
  // Get vehicles on the map
73
73
  const vehicles = await erlc.getVehicles(serverToken);
74
+
75
+ // Get emergency calls
76
+ const emergencyCalls = await erlc.getEmergencyCalls(serverToken);
77
+
78
+ // Fetch server info with v2 include flags in one request
79
+ const fullServer = await erlc.getServer(serverToken, {
80
+ players: true,
81
+ staff: true,
82
+ emergencyCalls: true,
83
+ });
74
84
  ```
75
85
 
76
86
  ### 📜 Logs
@@ -129,10 +139,10 @@ try {
129
139
 
130
140
  | Error Code | Description |
131
141
  |------------|-------------|
132
- | `401` | Unauthorized (Invalid Token) |
133
- | `403` | Forbidden (Permissions issue) |
134
- | `429` | Rate Limit Exceeded |
135
- | `500` | Internal Server Error |
142
+ | `2002` | Invalid or expired server key |
143
+ | `3002` | Server offline |
144
+ | `4001` | Rate limit exceeded |
145
+ | `9999` | In-game server module is out of date |
136
146
 
137
147
  ---
138
148
 
package/README_ES.md CHANGED
@@ -6,17 +6,17 @@
6
6
 
7
7
  [🇬🇧 English Version](README.md)
8
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.
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
10
 
11
11
  ---
12
12
 
13
13
  ## ✨ Características
14
14
 
15
- - 🎯 **Cobertura Total**: Soporte para el 100% de los endpoints de la API v1.
15
+ - 🎯 **Soporte API Actual**: Usa `https://api.erlc.gg/v2` donde está disponible.
16
16
  - 🛡️ **Tipado TypeScript**: Definiciones de tipos incluidas nativamente.
17
17
  - ⚡ **Ligero y Rápido**: Sin dependencias pesadas innecesarias.
18
18
  - 🔒 **Seguro**: Validación de tokens y manejo de errores robusto.
19
- - 🆕 **Actualizado**: Soporte para `GlobalToken` opcional (v3.2.0+).
19
+ - 🆕 **Actualizado**: Soporte para global API keys opcionales en apps grandes.
20
20
 
21
21
  ## 📦 Instalación
22
22
 
@@ -33,6 +33,7 @@ bun add erlc-api
33
33
  Puedes usar la librería con o sin un `Global Token` (requerido solo para aplicaciones a gran escala).
34
34
 
35
35
  **JavaScript**
36
+
36
37
  ```javascript
37
38
  const erlc = require("erlc-api");
38
39
 
@@ -44,6 +45,7 @@ const client = new erlc.Client();
44
45
  ```
45
46
 
46
47
  **TypeScript**
48
+
47
49
  ```typescript
48
50
  import { Client, getServer } from "erlc-api";
49
51
 
@@ -63,7 +65,9 @@ const serverToken = "tu-server-key-aqui";
63
65
 
64
66
  // Obtener estado del servidor
65
67
  const server = await erlc.getServer(serverToken);
66
- console.log(`Servidor: ${server.Name} | Jugadores: ${server.CurrentPlayers}/${server.MaxPlayers}`);
68
+ console.log(
69
+ `Servidor: ${server.Name} | Jugadores: ${server.CurrentPlayers}/${server.MaxPlayers}`,
70
+ );
67
71
 
68
72
  // Obtener jugadores conectados
69
73
  const players = await erlc.getPlayers(serverToken);
@@ -71,6 +75,16 @@ console.table(players); // Muestra nombre, ID, permisos y equipo
71
75
 
72
76
  // Obtener vehículos en el mapa
73
77
  const vehicles = await erlc.getVehicles(serverToken);
78
+
79
+ // Obtener llamadas de emergencia
80
+ const emergencyCalls = await erlc.getEmergencyCalls(serverToken);
81
+
82
+ // Obtener información del servidor con includes de v2 en una sola petición
83
+ const fullServer = await erlc.getServer(serverToken, {
84
+ players: true,
85
+ staff: true,
86
+ emergencyCalls: true,
87
+ });
74
88
  ```
75
89
 
76
90
  ### 📜 Registros (Logs)
@@ -99,7 +113,11 @@ const bans = await erlc.getBans(serverToken);
99
113
 
100
114
  // Obtener Staff del servidor
101
115
  const staff = await erlc.getStaff(serverToken);
116
+ ```
117
+
118
+ ### 📢 Otros Comandos
102
119
 
120
+ ```javascript
103
121
  // Ejecutar comando remoto (Ej: Anuncio)
104
122
  await erlc.runCommand(serverToken, ":h ¡Hola desde la API!");
105
123
 
@@ -118,26 +136,28 @@ try {
118
136
  await erlc.getServer(serverToken);
119
137
  } catch (error) {
120
138
  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ó.");
139
+
140
+ if (error.code === 4001)
141
+ console.log(" Rate limit alcanzado, espera un momento.");
142
+ if (error.code === 2002)
143
+ console.log("🔑 La Server Key es inválida o expiró.");
124
144
  }
125
145
  ```
126
146
 
127
147
  ### Códigos Comunes
128
148
 
129
- | Código | Significado | Solución |
130
- |:---:|---|---|
131
- | **2002** | Key Inválida | Verifica tu `Server-Key` en el juego. |
149
+ | Código | Significado | Solución |
150
+ | :------: | ---------------- | ---------------------------------------------- |
151
+ | **2002** | Key Inválida | Verifica tu `Server-Key` en el juego. |
132
152
  | **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. |
153
+ | **4001** | Rate Limit | Estás enviando muchas peticiones muy rápido. |
154
+ | **403** | No Autorizado | Verifica tus permisos o tokens. |
135
155
 
136
156
  ---
137
157
 
138
158
  ## 🔗 Enlaces Útiles
139
159
 
140
- - [Documentación Oficial de PRC](https://apidocs.policeroleplay.community/)
160
+ - [Documentación Oficial de ER:LC](https://apidocs.erlc.gg/)
141
161
  - [Discord de Soporte PRC](https://discord.gg/prc)
142
162
  - [NPM Package](https://www.npmjs.com/package/erlc-api)
143
163
 
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "erlc-api",
3
- "version": "3.3.1",
3
+ "version": "3.3.2a",
4
4
  "description": "An ER:LC API wrapper for JS/TS",
5
5
  "main": "index.js",
6
6
  "types": "src/types/index.d.ts",
7
+ "packageManager": "pnpm@11.1.2",
7
8
  "keywords": [
8
9
  "erlc",
9
10
  "roblox",
@@ -14,16 +15,22 @@
14
15
  "author": "egologics",
15
16
  "license": "MIT",
16
17
  "devDependencies": {
17
- "typescript": "^5.3.2"
18
+ "jest": "^30.4.2",
19
+ "typescript": "^6.0.3"
18
20
  },
19
21
  "dependencies": {
20
- "chalk": "^5.4.1",
22
+ "chalk": "^5.6.2",
21
23
  "cli-table3": "^0.6.5",
22
24
  "node-fetch": "^3.3.2",
23
- "ora": "^8.2.0"
25
+ "ora": "^9.4.0"
24
26
  },
25
27
  "scripts": {
26
- "test": "echo \"Error: no test specified\" && exit 1"
28
+ "test": "jest"
29
+ },
30
+ "pnpm": {
31
+ "onlyBuiltDependencies": [
32
+ "unrs-resolver"
33
+ ]
27
34
  },
28
35
  "repository": {
29
36
  "type": "git",
@@ -0,0 +1,2 @@
1
+ allowBuilds:
2
+ unrs-resolver: true
@@ -3,7 +3,13 @@ const assert = require("../functions/assert.js");
3
3
 
4
4
  /**
5
5
  * @typedef {Object} ClientConfig
6
- * @property {string} globalToken - Your ER:LC global API token
6
+ * @property {string} [globalToken] - Your ER:LC global API token
7
+ * @property {Object} [cache] - Cache configuration
8
+ * @property {boolean} [cache.enabled] - Enable in-memory cache
9
+ * @property {Object.<string, number>} [cache.ttlMs] - Per-endpoint TTL in ms
10
+ * @property {boolean} [cache.staleWhileRevalidate] - Placeholder for future strategy
11
+ * @property {Object} [logger] - Logger instance (console-compatible)
12
+ * @property {Function} [fetch] - Custom fetch implementation
7
13
  */
8
14
 
9
15
  /**
@@ -31,7 +37,12 @@ class Client {
31
37
  * @returns {ClientConfig} The client configuration.
32
38
  */
33
39
  config() {
34
- erlc.config = this.options;
40
+ // Mutate existing config object to preserve references
41
+ erlc.config.globalToken = this.options.globalToken;
42
+ erlc.config.serverToken = this.options.serverToken;
43
+ erlc.config.cache = this.options.cache;
44
+ erlc.config.logger = this.options.logger;
45
+ erlc.config.fetch = this.options.fetch;
35
46
  return erlc.config;
36
47
  }
37
48
  }
package/src/constants.js CHANGED
@@ -1,2 +1,5 @@
1
- exports.Vanity = "https://policeroleplay.community/join?code="
2
- exports.BASEURL = "https://api.policeroleplay.community/v1"
1
+ exports.Vanity = "https://erlc.gg/join/"
2
+ exports.API_ORIGIN = "https://api.erlc.gg"
3
+ exports.API_VERSION = "v2"
4
+ exports.BASEURL = `${exports.API_ORIGIN}/${exports.API_VERSION}`
5
+ exports.LEGACY_BASEURL = `${exports.API_ORIGIN}/v1`
package/src/erlc.js CHANGED
@@ -1,10 +1,33 @@
1
- exports.config = {};
1
+ exports.config = {
2
+ cache: {
3
+ enabled: false,
4
+ ttlMs: {
5
+ server: 10000,
6
+ players: 3000,
7
+ vehicles: 5000,
8
+ joinlogs: 3000,
9
+ killlogs: 3000,
10
+ commandlogs: 3000,
11
+ modcalls: 3000,
12
+ emergencycalls: 3000,
13
+ staff: 10000,
14
+ queue: 2000,
15
+ bans: 10000,
16
+ },
17
+ staleWhileRevalidate: false,
18
+ },
19
+ logger: console,
20
+ fetch: null,
21
+ };
22
+
23
+ Object.assign(exports, require("./constants.js"));
2
24
 
3
25
  exports.getBans = require("./functions/server/getBans.js");
4
26
  exports.getCommandLogs = require("./functions/server/getCommandLogs.js");
5
27
  exports.getJoinLogs = require("./functions/server/getJoinLogs.js");
6
28
  exports.getKillLogs = require("./functions/server/getKillLogs.js");
7
29
  exports.getModcallLogs = require("./functions/server/getModcallLogs.js");
30
+ exports.getEmergencyCalls = require("./functions/server/getEmergencyCalls.js");
8
31
  exports.getPlayers = require("./functions/server/getPlayers.js");
9
32
  exports.getServer = require("./functions/server/getServer.js");
10
33
  exports.getQueue = require("./functions/server/getQueue.js");
@@ -14,3 +37,8 @@ exports.getStaff = require("./functions/server/getStaff.js");
14
37
  exports.resetGlobalKey = require("./functions/global/resetGlobalKey.js");
15
38
 
16
39
  exports.Client = require("./classes/client.js");
40
+
41
+ exports.utils = {
42
+ cache: require("./utils/cache.js"),
43
+ discord: require("./utils/discord.js"),
44
+ };
@@ -21,6 +21,9 @@ class ErlcError extends Error {
21
21
  message: this.message,
22
22
  code: this.code,
23
23
  status: this.status,
24
+ retryAfter: this.retryAfter,
25
+ bucket: this.bucket,
26
+ commandId: this.commandId,
24
27
  timestamp: this.timestamp,
25
28
  stack: this.stack,
26
29
  };
@@ -1,4 +1,4 @@
1
- const { BASEURL } = require("../../constants.js");
1
+ const { LEGACY_BASEURL } = require("../../constants.js");
2
2
  const { processError } = require("../../utils/errorHandler.js");
3
3
 
4
4
  /**
@@ -8,20 +8,24 @@ const { processError } = require("../../utils/errorHandler.js");
8
8
  module.exports = () => {
9
9
  return new Promise(async (resolve, reject) => {
10
10
  try {
11
- const fetch = await import("node-fetch");
12
- const { config } = await import("../../erlc.js");
11
+ const { config } = require("../../erlc.js");
13
12
 
14
13
  // Check if global token is configured
15
14
  if (!config?.globalToken) {
16
15
  const error = await processError(
17
16
  new Error(
18
- "Global token not configured. Please initialize the client first."
19
- )
17
+ "Global token not configured. Please initialize the client first.",
18
+ ),
20
19
  );
21
20
  return reject(error);
22
21
  }
23
22
 
24
- const res = await fetch.default(`${BASEURL}/api-key/reset`, {
23
+ const f =
24
+ config?.fetch ||
25
+ (typeof globalThis.fetch === "function"
26
+ ? globalThis.fetch
27
+ : (await import("node-fetch")).default);
28
+ const res = await f(`${LEGACY_BASEURL}/api-key/reset`, {
25
29
  method: "POST",
26
30
  headers: {
27
31
  Authorization: config.globalToken,
@@ -44,13 +48,13 @@ module.exports = () => {
44
48
  // However, looking at other endpoints, they return data directly.
45
49
  // Let's assume it returns a JSON with the key, or we can inspect the response content type.
46
50
  // But for now, let's try to parse as JSON.
47
-
51
+
48
52
  const data = await res.json();
49
53
  // If data has a specific field for the key, we should return that.
50
54
  // If the documentation doesn't specify, I'll return the whole data object or try to find the key.
51
55
  // Based on "This will send a new key", it might be { "apiKey": "..." } or just the string if it's text/plain.
52
56
  // Given other endpoints return JSON, this likely returns JSON.
53
-
57
+
54
58
  resolve(data);
55
59
  } catch (error) {
56
60
  const processedError = await processError(error);
@@ -1,47 +1,17 @@
1
- const { BASEURL } = require("../../constants.js");
2
- const { processError } = require("../../utils/errorHandler.js");
1
+ const { requestLegacyServer } = require("./requestServer.js");
3
2
 
4
3
  /**
5
- * Retrieves the list of banned players from a server
4
+ * Retrieves the list of banned players from a server.
5
+ *
6
+ * The current v2 server document does not expose Bans as an include flag,
7
+ * so this uses the documented v1 bans route on the new api.erlc.gg domain.
8
+ *
6
9
  * @param {string} serverToken - The server API key
7
10
  * @returns {Promise<Object>} Promise that resolves to banned players object
8
11
  */
9
- module.exports = (serverToken) => {
10
- return new Promise(async (resolve, reject) => {
11
- // Input validation
12
- if (!serverToken || typeof serverToken !== "string") {
13
- return reject(new Error("Server token is required and must be a string"));
14
- }
15
-
16
- try {
17
- const fetch = await import("node-fetch");
18
- const { config } = await import("../../erlc.js");
19
-
20
- const headers = {
21
- "Server-Key": serverToken,
22
- };
23
- if (config?.globalToken) {
24
- headers["Authorization"] = config.globalToken;
25
- }
26
-
27
- const res = await fetch.default(`${BASEURL}/server/bans`, {
28
- headers: headers,
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
- const data = await res.json();
41
- resolve(data || {});
42
- } catch (error) {
43
- const processedError = await processError(error);
44
- reject(processedError);
45
- }
12
+ module.exports = (serverToken) =>
13
+ requestLegacyServer(serverToken, "/server/bans", {
14
+ endpoint: "bans",
15
+ defaultValue: {},
16
+ transform: (data) => data || {},
46
17
  });
47
- };
@@ -1,47 +1,15 @@
1
- const { BASEURL } = require("../../constants.js");
2
- const { processError } = require("../../utils/errorHandler.js");
1
+ const { requestServer } = require("./requestServer.js");
3
2
 
4
3
  /**
5
- * Retrieves command logs from a server
4
+ * Retrieves command logs from a server.
6
5
  * @param {string} serverToken - The server API key
7
6
  * @returns {Promise<Array>} Promise that resolves to array of command logs
8
7
  */
9
- module.exports = (serverToken) => {
10
- return new Promise(async (resolve, reject) => {
11
- // Input validation
12
- if (!serverToken || typeof serverToken !== "string") {
13
- return reject(new Error("Server token is required and must be a string"));
14
- }
15
-
16
- try {
17
- const fetch = await import("node-fetch");
18
- const { config } = await import("../../erlc.js");
19
-
20
- const headers = {
21
- "Server-Key": serverToken,
22
- };
23
- if (config?.globalToken) {
24
- headers["Authorization"] = config.globalToken;
25
- }
26
-
27
- const res = await fetch.default(`${BASEURL}/server/commandlogs`, {
28
- headers: headers,
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
- const data = await res.json();
41
- resolve(Array.isArray(data) ? data : []);
42
- } catch (error) {
43
- const processedError = await processError(error);
44
- reject(processedError);
45
- }
8
+ module.exports = (serverToken) =>
9
+ requestServer(serverToken, {
10
+ endpoint: "commandlogs",
11
+ includes: ["CommandLogs"],
12
+ defaultValue: [],
13
+ transform: (data) =>
14
+ Array.isArray(data?.CommandLogs) ? data.CommandLogs : [],
46
15
  });
47
- };
@@ -0,0 +1,15 @@
1
+ const { requestServer } = require("./requestServer.js");
2
+
3
+ /**
4
+ * Retrieves emergency call logs from a server.
5
+ * @param {string} serverToken - The server API key
6
+ * @returns {Promise<Array>} Promise that resolves to array of emergency calls
7
+ */
8
+ module.exports = (serverToken) =>
9
+ requestServer(serverToken, {
10
+ endpoint: "emergencycalls",
11
+ includes: ["EmergencyCalls"],
12
+ defaultValue: [],
13
+ transform: (data) =>
14
+ Array.isArray(data?.EmergencyCalls) ? data.EmergencyCalls : [],
15
+ });
@@ -1,47 +1,14 @@
1
- const { BASEURL } = require("../../constants.js");
2
- const { processError } = require("../../utils/errorHandler.js");
1
+ const { requestServer } = require("./requestServer.js");
3
2
 
4
3
  /**
5
- * Retrieves join/leave logs from a server
4
+ * Retrieves join/leave logs from a server.
6
5
  * @param {string} serverToken - The server API key
7
6
  * @returns {Promise<Array>} Promise that resolves to array of join logs
8
7
  */
9
- module.exports = (serverToken) => {
10
- return new Promise(async (resolve, reject) => {
11
- // Input validation
12
- if (!serverToken || typeof serverToken !== "string") {
13
- return reject(new Error("Server token is required and must be a string"));
14
- }
15
-
16
- try {
17
- const fetch = await import("node-fetch");
18
- const { config } = await import("../../erlc.js");
19
-
20
- const headers = {
21
- "Server-Key": serverToken,
22
- };
23
- if (config?.globalToken) {
24
- headers["Authorization"] = config.globalToken;
25
- }
26
-
27
- const res = await fetch.default(`${BASEURL}/server/joinlogs`, {
28
- headers: headers,
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
- const data = await res.json();
41
- resolve(Array.isArray(data) ? data : []);
42
- } catch (error) {
43
- const processedError = await processError(error);
44
- reject(processedError);
45
- }
8
+ module.exports = (serverToken) =>
9
+ requestServer(serverToken, {
10
+ endpoint: "joinlogs",
11
+ includes: ["JoinLogs"],
12
+ defaultValue: [],
13
+ transform: (data) => (Array.isArray(data?.JoinLogs) ? data.JoinLogs : []),
46
14
  });
47
- };
@@ -1,47 +1,14 @@
1
- const { BASEURL } = require("../../constants.js");
2
- const { processError } = require("../../utils/errorHandler.js");
1
+ const { requestServer } = require("./requestServer.js");
3
2
 
4
3
  /**
5
- * Retrieves kill logs from a server
4
+ * Retrieves kill logs from a server.
6
5
  * @param {string} serverToken - The server API key
7
6
  * @returns {Promise<Array>} Promise that resolves to array of kill logs
8
7
  */
9
- module.exports = (serverToken) => {
10
- return new Promise(async (resolve, reject) => {
11
- // Input validation
12
- if (!serverToken || typeof serverToken !== "string") {
13
- return reject(new Error("Server token is required and must be a string"));
14
- }
15
-
16
- try {
17
- const fetch = await import("node-fetch");
18
- const { config } = await import("../../erlc.js");
19
-
20
- const headers = {
21
- "Server-Key": serverToken,
22
- };
23
- if (config?.globalToken) {
24
- headers["Authorization"] = config.globalToken;
25
- }
26
-
27
- const res = await fetch.default(`${BASEURL}/server/killlogs`, {
28
- headers: headers,
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
- const data = await res.json();
41
- resolve(Array.isArray(data) ? data : []);
42
- } catch (error) {
43
- const processedError = await processError(error);
44
- reject(processedError);
45
- }
8
+ module.exports = (serverToken) =>
9
+ requestServer(serverToken, {
10
+ endpoint: "killlogs",
11
+ includes: ["KillLogs"],
12
+ defaultValue: [],
13
+ transform: (data) => (Array.isArray(data?.KillLogs) ? data.KillLogs : []),
46
14
  });
47
- };
@@ -1,47 +1,14 @@
1
- const { BASEURL } = require("../../constants.js");
2
- const { processError } = require("../../utils/errorHandler.js");
1
+ const { requestServer } = require("./requestServer.js");
3
2
 
4
3
  /**
5
- * Retrieves moderator call logs from a server
4
+ * Retrieves moderator call logs from a server.
6
5
  * @param {string} serverToken - The server API key
7
6
  * @returns {Promise<Array>} Promise that resolves to array of modcall logs
8
7
  */
9
- module.exports = (serverToken) => {
10
- return new Promise(async (resolve, reject) => {
11
- // Input validation
12
- if (!serverToken || typeof serverToken !== "string") {
13
- return reject(new Error("Server token is required and must be a string"));
14
- }
15
-
16
- try {
17
- const fetch = await import("node-fetch");
18
- const { config } = await import("../../erlc.js");
19
-
20
- const headers = {
21
- "Server-Key": serverToken,
22
- };
23
- if (config?.globalToken) {
24
- headers["Authorization"] = config.globalToken;
25
- }
26
-
27
- const res = await fetch.default(`${BASEURL}/server/modcalls`, {
28
- headers: headers,
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
- const data = await res.json();
41
- resolve(Array.isArray(data) ? data : []);
42
- } catch (error) {
43
- const processedError = await processError(error);
44
- reject(processedError);
45
- }
8
+ module.exports = (serverToken) =>
9
+ requestServer(serverToken, {
10
+ endpoint: "modcalls",
11
+ includes: ["ModCalls"],
12
+ defaultValue: [],
13
+ transform: (data) => (Array.isArray(data?.ModCalls) ? data.ModCalls : []),
46
14
  });
47
- };