erlc-api 2.3.4 → 3.1.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.
@@ -1,28 +1,53 @@
1
- const { BASEURL } = require("../../constants.js");
2
-
3
- module.exports = (serverToken) => {
4
- return new Promise(async (resolve, reject) => {
5
- try {
6
- const fetch = await import("node-fetch");
7
- const { config } = await import("../../erlc.js");
8
-
9
- const res = await fetch.default(`${BASEURL}/server/commandlogs`, {
10
- headers: {
11
- "Authorization": config?.globalToken,
12
- "Server-Key": serverToken,
13
- },
14
- });
15
- const data = await res.json().catch((err) => {
16
- return reject(err);
17
- });
18
-
19
- if (!res.ok) {
20
- return reject(data);
21
- }
22
-
23
- resolve(data);
24
- } catch (error) {
25
- reject(error);
26
- }
27
- });
28
- };
1
+ const { BASEURL } = require("../../constants.js");
2
+ const { processError } = require("../../utils/errorHandler.js");
3
+
4
+ /**
5
+ * Retrieves command logs from a server
6
+ * @param {string} serverToken - The server API key
7
+ * @returns {Promise<Array>} Promise that resolves to array of command logs
8
+ */
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
+ // Check if global token is configured
21
+ if (!config?.globalToken) {
22
+ const error = await processError(
23
+ new Error(
24
+ "Global token not configured. Please initialize the client first."
25
+ )
26
+ );
27
+ return reject(error);
28
+ }
29
+
30
+ const res = await fetch.default(`${BASEURL}/server/commandlogs`, {
31
+ headers: {
32
+ Authorization: config.globalToken,
33
+ "Server-Key": serverToken,
34
+ },
35
+ timeout: 10000, // 10 second timeout
36
+ });
37
+
38
+ if (!res.ok) {
39
+ const errorData = await res
40
+ .json()
41
+ .catch(() => ({ error: "Unknown API error" }));
42
+ const error = await processError(res, errorData);
43
+ return reject(error);
44
+ }
45
+
46
+ const data = await res.json();
47
+ resolve(Array.isArray(data) ? data : []);
48
+ } catch (error) {
49
+ const processedError = await processError(error);
50
+ reject(processedError);
51
+ }
52
+ });
53
+ };
@@ -1,28 +1,53 @@
1
- const { BASEURL } = require("../../constants.js");
2
-
3
- module.exports = (serverToken) => {
4
- return new Promise(async (resolve, reject) => {
5
- try {
6
- const fetch = await import("node-fetch");
7
- const { config } = await import("../../erlc.js");
8
-
9
- const res = await fetch.default(`${BASEURL}/server/joinlogs`, {
10
- headers: {
11
- "Authorization": config?.globalToken,
12
- "Server-Key": serverToken,
13
- },
14
- });
15
- const data = await res.json().catch((err) => {
16
- return reject(err);
17
- });
18
-
19
- if (!res.ok) {
20
- return reject(data);
21
- }
22
-
23
- resolve(data);
24
- } catch (error) {
25
- reject(error);
26
- }
27
- });
28
- };
1
+ const { BASEURL } = require("../../constants.js");
2
+ const { processError } = require("../../utils/errorHandler.js");
3
+
4
+ /**
5
+ * Retrieves join/leave logs from a server
6
+ * @param {string} serverToken - The server API key
7
+ * @returns {Promise<Array>} Promise that resolves to array of join logs
8
+ */
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
+ // Check if global token is configured
21
+ if (!config?.globalToken) {
22
+ const error = await processError(
23
+ new Error(
24
+ "Global token not configured. Please initialize the client first."
25
+ )
26
+ );
27
+ return reject(error);
28
+ }
29
+
30
+ const res = await fetch.default(`${BASEURL}/server/joinlogs`, {
31
+ headers: {
32
+ Authorization: config.globalToken,
33
+ "Server-Key": serverToken,
34
+ },
35
+ timeout: 10000, // 10 second timeout
36
+ });
37
+
38
+ if (!res.ok) {
39
+ const errorData = await res
40
+ .json()
41
+ .catch(() => ({ error: "Unknown API error" }));
42
+ const error = await processError(res, errorData);
43
+ return reject(error);
44
+ }
45
+
46
+ const data = await res.json();
47
+ resolve(Array.isArray(data) ? data : []);
48
+ } catch (error) {
49
+ const processedError = await processError(error);
50
+ reject(processedError);
51
+ }
52
+ });
53
+ };
@@ -1,28 +1,53 @@
1
- const { BASEURL } = require("../../constants.js");
2
-
3
- module.exports = (serverToken) => {
4
- return new Promise(async (resolve, reject) => {
5
- try {
6
- const fetch = await import("node-fetch");
7
- const { config } = await import("../../erlc.js");
8
-
9
- const res = await fetch.default(`${BASEURL}/server/killlogs`, {
10
- headers: {
11
- "Authorization": config?.globalToken,
12
- "Server-Key": serverToken,
13
- },
14
- });
15
- const data = await res.json().catch((err) => {
16
- return reject(err);
17
- });
18
-
19
- if (!res.ok) {
20
- return reject(data);
21
- }
22
-
23
- resolve(data);
24
- } catch (error) {
25
- reject(error);
26
- }
27
- });
28
- };
1
+ const { BASEURL } = require("../../constants.js");
2
+ const { processError } = require("../../utils/errorHandler.js");
3
+
4
+ /**
5
+ * Retrieves kill logs from a server
6
+ * @param {string} serverToken - The server API key
7
+ * @returns {Promise<Array>} Promise that resolves to array of kill logs
8
+ */
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
+ // Check if global token is configured
21
+ if (!config?.globalToken) {
22
+ const error = await processError(
23
+ new Error(
24
+ "Global token not configured. Please initialize the client first."
25
+ )
26
+ );
27
+ return reject(error);
28
+ }
29
+
30
+ const res = await fetch.default(`${BASEURL}/server/killlogs`, {
31
+ headers: {
32
+ Authorization: config.globalToken,
33
+ "Server-Key": serverToken,
34
+ },
35
+ timeout: 10000, // 10 second timeout
36
+ });
37
+
38
+ if (!res.ok) {
39
+ const errorData = await res
40
+ .json()
41
+ .catch(() => ({ error: "Unknown API error" }));
42
+ const error = await processError(res, errorData);
43
+ return reject(error);
44
+ }
45
+
46
+ const data = await res.json();
47
+ resolve(Array.isArray(data) ? data : []);
48
+ } catch (error) {
49
+ const processedError = await processError(error);
50
+ reject(processedError);
51
+ }
52
+ });
53
+ };
@@ -1,28 +1,53 @@
1
- const { BASEURL } = require("../../constants.js");
2
-
3
- module.exports = (serverToken) => {
4
- return new Promise(async (resolve, reject) => {
5
- try {
6
- const fetch = await import("node-fetch");
7
- const { config } = await import("../../erlc.js");
8
-
9
- const res = await fetch.default(`${BASEURL}/server/modcalls`, {
10
- headers: {
11
- "Authorization": config?.globalToken,
12
- "Server-Key": serverToken,
13
- },
14
- });
15
- const data = await res.json().catch((err) => {
16
- return reject(err);
17
- });
18
-
19
- if (!res.ok) {
20
- return reject(data);
21
- }
22
-
23
- resolve(data);
24
- } catch (error) {
25
- reject(error);
26
- }
27
- });
28
- };
1
+ const { BASEURL } = require("../../constants.js");
2
+ const { processError } = require("../../utils/errorHandler.js");
3
+
4
+ /**
5
+ * Retrieves moderator call logs from a server
6
+ * @param {string} serverToken - The server API key
7
+ * @returns {Promise<Array>} Promise that resolves to array of modcall logs
8
+ */
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
+ // Check if global token is configured
21
+ if (!config?.globalToken) {
22
+ const error = await processError(
23
+ new Error(
24
+ "Global token not configured. Please initialize the client first."
25
+ )
26
+ );
27
+ return reject(error);
28
+ }
29
+
30
+ const res = await fetch.default(`${BASEURL}/server/modcalls`, {
31
+ headers: {
32
+ Authorization: config.globalToken,
33
+ "Server-Key": serverToken,
34
+ },
35
+ timeout: 10000, // 10 second timeout
36
+ });
37
+
38
+ if (!res.ok) {
39
+ const errorData = await res
40
+ .json()
41
+ .catch(() => ({ error: "Unknown API error" }));
42
+ const error = await processError(res, errorData);
43
+ return reject(error);
44
+ }
45
+
46
+ const data = await res.json();
47
+ resolve(Array.isArray(data) ? data : []);
48
+ } catch (error) {
49
+ const processedError = await processError(error);
50
+ reject(processedError);
51
+ }
52
+ });
53
+ };
@@ -1,28 +1,53 @@
1
- const { BASEURL } = require("../../constants.js");
2
-
3
- module.exports = (serverToken) => {
4
- return new Promise(async (resolve, reject) => {
5
- try {
6
- const fetch = await import("node-fetch");
7
- const { config } = await import("../../erlc.js");
8
-
9
- const res = await fetch.default(`${BASEURL}/server/players`, {
10
- headers: {
11
- "Authorization": config?.globalToken,
12
- "Server-Key": serverToken,
13
- },
14
- });
15
- const data = await res.json().catch((err) => {
16
- return reject(err);
17
- });
18
-
19
- if (!res.ok) {
20
- return reject(data);
21
- }
22
-
23
- resolve(data);
24
- } catch (error) {
25
- reject(error);
26
- }
27
- });
28
- };
1
+ const { BASEURL } = require("../../constants.js");
2
+ const { processError } = require("../../utils/errorHandler.js");
3
+
4
+ /**
5
+ * Retrieves current players from a server
6
+ * @param {string} serverToken - The server API key
7
+ * @returns {Promise<Array>} Promise that resolves to array of current players
8
+ */
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
+ // Check if global token is configured
21
+ if (!config?.globalToken) {
22
+ const error = await processError(
23
+ new Error(
24
+ "Global token not configured. Please initialize the client first."
25
+ )
26
+ );
27
+ return reject(error);
28
+ }
29
+
30
+ const res = await fetch.default(`${BASEURL}/server/players`, {
31
+ headers: {
32
+ Authorization: config.globalToken,
33
+ "Server-Key": serverToken,
34
+ },
35
+ timeout: 10000, // 10 second timeout
36
+ });
37
+
38
+ if (!res.ok) {
39
+ const errorData = await res
40
+ .json()
41
+ .catch(() => ({ error: "Unknown API error" }));
42
+ const error = await processError(res, errorData);
43
+ return reject(error);
44
+ }
45
+
46
+ const data = await res.json();
47
+ resolve(Array.isArray(data) ? data : []);
48
+ } catch (error) {
49
+ const processedError = await processError(error);
50
+ reject(processedError);
51
+ }
52
+ });
53
+ };
@@ -1,28 +1,53 @@
1
- const { BASEURL } = require("../../constants.js");
2
-
3
- module.exports = (serverToken) => {
4
- return new Promise(async (resolve, reject) => {
5
- try {
6
- const fetch = await import("node-fetch");
7
- const { config } = await import("../../erlc.js");
8
-
9
- const res = await fetch.default(`${BASEURL}/server/queue`, {
10
- headers: {
11
- "Authorization": config?.globalToken,
12
- "Server-Key": serverToken,
13
- },
14
- });
15
- const data = await res.json().catch((err) => {
16
- return reject(err);
17
- });
18
-
19
- if (!res.ok) {
20
- return reject(data);
21
- }
22
-
23
- resolve(data);
24
- } catch (error) {
25
- reject(error);
26
- }
27
- });
28
- };
1
+ const { BASEURL } = require("../../constants.js");
2
+ const { processError } = require("../../utils/errorHandler.js");
3
+
4
+ /**
5
+ * Retrieves server queue information
6
+ * @param {string} serverToken - The server API key
7
+ * @returns {Promise<Array>} Promise that resolves to array of queued player IDs
8
+ */
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
+ // Check if global token is configured
21
+ if (!config?.globalToken) {
22
+ const error = await processError(
23
+ new Error(
24
+ "Global token not configured. Please initialize the client first."
25
+ )
26
+ );
27
+ return reject(error);
28
+ }
29
+
30
+ const res = await fetch.default(`${BASEURL}/server/queue`, {
31
+ headers: {
32
+ Authorization: config.globalToken,
33
+ "Server-Key": serverToken,
34
+ },
35
+ timeout: 10000, // 10 second timeout
36
+ });
37
+
38
+ if (!res.ok) {
39
+ const errorData = await res
40
+ .json()
41
+ .catch(() => ({ error: "Unknown API error" }));
42
+ const error = await processError(res, errorData);
43
+ return reject(error);
44
+ }
45
+
46
+ const data = await res.json();
47
+ resolve(Array.isArray(data) ? data : []);
48
+ } catch (error) {
49
+ const processedError = await processError(error);
50
+ reject(processedError);
51
+ }
52
+ });
53
+ };
@@ -1,52 +1,105 @@
1
- const { BASEURL , Vanity} = require("../../constants.js");
2
- module.exports = (serverToken) => {
3
- return new Promise(async (resolve, reject) => {
4
- try {
5
- const fetch = await import("node-fetch");
6
- const { config } = await import("../../erlc.js");
7
-
8
- const res = await fetch.default(`${BASEURL}/server`, {
9
- headers: {
10
- "Authorization": config?.globalToken,
11
- "Server-Key": serverToken,
12
- },
13
- });
14
-
15
- const data = await res.json().catch((err) => {
16
- return reject(err);
17
- });
18
-
19
- if (!res.ok) {
20
- return reject(data);
21
- }
22
- const getUsername = async (userId) => {
23
- const response = await fetch.default(`https://users.roblox.com/v1/users/${userId}`);
24
- const userData = await response.json();
25
- if (!response.ok) {
26
- throw new Error(`Error fetching username for ID: ${userId}`);
27
- }
28
- return userData.name;
29
- };
30
- try {
31
- const ownerUsername = await getUsername(data.OwnerId);
32
- const coOwnerUsernames = await Promise.all(data.CoOwnerIds.map(getUsername));
33
- const VanityURL = `${Vanity}${data.JoinKey}`
34
-
35
-
36
- data.OwnerUsername = ownerUsername;
37
- data.CoOwnerUsernames = coOwnerUsernames;
38
- data.VanityURL = VanityURL
39
-
40
- delete data.OwnerId;
41
- delete data.CoOwnerIds;
42
-
43
- resolve(data);
44
- } catch (error) {
45
- reject(error);
46
- }
47
-
48
- } catch (error) {
49
- reject(error);
50
- }
51
- });
52
- };
1
+ const { BASEURL, Vanity } = require("../../constants.js");
2
+ const { processError } = require("../../utils/errorHandler.js");
3
+
4
+ module.exports = (serverToken) => {
5
+ return new Promise(async (resolve, reject) => {
6
+ // Input validation
7
+ if (!serverToken || typeof serverToken !== "string") {
8
+ return reject(new Error("Server token is required and must be a string"));
9
+ }
10
+
11
+ try {
12
+ const fetch = await import("node-fetch");
13
+ const { config } = await import("../../erlc.js");
14
+
15
+ // Check if global token is configured
16
+ if (!config?.globalToken) {
17
+ return reject(
18
+ new Error(
19
+ "Global token not configured. Please initialize the client first."
20
+ )
21
+ );
22
+ }
23
+
24
+ const res = await fetch.default(`${BASEURL}/server`, {
25
+ headers: {
26
+ Authorization: config?.globalToken,
27
+ "Server-Key": serverToken,
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
+ const data = await res.json();
41
+
42
+ const getUsername = async (userId) => {
43
+ try {
44
+ const response = await fetch.default(
45
+ `https://users.roblox.com/v1/users/${userId}`
46
+ );
47
+ const userData = await response.json();
48
+ if (!response.ok) {
49
+ console.warn(`Warning: Could not fetch username for ID: ${userId}`);
50
+ return `User:${userId}`; // Fallback format
51
+ }
52
+ return userData.name;
53
+ } catch (error) {
54
+ console.warn(
55
+ `Warning: Error fetching username for ID: ${userId}`,
56
+ error
57
+ );
58
+ return `User:${userId}`; // Fallback format
59
+ }
60
+ };
61
+
62
+ try {
63
+ // Get owner username
64
+ const ownerUsername = await getUsername(data.OwnerId);
65
+
66
+ // Get co-owner usernames (handle empty array case)
67
+ const coOwnerUsernames =
68
+ data.CoOwnerIds && data.CoOwnerIds.length > 0
69
+ ? await Promise.all(data.CoOwnerIds.map(getUsername))
70
+ : [];
71
+
72
+ // Create vanity URL
73
+ const vanityURL = `${Vanity}${data.JoinKey}`;
74
+
75
+ // Add the new properties to the response
76
+ const enhancedData = {
77
+ ...data,
78
+ OwnerUsername: ownerUsername,
79
+ CoOwnerUsernames: coOwnerUsernames,
80
+ VanityURL: vanityURL,
81
+ };
82
+
83
+ // Remove the original ID properties as they're now converted to usernames
84
+ delete enhancedData.OwnerId;
85
+ delete enhancedData.CoOwnerIds;
86
+
87
+ resolve(enhancedData);
88
+ } catch (error) {
89
+ // If username fetching fails, still return the original data with IDs
90
+ console.warn(
91
+ "Warning: Could not fetch usernames, returning data with IDs:",
92
+ error
93
+ );
94
+ const fallbackData = {
95
+ ...data,
96
+ VanityURL: `${Vanity}${data.JoinKey}`,
97
+ };
98
+ resolve(fallbackData);
99
+ }
100
+ } catch (error) {
101
+ const processedError = await processError(error);
102
+ reject(processedError);
103
+ }
104
+ });
105
+ };