warframe-nexus-query 2.2.3 → 2.3.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/index.js +32 -20
- package/lib/market/v2/MarketFetcherV2.js +16 -8
- package/lib/market/v2/utils/cache.js +4 -4
- package/lib/priceCheckOptions.js +71 -0
- package/package.json +15 -9
- package/types/index.d.ts +19 -5
- package/lib/market/v2/.eslintrc.json +0 -6
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import md from 'node-md-config';
|
|
|
7
7
|
import promiseTimeout from './lib/promiseTimeout.js';
|
|
8
8
|
import Settings from './lib/Settings.js';
|
|
9
9
|
import Creator from './lib/AttachmentCreator.js';
|
|
10
|
+
import { normalizePriceCheckRanks } from './lib/priceCheckOptions.js';
|
|
10
11
|
import { MarketFetcherV2 } from './lib/market/v2/index.js';
|
|
11
12
|
|
|
12
13
|
export default class PriceCheckQuerier {
|
|
@@ -54,31 +55,40 @@ export default class PriceCheckQuerier {
|
|
|
54
55
|
/**
|
|
55
56
|
* Lookup a list of results for a query
|
|
56
57
|
* @param {string} query Query to search the nexus-stats database against
|
|
57
|
-
* @param {string} platform Platform to query price data for. One of 'pc', 'ps4', 'xb1'
|
|
58
|
+
* @param {string} [platform='pc'] Platform to query price data for. One of 'pc', 'ps4', 'xb1'
|
|
59
|
+
* @param {Object} [options={}] Optional market order filters (rank, ranks, rankLt, etc.)
|
|
58
60
|
* @returns {Promise<Array<NexusItem>>} a Promise of an array of Item objects
|
|
59
61
|
*/
|
|
60
|
-
async priceCheckQuery(query, platform = 'pc') {
|
|
62
|
+
async priceCheckQuery(query, platform = 'pc', options = {}) {
|
|
61
63
|
this.logger.info(`state:\n\tskipMarket: ${this.skipMarket}\n\tquery: ${query}\n\tplatform: ${platform}`);
|
|
62
64
|
if (!query) {
|
|
63
65
|
throw new Error('This funtcion requires a query to be provided');
|
|
64
66
|
}
|
|
65
|
-
// eslint-disable-next-line no-param-reassign
|
|
66
67
|
platform = this.settings.lookupAlias(platform.toLowerCase());
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
const ranks = normalizePriceCheckRanks(options);
|
|
70
|
+
const { ranks: _ignoredRanks, ...baseOptions } = options;
|
|
69
71
|
let attachments = [];
|
|
70
72
|
|
|
71
73
|
/* istanbul ignore else */
|
|
72
74
|
if (this.marketFetcher && !this.skipMarket) {
|
|
73
75
|
this.logger.info(`querying market for ${query} on ${platform}`);
|
|
74
76
|
try {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
const marketPlatform = this.settings.lookupAlias(platform, true);
|
|
78
|
+
const rankResults = await Promise.all(
|
|
79
|
+
ranks.map(async (rank) => {
|
|
80
|
+
const rankOptions = {
|
|
81
|
+
...baseOptions,
|
|
82
|
+
platform: marketPlatform,
|
|
83
|
+
};
|
|
84
|
+
if (rank !== undefined) rankOptions.rank = rank;
|
|
85
|
+
|
|
86
|
+
const marketPromise = this.marketFetcher.queryMarket(query, rankOptions);
|
|
87
|
+
return promiseTimeout(this.settings.timeouts.market, marketPromise);
|
|
88
|
+
})
|
|
89
|
+
);
|
|
90
|
+
attachments = rankResults.flat();
|
|
91
|
+
} catch {
|
|
82
92
|
this.logger.error(`Couldn't process ${query} on warframe.market... time out.`);
|
|
83
93
|
}
|
|
84
94
|
} else {
|
|
@@ -91,12 +101,13 @@ export default class PriceCheckQuerier {
|
|
|
91
101
|
/**
|
|
92
102
|
* Lookup a list of results for a query
|
|
93
103
|
* @param {string} query Query to search the nexus-stats database against
|
|
94
|
-
* @param {Object[]} priorResults results provided from a prior search
|
|
95
|
-
* @param {string} platform Platform to query price data for. One of 'pc', 'ps4', 'xb1'
|
|
104
|
+
* @param {Object[]} [priorResults] results provided from a prior search
|
|
105
|
+
* @param {string} [platform='pc'] Platform to query price data for. One of 'pc', 'ps4', 'xb1'
|
|
106
|
+
* @param {Object} [options={}] Optional market order filters (rank, ranks, rankLt, etc.)
|
|
96
107
|
* @returns {Promise<string>} a Promise of a string containing the results of the query
|
|
97
108
|
*/
|
|
98
|
-
async priceCheckQueryString(query, priorResults, platform = 'pc') {
|
|
99
|
-
const components = priorResults || (await this.priceCheckQuery(query, platform));
|
|
109
|
+
async priceCheckQueryString(query, priorResults, platform = 'pc', options = {}) {
|
|
110
|
+
const components = priorResults || (await this.priceCheckQuery(query, platform, options));
|
|
100
111
|
const tokens = [`[${platform.toUpperCase()}] ${query}`];
|
|
101
112
|
components.slice(0, 4).forEach((component) => {
|
|
102
113
|
tokens.push(`${md.lineEnd}${component.toString()}`);
|
|
@@ -109,12 +120,13 @@ export default class PriceCheckQuerier {
|
|
|
109
120
|
/**
|
|
110
121
|
* Lookup a list of results for a query
|
|
111
122
|
* @param {string} query Query to search the nexus-stats database against
|
|
112
|
-
* @param {Object[]} priorResults results provided from a prior search
|
|
113
|
-
* @param {string} platform Platform to query price data for. One of 'pc', 'ps4', 'xb1'
|
|
123
|
+
* @param {Object[]} [priorResults] results provided from a prior search
|
|
124
|
+
* @param {string} [platform='pc'] Platform to query price data for. One of 'pc', 'ps4', 'xb1'
|
|
125
|
+
* @param {Object} [options={}] Optional market order filters (rank, ranks, rankLt, etc.)
|
|
114
126
|
* @returns {Promise<Array<Object>>} a Promise of an array of attachment objects
|
|
115
127
|
*/
|
|
116
|
-
async priceCheckQueryAttachment(query, priorResults, platform = 'pc') {
|
|
117
|
-
const components = priorResults || (await this.priceCheckQuery(query, platform));
|
|
128
|
+
async priceCheckQueryAttachment(query, priorResults, platform = 'pc', options = {}) {
|
|
129
|
+
const components = priorResults || (await this.priceCheckQuery(query, platform, options));
|
|
118
130
|
const realPlatform = this.settings.lookupAlias(platform);
|
|
119
131
|
|
|
120
132
|
const attachment = this.creator.attachmentFromComponents(components, query, realPlatform);
|
|
@@ -145,7 +157,7 @@ export default class PriceCheckQuerier {
|
|
|
145
157
|
files.map(async (file) => {
|
|
146
158
|
try {
|
|
147
159
|
await unlink(join(global.__basedir, 'tmp', file));
|
|
148
|
-
} catch
|
|
160
|
+
} catch {
|
|
149
161
|
allSuccess = false;
|
|
150
162
|
this.logger.debug(`Couldn't delete ${file}`);
|
|
151
163
|
}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* Main entry point for interacting with the Warframe Market API v2
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { extractOrderFilters, labelSummaryForFilters } from '../../priceCheckOptions.js';
|
|
7
|
+
|
|
6
8
|
import HttpClient from './utils/http.js';
|
|
7
9
|
import VersionedCache from './utils/cache.js';
|
|
8
10
|
import Item from './models/Item.js';
|
|
@@ -261,12 +263,14 @@ export default class MarketFetcherV2 {
|
|
|
261
263
|
* @returns {Promise<Summary[]>}
|
|
262
264
|
*/
|
|
263
265
|
async queryMarket(query, options = {}) {
|
|
264
|
-
const { platform, successfulQuery } = options;
|
|
266
|
+
const { platform, successfulQuery, ranks: _ranks, ...rest } = options;
|
|
265
267
|
|
|
266
268
|
if (!platform) {
|
|
267
269
|
throw new Error('Platform is required');
|
|
268
270
|
}
|
|
269
271
|
|
|
272
|
+
const orderFilters = extractOrderFilters(rest);
|
|
273
|
+
|
|
270
274
|
// Search for item
|
|
271
275
|
const items = await this.getItems();
|
|
272
276
|
const normalizedQuery = query.toLowerCase().trim();
|
|
@@ -289,7 +293,7 @@ export default class MarketFetcherV2 {
|
|
|
289
293
|
const item = await this.getItemBySlug(matchedSlug);
|
|
290
294
|
|
|
291
295
|
// Get top orders for the item
|
|
292
|
-
const topOrders = await this.getTopOrders(item.slug, { platform });
|
|
296
|
+
const topOrders = await this.getTopOrders(item.slug, { platform, ...orderFilters });
|
|
293
297
|
|
|
294
298
|
// Calculate statistics
|
|
295
299
|
const sellStats = this.calculateStatistics(topOrders.sell, {
|
|
@@ -307,10 +311,13 @@ export default class MarketFetcherV2 {
|
|
|
307
311
|
}
|
|
308
312
|
|
|
309
313
|
// Create Summary object for v1 compatibility
|
|
310
|
-
const summary =
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
+
const summary = labelSummaryForFilters(
|
|
315
|
+
new Summary(item, topOrders, {
|
|
316
|
+
sell: sellStats,
|
|
317
|
+
buy: buyStats,
|
|
318
|
+
}),
|
|
319
|
+
orderFilters
|
|
320
|
+
);
|
|
314
321
|
|
|
315
322
|
// Return array of summaries (v1 compatibility)
|
|
316
323
|
return [summary];
|
|
@@ -320,10 +327,11 @@ export default class MarketFetcherV2 {
|
|
|
320
327
|
* Price check query (v1 compatibility method)
|
|
321
328
|
* @param {string} query - Search query
|
|
322
329
|
* @param {string} platform - Platform
|
|
330
|
+
* @param {Object} [options={}] - Optional order filters (rank, ranks, rankLt, etc.)
|
|
323
331
|
* @returns {Promise<Object>}
|
|
324
332
|
*/
|
|
325
|
-
async priceCheckQuery(query, platform) {
|
|
326
|
-
return this.queryMarket(query, { platform });
|
|
333
|
+
async priceCheckQuery(query, platform, options = {}) {
|
|
334
|
+
return this.queryMarket(query, { platform, ...options });
|
|
327
335
|
}
|
|
328
336
|
|
|
329
337
|
// ==========================================================================
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { create } from 'flat-cache';
|
|
2
2
|
|
|
3
3
|
import { API_BASE_URL, VERSION_CHECK_INTERVAL, CACHE_TTL } from '../constants.js';
|
|
4
4
|
|
|
@@ -24,7 +24,7 @@ export default class VersionedCache {
|
|
|
24
24
|
|
|
25
25
|
// Initialize persistent cache
|
|
26
26
|
if (persistent) {
|
|
27
|
-
this.#persistentCache =
|
|
27
|
+
this.#persistentCache = create({ cacheId });
|
|
28
28
|
this.#loadFromDisk();
|
|
29
29
|
} else {
|
|
30
30
|
this.#persistentCache = undefined;
|
|
@@ -191,7 +191,7 @@ export default class VersionedCache {
|
|
|
191
191
|
const serverVersion = currentVersions.data?.collections?.[collection];
|
|
192
192
|
|
|
193
193
|
return serverVersion && cachedVersion !== serverVersion;
|
|
194
|
-
} catch
|
|
194
|
+
} catch {
|
|
195
195
|
// If version check fails, don't force refresh
|
|
196
196
|
return false;
|
|
197
197
|
}
|
|
@@ -254,7 +254,7 @@ export default class VersionedCache {
|
|
|
254
254
|
if (this.#persistentCache) {
|
|
255
255
|
this.#persistentCache.destroy();
|
|
256
256
|
// Recreate the cache file (creates new empty cache)
|
|
257
|
-
this.#persistentCache =
|
|
257
|
+
this.#persistentCache = create({ cacheId: this.#cacheId });
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
260
|
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export const ORDER_FILTER_KEYS = [
|
|
2
|
+
'rank',
|
|
3
|
+
'rankLt',
|
|
4
|
+
'charges',
|
|
5
|
+
'chargesLt',
|
|
6
|
+
'amberStars',
|
|
7
|
+
'amberStarsLt',
|
|
8
|
+
'cyanStars',
|
|
9
|
+
'cyanStarsLt',
|
|
10
|
+
'subtype',
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {unknown} value - Rank value from query options
|
|
15
|
+
* @returns {number|undefined}
|
|
16
|
+
*/
|
|
17
|
+
export function parseRankValue(value) {
|
|
18
|
+
if (value === undefined || value === '') return undefined;
|
|
19
|
+
const rank = Number(value);
|
|
20
|
+
if (!Number.isInteger(rank) || rank < 0) return undefined;
|
|
21
|
+
return rank;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Resolve which mod ranks to price-check. `[undefined]` means no rank filter.
|
|
26
|
+
* @param {Record<string, unknown>} [options={}] - Price check options
|
|
27
|
+
* @returns {Array<number|undefined>}
|
|
28
|
+
*/
|
|
29
|
+
export function normalizePriceCheckRanks(options = {}) {
|
|
30
|
+
if (Array.isArray(options.ranks) && options.ranks.length) {
|
|
31
|
+
const parsed = options.ranks.map(parseRankValue).filter((rank) => rank !== undefined);
|
|
32
|
+
if (parsed.length) {
|
|
33
|
+
return [...new Set(parsed)].sort((a, b) => a - b);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const single = parseRankValue(options.rank);
|
|
38
|
+
if (single !== undefined) return [single];
|
|
39
|
+
|
|
40
|
+
return [undefined];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {Record<string, unknown>} [options={}] - Price check options
|
|
45
|
+
* @returns {Record<string, unknown>}
|
|
46
|
+
*/
|
|
47
|
+
export function extractOrderFilters(options = {}) {
|
|
48
|
+
/** @type {Record<string, unknown>} */
|
|
49
|
+
const filters = {};
|
|
50
|
+
|
|
51
|
+
ORDER_FILTER_KEYS.forEach((key) => {
|
|
52
|
+
if (options[key] !== undefined) filters[key] = options[key];
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return filters;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param {{ name: string }} summary - Market summary to label
|
|
60
|
+
* @param {Record<string, unknown>} filters - Active order filters
|
|
61
|
+
* @returns {{ name: string }}
|
|
62
|
+
*/
|
|
63
|
+
export function labelSummaryForFilters(summary, filters) {
|
|
64
|
+
if (filters.rank !== undefined) {
|
|
65
|
+
summary.name = `${summary.name} (R${filters.rank})`;
|
|
66
|
+
} else if (filters.rankLt !== undefined) {
|
|
67
|
+
summary.name = `${summary.name} (<R${filters.rankLt})`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return summary;
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "warframe-nexus-query",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "Query prices form nexus-stats.com and warframe.market.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"warframe",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"coverage": "npm test && c8 report --reporter=text-lcov | npx coveralls",
|
|
36
36
|
"lint": "eslint index.js lib/ test/",
|
|
37
37
|
"lint:fix": "eslint index.js lib/ test/ --fix",
|
|
38
|
-
"prepare": "husky
|
|
38
|
+
"prepare": "husky",
|
|
39
39
|
"test": "c8 mocha"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
@@ -45,21 +45,27 @@
|
|
|
45
45
|
"numeral": "^2.0.6"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@commitlint/cli": "^
|
|
49
|
-
"@commitlint/config-conventional": "^
|
|
48
|
+
"@commitlint/cli": "^21.0.1",
|
|
49
|
+
"@commitlint/config-conventional": "^21.0.1",
|
|
50
|
+
"@stylistic/eslint-plugin": "^5.10.0",
|
|
50
51
|
"@types/json-query": "^2.2.0",
|
|
51
|
-
"@wfcd/eslint-config": "^1.6.1",
|
|
52
52
|
"c8": "^11.0.0",
|
|
53
53
|
"chai": "^6.0.1",
|
|
54
|
+
"eslint": "^10.6.0",
|
|
55
|
+
"eslint-config-prettier": "^10.1.8",
|
|
56
|
+
"eslint-plugin-import-x": "^4.17.1",
|
|
57
|
+
"eslint-plugin-no-null": "^1.0.2",
|
|
58
|
+
"eslint-plugin-prettier": "^5.5.6",
|
|
59
|
+
"eslint-stylistic-airbnb": "^3.2.0",
|
|
60
|
+
"globals": "^17.7.0",
|
|
54
61
|
"husky": "^9.0.11",
|
|
55
|
-
"
|
|
56
|
-
"lint-staged": "^16.0.0",
|
|
62
|
+
"lint-staged": "^17.0.5",
|
|
57
63
|
"mocha": "^11.0.1",
|
|
58
64
|
"prettier": "^3.2.5"
|
|
59
65
|
},
|
|
60
66
|
"engines": {
|
|
61
|
-
"node": ">=
|
|
62
|
-
"npm": ">=
|
|
67
|
+
"node": ">=24",
|
|
68
|
+
"npm": ">=11"
|
|
63
69
|
},
|
|
64
70
|
"publishConfig": {
|
|
65
71
|
"provenance": true
|
package/types/index.d.ts
CHANGED
|
@@ -176,6 +176,7 @@ export interface QueryOptions {
|
|
|
176
176
|
platform: Platform;
|
|
177
177
|
successfulQuery?: () => void;
|
|
178
178
|
rank?: number;
|
|
179
|
+
ranks?: number[];
|
|
179
180
|
rankLt?: number;
|
|
180
181
|
charges?: number;
|
|
181
182
|
chargesLt?: number;
|
|
@@ -186,6 +187,9 @@ export interface QueryOptions {
|
|
|
186
187
|
subtype?: string;
|
|
187
188
|
}
|
|
188
189
|
|
|
190
|
+
/** Options for filtering price checks by mod rank and other order modifiers. */
|
|
191
|
+
export type PriceCheckOptions = Omit<QueryOptions, 'platform' | 'successfulQuery'>;
|
|
192
|
+
|
|
189
193
|
export interface GetTopOrdersOptions extends QueryOptions {
|
|
190
194
|
platform: Platform;
|
|
191
195
|
}
|
|
@@ -403,8 +407,8 @@ export interface MarketFetcherV2 {
|
|
|
403
407
|
formatPriceRange(stats: StatisticsData): string;
|
|
404
408
|
formatStatistics(stats: StatisticsData, type?: OrderType): string;
|
|
405
409
|
|
|
406
|
-
queryMarket(query: string, options:
|
|
407
|
-
priceCheckQuery(query: string, platform: Platform): Promise<SummaryV2[]>;
|
|
410
|
+
queryMarket(query: string, options: QueryOptions): Promise<SummaryV2[]>;
|
|
411
|
+
priceCheckQuery(query: string, platform: Platform, options?: PriceCheckOptions): Promise<SummaryV2[]>;
|
|
408
412
|
|
|
409
413
|
clearCache(): void;
|
|
410
414
|
checkVersions(): Promise<VersionedCacheVersionData>;
|
|
@@ -460,9 +464,19 @@ export class PriceCheckQuerier {
|
|
|
460
464
|
creator: AttachmentCreator;
|
|
461
465
|
|
|
462
466
|
constructor(options?: PriceCheckQuerierOptions);
|
|
463
|
-
priceCheckQuery(query: string, platform?: Platform): Promise<SummaryV2[]>;
|
|
464
|
-
priceCheckQueryString(
|
|
465
|
-
|
|
467
|
+
priceCheckQuery(query: string, platform?: Platform, options?: PriceCheckOptions): Promise<SummaryV2[]>;
|
|
468
|
+
priceCheckQueryString(
|
|
469
|
+
query: string,
|
|
470
|
+
priorResults?: SummaryV2[],
|
|
471
|
+
platform?: Platform,
|
|
472
|
+
options?: PriceCheckOptions
|
|
473
|
+
): Promise<string>;
|
|
474
|
+
priceCheckQueryAttachment(
|
|
475
|
+
query: string,
|
|
476
|
+
priorResults?: SummaryV2[],
|
|
477
|
+
platform?: Platform,
|
|
478
|
+
options?: PriceCheckOptions
|
|
479
|
+
): Promise<DiscordEmbed[]>;
|
|
466
480
|
stopUpdating(): Promise<void>;
|
|
467
481
|
}
|
|
468
482
|
|