@classytic/commerce-sdk 0.1.1 → 0.2.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.
Files changed (438) hide show
  1. package/README.md +187 -74
  2. package/dist/accounting/api/account.d.ts +49 -0
  3. package/dist/accounting/api/account.js +45 -0
  4. package/dist/accounting/api/budget.d.ts +76 -0
  5. package/dist/accounting/api/budget.js +82 -0
  6. package/dist/accounting/api/constants.d.ts +58 -0
  7. package/dist/accounting/api/constants.js +79 -0
  8. package/dist/accounting/api/fiscal-period.d.ts +31 -0
  9. package/dist/accounting/api/fiscal-period.js +30 -0
  10. package/dist/accounting/api/index.d.ts +7 -0
  11. package/dist/accounting/api/journal-entry.d.ts +66 -0
  12. package/dist/accounting/api/journal-entry.js +72 -0
  13. package/dist/accounting/api/posting.d.ts +55 -0
  14. package/dist/accounting/api/posting.js +70 -0
  15. package/dist/accounting/api/reports.d.ts +63 -0
  16. package/dist/accounting/api/reports.js +81 -0
  17. package/dist/accounting/hooks/account.d.ts +29 -0
  18. package/dist/accounting/hooks/account.js +102 -0
  19. package/dist/accounting/hooks/budget.d.ts +39 -0
  20. package/dist/accounting/hooks/budget.js +106 -0
  21. package/dist/accounting/hooks/fiscal-period.d.ts +22 -0
  22. package/dist/accounting/hooks/fiscal-period.js +52 -0
  23. package/dist/accounting/hooks/index.d.ts +6 -0
  24. package/dist/accounting/hooks/journal-entry.d.ts +37 -0
  25. package/dist/accounting/hooks/journal-entry.js +89 -0
  26. package/dist/accounting/hooks/posting.d.ts +128 -0
  27. package/dist/accounting/hooks/posting.js +119 -0
  28. package/dist/accounting/hooks/reports.d.ts +32 -0
  29. package/dist/accounting/hooks/reports.js +131 -0
  30. package/dist/accounting/index.d.ts +15 -0
  31. package/dist/accounting/index.js +15 -0
  32. package/dist/accounting/types/index.d.ts +375 -0
  33. package/dist/analytics/api/analytics.d.ts +16 -0
  34. package/dist/analytics/api/analytics.js +27 -0
  35. package/dist/analytics/api/index.d.ts +1 -0
  36. package/dist/analytics/hooks/analytics.d.ts +12 -0
  37. package/dist/analytics/hooks/analytics.js +33 -0
  38. package/dist/analytics/hooks/index.d.ts +1 -0
  39. package/dist/analytics/index.d.ts +4 -27
  40. package/dist/analytics/index.js +4 -6
  41. package/dist/analytics/types.d.ts +46 -0
  42. package/dist/audit/api/audit.d.ts +17 -0
  43. package/dist/audit/api/audit.js +21 -0
  44. package/dist/audit/hooks/audit.d.ts +17 -0
  45. package/dist/audit/hooks/audit.js +38 -0
  46. package/dist/audit/index.d.ts +4 -0
  47. package/dist/audit/index.js +4 -0
  48. package/dist/audit/types/index.d.ts +32 -0
  49. package/dist/auth/api/user-data.d.ts +30 -0
  50. package/dist/auth/api/user-data.js +70 -0
  51. package/dist/auth/hooks/user-search.d.ts +32 -0
  52. package/dist/auth/hooks/user-search.js +51 -0
  53. package/dist/auth/index.d.ts +4 -39
  54. package/dist/auth/index.js +5 -5
  55. package/dist/auth/types.d.ts +46 -0
  56. package/dist/auth/types.js +27 -0
  57. package/dist/catalog/api/category.d.ts +97 -0
  58. package/dist/catalog/api/category.js +109 -0
  59. package/dist/catalog/api/index.d.ts +4 -0
  60. package/dist/catalog/api/product.d.ts +136 -0
  61. package/dist/catalog/api/product.js +142 -0
  62. package/dist/catalog/api/review.d.ts +32 -0
  63. package/dist/catalog/api/review.js +41 -0
  64. package/dist/catalog/api/size-guide.d.ts +46 -0
  65. package/dist/catalog/api/size-guide.js +58 -0
  66. package/dist/catalog/hooks/category.d.ts +201 -0
  67. package/dist/catalog/hooks/category.js +295 -0
  68. package/dist/catalog/hooks/index.d.ts +4 -0
  69. package/dist/catalog/hooks/product.d.ts +165 -0
  70. package/dist/catalog/hooks/product.js +267 -0
  71. package/dist/catalog/hooks/review.d.ts +18 -0
  72. package/dist/catalog/hooks/review.js +38 -0
  73. package/dist/catalog/hooks/size-guide.d.ts +136 -0
  74. package/dist/catalog/hooks/size-guide.js +173 -0
  75. package/dist/catalog/index.d.ts +13 -571
  76. package/dist/catalog/index.js +10 -9
  77. package/dist/catalog/prefetch.d.ts +29 -0
  78. package/dist/catalog/prefetch.js +32 -0
  79. package/dist/catalog/types/category.d.ts +168 -0
  80. package/dist/catalog/types/index.d.ts +4 -0
  81. package/dist/catalog/types/product.d.ts +261 -0
  82. package/dist/catalog/types/review.d.ts +48 -0
  83. package/dist/catalog/types/size-guide.d.ts +118 -0
  84. package/dist/client.d.ts +138 -0
  85. package/dist/client.js +129 -0
  86. package/dist/content/api/cms.d.ts +27 -0
  87. package/dist/content/api/cms.js +43 -0
  88. package/dist/content/api/index.d.ts +2 -0
  89. package/dist/content/api/media.d.ts +74 -0
  90. package/dist/content/api/media.js +77 -0
  91. package/dist/content/hooks/cms.d.ts +31 -0
  92. package/dist/content/hooks/cms.js +62 -0
  93. package/dist/content/hooks/index.d.ts +2 -0
  94. package/dist/content/hooks/media.d.ts +74 -0
  95. package/dist/content/hooks/media.js +153 -0
  96. package/dist/content/index.d.ts +7 -309
  97. package/dist/content/index.js +6 -6
  98. package/dist/content/types/cms.d.ts +390 -0
  99. package/dist/content/types/media.d.ts +110 -0
  100. package/dist/core/api-factory.d.ts +17 -0
  101. package/dist/core/api-factory.js +39 -0
  102. package/dist/core/api-handler.d.ts +53 -0
  103. package/dist/core/api-handler.js +89 -0
  104. package/dist/core/index.d.ts +4 -166
  105. package/dist/core/index.js +4 -5
  106. package/dist/core/prefetch.d.ts +2 -0
  107. package/dist/core/prefetch.js +3 -0
  108. package/dist/core/react/crud.factory.d.ts +3 -0
  109. package/dist/core/react/crud.factory.js +5 -0
  110. package/dist/core/react/index.d.ts +4 -0
  111. package/dist/core/react/index.js +7 -0
  112. package/dist/core/react/mutation.factory.d.ts +9 -0
  113. package/dist/core/react/mutation.factory.js +21 -0
  114. package/dist/core/react/query.factory.d.ts +12 -0
  115. package/dist/core/react/query.factory.js +5 -0
  116. package/dist/core/server-context.d.ts +6 -0
  117. package/dist/core/server-context.js +12 -0
  118. package/dist/core/types/shared.d.ts +29 -0
  119. package/dist/finance/api/finance.d.ts +22 -0
  120. package/dist/finance/api/finance.js +29 -0
  121. package/dist/finance/api/index.d.ts +1 -0
  122. package/dist/finance/hooks/finance.d.ts +32 -0
  123. package/dist/finance/hooks/finance.js +66 -0
  124. package/dist/finance/hooks/index.d.ts +1 -0
  125. package/dist/finance/index.d.ts +4 -81
  126. package/dist/finance/index.js +4 -5
  127. package/dist/finance/types/finance.d.ts +82 -0
  128. package/dist/index.d.ts +139 -32
  129. package/dist/index.js +113 -29
  130. package/dist/inventory/api/adjustment.d.ts +123 -0
  131. package/dist/inventory/api/adjustment.js +120 -0
  132. package/dist/inventory/api/availability.d.ts +70 -0
  133. package/dist/inventory/api/availability.js +47 -0
  134. package/dist/inventory/api/cost.d.ts +58 -0
  135. package/dist/inventory/api/cost.js +34 -0
  136. package/dist/inventory/api/index.d.ts +18 -0
  137. package/dist/inventory/api/lot.d.ts +82 -0
  138. package/dist/inventory/api/lot.js +46 -0
  139. package/dist/inventory/api/movement.d.ts +71 -0
  140. package/dist/inventory/api/movement.js +75 -0
  141. package/dist/inventory/api/package.d.ts +97 -0
  142. package/dist/inventory/api/package.js +56 -0
  143. package/dist/inventory/api/procurement.d.ts +110 -0
  144. package/dist/inventory/api/procurement.js +59 -0
  145. package/dist/inventory/api/purchase.d.ts +106 -0
  146. package/dist/inventory/api/purchase.js +115 -0
  147. package/dist/inventory/api/replenishment.d.ts +145 -0
  148. package/dist/inventory/api/replenishment.js +63 -0
  149. package/dist/inventory/api/report.d.ts +102 -0
  150. package/dist/inventory/api/report.js +54 -0
  151. package/dist/inventory/api/request.d.ts +157 -0
  152. package/dist/inventory/api/request.js +140 -0
  153. package/dist/inventory/api/reservation.d.ts +77 -0
  154. package/dist/inventory/api/reservation.js +51 -0
  155. package/dist/inventory/api/scan.d.ts +29 -0
  156. package/dist/inventory/api/scan.js +30 -0
  157. package/dist/inventory/api/supplier.d.ts +9 -0
  158. package/dist/inventory/api/supplier.js +24 -0
  159. package/dist/inventory/api/trace.d.ts +71 -0
  160. package/dist/inventory/api/trace.js +39 -0
  161. package/dist/inventory/api/transfer.d.ts +162 -0
  162. package/dist/inventory/api/transfer.js +155 -0
  163. package/dist/inventory/api/warehouse.d.ts +199 -0
  164. package/dist/inventory/api/warehouse.js +155 -0
  165. package/dist/inventory/hooks/adjustment.d.ts +24 -0
  166. package/dist/inventory/hooks/adjustment.js +30 -0
  167. package/dist/inventory/hooks/availability.d.ts +16 -0
  168. package/dist/inventory/hooks/availability.js +35 -0
  169. package/dist/inventory/hooks/cost.d.ts +21 -0
  170. package/dist/inventory/hooks/cost.js +50 -0
  171. package/dist/inventory/hooks/index.d.ts +18 -0
  172. package/dist/inventory/hooks/inventory.d.ts +130 -0
  173. package/dist/inventory/hooks/inventory.js +267 -0
  174. package/dist/inventory/hooks/lot.d.ts +26 -0
  175. package/dist/inventory/hooks/lot.js +67 -0
  176. package/dist/inventory/hooks/movement.d.ts +68 -0
  177. package/dist/inventory/hooks/movement.js +106 -0
  178. package/dist/inventory/hooks/package.d.ts +32 -0
  179. package/dist/inventory/hooks/package.js +80 -0
  180. package/dist/inventory/hooks/procurement.d.ts +28 -0
  181. package/dist/inventory/hooks/procurement.js +87 -0
  182. package/dist/inventory/hooks/purchase.d.ts +63 -0
  183. package/dist/inventory/hooks/purchase.js +119 -0
  184. package/dist/inventory/hooks/replenishment.d.ts +34 -0
  185. package/dist/inventory/hooks/replenishment.js +87 -0
  186. package/dist/inventory/hooks/report.d.ts +37 -0
  187. package/dist/inventory/hooks/report.js +79 -0
  188. package/dist/inventory/hooks/request.d.ts +113 -0
  189. package/dist/inventory/hooks/request.js +218 -0
  190. package/dist/inventory/hooks/reservation.d.ts +25 -0
  191. package/dist/inventory/hooks/reservation.js +56 -0
  192. package/dist/inventory/hooks/scan.d.ts +14 -0
  193. package/dist/inventory/hooks/scan.js +22 -0
  194. package/dist/inventory/hooks/supplier.d.ts +24 -0
  195. package/dist/inventory/hooks/supplier.js +30 -0
  196. package/dist/inventory/hooks/trace.d.ts +19 -0
  197. package/dist/inventory/hooks/trace.js +55 -0
  198. package/dist/inventory/hooks/transfer.d.ts +90 -0
  199. package/dist/inventory/hooks/transfer.js +197 -0
  200. package/dist/inventory/hooks/warehouse.d.ts +87 -0
  201. package/dist/inventory/hooks/warehouse.js +240 -0
  202. package/dist/inventory/index.d.ts +39 -512
  203. package/dist/inventory/index.js +37 -16
  204. package/dist/inventory/types/index.d.ts +3 -0
  205. package/dist/inventory/types/inventory.d.ts +485 -0
  206. package/dist/inventory/types/supplier.d.ts +90 -0
  207. package/dist/inventory/types/warehouse.d.ts +182 -0
  208. package/dist/logistics/api/index.d.ts +1 -0
  209. package/dist/logistics/api/logistics.d.ts +260 -0
  210. package/dist/logistics/api/logistics.js +249 -0
  211. package/dist/logistics/hooks/index.d.ts +1 -0
  212. package/dist/logistics/hooks/logistics.d.ts +252 -0
  213. package/dist/logistics/hooks/logistics.js +370 -0
  214. package/dist/logistics/index.d.ts +4 -248
  215. package/dist/logistics/index.js +4 -7
  216. package/dist/logistics/types/logistics.d.ts +188 -0
  217. package/dist/node_modules/@tanstack/query-core/build/modern/hydration-C-jfQLut.d.ts +270 -0
  218. package/dist/notifications/api/notification.d.ts +15 -0
  219. package/dist/notifications/api/notification.js +43 -0
  220. package/dist/notifications/hooks/notification.d.ts +34 -0
  221. package/dist/notifications/hooks/notification.js +86 -0
  222. package/dist/notifications/hooks/stream.d.ts +22 -0
  223. package/dist/notifications/hooks/stream.js +80 -0
  224. package/dist/notifications/index.d.ts +5 -0
  225. package/dist/notifications/index.js +5 -0
  226. package/dist/notifications/types/index.d.ts +57 -0
  227. package/dist/payments/api/index.d.ts +1 -0
  228. package/dist/payments/api/payment.d.ts +89 -0
  229. package/dist/payments/api/payment.js +93 -0
  230. package/dist/payments/hooks/payment.d.ts +53 -0
  231. package/dist/payments/hooks/payment.js +93 -0
  232. package/dist/payments/index.d.ts +4 -55
  233. package/dist/payments/index.js +4 -6
  234. package/dist/payments/types/payment.d.ts +50 -0
  235. package/dist/permissions/checker.d.ts +125 -0
  236. package/dist/permissions/checker.js +150 -0
  237. package/dist/permissions/index.d.ts +3 -0
  238. package/dist/permissions/index.js +4 -0
  239. package/dist/permissions/roles.d.ts +39 -0
  240. package/dist/permissions/roles.js +66 -0
  241. package/dist/platform/api/branch.d.ts +57 -0
  242. package/dist/platform/api/branch.js +73 -0
  243. package/dist/platform/api/config.d.ts +67 -0
  244. package/dist/platform/api/config.js +83 -0
  245. package/dist/platform/api/features.d.ts +15 -0
  246. package/dist/platform/api/features.js +20 -0
  247. package/dist/platform/api/index.d.ts +6 -0
  248. package/dist/platform/api/promo.d.ts +286 -0
  249. package/dist/platform/api/promo.js +276 -0
  250. package/dist/platform/api/user.d.ts +10 -0
  251. package/dist/platform/api/user.js +29 -0
  252. package/dist/platform/api/webhook.d.ts +102 -0
  253. package/dist/platform/api/webhook.js +124 -0
  254. package/dist/platform/hooks/branch.d.ts +24 -0
  255. package/dist/platform/hooks/branch.js +31 -0
  256. package/dist/platform/hooks/config.d.ts +61 -0
  257. package/dist/platform/hooks/config.js +100 -0
  258. package/dist/platform/hooks/features.d.ts +22 -0
  259. package/dist/platform/hooks/features.js +75 -0
  260. package/dist/platform/hooks/index.d.ts +6 -0
  261. package/dist/platform/hooks/promo.d.ts +218 -0
  262. package/dist/platform/hooks/promo.js +451 -0
  263. package/dist/platform/hooks/user.d.ts +24 -0
  264. package/dist/platform/hooks/user.js +30 -0
  265. package/dist/platform/index.d.ts +18 -645
  266. package/dist/platform/index.js +14 -8
  267. package/dist/platform/prefetch.d.ts +9 -0
  268. package/dist/platform/prefetch.js +11 -0
  269. package/dist/platform/types/branch.d.ts +110 -0
  270. package/dist/platform/types/branch.js +16 -0
  271. package/dist/platform/types/config.d.ts +137 -0
  272. package/dist/platform/types/features.d.ts +46 -0
  273. package/dist/platform/types/promo.d.ts +260 -0
  274. package/dist/platform/types/user.d.ts +72 -0
  275. package/dist/platform/types/webhook.d.ts +165 -0
  276. package/dist/sales/api/cart.d.ts +34 -0
  277. package/dist/sales/api/cart.js +38 -0
  278. package/dist/sales/api/customer.d.ts +40 -0
  279. package/dist/sales/api/customer.js +52 -0
  280. package/dist/sales/api/earning-rules.d.ts +54 -0
  281. package/dist/sales/api/earning-rules.js +56 -0
  282. package/dist/sales/api/index.d.ts +9 -0
  283. package/dist/sales/api/loyalty.d.ts +54 -0
  284. package/dist/sales/api/loyalty.js +57 -0
  285. package/dist/sales/api/order.d.ts +147 -0
  286. package/dist/sales/api/order.js +69 -0
  287. package/dist/sales/api/pos.d.ts +81 -0
  288. package/dist/sales/api/pos.js +95 -0
  289. package/dist/sales/api/referrals.d.ts +63 -0
  290. package/dist/sales/api/referrals.js +62 -0
  291. package/dist/sales/api/tiers.d.ts +66 -0
  292. package/dist/sales/api/tiers.js +59 -0
  293. package/dist/sales/hooks/cart.d.ts +50 -0
  294. package/dist/sales/hooks/cart.js +161 -0
  295. package/dist/sales/hooks/customer.d.ts +100 -0
  296. package/dist/sales/hooks/customer.js +130 -0
  297. package/dist/sales/hooks/earning-rules.d.ts +31 -0
  298. package/dist/sales/hooks/earning-rules.js +112 -0
  299. package/dist/sales/hooks/index.d.ts +8 -0
  300. package/dist/sales/hooks/loyalty.d.ts +51 -0
  301. package/dist/sales/hooks/loyalty.js +122 -0
  302. package/dist/sales/hooks/order.d.ts +219 -0
  303. package/dist/sales/hooks/order.js +401 -0
  304. package/dist/sales/hooks/pos.d.ts +87 -0
  305. package/dist/sales/hooks/pos.js +222 -0
  306. package/dist/sales/hooks/referrals.d.ts +34 -0
  307. package/dist/sales/hooks/referrals.js +132 -0
  308. package/dist/sales/hooks/tiers.d.ts +32 -0
  309. package/dist/sales/hooks/tiers.js +144 -0
  310. package/dist/sales/index.d.ts +25 -587
  311. package/dist/sales/index.js +19 -9
  312. package/dist/sales/prefetch.d.ts +10 -0
  313. package/dist/sales/prefetch.js +13 -0
  314. package/dist/sales/types/cart.d.ts +123 -0
  315. package/dist/sales/types/customer.d.ts +119 -0
  316. package/dist/sales/types/earning-rules.d.ts +75 -0
  317. package/dist/sales/types/index.d.ts +8 -0
  318. package/dist/sales/types/loyalty.d.ts +120 -0
  319. package/dist/sales/types/order.d.ts +487 -0
  320. package/dist/sales/types/order.js +22 -0
  321. package/dist/sales/types/pos.d.ts +227 -0
  322. package/dist/sales/types/referrals.d.ts +51 -0
  323. package/dist/sales/types/tiers.d.ts +56 -0
  324. package/dist/server.d.ts +41 -23
  325. package/dist/server.js +41 -36
  326. package/dist/transaction/api/index.d.ts +1 -0
  327. package/dist/transaction/api/transaction.d.ts +63 -0
  328. package/dist/transaction/api/transaction.js +84 -0
  329. package/dist/transaction/hooks/index.d.ts +1 -0
  330. package/dist/transaction/hooks/transaction.d.ts +106 -0
  331. package/dist/transaction/hooks/transaction.js +156 -0
  332. package/dist/transaction/index.d.ts +4 -104
  333. package/dist/transaction/index.js +5 -8
  334. package/dist/transaction/types/transaction.d.ts +440 -0
  335. package/dist/transaction/types/transaction.js +86 -0
  336. package/package.json +36 -25
  337. package/dist/adjustment-MNH3AT6S.js +0 -5
  338. package/dist/adjustment-MNH3AT6S.js.map +0 -1
  339. package/dist/analytics/index.js.map +0 -1
  340. package/dist/analytics-DMcD-o8w.d.ts +0 -76
  341. package/dist/api-factory-B_h4RKBm.d.ts +0 -280
  342. package/dist/auth/index.js.map +0 -1
  343. package/dist/catalog/index.js.map +0 -1
  344. package/dist/chunk-24FDD6UR.js +0 -75
  345. package/dist/chunk-24FDD6UR.js.map +0 -1
  346. package/dist/chunk-2TF7QNYV.js +0 -159
  347. package/dist/chunk-2TF7QNYV.js.map +0 -1
  348. package/dist/chunk-2YAZ5WG6.js +0 -479
  349. package/dist/chunk-2YAZ5WG6.js.map +0 -1
  350. package/dist/chunk-36NLLAVH.js +0 -177
  351. package/dist/chunk-36NLLAVH.js.map +0 -1
  352. package/dist/chunk-3OYSJB3P.js +0 -126
  353. package/dist/chunk-3OYSJB3P.js.map +0 -1
  354. package/dist/chunk-5E57JODA.js +0 -135
  355. package/dist/chunk-5E57JODA.js.map +0 -1
  356. package/dist/chunk-7LZCW4VF.js +0 -13
  357. package/dist/chunk-7LZCW4VF.js.map +0 -1
  358. package/dist/chunk-ANYGZ6O5.js +0 -830
  359. package/dist/chunk-ANYGZ6O5.js.map +0 -1
  360. package/dist/chunk-AQAISI4F.js +0 -183
  361. package/dist/chunk-AQAISI4F.js.map +0 -1
  362. package/dist/chunk-B6MPVOV7.js +0 -328
  363. package/dist/chunk-B6MPVOV7.js.map +0 -1
  364. package/dist/chunk-CILP56G2.js +0 -94
  365. package/dist/chunk-CILP56G2.js.map +0 -1
  366. package/dist/chunk-ERQ52WHY.js +0 -534
  367. package/dist/chunk-ERQ52WHY.js.map +0 -1
  368. package/dist/chunk-FOTUJPM4.js +0 -640
  369. package/dist/chunk-FOTUJPM4.js.map +0 -1
  370. package/dist/chunk-IHCBBLLW.js +0 -198
  371. package/dist/chunk-IHCBBLLW.js.map +0 -1
  372. package/dist/chunk-J4JBQET2.js +0 -76
  373. package/dist/chunk-J4JBQET2.js.map +0 -1
  374. package/dist/chunk-L4OEI4VZ.js +0 -123
  375. package/dist/chunk-L4OEI4VZ.js.map +0 -1
  376. package/dist/chunk-LRV7MWWX.js +0 -616
  377. package/dist/chunk-LRV7MWWX.js.map +0 -1
  378. package/dist/chunk-N43VE355.js +0 -126
  379. package/dist/chunk-N43VE355.js.map +0 -1
  380. package/dist/chunk-PYYLHUV6.js +0 -3
  381. package/dist/chunk-PYYLHUV6.js.map +0 -1
  382. package/dist/chunk-QCTXAMLA.js +0 -261
  383. package/dist/chunk-QCTXAMLA.js.map +0 -1
  384. package/dist/chunk-RIKAPJNG.js +0 -40
  385. package/dist/chunk-RIKAPJNG.js.map +0 -1
  386. package/dist/chunk-U3XT35GZ.js +0 -202
  387. package/dist/chunk-U3XT35GZ.js.map +0 -1
  388. package/dist/chunk-W22WB3WZ.js +0 -148
  389. package/dist/chunk-W22WB3WZ.js.map +0 -1
  390. package/dist/chunk-WTIJMKML.js +0 -27
  391. package/dist/chunk-WTIJMKML.js.map +0 -1
  392. package/dist/chunk-X2CQFJPR.js +0 -75
  393. package/dist/chunk-X2CQFJPR.js.map +0 -1
  394. package/dist/chunk-YYFKLOKO.js +0 -769
  395. package/dist/chunk-YYFKLOKO.js.map +0 -1
  396. package/dist/client-Cs7E_usr.d.ts +0 -113
  397. package/dist/content/index.js.map +0 -1
  398. package/dist/core/index.js.map +0 -1
  399. package/dist/core/react.d.ts +0 -107
  400. package/dist/core/react.js +0 -5
  401. package/dist/core/react.js.map +0 -1
  402. package/dist/coupon-BZSZ0y3n.d.ts +0 -129
  403. package/dist/coupon-CDzL4bJG.d.ts +0 -655
  404. package/dist/crud.factory-DyKaPHcU.d.ts +0 -181
  405. package/dist/finance/index.js.map +0 -1
  406. package/dist/finance-BJdfKRw0.d.ts +0 -135
  407. package/dist/index.js.map +0 -1
  408. package/dist/inventory/index.js.map +0 -1
  409. package/dist/inventory-B5pssqRx.d.ts +0 -748
  410. package/dist/logistics/index.js.map +0 -1
  411. package/dist/logistics-CrpKadKE.d.ts +0 -410
  412. package/dist/media-CNLJK93J.d.ts +0 -721
  413. package/dist/movement-R3CERFAM.js +0 -5
  414. package/dist/movement-R3CERFAM.js.map +0 -1
  415. package/dist/order-B3dCvHgK.d.ts +0 -360
  416. package/dist/payment-BRboLqvU.d.ts +0 -127
  417. package/dist/payments/index.js.map +0 -1
  418. package/dist/platform/index.js.map +0 -1
  419. package/dist/pos-BCqkx2-K.d.ts +0 -527
  420. package/dist/product-p09zXkXB.d.ts +0 -260
  421. package/dist/purchase-54PER2PY.js +0 -5
  422. package/dist/purchase-54PER2PY.js.map +0 -1
  423. package/dist/request-MP6NV5ZE.js +0 -5
  424. package/dist/request-MP6NV5ZE.js.map +0 -1
  425. package/dist/sales/index.js.map +0 -1
  426. package/dist/server.js.map +0 -1
  427. package/dist/size-guide-DgjzjM5P.d.ts +0 -554
  428. package/dist/stock-2LP4HJSB.js +0 -5
  429. package/dist/stock-2LP4HJSB.js.map +0 -1
  430. package/dist/stock-CfrU5_Wr.d.ts +0 -632
  431. package/dist/supplier-BWJTRZ5Z.js +0 -5
  432. package/dist/supplier-BWJTRZ5Z.js.map +0 -1
  433. package/dist/transaction/index.js.map +0 -1
  434. package/dist/transaction-Bf6WjYCh.d.ts +0 -84
  435. package/dist/transaction-dL3WW-er.d.ts +0 -442
  436. package/dist/transfer-4XSS6HWT.js +0 -5
  437. package/dist/transfer-4XSS6HWT.js.map +0 -1
  438. package/dist/user-data-DdLjAGwO.d.ts +0 -132
@@ -0,0 +1,401 @@
1
+ "use client";
2
+
3
+ import { getToastHandler } from "../../core/react/mutation.factory.js";
4
+ import { createCrudHooks } from "../../core/react/crud.factory.js";
5
+ import orderApi from "../api/order.js";
6
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
7
+
8
+ //#region src/sales/hooks/order.ts
9
+ /**
10
+ * Order Hooks
11
+ *
12
+ * React hooks for order CRUD operations using the factory pattern.
13
+ * Includes customer-facing and admin-specific hooks.
14
+ */
15
+ /**
16
+ * Extended order query keys
17
+ */
18
+ const createOrderKeys = () => ({
19
+ all: ["orders"],
20
+ lists: () => [...createOrderKeys().all, "list"],
21
+ list: (params) => [...createOrderKeys().lists(), params],
22
+ details: () => [...createOrderKeys().all, "detail"],
23
+ detail: (id) => [...createOrderKeys().details(), id],
24
+ myOrders: (params) => [
25
+ ...createOrderKeys().all,
26
+ "my",
27
+ params
28
+ ],
29
+ myDetail: (id) => [
30
+ ...createOrderKeys().all,
31
+ "my",
32
+ "detail",
33
+ id
34
+ ]
35
+ });
36
+ /**
37
+ * Order hooks using createCrudHooks factory
38
+ *
39
+ * Provides:
40
+ * - useOrders: List orders with filtering/pagination
41
+ * - useOrderDetail: Get single order
42
+ * - useOrderActions: Create, update, delete mutations
43
+ * - useOrderNavigation: Navigation between orders
44
+ */
45
+ const orderHooks = createCrudHooks({
46
+ api: orderApi,
47
+ entityKey: "orders",
48
+ singular: "Order",
49
+ plural: "Orders",
50
+ defaults: { staleTime: 60 * 1e3 }
51
+ });
52
+ const ORDER_KEYS = createOrderKeys();
53
+ const { useList: useOrders, useDetail: useOrderDetail, useActions: useOrderActions, useNavigation: useOrderNavigation } = orderHooks;
54
+ /**
55
+ * Get customer's own orders
56
+ *
57
+ * @param token - Auth token
58
+ * @param params - Query params { page, limit, status, sort }
59
+ * @param options - Query options
60
+ *
61
+ * @example
62
+ * ```tsx
63
+ * function MyOrdersPage() {
64
+ * const { orders, isLoading, hasMore } = useMyOrders(token, { limit: 10 });
65
+ *
66
+ * return (
67
+ * <OrderList orders={orders} loading={isLoading} />
68
+ * );
69
+ * }
70
+ * ```
71
+ */
72
+ function useMyOrders(token, params = {}, options = {}) {
73
+ const { data, isLoading, isFetching, error, refetch } = useQuery({
74
+ queryKey: ORDER_KEYS.myOrders(params),
75
+ queryFn: async () => {
76
+ return await orderApi.getMyOrders({
77
+ token,
78
+ params
79
+ });
80
+ },
81
+ enabled: !!token && options.enabled !== false,
82
+ staleTime: options.staleTime ?? 30 * 1e3
83
+ });
84
+ const orders = data?.data || data?.docs || [];
85
+ const pagination = data?.pagination;
86
+ return {
87
+ orders,
88
+ total: pagination?.total || orders.length,
89
+ page: pagination?.page || 1,
90
+ limit: pagination?.limit || 10,
91
+ hasMore: pagination?.hasMore ?? false,
92
+ isLoading,
93
+ isFetching,
94
+ error,
95
+ refetch
96
+ };
97
+ }
98
+ /**
99
+ * Get customer's own order detail
100
+ *
101
+ * @param token - Auth token
102
+ * @param orderId - Order ID
103
+ * @param options - Query options
104
+ *
105
+ * @example
106
+ * ```tsx
107
+ * function OrderDetailPage({ orderId }) {
108
+ * const { data: order, isLoading } = useMyOrderDetail(token, orderId);
109
+ *
110
+ * if (isLoading) return <Skeleton />;
111
+ * return <OrderDetail order={order} />;
112
+ * }
113
+ * ```
114
+ */
115
+ function useMyOrderDetail(token, orderId, options = {}) {
116
+ return useQuery({
117
+ queryKey: ORDER_KEYS.myDetail(orderId),
118
+ queryFn: async () => {
119
+ return (await orderApi.getMyOrder({
120
+ token,
121
+ id: orderId
122
+ })).data;
123
+ },
124
+ enabled: !!token && !!orderId && options.enabled !== false,
125
+ staleTime: options.staleTime ?? 30 * 1e3
126
+ });
127
+ }
128
+ /**
129
+ * Customer order actions (checkout, request cancellation)
130
+ *
131
+ * @param token - Customer auth token
132
+ *
133
+ * @example
134
+ * ```tsx
135
+ * function CheckoutButton({ cart }) {
136
+ * const { checkout, isCheckingOut } = useCustomerOrderActions(token);
137
+ *
138
+ * const handleCheckout = async () => {
139
+ * const order = await checkout({
140
+ * items: cart.items,
141
+ * shipping: shippingAddress,
142
+ * payment: { method: 'bkash' },
143
+ * });
144
+ * router.push(`/orders/${order._id}`);
145
+ * };
146
+ *
147
+ * return (
148
+ * <Button onClick={handleCheckout} disabled={isCheckingOut}>
149
+ * {isCheckingOut ? 'Processing...' : 'Place Order'}
150
+ * </Button>
151
+ * );
152
+ * }
153
+ * ```
154
+ */
155
+ function useCustomerOrderActions(token) {
156
+ const queryClient = useQueryClient();
157
+ const toast = getToastHandler();
158
+ const checkoutMutation = useMutation({
159
+ mutationFn: async (data) => {
160
+ return (await orderApi.checkout({
161
+ token,
162
+ data
163
+ })).data;
164
+ },
165
+ onSuccess: () => {
166
+ queryClient.setQueryData(["cart"], null);
167
+ queryClient.invalidateQueries({ queryKey: ["cart"] });
168
+ queryClient.invalidateQueries({ queryKey: ORDER_KEYS.all });
169
+ toast.success("Order placed successfully!");
170
+ },
171
+ onError: (error) => {
172
+ toast.error(error.message || "Failed to place order");
173
+ }
174
+ });
175
+ const requestCancelMutation = useMutation({
176
+ mutationFn: async ({ orderId, reason }) => {
177
+ return (await orderApi.requestCancellation({
178
+ token,
179
+ id: orderId,
180
+ reason
181
+ })).data;
182
+ },
183
+ onSuccess: () => {
184
+ queryClient.invalidateQueries({ queryKey: ORDER_KEYS.all });
185
+ toast.success("Cancellation request submitted");
186
+ },
187
+ onError: (error) => {
188
+ toast.error(error.message || "Failed to request cancellation");
189
+ }
190
+ });
191
+ return {
192
+ checkout: checkoutMutation.mutateAsync,
193
+ isCheckingOut: checkoutMutation.isPending,
194
+ requestCancel: requestCancelMutation.mutateAsync,
195
+ isRequestingCancel: requestCancelMutation.isPending,
196
+ isLoading: checkoutMutation.isPending || requestCancelMutation.isPending
197
+ };
198
+ }
199
+ /**
200
+ * Guest checkout mutation (no auth required)
201
+ *
202
+ * For unauthenticated users. Items are sent from FE localStorage.
203
+ *
204
+ * @example
205
+ * ```tsx
206
+ * function GuestCheckoutButton({ cartItems, guestInfo, address }) {
207
+ * const { guestCheckout, isCheckingOut } = useGuestCheckout();
208
+ *
209
+ * const handleCheckout = async () => {
210
+ * const order = await guestCheckout({
211
+ * items: cartItems,
212
+ * guest: guestInfo,
213
+ * deliveryAddress: address,
214
+ * delivery: { method: 'standard', price: 80 },
215
+ * });
216
+ * router.push(`/order-confirmation/${order._id}`);
217
+ * };
218
+ *
219
+ * return (
220
+ * <Button onClick={handleCheckout} disabled={isCheckingOut}>
221
+ * {isCheckingOut ? 'Processing...' : 'Place Order'}
222
+ * </Button>
223
+ * );
224
+ * }
225
+ * ```
226
+ */
227
+ function useGuestCheckout() {
228
+ const queryClient = useQueryClient();
229
+ const toast = getToastHandler();
230
+ const mutation = useMutation({
231
+ mutationFn: async (data) => {
232
+ return (await orderApi.guestCheckout({ data })).data;
233
+ },
234
+ onSuccess: () => {
235
+ queryClient.invalidateQueries({ queryKey: ORDER_KEYS.all });
236
+ toast.success("Order placed successfully!");
237
+ },
238
+ onError: (error) => {
239
+ toast.error(error.message || "Failed to place order");
240
+ }
241
+ });
242
+ return {
243
+ guestCheckout: mutation.mutateAsync,
244
+ isCheckingOut: mutation.isPending
245
+ };
246
+ }
247
+ /**
248
+ * Admin order actions (status, fulfill, refund, cancel, shipping)
249
+ *
250
+ * @param token - Admin auth token
251
+ *
252
+ * @example
253
+ * ```tsx
254
+ * function OrderActions({ order }) {
255
+ * const {
256
+ * updateStatus,
257
+ * fulfillOrder,
258
+ * cancelOrder,
259
+ * isLoading,
260
+ * } = useAdminOrderActions(token);
261
+ *
262
+ * return (
263
+ * <>
264
+ * <Button onClick={() => updateStatus({ orderId: order._id, status: 'processing' })}>
265
+ * Mark Processing
266
+ * </Button>
267
+ * <Button onClick={() => fulfillOrder({ orderId: order._id, branchId: 'branch_123' })}>
268
+ * Fulfill Order
269
+ * </Button>
270
+ * </>
271
+ * );
272
+ * }
273
+ * ```
274
+ */
275
+ function useAdminOrderActions(token) {
276
+ const queryClient = useQueryClient();
277
+ const toast = getToastHandler();
278
+ const updateStatusMutation = useMutation({
279
+ mutationFn: async ({ orderId, status, note }) => {
280
+ return (await orderApi.updateStatus({
281
+ token,
282
+ id: orderId,
283
+ data: {
284
+ status,
285
+ note
286
+ }
287
+ })).data;
288
+ },
289
+ onSuccess: () => {
290
+ queryClient.invalidateQueries({ queryKey: ORDER_KEYS.all });
291
+ toast.success("Order status updated");
292
+ },
293
+ onError: (error) => {
294
+ toast.error(error.message || "Failed to update status");
295
+ }
296
+ });
297
+ const fulfillMutation = useMutation({
298
+ mutationFn: async ({ orderId, ...data }) => {
299
+ return (await orderApi.fulfill({
300
+ token,
301
+ id: orderId,
302
+ data
303
+ })).data;
304
+ },
305
+ onSuccess: () => {
306
+ queryClient.invalidateQueries({ queryKey: ORDER_KEYS.all });
307
+ queryClient.invalidateQueries({ queryKey: ["branches"] });
308
+ queryClient.invalidateQueries({ queryKey: ["stock"] });
309
+ toast.success("Order fulfilled successfully");
310
+ },
311
+ onError: (error) => {
312
+ toast.error(error.message || "Failed to fulfill order");
313
+ }
314
+ });
315
+ const refundMutation = useMutation({
316
+ mutationFn: async ({ orderId, amount, reason }) => {
317
+ return (await orderApi.refund({
318
+ token,
319
+ id: orderId,
320
+ data: {
321
+ amount,
322
+ reason
323
+ }
324
+ })).data;
325
+ },
326
+ onSuccess: () => {
327
+ queryClient.invalidateQueries({ queryKey: ORDER_KEYS.all });
328
+ toast.success("Refund processed successfully");
329
+ },
330
+ onError: (error) => {
331
+ toast.error(error.message || "Failed to process refund");
332
+ }
333
+ });
334
+ const cancelMutation = useMutation({
335
+ mutationFn: async ({ orderId, reason, refund }) => {
336
+ return (await orderApi.cancel({
337
+ token,
338
+ id: orderId,
339
+ reason,
340
+ refund
341
+ })).data;
342
+ },
343
+ onSuccess: () => {
344
+ queryClient.invalidateQueries({ queryKey: ORDER_KEYS.all });
345
+ toast.success("Order cancelled");
346
+ },
347
+ onError: (error) => {
348
+ toast.error(error.message || "Failed to cancel order");
349
+ }
350
+ });
351
+ const requestShippingMutation = useMutation({
352
+ mutationFn: async ({ orderId, ...data }) => {
353
+ return (await orderApi.requestShipping({
354
+ token,
355
+ id: orderId,
356
+ data
357
+ })).data;
358
+ },
359
+ onSuccess: () => {
360
+ queryClient.invalidateQueries({ queryKey: ORDER_KEYS.all });
361
+ toast.success("Shipping pickup requested");
362
+ },
363
+ onError: (error) => {
364
+ toast.error(error.message || "Failed to request shipping");
365
+ }
366
+ });
367
+ const updateShippingMutation = useMutation({
368
+ mutationFn: async ({ orderId, ...data }) => {
369
+ return (await orderApi.updateShipping({
370
+ token,
371
+ id: orderId,
372
+ data
373
+ })).data;
374
+ },
375
+ onSuccess: () => {
376
+ queryClient.invalidateQueries({ queryKey: ORDER_KEYS.all });
377
+ toast.success("Shipping status updated");
378
+ },
379
+ onError: (error) => {
380
+ toast.error(error.message || "Failed to update shipping");
381
+ }
382
+ });
383
+ return {
384
+ updateStatus: updateStatusMutation.mutateAsync,
385
+ isUpdatingStatus: updateStatusMutation.isPending,
386
+ fulfillOrder: fulfillMutation.mutateAsync,
387
+ isFulfilling: fulfillMutation.isPending,
388
+ refundOrder: refundMutation.mutateAsync,
389
+ isRefunding: refundMutation.isPending,
390
+ cancelOrder: cancelMutation.mutateAsync,
391
+ isCancelling: cancelMutation.isPending,
392
+ requestShipping: requestShippingMutation.mutateAsync,
393
+ isRequestingShipping: requestShippingMutation.isPending,
394
+ updateShipping: updateShippingMutation.mutateAsync,
395
+ isUpdatingShipping: updateShippingMutation.isPending,
396
+ isLoading: updateStatusMutation.isPending || fulfillMutation.isPending || refundMutation.isPending || cancelMutation.isPending || requestShippingMutation.isPending || updateShippingMutation.isPending
397
+ };
398
+ }
399
+
400
+ //#endregion
401
+ export { ORDER_KEYS, orderHooks, useAdminOrderActions, useCustomerOrderActions, useGuestCheckout, useMyOrderDetail, useMyOrders, useOrderActions, useOrderDetail, useOrderNavigation, useOrders };
@@ -0,0 +1,87 @@
1
+ import { ProductVariant } from "../../catalog/types/product.js";
2
+ import { PosLookupResponse, PosOrderPayload, PosProduct, PosProductsResponse, PosReceiptResponse } from "../types/pos.js";
3
+ import { BulkAdjustmentPayload, CreateAdjustmentPayload } from "../../inventory/types/inventory.js";
4
+ import * as _tanstack_react_query0 from "@tanstack/react-query";
5
+
6
+ //#region src/sales/hooks/pos.d.ts
7
+ declare const POS_KEYS: {
8
+ all: readonly ["pos"];
9
+ products: (branchId?: string) => readonly ["pos", "products", string | undefined];
10
+ productsList: (branchId?: string, params?: Record<string, unknown>) => readonly ["pos", "products", string | undefined, Record<string, unknown> | undefined];
11
+ lookup: (code: string, branchId?: string) => readonly ["pos", "lookup", string, string | undefined];
12
+ orders: () => readonly ["pos", "orders"];
13
+ receipt: (orderId: string) => readonly ["pos", "orders", string, "receipt"];
14
+ };
15
+ interface PosProductFilters {
16
+ category?: string;
17
+ search?: string;
18
+ inStockOnly?: boolean;
19
+ lowStockOnly?: boolean;
20
+ after?: string;
21
+ limit?: number;
22
+ sort?: string;
23
+ [key: string]: unknown;
24
+ }
25
+ interface UsePosProductsReturn {
26
+ products: PosProduct[];
27
+ summary: PosProductsResponse["summary"];
28
+ branch: PosProductsResponse["branch"];
29
+ hasMore: boolean;
30
+ nextCursor: string | null;
31
+ isLoading: boolean;
32
+ isFetching: boolean;
33
+ error: Error | null;
34
+ refetch: () => void;
35
+ }
36
+ interface QueryOptions {
37
+ enabled?: boolean;
38
+ }
39
+ interface UsePosOrdersReturn {
40
+ createOrder: (data: PosOrderPayload) => Promise<unknown>;
41
+ isCreatingOrder: boolean;
42
+ }
43
+ interface UsePosStockActionsReturn {
44
+ adjustStock: (data: CreateAdjustmentPayload) => Promise<unknown>;
45
+ isAdjusting: boolean;
46
+ setStock: (params: {
47
+ productId: string;
48
+ quantity: number;
49
+ branchId?: string;
50
+ variantSku?: string;
51
+ reason?: string;
52
+ }) => Promise<unknown>;
53
+ isSetting: boolean;
54
+ bulkAdjust: (data: BulkAdjustmentPayload) => Promise<unknown>;
55
+ isBulkAdjusting: boolean;
56
+ isLoading: boolean;
57
+ }
58
+ /** Fetch POS products with branch-specific stock */
59
+ declare function usePosProducts(token: string, branchId: string | undefined, filters?: PosProductFilters, options?: QueryOptions): UsePosProductsReturn;
60
+ /** Lookup product by barcode/SKU (query-based) */
61
+ declare function usePosLookup(token: string, code: string, branchId?: string, options?: QueryOptions): _tanstack_react_query0.UseQueryResult<PosLookupResponse, Error>;
62
+ /** Lookup product by barcode/SKU (mutation-based, for scan-and-act) */
63
+ declare function usePosLookupMutation(token: string): {
64
+ lookup: _tanstack_react_query0.UseMutateAsyncFunction<PosLookupResponse, Error, {
65
+ code: string;
66
+ branchId?: string;
67
+ }, unknown>;
68
+ isLooking: boolean;
69
+ error: Error | null;
70
+ };
71
+ /** Get receipt for an order */
72
+ declare function usePosReceipt(token: string, orderId: string, options?: QueryOptions): _tanstack_react_query0.UseQueryResult<PosReceiptResponse, Error>;
73
+ /** POS order operations */
74
+ declare function usePosOrders(token: string): UsePosOrdersReturn;
75
+ /** POS stock adjustment actions */
76
+ declare function usePosStockActions(token: string, branchId?: string): UsePosStockActionsReturn;
77
+ declare function generateIdempotencyKey(terminalId?: string): string;
78
+ declare function calculateVariantPrice(basePrice: number, priceModifier?: number): number;
79
+ declare function formatVariantLabel(attributes?: Record<string, string>): string;
80
+ declare function isVariantProduct(product: PosProduct): boolean;
81
+ declare function getAvailableVariants(product: PosProduct): ProductVariant[];
82
+ declare function findVariantBySku(product: PosProduct, sku: string): ProductVariant | null;
83
+ declare function getVariantStock(product: PosProduct, variantSku: string): number;
84
+ declare function isInStock(product: PosProduct, variantSku?: string): boolean;
85
+ declare function getPosProductImage(product: PosProduct): string;
86
+ //#endregion
87
+ export { POS_KEYS, PosProductFilters, UsePosOrdersReturn, UsePosProductsReturn, UsePosStockActionsReturn, calculateVariantPrice, findVariantBySku, formatVariantLabel, generateIdempotencyKey, getAvailableVariants, getPosProductImage, getVariantStock, isInStock, isVariantProduct, usePosLookup, usePosLookupMutation, usePosOrders, usePosProducts, usePosReceipt, usePosStockActions };
@@ -0,0 +1,222 @@
1
+ "use client";
2
+
3
+ import { useMutationWithTransition } from "../../core/react/mutation.factory.js";
4
+ import posApi from "../api/pos.js";
5
+ import { useQuery, useQueryClient } from "@tanstack/react-query";
6
+
7
+ //#region src/sales/hooks/pos.ts
8
+ /**
9
+ * POS Hooks
10
+ *
11
+ * React hooks for Point of Sale operations.
12
+ */
13
+ const POS_KEYS = {
14
+ all: ["pos"],
15
+ products: (branchId) => [
16
+ ...POS_KEYS.all,
17
+ "products",
18
+ branchId
19
+ ],
20
+ productsList: (branchId, params) => [...POS_KEYS.products(branchId), params],
21
+ lookup: (code, branchId) => [
22
+ ...POS_KEYS.all,
23
+ "lookup",
24
+ code,
25
+ branchId
26
+ ],
27
+ orders: () => [...POS_KEYS.all, "orders"],
28
+ receipt: (orderId) => [
29
+ ...POS_KEYS.orders(),
30
+ orderId,
31
+ "receipt"
32
+ ]
33
+ };
34
+ /** Fetch POS products with branch-specific stock */
35
+ function usePosProducts(token, branchId, filters = {}, options = {}) {
36
+ const { data, isLoading, isFetching, error, refetch } = useQuery({
37
+ queryKey: POS_KEYS.productsList(branchId, filters),
38
+ queryFn: () => posApi.getProducts({
39
+ token,
40
+ branchId,
41
+ category: filters.category,
42
+ search: filters.search,
43
+ inStockOnly: filters.inStockOnly,
44
+ lowStockOnly: filters.lowStockOnly,
45
+ after: filters.after,
46
+ limit: filters.limit || 50,
47
+ sort: filters.sort || "name"
48
+ }),
49
+ enabled: !!token && options.enabled !== false,
50
+ staleTime: 3e4,
51
+ refetchOnWindowFocus: true
52
+ });
53
+ return {
54
+ products: data?.docs || [],
55
+ summary: data?.summary || {
56
+ totalItems: 0,
57
+ totalQuantity: 0,
58
+ lowStockCount: 0,
59
+ outOfStockCount: 0
60
+ },
61
+ branch: data?.branch || {
62
+ _id: "",
63
+ code: "",
64
+ name: ""
65
+ },
66
+ hasMore: data?.hasMore || false,
67
+ nextCursor: data?.next || null,
68
+ isLoading,
69
+ isFetching,
70
+ error,
71
+ refetch
72
+ };
73
+ }
74
+ /** Lookup product by barcode/SKU (query-based) */
75
+ function usePosLookup(token, code, branchId, options = {}) {
76
+ return useQuery({
77
+ queryKey: POS_KEYS.lookup(code, branchId),
78
+ queryFn: () => posApi.lookup({
79
+ token,
80
+ code,
81
+ branchId
82
+ }),
83
+ enabled: !!token && !!code && code.length >= 2 && options.enabled !== false,
84
+ staleTime: 1e4,
85
+ retry: false
86
+ });
87
+ }
88
+ /** Lookup product by barcode/SKU (mutation-based, for scan-and-act) */
89
+ function usePosLookupMutation(token) {
90
+ const mutation = useMutationWithTransition({
91
+ mutationFn: ({ code, branchId }) => posApi.lookup({
92
+ token,
93
+ code,
94
+ branchId
95
+ }),
96
+ messages: { error: "Lookup failed" }
97
+ });
98
+ return {
99
+ lookup: mutation.mutateAsync,
100
+ isLooking: mutation.isPending,
101
+ error: mutation.error
102
+ };
103
+ }
104
+ /** Get receipt for an order */
105
+ function usePosReceipt(token, orderId, options = {}) {
106
+ return useQuery({
107
+ queryKey: POS_KEYS.receipt(orderId),
108
+ queryFn: async () => {
109
+ return await posApi.getReceipt({
110
+ token,
111
+ orderId
112
+ });
113
+ },
114
+ enabled: !!token && !!orderId && options.enabled !== false,
115
+ staleTime: Infinity
116
+ });
117
+ }
118
+ /** POS order operations */
119
+ function usePosOrders(token) {
120
+ const queryClient = useQueryClient();
121
+ const createOrderMutation = useMutationWithTransition({
122
+ mutationFn: (data) => posApi.createOrder({
123
+ token,
124
+ data
125
+ }),
126
+ onSuccess: (_result, variables) => {
127
+ queryClient.invalidateQueries({ queryKey: POS_KEYS.products(variables.branchId) });
128
+ }
129
+ });
130
+ return {
131
+ createOrder: createOrderMutation.mutateAsync,
132
+ isCreatingOrder: createOrderMutation.isPending
133
+ };
134
+ }
135
+ /** POS stock adjustment actions */
136
+ function usePosStockActions(token, branchId) {
137
+ const adjustMutation = useMutationWithTransition({
138
+ mutationFn: (data) => posApi.adjustStock({
139
+ token,
140
+ data
141
+ }),
142
+ invalidateQueries: [POS_KEYS.products(branchId)],
143
+ messages: {
144
+ success: "Stock adjusted",
145
+ error: "Failed to adjust stock"
146
+ }
147
+ });
148
+ const setMutation = useMutationWithTransition({
149
+ mutationFn: (params) => posApi.setStock({
150
+ token,
151
+ productId: params.productId,
152
+ data: {
153
+ quantity: params.quantity,
154
+ branchId: params.branchId || branchId,
155
+ variantSku: params.variantSku,
156
+ reason: params.reason
157
+ }
158
+ }),
159
+ invalidateQueries: [POS_KEYS.products(branchId)],
160
+ messages: {
161
+ success: "Stock updated",
162
+ error: "Failed to set stock"
163
+ }
164
+ });
165
+ const bulkMutation = useMutationWithTransition({
166
+ mutationFn: (data) => posApi.bulkAdjust({
167
+ token,
168
+ data
169
+ }),
170
+ invalidateQueries: [POS_KEYS.products(branchId)],
171
+ messages: {
172
+ success: "Bulk adjustment complete",
173
+ error: "Failed to bulk adjust"
174
+ }
175
+ });
176
+ return {
177
+ adjustStock: adjustMutation.mutateAsync,
178
+ isAdjusting: adjustMutation.isPending,
179
+ setStock: setMutation.mutateAsync,
180
+ isSetting: setMutation.isPending,
181
+ bulkAdjust: bulkMutation.mutateAsync,
182
+ isBulkAdjusting: bulkMutation.isPending,
183
+ isLoading: adjustMutation.isPending || setMutation.isPending || bulkMutation.isPending
184
+ };
185
+ }
186
+ function generateIdempotencyKey(terminalId) {
187
+ return `pos_${terminalId || "default"}_${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}_${Math.floor(Math.random() * 1e4).toString().padStart(4, "0")}`;
188
+ }
189
+ function calculateVariantPrice(basePrice, priceModifier = 0) {
190
+ return basePrice + priceModifier;
191
+ }
192
+ function formatVariantLabel(attributes) {
193
+ if (!attributes || Object.keys(attributes).length === 0) return "";
194
+ return Object.entries(attributes).map(([key, value]) => `${key.charAt(0).toUpperCase() + key.slice(1)}: ${value}`).join(", ");
195
+ }
196
+ function isVariantProduct(product) {
197
+ return product.productType === "variant" || !!product.variants && product.variants.length > 0;
198
+ }
199
+ function getAvailableVariants(product) {
200
+ if (!product.variants) return [];
201
+ return product.variants.filter((v) => v.isActive);
202
+ }
203
+ function findVariantBySku(product, sku) {
204
+ if (!product.variants) return null;
205
+ return product.variants.find((v) => v.sku === sku) || null;
206
+ }
207
+ function getVariantStock(product, variantSku) {
208
+ if (!product.branchStock?.variants) return 0;
209
+ return product.branchStock.variants.find((v) => v.sku === variantSku)?.quantity || 0;
210
+ }
211
+ function isInStock(product, variantSku) {
212
+ if (variantSku) return getVariantStock(product, variantSku) > 0;
213
+ return product.branchStock?.inStock ?? false;
214
+ }
215
+ function getPosProductImage(product) {
216
+ const firstImage = product.images?.[0];
217
+ if (!firstImage) return "/placeholder.png";
218
+ return firstImage.variants?.thumbnail || firstImage.url;
219
+ }
220
+
221
+ //#endregion
222
+ export { POS_KEYS, calculateVariantPrice, findVariantBySku, formatVariantLabel, generateIdempotencyKey, getAvailableVariants, getPosProductImage, getVariantStock, isInStock, isVariantProduct, usePosLookup, usePosLookupMutation, usePosOrders, usePosProducts, usePosReceipt, usePosStockActions };