mowojang 0.5.1 → 0.6.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/dist/index.d.ts +2 -0
- package/dist/index.js +25 -52
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -112,6 +112,8 @@ declare class Client {
|
|
|
112
112
|
constructor(clientOptions?: ClientOptions);
|
|
113
113
|
private shouldValidate;
|
|
114
114
|
private getValidationMinLength;
|
|
115
|
+
private getProfileCacheID;
|
|
116
|
+
private mirrorProfileCacheEntries;
|
|
115
117
|
/**
|
|
116
118
|
* Returns an Array of Player Profiles consisting of their Usernames and UUIDs
|
|
117
119
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
|
+
// <define:VERSION>
|
|
5
|
+
var define_VERSION_default = ["0.6.0"];
|
|
6
|
+
|
|
4
7
|
// src/utils.ts
|
|
5
8
|
var undashUUID = /* @__PURE__ */ __name((UUID) => UUID.replace(/-/g, "").toLowerCase(), "undashUUID");
|
|
6
9
|
var dashUUID = /* @__PURE__ */ __name((UUID) => undashUUID(UUID).replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5"), "dashUUID");
|
|
@@ -33,64 +36,13 @@ import { isAxiosError } from "axios";
|
|
|
33
36
|
// src/axiosInstance.ts
|
|
34
37
|
import axios from "axios";
|
|
35
38
|
import { setupCache } from "axios-cache-interceptor";
|
|
36
|
-
|
|
37
|
-
// package.json
|
|
38
|
-
var package_default = {
|
|
39
|
-
name: "mowojang",
|
|
40
|
-
version: "0.5.1",
|
|
41
|
-
description: "A simple TypeScript compatible wrapper for the Mowojang-API.",
|
|
42
|
-
exports: {
|
|
43
|
-
".": {
|
|
44
|
-
types: "./dist/index.d.ts",
|
|
45
|
-
import: "./dist/index.js"
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
files: [
|
|
49
|
-
"dist"
|
|
50
|
-
],
|
|
51
|
-
type: "module",
|
|
52
|
-
scripts: {
|
|
53
|
-
build: "tsup",
|
|
54
|
-
test: "node test test/index.js",
|
|
55
|
-
"prettier:check": "pnpm dlx prettier . --check",
|
|
56
|
-
"prettier:write": "pnpm dlx prettier . --write",
|
|
57
|
-
prepare: "pnpm build"
|
|
58
|
-
},
|
|
59
|
-
repository: {
|
|
60
|
-
type: "git",
|
|
61
|
-
url: "https://github.com/Pixelicc/mowojang"
|
|
62
|
-
},
|
|
63
|
-
keywords: [
|
|
64
|
-
"Minecraft",
|
|
65
|
-
"Mowojang",
|
|
66
|
-
"Wrapper",
|
|
67
|
-
"API"
|
|
68
|
-
],
|
|
69
|
-
author: "Pixelic",
|
|
70
|
-
license: "MIT",
|
|
71
|
-
engines: {
|
|
72
|
-
node: ">=22.0.0"
|
|
73
|
-
},
|
|
74
|
-
dependencies: {
|
|
75
|
-
axios: "^1.16.1",
|
|
76
|
-
"axios-cache-interceptor": "^1.12.0"
|
|
77
|
-
},
|
|
78
|
-
devDependencies: {
|
|
79
|
-
"@pixelic/logger": "jsr:~0.2.0",
|
|
80
|
-
"@types/node": "^25.9.1",
|
|
81
|
-
tsup: "^8.5.1",
|
|
82
|
-
typescript: "^6.0.3"
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// src/axiosInstance.ts
|
|
87
39
|
var axiosInstance_default = /* @__PURE__ */ __name((options, logger) => {
|
|
88
40
|
const instance = setupCache(
|
|
89
41
|
axios.create({
|
|
90
42
|
timeout: options?.timeout ?? 1e4,
|
|
91
43
|
maxRedirects: 0,
|
|
92
44
|
headers: {
|
|
93
|
-
"User-Agent": `axios/${axios.VERSION} mowojang/${
|
|
45
|
+
"User-Agent": `axios/${axios.VERSION} mowojang/${define_VERSION_default[0]} (https://www.npmjs.com/package/mowojang)`,
|
|
94
46
|
Accept: "application/json"
|
|
95
47
|
}
|
|
96
48
|
}),
|
|
@@ -313,6 +265,23 @@ var Client = class {
|
|
|
313
265
|
getValidationMinLength(config) {
|
|
314
266
|
return this.validation?.minimumUsernameLength ?? config?.validation?.minimumUsernameLength;
|
|
315
267
|
}
|
|
268
|
+
getProfileCacheID(player) {
|
|
269
|
+
const normalizedPlayer = validateUUID(player) ? `uuid:${undashUUID(player).toLowerCase()}` : `username:${player.toLowerCase()}`;
|
|
270
|
+
return `profile:${normalizedPlayer}`;
|
|
271
|
+
}
|
|
272
|
+
async mirrorProfileCacheEntries(ID, username, UUID) {
|
|
273
|
+
try {
|
|
274
|
+
const storage = this.axios.storage;
|
|
275
|
+
if (!storage.get || !storage.set) return;
|
|
276
|
+
const value = await storage.get(ID);
|
|
277
|
+
if (!value) return;
|
|
278
|
+
const usernameID = this.getProfileCacheID(username);
|
|
279
|
+
const uuidID = this.getProfileCacheID(UUID);
|
|
280
|
+
if (ID !== usernameID) await storage.set(usernameID, value);
|
|
281
|
+
if (ID !== uuidID) await storage.set(uuidID, value);
|
|
282
|
+
} catch {
|
|
283
|
+
}
|
|
284
|
+
}
|
|
316
285
|
/**
|
|
317
286
|
* Returns an Array of Player Profiles consisting of their Usernames and UUIDs
|
|
318
287
|
*
|
|
@@ -374,8 +343,12 @@ var Client = class {
|
|
|
374
343
|
if (this.shouldValidate(config) && !validatePlayer(player, this.getValidationMinLength(config)))
|
|
375
344
|
return { data: null, error: "INVALID_INPUT" };
|
|
376
345
|
const fetchResponse = await this.axios.get(`${this.baseURL}/${player}`, {
|
|
346
|
+
id: this.getProfileCacheID(player),
|
|
377
347
|
cache: config?.cache ?? { ttl: 60 * 60 * 1e3 }
|
|
378
348
|
});
|
|
349
|
+
if (config?.cache !== false && (typeof config?.cache !== "object" || config.cache.enabled !== false)) {
|
|
350
|
+
await this.mirrorProfileCacheEntries(fetchResponse.id, fetchResponse.data.name, fetchResponse.data.id);
|
|
351
|
+
}
|
|
379
352
|
return {
|
|
380
353
|
data: {
|
|
381
354
|
UUID: fetchResponse.data.id,
|