mowojang 0.3.9 → 0.4.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 +16 -0
- package/dist/package.json +9 -5
- package/dist/src/axiosInstance.d.ts +2 -1
- package/dist/src/axiosInstance.js +32 -2
- package/dist/src/client.d.ts +7 -3
- package/dist/src/client.js +36 -16
- package/dist/src/index.d.ts +1 -1
- package/dist/src/validators.d.ts +3 -3
- package/dist/src/validators.js +1 -1
- package/dist/types/misc.d.ts +4 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -38,6 +38,8 @@ const username = await Mowojang.getUsername("14727fae-fbdc-4aff-848c-d2713eb9939
|
|
|
38
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
|
+
Note: `getProfiles()` defaults to fetching each profile via individual GET requests to improve reliability. To use the POST bulk endpoint instead, pass `{ usePost: true }` as the second argument to `getProfiles()`.
|
|
42
|
+
|
|
41
43
|
## 🗃️ Utility Functions
|
|
42
44
|
|
|
43
45
|
All Utility Functions are exported combined as `utlis.x`.
|
|
@@ -65,3 +67,17 @@ All Validator Functions are exported combined as `validate.x`.
|
|
|
65
67
|
- [Website](https://matdoes.dev)
|
|
66
68
|
- [GitHub](https://github.com/mat-1)
|
|
67
69
|
- [Ko-Fi](https://ko-fi.com/matdoesdev)
|
|
70
|
+
|
|
71
|
+
## 📡 [Status](https://mowojang-status.pixelic.dev/)
|
|
72
|
+
|
|
73
|
+
<details>
|
|
74
|
+
<summary>Show status badges</summary>
|
|
75
|
+
|
|
76
|
+
- Mowojang API - GET /:username ->  
|
|
77
|
+
- Mowojang API - GET /:UUID ->  
|
|
78
|
+
- Mowojang API - GET /session/minecraft/profile/:UUID ->  
|
|
79
|
+
- Mowojang API - GET /users/profiles/minecraft/:username ->  
|
|
80
|
+
- Mowojang API - POST / - [username,UUID] ->  
|
|
81
|
+
- Minecraft API - GET /texture/:hash ->  
|
|
82
|
+
|
|
83
|
+
</details>
|
package/dist/package.json
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mowojang",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
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
|
-
"files": [
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
8
10
|
"type": "module",
|
|
9
11
|
"scripts": {
|
|
10
12
|
"build": "pnpm tsc",
|
|
11
13
|
"test": "node test test/index.js",
|
|
12
14
|
"prettier:check": "pnpm dlx prettier . --check",
|
|
13
|
-
"prettier:write": "pnpm dlx prettier . --write"
|
|
15
|
+
"prettier:write": "pnpm dlx prettier . --write",
|
|
16
|
+
"prepare": "pnpm build"
|
|
14
17
|
},
|
|
15
18
|
"repository": {
|
|
16
19
|
"type": "git",
|
|
@@ -28,11 +31,12 @@
|
|
|
28
31
|
"node": ">=22.0.0"
|
|
29
32
|
},
|
|
30
33
|
"dependencies": {
|
|
34
|
+
"@pixelic/logger": "npm:@jsr/pixelic__logger@^0.0.6",
|
|
31
35
|
"axios": "^1.7.9",
|
|
32
36
|
"axios-cache-interceptor": "^1.6.2"
|
|
33
37
|
},
|
|
34
38
|
"devDependencies": {
|
|
35
|
-
"@types/node": "^
|
|
36
|
-
"typescript": "^
|
|
39
|
+
"@types/node": "^25.9.1",
|
|
40
|
+
"typescript": "^6.0.3"
|
|
37
41
|
}
|
|
38
42
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type AxiosCacheInstance } from "axios-cache-interceptor";
|
|
2
2
|
import type { AxiosOptions } from "../types/index.d.ts";
|
|
3
|
-
|
|
3
|
+
import type { Logger } from "@pixelic/logger";
|
|
4
|
+
declare const _default: (options: AxiosOptions, logger: Logger) => AxiosCacheInstance;
|
|
4
5
|
export default _default;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import { setupCache } from "axios-cache-interceptor";
|
|
3
3
|
import PackageJSON from "../package.json" with { type: "json" };
|
|
4
|
-
export default (options) => {
|
|
5
|
-
|
|
4
|
+
export default (options, logger) => {
|
|
5
|
+
const instance = setupCache(axios.create({
|
|
6
6
|
timeout: options?.timeout ?? 10000,
|
|
7
7
|
maxRedirects: 0,
|
|
8
8
|
headers: {
|
|
@@ -14,4 +14,34 @@ export default (options) => {
|
|
|
14
14
|
cacheTakeover: false,
|
|
15
15
|
...options?.cache,
|
|
16
16
|
});
|
|
17
|
+
instance.interceptors.request.use((req) => {
|
|
18
|
+
// @ts-expect-error
|
|
19
|
+
req.internalId = Math.random().toString(16).slice(2, 10).padEnd(8, "0");
|
|
20
|
+
// @ts-expect-error
|
|
21
|
+
logger.debug("Pixelic/Mowojang", `(${req.internalId}) ${req.method?.toUpperCase()} ${axios.getUri(req)}`);
|
|
22
|
+
return req;
|
|
23
|
+
});
|
|
24
|
+
instance.interceptors.response.use((res) => {
|
|
25
|
+
if (res.cached) {
|
|
26
|
+
logger.debug("Mowojang",
|
|
27
|
+
// @ts-expect-error
|
|
28
|
+
`(${res.config.internalId}) ${res.stale ? "GET-CACHE-STALE" : "GET-CACHE"} ${axios.getUri(res.config)}`);
|
|
29
|
+
}
|
|
30
|
+
return res;
|
|
31
|
+
}, (err) => {
|
|
32
|
+
if (err.code === "ECONNRESET") {
|
|
33
|
+
const host = new URL(err.config.url).host;
|
|
34
|
+
var cleanHost = host;
|
|
35
|
+
if (host === "mowojang.matdoes.dev") {
|
|
36
|
+
cleanHost = "Mowojang";
|
|
37
|
+
}
|
|
38
|
+
else if (host === "mowojang.seraph.si") {
|
|
39
|
+
cleanHost = "Seraph";
|
|
40
|
+
}
|
|
41
|
+
logger.critical("Mowojang", `(${err.config.internalId}) Failed to establish Connection to ${host}`);
|
|
42
|
+
logger.info("Mowojang", `Check Status of ${cleanHost} on: https://mowojang-status.pixelic.dev`);
|
|
43
|
+
}
|
|
44
|
+
return Promise.reject(err);
|
|
45
|
+
});
|
|
46
|
+
return instance;
|
|
17
47
|
};
|
package/dist/src/client.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
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
|
+
private logger;
|
|
3
4
|
private axios;
|
|
4
5
|
private validation;
|
|
6
|
+
private baseURL;
|
|
5
7
|
constructor(clientOptions?: ClientOptions);
|
|
6
8
|
private shouldValidate;
|
|
7
9
|
private getValidationMinLength;
|
|
@@ -10,7 +12,9 @@ export default class Client {
|
|
|
10
12
|
*
|
|
11
13
|
* Players considered "INVALID" are excluded from the results
|
|
12
14
|
*/
|
|
13
|
-
getProfiles(players: Player[], config?: MowojangRequestConfig
|
|
15
|
+
getProfiles(players: Player[], config?: MowojangRequestConfig & {
|
|
16
|
+
usePost?: boolean;
|
|
17
|
+
}): MowojangResponse<MowojangProfile[], undefined>;
|
|
14
18
|
/**
|
|
15
19
|
* Returns a Player's Profile consisting of their Username and UUID
|
|
16
20
|
*
|
|
@@ -20,12 +24,12 @@ export default class Client {
|
|
|
20
24
|
* A Simple Wrapper to Retrieve Only the UUID of a Player's Profile
|
|
21
25
|
*
|
|
22
26
|
*/
|
|
23
|
-
getUUID(username: Username, config?: MowojangRequestConfig): Promise<null |
|
|
27
|
+
getUUID(username: Username, config?: MowojangRequestConfig): Promise<null | UUID>;
|
|
24
28
|
/**
|
|
25
29
|
* A Simple Wrapper to Retrieve Only the Username of a Player's Profile
|
|
26
30
|
*
|
|
27
31
|
*/
|
|
28
|
-
getUsername(UUID: UUID, config?: MowojangRequestConfig): Promise<null |
|
|
32
|
+
getUsername(UUID: UUID, config?: MowojangRequestConfig): Promise<null | Username>;
|
|
29
33
|
/**
|
|
30
34
|
* Returns an Array of Player Sessions consisting of their Usernames, UUIDs, Skins and Capes
|
|
31
35
|
*
|
package/dist/src/client.js
CHANGED
|
@@ -2,12 +2,17 @@ import { isAxiosError } from "axios";
|
|
|
2
2
|
import axiosInstance from "./axiosInstance.js";
|
|
3
3
|
import { validateArray, validatePlayer, validateUUID } from "./validators.js";
|
|
4
4
|
import { undashUUID } from "./utils.js";
|
|
5
|
+
import { Logger } from "@pixelic/logger";
|
|
5
6
|
export default class Client {
|
|
7
|
+
logger;
|
|
6
8
|
axios;
|
|
7
9
|
validation;
|
|
10
|
+
baseURL;
|
|
8
11
|
constructor(clientOptions) {
|
|
9
|
-
this.
|
|
12
|
+
this.logger = new Logger(clientOptions?.logger);
|
|
13
|
+
this.axios = axiosInstance(clientOptions ?? {}, this.logger);
|
|
10
14
|
this.validation = clientOptions?.validation ?? {};
|
|
15
|
+
this.baseURL = clientOptions?.baseURL ?? "https://mowojang.matdoes.dev";
|
|
11
16
|
}
|
|
12
17
|
shouldValidate(config) {
|
|
13
18
|
return this.validation?.enabled || config?.validation?.enabled || false;
|
|
@@ -39,23 +44,38 @@ export default class Client {
|
|
|
39
44
|
return player.toLowerCase();
|
|
40
45
|
})
|
|
41
46
|
.sort();
|
|
42
|
-
const
|
|
43
|
-
|
|
47
|
+
const usePost = config?.usePost ?? false;
|
|
48
|
+
if (usePost) {
|
|
49
|
+
const fetchResponse = await this.axios.post(this.baseURL, players, {
|
|
50
|
+
cache: config?.cache ?? { ttl: 15 * 60 * 1000 },
|
|
51
|
+
});
|
|
52
|
+
if (!Array.isArray(fetchResponse?.data))
|
|
53
|
+
return { data: null, error: "UNKNOWN_ERROR" };
|
|
54
|
+
return {
|
|
55
|
+
data: fetchResponse.data.map((player) => {
|
|
56
|
+
return {
|
|
57
|
+
UUID: player.id,
|
|
58
|
+
username: player.name,
|
|
59
|
+
};
|
|
60
|
+
}),
|
|
61
|
+
error: null,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// Default fallback to GET requests via getProfile()
|
|
65
|
+
const profilePromises = [];
|
|
66
|
+
players.forEach((player) => {
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
profilePromises.push(this.getProfile(player, config));
|
|
44
69
|
});
|
|
45
|
-
|
|
46
|
-
return { data: null, error: "UNKOWN_ERROR" };
|
|
70
|
+
const profiles = (await Promise.all(profilePromises)).filter((p) => p.data !== null).map((p) => p.data);
|
|
47
71
|
return {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
UUID: player.id,
|
|
51
|
-
username: player.name,
|
|
52
|
-
};
|
|
53
|
-
}),
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
data: profiles,
|
|
54
74
|
error: null,
|
|
55
75
|
};
|
|
56
76
|
}
|
|
57
77
|
catch {
|
|
58
|
-
return { data: null, error: "
|
|
78
|
+
return { data: null, error: "UNKNOWN_ERROR" };
|
|
59
79
|
}
|
|
60
80
|
}
|
|
61
81
|
/**
|
|
@@ -66,7 +86,7 @@ export default class Client {
|
|
|
66
86
|
try {
|
|
67
87
|
if (this.shouldValidate(config) && !validatePlayer(player, this.getValidationMinLength(config)))
|
|
68
88
|
return { data: null, error: "INVALID_INPUT" };
|
|
69
|
-
const fetchResponse = await this.axios.get(
|
|
89
|
+
const fetchResponse = await this.axios.get(`${this.baseURL}/${player}`, {
|
|
70
90
|
cache: config?.cache ?? { ttl: 15 * 60 * 1000 },
|
|
71
91
|
});
|
|
72
92
|
return {
|
|
@@ -130,7 +150,7 @@ export default class Client {
|
|
|
130
150
|
};
|
|
131
151
|
}
|
|
132
152
|
catch {
|
|
133
|
-
return { data: null, error: "
|
|
153
|
+
return { data: null, error: "UNKNOWN_ERROR" };
|
|
134
154
|
}
|
|
135
155
|
}
|
|
136
156
|
/**
|
|
@@ -144,7 +164,7 @@ export default class Client {
|
|
|
144
164
|
if (!UUID)
|
|
145
165
|
return { data: null, error: "INVALID_PLAYER" };
|
|
146
166
|
return await this.axios
|
|
147
|
-
.get(
|
|
167
|
+
.get(`${this.baseURL}/session/minecraft/profile/${UUID}`, {
|
|
148
168
|
cache: config?.cache ?? { ttl: 15 * 60 * 1000 },
|
|
149
169
|
})
|
|
150
170
|
.then((fetchResponse) => {
|
|
@@ -184,7 +204,7 @@ export default class Client {
|
|
|
184
204
|
if (isAxiosError(fetchError)) {
|
|
185
205
|
return { data: null, error: "INVALID_PLAYER" };
|
|
186
206
|
}
|
|
187
|
-
return { data: null, error: "
|
|
207
|
+
return { data: null, error: "UNKNOWN_ERROR" };
|
|
188
208
|
});
|
|
189
209
|
}
|
|
190
210
|
/**
|
package/dist/src/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { buildStorage, buildMemoryStorage } from "axios-cache-interceptor";
|
|
|
3
3
|
export declare const Client: typeof client;
|
|
4
4
|
export declare const validate: {
|
|
5
5
|
player: (player: import("../types/player.js").Player, minimumUsernameLength?: 1 | 2) => boolean;
|
|
6
|
-
UUID: (UUID:
|
|
6
|
+
UUID: (UUID: import("../types/player.js").UUID) => boolean;
|
|
7
7
|
username: (username: string, minimumLength?: 1 | 2) => boolean;
|
|
8
8
|
};
|
|
9
9
|
export declare const utils: {
|
package/dist/src/validators.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Player } from "../types/index.d.ts";
|
|
1
|
+
import type { UUID, Player } from "../types/index.d.ts";
|
|
2
2
|
/**
|
|
3
|
-
* Validates a
|
|
3
|
+
* Validates a UUID string both dashed or undashed
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
|
-
export declare const validateUUID: (UUID:
|
|
6
|
+
export declare const validateUUID: (UUID: UUID) => boolean;
|
|
7
7
|
/**
|
|
8
8
|
* Validates a Minecraft Username
|
|
9
9
|
*
|
package/dist/src/validators.js
CHANGED
package/dist/types/misc.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { LoggerConfig } from "@pixelic/logger";
|
|
1
2
|
import type { CacheOptions, CacheRequestConfig } from "axios-cache-interceptor";
|
|
2
3
|
export type ClientOptions = {
|
|
3
4
|
timeout?: number;
|
|
4
5
|
validation?: ValidationOptions;
|
|
5
6
|
cache?: CacheOptions;
|
|
7
|
+
baseURL?: string;
|
|
8
|
+
logger?: LoggerConfig;
|
|
6
9
|
};
|
|
7
10
|
export type AxiosOptions = {
|
|
8
11
|
timeout?: number;
|
|
@@ -22,5 +25,5 @@ export type MowojangResponse<D, E extends MowojangError | undefined> = Promise<{
|
|
|
22
25
|
error: null;
|
|
23
26
|
} | {
|
|
24
27
|
data: null;
|
|
25
|
-
error: E extends undefined ? "
|
|
28
|
+
error: E extends undefined ? "UNKNOWN_ERROR" | "INVALID_INPUT" : E | "UNKNOWN_ERROR" | "INVALID_INPUT";
|
|
26
29
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mowojang",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
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",
|
|
@@ -24,12 +24,13 @@
|
|
|
24
24
|
"node": ">=22.0.0"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
+
"@pixelic/logger": "npm:@jsr/pixelic__logger@^0.0.6",
|
|
27
28
|
"axios": "^1.7.9",
|
|
28
29
|
"axios-cache-interceptor": "^1.6.2"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
|
-
"@types/node": "^
|
|
32
|
-
"typescript": "^
|
|
32
|
+
"@types/node": "^25.9.1",
|
|
33
|
+
"typescript": "^6.0.3"
|
|
33
34
|
},
|
|
34
35
|
"scripts": {
|
|
35
36
|
"build": "pnpm tsc",
|