@vulog/aima-booking 1.2.34 → 1.2.35
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 +82 -6
- package/dist/index.d.cts +125 -1
- package/dist/index.d.mts +125 -1
- package/dist/index.mjs +77 -7
- package/package.json +3 -3
- package/src/getAdditionalDrivers.test.ts +61 -0
- package/src/getAdditionalDrivers.ts +23 -0
- package/src/getAvailableVehicles.test.ts +53 -0
- package/src/getBookingRequest.test.ts +72 -1
- package/src/getBookingRequest.ts +15 -1
- package/src/getDigitalContracts.test.ts +72 -0
- package/src/getDigitalContracts.ts +26 -0
- package/src/getSlaves.test.ts +60 -0
- package/src/getSlaves.ts +24 -0
- package/src/getSubscriptionsByUserId.test.ts +96 -0
- package/src/getSubscriptionsByUserId.ts +27 -0
- package/src/index.ts +11 -1
- package/src/submitCancellationRequest.test.ts +81 -0
- package/src/submitCancellationRequest.ts +38 -0
- package/src/types.ts +117 -0
package/dist/index.cjs
CHANGED
|
@@ -172,6 +172,11 @@ const getSubscriptionBookingRequestById = async (client, id) => {
|
|
|
172
172
|
...data
|
|
173
173
|
}));
|
|
174
174
|
};
|
|
175
|
+
const getScheduledBookingById = async (client, bookingId) => {
|
|
176
|
+
const result = zod.z.string().trim().min(1).uuid().safeParse(bookingId);
|
|
177
|
+
if (!result.success) throw new TypeError("Invalid bookingId", { cause: result.error.issues });
|
|
178
|
+
return client.get(`/boapi/proxy/user/scheduledBooking/by-service/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingId}`).then(({ data }) => data);
|
|
179
|
+
};
|
|
175
180
|
//#endregion
|
|
176
181
|
//#region src/getAvailableVehicles.ts
|
|
177
182
|
/** ISO date-time without milliseconds (e.g. 2025-02-10T12:00:00Z or 2025-02-10T12:00:00+01:00). */
|
|
@@ -352,7 +357,7 @@ const deallocateVehicle = async (client, bookingRequestId, vehicleId) => {
|
|
|
352
357
|
};
|
|
353
358
|
//#endregion
|
|
354
359
|
//#region src/updateScheduleBooking.ts
|
|
355
|
-
const schema$
|
|
360
|
+
const schema$7 = zod.default.object({
|
|
356
361
|
id: zod.default.string(),
|
|
357
362
|
startDate: zod.default.string().refine((date) => !Number.isNaN(Date.parse(date)), { message: "Invalid date" }).optional(),
|
|
358
363
|
latitude: zod.default.number().min(-90).max(90).optional(),
|
|
@@ -374,7 +379,7 @@ const schema$2 = zod.default.object({
|
|
|
374
379
|
plannedReturnDate: zod.default.string().refine((date) => !Number.isNaN(Date.parse(date)), { message: "Invalid date" }).optional()
|
|
375
380
|
});
|
|
376
381
|
const updateScheduleBooking = async (client, bookingRequestId, updateData) => {
|
|
377
|
-
const result = schema$
|
|
382
|
+
const result = schema$7.safeParse({
|
|
378
383
|
id: bookingRequestId,
|
|
379
384
|
...updateData
|
|
380
385
|
});
|
|
@@ -410,9 +415,9 @@ const triggerBRPayment = async (client, bookingRequestId, body) => {
|
|
|
410
415
|
};
|
|
411
416
|
//#endregion
|
|
412
417
|
//#region src/getBookingRequestsByUserId.ts
|
|
413
|
-
const schema$
|
|
418
|
+
const schema$6 = zod.z.object({ userId: zod.z.string().trim().min(1).uuid() });
|
|
414
419
|
const getBookingRequestsByUserId = async (client, userId) => {
|
|
415
|
-
const result = schema$
|
|
420
|
+
const result = schema$6.safeParse({ userId });
|
|
416
421
|
if (!result.success) throw new TypeError("Invalid userId", { cause: result.error.issues });
|
|
417
422
|
return client.get(`/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/users/${userId}`).then(({ data }) => data).catch((error) => {
|
|
418
423
|
if (error.formattedError?.status === 404) return [];
|
|
@@ -437,15 +442,80 @@ const releaseBRPayment = async (client, bookingRequestId, pspReference) => {
|
|
|
437
442
|
};
|
|
438
443
|
//#endregion
|
|
439
444
|
//#region src/cancelBookingRequest.ts
|
|
440
|
-
const schema = zod.default.object({ id: zod.default.string().uuid() });
|
|
445
|
+
const schema$5 = zod.default.object({ id: zod.default.string().uuid() });
|
|
441
446
|
const cancelBookingRequest = async (client, id) => {
|
|
442
|
-
const result = schema.safeParse({ id });
|
|
447
|
+
const result = schema$5.safeParse({ id });
|
|
443
448
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
444
449
|
return client.post(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/cancel/${id}`, {}).then(({ data }) => data).catch((error) => {
|
|
445
450
|
throw new TypeError("Failed to cancel booking request", { cause: error });
|
|
446
451
|
});
|
|
447
452
|
};
|
|
448
453
|
//#endregion
|
|
454
|
+
//#region src/getDigitalContracts.ts
|
|
455
|
+
const schema$4 = zod.z.object({ bookingId: zod.z.string().trim().min(1) });
|
|
456
|
+
const getDigitalContracts = async (client, bookingId, status = "SIGNED") => {
|
|
457
|
+
const result = schema$4.safeParse({ bookingId });
|
|
458
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
459
|
+
return client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/subscription/bookingrequests/${result.data.bookingId}/digitalContracts?status=${encodeURIComponent(status)}`).then(({ data }) => data);
|
|
460
|
+
};
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region src/getAdditionalDrivers.ts
|
|
463
|
+
const schema$3 = zod.z.object({ parentId: zod.z.string().trim().min(1) });
|
|
464
|
+
const getAdditionalDrivers = async (client, parentId) => {
|
|
465
|
+
const result = schema$3.safeParse({ parentId });
|
|
466
|
+
if (!result.success) throw new TypeError("Invalid parentId", { cause: result.error.issues });
|
|
467
|
+
return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/bookingrequests/${parentId}/additionalDrivers`).then(({ data }) => data);
|
|
468
|
+
};
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region src/getSlaves.ts
|
|
471
|
+
const schema$2 = zod.z.object({
|
|
472
|
+
parentId: zod.z.string().trim().min(1),
|
|
473
|
+
status: zod.z.enum(["ONGOING, COMPLETED", "UPCOMING"])
|
|
474
|
+
});
|
|
475
|
+
const getSlaves = async (client, parentId, status) => {
|
|
476
|
+
const result = schema$2.safeParse({
|
|
477
|
+
parentId,
|
|
478
|
+
status
|
|
479
|
+
});
|
|
480
|
+
if (!result.success) throw new TypeError("Invalid bookingId", { cause: result.error.issues });
|
|
481
|
+
return client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/subscription/bookingRequests/${parentId}/bookingRequestsSlave?bookingStatus=${status}`).then(({ data }) => data);
|
|
482
|
+
};
|
|
483
|
+
//#endregion
|
|
484
|
+
//#region src/getSubscriptionsByUserId.ts
|
|
485
|
+
const schema$1 = zod.z.object({
|
|
486
|
+
userId: zod.z.string().trim().min(1).uuid(),
|
|
487
|
+
active: zod.z.boolean().optional().default(true)
|
|
488
|
+
});
|
|
489
|
+
const getSubscriptionsByUserId = async (client, userId, active = true) => {
|
|
490
|
+
const result = schema$1.safeParse({
|
|
491
|
+
userId,
|
|
492
|
+
active
|
|
493
|
+
});
|
|
494
|
+
if (!result.success) throw new TypeError("Invalid userId", { cause: result.error.issues });
|
|
495
|
+
return client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/subscription/users/${userId}/${active ? "active" : "past"}`).then(({ data }) => data);
|
|
496
|
+
};
|
|
497
|
+
//#endregion
|
|
498
|
+
//#region src/submitCancellationRequest.ts
|
|
499
|
+
const schema = zod.z.object({
|
|
500
|
+
bookingRequestId: zod.z.string().uuid(),
|
|
501
|
+
userId: zod.z.string().uuid()
|
|
502
|
+
});
|
|
503
|
+
const submitCancellationRequest = async (client, bookingRequestId, userId) => {
|
|
504
|
+
const result = schema.safeParse({
|
|
505
|
+
bookingRequestId,
|
|
506
|
+
userId
|
|
507
|
+
});
|
|
508
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
509
|
+
return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/actions`, {
|
|
510
|
+
action: "EARLIER_CANCELLATION_REQUEST",
|
|
511
|
+
bookingStatusBO: "ONGOING",
|
|
512
|
+
status: "PENDING",
|
|
513
|
+
userId
|
|
514
|
+
}).then(({ data }) => data).catch((error) => {
|
|
515
|
+
throw new TypeError("Failed to submit cancellation request", { cause: error });
|
|
516
|
+
});
|
|
517
|
+
};
|
|
518
|
+
//#endregion
|
|
449
519
|
//#region src/createSubscription.ts
|
|
450
520
|
const createSubscriptionBodySchema = zod.z.object({
|
|
451
521
|
userId: zod.z.string().trim().min(1).uuid(),
|
|
@@ -479,17 +549,23 @@ exports.allocateVehicle = allocateVehicle;
|
|
|
479
549
|
exports.cancelBookingRequest = cancelBookingRequest;
|
|
480
550
|
exports.createSubscription = createSubscription;
|
|
481
551
|
exports.deallocateVehicle = deallocateVehicle;
|
|
552
|
+
exports.getAdditionalDrivers = getAdditionalDrivers;
|
|
482
553
|
exports.getAvailableVehicles = getAvailableVehicles;
|
|
483
554
|
exports.getBookingRequestById = getBookingRequestById;
|
|
484
555
|
exports.getBookingRequestByTrip = getBookingRequestByTrip;
|
|
485
556
|
exports.getBookingRequests = getBookingRequests;
|
|
486
557
|
exports.getBookingRequestsByUserId = getBookingRequestsByUserId;
|
|
558
|
+
exports.getDigitalContracts = getDigitalContracts;
|
|
487
559
|
exports.getSATBookingRequests = getSATBookingRequests;
|
|
488
560
|
exports.getScheduleBookingRequests = getScheduleBookingRequests;
|
|
561
|
+
exports.getScheduledBookingById = getScheduledBookingById;
|
|
562
|
+
exports.getSlaves = getSlaves;
|
|
489
563
|
exports.getStationById = getStationById;
|
|
490
564
|
exports.getStations = getStations;
|
|
491
565
|
exports.getSubscriptionBookingRequestById = getSubscriptionBookingRequestById;
|
|
492
566
|
exports.getSubscriptionBookingRequests = getSubscriptionBookingRequests;
|
|
567
|
+
exports.getSubscriptionsByUserId = getSubscriptionsByUserId;
|
|
493
568
|
exports.releaseBRPayment = releaseBRPayment;
|
|
569
|
+
exports.submitCancellationRequest = submitCancellationRequest;
|
|
494
570
|
exports.triggerBRPayment = triggerBRPayment;
|
|
495
571
|
exports.updateScheduleBooking = updateScheduleBooking;
|
package/dist/index.d.cts
CHANGED
|
@@ -209,6 +209,114 @@ type AvailableVehiclesResponse = {
|
|
|
209
209
|
stationId: string;
|
|
210
210
|
vehicles: Vehicle[];
|
|
211
211
|
};
|
|
212
|
+
type Slave = {
|
|
213
|
+
previous: string | null;
|
|
214
|
+
compositeStatus: string;
|
|
215
|
+
id: string;
|
|
216
|
+
startDate: string;
|
|
217
|
+
endDate: string;
|
|
218
|
+
profileId: string;
|
|
219
|
+
vehicleId: string;
|
|
220
|
+
modelId: number;
|
|
221
|
+
journeyId: string;
|
|
222
|
+
station: string;
|
|
223
|
+
status: string;
|
|
224
|
+
creationDate: string;
|
|
225
|
+
returnedDate: null;
|
|
226
|
+
serviceId: string;
|
|
227
|
+
pricingId: null;
|
|
228
|
+
plannedReturnDate: string | null;
|
|
229
|
+
cancellationDate: string | null;
|
|
230
|
+
rollingContract: boolean;
|
|
231
|
+
planDurationInMonths: number;
|
|
232
|
+
planName: string | null;
|
|
233
|
+
contractType: 'MVS' | 'SVS';
|
|
234
|
+
bookingReferenceId: string;
|
|
235
|
+
};
|
|
236
|
+
interface IFormatSlave extends Slave {
|
|
237
|
+
traveledDistance: number | null;
|
|
238
|
+
realStartDate?: string | null;
|
|
239
|
+
cancellationRequestOutDTO?: {
|
|
240
|
+
status: string;
|
|
241
|
+
action: string;
|
|
242
|
+
};
|
|
243
|
+
manualApproval: {
|
|
244
|
+
status: string;
|
|
245
|
+
action: string;
|
|
246
|
+
} | undefined;
|
|
247
|
+
from: 'ONGOING' | 'UPCOMING' | 'COMPLETED';
|
|
248
|
+
}
|
|
249
|
+
type Master = {
|
|
250
|
+
bookingReferenceId: string;
|
|
251
|
+
cancellationDate: string | null;
|
|
252
|
+
cityId: string | null;
|
|
253
|
+
contractType: 'MVS' | 'SVS';
|
|
254
|
+
creationDate: string;
|
|
255
|
+
customPrice: number | null;
|
|
256
|
+
deliveryAddress: string | null;
|
|
257
|
+
deliveryAddressAdditionalInfo: string | null;
|
|
258
|
+
deliveryCity: string | null;
|
|
259
|
+
deliveryPostalCode: string | null;
|
|
260
|
+
endDate: string;
|
|
261
|
+
fleetId: string;
|
|
262
|
+
id: string;
|
|
263
|
+
journeyId: string;
|
|
264
|
+
modelId: number;
|
|
265
|
+
parentId: string;
|
|
266
|
+
planDurationInMonths: number;
|
|
267
|
+
planName: string;
|
|
268
|
+
plannedReturnDate: string | null;
|
|
269
|
+
pricingId: string | null;
|
|
270
|
+
previous: string | null;
|
|
271
|
+
products: string[];
|
|
272
|
+
profileId: string;
|
|
273
|
+
returnedDate: string | null;
|
|
274
|
+
rollingContract: boolean;
|
|
275
|
+
serviceId: string;
|
|
276
|
+
startDate: string;
|
|
277
|
+
station: string;
|
|
278
|
+
status: string;
|
|
279
|
+
vehicleId: string;
|
|
280
|
+
userId: string;
|
|
281
|
+
};
|
|
282
|
+
interface IFormatSubscription extends Master {
|
|
283
|
+
slaves: {
|
|
284
|
+
ongoing: IFormatSlave[];
|
|
285
|
+
upcoming: IFormatSlave[];
|
|
286
|
+
completed: IFormatSlave[];
|
|
287
|
+
};
|
|
288
|
+
cancellationRequestStatus?: string;
|
|
289
|
+
}
|
|
290
|
+
type Contract = {
|
|
291
|
+
id: string;
|
|
292
|
+
status: 'SIGNED';
|
|
293
|
+
provider: 'DOCUSIGN';
|
|
294
|
+
creationDate: string;
|
|
295
|
+
profileId: string;
|
|
296
|
+
externalContractId: string;
|
|
297
|
+
type: string;
|
|
298
|
+
};
|
|
299
|
+
type AdditionalDriver = {
|
|
300
|
+
id: string;
|
|
301
|
+
fleetId: string;
|
|
302
|
+
bookingRequestId: string;
|
|
303
|
+
profileId: string;
|
|
304
|
+
updateDate: string;
|
|
305
|
+
invitationEmail: string;
|
|
306
|
+
profileStatus: string;
|
|
307
|
+
userId: string;
|
|
308
|
+
};
|
|
309
|
+
type BookingRequestSlave = {
|
|
310
|
+
id: string;
|
|
311
|
+
vehicleId: string;
|
|
312
|
+
modelId: number;
|
|
313
|
+
startDate: string;
|
|
314
|
+
endDate: string;
|
|
315
|
+
tripId: string;
|
|
316
|
+
parentId: string;
|
|
317
|
+
traveledDistance: number;
|
|
318
|
+
energyLevelEnd: number;
|
|
319
|
+
};
|
|
212
320
|
//#endregion
|
|
213
321
|
//#region src/getBookingRequests.d.ts
|
|
214
322
|
declare const BookingRequestStatusSchema: z.ZodEnum<["ALERT", "UPCOMING", "ONGOING", "COMPLETED", "CANCELLED", "PENDING_APPROVAL", "CONFIRMED", "PENDING", "LATE"]>;
|
|
@@ -253,6 +361,7 @@ declare const getSATBookingRequests: (client: Client, status: SATBookingRequestS
|
|
|
253
361
|
declare const getBookingRequestById: (client: Client, id: string) => Promise<BookingRequest>;
|
|
254
362
|
declare const getBookingRequestByTrip: (client: Client, tripId: string) => Promise<BookingRequest>;
|
|
255
363
|
declare const getSubscriptionBookingRequestById: (client: Client, id: string) => Promise<BookingRequest>;
|
|
364
|
+
declare const getScheduledBookingById: (client: Client, bookingId: string) => Promise<SATBookingRequest>;
|
|
256
365
|
//#endregion
|
|
257
366
|
//#region src/getAvailableVehicles.d.ts
|
|
258
367
|
declare const getAvailableVehicles: (client: Client, stationId: string, startDate: string) => Promise<AvailableVehiclesResponse>;
|
|
@@ -359,6 +468,21 @@ declare const releaseBRPayment: (client: Client, bookingRequestId: UUID, pspRefe
|
|
|
359
468
|
//#region src/cancelBookingRequest.d.ts
|
|
360
469
|
declare const cancelBookingRequest: (client: Client, id: string) => Promise<SATBookingRequest>;
|
|
361
470
|
//#endregion
|
|
471
|
+
//#region src/getDigitalContracts.d.ts
|
|
472
|
+
declare const getDigitalContracts: (client: Client, bookingId: string, status?: string) => Promise<Contract[]>;
|
|
473
|
+
//#endregion
|
|
474
|
+
//#region src/getAdditionalDrivers.d.ts
|
|
475
|
+
declare const getAdditionalDrivers: (client: Client, parentId: string) => Promise<AdditionalDriver[]>;
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/getSlaves.d.ts
|
|
478
|
+
declare const getSlaves: (client: Client, parentId: string, status: string) => Promise<BookingRequestSlave[]>;
|
|
479
|
+
//#endregion
|
|
480
|
+
//#region src/getSubscriptionsByUserId.d.ts
|
|
481
|
+
declare const getSubscriptionsByUserId: (client: Client, userId: string, active?: boolean) => Promise<Master[]>;
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/submitCancellationRequest.d.ts
|
|
484
|
+
declare const submitCancellationRequest: (client: Client, bookingRequestId: string, userId: string) => Promise<SATBookingRequest>;
|
|
485
|
+
//#endregion
|
|
362
486
|
//#region src/createSubscription.d.ts
|
|
363
487
|
type CreateSubscriptionBody = {
|
|
364
488
|
userId: string;
|
|
@@ -384,4 +508,4 @@ type CreateSubscriptionBody = {
|
|
|
384
508
|
};
|
|
385
509
|
declare const createSubscription: (client: Client, body: CreateSubscriptionBody) => Promise<BookingRequest>;
|
|
386
510
|
//#endregion
|
|
387
|
-
export { AvailableVehiclesResponse, BRPaymentItem, BaseBookingRequest, BookingCredit, BookingRequest, type BookingRequestFilters, type BookingRequestStatus, type CreateSubscriptionBody, CustomPrice, DayOpeningHours, Days, GeoInfo, type Include, type IncludeStation, OpeningHours, PaymentReceipts, PreferredPaymentMethod, SATBookingRequest, type SATBookingRequestStatus, Service, ServiceInfo, type ServiceType, Station, Timetable, TriggerBRPaymentResponse, Vehicle, allocateVehicle, cancelBookingRequest, createSubscription, deallocateVehicle, getAvailableVehicles, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getBookingRequestsByUserId, getSATBookingRequests, getScheduleBookingRequests, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests, releaseBRPayment, triggerBRPayment, updateScheduleBooking };
|
|
511
|
+
export { AdditionalDriver, AvailableVehiclesResponse, BRPaymentItem, BaseBookingRequest, BookingCredit, BookingRequest, type BookingRequestFilters, BookingRequestSlave, type BookingRequestStatus, Contract, type CreateSubscriptionBody, CustomPrice, DayOpeningHours, Days, GeoInfo, IFormatSlave, IFormatSubscription, type Include, type IncludeStation, Master, OpeningHours, PaymentReceipts, PreferredPaymentMethod, SATBookingRequest, type SATBookingRequestStatus, Service, ServiceInfo, type ServiceType, Slave, Station, Timetable, TriggerBRPaymentResponse, Vehicle, allocateVehicle, cancelBookingRequest, createSubscription, deallocateVehicle, getAdditionalDrivers, getAvailableVehicles, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getBookingRequestsByUserId, getDigitalContracts, getSATBookingRequests, getScheduleBookingRequests, getScheduledBookingById, getSlaves, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests, getSubscriptionsByUserId, releaseBRPayment, submitCancellationRequest, triggerBRPayment, updateScheduleBooking };
|
package/dist/index.d.mts
CHANGED
|
@@ -209,6 +209,114 @@ type AvailableVehiclesResponse = {
|
|
|
209
209
|
stationId: string;
|
|
210
210
|
vehicles: Vehicle[];
|
|
211
211
|
};
|
|
212
|
+
type Slave = {
|
|
213
|
+
previous: string | null;
|
|
214
|
+
compositeStatus: string;
|
|
215
|
+
id: string;
|
|
216
|
+
startDate: string;
|
|
217
|
+
endDate: string;
|
|
218
|
+
profileId: string;
|
|
219
|
+
vehicleId: string;
|
|
220
|
+
modelId: number;
|
|
221
|
+
journeyId: string;
|
|
222
|
+
station: string;
|
|
223
|
+
status: string;
|
|
224
|
+
creationDate: string;
|
|
225
|
+
returnedDate: null;
|
|
226
|
+
serviceId: string;
|
|
227
|
+
pricingId: null;
|
|
228
|
+
plannedReturnDate: string | null;
|
|
229
|
+
cancellationDate: string | null;
|
|
230
|
+
rollingContract: boolean;
|
|
231
|
+
planDurationInMonths: number;
|
|
232
|
+
planName: string | null;
|
|
233
|
+
contractType: 'MVS' | 'SVS';
|
|
234
|
+
bookingReferenceId: string;
|
|
235
|
+
};
|
|
236
|
+
interface IFormatSlave extends Slave {
|
|
237
|
+
traveledDistance: number | null;
|
|
238
|
+
realStartDate?: string | null;
|
|
239
|
+
cancellationRequestOutDTO?: {
|
|
240
|
+
status: string;
|
|
241
|
+
action: string;
|
|
242
|
+
};
|
|
243
|
+
manualApproval: {
|
|
244
|
+
status: string;
|
|
245
|
+
action: string;
|
|
246
|
+
} | undefined;
|
|
247
|
+
from: 'ONGOING' | 'UPCOMING' | 'COMPLETED';
|
|
248
|
+
}
|
|
249
|
+
type Master = {
|
|
250
|
+
bookingReferenceId: string;
|
|
251
|
+
cancellationDate: string | null;
|
|
252
|
+
cityId: string | null;
|
|
253
|
+
contractType: 'MVS' | 'SVS';
|
|
254
|
+
creationDate: string;
|
|
255
|
+
customPrice: number | null;
|
|
256
|
+
deliveryAddress: string | null;
|
|
257
|
+
deliveryAddressAdditionalInfo: string | null;
|
|
258
|
+
deliveryCity: string | null;
|
|
259
|
+
deliveryPostalCode: string | null;
|
|
260
|
+
endDate: string;
|
|
261
|
+
fleetId: string;
|
|
262
|
+
id: string;
|
|
263
|
+
journeyId: string;
|
|
264
|
+
modelId: number;
|
|
265
|
+
parentId: string;
|
|
266
|
+
planDurationInMonths: number;
|
|
267
|
+
planName: string;
|
|
268
|
+
plannedReturnDate: string | null;
|
|
269
|
+
pricingId: string | null;
|
|
270
|
+
previous: string | null;
|
|
271
|
+
products: string[];
|
|
272
|
+
profileId: string;
|
|
273
|
+
returnedDate: string | null;
|
|
274
|
+
rollingContract: boolean;
|
|
275
|
+
serviceId: string;
|
|
276
|
+
startDate: string;
|
|
277
|
+
station: string;
|
|
278
|
+
status: string;
|
|
279
|
+
vehicleId: string;
|
|
280
|
+
userId: string;
|
|
281
|
+
};
|
|
282
|
+
interface IFormatSubscription extends Master {
|
|
283
|
+
slaves: {
|
|
284
|
+
ongoing: IFormatSlave[];
|
|
285
|
+
upcoming: IFormatSlave[];
|
|
286
|
+
completed: IFormatSlave[];
|
|
287
|
+
};
|
|
288
|
+
cancellationRequestStatus?: string;
|
|
289
|
+
}
|
|
290
|
+
type Contract = {
|
|
291
|
+
id: string;
|
|
292
|
+
status: 'SIGNED';
|
|
293
|
+
provider: 'DOCUSIGN';
|
|
294
|
+
creationDate: string;
|
|
295
|
+
profileId: string;
|
|
296
|
+
externalContractId: string;
|
|
297
|
+
type: string;
|
|
298
|
+
};
|
|
299
|
+
type AdditionalDriver = {
|
|
300
|
+
id: string;
|
|
301
|
+
fleetId: string;
|
|
302
|
+
bookingRequestId: string;
|
|
303
|
+
profileId: string;
|
|
304
|
+
updateDate: string;
|
|
305
|
+
invitationEmail: string;
|
|
306
|
+
profileStatus: string;
|
|
307
|
+
userId: string;
|
|
308
|
+
};
|
|
309
|
+
type BookingRequestSlave = {
|
|
310
|
+
id: string;
|
|
311
|
+
vehicleId: string;
|
|
312
|
+
modelId: number;
|
|
313
|
+
startDate: string;
|
|
314
|
+
endDate: string;
|
|
315
|
+
tripId: string;
|
|
316
|
+
parentId: string;
|
|
317
|
+
traveledDistance: number;
|
|
318
|
+
energyLevelEnd: number;
|
|
319
|
+
};
|
|
212
320
|
//#endregion
|
|
213
321
|
//#region src/getBookingRequests.d.ts
|
|
214
322
|
declare const BookingRequestStatusSchema: z.ZodEnum<["ALERT", "UPCOMING", "ONGOING", "COMPLETED", "CANCELLED", "PENDING_APPROVAL", "CONFIRMED", "PENDING", "LATE"]>;
|
|
@@ -253,6 +361,7 @@ declare const getSATBookingRequests: (client: Client, status: SATBookingRequestS
|
|
|
253
361
|
declare const getBookingRequestById: (client: Client, id: string) => Promise<BookingRequest>;
|
|
254
362
|
declare const getBookingRequestByTrip: (client: Client, tripId: string) => Promise<BookingRequest>;
|
|
255
363
|
declare const getSubscriptionBookingRequestById: (client: Client, id: string) => Promise<BookingRequest>;
|
|
364
|
+
declare const getScheduledBookingById: (client: Client, bookingId: string) => Promise<SATBookingRequest>;
|
|
256
365
|
//#endregion
|
|
257
366
|
//#region src/getAvailableVehicles.d.ts
|
|
258
367
|
declare const getAvailableVehicles: (client: Client, stationId: string, startDate: string) => Promise<AvailableVehiclesResponse>;
|
|
@@ -359,6 +468,21 @@ declare const releaseBRPayment: (client: Client, bookingRequestId: UUID, pspRefe
|
|
|
359
468
|
//#region src/cancelBookingRequest.d.ts
|
|
360
469
|
declare const cancelBookingRequest: (client: Client, id: string) => Promise<SATBookingRequest>;
|
|
361
470
|
//#endregion
|
|
471
|
+
//#region src/getDigitalContracts.d.ts
|
|
472
|
+
declare const getDigitalContracts: (client: Client, bookingId: string, status?: string) => Promise<Contract[]>;
|
|
473
|
+
//#endregion
|
|
474
|
+
//#region src/getAdditionalDrivers.d.ts
|
|
475
|
+
declare const getAdditionalDrivers: (client: Client, parentId: string) => Promise<AdditionalDriver[]>;
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/getSlaves.d.ts
|
|
478
|
+
declare const getSlaves: (client: Client, parentId: string, status: string) => Promise<BookingRequestSlave[]>;
|
|
479
|
+
//#endregion
|
|
480
|
+
//#region src/getSubscriptionsByUserId.d.ts
|
|
481
|
+
declare const getSubscriptionsByUserId: (client: Client, userId: string, active?: boolean) => Promise<Master[]>;
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/submitCancellationRequest.d.ts
|
|
484
|
+
declare const submitCancellationRequest: (client: Client, bookingRequestId: string, userId: string) => Promise<SATBookingRequest>;
|
|
485
|
+
//#endregion
|
|
362
486
|
//#region src/createSubscription.d.ts
|
|
363
487
|
type CreateSubscriptionBody = {
|
|
364
488
|
userId: string;
|
|
@@ -384,4 +508,4 @@ type CreateSubscriptionBody = {
|
|
|
384
508
|
};
|
|
385
509
|
declare const createSubscription: (client: Client, body: CreateSubscriptionBody) => Promise<BookingRequest>;
|
|
386
510
|
//#endregion
|
|
387
|
-
export { AvailableVehiclesResponse, BRPaymentItem, BaseBookingRequest, BookingCredit, BookingRequest, type BookingRequestFilters, type BookingRequestStatus, type CreateSubscriptionBody, CustomPrice, DayOpeningHours, Days, GeoInfo, type Include, type IncludeStation, OpeningHours, PaymentReceipts, PreferredPaymentMethod, SATBookingRequest, type SATBookingRequestStatus, Service, ServiceInfo, type ServiceType, Station, Timetable, TriggerBRPaymentResponse, Vehicle, allocateVehicle, cancelBookingRequest, createSubscription, deallocateVehicle, getAvailableVehicles, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getBookingRequestsByUserId, getSATBookingRequests, getScheduleBookingRequests, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests, releaseBRPayment, triggerBRPayment, updateScheduleBooking };
|
|
511
|
+
export { AdditionalDriver, AvailableVehiclesResponse, BRPaymentItem, BaseBookingRequest, BookingCredit, BookingRequest, type BookingRequestFilters, BookingRequestSlave, type BookingRequestStatus, Contract, type CreateSubscriptionBody, CustomPrice, DayOpeningHours, Days, GeoInfo, IFormatSlave, IFormatSubscription, type Include, type IncludeStation, Master, OpeningHours, PaymentReceipts, PreferredPaymentMethod, SATBookingRequest, type SATBookingRequestStatus, Service, ServiceInfo, type ServiceType, Slave, Station, Timetable, TriggerBRPaymentResponse, Vehicle, allocateVehicle, cancelBookingRequest, createSubscription, deallocateVehicle, getAdditionalDrivers, getAvailableVehicles, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getBookingRequestsByUserId, getDigitalContracts, getSATBookingRequests, getScheduleBookingRequests, getScheduledBookingById, getSlaves, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests, getSubscriptionsByUserId, releaseBRPayment, submitCancellationRequest, triggerBRPayment, updateScheduleBooking };
|
package/dist/index.mjs
CHANGED
|
@@ -148,6 +148,11 @@ const getSubscriptionBookingRequestById = async (client, id) => {
|
|
|
148
148
|
...data
|
|
149
149
|
}));
|
|
150
150
|
};
|
|
151
|
+
const getScheduledBookingById = async (client, bookingId) => {
|
|
152
|
+
const result = z.string().trim().min(1).uuid().safeParse(bookingId);
|
|
153
|
+
if (!result.success) throw new TypeError("Invalid bookingId", { cause: result.error.issues });
|
|
154
|
+
return client.get(`/boapi/proxy/user/scheduledBooking/by-service/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingId}`).then(({ data }) => data);
|
|
155
|
+
};
|
|
151
156
|
//#endregion
|
|
152
157
|
//#region src/getAvailableVehicles.ts
|
|
153
158
|
/** ISO date-time without milliseconds (e.g. 2025-02-10T12:00:00Z or 2025-02-10T12:00:00+01:00). */
|
|
@@ -328,7 +333,7 @@ const deallocateVehicle = async (client, bookingRequestId, vehicleId) => {
|
|
|
328
333
|
};
|
|
329
334
|
//#endregion
|
|
330
335
|
//#region src/updateScheduleBooking.ts
|
|
331
|
-
const schema$
|
|
336
|
+
const schema$7 = z$1.object({
|
|
332
337
|
id: z$1.string(),
|
|
333
338
|
startDate: z$1.string().refine((date) => !Number.isNaN(Date.parse(date)), { message: "Invalid date" }).optional(),
|
|
334
339
|
latitude: z$1.number().min(-90).max(90).optional(),
|
|
@@ -350,7 +355,7 @@ const schema$2 = z$1.object({
|
|
|
350
355
|
plannedReturnDate: z$1.string().refine((date) => !Number.isNaN(Date.parse(date)), { message: "Invalid date" }).optional()
|
|
351
356
|
});
|
|
352
357
|
const updateScheduleBooking = async (client, bookingRequestId, updateData) => {
|
|
353
|
-
const result = schema$
|
|
358
|
+
const result = schema$7.safeParse({
|
|
354
359
|
id: bookingRequestId,
|
|
355
360
|
...updateData
|
|
356
361
|
});
|
|
@@ -386,9 +391,9 @@ const triggerBRPayment = async (client, bookingRequestId, body) => {
|
|
|
386
391
|
};
|
|
387
392
|
//#endregion
|
|
388
393
|
//#region src/getBookingRequestsByUserId.ts
|
|
389
|
-
const schema$
|
|
394
|
+
const schema$6 = z.object({ userId: z.string().trim().min(1).uuid() });
|
|
390
395
|
const getBookingRequestsByUserId = async (client, userId) => {
|
|
391
|
-
const result = schema$
|
|
396
|
+
const result = schema$6.safeParse({ userId });
|
|
392
397
|
if (!result.success) throw new TypeError("Invalid userId", { cause: result.error.issues });
|
|
393
398
|
return client.get(`/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/users/${userId}`).then(({ data }) => data).catch((error) => {
|
|
394
399
|
if (error.formattedError?.status === 404) return [];
|
|
@@ -413,15 +418,80 @@ const releaseBRPayment = async (client, bookingRequestId, pspReference) => {
|
|
|
413
418
|
};
|
|
414
419
|
//#endregion
|
|
415
420
|
//#region src/cancelBookingRequest.ts
|
|
416
|
-
const schema = z$1.object({ id: z$1.string().uuid() });
|
|
421
|
+
const schema$5 = z$1.object({ id: z$1.string().uuid() });
|
|
417
422
|
const cancelBookingRequest = async (client, id) => {
|
|
418
|
-
const result = schema.safeParse({ id });
|
|
423
|
+
const result = schema$5.safeParse({ id });
|
|
419
424
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
420
425
|
return client.post(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/cancel/${id}`, {}).then(({ data }) => data).catch((error) => {
|
|
421
426
|
throw new TypeError("Failed to cancel booking request", { cause: error });
|
|
422
427
|
});
|
|
423
428
|
};
|
|
424
429
|
//#endregion
|
|
430
|
+
//#region src/getDigitalContracts.ts
|
|
431
|
+
const schema$4 = z.object({ bookingId: z.string().trim().min(1) });
|
|
432
|
+
const getDigitalContracts = async (client, bookingId, status = "SIGNED") => {
|
|
433
|
+
const result = schema$4.safeParse({ bookingId });
|
|
434
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
435
|
+
return client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/subscription/bookingrequests/${result.data.bookingId}/digitalContracts?status=${encodeURIComponent(status)}`).then(({ data }) => data);
|
|
436
|
+
};
|
|
437
|
+
//#endregion
|
|
438
|
+
//#region src/getAdditionalDrivers.ts
|
|
439
|
+
const schema$3 = z.object({ parentId: z.string().trim().min(1) });
|
|
440
|
+
const getAdditionalDrivers = async (client, parentId) => {
|
|
441
|
+
const result = schema$3.safeParse({ parentId });
|
|
442
|
+
if (!result.success) throw new TypeError("Invalid parentId", { cause: result.error.issues });
|
|
443
|
+
return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/bookingrequests/${parentId}/additionalDrivers`).then(({ data }) => data);
|
|
444
|
+
};
|
|
445
|
+
//#endregion
|
|
446
|
+
//#region src/getSlaves.ts
|
|
447
|
+
const schema$2 = z.object({
|
|
448
|
+
parentId: z.string().trim().min(1),
|
|
449
|
+
status: z.enum(["ONGOING, COMPLETED", "UPCOMING"])
|
|
450
|
+
});
|
|
451
|
+
const getSlaves = async (client, parentId, status) => {
|
|
452
|
+
const result = schema$2.safeParse({
|
|
453
|
+
parentId,
|
|
454
|
+
status
|
|
455
|
+
});
|
|
456
|
+
if (!result.success) throw new TypeError("Invalid bookingId", { cause: result.error.issues });
|
|
457
|
+
return client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/subscription/bookingRequests/${parentId}/bookingRequestsSlave?bookingStatus=${status}`).then(({ data }) => data);
|
|
458
|
+
};
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region src/getSubscriptionsByUserId.ts
|
|
461
|
+
const schema$1 = z.object({
|
|
462
|
+
userId: z.string().trim().min(1).uuid(),
|
|
463
|
+
active: z.boolean().optional().default(true)
|
|
464
|
+
});
|
|
465
|
+
const getSubscriptionsByUserId = async (client, userId, active = true) => {
|
|
466
|
+
const result = schema$1.safeParse({
|
|
467
|
+
userId,
|
|
468
|
+
active
|
|
469
|
+
});
|
|
470
|
+
if (!result.success) throw new TypeError("Invalid userId", { cause: result.error.issues });
|
|
471
|
+
return client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/subscription/users/${userId}/${active ? "active" : "past"}`).then(({ data }) => data);
|
|
472
|
+
};
|
|
473
|
+
//#endregion
|
|
474
|
+
//#region src/submitCancellationRequest.ts
|
|
475
|
+
const schema = z.object({
|
|
476
|
+
bookingRequestId: z.string().uuid(),
|
|
477
|
+
userId: z.string().uuid()
|
|
478
|
+
});
|
|
479
|
+
const submitCancellationRequest = async (client, bookingRequestId, userId) => {
|
|
480
|
+
const result = schema.safeParse({
|
|
481
|
+
bookingRequestId,
|
|
482
|
+
userId
|
|
483
|
+
});
|
|
484
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
485
|
+
return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/actions`, {
|
|
486
|
+
action: "EARLIER_CANCELLATION_REQUEST",
|
|
487
|
+
bookingStatusBO: "ONGOING",
|
|
488
|
+
status: "PENDING",
|
|
489
|
+
userId
|
|
490
|
+
}).then(({ data }) => data).catch((error) => {
|
|
491
|
+
throw new TypeError("Failed to submit cancellation request", { cause: error });
|
|
492
|
+
});
|
|
493
|
+
};
|
|
494
|
+
//#endregion
|
|
425
495
|
//#region src/createSubscription.ts
|
|
426
496
|
const createSubscriptionBodySchema = z.object({
|
|
427
497
|
userId: z.string().trim().min(1).uuid(),
|
|
@@ -451,4 +521,4 @@ const createSubscription = async (client, body) => {
|
|
|
451
521
|
return client.post(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/subscription/bookingrequests`, result.data).then(({ data }) => data);
|
|
452
522
|
};
|
|
453
523
|
//#endregion
|
|
454
|
-
export { allocateVehicle, cancelBookingRequest, createSubscription, deallocateVehicle, getAvailableVehicles, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getBookingRequestsByUserId, getSATBookingRequests, getScheduleBookingRequests, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests, releaseBRPayment, triggerBRPayment, updateScheduleBooking };
|
|
524
|
+
export { allocateVehicle, cancelBookingRequest, createSubscription, deallocateVehicle, getAdditionalDrivers, getAvailableVehicles, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getBookingRequestsByUserId, getDigitalContracts, getSATBookingRequests, getScheduleBookingRequests, getScheduledBookingById, getSlaves, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests, getSubscriptionsByUserId, releaseBRPayment, submitCancellationRequest, triggerBRPayment, updateScheduleBooking };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-booking",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.35",
|
|
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.35",
|
|
36
|
+
"@vulog/aima-core": "1.2.35"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"es-toolkit": "^1.39.9",
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, test, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { Client } from '@vulog/aima-client';
|
|
3
|
+
import { randomUUID } from 'crypto';
|
|
4
|
+
import { getAdditionalDrivers } from './getAdditionalDrivers';
|
|
5
|
+
|
|
6
|
+
describe('getAdditionalDrivers', () => {
|
|
7
|
+
const getMock = vi.fn();
|
|
8
|
+
const client = {
|
|
9
|
+
get: getMock,
|
|
10
|
+
clientOptions: {
|
|
11
|
+
fleetId: 'FLEET_ID',
|
|
12
|
+
},
|
|
13
|
+
} as unknown as Client;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
getMock.mockReset();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('throws Invalid parentId when parentId is empty', async () => {
|
|
20
|
+
await expect(getAdditionalDrivers(client, '')).rejects.toThrow(TypeError);
|
|
21
|
+
await expect(getAdditionalDrivers(client, '')).rejects.toMatchObject({
|
|
22
|
+
message: 'Invalid parentId',
|
|
23
|
+
});
|
|
24
|
+
expect(getMock).not.toHaveBeenCalled();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('calls GET with correct URL and returns additional drivers', async () => {
|
|
28
|
+
const parentId = randomUUID();
|
|
29
|
+
const drivers = [
|
|
30
|
+
{
|
|
31
|
+
id: randomUUID(),
|
|
32
|
+
fleetId: 'FLEET_ID',
|
|
33
|
+
bookingRequestId: parentId,
|
|
34
|
+
profileId: randomUUID(),
|
|
35
|
+
updateDate: '2025-01-15T10:00:00Z',
|
|
36
|
+
invitationEmail: 'driver@example.com',
|
|
37
|
+
profileStatus: 'APPROVED',
|
|
38
|
+
userId: randomUUID(),
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
getMock.mockResolvedValueOnce({ data: drivers });
|
|
42
|
+
|
|
43
|
+
const result = await getAdditionalDrivers(client, parentId);
|
|
44
|
+
|
|
45
|
+
expect(getMock).toHaveBeenCalledTimes(1);
|
|
46
|
+
expect(getMock).toHaveBeenCalledWith(
|
|
47
|
+
`/boapi/proxy/user/fleets/FLEET_ID/bookingrequests/${parentId}/additionalDrivers`
|
|
48
|
+
);
|
|
49
|
+
expect(result).toEqual(drivers);
|
|
50
|
+
expect(result).toHaveLength(1);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('returns empty array when no additional drivers', async () => {
|
|
54
|
+
const parentId = randomUUID();
|
|
55
|
+
getMock.mockResolvedValueOnce({ data: [] });
|
|
56
|
+
|
|
57
|
+
const result = await getAdditionalDrivers(client, parentId);
|
|
58
|
+
|
|
59
|
+
expect(result).toEqual([]);
|
|
60
|
+
});
|
|
61
|
+
});
|