The official JavaScript and TypeScript SDK for the Fleetbase API.
Fleetbase SDK provides typed resources, stores, API actions, browser and Node.js transports, and extension points for custom adapters. Version 2 keeps the established v1 consumer API while providing correct ESM, CommonJS, TypeScript, and browser builds.
# npm
npm install @fleetbase/sdk
# pnpm
pnpm add @fleetbase/sdk
# Yarn
yarn add @fleetbase/sdk
# Bun
bun add @fleetbase/sdkThe SDK supports Node.js 20.19.4 and newer at runtime, including legacy Node 20 consumers. Use Node 22/24 for maintained deployments; building this repository requires Node 22.13 or newer. Its browser transport uses the standard Fetch API, so it works without framework-specific dependencies in modern browser applications and bundlers.
import Fleetbase from '@fleetbase/sdk';
const fleetbase = new Fleetbase('your_public_key');
const place = await fleetbase.places.create({
name: 'Space Needle',
street1: '400 Broad Street',
city: 'Seattle',
state: 'WA',
country: 'US',
});
console.log(place.id);The same root API is available to CommonJS consumers:
const { default: Fleetbase } = require('@fleetbase/sdk');
const fleetbase = new Fleetbase('your_server_key');Never expose a Fleetbase secret key in browser code. Browser applications must use a public key. Keep server credentials in environment variables or a secret manager.
The client exposes stores for frequently used API resources:
const order = await fleetbase.orders.findRecord('order_123');
const places = await fleetbase.places.query({ city: 'Seattle' });
const driver = await fleetbase.drivers.findRecord('driver_123');
const quotes = await fleetbase.serviceQuotes.fromPreliminary({
pickup: 'place_pickup',
dropoff: 'place_dropoff',
});Driver-app stores cover the FleetOps driver workflow — manifests, manifestStops, trailers, fuelReports, issues, and workOrders — alongside the driver-scoped helpers on existing stores:
const manifests = await fleetbase.drivers.manifests('driver_123', { status: 'active' });
const manifest = await fleetbase.manifests.optimize('manifest_123', { latitude: 1.29, longitude: 103.85 });
await fleetbase.manifestStops.update('manifest_stop_123', { status: 'arrived' }); // PATCH
await fleetbase.trailers.attach('trailer_123', { vehicle: 'vehicle_123' });
const trailers = await fleetbase.vehicles.trailers('vehicle_123');
await fleetbase.drivers.changePassword('driver_123', { password: 'current', new_password: 'next', new_password_confirmation: 'next' });Inspection stores and vehicle inspection actions are deferred until a released Fleet-Ops driver inspection API can be verified. Trailer attach returns a raw connection; detach and work-order send return acknowledgements without replacing the resource's attributes.
Resource instances can also be created directly:
import { Place, Point } from '@fleetbase/sdk';
const place = new Place({
name: 'Warehouse',
location: new Point(47.6062, -122.3321),
});The root package exports the existing resource classes, adapters, collection helpers, resolver and registry hooks, string helpers, validation utilities, and TypeScript request/configuration types.
Implement the stable adapter interface when requests need to use an application-specific transport:
import { Adapter } from '@fleetbase/sdk';
class CustomAdapter extends Adapter {
get(path, query, options) {
return customRequest('GET', path, { query, ...options });
}
post(path, data, options) {
return customRequest('POST', path, { data, ...options });
}
put(path, data, options) {
return customRequest('PUT', path, { data, ...options });
}
patch(path, data, options) {
return customRequest('PATCH', path, { data, ...options });
}
delete(path, options) {
return customRequest('DELETE', path, options);
}
}
const fleetbase = new Fleetbase('your_key', {
adapter: new CustomAdapter(),
});Calling fleetbase.setAdapter(adapter) updates the client and all existing stores.
Transport failures reject with FleetbaseError, which remains a normal JavaScript Error and adds safe structured details when available:
import { FleetbaseError } from '@fleetbase/sdk';
try {
await fleetbase.orders.findRecord('missing');
} catch (error) {
if (error instanceof FleetbaseError) {
console.error(error.status, error.code, error.requestId);
}
}The npm package contains:
- native ESM with declarations and source maps;
- true CommonJS (
.cjs) with CommonJS declarations; - a minified browser bundle at
dist/fleetbase.min.js; - no runtime dependencies.
Every release candidate is checked with Publint, Are The Types Wrong, packed-tarball content and size assertions, ESM/CommonJS export parity, strict TypeScript, cross-platform smoke tests, and 100% statement, branch, function, and line coverage.
Production-build fixtures verify the exact candidate tarball with Vite, webpack, esbuild, React, Vue, Svelte, Angular, Ember, Next.js (client and server), Nuxt (client and server), Expo web/React Native Android, and an edge-runtime VM. Chromium, Firefox, and WebKit gates also execute SDK construction, Fetch transport, resource serialization, authorization headers, and browser-only key validation. See the compatibility policy for the release-blocking matrix.
pnpm install --frozen-lockfile
pnpm run verifyPull-request tests are deterministic and do not need Fleetbase credentials. API behavior is cross-checked against the official Postman collections, Core API, and Fleet-Ops sources.
Maintainers can also run the secret-gated Live API integration workflow. It installs the exact packed SDK candidate and performs a read-only current-organization request using the FLEETBASE_PUBLIC_KEY repository secret; scheduled runs skip cleanly until that secret is configured, while manually dispatched runs fail clearly when it is absent.
See the release guide for publishing and the contribution guide for the development workflow.