@vulog/aima-booking 1.2.23 → 1.2.26

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.d.mts CHANGED
@@ -327,4 +327,10 @@ declare const triggerBRPaymentSchema: z$1.ZodObject<{
327
327
  }>;
328
328
  declare const triggerBRPayment: (client: Client, bookingRequestId: UUID, body: z$1.infer<typeof triggerBRPaymentSchema>["body"]) => Promise<TriggerBRPaymentResponse>;
329
329
 
330
- export { type BRPaymentItem, type BaseBookingRequest, type BookingCredit, type BookingRequest, type BookingRequestFilters, type BookingRequestStatus, type CustomPrice, type DayOpeningHours, type Days, type GeoInfo, type Include, type IncludeStation, type OpeningHours, type PaymentReceipts, type PreferredPaymentMethod, type SATBookingRequest, type SATBookingRequestStatus, type Service, type ServiceInfo, type ServiceType, type Station, type Timetable, type TriggerBRPaymentResponse, allocateVehicle, deallocateVehicle, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getSATBookingRequests, getScheduleBookingRequests, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests, triggerBRPayment, updateScheduleBooking };
330
+ declare const getBookingRequestsByUserId: (client: Client, userId: string) => Promise<BookingRequest[]>;
331
+
332
+ declare const releaseBRPayment: (client: Client, bookingRequestId: UUID, pspReference: string) => Promise<SATBookingRequest>;
333
+
334
+ declare const cancelBookingRequest: (client: Client, id: string) => Promise<SATBookingRequest>;
335
+
336
+ export { type BRPaymentItem, type BaseBookingRequest, type BookingCredit, type BookingRequest, type BookingRequestFilters, type BookingRequestStatus, type CustomPrice, type DayOpeningHours, type Days, type GeoInfo, type Include, type IncludeStation, type OpeningHours, type PaymentReceipts, type PreferredPaymentMethod, type SATBookingRequest, type SATBookingRequestStatus, type Service, type ServiceInfo, type ServiceType, type Station, type Timetable, type TriggerBRPaymentResponse, allocateVehicle, cancelBookingRequest, deallocateVehicle, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getBookingRequestsByUserId, getSATBookingRequests, getScheduleBookingRequests, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests, releaseBRPayment, triggerBRPayment, updateScheduleBooking };
package/dist/index.d.ts CHANGED
@@ -327,4 +327,10 @@ declare const triggerBRPaymentSchema: z$1.ZodObject<{
327
327
  }>;
328
328
  declare const triggerBRPayment: (client: Client, bookingRequestId: UUID, body: z$1.infer<typeof triggerBRPaymentSchema>["body"]) => Promise<TriggerBRPaymentResponse>;
329
329
 
330
- export { type BRPaymentItem, type BaseBookingRequest, type BookingCredit, type BookingRequest, type BookingRequestFilters, type BookingRequestStatus, type CustomPrice, type DayOpeningHours, type Days, type GeoInfo, type Include, type IncludeStation, type OpeningHours, type PaymentReceipts, type PreferredPaymentMethod, type SATBookingRequest, type SATBookingRequestStatus, type Service, type ServiceInfo, type ServiceType, type Station, type Timetable, type TriggerBRPaymentResponse, allocateVehicle, deallocateVehicle, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getSATBookingRequests, getScheduleBookingRequests, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests, triggerBRPayment, updateScheduleBooking };
330
+ declare const getBookingRequestsByUserId: (client: Client, userId: string) => Promise<BookingRequest[]>;
331
+
332
+ declare const releaseBRPayment: (client: Client, bookingRequestId: UUID, pspReference: string) => Promise<SATBookingRequest>;
333
+
334
+ declare const cancelBookingRequest: (client: Client, id: string) => Promise<SATBookingRequest>;
335
+
336
+ export { type BRPaymentItem, type BaseBookingRequest, type BookingCredit, type BookingRequest, type BookingRequestFilters, type BookingRequestStatus, type CustomPrice, type DayOpeningHours, type Days, type GeoInfo, type Include, type IncludeStation, type OpeningHours, type PaymentReceipts, type PreferredPaymentMethod, type SATBookingRequest, type SATBookingRequestStatus, type Service, type ServiceInfo, type ServiceType, type Station, type Timetable, type TriggerBRPaymentResponse, allocateVehicle, cancelBookingRequest, deallocateVehicle, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getBookingRequestsByUserId, getSATBookingRequests, getScheduleBookingRequests, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests, releaseBRPayment, triggerBRPayment, updateScheduleBooking };
package/dist/index.js CHANGED
@@ -31,16 +31,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  allocateVehicle: () => allocateVehicle,
34
+ cancelBookingRequest: () => cancelBookingRequest,
34
35
  deallocateVehicle: () => deallocateVehicle,
35
36
  getBookingRequestById: () => getBookingRequestById,
36
37
  getBookingRequestByTrip: () => getBookingRequestByTrip,
37
38
  getBookingRequests: () => getBookingRequests,
39
+ getBookingRequestsByUserId: () => getBookingRequestsByUserId,
38
40
  getSATBookingRequests: () => getSATBookingRequests,
39
41
  getScheduleBookingRequests: () => getScheduleBookingRequests,
40
42
  getStationById: () => getStationById,
41
43
  getStations: () => getStations,
42
44
  getSubscriptionBookingRequestById: () => getSubscriptionBookingRequestById,
43
45
  getSubscriptionBookingRequests: () => getSubscriptionBookingRequests,
46
+ releaseBRPayment: () => releaseBRPayment,
44
47
  triggerBRPayment: () => triggerBRPayment,
45
48
  updateScheduleBooking: () => updateScheduleBooking
46
49
  });
@@ -535,19 +538,89 @@ var triggerBRPayment = async (client, bookingRequestId, body) => {
535
538
  });
536
539
  });
537
540
  };
541
+
542
+ // src/getBookingRequestsByUserId.ts
543
+ var import_zod10 = require("zod");
544
+ var schema2 = import_zod10.z.object({
545
+ userId: import_zod10.z.string().trim().min(1).uuid()
546
+ });
547
+ var getBookingRequestsByUserId = async (client, userId) => {
548
+ const result = schema2.safeParse({ userId });
549
+ if (!result.success) {
550
+ throw new TypeError("Invalid userId", {
551
+ cause: result.error.issues
552
+ });
553
+ }
554
+ return client.get(
555
+ `/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/users/${userId}`
556
+ ).then(({ data }) => data).catch((error) => {
557
+ if (error.formattedError?.status === 404) {
558
+ return [];
559
+ }
560
+ throw error;
561
+ });
562
+ };
563
+
564
+ // src/releaseBRPayment.ts
565
+ var import_zod11 = __toESM(require("zod"));
566
+ var releaseBRPaymentSchema = import_zod11.default.object({
567
+ bookingRequestId: import_zod11.default.string().uuid(),
568
+ pspReference: import_zod11.default.string().uuid()
569
+ });
570
+ var releaseBRPayment = async (client, bookingRequestId, pspReference) => {
571
+ const resultPayload = releaseBRPaymentSchema.safeParse({ bookingRequestId, pspReference });
572
+ if (!resultPayload.success) {
573
+ throw new TypeError("Invalid args", {
574
+ cause: resultPayload.error.issues
575
+ });
576
+ }
577
+ return client.post(
578
+ `boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/paymentintent/${pspReference}/cancel`,
579
+ {}
580
+ ).then(({ data }) => data).catch((error) => {
581
+ throw new TypeError("Failed to release booking request payment", {
582
+ cause: error
583
+ });
584
+ });
585
+ };
586
+
587
+ // src/cancelBookingRequest.ts
588
+ var import_zod12 = __toESM(require("zod"));
589
+ var schema3 = import_zod12.default.object({
590
+ id: import_zod12.default.string().uuid()
591
+ });
592
+ var cancelBookingRequest = async (client, id) => {
593
+ const result = schema3.safeParse({ id });
594
+ if (!result.success) {
595
+ throw new TypeError("Invalid args", {
596
+ cause: result.error.issues
597
+ });
598
+ }
599
+ return client.post(
600
+ `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/cancel/${id}`,
601
+ {}
602
+ ).then(({ data }) => data).catch((error) => {
603
+ throw new TypeError("Failed to cancel booking request", {
604
+ cause: error
605
+ });
606
+ });
607
+ };
538
608
  // Annotate the CommonJS export names for ESM import in node:
539
609
  0 && (module.exports = {
540
610
  allocateVehicle,
611
+ cancelBookingRequest,
541
612
  deallocateVehicle,
542
613
  getBookingRequestById,
543
614
  getBookingRequestByTrip,
544
615
  getBookingRequests,
616
+ getBookingRequestsByUserId,
545
617
  getSATBookingRequests,
546
618
  getScheduleBookingRequests,
547
619
  getStationById,
548
620
  getStations,
549
621
  getSubscriptionBookingRequestById,
550
622
  getSubscriptionBookingRequests,
623
+ releaseBRPayment,
551
624
  triggerBRPayment,
552
625
  updateScheduleBooking
553
626
  });
package/dist/index.mjs CHANGED
@@ -487,18 +487,88 @@ var triggerBRPayment = async (client, bookingRequestId, body) => {
487
487
  });
488
488
  });
489
489
  };
490
+
491
+ // src/getBookingRequestsByUserId.ts
492
+ import { z as z10 } from "zod";
493
+ var schema2 = z10.object({
494
+ userId: z10.string().trim().min(1).uuid()
495
+ });
496
+ var getBookingRequestsByUserId = async (client, userId) => {
497
+ const result = schema2.safeParse({ userId });
498
+ if (!result.success) {
499
+ throw new TypeError("Invalid userId", {
500
+ cause: result.error.issues
501
+ });
502
+ }
503
+ return client.get(
504
+ `/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/users/${userId}`
505
+ ).then(({ data }) => data).catch((error) => {
506
+ if (error.formattedError?.status === 404) {
507
+ return [];
508
+ }
509
+ throw error;
510
+ });
511
+ };
512
+
513
+ // src/releaseBRPayment.ts
514
+ import z11 from "zod";
515
+ var releaseBRPaymentSchema = z11.object({
516
+ bookingRequestId: z11.string().uuid(),
517
+ pspReference: z11.string().uuid()
518
+ });
519
+ var releaseBRPayment = async (client, bookingRequestId, pspReference) => {
520
+ const resultPayload = releaseBRPaymentSchema.safeParse({ bookingRequestId, pspReference });
521
+ if (!resultPayload.success) {
522
+ throw new TypeError("Invalid args", {
523
+ cause: resultPayload.error.issues
524
+ });
525
+ }
526
+ return client.post(
527
+ `boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/paymentintent/${pspReference}/cancel`,
528
+ {}
529
+ ).then(({ data }) => data).catch((error) => {
530
+ throw new TypeError("Failed to release booking request payment", {
531
+ cause: error
532
+ });
533
+ });
534
+ };
535
+
536
+ // src/cancelBookingRequest.ts
537
+ import z12 from "zod";
538
+ var schema3 = z12.object({
539
+ id: z12.string().uuid()
540
+ });
541
+ var cancelBookingRequest = async (client, id) => {
542
+ const result = schema3.safeParse({ id });
543
+ if (!result.success) {
544
+ throw new TypeError("Invalid args", {
545
+ cause: result.error.issues
546
+ });
547
+ }
548
+ return client.post(
549
+ `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/cancel/${id}`,
550
+ {}
551
+ ).then(({ data }) => data).catch((error) => {
552
+ throw new TypeError("Failed to cancel booking request", {
553
+ cause: error
554
+ });
555
+ });
556
+ };
490
557
  export {
491
558
  allocateVehicle,
559
+ cancelBookingRequest,
492
560
  deallocateVehicle,
493
561
  getBookingRequestById,
494
562
  getBookingRequestByTrip,
495
563
  getBookingRequests,
564
+ getBookingRequestsByUserId,
496
565
  getSATBookingRequests,
497
566
  getScheduleBookingRequests,
498
567
  getStationById,
499
568
  getStations,
500
569
  getSubscriptionBookingRequestById,
501
570
  getSubscriptionBookingRequests,
571
+ releaseBRPayment,
502
572
  triggerBRPayment,
503
573
  updateScheduleBooking
504
574
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulog/aima-booking",
3
- "version": "1.2.23",
3
+ "version": "1.2.26",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "author": "Vulog",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@vulog/aima-client": "1.2.23",
23
- "@vulog/aima-core": "1.2.23"
22
+ "@vulog/aima-client": "1.2.26",
23
+ "@vulog/aima-core": "1.2.26"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "es-toolkit": "^1.39.9",
@@ -91,7 +91,7 @@ describe('cancelBookingRequest', () => {
91
91
 
92
92
  expect(postMock).toHaveBeenCalledTimes(1);
93
93
  expect(postMock).toHaveBeenCalledWith(
94
- `/boapi/proxy/user/scheduledBooking/fleets/FLEET_ID/bookingrequests/${id}/cancel`,
94
+ `/boapi/proxy/user/scheduledBooking/fleets/FLEET_ID/bookingrequests/cancel/${id}`,
95
95
  {}
96
96
  );
97
97
  expect(result).toEqual(minimalCancelledResponse);
@@ -16,7 +16,7 @@ export const cancelBookingRequest = async (client: Client, id: string): Promise<
16
16
  }
17
17
  return client
18
18
  .post<SATBookingRequest>(
19
- `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${id}/cancel`,
19
+ `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/cancel/${id}`,
20
20
  {}
21
21
  )
22
22
  .then(({ data }) => data)
@@ -0,0 +1,102 @@
1
+ import { describe, test, expect, vi, beforeEach } from 'vitest';
2
+ import { getBookingRequestsByUserId } from './getBookingRequestsByUserId';
3
+ import { Client } from '@vulog/aima-client';
4
+ import { randomUUID } from 'crypto';
5
+
6
+ describe('getBookingRequestsByUserId', () => {
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('invalid userId (empty string)', async () => {
20
+ const rejects = expect(() => getBookingRequestsByUserId(client, '')).rejects;
21
+ await rejects.toThrow(TypeError);
22
+ await rejects.toThrow('Invalid userId');
23
+ await rejects.toSatisfy((error: Error & { cause?: unknown }) => {
24
+ expect(error).toHaveProperty('cause');
25
+ return true;
26
+ });
27
+ });
28
+
29
+ test('invalid userId (not a UUID)', async () => {
30
+ const rejects = expect(() => getBookingRequestsByUserId(client, 'not-a-uuid')).rejects;
31
+ await rejects.toThrow(TypeError);
32
+ await rejects.toThrow('Invalid userId');
33
+ await rejects.toSatisfy((error: Error & { cause?: unknown }) => {
34
+ expect(error).toHaveProperty('cause');
35
+ const issues = error.cause as Array<{ code?: string }>;
36
+ expect(issues?.some((e) => e.code === 'invalid_string')).toBe(true);
37
+ return true;
38
+ });
39
+ });
40
+
41
+ test('invalid userId (whitespace only)', async () => {
42
+ const rejects = expect(() => getBookingRequestsByUserId(client, ' ')).rejects;
43
+ await rejects.toThrow(TypeError);
44
+ await rejects.toThrow('Invalid userId');
45
+ });
46
+
47
+ test('call returns booking requests', async () => {
48
+ const userId = randomUUID();
49
+ const data = [
50
+ {
51
+ id: randomUUID(),
52
+ status: 'CONFIRMED',
53
+ creationDate: '2024-11-14T13:27:30Z',
54
+ fleetId: 'VULOG-FRNCE',
55
+ userId,
56
+ cityId: 'a91a8d56-4bf8-4a88-9afb-3f3cc255e4f8',
57
+ completed: false,
58
+ },
59
+ ];
60
+ getMock.mockResolvedValueOnce({ data });
61
+
62
+ const result = await getBookingRequestsByUserId(client, userId);
63
+
64
+ expect(getMock).toHaveBeenCalledWith(
65
+ `/user/scheduledBooking/fleets/FLEET_ID/bookingrequests/users/${userId}`
66
+ );
67
+ expect(result).toEqual(data);
68
+ });
69
+
70
+ test('call with valid UUID returns empty array when 404', async () => {
71
+ const userId = randomUUID();
72
+ getMock.mockRejectedValueOnce({
73
+ formattedError: { status: 404 },
74
+ });
75
+
76
+ const result = await getBookingRequestsByUserId(client, userId);
77
+
78
+ expect(getMock).toHaveBeenCalledWith(
79
+ `/user/scheduledBooking/fleets/FLEET_ID/bookingrequests/users/${userId}`
80
+ );
81
+ expect(result).toEqual([]);
82
+ });
83
+
84
+ test('rethrows on non-404 error', async () => {
85
+ const userId = randomUUID();
86
+ const err = new Error('Network error');
87
+ getMock.mockRejectedValueOnce(err);
88
+
89
+ await expect(getBookingRequestsByUserId(client, userId)).rejects.toThrow('Network error');
90
+ });
91
+
92
+ test('rethrows when formattedError status is not 404', async () => {
93
+ const userId = randomUUID();
94
+ getMock.mockRejectedValueOnce({
95
+ formattedError: { status: 500 },
96
+ });
97
+
98
+ await expect(getBookingRequestsByUserId(client, userId)).rejects.toMatchObject({
99
+ formattedError: { status: 500 },
100
+ });
101
+ });
102
+ });
@@ -0,0 +1,28 @@
1
+ import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
3
+
4
+ import { BookingRequest } from './types';
5
+
6
+ const schema = z.object({
7
+ userId: z.string().trim().min(1).uuid(),
8
+ });
9
+
10
+ export const getBookingRequestsByUserId = async (client: Client, userId: string): Promise<BookingRequest[]> => {
11
+ const result = schema.safeParse({ userId });
12
+ if (!result.success) {
13
+ throw new TypeError('Invalid userId', {
14
+ cause: result.error.issues,
15
+ });
16
+ }
17
+ return client
18
+ .get<BookingRequest[]>(
19
+ `/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/users/${userId}`
20
+ )
21
+ .then(({ data }) => data)
22
+ .catch((error) => {
23
+ if (error.formattedError?.status === 404) {
24
+ return [];
25
+ }
26
+ throw error;
27
+ });
28
+ };
package/src/index.ts CHANGED
@@ -12,3 +12,6 @@ export { allocateVehicle } from './allocateVehicle';
12
12
  export { deallocateVehicle } from './deallocateVehicle';
13
13
  export { updateScheduleBooking } from './updateScheduleBooking';
14
14
  export { triggerBRPayment } from './triggerBRPayment';
15
+ export { getBookingRequestsByUserId } from './getBookingRequestsByUserId';
16
+ export { releaseBRPayment } from './releaseBRPayment';
17
+ export { cancelBookingRequest } from './cancelBookingRequest';