@vulog/aima-booking 1.2.29 → 1.2.31

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.mjs CHANGED
@@ -1,574 +1,425 @@
1
- // src/getBookingRequests.ts
2
1
  import { createPaginableOptionsSchema } from "@vulog/aima-core";
3
2
  import { isNumber } from "es-toolkit/compat";
4
- import { z } from "zod";
5
- var BookingRequestStatusSchema = z.enum([
6
- "ALERT",
7
- "UPCOMING",
8
- "ONGOING",
9
- "COMPLETED",
10
- "CANCELLED",
11
- "PENDING_APPROVAL",
12
- "CONFIRMED",
13
- "PENDING",
14
- "LATE"
3
+ import z$1, { z } from "zod";
4
+ //#region src/getBookingRequests.ts
5
+ const BookingRequestStatusSchema = z.enum([
6
+ "ALERT",
7
+ "UPCOMING",
8
+ "ONGOING",
9
+ "COMPLETED",
10
+ "CANCELLED",
11
+ "PENDING_APPROVAL",
12
+ "CONFIRMED",
13
+ "PENDING",
14
+ "LATE"
15
15
  ]);
16
- var ServiceTypeSchema = z.enum(["SUBSCRIPTION", "ROUND_TRIP_BOOKING", "SCHEDULED_BOOKING_STATION"]);
17
- var getBookingRequests = async (client, status, options) => {
18
- const preparedOptions = options ? { ...options, filters: options.filters || {} } : { filters: {} };
19
- const resultStatus = BookingRequestStatusSchema.safeParse(status);
20
- if (!resultStatus.success) {
21
- throw new TypeError("Invalid status", {
22
- cause: resultStatus.error.issues
23
- });
24
- }
25
- const date = /* @__PURE__ */ new Date();
26
- date.setMilliseconds(0);
27
- const startDate = date.toISOString().replace(".000Z", "Z");
28
- date.setMonth(date.getMonth() + 2);
29
- const endDate = date.toISOString().replace(".000Z", "Z");
30
- const BookingRequestFiltersSchema = z.object({
31
- serviceTypes: z.array(ServiceTypeSchema).optional(),
32
- serviceIds: z.array(z.string().uuid()).optional(),
33
- userId: z.string().uuid().optional(),
34
- modelId: z.number().positive().optional(),
35
- vehicleId: z.string().uuid().optional(),
36
- stationId: z.string().uuid().optional(),
37
- creationDate: z.string().date().optional(),
38
- startDate: z.string().datetime({ offset: false, precision: 0 }).default(startDate),
39
- endDate: z.string().datetime({ offset: false, precision: 0 }).default(endDate),
40
- includeProducts: z.enum(["true", "false"]).optional()
41
- }).default({});
42
- const PaginableOptionsSchema = createPaginableOptionsSchema(BookingRequestFiltersSchema).default({});
43
- const resultOptions = PaginableOptionsSchema.safeParse(preparedOptions);
44
- if (!resultOptions.success) {
45
- throw new TypeError("Invalid options", {
46
- cause: resultOptions.error.issues
47
- });
48
- }
49
- const finalOptions = resultOptions.data;
50
- const searchParams = new URLSearchParams();
51
- searchParams.append("page", finalOptions.page.toString());
52
- searchParams.append("size", finalOptions.pageSize.toString());
53
- Object.entries(finalOptions.filters).forEach(([key, value]) => {
54
- if (value === void 0) {
55
- return;
56
- }
57
- if (Array.isArray(value) && value.length > 0) {
58
- searchParams.append(key, value.join(","));
59
- return;
60
- }
61
- if (isNumber(value)) {
62
- searchParams.append(key, value.toString());
63
- return;
64
- }
65
- searchParams.append(key, value);
66
- });
67
- return client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/status/${status}/filters?${searchParams.toString()}`).then(({ data, headers }) => {
68
- return {
69
- data,
70
- page: headers.number,
71
- pageSize: headers.size,
72
- total: headers.totalelements,
73
- totalPages: headers.totalpages
74
- };
75
- });
16
+ const ServiceTypeSchema = z.enum([
17
+ "SUBSCRIPTION",
18
+ "ROUND_TRIP_BOOKING",
19
+ "SCHEDULED_BOOKING_STATION"
20
+ ]);
21
+ const getBookingRequests = async (client, status, options) => {
22
+ const preparedOptions = options ? {
23
+ ...options,
24
+ filters: options.filters || {}
25
+ } : { filters: {} };
26
+ const resultStatus = BookingRequestStatusSchema.safeParse(status);
27
+ if (!resultStatus.success) throw new TypeError("Invalid status", { cause: resultStatus.error.issues });
28
+ const date = /* @__PURE__ */ new Date();
29
+ date.setMilliseconds(0);
30
+ const startDate = date.toISOString().replace(".000Z", "Z");
31
+ date.setMonth(date.getMonth() + 2);
32
+ const endDate = date.toISOString().replace(".000Z", "Z");
33
+ const resultOptions = createPaginableOptionsSchema(z.object({
34
+ serviceTypes: z.array(ServiceTypeSchema).optional(),
35
+ serviceIds: z.array(z.string().uuid()).optional(),
36
+ userId: z.string().uuid().optional(),
37
+ modelId: z.number().positive().optional(),
38
+ vehicleId: z.string().uuid().optional(),
39
+ stationId: z.string().uuid().optional(),
40
+ creationDate: z.string().date().optional(),
41
+ startDate: z.string().datetime({
42
+ offset: false,
43
+ precision: 0
44
+ }).default(startDate),
45
+ endDate: z.string().datetime({
46
+ offset: false,
47
+ precision: 0
48
+ }).default(endDate),
49
+ includeProducts: z.enum(["true", "false"]).optional()
50
+ }).default({})).default({}).safeParse(preparedOptions);
51
+ if (!resultOptions.success) throw new TypeError("Invalid options", { cause: resultOptions.error.issues });
52
+ const finalOptions = resultOptions.data;
53
+ const searchParams = new URLSearchParams();
54
+ searchParams.append("page", finalOptions.page.toString());
55
+ searchParams.append("size", finalOptions.pageSize.toString());
56
+ Object.entries(finalOptions.filters).forEach(([key, value]) => {
57
+ if (value === void 0) return;
58
+ if (Array.isArray(value) && value.length > 0) {
59
+ searchParams.append(key, value.join(","));
60
+ return;
61
+ }
62
+ if (isNumber(value)) {
63
+ searchParams.append(key, value.toString());
64
+ return;
65
+ }
66
+ searchParams.append(key, value);
67
+ });
68
+ return client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/status/${status}/filters?${searchParams.toString()}`).then(({ data, headers }) => {
69
+ return {
70
+ data,
71
+ page: headers.number,
72
+ pageSize: headers.size,
73
+ total: headers.totalelements,
74
+ totalPages: headers.totalpages
75
+ };
76
+ });
76
77
  };
77
- var getScheduleBookingRequests = async (client, status, options) => {
78
- return getBookingRequests(client, status, {
79
- ...options,
80
- filters: {
81
- ...options?.filters,
82
- serviceTypes: ["ROUND_TRIP_BOOKING", "SCHEDULED_BOOKING_STATION"]
83
- }
84
- });
78
+ const getScheduleBookingRequests = async (client, status, options) => {
79
+ return getBookingRequests(client, status, {
80
+ ...options,
81
+ filters: {
82
+ ...options?.filters,
83
+ serviceTypes: ["ROUND_TRIP_BOOKING", "SCHEDULED_BOOKING_STATION"]
84
+ }
85
+ });
85
86
  };
86
- var getSubscriptionBookingRequests = async (client, status, options) => {
87
- return getBookingRequests(client, status, {
88
- ...options,
89
- filters: {
90
- ...options?.filters,
91
- serviceTypes: ["SUBSCRIPTION"]
92
- }
93
- });
87
+ const getSubscriptionBookingRequests = async (client, status, options) => {
88
+ return getBookingRequests(client, status, {
89
+ ...options,
90
+ filters: {
91
+ ...options?.filters,
92
+ serviceTypes: ["SUBSCRIPTION"]
93
+ }
94
+ });
94
95
  };
95
-
96
- // src/getSATBookingRequests.ts
97
- import { createPaginableOptionsSchema as createPaginableOptionsSchema2 } from "@vulog/aima-core";
98
- import { z as z2 } from "zod";
99
- var SATBookingRequestStatusSchema = z2.enum([
100
- "ALERT",
101
- "CANCELLED",
102
- "COMPLETED",
103
- "CONFIRMED",
104
- "LATE_RETURN",
105
- "ONGOING",
106
- "PENDING_PAYMENT",
107
- "PENDING",
108
- "UPCOMING_ALLOCATED",
109
- "UPCOMING_NOT_ALLOCATED"
96
+ //#endregion
97
+ //#region src/getSATBookingRequests.ts
98
+ const SATBookingRequestStatusSchema = z.enum([
99
+ "ALERT",
100
+ "CANCELLED",
101
+ "COMPLETED",
102
+ "CONFIRMED",
103
+ "LATE_RETURN",
104
+ "ONGOING",
105
+ "PENDING_PAYMENT",
106
+ "PENDING",
107
+ "UPCOMING_ALLOCATED",
108
+ "UPCOMING_NOT_ALLOCATED"
110
109
  ]);
111
- var getSATBookingRequests = async (client, status, options) => {
112
- const resultStatus = SATBookingRequestStatusSchema.safeParse(status);
113
- if (!resultStatus.success) {
114
- throw new TypeError("Invalid status", {
115
- cause: resultStatus.error.issues
116
- });
117
- }
118
- const PaginableOptionsSchema = createPaginableOptionsSchema2().default({});
119
- const resultOptions = PaginableOptionsSchema.safeParse(options);
120
- if (!resultOptions.success) {
121
- throw new TypeError("Invalid options", {
122
- cause: resultOptions.error.issues
123
- });
124
- }
125
- const finalOptions = resultOptions.data;
126
- const searchParams = new URLSearchParams();
127
- if (finalOptions.page) {
128
- searchParams.append("page", finalOptions.page.toString());
129
- }
130
- if (finalOptions.pageSize) {
131
- searchParams.append("size", finalOptions.pageSize.toString());
132
- }
133
- if (finalOptions.sortDirection && finalOptions.sort) {
134
- searchParams.append("sort", `${finalOptions.sort},${finalOptions.sortDirection}`);
135
- }
136
- if (finalOptions.sort && !finalOptions.sortDirection) {
137
- searchParams.append("sort", finalOptions.sort);
138
- }
139
- return client.get(`/boapi/proxy/user/scheduleATrip/fleets/${client.clientOptions.fleetId}/bookingrequests/status/${status}?${searchParams.toString()}`).then(({ data, headers }) => {
140
- return {
141
- data,
142
- page: headers.number,
143
- pageSize: headers.size,
144
- total: headers.totalelements,
145
- totalPages: headers.totalpages
146
- };
147
- });
110
+ const getSATBookingRequests = async (client, status, options) => {
111
+ const resultStatus = SATBookingRequestStatusSchema.safeParse(status);
112
+ if (!resultStatus.success) throw new TypeError("Invalid status", { cause: resultStatus.error.issues });
113
+ const resultOptions = createPaginableOptionsSchema().default({}).safeParse(options);
114
+ if (!resultOptions.success) throw new TypeError("Invalid options", { cause: resultOptions.error.issues });
115
+ const finalOptions = resultOptions.data;
116
+ const searchParams = new URLSearchParams();
117
+ if (finalOptions.page) searchParams.append("page", finalOptions.page.toString());
118
+ if (finalOptions.pageSize) searchParams.append("size", finalOptions.pageSize.toString());
119
+ if (finalOptions.sortDirection && finalOptions.sort) searchParams.append("sort", `${finalOptions.sort},${finalOptions.sortDirection}`);
120
+ if (finalOptions.sort && !finalOptions.sortDirection) searchParams.append("sort", finalOptions.sort);
121
+ return client.get(`/boapi/proxy/user/scheduleATrip/fleets/${client.clientOptions.fleetId}/bookingrequests/status/${status}?${searchParams.toString()}`).then(({ data, headers }) => {
122
+ return {
123
+ data,
124
+ page: headers.number,
125
+ pageSize: headers.size,
126
+ total: headers.totalelements,
127
+ totalPages: headers.totalpages
128
+ };
129
+ });
148
130
  };
149
-
150
- // src/getBookingRequest.ts
151
- import { z as z3 } from "zod";
152
- var getBookingRequestById = async (client, id) => {
153
- const result = z3.string().trim().min(1).uuid().safeParse(id);
154
- if (!result.success) {
155
- throw new TypeError("Invalid id", {
156
- cause: result.error.issues
157
- });
158
- }
159
- return client.get(
160
- `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${id}`
161
- ).then(({ data }) => data);
131
+ //#endregion
132
+ //#region src/getBookingRequest.ts
133
+ const getBookingRequestById = async (client, id) => {
134
+ const result = z.string().trim().min(1).uuid().safeParse(id);
135
+ if (!result.success) throw new TypeError("Invalid id", { cause: result.error.issues });
136
+ return client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${id}`).then(({ data }) => data);
162
137
  };
163
- var getBookingRequestByTrip = async (client, tripId) => {
164
- const result = z3.string().trim().min(1).safeParse(tripId);
165
- if (!result.success) {
166
- throw new TypeError("Invalid tripId", {
167
- cause: result.error.issues
168
- });
169
- }
170
- return client.get(
171
- `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/trip/${tripId}`
172
- ).then(({ data }) => data);
138
+ const getBookingRequestByTrip = async (client, tripId) => {
139
+ const result = z.string().trim().min(1).safeParse(tripId);
140
+ if (!result.success) throw new TypeError("Invalid tripId", { cause: result.error.issues });
141
+ return client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/trip/${tripId}`).then(({ data }) => data);
173
142
  };
174
- var getSubscriptionBookingRequestById = async (client, id) => {
175
- const result = z3.string().trim().min(1).uuid().safeParse(id);
176
- if (!result.success) {
177
- throw new TypeError("Invalid id", {
178
- cause: result.error.issues
179
- });
180
- }
181
- return client.get(
182
- `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/subscription/bookingrequests/${id}`
183
- ).then(({ data: { stationId, ...data } }) => ({ station: stationId, ...data }));
143
+ const getSubscriptionBookingRequestById = async (client, id) => {
144
+ const result = z.string().trim().min(1).uuid().safeParse(id);
145
+ if (!result.success) throw new TypeError("Invalid id", { cause: result.error.issues });
146
+ return client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/subscription/bookingrequests/${id}`).then(({ data: { stationId, ...data } }) => ({
147
+ station: stationId,
148
+ ...data
149
+ }));
184
150
  };
185
-
186
- // src/getStations.ts
187
- import { z as z4 } from "zod";
188
- var IncludeSchema = z4.enum(["INFO", "OPEN_HOUR", "SERVICES"]);
189
- var IncludesSchema = z4.array(IncludeSchema);
190
- var getStations = async (client, includes = []) => {
191
- const resultIncludes = IncludesSchema.safeParse(includes);
192
- if (!resultIncludes.success) {
193
- throw new TypeError("Invalid includes", {
194
- cause: resultIncludes.error.issues
195
- });
196
- }
197
- const searchParams = new URLSearchParams();
198
- if (includes.includes("OPEN_HOUR")) {
199
- searchParams.append("showTimetable", "true");
200
- }
201
- const stations = await client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/stations${searchParams.size > 0 ? `?${searchParams.toString()}` : ""}`).then(
202
- ({ data }) => data.map(
203
- (station) => Object.keys(station).reduce((acc, key) => {
204
- if (key === "stationTimetableDTO") {
205
- if (station.stationTimetableDTO?.stationId) {
206
- acc.openingHours = {
207
- alwaysOpen: station.stationTimetableDTO.alwaysOpen,
208
- timetable: Object.keys(station.stationTimetableDTO.timetable).reduce(
209
- (timetable, val) => {
210
- timetable[val] = station.stationTimetableDTO.timetable[val].map(
211
- (day) => ({
212
- id: day.id,
213
- closed: day.closed,
214
- openAt: day.openAt,
215
- closeAt: day.closeAt
216
- })
217
- );
218
- return timetable;
219
- },
220
- {}
221
- )
222
- };
223
- }
224
- return acc;
225
- }
226
- acc[key] = station[key];
227
- return acc;
228
- }, {})
229
- )
230
- );
231
- if (includes.includes("INFO")) {
232
- const pois = await client.get(`/boapi/proxy/geoloc/fleets/${client.clientOptions.fleetId}/pois`, {
233
- headers: { accept: "application/vnd.geo+json" }
234
- }).then(
235
- ({ data }) => data.features.reduce((acc, poi) => {
236
- const {
237
- geometry: {
238
- coordinates: [longitude, latitude]
239
- },
240
- properties
241
- } = poi;
242
- acc[properties.poiId] = {
243
- name: properties.name,
244
- coordinates: { latitude, longitude },
245
- geoProperties: properties
246
- };
247
- return acc;
248
- }, {})
249
- );
250
- stations.forEach((station) => {
251
- if (station.poiId && pois[station.poiId]) {
252
- Object.assign(station, pois[station.poiId]);
253
- }
254
- });
255
- }
256
- if (includes.includes("SERVICES")) {
257
- const services = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/stations/details?size=1000`).then(
258
- ({ data }) => data.stations.reduce((acc, service) => {
259
- if (!acc[service.station.id]) {
260
- acc[service.station.id] = { services: [] };
261
- }
262
- acc[service.station.id].services.push({
263
- id: service.serviceId,
264
- models: service.station.models
265
- });
266
- return acc;
267
- }, {})
268
- );
269
- stations.forEach((station) => {
270
- if (services[station.id]) {
271
- Object.assign(station, services[station.id]);
272
- }
273
- });
274
- }
275
- return stations;
151
+ //#endregion
152
+ //#region src/getAvailableVehicles.ts
153
+ /** ISO date-time without milliseconds (e.g. 2025-02-10T12:00:00Z or 2025-02-10T12:00:00+01:00). */
154
+ const isoDateTimeNoMs = z.string().trim().datetime({ precision: 0 });
155
+ const getAvailableVehiclesSchema = z.object({
156
+ stationId: z.string().trim().min(1),
157
+ startDate: isoDateTimeNoMs
158
+ });
159
+ const getAvailableVehicles = async (client, stationId, startDate) => {
160
+ const result = getAvailableVehiclesSchema.safeParse({
161
+ stationId,
162
+ startDate
163
+ });
164
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
165
+ return client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/subscription/stations/${stationId}/vehicles/available?startDate=${startDate}`).then(({ data }) => data);
276
166
  };
277
-
278
- // src/getStation.ts
279
- import { z as z5 } from "zod";
280
- var IncludeSchema2 = z5.enum(["INFO", "SERVICES"]);
281
- var IncludesSchema2 = z5.array(IncludeSchema2);
282
- var getStationById = async (client, id, includes = []) => {
283
- const resultIncludes = IncludesSchema2.safeParse(includes);
284
- if (!resultIncludes.success) {
285
- throw new TypeError("Invalid includes", {
286
- cause: resultIncludes.error.issues
287
- });
288
- }
289
- const station = await client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/stations/${id}`).then(({ data, status }) => {
290
- if (status === 200) {
291
- return Object.keys(data).reduce((acc, key) => {
292
- if (key === "stationTimetableDTO") {
293
- if (data.stationTimetableDTO?.stationId) {
294
- acc.openingHours = {
295
- alwaysOpen: data.stationTimetableDTO.alwaysOpen,
296
- timetable: Object.keys(data.stationTimetableDTO.timetable).reduce(
297
- (timetable, val) => {
298
- timetable[val] = data.stationTimetableDTO.timetable[val].map(
299
- (day) => ({
300
- id: day.id,
301
- closed: day.closed,
302
- openAt: day.openAt,
303
- closeAt: day.closeAt
304
- })
305
- );
306
- return timetable;
307
- },
308
- {}
309
- )
310
- };
311
- }
312
- return acc;
313
- }
314
- acc[key] = data[key];
315
- return acc;
316
- }, {});
317
- }
318
- if (status === 400) {
319
- return null;
320
- }
321
- return null;
322
- }).catch((error) => {
323
- if (error.formattedError?.status === 400) {
324
- return null;
325
- }
326
- throw error;
327
- });
328
- if (station && includes.includes("INFO")) {
329
- const poi = await client.get(
330
- `/boapi/proxy/geoloc/fleets/${client.clientOptions.fleetId}/pois/${station.poiId}`,
331
- {
332
- headers: { accept: "application/vnd.geo+json" }
333
- }
334
- ).then(
335
- ({ data }) => data.features.reduce(
336
- (max, current) => {
337
- if (current.properties.Version > max.version) {
338
- const {
339
- geometry: {
340
- coordinates: [longitude, latitude]
341
- },
342
- properties
343
- } = current;
344
- return {
345
- version: current.properties.Version,
346
- name: properties.name,
347
- coordinates: { latitude, longitude },
348
- geoProperties: properties
349
- };
350
- }
351
- return max;
352
- },
353
- { version: -1 }
354
- )
355
- );
356
- if (station.poiId && poi) {
357
- poi.version = void 0;
358
- Object.assign(station, poi);
359
- station.name = station.geoProperties?.name;
360
- }
361
- }
362
- if (station && includes.includes("SERVICES")) {
363
- const services = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/stations/details?showTimetable=false`).then(
364
- ({ data }) => data.stations.reduce((acc, service) => {
365
- if (!acc[service.station.id]) {
366
- acc[service.station.id] = { services: [] };
367
- }
368
- acc[service.station.id].services.push({
369
- id: service.serviceId,
370
- models: service.station.models
371
- });
372
- return acc;
373
- }, {})
374
- );
375
- if (services[station.id]) {
376
- Object.assign(station, services[station.id]);
377
- }
378
- }
379
- return station;
167
+ //#endregion
168
+ //#region src/getStations.ts
169
+ const IncludeSchema$1 = z.enum([
170
+ "INFO",
171
+ "OPEN_HOUR",
172
+ "SERVICES"
173
+ ]);
174
+ const IncludesSchema$1 = z.array(IncludeSchema$1);
175
+ const getStations = async (client, includes = []) => {
176
+ const resultIncludes = IncludesSchema$1.safeParse(includes);
177
+ if (!resultIncludes.success) throw new TypeError("Invalid includes", { cause: resultIncludes.error.issues });
178
+ const searchParams = new URLSearchParams();
179
+ if (includes.includes("OPEN_HOUR")) searchParams.append("showTimetable", "true");
180
+ const stations = await client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/stations${searchParams.size > 0 ? `?${searchParams.toString()}` : ""}`).then(({ data }) => data.map((station) => Object.keys(station).reduce((acc, key) => {
181
+ if (key === "stationTimetableDTO") {
182
+ if (station.stationTimetableDTO?.stationId) acc.openingHours = {
183
+ alwaysOpen: station.stationTimetableDTO.alwaysOpen,
184
+ timetable: Object.keys(station.stationTimetableDTO.timetable).reduce((timetable, val) => {
185
+ timetable[val] = station.stationTimetableDTO.timetable[val].map((day) => ({
186
+ id: day.id,
187
+ closed: day.closed,
188
+ openAt: day.openAt,
189
+ closeAt: day.closeAt
190
+ }));
191
+ return timetable;
192
+ }, {})
193
+ };
194
+ return acc;
195
+ }
196
+ acc[key] = station[key];
197
+ return acc;
198
+ }, {})));
199
+ if (includes.includes("INFO")) {
200
+ const pois = await client.get(`/boapi/proxy/geoloc/fleets/${client.clientOptions.fleetId}/pois`, { headers: { accept: "application/vnd.geo+json" } }).then(({ data }) => data.features.reduce((acc, poi) => {
201
+ const { geometry: { coordinates: [longitude, latitude] }, properties } = poi;
202
+ acc[properties.poiId] = {
203
+ name: properties.name,
204
+ coordinates: {
205
+ latitude,
206
+ longitude
207
+ },
208
+ geoProperties: properties
209
+ };
210
+ return acc;
211
+ }, {}));
212
+ stations.forEach((station) => {
213
+ if (station.poiId && pois[station.poiId]) Object.assign(station, pois[station.poiId]);
214
+ });
215
+ }
216
+ if (includes.includes("SERVICES")) {
217
+ const services = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/stations/details?size=1000`).then(({ data }) => data.stations.reduce((acc, service) => {
218
+ if (!acc[service.station.id]) acc[service.station.id] = { services: [] };
219
+ acc[service.station.id].services.push({
220
+ id: service.serviceId,
221
+ models: service.station.models
222
+ });
223
+ return acc;
224
+ }, {}));
225
+ stations.forEach((station) => {
226
+ if (services[station.id]) Object.assign(station, services[station.id]);
227
+ });
228
+ }
229
+ return stations;
380
230
  };
381
-
382
- // src/allocateVehicle.ts
383
- import z6 from "zod";
384
- var allocateVehicleSchema = z6.object({
385
- bookingRequestId: z6.string().uuid(),
386
- vehicleId: z6.string().uuid(),
387
- serviceId: z6.string().uuid()
388
- });
389
- var allocateVehicle = async (client, bookingRequestId, vehicleId, serviceId) => {
390
- const resultPayload = allocateVehicleSchema.safeParse({ bookingRequestId, vehicleId, serviceId });
391
- if (!resultPayload.success) {
392
- throw new TypeError("Invalid args", {
393
- cause: resultPayload.error.issues
394
- });
395
- }
396
- return client.post(
397
- `boapi/proxy/user/scheduleATrip/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/allocate/${vehicleId}?serviceId=${serviceId}`
398
- ).then(({ data }) => data);
231
+ //#endregion
232
+ //#region src/getStation.ts
233
+ const IncludeSchema = z.enum(["INFO", "SERVICES"]);
234
+ const IncludesSchema = z.array(IncludeSchema);
235
+ const getStationById = async (client, id, includes = []) => {
236
+ const resultIncludes = IncludesSchema.safeParse(includes);
237
+ if (!resultIncludes.success) throw new TypeError("Invalid includes", { cause: resultIncludes.error.issues });
238
+ const station = await client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/stations/${id}`).then(({ data, status }) => {
239
+ if (status === 200) return Object.keys(data).reduce((acc, key) => {
240
+ if (key === "stationTimetableDTO") {
241
+ if (data.stationTimetableDTO?.stationId) acc.openingHours = {
242
+ alwaysOpen: data.stationTimetableDTO.alwaysOpen,
243
+ timetable: Object.keys(data.stationTimetableDTO.timetable).reduce((timetable, val) => {
244
+ timetable[val] = data.stationTimetableDTO.timetable[val].map((day) => ({
245
+ id: day.id,
246
+ closed: day.closed,
247
+ openAt: day.openAt,
248
+ closeAt: day.closeAt
249
+ }));
250
+ return timetable;
251
+ }, {})
252
+ };
253
+ return acc;
254
+ }
255
+ acc[key] = data[key];
256
+ return acc;
257
+ }, {});
258
+ if (status === 400) return null;
259
+ return null;
260
+ }).catch((error) => {
261
+ if (error.formattedError?.status === 400) return null;
262
+ throw error;
263
+ });
264
+ if (station && includes.includes("INFO")) {
265
+ const poi = await client.get(`/boapi/proxy/geoloc/fleets/${client.clientOptions.fleetId}/pois/${station.poiId}`, { headers: { accept: "application/vnd.geo+json" } }).then(({ data }) => data.features.reduce((max, current) => {
266
+ if (current.properties.Version > max.version) {
267
+ const { geometry: { coordinates: [longitude, latitude] }, properties } = current;
268
+ return {
269
+ version: current.properties.Version,
270
+ name: properties.name,
271
+ coordinates: {
272
+ latitude,
273
+ longitude
274
+ },
275
+ geoProperties: properties
276
+ };
277
+ }
278
+ return max;
279
+ }, { version: -1 }));
280
+ if (station.poiId && poi) {
281
+ poi.version = void 0;
282
+ Object.assign(station, poi);
283
+ station.name = station.geoProperties?.name;
284
+ }
285
+ }
286
+ if (station && includes.includes("SERVICES")) {
287
+ const services = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/stations/details?showTimetable=false`).then(({ data }) => data.stations.reduce((acc, service) => {
288
+ if (!acc[service.station.id]) acc[service.station.id] = { services: [] };
289
+ acc[service.station.id].services.push({
290
+ id: service.serviceId,
291
+ models: service.station.models
292
+ });
293
+ return acc;
294
+ }, {}));
295
+ if (services[station.id]) Object.assign(station, services[station.id]);
296
+ }
297
+ return station;
399
298
  };
400
-
401
- // src/deallocateVehicle.ts
402
- import z7 from "zod";
403
- var deallocateVehicleSchema = z7.object({
404
- bookingRequestId: z7.string().uuid(),
405
- vehicleId: z7.string().uuid()
299
+ //#endregion
300
+ //#region src/allocateVehicle.ts
301
+ const allocateVehicleSchema = z$1.object({
302
+ bookingRequestId: z$1.string().uuid(),
303
+ vehicleId: z$1.string().uuid(),
304
+ serviceId: z$1.string().uuid()
406
305
  });
407
- var deallocateVehicle = async (client, bookingRequestId, vehicleId) => {
408
- const resultPayload = deallocateVehicleSchema.safeParse({ bookingRequestId, vehicleId });
409
- if (!resultPayload.success) {
410
- throw new TypeError("Invalid args", {
411
- cause: resultPayload.error.issues
412
- });
413
- }
414
- return client.delete(
415
- `boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/vehicles/${vehicleId}`
416
- ).then(({ data }) => data);
306
+ const allocateVehicle = async (client, bookingRequestId, vehicleId, serviceId) => {
307
+ const resultPayload = allocateVehicleSchema.safeParse({
308
+ bookingRequestId,
309
+ vehicleId,
310
+ serviceId
311
+ });
312
+ if (!resultPayload.success) throw new TypeError("Invalid args", { cause: resultPayload.error.issues });
313
+ return client.post(`boapi/proxy/user/scheduleATrip/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/allocate/${vehicleId}?serviceId=${serviceId}`).then(({ data }) => data);
417
314
  };
418
-
419
- // src/updateScheduleBooking.ts
420
- import z8 from "zod";
421
- var schema = z8.object({
422
- id: z8.string(),
423
- startDate: z8.string().refine((date) => !Number.isNaN(Date.parse(date)), {
424
- message: "Invalid date"
425
- }).optional(),
426
- latitude: z8.number().min(-90).max(90).optional(),
427
- longitude: z8.number().min(-180).max(180).optional(),
428
- radius: z8.number().min(0).optional(),
429
- userId: z8.string().optional(),
430
- status: z8.enum(["CONFIRMED", "CANCELLED", "PENDING"]).optional(),
431
- cityId: z8.string().optional(),
432
- profileId: z8.string().optional(),
433
- serviceId: z8.string().optional(),
434
- warning: z8.string().optional(),
435
- modelId: z8.number().optional(),
436
- notes: z8.string().optional(),
437
- bookingReferenceId: z8.string().optional(),
438
- plannedReturnDate: z8.string().refine((date) => !Number.isNaN(Date.parse(date)), {
439
- message: "Invalid date"
440
- }).optional()
315
+ //#endregion
316
+ //#region src/deallocateVehicle.ts
317
+ const deallocateVehicleSchema = z$1.object({
318
+ bookingRequestId: z$1.string().uuid(),
319
+ vehicleId: z$1.string().uuid()
441
320
  });
442
- var updateScheduleBooking = async (client, bookingRequestId, updateData) => {
443
- const result = schema.safeParse({ id: bookingRequestId, ...updateData });
444
- if (!result.success) {
445
- throw new TypeError("Invalid args", {
446
- cause: result.error.issues
447
- });
448
- }
449
- return client.post(
450
- `/boapi/proxy/user/scheduleATrip/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}`,
451
- updateData
452
- ).then(({ data }) => data);
321
+ const deallocateVehicle = async (client, bookingRequestId, vehicleId) => {
322
+ const resultPayload = deallocateVehicleSchema.safeParse({
323
+ bookingRequestId,
324
+ vehicleId
325
+ });
326
+ if (!resultPayload.success) throw new TypeError("Invalid args", { cause: resultPayload.error.issues });
327
+ return client.delete(`boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/vehicles/${vehicleId}`).then(({ data }) => data);
453
328
  };
454
-
455
- // src/triggerBRPayment.ts
456
- import z9 from "zod";
457
- var triggerBRPaymentSchema = z9.object({
458
- bookingRequestId: z9.string().uuid(),
459
- body: z9.object({
460
- scope: z9.enum(["RENTAL", "DEPOSIT"]),
461
- requiresActionReturnURL: z9.string().url().optional(),
462
- online: z9.boolean(),
463
- amountType: z9.enum(["FIXED", "PERCENTAGE"]),
464
- amountValue: z9.number().nonnegative(),
465
- preferredPaymentMethods: z9.array(
466
- z9.object({
467
- pspReference: z9.string(),
468
- amount: z9.number().default(0)
469
- })
470
- ).optional(),
471
- profileId: z9.string().uuid()
472
- })
329
+ //#endregion
330
+ //#region src/updateScheduleBooking.ts
331
+ const schema$2 = z$1.object({
332
+ id: z$1.string(),
333
+ startDate: z$1.string().refine((date) => !Number.isNaN(Date.parse(date)), { message: "Invalid date" }).optional(),
334
+ latitude: z$1.number().min(-90).max(90).optional(),
335
+ longitude: z$1.number().min(-180).max(180).optional(),
336
+ radius: z$1.number().min(0).optional(),
337
+ userId: z$1.string().optional(),
338
+ status: z$1.enum([
339
+ "CONFIRMED",
340
+ "CANCELLED",
341
+ "PENDING"
342
+ ]).optional(),
343
+ cityId: z$1.string().optional(),
344
+ profileId: z$1.string().optional(),
345
+ serviceId: z$1.string().optional(),
346
+ warning: z$1.string().optional(),
347
+ modelId: z$1.number().optional(),
348
+ notes: z$1.string().optional(),
349
+ bookingReferenceId: z$1.string().optional(),
350
+ plannedReturnDate: z$1.string().refine((date) => !Number.isNaN(Date.parse(date)), { message: "Invalid date" }).optional()
473
351
  });
474
- var triggerBRPayment = async (client, bookingRequestId, body) => {
475
- const resultPayload = triggerBRPaymentSchema.safeParse({ bookingRequestId, body });
476
- if (!resultPayload.success) {
477
- throw new TypeError("Invalid args", {
478
- cause: resultPayload.error.issues
479
- });
480
- }
481
- return client.post(
482
- `boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/payment`,
483
- resultPayload.data.body
484
- ).then(({ data }) => data).catch((error) => {
485
- throw new TypeError("Failed to trigger booking request payment", {
486
- cause: error
487
- });
488
- });
352
+ const updateScheduleBooking = async (client, bookingRequestId, updateData) => {
353
+ const result = schema$2.safeParse({
354
+ id: bookingRequestId,
355
+ ...updateData
356
+ });
357
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
358
+ return client.post(`/boapi/proxy/user/scheduleATrip/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}`, updateData).then(({ data }) => data);
489
359
  };
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()
360
+ //#endregion
361
+ //#region src/triggerBRPayment.ts
362
+ const triggerBRPaymentSchema = z$1.object({
363
+ bookingRequestId: z$1.string().uuid(),
364
+ body: z$1.object({
365
+ scope: z$1.enum(["RENTAL", "DEPOSIT"]),
366
+ requiresActionReturnURL: z$1.string().url().optional(),
367
+ online: z$1.boolean(),
368
+ amountType: z$1.enum(["FIXED", "PERCENTAGE"]),
369
+ amountValue: z$1.number().nonnegative(),
370
+ preferredPaymentMethods: z$1.array(z$1.object({
371
+ pspReference: z$1.string(),
372
+ amount: z$1.number().default(0)
373
+ })).optional(),
374
+ profileId: z$1.string().uuid()
375
+ })
495
376
  });
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
- });
377
+ const triggerBRPayment = async (client, bookingRequestId, body) => {
378
+ const resultPayload = triggerBRPaymentSchema.safeParse({
379
+ bookingRequestId,
380
+ body
381
+ });
382
+ if (!resultPayload.success) throw new TypeError("Invalid args", { cause: resultPayload.error.issues });
383
+ return client.post(`boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/payment`, resultPayload.data.body).then(({ data }) => data).catch((error) => {
384
+ throw new TypeError("Failed to trigger booking request payment", { cause: error });
385
+ });
511
386
  };
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
- });
387
+ //#endregion
388
+ //#region src/getBookingRequestsByUserId.ts
389
+ const schema$1 = z.object({ userId: z.string().trim().min(1).uuid() });
390
+ const getBookingRequestsByUserId = async (client, userId) => {
391
+ const result = schema$1.safeParse({ userId });
392
+ if (!result.success) throw new TypeError("Invalid userId", { cause: result.error.issues });
393
+ return client.get(`/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/users/${userId}`).then(({ data }) => data).catch((error) => {
394
+ if (error.formattedError?.status === 404) return [];
395
+ throw error;
396
+ });
534
397
  };
535
-
536
- // src/cancelBookingRequest.ts
537
- import z12 from "zod";
538
- var schema3 = z12.object({
539
- id: z12.string().uuid()
398
+ //#endregion
399
+ //#region src/releaseBRPayment.ts
400
+ const releaseBRPaymentSchema = z$1.object({
401
+ bookingRequestId: z$1.string().uuid(),
402
+ pspReference: z$1.string().uuid()
540
403
  });
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
- });
404
+ const releaseBRPayment = async (client, bookingRequestId, pspReference) => {
405
+ const resultPayload = releaseBRPaymentSchema.safeParse({
406
+ bookingRequestId,
407
+ pspReference
408
+ });
409
+ if (!resultPayload.success) throw new TypeError("Invalid args", { cause: resultPayload.error.issues });
410
+ return client.post(`boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/paymentintent/${pspReference}/cancel`, {}).then(({ data }) => data).catch((error) => {
411
+ throw new TypeError("Failed to release booking request payment", { cause: error });
412
+ });
556
413
  };
557
- export {
558
- allocateVehicle,
559
- cancelBookingRequest,
560
- deallocateVehicle,
561
- getBookingRequestById,
562
- getBookingRequestByTrip,
563
- getBookingRequests,
564
- getBookingRequestsByUserId,
565
- getSATBookingRequests,
566
- getScheduleBookingRequests,
567
- getStationById,
568
- getStations,
569
- getSubscriptionBookingRequestById,
570
- getSubscriptionBookingRequests,
571
- releaseBRPayment,
572
- triggerBRPayment,
573
- updateScheduleBooking
414
+ //#endregion
415
+ //#region src/cancelBookingRequest.ts
416
+ const schema = z$1.object({ id: z$1.string().uuid() });
417
+ const cancelBookingRequest = async (client, id) => {
418
+ const result = schema.safeParse({ id });
419
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
420
+ return client.post(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/cancel/${id}`, {}).then(({ data }) => data).catch((error) => {
421
+ throw new TypeError("Failed to cancel booking request", { cause: error });
422
+ });
574
423
  };
424
+ //#endregion
425
+ export { allocateVehicle, cancelBookingRequest, deallocateVehicle, getAvailableVehicles, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getBookingRequestsByUserId, getSATBookingRequests, getScheduleBookingRequests, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests, releaseBRPayment, triggerBRPayment, updateScheduleBooking };