Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@vulog/aima-vehicle

slecoustre1.5kMIT1.1.81TypeScript support: included

Vehicle management module for AIMA platform.

AIMA, VULOG, VEHICLE

readme

@vulog/aima-vehicle

Vehicle management module for AIMA platform.

Installation

npm i @vulog/aima-client @vulog/aima-core @vulog/aima-vehicle

Usage

Initialize Client

import { getClient } from '@vulog/aima-client';
import { getVehicles, getModelById, getModels, getVehicleById, getVehiclesRealTime } from '@vulog/aima-vehicle';

const client = getClient({
    apiKey: '...',
    baseUrl: '...',
    clientId: '...',
    clientSecret: '...',
    fleetId: '...',
});

Get All Vehicles

Fetches all vehicles with pagination (default page size: 500). The implementation uses an internal getVehiclesPage function to fetch individual pages of vehicles.

// Get all vehicles
const vehicles = await getVehicles(client);

// Get all vehicles with custom page size
const vehicles = await getVehicles(client, 1000);

The getVehicles function automatically handles pagination and will fetch all available vehicles up to a maximum of 50 pages. If you need to fetch a specific page of vehicles, you can use the internal getVehiclesPage function:

// Get a specific page of vehicles
const vehiclesPage = await getVehiclesPage(client, 0, 100); // First page, 100 vehicles per page

Note: getVehiclesPage is an internal function and is not exported from the package. It's used internally by getVehicles to handle the pagination logic.

Get Vehicle by ID

Fetches a specific vehicle by its ID.

const vehicle = await getVehicleById(client, 'dcb0c41e-4be3-11ea-83a5-024d0cba6da4');

Get All Models

Fetches all vehicle models.

const models = await getModels(client);

Get Model by ID

Fetches a specific model by its ID.

const model = await getModelById(client, 372);

Get Real-Time Vehicle Data

Fetches real-time data for all vehicles with pagination (default page size: 500). The implementation uses an internal getVehiclesRealTimePage function to fetch individual pages of real-time vehicle data.

// Get real-time data for all vehicles
const realTimeVehicles = await getVehiclesRealTime(client);

// Get real-time data with custom page size
const realTimeVehicles = await getVehiclesRealTime(client, 1000);

// Get only vehicles updated after a specific timestamp (in UTC milliseconds)
const lastSyncTime = Date.now() - 24 * 60 * 60 * 1000; // 24 hours ago
const updatedVehicles = await getVehiclesRealTime(client, 500, lastSyncTime);

The getVehiclesRealTime function automatically handles pagination and will fetch all available vehicles up to a maximum of 50 pages. If you need to fetch a specific page of real-time vehicle data, you can use the internal getVehiclesRealTimePage function:

// Get a specific page of real-time vehicle data
const realTimeVehiclesPage = await getVehiclesRealTimePage(client, 0, 100); // First page, 100 vehicles per page

// Get a specific page with lastUpdatedMillis filter
const updatedVehiclesPage = await getVehiclesRealTimePage(client, 0, 100, lastSyncTime);

Note: getVehiclesRealTimePage is an internal function and is not exported from the package. It's used internally by getVehiclesRealTime to handle the pagination logic.

Types

Vehicle

interface Vehicle {
    id: string;
    name: string;
    plate: string;
    vin: string;
    model: Model;
    options: Options[];
    createDate: string;
    updateDate: string;
    fleetId: string;
    externalId: string;
    wakeupProvider?: string;
    msisdn: string;
    iccid: string;
    imsi?: string;
    published: boolean;
    noBox: boolean;
    archived: boolean;
}

Model

interface Model {
    id: number;
    name: string;
    energyType: string;
    status: string;
    nbOfSeats: number;
    autonomy: number;
    creationDate: string;
    updateDate: string;
    description: string;
    fleetId: string;
    vehicleType: string;
    transmission: string;
    outOfServiceRange: string;
    recoveryRange: string;
    incentiveThresholds: any[];
    redistributeVehicleChargedEnoughRange: string;
    odometerReliable?: boolean;
}

Options

interface Options {
    id: number;
    fleetId: string;
    name: string;
    type: string;
    description: string;
}

VehicleRealTime

interface VehicleRealTime {
    id: string;
    name: string;
    plate: string;
    vin: string;
    fleetid: string;
    boxid: string;
    vehicle_status: number;
    zones: Zone[];
    releasable: boolean;
    box_status: number;
    autonomy: number;
    autonomy2: number;
    isCharging: boolean;
    battery: number;
    km: number;
    speed: number;
    location: {
        geohash: string;
        cap: number;
        latitude: number;
        longitude: number;
        gpsDate: string;
        lastMovingDate: string;
    };
    endTripLocation: {
        latitude: number;
        longitude: number;
    };
    endZoneIds: [];
    productIds: [];
    isDoorClosed: boolean;
    isDoorLocked: boolean;
    engineOn: boolean;
    immobilizerOn: boolean;
    secureOn: boolean;
    spareLockOn: boolean | null;
    pileLockOn: boolean | null;
    helmetPresent: boolean | null;
    helmet2Present: boolean | null;
    helmetBoxLockOn: boolean | null;
    helmet2LockOn: boolean | null;
    userId: string | null;
    user_locale: string | null;
    rfid: string | null;
    orderId: string | null;
    gatewayUrl: string | null;
    booking_status: number;
    booking_date: string | null;
    expiresOn: boolean | null;
    last_active_date: string;
    last_wakeUp_date: string;
    version: string;
    pricingId: string | null;
    start_date: string | null;
    theorStartDate: string | null;
    theorEndDate: string | null;
    startZones: Zone[];
    endZones: Zone[];
    disabled: boolean;
    outOfServiceReason: string;
    ignitionOffGeohash: string | null;
    geohashNeighbours: string[];
    cleanlinessStatus: boolean;
    needsRedistribution: boolean;
    batteryUnderThreshold: boolean;
    isBeingTowed: boolean;
    automaticallyEnableVehicleAfterRangeRecovery: boolean;
    key: {
        deviceName: string;
    };
    doNotTrack: boolean;
    energyLevel: number;
    lastOosDate: string;
    hasAlerts: boolean;
    firmwareModel: string;
    comeFromApp: string;
    doors: {
        frontLeftClosed: boolean;
        frontRightClosed: boolean;
        rearLeftClosed: boolean;
        rearRightClosed: boolean;
        trunkClosed: boolean;
        hoodClosed: boolean;
    };
    windows: {
        frontLeftClosed: boolean;
        frontRightClosed: boolean;
        rearLeftClosed: boolean;
        rearRightClosed: boolean;
        trunkClosed: boolean;
    };
    doorsAndWindowsClosed: boolean;
    vpChecksum: string;
    firmwareBuildDate: string;
}