@vulog/aima-vehicle 1.2.32 → 1.2.34
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/README.md +89 -0
- package/dist/index.cjs +29 -5
- package/dist/index.d.cts +8 -1
- package/dist/index.d.mts +8 -1
- package/dist/index.mjs +27 -6
- package/package.json +3 -3
- package/src/getOptions.ts +9 -0
- package/src/index.ts +2 -0
- package/src/vehicleOption.ts +40 -0
package/README.md
CHANGED
|
@@ -98,6 +98,95 @@ const updatedVehiclesPage = await getVehiclesRealTimePage(client, 0, 100, lastSy
|
|
|
98
98
|
|
|
99
99
|
Note: `getVehiclesRealTimePage` is an internal function and is not exported from the package. It's used internally by `getVehiclesRealTime` to handle the pagination logic.
|
|
100
100
|
|
|
101
|
+
### Create a Vehicle
|
|
102
|
+
|
|
103
|
+
Creates a new vehicle in the fleet.
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
import { createVehicle } from '@vulog/aima-vehicle';
|
|
107
|
+
|
|
108
|
+
const vehicle = await createVehicle(client, {
|
|
109
|
+
vin: '1HGBH41JXMN109186',
|
|
110
|
+
plate: 'AB-123-CD',
|
|
111
|
+
name: 'My Vehicle',
|
|
112
|
+
model: { id: 372 },
|
|
113
|
+
// optional fields
|
|
114
|
+
vuboxId: 'vubox-123',
|
|
115
|
+
externalId: 'ext-123',
|
|
116
|
+
noBox: false,
|
|
117
|
+
published: true,
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Get Options
|
|
122
|
+
|
|
123
|
+
Fetches all vehicle options available in the fleet.
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
import { getOptions } from '@vulog/aima-vehicle';
|
|
127
|
+
|
|
128
|
+
const options = await getOptions(client);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Add / Remove Option for Vehicle
|
|
132
|
+
|
|
133
|
+
Add or remove an option to/from a vehicle.
|
|
134
|
+
|
|
135
|
+
```javascript
|
|
136
|
+
import { addOptionForVehicle, removeOptionForVehicle } from '@vulog/aima-vehicle';
|
|
137
|
+
|
|
138
|
+
const vehicle = await addOptionForVehicle(client, 'vehicle-uuid', 25);
|
|
139
|
+
const vehicle = await removeOptionForVehicle(client, 'vehicle-uuid', 25);
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Add / Remove Service for Vehicle
|
|
143
|
+
|
|
144
|
+
Add or remove a service to/from a vehicle.
|
|
145
|
+
|
|
146
|
+
```javascript
|
|
147
|
+
import { addServiceForVehicle, removeServiceForVehicle } from '@vulog/aima-vehicle';
|
|
148
|
+
|
|
149
|
+
await addServiceForVehicle(client, 'service-uuid', 'vehicle-uuid');
|
|
150
|
+
await removeServiceForVehicle(client, 'service-uuid', 'vehicle-uuid');
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Enable / Disable Vehicle
|
|
154
|
+
|
|
155
|
+
Enable or disable a vehicle with a sub-status.
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
import { enableVehicle, disableVehicle } from '@vulog/aima-vehicle';
|
|
159
|
+
|
|
160
|
+
await enableVehicle(client, 'vehicle-uuid', { subStatus: 'AVAILABLE' });
|
|
161
|
+
await disableVehicle(client, 'vehicle-uuid', { subStatus: 'MAINTENANCE' });
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Ping Vehicle
|
|
165
|
+
|
|
166
|
+
Check if a vehicle box is connected.
|
|
167
|
+
|
|
168
|
+
```javascript
|
|
169
|
+
import { pingVehicleById } from '@vulog/aima-vehicle';
|
|
170
|
+
|
|
171
|
+
const isConnected = await pingVehicleById(client, 'vehicle-uuid');
|
|
172
|
+
// true = connected, false = connection problem
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Get Model Vehicles
|
|
176
|
+
|
|
177
|
+
Fetches paginated model vehicle listings.
|
|
178
|
+
|
|
179
|
+
```javascript
|
|
180
|
+
import { getModelVehicles } from '@vulog/aima-vehicle';
|
|
181
|
+
|
|
182
|
+
const result = await getModelVehicles(client, {
|
|
183
|
+
page: 0,
|
|
184
|
+
pageSize: 50,
|
|
185
|
+
sort: 'modelId',
|
|
186
|
+
sortDirection: 'DESC',
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
101
190
|
## Types
|
|
102
191
|
|
|
103
192
|
### Vehicle
|
package/dist/index.cjs
CHANGED
|
@@ -238,20 +238,42 @@ const createVehicle = async (client, body) => {
|
|
|
238
238
|
};
|
|
239
239
|
//#endregion
|
|
240
240
|
//#region src/vehicleService.ts
|
|
241
|
-
const uuidSchema = zod.z.string().trim().min(1).uuid();
|
|
241
|
+
const uuidSchema$1 = zod.z.string().trim().min(1).uuid();
|
|
242
242
|
const addServiceForVehicle = async (client, serviceId, vehicleId) => {
|
|
243
|
-
const parsedServiceId = uuidSchema.safeParse(serviceId);
|
|
244
|
-
const parsedVehicleId = uuidSchema.safeParse(vehicleId);
|
|
243
|
+
const parsedServiceId = uuidSchema$1.safeParse(serviceId);
|
|
244
|
+
const parsedVehicleId = uuidSchema$1.safeParse(vehicleId);
|
|
245
245
|
if (!parsedServiceId.success || !parsedVehicleId.success) throw new TypeError("Invalid args", { cause: [...parsedServiceId.error?.issues ?? [], ...parsedVehicleId.error?.issues ?? []] });
|
|
246
246
|
await client.put(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/services/${parsedServiceId.data}/vehicles/${parsedVehicleId.data}`, {});
|
|
247
247
|
};
|
|
248
248
|
const removeServiceForVehicle = async (client, serviceId, vehicleId) => {
|
|
249
|
-
const parsedServiceId = uuidSchema.safeParse(serviceId);
|
|
250
|
-
const parsedVehicleId = uuidSchema.safeParse(vehicleId);
|
|
249
|
+
const parsedServiceId = uuidSchema$1.safeParse(serviceId);
|
|
250
|
+
const parsedVehicleId = uuidSchema$1.safeParse(vehicleId);
|
|
251
251
|
if (!parsedServiceId.success || !parsedVehicleId.success) throw new TypeError("Invalid args", { cause: [...parsedServiceId.error?.issues ?? [], ...parsedVehicleId.error?.issues ?? []] });
|
|
252
252
|
await client.delete(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/services/${parsedServiceId.data}/vehicles/${parsedVehicleId.data}`);
|
|
253
253
|
};
|
|
254
254
|
//#endregion
|
|
255
|
+
//#region src/getOptions.ts
|
|
256
|
+
const getOptions = async (client) => {
|
|
257
|
+
return client.get(`/boapi/proxy/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/options`).then(({ data }) => data);
|
|
258
|
+
};
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/vehicleOption.ts
|
|
261
|
+
const uuidSchema = zod.z.string().trim().min(1).uuid();
|
|
262
|
+
const optionIdSchema = zod.z.number().int().positive();
|
|
263
|
+
const addOptionForVehicle = async (client, vehicleId, optionId) => {
|
|
264
|
+
const parsedVehicleId = uuidSchema.safeParse(vehicleId);
|
|
265
|
+
const parsedOptionId = optionIdSchema.safeParse(optionId);
|
|
266
|
+
if (!parsedVehicleId.success || !parsedOptionId.success) throw new TypeError("Invalid args", { cause: [...parsedVehicleId.error?.issues ?? [], ...parsedOptionId.error?.issues ?? []] });
|
|
267
|
+
return client.put(`/boapi/proxy/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/${parsedVehicleId.data}/options/${parsedOptionId.data}`, {}).then(({ data }) => data);
|
|
268
|
+
};
|
|
269
|
+
const removeOptionForVehicle = async (client, vehicleId, optionId) => {
|
|
270
|
+
const parsedVehicleId = uuidSchema.safeParse(vehicleId);
|
|
271
|
+
const parsedOptionId = optionIdSchema.safeParse(optionId);
|
|
272
|
+
if (!parsedVehicleId.success || !parsedOptionId.success) throw new TypeError("Invalid args", { cause: [...parsedVehicleId.error?.issues ?? [], ...parsedOptionId.error?.issues ?? []] });
|
|
273
|
+
return client.delete(`/boapi/proxy/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/${parsedVehicleId.data}/options/${parsedOptionId.data}`).then(({ data }) => data);
|
|
274
|
+
};
|
|
275
|
+
//#endregion
|
|
276
|
+
exports.addOptionForVehicle = addOptionForVehicle;
|
|
255
277
|
exports.addServiceForVehicle = addServiceForVehicle;
|
|
256
278
|
exports.createVehicle = createVehicle;
|
|
257
279
|
exports.disableVehicle = disableVehicle;
|
|
@@ -260,10 +282,12 @@ exports.getModelByIdAssets = getModelByIdAssets;
|
|
|
260
282
|
exports.getModelVehicles = getModelVehicles;
|
|
261
283
|
exports.getModels = getModels;
|
|
262
284
|
exports.getModelsById = getModelsById;
|
|
285
|
+
exports.getOptions = getOptions;
|
|
263
286
|
exports.getVehicleById = getVehicleById;
|
|
264
287
|
exports.getVehicleByIdAssets = getVehicleByIdAssets;
|
|
265
288
|
exports.getVehicleRealTimeById = getVehicleRealTimeById;
|
|
266
289
|
exports.getVehicles = getVehicles;
|
|
267
290
|
exports.getVehiclesRealTime = getVehiclesRealTime;
|
|
268
291
|
exports.pingVehicleById = pingVehicleById;
|
|
292
|
+
exports.removeOptionForVehicle = removeOptionForVehicle;
|
|
269
293
|
exports.removeServiceForVehicle = removeServiceForVehicle;
|
package/dist/index.d.cts
CHANGED
|
@@ -274,4 +274,11 @@ declare const createVehicle: (client: Client, body: CreateVehicleBody) => Promis
|
|
|
274
274
|
declare const addServiceForVehicle: (client: Client, serviceId: string, vehicleId: string) => Promise<void>;
|
|
275
275
|
declare const removeServiceForVehicle: (client: Client, serviceId: string, vehicleId: string) => Promise<void>;
|
|
276
276
|
//#endregion
|
|
277
|
-
|
|
277
|
+
//#region src/getOptions.d.ts
|
|
278
|
+
declare const getOptions: (client: Client) => Promise<Options[]>;
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/vehicleOption.d.ts
|
|
281
|
+
declare const addOptionForVehicle: (client: Client, vehicleId: string, optionId: number) => Promise<Vehicle>;
|
|
282
|
+
declare const removeOptionForVehicle: (client: Client, vehicleId: string, optionId: number) => Promise<Vehicle>;
|
|
283
|
+
//#endregion
|
|
284
|
+
export { Assets, CreateVehicleBody, DisableVehicleBody, EnableVehicleBody, Model, ModelVehicle, Options, Vehicle, VehicleRealTime, Zone, addOptionForVehicle, addServiceForVehicle, createVehicle, disableVehicle, enableVehicle, getModelByIdAssets, getModelVehicles, getModels, getModelsById, getOptions, getVehicleById, getVehicleByIdAssets, getVehicleRealTimeById, getVehicles, getVehiclesRealTime, pingVehicleById, removeOptionForVehicle, removeServiceForVehicle };
|
package/dist/index.d.mts
CHANGED
|
@@ -274,4 +274,11 @@ declare const createVehicle: (client: Client, body: CreateVehicleBody) => Promis
|
|
|
274
274
|
declare const addServiceForVehicle: (client: Client, serviceId: string, vehicleId: string) => Promise<void>;
|
|
275
275
|
declare const removeServiceForVehicle: (client: Client, serviceId: string, vehicleId: string) => Promise<void>;
|
|
276
276
|
//#endregion
|
|
277
|
-
|
|
277
|
+
//#region src/getOptions.d.ts
|
|
278
|
+
declare const getOptions: (client: Client) => Promise<Options[]>;
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/vehicleOption.d.ts
|
|
281
|
+
declare const addOptionForVehicle: (client: Client, vehicleId: string, optionId: number) => Promise<Vehicle>;
|
|
282
|
+
declare const removeOptionForVehicle: (client: Client, vehicleId: string, optionId: number) => Promise<Vehicle>;
|
|
283
|
+
//#endregion
|
|
284
|
+
export { Assets, CreateVehicleBody, DisableVehicleBody, EnableVehicleBody, Model, ModelVehicle, Options, Vehicle, VehicleRealTime, Zone, addOptionForVehicle, addServiceForVehicle, createVehicle, disableVehicle, enableVehicle, getModelByIdAssets, getModelVehicles, getModels, getModelsById, getOptions, getVehicleById, getVehicleByIdAssets, getVehicleRealTimeById, getVehicles, getVehiclesRealTime, pingVehicleById, removeOptionForVehicle, removeServiceForVehicle };
|
package/dist/index.mjs
CHANGED
|
@@ -214,18 +214,39 @@ const createVehicle = async (client, body) => {
|
|
|
214
214
|
};
|
|
215
215
|
//#endregion
|
|
216
216
|
//#region src/vehicleService.ts
|
|
217
|
-
const uuidSchema = z.string().trim().min(1).uuid();
|
|
217
|
+
const uuidSchema$1 = z.string().trim().min(1).uuid();
|
|
218
218
|
const addServiceForVehicle = async (client, serviceId, vehicleId) => {
|
|
219
|
-
const parsedServiceId = uuidSchema.safeParse(serviceId);
|
|
220
|
-
const parsedVehicleId = uuidSchema.safeParse(vehicleId);
|
|
219
|
+
const parsedServiceId = uuidSchema$1.safeParse(serviceId);
|
|
220
|
+
const parsedVehicleId = uuidSchema$1.safeParse(vehicleId);
|
|
221
221
|
if (!parsedServiceId.success || !parsedVehicleId.success) throw new TypeError("Invalid args", { cause: [...parsedServiceId.error?.issues ?? [], ...parsedVehicleId.error?.issues ?? []] });
|
|
222
222
|
await client.put(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/services/${parsedServiceId.data}/vehicles/${parsedVehicleId.data}`, {});
|
|
223
223
|
};
|
|
224
224
|
const removeServiceForVehicle = async (client, serviceId, vehicleId) => {
|
|
225
|
-
const parsedServiceId = uuidSchema.safeParse(serviceId);
|
|
226
|
-
const parsedVehicleId = uuidSchema.safeParse(vehicleId);
|
|
225
|
+
const parsedServiceId = uuidSchema$1.safeParse(serviceId);
|
|
226
|
+
const parsedVehicleId = uuidSchema$1.safeParse(vehicleId);
|
|
227
227
|
if (!parsedServiceId.success || !parsedVehicleId.success) throw new TypeError("Invalid args", { cause: [...parsedServiceId.error?.issues ?? [], ...parsedVehicleId.error?.issues ?? []] });
|
|
228
228
|
await client.delete(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/services/${parsedServiceId.data}/vehicles/${parsedVehicleId.data}`);
|
|
229
229
|
};
|
|
230
230
|
//#endregion
|
|
231
|
-
|
|
231
|
+
//#region src/getOptions.ts
|
|
232
|
+
const getOptions = async (client) => {
|
|
233
|
+
return client.get(`/boapi/proxy/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/options`).then(({ data }) => data);
|
|
234
|
+
};
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/vehicleOption.ts
|
|
237
|
+
const uuidSchema = z.string().trim().min(1).uuid();
|
|
238
|
+
const optionIdSchema = z.number().int().positive();
|
|
239
|
+
const addOptionForVehicle = async (client, vehicleId, optionId) => {
|
|
240
|
+
const parsedVehicleId = uuidSchema.safeParse(vehicleId);
|
|
241
|
+
const parsedOptionId = optionIdSchema.safeParse(optionId);
|
|
242
|
+
if (!parsedVehicleId.success || !parsedOptionId.success) throw new TypeError("Invalid args", { cause: [...parsedVehicleId.error?.issues ?? [], ...parsedOptionId.error?.issues ?? []] });
|
|
243
|
+
return client.put(`/boapi/proxy/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/${parsedVehicleId.data}/options/${parsedOptionId.data}`, {}).then(({ data }) => data);
|
|
244
|
+
};
|
|
245
|
+
const removeOptionForVehicle = async (client, vehicleId, optionId) => {
|
|
246
|
+
const parsedVehicleId = uuidSchema.safeParse(vehicleId);
|
|
247
|
+
const parsedOptionId = optionIdSchema.safeParse(optionId);
|
|
248
|
+
if (!parsedVehicleId.success || !parsedOptionId.success) throw new TypeError("Invalid args", { cause: [...parsedVehicleId.error?.issues ?? [], ...parsedOptionId.error?.issues ?? []] });
|
|
249
|
+
return client.delete(`/boapi/proxy/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/${parsedVehicleId.data}/options/${parsedOptionId.data}`).then(({ data }) => data);
|
|
250
|
+
};
|
|
251
|
+
//#endregion
|
|
252
|
+
export { addOptionForVehicle, addServiceForVehicle, createVehicle, disableVehicle, enableVehicle, getModelByIdAssets, getModelVehicles, getModels, getModelsById, getOptions, getVehicleById, getVehicleByIdAssets, getVehicleRealTimeById, getVehicles, getVehiclesRealTime, pingVehicleById, removeOptionForVehicle, removeServiceForVehicle };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-vehicle",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.34",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.cts",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"author": "Vulog",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@vulog/aima-client": "1.2.
|
|
36
|
-
"@vulog/aima-core": "1.2.
|
|
35
|
+
"@vulog/aima-client": "1.2.34",
|
|
36
|
+
"@vulog/aima-core": "1.2.34"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"zod": "^3.25.76"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
|
|
3
|
+
import { Options } from './types';
|
|
4
|
+
|
|
5
|
+
export const getOptions = async (client: Client): Promise<Options[]> => {
|
|
6
|
+
return client
|
|
7
|
+
.get<Options[]>(`/boapi/proxy/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/options`)
|
|
8
|
+
.then(({ data }) => data);
|
|
9
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { Vehicle } from './types';
|
|
5
|
+
|
|
6
|
+
const uuidSchema = z.string().trim().min(1).uuid();
|
|
7
|
+
const optionIdSchema = z.number().int().positive();
|
|
8
|
+
|
|
9
|
+
export const addOptionForVehicle = async (client: Client, vehicleId: string, optionId: number): Promise<Vehicle> => {
|
|
10
|
+
const parsedVehicleId = uuidSchema.safeParse(vehicleId);
|
|
11
|
+
const parsedOptionId = optionIdSchema.safeParse(optionId);
|
|
12
|
+
if (!parsedVehicleId.success || !parsedOptionId.success) {
|
|
13
|
+
throw new TypeError('Invalid args', {
|
|
14
|
+
cause: [...(parsedVehicleId.error?.issues ?? []), ...(parsedOptionId.error?.issues ?? [])],
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return client
|
|
19
|
+
.put<Vehicle>(
|
|
20
|
+
`/boapi/proxy/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/${parsedVehicleId.data}/options/${parsedOptionId.data}`,
|
|
21
|
+
{}
|
|
22
|
+
)
|
|
23
|
+
.then(({ data }) => data);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const removeOptionForVehicle = async (client: Client, vehicleId: string, optionId: number): Promise<Vehicle> => {
|
|
27
|
+
const parsedVehicleId = uuidSchema.safeParse(vehicleId);
|
|
28
|
+
const parsedOptionId = optionIdSchema.safeParse(optionId);
|
|
29
|
+
if (!parsedVehicleId.success || !parsedOptionId.success) {
|
|
30
|
+
throw new TypeError('Invalid args', {
|
|
31
|
+
cause: [...(parsedVehicleId.error?.issues ?? []), ...(parsedOptionId.error?.issues ?? [])],
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return client
|
|
36
|
+
.delete<Vehicle>(
|
|
37
|
+
`/boapi/proxy/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/${parsedVehicleId.data}/options/${parsedOptionId.data}`
|
|
38
|
+
)
|
|
39
|
+
.then(({ data }) => data);
|
|
40
|
+
};
|