warframe-nexus-query 2.3.9 → 3.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.
- package/README.md +10 -5
- package/dist/basedir.d.mts +3 -0
- package/dist/basedir.mjs +7 -0
- package/dist/index.d.mts +868 -0
- package/dist/index.mjs +1778 -0
- package/package.json +31 -17
- package/basedir.js +0 -4
- package/index.js +0 -172
- package/lib/AttachmentCreator.js +0 -198
- package/lib/Settings.js +0 -53
- package/lib/market/v2/MarketFetcherV2.js +0 -447
- package/lib/market/v2/constants.js +0 -60
- package/lib/market/v2/index.js +0 -12
- package/lib/market/v2/models/Item.js +0 -135
- package/lib/market/v2/models/Order.js +0 -197
- package/lib/market/v2/models/Summary.js +0 -165
- package/lib/market/v2/types.d.ts +0 -137
- package/lib/market/v2/utils/cache.js +0 -291
- package/lib/market/v2/utils/http.js +0 -246
- package/lib/market/v2/utils/i18n.js +0 -40
- package/lib/market/v2/utils/statistics.js +0 -185
- package/lib/priceCheckOptions.js +0 -71
- package/lib/promiseTimeout.js +0 -19
- package/types/index.d.ts +0 -522
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1778 @@
|
|
|
1
|
+
import { readdir, rmdir, unlink } from "node:fs/promises";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import md from "node-md-config";
|
|
5
|
+
import { create } from "flat-cache";
|
|
6
|
+
import n from "numeral";
|
|
7
|
+
// lib/promiseTimeout.ts
|
|
8
|
+
/**
|
|
9
|
+
* Copied from https://italonascimento.github.io/applying-a-timeout-to-your-promises
|
|
10
|
+
* Apply a timeout to your promise
|
|
11
|
+
* @param ms - Milliseconds to time out after
|
|
12
|
+
* @param promise - Promise to time out
|
|
13
|
+
* @returns Pending promise that works or rejects with an error
|
|
14
|
+
*/
|
|
15
|
+
function promiseTimeout(ms, promise) {
|
|
16
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
17
|
+
const id = setTimeout(() => {
|
|
18
|
+
clearTimeout(id);
|
|
19
|
+
reject(/* @__PURE__ */ new Error(`Timed out in ${ms}ms.`));
|
|
20
|
+
}, ms);
|
|
21
|
+
});
|
|
22
|
+
return Promise.race([promise, timeout]);
|
|
23
|
+
}
|
|
24
|
+
// lib/priceCheckOptions.ts
|
|
25
|
+
const ORDER_FILTER_KEYS = [
|
|
26
|
+
"rank",
|
|
27
|
+
"rankLt",
|
|
28
|
+
"charges",
|
|
29
|
+
"chargesLt",
|
|
30
|
+
"amberStars",
|
|
31
|
+
"amberStarsLt",
|
|
32
|
+
"cyanStars",
|
|
33
|
+
"cyanStarsLt",
|
|
34
|
+
"subtype"
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* @param value - Rank value from query options
|
|
38
|
+
* @returns Parsed rank, or undefined when the value is not a non-negative integer
|
|
39
|
+
*/
|
|
40
|
+
function parseRankValue(value) {
|
|
41
|
+
if (value === void 0 || value === "") return void 0;
|
|
42
|
+
const rank = Number(value);
|
|
43
|
+
if (!Number.isInteger(rank) || rank < 0) return void 0;
|
|
44
|
+
return rank;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Resolve which mod ranks to price-check. `[undefined]` means no rank filter.
|
|
48
|
+
* @param options - Price check options
|
|
49
|
+
* @returns Ranks to query
|
|
50
|
+
*/
|
|
51
|
+
function normalizePriceCheckRanks(options = {}) {
|
|
52
|
+
if (Array.isArray(options.ranks) && options.ranks.length) {
|
|
53
|
+
const parsed = options.ranks.map(parseRankValue).filter((rank) => rank !== void 0);
|
|
54
|
+
if (parsed.length) return [...new Set(parsed)].sort((a, b) => a - b);
|
|
55
|
+
}
|
|
56
|
+
const single = parseRankValue(options.rank);
|
|
57
|
+
if (single !== void 0) return [single];
|
|
58
|
+
return [void 0];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @param options - Price check options
|
|
62
|
+
* @returns Active order filters
|
|
63
|
+
*/
|
|
64
|
+
function extractOrderFilters(options = {}) {
|
|
65
|
+
const filters = {};
|
|
66
|
+
ORDER_FILTER_KEYS.forEach((key) => {
|
|
67
|
+
if (options[key] !== void 0) filters[key] = options[key];
|
|
68
|
+
});
|
|
69
|
+
return filters;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @param summary - Market summary to label
|
|
73
|
+
* @param filters - Active order filters
|
|
74
|
+
* @returns The same summary, with a rank suffix when a rank filter is set
|
|
75
|
+
*/
|
|
76
|
+
function labelSummaryForFilters(summary, filters) {
|
|
77
|
+
if (filters.rank !== void 0) summary.name = `${summary.name} (R${String(filters.rank)})`;
|
|
78
|
+
else if (filters.rankLt !== void 0) summary.name = `${summary.name} (<R${String(filters.rankLt)})`;
|
|
79
|
+
return summary;
|
|
80
|
+
}
|
|
81
|
+
// package.json
|
|
82
|
+
var version = "3.0.0";
|
|
83
|
+
// lib/market/v2/constants.ts
|
|
84
|
+
/**
|
|
85
|
+
* Constants for Warframe Market API v2
|
|
86
|
+
*/
|
|
87
|
+
const API_BASE_URL = process.env.MARKET_V2_URL_OVERRIDE || "https://api.warframe.market/v2";
|
|
88
|
+
const ASSETS_BASE_URL = process.env.MARKET_ASSETS_URL_OVERRIDE || "https://warframe.market/static/assets/";
|
|
89
|
+
const USER_AGENT = `@wfcd/nexus-query/${version} (+https://github.com/WFCD/warframe-nexus-query)`;
|
|
90
|
+
const DEFAULT_TIMEOUT = parseInt(process.env.MARKET_TIMEOUT || "", 10) || 5e3;
|
|
91
|
+
const MIN_REQUEST_INTERVAL = 3e3;
|
|
92
|
+
const CACHE_TTL = 36e5;
|
|
93
|
+
const PLATFORMS = {
|
|
94
|
+
pc: "pc",
|
|
95
|
+
ps4: "ps4",
|
|
96
|
+
playstation: "ps4",
|
|
97
|
+
xb1: "xbox",
|
|
98
|
+
xbone: "xbox",
|
|
99
|
+
xbox: "xbox",
|
|
100
|
+
switch: "switch",
|
|
101
|
+
swi: "switch",
|
|
102
|
+
ns: "switch",
|
|
103
|
+
mobile: "mobile"
|
|
104
|
+
};
|
|
105
|
+
const LANGUAGES = {
|
|
106
|
+
en: "en",
|
|
107
|
+
es: "es",
|
|
108
|
+
fr: "fr",
|
|
109
|
+
de: "de",
|
|
110
|
+
it: "it",
|
|
111
|
+
pl: "pl",
|
|
112
|
+
pt: "pt",
|
|
113
|
+
ru: "ru",
|
|
114
|
+
ko: "ko",
|
|
115
|
+
"zh-hans": "zh-hans",
|
|
116
|
+
"zh-hant": "zh-hant",
|
|
117
|
+
uk: "uk"
|
|
118
|
+
};
|
|
119
|
+
// lib/market/v2/utils/i18n.ts
|
|
120
|
+
/**
|
|
121
|
+
* i18n helper utilities
|
|
122
|
+
*/
|
|
123
|
+
/**
|
|
124
|
+
* Normalize language code
|
|
125
|
+
* @param lang - Language code
|
|
126
|
+
* @returns Normalized language code
|
|
127
|
+
*/
|
|
128
|
+
function normalizeLanguage(lang) {
|
|
129
|
+
if (!lang) return "en";
|
|
130
|
+
const normalized = lang.toLowerCase().trim();
|
|
131
|
+
return LANGUAGES[normalized] || "en";
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Extract localized data from i18n object
|
|
135
|
+
* @param i18n - i18n object
|
|
136
|
+
* @param locale - Preferred locale
|
|
137
|
+
* @returns Localized data
|
|
138
|
+
*/
|
|
139
|
+
function extractLocalized(i18n, locale = "en") {
|
|
140
|
+
if (!i18n) return {};
|
|
141
|
+
return i18n[locale] || i18n.en || {};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get field from i18n object with fallback
|
|
145
|
+
* @param i18n - i18n object
|
|
146
|
+
* @param field - Field name
|
|
147
|
+
* @param locale - Preferred locale
|
|
148
|
+
* @param defaultValue - Default value if not found
|
|
149
|
+
* @returns Localized field or the default
|
|
150
|
+
*/
|
|
151
|
+
function getLocalizedField(i18n, field, locale = "en", defaultValue = null) {
|
|
152
|
+
return extractLocalized(i18n, locale)[field] ?? defaultValue;
|
|
153
|
+
}
|
|
154
|
+
// lib/market/v2/utils/http.ts
|
|
155
|
+
/**
|
|
156
|
+
* HTTP client for Warframe Market API v2
|
|
157
|
+
*/
|
|
158
|
+
let requestChain = Promise.resolve();
|
|
159
|
+
let nextRequestAt = 0;
|
|
160
|
+
/**
|
|
161
|
+
* Hold the shared market slot so request starts are at least `interval` ms apart.
|
|
162
|
+
* @param interval - Minimum gap between request starts
|
|
163
|
+
* @returns Resolves when this caller may start a request
|
|
164
|
+
*/
|
|
165
|
+
function waitForRequestSlot(interval = MIN_REQUEST_INTERVAL) {
|
|
166
|
+
const slot = requestChain.then(async () => {
|
|
167
|
+
const delay = nextRequestAt - Date.now();
|
|
168
|
+
if (delay > 0) await new Promise((resolve) => {
|
|
169
|
+
setTimeout(resolve, delay);
|
|
170
|
+
});
|
|
171
|
+
nextRequestAt = Date.now() + interval;
|
|
172
|
+
});
|
|
173
|
+
requestChain = slot.then(() => void 0, () => void 0);
|
|
174
|
+
return slot;
|
|
175
|
+
}
|
|
176
|
+
async function fetchWithTimeout(url, options = {}, timeout = DEFAULT_TIMEOUT) {
|
|
177
|
+
const controller = new AbortController();
|
|
178
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
179
|
+
try {
|
|
180
|
+
const response = await fetch(url, {
|
|
181
|
+
...options,
|
|
182
|
+
signal: controller.signal
|
|
183
|
+
});
|
|
184
|
+
clearTimeout(timeoutId);
|
|
185
|
+
return response;
|
|
186
|
+
} catch (error) {
|
|
187
|
+
clearTimeout(timeoutId);
|
|
188
|
+
if (error instanceof Error && error.name === "AbortError") throw new Error(`Request timeout after ${timeout}ms`);
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function errorMessage(error) {
|
|
193
|
+
return error instanceof Error ? error.message : String(error);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* HTTP Client for Warframe Market API v2
|
|
197
|
+
*/
|
|
198
|
+
var HttpClient = class {
|
|
199
|
+
#baseURL;
|
|
200
|
+
#timeout;
|
|
201
|
+
#locale;
|
|
202
|
+
#logger;
|
|
203
|
+
#userAgent;
|
|
204
|
+
#minRequestInterval;
|
|
205
|
+
/**
|
|
206
|
+
* @param options - Client options
|
|
207
|
+
*/
|
|
208
|
+
constructor(options = {}) {
|
|
209
|
+
let baseURL = options.baseURL || API_BASE_URL;
|
|
210
|
+
if (!baseURL.endsWith("/")) baseURL += "/";
|
|
211
|
+
this.#baseURL = baseURL;
|
|
212
|
+
this.#timeout = options.timeout || DEFAULT_TIMEOUT;
|
|
213
|
+
this.#locale = normalizeLanguage(options.locale || "en");
|
|
214
|
+
this.#userAgent = options.userAgent || USER_AGENT;
|
|
215
|
+
this.#minRequestInterval = options.minRequestInterval ?? 3e3;
|
|
216
|
+
this.#logger = options.logger || console;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Make GET request
|
|
220
|
+
* @param path - API path
|
|
221
|
+
* @param options - Request options
|
|
222
|
+
* @returns Unwrapped response data
|
|
223
|
+
*/
|
|
224
|
+
async get(path, options = {}) {
|
|
225
|
+
const url = this.#buildUrl(path, options.query);
|
|
226
|
+
const headers = this.#buildHeaders(options);
|
|
227
|
+
this.#logger.debug?.(`[v2] GET ${url}`);
|
|
228
|
+
try {
|
|
229
|
+
await waitForRequestSlot(this.#minRequestInterval);
|
|
230
|
+
const response = await fetchWithTimeout(url, { headers }, this.#timeout);
|
|
231
|
+
if (!response.ok) throw await this.#handleError(response);
|
|
232
|
+
const data = await response.json();
|
|
233
|
+
return this.#unwrapResponse(data);
|
|
234
|
+
} catch (error) {
|
|
235
|
+
this.#logger.error?.(`HTTP GET ${path} failed:`, errorMessage(error));
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Make POST request
|
|
241
|
+
* @param path - API path
|
|
242
|
+
* @param body - Request body
|
|
243
|
+
* @param options - Request options
|
|
244
|
+
* @returns Unwrapped response data
|
|
245
|
+
*/
|
|
246
|
+
async post(path, body, options = {}) {
|
|
247
|
+
const url = this.#buildUrl(path);
|
|
248
|
+
const headers = {
|
|
249
|
+
...this.#buildHeaders(options),
|
|
250
|
+
"Content-Type": "application/json"
|
|
251
|
+
};
|
|
252
|
+
try {
|
|
253
|
+
await waitForRequestSlot(this.#minRequestInterval);
|
|
254
|
+
const response = await fetchWithTimeout(url, {
|
|
255
|
+
method: "POST",
|
|
256
|
+
headers,
|
|
257
|
+
body: JSON.stringify(body)
|
|
258
|
+
}, this.#timeout);
|
|
259
|
+
if (!response.ok) throw await this.#handleError(response);
|
|
260
|
+
const data = await response.json();
|
|
261
|
+
return this.#unwrapResponse(data);
|
|
262
|
+
} catch (error) {
|
|
263
|
+
this.#logger.error?.(`HTTP POST ${path} failed:`, errorMessage(error));
|
|
264
|
+
throw error;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Build full URL with query parameters
|
|
269
|
+
* @param path - API path
|
|
270
|
+
* @param query - Query parameters
|
|
271
|
+
* @returns Absolute URL
|
|
272
|
+
*/
|
|
273
|
+
#buildUrl(path, query) {
|
|
274
|
+
const cleanPath = path.startsWith("/") ? path.substring(1) : path;
|
|
275
|
+
const url = new URL(cleanPath, this.#baseURL);
|
|
276
|
+
if (query) Object.entries(query).forEach(([key, value]) => {
|
|
277
|
+
if (value !== void 0 && value !== null) url.searchParams.append(key, String(value));
|
|
278
|
+
});
|
|
279
|
+
return url.toString();
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Build request headers
|
|
283
|
+
* @param options - Options
|
|
284
|
+
* @returns Request headers
|
|
285
|
+
*/
|
|
286
|
+
#buildHeaders(options = {}) {
|
|
287
|
+
const headers = {
|
|
288
|
+
Accept: "application/json",
|
|
289
|
+
"User-Agent": this.#userAgent
|
|
290
|
+
};
|
|
291
|
+
const locale = options.locale || this.#locale;
|
|
292
|
+
if (locale) headers.Language = locale;
|
|
293
|
+
if (options.platform) headers.Platform = PLATFORMS[options.platform.toLowerCase()] || options.platform;
|
|
294
|
+
if (options.token) headers.Authorization = `Bearer ${options.token}`;
|
|
295
|
+
if (options.headers) Object.assign(headers, options.headers);
|
|
296
|
+
return headers;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Handle HTTP error response
|
|
300
|
+
* @param response - Response object
|
|
301
|
+
* @returns Error describing the failed response
|
|
302
|
+
*/
|
|
303
|
+
async #handleError(response) {
|
|
304
|
+
let message = `HTTP ${response.status}: ${response.statusText}`;
|
|
305
|
+
try {
|
|
306
|
+
const data = await response.json();
|
|
307
|
+
if (data.error && data.error.message) message = data.error.message;
|
|
308
|
+
} catch {}
|
|
309
|
+
const error = new Error(message);
|
|
310
|
+
error.status = response.status;
|
|
311
|
+
error.statusText = response.statusText;
|
|
312
|
+
return error;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Unwrap API response
|
|
316
|
+
* @param data - Response data
|
|
317
|
+
* @returns Inner `data` payload
|
|
318
|
+
*/
|
|
319
|
+
#unwrapResponse(data) {
|
|
320
|
+
if (data.error) {
|
|
321
|
+
const error = new Error(data.error.message || "API Error");
|
|
322
|
+
error.code = data.error.code;
|
|
323
|
+
throw error;
|
|
324
|
+
}
|
|
325
|
+
return data.data;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Set default locale
|
|
329
|
+
* @param locale - Language code
|
|
330
|
+
*/
|
|
331
|
+
setLocale(locale) {
|
|
332
|
+
this.#locale = normalizeLanguage(locale);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Set timeout
|
|
336
|
+
* @param timeout - Timeout in milliseconds
|
|
337
|
+
*/
|
|
338
|
+
setTimeout(timeout) {
|
|
339
|
+
this.#timeout = timeout;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
// lib/market/v2/utils/cache.ts
|
|
343
|
+
function messageOf(error) {
|
|
344
|
+
return error instanceof Error ? error.message : String(error);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Version-based cache system for Warframe Market API v2
|
|
348
|
+
* Uses version hashes from /v2/versions endpoint to invalidate cache
|
|
349
|
+
* Backs up to persistent storage using flat-cache
|
|
350
|
+
*/
|
|
351
|
+
var VersionedCache = class {
|
|
352
|
+
#cache;
|
|
353
|
+
#versions;
|
|
354
|
+
#lastVersionCheck;
|
|
355
|
+
#persistentCache;
|
|
356
|
+
#cacheId;
|
|
357
|
+
#userAgent;
|
|
358
|
+
#minRequestInterval;
|
|
359
|
+
maxSize;
|
|
360
|
+
ttl;
|
|
361
|
+
constructor({ maxSize = 100, ttl = CACHE_TTL, cacheId = "warframe-market-v2", persistent = true, userAgent = USER_AGENT, minRequestInterval = MIN_REQUEST_INTERVAL } = {}) {
|
|
362
|
+
this.#cache = /* @__PURE__ */ new Map();
|
|
363
|
+
this.maxSize = maxSize;
|
|
364
|
+
this.ttl = ttl;
|
|
365
|
+
this.#versions = void 0;
|
|
366
|
+
this.#lastVersionCheck = void 0;
|
|
367
|
+
this.#cacheId = cacheId;
|
|
368
|
+
this.#userAgent = userAgent;
|
|
369
|
+
this.#minRequestInterval = minRequestInterval;
|
|
370
|
+
if (persistent) {
|
|
371
|
+
this.#persistentCache = create({ cacheId });
|
|
372
|
+
this.#loadFromDisk();
|
|
373
|
+
} else this.#persistentCache = void 0;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Load cache from disk into memory
|
|
377
|
+
*/
|
|
378
|
+
#loadFromDisk() {
|
|
379
|
+
if (!this.#persistentCache) return;
|
|
380
|
+
try {
|
|
381
|
+
this.#persistentCache.keys().forEach((key) => {
|
|
382
|
+
const item = this.#persistentCache?.getKey(key);
|
|
383
|
+
if (item) {
|
|
384
|
+
if (item.timestamp && Date.now() - item.timestamp <= this.ttl) this.#cache.set(key, item);
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
const versionsData = this.#persistentCache.getKey("_versions_metadata");
|
|
388
|
+
if (versionsData) {
|
|
389
|
+
this.#versions = versionsData.versions;
|
|
390
|
+
this.#lastVersionCheck = versionsData.lastVersionCheck;
|
|
391
|
+
}
|
|
392
|
+
} catch (error) {
|
|
393
|
+
console.warn("Failed to load cache from disk:", messageOf(error));
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Save cache to disk
|
|
398
|
+
*/
|
|
399
|
+
#saveToDisk() {
|
|
400
|
+
if (!this.#persistentCache) return;
|
|
401
|
+
try {
|
|
402
|
+
Array.from(this.#cache.entries()).forEach(([key, value]) => {
|
|
403
|
+
this.#persistentCache?.setKey(key, value);
|
|
404
|
+
});
|
|
405
|
+
if (this.#versions || this.#lastVersionCheck) this.#persistentCache.setKey("_versions_metadata", {
|
|
406
|
+
versions: this.#versions,
|
|
407
|
+
lastVersionCheck: this.#lastVersionCheck
|
|
408
|
+
});
|
|
409
|
+
this.#persistentCache.save(true);
|
|
410
|
+
} catch (error) {
|
|
411
|
+
console.warn("Failed to save cache to disk:", messageOf(error));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Get item from cache or fetch it
|
|
416
|
+
* @param key - Cache key
|
|
417
|
+
* @param collection - Collection name (items, rivens, etc.)
|
|
418
|
+
* @param fetchFn - Function to fetch data if cache miss
|
|
419
|
+
* @returns Cached or freshly fetched value
|
|
420
|
+
*/
|
|
421
|
+
async get(key, collection, fetchFn) {
|
|
422
|
+
if (collection && await this.shouldRefresh(collection)) return this.refresh(key, collection, fetchFn);
|
|
423
|
+
const cached = this.#get(key);
|
|
424
|
+
if (cached !== void 0) return cached;
|
|
425
|
+
const data = await fetchFn();
|
|
426
|
+
this.set(key, data, collection);
|
|
427
|
+
return data;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Set item in cache
|
|
431
|
+
* @param key - Cache key
|
|
432
|
+
* @param value - Value to cache
|
|
433
|
+
* @param collection - Collection name for version tracking
|
|
434
|
+
*/
|
|
435
|
+
set(key, value, collection) {
|
|
436
|
+
if (this.#cache.size >= this.maxSize) {
|
|
437
|
+
const firstKey = this.#cache.keys().next().value;
|
|
438
|
+
if (firstKey !== void 0) {
|
|
439
|
+
this.#cache.delete(firstKey);
|
|
440
|
+
if (this.#persistentCache) this.#persistentCache.removeKey(firstKey);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
this.#cache.set(key, {
|
|
444
|
+
value,
|
|
445
|
+
timestamp: Date.now(),
|
|
446
|
+
collection
|
|
447
|
+
});
|
|
448
|
+
if (collection && this.#versions) {
|
|
449
|
+
const versionKey = `_version_${collection}`;
|
|
450
|
+
const collectionVersion = this.#versions.data?.collections?.[collection];
|
|
451
|
+
if (collectionVersion) this.#cache.set(versionKey, {
|
|
452
|
+
value: collectionVersion,
|
|
453
|
+
timestamp: Date.now()
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
this.#saveToDisk();
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Get item from cache (internal)
|
|
460
|
+
* @param key - Cache key
|
|
461
|
+
* @returns Cached value, or undefined on miss or expiry
|
|
462
|
+
*/
|
|
463
|
+
#get(key) {
|
|
464
|
+
const cached = this.#cache.get(key);
|
|
465
|
+
if (!cached) return void 0;
|
|
466
|
+
if (Date.now() - cached.timestamp > this.ttl) {
|
|
467
|
+
this.#cache.delete(key);
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
return cached.value;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Check if collection should be refreshed
|
|
474
|
+
* @param collection - Collection name
|
|
475
|
+
* @returns Whether the cached collection version is stale
|
|
476
|
+
*/
|
|
477
|
+
async shouldRefresh(collection) {
|
|
478
|
+
try {
|
|
479
|
+
const currentVersions = await this.checkVersions();
|
|
480
|
+
const cachedVersion = this.#get(`_version_${collection}`);
|
|
481
|
+
const serverVersion = currentVersions.data?.collections?.[collection];
|
|
482
|
+
return Boolean(serverVersion && cachedVersion !== serverVersion);
|
|
483
|
+
} catch {
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Refresh cache entry
|
|
489
|
+
* @param key - Cache key
|
|
490
|
+
* @param collection - Collection name
|
|
491
|
+
* @param fetchFn - Function to fetch fresh data
|
|
492
|
+
* @returns Fresh value
|
|
493
|
+
*/
|
|
494
|
+
async refresh(key, collection, fetchFn) {
|
|
495
|
+
const data = await fetchFn();
|
|
496
|
+
this.set(key, data, collection);
|
|
497
|
+
return data;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Check versions from server
|
|
501
|
+
* @returns Version payload
|
|
502
|
+
*/
|
|
503
|
+
async checkVersions() {
|
|
504
|
+
if (this.#versions && this.#lastVersionCheck && Date.now() - this.#lastVersionCheck < 3e5) return this.#versions;
|
|
505
|
+
try {
|
|
506
|
+
await waitForRequestSlot(this.#minRequestInterval);
|
|
507
|
+
const response = await fetch(`${API_BASE_URL}/versions`, { headers: {
|
|
508
|
+
Accept: "application/json",
|
|
509
|
+
"User-Agent": this.#userAgent
|
|
510
|
+
} });
|
|
511
|
+
if (!response.ok) throw new Error(`Version check failed: ${response.status}`);
|
|
512
|
+
this.#versions = await response.json();
|
|
513
|
+
this.#lastVersionCheck = Date.now();
|
|
514
|
+
this.#saveToDisk();
|
|
515
|
+
return this.#versions;
|
|
516
|
+
} catch (error) {
|
|
517
|
+
if (this.#versions) return this.#versions;
|
|
518
|
+
throw error;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Clear entire cache
|
|
523
|
+
*/
|
|
524
|
+
clear() {
|
|
525
|
+
this.#cache.clear();
|
|
526
|
+
this.#versions = void 0;
|
|
527
|
+
this.#lastVersionCheck = void 0;
|
|
528
|
+
if (this.#persistentCache) {
|
|
529
|
+
this.#persistentCache.destroy();
|
|
530
|
+
this.#persistentCache = create({ cacheId: this.#cacheId });
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Delete specific key from cache
|
|
535
|
+
* @param key - Cache key
|
|
536
|
+
*/
|
|
537
|
+
delete(key) {
|
|
538
|
+
this.#cache.delete(key);
|
|
539
|
+
if (this.#persistentCache) {
|
|
540
|
+
this.#persistentCache.removeKey(key);
|
|
541
|
+
this.#persistentCache.save(true);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Get cache size
|
|
546
|
+
* @returns Number of in-memory entries
|
|
547
|
+
*/
|
|
548
|
+
size() {
|
|
549
|
+
return this.#cache.size;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Check if key exists in cache (and is valid)
|
|
553
|
+
* @param key - Cache key
|
|
554
|
+
* @returns Whether the key is present and unexpired
|
|
555
|
+
*/
|
|
556
|
+
has(key) {
|
|
557
|
+
return this.#get(key) !== void 0;
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
// lib/market/v2/models/Item.ts
|
|
561
|
+
var Item = class {
|
|
562
|
+
id;
|
|
563
|
+
slug;
|
|
564
|
+
gameRef;
|
|
565
|
+
tags;
|
|
566
|
+
setRoot;
|
|
567
|
+
setParts;
|
|
568
|
+
quantityInSet;
|
|
569
|
+
rarity;
|
|
570
|
+
bulkTradable;
|
|
571
|
+
subtypes;
|
|
572
|
+
tradable;
|
|
573
|
+
vaulted;
|
|
574
|
+
maxRank;
|
|
575
|
+
maxCharges;
|
|
576
|
+
maxAmberStars;
|
|
577
|
+
maxCyanStars;
|
|
578
|
+
ducats;
|
|
579
|
+
vosfor;
|
|
580
|
+
tradingTax;
|
|
581
|
+
baseEndo;
|
|
582
|
+
endoMultiplier;
|
|
583
|
+
reqMasteryRank;
|
|
584
|
+
i18n;
|
|
585
|
+
locale;
|
|
586
|
+
name;
|
|
587
|
+
description;
|
|
588
|
+
wikiLink;
|
|
589
|
+
icon;
|
|
590
|
+
thumb;
|
|
591
|
+
subIcon;
|
|
592
|
+
type;
|
|
593
|
+
/**
|
|
594
|
+
* @param data - Raw item data from API
|
|
595
|
+
* @param locale - Language code for i18n
|
|
596
|
+
*/
|
|
597
|
+
constructor(data, locale = "en") {
|
|
598
|
+
this.id = data.id;
|
|
599
|
+
this.slug = data.slug;
|
|
600
|
+
this.gameRef = data.gameRef;
|
|
601
|
+
this.tags = data.tags || [];
|
|
602
|
+
this.setRoot = data.setRoot;
|
|
603
|
+
this.setParts = data.setParts || [];
|
|
604
|
+
this.quantityInSet = data.quantityInSet;
|
|
605
|
+
this.rarity = data.rarity;
|
|
606
|
+
this.bulkTradable = data.bulkTradable || false;
|
|
607
|
+
this.subtypes = data.subtypes || [];
|
|
608
|
+
this.tradable = data.tradable;
|
|
609
|
+
this.vaulted = data.vaulted;
|
|
610
|
+
this.maxRank = data.maxRank;
|
|
611
|
+
this.maxCharges = data.maxCharges;
|
|
612
|
+
this.maxAmberStars = data.maxAmberStars;
|
|
613
|
+
this.maxCyanStars = data.maxCyanStars;
|
|
614
|
+
this.ducats = data.ducats;
|
|
615
|
+
this.vosfor = data.vosfor;
|
|
616
|
+
this.tradingTax = data.tradingTax;
|
|
617
|
+
this.baseEndo = data.baseEndo;
|
|
618
|
+
this.endoMultiplier = data.endoMultiplier;
|
|
619
|
+
this.reqMasteryRank = data.reqMasteryRank;
|
|
620
|
+
this.i18n = data.i18n || {};
|
|
621
|
+
this.locale = locale;
|
|
622
|
+
const localizedData = this.i18n[locale] ?? this.i18n.en ?? {};
|
|
623
|
+
this.name = localizedData.name || this.slug;
|
|
624
|
+
this.description = localizedData.description;
|
|
625
|
+
this.wikiLink = localizedData.wikiLink;
|
|
626
|
+
this.icon = localizedData.icon;
|
|
627
|
+
this.thumb = localizedData.thumb;
|
|
628
|
+
this.subIcon = localizedData.subIcon;
|
|
629
|
+
this.type = "market-v2";
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Get localized field
|
|
633
|
+
* @param field - Field name
|
|
634
|
+
* @param lang - Language code (defaults to instance locale)
|
|
635
|
+
* @returns Localized value
|
|
636
|
+
*/
|
|
637
|
+
getLocalized(field, lang) {
|
|
638
|
+
const locale = lang || this.locale;
|
|
639
|
+
return this.i18n[locale]?.[field] || this.i18n.en?.[field];
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Get full icon URL
|
|
643
|
+
* @param baseUrl - Base URL for assets
|
|
644
|
+
* @returns Icon URL, or null when the item has no icon
|
|
645
|
+
*/
|
|
646
|
+
getIconUrl(baseUrl = "https://warframe.market/static/assets/") {
|
|
647
|
+
return this.icon ? `${baseUrl}${this.icon}` : null;
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Get full thumbnail URL
|
|
651
|
+
* @param baseUrl - Base URL for assets
|
|
652
|
+
* @returns Thumbnail URL, or null when the item has no thumbnail
|
|
653
|
+
*/
|
|
654
|
+
getThumbUrl(baseUrl = "https://warframe.market/static/assets/") {
|
|
655
|
+
return this.thumb ? `${baseUrl}${this.thumb}` : null;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Check if item is part of a set
|
|
659
|
+
* @returns Whether the item lists set parts
|
|
660
|
+
*/
|
|
661
|
+
isPartOfSet() {
|
|
662
|
+
return this.setParts && this.setParts.length > 0;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Check if item is vaulted
|
|
666
|
+
* @returns Whether the item is vaulted
|
|
667
|
+
*/
|
|
668
|
+
isVaulted() {
|
|
669
|
+
return this.vaulted === true;
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Convert to JSON
|
|
673
|
+
* @returns JSON-safe item
|
|
674
|
+
*/
|
|
675
|
+
toJSON() {
|
|
676
|
+
return {
|
|
677
|
+
id: this.id,
|
|
678
|
+
slug: this.slug,
|
|
679
|
+
name: this.name,
|
|
680
|
+
thumb: this.thumb,
|
|
681
|
+
icon: this.icon,
|
|
682
|
+
tradingTax: this.tradingTax,
|
|
683
|
+
ducats: this.ducats,
|
|
684
|
+
vosfor: this.vosfor,
|
|
685
|
+
masteryLevel: this.reqMasteryRank,
|
|
686
|
+
tradable: this.tradable,
|
|
687
|
+
vaulted: this.vaulted,
|
|
688
|
+
wikiUrl: this.wikiLink,
|
|
689
|
+
description: this.description,
|
|
690
|
+
tags: this.tags,
|
|
691
|
+
type: this.type
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Convert to string representation
|
|
696
|
+
* @returns Item label
|
|
697
|
+
*/
|
|
698
|
+
toString() {
|
|
699
|
+
return `${this.name} [${this.slug}]`;
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
// lib/market/v2/models/Order.ts
|
|
703
|
+
var OrderUser = class {
|
|
704
|
+
id;
|
|
705
|
+
ingameName;
|
|
706
|
+
avatar;
|
|
707
|
+
reputation;
|
|
708
|
+
locale;
|
|
709
|
+
platform;
|
|
710
|
+
crossplay;
|
|
711
|
+
status;
|
|
712
|
+
activity;
|
|
713
|
+
lastSeen;
|
|
714
|
+
constructor(data) {
|
|
715
|
+
this.id = data.id;
|
|
716
|
+
this.ingameName = data.ingameName;
|
|
717
|
+
this.avatar = data.avatar;
|
|
718
|
+
this.reputation = data.reputation || 0;
|
|
719
|
+
this.locale = data.locale;
|
|
720
|
+
this.platform = data.platform;
|
|
721
|
+
this.crossplay = data.crossplay || false;
|
|
722
|
+
this.status = data.status;
|
|
723
|
+
this.activity = data.activity;
|
|
724
|
+
this.lastSeen = data.lastSeen ? new Date(data.lastSeen) : null;
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Check if user is online
|
|
728
|
+
* @returns Whether the user is online or in game
|
|
729
|
+
*/
|
|
730
|
+
isOnline() {
|
|
731
|
+
return this.status === "online" || this.status === "ingame";
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Get activity description
|
|
735
|
+
* @returns Activity text, or null when unknown
|
|
736
|
+
*/
|
|
737
|
+
getActivityDescription() {
|
|
738
|
+
if (!this.activity || !this.activity.type) return null;
|
|
739
|
+
const { type, details } = this.activity;
|
|
740
|
+
switch (type) {
|
|
741
|
+
case "ON_MISSION": return details ? `On Mission: ${details}` : "On Mission";
|
|
742
|
+
case "IN_DOJO": return "In Dojo";
|
|
743
|
+
case "IN_ORBITER": return "In Orbiter";
|
|
744
|
+
case "IN_RELAY": return details ? `In Relay: ${details}` : "In Relay";
|
|
745
|
+
case "IDLE": return "Idle";
|
|
746
|
+
default: return null;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Get status emoji
|
|
751
|
+
* @returns Status emoji
|
|
752
|
+
*/
|
|
753
|
+
getStatusEmoji() {
|
|
754
|
+
switch (this.status) {
|
|
755
|
+
case "online": return "🟢";
|
|
756
|
+
case "ingame": return "🎮";
|
|
757
|
+
case "offline": return "⚫";
|
|
758
|
+
case "invisible": return "👻";
|
|
759
|
+
default: return "❓";
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Convert to JSON
|
|
764
|
+
* @returns JSON-safe user
|
|
765
|
+
*/
|
|
766
|
+
toJSON() {
|
|
767
|
+
return {
|
|
768
|
+
id: this.id,
|
|
769
|
+
ingameName: this.ingameName,
|
|
770
|
+
avatar: this.avatar,
|
|
771
|
+
reputation: this.reputation,
|
|
772
|
+
locale: this.locale,
|
|
773
|
+
platform: this.platform,
|
|
774
|
+
crossplay: this.crossplay,
|
|
775
|
+
status: this.status,
|
|
776
|
+
activity: this.activity,
|
|
777
|
+
lastSeen: this.lastSeen?.toISOString()
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
/**
|
|
782
|
+
* Order model for Warframe Market API v2
|
|
783
|
+
* Represents a buy or sell order with optional user information
|
|
784
|
+
*/
|
|
785
|
+
var Order = class {
|
|
786
|
+
id;
|
|
787
|
+
type;
|
|
788
|
+
platinum;
|
|
789
|
+
quantity;
|
|
790
|
+
perTrade;
|
|
791
|
+
rank;
|
|
792
|
+
charges;
|
|
793
|
+
subtype;
|
|
794
|
+
amberStars;
|
|
795
|
+
cyanStars;
|
|
796
|
+
visible;
|
|
797
|
+
createdAt;
|
|
798
|
+
updatedAt;
|
|
799
|
+
itemId;
|
|
800
|
+
group;
|
|
801
|
+
user;
|
|
802
|
+
/**
|
|
803
|
+
* @param data - Raw order data from API
|
|
804
|
+
*/
|
|
805
|
+
constructor(data) {
|
|
806
|
+
this.id = data.id;
|
|
807
|
+
this.type = data.type;
|
|
808
|
+
this.platinum = data.platinum;
|
|
809
|
+
this.quantity = data.quantity;
|
|
810
|
+
this.perTrade = data.perTrade;
|
|
811
|
+
this.rank = data.rank;
|
|
812
|
+
this.charges = data.charges;
|
|
813
|
+
this.subtype = data.subtype;
|
|
814
|
+
this.amberStars = data.amberStars;
|
|
815
|
+
this.cyanStars = data.cyanStars;
|
|
816
|
+
this.visible = data.visible;
|
|
817
|
+
this.createdAt = data.createdAt ? new Date(data.createdAt) : null;
|
|
818
|
+
this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : null;
|
|
819
|
+
this.itemId = data.itemId;
|
|
820
|
+
this.group = data.group;
|
|
821
|
+
this.user = data.user ? new OrderUser(data.user) : null;
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Check if order is from an online user
|
|
825
|
+
* @returns Whether the order user is online
|
|
826
|
+
*/
|
|
827
|
+
isUserOnline() {
|
|
828
|
+
if (!this.user) return false;
|
|
829
|
+
return this.user.status === "online" || this.user.status === "ingame";
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Check if order is buy type
|
|
833
|
+
* @returns Whether this is a buy order
|
|
834
|
+
*/
|
|
835
|
+
isBuyOrder() {
|
|
836
|
+
return this.type === "buy";
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* Check if order is sell type
|
|
840
|
+
* @returns Whether this is a sell order
|
|
841
|
+
*/
|
|
842
|
+
isSellOrder() {
|
|
843
|
+
return this.type === "sell";
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Get order age in hours
|
|
847
|
+
* @returns Age in hours
|
|
848
|
+
*/
|
|
849
|
+
getAgeHours() {
|
|
850
|
+
if (!this.updatedAt) return 0;
|
|
851
|
+
return (Date.now() - this.updatedAt.getTime()) / 36e5;
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Convert to JSON
|
|
855
|
+
* @returns JSON-safe order
|
|
856
|
+
*/
|
|
857
|
+
toJSON() {
|
|
858
|
+
return {
|
|
859
|
+
id: this.id,
|
|
860
|
+
type: this.type,
|
|
861
|
+
platinum: this.platinum,
|
|
862
|
+
quantity: this.quantity,
|
|
863
|
+
perTrade: this.perTrade,
|
|
864
|
+
rank: this.rank,
|
|
865
|
+
charges: this.charges,
|
|
866
|
+
subtype: this.subtype,
|
|
867
|
+
amberStars: this.amberStars,
|
|
868
|
+
cyanStars: this.cyanStars,
|
|
869
|
+
visible: this.visible,
|
|
870
|
+
createdAt: this.createdAt?.toISOString(),
|
|
871
|
+
updatedAt: this.updatedAt?.toISOString(),
|
|
872
|
+
itemId: this.itemId,
|
|
873
|
+
group: this.group,
|
|
874
|
+
user: this.user?.toJSON()
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Convert to string representation
|
|
879
|
+
* @returns Order label
|
|
880
|
+
*/
|
|
881
|
+
toString() {
|
|
882
|
+
const userStr = this.user ? ` by ${this.user.ingameName}` : "";
|
|
883
|
+
const modifiers = [];
|
|
884
|
+
if (this.rank != null) modifiers.push(`R${this.rank}`);
|
|
885
|
+
if (this.subtype) modifiers.push(this.subtype);
|
|
886
|
+
const modStr = modifiers.length > 0 ? ` (${modifiers.join(", ")})` : "";
|
|
887
|
+
return `${this.type.toUpperCase()}: ${this.platinum}p x${this.quantity}${modStr}${userStr}`;
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
// lib/market/v2/models/Summary.ts
|
|
891
|
+
/**
|
|
892
|
+
* Summary model for v2 API
|
|
893
|
+
* Compatible with v1 Summary but with v2 data structures
|
|
894
|
+
*/
|
|
895
|
+
var SummaryV2 = class {
|
|
896
|
+
name;
|
|
897
|
+
slug;
|
|
898
|
+
thumbnail;
|
|
899
|
+
partThumb;
|
|
900
|
+
icon;
|
|
901
|
+
tradingTax;
|
|
902
|
+
ducats;
|
|
903
|
+
vosfor;
|
|
904
|
+
masteryLevel;
|
|
905
|
+
tradable;
|
|
906
|
+
vaulted;
|
|
907
|
+
wikiUrl;
|
|
908
|
+
description;
|
|
909
|
+
codex;
|
|
910
|
+
url;
|
|
911
|
+
tags;
|
|
912
|
+
prices;
|
|
913
|
+
orders;
|
|
914
|
+
statistics;
|
|
915
|
+
type;
|
|
916
|
+
/**
|
|
917
|
+
* Create a summary from v2 Item and Order data
|
|
918
|
+
* @param item - Item object
|
|
919
|
+
* @param orders - Orders object with buy and sell lists
|
|
920
|
+
* @param statistics - Statistics object with buy and sell stats
|
|
921
|
+
*/
|
|
922
|
+
constructor(item, orders, statistics) {
|
|
923
|
+
this.name = item.name;
|
|
924
|
+
this.slug = item.slug;
|
|
925
|
+
this.thumbnail = item.getThumbUrl(ASSETS_BASE_URL);
|
|
926
|
+
this.partThumb = item.subIcon ? `${ASSETS_BASE_URL}${item.subIcon}` : this.thumbnail;
|
|
927
|
+
this.icon = item.getIconUrl(ASSETS_BASE_URL);
|
|
928
|
+
this.tradingTax = item.tradingTax || 0;
|
|
929
|
+
this.ducats = item.ducats || 0;
|
|
930
|
+
this.vosfor = item.vosfor || 0;
|
|
931
|
+
this.masteryLevel = item.reqMasteryRank;
|
|
932
|
+
this.tradable = item.tradable;
|
|
933
|
+
this.vaulted = item.vaulted;
|
|
934
|
+
this.wikiUrl = item.wikiLink;
|
|
935
|
+
this.description = item.description || "";
|
|
936
|
+
this.codex = this.description;
|
|
937
|
+
this.url = `https://warframe.market/items/${item.slug}`;
|
|
938
|
+
this.tags = item.tags || [];
|
|
939
|
+
this.prices = {
|
|
940
|
+
soldCount: statistics.sell.orderCount || 0,
|
|
941
|
+
soldPrice: statistics.sell.median || 0,
|
|
942
|
+
minimum: statistics.sell.min || 0,
|
|
943
|
+
maximum: statistics.sell.max || 0,
|
|
944
|
+
average: statistics.sell.avg || 0,
|
|
945
|
+
volume: statistics.sell.volume || 0
|
|
946
|
+
};
|
|
947
|
+
this.orders = orders;
|
|
948
|
+
this.statistics = statistics;
|
|
949
|
+
this.type = "market-v2";
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Get best online sellers
|
|
953
|
+
* @param limit - Number of sellers to return
|
|
954
|
+
* @returns Online sellers
|
|
955
|
+
*/
|
|
956
|
+
getOnlineSellers(limit = 5) {
|
|
957
|
+
return this.orders.sell.filter((order) => order.isUserOnline() && order.user).slice(0, limit).map((order) => ({
|
|
958
|
+
ingameName: order.user.ingameName,
|
|
959
|
+
platinum: order.platinum,
|
|
960
|
+
quantity: order.quantity,
|
|
961
|
+
status: order.user.status,
|
|
962
|
+
activity: order.user.getActivityDescription(),
|
|
963
|
+
reputation: order.user.reputation,
|
|
964
|
+
platform: order.user.platform,
|
|
965
|
+
crossplay: order.user.crossplay
|
|
966
|
+
}));
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* Get best online buyers
|
|
970
|
+
* @param limit - Number of buyers to return
|
|
971
|
+
* @returns Online buyers
|
|
972
|
+
*/
|
|
973
|
+
getOnlineBuyers(limit = 5) {
|
|
974
|
+
return this.orders.buy.filter((order) => order.isUserOnline() && order.user).slice(0, limit).map((order) => ({
|
|
975
|
+
ingameName: order.user.ingameName,
|
|
976
|
+
platinum: order.platinum,
|
|
977
|
+
quantity: order.quantity,
|
|
978
|
+
status: order.user.status,
|
|
979
|
+
activity: order.user.getActivityDescription(),
|
|
980
|
+
reputation: order.user.reputation,
|
|
981
|
+
platform: order.user.platform,
|
|
982
|
+
crossplay: order.user.crossplay
|
|
983
|
+
}));
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* String representation (v1 compatible)
|
|
987
|
+
* @param opt - Option: 'codex', 'item', 'location', 'traders', or 'all'
|
|
988
|
+
* @returns Formatted summary
|
|
989
|
+
*/
|
|
990
|
+
toString(opt = "item") {
|
|
991
|
+
let value = `**${this.name}**\n`;
|
|
992
|
+
if (opt === "codex" || opt === "all") value += `\`\`\`\nCodex: ${this.codex}\n\`\`\`\n`;
|
|
993
|
+
if (opt === "item" || opt === "all") {
|
|
994
|
+
value += "```\n";
|
|
995
|
+
if (this.masteryLevel) value += `Requires: MR ${this.masteryLevel} | `;
|
|
996
|
+
value += `Tax: ${this.tradingTax}cr\n`;
|
|
997
|
+
value += `Item is ${this.tradable ? "" : "not "}tradable`;
|
|
998
|
+
if (this.vaulted) value += " (VAULTED)";
|
|
999
|
+
value += "\n\n";
|
|
1000
|
+
value += `${this.prices.soldCount} sellers (${this.prices.volume} items)\n`;
|
|
1001
|
+
value += `Median: ${this.prices.soldPrice}p | `;
|
|
1002
|
+
value += `Range: ${this.prices.minimum}p - ${this.prices.maximum}p\n`;
|
|
1003
|
+
if ((this.statistics.buy.orderCount || 0) > 0) {
|
|
1004
|
+
value += `\n${this.statistics.buy.orderCount} buyers\n`;
|
|
1005
|
+
value += `Median: ${this.statistics.buy.median}p | `;
|
|
1006
|
+
value += `Range: ${this.statistics.buy.min}p - ${this.statistics.buy.max}p\n`;
|
|
1007
|
+
}
|
|
1008
|
+
value += "```\n";
|
|
1009
|
+
}
|
|
1010
|
+
if (opt === "traders" || opt === "all") {
|
|
1011
|
+
const sellers = this.getOnlineSellers(3);
|
|
1012
|
+
if (sellers.length > 0) {
|
|
1013
|
+
value += "\n**Online Sellers:**\n";
|
|
1014
|
+
sellers.forEach((seller) => {
|
|
1015
|
+
const statusEmoji = seller.status === "ingame" ? "🎮" : "🟢";
|
|
1016
|
+
const activity = seller.activity ? ` (${seller.activity})` : "";
|
|
1017
|
+
value += `${statusEmoji} ${seller.ingameName} - ${seller.platinum}p x${seller.quantity}${activity}\n`;
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
value += `\n${this.wikiUrl || this.url}`;
|
|
1022
|
+
return value;
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Padding helper (v1 compatibility)
|
|
1026
|
+
* @param str - String to pad
|
|
1027
|
+
* @param length - Target length
|
|
1028
|
+
* @param character - Padding character
|
|
1029
|
+
* @returns Padded string
|
|
1030
|
+
*/
|
|
1031
|
+
pad(str, length = 10, character = " ") {
|
|
1032
|
+
return str.padEnd(length, character);
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
// lib/market/v2/utils/statistics.ts
|
|
1036
|
+
/**
|
|
1037
|
+
* Calculate statistics from order list
|
|
1038
|
+
* @param orders - Array of orders
|
|
1039
|
+
* @param options - Calculation options
|
|
1040
|
+
* @returns Statistics object
|
|
1041
|
+
*/
|
|
1042
|
+
function calculateStatistics(orders, options = {}) {
|
|
1043
|
+
const { type = "sell", onlineOnly = true, includeOutliers = true } = options;
|
|
1044
|
+
let filtered = orders.filter((o) => o.type === type);
|
|
1045
|
+
if (onlineOnly) filtered = filtered.filter((o) => o.isUserOnline());
|
|
1046
|
+
let prices = filtered.map((o) => o.platinum).sort((a, b) => a - b);
|
|
1047
|
+
if (!includeOutliers && prices.length > 4) prices = removeOutliers(prices);
|
|
1048
|
+
if (prices.length === 0) return {
|
|
1049
|
+
volume: 0,
|
|
1050
|
+
orderCount: 0,
|
|
1051
|
+
median: 0,
|
|
1052
|
+
min: 0,
|
|
1053
|
+
max: 0,
|
|
1054
|
+
avg: 0,
|
|
1055
|
+
q1: 0,
|
|
1056
|
+
q3: 0
|
|
1057
|
+
};
|
|
1058
|
+
const volume = filtered.reduce((sum, o) => sum + o.quantity, 0);
|
|
1059
|
+
const median = calculateMedian(prices);
|
|
1060
|
+
const min = prices[0] ?? 0;
|
|
1061
|
+
const max = prices[prices.length - 1] ?? 0;
|
|
1062
|
+
const avg = prices.reduce((a, b) => a + b, 0) / prices.length;
|
|
1063
|
+
const q1 = calculatePercentile(prices, 25);
|
|
1064
|
+
const q3 = calculatePercentile(prices, 75);
|
|
1065
|
+
return {
|
|
1066
|
+
volume,
|
|
1067
|
+
orderCount: filtered.length,
|
|
1068
|
+
median: Math.round(median),
|
|
1069
|
+
min,
|
|
1070
|
+
max,
|
|
1071
|
+
avg: Math.round(avg),
|
|
1072
|
+
q1: Math.round(q1),
|
|
1073
|
+
q3: Math.round(q3)
|
|
1074
|
+
};
|
|
1075
|
+
}
|
|
1076
|
+
/**
|
|
1077
|
+
* Calculate median of sorted array
|
|
1078
|
+
* @param sortedPrices - Sorted price array
|
|
1079
|
+
* @returns Median price
|
|
1080
|
+
*/
|
|
1081
|
+
function calculateMedian(sortedPrices) {
|
|
1082
|
+
const len = sortedPrices.length;
|
|
1083
|
+
if (len === 0) return 0;
|
|
1084
|
+
const first = sortedPrices[0] ?? 0;
|
|
1085
|
+
if (len === 1) return first;
|
|
1086
|
+
const mid = Math.floor(len / 2);
|
|
1087
|
+
const upper = sortedPrices[mid] ?? 0;
|
|
1088
|
+
if (len % 2 === 0) return ((sortedPrices[mid - 1] ?? 0) + upper) / 2;
|
|
1089
|
+
return upper;
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Calculate percentile of sorted array
|
|
1093
|
+
* @param sortedPrices - Sorted price array
|
|
1094
|
+
* @param percentile - Percentile (0-100)
|
|
1095
|
+
* @returns Percentile value
|
|
1096
|
+
*/
|
|
1097
|
+
function calculatePercentile(sortedPrices, percentile) {
|
|
1098
|
+
if (sortedPrices.length === 0) return 0;
|
|
1099
|
+
const only = sortedPrices[0] ?? 0;
|
|
1100
|
+
if (sortedPrices.length === 1) return only;
|
|
1101
|
+
const index = percentile / 100 * (sortedPrices.length - 1);
|
|
1102
|
+
const lower = Math.floor(index);
|
|
1103
|
+
const upper = Math.ceil(index);
|
|
1104
|
+
const weight = index - lower;
|
|
1105
|
+
const lowerPrice = sortedPrices[lower] ?? 0;
|
|
1106
|
+
const upperPrice = sortedPrices[upper] ?? 0;
|
|
1107
|
+
return lowerPrice * (1 - weight) + upperPrice * weight;
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Remove outliers using IQR method
|
|
1111
|
+
* @param sortedPrices - Sorted price array
|
|
1112
|
+
* @returns Prices inside the IQR fence
|
|
1113
|
+
*/
|
|
1114
|
+
function removeOutliers(sortedPrices) {
|
|
1115
|
+
const q1 = calculatePercentile(sortedPrices, 25);
|
|
1116
|
+
const q3 = calculatePercentile(sortedPrices, 75);
|
|
1117
|
+
const iqr = q3 - q1;
|
|
1118
|
+
const lowerBound = q1 - 1.5 * iqr;
|
|
1119
|
+
const upperBound = q3 + 1.5 * iqr;
|
|
1120
|
+
return sortedPrices.filter((price) => price >= lowerBound && price <= upperBound);
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Get best orders (lowest sell / highest buy)
|
|
1124
|
+
* @param orders - Array of orders
|
|
1125
|
+
* @param options - Options
|
|
1126
|
+
* @returns Best buy and sell orders
|
|
1127
|
+
*/
|
|
1128
|
+
function getBestOrders(orders, options = {}) {
|
|
1129
|
+
const { limit = 5, onlineOnly = true } = options;
|
|
1130
|
+
let filtered = orders;
|
|
1131
|
+
if (onlineOnly) filtered = orders.filter((o) => o.isUserOnline());
|
|
1132
|
+
const buyOrders = filtered.filter((o) => o.isBuyOrder()).sort((a, b) => b.platinum - a.platinum);
|
|
1133
|
+
const sellOrders = filtered.filter((o) => o.isSellOrder()).sort((a, b) => a.platinum - b.platinum);
|
|
1134
|
+
return {
|
|
1135
|
+
buy: buyOrders.slice(0, limit),
|
|
1136
|
+
sell: sellOrders.slice(0, limit)
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Format price range string
|
|
1141
|
+
* @param stats - Statistics object
|
|
1142
|
+
* @returns Price range text
|
|
1143
|
+
*/
|
|
1144
|
+
function formatPriceRange(stats) {
|
|
1145
|
+
if (stats.orderCount === 0) return "No orders found";
|
|
1146
|
+
if (stats.min === stats.max) return `${stats.min}p`;
|
|
1147
|
+
return `${stats.min}p - ${stats.max}p (median: ${stats.median}p)`;
|
|
1148
|
+
}
|
|
1149
|
+
/**
|
|
1150
|
+
* Format statistics for display
|
|
1151
|
+
* @param stats - Statistics object
|
|
1152
|
+
* @param type - Order type ('buy' or 'sell')
|
|
1153
|
+
* @returns Formatted statistics
|
|
1154
|
+
*/
|
|
1155
|
+
function formatStatistics(stats, type = "sell") {
|
|
1156
|
+
const action = type === "sell" ? "Sellers" : "Buyers";
|
|
1157
|
+
if (stats.orderCount === 0) return `No ${action.toLowerCase()} found`;
|
|
1158
|
+
return [
|
|
1159
|
+
`**${action}:** ${stats.orderCount} orders (${stats.volume} items)`,
|
|
1160
|
+
`**Median:** ${stats.median}p`,
|
|
1161
|
+
`**Range:** ${stats.min}p - ${stats.max}p`,
|
|
1162
|
+
`**Average:** ${stats.avg}p`
|
|
1163
|
+
].join("\n");
|
|
1164
|
+
}
|
|
1165
|
+
// lib/market/v2/MarketFetcherV2.ts
|
|
1166
|
+
/**
|
|
1167
|
+
* Warframe Market API v2 Client
|
|
1168
|
+
* Main entry point for interacting with the Warframe Market API v2
|
|
1169
|
+
*/
|
|
1170
|
+
var MarketFetcherV2 = class {
|
|
1171
|
+
#http;
|
|
1172
|
+
#cache;
|
|
1173
|
+
#ordersCache;
|
|
1174
|
+
#ordersCacheMaxSize;
|
|
1175
|
+
locale;
|
|
1176
|
+
logger;
|
|
1177
|
+
/**
|
|
1178
|
+
* @param options - Fetcher options
|
|
1179
|
+
*/
|
|
1180
|
+
constructor(options = {}) {
|
|
1181
|
+
this.locale = normalizeLanguage(options.locale || "en");
|
|
1182
|
+
this.logger = options.logger || console;
|
|
1183
|
+
this.#ordersCacheMaxSize = options.ordersCacheSize || 50;
|
|
1184
|
+
this.#http = new HttpClient({
|
|
1185
|
+
baseURL: options.baseURL || API_BASE_URL,
|
|
1186
|
+
locale: this.locale,
|
|
1187
|
+
timeout: options.timeout,
|
|
1188
|
+
logger: this.logger,
|
|
1189
|
+
userAgent: options.userAgent,
|
|
1190
|
+
minRequestInterval: options.minRequestInterval
|
|
1191
|
+
});
|
|
1192
|
+
this.#cache = new VersionedCache({
|
|
1193
|
+
maxSize: options.cacheSize || 100,
|
|
1194
|
+
ttl: options.cacheTTL,
|
|
1195
|
+
userAgent: options.userAgent,
|
|
1196
|
+
minRequestInterval: options.minRequestInterval
|
|
1197
|
+
});
|
|
1198
|
+
this.#ordersCache = /* @__PURE__ */ new Map();
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Get list of all tradable items
|
|
1202
|
+
* @returns Tradable items
|
|
1203
|
+
*/
|
|
1204
|
+
async getItems() {
|
|
1205
|
+
const cachedItems = await this.#cache.get("items", "items", async () => {
|
|
1206
|
+
return await this.#http.get("/items", { locale: this.locale });
|
|
1207
|
+
});
|
|
1208
|
+
const first = cachedItems[0];
|
|
1209
|
+
if (cachedItems.length > 0 && first instanceof Item) return cachedItems;
|
|
1210
|
+
return cachedItems.map((item) => new Item(item, this.locale));
|
|
1211
|
+
}
|
|
1212
|
+
/**
|
|
1213
|
+
* Get item by slug
|
|
1214
|
+
* @param slug - Item slug
|
|
1215
|
+
* @returns Item
|
|
1216
|
+
*/
|
|
1217
|
+
async getItemBySlug(slug) {
|
|
1218
|
+
const cacheKey = `item_${slug}`;
|
|
1219
|
+
const cachedItem = await this.#cache.get(cacheKey, "items", async () => {
|
|
1220
|
+
return await this.#http.get(`/item/${slug}`, { locale: this.locale });
|
|
1221
|
+
});
|
|
1222
|
+
if (cachedItem instanceof Item) return cachedItem;
|
|
1223
|
+
return new Item(cachedItem, this.locale);
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Get all items in a set
|
|
1227
|
+
* @param slug - Item slug
|
|
1228
|
+
* @returns Set id and items
|
|
1229
|
+
*/
|
|
1230
|
+
async getItemSet(slug) {
|
|
1231
|
+
const cacheKey = `item_set_${slug}`;
|
|
1232
|
+
return this.#cache.get(cacheKey, "items", async () => {
|
|
1233
|
+
const data = await this.#http.get(`/item/${slug}/set`, { locale: this.locale });
|
|
1234
|
+
return {
|
|
1235
|
+
id: data.id,
|
|
1236
|
+
items: data.items.map((item) => item instanceof Item ? item : new Item(item, this.locale))
|
|
1237
|
+
};
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
/**
|
|
1241
|
+
* Get top orders for an item (RECOMMENDED for price checks)
|
|
1242
|
+
* @param slug - Item slug
|
|
1243
|
+
* @param options - Options
|
|
1244
|
+
* @returns Top buy and sell orders
|
|
1245
|
+
*/
|
|
1246
|
+
async getTopOrders(slug, options = {}) {
|
|
1247
|
+
const { platform, ...filters } = options;
|
|
1248
|
+
if (!platform) throw new Error("Platform is required");
|
|
1249
|
+
const cacheKey = `top_orders_${slug}_${platform}_${this.#stableStringify(filters)}`;
|
|
1250
|
+
const cached = this.#getOrdersFromCache(cacheKey);
|
|
1251
|
+
if (cached) return cached;
|
|
1252
|
+
const data = await this.#http.get(`/orders/item/${slug}/top`, {
|
|
1253
|
+
platform,
|
|
1254
|
+
query: filters
|
|
1255
|
+
});
|
|
1256
|
+
const result = {
|
|
1257
|
+
buy: data.buy.map((order) => new Order(order)),
|
|
1258
|
+
sell: data.sell.map((order) => new Order(order))
|
|
1259
|
+
};
|
|
1260
|
+
this.#setOrdersCache(cacheKey, result);
|
|
1261
|
+
return result;
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* Get all orders for an item
|
|
1265
|
+
* @param slug - Item slug
|
|
1266
|
+
* @param platform - Platform (pc, ps4, xbox, switch)
|
|
1267
|
+
* @returns Orders
|
|
1268
|
+
*/
|
|
1269
|
+
async getAllOrders(slug, platform) {
|
|
1270
|
+
if (!platform) throw new Error("Platform is required");
|
|
1271
|
+
const cacheKey = `all_orders_${slug}_${platform}`;
|
|
1272
|
+
const cached = this.#getOrdersFromCache(cacheKey);
|
|
1273
|
+
if (cached) return cached;
|
|
1274
|
+
const result = (await this.#http.get(`/orders/item/${slug}`, { platform })).map((order) => new Order(order));
|
|
1275
|
+
this.#setOrdersCache(cacheKey, result);
|
|
1276
|
+
return result;
|
|
1277
|
+
}
|
|
1278
|
+
/**
|
|
1279
|
+
* Get recent orders (last 4 hours)
|
|
1280
|
+
* @param platform - Platform (pc, ps4, xbox, switch)
|
|
1281
|
+
* @returns Recent orders
|
|
1282
|
+
*/
|
|
1283
|
+
async getRecentOrders(platform) {
|
|
1284
|
+
if (!platform) throw new Error("Platform is required");
|
|
1285
|
+
const cacheKey = `recent_orders_${platform}`;
|
|
1286
|
+
const cached = this.#getOrdersFromCache(cacheKey);
|
|
1287
|
+
if (cached) return cached;
|
|
1288
|
+
const result = (await this.#http.get("/orders/recent", { platform })).map((order) => new Order(order));
|
|
1289
|
+
this.#setOrdersCache(cacheKey, result);
|
|
1290
|
+
return result;
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* Calculate statistics from orders
|
|
1294
|
+
* @param orders - Orders array
|
|
1295
|
+
* @param options - Calculation options
|
|
1296
|
+
* @returns Statistics
|
|
1297
|
+
*/
|
|
1298
|
+
calculateStatistics(orders, options = {}) {
|
|
1299
|
+
return calculateStatistics(orders, options);
|
|
1300
|
+
}
|
|
1301
|
+
/**
|
|
1302
|
+
* Get best orders (sorted)
|
|
1303
|
+
* @param orders - Orders array
|
|
1304
|
+
* @param options - Options
|
|
1305
|
+
* @returns Best buy and sell orders
|
|
1306
|
+
*/
|
|
1307
|
+
getBestOrders(orders, options = {}) {
|
|
1308
|
+
return getBestOrders(orders, options);
|
|
1309
|
+
}
|
|
1310
|
+
/**
|
|
1311
|
+
* Format price range string
|
|
1312
|
+
* @param stats - Statistics object
|
|
1313
|
+
* @returns Price range text
|
|
1314
|
+
*/
|
|
1315
|
+
formatPriceRange(stats) {
|
|
1316
|
+
return formatPriceRange(stats);
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* Format statistics for display
|
|
1320
|
+
* @param stats - Statistics object
|
|
1321
|
+
* @param type - Order type
|
|
1322
|
+
* @returns Formatted statistics
|
|
1323
|
+
*/
|
|
1324
|
+
formatStatistics(stats, type) {
|
|
1325
|
+
return formatStatistics(stats, type);
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* Query market for item (v1 compatibility method)
|
|
1329
|
+
* @param query - Search query
|
|
1330
|
+
* @param options - Query options
|
|
1331
|
+
* @returns Matching summaries
|
|
1332
|
+
*/
|
|
1333
|
+
async queryMarket(query, options = {}) {
|
|
1334
|
+
const { platform, successfulQuery, ranks: _ranks, ...rest } = options;
|
|
1335
|
+
if (!platform) throw new Error("Platform is required");
|
|
1336
|
+
const orderFilters = extractOrderFilters(rest);
|
|
1337
|
+
const items = await this.getItems();
|
|
1338
|
+
const normalizedQuery = query.toLowerCase().trim();
|
|
1339
|
+
const matched = items.filter((item) => {
|
|
1340
|
+
const name = item.name.toLowerCase();
|
|
1341
|
+
const slug = item.slug.toLowerCase();
|
|
1342
|
+
return name.includes(normalizedQuery) || slug.includes(normalizedQuery);
|
|
1343
|
+
})[0];
|
|
1344
|
+
if (!matched) throw new Error(`No items found for query: ${query}`);
|
|
1345
|
+
const item = await this.getItemBySlug(matched.slug);
|
|
1346
|
+
const topOrders = await this.getTopOrders(item.slug, {
|
|
1347
|
+
platform,
|
|
1348
|
+
...orderFilters
|
|
1349
|
+
});
|
|
1350
|
+
const sellStats = this.calculateStatistics(topOrders.sell, {
|
|
1351
|
+
type: "sell",
|
|
1352
|
+
onlineOnly: true
|
|
1353
|
+
});
|
|
1354
|
+
const buyStats = this.calculateStatistics(topOrders.buy, {
|
|
1355
|
+
type: "buy",
|
|
1356
|
+
onlineOnly: true
|
|
1357
|
+
});
|
|
1358
|
+
if (successfulQuery && typeof successfulQuery === "function") successfulQuery();
|
|
1359
|
+
return [labelSummaryForFilters(new SummaryV2(item, topOrders, {
|
|
1360
|
+
sell: sellStats,
|
|
1361
|
+
buy: buyStats
|
|
1362
|
+
}), orderFilters)];
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Price check query (v1 compatibility method)
|
|
1366
|
+
* @param query - Search query
|
|
1367
|
+
* @param platform - Platform
|
|
1368
|
+
* @param options - Optional order filters (rank, ranks, rankLt, etc.)
|
|
1369
|
+
* @returns Matching summaries
|
|
1370
|
+
*/
|
|
1371
|
+
async priceCheckQuery(query, platform, options = {}) {
|
|
1372
|
+
return this.queryMarket(query, {
|
|
1373
|
+
platform,
|
|
1374
|
+
...options
|
|
1375
|
+
});
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Get from short-lived orders cache
|
|
1379
|
+
* @param key - Cache key
|
|
1380
|
+
* @returns Cached value, or null on miss
|
|
1381
|
+
*/
|
|
1382
|
+
#getOrdersFromCache(key) {
|
|
1383
|
+
const cached = this.#ordersCache.get(key);
|
|
1384
|
+
if (!cached) return null;
|
|
1385
|
+
if (Date.now() - cached.timestamp > 6e4) {
|
|
1386
|
+
this.#ordersCache.delete(key);
|
|
1387
|
+
return null;
|
|
1388
|
+
}
|
|
1389
|
+
return cached.value;
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* Set short-lived orders cache
|
|
1393
|
+
* @param key - Cache key
|
|
1394
|
+
* @param value - Value to cache
|
|
1395
|
+
*/
|
|
1396
|
+
#setOrdersCache(key, value) {
|
|
1397
|
+
if (this.#ordersCache.size >= this.#ordersCacheMaxSize) {
|
|
1398
|
+
const oldestKey = this.#ordersCache.keys().next().value;
|
|
1399
|
+
if (oldestKey !== void 0) this.#ordersCache.delete(oldestKey);
|
|
1400
|
+
}
|
|
1401
|
+
this.#ordersCache.set(key, {
|
|
1402
|
+
value,
|
|
1403
|
+
timestamp: Date.now()
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* Clear all caches
|
|
1408
|
+
*/
|
|
1409
|
+
clearCache() {
|
|
1410
|
+
this.#cache.clear();
|
|
1411
|
+
this.#ordersCache.clear();
|
|
1412
|
+
}
|
|
1413
|
+
/**
|
|
1414
|
+
* Check API versions
|
|
1415
|
+
* @returns Version payload
|
|
1416
|
+
*/
|
|
1417
|
+
async checkVersions() {
|
|
1418
|
+
return this.#cache.checkVersions();
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* Stable stringify for cache keys (sorts object keys recursively)
|
|
1422
|
+
* @param value - Value to stringify
|
|
1423
|
+
* @returns Deterministic JSON string
|
|
1424
|
+
*/
|
|
1425
|
+
#stableStringify(value) {
|
|
1426
|
+
if (value === null || value === void 0) return JSON.stringify(value);
|
|
1427
|
+
if (typeof value !== "object") return JSON.stringify(value);
|
|
1428
|
+
if (Array.isArray(value)) return `[${value.map((item) => this.#stableStringify(item)).join(",")}]`;
|
|
1429
|
+
const record = value;
|
|
1430
|
+
return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${this.#stableStringify(record[key])}`).join(",")}}`;
|
|
1431
|
+
}
|
|
1432
|
+
normalizePlatform(platform) {
|
|
1433
|
+
if (!platform) return void 0;
|
|
1434
|
+
return PLATFORMS[platform.toLowerCase()] || platform;
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1437
|
+
* Set locale
|
|
1438
|
+
* @param locale - Language code
|
|
1439
|
+
*/
|
|
1440
|
+
setLocale(locale) {
|
|
1441
|
+
this.locale = normalizeLanguage(locale);
|
|
1442
|
+
this.#http.setLocale(locale);
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Stop and cleanup (clears all caches)
|
|
1446
|
+
*/
|
|
1447
|
+
stop() {
|
|
1448
|
+
this.clearCache();
|
|
1449
|
+
}
|
|
1450
|
+
};
|
|
1451
|
+
// lib/Settings.ts
|
|
1452
|
+
/**
|
|
1453
|
+
* Settings storage for nexus query
|
|
1454
|
+
*/
|
|
1455
|
+
var Settings = class {
|
|
1456
|
+
userAgent;
|
|
1457
|
+
urls;
|
|
1458
|
+
platforms;
|
|
1459
|
+
timeouts;
|
|
1460
|
+
defaultString;
|
|
1461
|
+
constructor() {
|
|
1462
|
+
this.userAgent = process.env.MARKET_USER_AGENT || USER_AGENT;
|
|
1463
|
+
this.urls = {
|
|
1464
|
+
market: process.env.MARKET_URL_OVERRIDE || "https://api.warframe.market/v1/items",
|
|
1465
|
+
marketAssets: process.env.MARKET_ASSETS_URL_OVERRIDE || "https://warframe.market/static/assets/"
|
|
1466
|
+
};
|
|
1467
|
+
this.platforms = {
|
|
1468
|
+
pc: "pc",
|
|
1469
|
+
ps4: "ps4",
|
|
1470
|
+
playstation: "ps4",
|
|
1471
|
+
xbone: "xb1",
|
|
1472
|
+
xbox: "xb1",
|
|
1473
|
+
xb1: "xb1",
|
|
1474
|
+
swi: "switch",
|
|
1475
|
+
switch: "switch",
|
|
1476
|
+
ns: "switch",
|
|
1477
|
+
market: {
|
|
1478
|
+
pc: "pc",
|
|
1479
|
+
ps4: "ps4",
|
|
1480
|
+
playstation: "ps4",
|
|
1481
|
+
xbone: "xbox",
|
|
1482
|
+
xbox: "xbox",
|
|
1483
|
+
xb1: "xbox",
|
|
1484
|
+
swi: "switch",
|
|
1485
|
+
switch: "switch",
|
|
1486
|
+
ns: "switch"
|
|
1487
|
+
}
|
|
1488
|
+
};
|
|
1489
|
+
this.timeouts = { market: Number(process.env.MARKET_TIMEOUT) || 3e3 };
|
|
1490
|
+
this.defaultString = "Operator, there is no such item pricecheck available.";
|
|
1491
|
+
}
|
|
1492
|
+
/**
|
|
1493
|
+
* Look up real platform for platform alias
|
|
1494
|
+
* @param platformAlias - Alias of platform
|
|
1495
|
+
* @param market - Whether or not to use market-specific aliases
|
|
1496
|
+
* @returns Real platform identifier
|
|
1497
|
+
*/
|
|
1498
|
+
lookupAlias(platformAlias, market = false) {
|
|
1499
|
+
const key = platformAlias.toLowerCase();
|
|
1500
|
+
if (market) {
|
|
1501
|
+
const marketPlatforms = this.platforms.market;
|
|
1502
|
+
if (typeof marketPlatforms === "string") return void 0;
|
|
1503
|
+
return marketPlatforms[key];
|
|
1504
|
+
}
|
|
1505
|
+
const platform = this.platforms[key];
|
|
1506
|
+
return typeof platform === "string" ? platform : void 0;
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
// lib/AttachmentCreator.ts
|
|
1510
|
+
const numerFmt = "0,0";
|
|
1511
|
+
const wfcdLogo = "https://warframestat.us/wfcd_logo_color.png";
|
|
1512
|
+
const noResultAttachment = {
|
|
1513
|
+
type: "rich",
|
|
1514
|
+
title: "No result",
|
|
1515
|
+
color: 16733695,
|
|
1516
|
+
url: "https://warframe.market",
|
|
1517
|
+
fields: [],
|
|
1518
|
+
footer: {
|
|
1519
|
+
text: "Price data provided by NexusHub.co & Warframe.Market",
|
|
1520
|
+
icon_url: wfcdLogo
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
const baseAttachment = {
|
|
1524
|
+
type: "rich",
|
|
1525
|
+
title: "",
|
|
1526
|
+
color: 16711935,
|
|
1527
|
+
url: "",
|
|
1528
|
+
fields: [],
|
|
1529
|
+
thumbnail: { url: "" },
|
|
1530
|
+
footer: {
|
|
1531
|
+
icon_url: wfcdLogo,
|
|
1532
|
+
text: "Data by NexusHub.co & Warframe.Market"
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
/**
|
|
1536
|
+
* Calculate the safe value for a provided value
|
|
1537
|
+
* @param value - provided value
|
|
1538
|
+
* @returns safe value
|
|
1539
|
+
*/
|
|
1540
|
+
function safeValue(value) {
|
|
1541
|
+
return value ? `${Number.parseInt(String(value), 10)}p` : "No Data";
|
|
1542
|
+
}
|
|
1543
|
+
/**
|
|
1544
|
+
* Calculate the safe value for a provided value
|
|
1545
|
+
* @param value1 - provided minimum value
|
|
1546
|
+
* @param value2 - provided maximum value
|
|
1547
|
+
* @returns safe value
|
|
1548
|
+
*/
|
|
1549
|
+
function safeRange(value1, value2) {
|
|
1550
|
+
return value1 ? `${Number.parseInt(String(value1), 10)}p - ${Number.parseInt(String(value2), 10)}p` : "No Data";
|
|
1551
|
+
}
|
|
1552
|
+
/**
|
|
1553
|
+
* Build a field from provided nexus & market components (v1)
|
|
1554
|
+
* @param mComponent - market component
|
|
1555
|
+
* @returns built field
|
|
1556
|
+
*/
|
|
1557
|
+
function fieldValue(mComponent) {
|
|
1558
|
+
let mMedian;
|
|
1559
|
+
let mRange;
|
|
1560
|
+
if (mComponent.prices) {
|
|
1561
|
+
mMedian = safeValue(mComponent.prices.soldPrice);
|
|
1562
|
+
mRange = safeRange(mComponent.prices.minimum, mComponent.prices.maximum);
|
|
1563
|
+
}
|
|
1564
|
+
return {
|
|
1565
|
+
name: (mComponent.name || "").trim(),
|
|
1566
|
+
value: `\`\`\`haskell
|
|
1567
|
+
${"Value".padEnd(6, " ")} | Market\n${"Median".padEnd(6, " ")} | ${mMedian}\n${"Range".padEnd(6, " ")} | ${mRange}\n\`\`\`
|
|
1568
|
+
Trade Tax: ${n(mComponent.tradingTax).format(numerFmt)}cr\n`,
|
|
1569
|
+
inline: false
|
|
1570
|
+
};
|
|
1571
|
+
}
|
|
1572
|
+
/**
|
|
1573
|
+
* Build a field from v2 market component with trader info
|
|
1574
|
+
* @param mComponent - market component (v2)
|
|
1575
|
+
* @returns built field
|
|
1576
|
+
*/
|
|
1577
|
+
function fieldValueV2(mComponent) {
|
|
1578
|
+
if (!mComponent) throw new TypeError("mComponent is required");
|
|
1579
|
+
if (typeof mComponent !== "object") throw new TypeError("mComponent must be an object");
|
|
1580
|
+
if (!mComponent.name || typeof mComponent.name !== "string") throw new TypeError("mComponent.name must be a non-empty string");
|
|
1581
|
+
if (mComponent.tradingTax !== void 0 && typeof mComponent.tradingTax !== "number") throw new TypeError("mComponent.tradingTax must be a number");
|
|
1582
|
+
if (mComponent.statistics && typeof mComponent.statistics !== "object") throw new TypeError("mComponent.statistics must be an object");
|
|
1583
|
+
const sellStats = mComponent.statistics?.sell || {};
|
|
1584
|
+
const mMedian = safeValue(sellStats.median);
|
|
1585
|
+
const mRange = safeRange(sellStats.min, sellStats.max);
|
|
1586
|
+
const onlineSellers = mComponent.getOnlineSellers ? mComponent.getOnlineSellers(3) : [];
|
|
1587
|
+
let tradersInfo = "";
|
|
1588
|
+
if (onlineSellers.length > 0) {
|
|
1589
|
+
tradersInfo = "\n**Online Sellers:**\n";
|
|
1590
|
+
onlineSellers.forEach((trader, idx) => {
|
|
1591
|
+
const statusEmoji = trader.status === "online" ? "🟢" : "🟡";
|
|
1592
|
+
const activityText = trader.activity ? ` (${trader.activity})` : "";
|
|
1593
|
+
tradersInfo += `${idx + 1}. ${statusEmoji} ${trader.ingameName}: ${trader.platinum}p${activityText}\n`;
|
|
1594
|
+
});
|
|
1595
|
+
} else tradersInfo = "\n_No online sellers currently available_\n";
|
|
1596
|
+
return {
|
|
1597
|
+
name: mComponent.name.trim(),
|
|
1598
|
+
value: `\`\`\`haskell
|
|
1599
|
+
${"Value".padEnd(6, " ")} | Market\n${"Median".padEnd(6, " ")} | ${mMedian}\n${"Range".padEnd(6, " ")} | ${mRange}\n${"Volume".padEnd(6, " ")} | ${sellStats.orderCount || 0} orders\n\`\`\`
|
|
1600
|
+
Trade Tax: ${n(mComponent.tradingTax).format(numerFmt)}cr\n${tradersInfo}`,
|
|
1601
|
+
inline: false
|
|
1602
|
+
};
|
|
1603
|
+
}
|
|
1604
|
+
/**
|
|
1605
|
+
* Create the attachment itself
|
|
1606
|
+
*/
|
|
1607
|
+
var AttachmentCreator = class {
|
|
1608
|
+
/**
|
|
1609
|
+
* Build an attachment from the provided components
|
|
1610
|
+
* @param components - collected array of components with market data
|
|
1611
|
+
* @param query - Search query that these components match
|
|
1612
|
+
* @param platform - Platform for the request, defaults to 'pc'
|
|
1613
|
+
* @returns Discord-ready attachment describing the item
|
|
1614
|
+
*/
|
|
1615
|
+
attachmentFromComponents(components, _query, platform = "pc") {
|
|
1616
|
+
if (!components || !Array.isArray(components) || !components.length) return noResultAttachment;
|
|
1617
|
+
const attachment = JSON.parse(JSON.stringify(baseAttachment));
|
|
1618
|
+
const list = components;
|
|
1619
|
+
const v2Components = list.filter((component) => component && component.type === "market-v2" && component.statistics);
|
|
1620
|
+
const marketComponents = v2Components.length > 0 ? v2Components : list.filter((component) => component && component.type === "market-v1" && typeof component.prices?.soldPrice !== "undefined");
|
|
1621
|
+
const isV2 = v2Components.length > 0;
|
|
1622
|
+
/* istanbul ignore else */
|
|
1623
|
+
if (marketComponents.length > 0) {
|
|
1624
|
+
marketComponents.forEach((marketComponent, index) => {
|
|
1625
|
+
if (!index) {
|
|
1626
|
+
attachment.color = parseInt(marketComponent.color || "", 16);
|
|
1627
|
+
attachment.title = `[${platform.toUpperCase()}] ${(marketComponent.name || "").replace(/\sset/i, "")}`;
|
|
1628
|
+
attachment.url = marketComponent.url || "";
|
|
1629
|
+
attachment.thumbnail ||= { url: "" };
|
|
1630
|
+
attachment.thumbnail.url = marketComponent.thumbnail || "";
|
|
1631
|
+
}
|
|
1632
|
+
attachment.fields.push(isV2 ? fieldValueV2(marketComponent) : fieldValue(marketComponent));
|
|
1633
|
+
});
|
|
1634
|
+
attachment.footer = {
|
|
1635
|
+
icon_url: wfcdLogo,
|
|
1636
|
+
text: isV2 ? "Price data provided by Warframe.Market (API v2)" : "Price data provided by Warframe.Market"
|
|
1637
|
+
};
|
|
1638
|
+
} else return noResultAttachment;
|
|
1639
|
+
/* istanbul ignore else */
|
|
1640
|
+
if (attachment.fields.length) return attachment;
|
|
1641
|
+
/* istanbul ignore next */
|
|
1642
|
+
return noResultAttachment;
|
|
1643
|
+
}
|
|
1644
|
+
};
|
|
1645
|
+
// index.ts
|
|
1646
|
+
var PriceCheckQuerier = class {
|
|
1647
|
+
#useV2 = false;
|
|
1648
|
+
settings;
|
|
1649
|
+
logger;
|
|
1650
|
+
skipMarket;
|
|
1651
|
+
marketFetcher;
|
|
1652
|
+
apiVersion;
|
|
1653
|
+
creator;
|
|
1654
|
+
/**
|
|
1655
|
+
* Creates an instance representing a WarframeNexusStats data object
|
|
1656
|
+
* @param options - Querier options
|
|
1657
|
+
*/
|
|
1658
|
+
constructor({ logger = console, marketCache = void 0, skipMarket = false } = {}) {
|
|
1659
|
+
this.settings = new Settings();
|
|
1660
|
+
this.logger = logger;
|
|
1661
|
+
this.skipMarket = skipMarket;
|
|
1662
|
+
this.marketFetcher = marketCache;
|
|
1663
|
+
if (!skipMarket) try {
|
|
1664
|
+
this.#useV2 = process.env.WARFRAME_MARKET_API_VERSION === "v2";
|
|
1665
|
+
if (this.#useV2) {
|
|
1666
|
+
this.logger.debug?.("Using Warframe Market API v2");
|
|
1667
|
+
this.marketFetcher = new MarketFetcherV2({
|
|
1668
|
+
logger,
|
|
1669
|
+
userAgent: this.settings.userAgent
|
|
1670
|
+
});
|
|
1671
|
+
this.apiVersion = "v2";
|
|
1672
|
+
} else {
|
|
1673
|
+
this.logger.info?.("Using Warframe Market API v1");
|
|
1674
|
+
this.logger.warn?.("Api v1 is deprecated and impossible to use");
|
|
1675
|
+
this.marketFetcher = new MarketFetcherV2({
|
|
1676
|
+
logger,
|
|
1677
|
+
userAgent: this.settings.userAgent
|
|
1678
|
+
});
|
|
1679
|
+
this.apiVersion = "v2";
|
|
1680
|
+
}
|
|
1681
|
+
} catch (e) {
|
|
1682
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
1683
|
+
this.logger.error?.(`couldn't set up market fetcher: ${message}`);
|
|
1684
|
+
}
|
|
1685
|
+
this.creator = new AttachmentCreator();
|
|
1686
|
+
}
|
|
1687
|
+
/**
|
|
1688
|
+
* Lookup a list of results for a query
|
|
1689
|
+
* @param query - Query to search the nexus-stats database against
|
|
1690
|
+
* @param platform - Platform to query price data for. One of 'pc', 'ps4', 'xb1'
|
|
1691
|
+
* @param options - Optional market order filters (rank, ranks, rankLt, etc.)
|
|
1692
|
+
* @returns a Promise of an array of Item objects
|
|
1693
|
+
*/
|
|
1694
|
+
async priceCheckQuery(query, platform = "pc", options = {}) {
|
|
1695
|
+
this.logger.info?.(`state:\n\tskipMarket: ${this.skipMarket}\n\tquery: ${query}\n\tplatform: ${platform}`);
|
|
1696
|
+
if (!query) throw new Error("This funtcion requires a query to be provided");
|
|
1697
|
+
const resolvedPlatform = this.settings.lookupAlias(platform.toLowerCase());
|
|
1698
|
+
if (!resolvedPlatform) throw new Error(`Unknown platform: ${platform}`);
|
|
1699
|
+
const ranks = normalizePriceCheckRanks(options);
|
|
1700
|
+
const { ranks: _ignoredRanks, ...baseOptions } = options;
|
|
1701
|
+
let attachments = [];
|
|
1702
|
+
/* istanbul ignore else */
|
|
1703
|
+
if (this.marketFetcher && !this.skipMarket) {
|
|
1704
|
+
this.logger.info?.(`querying market for ${query} on ${resolvedPlatform}`);
|
|
1705
|
+
try {
|
|
1706
|
+
const marketPlatform = this.settings.lookupAlias(resolvedPlatform, true);
|
|
1707
|
+
attachments = (await Promise.all(ranks.map(async (rank) => {
|
|
1708
|
+
const rankOptions = {
|
|
1709
|
+
...baseOptions,
|
|
1710
|
+
platform: marketPlatform
|
|
1711
|
+
};
|
|
1712
|
+
if (rank !== void 0) rankOptions.rank = rank;
|
|
1713
|
+
const marketPromise = this.marketFetcher.queryMarket(query, rankOptions);
|
|
1714
|
+
return promiseTimeout(this.settings.timeouts.market, marketPromise);
|
|
1715
|
+
}))).flat();
|
|
1716
|
+
} catch {
|
|
1717
|
+
this.logger.error?.(`Couldn't process ${query} on warframe.market... time out.`);
|
|
1718
|
+
}
|
|
1719
|
+
} else this.logger.info?.("No market fetcher, skipping market");
|
|
1720
|
+
return attachments;
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
* Lookup a list of results for a query
|
|
1724
|
+
* @param query - Query to search the nexus-stats database against
|
|
1725
|
+
* @param priorResults - results provided from a prior search
|
|
1726
|
+
* @param platform - Platform to query price data for. One of 'pc', 'ps4', 'xb1'
|
|
1727
|
+
* @param options - Optional market order filters (rank, ranks, rankLt, etc.)
|
|
1728
|
+
* @returns a Promise of a string containing the results of the query
|
|
1729
|
+
*/
|
|
1730
|
+
async priceCheckQueryString(query, priorResults, platform = "pc", options = {}) {
|
|
1731
|
+
const components = priorResults || await this.priceCheckQuery(query, platform, options);
|
|
1732
|
+
const tokens = [`[${platform.toUpperCase()}] ${query}`];
|
|
1733
|
+
components.slice(0, 4).forEach((component) => {
|
|
1734
|
+
tokens.push(`${md.lineEnd}${component.toString()}`);
|
|
1735
|
+
});
|
|
1736
|
+
let componentsToReturnString = `${md.codeMulti}${tokens.join()}${md.blockEnd}`;
|
|
1737
|
+
componentsToReturnString = components.length > 0 ? componentsToReturnString : this.settings.defaultString;
|
|
1738
|
+
return componentsToReturnString;
|
|
1739
|
+
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Lookup a list of results for a query
|
|
1742
|
+
* @param query - Query to search the nexus-stats database against
|
|
1743
|
+
* @param priorResults - results provided from a prior search
|
|
1744
|
+
* @param platform - Platform to query price data for. One of 'pc', 'ps4', 'xb1'
|
|
1745
|
+
* @param options - Optional market order filters (rank, ranks, rankLt, etc.)
|
|
1746
|
+
* @returns a Promise of an array of attachment objects
|
|
1747
|
+
*/
|
|
1748
|
+
async priceCheckQueryAttachment(query, priorResults, platform = "pc", options = {}) {
|
|
1749
|
+
const components = priorResults || await this.priceCheckQuery(query, platform, options);
|
|
1750
|
+
const realPlatform = this.settings.lookupAlias(platform) || platform;
|
|
1751
|
+
return [this.creator.attachmentFromComponents(components, query, realPlatform)];
|
|
1752
|
+
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Stop updating caches
|
|
1755
|
+
*/
|
|
1756
|
+
async stopUpdating() {
|
|
1757
|
+
/* istanbul ignore else */
|
|
1758
|
+
if (!this.skipMarket && this.marketFetcher) {
|
|
1759
|
+
const fetcher = this.marketFetcher;
|
|
1760
|
+
if ("marketCache" in fetcher && fetcher.marketCache) fetcher.marketCache.stop();
|
|
1761
|
+
else if (typeof fetcher.stop === "function") fetcher.stop();
|
|
1762
|
+
} else this.logger.log?.("no market fetcher, or skipMarket was true");
|
|
1763
|
+
if (global.__basedir && existsSync(`${global.__basedir}/tmp`)) {
|
|
1764
|
+
const files = await readdir(`${global.__basedir}/tmp`);
|
|
1765
|
+
let allSuccess = true;
|
|
1766
|
+
await Promise.all(files.map(async (file) => {
|
|
1767
|
+
try {
|
|
1768
|
+
await unlink(join(global.__basedir, "tmp", file));
|
|
1769
|
+
} catch {
|
|
1770
|
+
allSuccess = false;
|
|
1771
|
+
this.logger.debug?.(`Couldn't delete ${file}`);
|
|
1772
|
+
}
|
|
1773
|
+
}));
|
|
1774
|
+
if (allSuccess) await rmdir(`${global.__basedir}/tmp`);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
};
|
|
1778
|
+
export { HttpClient, Item, MarketFetcherV2, Order, OrderUser, SummaryV2 as Summary, SummaryV2, VersionedCache, calculateStatistics, PriceCheckQuerier as default, extractLocalized, formatPriceRange, formatStatistics, getBestOrders, getLocalizedField, normalizeLanguage };
|