Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

steamapi

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

steamapi - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

120

app.js

@@ -1,2 +0,2 @@

const fetch = require('node-fetch');
const fetch = require('snekfetch').get;
const { version } = require('./package.json');

@@ -6,7 +6,11 @@ const appReg = /^\d+$/;

class API {
constructor(data) {
if (!data) console.log('no key provided | some methods may not work | go get one > https://goo.gl/DfNy5s');
class SteamAPI {
/**
* Sets Steam key for future use
* @param {string} key Steam key
*/
constructor(key) {
if (!key) console.log('no key provided | some methods may not work | go get one > https://goo.gl/DfNy5s');
this.baseURL = 'https://api.steampowered.com';
this.key = data;
this.key = key;
this.headers = {

@@ -16,13 +20,22 @@ 'User-Agent': `SteamAPI/${version} https://github.com/lloti/steampowered-api`

}
/**
* Get custom path that isn't in SteamAPI
* @param {string} path Path to request e.g '/IPlayerService/GetOwnedGames/v1?steamid=76561198378422474'
* @returns {Promise<object>} JSON Response
*/
get(path) {
return new Promise((resolve, reject) => {
fetch(`${this.baseURL}${path}${path.includes('?') ? '&' : '?'}key=${this.key}`, this.headers)
.then(res => res.json())
.then(resolve)
.then(res => resolve(res.body))
.catch(reject);
});
}
/**
* Resolve info based on id|profile|url
* @param {string} info Something to resolve e.g 'https://steamcommunity.com/id/xDim'
* @returns {Promise<string>} Profile ID
*/
resolve(info) {
if (!info) throw new Error('no info provided');
return new Promise(async(resolve, reject) => {
return new Promise(async (resolve, reject) => {
let steamID, steamURL;

@@ -47,4 +60,3 @@ if (/^(?:\/?profiles\/)?\d{17}$/.test(info)) {

steamID = await fetch(`${this.baseURL}/ISteamUser/ResolveVanityURL/v1?key=${this.key}&vanityurl=${steamURL}`, this.headers)
.then(res => res.json())
.then(json => json.response.success === 1 ? json.response.steamid : reject('Invalid profile link/id'))
.then(res => res.body.response.success === 1 ? res.body.response.steamid : reject('Invalid profile link/id'))
.catch(reject);

@@ -55,2 +67,7 @@ }

}
/**
* Get achievements for app id
* @param {string} app App ID
* @returns {Promise<Array<string>>} App achievements for ID
*/
getGameAchievements(app) {

@@ -60,3 +77,3 @@ if (!appReg.test(app)) throw new Error('no appid provided');

const json = await fetch(`${this.baseURL}/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v2?gameid=${app}`, this.headers)
.then(res => res.json())
.then(res => res.body)
.catch(reject);

@@ -66,2 +83,7 @@ resolve(json.achievementpercentages.achievements);

}
/**
* Get news for app id
* @param {string} app App ID
* @returns {Promise<Array<Object>} App news for ID
*/
getGameNews(app) {

@@ -71,3 +93,3 @@ if (!appReg.test(app)) throw new Error('no appid provided');

const json = await fetch(`${this.baseURL}/ISteamNews/GetNewsForApp/v2?appid=${app}`, this.headers)
.then(res => res.json())
.then(res => res.body)
.catch(reject);

@@ -78,7 +100,12 @@ if (json.appnews.count === 0) return reject('no news found');

}
/**
* Get number of current players for app id
* @param {string} app App ID
* @returns {Promise<number>} Number of players
*/
getGamePlayers(app) {
if (!appReg.test(app)) throw new Error('no appid provided');
return new Promise(async (resolve, reject) => {
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetNumberOfCurrentPlayers/v1?appid=${app}&count=1&name[0]`, this.headers)
.then(res => res.json())
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetNumberOfCurrentPlayers/v1?appid=${app}`, this.headers)
.then(res => res.body)
.catch(reject);

@@ -89,2 +116,7 @@ if (json.response.result !== 1) return reject('invalid app id');

}
/**
* Get schema for app id
* @param {string} app App ID
* @returns {Promise<number>} Schema
*/
getGameSchema(app) {

@@ -94,3 +126,3 @@ if (!appReg.test(app)) throw new Error('no appid provided');

const json = await fetch(`${this.baseURL}/ISteamUserStats/GetSchemaForGame/v2?key=${this.key}&appid=${app}`, this.headers)
.then(res => res.json())
.then(res => res.body)
.catch(reject);

@@ -101,8 +133,14 @@ if (!json.game) return reject('game not found');

}
getUserAchievements(player, app) {
if (!idReg.test(player)) throw new Error('no player id provided');
/**
* Get users achievements for app id
* @param {string} id User ID
* @param {string} app App ID
* @returns {Promise<Object>} Achievements
*/
getUserAchievements(id, app) {
if (!idReg.test(id)) throw new Error('no user id provided');
if (!/^\d+$/.test(app)) throw new Error('no appid provided');
return new Promise(async (resolve, reject) => {
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetPlayerAchievements/v1?key=${this.key}&steamid=${player}&appid=${app}`, this.headers)
.then(res => res.json())
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetPlayerAchievements/v1?key=${this.key}&steamid=${id}&appid=${app}`, this.headers)
.then(res => res.body)
.catch(reject);

@@ -113,2 +151,7 @@ if (!json.playerstats.success) return reject('error getting achievements');

}
/**
* Get users bans
* @param {string} id User ID
* @returns {Promise<Object>} Ban info
*/
getUserBans(id) {

@@ -118,3 +161,3 @@ if (!idReg.test(id)) throw new Error('no id provided');

const json = await fetch(`${this.baseURL}/ISteamUser/GetPlayerBans/v1?key=${this.key}&steamids=${id}`, this.headers)
.then(res => res.json())
.then(res => res.body)
.catch(reject);

@@ -133,2 +176,7 @@ const ban = json.players[0];

}
/**
* Get users friends
* @param {string} id User ID
* @returns {Promise<Array<Object>>} Friends
*/
getUserFriends(id) {

@@ -138,3 +186,3 @@ if (!idReg.test(id)) throw new Error('no id provided');

const json = await fetch(`${this.baseURL}/ISteamUser/GetFriendList/v1?key=${this.key}&steamid=${id}`, this.headers)
.then(res => res.json())
.then(res => res.body)
.catch(reject);

@@ -153,2 +201,7 @@ const friends = json.friendslist.friends;

}
/**
* Get users groups
* @param {string} id User ID
* @returns {Promise<Array<string>>} Groups
*/
getUserGroups(id) {

@@ -158,3 +211,3 @@ if (!idReg.test(id)) throw new Error('no id provided');

const json = await fetch(`${this.baseURL}/ISteamUser/GetUserGroupList/v1?key=${this.key}&steamid=${id}`, this.headers)
.then(res => res.json())
.then(res => res.body)
.catch(reject);

@@ -165,8 +218,14 @@ if (!json.response.success) return reject('failed');

}
getUserStats(player, app) {
if (!idReg.test(player)) throw new Error('no player id provided');
/**
* Get users stats for app id
* @param {string} id User ID
* @param {string} app App ID
* @returns {Promise<Object>} Stats for app id
*/
getUserStats(id, app) {
if (!idReg.test(id)) throw new Error('no user id provided');
if (!/^\d+$/.test(app)) throw new Error('no appid provided');
return new Promise(async (resolve, reject) => {
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetUserStatsForGame/v2?key=${this.key}&steamid=${player}&appid=${app}`, this.headers)
.then(res => res.json())
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetUserStatsForGame/v2?key=${this.key}&steamid=${id}&appid=${app}`, this.headers)
.then(res => res.body)
.catch(reject);

@@ -177,2 +236,7 @@ if (!json.playerstats) return reject('game not found for user');

}
/**
* Get users summary
* @param {string} id User ID
* @returns {Promise<Object>} Summary
*/
getUserSummary(id) {

@@ -182,3 +246,3 @@ if (!idReg.test(id)) throw new Error('no id provided');

const json = await fetch(`${this.baseURL}/ISteamUser/GetPlayerSummaries/v2?key=${this.key}&steamids=${id}`, this.headers)
.then(res => res.json())
.then(res => res.body)
.catch(reject);

@@ -209,2 +273,2 @@ const player = json.response.players[0];

module.exports = API;
module.exports = SteamAPI;

@@ -5,3 +5,3 @@ {

"main": "app.js",
"version": "1.1.0",
"version": "1.2.0",
"keywords": [

@@ -22,3 +22,4 @@ "steam",

"dependencies": {
"node-fetch": "*"
"node-fetch": "*",
"snekfetch": "^3.3.0"
},

@@ -35,2 +36,2 @@ "bugs": {

"homepage": "https://github.com/lloti/node-steamapi#readme"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc