@classytic/commerce-sdk 0.1.0

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.

Potentially problematic release.


This version of @classytic/commerce-sdk might be problematic. Click here for more details.

Files changed (131) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +104 -0
  3. package/dist/adjustment-DTSLM7AN.js +5 -0
  4. package/dist/adjustment-DTSLM7AN.js.map +1 -0
  5. package/dist/analytics/index.d.ts +27 -0
  6. package/dist/analytics/index.js +6 -0
  7. package/dist/analytics/index.js.map +1 -0
  8. package/dist/analytics-DMcD-o8w.d.ts +76 -0
  9. package/dist/api-factory-B_h4RKBm.d.ts +280 -0
  10. package/dist/auth/index.d.ts +39 -0
  11. package/dist/auth/index.js +5 -0
  12. package/dist/auth/index.js.map +1 -0
  13. package/dist/catalog/index.d.ts +479 -0
  14. package/dist/catalog/index.js +9 -0
  15. package/dist/catalog/index.js.map +1 -0
  16. package/dist/chunk-4ZQK3FFN.js +40 -0
  17. package/dist/chunk-4ZQK3FFN.js.map +1 -0
  18. package/dist/chunk-5L6EXDGH.js +465 -0
  19. package/dist/chunk-5L6EXDGH.js.map +1 -0
  20. package/dist/chunk-5ZFW3FEI.js +183 -0
  21. package/dist/chunk-5ZFW3FEI.js.map +1 -0
  22. package/dist/chunk-66OQAZSL.js +94 -0
  23. package/dist/chunk-66OQAZSL.js.map +1 -0
  24. package/dist/chunk-6RYGA6MF.js +123 -0
  25. package/dist/chunk-6RYGA6MF.js.map +1 -0
  26. package/dist/chunk-B6MPVOV7.js +328 -0
  27. package/dist/chunk-B6MPVOV7.js.map +1 -0
  28. package/dist/chunk-BDA2WSJA.js +148 -0
  29. package/dist/chunk-BDA2WSJA.js.map +1 -0
  30. package/dist/chunk-EIVYT3HM.js +126 -0
  31. package/dist/chunk-EIVYT3HM.js.map +1 -0
  32. package/dist/chunk-EPQN7ZKZ.js +27 -0
  33. package/dist/chunk-EPQN7ZKZ.js.map +1 -0
  34. package/dist/chunk-FA7QFJ2G.js +177 -0
  35. package/dist/chunk-FA7QFJ2G.js.map +1 -0
  36. package/dist/chunk-I5TIKUIQ.js +261 -0
  37. package/dist/chunk-I5TIKUIQ.js.map +1 -0
  38. package/dist/chunk-ILQUH444.js +135 -0
  39. package/dist/chunk-ILQUH444.js.map +1 -0
  40. package/dist/chunk-IXMWZJLV.js +616 -0
  41. package/dist/chunk-IXMWZJLV.js.map +1 -0
  42. package/dist/chunk-KZIGRIQG.js +75 -0
  43. package/dist/chunk-KZIGRIQG.js.map +1 -0
  44. package/dist/chunk-OF5M6R2S.js +769 -0
  45. package/dist/chunk-OF5M6R2S.js.map +1 -0
  46. package/dist/chunk-PYYLHUV6.js +3 -0
  47. package/dist/chunk-PYYLHUV6.js.map +1 -0
  48. package/dist/chunk-QO5AGZFP.js +159 -0
  49. package/dist/chunk-QO5AGZFP.js.map +1 -0
  50. package/dist/chunk-QUMTBLNE.js +76 -0
  51. package/dist/chunk-QUMTBLNE.js.map +1 -0
  52. package/dist/chunk-R5Z7NYLH.js +126 -0
  53. package/dist/chunk-R5Z7NYLH.js.map +1 -0
  54. package/dist/chunk-SZYWG5IB.js +75 -0
  55. package/dist/chunk-SZYWG5IB.js.map +1 -0
  56. package/dist/chunk-U3XT35GZ.js +202 -0
  57. package/dist/chunk-U3XT35GZ.js.map +1 -0
  58. package/dist/chunk-UGELTUIZ.js +830 -0
  59. package/dist/chunk-UGELTUIZ.js.map +1 -0
  60. package/dist/chunk-VR36QVX2.js +122 -0
  61. package/dist/chunk-VR36QVX2.js.map +1 -0
  62. package/dist/chunk-WUOQK7BO.js +13 -0
  63. package/dist/chunk-WUOQK7BO.js.map +1 -0
  64. package/dist/chunk-X6PV5MHG.js +582 -0
  65. package/dist/chunk-X6PV5MHG.js.map +1 -0
  66. package/dist/chunk-ZWLMFLLH.js +534 -0
  67. package/dist/chunk-ZWLMFLLH.js.map +1 -0
  68. package/dist/content/index.d.ts +309 -0
  69. package/dist/content/index.js +6 -0
  70. package/dist/content/index.js.map +1 -0
  71. package/dist/core/index.d.ts +107 -0
  72. package/dist/core/index.js +5 -0
  73. package/dist/core/index.js.map +1 -0
  74. package/dist/core/react.d.ts +107 -0
  75. package/dist/core/react.js +5 -0
  76. package/dist/core/react.js.map +1 -0
  77. package/dist/coupon-CHFcw7cd.d.ts +632 -0
  78. package/dist/coupon-zGkvO-Xx.d.ts +129 -0
  79. package/dist/crud.factory-DyKaPHcU.d.ts +181 -0
  80. package/dist/finance/index.d.ts +81 -0
  81. package/dist/finance/index.js +5 -0
  82. package/dist/finance/index.js.map +1 -0
  83. package/dist/finance-BJdfKRw0.d.ts +135 -0
  84. package/dist/index.d.ts +31 -0
  85. package/dist/index.js +29 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/inventory/index.d.ts +512 -0
  88. package/dist/inventory/index.js +16 -0
  89. package/dist/inventory/index.js.map +1 -0
  90. package/dist/inventory-DCiIZh8P.d.ts +742 -0
  91. package/dist/logistics/index.d.ts +226 -0
  92. package/dist/logistics/index.js +7 -0
  93. package/dist/logistics/index.js.map +1 -0
  94. package/dist/logistics-V8a9lUN3.d.ts +428 -0
  95. package/dist/media-CNLJK93J.d.ts +721 -0
  96. package/dist/movement-7MV3ADY5.js +5 -0
  97. package/dist/movement-7MV3ADY5.js.map +1 -0
  98. package/dist/payment-BRboLqvU.d.ts +127 -0
  99. package/dist/payments/index.d.ts +55 -0
  100. package/dist/payments/index.js +6 -0
  101. package/dist/payments/index.js.map +1 -0
  102. package/dist/platform/index.d.ts +645 -0
  103. package/dist/platform/index.js +8 -0
  104. package/dist/platform/index.js.map +1 -0
  105. package/dist/pos-D1jkkFl0.d.ts +885 -0
  106. package/dist/product-p09zXkXB.d.ts +260 -0
  107. package/dist/purchase-24BGT2HA.js +5 -0
  108. package/dist/purchase-24BGT2HA.js.map +1 -0
  109. package/dist/request-652PS6VR.js +5 -0
  110. package/dist/request-652PS6VR.js.map +1 -0
  111. package/dist/sales/index.d.ts +585 -0
  112. package/dist/sales/index.js +9 -0
  113. package/dist/sales/index.js.map +1 -0
  114. package/dist/server.d.ts +120 -0
  115. package/dist/server.js +27 -0
  116. package/dist/server.js.map +1 -0
  117. package/dist/size-guide-DgjzjM5P.d.ts +554 -0
  118. package/dist/stock-DEApGC-w.d.ts +632 -0
  119. package/dist/stock-OOUW57VQ.js +5 -0
  120. package/dist/stock-OOUW57VQ.js.map +1 -0
  121. package/dist/supplier-OC6JAWV6.js +5 -0
  122. package/dist/supplier-OC6JAWV6.js.map +1 -0
  123. package/dist/transaction/index.d.ts +104 -0
  124. package/dist/transaction/index.js +8 -0
  125. package/dist/transaction/index.js.map +1 -0
  126. package/dist/transaction-BTmoHpWh.d.ts +428 -0
  127. package/dist/transaction-u5oaNuav.d.ts +84 -0
  128. package/dist/transfer-7SYSH3RG.js +5 -0
  129. package/dist/transfer-7SYSH3RG.js.map +1 -0
  130. package/dist/user-data-DdLjAGwO.d.ts +132 -0
  131. package/package.json +146 -0
@@ -0,0 +1,616 @@
1
+ import { purchaseApi } from './chunk-6RYGA6MF.js';
2
+ import { transferApi } from './chunk-FA7QFJ2G.js';
3
+ import { requestApi } from './chunk-QO5AGZFP.js';
4
+ import { movementApi } from './chunk-SZYWG5IB.js';
5
+ import { adjustmentApi } from './chunk-R5Z7NYLH.js';
6
+ import { supplierApi } from './chunk-WUOQK7BO.js';
7
+ import { stockApi } from './chunk-KZIGRIQG.js';
8
+ import { posApi } from './chunk-66OQAZSL.js';
9
+ import { createCrudHooks } from './chunk-B6MPVOV7.js';
10
+ import { getToastHandler } from './chunk-U3XT35GZ.js';
11
+ import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
12
+ import { useMemo } from 'react';
13
+
14
+ // src/inventory/api/index.ts
15
+ var inventoryApis = {
16
+ stock: () => import('./stock-OOUW57VQ.js').then((m) => m.stockApi),
17
+ purchase: () => import('./purchase-24BGT2HA.js').then((m) => m.purchaseApi),
18
+ transfer: () => import('./transfer-7SYSH3RG.js').then((m) => m.transferApi),
19
+ request: () => import('./request-652PS6VR.js').then((m) => m.requestApi),
20
+ movement: () => import('./movement-7MV3ADY5.js').then((m) => m.movementApi),
21
+ adjustment: () => import('./adjustment-DTSLM7AN.js').then((m) => m.adjustmentApi),
22
+ supplier: () => import('./supplier-OC6JAWV6.js').then((m) => m.supplierApi)
23
+ };
24
+ var INVENTORY_KEYS = {
25
+ all: ["inventory"],
26
+ products: (branchId) => [...INVENTORY_KEYS.all, "products", branchId],
27
+ productsList: (branchId, params) => [...INVENTORY_KEYS.products(branchId), params],
28
+ lookup: (code, branchId) => [...INVENTORY_KEYS.all, "lookup", code, branchId]
29
+ };
30
+ function useInventory(token, branchId, filters = {}, options = {}) {
31
+ const queryKey = INVENTORY_KEYS.productsList(branchId, filters);
32
+ const { data, isLoading, isFetching, error, refetch } = useQuery({
33
+ queryKey,
34
+ queryFn: () => posApi.getProducts({
35
+ token,
36
+ branchId,
37
+ category: filters.category,
38
+ search: filters.search,
39
+ inStockOnly: filters.inStockOnly,
40
+ lowStockOnly: filters.lowStockOnly,
41
+ after: filters.after,
42
+ limit: filters.limit || 50,
43
+ sort: filters.sort || "name"
44
+ }),
45
+ enabled: !!token && options.enabled !== false,
46
+ staleTime: 30 * 1e3,
47
+ // 30 seconds - inventory changes frequently
48
+ refetchOnWindowFocus: true
49
+ });
50
+ return {
51
+ items: data?.docs || [],
52
+ summary: data?.summary || { totalItems: 0, totalQuantity: 0, lowStockCount: 0, outOfStockCount: 0 },
53
+ branch: data?.branch || { _id: "", code: "", name: "" },
54
+ hasMore: data?.hasMore || false,
55
+ nextCursor: data?.next || null,
56
+ isLoading,
57
+ isFetching,
58
+ error,
59
+ refetch
60
+ };
61
+ }
62
+ function useInventoryLookup(token, code, branchId, options = {}) {
63
+ return useQuery({
64
+ queryKey: INVENTORY_KEYS.lookup(code, branchId),
65
+ queryFn: () => posApi.lookup({ token, code, branchId }),
66
+ enabled: !!token && !!code && code.length >= 2 && options.enabled !== false,
67
+ staleTime: 10 * 1e3,
68
+ // 10 seconds
69
+ retry: false
70
+ });
71
+ }
72
+ function useStockActions(token) {
73
+ const queryClient = useQueryClient();
74
+ const toast = getToastHandler();
75
+ const invalidateStockQueries = (branchId) => {
76
+ queryClient.invalidateQueries({
77
+ queryKey: INVENTORY_KEYS.products(branchId)
78
+ });
79
+ queryClient.invalidateQueries({
80
+ queryKey: ["pos", "products", branchId]
81
+ });
82
+ };
83
+ const adjustMutation = useMutation({
84
+ mutationFn: (data) => adjustmentApi.create({ token, data }),
85
+ onSuccess: (_, variables) => {
86
+ invalidateStockQueries(variables.branchId);
87
+ toast.success("Stock adjusted successfully");
88
+ },
89
+ onError: (error) => {
90
+ toast.error(error.message || "Failed to adjust stock");
91
+ }
92
+ });
93
+ const setStockMutation = useMutation({
94
+ mutationFn: ({
95
+ productId,
96
+ quantity,
97
+ branchId,
98
+ variantSku,
99
+ notes
100
+ }) => adjustmentApi.create({
101
+ token,
102
+ data: {
103
+ productId,
104
+ quantity,
105
+ branchId,
106
+ variantSku,
107
+ mode: "set",
108
+ notes
109
+ }
110
+ }),
111
+ onSuccess: (_, variables) => {
112
+ invalidateStockQueries(variables.branchId);
113
+ toast.success("Stock level updated");
114
+ },
115
+ onError: (error) => {
116
+ toast.error(error.message || "Failed to update stock");
117
+ }
118
+ });
119
+ const bulkAdjustMutation = useMutation({
120
+ mutationFn: (data) => adjustmentApi.create({
121
+ token,
122
+ data: {
123
+ adjustments: data.adjustments,
124
+ branchId: data.branchId,
125
+ reason: data.reason
126
+ }
127
+ }),
128
+ onSuccess: (_, variables) => {
129
+ invalidateStockQueries(variables.branchId);
130
+ toast.success("Bulk adjustment completed");
131
+ },
132
+ onError: (error) => {
133
+ toast.error(error.message || "Failed to bulk adjust stock");
134
+ }
135
+ });
136
+ return {
137
+ // Adjust stock (add/remove/set)
138
+ adjust: adjustMutation.mutateAsync,
139
+ isAdjusting: adjustMutation.isPending,
140
+ // Set stock directly
141
+ setStock: setStockMutation.mutateAsync,
142
+ isSettingStock: setStockMutation.isPending,
143
+ // Bulk operations
144
+ bulkAdjust: bulkAdjustMutation.mutateAsync,
145
+ isBulkAdjusting: bulkAdjustMutation.isPending,
146
+ // Combined loading state
147
+ isLoading: adjustMutation.isPending || setStockMutation.isPending || bulkAdjustMutation.isPending
148
+ };
149
+ }
150
+ function getStockStatus(quantity, lowThreshold = 10) {
151
+ if (quantity === 0) return "out";
152
+ if (quantity <= lowThreshold) return "low";
153
+ return "ok";
154
+ }
155
+ function getStockStatusBadge(status) {
156
+ switch (status) {
157
+ case "out":
158
+ return { variant: "destructive", label: "Out of Stock" };
159
+ case "low":
160
+ return { variant: "warning", label: "Low Stock" };
161
+ case "ok":
162
+ return { variant: "success", label: "In Stock" };
163
+ }
164
+ }
165
+
166
+ // src/inventory/hooks/stock.ts
167
+ var stockHooks = createCrudHooks({
168
+ api: stockApi,
169
+ entityKey: "stock",
170
+ singular: "Stock Entry",
171
+ plural: "Stock Entries",
172
+ defaults: {
173
+ staleTime: 2 * 60 * 1e3
174
+ // 2 minutes
175
+ }
176
+ });
177
+ var {
178
+ KEYS: STOCK_KEYS,
179
+ useList: useStock,
180
+ useDetail: useStockDetail,
181
+ useActions: useStockActions2,
182
+ useNavigation: useStockNavigation
183
+ } = stockHooks;
184
+ var purchaseHooks = createCrudHooks({
185
+ api: purchaseApi,
186
+ entityKey: "purchases",
187
+ singular: "Purchase",
188
+ plural: "Purchases"
189
+ });
190
+ var {
191
+ KEYS: PURCHASE_KEYS,
192
+ useList: usePurchases,
193
+ useDetail: usePurchaseDetail,
194
+ useActions: usePurchaseActions,
195
+ useNavigation: usePurchaseNavigation
196
+ } = purchaseHooks;
197
+ function usePurchaseStateActions(token) {
198
+ const queryClient = useQueryClient();
199
+ const toast = getToastHandler();
200
+ const invalidateAll = () => {
201
+ queryClient.invalidateQueries({ queryKey: PURCHASE_KEYS.all });
202
+ queryClient.invalidateQueries({ queryKey: ["inventory"] });
203
+ queryClient.invalidateQueries({ queryKey: ["stock"] });
204
+ };
205
+ const receive = useMutation({
206
+ mutationFn: async (id) => {
207
+ const response = await purchaseApi.receive({ token, id });
208
+ return response.data;
209
+ },
210
+ onSuccess: () => {
211
+ invalidateAll();
212
+ toast.success("Purchase received - stock added");
213
+ },
214
+ onError: (err) => {
215
+ toast.error(err.message || "Failed to receive purchase");
216
+ }
217
+ });
218
+ const pay = useMutation({
219
+ mutationFn: async ({ id, amount, method, reference }) => {
220
+ const response = await purchaseApi.pay({ token, id, amount, method, reference });
221
+ return response.data;
222
+ },
223
+ onSuccess: () => {
224
+ invalidateAll();
225
+ toast.success("Payment recorded");
226
+ },
227
+ onError: (err) => {
228
+ toast.error(err.message || "Failed to record payment");
229
+ }
230
+ });
231
+ const cancel = useMutation({
232
+ mutationFn: async ({ id, reason }) => {
233
+ const response = await purchaseApi.cancel({ token, id, reason });
234
+ return response.data;
235
+ },
236
+ onSuccess: () => {
237
+ invalidateAll();
238
+ toast.success("Purchase cancelled");
239
+ },
240
+ onError: (err) => {
241
+ toast.error(err.message || "Failed to cancel purchase");
242
+ }
243
+ });
244
+ return {
245
+ receive,
246
+ pay,
247
+ cancel,
248
+ isReceiving: receive.isPending,
249
+ isPaying: pay.isPending,
250
+ isCancelling: cancel.isPending,
251
+ isLoading: receive.isPending || pay.isPending || cancel.isPending
252
+ };
253
+ }
254
+ var transferHooks = createCrudHooks({
255
+ api: transferApi,
256
+ entityKey: "transfers",
257
+ singular: "Transfer",
258
+ plural: "Transfers"
259
+ });
260
+ var {
261
+ KEYS: TRANSFER_KEYS,
262
+ useList: useTransfers,
263
+ useDetail: useTransferDetail,
264
+ useActions: useTransferActions,
265
+ useNavigation: useTransferNavigation
266
+ } = transferHooks;
267
+ function useTransferStateActions(token) {
268
+ const queryClient = useQueryClient();
269
+ const toast = getToastHandler();
270
+ const invalidateAll = () => {
271
+ queryClient.invalidateQueries({ queryKey: TRANSFER_KEYS.all });
272
+ queryClient.invalidateQueries({ queryKey: ["inventory"] });
273
+ queryClient.invalidateQueries({ queryKey: ["stock"] });
274
+ };
275
+ const approveMutation = useMutation({
276
+ mutationFn: async (id) => {
277
+ const response = await transferApi.approve({ token, id });
278
+ return response.data;
279
+ },
280
+ onSuccess: () => {
281
+ invalidateAll();
282
+ toast.success("Transfer approved");
283
+ },
284
+ onError: (err) => {
285
+ toast.error(err.message || "Failed to approve transfer");
286
+ }
287
+ });
288
+ const dispatchMutation = useMutation({
289
+ mutationFn: async ({ id, data }) => {
290
+ const response = await transferApi.dispatch({ token, id, data });
291
+ return response.data;
292
+ },
293
+ onSuccess: () => {
294
+ invalidateAll();
295
+ toast.success("Transfer dispatched - stock deducted");
296
+ },
297
+ onError: (err) => {
298
+ toast.error(err.message || "Failed to dispatch transfer");
299
+ }
300
+ });
301
+ const inTransitMutation = useMutation({
302
+ mutationFn: async (id) => {
303
+ const response = await transferApi.markInTransit({ token, id });
304
+ return response.data;
305
+ },
306
+ onSuccess: () => {
307
+ invalidateAll();
308
+ toast.success("Transfer marked in transit");
309
+ },
310
+ onError: (err) => {
311
+ toast.error(err.message || "Failed to mark transfer in transit");
312
+ }
313
+ });
314
+ const receiveMutation = useMutation({
315
+ mutationFn: async ({ id, data }) => {
316
+ const response = await transferApi.receive({ token, id, data });
317
+ return response.data;
318
+ },
319
+ onSuccess: () => {
320
+ invalidateAll();
321
+ toast.success("Transfer received - stock added");
322
+ },
323
+ onError: (err) => {
324
+ toast.error(err.message || "Failed to receive transfer");
325
+ }
326
+ });
327
+ const cancelMutation = useMutation({
328
+ mutationFn: async ({ id, reason }) => {
329
+ const response = await transferApi.cancel({ token, id, reason });
330
+ return response.data;
331
+ },
332
+ onSuccess: () => {
333
+ invalidateAll();
334
+ toast.success("Transfer cancelled");
335
+ },
336
+ onError: (err) => {
337
+ toast.error(err.message || "Failed to cancel transfer");
338
+ }
339
+ });
340
+ return {
341
+ approve: async (id) => {
342
+ return approveMutation.mutateAsync(id);
343
+ },
344
+ isApproving: approveMutation.isPending,
345
+ dispatch: async (params) => {
346
+ return dispatchMutation.mutateAsync(params);
347
+ },
348
+ isDispatching: dispatchMutation.isPending,
349
+ inTransit: async (id) => {
350
+ return inTransitMutation.mutateAsync(id);
351
+ },
352
+ isMarkingInTransit: inTransitMutation.isPending,
353
+ receive: async (params) => {
354
+ return receiveMutation.mutateAsync(params);
355
+ },
356
+ isReceiving: receiveMutation.isPending,
357
+ cancel: async (params) => {
358
+ return cancelMutation.mutateAsync(params);
359
+ },
360
+ isCancelling: cancelMutation.isPending,
361
+ isLoading: approveMutation.isPending || dispatchMutation.isPending || inTransitMutation.isPending || receiveMutation.isPending || cancelMutation.isPending
362
+ };
363
+ }
364
+ var TRANSFER_STATS_KEYS = {
365
+ all: ["transfers", "stats"],
366
+ byBranch: (branchId) => ["transfers", "stats", branchId]
367
+ };
368
+ function useTransferStats(token, branchId, options = {}) {
369
+ return useQuery({
370
+ queryKey: TRANSFER_STATS_KEYS.byBranch(branchId),
371
+ queryFn: () => transferApi.stats({ token, params: branchId ? { branchId } : {} }),
372
+ enabled: !!token && options.enabled !== false,
373
+ staleTime: 30 * 1e3,
374
+ // 30 seconds
375
+ select: (data) => data?.data
376
+ });
377
+ }
378
+
379
+ // src/inventory/hooks/adjustment.ts
380
+ var adjustmentHooks = createCrudHooks({
381
+ api: adjustmentApi,
382
+ entityKey: "adjustments",
383
+ singular: "Adjustment",
384
+ plural: "Adjustments"
385
+ });
386
+ var {
387
+ KEYS: ADJUSTMENT_KEYS,
388
+ useList: useAdjustments,
389
+ useDetail: useAdjustmentDetail,
390
+ useActions: useAdjustmentActions,
391
+ useNavigation: useAdjustmentNavigation
392
+ } = adjustmentHooks;
393
+ var MOVEMENT_KEYS = {
394
+ all: ["inventory", "movements"],
395
+ list: (params) => [...MOVEMENT_KEYS.all, "list", params],
396
+ lowStock: (params) => [...MOVEMENT_KEYS.all, "low-stock", params]
397
+ };
398
+ function useMovements(token, params, options = {}) {
399
+ const { data, isLoading, isFetching, error, refetch } = useQuery({
400
+ queryKey: MOVEMENT_KEYS.list(params),
401
+ queryFn: () => movementApi.list({ token, params }),
402
+ enabled: !!token && options.enabled !== false,
403
+ staleTime: options.staleTime ?? 15 * 1e3
404
+ // 15 seconds
405
+ });
406
+ const movements = useMemo(() => {
407
+ if (!data) return [];
408
+ return data.docs || data.data || [];
409
+ }, [data]);
410
+ const pagination = useMemo(() => {
411
+ if (!data) return null;
412
+ const d = data;
413
+ if (d.page === void 0) return null;
414
+ return {
415
+ page: d.page || 1,
416
+ limit: d.limit || 20,
417
+ total: d.total || 0,
418
+ pages: d.pages || 1,
419
+ hasNext: d.hasNext || false,
420
+ hasPrev: d.hasPrev || false
421
+ };
422
+ }, [data]);
423
+ return {
424
+ movements,
425
+ pagination,
426
+ isLoading,
427
+ isFetching,
428
+ error,
429
+ refetch
430
+ };
431
+ }
432
+ function useLowStock(token, params, options = {}) {
433
+ return useQuery({
434
+ queryKey: MOVEMENT_KEYS.lowStock(params),
435
+ queryFn: () => movementApi.lowStock({ token, params }),
436
+ enabled: !!token && options.enabled !== false,
437
+ staleTime: options.staleTime ?? 60 * 1e3
438
+ // 1 minute
439
+ });
440
+ }
441
+ function getStockChangeInvalidationKeys() {
442
+ return [
443
+ ["inventory"],
444
+ // All inventory product queries
445
+ MOVEMENT_KEYS.all
446
+ // Audit trail (new movements created)
447
+ ];
448
+ }
449
+ var REQUEST_KEYS = {
450
+ all: ["inventory", "requests"],
451
+ list: (params) => [...REQUEST_KEYS.all, "list", params],
452
+ pending: () => [...REQUEST_KEYS.all, "pending"],
453
+ detail: (id) => [...REQUEST_KEYS.all, "detail", id]
454
+ };
455
+ function useStockRequests(token, params, options = {}) {
456
+ const { data, isLoading, isFetching, error, refetch } = useQuery({
457
+ queryKey: REQUEST_KEYS.list(params),
458
+ queryFn: () => requestApi.list({ token, params }),
459
+ enabled: !!token && options.enabled !== false,
460
+ staleTime: options.staleTime ?? 15 * 1e3
461
+ });
462
+ const requests = useMemo(() => {
463
+ if (!data) return [];
464
+ return data.docs || data.data || [];
465
+ }, [data]);
466
+ return {
467
+ requests,
468
+ isLoading,
469
+ isFetching,
470
+ error,
471
+ refetch
472
+ };
473
+ }
474
+ function usePendingStockRequests(token, options = {}) {
475
+ const { data, isLoading, isFetching, error, refetch } = useQuery({
476
+ queryKey: REQUEST_KEYS.pending(),
477
+ queryFn: () => requestApi.listPending({ token }),
478
+ enabled: !!token && options.enabled !== false,
479
+ staleTime: options.staleTime ?? 15 * 1e3
480
+ });
481
+ const requests = useMemo(() => {
482
+ if (!data) return [];
483
+ return data.docs || data.data || [];
484
+ }, [data]);
485
+ return {
486
+ requests,
487
+ isLoading,
488
+ isFetching,
489
+ error,
490
+ refetch
491
+ };
492
+ }
493
+ function useStockRequestDetail(token, id, options = {}) {
494
+ return useQuery({
495
+ queryKey: REQUEST_KEYS.detail(id || ""),
496
+ queryFn: () => requestApi.getById({ token, id }),
497
+ enabled: !!token && !!id && options.enabled !== false,
498
+ staleTime: options.staleTime ?? 30 * 1e3
499
+ });
500
+ }
501
+ function useStockRequestActions(token) {
502
+ const queryClient = useQueryClient();
503
+ const toast = getToastHandler();
504
+ const createMutation = useMutation({
505
+ mutationFn: (data) => requestApi.create({ token, data }),
506
+ onSuccess: () => {
507
+ queryClient.invalidateQueries({ queryKey: REQUEST_KEYS.all });
508
+ toast.success("Stock request created");
509
+ },
510
+ onError: (err) => toast.error(err.message || "Failed to create request")
511
+ });
512
+ const approveMutation = useMutation({
513
+ mutationFn: ({
514
+ id,
515
+ items,
516
+ reviewNotes
517
+ }) => requestApi.approve({ token, id, items, reviewNotes }),
518
+ onSuccess: () => {
519
+ queryClient.invalidateQueries({ queryKey: REQUEST_KEYS.all });
520
+ toast.success("Request approved");
521
+ },
522
+ onError: (err) => toast.error(err.message || "Failed to approve request")
523
+ });
524
+ const rejectMutation = useMutation({
525
+ mutationFn: ({ id, reason }) => requestApi.reject({ token, id, reason }),
526
+ onSuccess: () => {
527
+ queryClient.invalidateQueries({ queryKey: REQUEST_KEYS.all });
528
+ toast.success("Request rejected");
529
+ },
530
+ onError: (err) => toast.error(err.message || "Failed to reject request")
531
+ });
532
+ const fulfillMutation = useMutation({
533
+ mutationFn: ({
534
+ id,
535
+ remarks,
536
+ items,
537
+ transport
538
+ }) => requestApi.fulfill({
539
+ token,
540
+ id,
541
+ remarks,
542
+ items,
543
+ transport,
544
+ documentType: "delivery_challan"
545
+ }),
546
+ onSuccess: () => {
547
+ queryClient.invalidateQueries({ queryKey: REQUEST_KEYS.all });
548
+ queryClient.invalidateQueries({ queryKey: TRANSFER_KEYS.all });
549
+ toast.success("Request fulfilled (transfer created)");
550
+ },
551
+ onError: (err) => toast.error(err.message || "Failed to fulfill request")
552
+ });
553
+ const cancelMutation = useMutation({
554
+ mutationFn: ({ id, reason }) => requestApi.cancel({ token, id, reason }),
555
+ onSuccess: () => {
556
+ queryClient.invalidateQueries({ queryKey: REQUEST_KEYS.all });
557
+ toast.success("Request cancelled");
558
+ },
559
+ onError: (err) => toast.error(err.message || "Failed to cancel request")
560
+ });
561
+ return {
562
+ create: async (data) => {
563
+ const result = await createMutation.mutateAsync(data);
564
+ return result.data;
565
+ },
566
+ isCreating: createMutation.isPending,
567
+ approve: async (params) => {
568
+ const result = await approveMutation.mutateAsync(params);
569
+ return result.data;
570
+ },
571
+ isApproving: approveMutation.isPending,
572
+ reject: async (params) => {
573
+ const result = await rejectMutation.mutateAsync(params);
574
+ return result.data;
575
+ },
576
+ isRejecting: rejectMutation.isPending,
577
+ fulfill: async (params) => {
578
+ const result = await fulfillMutation.mutateAsync(params);
579
+ return result.data;
580
+ },
581
+ isFulfilling: fulfillMutation.isPending,
582
+ cancel: async (params) => {
583
+ const result = await cancelMutation.mutateAsync(params);
584
+ return result.data;
585
+ },
586
+ isCancelling: cancelMutation.isPending,
587
+ isLoading: createMutation.isPending || approveMutation.isPending || rejectMutation.isPending || fulfillMutation.isPending || cancelMutation.isPending
588
+ };
589
+ }
590
+ function getTransferStateInvalidationKeys() {
591
+ return [
592
+ TRANSFER_KEYS.all,
593
+ // Transfer list and details
594
+ REQUEST_KEYS.all
595
+ // If transfer was from request fulfillment
596
+ ];
597
+ }
598
+
599
+ // src/inventory/hooks/supplier.ts
600
+ var supplierHooks = createCrudHooks({
601
+ api: supplierApi,
602
+ entityKey: "suppliers",
603
+ singular: "Supplier",
604
+ plural: "Suppliers"
605
+ });
606
+ var {
607
+ KEYS: SUPPLIER_KEYS,
608
+ useList: useSuppliers,
609
+ useDetail: useSupplierDetail,
610
+ useActions: useSupplierActions,
611
+ useNavigation: useSupplierNavigation
612
+ } = supplierHooks;
613
+
614
+ export { ADJUSTMENT_KEYS, INVENTORY_KEYS, MOVEMENT_KEYS, PURCHASE_KEYS, REQUEST_KEYS, STOCK_KEYS, SUPPLIER_KEYS, TRANSFER_KEYS, TRANSFER_STATS_KEYS, adjustmentHooks, getStockChangeInvalidationKeys, getStockStatus, getStockStatusBadge, getTransferStateInvalidationKeys, inventoryApis, purchaseHooks, stockHooks, supplierHooks, transferHooks, useAdjustmentActions, useAdjustmentDetail, useAdjustmentNavigation, useAdjustments, useInventory, useInventoryLookup, useLowStock, useMovements, usePendingStockRequests, usePurchaseActions, usePurchaseDetail, usePurchaseNavigation, usePurchaseStateActions, usePurchases, useStock, useStockActions, useStockDetail, useStockNavigation, useStockRequestActions, useStockRequestDetail, useStockRequests, useSupplierActions, useSupplierDetail, useSupplierNavigation, useSuppliers, useTransferActions, useTransferDetail, useTransferNavigation, useTransferStateActions, useTransferStats, useTransfers };
615
+ //# sourceMappingURL=chunk-IXMWZJLV.js.map
616
+ //# sourceMappingURL=chunk-IXMWZJLV.js.map