mcutils-js-api 1.0.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/README.md +15 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +18 -0
- package/dist/types/cache.d.ts +4 -0
- package/dist/types/cache.js +1 -0
- package/dist/types/response/error-response.d.ts +6 -0
- package/dist/types/response/error-response.js +1 -0
- package/dist/types/server/java-server.d.ts +19 -0
- package/dist/types/server/java-server.js +2 -0
- package/dist/types/server/server.d.ts +51 -0
- package/dist/types/server/server.js +2 -0
- package/package.json +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# mcutils-js-api
|
|
2
|
+
|
|
3
|
+
To install dependencies:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
bun install
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
To run:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bun run src/index.ts
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This project was created using `bun init` in bun v1.3.1. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ErrorResponse } from "./types/response/error-response";
|
|
2
|
+
import type { JavaServer } from "./types/server/java-server";
|
|
3
|
+
/**
|
|
4
|
+
* Fetch a Java Minecraft server.
|
|
5
|
+
*
|
|
6
|
+
* @param host the host to fetch the server using (eg: aetheria.cc)
|
|
7
|
+
* @returns the server or the error (if one occured)
|
|
8
|
+
*/
|
|
9
|
+
export declare function fetchJavaServer(host: string): Promise<{
|
|
10
|
+
server?: JavaServer;
|
|
11
|
+
error?: ErrorResponse;
|
|
12
|
+
}>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const API_BASE = "https://mc.fascinated.cc/api";
|
|
2
|
+
/**
|
|
3
|
+
* Fetch a Java Minecraft server.
|
|
4
|
+
*
|
|
5
|
+
* @param host the host to fetch the server using (eg: aetheria.cc)
|
|
6
|
+
* @returns the server or the error (if one occured)
|
|
7
|
+
*/
|
|
8
|
+
export async function fetchJavaServer(host) {
|
|
9
|
+
const response = await fetch(`${API_BASE}/server/java/${host}`);
|
|
10
|
+
if (response.ok) {
|
|
11
|
+
return {
|
|
12
|
+
server: (await response.json()),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
error: (await response.json()),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Server } from "./server";
|
|
2
|
+
export interface JavaServer extends Server {
|
|
3
|
+
version: ServerVersion;
|
|
4
|
+
favicon: ServerFavicon;
|
|
5
|
+
preventsChatReports: boolean;
|
|
6
|
+
enforcesSecureChat: boolean;
|
|
7
|
+
previewsChat: boolean;
|
|
8
|
+
mojangBlocked: boolean;
|
|
9
|
+
}
|
|
10
|
+
export type ServerVersion = {
|
|
11
|
+
name: string;
|
|
12
|
+
platform: string;
|
|
13
|
+
protocol: number;
|
|
14
|
+
protocolName: string;
|
|
15
|
+
};
|
|
16
|
+
export type ServerFavicon = {
|
|
17
|
+
base64: string;
|
|
18
|
+
url: string;
|
|
19
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Cache } from "../cache";
|
|
2
|
+
export interface Server extends Cache {
|
|
3
|
+
hostname: string;
|
|
4
|
+
ip: string;
|
|
5
|
+
port: number;
|
|
6
|
+
motd: ServerMotd;
|
|
7
|
+
players: ServerPlayers;
|
|
8
|
+
records: Array<DnsRecord>;
|
|
9
|
+
version: ServerVersion;
|
|
10
|
+
favicon: ServerFavicon;
|
|
11
|
+
preventsChatReports: boolean;
|
|
12
|
+
enforcesSecureChat: boolean;
|
|
13
|
+
previewsChat: boolean;
|
|
14
|
+
location: ServerLocation;
|
|
15
|
+
asn: AsnData;
|
|
16
|
+
mojangBlocked: boolean;
|
|
17
|
+
}
|
|
18
|
+
export type ServerMotd = {
|
|
19
|
+
raw: string[];
|
|
20
|
+
clean: string[];
|
|
21
|
+
html: string[];
|
|
22
|
+
};
|
|
23
|
+
export type ServerPlayers = {
|
|
24
|
+
online: number;
|
|
25
|
+
max: number;
|
|
26
|
+
};
|
|
27
|
+
export type DnsRecord = {
|
|
28
|
+
type: string;
|
|
29
|
+
ttl: number;
|
|
30
|
+
address: string;
|
|
31
|
+
};
|
|
32
|
+
export type ServerVersion = {
|
|
33
|
+
name: string;
|
|
34
|
+
platform: string;
|
|
35
|
+
protocol: number;
|
|
36
|
+
protocolName: string;
|
|
37
|
+
};
|
|
38
|
+
export type ServerFavicon = {
|
|
39
|
+
base64: string;
|
|
40
|
+
url: string;
|
|
41
|
+
};
|
|
42
|
+
export type ServerLocation = {
|
|
43
|
+
country: string;
|
|
44
|
+
region: string;
|
|
45
|
+
latitude: number;
|
|
46
|
+
longitude: number;
|
|
47
|
+
};
|
|
48
|
+
export type AsnData = {
|
|
49
|
+
asn: string;
|
|
50
|
+
asnOrg: string;
|
|
51
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcutils-js-api",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"module": "dist/index.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"prepublishOnly": "bun run build"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/bun": "latest",
|
|
17
|
+
"typescript": "^5"
|
|
18
|
+
}
|
|
19
|
+
}
|