riotapi-fetch-typed 1.0.3-dev → 1.0.4-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.
@@ -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/**\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 */\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\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":[]}
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.ChallengeInfo"][];
1991
- preferences: components["schemas"]["lol-challenges-v1.PlayerClientPreferences"];
1992
- totalPoints: components["schemas"]["lol-challenges-v1.ChallengePoints"];
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.ChallengePoints"];
2014
+ [key: string]: components["schemas"]["lol-challenges-v1.ChallengePointDto"];
1995
2015
  };
1996
2016
  };
1997
- /** ChallengeInfo */
1998
- "lol-challenges-v1.ChallengeInfo": {
1999
- /** Format: int64 */
2000
- challengeId: number;
2017
+ /** ChallengeInfoDto */
2018
+ "lol-challenges-v1.ChallengeInfoDto": {
2001
2019
  /** Format: double */
2002
2020
  percentile: number;
2003
- level: string;
2004
- /** Format: double */
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
- /** PlayerClientPreferences */
2014
- "lol-challenges-v1.PlayerClientPreferences": {
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
- /** ChallengePoints */
2023
- "lol-challenges-v1.ChallengePoints": {
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;
@@ -13423,4 +13602,4 @@ declare function createRiotFetch<FetchOptions extends BaseFetchOptions & Record<
13423
13602
  body?: GetRequestBody<ResolveTemplatePath<Path>, Extract<ChosenMethod, HTTPMethods>>;
13424
13603
  }) => Promise<RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, true> | RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, false>>;
13425
13604
 
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 };
13605
+ 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.ChallengeInfo"][];
1991
- preferences: components["schemas"]["lol-challenges-v1.PlayerClientPreferences"];
1992
- totalPoints: components["schemas"]["lol-challenges-v1.ChallengePoints"];
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.ChallengePoints"];
2014
+ [key: string]: components["schemas"]["lol-challenges-v1.ChallengePointDto"];
1995
2015
  };
1996
2016
  };
1997
- /** ChallengeInfo */
1998
- "lol-challenges-v1.ChallengeInfo": {
1999
- /** Format: int64 */
2000
- challengeId: number;
2017
+ /** ChallengeInfoDto */
2018
+ "lol-challenges-v1.ChallengeInfoDto": {
2001
2019
  /** Format: double */
2002
2020
  percentile: number;
2003
- level: string;
2004
- /** Format: double */
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
- /** PlayerClientPreferences */
2014
- "lol-challenges-v1.PlayerClientPreferences": {
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
- /** ChallengePoints */
2023
- "lol-challenges-v1.ChallengePoints": {
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;
@@ -13423,4 +13602,4 @@ declare function createRiotFetch<FetchOptions extends BaseFetchOptions & Record<
13423
13602
  body?: GetRequestBody<ResolveTemplatePath<Path>, Extract<ChosenMethod, HTTPMethods>>;
13424
13603
  }) => Promise<RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, true> | RiotFetchReturn<Path, Extract<ChosenMethod, HTTPMethods>, ThrowOnError, false>>;
13425
13604
 
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 };
13605
+ 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.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/**\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 */\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\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":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "riotapi-fetch-typed",
3
3
  "type": "module",
4
- "version": "1.0.3-dev",
4
+ "version": "1.0.4-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",