Comparing version 2.2.0 to 2.3.0
@@ -6,3 +6,3 @@ { | ||
"main": "index.js", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"license": "MIT", | ||
@@ -31,4 +31,5 @@ "eslintConfig": { | ||
"dependencies": { | ||
"node-fetch": "^2.6.11", | ||
"steamid": "^2.0.0" | ||
} | ||
} |
@@ -64,27 +64,26 @@ ## SteamAPI | ||
- [Documentation](#documentation) | ||
- [SteamAPI](#steamapi-1) | ||
- [new SteamAPI(key, [options])](#new-steamapikey-options) | ||
- [steamAPI.get(path, [base], [key]) ⇒ <code>Promise.<Object></code>](#steamapigetpath-base-key-%E2%87%92-codepromiseltobjectgtcode) | ||
- [steamAPI.resolve(info) ⇒ <code>Promise.<string></code>](#steamapiresolveinfo-%E2%87%92-codepromiseltstringgtcode) | ||
- [steamAPI.getAppList() ⇒ <code>Promise.<Array.<App>></code>](#steamapigetapplist-%E2%87%92-codepromiseltarrayltappgtgtcode) | ||
- [steamAPI.getFeaturedCategories() ⇒ <code>Promise.<Array.<Object>></code>](#steamapigetfeaturedcategories-%E2%87%92-codepromiseltarrayltobjectgtgtcode) | ||
- [steamAPI.getFeaturedGames() ⇒ <code>Promise.<Object></code>](#steamapigetfeaturedgames-%E2%87%92-codepromiseltobjectgtcode) | ||
- [steamAPI.getGameAchievements(app) ⇒ <code>Promise.<Object></code>](#steamapigetgameachievementsapp-%E2%87%92-codepromiseltobjectgtcode) | ||
- [steamAPI.getGameDetails(app, [force]) ⇒ <code>Promise.<Object></code>](#steamapigetgamedetailsapp-force-%E2%87%92-codepromiseltobjectgtcode) | ||
- [steamAPI.getGameNews(app) ⇒ <code>Promise.<Array.<Object>></code>](#steamapigetgamenewsapp-%E2%87%92-codepromiseltarrayltobjectgtgtcode) | ||
- [steamAPI.getGamePlayers(app) ⇒ <code>Promise.<number></code>](#steamapigetgameplayersapp-%E2%87%92-codepromiseltnumbergtcode) | ||
- [steamAPI.getGameSchema(app) ⇒ <code>Promise.<Object></code>](#steamapigetgameschemaapp-%E2%87%92-codepromiseltobjectgtcode) | ||
- [steamAPI.getServers(host) ⇒ <code>Promise.<Array.<Server>></code>](#steamapigetservershost-%E2%87%92-codepromiseltarrayltservergtgtcode) | ||
- [steamAPI.getUserAchievements(id, app) ⇒ <code>Promise.<PlayerAchievements></code>](#steamapigetuserachievementsid-app-%E2%87%92-codepromiseltplayerachievementsgtcode) | ||
- [steamAPI.getUserBadges(id) ⇒ <code>Promise.<PlayerBadges></code>](#steamapigetuserbadgesid-%E2%87%92-codepromiseltplayerbadgesgtcode) | ||
- [steamAPI.getUserBans(id) ⇒ <code>Promise.<(PlayerBans\|Array.<PlayerBans>)></code>](#steamapigetuserbansid-%E2%87%92-codepromiseltplayerbansarrayltplayerbansgtgtcode) | ||
- [steamAPI.getUserFriends(id) ⇒ <code>Promise.<Array.<Friend>></code>](#steamapigetuserfriendsid-%E2%87%92-codepromiseltarrayltfriendgtgtcode) | ||
- [steamAPI.getUserGroups(id) ⇒ <code>Promise.<Array.<string>></code>](#steamapigetusergroupsid-%E2%87%92-codepromiseltarrayltstringgtgtcode) | ||
- [steamAPI.getUserLevel(id) ⇒ <code>Promise.<number></code>](#steamapigetuserlevelid-%E2%87%92-codepromiseltnumbergtcode) | ||
- [steamAPI.getUserOwnedGames(id) ⇒ <code>Promise.<Array.<Game>></code>](#steamapigetuserownedgamesid-%E2%87%92-codepromiseltarrayltgamegtgtcode) | ||
- [steamAPI.getUserRecentGames(id) ⇒ <code>Promise.<Array.<RecentGame>></code>](#steamapigetuserrecentgamesid-%E2%87%92-codepromiseltarrayltrecentgamegtgtcode) | ||
- [steamAPI.getUserServers([hide], [key]) ⇒ <code>Promise.<PlayerServers></code>](#steamapigetuserservershide-key-%E2%87%92-codepromiseltplayerserversgtcode) | ||
- [steamAPI.getUserStats(id, app) ⇒ <code>Promise.<PlayerStats></code>](#steamapigetuserstatsid-app-%E2%87%92-codepromiseltplayerstatsgtcode) | ||
- [steamAPI.getUserSummary(id) ⇒ <code>Promise.<PlayerSummary></code>](#steamapigetusersummaryid-%E2%87%92-codepromiseltplayersummarygtcode) | ||
* [SteamAPI](#SteamAPI) | ||
* [new SteamAPI(key, [options])](#new_SteamAPI_new) | ||
* [.get(path, [base], [key])](#SteamAPI+get) ⇒ <code>Promise.<Object></code> | ||
* [.resolve(info)](#SteamAPI+resolve) ⇒ <code>Promise.<string></code> | ||
* [.getAppList()](#SteamAPI+getAppList) ⇒ <code>Promise.<Array.<App>></code> | ||
* [.getFeaturedCategories()](#SteamAPI+getFeaturedCategories) ⇒ <code>Promise.<Array.<Object>></code> | ||
* [.getFeaturedGames()](#SteamAPI+getFeaturedGames) ⇒ <code>Promise.<Object></code> | ||
* [.getGameAchievements(app)](#SteamAPI+getGameAchievements) ⇒ <code>Promise.<Object></code> | ||
* [.getGameDetails(app, [force], [region])](#SteamAPI+getGameDetails) ⇒ <code>Promise.<Object></code> | ||
* [.getGameNews(app)](#SteamAPI+getGameNews) ⇒ <code>Promise.<Array.<Object>></code> | ||
* [.getGamePlayers(app)](#SteamAPI+getGamePlayers) ⇒ <code>Promise.<number></code> | ||
* [.getGameSchema(app)](#SteamAPI+getGameSchema) ⇒ <code>Promise.<Object></code> | ||
* [.getServers(host)](#SteamAPI+getServers) ⇒ <code>Promise.<Array.<Server>></code> | ||
* [.getUserAchievements(id, app)](#SteamAPI+getUserAchievements) ⇒ <code>Promise.<PlayerAchievements></code> | ||
* [.getUserBadges(id)](#SteamAPI+getUserBadges) ⇒ <code>Promise.<PlayerBadges></code> | ||
* [.getUserBans(id)](#SteamAPI+getUserBans) ⇒ <code>Promise.<(PlayerBans\|Array.<PlayerBans>)></code> | ||
* [.getUserFriends(id)](#SteamAPI+getUserFriends) ⇒ <code>Promise.<Array.<Friend>></code> | ||
* [.getUserGroups(id)](#SteamAPI+getUserGroups) ⇒ <code>Promise.<Array.<string>></code> | ||
* [.getUserLevel(id)](#SteamAPI+getUserLevel) ⇒ <code>Promise.<number></code> | ||
* [.getUserOwnedGames(id, [includeF2P])](#SteamAPI+getUserOwnedGames) ⇒ <code>Promise.<Array.<Game>></code> | ||
* [.getUserRecentGames(id, [count])](#SteamAPI+getUserRecentGames) ⇒ <code>Promise.<Array.<RecentGame>></code> | ||
* [.getUserServers([hide], [key])](#SteamAPI+getUserServers) ⇒ <code>Promise.<PlayerServers></code> | ||
* [.getUserStats(id, app)](#SteamAPI+getUserStats) ⇒ <code>Promise.<PlayerStats></code> | ||
* [.getUserSummary(id)](#SteamAPI+getUserSummary) ⇒ <code>Promise.<PlayerSummary></code> | ||
@@ -167,3 +166,3 @@ <a name="new_SteamAPI_new"></a> | ||
### steamAPI.getGameDetails(app, [force]) ⇒ <code>Promise.<Object></code> | ||
### steamAPI.getGameDetails(app, [force], [region]) ⇒ <code>Promise.<Object></code> | ||
Get details for app id. | ||
@@ -179,2 +178,3 @@ <warn>Requests for this endpoint are limited to 200 every 5 minutes</warn> | ||
| [force] | <code>boolean</code> | <code>false</code> | Overwrite cache | | ||
| [region] | <code>string</code> | <code>"us"</code> | Store region | | ||
@@ -304,3 +304,3 @@ <a name="SteamAPI+getGameNews"></a> | ||
### steamAPI.getUserOwnedGames(id) ⇒ <code>Promise.<Array.<Game>></code> | ||
### steamAPI.getUserOwnedGames(id, [includeF2P]) ⇒ <code>Promise.<Array.<Game>></code> | ||
Get users owned games. | ||
@@ -311,9 +311,10 @@ | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| id | <code>string</code> | User ID | | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| id | <code>string</code> | | User ID | | ||
| [includeF2P] | <code>boolean</code> | <code>true</code> | Whether to include user's free-to-play games or not | | ||
<a name="SteamAPI+getUserRecentGames"></a> | ||
### steamAPI.getUserRecentGames(id) ⇒ <code>Promise.<Array.<RecentGame>></code> | ||
### steamAPI.getUserRecentGames(id, [count]) ⇒ <code>Promise.<Array.<RecentGame>></code> | ||
Get users recent games. | ||
@@ -327,2 +328,3 @@ | ||
| id | <code>string</code> | User ID | | ||
| [count] | <code>number</code> | Optionally limit the number of games to fetch to some number | | ||
@@ -329,0 +331,0 @@ <a name="SteamAPI+getUserServers"></a> |
@@ -17,4 +17,4 @@ const SteamID = require('steamid'); | ||
const { version, name } = require('../package.json'); | ||
const regions = ['us', 'ca', 'cc', 'es', 'de', 'fr', 'ru', 'nz', 'au', 'uk']; | ||
const reApp = /^\d{1,7}$/; | ||
const reRegion = /^us|es|de|fr|ru|nz|au|uk$/i; | ||
const reID = /^\d{17}$/; | ||
@@ -182,3 +182,3 @@ | ||
if (!reApp.test(app)) return Promise.reject(TypeError('Invalid/no app provided')); | ||
if (!reRegion.test(region)) return Promise.reject(TypeError('Invalid region provided')); | ||
if (!regions.includes(region)) return Promise.reject(TypeError('Invalid region provided')); | ||
@@ -353,9 +353,10 @@ const request = () => this | ||
* @param {string} id User ID | ||
* @param {boolean} [includeF2P=true] Whether to include user's free-to-play games or not | ||
* @returns {Promise<Game[]>} Owned games | ||
*/ | ||
getUserOwnedGames(id) { | ||
getUserOwnedGames(id, includeF2P = true) { | ||
if (!reID.test(id)) return Promise.reject(new TypeError('Invalid/no id provided')); | ||
return this | ||
.get(`/IPlayerService/GetOwnedGames/v1?steamid=${id}&include_appinfo=1`) | ||
.get(`/IPlayerService/GetOwnedGames/v1?steamid=${id}${includeF2P ? '&include_played_free_games=1' : ''}&include_appinfo=1`) | ||
.then(json => json.response.games ? json.response.games.map(game => new Game(game)) : Promise.reject(new Error('No games found'))); | ||
@@ -367,9 +368,10 @@ } | ||
* @param {string} id User ID | ||
* @param {number} [count] Optionally limit the number of games to fetch to some number | ||
* @returns {Promise<RecentGame[]>} Recent games | ||
*/ | ||
getUserRecentGames(id) { | ||
getUserRecentGames(id, count) { | ||
if (!reID.test(id)) return Promise.reject(new TypeError('Invalid/no id provided')); | ||
return this | ||
.get(`/IPlayerService/GetRecentlyPlayedGames/v1?steamid=${id}`) | ||
.get(`/IPlayerService/GetRecentlyPlayedGames/v1?steamid=${id}${count ? `&count=${count}` : ''}`) | ||
.then(json => json.response.total_count ? json.response.games.map(game => new RecentGame(game)) : []); | ||
@@ -376,0 +378,0 @@ } |
@@ -1,37 +0,13 @@ | ||
const { createDeflate, createGunzip } = require('zlib'); | ||
const { parse } = require('url'); | ||
const https = require('https'); | ||
const http = require('http'); | ||
const fetch = require('node-fetch'); | ||
const reg = /<h1>(.*)<\/h1>/; | ||
module.exports = (url, { headers } = {}) => { | ||
const fetch = url.startsWith('https') ? https.get : http.get; | ||
const options = Object.assign( | ||
parse(url), | ||
{ headers: Object.assign({ 'Accept-Encoding': 'gzip, deflate' }, headers) } | ||
); | ||
module.exports = async (url, options) => { | ||
const res = await fetch(url, options); | ||
if (res.status === 400) { | ||
const data = await res.text(); | ||
throw new Error(reg.test(data) ? data.match(reg)[1] : data); | ||
} | ||
if (res.status !== 200) throw new Error(res.statusText); | ||
return new Promise((resolve, reject) => { | ||
fetch(options, res => { | ||
const ce = res.headers['content-encoding']; | ||
let data = ''; | ||
let op = res; | ||
if (ce === 'deflate') res.pipe(op = createDeflate()); | ||
if (ce === 'gzip') res.pipe(op = createGunzip()); | ||
op.on('data', chunk => data += chunk); | ||
op.once('error', reject); | ||
op.once('end', () => { | ||
if (res.statusCode === 400) return reject(new Error(reg.test(data) ? data.match(reg)[1] : data)); | ||
if (res.statusCode !== 200) return reject(new Error(res.statusMessage)); | ||
try { | ||
resolve(JSON.parse(data)); | ||
} catch (_) { | ||
reject(new Error(data)); | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
return res.json(); | ||
}; |
/** | ||
* Yes, I do know what objectify means. | ||
* Convert | ||
@@ -7,6 +6,2 @@ * * [{ name: 'a', value: 'b' }, { name: 'b', value: 'c' }] | ||
* * { a: 'b', b: 'c' } | ||
* & | ||
* * [{ name: 'a', value: 'b', other: 'c' }, { name: 'b', value: 'c', other: 'd' }] | ||
* To | ||
* * { a: { value: 'b', other: 'c' }, b: { value: 'c', other: 'd' } } | ||
* @param {Object[]} arr The array to objectify | ||
@@ -13,0 +8,0 @@ * @param {string} [val=value] The name of the value |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
362
2
37499
2
637
+ Addednode-fetch@^2.6.11
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)