1declare module "smartcar" {
2 // Auth Client Configuration
3 interface AuthClientConfig {
4 clientId: string;
5 clientSecret: string;
6 redirectUri: string;
7 mode?: "live" | "test";
8 development?: boolean;
9 }
10
11 // Token Response
12 interface TokenResponse {
13 accessToken: string;
14 refreshToken: string;
15 expiresIn: number;
16 tokenType: string;
17 scope: string[];
18 refreshExpiresIn?: number;
19 }
20
21 // Vehicle Options
22 interface VehicleOptions {
23 unitSystem?: "metric" | "imperial";
24 version?: string;
25 flags?: Record<string, string | boolean>;
26 }
27
28 // Vehicle Attributes Response
29 interface VehicleAttributes {
30 id: string;
31 make: string;
32 model: string;
33 year: number;
34 vin?: string;
35 color?: string;
36 fuel?: {
37 type: string;
38 capacity: number;
39 remaining: number;
40 unit: string;
41 };
42 }
43
44 // VIN Response
45 interface VIN {
46 vin: string;
47 }
48
49 // Diagnostic System Status Response
50 interface DiagnosticSystemStatus {
51 status: string;
52 }
53
54 // Diagnostic Trouble Codes Response
55 interface DiagnosticTroubleCodes {
56 codes: Array<{
57 code: string;
58 description: string;
59 severity: string;
60 }>;
61 }
62
63 // Service History Response
64 interface ServiceHistory {
65 records: Array<{
66 id: string;
67 date: string;
68 mileage: number;
69 description: string;
70 cost?: number;
71 }>;
72 }
73
74 // Lock Status Response
75 interface LockStatus {
76 status: string;
77 }
78
79 // Odometer Response
80 interface Odometer {
81 distance: number;
82 unit: string;
83 }
84
85 // Location Response
86 interface Location {
87 latitude: number;
88 longitude: number;
89 bearing?: number;
90 speed?: number;
91 accuracy?: number;
92 }
93
94 // Charge Response (for EVs)
95 interface Charge {
96 percentage: number;
97 isPluggedIn: boolean;
98 range?: number;
99 timeRemaining?: number;
100 chargingState?: string;
101 }
102
103 // Battery Response (for EVs)
104 interface Battery {
105 range: number;
106 percentage: number;
107 }
108
109 // Engine Oil Response
110 interface EngineOil {
111 lifeRemaining: number;
112 unit: string;
113 }
114
115 // Tire Pressure Response
116 interface TirePressure {
117 frontLeft: number;
118 frontRight: number;
119 backLeft: number;
120 backRight: number;
121 unit: string;
122 }
123
124 // Fuel Tank Response
125 interface FuelTank {
126 range: number;
127 percentRemaining: number;
128 amountRemaining: number;
129 unit: string;
130 }
131
132 // Auth Client Class
133 export class AuthClient {
134 constructor(config: AuthClientConfig);
135
136 getAuthUrl(
137 scopes: string[],
138 options?: {
139 state?: string;
140 makeBypass?: string;
141 forcePrompt?: boolean;
142 singleSelect?: {
143 vin: string;
144 };
145 }
146 ): string;
147
148 exchangeCode(
149 code: string,
150 options?: {
151 forcePrompt?: boolean;
152 }
153 ): Promise<TokenResponse>;
154
155 exchangeRefreshToken(refreshToken: string): Promise<TokenResponse>;
156
157 getVehicles(accessToken: string): Promise<{
158 vehicles: Array<{
159 id: string;
160 make: string;
161 model: string;
162 year: number;
163 }>;
164 paging?: {
165 count: number;
166 offset: number;
167 };
168 }>;
169 }
170
171 // Vehicle Class
172 export class Vehicle {
173 constructor(id: string, accessToken: string, options?: VehicleOptions);
174
175 // Vehicle Information
176 attributes(): Promise<VehicleAttributes>;
177 vin(): Promise<VIN>;
178 permissions(): Promise<{
179 permissions: string[];
180 }>;
181
182 // Vehicle Data
183 odometer(): Promise<Odometer>;
184 location(): Promise<Location>;
185
186 // EV-specific methods
187 charge(): Promise<Charge>;
188 battery(): Promise<Battery>;
189 batteryCapacity(): Promise<{ capacity: number; unit: string }>;
190 nominalCapacity(): Promise<{ capacity: number; unit: string }>;
191
192 // ICE-specific methods
193 engineOil(): Promise<EngineOil>;
194 fuel(): Promise<FuelTank>;
195
196 // Other vehicle data
197 tirePressure(): Promise<TirePressure>;
198
199 // Vehicle Actions (if supported)
200 lock(): Promise<{ status: string }>;
201 unlock(): Promise<{ status: string }>;
202 lockStatus(): Promise<LockStatus>;
203 startCharge(): Promise<{ status: string }>;
204 stopCharge(): Promise<{ status: string }>;
205
206 // Navigation
207 sendDestination(destination: {
208 latitude: number;
209 longitude: number;
210 }): Promise<{ status: string }>;
211
212 // Service and Diagnostics
213 serviceHistory(): Promise<ServiceHistory>;
214 diagnosticSystemStatus(): Promise<DiagnosticSystemStatus>;
215 diagnosticTroubleCodes(): Promise<DiagnosticTroubleCodes>;
216
217 // Utility methods
218 disconnect(): Promise<{
219 status: string;
220 }>;
221 }
222
223 // Static utility functions
224 export function getVehicles(accessToken: string): Promise<{
225 vehicles: Array<{
226 id: string;
227 make: string;
228 model: string;
229 year: number;
230 }>;
231 paging?: {
232 count: number;
233 offset: number;
234 };
235 }>;
236
237 export function getCompatibility(
238 vin: string,
239 scope: string[],
240 options?: {
241 country?: string;
242 }
243 ): Promise<{
244 compatible: boolean;
245 reason?: string;
246 capabilities?: string[];
247 permissions?: string[];
248 }>;
249
250 // Error classes
251 export class SmartcarError extends Error {
252 type: string;
253 statusCode: number;
254 requestId?: string;
255 vehicleId?: string;
256 }
257
258 export class ValidationError extends SmartcarError {}
259 export class AuthenticationError extends SmartcarError {}
260 export class PermissionError extends SmartcarError {}
261 export class RateLimitError extends SmartcarError {}
262 export class MonthlyLimitError extends SmartcarError {}
263 export class ServerError extends SmartcarError {}
264 export class VehicleStateError extends SmartcarError {}
265}