mowojang 0.5.0 → 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 +23 -1
- package/dist/index.js +47 -54
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ type Username = string;
|
|
|
16
16
|
/**
|
|
17
17
|
* Minecraft UUIDv4 (both undashed and dashed will be accepted)
|
|
18
18
|
*
|
|
19
|
-
* @example
|
|
19
|
+
* @example 14727fae-fbdc-4aff-848c-d2713eb9939e
|
|
20
20
|
*/
|
|
21
21
|
type UUID = string;
|
|
22
22
|
|
|
@@ -112,11 +112,15 @@ 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
|
*
|
|
118
120
|
* Players considered "INVALID" are excluded from the results
|
|
119
121
|
*
|
|
122
|
+
* Default cache TTL: 1 hour when config.cache is not provided.
|
|
123
|
+
*
|
|
120
124
|
* @example
|
|
121
125
|
* ```TS
|
|
122
126
|
* const profiles = await client.getProfiles(["Pixelic", "14727faefbdc4aff848cd2713eb9939e"]);
|
|
@@ -128,6 +132,8 @@ declare class Client {
|
|
|
128
132
|
/**
|
|
129
133
|
* Returns a Player's Profile consisting of their Username and UUID
|
|
130
134
|
*
|
|
135
|
+
* Default cache TTL: 1 hour when config.cache is not provided.
|
|
136
|
+
*
|
|
131
137
|
* @example
|
|
132
138
|
* ```TS
|
|
133
139
|
* const profile = await client.getProfile("Pixelic");
|
|
@@ -137,6 +143,8 @@ declare class Client {
|
|
|
137
143
|
/**
|
|
138
144
|
* A simple Wrapper to retrieve only the UUID of a Player's Profile
|
|
139
145
|
*
|
|
146
|
+
* Uses getProfile cache behavior (default TTL: 1 hour when config.cache is not provided).
|
|
147
|
+
*
|
|
140
148
|
* @example
|
|
141
149
|
* ```TS
|
|
142
150
|
* const uuid = await client.getUUID("Pixelic");
|
|
@@ -146,6 +154,8 @@ declare class Client {
|
|
|
146
154
|
/**
|
|
147
155
|
* A simple Wrapper to retrieve only the Username of a Player's Profile
|
|
148
156
|
*
|
|
157
|
+
* Uses getProfile cache behavior (default TTL: 1 hour when config.cache is not provided).
|
|
158
|
+
*
|
|
149
159
|
* @example
|
|
150
160
|
* ```TS
|
|
151
161
|
* const username = await client.getUsername("14727faefbdc4aff848cd2713eb9939e");
|
|
@@ -157,6 +167,8 @@ declare class Client {
|
|
|
157
167
|
*
|
|
158
168
|
* Players considered "INVALID" are excluded from the results
|
|
159
169
|
*
|
|
170
|
+
* Uses getSession cache behavior (default TTL: 15 minutes when config.cache is not provided).
|
|
171
|
+
*
|
|
160
172
|
* @example
|
|
161
173
|
* ```TS
|
|
162
174
|
* const sessions = await client.getSessions(["Pixelic", "14727faefbdc4aff848cd2713eb9939e"]);
|
|
@@ -166,6 +178,8 @@ declare class Client {
|
|
|
166
178
|
/**
|
|
167
179
|
* Returns a Player's Sessions consisting of their Username, UUID, Skin and Cape
|
|
168
180
|
*
|
|
181
|
+
* Default cache TTL: 15 minutes when config.cache is not provided.
|
|
182
|
+
*
|
|
169
183
|
* @example
|
|
170
184
|
* ```TS
|
|
171
185
|
* const session = await client.getSession("Pixelic");
|
|
@@ -175,6 +189,8 @@ declare class Client {
|
|
|
175
189
|
/**
|
|
176
190
|
* A simple Wrapper to retrieve only the Skin from a Player's Session
|
|
177
191
|
*
|
|
192
|
+
* Uses getSession cache behavior (default TTL: 15 minutes when config.cache is not provided).
|
|
193
|
+
*
|
|
178
194
|
* @example
|
|
179
195
|
* ```TS
|
|
180
196
|
* const skin = await client.getSkin("Pixelic");
|
|
@@ -184,6 +200,8 @@ declare class Client {
|
|
|
184
200
|
/**
|
|
185
201
|
* A simple Wrapper to retrieve only the Player's Skin from their Session Data loaded into a Buffer
|
|
186
202
|
*
|
|
203
|
+
* Default cache TTL for the skin image request: 24 hours when config.cache is not provided.
|
|
204
|
+
*
|
|
187
205
|
* @example
|
|
188
206
|
* ```TS
|
|
189
207
|
* const skinBuffer = await client.getSkinBuffer("Pixelic");
|
|
@@ -193,6 +211,8 @@ declare class Client {
|
|
|
193
211
|
/**
|
|
194
212
|
* A simple Wrapper to retrieve only the Cape Data from a Player's Session
|
|
195
213
|
*
|
|
214
|
+
* Uses getSession cache behavior (default TTL: 15 minutes when config.cache is not provided).
|
|
215
|
+
*
|
|
196
216
|
* @example
|
|
197
217
|
* ```TS
|
|
198
218
|
* const cape = await client.getCape("Pixelic");
|
|
@@ -202,6 +222,8 @@ declare class Client {
|
|
|
202
222
|
/**
|
|
203
223
|
* A simple Wrapper to retrieve only the Player's Cape from their Session Data loaded into a Buffer
|
|
204
224
|
*
|
|
225
|
+
* Default cache TTL for the cape image request: 30 days when config.cache is not provided.
|
|
226
|
+
*
|
|
205
227
|
* @example
|
|
206
228
|
* ```TS
|
|
207
229
|
* const capeBuffer = await client.getCapeBuffer("Pixelic");
|
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.0",
|
|
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,11 +265,30 @@ 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
|
*
|
|
319
288
|
* Players considered "INVALID" are excluded from the results
|
|
320
289
|
*
|
|
290
|
+
* Default cache TTL: 1 hour when config.cache is not provided.
|
|
291
|
+
*
|
|
321
292
|
* @example
|
|
322
293
|
* ```TS
|
|
323
294
|
* const profiles = await client.getProfiles(["Pixelic", "14727faefbdc4aff848cd2713eb9939e"]);
|
|
@@ -334,7 +305,7 @@ var Client = class {
|
|
|
334
305
|
const usePost = config?.usePost ?? false;
|
|
335
306
|
if (usePost) {
|
|
336
307
|
const fetchResponse = await this.axios.post(this.baseURL, players, {
|
|
337
|
-
cache: config?.cache ?? { ttl:
|
|
308
|
+
cache: config?.cache ?? { ttl: 60 * 60 * 1e3 }
|
|
338
309
|
});
|
|
339
310
|
if (!Array.isArray(fetchResponse?.data)) return { data: null, error: "UNKNOWN_ERROR" };
|
|
340
311
|
return {
|
|
@@ -360,6 +331,8 @@ var Client = class {
|
|
|
360
331
|
/**
|
|
361
332
|
* Returns a Player's Profile consisting of their Username and UUID
|
|
362
333
|
*
|
|
334
|
+
* Default cache TTL: 1 hour when config.cache is not provided.
|
|
335
|
+
*
|
|
363
336
|
* @example
|
|
364
337
|
* ```TS
|
|
365
338
|
* const profile = await client.getProfile("Pixelic");
|
|
@@ -370,8 +343,12 @@ var Client = class {
|
|
|
370
343
|
if (this.shouldValidate(config) && !validatePlayer(player, this.getValidationMinLength(config)))
|
|
371
344
|
return { data: null, error: "INVALID_INPUT" };
|
|
372
345
|
const fetchResponse = await this.axios.get(`${this.baseURL}/${player}`, {
|
|
373
|
-
|
|
346
|
+
id: this.getProfileCacheID(player),
|
|
347
|
+
cache: config?.cache ?? { ttl: 60 * 60 * 1e3 }
|
|
374
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
|
+
}
|
|
375
352
|
return {
|
|
376
353
|
data: {
|
|
377
354
|
UUID: fetchResponse.data.id,
|
|
@@ -386,6 +363,8 @@ var Client = class {
|
|
|
386
363
|
/**
|
|
387
364
|
* A simple Wrapper to retrieve only the UUID of a Player's Profile
|
|
388
365
|
*
|
|
366
|
+
* Uses getProfile cache behavior (default TTL: 1 hour when config.cache is not provided).
|
|
367
|
+
*
|
|
389
368
|
* @example
|
|
390
369
|
* ```TS
|
|
391
370
|
* const uuid = await client.getUUID("Pixelic");
|
|
@@ -399,6 +378,8 @@ var Client = class {
|
|
|
399
378
|
/**
|
|
400
379
|
* A simple Wrapper to retrieve only the Username of a Player's Profile
|
|
401
380
|
*
|
|
381
|
+
* Uses getProfile cache behavior (default TTL: 1 hour when config.cache is not provided).
|
|
382
|
+
*
|
|
402
383
|
* @example
|
|
403
384
|
* ```TS
|
|
404
385
|
* const username = await client.getUsername("14727faefbdc4aff848cd2713eb9939e");
|
|
@@ -414,6 +395,8 @@ var Client = class {
|
|
|
414
395
|
*
|
|
415
396
|
* Players considered "INVALID" are excluded from the results
|
|
416
397
|
*
|
|
398
|
+
* Uses getSession cache behavior (default TTL: 15 minutes when config.cache is not provided).
|
|
399
|
+
*
|
|
417
400
|
* @example
|
|
418
401
|
* ```TS
|
|
419
402
|
* const sessions = await client.getSessions(["Pixelic", "14727faefbdc4aff848cd2713eb9939e"]);
|
|
@@ -440,6 +423,8 @@ var Client = class {
|
|
|
440
423
|
/**
|
|
441
424
|
* Returns a Player's Sessions consisting of their Username, UUID, Skin and Cape
|
|
442
425
|
*
|
|
426
|
+
* Default cache TTL: 15 minutes when config.cache is not provided.
|
|
427
|
+
*
|
|
443
428
|
* @example
|
|
444
429
|
* ```TS
|
|
445
430
|
* const session = await client.getSession("Pixelic");
|
|
@@ -494,6 +479,8 @@ var Client = class {
|
|
|
494
479
|
/**
|
|
495
480
|
* A simple Wrapper to retrieve only the Skin from a Player's Session
|
|
496
481
|
*
|
|
482
|
+
* Uses getSession cache behavior (default TTL: 15 minutes when config.cache is not provided).
|
|
483
|
+
*
|
|
497
484
|
* @example
|
|
498
485
|
* ```TS
|
|
499
486
|
* const skin = await client.getSkin("Pixelic");
|
|
@@ -507,6 +494,8 @@ var Client = class {
|
|
|
507
494
|
/**
|
|
508
495
|
* A simple Wrapper to retrieve only the Player's Skin from their Session Data loaded into a Buffer
|
|
509
496
|
*
|
|
497
|
+
* Default cache TTL for the skin image request: 24 hours when config.cache is not provided.
|
|
498
|
+
*
|
|
510
499
|
* @example
|
|
511
500
|
* ```TS
|
|
512
501
|
* const skinBuffer = await client.getSkinBuffer("Pixelic");
|
|
@@ -524,6 +513,8 @@ var Client = class {
|
|
|
524
513
|
/**
|
|
525
514
|
* A simple Wrapper to retrieve only the Cape Data from a Player's Session
|
|
526
515
|
*
|
|
516
|
+
* Uses getSession cache behavior (default TTL: 15 minutes when config.cache is not provided).
|
|
517
|
+
*
|
|
527
518
|
* @example
|
|
528
519
|
* ```TS
|
|
529
520
|
* const cape = await client.getCape("Pixelic");
|
|
@@ -537,6 +528,8 @@ var Client = class {
|
|
|
537
528
|
/**
|
|
538
529
|
* A simple Wrapper to retrieve only the Player's Cape from their Session Data loaded into a Buffer
|
|
539
530
|
*
|
|
531
|
+
* Default cache TTL for the cape image request: 30 days when config.cache is not provided.
|
|
532
|
+
*
|
|
540
533
|
* @example
|
|
541
534
|
* ```TS
|
|
542
535
|
* const capeBuffer = await client.getCapeBuffer("Pixelic");
|