Update Player type

This commit is contained in:
Braydon 2024-04-14 14:35:55 -04:00
parent 1968f835fd
commit abccde5896
4 changed files with 110 additions and 6 deletions

@ -1,6 +1,6 @@
{ {
"name": "restfulmc", "name": "restfulmc",
"version": "1.0.4", "version": "1.0.8",
"author": "Braydon (Rainnny) <braydonrainnny@gmail.com>", "author": "Braydon (Rainnny) <braydonrainnny@gmail.com>",
"description": "A simple, yet useful RESTful API for Minecraft utilizing Springboot.", "description": "A simple, yet useful RESTful API for Minecraft utilizing Springboot.",
"keywords": [ "keywords": [

@ -1,3 +1,4 @@
import { ErrorResponse } from "../types/generic";
import type { Player } from "../types/player"; import type { Player } from "../types/player";
const ENDPOINT = "https://mc.rainnny.club"; // The API endpoint to use const ENDPOINT = "https://mc.rainnny.club"; // The API endpoint to use
@ -11,6 +12,13 @@ const ENDPOINT = "https://mc.rainnny.club"; // The API endpoint to use
export const getPlayer = (query: string): Promise<Player> => { export const getPlayer = (query: string): Promise<Player> => {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
const response: Response = await fetch(`${ENDPOINT}/player/${query}`); // Request the player const response: Response = await fetch(`${ENDPOINT}/player/${query}`); // Request the player
resolve((await response.json()) as Player); // Resolve the player const json: any = await response.json();
// Resolve the player
if (response.ok) {
resolve(json as Player);
} else {
reject(json as ErrorResponse); // The request failed
}
}); });
}; };

24
Lib/src/types/generic.d.ts vendored Normal file

@ -0,0 +1,24 @@
/**
* 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;
};

@ -13,7 +13,32 @@ export type Player = {
* The skin of this player. * The skin of this player.
*/ */
skin: Skin; skin: Skin;
}
/**
* The cape of this player, undefined if none.
*/
cape?: Cape | undefined;
/**
* The properties of the Mojang
* profile for this player.
*/
properties: ProfileProperty[];
/**
* The profile actions this player has, undefined if none.
*/
profileActions?: ProfileAction[] | undefined;
/**
* Is this player legacy?
* <p>
* A "Legacy" player is a player that
* has not yet migrated to a Mojang account.
* </p>
*/
legacy: boolean;
};
/** /**
* A skin for a {@link Player}. * A skin for a {@link Player}.
@ -27,15 +52,62 @@ type Skin = {
/** /**
* The model of this skin. * The model of this skin.
*/ */
model: Model; model: SkinModel;
/** /**
* Is this skin legacy? * Is this skin legacy?
*/ */
legacy: boolean; legacy: boolean;
}
/**
* URLs to the parts of this skin.
* <p>
* The key is the part name, and
* the value is the URL.
* </p>
*/
parts: {
[key: string]: string;
};
};
/** /**
* Possible models for a skin. * Possible models for a skin.
*/ */
type Model = "default" | "slim"; type SkinModel = "default" | "slim";
/**
* A cape for a {@link Player}.
*/
type Cape = {
/**
* The texture URL of this cape.
*/
url: string;
};
/**
* A property of a Mojang profile.
*/
type ProfileProperty = {
/**
* The name of this property.
*/
name: string;
/**
* The Base64 value of this property.
*/
value: string;
/**
* The Base64 signature of this
* property, undefined if not signed.
*/
signature?: string | undefined;
};
/**
* Profile actions that can
*/
type ProfileAction = "FORCED_NAME_CHANGE" | "USING_BANNED_SKIN";