UNPKG

@qualiture/tesla-api

Version:

An unofficial library that wraps the Tesla Owner's API

52 lines (51 loc) 2.14 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const node_util_1 = __importDefault(require("node:util")); const axios_1 = __importDefault(require("axios")); const constants_1 = require("./constants"); class Vehicle { /** * Returns an array of vehicles for the current owner. * The owner is determined by the bearer token provided inside the `config` object * @param config * @returns An array of vehicles for the current owner */ static getOwnerVehicles(config) { return new Promise((resolve, reject) => { axios_1.default.get(constants_1.Constants.PRODUCT.ENDPOINT, config) .then((response) => { const data = response.data; const vehicles = data.response.filter((product) => !!product); resolve(vehicles); }).catch((err) => { reject(err.response?.data); }); }); } /** * Returns all vehicle data and vehicle configuration * @param vehicleId `id` of the vehicle (NB: This is *not* `vehicle_id`) * @param config * @returns A rollup of all vehicle data plus configuration */ static getVehicleData(vehicleId, config, includeLocationData) { return new Promise((resolve, reject) => { let parameters = constants_1.Constants.VEHICLE_DATA.DEFAULT_PARAMETERS; if (includeLocationData) { parameters += constants_1.Constants.VEHICLE_DATA.LOCATION_DATA_PARAMETER; } const vehicleDataEndpoint = node_util_1.default.format(constants_1.Constants.VEHICLE_DATA.ENDPOINT, vehicleId, parameters); axios_1.default.get(vehicleDataEndpoint, config) .then((response) => { const data = response.data; resolve(data.response); }).catch((err) => { reject(err.response?.data); }); }); } } exports.default = Vehicle;