mowojang 0.4.9 → 0.5.0
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 +2 -5
- package/dist/index.js +16 -31
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -6,9 +6,6 @@
|
|
|
6
6
|

|
|
7
7
|

|
|
8
8
|
|
|
9
|
-
> [!IMPORTANT]
|
|
10
|
-
> This is a third party wrapper for the [Mowojang](https://mowojang.matdoes.dev/) API!
|
|
11
|
-
|
|
12
9
|
## ✨ Quick Start
|
|
13
10
|
|
|
14
11
|
```TS
|
|
@@ -87,10 +84,10 @@ You can also use this package from the CLI using [mowojang-cli](https://www.npmj
|
|
|
87
84
|
|
|
88
85
|
- Mowojang Creator (Mat): [Website](https://matdoes.dev), [GitHub](https://github.com/mat-1) or [Ko-Fi](https://ko-fi.com/matdoesdev)
|
|
89
86
|
|
|
90
|
-
## 📡 [
|
|
87
|
+
## 📡 [Status](https://mowojang-status.pixelic.dev/)
|
|
91
88
|
|
|
92
89
|
<details>
|
|
93
|
-
<summary>Show
|
|
90
|
+
<summary>Show badges</summary>
|
|
94
91
|
|
|
95
92
|
- Mowojang API - GET /:username ->  
|
|
96
93
|
- Mowojang API - GET /:UUID ->  
|
package/dist/index.js
CHANGED
|
@@ -37,8 +37,8 @@ import { setupCache } from "axios-cache-interceptor";
|
|
|
37
37
|
// package.json
|
|
38
38
|
var package_default = {
|
|
39
39
|
name: "mowojang",
|
|
40
|
-
version: "0.
|
|
41
|
-
description: "A simple
|
|
40
|
+
version: "0.5.0",
|
|
41
|
+
description: "A simple TypeScript compatible wrapper for the Mowojang-API.",
|
|
42
42
|
exports: {
|
|
43
43
|
".": {
|
|
44
44
|
types: "./dist/index.d.ts",
|
|
@@ -102,7 +102,7 @@ var axiosInstance_default = /* @__PURE__ */ __name((options, logger) => {
|
|
|
102
102
|
);
|
|
103
103
|
instance.interceptors.request.use((req) => {
|
|
104
104
|
req.internalId = Math.random().toString(16).slice(2, 10).padEnd(8, "0");
|
|
105
|
-
logger.debug("Mowojang",
|
|
105
|
+
logger.debug("Mowojang", `${req.method?.toUpperCase()} ${axios.getUri(req)}`, req.internalId);
|
|
106
106
|
return req;
|
|
107
107
|
});
|
|
108
108
|
instance.interceptors.response.use(
|
|
@@ -110,8 +110,9 @@ var axiosInstance_default = /* @__PURE__ */ __name((options, logger) => {
|
|
|
110
110
|
if (res.cached) {
|
|
111
111
|
logger.debug(
|
|
112
112
|
"Mowojang",
|
|
113
|
+
`${res.stale ? "GET-CACHE-STALE" : "GET-CACHE"} ${axios.getUri(res.config)}`,
|
|
113
114
|
// @ts-expect-error
|
|
114
|
-
|
|
115
|
+
res.config.internalId
|
|
115
116
|
);
|
|
116
117
|
}
|
|
117
118
|
return res;
|
|
@@ -125,23 +126,17 @@ var axiosInstance_default = /* @__PURE__ */ __name((options, logger) => {
|
|
|
125
126
|
err.config._retry = true;
|
|
126
127
|
err.config.url = fullURL.replace("mowojang.matdoes.dev", "mowojang.seraph.si");
|
|
127
128
|
if (err.config.baseURL) delete err.config.baseURL;
|
|
128
|
-
logger.critical(
|
|
129
|
-
"Mowojang",
|
|
130
|
-
`(${err.config.internalId}) Failed to establish connection to mowojang.matdoes.dev`
|
|
131
|
-
);
|
|
129
|
+
logger.critical("Mowojang", `Failed to establish connection to mowojang.matdoes.dev`, err.config.internalId);
|
|
132
130
|
if (options.fallback) {
|
|
133
|
-
logger.info("Mowojang", `
|
|
131
|
+
logger.info("Mowojang", `Retrying request with fallback of mowojang.seraph.si`, err.config.internalId);
|
|
134
132
|
}
|
|
135
133
|
logger.info("Mowojang", `Check Status of Mowojang on: https://mowojang-status.pixelic.dev`);
|
|
136
134
|
if (options.fallback) return instance(err.config);
|
|
137
135
|
} else if (host === "mowojang.seraph.si") {
|
|
138
|
-
logger.critical(
|
|
139
|
-
"Mowojang",
|
|
140
|
-
`(${err.config.internalId}) Failed to establish connection to mowojang.seraph.si`
|
|
141
|
-
);
|
|
136
|
+
logger.critical("Mowojang", `Failed to establish connection to mowojang.seraph.si`, err.config.internalId);
|
|
142
137
|
logger.info("Mowojang", `Check Status of Seraph on: https://mowojang-status.pixelic.dev`);
|
|
143
138
|
} else {
|
|
144
|
-
logger.critical("Mowojang", `
|
|
139
|
+
logger.critical("Mowojang", `Failed to establish connection to ${host}`, err.config.internalId);
|
|
145
140
|
}
|
|
146
141
|
}
|
|
147
142
|
return Promise.reject(err);
|
|
@@ -313,14 +308,10 @@ var Client = class {
|
|
|
313
308
|
this.axios = axiosInstance_default({ fallback: true, ...clientOptions }, this.logger);
|
|
314
309
|
}
|
|
315
310
|
shouldValidate(config) {
|
|
316
|
-
return this.validation?.enabled || config?.validation?.enabled
|
|
311
|
+
return Boolean(this.validation?.enabled || config?.validation?.enabled);
|
|
317
312
|
}
|
|
318
313
|
getValidationMinLength(config) {
|
|
319
|
-
|
|
320
|
-
if (this.validation?.minimumUsernameLength === 2) return 2;
|
|
321
|
-
if (config?.validation?.minimumUsernameLength === 1) return 1;
|
|
322
|
-
if (config?.validation?.minimumUsernameLength === 2) return 2;
|
|
323
|
-
return void 0;
|
|
314
|
+
return this.validation?.minimumUsernameLength ?? config?.validation?.minimumUsernameLength;
|
|
324
315
|
}
|
|
325
316
|
/**
|
|
326
317
|
* Returns an Array of Player Profiles consisting of their Usernames and UUIDs
|
|
@@ -356,10 +347,7 @@ var Client = class {
|
|
|
356
347
|
error: null
|
|
357
348
|
};
|
|
358
349
|
}
|
|
359
|
-
const profilePromises =
|
|
360
|
-
players.forEach((player) => {
|
|
361
|
-
profilePromises.push(this.getProfile(player, config));
|
|
362
|
-
});
|
|
350
|
+
const profilePromises = players.map((player) => this.getProfile(player, config));
|
|
363
351
|
const profiles = (await Promise.all(profilePromises)).filter((p) => p.data !== null).map((p) => p.data);
|
|
364
352
|
return {
|
|
365
353
|
data: profiles,
|
|
@@ -439,10 +427,7 @@ var Client = class {
|
|
|
439
427
|
if (validateUUID(player)) return undashUUID(player);
|
|
440
428
|
return player.toLowerCase();
|
|
441
429
|
});
|
|
442
|
-
const sessionsPromises =
|
|
443
|
-
players.forEach((player) => {
|
|
444
|
-
sessionsPromises.push(this.getSession(player, config));
|
|
445
|
-
});
|
|
430
|
+
const sessionsPromises = players.map((player) => this.getSession(player, config));
|
|
446
431
|
const sessions = (await Promise.all(sessionsPromises)).filter((session) => session.data !== null).map((session) => session.data);
|
|
447
432
|
return {
|
|
448
433
|
data: sessions,
|
|
@@ -463,7 +448,7 @@ var Client = class {
|
|
|
463
448
|
async getSession(player, config) {
|
|
464
449
|
if (this.shouldValidate(config) && !validatePlayer(player, this.getValidationMinLength(config)))
|
|
465
450
|
return { data: null, error: "INVALID_INPUT" };
|
|
466
|
-
const UUID = await this.getUUID(player);
|
|
451
|
+
const UUID = validateUUID(player) ? undashUUID(player) : await this.getUUID(player);
|
|
467
452
|
if (!UUID) return { data: null, error: "INVALID_PLAYER" };
|
|
468
453
|
return await this.axios.get(`${this.baseURL}/session/minecraft/profile/${UUID}`, {
|
|
469
454
|
cache: config?.cache ?? { ttl: 15 * 60 * 1e3 }
|
|
@@ -534,7 +519,7 @@ var Client = class {
|
|
|
534
519
|
responseType: "arraybuffer",
|
|
535
520
|
cache: config?.cache ?? { ttl: 24 * 60 * 60 * 1e3 }
|
|
536
521
|
});
|
|
537
|
-
return Buffer.from(fetchResponse.data
|
|
522
|
+
return Buffer.from(fetchResponse.data);
|
|
538
523
|
}
|
|
539
524
|
/**
|
|
540
525
|
* A simple Wrapper to retrieve only the Cape Data from a Player's Session
|
|
@@ -564,7 +549,7 @@ var Client = class {
|
|
|
564
549
|
responseType: "arraybuffer",
|
|
565
550
|
cache: config?.cache ?? { ttl: 30 * 24 * 60 * 60 * 1e3 }
|
|
566
551
|
});
|
|
567
|
-
return Buffer.from(fetchResponse.data
|
|
552
|
+
return Buffer.from(fetchResponse.data);
|
|
568
553
|
}
|
|
569
554
|
};
|
|
570
555
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mowojang",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A simple
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "A simple TypeScript compatible wrapper for the Mowojang-API.",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.ts",
|