@open-mercato/core 0.10.1-develop.7709.1.046124599c → 0.10.1-develop.7714.1.9dbb8200d8

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 (276) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/dist/generated/entities/asn/index.js +19 -0
  3. package/dist/generated/entities/asn/index.js.map +7 -0
  4. package/dist/generated/entities/putaway_task/index.js +25 -0
  5. package/dist/generated/entities/putaway_task/index.js.map +7 -0
  6. package/dist/generated/entities/receiving_line/index.js +21 -0
  7. package/dist/generated/entities/receiving_line/index.js.map +7 -0
  8. package/dist/generated/entities.ids.generated.js +4 -1
  9. package/dist/generated/entities.ids.generated.js.map +2 -2
  10. package/dist/generated/entity-fields-registry.js +34 -0
  11. package/dist/generated/entity-fields-registry.js.map +2 -2
  12. package/dist/modules/communication_channels/lib/sanitize-channel-html.js +22 -3
  13. package/dist/modules/communication_channels/lib/sanitize-channel-html.js.map +2 -2
  14. package/dist/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.client.js +40 -11
  15. package/dist/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.client.js.map +2 -2
  16. package/dist/modules/customers/components/calendar/CalendarEventEditor.js +13 -2
  17. package/dist/modules/customers/components/calendar/CalendarEventEditor.js.map +2 -2
  18. package/dist/modules/wms/acl.js +2 -0
  19. package/dist/modules/wms/acl.js.map +2 -2
  20. package/dist/modules/wms/api/asns/[id]/complete/route.js +61 -0
  21. package/dist/modules/wms/api/asns/[id]/complete/route.js.map +7 -0
  22. package/dist/modules/wms/api/asns/[id]/receive/route.js +68 -0
  23. package/dist/modules/wms/api/asns/[id]/receive/route.js.map +7 -0
  24. package/dist/modules/wms/api/asns/route.js +197 -0
  25. package/dist/modules/wms/api/asns/route.js.map +7 -0
  26. package/dist/modules/wms/api/inventory/helpers.js +42 -34
  27. package/dist/modules/wms/api/inventory/helpers.js.map +2 -2
  28. package/dist/modules/wms/api/inventory/receive/route.js +1 -1
  29. package/dist/modules/wms/api/inventory/receive/route.js.map +2 -2
  30. package/dist/modules/wms/api/listEnrichers.js +23 -0
  31. package/dist/modules/wms/api/listEnrichers.js.map +2 -2
  32. package/dist/modules/wms/api/putaway-tasks/[id]/assign/route.js +56 -0
  33. package/dist/modules/wms/api/putaway-tasks/[id]/assign/route.js.map +7 -0
  34. package/dist/modules/wms/api/putaway-tasks/[id]/cancel/route.js +56 -0
  35. package/dist/modules/wms/api/putaway-tasks/[id]/cancel/route.js.map +7 -0
  36. package/dist/modules/wms/api/putaway-tasks/[id]/complete/route.js +65 -0
  37. package/dist/modules/wms/api/putaway-tasks/[id]/complete/route.js.map +7 -0
  38. package/dist/modules/wms/api/putaway-tasks/[id]/start/route.js +56 -0
  39. package/dist/modules/wms/api/putaway-tasks/[id]/start/route.js.map +7 -0
  40. package/dist/modules/wms/api/putaway-tasks/create-from-balance/route.js +51 -0
  41. package/dist/modules/wms/api/putaway-tasks/create-from-balance/route.js.map +7 -0
  42. package/dist/modules/wms/api/putaway-tasks/route.js +192 -0
  43. package/dist/modules/wms/api/putaway-tasks/route.js.map +7 -0
  44. package/dist/modules/wms/api/receiving-lines/route.js +180 -0
  45. package/dist/modules/wms/api/receiving-lines/route.js.map +7 -0
  46. package/dist/modules/wms/api/scan/putaway/route.js +104 -0
  47. package/dist/modules/wms/api/scan/putaway/route.js.map +7 -0
  48. package/dist/modules/wms/api/scan/receive/route.js +109 -0
  49. package/dist/modules/wms/api/scan/receive/route.js.map +7 -0
  50. package/dist/modules/wms/api/scan/resolve-location/route.js +89 -0
  51. package/dist/modules/wms/api/scan/resolve-location/route.js.map +7 -0
  52. package/dist/modules/wms/api/scan/resolve-lot/route.js +89 -0
  53. package/dist/modules/wms/api/scan/resolve-lot/route.js.map +7 -0
  54. package/dist/modules/wms/backend/wms/asns/[id]/page.js +9 -0
  55. package/dist/modules/wms/backend/wms/asns/[id]/page.js.map +7 -0
  56. package/dist/modules/wms/backend/wms/asns/[id]/page.meta.js +18 -0
  57. package/dist/modules/wms/backend/wms/asns/[id]/page.meta.js.map +7 -0
  58. package/dist/modules/wms/backend/wms/asns/page.js +9 -0
  59. package/dist/modules/wms/backend/wms/asns/page.js.map +7 -0
  60. package/dist/modules/wms/backend/wms/asns/page.meta.js +18 -0
  61. package/dist/modules/wms/backend/wms/asns/page.meta.js.map +7 -0
  62. package/dist/modules/wms/backend/wms/putaway/page.js +9 -0
  63. package/dist/modules/wms/backend/wms/putaway/page.js.map +7 -0
  64. package/dist/modules/wms/backend/wms/putaway/page.meta.js +18 -0
  65. package/dist/modules/wms/backend/wms/putaway/page.meta.js.map +7 -0
  66. package/dist/modules/wms/backend/wms/receiving/page.js +8 -0
  67. package/dist/modules/wms/backend/wms/receiving/page.js.map +7 -0
  68. package/dist/modules/wms/backend/wms/receiving/page.meta.js +18 -0
  69. package/dist/modules/wms/backend/wms/receiving/page.meta.js.map +7 -0
  70. package/dist/modules/wms/ce.js +27 -0
  71. package/dist/modules/wms/ce.js.map +2 -2
  72. package/dist/modules/wms/commands/asn.js +1746 -0
  73. package/dist/modules/wms/commands/asn.js.map +7 -0
  74. package/dist/modules/wms/commands/index.js +2 -0
  75. package/dist/modules/wms/commands/index.js.map +2 -2
  76. package/dist/modules/wms/commands/inventory-actions.js +347 -243
  77. package/dist/modules/wms/commands/inventory-actions.js.map +2 -2
  78. package/dist/modules/wms/commands/putaway.js +945 -0
  79. package/dist/modules/wms/commands/putaway.js.map +7 -0
  80. package/dist/modules/wms/commands/shared.js +51 -0
  81. package/dist/modules/wms/commands/shared.js.map +2 -2
  82. package/dist/modules/wms/components/backend/AssignPutawayTaskDialog.js +278 -0
  83. package/dist/modules/wms/components/backend/AssignPutawayTaskDialog.js.map +7 -0
  84. package/dist/modules/wms/components/backend/CompletePutawayTaskDialog.js +327 -0
  85. package/dist/modules/wms/components/backend/CompletePutawayTaskDialog.js.map +7 -0
  86. package/dist/modules/wms/components/backend/CreateAsnDialog.js +404 -0
  87. package/dist/modules/wms/components/backend/CreateAsnDialog.js.map +7 -0
  88. package/dist/modules/wms/components/backend/InventoryOperationsSection.js +16 -3
  89. package/dist/modules/wms/components/backend/InventoryOperationsSection.js.map +2 -2
  90. package/dist/modules/wms/components/backend/ReceiveAsnLineDialog.js +476 -0
  91. package/dist/modules/wms/components/backend/ReceiveAsnLineDialog.js.map +7 -0
  92. package/dist/modules/wms/components/backend/ReceiveInventoryDialog.js +2 -2
  93. package/dist/modules/wms/components/backend/ReceiveInventoryDialog.js.map +2 -2
  94. package/dist/modules/wms/components/backend/WmsAsnDetailPage.js +524 -0
  95. package/dist/modules/wms/components/backend/WmsAsnDetailPage.js.map +7 -0
  96. package/dist/modules/wms/components/backend/WmsAsnsListPage.js +339 -0
  97. package/dist/modules/wms/components/backend/WmsAsnsListPage.js.map +7 -0
  98. package/dist/modules/wms/components/backend/WmsLocationDetailPage.js +5 -6
  99. package/dist/modules/wms/components/backend/WmsLocationDetailPage.js.map +2 -2
  100. package/dist/modules/wms/components/backend/WmsLotDetailPage.js +5 -6
  101. package/dist/modules/wms/components/backend/WmsLotDetailPage.js.map +2 -2
  102. package/dist/modules/wms/components/backend/WmsOperationalDashboardPage.js +14 -10
  103. package/dist/modules/wms/components/backend/WmsOperationalDashboardPage.js.map +2 -2
  104. package/dist/modules/wms/components/backend/WmsPutawayQueuePage.js +598 -0
  105. package/dist/modules/wms/components/backend/WmsPutawayQueuePage.js.map +7 -0
  106. package/dist/modules/wms/components/backend/WmsSkuDetailPage.js +5 -6
  107. package/dist/modules/wms/components/backend/WmsSkuDetailPage.js.map +2 -2
  108. package/dist/modules/wms/components/backend/asnCompleteOptimisticLock.js +32 -0
  109. package/dist/modules/wms/components/backend/asnCompleteOptimisticLock.js.map +7 -0
  110. package/dist/modules/wms/components/backend/asnReceivingLinesLoader.js +36 -0
  111. package/dist/modules/wms/components/backend/asnReceivingLinesLoader.js.map +7 -0
  112. package/dist/modules/wms/components/backend/inboundStatusUi.js +106 -0
  113. package/dist/modules/wms/components/backend/inboundStatusUi.js.map +7 -0
  114. package/dist/modules/wms/components/backend/inventoryMutationLoaders.js +17 -0
  115. package/dist/modules/wms/components/backend/inventoryMutationLoaders.js.map +2 -2
  116. package/dist/modules/wms/components/backend/putawayQueueOptimisticLock.js +14 -0
  117. package/dist/modules/wms/components/backend/putawayQueueOptimisticLock.js.map +7 -0
  118. package/dist/modules/wms/components/backend/useWmsInventoryMutationAccess.js +4 -0
  119. package/dist/modules/wms/components/backend/useWmsInventoryMutationAccess.js.map +2 -2
  120. package/dist/modules/wms/data/enrichers.js +117 -12
  121. package/dist/modules/wms/data/enrichers.js.map +2 -2
  122. package/dist/modules/wms/data/entities.js +150 -1
  123. package/dist/modules/wms/data/entities.js.map +2 -2
  124. package/dist/modules/wms/data/validators.js +214 -0
  125. package/dist/modules/wms/data/validators.js.map +2 -2
  126. package/dist/modules/wms/events.js +12 -1
  127. package/dist/modules/wms/events.js.map +2 -2
  128. package/dist/modules/wms/extension-points.js +3 -1
  129. package/dist/modules/wms/extension-points.js.map +2 -2
  130. package/dist/modules/wms/lib/asnReceiving.js +124 -0
  131. package/dist/modules/wms/lib/asnReceiving.js.map +7 -0
  132. package/dist/modules/wms/lib/asnVendor.js +52 -0
  133. package/dist/modules/wms/lib/asnVendor.js.map +7 -0
  134. package/dist/modules/wms/lib/flashMutationError.js +4 -0
  135. package/dist/modules/wms/lib/flashMutationError.js.map +2 -2
  136. package/dist/modules/wms/lib/inventoryDisplayUi.js +24 -0
  137. package/dist/modules/wms/lib/inventoryDisplayUi.js.map +2 -2
  138. package/dist/modules/wms/lib/inventoryPolicy.js +17 -0
  139. package/dist/modules/wms/lib/inventoryPolicy.js.map +2 -2
  140. package/dist/modules/wms/lib/loadOperationalDashboard.js +67 -1
  141. package/dist/modules/wms/lib/loadOperationalDashboard.js.map +2 -2
  142. package/dist/modules/wms/lib/putaway.js +141 -0
  143. package/dist/modules/wms/lib/putaway.js.map +7 -0
  144. package/dist/modules/wms/lib/roleFeatures.js +3 -1
  145. package/dist/modules/wms/lib/roleFeatures.js.map +2 -2
  146. package/dist/modules/wms/lib/salesOrderInventoryAutomation.js +99 -1
  147. package/dist/modules/wms/lib/salesOrderInventoryAutomation.js.map +2 -2
  148. package/dist/modules/wms/lib/scanResolve.js +147 -0
  149. package/dist/modules/wms/lib/scanResolve.js.map +7 -0
  150. package/dist/modules/wms/lib/wmsIntegrationToggles.js +1 -1
  151. package/dist/modules/wms/lib/wmsIntegrationToggles.js.map +2 -2
  152. package/dist/modules/wms/migrations/Migration20260812120000.js +43 -0
  153. package/dist/modules/wms/migrations/Migration20260812120000.js.map +7 -0
  154. package/dist/modules/wms/migrations/Migration20260812130000.js +30 -0
  155. package/dist/modules/wms/migrations/Migration20260812130000.js.map +7 -0
  156. package/dist/modules/wms/migrations/Migration20260822120000.js +17 -0
  157. package/dist/modules/wms/migrations/Migration20260822120000.js.map +7 -0
  158. package/dist/modules/wms/migrations/Migration20260822130000.js +17 -0
  159. package/dist/modules/wms/migrations/Migration20260822130000.js.map +7 -0
  160. package/dist/modules/wms/migrations/Migration20261029120000.js +13 -0
  161. package/dist/modules/wms/migrations/Migration20261029120000.js.map +7 -0
  162. package/dist/modules/wms/search.js +85 -0
  163. package/dist/modules/wms/search.js.map +2 -2
  164. package/dist/modules/wms/subscribers/asn-line-received-reevaluate-reservations.js +14 -0
  165. package/dist/modules/wms/subscribers/asn-line-received-reevaluate-reservations.js.map +7 -0
  166. package/dist/modules/wms/subscribers/invalidate-enricher-cache-asn.js +12 -0
  167. package/dist/modules/wms/subscribers/invalidate-enricher-cache-asn.js.map +7 -0
  168. package/dist/modules/wms/subscribers/procurement-goods-receipt-created.js +163 -0
  169. package/dist/modules/wms/subscribers/procurement-goods-receipt-created.js.map +7 -0
  170. package/dist/modules/wms/subscribers/putaway-completed-reevaluate-reservations.js +14 -0
  171. package/dist/modules/wms/subscribers/putaway-completed-reevaluate-reservations.js.map +7 -0
  172. package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.client.js +37 -8
  173. package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.client.js.map +2 -2
  174. package/generated/entities/asn/index.ts +8 -0
  175. package/generated/entities/putaway_task/index.ts +11 -0
  176. package/generated/entities/receiving_line/index.ts +9 -0
  177. package/generated/entities.ids.generated.ts +4 -1
  178. package/generated/entity-fields-registry.ts +34 -0
  179. package/package.json +7 -7
  180. package/src/modules/auth/i18n/de.json +2 -0
  181. package/src/modules/auth/i18n/en.json +2 -0
  182. package/src/modules/auth/i18n/es.json +2 -0
  183. package/src/modules/auth/i18n/ko.json +2 -0
  184. package/src/modules/auth/i18n/pl.json +2 -0
  185. package/src/modules/communication_channels/i18n/de.json +2 -0
  186. package/src/modules/communication_channels/i18n/en.json +2 -0
  187. package/src/modules/communication_channels/i18n/es.json +2 -0
  188. package/src/modules/communication_channels/i18n/ko.json +2 -0
  189. package/src/modules/communication_channels/i18n/pl.json +2 -0
  190. package/src/modules/communication_channels/lib/sanitize-channel-html.ts +23 -3
  191. package/src/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.client.tsx +44 -12
  192. package/src/modules/customers/components/calendar/CalendarEventEditor.tsx +16 -2
  193. package/src/modules/wms/acl.ts +2 -0
  194. package/src/modules/wms/api/asns/[id]/complete/route.ts +62 -0
  195. package/src/modules/wms/api/asns/[id]/receive/route.ts +74 -0
  196. package/src/modules/wms/api/asns/route.ts +200 -0
  197. package/src/modules/wms/api/inventory/helpers.ts +57 -34
  198. package/src/modules/wms/api/inventory/receive/route.ts +2 -1
  199. package/src/modules/wms/api/listEnrichers.ts +38 -0
  200. package/src/modules/wms/api/putaway-tasks/[id]/assign/route.ts +56 -0
  201. package/src/modules/wms/api/putaway-tasks/[id]/cancel/route.ts +56 -0
  202. package/src/modules/wms/api/putaway-tasks/[id]/complete/route.ts +66 -0
  203. package/src/modules/wms/api/putaway-tasks/[id]/start/route.ts +56 -0
  204. package/src/modules/wms/api/putaway-tasks/create-from-balance/route.ts +50 -0
  205. package/src/modules/wms/api/putaway-tasks/route.ts +199 -0
  206. package/src/modules/wms/api/receiving-lines/route.ts +180 -0
  207. package/src/modules/wms/api/scan/putaway/route.ts +108 -0
  208. package/src/modules/wms/api/scan/receive/route.ts +118 -0
  209. package/src/modules/wms/api/scan/resolve-location/route.ts +92 -0
  210. package/src/modules/wms/api/scan/resolve-lot/route.ts +92 -0
  211. package/src/modules/wms/backend/wms/asns/[id]/page.meta.ts +14 -0
  212. package/src/modules/wms/backend/wms/asns/[id]/page.tsx +5 -0
  213. package/src/modules/wms/backend/wms/asns/page.meta.ts +14 -0
  214. package/src/modules/wms/backend/wms/asns/page.tsx +5 -0
  215. package/src/modules/wms/backend/wms/putaway/page.meta.ts +14 -0
  216. package/src/modules/wms/backend/wms/putaway/page.tsx +5 -0
  217. package/src/modules/wms/backend/wms/receiving/page.meta.ts +14 -0
  218. package/src/modules/wms/backend/wms/receiving/page.tsx +5 -0
  219. package/src/modules/wms/ce.ts +27 -0
  220. package/src/modules/wms/commands/asn.ts +2122 -0
  221. package/src/modules/wms/commands/index.ts +2 -0
  222. package/src/modules/wms/commands/inventory-actions.ts +413 -243
  223. package/src/modules/wms/commands/putaway.ts +1169 -0
  224. package/src/modules/wms/commands/shared.ts +51 -0
  225. package/src/modules/wms/components/backend/AssignPutawayTaskDialog.tsx +328 -0
  226. package/src/modules/wms/components/backend/CompletePutawayTaskDialog.tsx +366 -0
  227. package/src/modules/wms/components/backend/CreateAsnDialog.tsx +427 -0
  228. package/src/modules/wms/components/backend/InventoryOperationsSection.tsx +20 -2
  229. package/src/modules/wms/components/backend/ReceiveAsnLineDialog.tsx +535 -0
  230. package/src/modules/wms/components/backend/ReceiveInventoryDialog.tsx +2 -2
  231. package/src/modules/wms/components/backend/WmsAsnDetailPage.tsx +647 -0
  232. package/src/modules/wms/components/backend/WmsAsnsListPage.tsx +407 -0
  233. package/src/modules/wms/components/backend/WmsLocationDetailPage.tsx +4 -5
  234. package/src/modules/wms/components/backend/WmsLotDetailPage.tsx +4 -5
  235. package/src/modules/wms/components/backend/WmsOperationalDashboardPage.tsx +12 -8
  236. package/src/modules/wms/components/backend/WmsPutawayQueuePage.tsx +677 -0
  237. package/src/modules/wms/components/backend/WmsSkuDetailPage.tsx +4 -5
  238. package/src/modules/wms/components/backend/asnCompleteOptimisticLock.ts +52 -0
  239. package/src/modules/wms/components/backend/asnReceivingLinesLoader.ts +83 -0
  240. package/src/modules/wms/components/backend/inboundStatusUi.ts +154 -0
  241. package/src/modules/wms/components/backend/inventoryMutationLoaders.ts +20 -0
  242. package/src/modules/wms/components/backend/putawayQueueOptimisticLock.ts +20 -0
  243. package/src/modules/wms/components/backend/useWmsInventoryMutationAccess.ts +4 -0
  244. package/src/modules/wms/data/enrichers.ts +175 -13
  245. package/src/modules/wms/data/entities.ts +155 -0
  246. package/src/modules/wms/data/validators.ts +256 -0
  247. package/src/modules/wms/events.ts +11 -0
  248. package/src/modules/wms/extension-points.ts +2 -0
  249. package/src/modules/wms/i18n/de.json +205 -3
  250. package/src/modules/wms/i18n/en.json +205 -3
  251. package/src/modules/wms/i18n/es.json +205 -3
  252. package/src/modules/wms/i18n/ko.json +205 -3
  253. package/src/modules/wms/i18n/pl.json +205 -3
  254. package/src/modules/wms/lib/asnReceiving.ts +226 -0
  255. package/src/modules/wms/lib/asnVendor.ts +80 -0
  256. package/src/modules/wms/lib/flashMutationError.ts +4 -0
  257. package/src/modules/wms/lib/inventoryDisplayUi.ts +46 -0
  258. package/src/modules/wms/lib/inventoryPolicy.ts +31 -1
  259. package/src/modules/wms/lib/loadOperationalDashboard.ts +89 -1
  260. package/src/modules/wms/lib/putaway.ts +210 -0
  261. package/src/modules/wms/lib/roleFeatures.ts +2 -0
  262. package/src/modules/wms/lib/salesOrderInventoryAutomation.ts +150 -1
  263. package/src/modules/wms/lib/scanResolve.ts +185 -0
  264. package/src/modules/wms/lib/wmsIntegrationToggles.ts +2 -1
  265. package/src/modules/wms/migrations/.snapshot-open-mercato.json +1000 -0
  266. package/src/modules/wms/migrations/Migration20260812120000.ts +43 -0
  267. package/src/modules/wms/migrations/Migration20260812130000.ts +28 -0
  268. package/src/modules/wms/migrations/Migration20260822120000.ts +17 -0
  269. package/src/modules/wms/migrations/Migration20260822130000.ts +15 -0
  270. package/src/modules/wms/migrations/Migration20261029120000.ts +11 -0
  271. package/src/modules/wms/search.ts +95 -0
  272. package/src/modules/wms/subscribers/asn-line-received-reevaluate-reservations.ts +21 -0
  273. package/src/modules/wms/subscribers/invalidate-enricher-cache-asn.ts +12 -0
  274. package/src/modules/wms/subscribers/procurement-goods-receipt-created.ts +238 -0
  275. package/src/modules/wms/subscribers/putaway-completed-reevaluate-reservations.ts +21 -0
  276. package/src/modules/wms/widgets/injection/sales-order-stock-context/widget.client.tsx +63 -13
@@ -4,9 +4,12 @@ import { ensureOrganizationScope } from '@open-mercato/shared/lib/commands/scope
4
4
  import type { CrudIndexerConfig, CrudEventsConfig } from '@open-mercato/shared/lib/crud/types'
5
5
  import { E } from '#generated/entities.ids.generated'
6
6
  import {
7
+ Asn,
7
8
  InventoryBalance,
8
9
  InventoryMovement,
9
10
  InventoryReservation,
11
+ PutawayTask,
12
+ ReceivingLine,
10
13
  Warehouse,
11
14
  WarehouseZone,
12
15
  } from '../data/entities'
@@ -98,10 +101,58 @@ export const inventoryMovementCrudEvents: CrudEventsConfig<InventoryMovement> =
98
101
  }),
99
102
  }
100
103
 
104
+ export const asnCrudIndexer: CrudIndexerConfig<Asn> = {
105
+ entityType: E.wms.asn,
106
+ }
107
+
108
+ export const receivingLineCrudIndexer: CrudIndexerConfig<ReceivingLine> = {
109
+ entityType: E.wms.receiving_line,
110
+ }
111
+
112
+ export const asnCrudEvents: CrudEventsConfig<Asn> = {
113
+ module: 'wms',
114
+ entity: 'asn',
115
+ persistent: true,
116
+ buildPayload: (ctx) => ({
117
+ id: ctx.identifiers.id,
118
+ organizationId: ctx.identifiers.organizationId,
119
+ tenantId: ctx.identifiers.tenantId,
120
+ }),
121
+ }
122
+
123
+ export const receivingLineCrudEvents: CrudEventsConfig<ReceivingLine> = {
124
+ module: 'wms',
125
+ entity: 'receiving_line',
126
+ persistent: true,
127
+ buildPayload: (ctx) => ({
128
+ id: ctx.identifiers.id,
129
+ organizationId: ctx.identifiers.organizationId,
130
+ tenantId: ctx.identifiers.tenantId,
131
+ }),
132
+ }
133
+
134
+ export const putawayTaskCrudIndexer: CrudIndexerConfig<PutawayTask> = {
135
+ entityType: E.wms.putaway_task,
136
+ }
137
+
138
+ export const putawayTaskCrudEvents: CrudEventsConfig<PutawayTask> = {
139
+ module: 'wms',
140
+ entity: 'putaway_task',
141
+ persistent: true,
142
+ buildPayload: (ctx) => ({
143
+ id: ctx.identifiers.id,
144
+ organizationId: ctx.identifiers.organizationId,
145
+ tenantId: ctx.identifiers.tenantId,
146
+ }),
147
+ }
148
+
101
149
  // Cache alias resource kinds used to extend command-level cache invalidation
102
150
  // when a single mutation impacts multiple list resources.
103
151
  export const WMS_INVENTORY_BALANCE_RESOURCE = 'wms.inventoryBalance'
104
152
  export const WMS_INVENTORY_RESERVATION_RESOURCE = 'wms.inventoryReservation'
105
153
  export const WMS_INVENTORY_MOVEMENT_RESOURCE = 'wms.inventoryMovement'
154
+ export const WMS_ASN_RESOURCE = 'wms.asn'
155
+ export const WMS_RECEIVING_LINE_RESOURCE = 'wms.receivingLine'
156
+ export const WMS_PUTAWAY_TASK_RESOURCE = 'wms.putawayTask'
106
157
 
107
158
  export { ensureOrganizationScope }
@@ -0,0 +1,328 @@
1
+ "use client"
2
+
3
+ import * as React from 'react'
4
+ import { z } from 'zod'
5
+ import { flash } from '@open-mercato/ui/backend/FlashMessages'
6
+ import { flashMutationError } from '../../lib/flashMutationError'
7
+ import { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'
8
+ import { ComboboxInput } from '@open-mercato/ui/backend/inputs/ComboboxInput'
9
+ import { apiCall } from '@open-mercato/ui/backend/utils/apiCall'
10
+ import {
11
+ buildOptimisticLockHeader,
12
+ extractOptimisticLockConflict,
13
+ } from '@open-mercato/ui/backend/utils/optimisticLock'
14
+ import { raiseCrudError } from '@open-mercato/ui/backend/utils/serverErrors'
15
+ import { surfaceRecordConflict } from '@open-mercato/ui/backend/conflicts'
16
+ import { Button } from '@open-mercato/ui/primitives/button'
17
+ import {
18
+ Dialog,
19
+ DialogContent,
20
+ DialogDescription,
21
+ DialogFooter,
22
+ DialogHeader,
23
+ DialogTitle,
24
+ } from '@open-mercato/ui/primitives/dialog'
25
+ import { FormField } from '@open-mercato/ui/primitives/form-field'
26
+ import { KbdShortcut } from '@open-mercato/ui/primitives/kbd'
27
+ import { useT } from '@open-mercato/shared/lib/i18n/context'
28
+ import {
29
+ loadAssigneeOptions,
30
+ resolveAssigneeLabel,
31
+ } from './inventoryMutationLoaders'
32
+ import type { WmsInventoryMutationAccess } from './useWmsInventoryMutationAccess'
33
+
34
+ export type PutawayAssignTarget = {
35
+ id: string
36
+ assignedTo?: string | null
37
+ updatedAt?: string | null
38
+ }
39
+
40
+ type AssignPutawayTaskDialogProps = {
41
+ open: boolean
42
+ onOpenChange: (open: boolean) => void
43
+ access: WmsInventoryMutationAccess
44
+ task: PutawayAssignTarget | null
45
+ onSuccess?: () => void
46
+ onConflict?: (taskId: string, status: number, body: unknown) => void
47
+ }
48
+
49
+ const formSchema = z.object({
50
+ assignedTo: z.string().uuid(),
51
+ })
52
+
53
+ export function AssignPutawayTaskDialog({
54
+ open,
55
+ onOpenChange,
56
+ access,
57
+ task,
58
+ onSuccess,
59
+ onConflict,
60
+ }: AssignPutawayTaskDialogProps) {
61
+ const t = useT()
62
+ const { runMutation, retryLastMutation } = useGuardedMutation<{
63
+ retryLastMutation: () => Promise<boolean>
64
+ }>({
65
+ contextId: 'wms-putaway-assign',
66
+ })
67
+ const mutationContext = React.useMemo(
68
+ () => ({ retryLastMutation }),
69
+ [retryLastMutation],
70
+ )
71
+
72
+ const [assignedTo, setAssignedTo] = React.useState('')
73
+ const [optionLabels, setOptionLabels] = React.useState<Record<string, string>>({})
74
+ const [canListUsers, setCanListUsers] = React.useState(true)
75
+ const [fieldErrors, setFieldErrors] = React.useState<Record<string, string>>({})
76
+ const [submitting, setSubmitting] = React.useState(false)
77
+ const [lockUpdatedAt, setLockUpdatedAt] = React.useState<string | null>(null)
78
+ const lockUpdatedAtRef = React.useRef<string | null>(null)
79
+
80
+ const assigneeFallback = React.useMemo(() => {
81
+ const userId = access.userId?.trim()
82
+ if (!userId) return undefined
83
+ return {
84
+ userId,
85
+ label: t('wms.backend.putaway.assignee.me', 'Me'),
86
+ }
87
+ }, [access.userId, t])
88
+
89
+ const closeDialog = React.useCallback(() => {
90
+ if (submitting) return
91
+ onOpenChange(false)
92
+ }, [onOpenChange, submitting])
93
+
94
+ const registerOptionLabels = React.useCallback((options: Array<{ value: string; label: string }>) => {
95
+ setOptionLabels((prev) => {
96
+ const next = { ...prev }
97
+ for (const option of options) {
98
+ next[option.value] = option.label
99
+ }
100
+ return next
101
+ })
102
+ }, [])
103
+
104
+ React.useEffect(() => {
105
+ if (!open || !task) return
106
+ const seedAssignee = task.assignedTo?.trim() || access.userId?.trim() || ''
107
+ setAssignedTo(seedAssignee)
108
+ setFieldErrors({})
109
+ setSubmitting(false)
110
+ const seed = task.updatedAt ?? null
111
+ lockUpdatedAtRef.current = seed
112
+ setLockUpdatedAt(seed)
113
+ if (assigneeFallback) {
114
+ void loadAssigneeOptions(undefined, assigneeFallback).then((result) => {
115
+ setCanListUsers(result.canListUsers)
116
+ registerOptionLabels(result.options)
117
+ })
118
+ }
119
+ }, [access.userId, assigneeFallback, open, registerOptionLabels, task])
120
+
121
+ const resolveOptionLabel = React.useCallback(
122
+ (value: string) => {
123
+ if (!value) return ''
124
+ if (value === access.userId) return t('wms.backend.putaway.assignee.me', 'Me')
125
+ return optionLabels[value] || value
126
+ },
127
+ [access.userId, optionLabels, t],
128
+ )
129
+
130
+ const handleSubmit = React.useCallback(
131
+ async (event?: React.FormEvent) => {
132
+ event?.preventDefault()
133
+ if (!task) return
134
+ if (!access.scopeReady || !access.organizationId || !access.tenantId) {
135
+ flash(
136
+ t(
137
+ 'wms.backend.inventory.mutations.errors.scope',
138
+ 'Select an organization and sign in before posting inventory changes.',
139
+ ),
140
+ 'error',
141
+ )
142
+ return
143
+ }
144
+
145
+ const parsed = formSchema.safeParse({ assignedTo: assignedTo.trim() })
146
+ if (!parsed.success) {
147
+ setFieldErrors({
148
+ assignedTo: t('wms.backend.putaway.assign.errors.assignee', 'Select an assignee.'),
149
+ })
150
+ return
151
+ }
152
+ setFieldErrors({})
153
+ setSubmitting(true)
154
+
155
+ let conflictHandled = false
156
+ try {
157
+ await runMutation({
158
+ operation: async () => {
159
+ const call = await apiCall<{ ok?: boolean }>(
160
+ `/api/wms/putaway-tasks/${encodeURIComponent(task.id)}/assign`,
161
+ {
162
+ method: 'POST',
163
+ headers: {
164
+ 'content-type': 'application/json',
165
+ ...buildOptimisticLockHeader(lockUpdatedAtRef.current ?? undefined),
166
+ },
167
+ body: JSON.stringify({
168
+ organizationId: access.organizationId,
169
+ tenantId: access.tenantId,
170
+ assignedTo: parsed.data.assignedTo,
171
+ }),
172
+ },
173
+ )
174
+ if (!call.ok) {
175
+ const refreshLockFromConflict = () => {
176
+ const conflict = extractOptimisticLockConflict({
177
+ status: call.status,
178
+ body: call.result,
179
+ })
180
+ if (conflict?.currentUpdatedAt) {
181
+ lockUpdatedAtRef.current = conflict.currentUpdatedAt
182
+ setLockUpdatedAt(conflict.currentUpdatedAt)
183
+ }
184
+ onConflict?.(task.id, call.status, call.result)
185
+ }
186
+ if (
187
+ surfaceRecordConflict({ status: call.status, body: call.result }, t, {
188
+ onRefresh: refreshLockFromConflict,
189
+ })
190
+ ) {
191
+ refreshLockFromConflict()
192
+ conflictHandled = true
193
+ return {}
194
+ }
195
+ await raiseCrudError(
196
+ call.response,
197
+ t('wms.backend.putaway.errors.action', 'Failed to update putaway task.'),
198
+ )
199
+ }
200
+ return call.result ?? {}
201
+ },
202
+ context: mutationContext,
203
+ mutationPayload: { assignedTo: parsed.data.assignedTo },
204
+ })
205
+ if (conflictHandled) return
206
+ flash(t('wms.backend.putaway.flash.assigned', 'Putaway task assigned'), 'success')
207
+ onSuccess?.()
208
+ closeDialog()
209
+ } catch (error) {
210
+ flashMutationError(error, t('wms.backend.putaway.errors.action', 'Failed to update putaway task.'), t)
211
+ } finally {
212
+ setSubmitting(false)
213
+ }
214
+ },
215
+ [
216
+ access.organizationId,
217
+ access.scopeReady,
218
+ access.tenantId,
219
+ assignedTo,
220
+ closeDialog,
221
+ mutationContext,
222
+ onConflict,
223
+ onSuccess,
224
+ runMutation,
225
+ t,
226
+ task,
227
+ ],
228
+ )
229
+
230
+ const handleKeyDown = React.useCallback(
231
+ (event: React.KeyboardEvent) => {
232
+ if (event.key === 'Escape') {
233
+ event.preventDefault()
234
+ closeDialog()
235
+ return
236
+ }
237
+ if ((event.metaKey || event.ctrlKey) && event.key === 'Enter' && !submitting) {
238
+ event.preventDefault()
239
+ void handleSubmit()
240
+ }
241
+ },
242
+ [closeDialog, handleSubmit, submitting],
243
+ )
244
+
245
+ return (
246
+ <Dialog open={open} onOpenChange={(next) => (next ? onOpenChange(true) : closeDialog())}>
247
+ <DialogContent className="max-w-lg gap-0 overflow-hidden p-0" onKeyDown={handleKeyDown}>
248
+ <div className="border-b px-6 py-4 pr-12">
249
+ <DialogHeader className="space-y-1 text-left">
250
+ <DialogTitle>{t('wms.backend.putaway.assign.dialog.title', 'Assign putaway task')}</DialogTitle>
251
+ <DialogDescription>
252
+ {t(
253
+ 'wms.backend.putaway.assign.dialog.description',
254
+ 'Choose who should complete this putaway task.',
255
+ )}
256
+ </DialogDescription>
257
+ </DialogHeader>
258
+ </div>
259
+
260
+ <form onSubmit={(event) => void handleSubmit(event)} className="flex min-h-0 flex-1 flex-col">
261
+ <div className="space-y-4 overflow-y-auto px-6 py-6">
262
+ <FormField
263
+ label={t('wms.backend.putaway.columns.assignee', 'Assignee')}
264
+ required
265
+ error={fieldErrors.assignedTo}
266
+ >
267
+ {canListUsers ? (
268
+ <ComboboxInput
269
+ value={assignedTo}
270
+ onChange={(next) => setAssignedTo(next.trim())}
271
+ loadSuggestions={async (query) => {
272
+ const result = await loadAssigneeOptions(query, assigneeFallback)
273
+ setCanListUsers(result.canListUsers)
274
+ registerOptionLabels(result.options)
275
+ return result.options.map((option) => ({
276
+ value: option.value,
277
+ label: option.label,
278
+ }))
279
+ }}
280
+ resolveLabel={(value) => {
281
+ const known = resolveOptionLabel(value)
282
+ if (known && known !== value) return known
283
+ return resolveAssigneeLabel(value).then((label) => label ?? value)
284
+ }}
285
+ placeholder={t(
286
+ 'wms.backend.putaway.assign.dialog.assigneePlaceholder',
287
+ 'Select assignee',
288
+ )}
289
+ allowCustomValues={false}
290
+ disabled={submitting}
291
+ />
292
+ ) : (
293
+ <div className="rounded-md border bg-muted/40 px-3 py-2.5 text-sm text-foreground">
294
+ {resolveOptionLabel(assignedTo) || assignedTo}
295
+ </div>
296
+ )}
297
+ {!canListUsers ? (
298
+ <p className="mt-1 text-xs text-muted-foreground">
299
+ {t(
300
+ 'wms.backend.putaway.assign.dialog.assigneeLocked',
301
+ 'Only the current user can be assigned without user-directory access.',
302
+ )}
303
+ </p>
304
+ ) : null}
305
+ </FormField>
306
+ {lockUpdatedAt ? (
307
+ <span className="sr-only" data-testid="assign-putaway-lock-token">
308
+ {lockUpdatedAt}
309
+ </span>
310
+ ) : null}
311
+ </div>
312
+
313
+ <DialogFooter bordered={false} className="border-t px-6 py-4 sm:justify-between">
314
+ <KbdShortcut keys={['Ctrl/⌘', 'Enter']} />
315
+ <div className="flex gap-2">
316
+ <Button type="button" variant="outline" onClick={closeDialog} disabled={submitting}>
317
+ {t('ui.actions.cancel', 'Cancel')}
318
+ </Button>
319
+ <Button type="submit" disabled={submitting || !assignedTo.trim()}>
320
+ {t('wms.backend.putaway.actions.assign', 'Assign')}
321
+ </Button>
322
+ </div>
323
+ </DialogFooter>
324
+ </form>
325
+ </DialogContent>
326
+ </Dialog>
327
+ )
328
+ }