erlc-api 1.3.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/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 0Adexus0
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # ER:LC API Wrapper
2
+
3
+ A lightweight API Wrapper with 100% coverage of the ER:LC API. Fixed Error and Improvements
4
+
5
+ ## Getting Started
6
+
7
+ First you need to install the package.
8
+
9
+ `npm i erlc`
10
+
11
+ ### Setting Up
12
+
13
+ Setting up is super simple:
14
+
15
+ ```js
16
+ // index.js
17
+
18
+ const erlc = require("erlc");
19
+ const client = new erlc.Client({
20
+ globalToken: "", // Here you enter your global token provided for the API
21
+ });
22
+ client.config(); // Registers your client
23
+ ```
24
+
25
+ Now you can start using API Methods - here are a few examples:
26
+
27
+ ```js
28
+ // api.js
29
+
30
+ const erlc = require("erlc");
31
+
32
+ const getServerFunc = async () => {
33
+ const serverId = ""; // The server ApiKey you wish to target
34
+ const server = await erlc.getServer(serverId).catch(console.log); // Gets the server, logs any errors
35
+
36
+ console.log(server); // Logs the server object
37
+ };
38
+
39
+ getServerFunc();
40
+ ```
41
+
42
+ ### [PRC API Docs](https://apidocs.policeroleplay.community/reference/api-reference)
43
+
44
+ ### Credits
45
+
46
+ Library Re-Development - [Egologics](https://twitter.com/0Adexus0)
47
+ API Development - [Police Roleplay Community](https://twitter.com/PRC_Roblox)
package/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require("./src/erlc");
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "erlc-api",
3
+ "version": "1.3.0",
4
+ "description": "An ER:LC API wrapper for JS/TS",
5
+ "main": "index.js",
6
+ "types": "src/types/index.d.ts",
7
+ "keywords": [
8
+ "erlc",
9
+ "roblox",
10
+ "prc",
11
+ "erlc api"
12
+ ],
13
+ "author": "egologics",
14
+ "license": "MIT",
15
+ "devDependencies": {
16
+ "typescript": "^5.3.2"
17
+ },
18
+ "dependencies": {
19
+ "node-fetch": "^3.3.2"
20
+ },
21
+ "scripts": {
22
+ "test": "echo \"Error: no test specified\" && exit 1"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/Exodo0/ERLC-API.git"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/Exodo0/ERLC-API/issues"
30
+ },
31
+ "homepage": "https://github.com/Exodo0/ERLC-API#readme"
32
+ }
@@ -0,0 +1,38 @@
1
+ const erlc = require("../erlc.js");
2
+ const assert = require("../functions/assert.js");
3
+
4
+ /**
5
+ * @typedef {Object} ClientConfig
6
+ * @property {string} globalToken - Your ER:LC global API token
7
+ */
8
+
9
+ /**
10
+ * Creates an authorised ER:LC client for requests
11
+ * @class
12
+ * @param {ClientConfig} options - Client Options
13
+ */
14
+
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
+ }
27
+
28
+ /**
29
+ * Updates and returns the client configurationg
30
+ * @returns {ClientConfig} The client configuration.
31
+ */
32
+ config() {
33
+ erlc.config = this.options;
34
+ return erlc.config;
35
+ }
36
+ }
37
+
38
+ module.exports = Client;
@@ -0,0 +1,2 @@
1
+ exports.Vanity = "https://policeroleplay.community/join?code="
2
+ exports.BASEURL = "https://api.policeroleplay.community/v1"
package/src/erlc.js ADDED
@@ -0,0 +1,13 @@
1
+ exports.config = {}
2
+
3
+ exports.getBans = require('./functions/server/getBans.js')
4
+ exports.getCommandLogs = require('./functions/server/getCommandLogs.js')
5
+ exports.getJoinLogs = require('./functions/server/getJoinLogs.js')
6
+ exports.getKillLogs = require('./functions/server/getKillLogs.js')
7
+ exports.getModcallLogs = require('./functions/server/getModcallLogs.js')
8
+ exports.getPlayers = require('./functions/server/getPlayers.js')
9
+ exports.getServer = require('./functions/server/getServer.js')
10
+ exports.getQueue = require('./functions/server/getQueue.js')
11
+ exports.runCommand = require('./functions/server/runCommand.js')
12
+
13
+ exports.Client = require('./classes/client.js')
@@ -0,0 +1,5 @@
1
+ module.exports = function(condition, message) {
2
+ if (!condition) {
3
+ throw new Error(message);
4
+ }
5
+ }
@@ -0,0 +1,28 @@
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/bans`, {
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
+ };
@@ -0,0 +1,28 @@
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
+ };
@@ -0,0 +1,28 @@
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
+ };
@@ -0,0 +1,28 @@
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
+ };
@@ -0,0 +1,28 @@
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
+ };
@@ -0,0 +1,28 @@
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
+ };
@@ -0,0 +1,28 @@
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
+ };
@@ -0,0 +1,54 @@
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(
24
+ `https://users.roblox.com/v1/users/${userId}`
25
+ );
26
+ const userData = await response.json();
27
+ if (!response.ok) {
28
+ throw new Error(`Error fetching username for ID: ${userId}`);
29
+ }
30
+ return userData.name;
31
+ };
32
+ try {
33
+ const ownerUsername = await getUsername(data.OwnerId);
34
+ const coOwnerUsernames = await Promise.all(
35
+ data.CoOwnerIds.map(getUsername)
36
+ );
37
+ const VanityURL = `${Vanity}${data.JoinKey}`;
38
+
39
+ data.OwnerUsername = ownerUsername;
40
+ data.CoOwnerUsernames = coOwnerUsernames;
41
+ data.VanityURL = VanityURL;
42
+
43
+ delete data.OwnerId;
44
+ delete data.CoOwnerIds;
45
+
46
+ resolve(data);
47
+ } catch (error) {
48
+ reject(error);
49
+ }
50
+ } catch (error) {
51
+ reject(error);
52
+ }
53
+ });
54
+ };
@@ -0,0 +1,28 @@
1
+ const { BASEURL } = require("../../constants.js");
2
+
3
+ module.exports = (serverToken, command) => {
4
+ return new Promise(async (resolve, reject) => {
5
+ try {
6
+ const fetch = await import("node-fetch");
7
+ const { config } = await import("../../erlc.js");
8
+ const params = JSON.stringify({ command: `${command}` });
9
+ console.log(params);
10
+ const res = await fetch.default(`${BASEURL}/server/command`, {
11
+ headers: {
12
+ Authorization: config?.globalToken,
13
+ "Server-Key": serverToken,
14
+ "Content-Type": "application/json",
15
+ },
16
+ method: "POST",
17
+ body: params,
18
+ });
19
+ if (!res.ok) {
20
+ return reject(data);
21
+ }
22
+
23
+ resolve(true);
24
+ } catch (error) {
25
+ reject(error);
26
+ }
27
+ });
28
+ };
@@ -0,0 +1,5 @@
1
+ declare module 'NodeModule' {
2
+ interface NodeModule {
3
+ type?: string;
4
+ }
5
+ }
@@ -0,0 +1,74 @@
1
+ declare module 'erlc' {
2
+ export interface ClientConfig {
3
+ globalToken: string // The ER:LC global API token
4
+ }
5
+
6
+ export const BASEURL = "https://api.policeroleplay.community/v1"
7
+
8
+ type PlayerId = string
9
+ type PlayerName = string
10
+
11
+ export type ErlcPlayer = `${PlayerName}:${PlayerId}` // Playername:UserID
12
+ export type ErlcPlayerPermission = "Normal" | "Server Administrator" | "Server Owner" | "Server Moderator"
13
+
14
+ export interface ServerStatus {
15
+ Name: string; // The server name
16
+ OwnerId: number; // The roblox id of the server owner
17
+ CoOwnerIds: number[]; // The roblox ids of the server co owners
18
+ CurrentPlayers: number; // The amount of people currently in-game
19
+ MaxPlayers: number; // The amount of people who can join the server including server owner
20
+ JoinKey: string; // The code used to join the private server
21
+ AccVerifiedReq: "Disabled" | "Email" | "Phone/ID"; // The level of verification roblox accounts need to join the private server
22
+ TeamBalance: boolean; // If team balance is enabled or not
23
+ }
24
+
25
+ export interface ServerPlayer {
26
+ Player: ErlcPlayer;
27
+ Permission: ErlcPlayerPermission;
28
+ }
29
+
30
+ export interface JoinLog {
31
+ Join: boolean; // True is join and False is leave
32
+ Timestamp: number; // Timestamp in seconds
33
+ Player: ErlcPlayer;
34
+ }
35
+
36
+ export interface KillLog {
37
+ Killed: ErlcPlayer;
38
+ Timestamp: number; // Timestamp in seconds
39
+ Killer: ErlcPlayer;
40
+ }
41
+
42
+ export interface CommandLog {
43
+ Player: ErlcPlayer;
44
+ Timestamp: number; // Timestamp in seconds
45
+ Command: string;
46
+ }
47
+
48
+ export interface ModcallLog {
49
+ Caller: ErlcPlayer;
50
+ Moderator?: ErlcPlayer; // If call is unanswered property is undefined
51
+ Timestamp: number; // Timestamp in seconds
52
+ }
53
+
54
+ export type ServerBan = Record<PlayerId, PlayerName>;
55
+
56
+ export interface VSMCommandBody {
57
+ command : string; // ":h Hey everyone!"
58
+ }
59
+
60
+ export function getBans(serverToken: string): Promise<ServerBan>;
61
+ export function getCommandLogs(serverToken: string): Promise<CommandLog[]>;
62
+ export function getJoinLogs(serverToken: string): Promise<JoinLog[]>;
63
+ export function getKillLogs(serverToken: string): Promise<KillLog[]>;
64
+ export function getModcallLogs(serverToken: string): Promise<ModcallLog[]>;
65
+ export function getPlayers(serverToken: string): Promise<ServerPlayer[]>;
66
+ export function getQueue(serverToken: string): Promise<number[]>;
67
+ export function getServer(serverToken: string): Promise<ServerStatus>;
68
+ export function runCommand(serverToken: string, command: string): Promise<boolean>;
69
+
70
+ export class Client {
71
+ constructor(options: ClientConfig)
72
+ config(): ClientConfig;
73
+ }
74
+ }