lunar-js
Fully typed, zero-dependency TypeScript client for the Lunar API: install, quick start, configuration, and authentication.
lunar-js
lunar-js is a fully typed, dependency-free TypeScript client for the Lunar API.
- Zero runtime dependencies — built on the native
fetch(Node.js 18+). - Fully typed — every request and response shape is described in TypeScript.
- Ergonomic — top-level shortcuts (
client.fox()) plus structured resources (client.auth,client.admin,client.images). - Safe — request timeouts, a single
LunarAPIErrortype, and client-side guards against malformed image paths.
Install
npm install lunar-jsQuick start
import Client from 'lunar-js';
const client = new Client('Bearer your-token'); // the "Bearer " prefix is optional
const fox = await client.fox(); // -> RandomImage
console.log(fox.url);The constructor also accepts an options object:
const client = new Client({
token: 'your-token',
baseURL: 'https://api.lunargroup.dev', // default
timeoutMs: 15_000, // default
});Authentication
register and login are public. By default the returned accessToken is stored on the client, so subsequent authenticated calls just work:
const client = new Client();
await client.auth.login({ username: 'winter_fe', password: 'super-secret' });
const users = await client.admin.users(); // uses the stored token- Set or replace the token at any time with
client.setToken(token). - Check
client.authenticatedto see whether one is set. - Pass
{ store: false }tologin/registerto leave the current token untouched.
Licensed under AGPL-3.0.