warframe-nexus-query 1.7.1 → 2.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/index.js +19 -26
- package/lib/AttachmentCreator.js +3 -7
- package/lib/Settings.js +2 -6
- package/lib/market/v1/MarketFetcher.js +13 -16
- package/lib/market/v1/summary.js +6 -10
- package/lib/promiseTimeout.js +1 -3
- package/package.json +15 -21
package/index.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import fss from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
const fs = require('fs').promises;
|
|
5
|
-
const fss = require('fs');
|
|
6
|
-
const path = require('path');
|
|
5
|
+
import md from 'node-md-config';
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
import promiseTimeout from './lib/promiseTimeout.js';
|
|
8
|
+
import Settings from './lib/Settings.js';
|
|
9
|
+
import Creator from './lib/AttachmentCreator.js';
|
|
10
|
+
import MarketFetcher from './lib/market/v1/MarketFetcher.js';
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
global.__basedir = __dirname;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
module.exports = class PriceCheckQuerier {
|
|
12
|
+
export default class PriceCheckQuerier {
|
|
18
13
|
/**
|
|
19
14
|
* Creates an instance representing a WarframeNexusStats data object
|
|
20
15
|
* @constructor
|
|
@@ -32,7 +27,7 @@ module.exports = class PriceCheckQuerier {
|
|
|
32
27
|
*/
|
|
33
28
|
this.marketFetcher = new MarketFetcher({ logger, settings: this.settings, marketCache });
|
|
34
29
|
} catch (e) {
|
|
35
|
-
|
|
30
|
+
this.logger.error(`couldn't set up market fetcher: ${e.message}`);
|
|
36
31
|
}
|
|
37
32
|
}
|
|
38
33
|
|
|
@@ -71,7 +66,7 @@ module.exports = class PriceCheckQuerier {
|
|
|
71
66
|
const marketResults = await promiseTimeout(this.settings.timeouts.market, marketPromise);
|
|
72
67
|
attachments = [...attachments, ...marketResults];
|
|
73
68
|
} catch (e) {
|
|
74
|
-
|
|
69
|
+
this.logger.error(`Couldn't process ${query} on warframe.market... time out.`);
|
|
75
70
|
}
|
|
76
71
|
} else {
|
|
77
72
|
this.logger.info('No market fetcher, skipping market');
|
|
@@ -128,16 +123,14 @@ module.exports = class PriceCheckQuerier {
|
|
|
128
123
|
const files = await fs.readdir(`${global.__basedir}/tmp`);
|
|
129
124
|
let allSuccess = true;
|
|
130
125
|
await Promise.all(
|
|
131
|
-
files.map(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
this.logger.debug(`Couldn't delete ${file}`);
|
|
138
|
-
}
|
|
126
|
+
files.map(async (file) => {
|
|
127
|
+
try {
|
|
128
|
+
await fs.unlink(path.join(global.__basedir, 'tmp', file));
|
|
129
|
+
} catch (e) {
|
|
130
|
+
allSuccess = false;
|
|
131
|
+
this.logger.debug(`Couldn't delete ${file}`);
|
|
139
132
|
}
|
|
140
|
-
)
|
|
133
|
+
})
|
|
141
134
|
);
|
|
142
135
|
|
|
143
136
|
if (allSuccess) {
|
|
@@ -145,4 +138,4 @@ module.exports = class PriceCheckQuerier {
|
|
|
145
138
|
}
|
|
146
139
|
}
|
|
147
140
|
}
|
|
148
|
-
}
|
|
141
|
+
}
|
package/lib/AttachmentCreator.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import n from 'numeral';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const n = require('numeral');
|
|
5
|
-
const MarketComponent = require('./market/v1/summary'); // eslint-disable-line no-unused-vars
|
|
3
|
+
import MarketComponent from './market/v1/summary.js'; // eslint-disable-line no-unused-vars
|
|
6
4
|
|
|
7
5
|
const numerFmt = '0,0';
|
|
8
6
|
const wfcdLogo = 'https://warframestat.us/wfcd_logo_color.png';
|
|
@@ -80,7 +78,7 @@ function fieldValue(mComponent) {
|
|
|
80
78
|
/**
|
|
81
79
|
* Create the attachment itself
|
|
82
80
|
*/
|
|
83
|
-
class AttachmentCreator {
|
|
81
|
+
export default class AttachmentCreator {
|
|
84
82
|
/**
|
|
85
83
|
* Build an attachment from the provided components
|
|
86
84
|
* @param {Array<MarketComponent>} components -
|
|
@@ -125,5 +123,3 @@ class AttachmentCreator {
|
|
|
125
123
|
return noResultAttachment;
|
|
126
124
|
}
|
|
127
125
|
}
|
|
128
|
-
|
|
129
|
-
module.exports = AttachmentCreator;
|
package/lib/Settings.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Settings storage for nexus query
|
|
5
3
|
* @type {Settings}
|
|
6
4
|
* @property {number} maxCacheLength - maximum length to store cached data
|
|
7
5
|
* @property {Object} urls - URL list for nexus stats
|
|
8
6
|
*/
|
|
9
|
-
class Settings {
|
|
7
|
+
export default class Settings {
|
|
10
8
|
constructor() {
|
|
11
9
|
this.urls = {
|
|
12
10
|
market: process.env.MARKET_URL_OVERRIDE || 'https://api.warframe.market/v1/items',
|
|
@@ -37,7 +35,7 @@ class Settings {
|
|
|
37
35
|
};
|
|
38
36
|
|
|
39
37
|
this.timeouts = {
|
|
40
|
-
market: process.env.MARKET_TIMEOUT ||
|
|
38
|
+
market: process.env.MARKET_TIMEOUT || 3000,
|
|
41
39
|
};
|
|
42
40
|
|
|
43
41
|
this.defaultString = 'Operator, there is no such item pricecheck available.';
|
|
@@ -53,5 +51,3 @@ class Settings {
|
|
|
53
51
|
return market ? this.platforms.market[platformAlias.toLowerCase()] : this.platforms[platformAlias.toLowerCase()];
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
|
-
|
|
57
|
-
module.exports = Settings;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const fs = require('fs').promises;
|
|
3
|
+
import getColors from 'get-image-colors';
|
|
4
|
+
import imageDownloader from 'image-downloader';
|
|
5
|
+
import jsonQuery from 'json-query';
|
|
6
|
+
import JSONCache from 'json-fetch-cache';
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
import { baseDir } from '../../../basedir.js';
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
import MarketSummary from './summary.js';
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* @typedef {Object} MappedPrice
|
|
@@ -19,10 +18,10 @@ const MarketSummary = require('./summary');
|
|
|
19
18
|
* @property {string} datetime ts formatted date string
|
|
20
19
|
*/
|
|
21
20
|
|
|
22
|
-
class MarketFetcher {
|
|
21
|
+
export default class MarketFetcher {
|
|
23
22
|
constructor({ logger = console, settings, marketCache }) {
|
|
24
23
|
/**
|
|
25
|
-
* The json cache
|
|
24
|
+
* The json cache stored data from warframe.market
|
|
26
25
|
* @type {JSONCache}
|
|
27
26
|
*/
|
|
28
27
|
this.marketCache = marketCache || new JSONCache(settings.urls.market, settings.maxCacheLength, { logger });
|
|
@@ -91,7 +90,7 @@ class MarketFetcher {
|
|
|
91
90
|
async summaryForItem(item) {
|
|
92
91
|
try {
|
|
93
92
|
// set up temp folder
|
|
94
|
-
await fs.mkdir(`${
|
|
93
|
+
await fs.mkdir(`${baseDir}/tmp`);
|
|
95
94
|
} catch (e) {
|
|
96
95
|
// this.logger.error(e);
|
|
97
96
|
}
|
|
@@ -100,7 +99,7 @@ class MarketFetcher {
|
|
|
100
99
|
summary.prices = await this.averagesForItem(item.url_name);
|
|
101
100
|
const options = {
|
|
102
101
|
url: summary.thumbnail,
|
|
103
|
-
dest: `${
|
|
102
|
+
dest: `${baseDir}/tmp/${summary.name}.png`,
|
|
104
103
|
};
|
|
105
104
|
try {
|
|
106
105
|
const { image } = await imageDownloader.image(options);
|
|
@@ -112,7 +111,7 @@ class MarketFetcher {
|
|
|
112
111
|
/* istanbul ignore next */
|
|
113
112
|
this.logger.error(e);
|
|
114
113
|
} finally {
|
|
115
|
-
await fs.unlink(`${
|
|
114
|
+
await fs.unlink(`${baseDir}/tmp/${summary.name}.png`);
|
|
116
115
|
}
|
|
117
116
|
return summary;
|
|
118
117
|
}
|
|
@@ -123,7 +122,7 @@ class MarketFetcher {
|
|
|
123
122
|
try {
|
|
124
123
|
// get market data
|
|
125
124
|
const marketData = await this.marketCache.getDataJson();
|
|
126
|
-
|
|
125
|
+
if (!marketData) {
|
|
127
126
|
this.logger.info('No market data!');
|
|
128
127
|
return [];
|
|
129
128
|
}
|
|
@@ -147,5 +146,3 @@ class MarketFetcher {
|
|
|
147
146
|
return attachments;
|
|
148
147
|
}
|
|
149
148
|
}
|
|
150
|
-
|
|
151
|
-
module.exports = MarketFetcher;
|
package/lib/market/v1/summary.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const urls = {
|
|
4
2
|
market: process.env.MARKET_URL_OVERRIDE || 'https://api.warframe.market/v1/items',
|
|
5
3
|
marketAssets: process.env.MARKET_ASSETS_URL_OVERRIDE || 'https://warframe.market/static/assets/',
|
|
@@ -8,7 +6,7 @@ const urls = {
|
|
|
8
6
|
/**
|
|
9
7
|
* Represents an individual component object of an item.
|
|
10
8
|
*/
|
|
11
|
-
class Summary {
|
|
9
|
+
export default class Summary {
|
|
12
10
|
/**
|
|
13
11
|
* Represents an individual item.
|
|
14
12
|
* @param {json} itemData the component data to parse into a summary
|
|
@@ -18,7 +16,7 @@ class Summary {
|
|
|
18
16
|
this.name = itemData.en.item_name.trim();
|
|
19
17
|
this.thumbnail = `${urls.marketAssets}${itemData.thumb}`;
|
|
20
18
|
this.partThumb = `${urls.marketAssets}${itemData.sub_icon}`;
|
|
21
|
-
|
|
19
|
+
this.tradingTax = itemData.trading_tax || 0;
|
|
22
20
|
this.ducats = itemData.ducats || 0;
|
|
23
21
|
this.masteryLevel = itemData.mastery_level;
|
|
24
22
|
this.tradable = itemData.tradable;
|
|
@@ -38,17 +36,17 @@ class Summary {
|
|
|
38
36
|
*/
|
|
39
37
|
toString(opt = 'item') {
|
|
40
38
|
let value = this.name;
|
|
41
|
-
|
|
39
|
+
if (opt === 'codex' || opt === 'all') {
|
|
42
40
|
value += `\`\`\`\nCodex: ${this.codex}\n`;
|
|
43
41
|
}
|
|
44
|
-
|
|
42
|
+
if (opt === 'item' || opt === 'all') {
|
|
45
43
|
value +=
|
|
46
44
|
`${this.pad(`Requires: ${this.masteryLevel}`, 15)}| Tax: ${this.pad(`${this.tradingTax}cr`)}\n` +
|
|
47
|
-
`Item is ${
|
|
45
|
+
`Item is ${this.tradable ? '' : ' not '} tradable\n` +
|
|
48
46
|
`${this.pad(`Sold ${this.prices.soldCount} for ${this.prices.soldPrice}`, 15)}|` +
|
|
49
47
|
`Minimum ${this.prices.minimum} | Maximum ${this.prices.maximum}\n`;
|
|
50
48
|
}
|
|
51
|
-
|
|
49
|
+
if (opt === 'location' || opt === 'all') {
|
|
52
50
|
value += `${this.pad(`Drops: ${this.drops.map((drop) => drop.name).join(', ')}`, 15)}\n`;
|
|
53
51
|
}
|
|
54
52
|
value += `\`\`\`\n${this.wikiUrl}`;
|
|
@@ -65,5 +63,3 @@ class Summary {
|
|
|
65
63
|
return stringRet;
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
|
-
|
|
69
|
-
module.exports = Summary;
|
package/lib/promiseTimeout.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Copied from https://italonascimento.github.io/applying-a-timeout-to-your-promises
|
|
5
3
|
* Apply a timeout to your promise
|
|
@@ -7,7 +5,7 @@
|
|
|
7
5
|
* @param {Promise} promise Promise to time out
|
|
8
6
|
* @returns {Promise} Pending promise that works or rejects with an error
|
|
9
7
|
*/
|
|
10
|
-
|
|
8
|
+
export default (ms, promise) => {
|
|
11
9
|
// Create a promise that rejects in <ms> milliseconds
|
|
12
10
|
const timeout = new Promise((resolve, reject) => {
|
|
13
11
|
const id = setTimeout(() => {
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "warframe-nexus-query",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Query prices form nexus-stats.com and warframe.market.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "index.js",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"test": "
|
|
8
|
-
"coverage": "npm test &&
|
|
9
|
-
"build
|
|
8
|
+
"test": "c8 mocha",
|
|
9
|
+
"coverage": "npm test && c8 report --reporter=text-lcov | coveralls",
|
|
10
|
+
"build:docs": "jsdoc -c jsdoc-config.json -d docs",
|
|
10
11
|
"lint": "eslint index.js lib/ test/",
|
|
11
12
|
"lint:fix": "eslint index.js lib/ test/ --fix",
|
|
12
|
-
"postinstall": "install-peerdeps @wfcd/eslint-config@^1.
|
|
13
|
+
"postinstall": "install-peerdeps @wfcd/eslint-config@^1.5.0 -S"
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
16
|
"lib",
|
|
@@ -35,27 +36,26 @@
|
|
|
35
36
|
},
|
|
36
37
|
"homepage": "https://github.com/WFCD/warframe-nexus-query#README",
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"get-image-colors": "^
|
|
39
|
+
"get-image-colors": "^4.0.1",
|
|
39
40
|
"image-downloader": "^4.0.2",
|
|
40
41
|
"json-fetch-cache": "^1.2.6",
|
|
41
42
|
"json-query": "^2.2.2",
|
|
42
|
-
"node-fetch": "^2.6.0",
|
|
43
43
|
"node-md-config": "^2.0.1",
|
|
44
44
|
"numeral": "^2.0.6"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/json-query": "^2.2.0",
|
|
48
48
|
"@types/node-fetch": "^2.5.4",
|
|
49
|
-
"@wfcd/eslint-config": "^1.
|
|
49
|
+
"@wfcd/eslint-config": "^1.5.0",
|
|
50
|
+
"c8": "^9.1.0",
|
|
50
51
|
"chai": "^4.2.0",
|
|
51
52
|
"coveralls": "^3.1.1",
|
|
52
|
-
"install-peerdeps": "^
|
|
53
|
-
"mocha": "^10.2.0"
|
|
54
|
-
"nyc": "^15.1.0"
|
|
53
|
+
"install-peerdeps": "^2.0.3",
|
|
54
|
+
"mocha": "^10.2.0"
|
|
55
55
|
},
|
|
56
56
|
"engines": {
|
|
57
|
-
"node": ">=
|
|
58
|
-
"npm": ">=
|
|
57
|
+
"node": ">=18",
|
|
58
|
+
"npm": ">=8.19"
|
|
59
59
|
},
|
|
60
60
|
"release": {
|
|
61
61
|
"branch": "master"
|
|
@@ -68,13 +68,7 @@
|
|
|
68
68
|
"types/**"
|
|
69
69
|
],
|
|
70
70
|
"eslintConfig": {
|
|
71
|
-
"extends": "@wfcd",
|
|
72
|
-
"parserOptions": {
|
|
73
|
-
"ecmaVersion": 13
|
|
74
|
-
},
|
|
75
|
-
"env": {
|
|
76
|
-
"es6": true
|
|
77
|
-
},
|
|
71
|
+
"extends": "@wfcd/eslint-config/esm",
|
|
78
72
|
"rules": {
|
|
79
73
|
"no-underscore-dangle": [
|
|
80
74
|
"error",
|
|
@@ -102,7 +96,7 @@
|
|
|
102
96
|
"exit": true,
|
|
103
97
|
"slow": 10000
|
|
104
98
|
},
|
|
105
|
-
"
|
|
99
|
+
"c8": {
|
|
106
100
|
"reporter": [
|
|
107
101
|
"lcov",
|
|
108
102
|
"text"
|