import { NodeCG } from "nodecg-types/types/server" ; import { Result , emptySuccess , success , ServiceBundle , Logger } from "nodecg-io-core" ; import { ApiClient } from "@twurple/api" ; import { createAuthProvider , getTokenInfo , TwitchServiceConfig } from "nodecg-io-twitch-auth" ; export type TwitchApiServiceClient = ApiClient ; module . exports = ( nodecg ) => { new TwitchService ( nodecg , "twitch-api" , __dirname , "../twitch-api-schema.json" ) . register ( ) ; } ; class TwitchService extends ServiceBundle < TwitchServiceConfig , TwitchApiServiceClient > { async validateConfig ( config ) { await getTokenInfo ( config ) ; return emptySuccess ( ) ; } async createClient ( config , logger ) { const authProvider = await createAuthProvider ( config ) ; const client = new ApiClient ( { authProvider } ) ; logger . info ( "Successfully created twitch-api client." ) ; return success ( client ) ; } stopClient ( _client ) { } }