JavaScript SDK

The Mojave JavaScript SDK is the easiest way to interact with the Mojave API using Node.js, frontend apps, or serverless environments. It wraps all core endpoints and handles authentication, error handling, and pagination out of the box.

Installation

Install via npm or yarn:

bashCopyEditnpm install @mojave/sdk
# or
yarn add @mojave/sdk

Getting Started

Import and initialize the SDK with your API token:

import { Mojave } from '@mojave/sdk';

const mojave = new Mojave({
  token: 'YOUR_API_TOKEN' // Use env vars in production!
});

Basic Usage

Get current user

const me = await mojave.users.getMe();
console.log(me.name); // → Grace Hopper

Create a project

const project = await mojave.projects.create({
  name: 'Landing Page Revamp',
  client_id: 'cli_abc123',
  rate: 100,
});

Log time

await mojave.timeEntries.create({
  project_id: 'prj_xyz456',
  start_time: '2025-04-10T09:00:00Z',
  end_time: '2025-04-10T11:00:00Z',
  notes: 'Design meeting with team',
});

Last invoices

const invoices = await mojave.invoices.list();
console.log(invoices.length); // → 5

API Coverage

Resource

Supported Methods

Users

getMe()list()update()

Projects

list()get()create()update()

Tasks

list()create()update()

Time Entries

list()create()update()delete()

Invoices

list()create()send()markAsPaid()

Clients

list()create()update()

💡 All methods return promises and use async/await.

Error Handling

The SDK throws structured errors:

try {
  await mojave.projects.get('invalid_id');
} catch (err) {
  console.error(err.status); // 404
  console.error(err.message); // "Project not found"
}

Pagination

All list methods return paginated results with built-in support:

jsCopyEditconst { data, nextPage } = await mojave.timeEntries.list({ limit: 20 });

Use nextPage() to fetch the next page automatically.

Environment Support

Environment

Supported

Node.js

Browser (SPA)

✅ (with caution – avoid exposing tokens)

Serverless

React Native

Best Practices

  • Always use environment variables to store API tokens

  • Don’t expose tokens in public browser apps

  • Catch and log errors from API calls

  • Use .env and dotenv in local dev

Was this helpful?

Was this helpful?

Was this helpful?

Table of content

Table of content

Table of content

JavaScrip SDK

JavaScrip SDK