mowojang 0.4.0 → 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 +6 -6
- package/dist/package.json +8 -4
- package/dist/src/axiosInstance.d.ts +2 -1
- package/dist/src/axiosInstance.js +32 -2
- package/dist/src/client.d.ts +2 -0
- package/dist/src/client.js +9 -4
- package/dist/types/misc.d.ts +3 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -73,11 +73,11 @@ All Validator Functions are exported combined as `validate.x`.
|
|
|
73
73
|
<details>
|
|
74
74
|
<summary>Show status badges</summary>
|
|
75
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
82
|
|
|
83
83
|
</details>
|
package/dist/package.json
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mowojang",
|
|
3
|
-
"version": "0.4.
|
|
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
39
|
"@types/node": "^25.9.1",
|
|
36
|
-
"typescript": "^
|
|
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;
|
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;
|
|
@@ -41,7 +46,7 @@ export default class Client {
|
|
|
41
46
|
.sort();
|
|
42
47
|
const usePost = config?.usePost ?? false;
|
|
43
48
|
if (usePost) {
|
|
44
|
-
const fetchResponse = await this.axios.post(
|
|
49
|
+
const fetchResponse = await this.axios.post(this.baseURL, players, {
|
|
45
50
|
cache: config?.cache ?? { ttl: 15 * 60 * 1000 },
|
|
46
51
|
});
|
|
47
52
|
if (!Array.isArray(fetchResponse?.data))
|
|
@@ -81,7 +86,7 @@ export default class Client {
|
|
|
81
86
|
try {
|
|
82
87
|
if (this.shouldValidate(config) && !validatePlayer(player, this.getValidationMinLength(config)))
|
|
83
88
|
return { data: null, error: "INVALID_INPUT" };
|
|
84
|
-
const fetchResponse = await this.axios.get(
|
|
89
|
+
const fetchResponse = await this.axios.get(`${this.baseURL}/${player}`, {
|
|
85
90
|
cache: config?.cache ?? { ttl: 15 * 60 * 1000 },
|
|
86
91
|
});
|
|
87
92
|
return {
|
|
@@ -159,7 +164,7 @@ export default class Client {
|
|
|
159
164
|
if (!UUID)
|
|
160
165
|
return { data: null, error: "INVALID_PLAYER" };
|
|
161
166
|
return await this.axios
|
|
162
|
-
.get(
|
|
167
|
+
.get(`${this.baseURL}/session/minecraft/profile/${UUID}`, {
|
|
163
168
|
cache: config?.cache ?? { ttl: 15 * 60 * 1000 },
|
|
164
169
|
})
|
|
165
170
|
.then((fetchResponse) => {
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mowojang",
|
|
3
|
-
"version": "0.4.
|
|
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
32
|
"@types/node": "^25.9.1",
|
|
32
|
-
"typescript": "^
|
|
33
|
+
"typescript": "^6.0.3"
|
|
33
34
|
},
|
|
34
35
|
"scripts": {
|
|
35
36
|
"build": "pnpm tsc",
|