warframe-nexus-query 2.3.10 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "warframe-nexus-query",
3
- "version": "2.3.10",
3
+ "version": "3.0.0",
4
4
  "description": "Query prices form nexus-stats.com and warframe.market.",
5
5
  "keywords": [
6
6
  "warframe",
@@ -19,24 +19,32 @@
19
19
  "license": "Apache-2.0",
20
20
  "author": "tobitenno",
21
21
  "type": "module",
22
- "main": "index.js",
23
- "types": "./types/index.d.ts",
24
- "directories": {
25
- "test": "test"
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.mts",
25
+ "import": "./dist/index.mjs"
26
+ },
27
+ "./basedir": {
28
+ "types": "./dist/basedir.d.mts",
29
+ "import": "./dist/basedir.mjs"
30
+ }
26
31
  },
32
+ "main": "./dist/index.mjs",
33
+ "types": "./dist/index.d.mts",
27
34
  "files": [
28
- "lib",
29
- "index.js",
30
- "basedir.js",
31
- "types"
35
+ "dist"
32
36
  ],
33
37
  "scripts": {
34
- "build:docs": "jsdoc -c jsdoc-config.json -d docs",
35
- "coverage": "npm test && c8 report --reporter=text-lcov | npx coveralls",
36
- "lint": "eslint index.js lib/ test/",
37
- "lint:fix": "eslint index.js lib/ test/ --fix",
38
+ "build": "tsdown",
39
+ "build:docs": "typedoc",
40
+ "coverage": "npm run test:coverage && c8 report --reporter=text-lcov | npx coveralls",
41
+ "lint": "eslint eslint.config.mjs index.ts basedir.ts lib/ test/",
42
+ "lint:fix": "eslint eslint.config.mjs index.ts basedir.ts lib/ test/ --fix",
38
43
  "prepare": "husky",
39
- "test": "c8 mocha"
44
+ "prepublishOnly": "npm run build",
45
+ "pretest": "npm run build",
46
+ "test": "mocha",
47
+ "test:coverage": "c8 npm test"
40
48
  },
41
49
  "dependencies": {
42
50
  "flat-cache": "^6.1.19",
@@ -48,20 +56,26 @@
48
56
  "@commitlint/cli": "^21.0.1",
49
57
  "@commitlint/config-conventional": "^21.0.1",
50
58
  "@stylistic/eslint-plugin": "^5.10.0",
59
+ "@types/chai": "^5.2.3",
51
60
  "@types/json-query": "^2.2.0",
61
+ "@types/mocha": "^10.0.10",
62
+ "@types/node": "^26.6.5",
52
63
  "c8": "^12.0.0",
53
64
  "chai": "^6.0.1",
54
65
  "eslint": "^10.6.0",
55
- "eslint-config-prettier": "^10.1.8",
56
66
  "eslint-plugin-import-x": "^4.17.1",
57
67
  "eslint-plugin-no-null": "^1.0.2",
58
- "eslint-plugin-prettier": "^5.5.6",
59
68
  "eslint-stylistic-airbnb": "^3.2.0",
60
69
  "globals": "^17.7.0",
61
70
  "husky": "^9.0.11",
62
71
  "lint-staged": "^17.0.5",
63
72
  "mocha": "^12.0.2",
64
- "prettier": "^3.2.5"
73
+ "semantic-release": "^25.0.9",
74
+ "tsdown": "^0.22.14",
75
+ "tsx": "^4.23.15",
76
+ "typedoc": "^0.28.20",
77
+ "typescript": "^6.0.3",
78
+ "typescript-eslint": "^8.72.0"
65
79
  },
66
80
  "engines": {
67
81
  "node": ">=24",
package/basedir.js DELETED
@@ -1,4 +0,0 @@
1
- import { dirname } from 'node:path';
2
- import { fileURLToPath } from 'node:url';
3
-
4
- export default dirname(fileURLToPath(import.meta.url));
package/index.js DELETED
@@ -1,172 +0,0 @@
1
- import { readdir, unlink, rmdir } from 'node:fs/promises';
2
- import { existsSync as exists } from 'node:fs';
3
- import { join } from 'node:path';
4
-
5
- import md from 'node-md-config';
6
-
7
- import promiseTimeout from './lib/promiseTimeout.js';
8
- import Settings from './lib/Settings.js';
9
- import Creator from './lib/AttachmentCreator.js';
10
- import { normalizePriceCheckRanks } from './lib/priceCheckOptions.js';
11
- import { MarketFetcherV2 } from './lib/market/v2/index.js';
12
-
13
- export default class PriceCheckQuerier {
14
- #useV2 = false;
15
-
16
- /**
17
- * Creates an instance representing a WarframeNexusStats data object
18
- * @constructor
19
- */
20
- constructor({ logger = console, marketCache = undefined, skipMarket = false }) {
21
- this.settings = new Settings();
22
- this.logger = logger;
23
- this.skipMarket = skipMarket;
24
- this.marketFetcher = marketCache;
25
-
26
- if (!skipMarket) {
27
- try {
28
- this.#useV2 = process.env.WARFRAME_MARKET_API_VERSION === 'v2';
29
- /**
30
- * Fetch market data
31
- * @type {MarketFetcher|MarketFetcherV2}
32
- */
33
- if (this.#useV2) {
34
- this.logger.debug('Using Warframe Market API v2');
35
- this.marketFetcher = new MarketFetcherV2({ logger });
36
- this.apiVersion = 'v2';
37
- } else {
38
- this.logger.info('Using Warframe Market API v1');
39
- this.logger.warn('Api v1 is deprecated and impossible to use');
40
- this.marketFetcher = new MarketFetcherV2({ logger });
41
- this.apiVersion = 'v2';
42
- }
43
- } catch (e) {
44
- this.logger.error(`couldn't set up market fetcher: ${e.message}`);
45
- }
46
- }
47
-
48
- /**
49
- * Attachment creator for generating attachments
50
- * @type {Creator}
51
- */
52
- this.creator = new Creator();
53
- }
54
-
55
- /**
56
- * Lookup a list of results for a query
57
- * @param {string} query Query to search the nexus-stats database against
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.)
60
- * @returns {Promise<Array<NexusItem>>} a Promise of an array of Item objects
61
- */
62
- async priceCheckQuery(query, platform = 'pc', options = {}) {
63
- this.logger.info(`state:\n\tskipMarket: ${this.skipMarket}\n\tquery: ${query}\n\tplatform: ${platform}`);
64
- if (!query) {
65
- throw new Error('This funtcion requires a query to be provided');
66
- }
67
- platform = this.settings.lookupAlias(platform.toLowerCase());
68
-
69
- const ranks = normalizePriceCheckRanks(options);
70
- const { ranks: _ignoredRanks, ...baseOptions } = options;
71
- let attachments = [];
72
-
73
- /* istanbul ignore else */
74
- if (this.marketFetcher && !this.skipMarket) {
75
- this.logger.info(`querying market for ${query} on ${platform}`);
76
- try {
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 {
92
- this.logger.error(`Couldn't process ${query} on warframe.market... time out.`);
93
- }
94
- } else {
95
- this.logger.info('No market fetcher, skipping market');
96
- }
97
-
98
- return attachments;
99
- }
100
-
101
- /**
102
- * Lookup a list of results for a query
103
- * @param {string} query Query to search the nexus-stats database against
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.)
107
- * @returns {Promise<string>} a Promise of a string containing the results of the query
108
- */
109
- async priceCheckQueryString(query, priorResults, platform = 'pc', options = {}) {
110
- const components = priorResults || (await this.priceCheckQuery(query, platform, options));
111
- const tokens = [`[${platform.toUpperCase()}] ${query}`];
112
- components.slice(0, 4).forEach((component) => {
113
- tokens.push(`${md.lineEnd}${component.toString()}`);
114
- });
115
- let componentsToReturnString = `${md.codeMulti}${tokens.join()}${md.blockEnd}`;
116
- componentsToReturnString = components.length > 0 ? componentsToReturnString : this.settings.defaultString;
117
- return componentsToReturnString;
118
- }
119
-
120
- /**
121
- * Lookup a list of results for a query
122
- * @param {string} query Query to search the nexus-stats database against
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.)
126
- * @returns {Promise<Array<Object>>} a Promise of an array of attachment objects
127
- */
128
- async priceCheckQueryAttachment(query, priorResults, platform = 'pc', options = {}) {
129
- const components = priorResults || (await this.priceCheckQuery(query, platform, options));
130
- const realPlatform = this.settings.lookupAlias(platform);
131
-
132
- const attachment = this.creator.attachmentFromComponents(components, query, realPlatform);
133
- return [attachment];
134
- }
135
-
136
- /**
137
- * Stop updating caches
138
- */
139
- async stopUpdating() {
140
- /* istanbul ignore else */
141
- if (!this.skipMarket && this.marketFetcher) {
142
- // v1 API uses marketCache
143
- if (this.marketFetcher.marketCache) {
144
- this.marketFetcher.marketCache.stop();
145
- } else if (typeof this.marketFetcher.stop === 'function') {
146
- // v2 API has stop() method
147
- this.marketFetcher.stop();
148
- }
149
- } else {
150
- this.logger.log('no market fetcher, or skipMarket was true');
151
- }
152
-
153
- if (exists(`${global.__basedir}/tmp`)) {
154
- const files = await readdir(`${global.__basedir}/tmp`);
155
- let allSuccess = true;
156
- await Promise.all(
157
- files.map(async (file) => {
158
- try {
159
- await unlink(join(global.__basedir, 'tmp', file));
160
- } catch {
161
- allSuccess = false;
162
- this.logger.debug(`Couldn't delete ${file}`);
163
- }
164
- })
165
- );
166
-
167
- if (allSuccess) {
168
- await rmdir(`${global.__basedir}/tmp`);
169
- }
170
- }
171
- }
172
- }
@@ -1,198 +0,0 @@
1
- import n from 'numeral';
2
-
3
- const numerFmt = '0,0';
4
- const wfcdLogo = 'https://warframestat.us/wfcd_logo_color.png';
5
-
6
- const noResultAttachment = {
7
- type: 'rich',
8
- title: 'No result',
9
- color: 0xff55ff,
10
- url: 'https://warframe.market',
11
- footer: {
12
- text: 'Price data provided by NexusHub.co & Warframe.Market',
13
- icon_url: wfcdLogo,
14
- },
15
- };
16
-
17
- const baseAttachment = {
18
- type: 'rich',
19
- title: '',
20
- color: 0xff00ff,
21
- url: '',
22
- fields: [],
23
- thumbnail: { url: '' },
24
- footer: {
25
- icon_url: wfcdLogo,
26
- text: 'Data by NexusHub.co & Warframe.Market',
27
- },
28
- };
29
-
30
- /**
31
- * Calculate the safe value for a provided value
32
- * @param {string} value provided value
33
- * @returns {string} safe value
34
- */
35
- function safeValue(value) {
36
- return value ? `${Number.parseInt(value, 10)}p` : 'No Data';
37
- }
38
-
39
- /**
40
- * Calculate the safe value for a provided value
41
- * @param {string} value1 provided minimum value
42
- * @param {string} value2 provided maximum value
43
- * @returns {string} safe value
44
- */
45
- function safeRange(value1, value2) {
46
- return value1 ? `${Number.parseInt(value1, 10)}p - ${Number.parseInt(value2, 10)}p` : 'No Data';
47
- }
48
-
49
- /**
50
- * Build a field from provided nexus & market components (v1)
51
- * @param {MarketComponent} mComponent market component
52
- * @returns {Object} built field
53
- */
54
- function fieldValue(mComponent) {
55
- let mMedian;
56
- let mRange;
57
-
58
- if (mComponent) {
59
- mMedian = safeValue(mComponent.prices.soldPrice);
60
- mRange = safeRange(mComponent.prices.minimum, mComponent.prices.maximum);
61
- }
62
-
63
- return {
64
- name: mComponent.name.trim(),
65
- value:
66
- '```haskell\n' +
67
- `${'Value'.padEnd(6, ' ')} | Market\n` +
68
- `${'Median'.padEnd(6, ' ')} | ${mMedian}\n` +
69
- `${'Range'.padEnd(6, ' ')} | ${mRange}\n` +
70
- '```\n' +
71
- `Trade Tax: ${n(mComponent.tradingTax).format(numerFmt)}cr\n`,
72
- inline: false,
73
- };
74
- }
75
-
76
- /**
77
- * Build a field from v2 market component with trader info
78
- * @param {MarketComponent} mComponent market component (v2)
79
- * @returns {Object} built field
80
- */
81
- function fieldValueV2(mComponent) {
82
- // Validate input
83
- if (!mComponent) {
84
- throw new TypeError('mComponent is required');
85
- }
86
-
87
- if (typeof mComponent !== 'object') {
88
- throw new TypeError('mComponent must be an object');
89
- }
90
-
91
- if (!mComponent.name || typeof mComponent.name !== 'string') {
92
- throw new TypeError('mComponent.name must be a non-empty string');
93
- }
94
-
95
- if (mComponent.tradingTax !== undefined && typeof mComponent.tradingTax !== 'number') {
96
- throw new TypeError('mComponent.tradingTax must be a number');
97
- }
98
-
99
- if (mComponent.statistics && typeof mComponent.statistics !== 'object') {
100
- throw new TypeError('mComponent.statistics must be an object');
101
- }
102
-
103
- const sellStats = mComponent.statistics?.sell || {};
104
-
105
- const mMedian = safeValue(sellStats.median);
106
- const mRange = safeRange(sellStats.min, sellStats.max);
107
-
108
- // Get online sellers (up to 3)
109
- const onlineSellers = mComponent.getOnlineSellers ? mComponent.getOnlineSellers(3) : [];
110
-
111
- let tradersInfo = '';
112
- if (onlineSellers.length > 0) {
113
- tradersInfo = '\n**Online Sellers:**\n';
114
- onlineSellers.forEach((trader, idx) => {
115
- const statusEmoji = trader.status === 'online' ? '🟢' : '🟡';
116
- const activityText = trader.activity ? ` (${trader.activity})` : '';
117
- tradersInfo += `${idx + 1}. ${statusEmoji} ${trader.ingameName}: ${trader.platinum}p${activityText}\n`;
118
- });
119
- } else {
120
- tradersInfo = '\n_No online sellers currently available_\n';
121
- }
122
-
123
- return {
124
- name: mComponent.name.trim(),
125
- value:
126
- `\`\`\`haskell\n` +
127
- `${'Value'.padEnd(6, ' ')} | Market\n` +
128
- `${'Median'.padEnd(6, ' ')} | ${mMedian}\n` +
129
- `${'Range'.padEnd(6, ' ')} | ${mRange}\n` +
130
- `${'Volume'.padEnd(6, ' ')} | ${sellStats.orderCount || 0} orders\n` +
131
- `\`\`\`\n` +
132
- `Trade Tax: ${n(mComponent.tradingTax).format(numerFmt)}cr\n${tradersInfo}`,
133
- inline: false,
134
- };
135
- }
136
-
137
- /**
138
- * Create the attachment itself
139
- */
140
- export default class AttachmentCreator {
141
- /**
142
- * Build an attachment from the provided components
143
- * @param {Array<MarketComponent>} components -
144
- * collected array of components with market data
145
- * @param {string} query Search query that these components match
146
- * @param {string} [platform='pc'] Platform for the request, defaults to 'pc'
147
- * @returns {Object} Discord-ready attachment describing the item
148
- */
149
- attachmentFromComponents(components, query, platform = 'pc') {
150
- if (!components || !components.length || !Array.isArray(components)) return noResultAttachment;
151
-
152
- const attachment = JSON.parse(JSON.stringify(baseAttachment));
153
-
154
- // Check if we have v2 components
155
- const v2Components = components.filter(
156
- (component) => component && component.type === 'market-v2' && component.statistics
157
- );
158
-
159
- // Fall back to v1 components if no v2 found
160
- const marketComponents =
161
- v2Components.length > 0
162
- ? v2Components
163
- : components.filter(
164
- (component) =>
165
- component && component.type === 'market-v1' && typeof component.prices.soldPrice !== 'undefined'
166
- );
167
-
168
- const isV2 = v2Components.length > 0;
169
-
170
- /* istanbul ignore else */
171
- if (marketComponents.length > 0) {
172
- marketComponents.forEach((marketComponent, index) => {
173
- if (!index) {
174
- attachment.color = parseInt(marketComponent.color, 16);
175
- attachment.title = `[${platform.toUpperCase()}] ${marketComponent.name.replace(/\sset/i, '')}`;
176
- attachment.url = marketComponent.url;
177
- attachment.thumbnail.url = marketComponent.thumbnail;
178
- }
179
-
180
- // Use appropriate field builder based on version
181
- attachment.fields.push(isV2 ? fieldValueV2(marketComponent) : fieldValue(marketComponent));
182
- });
183
-
184
- attachment.footer = {
185
- icon_url: wfcdLogo,
186
- text: isV2 ? 'Price data provided by Warframe.Market (API v2)' : 'Price data provided by Warframe.Market',
187
- };
188
- } else {
189
- return noResultAttachment;
190
- }
191
- /* istanbul ignore else */
192
- if (attachment.fields.length) {
193
- return attachment;
194
- }
195
- /* istanbul ignore next */
196
- return noResultAttachment;
197
- }
198
- }
package/lib/Settings.js DELETED
@@ -1,53 +0,0 @@
1
- /**
2
- * Settings storage for nexus query
3
- * @type {Settings}
4
- * @property {number} maxCacheLength - maximum length to store cached data
5
- * @property {Object} urls - URL list for nexus stats
6
- */
7
- export default class Settings {
8
- constructor() {
9
- this.urls = {
10
- market: process.env.MARKET_URL_OVERRIDE || 'https://api.warframe.market/v1/items',
11
- marketAssets: process.env.MARKET_ASSETS_URL_OVERRIDE || 'https://warframe.market/static/assets/',
12
- };
13
-
14
- this.platforms = {
15
- pc: 'pc',
16
- ps4: 'ps4',
17
- playstation: 'ps4',
18
- xbone: 'xb1',
19
- xbox: 'xb1',
20
- xb1: 'xb1',
21
- swi: 'switch',
22
- switch: 'switch',
23
- ns: 'switch',
24
- market: {
25
- pc: 'pc',
26
- ps4: 'ps4',
27
- playstation: 'ps4',
28
- xbone: 'xbox',
29
- xbox: 'xbox',
30
- xb1: 'xbox',
31
- swi: 'switch',
32
- switch: 'switch',
33
- ns: 'switch',
34
- },
35
- };
36
-
37
- this.timeouts = {
38
- market: process.env.MARKET_TIMEOUT || 3000,
39
- };
40
-
41
- this.defaultString = 'Operator, there is no such item pricecheck available.';
42
- }
43
-
44
- /**
45
- * Look up real platform for platform alias
46
- * @param {string} platformAlias Alias of platform
47
- * @param {boolean} market Whether or not to use market-specific aliases
48
- * @returns {string} Real platform identifier
49
- */
50
- lookupAlias(platformAlias, market = false) {
51
- return market ? this.platforms.market[platformAlias.toLowerCase()] : this.platforms[platformAlias.toLowerCase()];
52
- }
53
- }