@vulog/aima-vehicle 1.2.48 → 1.2.49

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
@@ -7,9 +7,9 @@ const getModelsById = async (client, id) => {
7
7
  };
8
8
  //#endregion
9
9
  //#region src/getModelAssets.ts
10
- const schema$5 = zod.z.object({ id: zod.z.number().int().positive() });
10
+ const schema$7 = zod.z.object({ id: zod.z.number().int().positive() });
11
11
  const getModelByIdAssets = async (client, id) => {
12
- const result = schema$5.safeParse({ id });
12
+ const result = schema$7.safeParse({ id });
13
13
  if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
14
14
  return client.get(`boapi/proxy/eds/rest_pub/rest/fleets/${client.clientOptions.fleetId}/models/${id}/`).then(({ data }) => data);
15
15
  };
@@ -20,9 +20,9 @@ const getModels = async (client) => {
20
20
  };
21
21
  //#endregion
22
22
  //#region src/getVehicle.ts
23
- const schema$4 = zod.z.object({ id: zod.z.string().trim().min(1).uuid() });
23
+ const schema$6 = zod.z.object({ id: zod.z.string().trim().min(1).uuid() });
24
24
  const getVehicleById = async (client, id) => {
25
- const result = schema$4.safeParse({ id });
25
+ const result = schema$6.safeParse({ id });
26
26
  if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
27
27
  return client.get(`boapi/proxy/user/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.id}`).then(({ data }) => data).catch((error) => {
28
28
  if (error.formattedError?.status === 404) return null;
@@ -30,7 +30,7 @@ const getVehicleById = async (client, id) => {
30
30
  });
31
31
  };
32
32
  const getVehicleRealTimeById = async (client, id) => {
33
- const result = schema$4.safeParse({ id });
33
+ const result = schema$6.safeParse({ id });
34
34
  if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
35
35
  return client.get(`boapi/proxy/fleetmanager/public/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.id}`).then(({ data }) => data).catch((error) => {
36
36
  if (error.formattedError?.status === 404) return null;
@@ -39,9 +39,9 @@ const getVehicleRealTimeById = async (client, id) => {
39
39
  };
40
40
  //#endregion
41
41
  //#region src/getVehicleAssets.ts
42
- const schema$3 = zod.z.object({ id: zod.z.string().uuid() });
42
+ const schema$5 = zod.z.object({ id: zod.z.string().uuid() });
43
43
  const getVehicleByIdAssets = async (client, id) => {
44
- const result = schema$3.safeParse({ id });
44
+ const result = schema$5.safeParse({ id });
45
45
  if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
46
46
  return client.get(`boapi/proxy/eds/rest_pub/rest/fleets/${client.clientOptions.fleetId}/vehicles/${id}/`).then(({ data }) => data);
47
47
  };
@@ -132,14 +132,14 @@ const getVehiclesRealTime = async (client, pageSize = 500, lastUpdatedMillis) =>
132
132
  };
133
133
  //#endregion
134
134
  //#region src/pingVehicle.ts
135
- const schema$2 = zod.z.object({ id: zod.z.string().trim().min(1).uuid() });
135
+ const schema$4 = zod.z.object({ id: zod.z.string().trim().min(1).uuid() });
136
136
  /**
137
137
  * Pings a vehicle to check if it is alive (box connected).
138
138
  * Returns true if alive (HTTP 200), false if box not connected (code 410, codeStr 'carConnectionProblem'),
139
139
  * throws for other errors or invalid id.
140
140
  */
141
141
  const pingVehicleById = async (client, id) => {
142
- const result = schema$2.safeParse({ id });
142
+ const result = schema$4.safeParse({ id });
143
143
  if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
144
144
  try {
145
145
  await client.get(`boapi/proxy/fleetmanager/public/v2/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.id}/ping`);
@@ -151,17 +151,17 @@ const pingVehicleById = async (client, id) => {
151
151
  };
152
152
  //#endregion
153
153
  //#region src/enableVehicle.ts
154
- const schema$1 = zod.z.object({ subStatus: zod.z.string() });
154
+ const schema$3 = zod.z.object({ subStatus: zod.z.string() });
155
155
  const enableVehicle = async (client, vehicleId, payload) => {
156
- const result = schema$1.safeParse(payload);
156
+ const result = schema$3.safeParse(payload);
157
157
  if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
158
158
  return client.post(`boapi/proxy/fleetmanager/public/fleets/${client.clientOptions.fleetId}/vehicles/${vehicleId}/enable`, payload).then(({ data }) => data);
159
159
  };
160
160
  //#endregion
161
161
  //#region src/disableVehicle.ts
162
- const schema = zod.z.object({ subStatus: zod.z.string() });
162
+ const schema$2 = zod.z.object({ subStatus: zod.z.string() });
163
163
  const disableVehicle = async (client, vehicleId, payload) => {
164
- const result = schema.safeParse(payload);
164
+ const result = schema$2.safeParse(payload);
165
165
  if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
166
166
  return client.post(`boapi/proxy/fleetmanager/public/fleets/${client.clientOptions.fleetId}/vehicles/${vehicleId}/disable`, payload).then(({ data }) => data);
167
167
  };
@@ -206,7 +206,8 @@ const createVehicleBodySchema = zod.z.object({
206
206
  msisdn: zod.z.string().max(32).optional(),
207
207
  iccid: zod.z.string().max(32).optional(),
208
208
  imsi: zod.z.string().max(32).optional(),
209
- residualValue: zod.z.number().optional()
209
+ residualValue: zod.z.number().optional(),
210
+ registrationDate: zod.z.string().date().optional()
210
211
  });
211
212
  const createVehicle = async (client, body) => {
212
213
  const result = createVehicleBodySchema.safeParse(body);
@@ -214,6 +215,81 @@ const createVehicle = async (client, body) => {
214
215
  return client.post(`/boapi/proxy/vehicle/fleets/${client.clientOptions.fleetId}/vehicles`, result.data).then(({ data }) => data);
215
216
  };
216
217
  //#endregion
218
+ //#region src/createRfidCard.ts
219
+ const createRfidCardBodySchema = zod.z.object({
220
+ tag: zod.z.string().trim().min(1),
221
+ description: zod.z.string().max(128),
222
+ pinCode: zod.z.string().length(4)
223
+ });
224
+ const createRfidCard = async (client, body) => {
225
+ const result = createRfidCardBodySchema.safeParse(body);
226
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
227
+ return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/vehicles/rfids`, {
228
+ ...result.data,
229
+ fleetId: client.clientOptions.fleetId
230
+ }).then(({ data }) => data);
231
+ };
232
+ //#endregion
233
+ //#region src/getRfidCard.ts
234
+ const schema$1 = zod.z.object({ tag: zod.z.string().trim().min(1) });
235
+ const getRfidCardByTag = async (client, tag) => {
236
+ const result = schema$1.safeParse({ tag });
237
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
238
+ return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/vehicles/rfids/${result.data.tag}`).then(({ data }) => data).catch((error) => {
239
+ if (error.formattedError?.status === 404) return null;
240
+ throw error;
241
+ });
242
+ };
243
+ //#endregion
244
+ //#region src/getRfidCards.ts
245
+ /**
246
+ * Fetches a single page of RFID cards from the API
247
+ * @param client - The AIMA client instance
248
+ * @param page - The page number to fetch
249
+ * @param pageSize - Number of RFID cards per page
250
+ * @returns Promise that resolves to an array of RFID cards for the requested page
251
+ */
252
+ const getRfidCardsPage = async (client, page, pageSize) => {
253
+ return (await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/vehicles/rfids?page=${page}&size=${pageSize}`)).data;
254
+ };
255
+ /**
256
+ * Fetches all RFID cards from the API using pagination
257
+ * @param client - The AIMA client instance
258
+ * @param pageSize - Number of RFID cards per page (default: 500)
259
+ * @returns Promise that resolves to an array of all RFID cards
260
+ * @throws Error if more than 50 pages are required to fetch all RFID cards
261
+ */
262
+ const getRfidCards = async (client, pageSize = 500) => {
263
+ const result = zod.z.object({ pageSize: zod.z.number().min(1).default(500) }).safeParse({ pageSize });
264
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
265
+ const allRfidCards = [];
266
+ let currentPage = 0;
267
+ let hasMorePages = true;
268
+ const MAX_PAGES = 50;
269
+ while (hasMorePages) {
270
+ if (currentPage >= MAX_PAGES) throw new Error(`Maximum page limit (${MAX_PAGES}) reached. This might indicate an issue with the pagination or a very large dataset.`);
271
+ const rfidCards = await getRfidCardsPage(client, currentPage, result.data.pageSize);
272
+ allRfidCards.push(...rfidCards);
273
+ hasMorePages = rfidCards.length === result.data.pageSize;
274
+ currentPage += 1;
275
+ }
276
+ return allRfidCards;
277
+ };
278
+ //#endregion
279
+ //#region src/linkRfidCardToVehicle.ts
280
+ const schema = zod.z.object({
281
+ vehicleId: zod.z.string().trim().min(1).uuid(),
282
+ tag: zod.z.string().trim().min(1)
283
+ });
284
+ const linkRfidCardToVehicle = async (client, vehicleId, tag) => {
285
+ const result = schema.safeParse({
286
+ vehicleId,
287
+ tag
288
+ });
289
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
290
+ return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.vehicleId}/rfids/${result.data.tag}`).then(({ data }) => data);
291
+ };
292
+ //#endregion
217
293
  //#region src/vehicleService.ts
218
294
  const uuidSchema$1 = zod.z.string().trim().min(1).uuid();
219
295
  const addServiceForVehicle = async (client, serviceId, vehicleId) => {
@@ -252,6 +328,7 @@ const removeOptionForVehicle = async (client, vehicleId, optionId) => {
252
328
  //#endregion
253
329
  exports.addOptionForVehicle = addOptionForVehicle;
254
330
  exports.addServiceForVehicle = addServiceForVehicle;
331
+ exports.createRfidCard = createRfidCard;
255
332
  exports.createVehicle = createVehicle;
256
333
  exports.disableVehicle = disableVehicle;
257
334
  exports.enableVehicle = enableVehicle;
@@ -260,11 +337,14 @@ exports.getModelVehicles = getModelVehicles;
260
337
  exports.getModels = getModels;
261
338
  exports.getModelsById = getModelsById;
262
339
  exports.getOptions = getOptions;
340
+ exports.getRfidCardByTag = getRfidCardByTag;
341
+ exports.getRfidCards = getRfidCards;
263
342
  exports.getVehicleById = getVehicleById;
264
343
  exports.getVehicleByIdAssets = getVehicleByIdAssets;
265
344
  exports.getVehicleRealTimeById = getVehicleRealTimeById;
266
345
  exports.getVehicles = getVehicles;
267
346
  exports.getVehiclesRealTime = getVehiclesRealTime;
347
+ exports.linkRfidCardToVehicle = linkRfidCardToVehicle;
268
348
  exports.pingVehicleById = pingVehicleById;
269
349
  exports.removeOptionForVehicle = removeOptionForVehicle;
270
350
  exports.removeServiceForVehicle = removeServiceForVehicle;
package/dist/index.d.cts CHANGED
@@ -35,7 +35,8 @@ type Vehicle = {
35
35
  vin: string; /** Model information of the vehicle */
36
36
  model: Model; /** List of options/features installed on the vehicle */
37
37
  options: Options[]; /** Date when the vehicle was created */
38
- createDate: string; /** Date when the vehicle was last updated */
38
+ createDate: string; /** Date when the vehicle was registered */
39
+ registrationDate?: string; /** Date when the vehicle was last updated */
39
40
  updateDate: string; /** ID of the fleet this vehicle belongs to */
40
41
  fleetId: string; /** External system identifier */
41
42
  externalId: string; /** Provider used for vehicle wakeup */
@@ -59,6 +60,15 @@ type Options = {
59
60
  description: string;
60
61
  [key: string]: any;
61
62
  };
63
+ type RfidCard = {
64
+ tag: string;
65
+ description: string;
66
+ fleetId: string;
67
+ pinCode: string;
68
+ vehicleId?: string;
69
+ updateDate?: string;
70
+ [key: string]: any;
71
+ };
62
72
  type Zone = {
63
73
  type: string;
64
74
  version: number;
@@ -267,9 +277,34 @@ type CreateVehicleBody = {
267
277
  iccid?: string;
268
278
  imsi?: string;
269
279
  residualValue?: number;
280
+ registrationDate?: string;
270
281
  };
271
282
  declare const createVehicle: (client: Client, body: CreateVehicleBody) => Promise<Vehicle>;
272
283
  //#endregion
284
+ //#region src/createRfidCard.d.ts
285
+ type CreateRfidCardBody = {
286
+ tag: string;
287
+ description: string;
288
+ pinCode: string;
289
+ };
290
+ declare const createRfidCard: (client: Client, body: CreateRfidCardBody) => Promise<RfidCard>;
291
+ //#endregion
292
+ //#region src/getRfidCard.d.ts
293
+ declare const getRfidCardByTag: (client: Client, tag: string) => Promise<RfidCard | null>;
294
+ //#endregion
295
+ //#region src/getRfidCards.d.ts
296
+ /**
297
+ * Fetches all RFID cards from the API using pagination
298
+ * @param client - The AIMA client instance
299
+ * @param pageSize - Number of RFID cards per page (default: 500)
300
+ * @returns Promise that resolves to an array of all RFID cards
301
+ * @throws Error if more than 50 pages are required to fetch all RFID cards
302
+ */
303
+ declare const getRfidCards: (client: Client, pageSize?: number) => Promise<RfidCard[]>;
304
+ //#endregion
305
+ //#region src/linkRfidCardToVehicle.d.ts
306
+ declare const linkRfidCardToVehicle: (client: Client, vehicleId: string, tag: string) => Promise<RfidCard>;
307
+ //#endregion
273
308
  //#region src/vehicleService.d.ts
274
309
  declare const addServiceForVehicle: (client: Client, serviceId: string, vehicleId: string) => Promise<void>;
275
310
  declare const removeServiceForVehicle: (client: Client, serviceId: string, vehicleId: string) => Promise<void>;
@@ -281,4 +316,4 @@ declare const getOptions: (client: Client) => Promise<Options[]>;
281
316
  declare const addOptionForVehicle: (client: Client, vehicleId: string, optionId: number) => Promise<Vehicle>;
282
317
  declare const removeOptionForVehicle: (client: Client, vehicleId: string, optionId: number) => Promise<Vehicle>;
283
318
  //#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 };
319
+ export { Assets, CreateRfidCardBody, CreateVehicleBody, DisableVehicleBody, EnableVehicleBody, Model, ModelVehicle, Options, RfidCard, Vehicle, VehicleRealTime, Zone, addOptionForVehicle, addServiceForVehicle, createRfidCard, createVehicle, disableVehicle, enableVehicle, getModelByIdAssets, getModelVehicles, getModels, getModelsById, getOptions, getRfidCardByTag, getRfidCards, getVehicleById, getVehicleByIdAssets, getVehicleRealTimeById, getVehicles, getVehiclesRealTime, linkRfidCardToVehicle, pingVehicleById, removeOptionForVehicle, removeServiceForVehicle };
package/dist/index.d.mts CHANGED
@@ -35,7 +35,8 @@ type Vehicle = {
35
35
  vin: string; /** Model information of the vehicle */
36
36
  model: Model; /** List of options/features installed on the vehicle */
37
37
  options: Options[]; /** Date when the vehicle was created */
38
- createDate: string; /** Date when the vehicle was last updated */
38
+ createDate: string; /** Date when the vehicle was registered */
39
+ registrationDate?: string; /** Date when the vehicle was last updated */
39
40
  updateDate: string; /** ID of the fleet this vehicle belongs to */
40
41
  fleetId: string; /** External system identifier */
41
42
  externalId: string; /** Provider used for vehicle wakeup */
@@ -59,6 +60,15 @@ type Options = {
59
60
  description: string;
60
61
  [key: string]: any;
61
62
  };
63
+ type RfidCard = {
64
+ tag: string;
65
+ description: string;
66
+ fleetId: string;
67
+ pinCode: string;
68
+ vehicleId?: string;
69
+ updateDate?: string;
70
+ [key: string]: any;
71
+ };
62
72
  type Zone = {
63
73
  type: string;
64
74
  version: number;
@@ -267,9 +277,34 @@ type CreateVehicleBody = {
267
277
  iccid?: string;
268
278
  imsi?: string;
269
279
  residualValue?: number;
280
+ registrationDate?: string;
270
281
  };
271
282
  declare const createVehicle: (client: Client, body: CreateVehicleBody) => Promise<Vehicle>;
272
283
  //#endregion
284
+ //#region src/createRfidCard.d.ts
285
+ type CreateRfidCardBody = {
286
+ tag: string;
287
+ description: string;
288
+ pinCode: string;
289
+ };
290
+ declare const createRfidCard: (client: Client, body: CreateRfidCardBody) => Promise<RfidCard>;
291
+ //#endregion
292
+ //#region src/getRfidCard.d.ts
293
+ declare const getRfidCardByTag: (client: Client, tag: string) => Promise<RfidCard | null>;
294
+ //#endregion
295
+ //#region src/getRfidCards.d.ts
296
+ /**
297
+ * Fetches all RFID cards from the API using pagination
298
+ * @param client - The AIMA client instance
299
+ * @param pageSize - Number of RFID cards per page (default: 500)
300
+ * @returns Promise that resolves to an array of all RFID cards
301
+ * @throws Error if more than 50 pages are required to fetch all RFID cards
302
+ */
303
+ declare const getRfidCards: (client: Client, pageSize?: number) => Promise<RfidCard[]>;
304
+ //#endregion
305
+ //#region src/linkRfidCardToVehicle.d.ts
306
+ declare const linkRfidCardToVehicle: (client: Client, vehicleId: string, tag: string) => Promise<RfidCard>;
307
+ //#endregion
273
308
  //#region src/vehicleService.d.ts
274
309
  declare const addServiceForVehicle: (client: Client, serviceId: string, vehicleId: string) => Promise<void>;
275
310
  declare const removeServiceForVehicle: (client: Client, serviceId: string, vehicleId: string) => Promise<void>;
@@ -281,4 +316,4 @@ declare const getOptions: (client: Client) => Promise<Options[]>;
281
316
  declare const addOptionForVehicle: (client: Client, vehicleId: string, optionId: number) => Promise<Vehicle>;
282
317
  declare const removeOptionForVehicle: (client: Client, vehicleId: string, optionId: number) => Promise<Vehicle>;
283
318
  //#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 };
319
+ export { Assets, CreateRfidCardBody, CreateVehicleBody, DisableVehicleBody, EnableVehicleBody, Model, ModelVehicle, Options, RfidCard, Vehicle, VehicleRealTime, Zone, addOptionForVehicle, addServiceForVehicle, createRfidCard, createVehicle, disableVehicle, enableVehicle, getModelByIdAssets, getModelVehicles, getModels, getModelsById, getOptions, getRfidCardByTag, getRfidCards, getVehicleById, getVehicleByIdAssets, getVehicleRealTimeById, getVehicles, getVehiclesRealTime, linkRfidCardToVehicle, pingVehicleById, removeOptionForVehicle, removeServiceForVehicle };
package/dist/index.mjs CHANGED
@@ -6,9 +6,9 @@ const getModelsById = async (client, id) => {
6
6
  };
7
7
  //#endregion
8
8
  //#region src/getModelAssets.ts
9
- const schema$5 = z.object({ id: z.number().int().positive() });
9
+ const schema$7 = z.object({ id: z.number().int().positive() });
10
10
  const getModelByIdAssets = async (client, id) => {
11
- const result = schema$5.safeParse({ id });
11
+ const result = schema$7.safeParse({ id });
12
12
  if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
13
13
  return client.get(`boapi/proxy/eds/rest_pub/rest/fleets/${client.clientOptions.fleetId}/models/${id}/`).then(({ data }) => data);
14
14
  };
@@ -19,9 +19,9 @@ const getModels = async (client) => {
19
19
  };
20
20
  //#endregion
21
21
  //#region src/getVehicle.ts
22
- const schema$4 = z.object({ id: z.string().trim().min(1).uuid() });
22
+ const schema$6 = z.object({ id: z.string().trim().min(1).uuid() });
23
23
  const getVehicleById = async (client, id) => {
24
- const result = schema$4.safeParse({ id });
24
+ const result = schema$6.safeParse({ id });
25
25
  if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
26
26
  return client.get(`boapi/proxy/user/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.id}`).then(({ data }) => data).catch((error) => {
27
27
  if (error.formattedError?.status === 404) return null;
@@ -29,7 +29,7 @@ const getVehicleById = async (client, id) => {
29
29
  });
30
30
  };
31
31
  const getVehicleRealTimeById = async (client, id) => {
32
- const result = schema$4.safeParse({ id });
32
+ const result = schema$6.safeParse({ id });
33
33
  if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
34
34
  return client.get(`boapi/proxy/fleetmanager/public/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.id}`).then(({ data }) => data).catch((error) => {
35
35
  if (error.formattedError?.status === 404) return null;
@@ -38,9 +38,9 @@ const getVehicleRealTimeById = async (client, id) => {
38
38
  };
39
39
  //#endregion
40
40
  //#region src/getVehicleAssets.ts
41
- const schema$3 = z.object({ id: z.string().uuid() });
41
+ const schema$5 = z.object({ id: z.string().uuid() });
42
42
  const getVehicleByIdAssets = async (client, id) => {
43
- const result = schema$3.safeParse({ id });
43
+ const result = schema$5.safeParse({ id });
44
44
  if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
45
45
  return client.get(`boapi/proxy/eds/rest_pub/rest/fleets/${client.clientOptions.fleetId}/vehicles/${id}/`).then(({ data }) => data);
46
46
  };
@@ -131,14 +131,14 @@ const getVehiclesRealTime = async (client, pageSize = 500, lastUpdatedMillis) =>
131
131
  };
132
132
  //#endregion
133
133
  //#region src/pingVehicle.ts
134
- const schema$2 = z.object({ id: z.string().trim().min(1).uuid() });
134
+ const schema$4 = z.object({ id: z.string().trim().min(1).uuid() });
135
135
  /**
136
136
  * Pings a vehicle to check if it is alive (box connected).
137
137
  * Returns true if alive (HTTP 200), false if box not connected (code 410, codeStr 'carConnectionProblem'),
138
138
  * throws for other errors or invalid id.
139
139
  */
140
140
  const pingVehicleById = async (client, id) => {
141
- const result = schema$2.safeParse({ id });
141
+ const result = schema$4.safeParse({ id });
142
142
  if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
143
143
  try {
144
144
  await client.get(`boapi/proxy/fleetmanager/public/v2/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.id}/ping`);
@@ -150,17 +150,17 @@ const pingVehicleById = async (client, id) => {
150
150
  };
151
151
  //#endregion
152
152
  //#region src/enableVehicle.ts
153
- const schema$1 = z.object({ subStatus: z.string() });
153
+ const schema$3 = z.object({ subStatus: z.string() });
154
154
  const enableVehicle = async (client, vehicleId, payload) => {
155
- const result = schema$1.safeParse(payload);
155
+ const result = schema$3.safeParse(payload);
156
156
  if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
157
157
  return client.post(`boapi/proxy/fleetmanager/public/fleets/${client.clientOptions.fleetId}/vehicles/${vehicleId}/enable`, payload).then(({ data }) => data);
158
158
  };
159
159
  //#endregion
160
160
  //#region src/disableVehicle.ts
161
- const schema = z.object({ subStatus: z.string() });
161
+ const schema$2 = z.object({ subStatus: z.string() });
162
162
  const disableVehicle = async (client, vehicleId, payload) => {
163
- const result = schema.safeParse(payload);
163
+ const result = schema$2.safeParse(payload);
164
164
  if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
165
165
  return client.post(`boapi/proxy/fleetmanager/public/fleets/${client.clientOptions.fleetId}/vehicles/${vehicleId}/disable`, payload).then(({ data }) => data);
166
166
  };
@@ -205,7 +205,8 @@ const createVehicleBodySchema = z.object({
205
205
  msisdn: z.string().max(32).optional(),
206
206
  iccid: z.string().max(32).optional(),
207
207
  imsi: z.string().max(32).optional(),
208
- residualValue: z.number().optional()
208
+ residualValue: z.number().optional(),
209
+ registrationDate: z.string().date().optional()
209
210
  });
210
211
  const createVehicle = async (client, body) => {
211
212
  const result = createVehicleBodySchema.safeParse(body);
@@ -213,6 +214,81 @@ const createVehicle = async (client, body) => {
213
214
  return client.post(`/boapi/proxy/vehicle/fleets/${client.clientOptions.fleetId}/vehicles`, result.data).then(({ data }) => data);
214
215
  };
215
216
  //#endregion
217
+ //#region src/createRfidCard.ts
218
+ const createRfidCardBodySchema = z.object({
219
+ tag: z.string().trim().min(1),
220
+ description: z.string().max(128),
221
+ pinCode: z.string().length(4)
222
+ });
223
+ const createRfidCard = async (client, body) => {
224
+ const result = createRfidCardBodySchema.safeParse(body);
225
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
226
+ return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/vehicles/rfids`, {
227
+ ...result.data,
228
+ fleetId: client.clientOptions.fleetId
229
+ }).then(({ data }) => data);
230
+ };
231
+ //#endregion
232
+ //#region src/getRfidCard.ts
233
+ const schema$1 = z.object({ tag: z.string().trim().min(1) });
234
+ const getRfidCardByTag = async (client, tag) => {
235
+ const result = schema$1.safeParse({ tag });
236
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
237
+ return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/vehicles/rfids/${result.data.tag}`).then(({ data }) => data).catch((error) => {
238
+ if (error.formattedError?.status === 404) return null;
239
+ throw error;
240
+ });
241
+ };
242
+ //#endregion
243
+ //#region src/getRfidCards.ts
244
+ /**
245
+ * Fetches a single page of RFID cards from the API
246
+ * @param client - The AIMA client instance
247
+ * @param page - The page number to fetch
248
+ * @param pageSize - Number of RFID cards per page
249
+ * @returns Promise that resolves to an array of RFID cards for the requested page
250
+ */
251
+ const getRfidCardsPage = async (client, page, pageSize) => {
252
+ return (await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/vehicles/rfids?page=${page}&size=${pageSize}`)).data;
253
+ };
254
+ /**
255
+ * Fetches all RFID cards from the API using pagination
256
+ * @param client - The AIMA client instance
257
+ * @param pageSize - Number of RFID cards per page (default: 500)
258
+ * @returns Promise that resolves to an array of all RFID cards
259
+ * @throws Error if more than 50 pages are required to fetch all RFID cards
260
+ */
261
+ const getRfidCards = async (client, pageSize = 500) => {
262
+ const result = z.object({ pageSize: z.number().min(1).default(500) }).safeParse({ pageSize });
263
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
264
+ const allRfidCards = [];
265
+ let currentPage = 0;
266
+ let hasMorePages = true;
267
+ const MAX_PAGES = 50;
268
+ while (hasMorePages) {
269
+ if (currentPage >= MAX_PAGES) throw new Error(`Maximum page limit (${MAX_PAGES}) reached. This might indicate an issue with the pagination or a very large dataset.`);
270
+ const rfidCards = await getRfidCardsPage(client, currentPage, result.data.pageSize);
271
+ allRfidCards.push(...rfidCards);
272
+ hasMorePages = rfidCards.length === result.data.pageSize;
273
+ currentPage += 1;
274
+ }
275
+ return allRfidCards;
276
+ };
277
+ //#endregion
278
+ //#region src/linkRfidCardToVehicle.ts
279
+ const schema = z.object({
280
+ vehicleId: z.string().trim().min(1).uuid(),
281
+ tag: z.string().trim().min(1)
282
+ });
283
+ const linkRfidCardToVehicle = async (client, vehicleId, tag) => {
284
+ const result = schema.safeParse({
285
+ vehicleId,
286
+ tag
287
+ });
288
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
289
+ return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.vehicleId}/rfids/${result.data.tag}`).then(({ data }) => data);
290
+ };
291
+ //#endregion
216
292
  //#region src/vehicleService.ts
217
293
  const uuidSchema$1 = z.string().trim().min(1).uuid();
218
294
  const addServiceForVehicle = async (client, serviceId, vehicleId) => {
@@ -249,4 +325,4 @@ const removeOptionForVehicle = async (client, vehicleId, optionId) => {
249
325
  return client.delete(`/boapi/proxy/vehicle/fleets/${client.clientOptions.fleetId}/vehicles/${parsedVehicleId.data}/options/${parsedOptionId.data}`).then(({ data }) => data);
250
326
  };
251
327
  //#endregion
252
- export { addOptionForVehicle, addServiceForVehicle, createVehicle, disableVehicle, enableVehicle, getModelByIdAssets, getModelVehicles, getModels, getModelsById, getOptions, getVehicleById, getVehicleByIdAssets, getVehicleRealTimeById, getVehicles, getVehiclesRealTime, pingVehicleById, removeOptionForVehicle, removeServiceForVehicle };
328
+ export { addOptionForVehicle, addServiceForVehicle, createRfidCard, createVehicle, disableVehicle, enableVehicle, getModelByIdAssets, getModelVehicles, getModels, getModelsById, getOptions, getRfidCardByTag, getRfidCards, getVehicleById, getVehicleByIdAssets, getVehicleRealTimeById, getVehicles, getVehiclesRealTime, linkRfidCardToVehicle, 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.48",
4
+ "version": "1.2.49",
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.48",
36
- "@vulog/aima-core": "1.2.48"
35
+ "@vulog/aima-client": "1.2.49",
36
+ "@vulog/aima-core": "1.2.49"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "zod": "^4.3.6"
@@ -0,0 +1,30 @@
1
+ import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
3
+
4
+ import { RfidCard } from './types';
5
+
6
+ export type CreateRfidCardBody = {
7
+ tag: string;
8
+ description: string;
9
+ pinCode: string;
10
+ };
11
+
12
+ const createRfidCardBodySchema = z.object({
13
+ tag: z.string().trim().min(1),
14
+ description: z.string().max(128),
15
+ pinCode: z.string().length(4),
16
+ });
17
+
18
+ export const createRfidCard = async (client: Client, body: CreateRfidCardBody): Promise<RfidCard> => {
19
+ const result = createRfidCardBodySchema.safeParse(body);
20
+ if (!result.success) {
21
+ throw new TypeError('Invalid args', { cause: result.error.issues });
22
+ }
23
+
24
+ return client
25
+ .post<RfidCard>(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/vehicles/rfids`, {
26
+ ...result.data,
27
+ fleetId: client.clientOptions.fleetId,
28
+ })
29
+ .then(({ data }) => data);
30
+ };
@@ -85,4 +85,20 @@ describe('createVehicle', () => {
85
85
  const body = { vin: 'VIN123', plate: 'AB-123', name: 'Test' } as CreateVehicleBody;
86
86
  await expect(createVehicle(client, body)).rejects.toThrow(TypeError);
87
87
  });
88
+
89
+ test('should throw for invalid registrationDate', async () => {
90
+ const body = { ...validBody, registrationDate: 'not-a-date' };
91
+ await expect(createVehicle(client, body)).rejects.toThrow(TypeError);
92
+ });
93
+
94
+ test('should create a vehicle with valid registrationDate', async () => {
95
+ const body = { ...validBody, registrationDate: '2026-06-15' };
96
+ const mockResponse = { id: 'vehicle-uuid', ...body };
97
+ postMock.mockResolvedValueOnce({ data: mockResponse });
98
+
99
+ const result = await createVehicle(client, body);
100
+
101
+ expect(result).toEqual(mockResponse);
102
+ expect(postMock).toHaveBeenCalledWith('/boapi/proxy/vehicle/fleets/FLEET_ID/vehicles', body);
103
+ });
88
104
  });
@@ -18,6 +18,7 @@ export type CreateVehicleBody = {
18
18
  iccid?: string;
19
19
  imsi?: string;
20
20
  residualValue?: number;
21
+ registrationDate?: string;
21
22
  };
22
23
 
23
24
  const createVehicleBodySchema = z.object({
@@ -35,6 +36,7 @@ const createVehicleBodySchema = z.object({
35
36
  iccid: z.string().max(32).optional(),
36
37
  imsi: z.string().max(32).optional(),
37
38
  residualValue: z.number().optional(),
39
+ registrationDate: z.string().date().optional(),
38
40
  });
39
41
 
40
42
  export const createVehicle = async (client: Client, body: CreateVehicleBody): Promise<Vehicle> => {
@@ -0,0 +1,27 @@
1
+ import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
3
+
4
+ import { RfidCard } from './types';
5
+
6
+ const schema = z.object({
7
+ tag: z.string().trim().min(1),
8
+ });
9
+
10
+ export const getRfidCardByTag = async (client: Client, tag: string): Promise<RfidCard | null> => {
11
+ const result = schema.safeParse({ tag });
12
+ if (!result.success) {
13
+ throw new TypeError('Invalid args', {
14
+ cause: result.error.issues,
15
+ });
16
+ }
17
+
18
+ return client
19
+ .get<RfidCard>(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/vehicles/rfids/${result.data.tag}`)
20
+ .then(({ data }) => data)
21
+ .catch((error) => {
22
+ if (error.formattedError?.status === 404) {
23
+ return null;
24
+ }
25
+ throw error;
26
+ });
27
+ };
@@ -0,0 +1,58 @@
1
+ import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
3
+
4
+ import { RfidCard } from './types';
5
+
6
+ /**
7
+ * Fetches a single page of RFID cards from the API
8
+ * @param client - The AIMA client instance
9
+ * @param page - The page number to fetch
10
+ * @param pageSize - Number of RFID cards per page
11
+ * @returns Promise that resolves to an array of RFID cards for the requested page
12
+ */
13
+ const getRfidCardsPage = async (client: Client, page: number, pageSize: number): Promise<RfidCard[]> => {
14
+ const response = await client.get<RfidCard[]>(
15
+ `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/vehicles/rfids?page=${page}&size=${pageSize}`
16
+ );
17
+ return response.data;
18
+ };
19
+
20
+ /**
21
+ * Fetches all RFID cards from the API using pagination
22
+ * @param client - The AIMA client instance
23
+ * @param pageSize - Number of RFID cards per page (default: 500)
24
+ * @returns Promise that resolves to an array of all RFID cards
25
+ * @throws Error if more than 50 pages are required to fetch all RFID cards
26
+ */
27
+ export const getRfidCards = async (client: Client, pageSize = 500): Promise<RfidCard[]> => {
28
+ const schema = z.object({
29
+ pageSize: z.number().min(1).default(500),
30
+ });
31
+ const result = schema.safeParse({ pageSize });
32
+ if (!result.success) {
33
+ throw new TypeError('Invalid args', {
34
+ cause: result.error.issues,
35
+ });
36
+ }
37
+ const allRfidCards: RfidCard[] = [];
38
+ let currentPage = 0;
39
+ let hasMorePages = true;
40
+ const MAX_PAGES = 50;
41
+
42
+ while (hasMorePages) {
43
+ if (currentPage >= MAX_PAGES) {
44
+ throw new Error(
45
+ `Maximum page limit (${MAX_PAGES}) reached. This might indicate an issue with the pagination or a very large dataset.`
46
+ );
47
+ }
48
+
49
+ const rfidCards = await getRfidCardsPage(client, currentPage, result.data.pageSize);
50
+ allRfidCards.push(...rfidCards);
51
+
52
+ // Stop if we received fewer RFID cards than the page size (including 0)
53
+ hasMorePages = rfidCards.length === result.data.pageSize;
54
+ currentPage += 1;
55
+ }
56
+
57
+ return allRfidCards;
58
+ };
package/src/index.ts CHANGED
@@ -10,6 +10,10 @@ export * from './enableVehicle';
10
10
  export * from './disableVehicle';
11
11
  export * from './getModelVehicles';
12
12
  export * from './createVehicle';
13
+ export * from './createRfidCard';
14
+ export * from './getRfidCard';
15
+ export * from './getRfidCards';
16
+ export * from './linkRfidCardToVehicle';
13
17
  export * from './vehicleService';
14
18
  export * from './getOptions';
15
19
  export * from './vehicleOption';
@@ -0,0 +1,22 @@
1
+ import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
3
+
4
+ import { RfidCard } from './types';
5
+
6
+ const schema = z.object({
7
+ vehicleId: z.string().trim().min(1).uuid(),
8
+ tag: z.string().trim().min(1),
9
+ });
10
+
11
+ export const linkRfidCardToVehicle = async (client: Client, vehicleId: string, tag: string): Promise<RfidCard> => {
12
+ const result = schema.safeParse({ vehicleId, tag });
13
+ if (!result.success) {
14
+ throw new TypeError('Invalid args', { cause: result.error.issues });
15
+ }
16
+
17
+ return client
18
+ .post<RfidCard>(
19
+ `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.vehicleId}/rfids/${result.data.tag}`
20
+ )
21
+ .then(({ data }) => data);
22
+ };
package/src/types.ts CHANGED
@@ -57,6 +57,8 @@ export type Vehicle = {
57
57
  options: Options[];
58
58
  /** Date when the vehicle was created */
59
59
  createDate: string;
60
+ /** Date when the vehicle was registered */
61
+ registrationDate?: string;
60
62
  /** Date when the vehicle was last updated */
61
63
  updateDate: string;
62
64
  /** ID of the fleet this vehicle belongs to */
@@ -97,6 +99,16 @@ export type Options = {
97
99
  [key: string]: any;
98
100
  };
99
101
 
102
+ export type RfidCard = {
103
+ tag: string;
104
+ description: string;
105
+ fleetId: string;
106
+ pinCode: string;
107
+ vehicleId?: string;
108
+ updateDate?: string;
109
+ [key: string]: any;
110
+ };
111
+
100
112
  export type Zone = {
101
113
  type: string;
102
114
  version: number;