@open-mercato/core 0.7.1-develop.7123.1.25365e718d → 0.7.1-develop.7131.1.20abf9e885

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 (234) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/modules/audit_logs/api/audit-logs/actions/redo/route.js +5 -0
  3. package/dist/modules/audit_logs/api/audit-logs/actions/redo/route.js.map +2 -2
  4. package/dist/modules/auth/api/profile/route.js +5 -0
  5. package/dist/modules/auth/api/profile/route.js.map +2 -2
  6. package/dist/modules/customers/api/activities/route.js +13 -0
  7. package/dist/modules/customers/api/activities/route.js.map +2 -2
  8. package/dist/modules/customers/api/dictionaries/[kind]/[id]/route.js +9 -0
  9. package/dist/modules/customers/api/dictionaries/[kind]/[id]/route.js.map +2 -2
  10. package/dist/modules/customers/api/dictionaries/[kind]/route.js +5 -0
  11. package/dist/modules/customers/api/dictionaries/[kind]/route.js.map +2 -2
  12. package/dist/modules/customers/api/dictionaries/kind-settings/route.js +5 -0
  13. package/dist/modules/customers/api/dictionaries/kind-settings/route.js.map +2 -2
  14. package/dist/modules/customers/api/interactions/cancel/route.js +5 -0
  15. package/dist/modules/customers/api/interactions/cancel/route.js.map +2 -2
  16. package/dist/modules/customers/api/interactions/complete/route.js +5 -0
  17. package/dist/modules/customers/api/interactions/complete/route.js.map +2 -2
  18. package/dist/modules/customers/api/labels/assign/route.js +5 -0
  19. package/dist/modules/customers/api/labels/assign/route.js.map +2 -2
  20. package/dist/modules/customers/api/labels/route.js +5 -0
  21. package/dist/modules/customers/api/labels/route.js.map +2 -2
  22. package/dist/modules/customers/api/labels/unassign/route.js +5 -0
  23. package/dist/modules/customers/api/labels/unassign/route.js.map +2 -2
  24. package/dist/modules/customers/api/people/[id]/companies/[linkId]/route.js +9 -0
  25. package/dist/modules/customers/api/people/[id]/companies/[linkId]/route.js.map +2 -2
  26. package/dist/modules/customers/api/people/[id]/companies/route.js +5 -0
  27. package/dist/modules/customers/api/people/[id]/companies/route.js.map +2 -2
  28. package/dist/modules/customers/api/pipeline-stages/reorder/route.js +5 -0
  29. package/dist/modules/customers/api/pipeline-stages/reorder/route.js.map +2 -2
  30. package/dist/modules/customers/api/pipeline-stages/route.js +13 -0
  31. package/dist/modules/customers/api/pipeline-stages/route.js.map +2 -2
  32. package/dist/modules/customers/api/pipelines/route.js +13 -0
  33. package/dist/modules/customers/api/pipelines/route.js.map +2 -2
  34. package/dist/modules/customers/api/settings/address-format/route.js +5 -0
  35. package/dist/modules/customers/api/settings/address-format/route.js.map +2 -2
  36. package/dist/modules/customers/api/settings/dictionary-sort-modes/route.js +5 -0
  37. package/dist/modules/customers/api/settings/dictionary-sort-modes/route.js.map +2 -2
  38. package/dist/modules/customers/api/settings/stuck-threshold/route.js +5 -0
  39. package/dist/modules/customers/api/settings/stuck-threshold/route.js.map +2 -2
  40. package/dist/modules/customers/api/tags/assign/route.js +5 -0
  41. package/dist/modules/customers/api/tags/assign/route.js.map +2 -2
  42. package/dist/modules/customers/api/tags/unassign/route.js +5 -0
  43. package/dist/modules/customers/api/tags/unassign/route.js.map +2 -2
  44. package/dist/modules/customers/api/todos/route.js +13 -0
  45. package/dist/modules/customers/api/todos/route.js.map +2 -2
  46. package/dist/modules/customers/backend/customers/deals/[id]/hooks/useDealAssociations.js +5 -117
  47. package/dist/modules/customers/backend/customers/deals/[id]/hooks/useDealAssociations.js.map +2 -2
  48. package/dist/modules/customers/backend/customers/deals/[id]/page.js +1 -3
  49. package/dist/modules/customers/backend/customers/deals/[id]/page.js.map +2 -2
  50. package/dist/modules/customers/commands/deals.js +33 -9
  51. package/dist/modules/customers/commands/deals.js.map +3 -3
  52. package/dist/modules/customers/components/AddressEditor.js +71 -1
  53. package/dist/modules/customers/components/AddressEditor.js.map +2 -2
  54. package/dist/modules/customers/utils/addressFormat.js +18 -2
  55. package/dist/modules/customers/utils/addressFormat.js.map +2 -2
  56. package/dist/modules/dictionaries/api/[dictionaryId]/entries/[entryId]/route.js +9 -0
  57. package/dist/modules/dictionaries/api/[dictionaryId]/entries/[entryId]/route.js.map +2 -2
  58. package/dist/modules/dictionaries/api/[dictionaryId]/entries/reorder/route.js +5 -0
  59. package/dist/modules/dictionaries/api/[dictionaryId]/entries/reorder/route.js.map +2 -2
  60. package/dist/modules/dictionaries/api/[dictionaryId]/entries/route.js +5 -0
  61. package/dist/modules/dictionaries/api/[dictionaryId]/entries/route.js.map +2 -2
  62. package/dist/modules/dictionaries/api/[dictionaryId]/entries/set-default/route.js +5 -0
  63. package/dist/modules/dictionaries/api/[dictionaryId]/entries/set-default/route.js.map +2 -2
  64. package/dist/modules/directory/api/organization-branding/route.js +5 -0
  65. package/dist/modules/directory/api/organization-branding/route.js.map +2 -2
  66. package/dist/modules/eudr/api/plots/import/route.js.map +2 -2
  67. package/dist/modules/eudr/api/product-mappings/suggestions/apply/route.js.map +2 -2
  68. package/dist/modules/feature_toggles/api/overrides/route.js +5 -0
  69. package/dist/modules/feature_toggles/api/overrides/route.js.map +2 -2
  70. package/dist/modules/messages/api/[id]/actions/[actionId]/route.js +5 -0
  71. package/dist/modules/messages/api/[id]/actions/[actionId]/route.js.map +2 -2
  72. package/dist/modules/messages/api/[id]/conversation/archive/route.js +5 -0
  73. package/dist/modules/messages/api/[id]/conversation/archive/route.js.map +2 -2
  74. package/dist/modules/messages/api/[id]/conversation/read/route.js +5 -0
  75. package/dist/modules/messages/api/[id]/conversation/read/route.js.map +2 -2
  76. package/dist/modules/messages/api/[id]/conversation/route.js +5 -0
  77. package/dist/modules/messages/api/[id]/conversation/route.js.map +2 -2
  78. package/dist/modules/messages/api/[id]/forward/route.js +5 -0
  79. package/dist/modules/messages/api/[id]/forward/route.js.map +2 -2
  80. package/dist/modules/messages/api/[id]/reply/route.js +5 -0
  81. package/dist/modules/messages/api/[id]/reply/route.js.map +2 -2
  82. package/dist/modules/messages/api/[id]/route.js +9 -0
  83. package/dist/modules/messages/api/[id]/route.js.map +2 -2
  84. package/dist/modules/messages/api/token/[token]/route.js +5 -0
  85. package/dist/modules/messages/api/token/[token]/route.js.map +2 -2
  86. package/dist/modules/resources/api/resources/tags/assign/route.js +5 -0
  87. package/dist/modules/resources/api/resources/tags/assign/route.js.map +2 -2
  88. package/dist/modules/resources/api/resources/tags/unassign/route.js +5 -0
  89. package/dist/modules/resources/api/resources/tags/unassign/route.js.map +2 -2
  90. package/dist/modules/sales/api/quotes/accept/route.js +5 -0
  91. package/dist/modules/sales/api/quotes/accept/route.js.map +2 -2
  92. package/dist/modules/sales/api/quotes/convert/route.js +5 -0
  93. package/dist/modules/sales/api/quotes/convert/route.js.map +2 -2
  94. package/dist/modules/sales/api/settings/document-numbers/route.js +5 -0
  95. package/dist/modules/sales/api/settings/document-numbers/route.js.map +2 -2
  96. package/dist/modules/sales/api/settings/order-editing/route.js +5 -0
  97. package/dist/modules/sales/api/settings/order-editing/route.js.map +2 -2
  98. package/dist/modules/sales/components/documents/AddressesSection.js +17 -2
  99. package/dist/modules/sales/components/documents/AddressesSection.js.map +2 -2
  100. package/dist/modules/sales/components/documents/SalesDocumentForm.js +7 -24
  101. package/dist/modules/sales/components/documents/SalesDocumentForm.js.map +2 -2
  102. package/dist/modules/sales/components/documents/normalizeAddressDraft.js +29 -0
  103. package/dist/modules/sales/components/documents/normalizeAddressDraft.js.map +7 -0
  104. package/dist/modules/staff/api/leave-requests/accept/route.js +5 -0
  105. package/dist/modules/staff/api/leave-requests/accept/route.js.map +2 -2
  106. package/dist/modules/staff/api/leave-requests/reject/route.js +5 -0
  107. package/dist/modules/staff/api/leave-requests/reject/route.js.map +2 -2
  108. package/dist/modules/staff/api/team-members/self/route.js +5 -0
  109. package/dist/modules/staff/api/team-members/self/route.js.map +2 -2
  110. package/dist/modules/staff/api/team-members/tags/assign/route.js +5 -0
  111. package/dist/modules/staff/api/team-members/tags/assign/route.js.map +2 -2
  112. package/dist/modules/staff/api/team-members/tags/unassign/route.js +5 -0
  113. package/dist/modules/staff/api/team-members/tags/unassign/route.js.map +2 -2
  114. package/dist/modules/staff/api/timesheets/time-entries/start-timer/route.js +5 -0
  115. package/dist/modules/staff/api/timesheets/time-entries/start-timer/route.js.map +2 -2
  116. package/dist/modules/translations/api/[entityType]/[entityId]/route.js +9 -0
  117. package/dist/modules/translations/api/[entityType]/[entityId]/route.js.map +2 -2
  118. package/dist/modules/warranty_claims/api/ai/assess/route.js +5 -0
  119. package/dist/modules/warranty_claims/api/ai/assess/route.js.map +2 -2
  120. package/dist/modules/warranty_claims/api/assign/route.js +5 -0
  121. package/dist/modules/warranty_claims/api/assign/route.js.map +2 -2
  122. package/dist/modules/warranty_claims/api/credit-memo/route.js +5 -0
  123. package/dist/modules/warranty_claims/api/credit-memo/route.js.map +2 -2
  124. package/dist/modules/warranty_claims/api/events/route.js +5 -0
  125. package/dist/modules/warranty_claims/api/events/route.js.map +2 -2
  126. package/dist/modules/warranty_claims/api/portal/claims/[id]/submit/route.js +5 -0
  127. package/dist/modules/warranty_claims/api/portal/claims/[id]/submit/route.js.map +2 -2
  128. package/dist/modules/warranty_claims/api/portal/claims/[id]/withdraw/route.js +5 -0
  129. package/dist/modules/warranty_claims/api/portal/claims/[id]/withdraw/route.js.map +2 -2
  130. package/dist/modules/warranty_claims/api/portal/claims/route.js +5 -0
  131. package/dist/modules/warranty_claims/api/portal/claims/route.js.map +2 -2
  132. package/dist/modules/warranty_claims/api/portal/events/route.js +5 -0
  133. package/dist/modules/warranty_claims/api/portal/events/route.js.map +2 -2
  134. package/dist/modules/warranty_claims/api/receiving/route.js +5 -0
  135. package/dist/modules/warranty_claims/api/receiving/route.js.map +2 -2
  136. package/dist/modules/warranty_claims/api/replacement-order/route.js +5 -0
  137. package/dist/modules/warranty_claims/api/replacement-order/route.js.map +2 -2
  138. package/dist/modules/warranty_claims/api/return-label/route.js +5 -0
  139. package/dist/modules/warranty_claims/api/return-label/route.js.map +2 -2
  140. package/dist/modules/warranty_claims/api/sales-return/route.js +5 -0
  141. package/dist/modules/warranty_claims/api/sales-return/route.js.map +2 -2
  142. package/dist/modules/warranty_claims/api/settings-general/route.js +5 -0
  143. package/dist/modules/warranty_claims/api/settings-general/route.js.map +2 -2
  144. package/dist/modules/warranty_claims/api/submit/route.js +5 -0
  145. package/dist/modules/warranty_claims/api/submit/route.js.map +2 -2
  146. package/dist/modules/warranty_claims/api/transition/route.js +5 -0
  147. package/dist/modules/warranty_claims/api/transition/route.js.map +2 -2
  148. package/dist/modules/warranty_claims/api/vendor-recovery/route.js +5 -0
  149. package/dist/modules/warranty_claims/api/vendor-recovery/route.js.map +2 -2
  150. package/dist/modules/wms/api/sales-orders/[salesOrderId]/warehouse-assignment/route.js +5 -0
  151. package/dist/modules/wms/api/sales-orders/[salesOrderId]/warehouse-assignment/route.js.map +2 -2
  152. package/package.json +7 -7
  153. package/src/modules/audit_logs/api/audit-logs/actions/redo/route.ts +5 -0
  154. package/src/modules/auth/api/profile/route.ts +5 -0
  155. package/src/modules/customers/api/activities/route.ts +13 -0
  156. package/src/modules/customers/api/dictionaries/[kind]/[id]/route.ts +9 -0
  157. package/src/modules/customers/api/dictionaries/[kind]/route.ts +5 -0
  158. package/src/modules/customers/api/dictionaries/kind-settings/route.ts +5 -0
  159. package/src/modules/customers/api/interactions/cancel/route.ts +5 -0
  160. package/src/modules/customers/api/interactions/complete/route.ts +5 -0
  161. package/src/modules/customers/api/labels/assign/route.ts +5 -0
  162. package/src/modules/customers/api/labels/route.ts +5 -0
  163. package/src/modules/customers/api/labels/unassign/route.ts +5 -0
  164. package/src/modules/customers/api/people/[id]/companies/[linkId]/route.ts +9 -0
  165. package/src/modules/customers/api/people/[id]/companies/route.ts +5 -0
  166. package/src/modules/customers/api/pipeline-stages/reorder/route.ts +5 -0
  167. package/src/modules/customers/api/pipeline-stages/route.ts +13 -0
  168. package/src/modules/customers/api/pipelines/route.ts +13 -0
  169. package/src/modules/customers/api/settings/address-format/route.ts +5 -0
  170. package/src/modules/customers/api/settings/dictionary-sort-modes/route.ts +5 -0
  171. package/src/modules/customers/api/settings/stuck-threshold/route.ts +5 -0
  172. package/src/modules/customers/api/tags/assign/route.ts +5 -0
  173. package/src/modules/customers/api/tags/unassign/route.ts +5 -0
  174. package/src/modules/customers/api/todos/route.ts +13 -0
  175. package/src/modules/customers/backend/customers/deals/[id]/hooks/types.ts +0 -23
  176. package/src/modules/customers/backend/customers/deals/[id]/hooks/useDealAssociations.ts +11 -172
  177. package/src/modules/customers/backend/customers/deals/[id]/page.tsx +1 -1
  178. package/src/modules/customers/commands/deals.ts +84 -9
  179. package/src/modules/customers/components/AddressEditor.tsx +116 -1
  180. package/src/modules/customers/i18n/de.json +6 -0
  181. package/src/modules/customers/i18n/en.json +6 -0
  182. package/src/modules/customers/i18n/es.json +6 -0
  183. package/src/modules/customers/i18n/ko.json +6 -0
  184. package/src/modules/customers/i18n/pl.json +6 -0
  185. package/src/modules/customers/utils/addressFormat.tsx +59 -1
  186. package/src/modules/dictionaries/api/[dictionaryId]/entries/[entryId]/route.ts +9 -0
  187. package/src/modules/dictionaries/api/[dictionaryId]/entries/reorder/route.ts +5 -0
  188. package/src/modules/dictionaries/api/[dictionaryId]/entries/route.ts +5 -0
  189. package/src/modules/dictionaries/api/[dictionaryId]/entries/set-default/route.ts +5 -0
  190. package/src/modules/directory/api/organization-branding/route.ts +5 -0
  191. package/src/modules/eudr/api/plots/import/route.ts +7 -0
  192. package/src/modules/eudr/api/product-mappings/suggestions/apply/route.ts +7 -0
  193. package/src/modules/feature_toggles/api/overrides/route.ts +5 -0
  194. package/src/modules/messages/api/[id]/actions/[actionId]/route.ts +5 -0
  195. package/src/modules/messages/api/[id]/conversation/archive/route.ts +5 -0
  196. package/src/modules/messages/api/[id]/conversation/read/route.ts +5 -0
  197. package/src/modules/messages/api/[id]/conversation/route.ts +5 -0
  198. package/src/modules/messages/api/[id]/forward/route.ts +5 -0
  199. package/src/modules/messages/api/[id]/reply/route.ts +5 -0
  200. package/src/modules/messages/api/[id]/route.ts +9 -0
  201. package/src/modules/messages/api/token/[token]/route.ts +5 -0
  202. package/src/modules/resources/api/resources/tags/assign/route.ts +5 -0
  203. package/src/modules/resources/api/resources/tags/unassign/route.ts +5 -0
  204. package/src/modules/sales/api/quotes/accept/route.ts +5 -0
  205. package/src/modules/sales/api/quotes/convert/route.ts +5 -0
  206. package/src/modules/sales/api/settings/document-numbers/route.ts +5 -0
  207. package/src/modules/sales/api/settings/order-editing/route.ts +5 -0
  208. package/src/modules/sales/components/documents/AddressesSection.tsx +48 -5
  209. package/src/modules/sales/components/documents/SalesDocumentForm.tsx +5 -23
  210. package/src/modules/sales/components/documents/normalizeAddressDraft.ts +29 -0
  211. package/src/modules/staff/api/leave-requests/accept/route.ts +5 -0
  212. package/src/modules/staff/api/leave-requests/reject/route.ts +5 -0
  213. package/src/modules/staff/api/team-members/self/route.ts +5 -0
  214. package/src/modules/staff/api/team-members/tags/assign/route.ts +5 -0
  215. package/src/modules/staff/api/team-members/tags/unassign/route.ts +5 -0
  216. package/src/modules/staff/api/timesheets/time-entries/start-timer/route.ts +5 -0
  217. package/src/modules/translations/api/[entityType]/[entityId]/route.ts +9 -0
  218. package/src/modules/warranty_claims/api/ai/assess/route.ts +5 -0
  219. package/src/modules/warranty_claims/api/assign/route.ts +5 -0
  220. package/src/modules/warranty_claims/api/credit-memo/route.ts +5 -0
  221. package/src/modules/warranty_claims/api/events/route.ts +5 -0
  222. package/src/modules/warranty_claims/api/portal/claims/[id]/submit/route.ts +5 -0
  223. package/src/modules/warranty_claims/api/portal/claims/[id]/withdraw/route.ts +5 -0
  224. package/src/modules/warranty_claims/api/portal/claims/route.ts +5 -0
  225. package/src/modules/warranty_claims/api/portal/events/route.ts +5 -0
  226. package/src/modules/warranty_claims/api/receiving/route.ts +5 -0
  227. package/src/modules/warranty_claims/api/replacement-order/route.ts +5 -0
  228. package/src/modules/warranty_claims/api/return-label/route.ts +5 -0
  229. package/src/modules/warranty_claims/api/sales-return/route.ts +5 -0
  230. package/src/modules/warranty_claims/api/settings-general/route.ts +5 -0
  231. package/src/modules/warranty_claims/api/submit/route.ts +5 -0
  232. package/src/modules/warranty_claims/api/transition/route.ts +5 -0
  233. package/src/modules/warranty_claims/api/vendor-recovery/route.ts +5 -0
  234. package/src/modules/wms/api/sales-orders/[salesOrderId]/warehouse-assignment/route.ts +5 -0
@@ -1,5 +1,3 @@
1
- // @ts-nocheck
2
-
3
1
  "use client"
4
2
 
5
3
  import * as React from 'react'
@@ -72,17 +70,47 @@ const emptyDraft: AddressEditorDraft = {
72
70
  region: '',
73
71
  postalCode: '',
74
72
  country: '',
73
+ taxId: '',
74
+ taxIdType: '',
75
+ phone: '',
75
76
  isPrimary: false,
76
77
  }
77
78
 
78
79
  const EDITABLE_SNAPSHOT_KEYS = new Set(Object.keys(emptyDraft))
79
80
 
81
+ /**
82
+ * The fields the editor owns, typed, plus whatever else the caller's snapshot carried.
83
+ *
84
+ * The index signature is what lets an integration's extra keys — anything a future
85
+ * integration writes — survive the merge-back below, while the named fields stay `string` for callers
86
+ * that read them. `taxId` and `phone` are NOT among them any more: the editor renders both, so they
87
+ * are assigned from the draft like every other field. Reading
88
+ * `normalized.city` off a bare `Record<string, unknown>` yields `unknown`, which is what forced the
89
+ * `@ts-nocheck` on this file.
90
+ */
91
+ type NormalizedAddressDraft = {
92
+ name?: string
93
+ purpose?: string
94
+ companyName?: string
95
+ addressLine1?: string
96
+ addressLine2?: string
97
+ buildingNumber?: string
98
+ flatNumber?: string
99
+ city?: string
100
+ region?: string
101
+ postalCode?: string
102
+ country?: string
103
+ taxId?: string
104
+ phone?: string
105
+ isPrimary?: boolean
106
+ } & Record<string, unknown>
107
+
80
108
  function normalizeAddressDraft(
81
109
  draft?: AddressEditorDraft | null,
82
110
  previous?: Record<string, unknown> | null,
83
- ): Record<string, unknown> | null {
111
+ ): NormalizedAddressDraft | null {
84
112
  if (!draft) return null
85
- const normalized: Record<string, unknown> = {}
113
+ const normalized: NormalizedAddressDraft = {}
86
114
  let hasEditableContent = false
87
115
  const assign = (key: keyof AddressEditorDraft, target: string) => {
88
116
  const value = draft[key]
@@ -103,6 +131,9 @@ function normalizeAddressDraft(
103
131
  assign('region', 'region')
104
132
  assign('postalCode', 'postalCode')
105
133
  assign('country', 'country')
134
+ assign('taxId', 'taxId')
135
+ assign('taxIdType', 'taxIdType')
136
+ assign('phone', 'phone')
106
137
  assign('isPrimary', 'isPrimary')
107
138
  if (!hasEditableContent) return null
108
139
  if (previous) {
@@ -129,6 +160,9 @@ function draftFromSnapshot(snapshot?: Record<string, unknown> | null): AddressEd
129
160
  region: typeof record.region === 'string' ? record.region : '',
130
161
  postalCode: typeof record.postalCode === 'string' ? record.postalCode : '',
131
162
  country: typeof record.country === 'string' ? record.country : '',
163
+ taxId: typeof record.taxId === 'string' ? record.taxId : '',
164
+ taxIdType: typeof record.taxIdType === 'string' ? record.taxIdType : '',
165
+ phone: typeof record.phone === 'string' ? record.phone : '',
132
166
  isPrimary: record.isPrimary === true,
133
167
  }
134
168
  }
@@ -370,7 +404,10 @@ export function SalesDocumentAddressesSection({
370
404
  companyName: value.companyName ?? null,
371
405
  }
372
406
  })
373
- .filter((entry): entry is DocumentAddressAssignment => entry !== null)
407
+ // Narrow to non-null only. Asserting `DocumentAddressAssignment` here was wrong: its
408
+ // optional fields (`name?`, `purpose?`, …) admit `undefined`, which the mapped literal's
409
+ // `string | null` does not, so the predicate was not assignable to what it filtered.
410
+ .filter((entry): entry is NonNullable<typeof entry> => entry !== null)
374
411
  setDocumentAddresses(mapped)
375
412
  } else {
376
413
  setDocumentAddresses([])
@@ -1093,9 +1130,12 @@ export function SalesDocumentAddressesSection({
1093
1130
  <AddressEditor
1094
1131
  value={shippingDraft}
1095
1132
  format={addressFormat}
1133
+ showPhoneField
1134
+ showTaxIdField
1096
1135
  t={t as Translator}
1097
1136
  onChange={(next) => setShippingDraft(next)}
1098
1137
  hidePrimaryToggle
1138
+ disabled={locked}
1099
1139
  />
1100
1140
  <SwitchField
1101
1141
  label={t('sales.documents.form.address.saveToCustomer', 'Save this address to the customer')}
@@ -1160,9 +1200,12 @@ export function SalesDocumentAddressesSection({
1160
1200
  <AddressEditor
1161
1201
  value={billingDraft}
1162
1202
  format={addressFormat}
1203
+ showPhoneField
1204
+ showTaxIdField
1163
1205
  t={t as Translator}
1164
1206
  onChange={(next) => setBillingDraft(next)}
1165
1207
  hidePrimaryToggle
1208
+ disabled={locked}
1166
1209
  />
1167
1210
  <SwitchField
1168
1211
  label={t('sales.documents.form.address.saveToCustomer', 'Save this address to the customer')}
@@ -60,6 +60,7 @@ import { AddressEditor, type AddressEditorDraft } from '@open-mercato/core/modul
60
60
  import { useSalesChannelsEnabled } from '../useSalesChannelsEnabled'
61
61
  import { createLogger } from '@open-mercato/shared/lib/logger'
62
62
  import { SalesOrderDraftLines, createSalesOrderLineDraft, type SalesOrderLineDraft } from './SalesOrderDraftLines'
63
+ import { normalizeAddressDraft } from './normalizeAddressDraft'
63
64
 
64
65
  const logger = createLogger('sales')
65
66
 
@@ -435,29 +436,6 @@ function parseCustomerOptions(items: unknown[], kind: 'person' | 'company'): Cus
435
436
  return parsed
436
437
  }
437
438
 
438
- function normalizeAddressDraft(draft?: AddressDraft | null): Record<string, unknown> | null {
439
- if (!draft) return null
440
- const normalized: Record<string, unknown> = {}
441
- const assign = (key: keyof AddressDraft, target: string) => {
442
- const value = draft[key]
443
- if (typeof value === 'string' && value.trim().length) normalized[target] = value.trim()
444
- if (typeof value === 'boolean') normalized[target] = value
445
- }
446
- assign('name', 'name')
447
- assign('purpose', 'purpose')
448
- assign('companyName', 'companyName')
449
- assign('addressLine1', 'addressLine1')
450
- assign('addressLine2', 'addressLine2')
451
- assign('buildingNumber', 'buildingNumber')
452
- assign('flatNumber', 'flatNumber')
453
- assign('city', 'city')
454
- assign('region', 'region')
455
- assign('postalCode', 'postalCode')
456
- assign('country', 'country')
457
- assign('isPrimary', 'isPrimary')
458
- return Object.keys(normalized).length ? normalized : null
459
- }
460
-
461
439
  type DocumentNumberFieldProps = CrudCustomFieldRenderProps & { t: Translator }
462
440
 
463
441
  type BillingAddressSectionFieldProps = CrudCustomFieldRenderProps & {
@@ -655,6 +633,8 @@ function BillingAddressSectionField({ values, setFormValue, t, addressesLoading,
655
633
  t={t}
656
634
  onChange={(next) => updateValue('billingAddressDraft', next)}
657
635
  hidePrimaryToggle
636
+ showPhoneField
637
+ showTaxIdField
658
638
  />
659
639
  <SwitchField
660
640
  containerClassName="col-span-2"
@@ -1267,6 +1247,8 @@ export function SalesDocumentForm({ onCreated, isSubmitting = false, initialKind
1267
1247
  t={t}
1268
1248
  onChange={(next) => updateValue('shippingAddressDraft', next)}
1269
1249
  hidePrimaryToggle
1250
+ showPhoneField
1251
+ showTaxIdField
1270
1252
  />
1271
1253
  <SwitchField
1272
1254
  containerClassName="col-span-2"
@@ -0,0 +1,29 @@
1
+ import type { AddressEditorDraft } from '@open-mercato/core/modules/customers/components/AddressEditor'
2
+
3
+ export function normalizeAddressDraft(
4
+ draft?: AddressEditorDraft | null,
5
+ ): Record<string, unknown> | null {
6
+ if (!draft) return null
7
+ const normalized: Record<string, unknown> = {}
8
+ const assign = (key: keyof AddressEditorDraft, target: string) => {
9
+ const value = draft[key]
10
+ if (typeof value === 'string' && value.trim().length) normalized[target] = value.trim()
11
+ if (typeof value === 'boolean') normalized[target] = value
12
+ }
13
+ assign('name', 'name')
14
+ assign('purpose', 'purpose')
15
+ assign('companyName', 'companyName')
16
+ assign('addressLine1', 'addressLine1')
17
+ assign('addressLine2', 'addressLine2')
18
+ assign('buildingNumber', 'buildingNumber')
19
+ assign('flatNumber', 'flatNumber')
20
+ assign('city', 'city')
21
+ assign('region', 'region')
22
+ assign('postalCode', 'postalCode')
23
+ assign('country', 'country')
24
+ assign('taxId', 'taxId')
25
+ assign('taxIdType', 'taxIdType')
26
+ assign('phone', 'phone')
27
+ assign('isPrimary', 'isPrimary')
28
+ return Object.keys(normalized).length ? normalized : null
29
+ }
@@ -16,6 +16,7 @@ import {
16
16
  runStaffMutationGuards,
17
17
  } from '../../guards'
18
18
  import { createLogger } from '@open-mercato/shared/lib/logger'
19
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
19
20
 
20
21
  const logger = createLogger('staff')
21
22
 
@@ -112,6 +113,10 @@ export async function POST(req: Request) {
112
113
  if (isCrudHttpError(err)) {
113
114
  return NextResponse.json(err.body, { status: err.status })
114
115
  }
116
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
117
+ if (interceptorRejection) {
118
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
119
+ }
115
120
  const { translate } = await resolveTranslations()
116
121
  logger.error('staff.leave-requests.accept failed', { err })
117
122
  return NextResponse.json({ error: translate('staff.leaveRequests.errors.accept', 'Failed to approve leave request.') }, { status: 400 })
@@ -16,6 +16,7 @@ import {
16
16
  runStaffMutationGuards,
17
17
  } from '../../guards'
18
18
  import { createLogger } from '@open-mercato/shared/lib/logger'
19
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
19
20
 
20
21
  const logger = createLogger('staff')
21
22
 
@@ -112,6 +113,10 @@ export async function POST(req: Request) {
112
113
  if (isCrudHttpError(err)) {
113
114
  return NextResponse.json(err.body, { status: err.status })
114
115
  }
116
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
117
+ if (interceptorRejection) {
118
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
119
+ }
115
120
  const { translate } = await resolveTranslations()
116
121
  logger.error('staff.leave-requests.reject failed', { err })
117
122
  return NextResponse.json({ error: translate('staff.leaveRequests.errors.reject', 'Failed to reject leave request.') }, { status: 400 })
@@ -22,6 +22,7 @@ import {
22
22
  runStaffMutationGuards,
23
23
  } from '../../guards'
24
24
  import { createLogger } from '@open-mercato/shared/lib/logger'
25
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
25
26
 
26
27
  const logger = createLogger('staff')
27
28
 
@@ -185,6 +186,10 @@ export async function POST(req: Request) {
185
186
  if (isCrudHttpError(err)) {
186
187
  return NextResponse.json(err.body, { status: err.status })
187
188
  }
189
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
190
+ if (interceptorRejection) {
191
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
192
+ }
188
193
  const { translate } = await resolveTranslations()
189
194
  logger.error('staff.teamMembers.self.create failed', { err })
190
195
  return NextResponse.json({ error: translate('staff.teamMembers.form.errors.create', 'Failed to create team member.') }, { status: 400 })
@@ -19,6 +19,7 @@ import {
19
19
  runStaffMutationGuards,
20
20
  } from '../../../guards'
21
21
  import { createLogger } from '@open-mercato/shared/lib/logger'
22
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
22
23
 
23
24
  const logger = createLogger('staff')
24
25
 
@@ -115,6 +116,10 @@ export async function POST(req: Request) {
115
116
  if (isCrudHttpError(err)) {
116
117
  return NextResponse.json(err.body, { status: err.status })
117
118
  }
119
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
120
+ if (interceptorRejection) {
121
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
122
+ }
118
123
  const { translate } = await resolveTranslations()
119
124
  logger.error('staff.teamMembers.tags.assign failed', { err })
120
125
  return NextResponse.json({ error: translate('staff.teamMembers.tags.updateError', 'Failed to update tags.') }, { status: 400 })
@@ -19,6 +19,7 @@ import {
19
19
  runStaffMutationGuards,
20
20
  } from '../../../guards'
21
21
  import { createLogger } from '@open-mercato/shared/lib/logger'
22
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
22
23
 
23
24
  const logger = createLogger('staff')
24
25
 
@@ -115,6 +116,10 @@ export async function POST(req: Request) {
115
116
  if (isCrudHttpError(err)) {
116
117
  return NextResponse.json(err.body, { status: err.status })
117
118
  }
119
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
120
+ if (interceptorRejection) {
121
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
122
+ }
118
123
  const { translate } = await resolveTranslations()
119
124
  logger.error('staff.teamMembers.tags.unassign failed', { err })
120
125
  return NextResponse.json({ error: translate('staff.teamMembers.tags.updateError', 'Failed to update tags.') }, { status: 400 })
@@ -11,6 +11,7 @@ import { parseScopedCommandInput } from '@open-mercato/shared/lib/api/scoped'
11
11
  import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
12
12
  import { staffTimeEntryStartTimerSchema, type StaffTimeEntryStartTimerInput } from '../../../../data/validators'
13
13
  import { createLogger } from '@open-mercato/shared/lib/logger'
14
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
14
15
 
15
16
  const logger = createLogger('staff')
16
17
 
@@ -67,6 +68,10 @@ export async function POST(req: Request) {
67
68
  if (isCrudHttpError(err)) {
68
69
  return NextResponse.json(err.body, { status: err.status })
69
70
  }
71
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
72
+ if (interceptorRejection) {
73
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
74
+ }
70
75
  const { translate } = await resolveTranslations()
71
76
  logger.error('staff.timesheets.time-entries.start-timer failed', { err })
72
77
  return NextResponse.json(
@@ -13,6 +13,7 @@ import { serializeOperationMetadata } from '@open-mercato/shared/lib/commands/op
13
13
  import { enforceCommandOptimisticLockWithGuards } from '@open-mercato/shared/lib/crud/optimistic-lock-command'
14
14
  import type { OpenApiMethodDoc, OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
15
15
  import { createLogger } from '@open-mercato/shared/lib/logger'
16
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
16
17
 
17
18
  const logger = createLogger('translations').child({ component: 'entity-translations' })
18
19
 
@@ -226,6 +227,10 @@ export async function PUT(req: Request, ctx: { params?: { entityType?: string; e
226
227
  if (isCrudHttpError(err)) {
227
228
  return NextResponse.json(err.body, { status: err.status })
228
229
  }
230
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
231
+ if (interceptorRejection) {
232
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
233
+ }
229
234
  if (err instanceof z.ZodError) {
230
235
  return NextResponse.json({ error: 'Validation failed', details: err.issues }, { status: 400 })
231
236
  }
@@ -331,6 +336,10 @@ export async function DELETE(req: Request, ctx: { params?: { entityType?: string
331
336
  if (isCrudHttpError(err)) {
332
337
  return NextResponse.json(err.body, { status: err.status })
333
338
  }
339
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
340
+ if (interceptorRejection) {
341
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
342
+ }
334
343
  if (err instanceof z.ZodError) {
335
344
  return NextResponse.json({ error: 'Invalid parameters', details: err.issues }, { status: 400 })
336
345
  }
@@ -7,6 +7,7 @@ import { getAuthFromRequest, type AuthContext } from '@open-mercato/shared/lib/a
7
7
  import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
8
8
  import type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
9
9
  import { CrudHttpError, isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
10
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
10
11
  import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
11
12
  import { runRouteMutationGuards, type RouteMutationGuardResult } from '@open-mercato/shared/lib/crud/route-mutation-guard'
12
13
  import { withScopedPayload } from '@open-mercato/shared/lib/api/scoped'
@@ -338,6 +339,10 @@ export async function POST(req: Request) {
338
339
  return NextResponse.json({ status: 'ok', extraction })
339
340
  } catch (err) {
340
341
  if (isCrudHttpError(err)) return NextResponse.json(err.body, { status: err.status })
342
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
343
+ if (interceptorRejection) {
344
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
345
+ }
341
346
  if (isWarrantyAiNotConfiguredError(err)) {
342
347
  return NextResponse.json({ status: 'notConfigured' })
343
348
  }
@@ -6,6 +6,7 @@ import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/d
6
6
  import type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
7
7
  import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
8
8
  import { CrudHttpError, isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
9
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
9
10
  import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
10
11
  import { runRouteMutationGuards, type RouteMutationGuardResult } from '@open-mercato/shared/lib/crud/route-mutation-guard'
11
12
  import { withScopedPayload } from '@open-mercato/shared/lib/api/scoped'
@@ -114,6 +115,10 @@ export async function POST(req: Request) {
114
115
  return NextResponse.json({ ok: true, claimId: result?.claimId ?? commandInput.id })
115
116
  } catch (err) {
116
117
  if (isCrudHttpError(err)) return NextResponse.json(err.body, { status: err.status })
118
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
119
+ if (interceptorRejection) {
120
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
121
+ }
117
122
  const { translate } = await resolveTranslations()
118
123
  if (err instanceof z.ZodError) {
119
124
  return NextResponse.json({ error: translate('warranty_claims.errors.invalidInput', 'Invalid input') }, { status: 400 })
@@ -5,6 +5,7 @@ import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
5
5
  import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
6
6
  import type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
7
7
  import { CrudHttpError, isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
8
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
8
9
  import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
9
10
  import { runRouteMutationGuards, type RouteMutationGuardResult } from '@open-mercato/shared/lib/crud/route-mutation-guard'
10
11
  import { withScopedPayload } from '@open-mercato/shared/lib/api/scoped'
@@ -159,6 +160,10 @@ export async function POST(req: Request) {
159
160
  })
160
161
  } catch (err) {
161
162
  if (isCrudHttpError(err)) return NextResponse.json(err.body, { status: err.status })
163
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
164
+ if (interceptorRejection) {
165
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
166
+ }
162
167
  if (err instanceof z.ZodError) {
163
168
  return NextResponse.json({ error: 'warranty_claims.errors.invalidInput' }, { status: 400 })
164
169
  }
@@ -7,6 +7,7 @@ import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/d
7
7
  import type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
8
8
  import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
9
9
  import { CrudHttpError, isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
10
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
10
11
  import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
11
12
  import { runRouteMutationGuards, type RouteMutationGuardResult } from '@open-mercato/shared/lib/crud/route-mutation-guard'
12
13
  import { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'
@@ -175,6 +176,10 @@ export async function POST(req: Request) {
175
176
  return NextResponse.json({ ok: true, claimId: result?.claimId ?? commandInput.claimId })
176
177
  } catch (err) {
177
178
  if (isCrudHttpError(err)) return NextResponse.json(err.body, { status: err.status })
179
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
180
+ if (interceptorRejection) {
181
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
182
+ }
178
183
  const { translate } = await resolveTranslations()
179
184
  if (err instanceof z.ZodError) {
180
185
  return NextResponse.json({ error: translate('warranty_claims.errors.invalidInput', 'Invalid input') }, { status: 400 })
@@ -2,6 +2,7 @@ import { NextResponse } from 'next/server'
2
2
  import { z } from 'zod'
3
3
  import type { CommandBus } from '@open-mercato/shared/lib/commands'
4
4
  import { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
5
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
5
6
  import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
6
7
  import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
7
8
  import {
@@ -55,6 +56,10 @@ export async function POST(req: Request, ctx: PortalClaimActionRouteContext) {
55
56
  if (isCrudHttpError(err)) {
56
57
  return NextResponse.json(err.body, { status: err.status })
57
58
  }
59
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
60
+ if (interceptorRejection) {
61
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
62
+ }
58
63
  throw err
59
64
  }
60
65
 
@@ -2,6 +2,7 @@ import { NextResponse } from 'next/server'
2
2
  import { z } from 'zod'
3
3
  import type { CommandBus } from '@open-mercato/shared/lib/commands'
4
4
  import { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
5
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
5
6
  import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
6
7
  import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
7
8
  import type { TransitionClaimInput, WarrantyClaimStatus } from '../../../../../data/validators'
@@ -61,6 +62,10 @@ export async function POST(req: Request, ctx: PortalClaimActionRouteContext) {
61
62
  if (isCrudHttpError(err)) {
62
63
  return NextResponse.json(err.body, { status: err.status })
63
64
  }
65
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
66
+ if (interceptorRejection) {
67
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
68
+ }
64
69
  throw err
65
70
  }
66
71
 
@@ -5,6 +5,7 @@ import type { AuthContext } from '@open-mercato/shared/lib/auth/server'
5
5
  import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
6
6
  import type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
7
7
  import { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
8
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
8
9
  import { escapeLikePattern } from '@open-mercato/shared/lib/db/escapeLikePattern'
9
10
  import { runRouteMutationGuards, type RouteMutationGuardResult } from '@open-mercato/shared/lib/crud/route-mutation-guard'
10
11
  import { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'
@@ -522,6 +523,10 @@ export async function POST(req: Request) {
522
523
  if (isCrudHttpError(err)) {
523
524
  return NextResponse.json(err.body, { status: err.status })
524
525
  }
526
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
527
+ if (interceptorRejection) {
528
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
529
+ }
525
530
  throw err
526
531
  }
527
532
  }
@@ -5,6 +5,7 @@ import type { AuthContext } from '@open-mercato/shared/lib/auth/server'
5
5
  import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
6
6
  import type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
7
7
  import { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
8
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
8
9
  import { runRouteMutationGuards, type RouteMutationGuardResult } from '@open-mercato/shared/lib/crud/route-mutation-guard'
9
10
  import { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'
10
11
  import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
@@ -213,6 +214,10 @@ export async function POST(req: Request) {
213
214
  if (isCrudHttpError(err)) {
214
215
  return NextResponse.json(err.body, { status: err.status })
215
216
  }
217
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
218
+ if (interceptorRejection) {
219
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
220
+ }
216
221
  throw err
217
222
  }
218
223
 
@@ -5,6 +5,7 @@ import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
5
5
  import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
6
6
  import type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
7
7
  import { CrudHttpError, isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
8
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
8
9
  import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
9
10
  import { runRouteMutationGuards, type RouteMutationGuardResult } from '@open-mercato/shared/lib/crud/route-mutation-guard'
10
11
  import { withScopedPayload } from '@open-mercato/shared/lib/api/scoped'
@@ -184,6 +185,10 @@ export async function POST(req: Request) {
184
185
  return NextResponse.json({ ok: true, lineId: result.lineId, claimId: result.claimId })
185
186
  } catch (err) {
186
187
  if (isCrudHttpError(err)) return NextResponse.json(err.body, { status: err.status })
188
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
189
+ if (interceptorRejection) {
190
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
191
+ }
187
192
  if (err instanceof z.ZodError) {
188
193
  return NextResponse.json({ error: 'warranty_claims.errors.invalidInput' }, { status: 400 })
189
194
  }
@@ -5,6 +5,7 @@ import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
5
5
  import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
6
6
  import type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
7
7
  import { CrudHttpError, isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
8
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
8
9
  import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
9
10
  import { runRouteMutationGuards, type RouteMutationGuardResult } from '@open-mercato/shared/lib/crud/route-mutation-guard'
10
11
  import { withScopedPayload } from '@open-mercato/shared/lib/api/scoped'
@@ -156,6 +157,10 @@ export async function POST(req: Request) {
156
157
  })
157
158
  } catch (err) {
158
159
  if (isCrudHttpError(err)) return NextResponse.json(err.body, { status: err.status })
160
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
161
+ if (interceptorRejection) {
162
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
163
+ }
159
164
  if (err instanceof z.ZodError) {
160
165
  return NextResponse.json({ error: 'warranty_claims.errors.invalidInput' }, { status: 400 })
161
166
  }
@@ -6,6 +6,7 @@ import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
6
6
  import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
7
7
  import type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
8
8
  import { CrudHttpError, isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
9
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
9
10
  import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
10
11
  import { runRouteMutationGuards, type RouteMutationGuardResult } from '@open-mercato/shared/lib/crud/route-mutation-guard'
11
12
  import { withScopedPayload } from '@open-mercato/shared/lib/api/scoped'
@@ -264,6 +265,10 @@ export async function POST(req: Request) {
264
265
  return NextResponse.json(response)
265
266
  } catch (err) {
266
267
  if (isCrudHttpError(err)) return NextResponse.json(err.body, { status: err.status })
268
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
269
+ if (interceptorRejection) {
270
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
271
+ }
267
272
  if (err instanceof z.ZodError) {
268
273
  return NextResponse.json({ error: firstTranslatableIssueKey(err) }, { status: 400 })
269
274
  }
@@ -5,6 +5,7 @@ import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
5
5
  import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
6
6
  import type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
7
7
  import { CrudHttpError, isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
8
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
8
9
  import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
9
10
  import { runRouteMutationGuards, type RouteMutationGuardResult } from '@open-mercato/shared/lib/crud/route-mutation-guard'
10
11
  import { withScopedPayload } from '@open-mercato/shared/lib/api/scoped'
@@ -148,6 +149,10 @@ export async function POST(req: Request) {
148
149
  return NextResponse.json({ salesReturnId: result.salesReturnId, skippedLineIds: result.skippedLineIds })
149
150
  } catch (err) {
150
151
  if (isCrudHttpError(err)) return NextResponse.json(err.body, { status: err.status })
152
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
153
+ if (interceptorRejection) {
154
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
155
+ }
151
156
  if (err instanceof z.ZodError) {
152
157
  return NextResponse.json({ error: 'warranty_claims.errors.invalidInput' }, { status: 400 })
153
158
  }
@@ -7,6 +7,7 @@ import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/d
7
7
  import type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
8
8
  import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
9
9
  import { CrudHttpError, isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
10
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
10
11
  import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
11
12
  import { runRouteMutationGuards } from '@open-mercato/shared/lib/crud/route-mutation-guard'
12
13
  import { withScopedPayload } from '@open-mercato/shared/lib/api/scoped'
@@ -165,6 +166,10 @@ export async function PUT(req: Request) {
165
166
  })
166
167
  } catch (err) {
167
168
  if (isCrudHttpError(err)) return NextResponse.json(err.body, { status: err.status })
169
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
170
+ if (interceptorRejection) {
171
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
172
+ }
168
173
  const { translate } = await resolveTranslations()
169
174
  if (err instanceof z.ZodError) {
170
175
  return NextResponse.json({ error: translate('warranty_claims.errors.invalidInput', 'Invalid input') }, { status: 400 })
@@ -6,6 +6,7 @@ import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/d
6
6
  import type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
7
7
  import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
8
8
  import { CrudHttpError, isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
9
+ import { getCommandInterceptorHttpRejection } from '@open-mercato/shared/lib/commands/errors'
9
10
  import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
10
11
  import { runRouteMutationGuards, type RouteMutationGuardResult } from '@open-mercato/shared/lib/crud/route-mutation-guard'
11
12
  import { withScopedPayload } from '@open-mercato/shared/lib/api/scoped'
@@ -118,6 +119,10 @@ export async function POST(req: Request) {
118
119
  return NextResponse.json({ ok: true, claimId: result?.claimId ?? commandInput.id })
119
120
  } catch (err) {
120
121
  if (isCrudHttpError(err)) return NextResponse.json(err.body, { status: err.status })
122
+ const interceptorRejection = getCommandInterceptorHttpRejection(err)
123
+ if (interceptorRejection) {
124
+ return NextResponse.json(interceptorRejection.body, { status: interceptorRejection.status })
125
+ }
121
126
  const { translate } = await resolveTranslations()
122
127
  if (err instanceof z.ZodError) {
123
128
  return NextResponse.json({ error: translate('warranty_claims.errors.invalidInput', 'Invalid input') }, { status: 400 })