From cacf1dc4cc12e54e329079e0a2ef55dae9a46e67 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Mon, 15 Apr 2024 10:32:53 -0400 Subject: [PATCH] oops, missed some files --- JS-SDK/src/index.d.ts | 6 ------ JS-SDK/src/index.ts | 6 ++++++ JS-SDK/src/lib/restfulmc.ts | 10 ++++++---- JS-SDK/src/lib/webRequest.ts | 4 ++-- JS-SDK/src/types/error.d.ts | 2 +- JS-SDK/src/types/generic.d.ts | 24 ------------------------ JS-SDK/test/player.test.ts | 6 +++--- JS-SDK/test/server.test.ts | 6 +++--- 8 files changed, 21 insertions(+), 43 deletions(-) delete mode 100644 JS-SDK/src/index.d.ts delete mode 100644 JS-SDK/src/types/generic.d.ts diff --git a/JS-SDK/src/index.d.ts b/JS-SDK/src/index.d.ts deleted file mode 100644 index 6be1fae..0000000 --- a/JS-SDK/src/index.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from "./types/generic"; -export * from "./types/mojang"; -export * from "./types/player"; -export * from "./types/server/bedrock-server"; -export * from "./types/server/java-server"; -export * from "./types/server/server"; diff --git a/JS-SDK/src/index.ts b/JS-SDK/src/index.ts index cd141a2..b51237e 100644 --- a/JS-SDK/src/index.ts +++ b/JS-SDK/src/index.ts @@ -1 +1,7 @@ export * from "@/lib/restfulmc"; +export * from "@/types/error"; +export * from "@/types/mojang"; +export * from "@/types/player"; +export * from "@/types/server/bedrock-server"; +export * from "@/types/server/java-server"; +export * from "@/types/server/server"; diff --git a/JS-SDK/src/lib/restfulmc.ts b/JS-SDK/src/lib/restfulmc.ts index c0c8a62..57d92c4 100644 --- a/JS-SDK/src/lib/restfulmc.ts +++ b/JS-SDK/src/lib/restfulmc.ts @@ -1,8 +1,8 @@ +import { WebRequest } from "@/lib/webRequest"; import { MojangServerStatus } from "@/types/mojang"; import { CachedPlayer, SkinPart } from "@/types/player"; import { CachedBedrockMinecraftServer } from "@/types/server/bedrock-server"; import { CachedJavaMinecraftServer } from "@/types/server/java-server"; -import { WebRequest } from "@/lib/webRequest"; import { ServerPlatform } from "@/types/server/server"; /** @@ -61,9 +61,11 @@ export const getMinecraftServer = ( * @returns the promised blocked status */ export const isMojangBlocked = (hostname: string): Promise => - new WebRequest(`/server/blocked/${hostname}`).execute<{ - blocked: boolean; - }>().then((res) => res.blocked); + new WebRequest(`/server/blocked/${hostname}`) + .execute<{ + blocked: boolean; + }>() + .then((res) => res.blocked); /** * Get the icon of the Java Minecraft diff --git a/JS-SDK/src/lib/webRequest.ts b/JS-SDK/src/lib/webRequest.ts index f6de026..02b64b4 100644 --- a/JS-SDK/src/lib/webRequest.ts +++ b/JS-SDK/src/lib/webRequest.ts @@ -1,4 +1,4 @@ -import { ErrorResponse } from "@/types/generic"; +import { RestfulMCAPIError } from "@/types/error"; const API_ENDPOINT = "https://mc.rainnny.club"; // The API endpoint to use @@ -36,7 +36,7 @@ export class WebRequest { if (response.ok) { resolve(json as T); } else { - reject(json as ErrorResponse); // The request failed + reject(json as RestfulMCAPIError); // The request failed } } else { // Fallback to an array buffer diff --git a/JS-SDK/src/types/error.d.ts b/JS-SDK/src/types/error.d.ts index a2a3e1b..b97fa69 100644 --- a/JS-SDK/src/types/error.d.ts +++ b/JS-SDK/src/types/error.d.ts @@ -21,4 +21,4 @@ export type RestfulMCAPIError = { * The timestamp this error occurred. */ timestamp: string; -} +}; diff --git a/JS-SDK/src/types/generic.d.ts b/JS-SDK/src/types/generic.d.ts deleted file mode 100644 index 25620b5..0000000 --- a/JS-SDK/src/types/generic.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * A response representing an error. - */ -export type ErrorResponse = { - /** - * The status of this error. - */ - status: string; - - /** - * The HTTP code of this error. - */ - code: number; - - /** - * The message of this error. - */ - message: string; - - /** - * The timestamp this error occurred. - */ - timestamp: string; -}; diff --git a/JS-SDK/test/player.test.ts b/JS-SDK/test/player.test.ts index 1624b43..ee42457 100644 --- a/JS-SDK/test/player.test.ts +++ b/JS-SDK/test/player.test.ts @@ -1,5 +1,5 @@ import { getPlayer, getSkinPart } from "@/index"; -import { ErrorResponse } from "@/types/generic"; +import { RestfulMCAPIError } from "@/types/error"; import { CachedPlayer, SkinPart } from "@/types/player"; import { expect, test } from "bun:test"; @@ -20,7 +20,7 @@ test("ensurePlayerNotFound", async () => { try { await getPlayer("SDFSDFSDFSDFDDDG"); // Fetch the unknown player } catch (err) { - expect((err as ErrorResponse).code).toBe(404); + expect((err as RestfulMCAPIError).code).toBe(404); } }); @@ -32,7 +32,7 @@ test("ensureUsernameIsInvalid", async () => { try { await getPlayer("A"); // Fetch the invalid player } catch (err) { - expect((err as ErrorResponse).code).toBe(400); + expect((err as RestfulMCAPIError).code).toBe(400); } }); diff --git a/JS-SDK/test/server.test.ts b/JS-SDK/test/server.test.ts index 6a76a82..125db25 100644 --- a/JS-SDK/test/server.test.ts +++ b/JS-SDK/test/server.test.ts @@ -3,7 +3,7 @@ import { getMinecraftServer, isMojangBlocked, } from "@/index"; -import { ErrorResponse } from "@/types/generic"; +import { RestfulMCAPIError } from "@/types/error"; import { CachedBedrockMinecraftServer } from "@/types/server/bedrock-server"; import { CachedJavaMinecraftServer } from "@/types/server/java-server"; import { ServerPlatform } from "@/types/server/server"; @@ -41,7 +41,7 @@ test("ensureUnknownHostname", async () => { try { await getMinecraftServer(ServerPlatform.JAVA, "invalid"); // Fetch the unknown server } catch (err) { - expect((err as ErrorResponse).code).toBe(400); + expect((err as RestfulMCAPIError).code).toBe(400); } }); @@ -53,7 +53,7 @@ test("ensureUnknownPort", async () => { try { await getMinecraftServer(ServerPlatform.JAVA, "hypixel.net:A"); // Fetch the invalid server } catch (err) { - expect((err as ErrorResponse).code).toBe(400); + expect((err as RestfulMCAPIError).code).toBe(400); } });