Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API client library and storage providers #42

Open
samuelthomas2774 opened this issue Dec 19, 2022 · 0 comments
Open

API client library and storage providers #42

samuelthomas2774 opened this issue Dec 19, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@samuelthomas2774
Copy link
Owner

samuelthomas2774 commented Dec 19, 2022

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
  • 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 788083b. The API will change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant