mowojang 0.5.1 → 0.6.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/dist/index.d.ts +49 -34
- package/dist/index.js +45 -52
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -7,12 +7,14 @@ import { LoggerConfig } from '@pixelic/logger';
|
|
|
7
7
|
* @example "Technoblade" or "b876ec32-e396-476b-a115-8438d83c67d4"
|
|
8
8
|
*/
|
|
9
9
|
type Player = string | UUID;
|
|
10
|
+
|
|
10
11
|
/**
|
|
11
12
|
* Minecraft Username
|
|
12
13
|
*
|
|
13
14
|
* @example "Pixelic"
|
|
14
15
|
*/
|
|
15
16
|
type Username = string;
|
|
17
|
+
|
|
16
18
|
/**
|
|
17
19
|
* Minecraft UUIDv4 (both undashed and dashed will be accepted)
|
|
18
20
|
*
|
|
@@ -34,56 +36,67 @@ type UUID = string;
|
|
|
34
36
|
* ```
|
|
35
37
|
*/
|
|
36
38
|
type ClientOptions = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
logger?: LoggerConfig;
|
|
40
|
+
validation?: ValidationOptions;
|
|
41
|
+
timeout?: number;
|
|
42
|
+
cache?: CacheOptions;
|
|
43
|
+
baseURL?: string;
|
|
44
|
+
fallback?: boolean;
|
|
43
45
|
};
|
|
46
|
+
|
|
44
47
|
type AxiosOptions = {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
timeout?: number;
|
|
49
|
+
cache?: CacheOptions;
|
|
50
|
+
fallback: boolean;
|
|
48
51
|
};
|
|
52
|
+
|
|
49
53
|
type ValidationOptions = {
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
enabled?: boolean;
|
|
55
|
+
minimumUsernameLength?: 1 | 2;
|
|
52
56
|
};
|
|
57
|
+
|
|
53
58
|
type MowojangRequestConfig = {
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
validation?: ValidationOptions;
|
|
60
|
+
cache?: CacheRequestConfig<any, any>["cache"];
|
|
56
61
|
};
|
|
62
|
+
|
|
57
63
|
type MowojangError = "INVALID_PLAYER";
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
|
|
65
|
+
type MowojangResponse<D, E extends MowojangError | undefined> = Promise<
|
|
66
|
+
| {
|
|
67
|
+
data: D;
|
|
68
|
+
error: null;
|
|
69
|
+
}
|
|
70
|
+
| {
|
|
71
|
+
data: null;
|
|
72
|
+
error: E extends undefined ? "UNKNOWN_ERROR" | "INVALID_INPUT" : E | "UNKNOWN_ERROR" | "INVALID_INPUT";
|
|
73
|
+
}
|
|
74
|
+
>;
|
|
65
75
|
|
|
66
76
|
type MowojangProfile = {
|
|
67
|
-
|
|
68
|
-
|
|
77
|
+
UUID: UUID;
|
|
78
|
+
username: Username;
|
|
69
79
|
};
|
|
80
|
+
|
|
70
81
|
type MowojangSession = {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
82
|
+
UUID: UUID;
|
|
83
|
+
username: Username;
|
|
84
|
+
skin: MowojangSkin;
|
|
85
|
+
cape: MowojangCape;
|
|
86
|
+
actions: ("FORCED_NAME_CHANGE" | "USING_BANNED_SKIN")[];
|
|
76
87
|
};
|
|
88
|
+
|
|
77
89
|
type MowojangSkin = null | {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
90
|
+
url: string;
|
|
91
|
+
hash: string;
|
|
92
|
+
metadata: {
|
|
93
|
+
slim: boolean;
|
|
94
|
+
};
|
|
83
95
|
};
|
|
96
|
+
|
|
84
97
|
type MowojangCape = null | {
|
|
85
|
-
|
|
86
|
-
|
|
98
|
+
url: string;
|
|
99
|
+
hash: string;
|
|
87
100
|
};
|
|
88
101
|
|
|
89
102
|
declare class Client {
|
|
@@ -112,6 +125,8 @@ declare class Client {
|
|
|
112
125
|
constructor(clientOptions?: ClientOptions);
|
|
113
126
|
private shouldValidate;
|
|
114
127
|
private getValidationMinLength;
|
|
128
|
+
private getProfileCacheID;
|
|
129
|
+
private mirrorProfileCacheEntries;
|
|
115
130
|
/**
|
|
116
131
|
* Returns an Array of Player Profiles consisting of their Usernames and UUIDs
|
|
117
132
|
*
|
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.1"];
|
|
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,37 @@ 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, internalId) {
|
|
273
|
+
try {
|
|
274
|
+
const storage = this.axios.storage;
|
|
275
|
+
if (!storage.get || !storage.set) {
|
|
276
|
+
this.logger.warning(
|
|
277
|
+
"Mowojang",
|
|
278
|
+
`No Storage Methods available or set up for Profile Mirror to work with`,
|
|
279
|
+
internalId
|
|
280
|
+
);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const value = await storage.get(ID);
|
|
284
|
+
if (!value) return;
|
|
285
|
+
const usernameID = this.getProfileCacheID(username);
|
|
286
|
+
const uuidID = this.getProfileCacheID(UUID);
|
|
287
|
+
if (ID !== usernameID) {
|
|
288
|
+
await storage.set(usernameID, value);
|
|
289
|
+
this.logger.debug("Mowojang", `PROFILE-CACHE-MIRROR-SET ${ID} -> ${usernameID}`, internalId);
|
|
290
|
+
}
|
|
291
|
+
if (ID !== uuidID) {
|
|
292
|
+
await storage.set(uuidID, value);
|
|
293
|
+
this.logger.debug("Mowojang", `PROFILE-CACHE-MIRROR-SET ${ID} -> ${uuidID}`, internalId);
|
|
294
|
+
}
|
|
295
|
+
} catch (error) {
|
|
296
|
+
this.logger.error("Mowojang", error instanceof Error ? error.message : "Unknown Error", internalId);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
316
299
|
/**
|
|
317
300
|
* Returns an Array of Player Profiles consisting of their Usernames and UUIDs
|
|
318
301
|
*
|
|
@@ -374,8 +357,18 @@ var Client = class {
|
|
|
374
357
|
if (this.shouldValidate(config) && !validatePlayer(player, this.getValidationMinLength(config)))
|
|
375
358
|
return { data: null, error: "INVALID_INPUT" };
|
|
376
359
|
const fetchResponse = await this.axios.get(`${this.baseURL}/${player}`, {
|
|
360
|
+
id: this.getProfileCacheID(player),
|
|
377
361
|
cache: config?.cache ?? { ttl: 60 * 60 * 1e3 }
|
|
378
362
|
});
|
|
363
|
+
if (config?.cache !== false && (typeof config?.cache !== "object" || config.cache.enabled !== false)) {
|
|
364
|
+
const internalId = fetchResponse.config?.internalId;
|
|
365
|
+
await this.mirrorProfileCacheEntries(
|
|
366
|
+
fetchResponse.id,
|
|
367
|
+
fetchResponse.data.name,
|
|
368
|
+
fetchResponse.data.id,
|
|
369
|
+
internalId
|
|
370
|
+
);
|
|
371
|
+
}
|
|
379
372
|
return {
|
|
380
373
|
data: {
|
|
381
374
|
UUID: fetchResponse.data.id,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mowojang",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "A simple TypeScript compatible wrapper for the Mowojang-API.",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@pixelic/logger": "npm:@jsr/pixelic__logger@~0.2.0",
|
|
36
|
-
"@types/node": "^
|
|
36
|
+
"@types/node": "^26.1.2",
|
|
37
37
|
"tsup": "^8.5.1",
|
|
38
38
|
"typescript": "^6.0.3"
|
|
39
39
|
},
|