Socket
Socket
Sign inDemoInstall

@nestjs-twurple/api

Package Overview
Dependencies
223
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @nestjs-twurple/api

A NestJS wrapper for @twurple/api package


Version published
Weekly downloads
16
decreased by-58.97%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

NestJS Twurple API

A NestJS wrapper for @twurple/api package.

This module can be used alone or in combination with other @nestjs-twurple modules.

[!IMPORTANT] These packages require twurple version 7.0 or higher.

Table of Contents

Installation

This module can be used in combination with @nestjs-twurple/auth module. Install it if necessary.

yarn:

yarn add @nestjs-twurple/api @twurple/auth @twurple/api

npm:

npm i @nestjs-twurple/api @twurple/auth @twurple/api

Usage

For basic information, check out the general documentation at the root of the repository @nestjs-twurple.

Also take a look at the official @twurple/api reference and guides: Calling the Twitch API.

Import and Registration

The module must be register either with register or registerAsync static methods.

To create an API client, you must provide TwurpleApiOptions. The options below extended from the ApiConfig interface provided by @twurple/api package, so the example below may become outdated at some point.

interface TwurpleApiIptions {
	authProvider: AuthProvider;
	fetchOptions?: TwitchApiCallFetchOptions;
	logger?: Partial<LoggerOptions>;
}

Example of using register method:

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { RefreshingAuthProvider } from '@twurple/auth';
import { TwurpleApiModule } from '@nestjs-twurple/api';

@Module({
	imports: [
		ConfigModule.forRoot({ isGlobal: true }),
		TwurpleApiModule.register({
			isGlobal: true,
			authProvider: new RefreshingAuthProvider({
				// ...
			})
		})
	]
})
export class AppModule {}

You can also use TwurpleAuthModule from @nestjs-twurple/auth package to inject the auth provider:

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TWURPLE_AUTH_PROVIDER, TwurpleAuthModule } from '@nestjs-twurple/auth';
import { TwurpleApiModule } from '@nestjs-twurple/api';
import { AuthProvider } from '@twurple/auth';

@Module({
	imports: [
		ConfigModule.forRoot({ isGlobal: true }),
		TwurpleAuthModule.registerAsync({
			isGlobal: true,
			inject: [ConfigService],
			useFactory: (configService: ConfigService) => {
				return {
					type: 'refreshing',
					clientId: configService.get('TWITCH_CLIENT_ID'),
					clientSecret: configService.get('TWITCH_CLIENT_SECRET')
				};
			}
		}),
		TwurpleApiModule.registerAsync({
			isGlobal: true,
			inject: [TWURPLE_AUTH_PROVIDER],
			useFactory: (authProvider: AuthProvider) => {
				// Here we are able to access the auth provider instance
				// provided by TwurpleAuthModule
				return { authProvider };
			}
		})
	]
})
export class AppModule {}

Using the ApiClient

The module internally creates an ApiClient instance. You can inject it anywhere you need it using @InjectApiClient() decorator:

import { Injectable } from '@nestjs/common';
import { InjectApiClient } from '@nestjs-twurple/api';
import { ApiClient } from '@twurple/api';

@Injectable()
export class CustomProvider {
	constructor(@InjectApiClient() private readonly _apiClient: ApiClient) {}
}

Alternatively, you can use TWURPLE_API_CLIENT token to inject the ApiClient instance:

import { Inject, Injectable } from '@nestjs/common';
import { TWURPLE_API_CLIENT } from '@nestjs-twurple/api';
import { ApiClient } from '@twurple/api';

@Injectable()
export class CustomProvider {
	constructor(@Inject(TWURPLE_API_CLIENT) private readonly _apiClient: ApiClient) {}
}

Keywords

FAQs

Last updated on 05 Oct 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc