nxapi
nxapi copied to clipboard
API client library and storage providers
Add complete wrappers for the API clients, similar to the CoralUser
class used internally:
- Automatically handle caching data
- Automatically handle expiring the API client if not used for the normal duration of the access token
- Automatically handle recreating the API client if remote configuration data changes when the token is renewed
- #43
- Automatically handle sending additional requests to appear like the official app
- Use a storage provider to automatically handle getting/updating cached tokens
Storage providers
Add a storage provider interface implemented by JS library dependents for token management with API client wrappers.
Make a default storage provider that uses a separate directory for each user and use that with the app/cli. (Users can then be removed just by deleting that directory.)
Example
import { addUserAgent, LocalStorageProvider, Storage } from 'nxapi';
import { CoralUser } from 'nxapi/coral';
addUserAgent('my-project/1.0.0 (+https://github.com/...)');
const storage = await Storage.create(LocalStorageProvider, new URL('../data', import.meta.url));
const coral = await CoralUser.create(storage, 'naid');
// Get friends list
// If updated in the last 30s the cached data is returned
const friends = await coral.getFriends();
https://github.com/samuelthomas2774/splatoon3-replay-lookup is using the client added in https://github.com/samuelthomas2774/nxapi/commit/788083b7f6b714f15ab321e0b0b05a0677ae7238. The API will change.