twitch-toolkit
Advanced tools
Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "twitch-toolkit", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A set of tools to integrate with Twitch API, Twitch Chat and Twitch WebHooks.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -41,3 +41,3 @@ # twitch-toolkit | ||
| chatOptions.reconnect | Boolean | A flag to enable the auto-reconnect mode. `Default: false` | | ||
| chatOptions.ignoreSelf | String | A flag to ignore the bots own messages. `Default: false` | | ||
| chatOptions.ignoreSelf | Boolean | A flag to ignore the bots own messages. `Default: false` | | ||
| chatOptions.username | String | The bot's username. | | ||
@@ -44,0 +44,0 @@ | chatOptions.password | String | The bot's OAuth Token. You can get it at http://twitchapps.com/tmi/ | |
@@ -17,3 +17,3 @@ 'use strict'; | ||
TwitchApi.prototype.auth = async function () { | ||
TwitchApi.prototype.auth = async function() { | ||
try { | ||
@@ -27,3 +27,3 @@ var response = await request({ | ||
grant_type: 'client_credentials', | ||
scope: 'user:edit user:read:email', | ||
scope: 'user:edit user:read:email' | ||
}, | ||
@@ -34,3 +34,19 @@ json: true | ||
this.accessToken = response.access_token; | ||
return this.accessToken; | ||
} catch (err) { | ||
throw err; | ||
} | ||
}; | ||
TwitchApi.prototype.authValidateToken = async function(token) { | ||
try { | ||
var response = await request({ | ||
url: 'https://id.twitch.tv/oauth2/validate', | ||
method: 'GET', | ||
headers: { | ||
Authorization: 'OAuth ' + token | ||
} | ||
}); | ||
return response; | ||
} catch (err) { | ||
@@ -44,9 +60,13 @@ throw err; | ||
* This method requires no authentication. | ||
* | ||
* | ||
* @param {object} parameters The parameters to the api call. The parameter object is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-games | ||
* @returns {Promise<Object[]>} The data object in the API response. The response is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-games | ||
*/ | ||
TwitchApi.prototype.getGames = async function (parameters) { | ||
TwitchApi.prototype.getGames = async function(parameters) { | ||
try { | ||
return await performGetRequest(this, 'https://api.twitch.tv/helix/games', parameters); | ||
return await performGetRequest( | ||
this, | ||
'https://api.twitch.tv/helix/games', | ||
parameters | ||
); | ||
} catch (err) { | ||
@@ -60,9 +80,13 @@ throw err; | ||
* This method requires no authentication. | ||
* | ||
* | ||
* @param {object} parameters The parameters to the api call. The parameter object is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-streams | ||
* @returns {Promise<Object[]>} The data object in the API response. The response is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-streams | ||
*/ | ||
TwitchApi.prototype.getStreams = async function (options) { | ||
TwitchApi.prototype.getStreams = async function(options) { | ||
try { | ||
return await performGetRequest(this, 'https://api.twitch.tv/helix/streams', options); | ||
return await performGetRequest( | ||
this, | ||
'https://api.twitch.tv/helix/streams', | ||
options | ||
); | ||
} catch (err) { | ||
@@ -75,9 +99,15 @@ throw err; | ||
* Gets metadata information about active streams playing Overwatch or Hearthstone. Streams are sorted by number of current viewers, in descending order. Across multiple pages of results, there may be duplicate or missing streams, as viewers join and leave streams. | ||
* | ||
* @param {object} parameters The parameters to the api call. The parameter object is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-streams-metadata | ||
* | ||
* @param {string} token The users token. | ||
* @returns {Promise<Object[]>} The data object in the API response. The response is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-streams-metadata | ||
*/ | ||
TwitchApi.prototype.getStreamsMetadata = async function (options) { | ||
TwitchApi.prototype.getStreamsMetadata = async function(token) { | ||
try { | ||
return await performGetRequest(this, 'https://api.twitch.tv/helix/streams/metadata', options); | ||
return await performGetRequest( | ||
this, | ||
'https://api.twitch.tv/helix/streams/metadata', | ||
null, | ||
true, | ||
token | ||
); | ||
} catch (err) { | ||
@@ -90,11 +120,15 @@ throw err; | ||
* Gets information about one or more specified Twitch users. Users are identified by optional user IDs and/or login name. If neither a user ID nor a login name is specified, the user is looked up by Bearer token. | ||
* | ||
* | ||
* @todo add optional scope | ||
* | ||
* | ||
* @param {object} parameters The parameters to the api call. The parameter object is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-users | ||
* @returns {Promise<Object[]>} The data object in the API response. The response is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-users | ||
*/ | ||
TwitchApi.prototype.getUsers = async function (options) { | ||
TwitchApi.prototype.getUsers = async function(options) { | ||
try { | ||
return await performGetRequest(this, 'https://api.twitch.tv/helix/users', options); | ||
return await performGetRequest( | ||
this, | ||
'https://api.twitch.tv/helix/users', | ||
options | ||
); | ||
} catch (err) { | ||
@@ -108,9 +142,13 @@ throw err; | ||
* This method requires no authentication. | ||
* | ||
* | ||
* @param {object} parameters The parameters to the api call. The parameter object is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-users-follows | ||
* @returns {Promise<Object[]>} The data object in the API response. The response is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-users-follows | ||
*/ | ||
TwitchApi.prototype.getUsersFollows = async function (options) { | ||
TwitchApi.prototype.getUsersFollows = async function(options) { | ||
try { | ||
return await performGetRequest(this, 'https://api.twitch.tv/helix/users/follows', options); | ||
return await performGetRequest( | ||
this, | ||
'https://api.twitch.tv/helix/users/follows', | ||
options | ||
); | ||
} catch (err) { | ||
@@ -124,9 +162,13 @@ throw err; | ||
* This method requires no authentication. | ||
* | ||
* | ||
* @param {object} parameters The parameters to the api call. The parameter object is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-videos | ||
* @returns {Promise<Object[]>} The data object in the API response. The response is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-videos | ||
*/ | ||
TwitchApi.prototype.getVideos = async function (options) { | ||
TwitchApi.prototype.getVideos = async function(options) { | ||
try { | ||
return await performGetRequest(this, 'https://api.twitch.tv/helix/videos', options); | ||
return await performGetRequest( | ||
this, | ||
'https://api.twitch.tv/helix/videos', | ||
options | ||
); | ||
} catch (err) { | ||
@@ -140,9 +182,13 @@ throw err; | ||
* This method requires authentication. | ||
* | ||
* | ||
* @param {string} description The description to be added to the channel. | ||
* @returns {Promise<Object[]>} The data object in the API response. The response is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-videos | ||
*/ | ||
TwitchApi.prototype.updateUser = async function (description) { | ||
TwitchApi.prototype.updateUser = async function(description) { | ||
try { | ||
return await performPutRequest(this, 'https://api.twitch.tv/helix/users', { description }); | ||
return await performPutRequest( | ||
this, | ||
'https://api.twitch.tv/helix/users', | ||
{ description } | ||
); | ||
} catch (err) { | ||
@@ -153,10 +199,11 @@ throw err; | ||
/** | ||
* | ||
* | ||
* @param {object} api The API object. | ||
* @param {string} url The request URL. | ||
* @param {object} qs The query string object with the parameters. | ||
* @param {bool} requireAuth Check if the method requires authentication | ||
* @param {string} accessToken Check if a special token should be used | ||
*/ | ||
async function performGetRequest(api, url, qs, requireAuth) { | ||
async function performGetRequest(api, url, qs, requireAuth, accessToken) { | ||
try { | ||
@@ -167,3 +214,3 @@ let headers = { | ||
await validePeformAuth(requireAuth, api, headers); | ||
await validePeformAuth(requireAuth, api, headers, accessToken); | ||
@@ -192,3 +239,3 @@ var response = await request({ | ||
'Client-ID': api.config.client_id, | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}; | ||
@@ -216,3 +263,3 @@ | ||
async function validePeformAuth(requireAuth, api, headers) { | ||
async function validePeformAuth(requireAuth, api, headers, token) { | ||
try { | ||
@@ -223,3 +270,4 @@ if (requireAuth) { | ||
} | ||
headers['Authorization'] = 'Bearer ' + api.accessToken; | ||
let accessToken = token || api.access_token; | ||
headers['Authorization'] = 'Bearer ' + accessToken; | ||
} | ||
@@ -231,2 +279,2 @@ } catch (err) { | ||
module.exports = TwitchApi; | ||
module.exports = TwitchApi; |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances 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
105511
15
2770
2