npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

twitch-api-typescript

v0.5.5

Published

Fully typed TwitchAPI wrapper that makes working with TwitchAPI as easy as possible

Downloads

8

Readme

TwitchTS

Fully typed TwitchAPI wrapper that makes working with TwitchAPI as easy as possible NPM

💻 Installation

# With npm:
npm install twitch-api-typescript

#With yarn:
#Not added yet

⚙️ Usage

Tokenmanagement

TwitchTS always tries to use the user access token first for API calls that can be called using the app access token or user access token. So if you know that you only make calls where the app access token is enough, then it is enough to just specify that.

During initialization, several pieces of optional information can be specified for token management:

  1. user access token
    • If this token was specified at initialization, it will be used for all API calls where a user token is required (or for those where a simple app access token is required)
  2. app access token
    • If this token was specified at initialization, it will be used for all API calls where an app access token is required.
  3. application secret
    • If the client secret is specified during initialization, then TwitchTS will automatically renew the app access token. It is necessary to specify an app access token if a client secret is specified
  4. refresh token
    • If the refresh token is specified during initialization, then TwitchTS will automatically renew the user access token (about 1 hour before expiration). It is necessary to specify a user access token when a refresh token is specified

The following are a few examples of how the individual tokens/secret can be specified

User access token & app access token:
const apiClient = new TwitchAPI({
    clientId: "{YOUR-CLIENT-ID}",
    tokens:{
        userToken: "{YOUR-USER-ACCESS-TOKEN}",
        appToken: "{YOUR-APP-ACCESS-TOKEN}"
    }
})
await apiClient.init();
Refresh token only:
const apiClient = new TwitchAPI({
    clientId: "{YOUR-CLIENT-ID}",
    tokens:{
        refreshToken: "{YOUR-REFRESH-TOKEN}"
    }
})
await apiClient.init();
Client secret only:
const apiClient = new TwitchAPI({
    clientId: "{YOUR-CLIENT-ID}",
    clientSecret: "{YOUR-CLIENT-SECRET}"
})
await apiClient.init();

At runtime, all settings related to tokens can be changed. TwitchTS offers a public interface for this purpose:

const apiClient = new TwitchAPI({
   clientId: "{YOUR-CLIENT-ID}",
   ...
})

//Setting tokens/secret to a new value directly. 
apiClient._tokenHandler.userAccessToken = "{NEW-USER-ACCESS-TOKEN}"
apiClient._tokenHandler.appAccessToken = "{NEW-APP-ACCESS-TOKEN}"
apiClient._tokenHandler.refreshToken = "{NEW-REFRESH-TOKEN}"
apiClient._tokenHandler.clientSecret = "{NEW-CLIENT-SECRET}"

//Manually trigger a refresh of the respective token
await apiClient._tokenHandler.renewAppAccessToken();
await apiClient._tokenHandler.renewUserAccessToken();

//Stop the refresh interval of the respective token refresh routine
await apiClient._tokenHandler.stopAppTokenRefresh();
await apiClient._tokenHandler.stopUserTokenRefresh();

//Start/Restart the refresh interval of the respective token refresh routine
await apiClient._tokenHandler.startAppTokenRefresh();
await apiClient._tokenHandler.stopUserTokenRefresh();

📝 NOT IMPLEMENTED YET

  • Update Drops Entitlements
  • Get Extension Configuration Segment
  • Set Extension Configuration Segment
  • Set Extension Required Configuration
  • Update Extension Bits Product
  • Get Channel Stream Schedule
  • Update Channel Stream Schedule
  • Create Channel Stream Schedule Segment
  • Update Channel Stream Schedule Segment
  • Delete Channel Stream Schedule Segment
  • Update User Extensions

📝 TODO

  • [ ] Implement remaining API calls
  • [ ] Finish code documentation
  • [x] Make refresh token & user secret optional at initialization
  • [x] Custom exceptions
  • [ ] User input validation with ZOD
  • [ ] Proper tests
  • [ ] Refactoring for a better UX and code readings

LICENSE

Copyright © 2022 François Egner.
This project is GNU General Public License v3.0 licensed.