@vulog/aima-vehicle 1.2.31 → 1.2.33

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 CHANGED
@@ -237,6 +237,44 @@ const createVehicle = async (client, body) => {
237
237
  return client.post(`/boapi/proxy/vehicle/fleets/${client.clientOptions.fleetId}/vehicles`, result.data).then(({ data }) => data);
238
238
  };
239
239
  //#endregion
240
+ //#region src/vehicleService.ts
241
+ const uuidSchema$1 = zod.z.string().trim().min(1).uuid();
242
+ const addServiceForVehicle = async (client, serviceId, vehicleId) => {
243
+ const parsedServiceId = uuidSchema$1.safeParse(serviceId);
244
+ const parsedVehicleId = uuidSchema$1.safeParse(vehicleId);
245
+ if (!parsedServiceId.success || !parsedVehicleId.success) throw new TypeError("Invalid args", { cause: [...parsedServiceId.error?.issues ?? [], ...parsedVehicleId.error?.issues ?? []] });
246
+ await client.put(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/services/${parsedServiceId.data}/vehicles/${parsedVehicleId.data}`, {});
247
+ };
248
+ const removeServiceForVehicle = async (client, serviceId, vehicleId) => {
249
+ const parsedServiceId = uuidSchema$1.safeParse(serviceId);
250
+ const parsedVehicleId = uuidSchema$1.safeParse(vehicleId);
251
+ if (!parsedServiceId.success || !parsedVehicleId.success) throw new TypeError("Invalid args", { cause: [...parsedServiceId.error?.issues ?? [], ...parsedVehicleId.error?.issues ?? []] });
252
+ await client.delete(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/services/${parsedServiceId.data}/vehicles/${parsedVehicleId.data}`);
253
+ };
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;
277
+ exports.addServiceForVehicle = addServiceForVehicle;
240
278
  exports.createVehicle = createVehicle;
241
279
  exports.disableVehicle = disableVehicle;
242
280
  exports.enableVehicle = enableVehicle;
@@ -244,9 +282,12 @@ exports.getModelByIdAssets = getModelByIdAssets;
244
282
  exports.getModelVehicles = getModelVehicles;
245
283
  exports.getModels = getModels;
246
284
  exports.getModelsById = getModelsById;
285
+ exports.getOptions = getOptions;
247
286
  exports.getVehicleById = getVehicleById;
248
287
  exports.getVehicleByIdAssets = getVehicleByIdAssets;
249
288
  exports.getVehicleRealTimeById = getVehicleRealTimeById;
250
289
  exports.getVehicles = getVehicles;
251
290
  exports.getVehiclesRealTime = getVehiclesRealTime;
252
291
  exports.pingVehicleById = pingVehicleById;
292
+ exports.removeOptionForVehicle = removeOptionForVehicle;
293
+ exports.removeServiceForVehicle = removeServiceForVehicle;
package/dist/index.d.cts CHANGED
@@ -270,4 +270,15 @@ type CreateVehicleBody = {
270
270
  };
271
271
  declare const createVehicle: (client: Client, body: CreateVehicleBody) => Promise<Vehicle>;
272
272
  //#endregion
273
- export { Assets, CreateVehicleBody, DisableVehicleBody, EnableVehicleBody, Model, ModelVehicle, Options, Vehicle, VehicleRealTime, Zone, createVehicle, disableVehicle, enableVehicle, getModelByIdAssets, getModelVehicles, getModels, getModelsById, getVehicleById, getVehicleByIdAssets, getVehicleRealTimeById, getVehicles, getVehiclesRealTime, pingVehicleById };
273
+ //#region src/vehicleService.d.ts
274
+ declare const addServiceForVehicle: (client: Client, serviceId: string, vehicleId: string) => Promise<void>;
275
+ declare const removeServiceForVehicle: (client: Client, serviceId: string, vehicleId: string) => Promise<void>;
276
+ //#endregion
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
@@ -270,4 +270,15 @@ type CreateVehicleBody = {
270
270
  };
271
271
  declare const createVehicle: (client: Client, body: CreateVehicleBody) => Promise<Vehicle>;
272
272
  //#endregion
273
- export { Assets, CreateVehicleBody, DisableVehicleBody, EnableVehicleBody, Model, ModelVehicle, Options, Vehicle, VehicleRealTime, Zone, createVehicle, disableVehicle, enableVehicle, getModelByIdAssets, getModelVehicles, getModels, getModelsById, getVehicleById, getVehicleByIdAssets, getVehicleRealTimeById, getVehicles, getVehiclesRealTime, pingVehicleById };
273
+ //#region src/vehicleService.d.ts
274
+ declare const addServiceForVehicle: (client: Client, serviceId: string, vehicleId: string) => Promise<void>;
275
+ declare const removeServiceForVehicle: (client: Client, serviceId: string, vehicleId: string) => Promise<void>;
276
+ //#endregion
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
@@ -213,4 +213,40 @@ const createVehicle = async (client, body) => {
213
213
  return client.post(`/boapi/proxy/vehicle/fleets/${client.clientOptions.fleetId}/vehicles`, result.data).then(({ data }) => data);
214
214
  };
215
215
  //#endregion
216
- export { createVehicle, disableVehicle, enableVehicle, getModelByIdAssets, getModelVehicles, getModels, getModelsById, getVehicleById, getVehicleByIdAssets, getVehicleRealTimeById, getVehicles, getVehiclesRealTime, pingVehicleById };
216
+ //#region src/vehicleService.ts
217
+ const uuidSchema$1 = z.string().trim().min(1).uuid();
218
+ const addServiceForVehicle = async (client, serviceId, vehicleId) => {
219
+ const parsedServiceId = uuidSchema$1.safeParse(serviceId);
220
+ const parsedVehicleId = uuidSchema$1.safeParse(vehicleId);
221
+ if (!parsedServiceId.success || !parsedVehicleId.success) throw new TypeError("Invalid args", { cause: [...parsedServiceId.error?.issues ?? [], ...parsedVehicleId.error?.issues ?? []] });
222
+ await client.put(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/services/${parsedServiceId.data}/vehicles/${parsedVehicleId.data}`, {});
223
+ };
224
+ const removeServiceForVehicle = async (client, serviceId, vehicleId) => {
225
+ const parsedServiceId = uuidSchema$1.safeParse(serviceId);
226
+ const parsedVehicleId = uuidSchema$1.safeParse(vehicleId);
227
+ if (!parsedServiceId.success || !parsedVehicleId.success) throw new TypeError("Invalid args", { cause: [...parsedServiceId.error?.issues ?? [], ...parsedVehicleId.error?.issues ?? []] });
228
+ await client.delete(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/services/${parsedServiceId.data}/vehicles/${parsedVehicleId.data}`);
229
+ };
230
+ //#endregion
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.31",
4
+ "version": "1.2.33",
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.31",
36
- "@vulog/aima-core": "1.2.31"
35
+ "@vulog/aima-client": "1.2.33",
36
+ "@vulog/aima-core": "1.2.33"
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
@@ -10,3 +10,6 @@ export * from './enableVehicle';
10
10
  export * from './disableVehicle';
11
11
  export * from './getModelVehicles';
12
12
  export * from './createVehicle';
13
+ export * from './vehicleService';
14
+ export * from './getOptions';
15
+ export * from './vehicleOption';
@@ -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
+ };
@@ -0,0 +1,63 @@
1
+ import { describe, test, vi, expect, beforeEach } from 'vitest';
2
+ import { Client } from '@vulog/aima-client';
3
+ import { addServiceForVehicle, removeServiceForVehicle } from './vehicleService';
4
+
5
+ describe('vehicleService', () => {
6
+ const putMock = vi.fn();
7
+ const deleteMock = vi.fn();
8
+ const client = {
9
+ put: putMock,
10
+ delete: deleteMock,
11
+ clientOptions: {
12
+ fleetId: 'FLEET_ID',
13
+ },
14
+ } as unknown as Client;
15
+
16
+ const serviceId = 'ed539d7d-d815-405b-bc00-71008fb1954c';
17
+ const vehicleId = 'b931b17e-214f-4a73-ad94-77a973435768';
18
+
19
+ beforeEach(() => {
20
+ vi.clearAllMocks();
21
+ });
22
+
23
+ describe('addServiceForVehicle', () => {
24
+ test('should call PUT with correct URL', async () => {
25
+ putMock.mockResolvedValueOnce({ data: undefined });
26
+
27
+ await addServiceForVehicle(client, serviceId, vehicleId);
28
+
29
+ expect(putMock).toHaveBeenCalledWith(
30
+ `/boapi/proxy/user/fleets/FLEET_ID/services/${serviceId}/vehicles/${vehicleId}`,
31
+ {}
32
+ );
33
+ });
34
+
35
+ test('should throw for invalid serviceId', async () => {
36
+ await expect(addServiceForVehicle(client, 'not-a-uuid', vehicleId)).rejects.toThrow(TypeError);
37
+ });
38
+
39
+ test('should throw for invalid vehicleId', async () => {
40
+ await expect(addServiceForVehicle(client, serviceId, 'not-a-uuid')).rejects.toThrow(TypeError);
41
+ });
42
+ });
43
+
44
+ describe('removeServiceForVehicle', () => {
45
+ test('should call DELETE with correct URL', async () => {
46
+ deleteMock.mockResolvedValueOnce({ data: undefined });
47
+
48
+ await removeServiceForVehicle(client, serviceId, vehicleId);
49
+
50
+ expect(deleteMock).toHaveBeenCalledWith(
51
+ `/boapi/proxy/user/fleets/FLEET_ID/services/${serviceId}/vehicles/${vehicleId}`
52
+ );
53
+ });
54
+
55
+ test('should throw for invalid serviceId', async () => {
56
+ await expect(removeServiceForVehicle(client, 'not-a-uuid', vehicleId)).rejects.toThrow(TypeError);
57
+ });
58
+
59
+ test('should throw for invalid vehicleId', async () => {
60
+ await expect(removeServiceForVehicle(client, serviceId, 'not-a-uuid')).rejects.toThrow(TypeError);
61
+ });
62
+ });
63
+ });
@@ -0,0 +1,33 @@
1
+ import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
3
+
4
+ const uuidSchema = z.string().trim().min(1).uuid();
5
+
6
+ export const addServiceForVehicle = async (client: Client, serviceId: string, vehicleId: string): Promise<void> => {
7
+ const parsedServiceId = uuidSchema.safeParse(serviceId);
8
+ const parsedVehicleId = uuidSchema.safeParse(vehicleId);
9
+ if (!parsedServiceId.success || !parsedVehicleId.success) {
10
+ throw new TypeError('Invalid args', {
11
+ cause: [...(parsedServiceId.error?.issues ?? []), ...(parsedVehicleId.error?.issues ?? [])],
12
+ });
13
+ }
14
+
15
+ await client.put<void>(
16
+ `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/services/${parsedServiceId.data}/vehicles/${parsedVehicleId.data}`,
17
+ {}
18
+ );
19
+ };
20
+
21
+ export const removeServiceForVehicle = async (client: Client, serviceId: string, vehicleId: string): Promise<void> => {
22
+ const parsedServiceId = uuidSchema.safeParse(serviceId);
23
+ const parsedVehicleId = uuidSchema.safeParse(vehicleId);
24
+ if (!parsedServiceId.success || !parsedVehicleId.success) {
25
+ throw new TypeError('Invalid args', {
26
+ cause: [...(parsedServiceId.error?.issues ?? []), ...(parsedVehicleId.error?.issues ?? [])],
27
+ });
28
+ }
29
+
30
+ await client.delete<void>(
31
+ `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/services/${parsedServiceId.data}/vehicles/${parsedVehicleId.data}`
32
+ );
33
+ };