warframe-nexus-query 2.1.1 → 2.2.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/README.md CHANGED
@@ -3,45 +3,385 @@
3
3
  [![Supported by the Warframe Community Developers](https://img.shields.io/badge/Warframe_Comm_Devs-supported-blue.svg?color=2E96EF&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyOTgiIGhlaWdodD0iMTczIiB2aWV3Qm94PSIwIDAgMjk4IDE3MyI%2BPHBhdGggZD0iTTE4NSA2N2MxNSA4IDI4IDE2IDMxIDE5czIzIDE4LTcgNjBjMCAwIDM1LTMxIDI2LTc5LTE0LTctNjItMzYtNzAtNDUtNC01LTEwLTEyLTE1LTIyLTUgMTAtOSAxNC0xNSAyMi0xMyAxMy01OCAzOC03MiA0NS05IDQ4IDI2IDc5IDI2IDc5LTMwLTQyLTEwLTU3LTctNjBsMzEtMTkgMzYtMjIgMzYgMjJ6TTU1IDE3M2wtMTctM2MtOC0xOS0yMC00NC0yNC01MC01LTctNy0xMS0xNC0xNWwxOC0yYzE2LTMgMjItNyAzMi0xMyAxIDYgMCA5IDIgMTQtNiA0LTIxIDEwLTI0IDE2IDMgMTQgNSAyNyAyNyA1M3ptMTYtMTFsLTktMi0xNC0yOWEzMCAzMCAwIDAgMC04LThoN2wxMy00IDQgN2MtMyAyLTcgMy04IDZhODYgODYgMCAwIDAgMTUgMzB6bTE3MiAxMWwxNy0zYzgtMTkgMjAtNDQgMjQtNTAgNS03IDctMTEgMTQtMTVsLTE4LTJjLTE2LTMtMjItNy0zMi0xMy0xIDYgMCA5LTIgMTQgNiA0IDIxIDEwIDI0IDE2LTMgMTQtNSAyNy0yNyA1M3ptLTE2LTExbDktMiAxNC0yOWEzMCAzMCAwIDAgMSA4LThoLTdsLTEzLTQtNCA3YzMgMiA3IDMgOCA2YTg2IDg2IDAgMCAxLTE1IDMwem0tNzktNDBsLTYtNmMtMSAzLTMgNi02IDdsNSA1YTUgNSAwIDAgMSAyIDB6bS0xMy0yYTQgNCAwIDAgMSAxLTJsMi0yYTQgNCAwIDAgMSAyLTFsNC0xNy0xNy0xMC04IDcgMTMgOC0yIDctNyAyLTgtMTItOCA4IDEwIDE3em0xMiAxMWE1IDUgMCAwIDAtNC0yIDQgNCAwIDAgMC0zIDFsLTMwIDI3YTUgNSAwIDAgMCAwIDdsNCA0YTYgNiAwIDAgMCA0IDIgNSA1IDAgMCAwIDMtMWwyNy0zMWMyLTIgMS01LTEtN3ptMzkgMjZsLTMwLTI4LTYgNmE1IDUgMCAwIDEgMCAzbDI2IDI5YTEgMSAwIDAgMCAxIDBsNS0yIDItMmMxLTIgMy01IDItNnptNS00NWEyIDIgMCAwIDAtNCAwbC0xIDEtMi00YzEtMy01LTktNS05LTEzLTE0LTIzLTE0LTI3LTEzLTIgMS0yIDEgMCAyIDE0IDIgMTUgMTAgMTMgMTNhNCA0IDAgMCAwLTEgMyAzIDMgMCAwIDAgMSAxbC0yMSAyMmE3IDcgMCAwIDEgNCAyIDggOCAwIDAgMSAyIDNsMjAtMjFhNyA3IDAgMCAwIDEgMSA0IDQgMCAwIDAgNCAwYzEtMSA2IDMgNyA0aC0xYTMgMyAwIDAgMCAwIDQgMiAyIDAgMCAwIDQgMGw2LTZhMyAzIDAgMCAwIDAtM3oiIGZpbGw9IiMyZTk2ZWYiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvc3ZnPg%3D%3D)](https://github.com/WFCD/banner/blob/master/PROJECTS.md)
4
4
  [![Discord](https://img.shields.io/discord/256087517353213954.svg?logo=discord)](https://discord.gg/jGZxH9f)
5
5
 
6
+ A Node.js library for querying Warframe item prices from the [Warframe.Market](https://warframe.market) API.
6
7
 
7
- A node project for allowing simple summary of the [Warframe.Market](https://warframe.market) pricing API.
8
+ ## Features
9
+
10
+ - 🔄 Support for both Warframe Market API v1 and v2
11
+ - 📊 Real-time price statistics (median, min, max, average)
12
+ - 👥 Live trader information with online status (v2)
13
+ - 🌍 Full internationalization support (12 languages)
14
+ - 🎮 Multi-platform support (PC, PlayStation, Xbox, Nintendo Switch)
15
+ - 💾 Smart caching with version-based invalidation
16
+ - 📱 Discord webhook integration ready
8
17
 
9
18
  ## Installation
10
- ```
19
+
20
+ ```bash
11
21
  npm install --save warframe-nexus-query
12
22
  ```
13
23
 
14
- ## Usage
24
+ ## Quick Start
25
+
26
+ ```javascript
27
+ import PriceCheckQuerier from 'warframe-nexus-query';
28
+
29
+ const querier = new PriceCheckQuerier({ logger: console });
30
+
31
+ // Query item prices
32
+ const results = await querier.priceCheckQuery('loki prime', 'pc');
33
+ console.log(results);
34
+
35
+ // Get Discord-formatted attachments
36
+ const attachments = await querier.priceCheckQueryAttachment('ash prime systems', undefined, 'pc');
37
+ console.log(attachments);
38
+
39
+ // Clean up when done
40
+ await querier.stopUpdating();
41
+ ```
42
+
43
+ ## API
44
+
45
+ ### Constructor
46
+
47
+ ```javascript
48
+ const querier = new PriceCheckQuerier(options);
49
+ ```
50
+
51
+ **Options:**
52
+
53
+ - `logger` - Logger instance (default: `console`)
54
+ - `marketCache` - Custom cache implementation (optional)
55
+ - `skipMarket` - Skip market data fetching (default: `false`)
56
+
57
+ ### Methods
58
+
59
+ #### `priceCheckQuery(query, platform)`
60
+
61
+ Query item prices and return raw result objects.
62
+
63
+ **Parameters:**
64
+
65
+ - `query` (string) - Item name to search for
66
+ - `platform` (string) - Platform: `'pc'`, `'ps4'`, `'playstation'`, `'xb1'`, `'xbox'`, `'xbone'`, `'swi'`, `'switch'`, `'ns'`
67
+
68
+ **Returns:** `Promise<Array<Summary>>` - Array of price summary objects
69
+
70
+ ```javascript
71
+ const results = await querier.priceCheckQuery('nova prime set', 'pc');
72
+ ```
73
+
74
+ #### `priceCheckQueryString(query, platform)`
75
+
76
+ Query item prices and return formatted string.
77
+
78
+ **Parameters:**
79
+
80
+ - `query` (string) - Item name to search for
81
+ - `platform` (string) - Platform identifier
82
+
83
+ **Returns:** `Promise<string>` - Formatted price string
84
+
85
+ ```javascript
86
+ const priceString = await querier.priceCheckQueryString('maiming strike', 'pc');
87
+ console.log(priceString); // "Maiming Strike: 150p (avg)"
88
+ ```
89
+
90
+ #### `priceCheckQueryAttachment(query, priorResults, platform)`
91
+
92
+ Query item prices and return Discord-formatted embeds.
93
+
94
+ **Parameters:**
95
+
96
+ - `query` (string) - Item name to search for
97
+ - `priorResults` (Array|undefined) - Prior query results to use instead of fetching new data
98
+ - `platform` (string) - Platform identifier
99
+
100
+ **Returns:** `Promise<Array<Object>>` - Array of Discord embed objects
101
+
102
+ ```javascript
103
+ const embeds = await querier.priceCheckQueryAttachment('condition overload', undefined, 'pc');
104
+ // Send embeds to Discord webhook
105
+ await fetch(webhookUrl, {
106
+ method: 'POST',
107
+ body: JSON.stringify({ embeds }),
108
+ headers: { 'Content-Type': 'application/json' },
109
+ });
110
+ ```
111
+
112
+ #### `stopUpdating()`
113
+
114
+ Clean up resources and stop background updates.
115
+
116
+ ```javascript
117
+ await querier.stopUpdating();
118
+ ```
119
+
120
+ ## Environment Variables
121
+
122
+ | Variable | Description | Default | Example |
123
+ | ----------------------------- | ------------------------ | --------- | ----------------------- |
124
+ | `WARFRAME_MARKET_API_VERSION` | API version to use | `v1` | `v2` |
125
+ | `MARKET_TIMEOUT` | API request timeout (ms) | `30000` | `60000` |
126
+ | `MARKET_CACHE_PATH` | Cache directory path | `./cache` | `/tmp/wf-cache` |
127
+ | `MARKET_V2_URL_OVERRIDE` | Custom v2 API base URL | - | `https://custom.api/v2` |
128
+
129
+ ### API Version Selection
130
+
131
+ Switch between v1 and v2 APIs:
132
+
133
+ ```bash
134
+ # Use v2 API (recommended)
135
+ WARFRAME_MARKET_API_VERSION=v2 node app.js
136
+
137
+ # Use v1 API (legacy)
138
+ WARFRAME_MARKET_API_VERSION=v1 node app.js
139
+ ```
140
+
141
+ ## API v2 Features
142
+
143
+ The v2 API includes enhanced features:
144
+
145
+ - **Version-based caching** - Automatic cache invalidation when items update
146
+ - **Real-time trader data** - See who's online and ready to trade
147
+ - **Trader activity** - View current in-game activity (mission, dojo, relay, etc.)
148
+ - **User reputation** - Trader reputation scores
149
+ - **Crossplay support** - Trade across platforms
150
+ - **Better performance** - Optimized endpoints for faster queries
151
+
152
+ ### v2 Example Response
153
+
154
+ ```javascript
155
+ {
156
+ item: 'Ash Prime Systems',
157
+ prices: {
158
+ selling: { median: 15, average: 18.5, min: 10, max: 30 },
159
+ buying: { median: 12, average: 11.8, min: 8, max: 15 }
160
+ },
161
+ traders: [
162
+ {
163
+ user: 'TraderName',
164
+ platinum: 15,
165
+ quantity: 3,
166
+ status: 'online',
167
+ reputation: 156,
168
+ activity: 'In Dojo'
169
+ }
170
+ ]
171
+ }
172
+ ```
173
+
174
+ ## Platform Aliases
175
+
176
+ The following platform identifiers are supported:
177
+
178
+ | Platform | Aliases |
179
+ | --------------- | ---------------------- |
180
+ | PC | `pc` |
181
+ | PlayStation | `ps4`, `playstation` |
182
+ | Xbox | `xb1`, `xbox`, `xbone` |
183
+ | Nintendo Switch | `swi`, `switch`, `ns` |
184
+
185
+ ## Response Objects
186
+
187
+ ### Summary Object
188
+
189
+ Result object returned by `priceCheckQuery()`:
190
+
191
+ ```javascript
192
+ {
193
+ type: 'market-v2', // 'market' for v1, 'market-v2' for v2
194
+ item: 'Item Name',
195
+ platform: 'pc',
196
+ componentName: 'Set',
197
+ prices: {
198
+ selling: {
199
+ median: 100,
200
+ average: 105.5,
201
+ min: 80,
202
+ max: 150,
203
+ count: 25
204
+ },
205
+ buying: {
206
+ median: 90,
207
+ average: 88.2,
208
+ min: 60,
209
+ max: 95,
210
+ count: 15
211
+ }
212
+ },
213
+ traders: [ // v2 only
214
+ {
215
+ user: 'Username',
216
+ platinum: 100,
217
+ quantity: 2,
218
+ status: 'online', // 'online' | 'ingame' | 'offline'
219
+ reputation: 250,
220
+ activity: 'On Mission'
221
+ }
222
+ ]
223
+ }
224
+ ```
225
+
226
+ ### Discord Embed Object
227
+
228
+ Result object returned by `priceCheckQueryAttachment()`:
229
+
230
+ ```javascript
231
+ {
232
+ title: 'Ash Prime Systems [PC]',
233
+ url: 'https://warframe.market/items/ash_prime_systems',
234
+ thumbnail: { url: 'https://warframe.market/static/assets/...' },
235
+ color: 0x336699,
236
+ fields: [
237
+ {
238
+ name: 'Selling',
239
+ value: '💰 15p (median)\n📊 10-30p range\n📦 25 orders',
240
+ inline: true
241
+ },
242
+ {
243
+ name: 'Buying',
244
+ value: '💰 12p (median)\n📊 8-15p range\n📦 15 orders',
245
+ inline: true
246
+ },
247
+ {
248
+ name: '🟢 Online Traders',
249
+ value: 'TraderName: 15p x3'
250
+ }
251
+ ],
252
+ footer: {
253
+ text: 'Warframe Market • Updated 2 minutes ago'
254
+ }
255
+ }
256
+ ```
257
+
258
+ ## Examples
259
+
260
+ ### Basic Price Check
261
+
262
+ ```javascript
263
+ import PriceCheckQuerier from 'warframe-nexus-query';
264
+
265
+ const querier = new PriceCheckQuerier({ logger: console });
266
+
267
+ // Search for an item
268
+ const results = await querier.priceCheckQuery('nikana prime', 'pc');
269
+
270
+ results.forEach((result) => {
271
+ console.log(`${result.item} - ${result.componentName}`);
272
+ console.log(`Median sell price: ${result.prices.selling.median}p`);
273
+ console.log(`Median buy price: ${result.prices.buying.median}p`);
274
+ });
275
+
276
+ await querier.stopUpdating();
277
+ ```
278
+
279
+ ### Discord Bot Integration
280
+
281
+ ```javascript
282
+ import PriceCheckQuerier from 'warframe-nexus-query';
283
+ import { Client, GatewayIntentBits } from 'discord.js';
284
+
285
+ const bot = new Client({ intents: [GatewayIntentBits.Guilds] });
286
+ const querier = new PriceCheckQuerier({ logger: console });
287
+
288
+ bot.on('interactionCreate', async (interaction) => {
289
+ if (!interaction.isChatInputCommand()) return;
290
+
291
+ if (interaction.commandName === 'price') {
292
+ const item = interaction.options.getString('item');
293
+ const platform = interaction.options.getString('platform') || 'pc';
294
+
295
+ const embeds = await querier.priceCheckQueryAttachment(item, undefined, platform);
296
+
297
+ if (embeds.length > 0) {
298
+ await interaction.reply({ embeds });
299
+ } else {
300
+ await interaction.reply('No results found for that item.');
301
+ }
302
+ }
303
+ });
304
+
305
+ bot.login(process.env.DISCORD_TOKEN);
306
+ ```
307
+
308
+ ### Multi-Platform Price Comparison
309
+
310
+ ```javascript
311
+ import PriceCheckQuerier from 'warframe-nexus-query';
312
+
313
+ const querier = new PriceCheckQuerier({ logger: console });
314
+ const platforms = ['pc', 'ps4', 'xbox', 'switch'];
315
+
316
+ for (const platform of platforms) {
317
+ const results = await querier.priceCheckQuery('Trinity Prime Set', platform);
318
+
319
+ if (results.length > 0) {
320
+ const price = results[0].prices.selling.median;
321
+ console.log(`${platform.toUpperCase()}: ${price}p`);
322
+ }
323
+ }
324
+
325
+ await querier.stopUpdating();
326
+ ```
327
+
328
+ ## Testing
329
+
330
+ ```bash
331
+ # Run tests
332
+ npm test
333
+
334
+ # Run linter
335
+ npm run lint
336
+
337
+ # Generate coverage report
338
+ npm run coverage
339
+
340
+ # Generate API documentation
341
+ npm run build:docs
342
+ ```
343
+
344
+ ## Development
345
+
346
+ ```bash
347
+ # Clone repository
348
+ git clone https://github.com/WFCD/warframe-nexus-query.git
349
+ cd warframe-nexus-query
350
+
351
+ # Install dependencies
352
+ npm install
353
+
354
+ # Run tests in watch mode
355
+ npm test -- --watch
356
+
357
+ # Lint and auto-fix
358
+ npm run lint:fix
359
+ ```
15
360
 
16
- | Require | Module File | Accessor | Description | parameters |
17
- |------------------------|-------------|--------------------------|---------------------------------------------------------|---------------------|
18
- | `warframe-nexus-query` | `index.js` | `.priceCheckQueryString` | Get Query result string | `query`, `callback` |
19
- | `warframe-nexus-query` | `index.js` | `.priceCheckQuery` | Get Query result objects, has more parameters available | `query`, `callback` |
361
+ ## Contributing
20
362
 
21
- ## Environment variables
363
+ Contributions are welcome! Please:
22
364
 
23
- | Variable | example | default |
24
- |------------------------------|---------------------------------|-------------------------------|
25
- | `NEXUSSTATS_MAX_CACHED_TIME` | `600000` | `30000` |
26
- | `NEXUSSTATS_URL_OVERRIDE` | `'https://nexus-stats.com/api'` | `https://nexus-stats.com/api` |
365
+ 1. Fork the repository
366
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
367
+ 3. Commit your changes (`git commit -m 'feat: add amazing feature'`)
368
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
369
+ 5. Open a Pull Request
27
370
 
371
+ ## License
28
372
 
29
- ## Objects
373
+ Licensed under the Apache License 2.0. See [LICENSE](LICENSE) for details.
30
374
 
31
- Item
375
+ ## Links
32
376
 
33
- * `components` - List of component objects
34
- * `id` - Unique identifier for the Item object
35
- * `title` - Title of the item
36
- * `type` - Type of the item
37
- * `supplyPercent` - Of the total amount of item listings for this object, this is the percent for sale
38
- * `demandPercent` - Of the total amount of item listings for this object, this is t looking to be bought
39
- * `supplyAmount` - Of the total amount of item listings for this object, this is the number for sale
40
- * `demandAmount` - Of the total amount of item listings for this object, this is the number looking to be bought
377
+ - [GitHub Repository](https://github.com/WFCD/warframe-nexus-query)
378
+ - [npm Package](https://www.npmjs.com/package/warframe-nexus-query)
379
+ - [Warframe Market API](https://warframe.market)
380
+ - [Discord Community](https://discord.gg/jGZxH9f)
381
+ - [Warframe Community Developers](https://github.com/WFCD)
41
382
 
42
- Component
383
+ ## Acknowledgments
43
384
 
44
- * `name` - Name of the component
45
- * `avgPrice` - Average platinum price
46
- * `rawAverage` - Raw average (non-rounded) price of the component
47
- * `data` - Array of Miscellaneous data
385
+ - Built by the [Warframe Community Developers](https://github.com/WFCD)
386
+ - Powered by [Warframe.Market](https://warframe.market) API
387
+ - Maintained by [tobitenno](https://github.com/tobitenno) and contributors
package/index.js CHANGED
@@ -7,9 +7,11 @@ 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 MarketFetcher from './lib/market/v1/MarketFetcher.js';
10
+ import { MarketFetcherV2 } from './lib/market/v2/index.js';
11
11
 
12
12
  export default class PriceCheckQuerier {
13
+ #useV2 = false;
14
+
13
15
  /**
14
16
  * Creates an instance representing a WarframeNexusStats data object
15
17
  * @constructor
@@ -18,14 +20,25 @@ export default class PriceCheckQuerier {
18
20
  this.settings = new Settings();
19
21
  this.logger = logger;
20
22
  this.skipMarket = skipMarket;
23
+ this.marketFetcher = marketCache;
21
24
 
22
25
  if (!skipMarket) {
23
26
  try {
27
+ this.#useV2 = process.env.WARFRAME_MARKET_API_VERSION === 'v2';
24
28
  /**
25
29
  * Fetch market data
26
- * @type {MarketFetcher}
30
+ * @type {MarketFetcher|MarketFetcherV2}
27
31
  */
28
- this.marketFetcher = new MarketFetcher({ logger, settings: this.settings, marketCache });
32
+ if (this.#useV2) {
33
+ this.logger.debug('Using Warframe Market API v2');
34
+ this.marketFetcher = new MarketFetcherV2({ logger });
35
+ this.apiVersion = 'v2';
36
+ } else {
37
+ this.logger.info('Using Warframe Market API v1');
38
+ this.logger.warn('Api v1 is deprecated and impossible to use');
39
+ this.marketFetcher = new MarketFetcherV2({ logger });
40
+ this.apiVersion = 'v2';
41
+ }
29
42
  } catch (e) {
30
43
  this.logger.error(`couldn't set up market fetcher: ${e.message}`);
31
44
  }
@@ -113,10 +126,16 @@ export default class PriceCheckQuerier {
113
126
  */
114
127
  async stopUpdating() {
115
128
  /* istanbul ignore else */
116
- if (!this.skipMarket && this.marketFetcher.marketCache) {
117
- this.marketFetcher.marketCache.stop();
129
+ if (!this.skipMarket && this.marketFetcher) {
130
+ // v1 API uses marketCache
131
+ if (this.marketFetcher.marketCache) {
132
+ this.marketFetcher.marketCache.stop();
133
+ } else if (typeof this.marketFetcher.stop === 'function') {
134
+ // v2 API has stop() method
135
+ this.marketFetcher.stop();
136
+ }
118
137
  } else {
119
- this.logger.log('no market cache, or skipMarket was true');
138
+ this.logger.log('no market fetcher, or skipMarket was true');
120
139
  }
121
140
 
122
141
  if (fss.existsSync(`${global.__basedir}/tmp`)) {
@@ -1,7 +1,5 @@
1
1
  import n from 'numeral';
2
2
 
3
- import MarketComponent from './market/v1/summary.js'; // eslint-disable-line no-unused-vars
4
-
5
3
  const numerFmt = '0,0';
6
4
  const wfcdLogo = 'https://warframestat.us/wfcd_logo_color.png';
7
5
 
@@ -49,7 +47,7 @@ function safeRange(value1, value2) {
49
47
  }
50
48
 
51
49
  /**
52
- * Build a field from provided nexus & market components
50
+ * Build a field from provided nexus & market components (v1)
53
51
  * @param {MarketComponent} mComponent market component
54
52
  * @returns {Object} built field
55
53
  */
@@ -75,6 +73,67 @@ function fieldValue(mComponent) {
75
73
  };
76
74
  }
77
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
+
78
137
  /**
79
138
  * Create the attachment itself
80
139
  */
@@ -91,10 +150,23 @@ export default class AttachmentCreator {
91
150
  if (!components || !components.length || !Array.isArray(components)) return noResultAttachment;
92
151
 
93
152
  const attachment = JSON.parse(JSON.stringify(baseAttachment));
94
- const marketComponents = components.filter(
95
- (component) => component && component.type === 'market-v1' && typeof component.prices.soldPrice !== 'undefined'
153
+
154
+ // Check if we have v2 components
155
+ const v2Components = components.filter(
156
+ (component) => component && component.type === 'market-v2' && component.statistics
96
157
  );
97
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
+
98
170
  /* istanbul ignore else */
99
171
  if (marketComponents.length > 0) {
100
172
  marketComponents.forEach((marketComponent, index) => {
@@ -105,12 +177,13 @@ export default class AttachmentCreator {
105
177
  attachment.thumbnail.url = marketComponent.thumbnail;
106
178
  }
107
179
 
108
- attachment.fields.push(fieldValue(marketComponent));
180
+ // Use appropriate field builder based on version
181
+ attachment.fields.push(isV2 ? fieldValueV2(marketComponent) : fieldValue(marketComponent));
109
182
  });
110
183
 
111
184
  attachment.footer = {
112
185
  icon_url: wfcdLogo,
113
- text: 'Price data provided by Warframe.Market',
186
+ text: isV2 ? 'Price data provided by Warframe.Market (API v2)' : 'Price data provided by Warframe.Market',
114
187
  };
115
188
  } else {
116
189
  return noResultAttachment;
@@ -0,0 +1,6 @@
1
+ {
2
+ "rules": {
3
+ "no-null/no-null": "off",
4
+ "no-use-before-define": ["error", { "functions": false }]
5
+ }
6
+ }