@vulog/aima-vehicle 1.2.29 → 1.2.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +252 -0
- package/dist/index.d.cts +273 -0
- package/dist/index.d.mts +211 -218
- package/dist/index.mjs +201 -261
- package/package.json +20 -7
- package/src/createVehicle.test.ts +88 -0
- package/src/createVehicle.ts +49 -0
- package/src/getModelVehicles.test.ts +4 -4
- package/src/index.ts +1 -0
- package/{tsup.config.ts → tsdown.config.ts} +1 -1
- package/dist/index.d.ts +0 -280
- package/dist/index.js +0 -324
- /package/{.eslintrc.js → .eslintrc.cjs} +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { Vehicle } from './types';
|
|
5
|
+
|
|
6
|
+
export type CreateVehicleBody = {
|
|
7
|
+
vin: string;
|
|
8
|
+
plate: string;
|
|
9
|
+
name: string;
|
|
10
|
+
model: { id: number };
|
|
11
|
+
vuboxId?: string;
|
|
12
|
+
externalId?: string;
|
|
13
|
+
wakeupProvider?: string;
|
|
14
|
+
noBox?: boolean;
|
|
15
|
+
published?: boolean;
|
|
16
|
+
archived?: boolean;
|
|
17
|
+
msisdn?: string;
|
|
18
|
+
iccid?: string;
|
|
19
|
+
imsi?: string;
|
|
20
|
+
residualValue?: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const createVehicleBodySchema = z.object({
|
|
24
|
+
vin: z.string().trim().min(1).max(20),
|
|
25
|
+
plate: z.string().trim().min(1).max(16),
|
|
26
|
+
name: z.string().trim().min(1).max(64),
|
|
27
|
+
model: z.object({ id: z.number().int().positive() }),
|
|
28
|
+
vuboxId: z.string().optional(),
|
|
29
|
+
externalId: z.string().max(32).optional(),
|
|
30
|
+
wakeupProvider: z.string().max(16).optional(),
|
|
31
|
+
noBox: z.boolean().optional(),
|
|
32
|
+
published: z.boolean().optional(),
|
|
33
|
+
archived: z.boolean().optional(),
|
|
34
|
+
msisdn: z.string().max(32).optional(),
|
|
35
|
+
iccid: z.string().max(32).optional(),
|
|
36
|
+
imsi: z.string().max(32).optional(),
|
|
37
|
+
residualValue: z.number().optional(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const createVehicle = async (client: Client, body: CreateVehicleBody): Promise<Vehicle> => {
|
|
41
|
+
const result = createVehicleBodySchema.safeParse(body);
|
|
42
|
+
if (!result.success) {
|
|
43
|
+
throw new TypeError('Invalid args', { cause: result.error.issues });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return client
|
|
47
|
+
.post<Vehicle>(`/boapi/proxy/vehicle/fleets/${client.clientOptions.fleetId}/vehicles`, result.data)
|
|
48
|
+
.then(({ data }) => data);
|
|
49
|
+
};
|
|
@@ -61,7 +61,7 @@ describe('getModelVehicles', () => {
|
|
|
61
61
|
const calledUrl = getMock.mock.calls[0][0];
|
|
62
62
|
const url = new URL(calledUrl, 'http://example.com');
|
|
63
63
|
expect(url.searchParams.get('page')).toBe('0');
|
|
64
|
-
expect(url.searchParams.get('
|
|
64
|
+
expect(url.searchParams.get('size')).toBe('100');
|
|
65
65
|
// sort is not provided in default options, so it should not be in URL
|
|
66
66
|
expect(url.searchParams.get('sort')).toBe(null);
|
|
67
67
|
});
|
|
@@ -108,7 +108,7 @@ describe('getModelVehicles', () => {
|
|
|
108
108
|
const calledUrl = getMock.mock.calls[0][0];
|
|
109
109
|
const url = new URL(calledUrl, 'http://example.com');
|
|
110
110
|
expect(url.searchParams.get('page')).toBe('1');
|
|
111
|
-
expect(url.searchParams.get('
|
|
111
|
+
expect(url.searchParams.get('size')).toBe('50');
|
|
112
112
|
expect(url.searchParams.get('sort')).toBe('modelId,DESC');
|
|
113
113
|
});
|
|
114
114
|
|
|
@@ -138,8 +138,8 @@ describe('getModelVehicles', () => {
|
|
|
138
138
|
|
|
139
139
|
const calledUrl = getMock.mock.calls[0][0];
|
|
140
140
|
const url = new URL(calledUrl, 'http://example.com');
|
|
141
|
-
// Should only have page and
|
|
142
|
-
expect(url.searchParams.toString()).toBe('page=0&
|
|
141
|
+
// Should only have page and size parameters since sort and filters are not provided
|
|
142
|
+
expect(url.searchParams.toString()).toBe('page=0&size=100');
|
|
143
143
|
});
|
|
144
144
|
|
|
145
145
|
test('should throw error for invalid page number', async () => {
|
package/src/index.ts
CHANGED
package/dist/index.d.ts
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import { Client } from '@vulog/aima-client';
|
|
2
|
-
import { PaginableOptions, PaginableResponse } from '@vulog/aima-core';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Represents a vehicle model with its specifications and characteristics
|
|
6
|
-
*/
|
|
7
|
-
type Model = {
|
|
8
|
-
/** Unique identifier of the model */
|
|
9
|
-
id: number;
|
|
10
|
-
/** Name of the model (e.g., "C-Zero") */
|
|
11
|
-
name: string;
|
|
12
|
-
/** Type of energy used by the vehicle (e.g., "ELECTRIC") */
|
|
13
|
-
energyType: string;
|
|
14
|
-
/** Current status of the model (e.g., "ACTIVE") */
|
|
15
|
-
status: string;
|
|
16
|
-
/** Number of seats in the vehicle */
|
|
17
|
-
nbOfSeats: number;
|
|
18
|
-
/** Maximum range/autonomy of the vehicle in kilometers */
|
|
19
|
-
autonomy: number;
|
|
20
|
-
/** Date when the model was created */
|
|
21
|
-
creationDate: string;
|
|
22
|
-
/** Date when the model was last updated */
|
|
23
|
-
updateDate: string;
|
|
24
|
-
/** Description of the model (e.g., brand name) */
|
|
25
|
-
description: string;
|
|
26
|
-
/** ID of the fleet this model belongs to */
|
|
27
|
-
fleetId: string;
|
|
28
|
-
/** Type of vehicle (e.g., "CAR") */
|
|
29
|
-
vehicleType: string;
|
|
30
|
-
/** Type of transmission (e.g., "UNDEFINED") */
|
|
31
|
-
transmission: string;
|
|
32
|
-
/** Range threshold for out of service status */
|
|
33
|
-
outOfServiceRange: string;
|
|
34
|
-
/** Range threshold for recovery */
|
|
35
|
-
recoveryRange: string;
|
|
36
|
-
/** Array of incentive thresholds */
|
|
37
|
-
incentiveThresholds: any[];
|
|
38
|
-
/** Range threshold for vehicle redistribution */
|
|
39
|
-
redistributeVehicleChargedEnoughRange: string;
|
|
40
|
-
/** Indicates if the odometer readings are reliable */
|
|
41
|
-
odometerReliable?: boolean;
|
|
42
|
-
[key: string]: any;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Represents a vehicle in the system
|
|
46
|
-
*/
|
|
47
|
-
type Vehicle = {
|
|
48
|
-
/** Unique identifier of the vehicle */
|
|
49
|
-
id: string;
|
|
50
|
-
/** Name of the vehicle */
|
|
51
|
-
name: string;
|
|
52
|
-
/** License plate number */
|
|
53
|
-
plate: string;
|
|
54
|
-
/** Vehicle Identification Number */
|
|
55
|
-
vin: string;
|
|
56
|
-
/** Model information of the vehicle */
|
|
57
|
-
model: Model;
|
|
58
|
-
/** List of options/features installed on the vehicle */
|
|
59
|
-
options: Options[];
|
|
60
|
-
/** Date when the vehicle was created */
|
|
61
|
-
createDate: string;
|
|
62
|
-
/** Date when the vehicle was last updated */
|
|
63
|
-
updateDate: string;
|
|
64
|
-
/** ID of the fleet this vehicle belongs to */
|
|
65
|
-
fleetId: string;
|
|
66
|
-
/** External system identifier */
|
|
67
|
-
externalId: string;
|
|
68
|
-
/** Provider used for vehicle wakeup */
|
|
69
|
-
wakeupProvider?: string;
|
|
70
|
-
/** Mobile Subscriber Integrated Services Digital Network Number */
|
|
71
|
-
msisdn: string;
|
|
72
|
-
/** Integrated Circuit Card Identifier */
|
|
73
|
-
iccid: string;
|
|
74
|
-
/** International Mobile Subscriber Identity */
|
|
75
|
-
imsi?: string;
|
|
76
|
-
/** Whether the vehicle is published in the system */
|
|
77
|
-
published: boolean;
|
|
78
|
-
/** Whether the vehicle has no box installed */
|
|
79
|
-
noBox: boolean;
|
|
80
|
-
/** Whether the vehicle is archived */
|
|
81
|
-
archived: boolean;
|
|
82
|
-
[key: string]: any;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Represents a vehicle option or feature
|
|
86
|
-
*/
|
|
87
|
-
type Options = {
|
|
88
|
-
/** Unique identifier of the option */
|
|
89
|
-
id: number;
|
|
90
|
-
/** ID of the fleet this option belongs to */
|
|
91
|
-
fleetId: string;
|
|
92
|
-
/** Name of the option */
|
|
93
|
-
name: string;
|
|
94
|
-
/** Type of the option (e.g., "Color", "Gearbox") */
|
|
95
|
-
type: string;
|
|
96
|
-
/** Description of the option */
|
|
97
|
-
description: string;
|
|
98
|
-
[key: string]: any;
|
|
99
|
-
};
|
|
100
|
-
type Zone = {
|
|
101
|
-
type: string;
|
|
102
|
-
version: number;
|
|
103
|
-
zoneId: string;
|
|
104
|
-
sticky: boolean;
|
|
105
|
-
labels: {
|
|
106
|
-
labelId: string;
|
|
107
|
-
name: string;
|
|
108
|
-
publicName: string;
|
|
109
|
-
}[];
|
|
110
|
-
};
|
|
111
|
-
type VehicleRealTime = {
|
|
112
|
-
id: string;
|
|
113
|
-
name: string;
|
|
114
|
-
plate: string;
|
|
115
|
-
vin: string;
|
|
116
|
-
fleetid: string;
|
|
117
|
-
currentFleetId: string;
|
|
118
|
-
ownerFleetId: string;
|
|
119
|
-
boxid: string;
|
|
120
|
-
vehicle_status: number;
|
|
121
|
-
zones: Zone[];
|
|
122
|
-
releasable: boolean;
|
|
123
|
-
box_status: number;
|
|
124
|
-
autonomy: number;
|
|
125
|
-
autonomy2: number;
|
|
126
|
-
isCharging: boolean;
|
|
127
|
-
battery: number;
|
|
128
|
-
km: number;
|
|
129
|
-
speed: number;
|
|
130
|
-
location: {
|
|
131
|
-
geohash: string;
|
|
132
|
-
cap: number;
|
|
133
|
-
latitude: number;
|
|
134
|
-
longitude: number;
|
|
135
|
-
gpsDate: string;
|
|
136
|
-
lastMovingDate: string;
|
|
137
|
-
};
|
|
138
|
-
endTripLocation: {
|
|
139
|
-
latitude: number;
|
|
140
|
-
longitude: number;
|
|
141
|
-
};
|
|
142
|
-
endZoneIds: [];
|
|
143
|
-
productIds: [];
|
|
144
|
-
isDoorClosed: boolean;
|
|
145
|
-
isDoorLocked: boolean;
|
|
146
|
-
engineOn: boolean;
|
|
147
|
-
immobilizerOn: boolean;
|
|
148
|
-
secureOn: boolean;
|
|
149
|
-
spareLockOn: boolean | null;
|
|
150
|
-
pileLockOn: boolean | null;
|
|
151
|
-
helmetPresent: boolean | null;
|
|
152
|
-
helmet2Present: boolean | null;
|
|
153
|
-
helmetBoxLockOn: boolean | null;
|
|
154
|
-
helmet2LockOn: boolean | null;
|
|
155
|
-
userId: string | null;
|
|
156
|
-
user_locale: string | null;
|
|
157
|
-
rfid: string | null;
|
|
158
|
-
orderId: string | null;
|
|
159
|
-
gatewayUrl: string | null;
|
|
160
|
-
booking_status: number;
|
|
161
|
-
booking_date: string | null;
|
|
162
|
-
expiresOn: boolean | null;
|
|
163
|
-
last_active_date: string;
|
|
164
|
-
last_wakeUp_date: string;
|
|
165
|
-
version: string;
|
|
166
|
-
pricingId: string | null;
|
|
167
|
-
start_date: string | null;
|
|
168
|
-
theorStartDate: string | null;
|
|
169
|
-
theorEndDate: string | null;
|
|
170
|
-
startZones: Zone[];
|
|
171
|
-
endZones: Zone[];
|
|
172
|
-
disabled: boolean;
|
|
173
|
-
outOfServiceReason: string;
|
|
174
|
-
ignitionOffGeohash: string | null;
|
|
175
|
-
geohashNeighbours: string[];
|
|
176
|
-
cleanlinessStatus: boolean;
|
|
177
|
-
needsRedistribution: boolean;
|
|
178
|
-
batteryUnderThreshold: boolean;
|
|
179
|
-
isBeingTowed: boolean;
|
|
180
|
-
automaticallyEnableVehicleAfterRangeRecovery: boolean;
|
|
181
|
-
key: {
|
|
182
|
-
deviceName: string;
|
|
183
|
-
};
|
|
184
|
-
doNotTrack: boolean;
|
|
185
|
-
energyLevel: number;
|
|
186
|
-
lastOosDate: string;
|
|
187
|
-
hasAlerts: boolean;
|
|
188
|
-
firmwareModel: string;
|
|
189
|
-
comeFromApp: string;
|
|
190
|
-
doors: {
|
|
191
|
-
frontLeftClosed: boolean;
|
|
192
|
-
frontRightClosed: boolean;
|
|
193
|
-
rearLeftClosed: boolean;
|
|
194
|
-
rearRightClosed: boolean;
|
|
195
|
-
trunkClosed: boolean;
|
|
196
|
-
hoodClosed: boolean;
|
|
197
|
-
};
|
|
198
|
-
windows: {
|
|
199
|
-
frontLeftClosed: boolean;
|
|
200
|
-
frontRightClosed: boolean;
|
|
201
|
-
rearLeftClosed: boolean;
|
|
202
|
-
rearRightClosed: boolean;
|
|
203
|
-
trunkClosed: boolean;
|
|
204
|
-
};
|
|
205
|
-
doorsAndWindowsClosed: boolean;
|
|
206
|
-
vpChecksum: string;
|
|
207
|
-
firmwareBuildDate: string;
|
|
208
|
-
[key: string]: any;
|
|
209
|
-
};
|
|
210
|
-
type Assets = {
|
|
211
|
-
fleet_id: string;
|
|
212
|
-
model_id: number;
|
|
213
|
-
assets: {
|
|
214
|
-
aid: string;
|
|
215
|
-
type: string;
|
|
216
|
-
url: string | null;
|
|
217
|
-
value: number | null;
|
|
218
|
-
b_value: boolean | null;
|
|
219
|
-
text: string | null;
|
|
220
|
-
[key: string]: any;
|
|
221
|
-
}[];
|
|
222
|
-
[key: string]: any;
|
|
223
|
-
};
|
|
224
|
-
type ModelVehicle = {
|
|
225
|
-
serviceId: string;
|
|
226
|
-
serviceVisibility: 'PUBLIC' | 'PRIVATE';
|
|
227
|
-
modelId: number;
|
|
228
|
-
vehicles: string[];
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
declare const getModelsById: (client: Client, id: number) => Promise<Model>;
|
|
232
|
-
|
|
233
|
-
declare const getModelByIdAssets: (client: Client, id: number) => Promise<Assets>;
|
|
234
|
-
|
|
235
|
-
declare const getModels: (client: Client) => Promise<Model[]>;
|
|
236
|
-
|
|
237
|
-
declare const getVehicleById: (client: Client, id: string) => Promise<Vehicle | null>;
|
|
238
|
-
declare const getVehicleRealTimeById: (client: Client, id: string) => Promise<VehicleRealTime | null>;
|
|
239
|
-
|
|
240
|
-
declare const getVehicleByIdAssets: (client: Client, id: string) => Promise<Assets>;
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Fetches all vehicles from the API using pagination
|
|
244
|
-
* @param client - The AIMA client instance
|
|
245
|
-
* @param pageSize - Number of vehicles per page (default: 500)
|
|
246
|
-
* @returns Promise that resolves to an array of all vehicles
|
|
247
|
-
* @throws Error if more than 50 pages are required to fetch all vehicles
|
|
248
|
-
*/
|
|
249
|
-
declare const getVehicles: (client: Client, pageSize?: number) => Promise<Vehicle[]>;
|
|
250
|
-
/**
|
|
251
|
-
* Fetches all real-time vehicle data from the API using pagination
|
|
252
|
-
* @param client - The AIMA client instance
|
|
253
|
-
* @param pageSize - Number of vehicles per page (default: 500)
|
|
254
|
-
* @param lastUpdatedMillis - Optional timestamp in UTC milliseconds. If provided, only vehicles updated after this timestamp will be returned.
|
|
255
|
-
* @returns Promise that resolves to an array of all real-time vehicle data
|
|
256
|
-
* @throws Error if more than 50 pages are required to fetch all vehicles
|
|
257
|
-
* @throws Error if lastUpdatedMillis is in the future
|
|
258
|
-
*/
|
|
259
|
-
declare const getVehiclesRealTime: (client: Client, pageSize?: number, lastUpdatedMillis?: number) => Promise<VehicleRealTime[]>;
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Pings a vehicle to check if it is alive (box connected).
|
|
263
|
-
* Returns true if alive (HTTP 200), false if box not connected (code 410, codeStr 'carConnectionProblem'),
|
|
264
|
-
* throws for other errors or invalid id.
|
|
265
|
-
*/
|
|
266
|
-
declare const pingVehicleById: (client: Client, id: string) => Promise<boolean>;
|
|
267
|
-
|
|
268
|
-
type EnableVehicleBody = {
|
|
269
|
-
subStatus: string;
|
|
270
|
-
};
|
|
271
|
-
declare const enableVehicle: (client: Client, vehicleId: string, payload: EnableVehicleBody) => Promise<void>;
|
|
272
|
-
|
|
273
|
-
type DisableVehicleBody = {
|
|
274
|
-
subStatus: string;
|
|
275
|
-
};
|
|
276
|
-
declare const disableVehicle: (client: Client, vehicleId: string, payload: DisableVehicleBody) => Promise<void>;
|
|
277
|
-
|
|
278
|
-
declare const getModelVehicles: (client: Client, options?: PaginableOptions) => Promise<PaginableResponse<ModelVehicle>>;
|
|
279
|
-
|
|
280
|
-
export { type Assets, type DisableVehicleBody, type EnableVehicleBody, type Model, type ModelVehicle, type Options, type Vehicle, type VehicleRealTime, type Zone, disableVehicle, enableVehicle, getModelByIdAssets, getModelVehicles, getModels, getModelsById, getVehicleById, getVehicleByIdAssets, getVehicleRealTimeById, getVehicles, getVehiclesRealTime, pingVehicleById };
|
package/dist/index.js
DELETED
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
disableVehicle: () => disableVehicle,
|
|
34
|
-
enableVehicle: () => enableVehicle,
|
|
35
|
-
getModelByIdAssets: () => getModelByIdAssets,
|
|
36
|
-
getModelVehicles: () => getModelVehicles,
|
|
37
|
-
getModels: () => getModels,
|
|
38
|
-
getModelsById: () => getModelsById,
|
|
39
|
-
getVehicleById: () => getVehicleById,
|
|
40
|
-
getVehicleByIdAssets: () => getVehicleByIdAssets,
|
|
41
|
-
getVehicleRealTimeById: () => getVehicleRealTimeById,
|
|
42
|
-
getVehicles: () => getVehicles,
|
|
43
|
-
getVehiclesRealTime: () => getVehiclesRealTime,
|
|
44
|
-
pingVehicleById: () => pingVehicleById
|
|
45
|
-
});
|
|
46
|
-
module.exports = __toCommonJS(index_exports);
|
|
47
|
-
|
|
48
|
-
// src/getModel.ts
|
|
49
|
-
var getModelsById = async (client, id) => {
|
|
50
|
-
return client.get(`boapi/proxy/user/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/models/${id}`).then(({ data }) => data);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// src/getModelAssets.ts
|
|
54
|
-
var import_zod = require("zod");
|
|
55
|
-
var schema = import_zod.z.object({
|
|
56
|
-
id: import_zod.z.number().int().positive()
|
|
57
|
-
});
|
|
58
|
-
var getModelByIdAssets = async (client, id) => {
|
|
59
|
-
const result = schema.safeParse({ id });
|
|
60
|
-
if (!result.success) {
|
|
61
|
-
throw new TypeError("Invalid args", {
|
|
62
|
-
cause: result.error.issues
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
return client.get(`boapi/proxy/eds/rest_pub/rest/fleets/${client.clientOptions.fleetId}/models/${id}/`).then(({ data }) => data);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// src/getModels.ts
|
|
69
|
-
var getModels = async (client) => {
|
|
70
|
-
return client.get(`boapi/proxy/user/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/models`).then(({ data }) => data);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// src/getVehicle.ts
|
|
74
|
-
var import_zod2 = require("zod");
|
|
75
|
-
var schema2 = import_zod2.z.object({
|
|
76
|
-
id: import_zod2.z.string().trim().min(1).uuid()
|
|
77
|
-
});
|
|
78
|
-
var getVehicleById = async (client, id) => {
|
|
79
|
-
const result = schema2.safeParse({ id });
|
|
80
|
-
if (!result.success) {
|
|
81
|
-
throw new TypeError("Invalid args", {
|
|
82
|
-
cause: result.error.issues
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return client.get(`boapi/proxy/user/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.id}`).then(({ data }) => data).catch((error) => {
|
|
86
|
-
if (error.formattedError?.status === 404) {
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
throw error;
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
var getVehicleRealTimeById = async (client, id) => {
|
|
93
|
-
const result = schema2.safeParse({ id });
|
|
94
|
-
if (!result.success) {
|
|
95
|
-
throw new TypeError("Invalid args", {
|
|
96
|
-
cause: result.error.issues
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
return client.get(
|
|
100
|
-
`boapi/proxy/fleetmanager/public/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.id}`
|
|
101
|
-
).then(({ data }) => data).catch((error) => {
|
|
102
|
-
if (error.formattedError?.status === 404) {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
throw error;
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// src/getVehicleAssets.ts
|
|
110
|
-
var import_zod3 = require("zod");
|
|
111
|
-
var schema3 = import_zod3.z.object({
|
|
112
|
-
id: import_zod3.z.string().uuid()
|
|
113
|
-
});
|
|
114
|
-
var getVehicleByIdAssets = async (client, id) => {
|
|
115
|
-
const result = schema3.safeParse({ id });
|
|
116
|
-
if (!result.success) {
|
|
117
|
-
throw new TypeError("Invalid args", {
|
|
118
|
-
cause: result.error.issues
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
return client.get(`boapi/proxy/eds/rest_pub/rest/fleets/${client.clientOptions.fleetId}/vehicles/${id}/`).then(({ data }) => data);
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
// src/getVehicles.ts
|
|
125
|
-
var import_zod4 = require("zod");
|
|
126
|
-
var getVehiclesPage = async (client, page, pageSize) => {
|
|
127
|
-
const response = await client.get(
|
|
128
|
-
`boapi/proxy/user/vehicle/fleets/${client.clientOptions.fleetId}/vehicles?page=${page}&size=${pageSize}`
|
|
129
|
-
);
|
|
130
|
-
return response.data;
|
|
131
|
-
};
|
|
132
|
-
var getVehicles = async (client, pageSize = 500) => {
|
|
133
|
-
const schema7 = import_zod4.z.object({
|
|
134
|
-
pageSize: import_zod4.z.number().min(1).default(500)
|
|
135
|
-
});
|
|
136
|
-
const result = schema7.safeParse({ pageSize });
|
|
137
|
-
if (!result.success) {
|
|
138
|
-
throw new TypeError("Invalid args", {
|
|
139
|
-
cause: result.error.issues
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
const allVehicles = [];
|
|
143
|
-
let currentPage = 0;
|
|
144
|
-
let hasMorePages = true;
|
|
145
|
-
const MAX_PAGES = 50;
|
|
146
|
-
while (hasMorePages) {
|
|
147
|
-
if (currentPage >= MAX_PAGES) {
|
|
148
|
-
throw new Error(
|
|
149
|
-
`Maximum page limit (${MAX_PAGES}) reached. This might indicate an issue with the pagination or a very large dataset.`
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
const vehicles = await getVehiclesPage(client, currentPage, result.data.pageSize);
|
|
153
|
-
allVehicles.push(...vehicles);
|
|
154
|
-
hasMorePages = vehicles.length === result.data.pageSize;
|
|
155
|
-
currentPage += 1;
|
|
156
|
-
}
|
|
157
|
-
return allVehicles;
|
|
158
|
-
};
|
|
159
|
-
var getVehiclesRealTimePage = async (client, page, pageSize, lastUpdatedMillis) => {
|
|
160
|
-
const queryParams = new URLSearchParams({
|
|
161
|
-
page: page.toString(),
|
|
162
|
-
size: pageSize.toString()
|
|
163
|
-
});
|
|
164
|
-
if (lastUpdatedMillis !== void 0) {
|
|
165
|
-
queryParams.append("lastUpdatedMillis", lastUpdatedMillis.toString());
|
|
166
|
-
}
|
|
167
|
-
const response = await client.get(
|
|
168
|
-
`boapi/proxy/fleetmanager/public/fleets/${client.clientOptions.fleetId}/vehicles?${queryParams.toString()}`
|
|
169
|
-
);
|
|
170
|
-
return response.data;
|
|
171
|
-
};
|
|
172
|
-
var getVehiclesRealTime = async (client, pageSize = 500, lastUpdatedMillis) => {
|
|
173
|
-
const schema7 = import_zod4.z.object({
|
|
174
|
-
pageSize: import_zod4.z.number().min(1).default(500),
|
|
175
|
-
lastUpdatedMillis: import_zod4.z.number().positive().optional()
|
|
176
|
-
});
|
|
177
|
-
const result = schema7.safeParse({ pageSize, lastUpdatedMillis });
|
|
178
|
-
if (!result.success) {
|
|
179
|
-
throw new TypeError("Invalid args", {
|
|
180
|
-
cause: result.error.issues
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
const allVehicles = [];
|
|
184
|
-
let currentPage = 0;
|
|
185
|
-
let hasMorePages = true;
|
|
186
|
-
const MAX_PAGES = 50;
|
|
187
|
-
if (lastUpdatedMillis !== void 0) {
|
|
188
|
-
const now = Date.now();
|
|
189
|
-
if (lastUpdatedMillis > now) {
|
|
190
|
-
throw new Error("lastUpdatedMillis must be in the past");
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
while (hasMorePages) {
|
|
194
|
-
if (currentPage >= MAX_PAGES) {
|
|
195
|
-
throw new Error(
|
|
196
|
-
`Maximum page limit (${MAX_PAGES}) reached. This might indicate an issue with the pagination or a very large dataset.`
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
const vehicles = await getVehiclesRealTimePage(
|
|
200
|
-
client,
|
|
201
|
-
currentPage,
|
|
202
|
-
result.data.pageSize,
|
|
203
|
-
result.data.lastUpdatedMillis
|
|
204
|
-
);
|
|
205
|
-
allVehicles.push(...vehicles);
|
|
206
|
-
hasMorePages = vehicles.length === result.data.pageSize;
|
|
207
|
-
currentPage += 1;
|
|
208
|
-
}
|
|
209
|
-
return allVehicles;
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
// src/pingVehicle.ts
|
|
213
|
-
var import_zod5 = require("zod");
|
|
214
|
-
var schema4 = import_zod5.z.object({
|
|
215
|
-
id: import_zod5.z.string().trim().min(1).uuid()
|
|
216
|
-
});
|
|
217
|
-
var pingVehicleById = async (client, id) => {
|
|
218
|
-
const result = schema4.safeParse({ id });
|
|
219
|
-
if (!result.success) {
|
|
220
|
-
throw new TypeError("Invalid args", {
|
|
221
|
-
cause: result.error.issues
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
try {
|
|
225
|
-
await client.get(
|
|
226
|
-
`boapi/proxy/fleetmanager/public/v2/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.id}/ping`
|
|
227
|
-
);
|
|
228
|
-
return true;
|
|
229
|
-
} catch (error) {
|
|
230
|
-
if (error?.response?.data?.codeStr === "carConnectionProblem" && error?.response?.data?.code === 410) {
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
throw error;
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
// src/enableVehicle.ts
|
|
238
|
-
var import_zod6 = __toESM(require("zod"));
|
|
239
|
-
var schema5 = import_zod6.default.object({
|
|
240
|
-
subStatus: import_zod6.default.string()
|
|
241
|
-
});
|
|
242
|
-
var enableVehicle = async (client, vehicleId, payload) => {
|
|
243
|
-
const result = schema5.safeParse(payload);
|
|
244
|
-
if (!result.success) {
|
|
245
|
-
throw new TypeError("Invalid args", {
|
|
246
|
-
cause: result.error.issues
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
return client.post(
|
|
250
|
-
`boapi/proxy/fleetmanager/public/fleets/${client.clientOptions.fleetId}/vehicles/${vehicleId}/enable`,
|
|
251
|
-
payload
|
|
252
|
-
).then(({ data }) => data);
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
// src/disableVehicle.ts
|
|
256
|
-
var import_zod7 = __toESM(require("zod"));
|
|
257
|
-
var schema6 = import_zod7.default.object({
|
|
258
|
-
subStatus: import_zod7.default.string()
|
|
259
|
-
});
|
|
260
|
-
var disableVehicle = async (client, vehicleId, payload) => {
|
|
261
|
-
const result = schema6.safeParse(payload);
|
|
262
|
-
if (!result.success) {
|
|
263
|
-
throw new TypeError("Invalid args", {
|
|
264
|
-
cause: result.error.issues
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
return client.post(
|
|
268
|
-
`boapi/proxy/fleetmanager/public/fleets/${client.clientOptions.fleetId}/vehicles/${vehicleId}/disable`,
|
|
269
|
-
payload
|
|
270
|
-
).then(({ data }) => data);
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
// src/getModelVehicles.ts
|
|
274
|
-
var import_aima_core = require("@vulog/aima-core");
|
|
275
|
-
var getModelVehicles = async (client, options) => {
|
|
276
|
-
const PaginableOptionsSchema = (0, import_aima_core.createPaginableOptionsSchema)().default({});
|
|
277
|
-
const resultOptions = PaginableOptionsSchema.safeParse(options);
|
|
278
|
-
if (!resultOptions.success) {
|
|
279
|
-
throw new TypeError("Invalid options", {
|
|
280
|
-
cause: resultOptions.error.issues
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
const finalOptions = resultOptions.data;
|
|
284
|
-
const searchParams = new URLSearchParams();
|
|
285
|
-
searchParams.append("page", finalOptions.page.toString());
|
|
286
|
-
searchParams.append("size", finalOptions.pageSize.toString());
|
|
287
|
-
if (finalOptions.sort) {
|
|
288
|
-
searchParams.append("sort", `${finalOptions.sort.toString()},${finalOptions.sortDirection.toString()}`);
|
|
289
|
-
}
|
|
290
|
-
if (finalOptions.filters) {
|
|
291
|
-
Object.entries(finalOptions.filters).forEach(([key, value]) => {
|
|
292
|
-
if (value === void 0) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
searchParams.append(key, value);
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
const basePath = `boapi/proxy/user/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/models/modelvehicles`;
|
|
299
|
-
const urlWithParams = `${basePath}?${searchParams.toString()}`;
|
|
300
|
-
return client.get(urlWithParams).then(({ data, headers }) => {
|
|
301
|
-
return {
|
|
302
|
-
data,
|
|
303
|
-
page: headers.number,
|
|
304
|
-
pageSize: headers.size,
|
|
305
|
-
total: headers.totalelements,
|
|
306
|
-
totalPages: headers.totalpages
|
|
307
|
-
};
|
|
308
|
-
});
|
|
309
|
-
};
|
|
310
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
311
|
-
0 && (module.exports = {
|
|
312
|
-
disableVehicle,
|
|
313
|
-
enableVehicle,
|
|
314
|
-
getModelByIdAssets,
|
|
315
|
-
getModelVehicles,
|
|
316
|
-
getModels,
|
|
317
|
-
getModelsById,
|
|
318
|
-
getVehicleById,
|
|
319
|
-
getVehicleByIdAssets,
|
|
320
|
-
getVehicleRealTimeById,
|
|
321
|
-
getVehicles,
|
|
322
|
-
getVehiclesRealTime,
|
|
323
|
-
pingVehicleById
|
|
324
|
-
});
|
|
File without changes
|