mowojang 0.4.9 → 0.5.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/README.md CHANGED
@@ -6,9 +6,6 @@
6
6
  ![Publish Size](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fpackagephobia.com%2Fv2%2Fapi.json%3Fp%3Dmowojang&query=%24.publish.pretty&label=Publish%20Size)
7
7
  ![Install Size](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fpackagephobia.com%2Fv2%2Fapi.json%3Fp%3Dmowojang&query=%24.install.pretty&label=Install%20Size)
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
- ## 📡 [Mowojang Status](https://mowojang-status.pixelic.dev/)
87
+ ## 📡 [Status](https://mowojang-status.pixelic.dev/)
91
88
 
92
89
  <details>
93
- <summary>Show status badges</summary>
90
+ <summary>Show badges</summary>
94
91
 
95
92
  - Mowojang API - GET /:username -> ![30d uptime](https://mowojang-status.pixelic.dev/api/v1/endpoints/mowojang-api_mowojang-api---get--:username/uptimes/30d/badge.svg) ![latency](https://mowojang-status.pixelic.dev/api/v1/endpoints/mowojang-api_mowojang-api---get--:username/response-times/30d/badge.svg)
96
93
  - Mowojang API - GET /:UUID -> ![30d uptime](https://mowojang-status.pixelic.dev/api/v1/endpoints/mowojang-api_mowojang-api---get--:uuid/uptimes/30d/badge.svg) ![latency](https://mowojang-status.pixelic.dev/api/v1/endpoints/mowojang-api_mowojang-api---get--:uuid/response-times/30d/badge.svg)
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 b876ec32e396476ba1158438d83c67d4
19
+ * @example 14727fae-fbdc-4aff-848c-d2713eb9939e
20
20
  */
21
21
  type UUID = string;
22
22
 
@@ -117,6 +117,8 @@ declare class Client {
117
117
  *
118
118
  * Players considered "INVALID" are excluded from the results
119
119
  *
120
+ * Default cache TTL: 1 hour when config.cache is not provided.
121
+ *
120
122
  * @example
121
123
  * ```TS
122
124
  * const profiles = await client.getProfiles(["Pixelic", "14727faefbdc4aff848cd2713eb9939e"]);
@@ -128,6 +130,8 @@ declare class Client {
128
130
  /**
129
131
  * Returns a Player's Profile consisting of their Username and UUID
130
132
  *
133
+ * Default cache TTL: 1 hour when config.cache is not provided.
134
+ *
131
135
  * @example
132
136
  * ```TS
133
137
  * const profile = await client.getProfile("Pixelic");
@@ -137,6 +141,8 @@ declare class Client {
137
141
  /**
138
142
  * A simple Wrapper to retrieve only the UUID of a Player's Profile
139
143
  *
144
+ * Uses getProfile cache behavior (default TTL: 1 hour when config.cache is not provided).
145
+ *
140
146
  * @example
141
147
  * ```TS
142
148
  * const uuid = await client.getUUID("Pixelic");
@@ -146,6 +152,8 @@ declare class Client {
146
152
  /**
147
153
  * A simple Wrapper to retrieve only the Username of a Player's Profile
148
154
  *
155
+ * Uses getProfile cache behavior (default TTL: 1 hour when config.cache is not provided).
156
+ *
149
157
  * @example
150
158
  * ```TS
151
159
  * const username = await client.getUsername("14727faefbdc4aff848cd2713eb9939e");
@@ -157,6 +165,8 @@ declare class Client {
157
165
  *
158
166
  * Players considered "INVALID" are excluded from the results
159
167
  *
168
+ * Uses getSession cache behavior (default TTL: 15 minutes when config.cache is not provided).
169
+ *
160
170
  * @example
161
171
  * ```TS
162
172
  * const sessions = await client.getSessions(["Pixelic", "14727faefbdc4aff848cd2713eb9939e"]);
@@ -166,6 +176,8 @@ declare class Client {
166
176
  /**
167
177
  * Returns a Player's Sessions consisting of their Username, UUID, Skin and Cape
168
178
  *
179
+ * Default cache TTL: 15 minutes when config.cache is not provided.
180
+ *
169
181
  * @example
170
182
  * ```TS
171
183
  * const session = await client.getSession("Pixelic");
@@ -175,6 +187,8 @@ declare class Client {
175
187
  /**
176
188
  * A simple Wrapper to retrieve only the Skin from a Player's Session
177
189
  *
190
+ * Uses getSession cache behavior (default TTL: 15 minutes when config.cache is not provided).
191
+ *
178
192
  * @example
179
193
  * ```TS
180
194
  * const skin = await client.getSkin("Pixelic");
@@ -184,6 +198,8 @@ declare class Client {
184
198
  /**
185
199
  * A simple Wrapper to retrieve only the Player's Skin from their Session Data loaded into a Buffer
186
200
  *
201
+ * Default cache TTL for the skin image request: 24 hours when config.cache is not provided.
202
+ *
187
203
  * @example
188
204
  * ```TS
189
205
  * const skinBuffer = await client.getSkinBuffer("Pixelic");
@@ -193,6 +209,8 @@ declare class Client {
193
209
  /**
194
210
  * A simple Wrapper to retrieve only the Cape Data from a Player's Session
195
211
  *
212
+ * Uses getSession cache behavior (default TTL: 15 minutes when config.cache is not provided).
213
+ *
196
214
  * @example
197
215
  * ```TS
198
216
  * const cape = await client.getCape("Pixelic");
@@ -202,6 +220,8 @@ declare class Client {
202
220
  /**
203
221
  * A simple Wrapper to retrieve only the Player's Cape from their Session Data loaded into a Buffer
204
222
  *
223
+ * Default cache TTL for the cape image request: 30 days when config.cache is not provided.
224
+ *
205
225
  * @example
206
226
  * ```TS
207
227
  * const capeBuffer = await client.getCapeBuffer("Pixelic");
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.4.9",
41
- description: "A simple JavaScript and TypeScript compatible wrapper for the Mowojang-API.",
40
+ version: "0.5.1",
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", `(${req.internalId}) ${req.method?.toUpperCase()} ${axios.getUri(req)}`);
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
- `(${res.config.internalId}) ${res.stale ? "GET-CACHE-STALE" : "GET-CACHE"} ${axios.getUri(res.config)}`
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", `(${err.config.internalId}) Retrying request with fallback of mowojang.seraph.si`);
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", `(${err.config.internalId}) Failed to establish connection to ${host}`);
139
+ logger.critical("Mowojang", `Failed to establish connection to ${host}`, err.config.internalId);
145
140
  }
146
141
  }
147
142
  return Promise.reject(err);
@@ -313,20 +308,18 @@ 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 || false;
311
+ return Boolean(this.validation?.enabled || config?.validation?.enabled);
317
312
  }
318
313
  getValidationMinLength(config) {
319
- if (this.validation?.minimumUsernameLength === 1) return 1;
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
327
318
  *
328
319
  * Players considered "INVALID" are excluded from the results
329
320
  *
321
+ * Default cache TTL: 1 hour when config.cache is not provided.
322
+ *
330
323
  * @example
331
324
  * ```TS
332
325
  * const profiles = await client.getProfiles(["Pixelic", "14727faefbdc4aff848cd2713eb9939e"]);
@@ -343,7 +336,7 @@ var Client = class {
343
336
  const usePost = config?.usePost ?? false;
344
337
  if (usePost) {
345
338
  const fetchResponse = await this.axios.post(this.baseURL, players, {
346
- cache: config?.cache ?? { ttl: 15 * 60 * 1e3 }
339
+ cache: config?.cache ?? { ttl: 60 * 60 * 1e3 }
347
340
  });
348
341
  if (!Array.isArray(fetchResponse?.data)) return { data: null, error: "UNKNOWN_ERROR" };
349
342
  return {
@@ -356,10 +349,7 @@ var Client = class {
356
349
  error: null
357
350
  };
358
351
  }
359
- const profilePromises = [];
360
- players.forEach((player) => {
361
- profilePromises.push(this.getProfile(player, config));
362
- });
352
+ const profilePromises = players.map((player) => this.getProfile(player, config));
363
353
  const profiles = (await Promise.all(profilePromises)).filter((p) => p.data !== null).map((p) => p.data);
364
354
  return {
365
355
  data: profiles,
@@ -372,6 +362,8 @@ var Client = class {
372
362
  /**
373
363
  * Returns a Player's Profile consisting of their Username and UUID
374
364
  *
365
+ * Default cache TTL: 1 hour when config.cache is not provided.
366
+ *
375
367
  * @example
376
368
  * ```TS
377
369
  * const profile = await client.getProfile("Pixelic");
@@ -382,7 +374,7 @@ var Client = class {
382
374
  if (this.shouldValidate(config) && !validatePlayer(player, this.getValidationMinLength(config)))
383
375
  return { data: null, error: "INVALID_INPUT" };
384
376
  const fetchResponse = await this.axios.get(`${this.baseURL}/${player}`, {
385
- cache: config?.cache ?? { ttl: 15 * 60 * 1e3 }
377
+ cache: config?.cache ?? { ttl: 60 * 60 * 1e3 }
386
378
  });
387
379
  return {
388
380
  data: {
@@ -398,6 +390,8 @@ var Client = class {
398
390
  /**
399
391
  * A simple Wrapper to retrieve only the UUID of a Player's Profile
400
392
  *
393
+ * Uses getProfile cache behavior (default TTL: 1 hour when config.cache is not provided).
394
+ *
401
395
  * @example
402
396
  * ```TS
403
397
  * const uuid = await client.getUUID("Pixelic");
@@ -411,6 +405,8 @@ var Client = class {
411
405
  /**
412
406
  * A simple Wrapper to retrieve only the Username of a Player's Profile
413
407
  *
408
+ * Uses getProfile cache behavior (default TTL: 1 hour when config.cache is not provided).
409
+ *
414
410
  * @example
415
411
  * ```TS
416
412
  * const username = await client.getUsername("14727faefbdc4aff848cd2713eb9939e");
@@ -426,6 +422,8 @@ var Client = class {
426
422
  *
427
423
  * Players considered "INVALID" are excluded from the results
428
424
  *
425
+ * Uses getSession cache behavior (default TTL: 15 minutes when config.cache is not provided).
426
+ *
429
427
  * @example
430
428
  * ```TS
431
429
  * const sessions = await client.getSessions(["Pixelic", "14727faefbdc4aff848cd2713eb9939e"]);
@@ -439,10 +437,7 @@ var Client = class {
439
437
  if (validateUUID(player)) return undashUUID(player);
440
438
  return player.toLowerCase();
441
439
  });
442
- const sessionsPromises = [];
443
- players.forEach((player) => {
444
- sessionsPromises.push(this.getSession(player, config));
445
- });
440
+ const sessionsPromises = players.map((player) => this.getSession(player, config));
446
441
  const sessions = (await Promise.all(sessionsPromises)).filter((session) => session.data !== null).map((session) => session.data);
447
442
  return {
448
443
  data: sessions,
@@ -455,6 +450,8 @@ var Client = class {
455
450
  /**
456
451
  * Returns a Player's Sessions consisting of their Username, UUID, Skin and Cape
457
452
  *
453
+ * Default cache TTL: 15 minutes when config.cache is not provided.
454
+ *
458
455
  * @example
459
456
  * ```TS
460
457
  * const session = await client.getSession("Pixelic");
@@ -463,7 +460,7 @@ var Client = class {
463
460
  async getSession(player, config) {
464
461
  if (this.shouldValidate(config) && !validatePlayer(player, this.getValidationMinLength(config)))
465
462
  return { data: null, error: "INVALID_INPUT" };
466
- const UUID = await this.getUUID(player);
463
+ const UUID = validateUUID(player) ? undashUUID(player) : await this.getUUID(player);
467
464
  if (!UUID) return { data: null, error: "INVALID_PLAYER" };
468
465
  return await this.axios.get(`${this.baseURL}/session/minecraft/profile/${UUID}`, {
469
466
  cache: config?.cache ?? { ttl: 15 * 60 * 1e3 }
@@ -509,6 +506,8 @@ var Client = class {
509
506
  /**
510
507
  * A simple Wrapper to retrieve only the Skin from a Player's Session
511
508
  *
509
+ * Uses getSession cache behavior (default TTL: 15 minutes when config.cache is not provided).
510
+ *
512
511
  * @example
513
512
  * ```TS
514
513
  * const skin = await client.getSkin("Pixelic");
@@ -522,6 +521,8 @@ var Client = class {
522
521
  /**
523
522
  * A simple Wrapper to retrieve only the Player's Skin from their Session Data loaded into a Buffer
524
523
  *
524
+ * Default cache TTL for the skin image request: 24 hours when config.cache is not provided.
525
+ *
525
526
  * @example
526
527
  * ```TS
527
528
  * const skinBuffer = await client.getSkinBuffer("Pixelic");
@@ -534,11 +535,13 @@ var Client = class {
534
535
  responseType: "arraybuffer",
535
536
  cache: config?.cache ?? { ttl: 24 * 60 * 60 * 1e3 }
536
537
  });
537
- return Buffer.from(fetchResponse.data, "base64");
538
+ return Buffer.from(fetchResponse.data);
538
539
  }
539
540
  /**
540
541
  * A simple Wrapper to retrieve only the Cape Data from a Player's Session
541
542
  *
543
+ * Uses getSession cache behavior (default TTL: 15 minutes when config.cache is not provided).
544
+ *
542
545
  * @example
543
546
  * ```TS
544
547
  * const cape = await client.getCape("Pixelic");
@@ -552,6 +555,8 @@ var Client = class {
552
555
  /**
553
556
  * A simple Wrapper to retrieve only the Player's Cape from their Session Data loaded into a Buffer
554
557
  *
558
+ * Default cache TTL for the cape image request: 30 days when config.cache is not provided.
559
+ *
555
560
  * @example
556
561
  * ```TS
557
562
  * const capeBuffer = await client.getCapeBuffer("Pixelic");
@@ -564,7 +569,7 @@ var Client = class {
564
569
  responseType: "arraybuffer",
565
570
  cache: config?.cache ?? { ttl: 30 * 24 * 60 * 60 * 1e3 }
566
571
  });
567
- return Buffer.from(fetchResponse.data, "base64");
572
+ return Buffer.from(fetchResponse.data);
568
573
  }
569
574
  };
570
575
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mowojang",
3
- "version": "0.4.9",
4
- "description": "A simple JavaScript and TypeScript compatible wrapper for the Mowojang-API.",
3
+ "version": "0.5.1",
4
+ "description": "A simple TypeScript compatible wrapper for the Mowojang-API.",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",