@burdenoff/microfe-movethewheels 2026.930.2 → 2026.930.4

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,20 @@ 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/useInventory.ts
5
- var o = "\n query ListInventoryItems($filter: InventoryFilterInput, $pagination: PaginationInput) {\n inventoryItems(filter: $filter, pagination: $pagination) {\n id\n cargoItemId\n warehouseId\n onHand\n available\n allocated\n damaged\n reorderPoint\n createdAt\n updatedAt\n cargoItem {\n id\n name\n sku\n }\n warehouse {\n id\n name\n code\n }\n }\n inventoryItemsCount(filter: $filter)\n }\n", s = "\n query ListCargoItems($filter: CargoItemFilterInput, $pagination: PaginationInput) {\n cargoItems(filter: $filter, pagination: $pagination) {\n id\n sku\n name\n description\n category\n brand\n dimensions\n weight\n value\n hazardous\n fragile\n temperatureControlled\n createdAt\n updatedAt\n }\n cargoItemsCount(filter: $filter)\n }\n", c = "\n query ListWarehouses($filter: WarehouseFilterInput, $pagination: PaginationInput) {\n warehouses(filter: $filter, pagination: $pagination) {\n id\n name\n code\n type\n address\n status\n contactInfo\n operatingHours\n totalCapacity\n usedCapacity\n createdAt\n }\n warehousesCount(filter: $filter)\n }\n", l = "\n query GetCargoItem($id: ID!) {\n cargoItem(id: $id) {\n id\n sku\n name\n description\n category\n brand\n dimensions\n weight\n value\n hazardous\n fragile\n temperatureControlled\n createdAt\n updatedAt\n }\n }\n", u = "\n query GetWarehouse($id: ID!) {\n warehouse(id: $id) {\n id\n name\n code\n type\n address\n status\n contactInfo\n operatingHours\n totalCapacity\n usedCapacity\n createdAt\n }\n }\n", d = "\n query GetInventoryStats {\n inventoryStats {\n totalOnHand\n totalAvailable\n totalAllocated\n totalDamaged\n lowStockCount\n }\n cargoItemsCount\n warehousesCount\n }\n", f = "\n query ListInventoryTransactions($filter: InventoryFilterInput, $pagination: PaginationInput) {\n inventoryTransactions(filter: $filter, pagination: $pagination) {\n id\n transactionNumber\n type\n quantity\n cargoItemId\n warehouseId\n notes\n referenceType\n referenceId\n createdAt\n }\n }\n", p = "\n mutation CreateCargoItem($input: CreateCargoItemInput!) {\n createCargoItem(input: $input) {\n id\n sku\n name\n description\n category\n brand\n dimensions\n weight\n value\n hazardous\n fragile\n temperatureControlled\n createdAt\n updatedAt\n }\n }\n", m = "\n mutation UpdateCargoItem($id: ID!, $input: UpdateCargoItemInput!) {\n updateCargoItem(id: $id, input: $input) {\n id\n sku\n name\n description\n category\n brand\n dimensions\n weight\n value\n hazardous\n fragile\n temperatureControlled\n createdAt\n updatedAt\n }\n }\n", h = "\n mutation DeleteCargoItem($id: ID!) {\n deleteCargoItem(id: $id)\n }\n", g = "\n mutation CreateWarehouse($input: CreateWarehouseInput!) {\n createWarehouse(input: $input) {\n id\n name\n code\n type\n address\n status\n contactInfo\n operatingHours\n totalCapacity\n usedCapacity\n createdAt\n }\n }\n", _ = "\n mutation DeleteWarehouse($id: ID!) {\n deleteWarehouse(id: $id)\n }\n", v = "\n mutation UpdateWarehouse($id: ID!, $input: UpdateWarehouseInput!) {\n updateWarehouse(id: $id, input: $input) {\n id\n name\n code\n type\n address\n status\n contactInfo\n operatingHours\n totalCapacity\n usedCapacity\n createdAt\n }\n }\n", y = "\n mutation AdjustInventoryStock($input: AdjustInventoryStockInput!) {\n adjustInventoryStock(input: $input) {\n id\n cargoItemId\n warehouseId\n onHand\n available\n allocated\n damaged\n reorderPoint\n createdAt\n updatedAt\n }\n }\n", b = "\n mutation TransferInventoryStock($input: TransferInventoryStockInput!) {\n transferInventoryStock(input: $input) {\n source {\n id\n cargoItemId\n warehouseId\n onHand\n available\n allocated\n damaged\n reorderPoint\n createdAt\n updatedAt\n }\n destination {\n id\n cargoItemId\n warehouseId\n onHand\n available\n allocated\n damaged\n reorderPoint\n createdAt\n updatedAt\n }\n }\n }\n";
6
- function x(e) {
5
+ var o = "\n query ListInventoryItems($filter: InventoryFilterInput, $pagination: PaginationInput) {\n inventoryItems(filter: $filter, pagination: $pagination) {\n id\n cargoItemId\n warehouseId\n onHand\n available\n allocated\n damaged\n reorderPoint\n createdAt\n updatedAt\n cargoItem {\n id\n name\n sku\n }\n warehouse {\n id\n name\n code\n }\n }\n inventoryItemsCount(filter: $filter)\n }\n", s = "\n query ListCargoItems($filter: CargoItemFilterInput, $pagination: PaginationInput) {\n cargoItems(filter: $filter, pagination: $pagination) {\n id\n sku\n name\n description\n category\n brand\n dimensions\n weight\n value\n hazardous\n fragile\n temperatureControlled\n createdAt\n updatedAt\n }\n cargoItemsCount(filter: $filter)\n }\n", c = "\n query ListWarehouses($filter: WarehouseFilterInput, $pagination: PaginationInput) {\n warehouses(filter: $filter, pagination: $pagination) {\n id\n name\n code\n type\n address\n status\n contactInfo\n operatingHours\n totalCapacity\n usedCapacity\n createdAt\n }\n warehousesCount(filter: $filter)\n }\n", l = "\n query GetCargoItem($id: ID!) {\n cargoItem(id: $id) {\n id\n sku\n name\n description\n category\n brand\n dimensions\n weight\n value\n hazardous\n fragile\n temperatureControlled\n createdAt\n updatedAt\n }\n }\n", u = "\n query GetWarehouse($id: ID!) {\n warehouse(id: $id) {\n id\n name\n code\n type\n address\n status\n contactInfo\n operatingHours\n totalCapacity\n usedCapacity\n createdAt\n }\n }\n", d = "\n query GetInventoryStats {\n inventoryStats {\n totalOnHand\n totalAvailable\n totalAllocated\n totalDamaged\n lowStockCount\n }\n cargoItemsCount\n warehousesCount\n }\n", f = "\n query ListInventoryTransactions($filter: InventoryFilterInput, $pagination: PaginationInput) {\n inventoryTransactions(filter: $filter, pagination: $pagination) {\n id\n transactionNumber\n type\n quantity\n cargoItemId\n warehouseId\n notes\n referenceType\n referenceId\n createdAt\n }\n }\n", p = "\n mutation CreateCargoItem($input: CreateCargoItemInput!) {\n createCargoItem(input: $input) {\n id\n sku\n name\n description\n category\n brand\n dimensions\n weight\n value\n hazardous\n fragile\n temperatureControlled\n createdAt\n updatedAt\n }\n }\n", m = "\n mutation UpdateCargoItem($id: ID!, $input: UpdateCargoItemInput!) {\n updateCargoItem(id: $id, input: $input) {\n id\n sku\n name\n description\n category\n brand\n dimensions\n weight\n value\n hazardous\n fragile\n temperatureControlled\n createdAt\n updatedAt\n }\n }\n", h = "\n mutation DeleteCargoItem($id: ID!) {\n deleteCargoItem(id: $id)\n }\n", g = "\n mutation CreateWarehouse($input: CreateWarehouseInput!) {\n createWarehouse(input: $input) {\n id\n name\n code\n type\n address\n status\n contactInfo\n operatingHours\n totalCapacity\n usedCapacity\n createdAt\n }\n }\n", _ = "\n mutation DeleteWarehouse($id: ID!) {\n deleteWarehouse(id: $id)\n }\n", v = "\n mutation UpdateWarehouse($id: ID!, $input: UpdateWarehouseInput!) {\n updateWarehouse(id: $id, input: $input) {\n id\n name\n code\n type\n address\n status\n contactInfo\n operatingHours\n totalCapacity\n usedCapacity\n createdAt\n }\n }\n", y = "\n id\n cargoItemId\n warehouseId\n onHand\n available\n allocated\n damaged\n reorderPoint\n createdAt\n updatedAt\n cargoItem {\n id\n name\n sku\n }\n warehouse {\n id\n name\n code\n }\n", b = `
6
+ query FindStockLine($filter: InventoryFilterInput, $pagination: PaginationInput) {
7
+ inventoryItems(filter: $filter, pagination: $pagination) {
8
+ ${y}
9
+ }
10
+ }
11
+ `, x = `
12
+ mutation CreateInventoryItem($input: CreateInventoryItemInput!) {
13
+ createInventoryItem(input: $input) {
14
+ ${y}
15
+ }
16
+ }
17
+ `, S = "\n mutation AdjustInventoryStock($input: AdjustInventoryStockInput!) {\n adjustInventoryStock(input: $input) {\n id\n cargoItemId\n warehouseId\n onHand\n available\n allocated\n damaged\n reorderPoint\n createdAt\n updatedAt\n }\n }\n", C = "\n mutation TransferInventoryStock($input: TransferInventoryStockInput!) {\n transferInventoryStock(input: $input) {\n source {\n id\n cargoItemId\n warehouseId\n onHand\n available\n allocated\n damaged\n reorderPoint\n createdAt\n updatedAt\n }\n destination {\n id\n cargoItemId\n warehouseId\n onHand\n available\n allocated\n damaged\n reorderPoint\n createdAt\n updatedAt\n }\n }\n }\n";
18
+ function w(e) {
7
19
  if (!e) return;
8
20
  let t = {};
9
21
  for (let n of [
@@ -16,7 +28,7 @@ function x(e) {
16
28
  }
17
29
  return typeof e.unit == "string" && e.unit.trim() && (t.unit = e.unit), Object.keys(t).length > 0 ? t : void 0;
18
30
  }
19
- function S(e) {
31
+ function T(e) {
20
32
  return {
21
33
  id: e.id,
22
34
  sku: e.sku,
@@ -24,7 +36,7 @@ function S(e) {
24
36
  description: e.description ?? void 0,
25
37
  category: e.category ?? void 0,
26
38
  brand: e.brand ?? void 0,
27
- dimensions: x(e.dimensions),
39
+ dimensions: w(e.dimensions),
28
40
  weight: e.weight ?? void 0,
29
41
  value: e.value ?? void 0,
30
42
  barcode: void 0,
@@ -37,10 +49,10 @@ function S(e) {
37
49
  updatedAt: new Date(e.updatedAt)
38
50
  };
39
51
  }
40
- function C(e) {
52
+ function E(e) {
41
53
  return e ? Object.fromEntries(Object.entries(e).flatMap(([e, t]) => typeof t == "string" && t.trim() ? [[e, t]] : [])) : {};
42
54
  }
43
- function w(e) {
55
+ function D(e) {
44
56
  let t = typeof e.totalCapacity == "number" ? e.totalCapacity : void 0, n = typeof e.usedCapacity == "number" ? e.usedCapacity : void 0, r = e.operatingHours ?? {}, i = {};
45
57
  for (let [e, t] of Object.entries(r)) t && typeof t == "object" && "open" in t && "close" in t ? i[e] = {
46
58
  open: String(t.open),
@@ -51,7 +63,7 @@ function w(e) {
51
63
  id: e.id,
52
64
  name: e.name,
53
65
  code: e.code,
54
- address: C(e.address),
66
+ address: E(e.address),
55
67
  type: e.type.toLowerCase(),
56
68
  status: e.status,
57
69
  capacity: {
@@ -67,7 +79,7 @@ function w(e) {
67
79
  createdAt: new Date(e.createdAt)
68
80
  };
69
81
  }
70
- function T(e) {
82
+ function O(e) {
71
83
  return {
72
84
  id: e.id,
73
85
  productId: e.cargoItemId,
@@ -85,7 +97,7 @@ function T(e) {
85
97
  updatedAt: new Date(e.updatedAt)
86
98
  };
87
99
  }
88
- function E() {
100
+ function k() {
89
101
  let { apiGatewayUrl: t, authToken: n, workspaceToken: r, workspaceId: a, tenantId: o, currentUser: s } = e();
90
102
  return i(() => ({
91
103
  apiGatewayUrl: t,
@@ -103,32 +115,32 @@ function E() {
103
115
  s?.id
104
116
  ]);
105
117
  }
106
- function D(e = {}) {
107
- let { filters: l, search: u, limit: d = 10, offset: f = 0 } = e, x = i(() => l, [
118
+ function A(e = {}) {
119
+ let { filters: l, search: u, limit: d = 10, offset: f = 0 } = e, y = i(() => l, [
108
120
  l?.lowStock,
109
121
  l?.productId,
110
122
  l?.search,
111
123
  l?.warehouseId
112
- ]), C = E(), [D, O] = a([]), [k, A] = a([]), [j, M] = a([]), [N, P] = a([]), [F, I] = a(0), [L, R] = a(!1), [z, B] = a(!1), [V, H] = a(null), U = n(async () => {
124
+ ]), b = k(), [x, w] = a([]), [E, A] = a([]), [j, M] = a([]), [N, P] = a([]), [F, I] = a(0), [L, R] = a(!1), [z, B] = a(!1), [V, H] = a(null), U = n(async () => {
113
125
  B(!0), H(null);
114
126
  try {
115
127
  let e = {
116
- warehouseId: x?.warehouseId,
117
- cargoItemId: x?.productId,
118
- search: u || x?.search || void 0,
119
- lowStock: x?.lowStock || void 0
128
+ warehouseId: y?.warehouseId,
129
+ cargoItemId: y?.productId,
130
+ search: u || y?.search || void 0,
131
+ lowStock: y?.lowStock || void 0
120
132
  }, [n, r, i, a] = await Promise.all([
121
- t(C, o, {
133
+ t(b, o, {
122
134
  filter: e,
123
135
  pagination: {
124
136
  limit: d,
125
137
  offset: f
126
138
  }
127
139
  }),
128
- t(C, o, {
140
+ t(b, o, {
129
141
  filter: {
130
- warehouseId: x?.warehouseId,
131
- cargoItemId: x?.productId,
142
+ warehouseId: y?.warehouseId,
143
+ cargoItemId: y?.productId,
132
144
  lowStock: !0
133
145
  },
134
146
  pagination: {
@@ -136,24 +148,24 @@ function D(e = {}) {
136
148
  offset: 0
137
149
  }
138
150
  }),
139
- t(C, s, { pagination: {
151
+ t(b, s, { pagination: {
140
152
  limit: 5,
141
153
  offset: 0
142
154
  } }),
143
- t(C, c, { pagination: {
155
+ t(b, c, { pagination: {
144
156
  limit: 5,
145
157
  offset: 0
146
158
  } })
147
159
  ]);
148
- O(n.inventoryItems.map(T)), A(r.inventoryItems.map(T)), I(n.inventoryItemsCount), R(f + n.inventoryItems.length < n.inventoryItemsCount), M(i.cargoItems.map(S)), P(a.warehouses.map(w));
160
+ w(n.inventoryItems.map(O)), A(r.inventoryItems.map(O)), I(n.inventoryItemsCount), R(f + n.inventoryItems.length < n.inventoryItemsCount), M(i.cargoItems.map(T)), P(a.warehouses.map(D));
149
161
  } catch (e) {
150
162
  H(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load inventory data"));
151
163
  } finally {
152
164
  B(!1);
153
165
  }
154
166
  }, [
155
- x,
156
- C,
167
+ y,
168
+ b,
157
169
  d,
158
170
  f,
159
171
  u
@@ -164,31 +176,31 @@ function D(e = {}) {
164
176
  let W = n(() => {
165
177
  U();
166
178
  }, [U]), G = n(async (e, n, r) => {
167
- let i = D.find((t) => t.id === e);
179
+ let i = x.find((t) => t.id === e);
168
180
  if (!i) throw Error("Inventory item not found");
169
- let a = T((await t(C, y, { input: {
181
+ let a = O((await t(b, S, { input: {
170
182
  id: e,
171
183
  onHand: i.quantity + n,
172
184
  available: i.availableQuantity + n,
173
185
  allocated: i.reservedQuantity,
174
186
  damaged: i.damagedQuantity
175
187
  } })).adjustInventoryStock);
176
- return O((t) => t.map((t) => t.id === e ? a : t)), a;
177
- }, [C, D]), K = n(async (e, n, r, i) => {
188
+ return w((t) => t.map((t) => t.id === e ? a : t)), a;
189
+ }, [b, x]), K = n(async (e, n, r, i) => {
178
190
  if (!Number.isInteger(i) || i <= 0) throw Error("Transfer quantity must be a positive whole number.");
179
191
  if (e === n) throw Error("Source and destination warehouses must be different.");
180
- let a = D.find((t) => t.warehouseId === e && t.productId === r);
192
+ let a = x.find((t) => t.warehouseId === e && t.productId === r);
181
193
  if (!a) throw Error("Source inventory not found");
182
- let o = D.find((e) => e.warehouseId === n && e.productId === r);
194
+ let o = x.find((e) => e.warehouseId === n && e.productId === r);
183
195
  if (!o) throw Error("Destination inventory not found");
184
- let s = await t(C, b, { input: {
196
+ let s = await t(b, C, { input: {
185
197
  sourceInventoryItemId: a.id,
186
198
  destinationInventoryItemId: o.id,
187
199
  quantity: i
188
- } }), c = T(s.transferInventoryStock.source), l = T(s.transferInventoryStock.destination);
189
- O((e) => e.map((e) => e.id === c.id ? c : e.id === l.id ? l : e));
190
- }, [C, D]), q = n(async (e) => {
191
- let n = S((await t(C, p, { input: {
200
+ } }), c = O(s.transferInventoryStock.source), l = O(s.transferInventoryStock.destination);
201
+ w((e) => e.map((e) => e.id === c.id ? c : e.id === l.id ? l : e));
202
+ }, [b, x]), q = n(async (e) => {
203
+ let n = T((await t(b, p, { input: {
192
204
  name: e.name,
193
205
  sku: e.sku,
194
206
  description: e.description,
@@ -202,8 +214,8 @@ function D(e = {}) {
202
214
  temperatureControlled: e.temperatureControlled
203
215
  } })).createCargoItem);
204
216
  return M((e) => [n, ...e]), n;
205
- }, [C]), J = n(async (e) => {
206
- let n = w((await t(C, g, { input: {
217
+ }, [b]), J = n(async (e) => {
218
+ let n = D((await t(b, g, { input: {
207
219
  code: e.code,
208
220
  name: e.name,
209
221
  type: e.type,
@@ -214,10 +226,10 @@ function D(e = {}) {
214
226
  usedCapacity: e.usedCapacity
215
227
  } })).createWarehouse);
216
228
  return P((e) => [n, ...e]), n;
217
- }, [C]);
229
+ }, [b]);
218
230
  return {
219
- inventory: D,
220
- lowStockItems: k,
231
+ inventory: x,
232
+ lowStockItems: E,
221
233
  products: j,
222
234
  warehouses: N,
223
235
  totalItems: F,
@@ -229,7 +241,7 @@ function D(e = {}) {
229
241
  transferStock: K,
230
242
  createProduct: q,
231
243
  updateProduct: n(async (e, n) => {
232
- let r = S((await t(C, m, {
244
+ let r = T((await t(b, m, {
233
245
  id: e,
234
246
  input: {
235
247
  name: n.name,
@@ -246,13 +258,13 @@ function D(e = {}) {
246
258
  }
247
259
  })).updateCargoItem);
248
260
  return M((t) => t.map((t) => t.id === e ? r : t)), r;
249
- }, [C]),
261
+ }, [b]),
250
262
  deleteProduct: n(async (e) => {
251
- await t(C, h, { id: e }), M((t) => t.filter((t) => t.id !== e));
252
- }, [C]),
263
+ await t(b, h, { id: e }), M((t) => t.filter((t) => t.id !== e));
264
+ }, [b]),
253
265
  createWarehouse: J,
254
266
  updateWarehouse: n(async (e, n) => {
255
- let r = w((await t(C, v, {
267
+ let r = D((await t(b, v, {
256
268
  id: e,
257
269
  input: {
258
270
  code: n.code,
@@ -266,15 +278,15 @@ function D(e = {}) {
266
278
  }
267
279
  })).updateWarehouse);
268
280
  return P((t) => t.map((t) => t.id === e ? r : t)), r;
269
- }, [C]),
281
+ }, [b]),
270
282
  deleteWarehouse: n(async (e) => {
271
- await t(C, _, { id: e }), P((t) => t.filter((t) => t.id !== e));
272
- }, [C])
283
+ await t(b, _, { id: e }), P((t) => t.filter((t) => t.id !== e));
284
+ }, [b])
273
285
  };
274
286
  }
275
- function O(e = {}) {
276
- let { limit: i = 20, offset: o = 0, search: c, category: l } = e, u = E(), [d, f] = a([]), [p, m] = a(0), [h, g] = a(!1), [_, v] = a(!1), [y, b] = a(!1), [x, C] = a(null), w = n(async () => {
277
- v(!0), C(null);
287
+ function j(e = {}) {
288
+ let { limit: i = 20, offset: o = 0, search: c, category: l } = e, u = k(), [d, f] = a([]), [p, m] = a(0), [h, g] = a(!1), [_, v] = a(!1), [y, b] = a(!1), [x, S] = a(null), C = n(async () => {
289
+ v(!0), S(null);
278
290
  try {
279
291
  let e = await t(u, s, {
280
292
  filter: {
@@ -286,9 +298,9 @@ function O(e = {}) {
286
298
  offset: o
287
299
  }
288
300
  });
289
- g(o + e.cargoItems.length < e.cargoItemsCount), m(e.cargoItemsCount), f(e.cargoItems.map(S));
301
+ g(o + e.cargoItems.length < e.cargoItemsCount), m(e.cargoItemsCount), f(e.cargoItems.map(T));
290
302
  } catch (e) {
291
- C(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load products"));
303
+ S(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load products"));
292
304
  } finally {
293
305
  v(!1);
294
306
  }
@@ -298,10 +310,10 @@ function O(e = {}) {
298
310
  o,
299
311
  c,
300
312
  l
301
- ]), T = n(async () => {
313
+ ]), w = n(async () => {
302
314
  if (!h || _ || y) return;
303
315
  let e = o + d.length;
304
- b(!0), C(null);
316
+ b(!0), S(null);
305
317
  try {
306
318
  let n = await t(u, s, {
307
319
  filter: {
@@ -312,13 +324,13 @@ function O(e = {}) {
312
324
  limit: i,
313
325
  offset: e
314
326
  }
315
- }), r = n.cargoItems.map(S);
327
+ }), r = n.cargoItems.map(T);
316
328
  m(n.cargoItemsCount), g(e + r.length < n.cargoItemsCount), f((e) => {
317
329
  let t = new Set(e.map((e) => e.id));
318
330
  return [...e, ...r.filter((e) => !t.has(e.id))];
319
331
  });
320
332
  } catch (e) {
321
- C(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load more products"));
333
+ S(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load more products"));
322
334
  } finally {
323
335
  b(!1);
324
336
  }
@@ -334,21 +346,21 @@ function O(e = {}) {
334
346
  c
335
347
  ]);
336
348
  return r(() => {
337
- w();
338
- }, [w]), {
349
+ C();
350
+ }, [C]), {
339
351
  products: d,
340
352
  totalProducts: p,
341
353
  hasMore: h,
342
354
  isLoading: _,
343
355
  isLoadingMore: y,
344
356
  error: x,
345
- refetch: () => void w(),
346
- loadMore: T
357
+ refetch: () => void C(),
358
+ loadMore: w
347
359
  };
348
360
  }
349
- var k = "\n query CargoItemStats {\n cargoItemStats {\n total\n specialHandling\n temperatureControlled\n }\n }\n";
350
- function A() {
351
- let e = E(), [n, i] = a({
361
+ var M = "\n query CargoItemStats {\n cargoItemStats {\n total\n specialHandling\n temperatureControlled\n }\n }\n";
362
+ function N() {
363
+ let e = k(), [n, i] = a({
352
364
  total: 0,
353
365
  specialHandling: 0,
354
366
  temperatureControlled: 0
@@ -357,7 +369,7 @@ function A() {
357
369
  (async () => {
358
370
  s(!0), l(null);
359
371
  try {
360
- i((await t(e, k)).cargoItemStats);
372
+ i((await t(e, M)).cargoItemStats);
361
373
  } catch (e) {
362
374
  l(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load product stats"));
363
375
  } finally {
@@ -370,8 +382,8 @@ function A() {
370
382
  error: c
371
383
  };
372
384
  }
373
- function j(e) {
374
- let i = E(), [o, s] = a(null), [c, u] = a(!1), [d, f] = a(null), p = n(async () => {
385
+ function P(e) {
386
+ let i = k(), [o, s] = a(null), [c, u] = a(!1), [d, f] = a(null), p = n(async () => {
375
387
  if (!e) {
376
388
  s(null);
377
389
  return;
@@ -379,7 +391,7 @@ function j(e) {
379
391
  u(!0), f(null);
380
392
  try {
381
393
  let n = await t(i, l, { id: e });
382
- s(n.cargoItem ? S(n.cargoItem) : null);
394
+ s(n.cargoItem ? T(n.cargoItem) : null);
383
395
  } catch (e) {
384
396
  f(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load product"));
385
397
  } finally {
@@ -395,9 +407,9 @@ function j(e) {
395
407
  refetch: () => void p()
396
408
  };
397
409
  }
398
- function M(e = {}) {
399
- let { limit: i = 20, offset: o = 0, search: s, status: l } = e, u = E(), [d, f] = a([]), [p, m] = a(0), [h, g] = a(!1), [_, v] = a(!1), [y, b] = a(null), x = n(async () => {
400
- v(!0), b(null);
410
+ function F(e = {}) {
411
+ let { limit: i = 20, offset: o = 0, search: s, status: l } = e, u = k(), [d, f] = a([]), [p, m] = a(0), [h, g] = a(!1), [_, v] = a(!1), [y, b] = a(!1), [x, S] = a(null), C = n(async () => {
412
+ v(!0), S(null);
401
413
  try {
402
414
  let e = await t(u, c, {
403
415
  filter: {
@@ -409,9 +421,9 @@ function M(e = {}) {
409
421
  offset: o
410
422
  }
411
423
  });
412
- m(e.warehousesCount), g(o + e.warehouses.length < e.warehousesCount), f(e.warehouses.map(w));
424
+ m(e.warehousesCount), g(o + e.warehouses.length < e.warehousesCount), f(e.warehouses.map(D));
413
425
  } catch (e) {
414
- b(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load warehouses"));
426
+ S(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load warehouses"));
415
427
  } finally {
416
428
  v(!1);
417
429
  }
@@ -421,21 +433,57 @@ function M(e = {}) {
421
433
  o,
422
434
  s,
423
435
  l
436
+ ]), w = n(async () => {
437
+ if (!h || _ || y) return;
438
+ let e = o + d.length;
439
+ b(!0), S(null);
440
+ try {
441
+ let n = await t(u, c, {
442
+ filter: {
443
+ search: s || void 0,
444
+ status: l || void 0
445
+ },
446
+ pagination: {
447
+ limit: i,
448
+ offset: e
449
+ }
450
+ }), r = n.warehouses.map(D);
451
+ m(n.warehousesCount), g(e + r.length < n.warehousesCount), f((e) => {
452
+ let t = new Set(e.map((e) => e.id));
453
+ return [...e, ...r.filter((e) => !t.has(e.id))];
454
+ });
455
+ } catch (e) {
456
+ S(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load more warehouses"));
457
+ } finally {
458
+ b(!1);
459
+ }
460
+ }, [
461
+ u,
462
+ h,
463
+ _,
464
+ y,
465
+ i,
466
+ o,
467
+ s,
468
+ l,
469
+ d.length
424
470
  ]);
425
471
  return r(() => {
426
- x();
427
- }, [x]), {
472
+ C();
473
+ }, [C]), {
428
474
  warehouses: d,
429
475
  totalWarehouses: p,
430
476
  hasMore: h,
431
477
  isLoading: _,
432
- error: y,
433
- refetch: () => void x()
478
+ isLoadingMore: y,
479
+ error: x,
480
+ refetch: () => void C(),
481
+ loadMore: w
434
482
  };
435
483
  }
436
- var N = "\n query WarehouseStats {\n warehouseStats {\n total\n active\n avgUtilization\n }\n }\n";
437
- function P() {
438
- let e = E(), [n, i] = a({
484
+ var I = "\n query WarehouseStats {\n warehouseStats {\n total\n active\n avgUtilization\n }\n }\n";
485
+ function L() {
486
+ let e = k(), [n, i] = a({
439
487
  total: 0,
440
488
  active: 0,
441
489
  avgUtilization: 0
@@ -444,7 +492,7 @@ function P() {
444
492
  (async () => {
445
493
  s(!0), l(null);
446
494
  try {
447
- i((await t(e, N)).warehouseStats);
495
+ i((await t(e, I)).warehouseStats);
448
496
  } catch (e) {
449
497
  l(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load warehouse stats"));
450
498
  } finally {
@@ -457,8 +505,8 @@ function P() {
457
505
  error: c
458
506
  };
459
507
  }
460
- function F(e) {
461
- let i = E(), [o, s] = a(null), [c, l] = a(!1), [d, f] = a(null), p = n(async () => {
508
+ function R(e) {
509
+ let i = k(), [o, s] = a(null), [c, l] = a(!1), [d, f] = a(null), p = n(async () => {
462
510
  if (!e) {
463
511
  s(null);
464
512
  return;
@@ -466,7 +514,7 @@ function F(e) {
466
514
  l(!0), f(null);
467
515
  try {
468
516
  let n = await t(i, u, { id: e });
469
- s(n.warehouse ? w(n.warehouse) : null);
517
+ s(n.warehouse ? D(n.warehouse) : null);
470
518
  } catch (e) {
471
519
  f(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load warehouse"));
472
520
  } finally {
@@ -483,8 +531,8 @@ function F(e) {
483
531
  reload: p
484
532
  };
485
533
  }
486
- function I() {
487
- let e = E(), [n, i] = a({
534
+ function z() {
535
+ let e = k(), [i, o] = a({
488
536
  totalOnHand: 0,
489
537
  totalAvailable: 0,
490
538
  totalAllocated: 0,
@@ -492,43 +540,46 @@ function I() {
492
540
  lowStockCount: 0,
493
541
  totalProducts: 0,
494
542
  totalWarehouses: 0
495
- }), [o, s] = a(!1), [c, l] = a(null);
543
+ }), [s, c] = a(!1), [l, u] = a(null), f = n(async () => {
544
+ c(!0), u(null);
545
+ try {
546
+ let n = await t(e, d);
547
+ o({
548
+ totalOnHand: n.inventoryStats.totalOnHand,
549
+ totalAvailable: n.inventoryStats.totalAvailable,
550
+ totalAllocated: n.inventoryStats.totalAllocated,
551
+ totalDamaged: n.inventoryStats.totalDamaged,
552
+ lowStockCount: n.inventoryStats.lowStockCount,
553
+ totalProducts: n.cargoItemsCount,
554
+ totalWarehouses: n.warehousesCount
555
+ });
556
+ } catch (e) {
557
+ u(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load inventory stats"));
558
+ } finally {
559
+ c(!1);
560
+ }
561
+ }, [e]);
496
562
  return r(() => {
497
- (async () => {
498
- s(!0), l(null);
499
- try {
500
- let n = await t(e, d);
501
- i({
502
- totalOnHand: n.inventoryStats.totalOnHand,
503
- totalAvailable: n.inventoryStats.totalAvailable,
504
- totalAllocated: n.inventoryStats.totalAllocated,
505
- totalDamaged: n.inventoryStats.totalDamaged,
506
- lowStockCount: n.inventoryStats.lowStockCount,
507
- totalProducts: n.cargoItemsCount,
508
- totalWarehouses: n.warehousesCount
509
- });
510
- } catch (e) {
511
- l(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load inventory stats"));
512
- } finally {
513
- s(!1);
514
- }
515
- })();
516
- }, [e]), {
517
- stats: n,
518
- isLoading: o,
519
- error: c
563
+ f();
564
+ }, [f]), {
565
+ stats: i,
566
+ isLoading: s,
567
+ error: l,
568
+ refetch: n(() => {
569
+ f();
570
+ }, [f])
520
571
  };
521
572
  }
522
- var L = "\n query GetCargoItemStockLevels($cargoItemId: ID!, $pagination: PaginationInput) {\n inventoryItems(filter: { cargoItemId: $cargoItemId }, pagination: $pagination) {\n id\n onHand\n available\n allocated\n damaged\n reorderPoint\n warehouse {\n id\n name\n code\n }\n }\n inventoryItemsCount(filter: { cargoItemId: $cargoItemId })\n inventoryStats(filter: { cargoItemId: $cargoItemId }) {\n totalAvailable\n }\n }\n";
523
- function R(e, i = {}) {
524
- let { limit: o = 20, offset: s = 0 } = i, c = E(), [l, u] = a([]), [d, f] = a(0), [p, m] = a(0), [h, g] = a(!1), [_, v] = a(null), y = n(async () => {
573
+ var B = "\n query GetCargoItemStockLevels($cargoItemId: ID!, $pagination: PaginationInput) {\n inventoryItems(filter: { cargoItemId: $cargoItemId }, pagination: $pagination) {\n id\n onHand\n available\n allocated\n damaged\n reorderPoint\n warehouse {\n id\n name\n code\n }\n }\n inventoryItemsCount(filter: { cargoItemId: $cargoItemId })\n inventoryStats(filter: { cargoItemId: $cargoItemId }) {\n totalAvailable\n }\n }\n";
574
+ function V(e, i = {}) {
575
+ let { limit: o = 20, offset: s = 0 } = i, c = k(), [l, u] = a([]), [d, f] = a(0), [p, m] = a(0), [h, g] = a(!1), [_, v] = a(null), y = n(async () => {
525
576
  if (!e) {
526
577
  u([]), f(0), m(0);
527
578
  return;
528
579
  }
529
580
  g(!0), v(null);
530
581
  try {
531
- let n = await t(c, L, {
582
+ let n = await t(c, B, {
532
583
  cargoItemId: e,
533
584
  pagination: {
534
585
  limit: o,
@@ -573,22 +624,22 @@ function R(e, i = {}) {
573
624
  refetch: b
574
625
  };
575
626
  }
576
- var z = [
627
+ var H = [
577
628
  "RECEIPT",
578
629
  "ISSUE",
579
630
  "TRANSFER",
580
631
  "ADJUSTMENT",
581
632
  "RETURN"
582
633
  ];
583
- function B(e) {
634
+ function U(e) {
584
635
  let t = e.toUpperCase();
585
- return z.find((e) => e === t) ?? "ADJUSTMENT";
636
+ return H.find((e) => e === t) ?? "ADJUSTMENT";
586
637
  }
587
- function V(e) {
638
+ function W(e) {
588
639
  return {
589
640
  id: e.id,
590
641
  transactionNumber: e.transactionNumber,
591
- type: B(e.type),
642
+ type: U(e.type),
592
643
  quantity: e.quantity,
593
644
  productId: e.cargoItemId,
594
645
  warehouseId: e.warehouseId,
@@ -598,8 +649,8 @@ function V(e) {
598
649
  createdAt: new Date(e.createdAt)
599
650
  };
600
651
  }
601
- function H(e = {}) {
602
- let { limit: i = 10, productId: o, warehouseId: s } = e, c = E(), [l, u] = a([]), [d, p] = a(!1), [m, h] = a(null), g = n(async () => {
652
+ function G(e = {}) {
653
+ let { limit: i = 10, productId: o, warehouseId: s } = e, c = k(), [l, u] = a([]), [d, p] = a(!1), [m, h] = a(null), g = n(async () => {
603
654
  p(!0), h(null);
604
655
  try {
605
656
  u((await t(c, f, {
@@ -611,7 +662,7 @@ function H(e = {}) {
611
662
  limit: i,
612
663
  offset: 0
613
664
  }
614
- })).inventoryTransactions.map(V));
665
+ })).inventoryTransactions.map(W));
615
666
  } catch (e) {
616
667
  h(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load inventory transactions"));
617
668
  } finally {
@@ -634,5 +685,78 @@ function H(e = {}) {
634
685
  }, [g])
635
686
  };
636
687
  }
688
+ function K(e, t) {
689
+ if (!Number.isInteger(e) || e <= 0) throw Error(`${t} must be a positive whole number.`);
690
+ }
691
+ function q() {
692
+ let e = k(), r = n(async (n) => {
693
+ let r = (await t(e, b, {
694
+ filter: n,
695
+ pagination: { limit: 1 }
696
+ })).inventoryItems[0];
697
+ return r ? O(r) : null;
698
+ }, [e]), i = n(async (n, r) => {
699
+ let i = n.quantity + r, a = n.availableQuantity + r;
700
+ if (a < 0) throw Error(`Only ${n.availableQuantity.toLocaleString()} unit(s) are available to remove.`);
701
+ if (i < 0) throw Error("On-hand stock cannot go below zero.");
702
+ return O((await t(e, S, { input: {
703
+ id: n.id,
704
+ onHand: i,
705
+ available: a,
706
+ allocated: n.reservedQuantity,
707
+ damaged: n.damagedQuantity
708
+ } })).adjustInventoryStock);
709
+ }, [e]), a = n(async (e, t) => {
710
+ if (!Number.isInteger(t) || t === 0) throw Error("Enter a whole-number change other than zero.");
711
+ let n = await r({ inventoryItemId: e });
712
+ if (!n) throw Error("This stock line no longer exists.");
713
+ return i(n, t);
714
+ }, [i, r]);
715
+ return {
716
+ receiveStock: n(async (n) => {
717
+ K(n.quantity, "Quantity received");
718
+ let a = await r({
719
+ cargoItemId: n.productId,
720
+ warehouseId: n.warehouseId
721
+ });
722
+ return a ? i(a, n.quantity) : O((await t(e, x, { input: {
723
+ cargoItemId: n.productId,
724
+ warehouseId: n.warehouseId,
725
+ onHand: n.quantity,
726
+ available: n.quantity,
727
+ ...n.reorderPoint !== null && n.reorderPoint !== void 0 ? { reorderPoint: n.reorderPoint } : {}
728
+ } })).createInventoryItem);
729
+ }, [
730
+ i,
731
+ r,
732
+ e
733
+ ]),
734
+ adjustStock: a,
735
+ transferStock: n(async (n) => {
736
+ K(n.quantity, "Transfer quantity");
737
+ let i = await r({ inventoryItemId: n.sourceInventoryId });
738
+ if (!i) throw Error("The source stock line no longer exists.");
739
+ if (i.warehouseId === n.destinationWarehouseId) throw Error("Source and destination warehouses must be different.");
740
+ if (n.quantity > i.availableQuantity) throw Error(`Only ${i.availableQuantity.toLocaleString()} unit(s) are available to transfer.`);
741
+ let a = await r({
742
+ cargoItemId: i.productId,
743
+ warehouseId: n.destinationWarehouseId
744
+ });
745
+ a ||= O((await t(e, x, { input: {
746
+ cargoItemId: i.productId,
747
+ warehouseId: n.destinationWarehouseId
748
+ } })).createInventoryItem);
749
+ let o = await t(e, C, { input: {
750
+ sourceInventoryItemId: i.id,
751
+ destinationInventoryItemId: a.id,
752
+ quantity: n.quantity
753
+ } });
754
+ return {
755
+ source: O(o.transferInventoryStock.source),
756
+ destination: O(o.transferInventoryStock.destination)
757
+ };
758
+ }, [r, e])
759
+ };
760
+ }
637
761
  //#endregion
638
- export { D as useInventory, I as useInventoryStats, H as useInventoryTransactions, j as useProduct, A as useProductStats, R as useProductStockLevels, O as useProducts, F as useWarehouse, P as useWarehouseStats, M as useWarehouses };
762
+ export { A as useInventory, z as useInventoryStats, G as useInventoryTransactions, P as useProduct, N as useProductStats, V as useProductStockLevels, j as useProducts, q as useStockActions, R as useWarehouse, L as useWarehouseStats, F as useWarehouses };