mowojang 0.3.2 → 0.3.4

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
@@ -35,7 +35,7 @@ const username = await Mowojang.getUsername("14727fae-fbdc-4aff-848c-d2713eb9939
35
35
  - `getCape()`: Returns the Cape the specified Player has currently selected
36
36
  - `getCapeBuffer()`: Returns Cape Image fetched via getCape() as a Buffer
37
37
 
38
- All above Functions accept an second Argument containing an optional config.
38
+ All above Functions accept an second Argument containing an optional config object.
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).
40
40
 
41
41
  ## 🗃️ Utility Functions
@@ -50,7 +50,7 @@ All Utility Functions are exported combined as `utlis.x`.
50
50
  All Validator Functions are exported combined as `validate.x`.
51
51
 
52
52
  - `UUID()`: Returns whether the provided String is an valid UUID (Accepts both undashed and dashed UUIDv4 Strings)
53
- - `username()`: Returns whether the provided String is an valid Username
53
+ - `username()`: Returns whether the provided String is an valid Username (Accepts a second argument stating the minimum length required to pass the validation)
54
54
  - `player()` Combines the above
55
55
 
56
56
  ## ⚙️ Development
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mowojang",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
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",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "https://github.com/pixelicc/mowojang-js.git"
16
+ "url": "https://github.com/Pixelicc/mowojang-js"
17
17
  },
18
18
  "keywords": [
19
19
  "Minecraft",
@@ -27,11 +27,11 @@
27
27
  "node": ">=20.0.0"
28
28
  },
29
29
  "dependencies": {
30
- "axios": "^1.7.7",
31
- "axios-cache-interceptor": "^1.6.0"
30
+ "axios": "^1.7.9",
31
+ "axios-cache-interceptor": "^1.6.2"
32
32
  },
33
33
  "devDependencies": {
34
- "@types/node": "^22.7.3",
35
- "typescript": "^5.6.2"
34
+ "@types/node": "^22.10.7",
35
+ "typescript": "^5.7.3"
36
36
  }
37
37
  }
@@ -3,7 +3,7 @@ import { setupCache } from "axios-cache-interceptor";
3
3
  import PackageJSON from "../package.json" with { type: "json" };
4
4
  export default (options) => {
5
5
  return setupCache(axios.create({
6
- timeout: options?.timeout ?? 5000,
6
+ timeout: options?.timeout ?? 10000,
7
7
  maxRedirects: 0,
8
8
  headers: {
9
9
  "User-Agent": `axios/${axios.VERSION} mowojang/${PackageJSON.version} (https://www.npmjs.com/package/mowojang)`,
@@ -1,7 +1,10 @@
1
1
  import type { Player, Username, UUID, ClientOptions, MowojangCape, MowojangProfile, MowojangRequestConfig, MowojangResponse, MowojangSession, MowojangSkin } from "../types/index.d.ts";
2
2
  export default class Client {
3
3
  private axios;
4
+ private validation;
4
5
  constructor(clientOptions?: ClientOptions);
6
+ private shouldValidate;
7
+ private getValidationMinLength;
5
8
  /**
6
9
  * Returns an Array of Player Profiles consisting of their Usernames and UUIDs
7
10
  *
@@ -4,8 +4,24 @@ import { validateArray, validatePlayer, validateUUID } from "./validators.js";
4
4
  import { undashUUID } from "./utils.js";
5
5
  export default class Client {
6
6
  axios;
7
+ validation;
7
8
  constructor(clientOptions) {
8
9
  this.axios = axiosInstance(clientOptions);
10
+ this.validation = clientOptions?.validation ?? {};
11
+ }
12
+ shouldValidate(config) {
13
+ return this.validation?.enabled || config?.validation?.enabled || false;
14
+ }
15
+ getValidationMinLength(config) {
16
+ if (this.validation?.minimumUsernameLength === 1)
17
+ return 1;
18
+ if (this.validation?.minimumUsernameLength === 2)
19
+ return 2;
20
+ if (config?.validation?.minimumUsernameLength === 1)
21
+ return 1;
22
+ if (config?.validation?.minimumUsernameLength === 2)
23
+ return 2;
24
+ return undefined;
9
25
  }
10
26
  /**
11
27
  * Returns an Array of Player Profiles consisting of their Usernames and UUIDs
@@ -14,7 +30,7 @@ export default class Client {
14
30
  */
15
31
  async getProfiles(players, config) {
16
32
  try {
17
- if (config?.validate !== false && !validateArray(players, validatePlayer))
33
+ if (this.shouldValidate(config) && !validateArray(players, validatePlayer, this.getValidationMinLength(config)))
18
34
  return { data: null, error: "INVALID_INPUT" };
19
35
  players = players
20
36
  .map((player) => {
@@ -47,7 +63,7 @@ export default class Client {
47
63
  *
48
64
  */
49
65
  async getProfile(player, config) {
50
- if (config?.validate !== false && !validatePlayer(player))
66
+ if (this.shouldValidate(config) && !validatePlayer(player, this.getValidationMinLength(config)))
51
67
  return { data: null, error: "INVALID_INPUT" };
52
68
  const profiles = await this.getProfiles([player], config);
53
69
  if (profiles.error)
@@ -83,7 +99,7 @@ export default class Client {
83
99
  */
84
100
  async getSessions(players, config) {
85
101
  try {
86
- if (config?.validate !== false && !validateArray(players, validatePlayer))
102
+ if (this.shouldValidate(config) && !validateArray(players, validatePlayer, this.getValidationMinLength(config)))
87
103
  return { data: null, error: "INVALID_INPUT" };
88
104
  players = players.map((player) => {
89
105
  if (validateUUID(player))
@@ -113,7 +129,7 @@ export default class Client {
113
129
  *
114
130
  */
115
131
  async getSession(player, config) {
116
- if (config?.validate !== false && !validatePlayer(player))
132
+ if (this.shouldValidate(config) && !validatePlayer(player, this.getValidationMinLength(config)))
117
133
  return { data: null, error: "INVALID_INPUT" };
118
134
  const UUID = await this.getUUID(player);
119
135
  if (!UUID)
@@ -2,9 +2,9 @@ import client from "./client.js";
2
2
  import { buildStorage, buildMemoryStorage } from "axios-cache-interceptor";
3
3
  export declare const Client: typeof client;
4
4
  export declare const validate: {
5
- player: (player: import("../types/player.js").Player) => boolean;
5
+ player: (player: import("../types/player.js").Player, minimumUsernameLength?: 1 | 2) => boolean;
6
6
  UUID: (UUID: string) => boolean;
7
- username: (username: string) => boolean;
7
+ username: (username: string, minimumLength?: 1 | 2) => boolean;
8
8
  };
9
9
  export declare const utils: {
10
10
  dashUUID: (UUID: import("../types/player.js").UUID) => import("../types/player.js").UUID;
@@ -6,11 +6,14 @@ import type { Player } from "../types/index.d.ts";
6
6
  export declare const validateUUID: (UUID: string) => boolean;
7
7
  /**
8
8
  * Validates a Minecraft Username
9
+ *
10
+ * @param minimumLength Allows you to set a custom minimum length needed to pass the validation process. This option only exists as older Minecraft Usernames were allowed to be shorter than 3 characters.
9
11
  */
10
- export declare const validateUsername: (username: string) => boolean;
12
+ export declare const validateUsername: (username: string, minimumLength?: 1 | 2) => boolean;
11
13
  /**
12
14
  * Validates a Minecraft Player by either validating their Username or supplied UUID
13
15
  *
16
+ * @param minimumUsernameLength Allows you to set a custom minimum length needed to pass the validation process. This option only exists as older Minecraft Usernames were allowed to be shorter than 3 characters.
14
17
  */
15
- export declare const validatePlayer: (player: Player) => boolean;
18
+ export declare const validatePlayer: (player: Player, minimumUsernameLength?: 1 | 2) => boolean;
16
19
  export declare const validateArray: <T>(array: T[], validatorFunction: (item: T, ...params: any[]) => boolean, ...params: any[]) => boolean;
@@ -13,17 +13,24 @@ export const validateUUID = (UUID) => {
13
13
  };
14
14
  /**
15
15
  * Validates a Minecraft Username
16
+ *
17
+ * @param minimumLength Allows you to set a custom minimum length needed to pass the validation process. This option only exists as older Minecraft Usernames were allowed to be shorter than 3 characters.
16
18
  */
17
- export const validateUsername = (username) => {
19
+ export const validateUsername = (username, minimumLength) => {
18
20
  if (typeof username !== "string")
19
21
  return false;
20
- return /^[a-zA-Z0-9_]{1,16}$/.test(username);
22
+ if (minimumLength === 1)
23
+ return /^[a-zA-Z0-9_]{1,16}$/.test(username);
24
+ if (minimumLength === 2)
25
+ return /^[a-zA-Z0-9_]{2,16}$/.test(username);
26
+ return /^[a-zA-Z0-9_]{3,16}$/.test(username);
21
27
  };
22
28
  /**
23
29
  * Validates a Minecraft Player by either validating their Username or supplied UUID
24
30
  *
31
+ * @param minimumUsernameLength Allows you to set a custom minimum length needed to pass the validation process. This option only exists as older Minecraft Usernames were allowed to be shorter than 3 characters.
25
32
  */
26
- export const validatePlayer = (player) => validateUUID(player) || validateUsername(player);
33
+ export const validatePlayer = (player, minimumUsernameLength) => validateUUID(player) || validateUsername(player, minimumUsernameLength);
27
34
  export const validateArray = (array, validatorFunction, ...params) => {
28
35
  if (!Array.isArray(array))
29
36
  return false;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "mowojang",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
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-js.git"
10
+ "url": "https://github.com/Pixelicc/mowojang-js"
11
11
  },
12
12
  "keywords": [
13
13
  "Minecraft",
@@ -21,12 +21,12 @@
21
21
  "node": ">=20.0.0"
22
22
  },
23
23
  "dependencies": {
24
- "axios": "^1.7.7",
25
- "axios-cache-interceptor": "^1.6.0"
24
+ "axios": "^1.7.9",
25
+ "axios-cache-interceptor": "^1.6.2"
26
26
  },
27
27
  "devDependencies": {
28
- "@types/node": "^22.7.3",
29
- "typescript": "^5.6.2"
28
+ "@types/node": "^22.10.7",
29
+ "typescript": "^5.7.3"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "pnpm tsc",