vibrant-oauth2-client
v1.0.1
Published
Vibrant Wellness OAuth2 client for Node.js
Maintainers
Readme
vibrant-oauth2-client
OAuth2 client credentials client for the Vibrant Wellness API. Handles token acquisition, caching, and automatic refresh.
Features
- Client Credentials grant flow against
https://api.vibrant-wellness.com/v1/oauth2/token - Automatic caching — tokens are reused until they expire (with a 60-second safety buffer)
- Request deduplication — concurrent
getToken()calls share a single in-flight request - Dual format — ships both CommonJS and ESM builds with full TypeScript declarations
Requirements
- Node.js >= 18.0.0
Installation
npm install vibrant-oauth2-clientConfiguration
Set the following environment variables before instantiating the client:
| Variable | Description |
| ---------------------- | ---------------------------------- |
| VIBRANT_CLIENT_ID | Your OAuth2 client ID |
| VIBRANT_CLIENT_SECRET| Your OAuth2 client secret |
Usage
import { VibrantClient } from "vibrant-oauth2-client";
const client = new VibrantClient();
// Returns a cached token or fetches a new one automatically.
// The returned string includes the token type prefix (e.g. "Bearer <token>").
const token = await client.getToken();
// Use the token in downstream requests:
const response = await fetch("https://api.vibrant-wellness.com/v1/some-endpoint", {
headers: { Authorization: token },
});
// Force a fresh token on next call:
client.clearCache();API
new VibrantClient()
Creates a new client. Reads VIBRANT_CLIENT_ID and VIBRANT_CLIENT_SECRET from the environment. Throws if either is missing.
client.getToken(): Promise<string>
Returns a valid access token string (prefixed with the token type, e.g. Bearer ...). Automatically fetches a new token when the cached one is expired or about to expire.
client.clearCache(): void
Clears the cached token so the next getToken() call fetches a fresh one.
Exported Types
interface TokenResponse {
access_token: string;
token_type: string;
expires_in: number;
scope?: string;
}
interface CachedToken {
accessToken: string;
expiresAt: Date;
}Development
# Install dependencies
npm install
# Build (CJS + ESM + type declarations)
npm run buildLicense
MIT
