mowojang 0.7.2 → 0.8.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 +1 -1
- package/dist/index.js +12 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ type MowojangCache = readonly {
|
|
|
73
73
|
/** Deletes a raw internal cache entry by cache key. */
|
|
74
74
|
readonly del: (key: string) => Promise<void>;
|
|
75
75
|
/** Checks whether a cached value exists for a cache key. */
|
|
76
|
-
readonly has: (key: string) => Promise<boolean>;
|
|
76
|
+
readonly has: (key: string, allowStale?: boolean) => Promise<boolean>;
|
|
77
77
|
/**
|
|
78
78
|
* Direct reference to the internal axios-cache-interceptor storage instance.
|
|
79
79
|
*
|
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.
|
|
5
|
+
var define_VERSION_default = ["0.8.0"];
|
|
6
6
|
|
|
7
7
|
// src/utils.ts
|
|
8
8
|
var undashUUID = /* @__PURE__ */ __name((UUID) => UUID.replace(/-/g, "").toLowerCase(), "undashUUID");
|
|
@@ -41,6 +41,7 @@ var axiosInstance_default = /* @__PURE__ */ __name((options, logger) => {
|
|
|
41
41
|
axios.create({
|
|
42
42
|
timeout: options?.timeout ?? 1e4,
|
|
43
43
|
maxRedirects: 0,
|
|
44
|
+
validateStatus: /* @__PURE__ */ __name((status) => status === 200 || status === 404, "validateStatus"),
|
|
44
45
|
headers: {
|
|
45
46
|
"User-Agent": `axios/${axios.VERSION} mowojang/${define_VERSION_default[0]} (https://www.npmjs.com/package/mowojang)`,
|
|
46
47
|
Accept: "application/json"
|
|
@@ -49,6 +50,9 @@ var axiosInstance_default = /* @__PURE__ */ __name((options, logger) => {
|
|
|
49
50
|
{
|
|
50
51
|
methods: ["get", "post"],
|
|
51
52
|
cacheTakeover: false,
|
|
53
|
+
cachePredicate: {
|
|
54
|
+
statusCheck: /* @__PURE__ */ __name((status) => status === 200 || status === 404, "statusCheck")
|
|
55
|
+
},
|
|
52
56
|
...options?.cache
|
|
53
57
|
}
|
|
54
58
|
);
|
|
@@ -268,7 +272,7 @@ var Client = class {
|
|
|
268
272
|
set: /* @__PURE__ */ __name(async (key, value) => await this._setCacheKey(key, value), "set"),
|
|
269
273
|
get: /* @__PURE__ */ __name(async (key) => await this._getCacheKey(key), "get"),
|
|
270
274
|
del: /* @__PURE__ */ __name(async (key) => await this._delCacheKey(key), "del"),
|
|
271
|
-
has: /* @__PURE__ */ __name(async (key) => await this._hasCacheKey(key), "has"),
|
|
275
|
+
has: /* @__PURE__ */ __name(async (key, allowStale = false) => await this._hasCacheKey(key, allowStale), "has"),
|
|
272
276
|
_storage: this.axios.storage
|
|
273
277
|
};
|
|
274
278
|
}
|
|
@@ -347,11 +351,12 @@ var Client = class {
|
|
|
347
351
|
this.logger.error("Mowojang", error instanceof Error ? error.message : "Unknown Error");
|
|
348
352
|
}
|
|
349
353
|
}
|
|
350
|
-
async _hasCacheKey(key) {
|
|
354
|
+
async _hasCacheKey(key, allowStale) {
|
|
351
355
|
try {
|
|
352
356
|
if (this.axios.storage.get) {
|
|
353
357
|
const value = await this.axios.storage.get(key);
|
|
354
|
-
|
|
358
|
+
if (!value) return false;
|
|
359
|
+
return value.state === "cached" && "data" in value || allowStale && value.state === "stale" && "data" in value;
|
|
355
360
|
}
|
|
356
361
|
} catch (error) {
|
|
357
362
|
this.logger.error("Mowojang", error instanceof Error ? error.message : "Unknown Error");
|
|
@@ -422,6 +427,9 @@ var Client = class {
|
|
|
422
427
|
id: this.getCacheKey("profile", player),
|
|
423
428
|
cache: config?.cache ?? { ttl: 60 * 60 * 1e3 }
|
|
424
429
|
});
|
|
430
|
+
if (fetchResponse.status === 404) {
|
|
431
|
+
return { data: null, error: "INVALID_PLAYER" };
|
|
432
|
+
}
|
|
425
433
|
if (config?.cache !== false && (typeof config?.cache !== "object" || config.cache.enabled !== false)) {
|
|
426
434
|
const internalId = fetchResponse.config?.internalId;
|
|
427
435
|
await this.mirrorProfileCacheEntries(
|