realmsplus-api 1.0.0 → 1.0.3
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 +9 -7
- package/index.js +5 -2
- package/package.json +2 -14
- package/src/api.js +14 -39
- package/src/libs/Rest.js +47 -0
- package/tests/main.js +13 -0
package/README.md
CHANGED
|
@@ -32,13 +32,15 @@ import { RealmsPlusAPI } from "realmsplus-api";
|
|
|
32
32
|
|
|
33
33
|
const client = new RealmsPlusAPI("your-api-key");
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
(async () => {
|
|
36
|
+
// Check service health
|
|
37
|
+
const health = await client.getHealth();
|
|
38
|
+
console.log(health);
|
|
39
|
+
|
|
40
|
+
// Query the hacker database
|
|
41
|
+
const result = await client.getHackerDB("all");
|
|
42
|
+
console.log(result);
|
|
43
|
+
})();
|
|
42
44
|
```
|
|
43
45
|
|
|
44
46
|
See more [examples](./examples)
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "realmsplus-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Official SDK for the Realms+ API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./index.d.ts",
|
|
11
|
-
"import": "./index.js"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"index.js",
|
|
16
|
-
"index.d.ts",
|
|
17
|
-
"src/"
|
|
18
|
-
],
|
|
19
7
|
"engines": {
|
|
20
8
|
"node": ">=22.0.0"
|
|
21
9
|
},
|
|
@@ -40,4 +28,4 @@
|
|
|
40
28
|
"url": "https://github.com/All-Realms-Are-Safe/realmsplus-api/issues"
|
|
41
29
|
},
|
|
42
30
|
"homepage": "https://github.com/All-Realms-Are-Safe/realmsplus-api#readme"
|
|
43
|
-
}
|
|
31
|
+
}
|
package/src/api.js
CHANGED
|
@@ -1,49 +1,22 @@
|
|
|
1
|
+
const Rest = require("./libs/Rest");
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Represents the public routes of the Realms+ API
|
|
3
5
|
*/
|
|
4
|
-
|
|
6
|
+
class RealmsPlusAPI extends Rest {
|
|
5
7
|
/**
|
|
6
8
|
*
|
|
7
9
|
* @param {string} apiKey - your private api key
|
|
8
10
|
*/
|
|
9
11
|
constructor(apiKey) {
|
|
10
|
-
|
|
11
|
-
this.baseUrl = "https://api.realmsplus.com/v1";
|
|
12
|
-
this.headers = {
|
|
13
|
-
"api-key": this.apiKey,
|
|
14
|
-
"Content-Type": "application/json"
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
async #request(method, url, body) {
|
|
19
|
-
try {
|
|
20
|
-
const data = {
|
|
21
|
-
method: method,
|
|
22
|
-
headers: this.headers
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
method !== "GET" &&
|
|
27
|
-
method !== "DELETE" &&
|
|
28
|
-
body
|
|
29
|
-
) {
|
|
30
|
-
data.body = JSON.stringify(body);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const res = await fetch(`${this.baseUrl}${url}`, data);
|
|
34
|
-
console.log(res.status);
|
|
35
|
-
const parsed = await res.json();
|
|
36
|
-
return parsed;
|
|
37
|
-
} catch (error) {
|
|
38
|
-
throw new Error(error);
|
|
39
|
-
};
|
|
12
|
+
super("https://api.realmsplus.com/v1", { "api-key": apiKey, "Content-Type": "application/json" });
|
|
40
13
|
};
|
|
41
14
|
|
|
42
15
|
/**
|
|
43
16
|
* Gets the service health
|
|
44
17
|
*/
|
|
45
18
|
async getHealth() {
|
|
46
|
-
return await this
|
|
19
|
+
return await this.get("/health");
|
|
47
20
|
};
|
|
48
21
|
|
|
49
22
|
/**
|
|
@@ -51,7 +24,7 @@ export class RealmsPlusAPI {
|
|
|
51
24
|
* @param {string} id - the unique id to search for. Allowed types: `all`, `<discord-id>`, `<fingerprint-id>`
|
|
52
25
|
*/
|
|
53
26
|
async getDiscordDB(id) {
|
|
54
|
-
return await this
|
|
27
|
+
return await this.get(`/database/discordDB/${id}`);
|
|
55
28
|
};
|
|
56
29
|
|
|
57
30
|
/**
|
|
@@ -59,21 +32,23 @@ export class RealmsPlusAPI {
|
|
|
59
32
|
* @param {string} id - the unique id to search for. Allowed types: `all`, `<xuid-id>`, `<discord-id>`, `<fingerprint-id>`
|
|
60
33
|
*/
|
|
61
34
|
async getHackerDB(id) {
|
|
62
|
-
return await this
|
|
35
|
+
return await this.get(`/database/hackerDB/${id}`);
|
|
63
36
|
};
|
|
64
37
|
|
|
65
38
|
/**
|
|
66
|
-
*
|
|
67
|
-
* @param {
|
|
39
|
+
* Report a user to the ARAS team. username value can be a gamertag or discord tag
|
|
40
|
+
* @param {"discordDB" | "hackerDB"} category - the category of the report. Allowed types: `discordDB`, `hackerDB`
|
|
68
41
|
* @param {{
|
|
69
42
|
* username: string,
|
|
70
43
|
* xuid: string | null,
|
|
71
44
|
* discordName: string | null,
|
|
72
45
|
* discordId: string | null,
|
|
73
46
|
* reason: string
|
|
74
|
-
* }} data - the data for the report.
|
|
47
|
+
* }} data - the data for the report.
|
|
75
48
|
*/
|
|
76
49
|
async reportUser(category, data) {
|
|
77
|
-
return await this
|
|
50
|
+
return await this.post(`/database/report/${category}`, data);
|
|
78
51
|
};
|
|
79
|
-
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
module.exports = RealmsPlusAPI;
|
package/src/libs/Rest.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
class Rest {
|
|
2
|
+
constructor(baseUrl, headers) {
|
|
3
|
+
this.base = baseUrl;
|
|
4
|
+
this.headers = headers
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {Response} res
|
|
9
|
+
*/
|
|
10
|
+
async #parse(res) {
|
|
11
|
+
let data = null;
|
|
12
|
+
try {
|
|
13
|
+
data = await res.json();
|
|
14
|
+
} catch { }
|
|
15
|
+
|
|
16
|
+
const final = {
|
|
17
|
+
status: res.status,
|
|
18
|
+
ok: res.ok,
|
|
19
|
+
data
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
if (!res.ok) final.headers = Object.fromEntries(res.headers);
|
|
23
|
+
return final;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
async get(url) {
|
|
27
|
+
const res = await fetch(`${this.base}${url}`, { headers: this.headers });
|
|
28
|
+
return await this.#parse(res);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
async post(url, data) {
|
|
32
|
+
const res = await fetch(`${this.base}${url}`, { method: "POST", headers: this.headers, body: JSON.stringify(data) });
|
|
33
|
+
return await this.#parse(res);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
async put(url, data) {
|
|
37
|
+
const res = await fetch(`${this.base}${url}`, { method: "PUT", headers: this.headers, body: JSON.stringify(data) });
|
|
38
|
+
return await this.#parse(res);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
async delete(url) {
|
|
42
|
+
const res = await fetch(`${this.base}${url}`, { method: "DELETE", headers: this.headers });
|
|
43
|
+
return await this.#parse(res);
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
module.exports = Rest;
|
package/tests/main.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { RealmsPlusAPI } = require("../index");
|
|
2
|
+
|
|
3
|
+
const client = new RealmsPlusAPI("guhcat_is_cool");
|
|
4
|
+
(async () => {
|
|
5
|
+
const health = await client.getHealth();
|
|
6
|
+
console.log(health);
|
|
7
|
+
|
|
8
|
+
const hackers = await client.getHackerDB("all");
|
|
9
|
+
console.log(hackers);
|
|
10
|
+
|
|
11
|
+
const discord = await client.getDiscordDB("all");
|
|
12
|
+
console.log(discord);
|
|
13
|
+
})();
|