mowojang 0.6.0 → 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 +47 -34
- package/dist/index.js +27 -7
- 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 {
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// <define:VERSION>
|
|
5
|
-
var define_VERSION_default = ["0.6.
|
|
5
|
+
var define_VERSION_default = ["0.6.1"];
|
|
6
6
|
|
|
7
7
|
// src/utils.ts
|
|
8
8
|
var undashUUID = /* @__PURE__ */ __name((UUID) => UUID.replace(/-/g, "").toLowerCase(), "undashUUID");
|
|
@@ -269,17 +269,31 @@ var Client = class {
|
|
|
269
269
|
const normalizedPlayer = validateUUID(player) ? `uuid:${undashUUID(player).toLowerCase()}` : `username:${player.toLowerCase()}`;
|
|
270
270
|
return `profile:${normalizedPlayer}`;
|
|
271
271
|
}
|
|
272
|
-
async mirrorProfileCacheEntries(ID, username, UUID) {
|
|
272
|
+
async mirrorProfileCacheEntries(ID, username, UUID, internalId) {
|
|
273
273
|
try {
|
|
274
274
|
const storage = this.axios.storage;
|
|
275
|
-
if (!storage.get || !storage.set)
|
|
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
|
+
}
|
|
276
283
|
const value = await storage.get(ID);
|
|
277
284
|
if (!value) return;
|
|
278
285
|
const usernameID = this.getProfileCacheID(username);
|
|
279
286
|
const uuidID = this.getProfileCacheID(UUID);
|
|
280
|
-
if (ID !== usernameID)
|
|
281
|
-
|
|
282
|
-
|
|
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);
|
|
283
297
|
}
|
|
284
298
|
}
|
|
285
299
|
/**
|
|
@@ -347,7 +361,13 @@ var Client = class {
|
|
|
347
361
|
cache: config?.cache ?? { ttl: 60 * 60 * 1e3 }
|
|
348
362
|
});
|
|
349
363
|
if (config?.cache !== false && (typeof config?.cache !== "object" || config.cache.enabled !== false)) {
|
|
350
|
-
|
|
364
|
+
const internalId = fetchResponse.config?.internalId;
|
|
365
|
+
await this.mirrorProfileCacheEntries(
|
|
366
|
+
fetchResponse.id,
|
|
367
|
+
fetchResponse.data.name,
|
|
368
|
+
fetchResponse.data.id,
|
|
369
|
+
internalId
|
|
370
|
+
);
|
|
351
371
|
}
|
|
352
372
|
return {
|
|
353
373
|
data: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mowojang",
|
|
3
|
-
"version": "0.6.
|
|
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
|
},
|