riotapi-fetch-typed 1.0.3-dev → 1.1.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/dist/index.cjs +6 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +231 -27
- package/dist/index.d.ts +231 -27
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
package/dist/index.cjs
CHANGED
|
@@ -61,8 +61,12 @@ function createRiotFetch({
|
|
|
61
61
|
defaultOptions.headers = headers;
|
|
62
62
|
return async (request, options) => {
|
|
63
63
|
const baseURL = baseUrl(options.region);
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
let req = new URL(request, baseURL).toString();
|
|
65
|
+
if (options.query) {
|
|
66
|
+
const query = Object.entries(options.query).map(([key, value]) => [key, String(value)]);
|
|
67
|
+
req += new URLSearchParams(query).toString();
|
|
68
|
+
}
|
|
69
|
+
const response = await fetchFn(req, {
|
|
66
70
|
...defaultOptions,
|
|
67
71
|
...options,
|
|
68
72
|
body: JSON.stringify(options.body)
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +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, HTTPMethods>, 200>,\n\t\t\terror: false,\n\t\t} as RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, false>;\n\t};\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwHO,IAAM,YAAN,cAAwB,MAAM;AAAA,EACpC,YAAY,SAAiB,YAAoB,MAAsB;AACtE,UAAM,OAAO;AACb,SAAK,aAAa;AAClB,SAAK,OAAO;AAAA,EACb;AAAA,EACA;AAAA,EACA;AACD;AASA,SAAS,gBAAgB,KAAoC;AAC5D,MAAI,OAAO,QAAQ,YAAY,QAAQ,KAAM,QAAO;AAEpD,QAAM,OAAO;AAEb,MAAI,KAAK,WAAW,QAAW;AAC9B,QAAI,OAAO,KAAK,WAAW,UAAU;AACpC,aAAO;AAAA,IACR;AAEA,QAAI,iBAAiB,KAAK,UAAU,OAAO,KAAK,OAAO,gBAAgB,UAAW;AACjF,aAAO;AAAA,IACR;AAEA,QAAI,aAAa,KAAK,UAAU,OAAO,KAAK,OAAO,YAAY,UAAW;AACzE,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO;AACR;AA6EO,SAAS,gBAIf;AAAA,EACC;AAAA,EACA,UAAU;AAAA,EACV,UAAU,CAAC,WAAmB,WAAW,MAAM;AAAA,EAC/C,uBAAuB;AACxB,GACA,iBAA+B,CAAC,GAC/B;AACD,QAAM,UAAU,IAAI,QAAQ,eAAe,OAAO;AAClD,UAAQ,OAAO,gBAAgB,MAAM;AACrC,UAAQ,OAAO,gBAAgB,kBAAkB;AACjD,iBAAe,UAAU;AAazB,SAAO,OAKN,SACA,YAKI;AACJ,UAAM,UAAU,QAAQ,QAAQ,MAAM;AACtC,UAAM,MAAM,IAAI,IAAI,SAAS,OAAO;AACpC,UAAM,WAAW,MAAM,QAAQ,IAAI,SAAS,GAAG;AAAA,MAC9C,GAAG;AAAA,MACH,GAAG;AAAA,MACH,MAAM,KAAK,UAAU,QAAQ,IAAI;AAAA,IAClC,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AACjB,YAAM,gBAAgB,MAAM,SAAS,KAAK,EACxC,KAAK,SAAO,gBAAgB,GAAG,IAAI,MAAM,MAAS,EAClD,MAAM,MAAM,MAAS;AAGvB,UAAI,sBAAsB;AACzB,cAAM,IAAI;AAAA,UACT;AAAA,UACA,SAAS;AAAA,UACT;AAAA,QACD;AAAA,MACD;AAEA,aAAO;AAAA,QACN;AAAA,QACA,MAAM;AAAA,QACN,OAAO;AAAA,MACR;AAAA,IACD;AAEA,WAAO;AAAA,MACN;AAAA,MACA,MAAM,MAAM,SAAS,KAAK;AAAA,MAC1B,OAAO;AAAA,IACR;AAAA,EACD;AACD;","names":[]}
|
|
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/** Splits a Path by `/` into an array */\ntype SplitPath<Path extends string> = Path extends `${infer Head}/${infer Tail}`\n\t? [Head, ...SplitPath<Tail>]\n\t: [Path];\n\n/**\n * Compares two splitted paths.\n *\n * Type is true if both splitted paths have the same length and every segment of Concrete extends its corresponding segment Template\n * */\ntype MatchSegments<Template extends string[], Concrete extends string[]> =\n Template extends [infer TemplateSegment, ...infer TemplateRest]\n \t? Concrete extends [infer ConcreteSegment, ...infer ConcreteRest]\n \t\t? ConcreteSegment extends TemplateSegment\n \t\t\t? TemplateRest extends string[]\n \t\t\t\t? ConcreteRest extends string[]\n \t\t\t\t\t? MatchSegments<TemplateRest, ConcreteRest>\n \t\t\t\t\t: never\n \t\t\t\t: never\n \t\t\t: false\n \t\t: Concrete extends []\n \t\t\t? Template extends []\n \t\t\t\t? true\n \t\t\t\t: false\n \t\t\t: false\n \t: Template extends []\n \t\t? Concrete extends []\n \t\t\t? true\n \t\t\t: false\n \t\t: false;\n\n/**\n * Gives all API Paths that matches the 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 *\n * @example ResolveTemplatePath<`/riot/account/v1/accounts/by-riot-id/gameName/gameTag`>\n * -> \"/riot/account/v1/accounts/by-riot-id/{gameName}/{tagLine}\"\n */\ntype ResolveTemplatePath<Path extends TemplatePaths> = {\n\t[P in Paths]: MatchSegments<SplitPath<TemplatifyPath<P>>, SplitPath<Path>> extends true ? P : never\n}[Paths];\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\ntype GetRequestBody<Path extends Paths, Method extends Methods<Path>> =\n paths[Path][Method] extends { requestBody?: never }\n \t? { body?: never }\n \t: paths[Path][Method] extends { requestBody: { content: { 'application/json': infer U } } }\n \t\t? { body: U }\n \t\t: paths[Path][Method] extends { requestBody?: { content: { 'application/json': infer U } } }\n \t\t\t? { body?: U }\n \t\t\t: unknown;\n\n\n/** Get the query parameters for a specific API path and method */\ntype GetQuery<Path extends Paths, Method extends Methods<Path>> =\n Pick<paths[Path][Method]['parameters'], 'query'>;\n\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 */\nexport interface 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}\n\t\t\t& GetRequestBody<ResolveTemplatePath<Path>, Extract<ChosenMethod, HTTPMethods>>\n\t\t\t& GetQuery<ResolveTemplatePath<Path>, Extract<ChosenMethod, HTTPMethods>>,\n\t) => {\n\t\tconst baseURL = baseUrl(options.region);\n\t\tlet req = new URL(request, baseURL).toString();\n\t\tif (options.query) {\n\t\t\tconst query = Object.entries(options.query).map(([key, value]) => [key, String(value)]);\n\t\t\treq += new URLSearchParams(query).toString();\n\t\t}\n\n\t\tconst response = await fetchFn(req, {\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, HTTPMethods>, 200>,\n\t\t\terror: false,\n\t\t} as RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, false>;\n\t};\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmKO,IAAM,YAAN,cAAwB,MAAM;AAAA,EACpC,YAAY,SAAiB,YAAoB,MAAsB;AACtE,UAAM,OAAO;AACb,SAAK,aAAa;AAClB,SAAK,OAAO;AAAA,EACb;AAAA,EACA;AAAA,EACA;AACD;AASA,SAAS,gBAAgB,KAAoC;AAC5D,MAAI,OAAO,QAAQ,YAAY,QAAQ,KAAM,QAAO;AAEpD,QAAM,OAAO;AAEb,MAAI,KAAK,WAAW,QAAW;AAC9B,QAAI,OAAO,KAAK,WAAW,UAAU;AACpC,aAAO;AAAA,IACR;AAEA,QAAI,iBAAiB,KAAK,UAAU,OAAO,KAAK,OAAO,gBAAgB,UAAW;AACjF,aAAO;AAAA,IACR;AAEA,QAAI,aAAa,KAAK,UAAU,OAAO,KAAK,OAAO,YAAY,UAAW;AACzE,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO;AACR;AA6EO,SAAS,gBAIf;AAAA,EACC;AAAA,EACA,UAAU;AAAA,EACV,UAAU,CAAC,WAAmB,WAAW,MAAM;AAAA,EAC/C,uBAAuB;AACxB,GACA,iBAA+B,CAAC,GAC/B;AACD,QAAM,UAAU,IAAI,QAAQ,eAAe,OAAO;AAClD,UAAQ,OAAO,gBAAgB,MAAM;AACrC,UAAQ,OAAO,gBAAgB,kBAAkB;AACjD,iBAAe,UAAU;AAazB,SAAO,OAKN,SACA,YAMI;AACJ,UAAM,UAAU,QAAQ,QAAQ,MAAM;AACtC,QAAI,MAAM,IAAI,IAAI,SAAS,OAAO,EAAE,SAAS;AAC7C,QAAI,QAAQ,OAAO;AAClB,YAAM,QAAQ,OAAO,QAAQ,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,OAAO,KAAK,CAAC,CAAC;AACtF,aAAO,IAAI,gBAAgB,KAAK,EAAE,SAAS;AAAA,IAC5C;AAEA,UAAM,WAAW,MAAM,QAAQ,KAAK;AAAA,MACnC,GAAG;AAAA,MACH,GAAG;AAAA,MACH,MAAM,KAAK,UAAU,QAAQ,IAAI;AAAA,IAClC,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AACjB,YAAM,gBAAgB,MAAM,SAAS,KAAK,EACxC,KAAK,SAAO,gBAAgB,GAAG,IAAI,MAAM,MAAS,EAClD,MAAM,MAAM,MAAS;AAGvB,UAAI,sBAAsB;AACzB,cAAM,IAAI;AAAA,UACT;AAAA,UACA,SAAS;AAAA,UACT;AAAA,QACD;AAAA,MACD;AAEA,aAAO;AAAA,QACN;AAAA,QACA,MAAM;AAAA,QACN,OAAO;AAAA,MACR;AAAA,IACD;AAEA,WAAO;AAAA,MACN;AAAA,MACA,MAAM,MAAM,SAAS,KAAK;AAAA,MAC1B,OAAO;AAAA,IACR;AAAA,EACD;AACD;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -830,6 +830,26 @@ interface paths {
|
|
|
830
830
|
patch?: never;
|
|
831
831
|
trace?: never;
|
|
832
832
|
};
|
|
833
|
+
"/riftbound/content/v1/contents": {
|
|
834
|
+
parameters: {
|
|
835
|
+
query?: never;
|
|
836
|
+
header?: never;
|
|
837
|
+
path?: never;
|
|
838
|
+
cookie?: never;
|
|
839
|
+
};
|
|
840
|
+
/**
|
|
841
|
+
* Get riftbound content
|
|
842
|
+
* @description Get riftbound content
|
|
843
|
+
*/
|
|
844
|
+
get: operations["riftbound-content-v1.getContent"];
|
|
845
|
+
put?: never;
|
|
846
|
+
post?: never;
|
|
847
|
+
delete?: never;
|
|
848
|
+
options?: never;
|
|
849
|
+
head?: never;
|
|
850
|
+
patch?: never;
|
|
851
|
+
trace?: never;
|
|
852
|
+
};
|
|
833
853
|
"/lol/spectator/tft/v5/active-games/by-puuid/{encryptedPUUID}": {
|
|
834
854
|
parameters: {
|
|
835
855
|
query?: never;
|
|
@@ -1987,31 +2007,35 @@ interface components {
|
|
|
1987
2007
|
"lol-challenges-v1.Level": Record<string, never>;
|
|
1988
2008
|
/** PlayerInfoDto */
|
|
1989
2009
|
"lol-challenges-v1.PlayerInfoDto": {
|
|
1990
|
-
challenges: components["schemas"]["lol-challenges-v1.
|
|
1991
|
-
preferences: components["schemas"]["lol-challenges-v1.
|
|
1992
|
-
totalPoints: components["schemas"]["lol-challenges-v1.
|
|
2010
|
+
challenges: components["schemas"]["lol-challenges-v1.ChallengeInfoDto"][];
|
|
2011
|
+
preferences: components["schemas"]["lol-challenges-v1.PlayerClientPreferencesDto"];
|
|
2012
|
+
totalPoints: components["schemas"]["lol-challenges-v1.ChallengePointDto"];
|
|
1993
2013
|
categoryPoints: {
|
|
1994
|
-
[key: string]: components["schemas"]["lol-challenges-v1.
|
|
2014
|
+
[key: string]: components["schemas"]["lol-challenges-v1.ChallengePointDto"];
|
|
1995
2015
|
};
|
|
1996
2016
|
};
|
|
1997
|
-
/**
|
|
1998
|
-
"lol-challenges-v1.
|
|
1999
|
-
/** Format: int64 */
|
|
2000
|
-
challengeId: number;
|
|
2017
|
+
/** ChallengeInfoDto */
|
|
2018
|
+
"lol-challenges-v1.ChallengeInfoDto": {
|
|
2001
2019
|
/** Format: double */
|
|
2002
2020
|
percentile: number;
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
value: number;
|
|
2021
|
+
/** Format: int32 */
|
|
2022
|
+
playersInLevel?: number;
|
|
2006
2023
|
/** Format: int64 */
|
|
2007
2024
|
achievedTime?: number;
|
|
2025
|
+
/** Format: double */
|
|
2026
|
+
value: number;
|
|
2008
2027
|
/** Format: int64 */
|
|
2028
|
+
challengeId: number;
|
|
2029
|
+
/**
|
|
2030
|
+
* @description (Legal values: NONE, IRON, BRONZE, SILVER, GOLD, PLATINUM, DIAMOND, MASTER, GRANDMASTER, CHALLENGER, HIGHEST_NOT_LEADERBOARD_ONLY, HIGHEST, LOWEST)
|
|
2031
|
+
* @enum {string}
|
|
2032
|
+
*/
|
|
2033
|
+
level: "NONE" | "IRON" | "BRONZE" | "SILVER" | "GOLD" | "PLATINUM" | "DIAMOND" | "MASTER" | "GRANDMASTER" | "CHALLENGER" | "HIGHEST_NOT_LEADERBOARD_ONLY" | "HIGHEST" | "LOWEST";
|
|
2034
|
+
/** Format: int32 */
|
|
2009
2035
|
position?: number;
|
|
2010
|
-
/** Format: int64 */
|
|
2011
|
-
playersInLevel?: number;
|
|
2012
2036
|
};
|
|
2013
|
-
/**
|
|
2014
|
-
"lol-challenges-v1.
|
|
2037
|
+
/** PlayerClientPreferencesDto */
|
|
2038
|
+
"lol-challenges-v1.PlayerClientPreferencesDto": {
|
|
2015
2039
|
bannerAccent?: string;
|
|
2016
2040
|
title?: string;
|
|
2017
2041
|
challengeIds?: number[];
|
|
@@ -2019,8 +2043,8 @@ interface components {
|
|
|
2019
2043
|
/** Format: int32 */
|
|
2020
2044
|
prestigeCrestBorderLevel?: number;
|
|
2021
2045
|
};
|
|
2022
|
-
/**
|
|
2023
|
-
"lol-challenges-v1.
|
|
2046
|
+
/** ChallengePointsDto */
|
|
2047
|
+
"lol-challenges-v1.ChallengePointDto": {
|
|
2024
2048
|
level: string;
|
|
2025
2049
|
/** Format: int64 */
|
|
2026
2050
|
current: number;
|
|
@@ -3289,6 +3313,61 @@ interface components {
|
|
|
3289
3313
|
/** Format: int32 */
|
|
3290
3314
|
featState?: number;
|
|
3291
3315
|
};
|
|
3316
|
+
/** RiftboundContentDTO */
|
|
3317
|
+
"riftbound-content-v1.RiftboundContentDTO": {
|
|
3318
|
+
/** @description Game Name */
|
|
3319
|
+
game: string;
|
|
3320
|
+
/** @description Content version */
|
|
3321
|
+
version: string;
|
|
3322
|
+
/** @description ISO Timestamp of content last update */
|
|
3323
|
+
lastUpdated: string;
|
|
3324
|
+
sets: components["schemas"]["riftbound-content-v1.SetDTO"][];
|
|
3325
|
+
};
|
|
3326
|
+
/** SetDTO */
|
|
3327
|
+
"riftbound-content-v1.SetDTO": {
|
|
3328
|
+
/** @description Set ID */
|
|
3329
|
+
id: string;
|
|
3330
|
+
/** @description Set Name */
|
|
3331
|
+
name: string;
|
|
3332
|
+
cards: components["schemas"]["riftbound-content-v1.CardDTO"][];
|
|
3333
|
+
};
|
|
3334
|
+
/** CardDTO */
|
|
3335
|
+
"riftbound-content-v1.CardDTO": {
|
|
3336
|
+
/** @description Card ID */
|
|
3337
|
+
id: string;
|
|
3338
|
+
/** Format: int64 */
|
|
3339
|
+
collectorNumber: number;
|
|
3340
|
+
set: string;
|
|
3341
|
+
/** @description Card Name */
|
|
3342
|
+
name: string;
|
|
3343
|
+
description: string;
|
|
3344
|
+
/** @description Card Type */
|
|
3345
|
+
type: string;
|
|
3346
|
+
rarity: string;
|
|
3347
|
+
faction: string;
|
|
3348
|
+
stats: components["schemas"]["riftbound-content-v1.CardStatsDTO"];
|
|
3349
|
+
keywords: string[];
|
|
3350
|
+
art: components["schemas"]["riftbound-content-v1.CardArtDTO"];
|
|
3351
|
+
flavorText: string;
|
|
3352
|
+
tags: string[];
|
|
3353
|
+
};
|
|
3354
|
+
/** CardStatsDTO */
|
|
3355
|
+
"riftbound-content-v1.CardStatsDTO": {
|
|
3356
|
+
/** Format: int64 */
|
|
3357
|
+
energy: number;
|
|
3358
|
+
/** Format: int64 */
|
|
3359
|
+
might: number;
|
|
3360
|
+
/** Format: int64 */
|
|
3361
|
+
cost: number;
|
|
3362
|
+
/** Format: int64 */
|
|
3363
|
+
power: number;
|
|
3364
|
+
};
|
|
3365
|
+
/** CardArtDTO */
|
|
3366
|
+
"riftbound-content-v1.CardArtDTO": {
|
|
3367
|
+
thumbnailURL: string;
|
|
3368
|
+
fullURL: string;
|
|
3369
|
+
artist: string;
|
|
3370
|
+
};
|
|
3292
3371
|
/** CurrentGameInfo */
|
|
3293
3372
|
"spectator-tft-v5.CurrentGameInfo": {
|
|
3294
3373
|
/**
|
|
@@ -9264,6 +9343,106 @@ interface operations {
|
|
|
9264
9343
|
};
|
|
9265
9344
|
};
|
|
9266
9345
|
};
|
|
9346
|
+
"riftbound-content-v1.getContent": {
|
|
9347
|
+
parameters: {
|
|
9348
|
+
query?: {
|
|
9349
|
+
/** @description Defaults to en. Optional. Specifies the language and regional settings for the response. Use a locale code. During beta only en available. */
|
|
9350
|
+
locale?: string;
|
|
9351
|
+
};
|
|
9352
|
+
header?: never;
|
|
9353
|
+
path?: never;
|
|
9354
|
+
cookie?: never;
|
|
9355
|
+
};
|
|
9356
|
+
requestBody?: never;
|
|
9357
|
+
responses: {
|
|
9358
|
+
/** @description Success */
|
|
9359
|
+
200: {
|
|
9360
|
+
headers: {
|
|
9361
|
+
[name: string]: unknown;
|
|
9362
|
+
};
|
|
9363
|
+
content: {
|
|
9364
|
+
"application/json": components["schemas"]["riftbound-content-v1.RiftboundContentDTO"];
|
|
9365
|
+
};
|
|
9366
|
+
};
|
|
9367
|
+
/** @description Bad request */
|
|
9368
|
+
400: {
|
|
9369
|
+
headers: {
|
|
9370
|
+
[name: string]: unknown;
|
|
9371
|
+
};
|
|
9372
|
+
content?: never;
|
|
9373
|
+
};
|
|
9374
|
+
/** @description Unauthorized */
|
|
9375
|
+
401: {
|
|
9376
|
+
headers: {
|
|
9377
|
+
[name: string]: unknown;
|
|
9378
|
+
};
|
|
9379
|
+
content?: never;
|
|
9380
|
+
};
|
|
9381
|
+
/** @description Forbidden */
|
|
9382
|
+
403: {
|
|
9383
|
+
headers: {
|
|
9384
|
+
[name: string]: unknown;
|
|
9385
|
+
};
|
|
9386
|
+
content?: never;
|
|
9387
|
+
};
|
|
9388
|
+
/** @description Data not found */
|
|
9389
|
+
404: {
|
|
9390
|
+
headers: {
|
|
9391
|
+
[name: string]: unknown;
|
|
9392
|
+
};
|
|
9393
|
+
content?: never;
|
|
9394
|
+
};
|
|
9395
|
+
/** @description Method not allowed */
|
|
9396
|
+
405: {
|
|
9397
|
+
headers: {
|
|
9398
|
+
[name: string]: unknown;
|
|
9399
|
+
};
|
|
9400
|
+
content?: never;
|
|
9401
|
+
};
|
|
9402
|
+
/** @description Unsupported media type */
|
|
9403
|
+
415: {
|
|
9404
|
+
headers: {
|
|
9405
|
+
[name: string]: unknown;
|
|
9406
|
+
};
|
|
9407
|
+
content?: never;
|
|
9408
|
+
};
|
|
9409
|
+
/** @description Rate limit exceeded */
|
|
9410
|
+
429: {
|
|
9411
|
+
headers: {
|
|
9412
|
+
[name: string]: unknown;
|
|
9413
|
+
};
|
|
9414
|
+
content?: never;
|
|
9415
|
+
};
|
|
9416
|
+
/** @description Internal server error */
|
|
9417
|
+
500: {
|
|
9418
|
+
headers: {
|
|
9419
|
+
[name: string]: unknown;
|
|
9420
|
+
};
|
|
9421
|
+
content?: never;
|
|
9422
|
+
};
|
|
9423
|
+
/** @description Bad gateway */
|
|
9424
|
+
502: {
|
|
9425
|
+
headers: {
|
|
9426
|
+
[name: string]: unknown;
|
|
9427
|
+
};
|
|
9428
|
+
content?: never;
|
|
9429
|
+
};
|
|
9430
|
+
/** @description Service unavailable */
|
|
9431
|
+
503: {
|
|
9432
|
+
headers: {
|
|
9433
|
+
[name: string]: unknown;
|
|
9434
|
+
};
|
|
9435
|
+
content?: never;
|
|
9436
|
+
};
|
|
9437
|
+
/** @description Gateway timeout */
|
|
9438
|
+
504: {
|
|
9439
|
+
headers: {
|
|
9440
|
+
[name: string]: unknown;
|
|
9441
|
+
};
|
|
9442
|
+
content?: never;
|
|
9443
|
+
};
|
|
9444
|
+
};
|
|
9445
|
+
};
|
|
9267
9446
|
"spectator-tft-v5.getCurrentGameInfoByPuuid": {
|
|
9268
9447
|
parameters: {
|
|
9269
9448
|
query?: never;
|
|
@@ -13299,14 +13478,25 @@ type Paths = keyof paths;
|
|
|
13299
13478
|
type TemplatifyPath<Path extends string> = Path extends `${infer Start}/{${string}}${infer End}` ? `${Start}/${string}${TemplatifyPath<End>}` : Path;
|
|
13300
13479
|
/** Every possible API path, but templatified */
|
|
13301
13480
|
type TemplatePaths = TemplatifyPath<Paths>;
|
|
13481
|
+
/** Splits a Path by `/` into an array */
|
|
13482
|
+
type SplitPath<Path extends string> = Path extends `${infer Head}/${infer Tail}` ? [Head, ...SplitPath<Tail>] : [Path];
|
|
13483
|
+
/**
|
|
13484
|
+
* Compares two splitted paths.
|
|
13485
|
+
*
|
|
13486
|
+
* Type is true if both splitted paths have the same length and every segment of Concrete extends its corresponding segment Template
|
|
13487
|
+
* */
|
|
13488
|
+
type MatchSegments<Template extends string[], Concrete extends string[]> = Template extends [infer TemplateSegment, ...infer TemplateRest] ? Concrete extends [infer ConcreteSegment, ...infer ConcreteRest] ? ConcreteSegment extends TemplateSegment ? TemplateRest extends string[] ? ConcreteRest extends string[] ? MatchSegments<TemplateRest, ConcreteRest> : never : never : false : Concrete extends [] ? Template extends [] ? true : false : false : Template extends [] ? Concrete extends [] ? true : false : false;
|
|
13302
13489
|
/**
|
|
13303
|
-
* Gives all API Paths that matches the
|
|
13490
|
+
* Gives all API Paths that matches the path. Basically the reverse operation of TemplatifyPath
|
|
13304
13491
|
*
|
|
13305
13492
|
* @example ResolveTemplatePath<`/riot/account/v1/accounts/by-puuid/${string}`>
|
|
13306
13493
|
* -> "/riot/account/v1/accounts/by-puuid/{puuid}"
|
|
13494
|
+
*
|
|
13495
|
+
* @example ResolveTemplatePath<`/riot/account/v1/accounts/by-riot-id/gameName/gameTag`>
|
|
13496
|
+
* -> "/riot/account/v1/accounts/by-riot-id/{gameName}/{tagLine}"
|
|
13307
13497
|
*/
|
|
13308
|
-
type ResolveTemplatePath<
|
|
13309
|
-
[P in Paths]:
|
|
13498
|
+
type ResolveTemplatePath<Path extends TemplatePaths> = {
|
|
13499
|
+
[P in Paths]: MatchSegments<SplitPath<TemplatifyPath<P>>, SplitPath<Path>> extends true ? P : never;
|
|
13310
13500
|
}[Paths];
|
|
13311
13501
|
type HTTPMethods = 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace';
|
|
13312
13502
|
/**
|
|
@@ -13321,18 +13511,33 @@ type GetResponses<Path extends Paths, Method extends Methods<Path>> = paths[Path
|
|
|
13321
13511
|
} ? Responses : never;
|
|
13322
13512
|
/** Get the response body for a specific API path, method and status code */
|
|
13323
13513
|
type GetResponseBody<Path extends Paths, Method extends Methods<Path>, StatusCode extends number> = GetResponses<Path, Method> extends Record<StatusCode, {
|
|
13324
|
-
content
|
|
13514
|
+
content?: {
|
|
13325
13515
|
'application/json': infer Body;
|
|
13326
13516
|
};
|
|
13327
13517
|
}> ? Body : never;
|
|
13328
|
-
/** Get the request body for a specific API path and method */
|
|
13329
13518
|
type GetRequestBody<Path extends Paths, Method extends Methods<Path>> = paths[Path][Method] extends {
|
|
13519
|
+
requestBody?: never;
|
|
13520
|
+
} ? {
|
|
13521
|
+
body?: never;
|
|
13522
|
+
} : paths[Path][Method] extends {
|
|
13330
13523
|
requestBody: {
|
|
13331
13524
|
content: {
|
|
13332
|
-
'application/json': infer
|
|
13525
|
+
'application/json': infer U;
|
|
13526
|
+
};
|
|
13527
|
+
};
|
|
13528
|
+
} ? {
|
|
13529
|
+
body: U;
|
|
13530
|
+
} : paths[Path][Method] extends {
|
|
13531
|
+
requestBody?: {
|
|
13532
|
+
content: {
|
|
13533
|
+
'application/json': infer U;
|
|
13333
13534
|
};
|
|
13334
13535
|
};
|
|
13335
|
-
} ?
|
|
13536
|
+
} ? {
|
|
13537
|
+
body?: U;
|
|
13538
|
+
} : unknown;
|
|
13539
|
+
/** Get the query parameters for a specific API path and method */
|
|
13540
|
+
type GetQuery<Path extends Paths, Method extends Methods<Path>> = Pick<paths[Path][Method]['parameters'], 'query'>;
|
|
13336
13541
|
/** Regions for /riot/account/ endpoints */
|
|
13337
13542
|
type AccountRegion = 'americas' | 'asia' | 'europe';
|
|
13338
13543
|
/** Regions for some lol and tft endpoints */
|
|
@@ -13420,7 +13625,6 @@ declare function createRiotFetch<FetchOptions extends BaseFetchOptions & Record<
|
|
|
13420
13625
|
}, ThrowOnError>, defaultOptions?: FetchOptions): <Path extends TemplatePaths, UsableMethods extends Methods<ResolveTemplatePath<Path>>, ChosenMethod extends UsableMethods | undefined = "get" extends UsableMethods ? "get" : UsableMethods>(request: Path, options: FetchOptions & {
|
|
13421
13626
|
region: GetSubdomain<ResolveTemplatePath<Path>>;
|
|
13422
13627
|
method?: UsableMethods;
|
|
13423
|
-
|
|
13424
|
-
}) => Promise<RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, true> | RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, false>>;
|
|
13628
|
+
} & GetRequestBody<ResolveTemplatePath<Path>, Extract<ChosenMethod, HTTPMethods>> & GetQuery<ResolveTemplatePath<Path>, Extract<ChosenMethod, HTTPMethods>>) => Promise<RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, true> | RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, false>>;
|
|
13425
13629
|
|
|
13426
|
-
export { type $defs, type AccountRegion, type CreateRiotFetchOptions, type HTTPMethods, type LolRegion, type LorRegion, type MatchRegion, RiotError, type RiotErrorData, type ValorantRegion, type components, createRiotFetch, type operations, type paths, type webhooks };
|
|
13630
|
+
export { type $defs, type AccountRegion, type BaseFetchOptions, type CreateRiotFetchOptions, type HTTPMethods, type LolRegion, type LorRegion, type MatchRegion, RiotError, type RiotErrorData, type ValorantRegion, type components, createRiotFetch, type operations, type paths, type webhooks };
|
package/dist/index.d.ts
CHANGED
|
@@ -830,6 +830,26 @@ interface paths {
|
|
|
830
830
|
patch?: never;
|
|
831
831
|
trace?: never;
|
|
832
832
|
};
|
|
833
|
+
"/riftbound/content/v1/contents": {
|
|
834
|
+
parameters: {
|
|
835
|
+
query?: never;
|
|
836
|
+
header?: never;
|
|
837
|
+
path?: never;
|
|
838
|
+
cookie?: never;
|
|
839
|
+
};
|
|
840
|
+
/**
|
|
841
|
+
* Get riftbound content
|
|
842
|
+
* @description Get riftbound content
|
|
843
|
+
*/
|
|
844
|
+
get: operations["riftbound-content-v1.getContent"];
|
|
845
|
+
put?: never;
|
|
846
|
+
post?: never;
|
|
847
|
+
delete?: never;
|
|
848
|
+
options?: never;
|
|
849
|
+
head?: never;
|
|
850
|
+
patch?: never;
|
|
851
|
+
trace?: never;
|
|
852
|
+
};
|
|
833
853
|
"/lol/spectator/tft/v5/active-games/by-puuid/{encryptedPUUID}": {
|
|
834
854
|
parameters: {
|
|
835
855
|
query?: never;
|
|
@@ -1987,31 +2007,35 @@ interface components {
|
|
|
1987
2007
|
"lol-challenges-v1.Level": Record<string, never>;
|
|
1988
2008
|
/** PlayerInfoDto */
|
|
1989
2009
|
"lol-challenges-v1.PlayerInfoDto": {
|
|
1990
|
-
challenges: components["schemas"]["lol-challenges-v1.
|
|
1991
|
-
preferences: components["schemas"]["lol-challenges-v1.
|
|
1992
|
-
totalPoints: components["schemas"]["lol-challenges-v1.
|
|
2010
|
+
challenges: components["schemas"]["lol-challenges-v1.ChallengeInfoDto"][];
|
|
2011
|
+
preferences: components["schemas"]["lol-challenges-v1.PlayerClientPreferencesDto"];
|
|
2012
|
+
totalPoints: components["schemas"]["lol-challenges-v1.ChallengePointDto"];
|
|
1993
2013
|
categoryPoints: {
|
|
1994
|
-
[key: string]: components["schemas"]["lol-challenges-v1.
|
|
2014
|
+
[key: string]: components["schemas"]["lol-challenges-v1.ChallengePointDto"];
|
|
1995
2015
|
};
|
|
1996
2016
|
};
|
|
1997
|
-
/**
|
|
1998
|
-
"lol-challenges-v1.
|
|
1999
|
-
/** Format: int64 */
|
|
2000
|
-
challengeId: number;
|
|
2017
|
+
/** ChallengeInfoDto */
|
|
2018
|
+
"lol-challenges-v1.ChallengeInfoDto": {
|
|
2001
2019
|
/** Format: double */
|
|
2002
2020
|
percentile: number;
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
value: number;
|
|
2021
|
+
/** Format: int32 */
|
|
2022
|
+
playersInLevel?: number;
|
|
2006
2023
|
/** Format: int64 */
|
|
2007
2024
|
achievedTime?: number;
|
|
2025
|
+
/** Format: double */
|
|
2026
|
+
value: number;
|
|
2008
2027
|
/** Format: int64 */
|
|
2028
|
+
challengeId: number;
|
|
2029
|
+
/**
|
|
2030
|
+
* @description (Legal values: NONE, IRON, BRONZE, SILVER, GOLD, PLATINUM, DIAMOND, MASTER, GRANDMASTER, CHALLENGER, HIGHEST_NOT_LEADERBOARD_ONLY, HIGHEST, LOWEST)
|
|
2031
|
+
* @enum {string}
|
|
2032
|
+
*/
|
|
2033
|
+
level: "NONE" | "IRON" | "BRONZE" | "SILVER" | "GOLD" | "PLATINUM" | "DIAMOND" | "MASTER" | "GRANDMASTER" | "CHALLENGER" | "HIGHEST_NOT_LEADERBOARD_ONLY" | "HIGHEST" | "LOWEST";
|
|
2034
|
+
/** Format: int32 */
|
|
2009
2035
|
position?: number;
|
|
2010
|
-
/** Format: int64 */
|
|
2011
|
-
playersInLevel?: number;
|
|
2012
2036
|
};
|
|
2013
|
-
/**
|
|
2014
|
-
"lol-challenges-v1.
|
|
2037
|
+
/** PlayerClientPreferencesDto */
|
|
2038
|
+
"lol-challenges-v1.PlayerClientPreferencesDto": {
|
|
2015
2039
|
bannerAccent?: string;
|
|
2016
2040
|
title?: string;
|
|
2017
2041
|
challengeIds?: number[];
|
|
@@ -2019,8 +2043,8 @@ interface components {
|
|
|
2019
2043
|
/** Format: int32 */
|
|
2020
2044
|
prestigeCrestBorderLevel?: number;
|
|
2021
2045
|
};
|
|
2022
|
-
/**
|
|
2023
|
-
"lol-challenges-v1.
|
|
2046
|
+
/** ChallengePointsDto */
|
|
2047
|
+
"lol-challenges-v1.ChallengePointDto": {
|
|
2024
2048
|
level: string;
|
|
2025
2049
|
/** Format: int64 */
|
|
2026
2050
|
current: number;
|
|
@@ -3289,6 +3313,61 @@ interface components {
|
|
|
3289
3313
|
/** Format: int32 */
|
|
3290
3314
|
featState?: number;
|
|
3291
3315
|
};
|
|
3316
|
+
/** RiftboundContentDTO */
|
|
3317
|
+
"riftbound-content-v1.RiftboundContentDTO": {
|
|
3318
|
+
/** @description Game Name */
|
|
3319
|
+
game: string;
|
|
3320
|
+
/** @description Content version */
|
|
3321
|
+
version: string;
|
|
3322
|
+
/** @description ISO Timestamp of content last update */
|
|
3323
|
+
lastUpdated: string;
|
|
3324
|
+
sets: components["schemas"]["riftbound-content-v1.SetDTO"][];
|
|
3325
|
+
};
|
|
3326
|
+
/** SetDTO */
|
|
3327
|
+
"riftbound-content-v1.SetDTO": {
|
|
3328
|
+
/** @description Set ID */
|
|
3329
|
+
id: string;
|
|
3330
|
+
/** @description Set Name */
|
|
3331
|
+
name: string;
|
|
3332
|
+
cards: components["schemas"]["riftbound-content-v1.CardDTO"][];
|
|
3333
|
+
};
|
|
3334
|
+
/** CardDTO */
|
|
3335
|
+
"riftbound-content-v1.CardDTO": {
|
|
3336
|
+
/** @description Card ID */
|
|
3337
|
+
id: string;
|
|
3338
|
+
/** Format: int64 */
|
|
3339
|
+
collectorNumber: number;
|
|
3340
|
+
set: string;
|
|
3341
|
+
/** @description Card Name */
|
|
3342
|
+
name: string;
|
|
3343
|
+
description: string;
|
|
3344
|
+
/** @description Card Type */
|
|
3345
|
+
type: string;
|
|
3346
|
+
rarity: string;
|
|
3347
|
+
faction: string;
|
|
3348
|
+
stats: components["schemas"]["riftbound-content-v1.CardStatsDTO"];
|
|
3349
|
+
keywords: string[];
|
|
3350
|
+
art: components["schemas"]["riftbound-content-v1.CardArtDTO"];
|
|
3351
|
+
flavorText: string;
|
|
3352
|
+
tags: string[];
|
|
3353
|
+
};
|
|
3354
|
+
/** CardStatsDTO */
|
|
3355
|
+
"riftbound-content-v1.CardStatsDTO": {
|
|
3356
|
+
/** Format: int64 */
|
|
3357
|
+
energy: number;
|
|
3358
|
+
/** Format: int64 */
|
|
3359
|
+
might: number;
|
|
3360
|
+
/** Format: int64 */
|
|
3361
|
+
cost: number;
|
|
3362
|
+
/** Format: int64 */
|
|
3363
|
+
power: number;
|
|
3364
|
+
};
|
|
3365
|
+
/** CardArtDTO */
|
|
3366
|
+
"riftbound-content-v1.CardArtDTO": {
|
|
3367
|
+
thumbnailURL: string;
|
|
3368
|
+
fullURL: string;
|
|
3369
|
+
artist: string;
|
|
3370
|
+
};
|
|
3292
3371
|
/** CurrentGameInfo */
|
|
3293
3372
|
"spectator-tft-v5.CurrentGameInfo": {
|
|
3294
3373
|
/**
|
|
@@ -9264,6 +9343,106 @@ interface operations {
|
|
|
9264
9343
|
};
|
|
9265
9344
|
};
|
|
9266
9345
|
};
|
|
9346
|
+
"riftbound-content-v1.getContent": {
|
|
9347
|
+
parameters: {
|
|
9348
|
+
query?: {
|
|
9349
|
+
/** @description Defaults to en. Optional. Specifies the language and regional settings for the response. Use a locale code. During beta only en available. */
|
|
9350
|
+
locale?: string;
|
|
9351
|
+
};
|
|
9352
|
+
header?: never;
|
|
9353
|
+
path?: never;
|
|
9354
|
+
cookie?: never;
|
|
9355
|
+
};
|
|
9356
|
+
requestBody?: never;
|
|
9357
|
+
responses: {
|
|
9358
|
+
/** @description Success */
|
|
9359
|
+
200: {
|
|
9360
|
+
headers: {
|
|
9361
|
+
[name: string]: unknown;
|
|
9362
|
+
};
|
|
9363
|
+
content: {
|
|
9364
|
+
"application/json": components["schemas"]["riftbound-content-v1.RiftboundContentDTO"];
|
|
9365
|
+
};
|
|
9366
|
+
};
|
|
9367
|
+
/** @description Bad request */
|
|
9368
|
+
400: {
|
|
9369
|
+
headers: {
|
|
9370
|
+
[name: string]: unknown;
|
|
9371
|
+
};
|
|
9372
|
+
content?: never;
|
|
9373
|
+
};
|
|
9374
|
+
/** @description Unauthorized */
|
|
9375
|
+
401: {
|
|
9376
|
+
headers: {
|
|
9377
|
+
[name: string]: unknown;
|
|
9378
|
+
};
|
|
9379
|
+
content?: never;
|
|
9380
|
+
};
|
|
9381
|
+
/** @description Forbidden */
|
|
9382
|
+
403: {
|
|
9383
|
+
headers: {
|
|
9384
|
+
[name: string]: unknown;
|
|
9385
|
+
};
|
|
9386
|
+
content?: never;
|
|
9387
|
+
};
|
|
9388
|
+
/** @description Data not found */
|
|
9389
|
+
404: {
|
|
9390
|
+
headers: {
|
|
9391
|
+
[name: string]: unknown;
|
|
9392
|
+
};
|
|
9393
|
+
content?: never;
|
|
9394
|
+
};
|
|
9395
|
+
/** @description Method not allowed */
|
|
9396
|
+
405: {
|
|
9397
|
+
headers: {
|
|
9398
|
+
[name: string]: unknown;
|
|
9399
|
+
};
|
|
9400
|
+
content?: never;
|
|
9401
|
+
};
|
|
9402
|
+
/** @description Unsupported media type */
|
|
9403
|
+
415: {
|
|
9404
|
+
headers: {
|
|
9405
|
+
[name: string]: unknown;
|
|
9406
|
+
};
|
|
9407
|
+
content?: never;
|
|
9408
|
+
};
|
|
9409
|
+
/** @description Rate limit exceeded */
|
|
9410
|
+
429: {
|
|
9411
|
+
headers: {
|
|
9412
|
+
[name: string]: unknown;
|
|
9413
|
+
};
|
|
9414
|
+
content?: never;
|
|
9415
|
+
};
|
|
9416
|
+
/** @description Internal server error */
|
|
9417
|
+
500: {
|
|
9418
|
+
headers: {
|
|
9419
|
+
[name: string]: unknown;
|
|
9420
|
+
};
|
|
9421
|
+
content?: never;
|
|
9422
|
+
};
|
|
9423
|
+
/** @description Bad gateway */
|
|
9424
|
+
502: {
|
|
9425
|
+
headers: {
|
|
9426
|
+
[name: string]: unknown;
|
|
9427
|
+
};
|
|
9428
|
+
content?: never;
|
|
9429
|
+
};
|
|
9430
|
+
/** @description Service unavailable */
|
|
9431
|
+
503: {
|
|
9432
|
+
headers: {
|
|
9433
|
+
[name: string]: unknown;
|
|
9434
|
+
};
|
|
9435
|
+
content?: never;
|
|
9436
|
+
};
|
|
9437
|
+
/** @description Gateway timeout */
|
|
9438
|
+
504: {
|
|
9439
|
+
headers: {
|
|
9440
|
+
[name: string]: unknown;
|
|
9441
|
+
};
|
|
9442
|
+
content?: never;
|
|
9443
|
+
};
|
|
9444
|
+
};
|
|
9445
|
+
};
|
|
9267
9446
|
"spectator-tft-v5.getCurrentGameInfoByPuuid": {
|
|
9268
9447
|
parameters: {
|
|
9269
9448
|
query?: never;
|
|
@@ -13299,14 +13478,25 @@ type Paths = keyof paths;
|
|
|
13299
13478
|
type TemplatifyPath<Path extends string> = Path extends `${infer Start}/{${string}}${infer End}` ? `${Start}/${string}${TemplatifyPath<End>}` : Path;
|
|
13300
13479
|
/** Every possible API path, but templatified */
|
|
13301
13480
|
type TemplatePaths = TemplatifyPath<Paths>;
|
|
13481
|
+
/** Splits a Path by `/` into an array */
|
|
13482
|
+
type SplitPath<Path extends string> = Path extends `${infer Head}/${infer Tail}` ? [Head, ...SplitPath<Tail>] : [Path];
|
|
13483
|
+
/**
|
|
13484
|
+
* Compares two splitted paths.
|
|
13485
|
+
*
|
|
13486
|
+
* Type is true if both splitted paths have the same length and every segment of Concrete extends its corresponding segment Template
|
|
13487
|
+
* */
|
|
13488
|
+
type MatchSegments<Template extends string[], Concrete extends string[]> = Template extends [infer TemplateSegment, ...infer TemplateRest] ? Concrete extends [infer ConcreteSegment, ...infer ConcreteRest] ? ConcreteSegment extends TemplateSegment ? TemplateRest extends string[] ? ConcreteRest extends string[] ? MatchSegments<TemplateRest, ConcreteRest> : never : never : false : Concrete extends [] ? Template extends [] ? true : false : false : Template extends [] ? Concrete extends [] ? true : false : false;
|
|
13302
13489
|
/**
|
|
13303
|
-
* Gives all API Paths that matches the
|
|
13490
|
+
* Gives all API Paths that matches the path. Basically the reverse operation of TemplatifyPath
|
|
13304
13491
|
*
|
|
13305
13492
|
* @example ResolveTemplatePath<`/riot/account/v1/accounts/by-puuid/${string}`>
|
|
13306
13493
|
* -> "/riot/account/v1/accounts/by-puuid/{puuid}"
|
|
13494
|
+
*
|
|
13495
|
+
* @example ResolveTemplatePath<`/riot/account/v1/accounts/by-riot-id/gameName/gameTag`>
|
|
13496
|
+
* -> "/riot/account/v1/accounts/by-riot-id/{gameName}/{tagLine}"
|
|
13307
13497
|
*/
|
|
13308
|
-
type ResolveTemplatePath<
|
|
13309
|
-
[P in Paths]:
|
|
13498
|
+
type ResolveTemplatePath<Path extends TemplatePaths> = {
|
|
13499
|
+
[P in Paths]: MatchSegments<SplitPath<TemplatifyPath<P>>, SplitPath<Path>> extends true ? P : never;
|
|
13310
13500
|
}[Paths];
|
|
13311
13501
|
type HTTPMethods = 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace';
|
|
13312
13502
|
/**
|
|
@@ -13321,18 +13511,33 @@ type GetResponses<Path extends Paths, Method extends Methods<Path>> = paths[Path
|
|
|
13321
13511
|
} ? Responses : never;
|
|
13322
13512
|
/** Get the response body for a specific API path, method and status code */
|
|
13323
13513
|
type GetResponseBody<Path extends Paths, Method extends Methods<Path>, StatusCode extends number> = GetResponses<Path, Method> extends Record<StatusCode, {
|
|
13324
|
-
content
|
|
13514
|
+
content?: {
|
|
13325
13515
|
'application/json': infer Body;
|
|
13326
13516
|
};
|
|
13327
13517
|
}> ? Body : never;
|
|
13328
|
-
/** Get the request body for a specific API path and method */
|
|
13329
13518
|
type GetRequestBody<Path extends Paths, Method extends Methods<Path>> = paths[Path][Method] extends {
|
|
13519
|
+
requestBody?: never;
|
|
13520
|
+
} ? {
|
|
13521
|
+
body?: never;
|
|
13522
|
+
} : paths[Path][Method] extends {
|
|
13330
13523
|
requestBody: {
|
|
13331
13524
|
content: {
|
|
13332
|
-
'application/json': infer
|
|
13525
|
+
'application/json': infer U;
|
|
13526
|
+
};
|
|
13527
|
+
};
|
|
13528
|
+
} ? {
|
|
13529
|
+
body: U;
|
|
13530
|
+
} : paths[Path][Method] extends {
|
|
13531
|
+
requestBody?: {
|
|
13532
|
+
content: {
|
|
13533
|
+
'application/json': infer U;
|
|
13333
13534
|
};
|
|
13334
13535
|
};
|
|
13335
|
-
} ?
|
|
13536
|
+
} ? {
|
|
13537
|
+
body?: U;
|
|
13538
|
+
} : unknown;
|
|
13539
|
+
/** Get the query parameters for a specific API path and method */
|
|
13540
|
+
type GetQuery<Path extends Paths, Method extends Methods<Path>> = Pick<paths[Path][Method]['parameters'], 'query'>;
|
|
13336
13541
|
/** Regions for /riot/account/ endpoints */
|
|
13337
13542
|
type AccountRegion = 'americas' | 'asia' | 'europe';
|
|
13338
13543
|
/** Regions for some lol and tft endpoints */
|
|
@@ -13420,7 +13625,6 @@ declare function createRiotFetch<FetchOptions extends BaseFetchOptions & Record<
|
|
|
13420
13625
|
}, ThrowOnError>, defaultOptions?: FetchOptions): <Path extends TemplatePaths, UsableMethods extends Methods<ResolveTemplatePath<Path>>, ChosenMethod extends UsableMethods | undefined = "get" extends UsableMethods ? "get" : UsableMethods>(request: Path, options: FetchOptions & {
|
|
13421
13626
|
region: GetSubdomain<ResolveTemplatePath<Path>>;
|
|
13422
13627
|
method?: UsableMethods;
|
|
13423
|
-
|
|
13424
|
-
}) => Promise<RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, true> | RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, false>>;
|
|
13628
|
+
} & GetRequestBody<ResolveTemplatePath<Path>, Extract<ChosenMethod, HTTPMethods>> & GetQuery<ResolveTemplatePath<Path>, Extract<ChosenMethod, HTTPMethods>>) => Promise<RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, true> | RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, false>>;
|
|
13425
13629
|
|
|
13426
|
-
export { type $defs, type AccountRegion, type CreateRiotFetchOptions, type HTTPMethods, type LolRegion, type LorRegion, type MatchRegion, RiotError, type RiotErrorData, type ValorantRegion, type components, createRiotFetch, type operations, type paths, type webhooks };
|
|
13630
|
+
export { type $defs, type AccountRegion, type BaseFetchOptions, type CreateRiotFetchOptions, type HTTPMethods, type LolRegion, type LorRegion, type MatchRegion, RiotError, type RiotErrorData, type ValorantRegion, type components, createRiotFetch, type operations, type paths, type webhooks };
|
package/dist/index.js
CHANGED
|
@@ -36,8 +36,12 @@ function createRiotFetch({
|
|
|
36
36
|
defaultOptions.headers = headers;
|
|
37
37
|
return async (request, options) => {
|
|
38
38
|
const baseURL = baseUrl(options.region);
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
let req = new URL(request, baseURL).toString();
|
|
40
|
+
if (options.query) {
|
|
41
|
+
const query = Object.entries(options.query).map(([key, value]) => [key, String(value)]);
|
|
42
|
+
req += new URLSearchParams(query).toString();
|
|
43
|
+
}
|
|
44
|
+
const response = await fetchFn(req, {
|
|
41
45
|
...defaultOptions,
|
|
42
46
|
...options,
|
|
43
47
|
body: JSON.stringify(options.body)
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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, HTTPMethods>, 200>,\n\t\t\terror: false,\n\t\t} as RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, false>;\n\t};\n}"],"mappings":";AAwHO,IAAM,YAAN,cAAwB,MAAM;AAAA,EACpC,YAAY,SAAiB,YAAoB,MAAsB;AACtE,UAAM,OAAO;AACb,SAAK,aAAa;AAClB,SAAK,OAAO;AAAA,EACb;AAAA,EACA;AAAA,EACA;AACD;AASA,SAAS,gBAAgB,KAAoC;AAC5D,MAAI,OAAO,QAAQ,YAAY,QAAQ,KAAM,QAAO;AAEpD,QAAM,OAAO;AAEb,MAAI,KAAK,WAAW,QAAW;AAC9B,QAAI,OAAO,KAAK,WAAW,UAAU;AACpC,aAAO;AAAA,IACR;AAEA,QAAI,iBAAiB,KAAK,UAAU,OAAO,KAAK,OAAO,gBAAgB,UAAW;AACjF,aAAO;AAAA,IACR;AAEA,QAAI,aAAa,KAAK,UAAU,OAAO,KAAK,OAAO,YAAY,UAAW;AACzE,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO;AACR;AA6EO,SAAS,gBAIf;AAAA,EACC;AAAA,EACA,UAAU;AAAA,EACV,UAAU,CAAC,WAAmB,WAAW,MAAM;AAAA,EAC/C,uBAAuB;AACxB,GACA,iBAA+B,CAAC,GAC/B;AACD,QAAM,UAAU,IAAI,QAAQ,eAAe,OAAO;AAClD,UAAQ,OAAO,gBAAgB,MAAM;AACrC,UAAQ,OAAO,gBAAgB,kBAAkB;AACjD,iBAAe,UAAU;AAazB,SAAO,OAKN,SACA,YAKI;AACJ,UAAM,UAAU,QAAQ,QAAQ,MAAM;AACtC,UAAM,MAAM,IAAI,IAAI,SAAS,OAAO;AACpC,UAAM,WAAW,MAAM,QAAQ,IAAI,SAAS,GAAG;AAAA,MAC9C,GAAG;AAAA,MACH,GAAG;AAAA,MACH,MAAM,KAAK,UAAU,QAAQ,IAAI;AAAA,IAClC,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AACjB,YAAM,gBAAgB,MAAM,SAAS,KAAK,EACxC,KAAK,SAAO,gBAAgB,GAAG,IAAI,MAAM,MAAS,EAClD,MAAM,MAAM,MAAS;AAGvB,UAAI,sBAAsB;AACzB,cAAM,IAAI;AAAA,UACT;AAAA,UACA,SAAS;AAAA,UACT;AAAA,QACD;AAAA,MACD;AAEA,aAAO;AAAA,QACN;AAAA,QACA,MAAM;AAAA,QACN,OAAO;AAAA,MACR;AAAA,IACD;AAEA,WAAO;AAAA,MACN;AAAA,MACA,MAAM,MAAM,SAAS,KAAK;AAAA,MAC1B,OAAO;AAAA,IACR;AAAA,EACD;AACD;","names":[]}
|
|
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/** Splits a Path by `/` into an array */\ntype SplitPath<Path extends string> = Path extends `${infer Head}/${infer Tail}`\n\t? [Head, ...SplitPath<Tail>]\n\t: [Path];\n\n/**\n * Compares two splitted paths.\n *\n * Type is true if both splitted paths have the same length and every segment of Concrete extends its corresponding segment Template\n * */\ntype MatchSegments<Template extends string[], Concrete extends string[]> =\n Template extends [infer TemplateSegment, ...infer TemplateRest]\n \t? Concrete extends [infer ConcreteSegment, ...infer ConcreteRest]\n \t\t? ConcreteSegment extends TemplateSegment\n \t\t\t? TemplateRest extends string[]\n \t\t\t\t? ConcreteRest extends string[]\n \t\t\t\t\t? MatchSegments<TemplateRest, ConcreteRest>\n \t\t\t\t\t: never\n \t\t\t\t: never\n \t\t\t: false\n \t\t: Concrete extends []\n \t\t\t? Template extends []\n \t\t\t\t? true\n \t\t\t\t: false\n \t\t\t: false\n \t: Template extends []\n \t\t? Concrete extends []\n \t\t\t? true\n \t\t\t: false\n \t\t: false;\n\n/**\n * Gives all API Paths that matches the 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 *\n * @example ResolveTemplatePath<`/riot/account/v1/accounts/by-riot-id/gameName/gameTag`>\n * -> \"/riot/account/v1/accounts/by-riot-id/{gameName}/{tagLine}\"\n */\ntype ResolveTemplatePath<Path extends TemplatePaths> = {\n\t[P in Paths]: MatchSegments<SplitPath<TemplatifyPath<P>>, SplitPath<Path>> extends true ? P : never\n}[Paths];\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\ntype GetRequestBody<Path extends Paths, Method extends Methods<Path>> =\n paths[Path][Method] extends { requestBody?: never }\n \t? { body?: never }\n \t: paths[Path][Method] extends { requestBody: { content: { 'application/json': infer U } } }\n \t\t? { body: U }\n \t\t: paths[Path][Method] extends { requestBody?: { content: { 'application/json': infer U } } }\n \t\t\t? { body?: U }\n \t\t\t: unknown;\n\n\n/** Get the query parameters for a specific API path and method */\ntype GetQuery<Path extends Paths, Method extends Methods<Path>> =\n Pick<paths[Path][Method]['parameters'], 'query'>;\n\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 */\nexport interface 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}\n\t\t\t& GetRequestBody<ResolveTemplatePath<Path>, Extract<ChosenMethod, HTTPMethods>>\n\t\t\t& GetQuery<ResolveTemplatePath<Path>, Extract<ChosenMethod, HTTPMethods>>,\n\t) => {\n\t\tconst baseURL = baseUrl(options.region);\n\t\tlet req = new URL(request, baseURL).toString();\n\t\tif (options.query) {\n\t\t\tconst query = Object.entries(options.query).map(([key, value]) => [key, String(value)]);\n\t\t\treq += new URLSearchParams(query).toString();\n\t\t}\n\n\t\tconst response = await fetchFn(req, {\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, HTTPMethods>, 200>,\n\t\t\terror: false,\n\t\t} as RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, false>;\n\t};\n}"],"mappings":";AAmKO,IAAM,YAAN,cAAwB,MAAM;AAAA,EACpC,YAAY,SAAiB,YAAoB,MAAsB;AACtE,UAAM,OAAO;AACb,SAAK,aAAa;AAClB,SAAK,OAAO;AAAA,EACb;AAAA,EACA;AAAA,EACA;AACD;AASA,SAAS,gBAAgB,KAAoC;AAC5D,MAAI,OAAO,QAAQ,YAAY,QAAQ,KAAM,QAAO;AAEpD,QAAM,OAAO;AAEb,MAAI,KAAK,WAAW,QAAW;AAC9B,QAAI,OAAO,KAAK,WAAW,UAAU;AACpC,aAAO;AAAA,IACR;AAEA,QAAI,iBAAiB,KAAK,UAAU,OAAO,KAAK,OAAO,gBAAgB,UAAW;AACjF,aAAO;AAAA,IACR;AAEA,QAAI,aAAa,KAAK,UAAU,OAAO,KAAK,OAAO,YAAY,UAAW;AACzE,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO;AACR;AA6EO,SAAS,gBAIf;AAAA,EACC;AAAA,EACA,UAAU;AAAA,EACV,UAAU,CAAC,WAAmB,WAAW,MAAM;AAAA,EAC/C,uBAAuB;AACxB,GACA,iBAA+B,CAAC,GAC/B;AACD,QAAM,UAAU,IAAI,QAAQ,eAAe,OAAO;AAClD,UAAQ,OAAO,gBAAgB,MAAM;AACrC,UAAQ,OAAO,gBAAgB,kBAAkB;AACjD,iBAAe,UAAU;AAazB,SAAO,OAKN,SACA,YAMI;AACJ,UAAM,UAAU,QAAQ,QAAQ,MAAM;AACtC,QAAI,MAAM,IAAI,IAAI,SAAS,OAAO,EAAE,SAAS;AAC7C,QAAI,QAAQ,OAAO;AAClB,YAAM,QAAQ,OAAO,QAAQ,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,OAAO,KAAK,CAAC,CAAC;AACtF,aAAO,IAAI,gBAAgB,KAAK,EAAE,SAAS;AAAA,IAC5C;AAEA,UAAM,WAAW,MAAM,QAAQ,KAAK;AAAA,MACnC,GAAG;AAAA,MACH,GAAG;AAAA,MACH,MAAM,KAAK,UAAU,QAAQ,IAAI;AAAA,IAClC,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AACjB,YAAM,gBAAgB,MAAM,SAAS,KAAK,EACxC,KAAK,SAAO,gBAAgB,GAAG,IAAI,MAAM,MAAS,EAClD,MAAM,MAAM,MAAS;AAGvB,UAAI,sBAAsB;AACzB,cAAM,IAAI;AAAA,UACT;AAAA,UACA,SAAS;AAAA,UACT;AAAA,QACD;AAAA,MACD;AAEA,aAAO;AAAA,QACN;AAAA,QACA,MAAM;AAAA,QACN,OAAO;AAAA,MACR;AAAA,IACD;AAEA,WAAO;AAAA,MACN;AAAA,MACA,MAAM,MAAM,SAAS,KAAK;AAAA,MAC1B,OAAO;AAAA,IACR;AAAA,EACD;AACD;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "riotapi-fetch-typed",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0-dev",
|
|
5
5
|
"description": "Fetch the Riot Games API with type safety, thanks to the OpenAPI specification.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -18,21 +18,20 @@
|
|
|
18
18
|
"author": "TournamentStats",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@eslint/js": "^9.
|
|
21
|
+
"@eslint/js": "^9.34.0",
|
|
22
22
|
"@stylistic/eslint-plugin": "^5.2.3",
|
|
23
23
|
"@types/node": "^24.3.0",
|
|
24
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "^8.41.0",
|
|
25
25
|
"@vitest/coverage-v8": "3.2.4",
|
|
26
26
|
"dotenv": "^17.2.1",
|
|
27
|
-
"eslint": "^9.
|
|
27
|
+
"eslint": "^9.34.0",
|
|
28
28
|
"jiti": "^2.5.1",
|
|
29
29
|
"ofetch": "^1.4.1",
|
|
30
30
|
"openapi-typescript": "^7.9.1",
|
|
31
31
|
"tsup": "^8.5.0",
|
|
32
|
-
"tsx": "^4.20.
|
|
33
|
-
"type-fest": "^4.41.0",
|
|
32
|
+
"tsx": "^4.20.5",
|
|
34
33
|
"typescript": "^5.9.2",
|
|
35
|
-
"typescript-eslint": "^8.
|
|
34
|
+
"typescript-eslint": "^8.41.0",
|
|
36
35
|
"vitest": "^3.2.4"
|
|
37
36
|
},
|
|
38
37
|
"files": [
|