@vulog/aima-trip 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.cjs ADDED
@@ -0,0 +1,142 @@
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 zod = require("zod");
25
+ zod = __toESM(zod);
26
+ let _vulog_aima_core = require("@vulog/aima-core");
27
+ //#region src/addRemoveTripRelatedProduct.ts
28
+ const schema$1 = zod.default.object({
29
+ vehicleId: zod.default.string().trim().min(1).uuid(),
30
+ productId: zod.default.string().trim().min(1).uuid()
31
+ });
32
+ const addRemoveTripRelatedProduct = async (client, action, vehicleId, productId) => {
33
+ const result = schema$1.safeParse({
34
+ vehicleId,
35
+ productId
36
+ });
37
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
38
+ await client[action === "ADD" ? "put" : "delete"](`/boapi/proxy/fleetmanager/public/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.vehicleId}/products/${result.data.productId}`);
39
+ };
40
+ const addTripRelatedProduct = async (client, vehicleId, productId) => addRemoveTripRelatedProduct(client, "ADD", vehicleId, productId);
41
+ const removeTripRelatedProduct = async (client, vehicleId, productId) => addRemoveTripRelatedProduct(client, "REMOVE", vehicleId, productId);
42
+ //#endregion
43
+ //#region src/endTrip.ts
44
+ const schema = zod.default.object({
45
+ vehicleId: zod.default.string().trim().min(1).uuid(),
46
+ userId: zod.default.string().trim().min(1).uuid(),
47
+ orderId: zod.default.string().trim().min(1)
48
+ });
49
+ const endTrip = async (client, info) => {
50
+ const result = schema.safeParse(info);
51
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
52
+ await client.post(`/boapi/proxy/fleetmanager/public/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.vehicleId}/trip/end`, {
53
+ userId: result.data.userId,
54
+ orderId: result.data.orderId
55
+ });
56
+ };
57
+ //#endregion
58
+ //#region src/getVehiclesBooked.ts
59
+ const optionsSchema = zod.default.object({
60
+ minDuration: zod.default.number().positive().optional(),
61
+ boxStatus: zod.default.array(zod.default.number()).optional()
62
+ });
63
+ const getVehiclesBooked = async (client, options = {}) => {
64
+ const result = optionsSchema.safeParse(options);
65
+ if (!result.success) throw new TypeError("Invalid options", { cause: result.error.issues });
66
+ return client.get(`/boapi/proxy/fleetmanager/public/fleets/${client.clientOptions.fleetId}/book`).then(({ data }) => {
67
+ let filterData = data;
68
+ if (result.data.minDuration) filterData = filterData.filter((book) => {
69
+ if (!book.start_date) return false;
70
+ const startDate = new Date(book.start_date);
71
+ return ((/* @__PURE__ */ new Date()).getTime() - startDate.getTime()) / 1e3 >= result.data.minDuration * 60;
72
+ });
73
+ if (result.data.boxStatus && result.data.boxStatus.length > 0) filterData = filterData.filter((book) => {
74
+ return result.data.boxStatus?.includes(book.box_status);
75
+ });
76
+ return filterData;
77
+ });
78
+ };
79
+ const schemaByUserId$1 = zod.default.object({ userId: zod.default.string().trim().min(1).uuid() });
80
+ const getVehiclesBookedByUserId = async (client, userId) => {
81
+ const result = schemaByUserId$1.safeParse({ userId });
82
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
83
+ return client.get(`/boapi/proxy/fleetmanager/public/fleets/${client.clientOptions.fleetId}/users/${result.data.userId}/vehicles`).then(({ data }) => data).catch((error) => {
84
+ if (error.formattedError?.status === 404) return [];
85
+ throw error;
86
+ });
87
+ };
88
+ const getVehicleBookedByTripId = async (client, tripId) => {
89
+ return client.get(`/boapi/proxy/fleetmanager/public/fleets/${client.clientOptions.fleetId}/trips/${tripId}/vehicle`).then(({ data }) => data).catch((error) => {
90
+ if (error.formattedError?.status === 404) return null;
91
+ throw error;
92
+ });
93
+ };
94
+ //#endregion
95
+ //#region src/getTripById.ts
96
+ const getTripById = async (client, tripId) => {
97
+ const { fleetId } = client.clientOptions;
98
+ return client.get(`/boapi/proxy/trip/fleets/${fleetId}/trips/${tripId}`).then(({ data }) => data).catch((error) => {
99
+ if (error.formattedError?.status === 404) return {};
100
+ throw error;
101
+ });
102
+ };
103
+ //#endregion
104
+ //#region src/getOngoingTripPaymentsByTripIds.ts
105
+ const getOngoingTripPaymentsByTripIds = async (client, tripIds) => {
106
+ const result = zod.z.object({ tripIds: zod.z.array(zod.z.string()).nonempty() }).safeParse({ tripIds });
107
+ if (!result.success) throw new TypeError("Invalid parameters", { cause: result.error.issues });
108
+ return client.post(`/boapi/proxy/trip/fleets/${client.clientOptions.fleetId}/trips/ongoing`, { ids: tripIds }).then(({ data }) => data);
109
+ };
110
+ //#endregion
111
+ //#region src/getTrips.ts
112
+ const schemaByUserId = zod.default.object({ userId: zod.default.string().trim().min(1).uuid() });
113
+ const getTripsByUserId = async (client, userId, options) => {
114
+ const result = schemaByUserId.safeParse({ userId });
115
+ if (!result.success) throw new TypeError("Invalid userId", { cause: result.error.issues });
116
+ const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)(void 0, zod.default.enum(["date"]).optional().default("date")).default({}).safeParse(options);
117
+ if (!resultOptions.success) throw new TypeError("Invalid options", { cause: resultOptions.error.issues });
118
+ const finalOptions = resultOptions.data;
119
+ const searchParams = new URLSearchParams();
120
+ searchParams.append("page", finalOptions.page.toString());
121
+ searchParams.append("size", finalOptions.pageSize.toString());
122
+ searchParams.append("sort", `${finalOptions.sort.toString()},${finalOptions.sortDirection.toString()}`);
123
+ return client.get(`/boapi/proxy/trip/fleets/${client.clientOptions.fleetId}/trips/users/${userId}?${searchParams.toString()}`).then(({ data, headers }) => {
124
+ return {
125
+ data,
126
+ page: headers.number,
127
+ pageSize: headers.size,
128
+ total: headers.totalelements,
129
+ totalPages: headers.totalpages
130
+ };
131
+ });
132
+ };
133
+ //#endregion
134
+ exports.addTripRelatedProduct = addTripRelatedProduct;
135
+ exports.endTrip = endTrip;
136
+ exports.getOngoingTripPaymentsByTripIds = getOngoingTripPaymentsByTripIds;
137
+ exports.getTripById = getTripById;
138
+ exports.getTripsByUserId = getTripsByUserId;
139
+ exports.getVehicleBookedByTripId = getVehicleBookedByTripId;
140
+ exports.getVehiclesBooked = getVehiclesBooked;
141
+ exports.getVehiclesBookedByUserId = getVehiclesBookedByUserId;
142
+ exports.removeTripRelatedProduct = removeTripRelatedProduct;
@@ -0,0 +1,248 @@
1
+ import { Client } from "@vulog/aima-client";
2
+ import z from "zod";
3
+ import { UUID } from "crypto";
4
+ import { PaginableOptions, PaginableResponse } from "@vulog/aima-core";
5
+
6
+ //#region src/addRemoveTripRelatedProduct.d.ts
7
+ declare const addTripRelatedProduct: (client: Client, vehicleId: string, productId: string) => Promise<void>;
8
+ declare const removeTripRelatedProduct: (client: Client, vehicleId: string, productId: string) => Promise<void>;
9
+ //#endregion
10
+ //#region src/types.d.ts
11
+ type Zone = {
12
+ type: 'allowed' | 'forbidden';
13
+ version: number;
14
+ zoneId: string;
15
+ sticky: boolean;
16
+ labels: string[];
17
+ };
18
+ type FleetManagerBook = {
19
+ id: string;
20
+ name: string;
21
+ plate: string;
22
+ vin: string;
23
+ fleetid: string;
24
+ boxid: string;
25
+ vehicle_status: number;
26
+ zones: Zone[];
27
+ releasable: boolean;
28
+ box_status: number;
29
+ autonomy: number;
30
+ autonomy2: number;
31
+ isCharging: boolean;
32
+ battery: number;
33
+ km: number;
34
+ speed: number;
35
+ location: {
36
+ geohash: string;
37
+ cap: number;
38
+ latitude: number;
39
+ longitude: number;
40
+ gpsDate: string;
41
+ lastMovingDate: string;
42
+ };
43
+ endZoneIds: string[];
44
+ productIds: string[];
45
+ isDoorClosed: boolean | null;
46
+ isDoorLocked: boolean | null;
47
+ engineOn: boolean | null;
48
+ immobilizerOn: boolean | null;
49
+ secureOn: boolean | null;
50
+ spareLockOn: boolean | null;
51
+ pileLockOn: boolean | null;
52
+ helmetPresent: boolean | null;
53
+ helmet2Present: boolean | null;
54
+ helmetBoxLockOn: boolean | null;
55
+ helmet2LockOn: boolean | null;
56
+ userId: string;
57
+ user_locale: string;
58
+ rfid: string;
59
+ orderId: string;
60
+ gatewayUrl: string | null;
61
+ booking_status: number;
62
+ booking_date: string;
63
+ expiresOn: string;
64
+ last_active_date: string;
65
+ last_wakeUp_date: string | null;
66
+ version: string;
67
+ pricingId: string;
68
+ start_date: string;
69
+ theorStartDate: string | null;
70
+ theorEndDate: string | null;
71
+ startZones: Zone[];
72
+ endZones: Zone[];
73
+ disabled: boolean;
74
+ outOfServiceReason: string | null;
75
+ ignitionOffGeohash: string;
76
+ geohashNeighbours: string[];
77
+ cleanlinessStatus: boolean;
78
+ needsRedistribution: boolean;
79
+ batteryUnderThreshold: boolean;
80
+ isBeingTowed: boolean;
81
+ automaticallyEnableVehicleAfterRangeRecovery: boolean;
82
+ key?: {
83
+ sessionKey?: string | null;
84
+ token?: string | null;
85
+ deviceName?: string | null;
86
+ expirationDate?: string | null;
87
+ };
88
+ startTripLocation?: {
89
+ latitude?: number;
90
+ longitude?: number;
91
+ };
92
+ doNotTrack: boolean;
93
+ start_mileage: number;
94
+ profileType: 'Single' | 'Business';
95
+ lastOosDate?: string | null;
96
+ entityId: string;
97
+ hasAlerts: boolean;
98
+ firmwareModel: string;
99
+ comeFromApp: string;
100
+ vpChecksum: string;
101
+ serviceType: string;
102
+ preAuthEnabled: boolean;
103
+ username: string;
104
+ preauth_status: string;
105
+ profileId: string;
106
+ energyLevel: number;
107
+ energyLevelStart: number;
108
+ serviceId: string;
109
+ doors?: {
110
+ frontLeftClosed?: boolean | null;
111
+ frontRightClosed?: boolean | null;
112
+ rearLeftClosed?: boolean | null;
113
+ rearRightClosed?: boolean | null;
114
+ trunkClosed?: boolean | null;
115
+ };
116
+ doorsAndWindowsClosed: boolean;
117
+ handDelivered: boolean;
118
+ deviceIds: string[];
119
+ start_pause_date?: string;
120
+ billingGroupId?: string;
121
+ };
122
+ type EndTripInfo = {
123
+ vehicleId: string;
124
+ userId: string;
125
+ orderId: string;
126
+ };
127
+ type TripZone = {
128
+ zoneId: string;
129
+ version: number;
130
+ type: string;
131
+ sticky: boolean;
132
+ };
133
+ type TripLocation = {
134
+ latitude: number;
135
+ longitude: number;
136
+ };
137
+ type TripEvent = {
138
+ eventType: string;
139
+ timestamp: string;
140
+ parameters: string | null;
141
+ };
142
+ type TripOverriddenInfo = {
143
+ duration: {
144
+ adjustedBookDuration: number;
145
+ adjustedPauseDuration: number;
146
+ adjustedDrivingDuration: number;
147
+ };
148
+ };
149
+ type TripAdditionalInfo = {
150
+ firstDriveDelayMinutes: number;
151
+ bookDuration: number;
152
+ startZones: TripZone[];
153
+ endZones: TripZone[];
154
+ isAutolock: boolean;
155
+ isCancel: boolean;
156
+ isReleaseOnServer: boolean;
157
+ isBilled: boolean;
158
+ suspicious: boolean;
159
+ startLocation: TripLocation;
160
+ endLocation: TripLocation;
161
+ overriddenTripInfo: TripOverriddenInfo;
162
+ bypassBookingRequestCompleted: boolean;
163
+ ignoreOdometer: boolean;
164
+ startTripEventDate: string;
165
+ };
166
+ type Trip = {
167
+ id: string;
168
+ tripId: string;
169
+ fleetId: string;
170
+ userId: string;
171
+ profileId: string;
172
+ profileType: string;
173
+ vehicleId: string;
174
+ length: number;
175
+ duration: number;
176
+ pauseDuration: number;
177
+ tripDuration: number;
178
+ bookingDuration: number;
179
+ drivingDuration: number;
180
+ date: string;
181
+ endDate: string;
182
+ additionalInfo: TripAdditionalInfo;
183
+ pricingId: string;
184
+ productIds: string[];
185
+ serviceId: string;
186
+ serviceType: string;
187
+ theorStartDate: string;
188
+ theorEndDate: string;
189
+ ticketInfo: any;
190
+ tripEvents: TripEvent[];
191
+ lastUpdateDate: string;
192
+ };
193
+ //#endregion
194
+ //#region src/endTrip.d.ts
195
+ declare const endTrip: (client: Client, info: EndTripInfo) => Promise<void>;
196
+ //#endregion
197
+ //#region src/getVehiclesBooked.d.ts
198
+ declare const optionsSchema: z.ZodObject<{
199
+ minDuration: z.ZodOptional<z.ZodNumber>;
200
+ boxStatus: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
201
+ }, "strip", z.ZodTypeAny, {
202
+ minDuration?: number | undefined;
203
+ boxStatus?: number[] | undefined;
204
+ }, {
205
+ minDuration?: number | undefined;
206
+ boxStatus?: number[] | undefined;
207
+ }>;
208
+ declare const getVehiclesBooked: (client: Client, options?: z.infer<typeof optionsSchema>) => Promise<FleetManagerBook[]>;
209
+ declare const getVehiclesBookedByUserId: (client: Client, userId: string) => Promise<FleetManagerBook[]>;
210
+ declare const getVehicleBookedByTripId: (client: Client, tripId: string) => Promise<FleetManagerBook | null>;
211
+ //#endregion
212
+ //#region src/getTripById.d.ts
213
+ declare const getTripById: (client: Client, tripId: string) => Promise<Trip | Record<string, never>>;
214
+ //#endregion
215
+ //#region src/getOngoingTripPaymentsByTripIds.d.ts
216
+ type PaymentReceipt = {
217
+ id: string;
218
+ pspName: string;
219
+ pspReference: string;
220
+ pspPublishableKey: string;
221
+ amount: number;
222
+ currency: string;
223
+ date: string;
224
+ status: 'PAID' | 'REFUNDED';
225
+ paymentMethodType: string;
226
+ paymentMethodPspReference: string;
227
+ paymentIntentPspReference: string;
228
+ number: number;
229
+ code: string;
230
+ declineCode: string;
231
+ pspClientSecret: string;
232
+ reason: string;
233
+ note: string;
234
+ };
235
+ type Payment = {
236
+ paymentReceipts?: PaymentReceipt[];
237
+ id: string;
238
+ fleetId: string;
239
+ profileId: UUID;
240
+ vehicleId: UUID;
241
+ serviceId: UUID;
242
+ };
243
+ declare const getOngoingTripPaymentsByTripIds: (client: Client, tripIds: string[]) => Promise<Payment[]>;
244
+ //#endregion
245
+ //#region src/getTrips.d.ts
246
+ declare const getTripsByUserId: (client: Client, userId: string, options?: PaginableOptions<void, "date">) => Promise<PaginableResponse<Trip>>;
247
+ //#endregion
248
+ export { EndTripInfo, FleetManagerBook, Payment, PaymentReceipt, Trip, TripAdditionalInfo, TripEvent, TripLocation, TripOverriddenInfo, TripZone, Zone, addTripRelatedProduct, endTrip, getOngoingTripPaymentsByTripIds, getTripById, getTripsByUserId, getVehicleBookedByTripId, getVehiclesBooked, getVehiclesBookedByUserId, removeTripRelatedProduct };