@vulog/aima-booking 1.2.30 → 1.2.32

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,594 +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/getAvailableVehicles.ts
187
- import { z as z4 } from "zod";
188
- var isoDateTimeNoMs = z4.string().trim().datetime({ precision: 0 });
189
- var getAvailableVehiclesSchema = z4.object({
190
- stationId: z4.string().trim().min(1),
191
- startDate: isoDateTimeNoMs
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
192
158
  });
193
- var getAvailableVehicles = async (client, stationId, startDate) => {
194
- const result = getAvailableVehiclesSchema.safeParse({ stationId, startDate });
195
- if (!result.success) {
196
- throw new TypeError("Invalid args", {
197
- cause: result.error.issues
198
- });
199
- }
200
- return client.get(
201
- `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/subscription/stations/${stationId}/vehicles/available?startDate=${startDate}`
202
- ).then(({ data }) => data);
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);
203
166
  };
204
-
205
- // src/getStations.ts
206
- import { z as z5 } from "zod";
207
- var IncludeSchema = z5.enum(["INFO", "OPEN_HOUR", "SERVICES"]);
208
- var IncludesSchema = z5.array(IncludeSchema);
209
- var getStations = async (client, includes = []) => {
210
- const resultIncludes = IncludesSchema.safeParse(includes);
211
- if (!resultIncludes.success) {
212
- throw new TypeError("Invalid includes", {
213
- cause: resultIncludes.error.issues
214
- });
215
- }
216
- const searchParams = new URLSearchParams();
217
- if (includes.includes("OPEN_HOUR")) {
218
- searchParams.append("showTimetable", "true");
219
- }
220
- const stations = await client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/stations${searchParams.size > 0 ? `?${searchParams.toString()}` : ""}`).then(
221
- ({ data }) => data.map(
222
- (station) => Object.keys(station).reduce((acc, key) => {
223
- if (key === "stationTimetableDTO") {
224
- if (station.stationTimetableDTO?.stationId) {
225
- acc.openingHours = {
226
- alwaysOpen: station.stationTimetableDTO.alwaysOpen,
227
- timetable: Object.keys(station.stationTimetableDTO.timetable).reduce(
228
- (timetable, val) => {
229
- timetable[val] = station.stationTimetableDTO.timetable[val].map(
230
- (day) => ({
231
- id: day.id,
232
- closed: day.closed,
233
- openAt: day.openAt,
234
- closeAt: day.closeAt
235
- })
236
- );
237
- return timetable;
238
- },
239
- {}
240
- )
241
- };
242
- }
243
- return acc;
244
- }
245
- acc[key] = station[key];
246
- return acc;
247
- }, {})
248
- )
249
- );
250
- if (includes.includes("INFO")) {
251
- const pois = await client.get(`/boapi/proxy/geoloc/fleets/${client.clientOptions.fleetId}/pois`, {
252
- headers: { accept: "application/vnd.geo+json" }
253
- }).then(
254
- ({ data }) => data.features.reduce((acc, poi) => {
255
- const {
256
- geometry: {
257
- coordinates: [longitude, latitude]
258
- },
259
- properties
260
- } = poi;
261
- acc[properties.poiId] = {
262
- name: properties.name,
263
- coordinates: { latitude, longitude },
264
- geoProperties: properties
265
- };
266
- return acc;
267
- }, {})
268
- );
269
- stations.forEach((station) => {
270
- if (station.poiId && pois[station.poiId]) {
271
- Object.assign(station, pois[station.poiId]);
272
- }
273
- });
274
- }
275
- if (includes.includes("SERVICES")) {
276
- const services = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/stations/details?size=1000`).then(
277
- ({ data }) => data.stations.reduce((acc, service) => {
278
- if (!acc[service.station.id]) {
279
- acc[service.station.id] = { services: [] };
280
- }
281
- acc[service.station.id].services.push({
282
- id: service.serviceId,
283
- models: service.station.models
284
- });
285
- return acc;
286
- }, {})
287
- );
288
- stations.forEach((station) => {
289
- if (services[station.id]) {
290
- Object.assign(station, services[station.id]);
291
- }
292
- });
293
- }
294
- return stations;
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;
295
230
  };
296
-
297
- // src/getStation.ts
298
- import { z as z6 } from "zod";
299
- var IncludeSchema2 = z6.enum(["INFO", "SERVICES"]);
300
- var IncludesSchema2 = z6.array(IncludeSchema2);
301
- var getStationById = async (client, id, includes = []) => {
302
- const resultIncludes = IncludesSchema2.safeParse(includes);
303
- if (!resultIncludes.success) {
304
- throw new TypeError("Invalid includes", {
305
- cause: resultIncludes.error.issues
306
- });
307
- }
308
- const station = await client.get(`/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/stations/${id}`).then(({ data, status }) => {
309
- if (status === 200) {
310
- return Object.keys(data).reduce((acc, key) => {
311
- if (key === "stationTimetableDTO") {
312
- if (data.stationTimetableDTO?.stationId) {
313
- acc.openingHours = {
314
- alwaysOpen: data.stationTimetableDTO.alwaysOpen,
315
- timetable: Object.keys(data.stationTimetableDTO.timetable).reduce(
316
- (timetable, val) => {
317
- timetable[val] = data.stationTimetableDTO.timetable[val].map(
318
- (day) => ({
319
- id: day.id,
320
- closed: day.closed,
321
- openAt: day.openAt,
322
- closeAt: day.closeAt
323
- })
324
- );
325
- return timetable;
326
- },
327
- {}
328
- )
329
- };
330
- }
331
- return acc;
332
- }
333
- acc[key] = data[key];
334
- return acc;
335
- }, {});
336
- }
337
- if (status === 400) {
338
- return null;
339
- }
340
- return null;
341
- }).catch((error) => {
342
- if (error.formattedError?.status === 400) {
343
- return null;
344
- }
345
- throw error;
346
- });
347
- if (station && includes.includes("INFO")) {
348
- const poi = await client.get(
349
- `/boapi/proxy/geoloc/fleets/${client.clientOptions.fleetId}/pois/${station.poiId}`,
350
- {
351
- headers: { accept: "application/vnd.geo+json" }
352
- }
353
- ).then(
354
- ({ data }) => data.features.reduce(
355
- (max, current) => {
356
- if (current.properties.Version > max.version) {
357
- const {
358
- geometry: {
359
- coordinates: [longitude, latitude]
360
- },
361
- properties
362
- } = current;
363
- return {
364
- version: current.properties.Version,
365
- name: properties.name,
366
- coordinates: { latitude, longitude },
367
- geoProperties: properties
368
- };
369
- }
370
- return max;
371
- },
372
- { version: -1 }
373
- )
374
- );
375
- if (station.poiId && poi) {
376
- poi.version = void 0;
377
- Object.assign(station, poi);
378
- station.name = station.geoProperties?.name;
379
- }
380
- }
381
- if (station && includes.includes("SERVICES")) {
382
- const services = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/stations/details?showTimetable=false`).then(
383
- ({ data }) => data.stations.reduce((acc, service) => {
384
- if (!acc[service.station.id]) {
385
- acc[service.station.id] = { services: [] };
386
- }
387
- acc[service.station.id].services.push({
388
- id: service.serviceId,
389
- models: service.station.models
390
- });
391
- return acc;
392
- }, {})
393
- );
394
- if (services[station.id]) {
395
- Object.assign(station, services[station.id]);
396
- }
397
- }
398
- return station;
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/allocateVehicle.ts
402
- import z7 from "zod";
403
- var allocateVehicleSchema = z7.object({
404
- bookingRequestId: z7.string().uuid(),
405
- vehicleId: z7.string().uuid(),
406
- serviceId: 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()
407
305
  });
408
- var allocateVehicle = async (client, bookingRequestId, vehicleId, serviceId) => {
409
- const resultPayload = allocateVehicleSchema.safeParse({ bookingRequestId, vehicleId, serviceId });
410
- if (!resultPayload.success) {
411
- throw new TypeError("Invalid args", {
412
- cause: resultPayload.error.issues
413
- });
414
- }
415
- return client.post(
416
- `boapi/proxy/user/scheduleATrip/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/allocate/${vehicleId}?serviceId=${serviceId}`
417
- ).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);
418
314
  };
419
-
420
- // src/deallocateVehicle.ts
421
- import z8 from "zod";
422
- var deallocateVehicleSchema = z8.object({
423
- bookingRequestId: z8.string().uuid(),
424
- vehicleId: z8.string().uuid()
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()
425
320
  });
426
- var deallocateVehicle = async (client, bookingRequestId, vehicleId) => {
427
- const resultPayload = deallocateVehicleSchema.safeParse({ bookingRequestId, vehicleId });
428
- if (!resultPayload.success) {
429
- throw new TypeError("Invalid args", {
430
- cause: resultPayload.error.issues
431
- });
432
- }
433
- return client.delete(
434
- `boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/vehicles/${vehicleId}`
435
- ).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);
436
328
  };
437
-
438
- // src/updateScheduleBooking.ts
439
- import z9 from "zod";
440
- var schema = z9.object({
441
- id: z9.string(),
442
- startDate: z9.string().refine((date) => !Number.isNaN(Date.parse(date)), {
443
- message: "Invalid date"
444
- }).optional(),
445
- latitude: z9.number().min(-90).max(90).optional(),
446
- longitude: z9.number().min(-180).max(180).optional(),
447
- radius: z9.number().min(0).optional(),
448
- userId: z9.string().optional(),
449
- status: z9.enum(["CONFIRMED", "CANCELLED", "PENDING"]).optional(),
450
- cityId: z9.string().optional(),
451
- profileId: z9.string().optional(),
452
- serviceId: z9.string().optional(),
453
- warning: z9.string().optional(),
454
- modelId: z9.number().optional(),
455
- notes: z9.string().optional(),
456
- bookingReferenceId: z9.string().optional(),
457
- plannedReturnDate: z9.string().refine((date) => !Number.isNaN(Date.parse(date)), {
458
- message: "Invalid date"
459
- }).optional()
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()
460
351
  });
461
- var updateScheduleBooking = async (client, bookingRequestId, updateData) => {
462
- const result = schema.safeParse({ id: bookingRequestId, ...updateData });
463
- if (!result.success) {
464
- throw new TypeError("Invalid args", {
465
- cause: result.error.issues
466
- });
467
- }
468
- return client.post(
469
- `/boapi/proxy/user/scheduleATrip/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}`,
470
- updateData
471
- ).then(({ data }) => data);
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);
472
359
  };
473
-
474
- // src/triggerBRPayment.ts
475
- import z10 from "zod";
476
- var triggerBRPaymentSchema = z10.object({
477
- bookingRequestId: z10.string().uuid(),
478
- body: z10.object({
479
- scope: z10.enum(["RENTAL", "DEPOSIT"]),
480
- requiresActionReturnURL: z10.string().url().optional(),
481
- online: z10.boolean(),
482
- amountType: z10.enum(["FIXED", "PERCENTAGE"]),
483
- amountValue: z10.number().nonnegative(),
484
- preferredPaymentMethods: z10.array(
485
- z10.object({
486
- pspReference: z10.string(),
487
- amount: z10.number().default(0)
488
- })
489
- ).optional(),
490
- profileId: z10.string().uuid()
491
- })
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
+ })
492
376
  });
493
- var triggerBRPayment = async (client, bookingRequestId, body) => {
494
- const resultPayload = triggerBRPaymentSchema.safeParse({ bookingRequestId, body });
495
- if (!resultPayload.success) {
496
- throw new TypeError("Invalid args", {
497
- cause: resultPayload.error.issues
498
- });
499
- }
500
- return client.post(
501
- `boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/payment`,
502
- resultPayload.data.body
503
- ).then(({ data }) => data).catch((error) => {
504
- throw new TypeError("Failed to trigger booking request payment", {
505
- cause: error
506
- });
507
- });
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
+ });
508
386
  };
509
-
510
- // src/getBookingRequestsByUserId.ts
511
- import { z as z11 } from "zod";
512
- var schema2 = z11.object({
513
- userId: z11.string().trim().min(1).uuid()
514
- });
515
- var getBookingRequestsByUserId = async (client, userId) => {
516
- const result = schema2.safeParse({ userId });
517
- if (!result.success) {
518
- throw new TypeError("Invalid userId", {
519
- cause: result.error.issues
520
- });
521
- }
522
- return client.get(
523
- `/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/users/${userId}`
524
- ).then(({ data }) => data).catch((error) => {
525
- if (error.formattedError?.status === 404) {
526
- return [];
527
- }
528
- throw error;
529
- });
530
- };
531
-
532
- // src/releaseBRPayment.ts
533
- import z12 from "zod";
534
- var releaseBRPaymentSchema = z12.object({
535
- bookingRequestId: z12.string().uuid(),
536
- pspReference: z12.string().uuid()
537
- });
538
- var releaseBRPayment = async (client, bookingRequestId, pspReference) => {
539
- const resultPayload = releaseBRPaymentSchema.safeParse({ bookingRequestId, pspReference });
540
- if (!resultPayload.success) {
541
- throw new TypeError("Invalid args", {
542
- cause: resultPayload.error.issues
543
- });
544
- }
545
- return client.post(
546
- `boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/paymentintent/${pspReference}/cancel`,
547
- {}
548
- ).then(({ data }) => data).catch((error) => {
549
- throw new TypeError("Failed to release booking request payment", {
550
- cause: error
551
- });
552
- });
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
+ });
553
397
  };
554
-
555
- // src/cancelBookingRequest.ts
556
- import z13 from "zod";
557
- var schema3 = z13.object({
558
- id: z13.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()
559
403
  });
560
- var cancelBookingRequest = async (client, id) => {
561
- const result = schema3.safeParse({ id });
562
- if (!result.success) {
563
- throw new TypeError("Invalid args", {
564
- cause: result.error.issues
565
- });
566
- }
567
- return client.post(
568
- `/boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/cancel/${id}`,
569
- {}
570
- ).then(({ data }) => data).catch((error) => {
571
- throw new TypeError("Failed to cancel booking request", {
572
- cause: error
573
- });
574
- });
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
+ });
575
413
  };
576
- export {
577
- allocateVehicle,
578
- cancelBookingRequest,
579
- deallocateVehicle,
580
- getAvailableVehicles,
581
- getBookingRequestById,
582
- getBookingRequestByTrip,
583
- getBookingRequests,
584
- getBookingRequestsByUserId,
585
- getSATBookingRequests,
586
- getScheduleBookingRequests,
587
- getStationById,
588
- getStations,
589
- getSubscriptionBookingRequestById,
590
- getSubscriptionBookingRequests,
591
- releaseBRPayment,
592
- triggerBRPayment,
593
- 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
+ });
594
423
  };
424
+ //#endregion
425
+ export { allocateVehicle, cancelBookingRequest, deallocateVehicle, getAvailableVehicles, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getBookingRequestsByUserId, getSATBookingRequests, getScheduleBookingRequests, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests, releaseBRPayment, triggerBRPayment, updateScheduleBooking };