mowojang 0.4.1 → 0.4.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 +16 -0
- package/dist/package.json +3 -3
- package/dist/src/axiosInstance.js +29 -9
- package/dist/src/client.js +2 -2
- package/dist/types/misc.d.ts +4 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -18,6 +18,22 @@ const UUID = await Mowojang.getUUID("Pixelic")
|
|
|
18
18
|
const username = await Mowojang.getUsername("14727fae-fbdc-4aff-848c-d2713eb9939e")
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
## ⚙️ Configuration
|
|
22
|
+
|
|
23
|
+
The `Client` constructor accepts an **optional** configuration object.
|
|
24
|
+
|
|
25
|
+
```TS
|
|
26
|
+
const Mowojang = new MowojangClient({
|
|
27
|
+
baseURL: "https://mowojang.matdoes.dev", // The base URL for the Mowojang API
|
|
28
|
+
fallback: true, // Whether to fallback to mowojang.seraph.si if the default baseURL is down
|
|
29
|
+
timeout: 10000, // Request timeout in milliseconds
|
|
30
|
+
validation: {
|
|
31
|
+
enabled: true, // Enable automatic validation for inputs (UUIDs and Usernames)
|
|
32
|
+
minimumUsernameLength: 1, // Minimum username length required to pass validation (1 or 2), default is 3.
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
21
37
|
> [!TIP]
|
|
22
38
|
> 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
39
|
> Guide: [Custom-Caching](docs/custom-caching.md)
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mowojang",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.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",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@pixelic/logger": "npm:@jsr/pixelic__logger@^0.0.6",
|
|
35
|
-
"axios": "^1.
|
|
36
|
-
"axios-cache-interceptor": "^1.
|
|
35
|
+
"axios": "^1.16.1",
|
|
36
|
+
"axios-cache-interceptor": "^1.12.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^25.9.1",
|
|
@@ -18,7 +18,7 @@ export default (options, logger) => {
|
|
|
18
18
|
// @ts-expect-error
|
|
19
19
|
req.internalId = Math.random().toString(16).slice(2, 10).padEnd(8, "0");
|
|
20
20
|
// @ts-expect-error
|
|
21
|
-
logger.debug("
|
|
21
|
+
logger.debug("Mowojang", `(${req.internalId}) ${req.method?.toUpperCase()} ${axios.getUri(req)}`);
|
|
22
22
|
return req;
|
|
23
23
|
});
|
|
24
24
|
instance.interceptors.response.use((res) => {
|
|
@@ -29,17 +29,37 @@ export default (options, logger) => {
|
|
|
29
29
|
}
|
|
30
30
|
return res;
|
|
31
31
|
}, (err) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
const isConnectionError = err.code === "ECONNRESET" || err.code === "ETIMEDOUT" || (err?.response?.status ?? 0) >= 500;
|
|
33
|
+
if (isConnectionError) {
|
|
34
|
+
const fullURL = axios.getUri(err.config);
|
|
35
|
+
const host = new URL(fullURL).host;
|
|
36
|
+
/**
|
|
37
|
+
* If Mowojang (mowojang.matdoes.dev) is down, this falls back to Seraph (mowojang.seraph.si).
|
|
38
|
+
* This gets ignored if a different `baseURL` is passed in the initial config.
|
|
39
|
+
*/
|
|
40
|
+
if (host === "mowojang.matdoes.dev" && !err.config._retry) {
|
|
41
|
+
err.config._retry = true;
|
|
42
|
+
err.config.url = fullURL.replace("mowojang.matdoes.dev", "mowojang.seraph.si");
|
|
43
|
+
if (err.config.baseURL)
|
|
44
|
+
delete err.config.baseURL;
|
|
45
|
+
logger.critical("Mowojang", `(${err.config.internalId}) Failed to establish connection to mowojang.matdoes.dev`);
|
|
46
|
+
if (options.fallback) {
|
|
47
|
+
logger.info("Mowojang", `(${err.config.internalId}) Retrying request with fallback of mowojang.seraph.si`);
|
|
48
|
+
}
|
|
49
|
+
logger.info("Mowojang", `Check Status of Mowojang on: https://mowojang-status.pixelic.dev`);
|
|
50
|
+
if (options.fallback)
|
|
51
|
+
return instance(err.config);
|
|
37
52
|
}
|
|
38
53
|
else if (host === "mowojang.seraph.si") {
|
|
39
|
-
|
|
54
|
+
logger.critical("Mowojang", `(${err.config.internalId}) Failed to establish connection to mowojang.seraph.si`);
|
|
55
|
+
logger.info("Mowojang", `Check Status of Seraph on: https://mowojang-status.pixelic.dev`);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
/**
|
|
59
|
+
* Logging fallback for a different `baseURL` passed in the initial config.
|
|
60
|
+
*/
|
|
61
|
+
logger.critical("Mowojang", `(${err.config.internalId}) Failed to establish connection to ${host}`);
|
|
40
62
|
}
|
|
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
63
|
}
|
|
44
64
|
return Promise.reject(err);
|
|
45
65
|
});
|
package/dist/src/client.js
CHANGED
|
@@ -10,9 +10,9 @@ export default class Client {
|
|
|
10
10
|
baseURL;
|
|
11
11
|
constructor(clientOptions) {
|
|
12
12
|
this.logger = new Logger(clientOptions?.logger);
|
|
13
|
-
this.axios = axiosInstance(clientOptions ?? {}, this.logger);
|
|
14
13
|
this.validation = clientOptions?.validation ?? {};
|
|
15
|
-
this.baseURL = clientOptions?.baseURL ?? "https://mowojang.matdoes.dev";
|
|
14
|
+
this.baseURL = (clientOptions?.baseURL ?? "https://mowojang.matdoes.dev").toLowerCase();
|
|
15
|
+
this.axios = axiosInstance({ fallback: true, ...clientOptions }, this.logger);
|
|
16
16
|
}
|
|
17
17
|
shouldValidate(config) {
|
|
18
18
|
return this.validation?.enabled || config?.validation?.enabled || false;
|
package/dist/types/misc.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { LoggerConfig } from "@pixelic/logger";
|
|
2
2
|
import type { CacheOptions, CacheRequestConfig } from "axios-cache-interceptor";
|
|
3
3
|
export type ClientOptions = {
|
|
4
|
-
|
|
4
|
+
logger?: LoggerConfig;
|
|
5
5
|
validation?: ValidationOptions;
|
|
6
|
+
timeout?: number;
|
|
6
7
|
cache?: CacheOptions;
|
|
7
8
|
baseURL?: string;
|
|
8
|
-
|
|
9
|
+
fallback?: boolean;
|
|
9
10
|
};
|
|
10
11
|
export type AxiosOptions = {
|
|
11
12
|
timeout?: number;
|
|
12
13
|
cache?: CacheOptions;
|
|
14
|
+
fallback: boolean;
|
|
13
15
|
};
|
|
14
16
|
export type ValidationOptions = {
|
|
15
17
|
enabled?: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mowojang",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.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",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@pixelic/logger": "npm:@jsr/pixelic__logger@^0.0.6",
|
|
28
|
-
"axios": "^1.
|
|
29
|
-
"axios-cache-interceptor": "^1.
|
|
28
|
+
"axios": "^1.16.1",
|
|
29
|
+
"axios-cache-interceptor": "^1.12.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "^25.9.1",
|