mowojang 0.3.0 → 0.3.2
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 +0 -1
- package/dist/package.json +5 -5
- package/dist/src/axiosInstance.d.ts +2 -2
- package/dist/src/client.d.ts +2 -2
- package/dist/src/client.js +12 -13
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/validators.d.ts +1 -1
- package/package.json +5 -5
- package/tsconfig.json +1 -0
package/README.md
CHANGED
|
@@ -58,7 +58,6 @@ All Validator Functions are exported combined as `validate.x`.
|
|
|
58
58
|
- `pnpm install`: Installs all required dependencies
|
|
59
59
|
- `pnpm build`: Runs the TypeScript compiler
|
|
60
60
|
- `pnpm test`: Runs tests for all Functions
|
|
61
|
-
- `pnpm publish`: Publish the Package to NPM
|
|
62
61
|
|
|
63
62
|
## 📎 Credits
|
|
64
63
|
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mowojang",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
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",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"node": ">=20.0.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"axios": "^1.7.
|
|
31
|
-
"axios-cache-interceptor": "^1.
|
|
30
|
+
"axios": "^1.7.7",
|
|
31
|
+
"axios-cache-interceptor": "^1.6.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@types/node": "^
|
|
35
|
-
"typescript": "^5.
|
|
34
|
+
"@types/node": "^22.7.3",
|
|
35
|
+
"typescript": "^5.6.2"
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AxiosCacheInstance } from "axios-cache-interceptor";
|
|
2
|
-
import { AxiosOptions } from "../types/index.
|
|
1
|
+
import { type AxiosCacheInstance } from "axios-cache-interceptor";
|
|
2
|
+
import type { AxiosOptions } from "../types/index.d.ts";
|
|
3
3
|
declare const _default: (options?: AxiosOptions) => AxiosCacheInstance;
|
|
4
4
|
export default _default;
|
package/dist/src/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Player, Username, UUID, ClientOptions, MowojangCape, MowojangProfile, MowojangRequestConfig, MowojangResponse, MowojangSession, MowojangSkin } from "../types/index.
|
|
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
4
|
constructor(clientOptions?: ClientOptions);
|
|
@@ -28,7 +28,7 @@ export default class Client {
|
|
|
28
28
|
*
|
|
29
29
|
* Players considered "INVALID" are excluded from the results
|
|
30
30
|
*/
|
|
31
|
-
getSessions(players: Player[], config?: MowojangRequestConfig): MowojangResponse<MowojangSession[],
|
|
31
|
+
getSessions(players: Player[], config?: MowojangRequestConfig): MowojangResponse<MowojangSession[], undefined>;
|
|
32
32
|
/**
|
|
33
33
|
* Returns a Player's Sessions consisting of their Username, UUID, Skin and Cape
|
|
34
34
|
*
|
package/dist/src/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isAxiosError } from "axios";
|
|
2
2
|
import axiosInstance from "./axiosInstance.js";
|
|
3
|
-
import { validateArray, validatePlayer, validateUUID
|
|
3
|
+
import { validateArray, validatePlayer, validateUUID } from "./validators.js";
|
|
4
4
|
import { undashUUID } from "./utils.js";
|
|
5
5
|
export default class Client {
|
|
6
6
|
axios;
|
|
@@ -14,13 +14,15 @@ export default class Client {
|
|
|
14
14
|
*/
|
|
15
15
|
async getProfiles(players, config) {
|
|
16
16
|
try {
|
|
17
|
-
if (!validateArray(players, validatePlayer))
|
|
17
|
+
if (config?.validate !== false && !validateArray(players, validatePlayer))
|
|
18
18
|
return { data: null, error: "INVALID_INPUT" };
|
|
19
|
-
players = players
|
|
19
|
+
players = players
|
|
20
|
+
.map((player) => {
|
|
20
21
|
if (validateUUID(player))
|
|
21
22
|
return undashUUID(player);
|
|
22
23
|
return player.toLowerCase();
|
|
23
|
-
})
|
|
24
|
+
})
|
|
25
|
+
.sort();
|
|
24
26
|
const fetchResponse = await this.axios.post("https://mowojang.matdoes.dev/", players, {
|
|
25
27
|
cache: config?.cache ?? { ttl: 15 * 60 * 1000 },
|
|
26
28
|
});
|
|
@@ -45,7 +47,7 @@ export default class Client {
|
|
|
45
47
|
*
|
|
46
48
|
*/
|
|
47
49
|
async getProfile(player, config) {
|
|
48
|
-
if (!validatePlayer(player))
|
|
50
|
+
if (config?.validate !== false && !validatePlayer(player))
|
|
49
51
|
return { data: null, error: "INVALID_INPUT" };
|
|
50
52
|
const profiles = await this.getProfiles([player], config);
|
|
51
53
|
if (profiles.error)
|
|
@@ -59,8 +61,6 @@ export default class Client {
|
|
|
59
61
|
*
|
|
60
62
|
*/
|
|
61
63
|
async getUUID(username, config) {
|
|
62
|
-
if (!validateUsername(username))
|
|
63
|
-
return null;
|
|
64
64
|
const profile = await this.getProfile(username, config);
|
|
65
65
|
if (profile.error)
|
|
66
66
|
return null;
|
|
@@ -71,8 +71,6 @@ export default class Client {
|
|
|
71
71
|
*
|
|
72
72
|
*/
|
|
73
73
|
async getUsername(UUID, config) {
|
|
74
|
-
if (!validateUUID(UUID))
|
|
75
|
-
return null;
|
|
76
74
|
const profile = await this.getProfile(UUID, config);
|
|
77
75
|
if (profile.error)
|
|
78
76
|
return null;
|
|
@@ -85,7 +83,7 @@ export default class Client {
|
|
|
85
83
|
*/
|
|
86
84
|
async getSessions(players, config) {
|
|
87
85
|
try {
|
|
88
|
-
if (!validateArray(players, validatePlayer))
|
|
86
|
+
if (config?.validate !== false && !validateArray(players, validatePlayer))
|
|
89
87
|
return { data: null, error: "INVALID_INPUT" };
|
|
90
88
|
players = players.map((player) => {
|
|
91
89
|
if (validateUUID(player))
|
|
@@ -94,10 +92,11 @@ export default class Client {
|
|
|
94
92
|
});
|
|
95
93
|
const sessionsPromises = [];
|
|
96
94
|
players.forEach((player) => {
|
|
95
|
+
// @ts-ignore
|
|
97
96
|
sessionsPromises.push(this.getSession(player, config));
|
|
98
97
|
});
|
|
99
98
|
const sessions = (await Promise.all(sessionsPromises))
|
|
100
|
-
.filter((session) => session.data)
|
|
99
|
+
.filter((session) => session.data !== null)
|
|
101
100
|
.map((session) => session.data);
|
|
102
101
|
return {
|
|
103
102
|
// @ts-ignore
|
|
@@ -114,11 +113,11 @@ export default class Client {
|
|
|
114
113
|
*
|
|
115
114
|
*/
|
|
116
115
|
async getSession(player, config) {
|
|
117
|
-
if (!validatePlayer(player))
|
|
116
|
+
if (config?.validate !== false && !validatePlayer(player))
|
|
118
117
|
return { data: null, error: "INVALID_INPUT" };
|
|
119
118
|
const UUID = await this.getUUID(player);
|
|
120
119
|
if (!UUID)
|
|
121
|
-
return { data: null, error: "
|
|
120
|
+
return { data: null, error: "INVALID_PLAYER" };
|
|
122
121
|
return await this.axios
|
|
123
122
|
.get(`https://mowojang.matdoes.dev/session/minecraft/profile/${UUID}`, {
|
|
124
123
|
cache: config?.cache ?? { ttl: 15 * 60 * 1000 },
|
package/dist/src/utils.d.ts
CHANGED
package/dist/src/validators.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mowojang",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
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",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"node": ">=20.0.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"axios": "^1.7.
|
|
25
|
-
"axios-cache-interceptor": "^1.
|
|
24
|
+
"axios": "^1.7.7",
|
|
25
|
+
"axios-cache-interceptor": "^1.6.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/node": "^
|
|
29
|
-
"typescript": "^5.
|
|
28
|
+
"@types/node": "^22.7.3",
|
|
29
|
+
"typescript": "^5.6.2"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "pnpm tsc",
|