mowojang 0.9.2 → 1.0.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.
Files changed (2) hide show
  1. package/dist/index.js +54 -15
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -5,10 +5,11 @@ var __defProp = Object.defineProperty;
5
5
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
6
 
7
7
  // <define:VERSION>
8
- var define_VERSION_default = ["0.9.2"];
8
+ var define_VERSION_default = ["1.0.0"];
9
9
 
10
10
  // src/utils.ts
11
11
  var undashUUID = /* @__PURE__ */ __name((UUID) => UUID.replaceAll("-", "").toLowerCase(), "undashUUID");
12
+ var formatRequestDuration = /* @__PURE__ */ __name((duration) => duration === void 0 ? "N/A ms" : `${duration}ms`, "formatRequestDuration");
12
13
  var dashUUID = /* @__PURE__ */ __name((UUID) => undashUUID(UUID).replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5"), "dashUUID");
13
14
 
14
15
  // src/validators.ts
@@ -221,9 +222,6 @@ var axiosInstance_default = /* @__PURE__ */ __name((options, logger) => {
221
222
  );
222
223
  instance.interceptors.request.use((req) => {
223
224
  req.internalId = Math.random().toString(16).slice(2, 10).padEnd(8, "0");
224
- if (isDebugEnabled(logger)) {
225
- logger.debug("Mowojang", `${req.method?.toUpperCase()} ${axios.getUri(req)}`, req.internalId);
226
- }
227
225
  return req;
228
226
  });
229
227
  instance.interceptors.response.use(
@@ -241,7 +239,15 @@ var axiosInstance_default = /* @__PURE__ */ __name((options, logger) => {
241
239
  if (res.cached && isDebugEnabled(logger)) {
242
240
  logger.debug(
243
241
  "Mowojang",
244
- `${res.stale ? "GET-CACHE-STALE" : "GET-CACHE"} ${axios.getUri(res.config)}`,
242
+ `${res.stale ? "GET-CACHE-STALE" : "GET-CACHE"} ${axios.getUri(res.config)} (${formatRequestDuration(res.duration)})`,
243
+ // @ts-expect-error
244
+ res.config.internalId
245
+ );
246
+ }
247
+ if (isDebugEnabled(logger)) {
248
+ logger.debug(
249
+ "Mowojang",
250
+ `${res.config.method?.toUpperCase()} ${axios.getUri(res.config)} (${formatRequestDuration(res.duration)})`,
245
251
  // @ts-expect-error
246
252
  res.config.internalId
247
253
  );
@@ -249,6 +255,13 @@ var axiosInstance_default = /* @__PURE__ */ __name((options, logger) => {
249
255
  return res;
250
256
  },
251
257
  (err) => {
258
+ if (isDebugEnabled(logger) && err.config) {
259
+ logger.debug(
260
+ "Mowojang",
261
+ `${err.config.method?.toUpperCase()} ${axios.getUri(err.config)} (${formatRequestDuration(err.response?.duration)})`,
262
+ err.config.internalId
263
+ );
264
+ }
252
265
  const isConnectionError = ["ECONNRESET", "ETIMEDOUT", "ECONNREFUSED", "ENOTFOUND", "EAI_AGAIN"].includes(err.code) || (err?.response?.status ?? 0) >= 500;
253
266
  if (!isConnectionError) return Promise.reject(err);
254
267
  const fullURL = axios.getUri(err.config);
@@ -265,13 +278,23 @@ var axiosInstance_default = /* @__PURE__ */ __name((options, logger) => {
265
278
  logger.critical("Mowojang", `Failed to establish connection to ${host}`, err.config.internalId);
266
279
  const shouldFallback = shouldRetryWithFallback && options.fallback;
267
280
  if (shouldFallback) {
268
- logger.info("Mowojang", `Retrying request with fallback of playerdb.co`, err.config.internalId);
281
+ logger.info(
282
+ "Mowojang",
283
+ `Retrying request with fallback of playerdb.co (${formatRequestDuration(err.response?.duration)})`,
284
+ err.config.internalId
285
+ );
269
286
  }
270
287
  if (isPrimaryHost) {
271
- logger.info("Mowojang", `Check Status of Mowojang on: https://mowojang-status.pixelic.dev`);
288
+ logger.info(
289
+ "Mowojang",
290
+ `Check Status of Mowojang on: https://mowojang-status.pixelic.dev (${formatRequestDuration(err.response?.duration)})`
291
+ );
272
292
  }
273
293
  if (isFallbackHost) {
274
- logger.info("Mowojang", `Check Status of PlayerDB on: https://playerdb.co`);
294
+ logger.info(
295
+ "Mowojang",
296
+ `Check Status of PlayerDB on: https://playerdb.co (${formatRequestDuration(err.response?.duration)})`
297
+ );
275
298
  }
276
299
  if (shouldFallback) return instance(err.config);
277
300
  return Promise.reject(err);
@@ -351,7 +374,7 @@ var Client = class {
351
374
  const normalized = validateUUID(value) ? `uuid:${undashUUID(value).toLowerCase()}` : `username:${value.toLowerCase()}`;
352
375
  return `${prefix}:${normalized}`;
353
376
  }
354
- async mirrorPlayerCacheEntries(prefix, ID, username, UUID, internalId) {
377
+ async mirrorPlayerCacheEntries(prefix, ID, username, UUID, internalId, duration) {
355
378
  try {
356
379
  const storage = this.axios.storage;
357
380
  if (!storage.get || !storage.set) {
@@ -370,13 +393,21 @@ var Client = class {
370
393
  if (ID !== usernameID) {
371
394
  await storage.set(usernameID, value);
372
395
  if (isDebugEnabled2(this.logger)) {
373
- this.logger.debug("Mowojang", `${label}-CACHE-MIRROR-SET ${ID} -> ${usernameID}`, internalId);
396
+ this.logger.debug(
397
+ "Mowojang",
398
+ `${label}-CACHE-MIRROR-SET ${ID} -> ${usernameID} (${formatRequestDuration(duration)})`,
399
+ internalId
400
+ );
374
401
  }
375
402
  }
376
403
  if (ID !== uuidID) {
377
404
  await storage.set(uuidID, value);
378
405
  if (isDebugEnabled2(this.logger)) {
379
- this.logger.debug("Mowojang", `${label}-CACHE-MIRROR-SET ${ID} -> ${uuidID}`, internalId);
406
+ this.logger.debug(
407
+ "Mowojang",
408
+ `${label}-CACHE-MIRROR-SET ${ID} -> ${uuidID} (${formatRequestDuration(duration)})`,
409
+ internalId
410
+ );
380
411
  }
381
412
  }
382
413
  } catch (error) {
@@ -506,7 +537,8 @@ var Client = class {
506
537
  fetchResponse.id,
507
538
  fetchResponse.data.name,
508
539
  fetchResponse.data.id,
509
- internalId
540
+ internalId,
541
+ fetchResponse.duration
510
542
  );
511
543
  }
512
544
  return {
@@ -628,7 +660,8 @@ var Client = class {
628
660
  fetchResponse.id,
629
661
  fetchResponse.data.name,
630
662
  fetchResponse.data.id,
631
- internalId
663
+ internalId,
664
+ fetchResponse.duration
632
665
  );
633
666
  }
634
667
  return {
@@ -691,7 +724,10 @@ var Client = class {
691
724
  // @ts-expect-error
692
725
  err.config.internalId
693
726
  );
694
- this.logger.info("Mowojang", `Check Status of Mojang Textures API on: https://mowojang-status.pixelic.dev`);
727
+ this.logger.info(
728
+ "Mowojang",
729
+ `Check Status of Mojang Textures API on: https://mowojang-status.pixelic.dev (${formatRequestDuration(err.response?.duration)})`
730
+ );
695
731
  }
696
732
  return null;
697
733
  }
@@ -739,7 +775,10 @@ var Client = class {
739
775
  // @ts-expect-error
740
776
  err.config.internalId
741
777
  );
742
- this.logger.info("Mowojang", `Check Status of Mojang Textures API on: https://mowojang-status.pixelic.dev`);
778
+ this.logger.info(
779
+ "Mowojang",
780
+ `Check Status of Mojang Textures API on: https://mowojang-status.pixelic.dev (${formatRequestDuration(err.response?.duration)})`
781
+ );
743
782
  }
744
783
  return null;
745
784
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mowojang",
3
- "version": "0.9.2",
3
+ "version": "1.0.0",
4
4
  "description": "A simple TypeScript compatible wrapper for the Mowojang-API.",
5
5
  "exports": {
6
6
  ".": {
@@ -34,17 +34,17 @@
34
34
  "devDependencies": {
35
35
  "@eslint/js": "^10.0.1",
36
36
  "@pixelic/logger": "npm:@jsr/pixelic__logger@^0.3.0",
37
- "@types/node": "^26.6.6",
38
- "@typescript-eslint/eslint-plugin": "^8.72.2",
39
- "@typescript-eslint/parser": "^8.72.2",
40
- "eslint": "^10.14.0",
41
- "eslint-config-prettier": "^10.1.8",
37
+ "@types/node": "^26.6.11",
38
+ "@typescript-eslint/eslint-plugin": "^8.74.0",
39
+ "@typescript-eslint/parser": "^8.74.0",
40
+ "eslint": "^10.16.0",
41
+ "eslint-config-prettier": "^10.1.9",
42
42
  "eslint-plugin-prettier": "^5.5.7",
43
43
  "jiti": "^2.7.0",
44
44
  "prettier": "^3.10.1",
45
45
  "tsup": "^9.0.0",
46
46
  "typescript": "^6.0.3",
47
- "typescript-eslint": "^8.72.2"
47
+ "typescript-eslint": "^8.74.0"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "pnpm tsup",