riotapi-fetch-typed 1.0.0-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +106 -0
- package/dist/index.cjs +97 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +13426 -0
- package/dist/index.d.ts +13426 -0
- package/dist/index.js +71 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 TournamentStats
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# riotapi-fetch-typed
|
|
2
|
+
|
|
3
|
+
Fetch the Riot Games API with type safety, thanks to the OpenAPI specification.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Just a thin wrapper around fetch
|
|
8
|
+
- (Almost) Fully Type-safe
|
|
9
|
+
- Regions (based on API Route)
|
|
10
|
+
- API Routes
|
|
11
|
+
- HTTP Methods
|
|
12
|
+
- Request Body
|
|
13
|
+
- Response Body
|
|
14
|
+
- Errors
|
|
15
|
+
- Almost instant updates with zero maintenance, Updates on the API just need a regeneration of the src/types/openapi.d.ts file using `openapi-typescript`
|
|
16
|
+
- supports all endpoints that are in the [OpenAPI specification](https://github.com/MingweiSamuel/riotapi-schema)
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Without Error throwing
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { createRiotFetch } from "riotapi-fetch-typed";
|
|
24
|
+
|
|
25
|
+
const riotFetch = createRiotFetch({ apiKey: process.env.RIOT_API_KEY! });
|
|
26
|
+
|
|
27
|
+
const puuid =
|
|
28
|
+
"Zz2sEt4n_mfS37AyXSqXnNw4eXDHHRfsYXD2FQb7jOLIrttOjtIe88cu_fKqwkPVgCSc_4slSNSrbg";
|
|
29
|
+
// theoretically the route could support autofill, but current vscode typescript language doesn't support it, sadge. See below for issues
|
|
30
|
+
const { response, data, error } = await riotFetch(
|
|
31
|
+
`/riot/account/v1/accounts/by-puuid/${puuid}`,
|
|
32
|
+
{
|
|
33
|
+
region: "europe", // type-safe
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if (!error) {
|
|
38
|
+
const { gameName, tagLine } = data;
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### With Error throwing
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
const riotFetch = createRiotFetch({
|
|
46
|
+
apiKey: process.env.RIOT_API_KEY!,
|
|
47
|
+
throwOnResponseError: true,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const { response, data } = await riotFetch("/lol/tournament/v5/codes", {
|
|
52
|
+
region: "europe",
|
|
53
|
+
method: "post", // also type-safe
|
|
54
|
+
body: {
|
|
55
|
+
enoughPlayers: false,
|
|
56
|
+
mapType: "SUMMONERS_RIFT",
|
|
57
|
+
pickType: "TOURNAMENT_DRAFT",
|
|
58
|
+
spectatorType: "ALL",
|
|
59
|
+
teamSize: 5,
|
|
60
|
+
}, // body is also fully typed and annotated (if exists)
|
|
61
|
+
});
|
|
62
|
+
const tournamentCodes = data;
|
|
63
|
+
} catch (e: unknown) {
|
|
64
|
+
if (e instanceof RiotError) {
|
|
65
|
+
console.error(e.statusCode, e.data);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Installation
|
|
71
|
+
|
|
72
|
+
Install it using your package manager:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
$ npm install riot-games-fetch-typed
|
|
76
|
+
# or
|
|
77
|
+
$ pnpm install riot-games-fetch-typed
|
|
78
|
+
# or
|
|
79
|
+
$ yarn install riot-games-fetch-typed
|
|
80
|
+
# or
|
|
81
|
+
$ bun install riot-games-fetch-typed
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Autocomplete related issues
|
|
85
|
+
|
|
86
|
+
This library would be much more DX-friendly if typescript could autocomplete / give suggestions for template literal types. I think in theory
|
|
87
|
+
this could be possible, but in reality I have no clue if the typescript eco-system would allow something like that.
|
|
88
|
+
|
|
89
|
+
Issues/PRs i found that maybe relates to the autocompletion of template literals.
|
|
90
|
+
|
|
91
|
+
- https://github.com/microsoft/TypeScript/issues/57902
|
|
92
|
+
- https://github.com/microsoft/TypeScript/pull/59794
|
|
93
|
+
- https://github.com/microsoft/TypeScript/issues/61217
|
|
94
|
+
|
|
95
|
+
## How it works
|
|
96
|
+
|
|
97
|
+
This module uses the `openapi-typescript` module to generate typescript data from the Riot API OpenAPI Specification, that itself is generated from the officially documentation. Huge thanks to [Mingwei Samuel](https://github.com/MingweiSamuel) who provides them at https://github.com/MingweiSamuel/riotapi-schema. With these type information, typescript's flexible typing system including template literals and type infering, we can infer the type of response and method and applicable regions from the fetch parameters.
|
|
98
|
+
|
|
99
|
+
## Contributing
|
|
100
|
+
|
|
101
|
+
Feel free to contribute.
|
|
102
|
+
|
|
103
|
+
## This also exist
|
|
104
|
+
|
|
105
|
+
- https://openapi-ts.dev/openapi-fetch/
|
|
106
|
+
- Much more feature complete, riotapi-fetch-typed is tailored for the Riot API and would require much more work to be as general as openapi-fetch
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
RiotError: () => RiotError,
|
|
24
|
+
createRiotFetch: () => createRiotFetch
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var RiotError = class extends Error {
|
|
28
|
+
constructor(message, statusCode, data) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.statusCode = statusCode;
|
|
31
|
+
this.data = data;
|
|
32
|
+
}
|
|
33
|
+
statusCode;
|
|
34
|
+
data;
|
|
35
|
+
};
|
|
36
|
+
function isRiotErrorData(obj) {
|
|
37
|
+
if (typeof obj !== "object" || obj === null) return false;
|
|
38
|
+
const data = obj;
|
|
39
|
+
if (data.status !== void 0) {
|
|
40
|
+
if (typeof data.status !== "object") {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if ("status_code" in data.status && typeof data.status.status_code !== "number") {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if ("message" in data.status && typeof data.status.message !== "string") {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
function createRiotFetch({
|
|
53
|
+
apiKey,
|
|
54
|
+
fetchFn = fetch,
|
|
55
|
+
baseUrl = (region) => `https://${region}.api.riotgames.com/`,
|
|
56
|
+
throwOnResponseError = false
|
|
57
|
+
}, defaultOptions = {}) {
|
|
58
|
+
const headers = new Headers(defaultOptions.headers);
|
|
59
|
+
headers.append("X-Riot-Token", apiKey);
|
|
60
|
+
headers.append("Content-Type", "application/json");
|
|
61
|
+
defaultOptions.headers = headers;
|
|
62
|
+
return async (request, options) => {
|
|
63
|
+
const baseURL = baseUrl(options.region);
|
|
64
|
+
const req = new URL(request, baseURL);
|
|
65
|
+
const response = await fetchFn(req.toString(), {
|
|
66
|
+
...defaultOptions,
|
|
67
|
+
...options,
|
|
68
|
+
body: JSON.stringify(options.body)
|
|
69
|
+
});
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
const riotErrorData = await response.json().then((obj) => isRiotErrorData(obj) ? obj : void 0).catch(() => void 0);
|
|
72
|
+
if (throwOnResponseError) {
|
|
73
|
+
throw new RiotError(
|
|
74
|
+
"Riot Games Fetch Error",
|
|
75
|
+
response.status,
|
|
76
|
+
riotErrorData
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
response,
|
|
81
|
+
data: riotErrorData,
|
|
82
|
+
error: true
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
response,
|
|
87
|
+
data: await response.json(),
|
|
88
|
+
error: false
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
93
|
+
0 && (module.exports = {
|
|
94
|
+
RiotError,
|
|
95
|
+
createRiotFetch
|
|
96
|
+
});
|
|
97
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { paths, components } from './types/openapi.d.js';\n\nexport * from './types/openapi.d.js';\n\n\n/** Every possible API path, based on the OpenAPI document */\ntype Paths = keyof paths;\n\n/**\n * Type util that replaces all occurences of curly brackets pairs in a string literal type to string placeholders,\n * resulting in a template literal type. For that it recursively tests the string for curly bracket pairs.\n *\n * @example TemplatifyPath<'summoner/{summonerName}/ranked'> -> `summoner/${string}/ranked`\n */\ntype TemplatifyPath<Path extends string> =\n\tPath extends `${infer Start}/{${string}}${infer End}`\n\t\t? `${Start}/${string}${TemplatifyPath<End>}`\n\t\t: Path;\n\n\n/** Every possible API path, but templatified */\ntype TemplatePaths = TemplatifyPath<Paths>;\n\n/**\n * Gives all API Paths that matches the templatified path. Basically the reverse operation of TemplatifyPath\n *\n * @example ResolveTemplatePath<`/riot/account/v1/accounts/by-puuid/${string}`>\n * -> \"/riot/account/v1/accounts/by-puuid/{puuid}\"\n */\ntype ResolveTemplatePath<TemplatePath extends TemplatePaths> = {\n\t[P in Paths]: TemplatePath extends TemplatifyPath<P> ? P : never;\n}[Paths];\n\n\nexport type HTTPMethods = 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace';\n\n/**\n * Get all available methods for a specific API path\n */\ntype Methods<Path extends Paths> = Exclude<keyof {\n\t[K in keyof paths[Path] as paths[Path][K] extends undefined ? never : K]: paths[Path][K]\n}, 'parameters'>;\n\n/** Get all possible responses for a specific API path and method */\ntype GetResponses<Path extends Paths, Method extends Methods<Path>> =\n\tpaths[Path][Method] extends { responses: infer Responses }\n\t\t? Responses\n\t\t: never;\n\n\n/** Get the response body for a specific API path, method and status code */\ntype GetResponseBody<Path extends Paths, Method extends Methods<Path>, StatusCode extends number> =\n\tGetResponses<Path, Method> extends Record<StatusCode, { content: { 'application/json': infer Body } }>\n\t\t? Body\n\t\t: never;\n\n/** Get the request body for a specific API path and method */\ntype GetRequestBody<Path extends Paths, Method extends Methods<Path>> =\n\tpaths[Path][Method] extends { requestBody: { content: { 'application/json': infer Body } } }\n\t\t? Body\n\t\t: never;\n\n/** Regions for /riot/account/ endpoints */\nexport type AccountRegion = 'americas' | 'asia' | 'europe';\n/** Regions for some lol and tft endpoints */\nexport type LolRegion = 'br1' | 'eun1' | 'euw1' | 'jp1' | 'kr' | 'la1' | 'la2' | 'me1' | 'na1' | 'oc1' | 'ph2' | 'ru' | 'sg2' | 'th2' | 'tr1' | 'tw2' | 'vn2';\n/** Regions for lol and tft matches endpoints */\nexport type MatchRegion = 'americas' | 'asia' | 'europe' | 'sea';\n/** Regions for /lor/ endpoints */\nexport type LorRegion = 'americas' | 'europe' | 'sea';\n/** Regions for /val/ endpoints */\nexport type ValorantRegion = 'ap' | 'br' | 'eu' | 'latam' | 'na' | 'esports' | 'kr';\n\n\n/** Get the relevant subdomains, depending on the endpoint */\n// i dont like eslint indenting here\n/* eslint-disable @stylistic/indent */\ntype GetSubdomain<Path extends TemplatePaths> =\n\tPath extends `/riot/account/${string}` ? AccountRegion :\n\tPath extends `/lol/champion-mastery/${string}` ? LolRegion :\n\tPath extends `/lol/platform/${string}` ? LolRegion :\n\tPath extends `/lol/clash/${string}` ? LolRegion :\n\tPath extends `/lol/league-exp/${string}` ? LolRegion :\n\tPath extends `/lol/league/${string}` ? LolRegion :\n\tPath extends `/lol/challenges/${string}` ? LolRegion :\n\tPath extends `/lol/rso-match/${string}` ? MatchRegion :\n\tPath extends `/lol/status/${string}` ? LolRegion :\n\tPath extends `/lor/deck/${string}` ? LorRegion :\n\tPath extends `/lor/inventory/${string}` ? LorRegion :\n\tPath extends `/lor/match/${string}` ? LorRegion | 'apac' :\n\tPath extends `/lor/ranked/${string}` ? LorRegion :\n\tPath extends `/lor/status/${string}` ? LorRegion :\n\tPath extends `/lol/match/${string}` ? MatchRegion :\n\tPath extends `/lol/spectator/${string}` ? LolRegion :\n\tPath extends `/fulfillment/${string}` ? LolRegion :\n\tPath extends `/lol/summoner/${string}` ? LolRegion :\n\tPath extends `/tft/league/${string}` ? LolRegion :\n\tPath extends `/tft/match/${string}` ? MatchRegion | 'esports' | 'esportseu' :\n\tPath extends `/tft/status/${string}` ? LolRegion :\n\tPath extends `/tft/summoner/${string}` ? LolRegion :\n\t// seems like only americas but not sure\n\tPath extends `/lol/tournament-stub/${string}` ? 'americas' :\n\t// don't know, can't see in api reference\n\tPath extends `/lol/tournament/${string}` ? LolRegion | MatchRegion :\n\t// The api docs do not include all regions for console, but for stability we will just include them\n\tPath extends `/val/match/console/${string}` ? ValorantRegion :\n\tPath extends `/val/console/ranked/${string}` ? ValorantRegion :\n\tPath extends `/val/content/${string}` ? ValorantRegion :\n\tPath extends `/val/match/${string}` ? ValorantRegion :\n\tPath extends `/val/ranked/${string}` ? ValorantRegion :\n\tPath extends `/val/status/${string}` ? Exclude<ValorantRegion, 'esports'>\n\t: never;\n/* eslint-enable @stylistic/indent */\n\n/** Typical structure for a RiotError json object. */\nexport type RiotErrorData = components['schemas']['Error'];\n\n/**\n * Error Class for a 4xx/5xx response code in a fetch to the Riot API\n */\nexport class RiotError extends Error {\n\tconstructor(message: string, statusCode: number, data?: RiotErrorData) {\n\t\tsuper(message);\n\t\tthis.statusCode = statusCode;\n\t\tthis.data = data;\n\t}\n\tstatusCode: number;\n\tdata: RiotErrorData | undefined;\n}\n\n/**\n * Type guard to check if an object is in the form of an riot error.\n * The API may return a structure like that on error, but we cannot be sure.\n *\n * @param obj obj to be checked\n * @returns true if obj has the form of RiotErroData\n */\nfunction isRiotErrorData(obj: unknown): obj is RiotErrorData {\n\tif (typeof obj !== 'object' || obj === null) return false;\n\n\tconst data = obj as RiotErrorData;\n\n\tif (data.status !== undefined) {\n\t\tif (typeof data.status !== 'object') {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ('status_code' in data.status && typeof data.status.status_code !== 'number')\t\t{\n\t\t\treturn false;\n\t\t}\n\n\t\tif ('message' in data.status && typeof data.status.message !== 'string')\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n\n/**\n * This is a mess. I am sorry for this type abonimation.\n *\n * @template Path the Path of the API route\n * @template ChosenMethod the Method that is chosen, has to be one of the available methods of the Path\n * @template ThrowOnError Wether createRiotFetch is configured to throw on http errors or not\n * @template error response.ok, used for type narrowing\n */\ntype RiotFetchReturn<\n\tPath extends TemplatePaths,\n\tChosenMethod extends Methods<ResolveTemplatePath<Path>>,\n\tThrowOnError extends boolean,\n\terror extends boolean,\n> = ThrowOnError extends true\n\t? error extends false\n\t\t? {\n\t\t\t/** The response object of the fetch */\n\t\t\tresponse: Response;\n\t\t\t/** Typed result of response.json() */\n\t\t\tdata: GetResponseBody<ResolveTemplatePath<Path>, ChosenMethod, 200>;\n\t\t}\n\t\t: never\n\t: error extends false\n\t\t? {\n\t\t\t/** The response object of the fetch */\n\t\t\tresponse: Response;\n\t\t\t/** Typed result of response.json() or eventual error data */\n\t\t\tdata: GetResponseBody<ResolveTemplatePath<Path>, ChosenMethod, 200>;\n\t\t\t/** Wether the fetch errored */\n\t\t\terror: false;\n\t\t}\n\t\t: {\n\t\t\t/** The response object of the fetch */\n\t\t\tresponse: Response;\n\t\t\t/** Typed result of response.json() or eventual error data */\n\t\t\tdata:RiotErrorData | undefined;\n\t\t\t/** Wether the fetch errored */\n\t\t\terror: true;\n\t\t};\n\n/**\n * Options for the createRiotFetch functions\n * @template FetchOptions Options the fetch function can accept\n * @template ThrowOnError We set throwOnResponseError as a generic literal boolean, so that we can better type it\n */\nexport interface CreateRiotFetchOptions<FetchOptions, ThrowOnError extends boolean> {\n\t/** The Api Key obtained from Riot Games */\n\tapiKey: string\n\t/** fetch function that gets called (default: `undici.fetch`) */\n\tfetchFn?: (request: string, fetchOptions: FetchOptions) => Promise<Response>\n\t/** Function for dynamically creating the base url based on the given region. (default: standard riot api) */\n\tbaseUrl?: (region: string) => string,\n\t/**\n\t * Wether on 4xx/5xx response status the fetch should error or set error = true and include eventual error data in data\n\t * @see RiotError\n\t */\n\tthrowOnResponseError?: ThrowOnError,\n}\n\n/**\n * Basic Fetch Options that are essential for the functioning of createRiotFetch\n */\ninterface BaseFetchOptions {\n\tmethod?: HTTPMethods,\n\theaders?: Headers,\n}\n\n/**\n * Creates a new function that basically wraps the provided fetch function to provide type information.\n *\n * @param {CreateRiotFetchOptions} createRiotFetchOptions Options for the createRiotFetch function\n * @param defaultOptions Options that get passed to the fetch function by default\n * @returns A fetch function to get fetch the Riot Games API type-safe\n */\nexport function createRiotFetch<\n\tFetchOptions extends BaseFetchOptions & Record<string, unknown>,\n\tThrowOnError extends boolean = false\n>(\n\t{\n\t\tapiKey,\n\t\tfetchFn = fetch,\n\t\tbaseUrl = (region: string) => `https://${region}.api.riotgames.com/`,\n\t\tthrowOnResponseError = false as ThrowOnError\n\t}: CreateRiotFetchOptions<FetchOptions & { body?: BodyInit }, ThrowOnError>,\n\tdefaultOptions: FetchOptions = {} as FetchOptions\n) {\n\tconst headers = new Headers(defaultOptions.headers);\n\theaders.append('X-Riot-Token', apiKey);\n\theaders.append('Content-Type', 'application/json');\n\tdefaultOptions.headers = headers;\n\n\t/**\n\t * A functions that can be used to fetch the Riot Games API with already defined defaults and type information\n\t * based on it's OpenAPI specification.\n\t *\n\t * @template Path The literal type of the path, inferred by `request`\n\t * @template UsableMethods All Methods that can be selected, used to autocomplete `method`\n\t * @template ChosenMethod The method\n\t * @param request The path of the resource requested. Gets merged using `URL`\n\t * @returns Response Object, a promise for the return body, depending on Path, Method and Status Code and an error indicator\n\t * @throws { RiotError } if `throwOnResponseError = true` and !response.ok\n\t */\n\treturn async <\n\t\tPath extends TemplatePaths,\n\t\tUsableMethods extends Methods<ResolveTemplatePath<Path>>,\n\t\tChosenMethod extends UsableMethods | undefined = 'get' extends UsableMethods ? 'get' : UsableMethods,\n\t>(\n\t\trequest: Path,\n\t\toptions: FetchOptions & {\n\t\t\tregion: GetSubdomain<ResolveTemplatePath<Path>>,\n\t\t\tmethod?: UsableMethods,\n\t\t\tbody?: GetRequestBody<ResolveTemplatePath<Path>, Extract<ChosenMethod, HTTPMethods>>\n\t\t},\n\t) => {\n\t\tconst baseURL = baseUrl(options.region);\n\t\tconst req = new URL(request, baseURL);\n\t\tconst response = await fetchFn(req.toString(), {\n\t\t\t...defaultOptions,\n\t\t\t...options,\n\t\t\tbody: JSON.stringify(options.body)\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst riotErrorData = await response.json()\n\t\t\t\t.then(obj => isRiotErrorData(obj) ? obj : undefined)\n\t\t\t\t.catch(() => undefined);\n\n\n\t\t\tif (throwOnResponseError) {\n\t\t\t\tthrow new RiotError(\n\t\t\t\t\t'Riot Games Fetch Error',\n\t\t\t\t\tresponse.status,\n\t\t\t\t\triotErrorData\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tresponse,\n\t\t\t\tdata: riotErrorData,\n\t\t\t\terror: true,\n\t\t\t} as RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, true>;\n\t\t}\n\n\t\treturn {\n\t\t\tresponse,\n\t\t\tdata: await response.json() as GetResponseBody<ResolveTemplatePath<Path>, Extract<ChosenMethod, H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