@tqman/valorant-api-types
v0.8.1
Published
A collection of documented endpoints and return types for the unofficial Valorant API
Downloads
18
Maintainers
Readme
Valorant API Types
This is a collection of documented endpoints and return types for the unofficial Valorant API.
In the future, this project could include types for the websocket events and xmpp events.
Types may be incomplete or incorrect, please open an issue if you find any problems.
Note
This is my personal fork of valorant-api-types directory from valorant-api-docs
Installation
Install with npm install valorant-api-types
if using the endpoint data or npm install valorant-api-types --save-dev
if just using the types.
Usage
Using just the raw return types:
import {PresenceResponse} from 'valorant-api-types'
async function getPresenceRaw(): Promise<PresenceResponse> {
return (await fetch('...')).json()
}
Internally, valorant-api-types uses zod to document and transform return data. If you install zod as a dev dependency, the following code is equivalent to the above code and adds no runtime overhead:
import {presenceEndpoint} from 'valorant-api-types'
import {z} from 'zod'
async function getPresenceRaw(): Promise<z.input<typeof presenceEndpoint.responses['200']>> {
return (await fetch('...')).json()
}
The zod types can be used to parse and transform the raw data into a more usable format:
import {presenceEndpoint} from 'valorant-api-types'
import {z} from 'zod'
// presences[0].private -> base64-encoded json string
type PresenceResponseRaw = z.input<typeof presenceEndpoint.responses['200']>
// presences[0].private -> {sessionLoopState: string, customGameName: string, ...}
type PresenceResponseProcessed = z.output<typeof presenceEndpoint.responses['200']>
async function getPresence(): Promise<PresenceResponseProcessed > {
const returnData = await (await fetch('...')).json()
return presenceEndpoint.responses['200'].parse(returnData)
}
The list of endpoints is exported and can be used to make your own docs or tools:
import {endpoints} from 'valorant-api-types'
for(const endpoint of Object.values(endpoints)) {
console.log(`${endpoint.name} - ${endpoint.description}`)
}
Most text data can be markdown including the description and Zod type descriptions.
Linking to other endpoints is done with [{method} {name}]
(for example, [POST Auth Cookies]
)
which can be replaced with an appropriate link.