@vulog/aima-booking 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,4 +19,8 @@ const client = getClient({
19
19
  const response = await getBookingRequests(client, 'ONGOING');
20
20
 
21
21
  const station = await getStations(client, ['OPEN_HOUR', 'INFO']);
22
+
23
+ const br1 = await getBookingRequestById(client, 'bb493049-5b4f-43ea-8a65-964a13aec549');
24
+ const br2 = await getBookingRequestByTrip(client, '33E8E42710144E15A5CC447E4D3524F4');
25
+ const sub = await getSubscriptionBookingRequestById(client, 'b7faa2a2-e8fc-4a29-8de7-09ce783b9797');
22
26
  ```
package/dist/index.d.mts CHANGED
@@ -2,33 +2,20 @@ import { Client } from '@vulog/aima-client';
2
2
  import { PaginableOptions, PaginableResponse } from '@vulog/aima-core';
3
3
  import { z } from 'zod';
4
4
 
5
- declare const BookingRequestStatusSchema: z.ZodEnum<["ALERT", "UPCOMING", "ONGOING", "COMPLETED", "CANCELLED", "PENDING_APPROVAL"]>;
6
- type BookingRequestStatus = z.infer<typeof BookingRequestStatusSchema>;
7
- declare const ServiceTypeSchema: z.ZodEnum<["SUBSCRIPTION", "ROUND_TRIP_BOOKING", "SCHEDULED_BOOKING_STATION"]>;
8
- type ServiceType = z.infer<typeof ServiceTypeSchema>;
9
- type SpecificBookingRequestFilters = {
10
- serviceIds?: string[];
11
- userId?: string;
12
- modelId?: number;
13
- vehicleId?: string;
14
- stationId?: string;
15
- /**
16
- * Format: yyyy-MM-dd
17
- */
18
- creationDate?: string;
19
- /**
20
- * Format: yyyy-MM-dd'T'HH:mm:ssZ
21
- * default now plus 2 months
22
- */
23
- startDate?: string;
24
- /**
25
- * Format: yyyy-MM-dd'T'HH:mm:ssZ
26
- * default now plus 2 months
27
- */
28
- endDate?: string;
29
- };
30
- type BookingRequestFilters = SpecificBookingRequestFilters & {
31
- serviceTypes?: ServiceType[];
5
+ type PaymentReceipts = {
6
+ id: string;
7
+ pspName: string;
8
+ pspReference: string;
9
+ amount: number;
10
+ currency: string;
11
+ date: string;
12
+ status: string;
13
+ paymentMethodType: string;
14
+ paymentIntentPspReference?: string;
15
+ number: number;
16
+ metadatas: {
17
+ scope: string;
18
+ };
32
19
  };
33
20
  type BookingRequest = {
34
21
  id: string;
@@ -37,39 +24,83 @@ type BookingRequest = {
37
24
  returnedDate?: string;
38
25
  profileId: string;
39
26
  vehicleId?: string;
40
- modelId: 1647;
27
+ modelId: number;
41
28
  journeyId?: string;
42
29
  station: string;
43
- profileType: 'Single' | 'Business';
30
+ profileType?: 'Single' | 'Business';
44
31
  entityName?: string;
45
32
  status: string;
46
33
  creationDate: string;
47
34
  realStartDate?: string;
48
35
  cancellationDate?: string;
49
36
  cancelledBy?: string;
37
+ fleetId: string;
50
38
  userId: string;
51
39
  serviceId: string;
40
+ warning?: string;
41
+ paymentReceipts?: PaymentReceipts[];
42
+ credit?: string;
52
43
  cityId: string;
44
+ vehicleResidualValue?: number;
45
+ notes?: string;
46
+ plannedReturnDate?: string;
53
47
  deliveryAddress?: string;
54
48
  deliveryAddressAdditionalInfo?: string;
55
49
  deliveryCity?: string;
56
50
  deliveryPostalCode?: string;
57
- rollingContract: string;
51
+ dropOffStation?: string;
52
+ rollingContract: boolean;
58
53
  planDurationInMonths?: number;
59
54
  contractType?: string;
55
+ customPrice?: string;
60
56
  productIds: string[];
61
57
  bookingReferenceId?: string;
62
58
  pricingDetails: {
63
59
  pricingId: string;
64
60
  providerType: string;
65
61
  }[];
62
+ pricePerUnit?: string;
63
+ modelName?: string;
66
64
  completed: boolean;
67
65
  [key: string]: any;
68
66
  };
67
+
68
+ declare const BookingRequestStatusSchema: z.ZodEnum<["ALERT", "UPCOMING", "ONGOING", "COMPLETED", "CANCELLED", "PENDING_APPROVAL"]>;
69
+ type BookingRequestStatus = z.infer<typeof BookingRequestStatusSchema>;
70
+ declare const ServiceTypeSchema: z.ZodEnum<["SUBSCRIPTION", "ROUND_TRIP_BOOKING", "SCHEDULED_BOOKING_STATION"]>;
71
+ type ServiceType = z.infer<typeof ServiceTypeSchema>;
72
+ type SpecificBookingRequestFilters = {
73
+ serviceIds?: string[];
74
+ userId?: string;
75
+ modelId?: number;
76
+ vehicleId?: string;
77
+ stationId?: string;
78
+ /**
79
+ * Format: yyyy-MM-dd
80
+ */
81
+ creationDate?: string;
82
+ /**
83
+ * Format: yyyy-MM-dd'T'HH:mm:ssZ
84
+ * default now
85
+ */
86
+ startDate?: string;
87
+ /**
88
+ * Format: yyyy-MM-dd'T'HH:mm:ssZ
89
+ * default now plus 2 months
90
+ */
91
+ endDate?: string;
92
+ };
93
+ type BookingRequestFilters = SpecificBookingRequestFilters & {
94
+ serviceTypes?: ServiceType[];
95
+ };
69
96
  declare const getBookingRequests: (client: Client, status: BookingRequestStatus, options?: PaginableOptions<BookingRequestFilters>) => Promise<PaginableResponse<BookingRequest>>;
70
97
  declare const getScheduleBookingRequests: (client: Client, status: BookingRequestStatus, options?: PaginableOptions<SpecificBookingRequestFilters>) => Promise<PaginableResponse<BookingRequest>>;
71
98
  declare const getSubscriptionBookingRequests: (client: Client, status: BookingRequestStatus, options?: PaginableOptions<SpecificBookingRequestFilters>) => Promise<PaginableResponse<BookingRequest>>;
72
99
 
100
+ declare const getBookingRequestById: (client: Client, id: string) => Promise<BookingRequest>;
101
+ declare const getBookingRequestByTrip: (client: Client, tripId: string) => Promise<BookingRequest>;
102
+ declare const getSubscriptionBookingRequestById: (client: Client, id: string) => Promise<BookingRequest>;
103
+
73
104
  declare const IncludeSchema: z.ZodEnum<["INFO", "OPEN_HOUR", "SERVICES"]>;
74
105
  type Include = z.infer<typeof IncludeSchema>;
75
106
  type Days = 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY' | 'SUNDAY';
@@ -115,4 +146,4 @@ type Station = Partial<GeoInfo> & Partial<ServiceInfo> & {
115
146
  };
116
147
  declare const getStations: (client: Client, includes?: Include[]) => Promise<Station[]>;
117
148
 
118
- export { type BookingRequest, type BookingRequestFilters, type BookingRequestStatus, type DayOpeningHours, type Days, type Include, type OpeningHours, type ServiceType, type Station, type Timetable, getBookingRequests, getScheduleBookingRequests, getStations, getSubscriptionBookingRequests };
149
+ export { type BookingRequest, type BookingRequestFilters, type BookingRequestStatus, type DayOpeningHours, type Days, type Include, type OpeningHours, type ServiceType, type Station, type Timetable, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getScheduleBookingRequests, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests };
package/dist/index.d.ts CHANGED
@@ -2,33 +2,20 @@ import { Client } from '@vulog/aima-client';
2
2
  import { PaginableOptions, PaginableResponse } from '@vulog/aima-core';
3
3
  import { z } from 'zod';
4
4
 
5
- declare const BookingRequestStatusSchema: z.ZodEnum<["ALERT", "UPCOMING", "ONGOING", "COMPLETED", "CANCELLED", "PENDING_APPROVAL"]>;
6
- type BookingRequestStatus = z.infer<typeof BookingRequestStatusSchema>;
7
- declare const ServiceTypeSchema: z.ZodEnum<["SUBSCRIPTION", "ROUND_TRIP_BOOKING", "SCHEDULED_BOOKING_STATION"]>;
8
- type ServiceType = z.infer<typeof ServiceTypeSchema>;
9
- type SpecificBookingRequestFilters = {
10
- serviceIds?: string[];
11
- userId?: string;
12
- modelId?: number;
13
- vehicleId?: string;
14
- stationId?: string;
15
- /**
16
- * Format: yyyy-MM-dd
17
- */
18
- creationDate?: string;
19
- /**
20
- * Format: yyyy-MM-dd'T'HH:mm:ssZ
21
- * default now plus 2 months
22
- */
23
- startDate?: string;
24
- /**
25
- * Format: yyyy-MM-dd'T'HH:mm:ssZ
26
- * default now plus 2 months
27
- */
28
- endDate?: string;
29
- };
30
- type BookingRequestFilters = SpecificBookingRequestFilters & {
31
- serviceTypes?: ServiceType[];
5
+ type PaymentReceipts = {
6
+ id: string;
7
+ pspName: string;
8
+ pspReference: string;
9
+ amount: number;
10
+ currency: string;
11
+ date: string;
12
+ status: string;
13
+ paymentMethodType: string;
14
+ paymentIntentPspReference?: string;
15
+ number: number;
16
+ metadatas: {
17
+ scope: string;
18
+ };
32
19
  };
33
20
  type BookingRequest = {
34
21
  id: string;
@@ -37,39 +24,83 @@ type BookingRequest = {
37
24
  returnedDate?: string;
38
25
  profileId: string;
39
26
  vehicleId?: string;
40
- modelId: 1647;
27
+ modelId: number;
41
28
  journeyId?: string;
42
29
  station: string;
43
- profileType: 'Single' | 'Business';
30
+ profileType?: 'Single' | 'Business';
44
31
  entityName?: string;
45
32
  status: string;
46
33
  creationDate: string;
47
34
  realStartDate?: string;
48
35
  cancellationDate?: string;
49
36
  cancelledBy?: string;
37
+ fleetId: string;
50
38
  userId: string;
51
39
  serviceId: string;
40
+ warning?: string;
41
+ paymentReceipts?: PaymentReceipts[];
42
+ credit?: string;
52
43
  cityId: string;
44
+ vehicleResidualValue?: number;
45
+ notes?: string;
46
+ plannedReturnDate?: string;
53
47
  deliveryAddress?: string;
54
48
  deliveryAddressAdditionalInfo?: string;
55
49
  deliveryCity?: string;
56
50
  deliveryPostalCode?: string;
57
- rollingContract: string;
51
+ dropOffStation?: string;
52
+ rollingContract: boolean;
58
53
  planDurationInMonths?: number;
59
54
  contractType?: string;
55
+ customPrice?: string;
60
56
  productIds: string[];
61
57
  bookingReferenceId?: string;
62
58
  pricingDetails: {
63
59
  pricingId: string;
64
60
  providerType: string;
65
61
  }[];
62
+ pricePerUnit?: string;
63
+ modelName?: string;
66
64
  completed: boolean;
67
65
  [key: string]: any;
68
66
  };
67
+
68
+ declare const BookingRequestStatusSchema: z.ZodEnum<["ALERT", "UPCOMING", "ONGOING", "COMPLETED", "CANCELLED", "PENDING_APPROVAL"]>;
69
+ type BookingRequestStatus = z.infer<typeof BookingRequestStatusSchema>;
70
+ declare const ServiceTypeSchema: z.ZodEnum<["SUBSCRIPTION", "ROUND_TRIP_BOOKING", "SCHEDULED_BOOKING_STATION"]>;
71
+ type ServiceType = z.infer<typeof ServiceTypeSchema>;
72
+ type SpecificBookingRequestFilters = {
73
+ serviceIds?: string[];
74
+ userId?: string;
75
+ modelId?: number;
76
+ vehicleId?: string;
77
+ stationId?: string;
78
+ /**
79
+ * Format: yyyy-MM-dd
80
+ */
81
+ creationDate?: string;
82
+ /**
83
+ * Format: yyyy-MM-dd'T'HH:mm:ssZ
84
+ * default now
85
+ */
86
+ startDate?: string;
87
+ /**
88
+ * Format: yyyy-MM-dd'T'HH:mm:ssZ
89
+ * default now plus 2 months
90
+ */
91
+ endDate?: string;
92
+ };
93
+ type BookingRequestFilters = SpecificBookingRequestFilters & {
94
+ serviceTypes?: ServiceType[];
95
+ };
69
96
  declare const getBookingRequests: (client: Client, status: BookingRequestStatus, options?: PaginableOptions<BookingRequestFilters>) => Promise<PaginableResponse<BookingRequest>>;
70
97
  declare const getScheduleBookingRequests: (client: Client, status: BookingRequestStatus, options?: PaginableOptions<SpecificBookingRequestFilters>) => Promise<PaginableResponse<BookingRequest>>;
71
98
  declare const getSubscriptionBookingRequests: (client: Client, status: BookingRequestStatus, options?: PaginableOptions<SpecificBookingRequestFilters>) => Promise<PaginableResponse<BookingRequest>>;
72
99
 
100
+ declare const getBookingRequestById: (client: Client, id: string) => Promise<BookingRequest>;
101
+ declare const getBookingRequestByTrip: (client: Client, tripId: string) => Promise<BookingRequest>;
102
+ declare const getSubscriptionBookingRequestById: (client: Client, id: string) => Promise<BookingRequest>;
103
+
73
104
  declare const IncludeSchema: z.ZodEnum<["INFO", "OPEN_HOUR", "SERVICES"]>;
74
105
  type Include = z.infer<typeof IncludeSchema>;
75
106
  type Days = 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY' | 'SUNDAY';
@@ -115,4 +146,4 @@ type Station = Partial<GeoInfo> & Partial<ServiceInfo> & {
115
146
  };
116
147
  declare const getStations: (client: Client, includes?: Include[]) => Promise<Station[]>;
117
148
 
118
- export { type BookingRequest, type BookingRequestFilters, type BookingRequestStatus, type DayOpeningHours, type Days, type Include, type OpeningHours, type ServiceType, type Station, type Timetable, getBookingRequests, getScheduleBookingRequests, getStations, getSubscriptionBookingRequests };
149
+ export { type BookingRequest, type BookingRequestFilters, type BookingRequestStatus, type DayOpeningHours, type Days, type Include, type OpeningHours, type ServiceType, type Station, type Timetable, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getScheduleBookingRequests, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests };
package/dist/index.js CHANGED
@@ -20,16 +20,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ getBookingRequestById: () => getBookingRequestById,
24
+ getBookingRequestByTrip: () => getBookingRequestByTrip,
23
25
  getBookingRequests: () => getBookingRequests,
24
26
  getScheduleBookingRequests: () => getScheduleBookingRequests,
25
27
  getStations: () => getStations,
28
+ getSubscriptionBookingRequestById: () => getSubscriptionBookingRequestById,
26
29
  getSubscriptionBookingRequests: () => getSubscriptionBookingRequests
27
30
  });
28
31
  module.exports = __toCommonJS(src_exports);
29
32
 
30
33
  // src/getBookingRequests.ts
31
34
  var import_aima_core = require("@vulog/aima-core");
32
- var import_lodash = require("lodash");
35
+ var import_compat = require("es-toolkit/compat");
33
36
  var import_zod = require("zod");
34
37
  var BookingRequestStatusSchema = import_zod.z.enum([
35
38
  "ALERT",
@@ -82,7 +85,7 @@ var getBookingRequests = async (client, status, options) => {
82
85
  searchParams.append(key, value.join(","));
83
86
  return;
84
87
  }
85
- if ((0, import_lodash.isNumber)(value)) {
88
+ if ((0, import_compat.isNumber)(value)) {
86
89
  searchParams.append(key, value.toString());
87
90
  return;
88
91
  }
@@ -117,10 +120,46 @@ var getSubscriptionBookingRequests = async (client, status, options) => {
117
120
  });
118
121
  };
119
122
 
120
- // src/getStations.ts
123
+ // src/getBookingRequest.ts
121
124
  var import_zod2 = require("zod");
122
- var IncludeSchema = import_zod2.z.enum(["INFO", "OPEN_HOUR", "SERVICES"]);
123
- var IncludesSchema = import_zod2.z.array(IncludeSchema);
125
+ var getBookingRequestById = async (client, id) => {
126
+ const result = import_zod2.z.string().trim().min(1).uuid().safeParse(id);
127
+ if (!result.success) {
128
+ throw new TypeError("Invalid id", {
129
+ cause: result.error.issues
130
+ });
131
+ }
132
+ return client.get(
133
+ `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${id}`
134
+ ).then(({ data }) => data);
135
+ };
136
+ var getBookingRequestByTrip = async (client, tripId) => {
137
+ const result = import_zod2.z.string().trim().min(1).safeParse(tripId);
138
+ if (!result.success) {
139
+ throw new TypeError("Invalid tripId", {
140
+ cause: result.error.issues
141
+ });
142
+ }
143
+ return client.get(
144
+ `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/trip/${tripId}`
145
+ ).then(({ data }) => data);
146
+ };
147
+ var getSubscriptionBookingRequestById = async (client, id) => {
148
+ const result = import_zod2.z.string().trim().min(1).uuid().safeParse(id);
149
+ if (!result.success) {
150
+ throw new TypeError("Invalid id", {
151
+ cause: result.error.issues
152
+ });
153
+ }
154
+ return client.get(
155
+ `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/subscription/bookingrequests/${id}`
156
+ ).then(({ data: { stationId, ...data } }) => ({ station: stationId, ...data }));
157
+ };
158
+
159
+ // src/getStations.ts
160
+ var import_zod3 = require("zod");
161
+ var IncludeSchema = import_zod3.z.enum(["INFO", "OPEN_HOUR", "SERVICES"]);
162
+ var IncludesSchema = import_zod3.z.array(IncludeSchema);
124
163
  var getStations = async (client, includes = []) => {
125
164
  const resultIncludes = IncludesSchema.safeParse(includes);
126
165
  if (!resultIncludes.success) {
@@ -210,8 +249,11 @@ var getStations = async (client, includes = []) => {
210
249
  };
211
250
  // Annotate the CommonJS export names for ESM import in node:
212
251
  0 && (module.exports = {
252
+ getBookingRequestById,
253
+ getBookingRequestByTrip,
213
254
  getBookingRequests,
214
255
  getScheduleBookingRequests,
215
256
  getStations,
257
+ getSubscriptionBookingRequestById,
216
258
  getSubscriptionBookingRequests
217
259
  });
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/getBookingRequests.ts
2
2
  import { createPaginableOptionsSchema } from "@vulog/aima-core";
3
- import { isNumber } from "lodash";
3
+ import { isNumber } from "es-toolkit/compat";
4
4
  import { z } from "zod";
5
5
  var BookingRequestStatusSchema = z.enum([
6
6
  "ALERT",
@@ -88,10 +88,46 @@ var getSubscriptionBookingRequests = async (client, status, options) => {
88
88
  });
89
89
  };
90
90
 
91
- // src/getStations.ts
91
+ // src/getBookingRequest.ts
92
92
  import { z as z2 } from "zod";
93
- var IncludeSchema = z2.enum(["INFO", "OPEN_HOUR", "SERVICES"]);
94
- var IncludesSchema = z2.array(IncludeSchema);
93
+ var getBookingRequestById = async (client, id) => {
94
+ const result = z2.string().trim().min(1).uuid().safeParse(id);
95
+ if (!result.success) {
96
+ throw new TypeError("Invalid id", {
97
+ cause: result.error.issues
98
+ });
99
+ }
100
+ return client.get(
101
+ `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${id}`
102
+ ).then(({ data }) => data);
103
+ };
104
+ var getBookingRequestByTrip = async (client, tripId) => {
105
+ const result = z2.string().trim().min(1).safeParse(tripId);
106
+ if (!result.success) {
107
+ throw new TypeError("Invalid tripId", {
108
+ cause: result.error.issues
109
+ });
110
+ }
111
+ return client.get(
112
+ `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/trip/${tripId}`
113
+ ).then(({ data }) => data);
114
+ };
115
+ var getSubscriptionBookingRequestById = async (client, id) => {
116
+ const result = z2.string().trim().min(1).uuid().safeParse(id);
117
+ if (!result.success) {
118
+ throw new TypeError("Invalid id", {
119
+ cause: result.error.issues
120
+ });
121
+ }
122
+ return client.get(
123
+ `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/subscription/bookingrequests/${id}`
124
+ ).then(({ data: { stationId, ...data } }) => ({ station: stationId, ...data }));
125
+ };
126
+
127
+ // src/getStations.ts
128
+ import { z as z3 } from "zod";
129
+ var IncludeSchema = z3.enum(["INFO", "OPEN_HOUR", "SERVICES"]);
130
+ var IncludesSchema = z3.array(IncludeSchema);
95
131
  var getStations = async (client, includes = []) => {
96
132
  const resultIncludes = IncludesSchema.safeParse(includes);
97
133
  if (!resultIncludes.success) {
@@ -180,8 +216,11 @@ var getStations = async (client, includes = []) => {
180
216
  return stations;
181
217
  };
182
218
  export {
219
+ getBookingRequestById,
220
+ getBookingRequestByTrip,
183
221
  getBookingRequests,
184
222
  getScheduleBookingRequests,
185
223
  getStations,
224
+ getSubscriptionBookingRequestById,
186
225
  getSubscriptionBookingRequests
187
226
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulog/aima-booking",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,8 @@
8
8
  "build": "tsup",
9
9
  "dev": "tsup --watch",
10
10
  "test": "vitest run",
11
- "test:watch": "vitest"
11
+ "test:watch": "vitest",
12
+ "lint": "eslint src/**/* --ext .ts"
12
13
  },
13
14
  "keywords": [
14
15
  "AIMA",
@@ -18,24 +19,23 @@
18
19
  "author": "Vulog",
19
20
  "license": "ISC",
20
21
  "devDependencies": {
21
- "@types/lodash": "^4.17.12",
22
- "@types/node": "^22.7.9",
22
+ "@types/node": "^22.10.1",
23
23
  "eslint-config-airbnb-base": "^15.0.0",
24
24
  "eslint-config-airbnb-typescript": "^18.0.0",
25
25
  "eslint-config-prettier": "^9.1.0",
26
26
  "eslint-plugin-import": "^2.31.0",
27
27
  "eslint-plugin-prettier": "^5.2.1",
28
28
  "eslint-plugin-unused-imports": "^4.1.4",
29
- "prettier": "^3.3.3",
30
- "tsup": "^8.3.0",
31
- "typescript": "^5.6.3",
32
- "vitest": "^2.1.3"
29
+ "prettier": "^3.4.1",
30
+ "tsup": "^8.3.5",
31
+ "typescript": "^5.7.2",
32
+ "vitest": "^2.1.8"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@vulog/aima-client": "^1.0.0",
36
36
  "@vulog/aima-core": "^1.0.0",
37
- "lodash": "^4.17.21",
37
+ "es-toolkit": "^1.29.0",
38
38
  "zod": "^3.23.8"
39
39
  },
40
40
  "description": ""
41
- }
41
+ }
@@ -0,0 +1,446 @@
1
+ import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { getBookingRequestById, getBookingRequestByTrip, getSubscriptionBookingRequestById } from './getBookingRequest';
3
+ import { Client } from '@vulog/aima-client';
4
+ import { randomUUID } from 'crypto';
5
+ import { PaymentReceipts } from './types';
6
+
7
+ describe('getBookingRequestByID', () => {
8
+ const getMock = vi.fn();
9
+ const client = {
10
+ get: getMock,
11
+ clientOptions: {
12
+ fleetId: 'FLEET_ID',
13
+ },
14
+ } as unknown as Client;
15
+
16
+ beforeEach(() => {
17
+ getMock.mockReset();
18
+ vi.useFakeTimers({ now: new Date('2025-01-12T13:35:50.123Z') });
19
+ });
20
+
21
+ afterEach(() => {
22
+ vi.useRealTimers();
23
+ });
24
+
25
+ test('call OK', async () => {
26
+ const data = {
27
+ id: 'e5ebc129-2c28-4111-993d-9b0edae26e84',
28
+ startDate: '2024-11-29T08:00:00Z',
29
+ endDate: '2024-11-29T09:00:00Z',
30
+ returnedDate: '2024-11-18T16:36:50Z',
31
+ profileId: '9cf8f71b-a535-4b26-b6bd-2b9856cd1cbc',
32
+ vehicleId: 'b78d5df9-3d7d-4fd9-bb05-8e6e3b005fcb',
33
+ modelId: 2722,
34
+ journeyId: '7FA2210A986C2769678CB958434E41DA',
35
+ station: '0e4a1a69-717f-40b6-b57b-e51587451c10',
36
+ profileType: null,
37
+ entityName: null,
38
+ status: 'CONFIRMED',
39
+ creationDate: '2024-11-14T13:27:30Z',
40
+ realStartDate: '2024-11-18T16:31:44Z',
41
+ cancellationDate: null,
42
+ cancelledBy: null,
43
+ fleetId: 'VULOG-FRNCE',
44
+ userId: 'e2a19a00-87de-4e3e-8da3-6053cb137c47',
45
+ latitude: null,
46
+ longitude: null,
47
+ radius: null,
48
+ serviceId: '71ee2cd8-1857-407e-adb9-e323311b3620',
49
+ warning: null,
50
+ email: null,
51
+ paymentReceipts: [
52
+ {
53
+ id: '673b64d4748a38189efe859c',
54
+ pspName: 'ADYEN',
55
+ pspReference: 'HHJLM9M2D725VDV6',
56
+ amount: 60,
57
+ currency: 'EUR',
58
+ date: '2024-11-18T16:01:24.542Z',
59
+ status: 'AUTHORIZED',
60
+ paymentMethodType: 'CREDIT_CARD',
61
+ number: 10942,
62
+ metadatas: {
63
+ scope: 'RENTAL',
64
+ }
65
+ },
66
+ ],
67
+ credits: null,
68
+ requiresActionReturnURL: null,
69
+ trip: null,
70
+ failureReason: null,
71
+ cityId: 'a91a8d56-4bf8-4a88-9afb-3f3cc255e4f8',
72
+ vehicleResidualValue: null,
73
+ price: null,
74
+ notes: null,
75
+ plannedReturnDate: null,
76
+ deliveryAddress: null,
77
+ deliveryAddressAdditionalInfo: null,
78
+ deliveryCity: null,
79
+ deliveryPostalCode: null,
80
+ dropOffStation: null,
81
+ thresholdDateLimit: null,
82
+ cancellationFeeAmount: null,
83
+ rollingContract: false,
84
+ planDurationInMonths: null,
85
+ planName: null,
86
+ parentId: null,
87
+ contractType: null,
88
+ previous: null,
89
+ customPrice: null,
90
+ productIds: [
91
+ 'f271997b-1184-429d-b951-bde23c1e2711'
92
+ ],
93
+ preallocatedVehicleId: null,
94
+ bookingReferenceId: 'bW9ACW',
95
+ pricingDetails: [
96
+ {
97
+ pricingId: '4405ffcb-5573-4fe3-8f19-5a3433b59bf4',
98
+ providerType: 'DEFAULT',
99
+ }
100
+ ],
101
+ earlyCancelledByUser: false,
102
+ completed: true,
103
+ };
104
+ getMock.mockResolvedValueOnce({
105
+ data: data,
106
+ });
107
+
108
+ const brId = randomUUID();
109
+ const result = await getBookingRequestById(client, brId);
110
+ expect(getMock).toBeCalled();
111
+ expect(getMock).toBeCalledWith(
112
+ `/boapi/proxy/user/scheduledBooking/fleets/FLEET_ID/bookingrequests/${brId}`
113
+ );
114
+ expect(result).toBeTruthy();
115
+ expect(result.id).toEqual(data.id);
116
+ expect(result.startDate).toEqual(data.startDate);
117
+ expect(result.endDate).toEqual(data.endDate);
118
+ expect(result.returnedDate).toEqual(data.returnedDate);
119
+ expect(result.profileId).toEqual(data.profileId);
120
+ expect(result.vehicleId).toEqual(data.vehicleId);
121
+ expect(result.modelId).toEqual(data.modelId);
122
+ expect(result.journeyId).toEqual(data.journeyId);
123
+ expect(result.station).toEqual(data.station);
124
+ expect(result.profileType).toEqual(data.profileType);
125
+ expect(result.entityName).toEqual(data.entityName);
126
+ expect(result.status).toEqual(data.status);
127
+ expect(result.creationDate).toEqual(data.creationDate);
128
+ expect(result.realStartDate).toEqual(data.realStartDate);
129
+ expect(result.cancellationDate).toEqual(data.cancellationDate);
130
+ expect(result.cancelledBy).toEqual(data.cancelledBy);
131
+ expect(result.fleetId).toEqual(data.fleetId);
132
+ expect(result.userId).toEqual(data.userId);
133
+ expect(result.serviceId).toEqual(data.serviceId);
134
+ expect(result.warning).toEqual(data.warning);
135
+ expect(result.paymentReceipts).toBeTruthy();
136
+ expect(result.paymentReceipts?.length).toEqual(data.paymentReceipts.length);
137
+ const pr = result.paymentReceipts ? result.paymentReceipts[0] : null;
138
+ expect(pr).toBeTruthy();
139
+ expect(pr?.id).toEqual(data.paymentReceipts[0].id);
140
+ expect(pr?.pspName).toEqual(data.paymentReceipts[0].pspName);
141
+ expect(pr?.pspReference).toEqual(data.paymentReceipts[0].pspReference);
142
+ expect(pr?.amount).toEqual(data.paymentReceipts[0].amount);
143
+ expect(pr?.currency).toEqual(data.paymentReceipts[0].currency);
144
+ expect(pr?.date).toEqual(data.paymentReceipts[0].date);
145
+ expect(pr?.status).toEqual(data.paymentReceipts[0].status);
146
+ expect(pr?.paymentMethodType).toEqual(data.paymentReceipts[0].paymentMethodType);
147
+ expect(pr?.number).toEqual(data.paymentReceipts[0].number);
148
+ expect(pr?.metadatas).toBeTruthy();
149
+ expect(pr?.metadatas.scope).toEqual(data.paymentReceipts[0].metadatas.scope);
150
+ expect(result.credits).toEqual(data.credits);
151
+ expect(result.requiresActionReturnURL).toEqual(data.requiresActionReturnURL);
152
+ expect(result.trip).toEqual(data.trip);
153
+ expect(result.failureReason).toEqual(data.failureReason);
154
+ expect(result.cityId).toEqual(data.cityId);
155
+ expect(result.vehicleResidualValue).toEqual(data.vehicleResidualValue);
156
+ expect(result.price).toEqual(data.price);
157
+ expect(result.notes).toEqual(data.notes);
158
+ expect(result.plannedReturnDate).toEqual(data.plannedReturnDate);
159
+ expect(result.deliveryAddress).toEqual(data.deliveryAddress);
160
+ expect(result.deliveryAddressAdditionalInfo).toEqual(data.deliveryAddressAdditionalInfo);
161
+ expect(result.deliveryCity).toEqual(data.deliveryCity);
162
+ expect(result.deliveryPostalCode).toEqual(data.deliveryPostalCode);
163
+ expect(result.dropOffStation).toEqual(data.dropOffStation);
164
+ expect(result.thresholdDateLimit).toEqual(data.thresholdDateLimit);
165
+ expect(result.cancellationFeeAmount).toEqual(data.cancellationFeeAmount);
166
+ expect(result.rollingContract).toEqual(data.rollingContract);
167
+ expect(result.planDurationInMonths).toEqual(data.planDurationInMonths);
168
+ expect(result.planName).toEqual(data.planName);
169
+ expect(result.parentId).toEqual(data.parentId);
170
+ expect(result.contractType).toEqual(data.contractType);
171
+ expect(result.previous).toEqual(data.previous);
172
+ expect(result.customPrice).toEqual(data.customPrice);
173
+ expect(result.productIds).toBeTruthy();
174
+ expect(result.productIds.length).toEqual(data.productIds.length);
175
+ expect(result.productIds[0]).toEqual(data.productIds[0]);
176
+ expect(result.preallocatedVehicleId).toEqual(data.preallocatedVehicleId);
177
+ expect(result.bookingReferenceId).toEqual(data.bookingReferenceId);
178
+ expect(result.pricingDetails).toBeTruthy();
179
+ expect(result.pricingDetails.length).toEqual(data.pricingDetails.length);
180
+ expect(result.pricingDetails[0].pricingId).toEqual(data.pricingDetails[0].pricingId);
181
+ expect(result.pricingDetails[0].providerType).toEqual(data.pricingDetails[0].providerType);
182
+ expect(result.earlyCancelledByUser).toEqual(data.earlyCancelledByUser);
183
+ expect(result.completed).toEqual(data.completed);
184
+ });
185
+ });
186
+
187
+ describe('getBookingRequestByTripID', () => {
188
+ const getMock = vi.fn();
189
+ const client = {
190
+ get: getMock,
191
+ clientOptions: {
192
+ fleetId: 'FLEET_ID',
193
+ },
194
+ } as unknown as Client;
195
+
196
+ beforeEach(() => {
197
+ getMock.mockReset();
198
+ vi.useFakeTimers({ now: new Date('2025-01-12T13:35:50.123Z') });
199
+ });
200
+
201
+ afterEach(() => {
202
+ vi.useRealTimers();
203
+ });
204
+
205
+ test('call byTrip OK', async () => {
206
+ const data = {
207
+ id: 'e5ebc129-2c28-4111-993d-9b0edae26e84',
208
+ startDate: '2024-11-29T08:00:00Z',
209
+ endDate: '2024-11-29T09:00:00Z',
210
+ returnedDate: '2024-11-18T16:36:50Z',
211
+ profileId: '9cf8f71b-a535-4b26-b6bd-2b9856cd1cbc',
212
+ vehicleId: 'b78d5df9-3d7d-4fd9-bb05-8e6e3b005fcb',
213
+ modelId: 2722,
214
+ journeyId: '7FA2210A986C2769678CB958434E41DA',
215
+ station: '0e4a1a69-717f-40b6-b57b-e51587451c10',
216
+ profileType: null,
217
+ entityName: null,
218
+ status: 'CONFIRMED',
219
+ creationDate: '2024-11-14T13:27:30Z',
220
+ realStartDate: '2024-11-18T16:31:44Z',
221
+ cancellationDate: null,
222
+ cancelledBy: null,
223
+ fleetId: 'VULOG-FRNCE',
224
+ userId: 'e2a19a00-87de-4e3e-8da3-6053cb137c47',
225
+ latitude: null,
226
+ longitude: null,
227
+ radius: null,
228
+ serviceId: '71ee2cd8-1857-407e-adb9-e323311b3620',
229
+ warning: null,
230
+ email: null,
231
+ credits: null,
232
+ requiresActionReturnURL: null,
233
+ trip: null,
234
+ failureReason: null,
235
+ cityId: 'a91a8d56-4bf8-4a88-9afb-3f3cc255e4f8',
236
+ vehicleResidualValue: null,
237
+ price: null,
238
+ notes: null,
239
+ plannedReturnDate: null,
240
+ deliveryAddress: null,
241
+ deliveryAddressAdditionalInfo: null,
242
+ deliveryCity: null,
243
+ deliveryPostalCode: null,
244
+ dropOffStation: null,
245
+ thresholdDateLimit: null,
246
+ cancellationFeeAmount: null,
247
+ rollingContract: false,
248
+ planDurationInMonths: null,
249
+ planName: null,
250
+ parentId: null,
251
+ contractType: null,
252
+ previous: null,
253
+ customPrice: null,
254
+ productIds: [
255
+ 'f271997b-1184-429d-b951-bde23c1e2711'
256
+ ],
257
+ preallocatedVehicleId: null,
258
+ bookingReferenceId: 'bW9ACW',
259
+ pricingDetails: [
260
+ {
261
+ pricingId: '4405ffcb-5573-4fe3-8f19-5a3433b59bf4',
262
+ providerType: 'DEFAULT',
263
+ }
264
+ ],
265
+ earlyCancelledByUser: false,
266
+ completed: true,
267
+ };
268
+ getMock.mockResolvedValueOnce({
269
+ data: data,
270
+ });
271
+
272
+ const tripId = randomUUID();
273
+ const result = await getBookingRequestByTrip(client, tripId);
274
+ expect(getMock).toBeCalled();
275
+ expect(getMock).toBeCalledWith(
276
+ `/boapi/proxy/user/scheduledBooking/fleets/FLEET_ID/bookingrequests/trip/${tripId}`
277
+ );
278
+ expect(result).toBeTruthy();
279
+ expect(result.id).toEqual(data.id);
280
+ expect(result.startDate).toEqual(data.startDate);
281
+ expect(result.endDate).toEqual(data.endDate);
282
+ expect(result.returnedDate).toEqual(data.returnedDate);
283
+ expect(result.profileId).toEqual(data.profileId);
284
+ expect(result.vehicleId).toEqual(data.vehicleId);
285
+ expect(result.modelId).toEqual(data.modelId);
286
+ expect(result.journeyId).toEqual(data.journeyId);
287
+ expect(result.station).toEqual(data.station);
288
+ expect(result.profileType).toEqual(data.profileType);
289
+ expect(result.entityName).toEqual(data.entityName);
290
+ expect(result.status).toEqual(data.status);
291
+ expect(result.creationDate).toEqual(data.creationDate);
292
+ expect(result.realStartDate).toEqual(data.realStartDate);
293
+ expect(result.cancellationDate).toEqual(data.cancellationDate);
294
+ expect(result.cancelledBy).toEqual(data.cancelledBy);
295
+ expect(result.fleetId).toEqual(data.fleetId);
296
+ expect(result.userId).toEqual(data.userId);
297
+ expect(result.serviceId).toEqual(data.serviceId);
298
+ expect(result.warning).toEqual(data.warning);
299
+ expect(result.credits).toEqual(data.credits);
300
+ expect(result.requiresActionReturnURL).toEqual(data.requiresActionReturnURL);
301
+ expect(result.trip).toEqual(data.trip);
302
+ expect(result.failureReason).toEqual(data.failureReason);
303
+ expect(result.cityId).toEqual(data.cityId);
304
+ expect(result.vehicleResidualValue).toEqual(data.vehicleResidualValue);
305
+ expect(result.price).toEqual(data.price);
306
+ expect(result.notes).toEqual(data.notes);
307
+ expect(result.plannedReturnDate).toEqual(data.plannedReturnDate);
308
+ expect(result.deliveryAddress).toEqual(data.deliveryAddress);
309
+ expect(result.deliveryAddressAdditionalInfo).toEqual(data.deliveryAddressAdditionalInfo);
310
+ expect(result.deliveryCity).toEqual(data.deliveryCity);
311
+ expect(result.deliveryPostalCode).toEqual(data.deliveryPostalCode);
312
+ expect(result.dropOffStation).toEqual(data.dropOffStation);
313
+ expect(result.thresholdDateLimit).toEqual(data.thresholdDateLimit);
314
+ expect(result.cancellationFeeAmount).toEqual(data.cancellationFeeAmount);
315
+ expect(result.rollingContract).toEqual(data.rollingContract);
316
+ expect(result.planDurationInMonths).toEqual(data.planDurationInMonths);
317
+ expect(result.planName).toEqual(data.planName);
318
+ expect(result.parentId).toEqual(data.parentId);
319
+ expect(result.contractType).toEqual(data.contractType);
320
+ expect(result.previous).toEqual(data.previous);
321
+ expect(result.customPrice).toEqual(data.customPrice);
322
+ expect(result.productIds).toBeTruthy();
323
+ expect(result.productIds.length).toEqual(data.productIds.length);
324
+ expect(result.productIds[0]).toEqual(data.productIds[0]);
325
+ expect(result.preallocatedVehicleId).toEqual(data.preallocatedVehicleId);
326
+ expect(result.bookingReferenceId).toEqual(data.bookingReferenceId);
327
+ expect(result.pricingDetails).toBeTruthy();
328
+ expect(result.pricingDetails.length).toEqual(data.pricingDetails.length);
329
+ expect(result.pricingDetails[0].pricingId).toEqual(data.pricingDetails[0].pricingId);
330
+ expect(result.pricingDetails[0].providerType).toEqual(data.pricingDetails[0].providerType);
331
+ expect(result.earlyCancelledByUser).toEqual(data.earlyCancelledByUser);
332
+ expect(result.completed).toEqual(data.completed);
333
+ });
334
+ });
335
+
336
+ describe('getsubscriptionBookingRequestByID', () => {
337
+ const getMock = vi.fn();
338
+ const client = {
339
+ get: getMock,
340
+ clientOptions: {
341
+ fleetId: 'FLEET_ID',
342
+ },
343
+ } as unknown as Client;
344
+
345
+ beforeEach(() => {
346
+ getMock.mockReset();
347
+ vi.useFakeTimers({ now: new Date('2025-01-12T13:35:50.123Z') });
348
+ });
349
+
350
+ afterEach(() => {
351
+ vi.useRealTimers();
352
+ });
353
+
354
+ test('call SubscriptionById OK', async () => {
355
+ const data = {
356
+ id: 'e5ebc129-2c28-4111-993d-9b0edae26e84',
357
+ startDate: '2024-11-29T08:00:00Z',
358
+ endDate: '2024-11-29T09:00:00Z',
359
+ profileId: '9cf8f71b-a535-4b26-b6bd-2b9856cd1cbc',
360
+ vehicleId: 'b78d5df9-3d7d-4fd9-bb05-8e6e3b005fcb',
361
+ modelId: 2722,
362
+ status: 'CONFIRMED',
363
+ creationDate: '2024-11-14T13:27:30Z',
364
+ fleetId: 'VULOG-FRNCE',
365
+ userId: 'e2a19a00-87de-4e3e-8da3-6053cb137c47',
366
+ serviceId: '71ee2cd8-1857-407e-adb9-e323311b3620',
367
+ cityId: 'a91a8d56-4bf8-4a88-9afb-3f3cc255e4f8',
368
+ pricingId: null,
369
+ productIds: [
370
+ 'f271997b-1184-429d-b951-bde23c1e2711'
371
+ ],
372
+ modelBasePrice: null,
373
+ modelRate: null,
374
+ vehicleResidualValue: null,
375
+ deliveryAddress: null,
376
+ deliveryAddressAdditionalInfo: null,
377
+ deliveryCity: null,
378
+ deliveryPostalCode: null,
379
+ pricePerUnit: '3750.00',
380
+ plannedReturnDate: null,
381
+ notes: null,
382
+ modelName: '718 Boxster',
383
+ vehiclePlate: 'SP XL 920',
384
+ journeyId: 'ED169129570A75211BB2E4C0BDDAA844',
385
+ returnedDate: '2024-06-25T15:21:24Z',
386
+ cancellationDate: null,
387
+ contractType: 'MVS',
388
+ parentId: 'f544a02f-54f2-4b57-9d40-bca83dab79d6',
389
+ previous: null,
390
+ type: 'SLAVE',
391
+ rollingContract: true,
392
+ bookingReferenceId: '61IP5M',
393
+ completed: true,
394
+ stationId: 'a4331f44-9ee2-4d09-b3d7-9a2b2952f3d3',
395
+ };
396
+ getMock.mockResolvedValueOnce({
397
+ data: data,
398
+ });
399
+
400
+ const id = randomUUID();
401
+ const result = await getSubscriptionBookingRequestById(client, id);
402
+ expect(getMock).toBeCalled();
403
+ expect(getMock).toBeCalledWith(
404
+ `/boapi/proxy/user/scheduledBooking/fleets/FLEET_ID/subscription/bookingrequests/${id}`
405
+ );
406
+ expect(result).toBeTruthy();
407
+ expect(result.id).toEqual(data.id);
408
+ expect(result.startDate).toEqual(data.startDate);
409
+ expect(result.endDate).toEqual(data.endDate);
410
+ expect(result.profileId).toEqual(data.profileId);
411
+ expect(result.vehicleId).toEqual(data.vehicleId);
412
+ expect(result.modelId).toEqual(data.modelId);
413
+ expect(result.status).toEqual(data.status);
414
+ expect(result.creationDate).toEqual(data.creationDate);
415
+ expect(result.fleetId).toEqual(data.fleetId);
416
+ expect(result.userId).toEqual(data.userId);
417
+ expect(result.serviceId).toEqual(data.serviceId);
418
+ expect(result.cityId).toEqual(data.cityId);
419
+ expect(result.productIds).toBeTruthy();
420
+ expect(result.productIds.length).toEqual(data.productIds.length);
421
+ expect(result.productIds[0]).toEqual(data.productIds[0]);
422
+ expect(result.modelBasePrice).toEqual(data.modelBasePrice);
423
+ expect(result.modelRate).toEqual(data.modelRate);
424
+ expect(result.vehicleResidualValue).toEqual(data.vehicleResidualValue);
425
+ expect(result.deliveryAddress).toEqual(data.deliveryAddress);
426
+ expect(result.deliveryAddressAdditionalInfo).toEqual(data.deliveryAddressAdditionalInfo);
427
+ expect(result.deliveryCity).toEqual(data.deliveryCity);
428
+ expect(result.deliveryPostalCode).toEqual(data.deliveryPostalCode);
429
+ expect(result.pricePerUnit).toEqual(data.pricePerUnit);
430
+ expect(result.plannedReturnDate).toEqual(data.plannedReturnDate);
431
+ expect(result.notes).toEqual(data.notes);
432
+ expect(result.modelName).toEqual(data.modelName);
433
+ expect(result.vehiclePlate).toEqual(data.vehiclePlate);
434
+ expect(result.journeyId).toEqual(data.journeyId);
435
+ expect(result.returnedDate).toEqual(data.returnedDate);
436
+ expect(result.cancellationDate).toEqual(data.cancellationDate);
437
+ expect(result.contractType).toEqual(data.contractType);
438
+ expect(result.parentId).toEqual(data.parentId);
439
+ expect(result.previous).toEqual(data.previous);
440
+ expect(result.type).toEqual(data.type);
441
+ expect(result.rollingContract).toEqual(data.rollingContract);
442
+ expect(result.bookingReferenceId).toEqual(data.bookingReferenceId);
443
+ expect(result.completed).toEqual(data.completed);
444
+ expect(result.station).toEqual(data.stationId);
445
+ });
446
+ });
@@ -0,0 +1,48 @@
1
+ import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
3
+
4
+ import { BookingRequest } from './types';
5
+
6
+ export const getBookingRequestById = async (client: Client, id: string): Promise<BookingRequest> => {
7
+ const result = z.string().trim().min(1).uuid().safeParse(id);
8
+ if (!result.success) {
9
+ throw new TypeError('Invalid id', {
10
+ cause: result.error.issues,
11
+ });
12
+ }
13
+ return client
14
+ .get<BookingRequest>(
15
+ `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${id}`
16
+ )
17
+ .then(({ data }) => data);
18
+ };
19
+
20
+ export const getBookingRequestByTrip = async (client: Client, tripId: string): Promise<BookingRequest> => {
21
+ const result = z.string().trim().min(1).safeParse(tripId);
22
+ if (!result.success) {
23
+ throw new TypeError('Invalid tripId', {
24
+ cause: result.error.issues,
25
+ });
26
+ }
27
+ return client
28
+ .get<BookingRequest>(
29
+ `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/trip/${tripId}`
30
+ )
31
+ .then(({ data }) => data);
32
+ };
33
+
34
+ type BookingRequestSubscription = Omit<BookingRequest, 'station'> & { stationId: string };
35
+
36
+ export const getSubscriptionBookingRequestById = async (client: Client, id: string): Promise<BookingRequest> => {
37
+ const result = z.string().trim().min(1).uuid().safeParse(id);
38
+ if (!result.success) {
39
+ throw new TypeError('Invalid id', {
40
+ cause: result.error.issues,
41
+ });
42
+ }
43
+ return client
44
+ .get<BookingRequestSubscription>(
45
+ `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/subscription/bookingrequests/${id}`
46
+ )
47
+ .then(({ data: { stationId, ...data } }) => ({ station: stationId, ...data }) as BookingRequest);
48
+ };
@@ -21,9 +21,9 @@ describe('getBookingRequests', () => {
21
21
  });
22
22
 
23
23
  test('Fake status', async () => {
24
- const rejects = await expect(() => getBookingRequests({} as Client, 'FAKE' as any)).rejects;
25
- rejects.toThrowError('Invalid status');
26
- rejects.toSatisfy((error: any) => {
24
+ const rejects = expect(() => getBookingRequests({} as Client, 'FAKE' as any)).rejects;
25
+ await rejects.toThrowError('Invalid status');
26
+ await rejects.toSatisfy((error: any) => {
27
27
  expect(error).toHaveProperty('cause');
28
28
  expect(error.cause).toHaveLength(1);
29
29
  expect(error.cause[0]).toHaveProperty('received');
@@ -35,13 +35,13 @@ describe('getBookingRequests', () => {
35
35
  });
36
36
 
37
37
  test('negative page', async () => {
38
- const rejects = await expect(() =>
38
+ const rejects = expect(() =>
39
39
  getBookingRequests({} as Client, 'UPCOMING', {
40
40
  page: -1,
41
41
  })
42
42
  ).rejects;
43
- rejects.toThrowError('Invalid options');
44
- rejects.toSatisfy((error: any) => {
43
+ await rejects.toThrowError('Invalid options');
44
+ await rejects.toSatisfy((error: any) => {
45
45
  expect(error).toHaveProperty('cause');
46
46
  expect(error.cause).toHaveLength(1);
47
47
  expect(error.cause[0]).toHaveProperty('path');
@@ -53,14 +53,14 @@ describe('getBookingRequests', () => {
53
53
  });
54
54
 
55
55
  test('negative pageSize', async () => {
56
- const rejects = await expect(() =>
56
+ const rejects = expect(() =>
57
57
  getBookingRequests({} as Client, 'UPCOMING', {
58
58
  page: 0,
59
59
  pageSize: -1,
60
60
  })
61
61
  ).rejects;
62
- rejects.toThrowError('Invalid options');
63
- rejects.toSatisfy((error: any) => {
62
+ await rejects.toThrowError('Invalid options');
63
+ await rejects.toSatisfy((error: any) => {
64
64
  expect(error).toHaveProperty('cause');
65
65
  expect(error.cause).toHaveLength(1);
66
66
  expect(error.cause[0]).toHaveProperty('path');
@@ -72,13 +72,13 @@ describe('getBookingRequests', () => {
72
72
  });
73
73
 
74
74
  test('too big pageSize', async () => {
75
- const rejects = await expect(() =>
75
+ const rejects = expect(() =>
76
76
  getBookingRequests({} as Client, 'UPCOMING', {
77
77
  pageSize: 1001,
78
78
  })
79
79
  ).rejects;
80
- rejects.toThrowError('Invalid options');
81
- rejects.toSatisfy((error: any) => {
80
+ await rejects.toThrowError('Invalid options');
81
+ await rejects.toSatisfy((error: any) => {
82
82
  expect(error).toHaveProperty('cause');
83
83
  expect(error.cause).toHaveLength(1);
84
84
  expect(error.cause[0]).toHaveProperty('path');
@@ -1,8 +1,10 @@
1
1
  import { Client } from '@vulog/aima-client';
2
2
  import { createPaginableOptionsSchema, PaginableOptions, PaginableResponse } from '@vulog/aima-core';
3
- import { isNumber } from 'lodash';
3
+ import { isNumber } from 'es-toolkit/compat';
4
4
  import { z } from 'zod';
5
5
 
6
+ import { BookingRequest } from './types';
7
+
6
8
  const BookingRequestStatusSchema = z.enum([
7
9
  'ALERT',
8
10
  'UPCOMING',
@@ -28,7 +30,7 @@ export type SpecificBookingRequestFilters = {
28
30
  creationDate?: string;
29
31
  /**
30
32
  * Format: yyyy-MM-dd'T'HH:mm:ssZ
31
- * default now plus 2 months
33
+ * default now
32
34
  */
33
35
  startDate?: string;
34
36
  /**
@@ -41,43 +43,6 @@ export type BookingRequestFilters = SpecificBookingRequestFilters & {
41
43
  serviceTypes?: ServiceType[];
42
44
  };
43
45
 
44
- export type BookingRequest = {
45
- id: string;
46
- startDate: string;
47
- endDate: string;
48
- returnedDate?: string;
49
- profileId: string;
50
- vehicleId?: string;
51
- modelId: 1647;
52
- journeyId?: string;
53
- station: string;
54
- profileType: 'Single' | 'Business';
55
- entityName?: string;
56
- status: string;
57
- creationDate: string;
58
- realStartDate?: string;
59
- cancellationDate?: string;
60
- cancelledBy?: string;
61
- userId: string;
62
- serviceId: string;
63
- cityId: string;
64
- deliveryAddress?: string;
65
- deliveryAddressAdditionalInfo?: string;
66
- deliveryCity?: string;
67
- deliveryPostalCode?: string;
68
- rollingContract: string;
69
- planDurationInMonths?: number;
70
- contractType?: string;
71
- productIds: string[];
72
- bookingReferenceId?: string;
73
- pricingDetails: {
74
- pricingId: string;
75
- providerType: string;
76
- }[];
77
- completed: boolean;
78
- [key: string]: any;
79
- };
80
-
81
46
  export const getBookingRequests = async (
82
47
  client: Client,
83
48
  status: BookingRequestStatus,
@@ -22,9 +22,9 @@ describe('getStations', () => {
22
22
  });
23
23
 
24
24
  test('Fake includes', async () => {
25
- const rejects = await expect(() => getStations(client, 'FAKE' as any)).rejects;
26
- rejects.toThrowError('Invalid includes');
27
- rejects.toSatisfy((error: any) => {
25
+ const rejects = expect(() => getStations(client, 'FAKE' as any)).rejects;
26
+ await rejects.toThrowError('Invalid includes');
27
+ await rejects.toSatisfy((error: any) => {
28
28
  expect(error).toHaveProperty('cause');
29
29
  expect(error.cause).toHaveLength(1);
30
30
  expect(error.cause[0]).toHaveProperty('code');
@@ -34,9 +34,9 @@ describe('getStations', () => {
34
34
  });
35
35
 
36
36
  test('Fake includes', async () => {
37
- const rejects = await expect(() => getStations(client, ['FAKE'] as any)).rejects;
38
- rejects.toThrowError('Invalid includes');
39
- rejects.toSatisfy((error: any) => {
37
+ const rejects = expect(() => getStations(client, ['FAKE'] as any)).rejects;
38
+ await rejects.toThrowError('Invalid includes');
39
+ await rejects.toSatisfy((error: any) => {
40
40
  expect(error).toHaveProperty('cause');
41
41
  expect(error.cause).toHaveLength(1);
42
42
  expect(error.cause[0]).toHaveProperty('received');
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export { getBookingRequests, getScheduleBookingRequests, getSubscriptionBookingRequests } from './getBookingRequests';
2
- export type { BookingRequest, BookingRequestStatus, ServiceType, BookingRequestFilters } from './getBookingRequests';
2
+ export { getBookingRequestById, getBookingRequestByTrip, getSubscriptionBookingRequestById } from './getBookingRequest';
3
+ export type { BookingRequest } from './types';
4
+ export type { BookingRequestStatus, ServiceType, BookingRequestFilters } from './getBookingRequests';
3
5
  export { getStations } from './getStations';
4
6
  export type { Station, Include, Days, DayOpeningHours, Timetable, OpeningHours } from './getStations';
package/src/types.ts ADDED
@@ -0,0 +1,64 @@
1
+ export type PaymentReceipts = {
2
+ id: string; // '65e99055a978ce72533ee08b'
3
+ pspName: string; // 'ADYEN'
4
+ pspReference: string; // 'M9J884TSHRQWFL65'
5
+ amount: number; // 80.0,
6
+ currency: string; // 'EUR',
7
+ date: string; // 'yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
8
+ status: string; // 'AUTHORIZED', 'PAID'
9
+ paymentMethodType: string; // 'CREDIT_CARD'
10
+ // paymentMethodPspReference: 'CQDHSR78FMGG3PT5',
11
+ paymentIntentPspReference?: string; // 'FP6D9BMWM3TPBC75',
12
+ number: number;
13
+ metadatas: {
14
+ scope: string; // 'RENTAL'
15
+ };
16
+ };
17
+
18
+ export type BookingRequest = {
19
+ id: string;
20
+ startDate: string;
21
+ endDate: string;
22
+ returnedDate?: string;
23
+ profileId: string;
24
+ vehicleId?: string;
25
+ modelId: number;
26
+ journeyId?: string;
27
+ station: string;
28
+ profileType?: 'Single' | 'Business';
29
+ entityName?: string;
30
+ status: string;
31
+ creationDate: string;
32
+ realStartDate?: string;
33
+ cancellationDate?: string;
34
+ cancelledBy?: string;
35
+ fleetId: string;
36
+ userId: string;
37
+ serviceId: string;
38
+ warning?: string;
39
+ paymentReceipts?: PaymentReceipts[];
40
+ credit?: string;
41
+ cityId: string;
42
+ vehicleResidualValue?: number;
43
+ notes?: string;
44
+ plannedReturnDate?: string;
45
+ deliveryAddress?: string;
46
+ deliveryAddressAdditionalInfo?: string;
47
+ deliveryCity?: string;
48
+ deliveryPostalCode?: string;
49
+ dropOffStation?: string;
50
+ rollingContract: boolean;
51
+ planDurationInMonths?: number;
52
+ contractType?: string;
53
+ customPrice?: string;
54
+ productIds: string[];
55
+ bookingReferenceId?: string;
56
+ pricingDetails: {
57
+ pricingId: string;
58
+ providerType: string;
59
+ }[];
60
+ pricePerUnit?: string;
61
+ modelName?: string;
62
+ completed: boolean;
63
+ [key: string]: any;
64
+ };