@vulog/aima-trip 1.2.13 → 1.2.15

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.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Client } from '@vulog/aima-client';
2
2
  import z from 'zod';
3
3
  import { UUID } from 'crypto';
4
+ import { PaginableOptions, PaginableResponse } from '@vulog/aima-core';
4
5
 
5
6
  declare const addTripRelatedProduct: (client: Client, vehicleId: string, productId: string) => Promise<void>;
6
7
  declare const removeTripRelatedProduct: (client: Client, vehicleId: string, productId: string) => Promise<void>;
@@ -121,23 +122,6 @@ type EndTripInfo = {
121
122
  userId: string;
122
123
  orderId: string;
123
124
  };
124
-
125
- declare const endTrip: (client: Client, info: EndTripInfo) => Promise<void>;
126
-
127
- declare const optionsSchema: z.ZodObject<{
128
- minDuration: z.ZodOptional<z.ZodNumber>;
129
- boxStatus: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
130
- }, "strip", z.ZodTypeAny, {
131
- minDuration?: number | undefined;
132
- boxStatus?: number[] | undefined;
133
- }, {
134
- minDuration?: number | undefined;
135
- boxStatus?: number[] | undefined;
136
- }>;
137
- declare const getVehiclesBooked: (client: Client, options?: z.infer<typeof optionsSchema>) => Promise<FleetManagerBook[]>;
138
- declare const getVehiclesBookedByUserId: (client: Client, userId: string) => Promise<FleetManagerBook[]>;
139
- declare const getVehicleBookedByTripId: (client: Client, tripId: string) => Promise<FleetManagerBook | null>;
140
-
141
125
  type TripZone = {
142
126
  zoneId: string;
143
127
  version: number;
@@ -177,7 +161,7 @@ type TripAdditionalInfo = {
177
161
  ignoreOdometer: boolean;
178
162
  startTripEventDate: string;
179
163
  };
180
- type TripResponse = {
164
+ type Trip = {
181
165
  id: string;
182
166
  tripId: string;
183
167
  fleetId: string;
@@ -204,7 +188,24 @@ type TripResponse = {
204
188
  tripEvents: TripEvent[];
205
189
  lastUpdateDate: string;
206
190
  };
207
- declare const getTripById: (client: Client, tripId: string) => Promise<TripResponse | Record<string, never>>;
191
+
192
+ declare const endTrip: (client: Client, info: EndTripInfo) => Promise<void>;
193
+
194
+ declare const optionsSchema: z.ZodObject<{
195
+ minDuration: z.ZodOptional<z.ZodNumber>;
196
+ boxStatus: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
197
+ }, "strip", z.ZodTypeAny, {
198
+ minDuration?: number | undefined;
199
+ boxStatus?: number[] | undefined;
200
+ }, {
201
+ minDuration?: number | undefined;
202
+ boxStatus?: number[] | undefined;
203
+ }>;
204
+ declare const getVehiclesBooked: (client: Client, options?: z.infer<typeof optionsSchema>) => Promise<FleetManagerBook[]>;
205
+ declare const getVehiclesBookedByUserId: (client: Client, userId: string) => Promise<FleetManagerBook[]>;
206
+ declare const getVehicleBookedByTripId: (client: Client, tripId: string) => Promise<FleetManagerBook | null>;
207
+
208
+ declare const getTripById: (client: Client, tripId: string) => Promise<Trip | Record<string, never>>;
208
209
 
209
210
  type PaymentReceipt = {
210
211
  id: string;
@@ -235,4 +236,6 @@ type Payment = {
235
236
  };
236
237
  declare const getOngoingTripPaymentsByTripIds: (client: Client, tripIds: string[]) => Promise<Payment[]>;
237
238
 
238
- export { type EndTripInfo, type FleetManagerBook, type Payment, type PaymentReceipt, type TripAdditionalInfo, type TripEvent, type TripLocation, type TripOverriddenInfo, type TripResponse, type TripZone, type Zone, addTripRelatedProduct, endTrip, getOngoingTripPaymentsByTripIds, getTripById, getVehicleBookedByTripId, getVehiclesBooked, getVehiclesBookedByUserId, removeTripRelatedProduct };
239
+ declare const getTripsByUserId: (client: Client, userId: string, options?: PaginableOptions<void, "date">) => Promise<PaginableResponse<Trip>>;
240
+
241
+ export { type EndTripInfo, type FleetManagerBook, type Payment, type PaymentReceipt, type Trip, type TripAdditionalInfo, type TripEvent, type TripLocation, type TripOverriddenInfo, type TripZone, type Zone, addTripRelatedProduct, endTrip, getOngoingTripPaymentsByTripIds, getTripById, getTripsByUserId, getVehicleBookedByTripId, getVehiclesBooked, getVehiclesBookedByUserId, removeTripRelatedProduct };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Client } from '@vulog/aima-client';
2
2
  import z from 'zod';
3
3
  import { UUID } from 'crypto';
4
+ import { PaginableOptions, PaginableResponse } from '@vulog/aima-core';
4
5
 
5
6
  declare const addTripRelatedProduct: (client: Client, vehicleId: string, productId: string) => Promise<void>;
6
7
  declare const removeTripRelatedProduct: (client: Client, vehicleId: string, productId: string) => Promise<void>;
@@ -121,23 +122,6 @@ type EndTripInfo = {
121
122
  userId: string;
122
123
  orderId: string;
123
124
  };
124
-
125
- declare const endTrip: (client: Client, info: EndTripInfo) => Promise<void>;
126
-
127
- declare const optionsSchema: z.ZodObject<{
128
- minDuration: z.ZodOptional<z.ZodNumber>;
129
- boxStatus: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
130
- }, "strip", z.ZodTypeAny, {
131
- minDuration?: number | undefined;
132
- boxStatus?: number[] | undefined;
133
- }, {
134
- minDuration?: number | undefined;
135
- boxStatus?: number[] | undefined;
136
- }>;
137
- declare const getVehiclesBooked: (client: Client, options?: z.infer<typeof optionsSchema>) => Promise<FleetManagerBook[]>;
138
- declare const getVehiclesBookedByUserId: (client: Client, userId: string) => Promise<FleetManagerBook[]>;
139
- declare const getVehicleBookedByTripId: (client: Client, tripId: string) => Promise<FleetManagerBook | null>;
140
-
141
125
  type TripZone = {
142
126
  zoneId: string;
143
127
  version: number;
@@ -177,7 +161,7 @@ type TripAdditionalInfo = {
177
161
  ignoreOdometer: boolean;
178
162
  startTripEventDate: string;
179
163
  };
180
- type TripResponse = {
164
+ type Trip = {
181
165
  id: string;
182
166
  tripId: string;
183
167
  fleetId: string;
@@ -204,7 +188,24 @@ type TripResponse = {
204
188
  tripEvents: TripEvent[];
205
189
  lastUpdateDate: string;
206
190
  };
207
- declare const getTripById: (client: Client, tripId: string) => Promise<TripResponse | Record<string, never>>;
191
+
192
+ declare const endTrip: (client: Client, info: EndTripInfo) => Promise<void>;
193
+
194
+ declare const optionsSchema: z.ZodObject<{
195
+ minDuration: z.ZodOptional<z.ZodNumber>;
196
+ boxStatus: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
197
+ }, "strip", z.ZodTypeAny, {
198
+ minDuration?: number | undefined;
199
+ boxStatus?: number[] | undefined;
200
+ }, {
201
+ minDuration?: number | undefined;
202
+ boxStatus?: number[] | undefined;
203
+ }>;
204
+ declare const getVehiclesBooked: (client: Client, options?: z.infer<typeof optionsSchema>) => Promise<FleetManagerBook[]>;
205
+ declare const getVehiclesBookedByUserId: (client: Client, userId: string) => Promise<FleetManagerBook[]>;
206
+ declare const getVehicleBookedByTripId: (client: Client, tripId: string) => Promise<FleetManagerBook | null>;
207
+
208
+ declare const getTripById: (client: Client, tripId: string) => Promise<Trip | Record<string, never>>;
208
209
 
209
210
  type PaymentReceipt = {
210
211
  id: string;
@@ -235,4 +236,6 @@ type Payment = {
235
236
  };
236
237
  declare const getOngoingTripPaymentsByTripIds: (client: Client, tripIds: string[]) => Promise<Payment[]>;
237
238
 
238
- export { type EndTripInfo, type FleetManagerBook, type Payment, type PaymentReceipt, type TripAdditionalInfo, type TripEvent, type TripLocation, type TripOverriddenInfo, type TripResponse, type TripZone, type Zone, addTripRelatedProduct, endTrip, getOngoingTripPaymentsByTripIds, getTripById, getVehicleBookedByTripId, getVehiclesBooked, getVehiclesBookedByUserId, removeTripRelatedProduct };
239
+ declare const getTripsByUserId: (client: Client, userId: string, options?: PaginableOptions<void, "date">) => Promise<PaginableResponse<Trip>>;
240
+
241
+ export { type EndTripInfo, type FleetManagerBook, type Payment, type PaymentReceipt, type Trip, type TripAdditionalInfo, type TripEvent, type TripLocation, type TripOverriddenInfo, type TripZone, type Zone, addTripRelatedProduct, endTrip, getOngoingTripPaymentsByTripIds, getTripById, getTripsByUserId, getVehicleBookedByTripId, getVehiclesBooked, getVehiclesBookedByUserId, removeTripRelatedProduct };
package/dist/index.js CHANGED
@@ -34,6 +34,7 @@ __export(index_exports, {
34
34
  endTrip: () => endTrip,
35
35
  getOngoingTripPaymentsByTripIds: () => getOngoingTripPaymentsByTripIds,
36
36
  getTripById: () => getTripById,
37
+ getTripsByUserId: () => getTripsByUserId,
37
38
  getVehicleBookedByTripId: () => getVehicleBookedByTripId,
38
39
  getVehiclesBooked: () => getVehiclesBooked,
39
40
  getVehiclesBookedByUserId: () => getVehiclesBookedByUserId,
@@ -173,12 +174,52 @@ var getOngoingTripPaymentsByTripIds = async (client, tripIds) => {
173
174
  }
174
175
  return client.post(`/boapi/proxy/trip/fleets/${client.clientOptions.fleetId}/trips/ongoing`, { ids: tripIds }).then(({ data }) => data);
175
176
  };
177
+
178
+ // src/getTrips.ts
179
+ var import_aima_core = require("@vulog/aima-core");
180
+ var import_zod5 = __toESM(require("zod"));
181
+ var schemaByUserId2 = import_zod5.default.object({
182
+ userId: import_zod5.default.string().trim().min(1).uuid()
183
+ });
184
+ var getTripsByUserId = async (client, userId, options) => {
185
+ const result = schemaByUserId2.safeParse({ userId });
186
+ if (!result.success) {
187
+ throw new TypeError("Invalid userId", {
188
+ cause: result.error.issues
189
+ });
190
+ }
191
+ const PaginableOptionsSchema = (0, import_aima_core.createPaginableOptionsSchema)(
192
+ void 0,
193
+ import_zod5.default.enum(["date"]).optional().default("date")
194
+ ).default({});
195
+ const resultOptions = PaginableOptionsSchema.safeParse(options);
196
+ if (!resultOptions.success) {
197
+ throw new TypeError("Invalid options", {
198
+ cause: resultOptions.error.issues
199
+ });
200
+ }
201
+ const finalOptions = resultOptions.data;
202
+ const searchParams = new URLSearchParams();
203
+ searchParams.append("page", finalOptions.page.toString());
204
+ searchParams.append("size", finalOptions.pageSize.toString());
205
+ searchParams.append("sort", `${finalOptions.sort.toString()},${finalOptions.sortDirection.toString()}`);
206
+ return client.get(`/boapi/proxy/trip/fleets/${client.clientOptions.fleetId}/trips/users/${userId}?${searchParams.toString()}`).then(({ data, headers }) => {
207
+ return {
208
+ data,
209
+ page: headers.number,
210
+ pageSize: headers.size,
211
+ total: headers.totalelements,
212
+ totalPages: headers.totalpages
213
+ };
214
+ });
215
+ };
176
216
  // Annotate the CommonJS export names for ESM import in node:
177
217
  0 && (module.exports = {
178
218
  addTripRelatedProduct,
179
219
  endTrip,
180
220
  getOngoingTripPaymentsByTripIds,
181
221
  getTripById,
222
+ getTripsByUserId,
182
223
  getVehicleBookedByTripId,
183
224
  getVehiclesBooked,
184
225
  getVehiclesBookedByUserId,
package/dist/index.mjs CHANGED
@@ -130,11 +130,51 @@ var getOngoingTripPaymentsByTripIds = async (client, tripIds) => {
130
130
  }
131
131
  return client.post(`/boapi/proxy/trip/fleets/${client.clientOptions.fleetId}/trips/ongoing`, { ids: tripIds }).then(({ data }) => data);
132
132
  };
133
+
134
+ // src/getTrips.ts
135
+ import { createPaginableOptionsSchema } from "@vulog/aima-core";
136
+ import z5 from "zod";
137
+ var schemaByUserId2 = z5.object({
138
+ userId: z5.string().trim().min(1).uuid()
139
+ });
140
+ var getTripsByUserId = async (client, userId, options) => {
141
+ const result = schemaByUserId2.safeParse({ userId });
142
+ if (!result.success) {
143
+ throw new TypeError("Invalid userId", {
144
+ cause: result.error.issues
145
+ });
146
+ }
147
+ const PaginableOptionsSchema = createPaginableOptionsSchema(
148
+ void 0,
149
+ z5.enum(["date"]).optional().default("date")
150
+ ).default({});
151
+ const resultOptions = PaginableOptionsSchema.safeParse(options);
152
+ if (!resultOptions.success) {
153
+ throw new TypeError("Invalid options", {
154
+ cause: resultOptions.error.issues
155
+ });
156
+ }
157
+ const finalOptions = resultOptions.data;
158
+ const searchParams = new URLSearchParams();
159
+ searchParams.append("page", finalOptions.page.toString());
160
+ searchParams.append("size", finalOptions.pageSize.toString());
161
+ searchParams.append("sort", `${finalOptions.sort.toString()},${finalOptions.sortDirection.toString()}`);
162
+ return client.get(`/boapi/proxy/trip/fleets/${client.clientOptions.fleetId}/trips/users/${userId}?${searchParams.toString()}`).then(({ data, headers }) => {
163
+ return {
164
+ data,
165
+ page: headers.number,
166
+ pageSize: headers.size,
167
+ total: headers.totalelements,
168
+ totalPages: headers.totalpages
169
+ };
170
+ });
171
+ };
133
172
  export {
134
173
  addTripRelatedProduct,
135
174
  endTrip,
136
175
  getOngoingTripPaymentsByTripIds,
137
176
  getTripById,
177
+ getTripsByUserId,
138
178
  getVehicleBookedByTripId,
139
179
  getVehiclesBooked,
140
180
  getVehiclesBookedByUserId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulog/aima-trip",
3
- "version": "1.2.13",
3
+ "version": "1.2.15",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "author": "Vulog",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@vulog/aima-client": "1.2.13",
23
- "@vulog/aima-core": "1.2.13"
22
+ "@vulog/aima-client": "1.2.15",
23
+ "@vulog/aima-core": "1.2.15"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "zod": "^3.25.76"
@@ -1,82 +1,11 @@
1
1
  import { Client } from '@vulog/aima-client';
2
2
 
3
- // DTO for the getTripById API response
4
- export type TripZone = {
5
- zoneId: string;
6
- version: number;
7
- type: string;
8
- sticky: boolean;
9
- };
10
-
11
- export type TripLocation = {
12
- latitude: number;
13
- longitude: number;
14
- };
15
-
16
- export type TripEvent = {
17
- eventType: string;
18
- timestamp: string;
19
- parameters: string | null;
20
- };
21
-
22
- export type TripOverriddenInfo = {
23
- duration: {
24
- adjustedBookDuration: number;
25
- adjustedPauseDuration: number;
26
- adjustedDrivingDuration: number;
27
- };
28
- };
29
-
30
- export type TripAdditionalInfo = {
31
- firstDriveDelayMinutes: number;
32
- bookDuration: number;
33
- startZones: TripZone[];
34
- endZones: TripZone[];
35
- isAutolock: boolean;
36
- isCancel: boolean;
37
- isReleaseOnServer: boolean;
38
- isBilled: boolean;
39
- suspicious: boolean;
40
- startLocation: TripLocation;
41
- endLocation: TripLocation;
42
- overriddenTripInfo: TripOverriddenInfo;
43
- bypassBookingRequestCompleted: boolean;
44
- ignoreOdometer: boolean;
45
- startTripEventDate: string;
46
- };
47
-
48
- export type TripResponse = {
49
- id: string;
50
- tripId: string;
51
- fleetId: string;
52
- userId: string;
53
- profileId: string;
54
- profileType: string;
55
- vehicleId: string;
56
- length: number;
57
- duration: number;
58
- pauseDuration: number;
59
- tripDuration: number;
60
- bookingDuration: number;
61
- drivingDuration: number;
62
- date: string;
63
- endDate: string;
64
- additionalInfo: TripAdditionalInfo;
65
- pricingId: string;
66
- productIds: string[];
67
- serviceId: string;
68
- serviceType: string;
69
- theorStartDate: string;
70
- theorEndDate: string;
71
- ticketInfo: any;
72
- tripEvents: TripEvent[];
73
- lastUpdateDate: string;
74
- };
3
+ import { Trip } from './types';
75
4
 
76
- export const getTripById = async (client: Client, tripId: string): Promise<TripResponse | Record<string, never>> => {
5
+ export const getTripById = async (client: Client, tripId: string): Promise<Trip | Record<string, never>> => {
77
6
  const { fleetId } = client.clientOptions;
78
7
  return client
79
- .get<TripResponse>(`/boapi/proxy/trip/fleets/${fleetId}/trips/${tripId}`)
8
+ .get<Trip>(`/boapi/proxy/trip/fleets/${fleetId}/trips/${tripId}`)
80
9
  .then(({ data }) => data)
81
10
  .catch((error) => {
82
11
  if (error.formattedError?.status === 404) {
@@ -0,0 +1,55 @@
1
+ import { Client } from '@vulog/aima-client';
2
+ import { createPaginableOptionsSchema, PaginableOptions, PaginableResponse } from '@vulog/aima-core';
3
+ import z from 'zod';
4
+
5
+ import { Trip } from './types';
6
+
7
+ const schemaByUserId = z.object({
8
+ userId: z.string().trim().min(1).uuid(),
9
+ });
10
+
11
+ export const getTripsByUserId = async (
12
+ client: Client,
13
+ userId: string,
14
+ options?: PaginableOptions<void, 'date'>
15
+ ): Promise<PaginableResponse<Trip>> => {
16
+ const result = schemaByUserId.safeParse({ userId });
17
+ if (!result.success) {
18
+ throw new TypeError('Invalid userId', {
19
+ cause: result.error.issues,
20
+ });
21
+ }
22
+
23
+ const PaginableOptionsSchema = createPaginableOptionsSchema(
24
+ undefined,
25
+ z.enum(['date']).optional().default('date')
26
+ ).default({});
27
+
28
+ const resultOptions = PaginableOptionsSchema.safeParse(options);
29
+ if (!resultOptions.success) {
30
+ throw new TypeError('Invalid options', {
31
+ cause: resultOptions.error.issues,
32
+ });
33
+ }
34
+
35
+ const finalOptions = resultOptions.data;
36
+
37
+ const searchParams = new URLSearchParams();
38
+ searchParams.append('page', finalOptions.page!.toString());
39
+ searchParams.append('size', finalOptions.pageSize!.toString());
40
+ searchParams.append('sort', `${finalOptions.sort!.toString()},${finalOptions.sortDirection!.toString()}`);
41
+
42
+ return client
43
+ .get<
44
+ Trip[]
45
+ >(`/boapi/proxy/trip/fleets/${client.clientOptions.fleetId}/trips/users/${userId}?${searchParams.toString()}`)
46
+ .then(({ data, headers }) => {
47
+ return {
48
+ data,
49
+ page: headers.number,
50
+ pageSize: headers.size,
51
+ total: headers.totalelements,
52
+ totalPages: headers.totalpages,
53
+ };
54
+ });
55
+ };
package/src/index.ts CHANGED
@@ -4,3 +4,4 @@ export * from './getVehiclesBooked';
4
4
  export * from './types';
5
5
  export * from './getTripById';
6
6
  export * from './getOngoingTripPaymentsByTripIds';
7
+ export * from './getTrips';
package/src/types.ts CHANGED
@@ -116,3 +116,75 @@ export type EndTripInfo = {
116
116
  userId: string;
117
117
  orderId: string;
118
118
  };
119
+
120
+ export type TripZone = {
121
+ zoneId: string;
122
+ version: number;
123
+ type: string;
124
+ sticky: boolean;
125
+ };
126
+
127
+ export type TripLocation = {
128
+ latitude: number;
129
+ longitude: number;
130
+ };
131
+
132
+ export type TripEvent = {
133
+ eventType: string;
134
+ timestamp: string;
135
+ parameters: string | null;
136
+ };
137
+
138
+ export type TripOverriddenInfo = {
139
+ duration: {
140
+ adjustedBookDuration: number;
141
+ adjustedPauseDuration: number;
142
+ adjustedDrivingDuration: number;
143
+ };
144
+ };
145
+
146
+ export type TripAdditionalInfo = {
147
+ firstDriveDelayMinutes: number;
148
+ bookDuration: number;
149
+ startZones: TripZone[];
150
+ endZones: TripZone[];
151
+ isAutolock: boolean;
152
+ isCancel: boolean;
153
+ isReleaseOnServer: boolean;
154
+ isBilled: boolean;
155
+ suspicious: boolean;
156
+ startLocation: TripLocation;
157
+ endLocation: TripLocation;
158
+ overriddenTripInfo: TripOverriddenInfo;
159
+ bypassBookingRequestCompleted: boolean;
160
+ ignoreOdometer: boolean;
161
+ startTripEventDate: string;
162
+ };
163
+
164
+ export type Trip = {
165
+ id: string;
166
+ tripId: string;
167
+ fleetId: string;
168
+ userId: string;
169
+ profileId: string;
170
+ profileType: string;
171
+ vehicleId: string;
172
+ length: number;
173
+ duration: number;
174
+ pauseDuration: number;
175
+ tripDuration: number;
176
+ bookingDuration: number;
177
+ drivingDuration: number;
178
+ date: string;
179
+ endDate: string;
180
+ additionalInfo: TripAdditionalInfo;
181
+ pricingId: string;
182
+ productIds: string[];
183
+ serviceId: string;
184
+ serviceType: string;
185
+ theorStartDate: string;
186
+ theorEndDate: string;
187
+ ticketInfo: any;
188
+ tripEvents: TripEvent[];
189
+ lastUpdateDate: string;
190
+ };