mowojang 0.2.2 → 0.3.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 CHANGED
@@ -1,11 +1,11 @@
1
- # Mowojang-API NPM Wrapper
1
+ # mowojang-js
2
2
 
3
3
  ![NPM Version](https://img.shields.io/npm/v/mowojang?label=NPM)
4
- ![NPM Downloads](https://img.shields.io/npm/dw/mowojang?label=Downloads)
4
+ ![NPM Downloads](https://img.shields.io/npm/dm/mowojang?label=Downloads)
5
5
  ![NPM License](https://img.shields.io/npm/l/mowojang?label=License)
6
6
 
7
7
  > [!IMPORTANT]
8
- > This is not an official Wrapper for the [Mowojang-API](https://mowojang.matdoes.dev/)!
8
+ > This is a third party wrapper for the [Mowojang-API](https://mowojang.matdoes.dev/)!
9
9
 
10
10
  ## ✨ Quick Start
11
11
 
@@ -19,7 +19,7 @@ const username = await Mowojang.getUsername("14727fae-fbdc-4aff-848c-d2713eb9939
19
19
  ```
20
20
 
21
21
  > [!TIP]
22
- > If you plan on using this in a long-running process with frequent usage check out this guide on how to setup custom caching to prevent memory leaks.
22
+ > If you plan on using this in a long-running process with heavy usage check out this guide on how to setup custom caching to prevent memory leaks.
23
23
  > Guide: [Custom-Caching](docs/custom-caching.md)
24
24
 
25
25
  ## 🔧 Functions / Supported Endpoints
@@ -28,12 +28,12 @@ const username = await Mowojang.getUsername("14727fae-fbdc-4aff-848c-d2713eb9939
28
28
  - `getProfile()`: Retrieve full Player Data by UUID or Username
29
29
  - `getSessions()`: Retrieve Player Session Data of multiple Players by UUID or Username
30
30
  - `getSession()`: Retrieve Player Session Data by UUID or Username
31
- - `getUUID()`: Converts Username to UUID
32
- - `getUsername()`: Converts UUID to Username
31
+ - `getUUID()`: Converts a Player's Username to UUID
32
+ - `getUsername()`: Converts a Player's UUID to Username
33
33
  - `getSkin()`: Returns the Skin the specified Player is currently wearing
34
- - `getSkinBuffer()`: Skin-Data fetched via getSkin() as a Buffer
35
- - `getCape()`: Returns the Cape the specified Player is currently wearing
36
- - `getCapeBuffer()`: Cape-Data fetched via getCape() as a Buffer
34
+ - `getSkinBuffer()`: Returns Skin Image fetched via getSkin() as a Buffer
35
+ - `getCape()`: Returns the Cape the specified Player has currently selected
36
+ - `getCapeBuffer()`: Returns Cape Image fetched via getCape() as a Buffer
37
37
 
38
38
  All above Functions accept an second Argument containing an optional config.
39
39
  Cache options can also be passed there via the cache key. All available cache options can be found [here](https://axios-cache-interceptor.js.org/config/request-specifics#cache).
package/dist/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mowojang",
3
- "version": "0.2.2",
4
- "description": "A simple JavaScript and TypeScript compatible API Wrapper for the Mowojang-API.",
3
+ "version": "0.3.0",
4
+ "description": "A simple JavaScript and TypeScript compatible wrapper for the Mowojang-API.",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
7
7
  "type": "module",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "https://github.com/pixelicc/mowojang-api-wrapper.git"
16
+ "url": "https://github.com/pixelicc/mowojang-js.git"
17
17
  },
18
18
  "keywords": [
19
19
  "Minecraft",
@@ -3,54 +3,54 @@ export default class Client {
3
3
  private axios;
4
4
  constructor(clientOptions?: ClientOptions);
5
5
  /**
6
- * Returns an Array of Player Profiles
6
+ * Returns an Array of Player Profiles consisting of their Usernames and UUIDs
7
7
  *
8
8
  * Players considered "INVALID" are excluded from the results
9
9
  */
10
10
  getProfiles(players: Player[], config?: MowojangRequestConfig): MowojangResponse<MowojangProfile[], undefined>;
11
11
  /**
12
- * Returns a Player Profile
12
+ * Returns a Player's Profile consisting of their Username and UUID
13
13
  *
14
14
  */
15
15
  getProfile(player: Player, config?: MowojangRequestConfig): MowojangResponse<MowojangProfile, "INVALID_PLAYER">;
16
16
  /**
17
- * Simple Wrapper to only retrieve the UUID from the Player's Profile Data
17
+ * A Simple Wrapper to Retrieve Only the UUID of a Player's Profile
18
18
  *
19
19
  */
20
20
  getUUID(username: Username, config?: MowojangRequestConfig): Promise<null | Username>;
21
21
  /**
22
- * Simple Wrapper to only retrieve the Username from the Player's Profile Data
22
+ * A Simple Wrapper to Retrieve Only the Username of a Player's Profile
23
23
  *
24
24
  */
25
25
  getUsername(UUID: UUID, config?: MowojangRequestConfig): Promise<null | UUID>;
26
26
  /**
27
- * Returns an Array of Player Sessions
27
+ * Returns an Array of Player Sessions consisting of their Usernames, UUIDs, Skins and Capes
28
28
  *
29
29
  * Players considered "INVALID" are excluded from the results
30
30
  */
31
31
  getSessions(players: Player[], config?: MowojangRequestConfig): MowojangResponse<MowojangSession[], "INVALID_PLAYER">;
32
32
  /**
33
- * Returns a Player Session
33
+ * Returns a Player's Sessions consisting of their Username, UUID, Skin and Cape
34
34
  *
35
35
  */
36
36
  getSession(player: Player, config?: MowojangRequestConfig): MowojangResponse<MowojangSession, "INVALID_PLAYER">;
37
37
  /**
38
- * Simple Wrapper to only retrieve the Skin Data from the Player's Session Data
38
+ * A Simple Wrapper to Retrieve Only the Skin from a Player's Session
39
39
  *
40
40
  */
41
41
  getSkin(player: Player, config?: MowojangRequestConfig): Promise<null | MowojangSkin>;
42
42
  /**
43
- * Simple Wrapper to only retrieve the Player's Skin from the Player's Session Data loaded into a Buffer
43
+ * A Simple Wrapper to Retrieve Only the Player's Skin from their Session Data Loaded into a Buffer
44
44
  *
45
45
  */
46
46
  getSkinBuffer(player: Player, config?: MowojangRequestConfig): Promise<null | Buffer>;
47
47
  /**
48
- * Simple Wrapper to only retrieve the Cape Data from the Player's Session Data
48
+ * A Simple Wrapper to Retrieve Only the Cape Data from a Player's Session
49
49
  *
50
50
  */
51
51
  getCape(player: Player, config?: MowojangRequestConfig): Promise<null | MowojangCape>;
52
52
  /**
53
- * Simple Wrapper to only retrieve the Player's Cape from the Player's Session Data loaded into a Buffer
53
+ * A Simple Wrapper to Retrieve Only the Player's Cape from their Session Data Loaded into a Buffer
54
54
  *
55
55
  */
56
56
  getCapeBuffer(player: Player, config?: MowojangRequestConfig): Promise<null | Buffer>;
@@ -8,7 +8,7 @@ export default class Client {
8
8
  this.axios = axiosInstance(clientOptions);
9
9
  }
10
10
  /**
11
- * Returns an Array of Player Profiles
11
+ * Returns an Array of Player Profiles consisting of their Usernames and UUIDs
12
12
  *
13
13
  * Players considered "INVALID" are excluded from the results
14
14
  */
@@ -41,7 +41,7 @@ export default class Client {
41
41
  }
42
42
  }
43
43
  /**
44
- * Returns a Player Profile
44
+ * Returns a Player's Profile consisting of their Username and UUID
45
45
  *
46
46
  */
47
47
  async getProfile(player, config) {
@@ -55,7 +55,7 @@ export default class Client {
55
55
  return { data: profiles.data[0], error: null };
56
56
  }
57
57
  /**
58
- * Simple Wrapper to only retrieve the UUID from the Player's Profile Data
58
+ * A Simple Wrapper to Retrieve Only the UUID of a Player's Profile
59
59
  *
60
60
  */
61
61
  async getUUID(username, config) {
@@ -67,7 +67,7 @@ export default class Client {
67
67
  return profile.data.UUID;
68
68
  }
69
69
  /**
70
- * Simple Wrapper to only retrieve the Username from the Player's Profile Data
70
+ * A Simple Wrapper to Retrieve Only the Username of a Player's Profile
71
71
  *
72
72
  */
73
73
  async getUsername(UUID, config) {
@@ -79,7 +79,7 @@ export default class Client {
79
79
  return profile.data.username;
80
80
  }
81
81
  /**
82
- * Returns an Array of Player Sessions
82
+ * Returns an Array of Player Sessions consisting of their Usernames, UUIDs, Skins and Capes
83
83
  *
84
84
  * Players considered "INVALID" are excluded from the results
85
85
  */
@@ -110,7 +110,7 @@ export default class Client {
110
110
  }
111
111
  }
112
112
  /**
113
- * Returns a Player Session
113
+ * Returns a Player's Sessions consisting of their Username, UUID, Skin and Cape
114
114
  *
115
115
  */
116
116
  async getSession(player, config) {
@@ -164,7 +164,7 @@ export default class Client {
164
164
  });
165
165
  }
166
166
  /**
167
- * Simple Wrapper to only retrieve the Skin Data from the Player's Session Data
167
+ * A Simple Wrapper to Retrieve Only the Skin from a Player's Session
168
168
  *
169
169
  */
170
170
  async getSkin(player, config) {
@@ -174,7 +174,7 @@ export default class Client {
174
174
  return session.data.skin;
175
175
  }
176
176
  /**
177
- * Simple Wrapper to only retrieve the Player's Skin from the Player's Session Data loaded into a Buffer
177
+ * A Simple Wrapper to Retrieve Only the Player's Skin from their Session Data Loaded into a Buffer
178
178
  *
179
179
  */
180
180
  async getSkinBuffer(player, config) {
@@ -188,7 +188,7 @@ export default class Client {
188
188
  return Buffer.from(fetchResponse.data, "base64");
189
189
  }
190
190
  /**
191
- * Simple Wrapper to only retrieve the Cape Data from the Player's Session Data
191
+ * A Simple Wrapper to Retrieve Only the Cape Data from a Player's Session
192
192
  *
193
193
  */
194
194
  async getCape(player, config) {
@@ -198,7 +198,7 @@ export default class Client {
198
198
  return session.data.cape;
199
199
  }
200
200
  /**
201
- * Simple Wrapper to only retrieve the Player's Cape from the Player's Session Data loaded into a Buffer
201
+ * A Simple Wrapper to Retrieve Only the Player's Cape from their Session Data Loaded into a Buffer
202
202
  *
203
203
  */
204
204
  async getCapeBuffer(player, config) {
@@ -7,8 +7,8 @@ export declare const validate: {
7
7
  username: (username: string) => boolean;
8
8
  };
9
9
  export declare const utils: {
10
- dashUUID: (UUID: string) => import("../types/player.js").UUID;
11
- undashUUID: (UUID: string) => import("../types/player.js").UUID;
10
+ dashUUID: (UUID: import("../types/player.js").UUID) => import("../types/player.js").UUID;
11
+ undashUUID: (UUID: import("../types/player.js").UUID) => import("../types/player.js").UUID;
12
12
  };
13
13
  export declare const cache: {
14
14
  buildStorage: typeof buildStorage;
@@ -1,3 +1,11 @@
1
1
  import { UUID } from "../types/index.js";
2
- export declare const undashUUID: (UUID: string) => UUID;
3
- export declare const dashUUID: (UUID: string) => UUID;
2
+ /**
3
+ * Removes dashes from a UUID string
4
+ *
5
+ */
6
+ export declare const undashUUID: (UUID: UUID) => UUID;
7
+ /**
8
+ * Adds dashes to a UUID string if not already dashed
9
+ *
10
+ */
11
+ export declare const dashUUID: (UUID: UUID) => UUID;
package/dist/src/utils.js CHANGED
@@ -1,2 +1,10 @@
1
+ /**
2
+ * Removes dashes from a UUID string
3
+ *
4
+ */
1
5
  export const undashUUID = (UUID) => UUID.replace(/-/g, "").toLowerCase();
6
+ /**
7
+ * Adds dashes to a UUID string if not already dashed
8
+ *
9
+ */
2
10
  export const dashUUID = (UUID) => undashUUID(UUID).replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5");
@@ -1,5 +1,16 @@
1
1
  import { Player } from "../types/index.js";
2
+ /**
3
+ * Validates a UUIDv4 string
4
+ *
5
+ */
2
6
  export declare const validateUUID: (UUID: string) => boolean;
7
+ /**
8
+ * Validates a Minecraft Username
9
+ */
3
10
  export declare const validateUsername: (username: string) => boolean;
11
+ /**
12
+ * Validates a Minecraft Player by either validating their Username or supplied UUID
13
+ *
14
+ */
4
15
  export declare const validatePlayer: (player: Player) => boolean;
5
16
  export declare const validateArray: <T>(array: T[], validatorFunction: (item: T, ...params: any[]) => boolean, ...params: any[]) => boolean;
@@ -1,4 +1,8 @@
1
1
  import { undashUUID } from "./utils.js";
2
+ /**
3
+ * Validates a UUIDv4 string
4
+ *
5
+ */
2
6
  export const validateUUID = (UUID) => {
3
7
  if (typeof UUID !== "string")
4
8
  return false;
@@ -7,11 +11,18 @@ export const validateUUID = (UUID) => {
7
11
  return false;
8
12
  return /[0-9a-f]{12}4[0-9a-f]{19}/.test(UUID);
9
13
  };
14
+ /**
15
+ * Validates a Minecraft Username
16
+ */
10
17
  export const validateUsername = (username) => {
11
18
  if (typeof username !== "string")
12
19
  return false;
13
20
  return /^[a-zA-Z0-9_]{1,16}$/.test(username);
14
21
  };
22
+ /**
23
+ * Validates a Minecraft Player by either validating their Username or supplied UUID
24
+ *
25
+ */
15
26
  export const validatePlayer = (player) => validateUUID(player) || validateUsername(player);
16
27
  export const validateArray = (array, validatorFunction, ...params) => {
17
28
  if (!Array.isArray(array))
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "mowojang",
3
- "version": "0.2.2",
4
- "description": "A simple JavaScript and TypeScript compatible API Wrapper for the Mowojang-API.",
3
+ "version": "0.3.0",
4
+ "description": "A simple JavaScript and TypeScript compatible wrapper for the Mowojang-API.",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
7
7
  "type": "module",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/pixelicc/mowojang-api-wrapper.git"
10
+ "url": "https://github.com/pixelicc/mowojang-js.git"
11
11
  },
12
12
  "keywords": [
13
13
  "Minecraft",
package/.prettierignore DELETED
@@ -1,5 +0,0 @@
1
- node_modules
2
- dist
3
- pnpm-lock.yaml
4
- package.json
5
- tsconfig.json
package/.prettierrc DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "printWidth": 120,
3
- "tabWidth": 2,
4
- "semi": true,
5
- "singleQuote": false,
6
- "trailingComma": "all"
7
- }
@@ -1,6 +0,0 @@
1
- {
2
- "editor.defaultFormatter": "esbenp.prettier-vscode",
3
- "editor.tabSize": 2,
4
- "editor.formatOnSave": true,
5
- "typescript.tsdk": "node_modules/typescript/lib"
6
- }
@@ -1,44 +0,0 @@
1
- # 💾 Custom Caching / Storage
2
-
3
- As the `Mowojang` library just uses the `axios-cache-interceptor` library internally you can also follow their docs on the two exported builders accessable via the cache export: `buildMemoryStorage()` and `buildStorage()`
4
-
5
- Docs: https://axios-cache-interceptor.js.org/guide/storages
6
-
7
- ## Custom Memory Storage
8
-
9
- ```TS
10
- import { Client, cache } from "mowojang"
11
-
12
- const Mowojang = new Client({
13
- cache: {
14
- storage: cache.buildMemoryStorage(
15
- false, // Doesn't clone data
16
- 60 * 60 * 1000, // Cleans cache-leftovers every hour
17
- false // Doesn't set a max entry limit
18
- /**
19
- * More detailed documentation:
20
- *
21
- * https://axios-cache-interceptor.js.org/guide/storages#memory-storage
22
- */
23
- )
24
- }
25
- })
26
- ```
27
-
28
- ## Custom Storage
29
-
30
- ```TS
31
- import { Client, cache } from "mowojang"
32
-
33
- const Mowojang = new Client({
34
- cache: {
35
- storage: cache.buildStorage({
36
- /**
37
- * More detailed documentation:
38
- *
39
- * https://axios-cache-interceptor.js.org/guide/storages#buildstorage
40
- */
41
- })
42
- }
43
- })
44
- ```
package/types/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./misc.js";
2
- export * from "./player.js";
3
- export * from "./structures.js";
package/types/misc.d.ts DELETED
@@ -1,28 +0,0 @@
1
- import { CacheOptions, CacheRequestConfig } from "axios-cache-interceptor";
2
-
3
- export type ClientOptions = {
4
- timeout?: number;
5
- cache?: CacheOptions;
6
- };
7
-
8
- export type AxiosOptions = {
9
- timeout?: number;
10
- cache?: CacheOptions;
11
- };
12
-
13
- export type MowojangRequestConfig = {
14
- cache?: CacheRequestConfig<any, any>["cache"];
15
- };
16
-
17
- export type MowojangError = "INVALID_PLAYER";
18
-
19
- export type MowojangResponse<D, E extends MowojangError | undefined> = Promise<
20
- | {
21
- data: D;
22
- error: null;
23
- }
24
- | {
25
- data: null;
26
- error: E extends undefined ? "UNKOWN_ERROR" | "INVALID_INPUT" : E | "UNKOWN_ERROR" | "INVALID_INPUT";
27
- }
28
- >;
package/types/player.d.ts DELETED
@@ -1,20 +0,0 @@
1
- /**
2
- * Minecraft Username or UUIDv4 (both undashed and dashed will be accepted)
3
- *
4
- * @example "Technoblade" or "b876ec32-e396-476b-a115-8438d83c67d4"
5
- */
6
- export type Player = string | UUID;
7
-
8
- /**
9
- * Minecraft Username
10
- *
11
- * @example "Pixelic"
12
- */
13
- export type Username = string;
14
-
15
- /**
16
- * Minecraft UUIDv4 (both undashed and dashed will be accepted)
17
- *
18
- * @example b876ec32e396476ba1158438d83c67d4
19
- */
20
- export type UUID = string;
@@ -1,27 +0,0 @@
1
- import { UUID, Username } from "./index.js";
2
-
3
- export type MowojangProfile = {
4
- UUID: UUID;
5
- username: Username;
6
- };
7
-
8
- export type MowojangSession = {
9
- UUID: UUID;
10
- username: Username;
11
- skin: MowojangSkin;
12
- cape: MowojangCape;
13
- actions: ("FORCED_NAME_CHANGE" | "USING_BANNED_SKIN")[];
14
- };
15
-
16
- export type MowojangSkin = null | {
17
- url: string;
18
- hash: string;
19
- metadata: {
20
- slim: boolean;
21
- };
22
- };
23
-
24
- export type MowojangCape = null | {
25
- url: string;
26
- hash: string;
27
- };