mowojang 0.3.3 → 0.3.5
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/dist/package.json +2 -2
- package/dist/src/axiosInstance.js +1 -1
- package/dist/src/client.d.ts +3 -0
- package/dist/src/client.js +20 -6
- package/package.json +2 -2
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mowojang",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
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/
|
|
16
|
+
"url": "https://github.com/Pixelicc/mowojang-js"
|
|
17
17
|
},
|
|
18
18
|
"keywords": [
|
|
19
19
|
"Minecraft",
|
|
@@ -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 ??
|
|
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)`,
|
package/dist/src/client.d.ts
CHANGED
|
@@ -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
|
*
|
package/dist/src/client.js
CHANGED
|
@@ -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,8 +30,7 @@ export default class Client {
|
|
|
14
30
|
*/
|
|
15
31
|
async getProfiles(players, config) {
|
|
16
32
|
try {
|
|
17
|
-
if (config
|
|
18
|
-
!validateArray(players, validatePlayer, config?.validationOptions?.minimumUsernameLength))
|
|
33
|
+
if (this.shouldValidate(config) && !validateArray(players, validatePlayer, this.getValidationMinLength(config)))
|
|
19
34
|
return { data: null, error: "INVALID_INPUT" };
|
|
20
35
|
players = players
|
|
21
36
|
.map((player) => {
|
|
@@ -48,7 +63,7 @@ export default class Client {
|
|
|
48
63
|
*
|
|
49
64
|
*/
|
|
50
65
|
async getProfile(player, config) {
|
|
51
|
-
if (config
|
|
66
|
+
if (this.shouldValidate(config) && !validatePlayer(player, this.getValidationMinLength(config)))
|
|
52
67
|
return { data: null, error: "INVALID_INPUT" };
|
|
53
68
|
const profiles = await this.getProfiles([player], config);
|
|
54
69
|
if (profiles.error)
|
|
@@ -84,8 +99,7 @@ export default class Client {
|
|
|
84
99
|
*/
|
|
85
100
|
async getSessions(players, config) {
|
|
86
101
|
try {
|
|
87
|
-
if (config
|
|
88
|
-
!validateArray(players, validatePlayer, config?.validationOptions?.minimumUsernameLength))
|
|
102
|
+
if (this.shouldValidate(config) && !validateArray(players, validatePlayer, this.getValidationMinLength(config)))
|
|
89
103
|
return { data: null, error: "INVALID_INPUT" };
|
|
90
104
|
players = players.map((player) => {
|
|
91
105
|
if (validateUUID(player))
|
|
@@ -115,7 +129,7 @@ export default class Client {
|
|
|
115
129
|
*
|
|
116
130
|
*/
|
|
117
131
|
async getSession(player, config) {
|
|
118
|
-
if (config
|
|
132
|
+
if (this.shouldValidate(config) && !validatePlayer(player, this.getValidationMinLength(config)))
|
|
119
133
|
return { data: null, error: "INVALID_INPUT" };
|
|
120
134
|
const UUID = await this.getUUID(player);
|
|
121
135
|
if (!UUID)
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mowojang",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
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/
|
|
10
|
+
"url": "https://github.com/Pixelicc/mowojang-js"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
13
13
|
"Minecraft",
|