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