TwitchTS
Fully typed TwitchAPI wrapper that makes working with TwitchAPI as easy as possible
💻 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:
- 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)
- 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.
- 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
- 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}",
...
})
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}"
await apiClient._tokenHandler.renewAppAccessToken();
await apiClient._tokenHandler.renewUserAccessToken();
await apiClient._tokenHandler.stopAppTokenRefresh();
await apiClient._tokenHandler.stopUserTokenRefresh();
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
LICENSE
Copyright © 2022 François Egner.
This project is GNU General Public License v3.0 licensed.