Skip to content
← Public packages

@kentcdodds/twitch

Monitor Twitch streams, send chat, and update channel settings.

src/types.ts

153 lines · 2.8 KB · TypeScript
export type TwitchUser = {
	id: string
	login: string
	displayName: string
	type?: string
	broadcasterType?: string
	description?: string
	profileImageUrl?: string
	viewCount?: number
	createdAt?: string
	email?: string
}

export type TwitchStream = {
	id: string
	userId: string
	userLogin: string
	userName: string
	gameId?: string
	gameName?: string
	type?: string
	title?: string
	viewerCount?: number
	startedAt?: string
	language?: string
	thumbnailUrl?: string
	isLive: true
}

export type TwitchStreamStatus = TwitchStream | { userLogin: string; isLive: false }

export type TwitchQuery = Record<
	string,
	string | number | boolean | null | undefined | Array<string | number>
>

export type TwitchRequestOptions = {
	path: string
	method?: string
	query?: TwitchQuery
	body?: unknown
	headers?: Record<string, string>
	throwOnError?: boolean
}

export type TwitchResponse<T = unknown> = {
	url: string
	ok: boolean
	status: number
	statusText: string
	data: T
	text: string
}

export type TwitchGetStreamParams = {
	login?: string
	logins?: string[]
}

export type TwitchSendChatMessageParams = {
	broadcasterLogin: string
	message: string
}

export type TwitchListChattersParams = {
	broadcasterLogin?: string
	limit?: number
	after?: string
	cursor?: string
}

export type TwitchUpdateChannelInfoParams = {
	broadcasterLogin?: string
	title?: string
	gameId?: string
	gameName?: string
}

export type TwitchChatter = {
	userId: string
	userLogin: string
	userName: string
}

export type TwitchListChattersResult = {
	broadcasterLogin: string
	total: number
	chatters: TwitchChatter[]
	cursor: string | null
}

export type TwitchSendChatMessageResult = {
	broadcasterLogin: string
	senderLogin: string
	messageId: string | null
	isSent: boolean
	dropReason: string | null
}

export type TwitchUpdateChannelInfoResult = {
	broadcasterLogin: string
	updated: Record<string, unknown>
	status: number
}

export type TwitchSmokeTestResult = {
	ok: true
	login: string
	displayName: string
	broadcasterType?: string
	stream: TwitchStreamStatus
}

export type TwitchGuideResult = {
	integration: string
	redirectUri: string
	connectUrl: string
	scopes: string[]
	minimalStreamScopes: string[]
	scopeCount: number
	scopeNotes: string[]
	setup: string[]
	commonTasks: Record<string, string>
	openapi: {
		specUrl: string
		slugs: string[]
		auth: string
	}
}

export type TwitchPackageOverview = {
	kodyId: string
	integration: string
	connectUrl: string
	exports: string[]
	openapiSlugs: string[]
}

/**
 * Return exported Twitch TypeScript type names for agent discovery.
 */
export default function describeTwitchTypes(): string[] {
	return [
		'TwitchChatter',
		'TwitchOfflineChannel',
		'TwitchQuery',
		'TwitchRequestOptions',
		'TwitchResponse',
		'TwitchStream',
		'TwitchStreamStatus',
		'TwitchUser',
	]
}