@burdenoff/microfe-movethewheels 2026.1108.5 → 2026.1109.1

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.
@@ -2,8 +2,46 @@ import { useMoveTheWheels as e } from "../providers/MoveTheWheelsProvider.js";
2
2
  import { executeGraphQL as t } from "../utils/graphqlClient.js";
3
3
  import { useCallback as n, useEffect as r, useMemo as i, useState as a } from "react";
4
4
  //#region src/movethewheels/hooks/useRoutes.ts
5
- var o = "\n query ListRoutes($filter: RouteFilterInput, $pagination: PaginationInput) {\n routes(filter: $filter, pagination: $pagination) {\n id\n name\n status\n shipmentId\n vehicleId\n driverId\n waypoints\n estimatedDistance\n estimatedDuration\n fuelCost\n actualDistance\n actualDuration\n createdAt\n }\n routesCount(filter: $filter)\n }\n", s = "\n query GetRoute($id: ID!) {\n route(id: $id) {\n id\n name\n status\n shipmentId\n vehicleId\n driverId\n waypoints\n estimatedDistance\n estimatedDuration\n fuelCost\n actualDistance\n actualDuration\n createdAt\n }\n }\n", c = "\n mutation CreateRoute($input: CreateRouteInput!) {\n createRoute(input: $input) {\n id\n name\n status\n shipmentId\n vehicleId\n driverId\n waypoints\n estimatedDistance\n estimatedDuration\n fuelCost\n actualDistance\n actualDuration\n createdAt\n }\n }\n", l = "\n mutation UpdateRoute($id: ID!, $input: UpdateRouteInput!) {\n updateRoute(id: $id, input: $input) {\n id\n name\n status\n shipmentId\n vehicleId\n driverId\n waypoints\n estimatedDistance\n estimatedDuration\n fuelCost\n actualDistance\n actualDuration\n createdAt\n }\n }\n", u = "\n mutation DeleteRoute($id: ID!) {\n deleteRoute(id: $id)\n }\n", d = "\n mutation OptimizeRoute($id: ID!) {\n optimizeRoute(id: $id) {\n id\n name\n status\n shipmentId\n vehicleId\n driverId\n waypoints\n estimatedDistance\n estimatedDuration\n fuelCost\n actualDistance\n actualDuration\n createdAt\n }\n }\n";
6
- function f(e) {
5
+ var o = "\n lastOptimization {\n strategy\n ranAt\n waypointCount\n distanceBeforeKm\n distanceAfterKm\n distanceSavedKm\n durationAfterMinutes\n feasible\n violations {\n code\n message\n sequence\n }\n }\n", s = "\n query ListRoutes($filter: RouteFilterInput, $pagination: PaginationInput) {\n routes(filter: $filter, pagination: $pagination) {\n id\n name\n status\n shipmentId\n vehicleId\n driverId\n waypoints\n estimatedDistance\n estimatedDuration\n fuelCost\n actualDistance\n actualDuration\n createdAt\n }\n routesCount(filter: $filter)\n }\n", c = `
6
+ query GetRoute($id: ID!) {
7
+ route(id: $id) {
8
+ id
9
+ name
10
+ status
11
+ shipmentId
12
+ vehicleId
13
+ driverId
14
+ waypoints
15
+ estimatedDistance
16
+ estimatedDuration
17
+ fuelCost
18
+ actualDistance
19
+ actualDuration
20
+ createdAt
21
+ ${o}
22
+ }
23
+ }
24
+ `, l = "\n mutation CreateRoute($input: CreateRouteInput!) {\n createRoute(input: $input) {\n id\n name\n status\n shipmentId\n vehicleId\n driverId\n waypoints\n estimatedDistance\n estimatedDuration\n fuelCost\n actualDistance\n actualDuration\n createdAt\n }\n }\n", u = "\n mutation UpdateRoute($id: ID!, $input: UpdateRouteInput!) {\n updateRoute(id: $id, input: $input) {\n id\n name\n status\n shipmentId\n vehicleId\n driverId\n waypoints\n estimatedDistance\n estimatedDuration\n fuelCost\n actualDistance\n actualDuration\n createdAt\n }\n }\n", d = "\n mutation DeleteRoute($id: ID!) {\n deleteRoute(id: $id)\n }\n", f = `
25
+ mutation OptimizeRoute($id: ID!, $input: OptimizeRouteInput) {
26
+ optimizeRoute(id: $id, input: $input) {
27
+ id
28
+ name
29
+ status
30
+ shipmentId
31
+ vehicleId
32
+ driverId
33
+ waypoints
34
+ estimatedDistance
35
+ estimatedDuration
36
+ fuelCost
37
+ actualDistance
38
+ actualDuration
39
+ createdAt
40
+ ${o}
41
+ }
42
+ }
43
+ `;
44
+ function p(e) {
7
45
  switch (e) {
8
46
  case "IN_PROGRESS": return "in_progress";
9
47
  case "COMPLETED": return "completed";
@@ -11,7 +49,7 @@ function f(e) {
11
49
  default: return "planned";
12
50
  }
13
51
  }
14
- function p(e) {
52
+ function m(e) {
15
53
  if (e) switch (e) {
16
54
  case "in_progress": return "IN_PROGRESS";
17
55
  case "completed": return "COMPLETED";
@@ -19,7 +57,7 @@ function p(e) {
19
57
  default: return "PLANNED";
20
58
  }
21
59
  }
22
- function m(e) {
60
+ function h(e) {
23
61
  return Array.isArray(e) ? e.map((e, t) => {
24
62
  let n = e ?? {}, r = n.address, i = r && typeof r == "object" ? r : {}, a = typeof r == "string" ? r : void 0;
25
63
  return {
@@ -44,23 +82,24 @@ function m(e) {
44
82
  };
45
83
  }) : [];
46
84
  }
47
- function h(e) {
85
+ function g(e) {
48
86
  return {
49
87
  id: e.id,
50
88
  name: e.name,
51
89
  driverId: e.driverId ?? void 0,
52
90
  vehicleId: e.vehicleId ?? void 0,
53
- status: f(e.status),
54
- stops: m(e.waypoints),
91
+ status: p(e.status),
92
+ stops: h(e.waypoints),
55
93
  distance: e.actualDistance ?? e.estimatedDistance ?? 0,
56
94
  estimatedDuration: e.estimatedDuration ?? 0,
57
95
  fuelCost: e.fuelCost ?? void 0,
58
96
  actualDuration: e.actualDuration ?? void 0,
59
- optimized: void 0,
97
+ optimized: e.lastOptimization ? !0 : void 0,
98
+ lastOptimization: e.lastOptimization ?? void 0,
60
99
  createdAt: new Date(e.createdAt)
61
100
  };
62
101
  }
63
- function g() {
102
+ function _() {
64
103
  let { apiGatewayUrl: t, authToken: n, workspaceToken: r, workspaceId: a, tenantId: o, currentUser: s } = e();
65
104
  return i(() => ({
66
105
  apiGatewayUrl: t,
@@ -78,23 +117,23 @@ function g() {
78
117
  s?.id
79
118
  ]);
80
119
  }
81
- function _(e = {}) {
82
- let { driverId: i, vehicleId: s, status: f, search: m, limit: _ = 20, offset: v = 0 } = e, y = g(), [b, x] = a([]), [S, C] = a(0), [w, T] = a(!1), [E, D] = a(!1), [O, k] = a(!1), [A, j] = a(null), M = n(async () => {
120
+ function v(e = {}) {
121
+ let { driverId: i, vehicleId: o, status: c, search: p, limit: h = 20, offset: v = 0 } = e, y = _(), [b, x] = a([]), [S, C] = a(0), [w, T] = a(!1), [E, D] = a(!1), [O, k] = a(!1), [A, j] = a(null), M = n(async () => {
83
122
  D(!0), j(null);
84
123
  try {
85
- let e = await t(y, o, {
124
+ let e = await t(y, s, {
86
125
  filter: {
87
126
  driverId: i,
88
- vehicleId: s,
89
- status: f ? p(f) : void 0,
90
- search: m || void 0
127
+ vehicleId: o,
128
+ status: c ? m(c) : void 0,
129
+ search: p || void 0
91
130
  },
92
131
  pagination: {
93
- limit: _,
132
+ limit: h,
94
133
  offset: v
95
134
  }
96
135
  });
97
- C(e.routesCount), T(v + e.routes.length < e.routesCount), x(e.routes.map(h));
136
+ C(e.routesCount), T(v + e.routes.length < e.routesCount), x(e.routes.map(g));
98
137
  } catch (e) {
99
138
  j(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load routes"));
100
139
  } finally {
@@ -103,28 +142,28 @@ function _(e = {}) {
103
142
  }, [
104
143
  i,
105
144
  y,
106
- m,
107
- f,
108
- s,
109
- _,
145
+ p,
146
+ c,
147
+ o,
148
+ h,
110
149
  v
111
150
  ]), N = n(async () => {
112
151
  if (!w || E || O) return;
113
152
  let e = v + b.length;
114
153
  k(!0), j(null);
115
154
  try {
116
- let n = await t(y, o, {
155
+ let n = await t(y, s, {
117
156
  filter: {
118
157
  driverId: i,
119
- vehicleId: s,
120
- status: f ? p(f) : void 0,
121
- search: m || void 0
158
+ vehicleId: o,
159
+ status: c ? m(c) : void 0,
160
+ search: p || void 0
122
161
  },
123
162
  pagination: {
124
- limit: _,
163
+ limit: h,
125
164
  offset: e
126
165
  }
127
- }), r = n.routes.map(h);
166
+ }), r = n.routes.map(g);
128
167
  C(n.routesCount), T(e + r.length < n.routesCount), x((e) => {
129
168
  let t = new Set(e.map((e) => e.id));
130
169
  return [...e, ...r.filter((e) => !t.has(e.id))];
@@ -140,12 +179,12 @@ function _(e = {}) {
140
179
  w,
141
180
  E,
142
181
  O,
143
- _,
182
+ h,
144
183
  v,
145
184
  b.length,
146
- m,
147
- f,
148
- s
185
+ p,
186
+ c,
187
+ o
149
188
  ]);
150
189
  r(() => {
151
190
  M();
@@ -153,9 +192,9 @@ function _(e = {}) {
153
192
  let P = n(() => {
154
193
  M();
155
194
  }, [M]), F = n(async (e) => {
156
- let n = h((await t(y, c, { input: {
195
+ let n = g((await t(y, l, { input: {
157
196
  name: e.name ?? `Route ${(/* @__PURE__ */ new Date()).toLocaleDateString()}`,
158
- status: p(e.status),
197
+ status: m(e.status),
159
198
  shipmentId: void 0,
160
199
  vehicleId: e.vehicleId,
161
200
  driverId: e.driverId,
@@ -165,11 +204,11 @@ function _(e = {}) {
165
204
  } })).createRoute);
166
205
  return x((e) => [n, ...e]), n;
167
206
  }, [y]), I = n(async (e, n) => {
168
- let r = h((await t(y, l, {
207
+ let r = g((await t(y, u, {
169
208
  id: e,
170
209
  input: {
171
210
  name: n.name,
172
- status: p(n.status),
211
+ status: m(n.status),
173
212
  shipmentId: void 0,
174
213
  vehicleId: Object.prototype.hasOwnProperty.call(n, "vehicleId") ? n.vehicleId ?? null : void 0,
175
214
  driverId: Object.prototype.hasOwnProperty.call(n, "driverId") ? n.driverId ?? null : void 0,
@@ -192,14 +231,14 @@ function _(e = {}) {
192
231
  createRoute: F,
193
232
  updateRoute: I,
194
233
  deleteRoute: n(async (e) => {
195
- await t(y, u, { id: e }), x((t) => t.filter((t) => t.id !== e));
234
+ await t(y, d, { id: e }), x((t) => t.filter((t) => t.id !== e));
196
235
  }, [y]),
197
- optimizeRoute: n(async (e) => {
198
- let n = {
199
- ...h((await t(y, d, { id: e })).optimizeRoute),
200
- optimized: !0
201
- };
202
- return x((t) => t.map((t) => t.id === e ? n : t)), n;
236
+ optimizeRoute: n(async (e, n) => {
237
+ let r = g((await t(y, f, {
238
+ id: e,
239
+ input: n ? { strategy: n } : void 0
240
+ })).optimizeRoute);
241
+ return x((t) => t.map((t) => t.id === e ? r : t)), r;
203
242
  }, [y]),
204
243
  updateStopStatus: n(async (e, t, n) => {
205
244
  let r = b.find((t) => t.id === e);
@@ -216,16 +255,16 @@ function _(e = {}) {
216
255
  }, [b, I])
217
256
  };
218
257
  }
219
- function v(e) {
220
- let i = g(), [o, c] = a(null), [l, u] = a(!1), [d, f] = a(null), p = n(async () => {
258
+ function y(e) {
259
+ let i = _(), [o, s] = a(null), [l, u] = a(!1), [d, f] = a(null), p = n(async () => {
221
260
  if (!e) {
222
- c(null);
261
+ s(null);
223
262
  return;
224
263
  }
225
264
  u(!0), f(null);
226
265
  try {
227
- let n = await t(i, s, { id: e });
228
- c(n.route ? h(n.route) : null);
266
+ let n = await t(i, c, { id: e });
267
+ s(n.route ? g(n.route) : null);
229
268
  } catch (e) {
230
269
  f(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load route"));
231
270
  } finally {
@@ -241,9 +280,9 @@ function v(e) {
241
280
  refetch: () => void p()
242
281
  };
243
282
  }
244
- var y = "\n query RouteStats {\n routeStats {\n total\n totalDistance\n totalDuration\n completed\n inProgress\n planned\n optimized\n }\n }\n";
245
- function b() {
246
- let e = g(), [n, i] = a({
283
+ var b = "\n query RouteStats {\n routeStats {\n total\n totalDistance\n totalDuration\n completed\n inProgress\n planned\n optimized\n }\n }\n";
284
+ function x() {
285
+ let e = _(), [n, i] = a({
247
286
  totalRoutes: 0,
248
287
  totalDistance: 0,
249
288
  totalDuration: 0,
@@ -258,7 +297,7 @@ function b() {
258
297
  (async () => {
259
298
  s(!0), l(null);
260
299
  try {
261
- let n = (await t(e, y)).routeStats;
300
+ let n = (await t(e, b)).routeStats;
262
301
  i({
263
302
  totalRoutes: n.total,
264
303
  totalDistance: n.totalDistance,
@@ -283,4 +322,4 @@ function b() {
283
322
  };
284
323
  }
285
324
  //#endregion
286
- export { h as mapRoute, v as useRoute, b as useRouteStats, _ as useRoutes };
325
+ export { g as mapRoute, y as useRoute, x as useRouteStats, v as useRoutes };
@@ -1,4 +1,4 @@
1
- import { Route, RouteStop } from '../types';
1
+ import { Route, RouteOptimizationStrategy, RouteOptimizationSummary, RouteStop } from '../types';
2
2
  interface UseRoutesOptions {
3
3
  driverId?: string;
4
4
  vehicleId?: string;
@@ -24,7 +24,7 @@ interface UseRoutesResult {
24
24
  driverId?: string | null;
25
25
  }) => Promise<Route>;
26
26
  deleteRoute: (id: string) => Promise<void>;
27
- optimizeRoute: (routeId: string) => Promise<Route>;
27
+ optimizeRoute: (routeId: string, strategy?: RouteOptimizationStrategy) => Promise<Route>;
28
28
  updateStopStatus: (routeId: string, stopId: string, status: RouteStop['status']) => Promise<Route>;
29
29
  }
30
30
  interface ApiRoute {
@@ -40,6 +40,7 @@ interface ApiRoute {
40
40
  fuelCost?: number | null;
41
41
  actualDistance?: number | null;
42
42
  actualDuration?: number | null;
43
+ lastOptimization?: RouteOptimizationSummary | null;
43
44
  createdAt: string;
44
45
  }
45
46
  export declare function mapRoute(route: ApiRoute): Route;
@@ -403,6 +403,24 @@ export interface TrafficCondition {
403
403
  delay: number;
404
404
  location: string;
405
405
  }
406
+ export type RouteOptimizationStrategy = 'AUTO' | 'NEAREST_NEIGHBOUR' | 'TIME_WINDOW' | 'TWO_OPT';
407
+ export type RouteOptimizationViolationCode = 'WINDOW_MISSED' | 'OVER_CAPACITY' | 'OVER_DRIVER_HOURS' | 'NO_COORDINATES';
408
+ export interface RouteOptimizationViolation {
409
+ code: RouteOptimizationViolationCode;
410
+ message: string;
411
+ sequence?: number | null;
412
+ }
413
+ export interface RouteOptimizationSummary {
414
+ strategy: RouteOptimizationStrategy;
415
+ ranAt: string;
416
+ waypointCount: number;
417
+ distanceBeforeKm?: number | null;
418
+ distanceAfterKm?: number | null;
419
+ distanceSavedKm?: number | null;
420
+ durationAfterMinutes?: number | null;
421
+ feasible: boolean;
422
+ violations: RouteOptimizationViolation[];
423
+ }
406
424
  export interface Route {
407
425
  id: string;
408
426
  name: string;
@@ -415,8 +433,10 @@ export interface Route {
415
433
  /** Estimated fuel cost for the route (svc MtwRoute.fuelCost). */
416
434
  fuelCost?: number;
417
435
  actualDuration?: number;
418
- /** Backend currently does not expose whether optimization has run. */
436
+ /** True once the backend reports a persisted optimization summary. */
419
437
  optimized?: boolean;
438
+ /** Summary of the most recent optimizeRoute run, when one has run. */
439
+ lastOptimization?: RouteOptimizationSummary;
420
440
  createdAt: Date;
421
441
  }
422
442
  export type TrackingAlertSeverity = 'low' | 'medium' | 'high' | 'critical';