@twurple/api-call
Advanced tools
Comparing version 5.0.0-pre.12 to 5.0.0-pre.13
@@ -6,6 +6,8 @@ /// <reference lib="dom" /> | ||
* | ||
* @param options | ||
* @param clientId | ||
* @param accessToken | ||
* @param fetchOptions | ||
* @param options The configuration of the call. | ||
* @param clientId The client ID of your application. | ||
* @param accessToken The access token to call the API with. | ||
* | ||
* You need to obtain one using one of the [Twitch OAuth flows](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/). | ||
* @param fetchOptions Additional options to be passed to the `fetch` function. | ||
*/ | ||
@@ -12,0 +14,0 @@ export declare function callTwitchApiRaw(options: TwitchApiCallOptions, clientId?: string, accessToken?: string, fetchOptions?: TwitchApiCallFetchOptions): Promise<Response>; |
@@ -12,15 +12,15 @@ "use strict"; | ||
* | ||
* @param options | ||
* @param clientId | ||
* @param accessToken | ||
* @param fetchOptions | ||
* @param options The configuration of the call. | ||
* @param clientId The client ID of your application. | ||
* @param accessToken The access token to call the API with. | ||
* | ||
* You need to obtain one using one of the [Twitch OAuth flows](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/). | ||
* @param fetchOptions Additional options to be passed to the `fetch` function. | ||
*/ | ||
async function callTwitchApiRaw(options, clientId, accessToken, fetchOptions = {}) { | ||
var _a, _b; | ||
const type = (_a = options.type) !== null && _a !== void 0 ? _a : 'kraken'; | ||
const type = (_a = options.type) !== null && _a !== void 0 ? _a : 'helix'; | ||
const url = url_1.getTwitchApiUrl(options.url, type); | ||
const params = qs_1.stringify(options.query, { arrayFormat: 'repeat' }); | ||
const headers = new cross_fetch_1.Headers({ | ||
Accept: type === 'kraken' ? 'application/vnd.twitchtv.v5+json' : 'application/json' | ||
}); | ||
const headers = new cross_fetch_1.Headers({ Accept: 'application/json' }); | ||
let body = undefined; | ||
@@ -27,0 +27,0 @@ if (options.jsonBody) { |
@@ -9,6 +9,6 @@ import { CustomError } from '@twurple/common'; | ||
/** @private */ | ||
constructor(statusCode: number, statusText: string, body: Record<string, unknown>); | ||
constructor(_statusCode: number, statusText: string, _body: string, isJson: boolean); | ||
get statusCode(): number; | ||
get body(): Record<string, unknown>; | ||
get body(): string; | ||
} | ||
//# sourceMappingURL=HttpStatusCodeError.d.ts.map |
@@ -10,6 +10,6 @@ "use strict"; | ||
/** @private */ | ||
constructor(statusCode, statusText, body) { | ||
super(`Encountered HTTP status code ${statusCode}: ${statusText}\n\nBody:\n${JSON.stringify(body, null, 2)}`); | ||
this._statusCode = statusCode; | ||
this._body = body; | ||
constructor(_statusCode, statusText, _body, isJson) { | ||
super(`Encountered HTTP status code ${_statusCode}: ${statusText}\n\nBody:\n${!isJson && _body.length > 150 ? `${_body.substr(0, 147)}...` : _body}`); | ||
this._statusCode = _statusCode; | ||
this._body = _body; | ||
} | ||
@@ -16,0 +16,0 @@ get statusCode() { |
@@ -8,3 +8,5 @@ "use strict"; | ||
if (!response.ok) { | ||
throw new HttpStatusCodeError_1.HttpStatusCodeError(response.status, response.statusText, await response.json()); | ||
const isJson = response.headers.get('Content-Type') === 'application/json'; | ||
const text = isJson ? JSON.stringify(await response.json(), null, 2) : await response.text(); | ||
throw new HttpStatusCodeError_1.HttpStatusCodeError(response.status, response.statusText, text, isJson); | ||
} | ||
@@ -11,0 +13,0 @@ if (response.status === 204) { |
@@ -7,6 +7,4 @@ "use strict"; | ||
switch (type) { | ||
case 'kraken': | ||
case 'helix': | ||
const typeName = type === 'kraken' ? 'kraken' : 'helix'; | ||
return `https://api.twitch.tv/${typeName}/${url.replace(/^\//, '')}`; | ||
return `https://api.twitch.tv/helix/${url.replace(/^\//, '')}`; | ||
case 'auth': | ||
@@ -13,0 +11,0 @@ return `https://id.twitch.tv/oauth2/${url.replace(/^\//, '')}`; |
/// <reference lib="dom" /> | ||
import type { RequestInit as NodeRequestInit } from 'node-fetch'; | ||
/** | ||
* The endpoint to call, i.e. /kraken, /helix or a custom (potentially unsupported) endpoint. | ||
* The endpoint to call, i.e. /helix or a custom (potentially unsupported) endpoint. | ||
*/ | ||
export declare type TwitchApiCallType = 'kraken' | 'helix' | 'auth' | 'custom'; | ||
export declare type TwitchApiCallType = 'helix' | 'auth' | 'custom'; | ||
/** | ||
@@ -18,3 +18,3 @@ * Configuration for a single API call. | ||
/** | ||
* The endpoint to call, i.e. /kraken, /helix or a custom (potentially unsupported) endpoint. | ||
* The endpoint to call, i.e. /helix or a custom (potentially unsupported) endpoint. | ||
*/ | ||
@@ -21,0 +21,0 @@ type?: TwitchApiCallType; |
{ | ||
"name": "@twurple/api-call", | ||
"version": "5.0.0-pre.12", | ||
"version": "5.0.0-pre.13", | ||
"publishConfig": { | ||
@@ -35,3 +35,3 @@ "access": "public" | ||
"@d-fischer/qs": "^7.0.2", | ||
"@twurple/common": "^5.0.0-pre.12", | ||
"@twurple/common": "^5.0.0-pre.13", | ||
"@types/node-fetch": "^2.5.7", | ||
@@ -52,3 +52,3 @@ "node-fetch": "^2.6.1", | ||
}, | ||
"gitHead": "d11ad975261eed9e7ac72de5d1ec471c1d575a4c" | ||
"gitHead": "f305beefb6f619faed0776ab62eff51db5d8530d" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17232
330