mowojang 0.2.2 → 0.3.1
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 +9 -10
- package/dist/package.json +7 -7
- package/dist/src/client.d.ts +11 -11
- package/dist/src/client.js +22 -23
- package/dist/src/index.d.ts +2 -2
- package/dist/src/utils.d.ts +10 -2
- package/dist/src/utils.js +8 -0
- package/dist/src/validators.d.ts +11 -0
- package/dist/src/validators.js +11 -0
- package/package.json +7 -7
- package/.prettierignore +0 -5
- package/.prettierrc +0 -7
- package/.vscode/settings.json +0 -6
- package/docs/custom-caching.md +0 -44
- package/types/index.d.ts +0 -3
- package/types/misc.d.ts +0 -28
- package/types/player.d.ts +0 -20
- package/types/structures.d.ts +0 -27
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# mowojang-js
|
|
2
2
|
|
|
3
3
|

|
|
4
|
-

|
|
5
5
|

|
|
6
6
|
|
|
7
7
|
> [!IMPORTANT]
|
|
8
|
-
> This is
|
|
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
|
|
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
|
|
35
|
-
- `getCape()`: Returns the Cape the specified Player
|
|
36
|
-
- `getCapeBuffer()`: Cape
|
|
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).
|
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mowojang",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A simple JavaScript and TypeScript compatible
|
|
3
|
+
"version": "0.3.1",
|
|
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-
|
|
16
|
+
"url": "https://github.com/pixelicc/mowojang-js.git"
|
|
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.
|
|
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
|
}
|
package/dist/src/client.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
getSessions(players: Player[], config?: MowojangRequestConfig): MowojangResponse<MowojangSession[],
|
|
31
|
+
getSessions(players: Player[], config?: MowojangRequestConfig): MowojangResponse<MowojangSession[], undefined>;
|
|
32
32
|
/**
|
|
33
|
-
* Returns a Player
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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>;
|
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;
|
|
@@ -8,19 +8,21 @@ 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
|
*/
|
|
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
|
});
|
|
@@ -41,11 +43,11 @@ export default class Client {
|
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
|
-
* Returns a Player Profile
|
|
46
|
+
* Returns a Player's Profile consisting of their Username and UUID
|
|
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)
|
|
@@ -55,37 +57,33 @@ export default class Client {
|
|
|
55
57
|
return { data: profiles.data[0], error: null };
|
|
56
58
|
}
|
|
57
59
|
/**
|
|
58
|
-
* Simple Wrapper to
|
|
60
|
+
* A Simple Wrapper to Retrieve Only the UUID of a Player's Profile
|
|
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;
|
|
67
67
|
return profile.data.UUID;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
* Simple Wrapper to
|
|
70
|
+
* A Simple Wrapper to Retrieve Only the Username of a Player's Profile
|
|
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;
|
|
79
77
|
return profile.data.username;
|
|
80
78
|
}
|
|
81
79
|
/**
|
|
82
|
-
* Returns an Array of Player Sessions
|
|
80
|
+
* Returns an Array of Player Sessions consisting of their Usernames, UUIDs, Skins and Capes
|
|
83
81
|
*
|
|
84
82
|
* Players considered "INVALID" are excluded from the results
|
|
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
|
|
@@ -110,15 +109,15 @@ export default class Client {
|
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
/**
|
|
113
|
-
* Returns a Player
|
|
112
|
+
* Returns a Player's Sessions consisting of their Username, UUID, Skin and Cape
|
|
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 },
|
|
@@ -164,7 +163,7 @@ export default class Client {
|
|
|
164
163
|
});
|
|
165
164
|
}
|
|
166
165
|
/**
|
|
167
|
-
* Simple Wrapper to
|
|
166
|
+
* A Simple Wrapper to Retrieve Only the Skin from a Player's Session
|
|
168
167
|
*
|
|
169
168
|
*/
|
|
170
169
|
async getSkin(player, config) {
|
|
@@ -174,7 +173,7 @@ export default class Client {
|
|
|
174
173
|
return session.data.skin;
|
|
175
174
|
}
|
|
176
175
|
/**
|
|
177
|
-
* Simple Wrapper to
|
|
176
|
+
* A Simple Wrapper to Retrieve Only the Player's Skin from their Session Data Loaded into a Buffer
|
|
178
177
|
*
|
|
179
178
|
*/
|
|
180
179
|
async getSkinBuffer(player, config) {
|
|
@@ -188,7 +187,7 @@ export default class Client {
|
|
|
188
187
|
return Buffer.from(fetchResponse.data, "base64");
|
|
189
188
|
}
|
|
190
189
|
/**
|
|
191
|
-
* Simple Wrapper to
|
|
190
|
+
* A Simple Wrapper to Retrieve Only the Cape Data from a Player's Session
|
|
192
191
|
*
|
|
193
192
|
*/
|
|
194
193
|
async getCape(player, config) {
|
|
@@ -198,7 +197,7 @@ export default class Client {
|
|
|
198
197
|
return session.data.cape;
|
|
199
198
|
}
|
|
200
199
|
/**
|
|
201
|
-
* Simple Wrapper to
|
|
200
|
+
* A Simple Wrapper to Retrieve Only the Player's Cape from their Session Data Loaded into a Buffer
|
|
202
201
|
*
|
|
203
202
|
*/
|
|
204
203
|
async getCapeBuffer(player, config) {
|
package/dist/src/index.d.ts
CHANGED
|
@@ -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:
|
|
11
|
-
undashUUID: (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;
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
import { UUID } from "../types/index.js";
|
|
2
|
-
|
|
3
|
-
|
|
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");
|
package/dist/src/validators.d.ts
CHANGED
|
@@ -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;
|
package/dist/src/validators.js
CHANGED
|
@@ -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.
|
|
4
|
-
"description": "A simple JavaScript and TypeScript compatible
|
|
3
|
+
"version": "0.3.1",
|
|
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-
|
|
10
|
+
"url": "https://github.com/pixelicc/mowojang-js.git"
|
|
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.
|
|
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",
|
package/.prettierignore
DELETED
package/.prettierrc
DELETED
package/.vscode/settings.json
DELETED
package/docs/custom-caching.md
DELETED
|
@@ -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
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;
|
package/types/structures.d.ts
DELETED
|
@@ -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
|
-
};
|