Skip to content

Commit bd54325

Browse files
add server registry endpoint
1 parent 62061e6 commit bd54325

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mcutils-js-api",
3-
"version": "2.0.25",
3+
"version": "2.0.26",
44
"module": "dist/index.js",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { CachedPlayer } from "./types/cache/cached-player";
77
import type { CachedPlayerName } from "./types/cache/cached-player-name";
88
import type { ServerPlatform } from "./types/server/server";
99
import type { Cape } from "./types/player/cape/cape";
10+
import { ServerRegistryEntry } from "./types/server-registry/server-registry-entry";
1011

1112
export class McUtilsAPI {
1213
private readonly endpoint: string;
@@ -310,6 +311,22 @@ export class McUtilsAPI {
310311
error: (await response.json()) as ErrorResponse,
311312
};
312313
}
314+
315+
/**
316+
* Fetch the list of available server registry entries.
317+
*
318+
* @param query the query to search for (eg: aetheria)
319+
* @returns the list of server registry entries or the error (if one occurred)
320+
*/
321+
async fetchServerRegistryEntries(query: string): Promise<{ entries?: ServerRegistryEntry[]; error?: ErrorResponse }> {
322+
const response = await fetch(`${this.endpoint}/servers${this.buildParams({ query: query })}`);
323+
if (response.ok) {
324+
return { entries: (await response.json()) as ServerRegistryEntry[] };
325+
}
326+
return {
327+
error: (await response.json()) as ErrorResponse,
328+
};
329+
}
313330
}
314331

315332
export default McUtilsAPI;

src/test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import McUtilsAPI from ".";
22

33
const api = new McUtilsAPI();
44

5-
api.fetchJavaServer("aetheria.cc").then((result) => {
5+
api.fetchServerRegistryEntries("wild").then((result) => {
66
console.log(result);
7-
});
8-
api.fetchPlayer("ImFascinated").then((result) => {
9-
console.log(result.player?.skin?.parts.FULLBODY_FRONT);
107
});

0 commit comments

Comments
 (0)