26 lines
882 B
TypeScript
26 lines
882 B
TypeScript
|
import * as config from "./config";
|
||
|
import fetch, { Response as FetchResponse } from "node-fetch";
|
||
|
|
||
|
export interface TokenResponse {
|
||
|
access_token: string;
|
||
|
refresh_token: string;
|
||
|
token_type: string;
|
||
|
expires_in: number;
|
||
|
}
|
||
|
|
||
|
export interface TokenPair {
|
||
|
access_token: string;
|
||
|
refresh_token: string;
|
||
|
}
|
||
|
|
||
|
export async function apiRequest(tokens: TokenPair, method: string, endpoint: string): Promise<any>;
|
||
|
export async function apiRequest(tokens: TokenPair, method: string, endpoint: string, query: string): Promise<any>;
|
||
|
export async function apiRequest(tokens: TokenPair, method: string, endpoint: string, query?: string,) {
|
||
|
var headers = {
|
||
|
"Authorization": "Bearer " + tokens.access_token,
|
||
|
"Client-ID": config.twitchClientId
|
||
|
};
|
||
|
return fetch("https://api.twitch.tv/helix" + endpoint, { method: method, headers: headers})
|
||
|
.then(async (res: FetchResponse) => res.json());
|
||
|
}
|