@open-mercato/core 0.6.4-develop.4217.1.c9aa050183 → 0.6.4-develop.4236.1.9fa6806b34

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 (370) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/dist/generated/entities/staff_time_entry/index.js +37 -0
  3. package/dist/generated/entities/staff_time_entry/index.js.map +7 -0
  4. package/dist/generated/entities/staff_time_entry_segment/index.js +23 -0
  5. package/dist/generated/entities/staff_time_entry_segment/index.js.map +7 -0
  6. package/dist/generated/entities/staff_time_project/index.js +35 -0
  7. package/dist/generated/entities/staff_time_project/index.js.map +7 -0
  8. package/dist/generated/entities/staff_time_project_member/index.js +29 -0
  9. package/dist/generated/entities/staff_time_project_member/index.js.map +7 -0
  10. package/dist/generated/entities.ids.generated.js +5 -1
  11. package/dist/generated/entities.ids.generated.js.map +2 -2
  12. package/dist/generated/entity-fields-registry.js +64 -0
  13. package/dist/generated/entity-fields-registry.js.map +2 -2
  14. package/dist/helpers/integration/timesheetFixtures.js +50 -0
  15. package/dist/helpers/integration/timesheetFixtures.js.map +7 -0
  16. package/dist/modules/attachments/api/library/[id]/route.js +20 -16
  17. package/dist/modules/attachments/api/library/[id]/route.js.map +2 -2
  18. package/dist/modules/attachments/api/route.js +18 -14
  19. package/dist/modules/attachments/api/route.js.map +2 -2
  20. package/dist/modules/auth/api/roles/acl/route.js +10 -4
  21. package/dist/modules/auth/api/roles/acl/route.js.map +2 -2
  22. package/dist/modules/auth/api/sidebar/preferences/route.js +27 -20
  23. package/dist/modules/auth/api/sidebar/preferences/route.js.map +2 -2
  24. package/dist/modules/auth/api/users/acl/route.js +16 -11
  25. package/dist/modules/auth/api/users/acl/route.js.map +2 -2
  26. package/dist/modules/auth/commands/users.js +87 -71
  27. package/dist/modules/auth/commands/users.js.map +2 -2
  28. package/dist/modules/auth/services/sidebarPreferencesService.js +39 -30
  29. package/dist/modules/auth/services/sidebarPreferencesService.js.map +2 -2
  30. package/dist/modules/catalog/commands/categories.js +61 -12
  31. package/dist/modules/catalog/commands/categories.js.map +2 -2
  32. package/dist/modules/catalog/commands/products.js +79 -54
  33. package/dist/modules/catalog/commands/products.js.map +2 -2
  34. package/dist/modules/catalog/commands/variants.js +29 -16
  35. package/dist/modules/catalog/commands/variants.js.map +2 -2
  36. package/dist/modules/currencies/commands/currencies.js +15 -8
  37. package/dist/modules/currencies/commands/currencies.js.map +2 -2
  38. package/dist/modules/customer_accounts/api/admin/users.js +27 -26
  39. package/dist/modules/customer_accounts/api/admin/users.js.map +2 -2
  40. package/dist/modules/customer_accounts/api/password/reset-confirm.js +5 -5
  41. package/dist/modules/customer_accounts/api/password/reset-confirm.js.map +2 -2
  42. package/dist/modules/customer_accounts/api/portal/users/[id]/roles.js +11 -10
  43. package/dist/modules/customer_accounts/api/portal/users/[id]/roles.js.map +2 -2
  44. package/dist/modules/customers/commands/addresses.js +35 -21
  45. package/dist/modules/customers/commands/addresses.js.map +2 -2
  46. package/dist/modules/customers/commands/companies.js +163 -162
  47. package/dist/modules/customers/commands/companies.js.map +2 -2
  48. package/dist/modules/customers/commands/deals.js +3 -4
  49. package/dist/modules/customers/commands/deals.js.map +2 -2
  50. package/dist/modules/customers/commands/interactions.js +19 -22
  51. package/dist/modules/customers/commands/interactions.js.map +2 -2
  52. package/dist/modules/customers/commands/people.js +18 -15
  53. package/dist/modules/customers/commands/people.js.map +2 -2
  54. package/dist/modules/customers/commands/personCompanyLinks.js +105 -94
  55. package/dist/modules/customers/commands/personCompanyLinks.js.map +2 -2
  56. package/dist/modules/customers/commands/pipeline-stages.js +30 -23
  57. package/dist/modules/customers/commands/pipeline-stages.js.map +2 -2
  58. package/dist/modules/customers/commands/pipelines.js +27 -20
  59. package/dist/modules/customers/commands/pipelines.js.map +2 -2
  60. package/dist/modules/customers/commands/tags.js +13 -5
  61. package/dist/modules/customers/commands/tags.js.map +2 -2
  62. package/dist/modules/dashboards/api/users/widgets/route.js +0 -1
  63. package/dist/modules/dashboards/api/users/widgets/route.js.map +2 -2
  64. package/dist/modules/dashboards/api/widgets/data/route.js +29 -1
  65. package/dist/modules/dashboards/api/widgets/data/route.js.map +2 -2
  66. package/dist/modules/data_sync/lib/sync-engine.js +4 -4
  67. package/dist/modules/data_sync/lib/sync-engine.js.map +2 -2
  68. package/dist/modules/data_sync/lib/sync-run-service.js +51 -27
  69. package/dist/modules/data_sync/lib/sync-run-service.js.map +2 -2
  70. package/dist/modules/directory/commands/organizations.js +192 -158
  71. package/dist/modules/directory/commands/organizations.js.map +3 -3
  72. package/dist/modules/inbox_ops/api/emails/[id]/reprocess/route.js +22 -16
  73. package/dist/modules/inbox_ops/api/emails/[id]/reprocess/route.js.map +2 -2
  74. package/dist/modules/messages/commands/messages.js +77 -75
  75. package/dist/modules/messages/commands/messages.js.map +2 -2
  76. package/dist/modules/messages/commands/shared.js +132 -132
  77. package/dist/modules/messages/commands/shared.js.map +2 -2
  78. package/dist/modules/perspectives/api/[tableId]/route.js +37 -26
  79. package/dist/modules/perspectives/api/[tableId]/route.js.map +2 -2
  80. package/dist/modules/resources/commands/resources.js +125 -117
  81. package/dist/modules/resources/commands/resources.js.map +2 -2
  82. package/dist/modules/resources/commands/tags.js +7 -3
  83. package/dist/modules/resources/commands/tags.js.map +2 -2
  84. package/dist/modules/sales/api/quotes/send/route.js +12 -11
  85. package/dist/modules/sales/api/quotes/send/route.js.map +2 -2
  86. package/dist/modules/sales/commands/documents.js +629 -478
  87. package/dist/modules/sales/commands/documents.js.map +2 -2
  88. package/dist/modules/sales/commands/payments.js +146 -146
  89. package/dist/modules/sales/commands/payments.js.map +2 -2
  90. package/dist/modules/sales/commands/returns.js +68 -60
  91. package/dist/modules/sales/commands/returns.js.map +2 -2
  92. package/dist/modules/staff/acl.js +10 -1
  93. package/dist/modules/staff/acl.js.map +2 -2
  94. package/dist/modules/staff/analytics.js +33 -0
  95. package/dist/modules/staff/analytics.js.map +7 -0
  96. package/dist/modules/staff/api/guards.js +31 -0
  97. package/dist/modules/staff/api/guards.js.map +7 -0
  98. package/dist/modules/staff/api/interceptors.js +96 -0
  99. package/dist/modules/staff/api/interceptors.js.map +7 -0
  100. package/dist/modules/staff/api/timesheets/my-projects/[projectId]/route.js +170 -0
  101. package/dist/modules/staff/api/timesheets/my-projects/[projectId]/route.js.map +7 -0
  102. package/dist/modules/staff/api/timesheets/my-projects/route.js +103 -0
  103. package/dist/modules/staff/api/timesheets/my-projects/route.js.map +7 -0
  104. package/dist/modules/staff/api/timesheets/projects/kpis/route.js +147 -0
  105. package/dist/modules/staff/api/timesheets/projects/kpis/route.js.map +7 -0
  106. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/[segmentId]/route.js +171 -0
  107. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/[segmentId]/route.js.map +7 -0
  108. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/route.js +180 -0
  109. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/route.js.map +7 -0
  110. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.js +155 -0
  111. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.js.map +7 -0
  112. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-stop/route.js +173 -0
  113. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-stop/route.js.map +7 -0
  114. package/dist/modules/staff/api/timesheets/time-entries/bulk/route.js +260 -0
  115. package/dist/modules/staff/api/timesheets/time-entries/bulk/route.js.map +7 -0
  116. package/dist/modules/staff/api/timesheets/time-entries/route.js +188 -0
  117. package/dist/modules/staff/api/timesheets/time-entries/route.js.map +7 -0
  118. package/dist/modules/staff/api/timesheets/time-projects/[id]/employees/route.js +159 -0
  119. package/dist/modules/staff/api/timesheets/time-projects/[id]/employees/route.js.map +7 -0
  120. package/dist/modules/staff/api/timesheets/time-projects/route.js +230 -0
  121. package/dist/modules/staff/api/timesheets/time-projects/route.js.map +7 -0
  122. package/dist/modules/staff/backend/staff/timesheets/page.js +710 -0
  123. package/dist/modules/staff/backend/staff/timesheets/page.js.map +7 -0
  124. package/dist/modules/staff/backend/staff/timesheets/page.meta.js +22 -0
  125. package/dist/modules/staff/backend/staff/timesheets/page.meta.js.map +7 -0
  126. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.js +125 -0
  127. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.js.map +7 -0
  128. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.meta.js +16 -0
  129. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.meta.js.map +7 -0
  130. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.js +418 -0
  131. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.js.map +7 -0
  132. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.meta.js +16 -0
  133. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.meta.js.map +7 -0
  134. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.js +79 -0
  135. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.js.map +7 -0
  136. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.meta.js +16 -0
  137. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.meta.js.map +7 -0
  138. package/dist/modules/staff/backend/staff/timesheets/projects/page.js +602 -0
  139. package/dist/modules/staff/backend/staff/timesheets/projects/page.js.map +7 -0
  140. package/dist/modules/staff/backend/staff/timesheets/projects/page.meta.js +25 -0
  141. package/dist/modules/staff/backend/staff/timesheets/projects/page.meta.js.map +7 -0
  142. package/dist/modules/staff/backend/staff/timesheets/projects/projectFormConfig.js +123 -0
  143. package/dist/modules/staff/backend/staff/timesheets/projects/projectFormConfig.js.map +7 -0
  144. package/dist/modules/staff/cli.js +38 -1
  145. package/dist/modules/staff/cli.js.map +2 -2
  146. package/dist/modules/staff/commands/index.js +2 -0
  147. package/dist/modules/staff/commands/index.js.map +2 -2
  148. package/dist/modules/staff/commands/leave-requests.js +30 -28
  149. package/dist/modules/staff/commands/leave-requests.js.map +3 -3
  150. package/dist/modules/staff/commands/team-members.js +21 -20
  151. package/dist/modules/staff/commands/team-members.js.map +2 -2
  152. package/dist/modules/staff/commands/timesheets-entries.js +409 -0
  153. package/dist/modules/staff/commands/timesheets-entries.js.map +7 -0
  154. package/dist/modules/staff/commands/timesheets-projects.js +618 -0
  155. package/dist/modules/staff/commands/timesheets-projects.js.map +7 -0
  156. package/dist/modules/staff/data/enrichers.js +104 -0
  157. package/dist/modules/staff/data/enrichers.js.map +7 -0
  158. package/dist/modules/staff/data/entities.js +226 -1
  159. package/dist/modules/staff/data/entities.js.map +2 -2
  160. package/dist/modules/staff/data/validators.js +113 -1
  161. package/dist/modules/staff/data/validators.js.map +2 -2
  162. package/dist/modules/staff/events.js +13 -1
  163. package/dist/modules/staff/events.js.map +2 -2
  164. package/dist/modules/staff/lib/crud.js +7 -1
  165. package/dist/modules/staff/lib/crud.js.map +2 -2
  166. package/dist/modules/staff/lib/staffMemberResolver.js +15 -0
  167. package/dist/modules/staff/lib/staffMemberResolver.js.map +7 -0
  168. package/dist/modules/staff/lib/timesheets-projects/computeProjectHoursTrend.js +60 -0
  169. package/dist/modules/staff/lib/timesheets-projects/computeProjectHoursTrend.js.map +7 -0
  170. package/dist/modules/staff/lib/timesheets-projects/computeProjectsKpis.js +260 -0
  171. package/dist/modules/staff/lib/timesheets-projects/computeProjectsKpis.js.map +7 -0
  172. package/dist/modules/staff/lib/timesheets-projects/dateBuckets.js +41 -0
  173. package/dist/modules/staff/lib/timesheets-projects/dateBuckets.js.map +7 -0
  174. package/dist/modules/staff/lib/timesheets-projects/initials.js +10 -0
  175. package/dist/modules/staff/lib/timesheets-projects/initials.js.map +7 -0
  176. package/dist/modules/staff/lib/timesheets-projects/kpiMath.js +12 -0
  177. package/dist/modules/staff/lib/timesheets-projects/kpiMath.js.map +7 -0
  178. package/dist/modules/staff/lib/timesheets-projects/listProjectMembersPreview.js +55 -0
  179. package/dist/modules/staff/lib/timesheets-projects/listProjectMembersPreview.js.map +7 -0
  180. package/dist/modules/staff/lib/timesheets-projects-ui/HoursSparkline.js +66 -0
  181. package/dist/modules/staff/lib/timesheets-projects-ui/HoursSparkline.js.map +7 -0
  182. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectCard.js +81 -0
  183. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectCard.js.map +7 -0
  184. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectMembersAvatarStack.js +58 -0
  185. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectMembersAvatarStack.js.map +7 -0
  186. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectsKpiStrip.js +152 -0
  187. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectsKpiStrip.js.map +7 -0
  188. package/dist/modules/staff/lib/timesheets-projects-ui/SavedViewTabs.js +37 -0
  189. package/dist/modules/staff/lib/timesheets-projects-ui/SavedViewTabs.js.map +7 -0
  190. package/dist/modules/staff/lib/timesheets-projects-ui/ViewModeToggle.js +57 -0
  191. package/dist/modules/staff/lib/timesheets-projects-ui/ViewModeToggle.js.map +7 -0
  192. package/dist/modules/staff/lib/timesheets-projects-ui/useProjectsViewMode.js +50 -0
  193. package/dist/modules/staff/lib/timesheets-projects-ui/useProjectsViewMode.js.map +7 -0
  194. package/dist/modules/staff/lib/timesheets-ui/AddRowDropdown.js +163 -0
  195. package/dist/modules/staff/lib/timesheets-ui/AddRowDropdown.js.map +7 -0
  196. package/dist/modules/staff/lib/timesheets-ui/CalendarPicker.js +209 -0
  197. package/dist/modules/staff/lib/timesheets-ui/CalendarPicker.js.map +7 -0
  198. package/dist/modules/staff/lib/timesheets-ui/ColorPicker.js +52 -0
  199. package/dist/modules/staff/lib/timesheets-ui/ColorPicker.js.map +7 -0
  200. package/dist/modules/staff/lib/timesheets-ui/CreateProjectDialog.js +77 -0
  201. package/dist/modules/staff/lib/timesheets-ui/CreateProjectDialog.js.map +7 -0
  202. package/dist/modules/staff/lib/timesheets-ui/ListView.js +173 -0
  203. package/dist/modules/staff/lib/timesheets-ui/ListView.js.map +7 -0
  204. package/dist/modules/staff/lib/timesheets-ui/ProjectColorDot.js +32 -0
  205. package/dist/modules/staff/lib/timesheets-ui/ProjectColorDot.js.map +7 -0
  206. package/dist/modules/staff/lib/timesheets-ui/TimerBar.js +270 -0
  207. package/dist/modules/staff/lib/timesheets-ui/TimerBar.js.map +7 -0
  208. package/dist/modules/staff/lib/timesheets-ui/ViewSwitcher.js +57 -0
  209. package/dist/modules/staff/lib/timesheets-ui/ViewSwitcher.js.map +7 -0
  210. package/dist/modules/staff/lib/timesheets-ui/colors.js +43 -0
  211. package/dist/modules/staff/lib/timesheets-ui/colors.js.map +7 -0
  212. package/dist/modules/staff/migrations/Migration20260326135612.js +24 -0
  213. package/dist/modules/staff/migrations/Migration20260326135612.js.map +7 -0
  214. package/dist/modules/staff/migrations/Migration20260413102715.js +23 -0
  215. package/dist/modules/staff/migrations/Migration20260413102715.js.map +7 -0
  216. package/dist/modules/staff/migrations/Migration20260413111602.js +13 -0
  217. package/dist/modules/staff/migrations/Migration20260413111602.js.map +7 -0
  218. package/dist/modules/staff/migrations/Migration20260511112759.js +19 -0
  219. package/dist/modules/staff/migrations/Migration20260511112759.js.map +7 -0
  220. package/dist/modules/staff/search.js +35 -0
  221. package/dist/modules/staff/search.js.map +2 -2
  222. package/dist/modules/staff/setup.js +15 -1
  223. package/dist/modules/staff/setup.js.map +2 -2
  224. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/config.js +16 -0
  225. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/config.js.map +7 -0
  226. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.client.js +126 -0
  227. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.client.js.map +7 -0
  228. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.js +26 -0
  229. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.js.map +7 -0
  230. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/config.js +15 -0
  231. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/config.js.map +7 -0
  232. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.client.js +238 -0
  233. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.client.js.map +7 -0
  234. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.js +26 -0
  235. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.js.map +7 -0
  236. package/dist/modules/staff/widgets/injection/timer-sidebar-indicator/widget.js +145 -0
  237. package/dist/modules/staff/widgets/injection/timer-sidebar-indicator/widget.js.map +7 -0
  238. package/dist/modules/staff/widgets/injection-table.js +12 -0
  239. package/dist/modules/staff/widgets/injection-table.js.map +7 -0
  240. package/dist/modules/sync_excel/api/import/route.js +19 -17
  241. package/dist/modules/sync_excel/api/import/route.js.map +2 -2
  242. package/dist/modules/translations/commands/translations.js +22 -19
  243. package/dist/modules/translations/commands/translations.js.map +2 -2
  244. package/generated/entities/staff_time_entry/index.ts +17 -0
  245. package/generated/entities/staff_time_entry_segment/index.ts +10 -0
  246. package/generated/entities/staff_time_project/index.ts +16 -0
  247. package/generated/entities/staff_time_project_member/index.ts +13 -0
  248. package/generated/entities.ids.generated.ts +5 -1
  249. package/generated/entity-fields-registry.ts +64 -0
  250. package/package.json +7 -7
  251. package/src/helpers/integration/timesheetFixtures.ts +61 -0
  252. package/src/modules/attachments/api/library/[id]/route.ts +24 -17
  253. package/src/modules/attachments/api/route.ts +20 -14
  254. package/src/modules/auth/api/roles/acl/route.ts +11 -5
  255. package/src/modules/auth/api/sidebar/preferences/route.ts +33 -24
  256. package/src/modules/auth/api/users/acl/route.ts +17 -12
  257. package/src/modules/auth/commands/users.ts +96 -80
  258. package/src/modules/auth/services/sidebarPreferencesService.ts +40 -32
  259. package/src/modules/catalog/commands/categories.ts +61 -12
  260. package/src/modules/catalog/commands/products.ts +93 -60
  261. package/src/modules/catalog/commands/variants.ts +29 -16
  262. package/src/modules/currencies/commands/currencies.ts +27 -14
  263. package/src/modules/customer_accounts/api/admin/users.ts +31 -26
  264. package/src/modules/customer_accounts/api/password/reset-confirm.ts +5 -6
  265. package/src/modules/customer_accounts/api/portal/users/[id]/roles.ts +14 -13
  266. package/src/modules/customers/commands/addresses.ts +35 -23
  267. package/src/modules/customers/commands/companies.ts +166 -165
  268. package/src/modules/customers/commands/deals.ts +2 -4
  269. package/src/modules/customers/commands/interactions.ts +20 -26
  270. package/src/modules/customers/commands/people.ts +18 -15
  271. package/src/modules/customers/commands/personCompanyLinks.ts +109 -100
  272. package/src/modules/customers/commands/pipeline-stages.ts +31 -27
  273. package/src/modules/customers/commands/pipelines.ts +29 -23
  274. package/src/modules/customers/commands/tags.ts +13 -5
  275. package/src/modules/dashboards/api/users/widgets/route.ts +0 -1
  276. package/src/modules/dashboards/api/widgets/data/route.ts +36 -1
  277. package/src/modules/data_sync/lib/sync-engine.ts +4 -5
  278. package/src/modules/data_sync/lib/sync-run-service.ts +57 -28
  279. package/src/modules/directory/commands/organizations.ts +203 -166
  280. package/src/modules/inbox_ops/api/emails/[id]/reprocess/route.ts +26 -18
  281. package/src/modules/messages/commands/messages.ts +82 -80
  282. package/src/modules/messages/commands/shared.ts +138 -133
  283. package/src/modules/perspectives/api/[tableId]/route.ts +38 -27
  284. package/src/modules/resources/commands/resources.ts +127 -117
  285. package/src/modules/resources/commands/tags.ts +7 -3
  286. package/src/modules/sales/api/quotes/send/route.ts +17 -12
  287. package/src/modules/sales/commands/documents.ts +673 -481
  288. package/src/modules/sales/commands/payments.ts +158 -152
  289. package/src/modules/sales/commands/returns.ts +74 -63
  290. package/src/modules/staff/acl.ts +11 -0
  291. package/src/modules/staff/analytics.ts +30 -0
  292. package/src/modules/staff/api/guards.ts +59 -0
  293. package/src/modules/staff/api/interceptors.ts +122 -0
  294. package/src/modules/staff/api/timesheets/my-projects/[projectId]/route.ts +191 -0
  295. package/src/modules/staff/api/timesheets/my-projects/route.ts +115 -0
  296. package/src/modules/staff/api/timesheets/projects/kpis/route.ts +159 -0
  297. package/src/modules/staff/api/timesheets/time-entries/[id]/segments/[segmentId]/route.ts +187 -0
  298. package/src/modules/staff/api/timesheets/time-entries/[id]/segments/route.ts +191 -0
  299. package/src/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.ts +168 -0
  300. package/src/modules/staff/api/timesheets/time-entries/[id]/timer-stop/route.ts +191 -0
  301. package/src/modules/staff/api/timesheets/time-entries/bulk/route.ts +292 -0
  302. package/src/modules/staff/api/timesheets/time-entries/route.ts +193 -0
  303. package/src/modules/staff/api/timesheets/time-projects/[id]/employees/route.ts +167 -0
  304. package/src/modules/staff/api/timesheets/time-projects/route.ts +244 -0
  305. package/src/modules/staff/backend/staff/timesheets/page.meta.ts +20 -0
  306. package/src/modules/staff/backend/staff/timesheets/page.tsx +899 -0
  307. package/src/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.meta.ts +12 -0
  308. package/src/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.tsx +141 -0
  309. package/src/modules/staff/backend/staff/timesheets/projects/[id]/page.meta.ts +12 -0
  310. package/src/modules/staff/backend/staff/timesheets/projects/[id]/page.tsx +579 -0
  311. package/src/modules/staff/backend/staff/timesheets/projects/create/page.meta.ts +12 -0
  312. package/src/modules/staff/backend/staff/timesheets/projects/create/page.tsx +90 -0
  313. package/src/modules/staff/backend/staff/timesheets/projects/page.meta.ts +23 -0
  314. package/src/modules/staff/backend/staff/timesheets/projects/page.tsx +765 -0
  315. package/src/modules/staff/backend/staff/timesheets/projects/projectFormConfig.ts +138 -0
  316. package/src/modules/staff/cli.ts +40 -1
  317. package/src/modules/staff/commands/index.ts +2 -0
  318. package/src/modules/staff/commands/leave-requests.ts +37 -29
  319. package/src/modules/staff/commands/team-members.ts +25 -20
  320. package/src/modules/staff/commands/timesheets-entries.ts +504 -0
  321. package/src/modules/staff/commands/timesheets-projects.ts +699 -0
  322. package/src/modules/staff/data/enrichers.ts +134 -0
  323. package/src/modules/staff/data/entities.ts +198 -0
  324. package/src/modules/staff/data/validators.ts +129 -0
  325. package/src/modules/staff/events.ts +13 -0
  326. package/src/modules/staff/i18n/de.json +209 -1
  327. package/src/modules/staff/i18n/en.json +209 -1
  328. package/src/modules/staff/i18n/es.json +209 -1
  329. package/src/modules/staff/i18n/pl.json +209 -1
  330. package/src/modules/staff/lib/crud.ts +8 -0
  331. package/src/modules/staff/lib/staffMemberResolver.ts +22 -0
  332. package/src/modules/staff/lib/timesheets-projects/computeProjectHoursTrend.ts +89 -0
  333. package/src/modules/staff/lib/timesheets-projects/computeProjectsKpis.ts +311 -0
  334. package/src/modules/staff/lib/timesheets-projects/dateBuckets.ts +37 -0
  335. package/src/modules/staff/lib/timesheets-projects/initials.ts +6 -0
  336. package/src/modules/staff/lib/timesheets-projects/kpiMath.ts +8 -0
  337. package/src/modules/staff/lib/timesheets-projects/listProjectMembersPreview.ts +83 -0
  338. package/src/modules/staff/lib/timesheets-projects-ui/HoursSparkline.tsx +75 -0
  339. package/src/modules/staff/lib/timesheets-projects-ui/ProjectCard.tsx +110 -0
  340. package/src/modules/staff/lib/timesheets-projects-ui/ProjectMembersAvatarStack.tsx +73 -0
  341. package/src/modules/staff/lib/timesheets-projects-ui/ProjectsKpiStrip.tsx +185 -0
  342. package/src/modules/staff/lib/timesheets-projects-ui/SavedViewTabs.tsx +53 -0
  343. package/src/modules/staff/lib/timesheets-projects-ui/ViewModeToggle.tsx +63 -0
  344. package/src/modules/staff/lib/timesheets-projects-ui/useProjectsViewMode.ts +63 -0
  345. package/src/modules/staff/lib/timesheets-ui/AddRowDropdown.tsx +188 -0
  346. package/src/modules/staff/lib/timesheets-ui/CalendarPicker.tsx +229 -0
  347. package/src/modules/staff/lib/timesheets-ui/ColorPicker.tsx +65 -0
  348. package/src/modules/staff/lib/timesheets-ui/CreateProjectDialog.tsx +99 -0
  349. package/src/modules/staff/lib/timesheets-ui/ListView.tsx +230 -0
  350. package/src/modules/staff/lib/timesheets-ui/ProjectColorDot.tsx +40 -0
  351. package/src/modules/staff/lib/timesheets-ui/TimerBar.tsx +327 -0
  352. package/src/modules/staff/lib/timesheets-ui/ViewSwitcher.tsx +60 -0
  353. package/src/modules/staff/lib/timesheets-ui/colors.ts +58 -0
  354. package/src/modules/staff/migrations/.snapshot-open-mercato.json +1148 -0
  355. package/src/modules/staff/migrations/Migration20260326135612.ts +26 -0
  356. package/src/modules/staff/migrations/Migration20260413102715.ts +25 -0
  357. package/src/modules/staff/migrations/Migration20260413111602.ts +13 -0
  358. package/src/modules/staff/migrations/Migration20260511112759.ts +21 -0
  359. package/src/modules/staff/search.ts +35 -0
  360. package/src/modules/staff/setup.ts +15 -0
  361. package/src/modules/staff/widgets/dashboard/timesheets-hours-by-project/config.ts +17 -0
  362. package/src/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.client.tsx +158 -0
  363. package/src/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.ts +25 -0
  364. package/src/modules/staff/widgets/dashboard/timesheets-time-reporting/config.ts +15 -0
  365. package/src/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.client.tsx +297 -0
  366. package/src/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.ts +25 -0
  367. package/src/modules/staff/widgets/injection/timer-sidebar-indicator/widget.tsx +161 -0
  368. package/src/modules/staff/widgets/injection-table.ts +10 -0
  369. package/src/modules/sync_excel/api/import/route.ts +23 -18
  370. package/src/modules/translations/commands/translations.ts +49 -41
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/modules/customers/commands/interactions.ts"],
4
- "sourcesContent": ["import { z } from 'zod'\nimport { registerCommand } from '@open-mercato/shared/lib/commands'\nimport type { CommandHandler } from '@open-mercato/shared/lib/commands'\nimport {\n parseWithCustomFields,\n setCustomFieldsIfAny,\n emitCrudSideEffects,\n emitCrudUndoSideEffects,\n requireId,\n normalizeAuthorUserId,\n} from '@open-mercato/shared/lib/commands/helpers'\nimport { DefaultDataEngine, type DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { CommandRuntimeContext } from '@open-mercato/shared/lib/commands'\nimport { CustomerInteraction } from '../data/entities'\nimport {\n interactionCreateSchema,\n interactionUpdateSchema,\n interactionCompleteSchema,\n interactionCancelSchema,\n type InteractionCreateInput,\n type InteractionUpdateInput,\n type InteractionCompleteInput,\n type InteractionCancelInput,\n} from '../data/validators'\nimport {\n ensureOrganizationScope,\n ensureTenantScope,\n requireTimelineParentEntity,\n extractUndoPayload,\n emitQueryIndexUpsertEvents,\n requireDealInScope,\n resolveParentResourceKind,\n} from './shared'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport {\n loadCustomFieldSnapshot,\n buildCustomFieldResetMap,\n} from '@open-mercato/shared/lib/commands/customFieldSnapshots'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport type { CrudIndexerConfig, CrudEventsConfig } from '@open-mercato/shared/lib/crud/types'\nimport { recomputeNextInteraction } from '../lib/interactionProjection'\n\nconst INTERACTION_ENTITY_ID = 'customers:customer_interaction'\nconst interactionCrudIndexer: CrudIndexerConfig<CustomerInteraction> = {\n entityType: 'customers:customer_interaction' as const,\n}\n\nconst interactionCrudEvents: CrudEventsConfig = {\n module: 'customers',\n entity: 'interaction',\n persistent: true,\n buildPayload: (ctx) => ({\n id: ctx.identifiers.id,\n organizationId: ctx.identifiers.organizationId,\n tenantId: ctx.identifiers.tenantId,\n entityId:\n ctx.entity && typeof ctx.entity === 'object' && 'entity' in (ctx.entity as Record<string, unknown>)\n ? (() => {\n const entityRef = (ctx.entity as CustomerInteraction).entity\n return typeof entityRef === 'string' ? entityRef : entityRef?.id ?? null\n })()\n : null,\n interactionType:\n ctx.entity && typeof ctx.entity === 'object' && 'interactionType' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerInteraction).interactionType\n : null,\n status:\n ctx.entity && typeof ctx.entity === 'object' && 'status' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerInteraction).status\n : null,\n source:\n ctx.entity && typeof ctx.entity === 'object' && 'source' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerInteraction).source ?? null\n : null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n }),\n}\n\ntype InteractionSnapshot = {\n interaction: {\n id: string\n organizationId: string\n tenantId: string\n entityId: string\n entityKind: string | null\n dealId: string | null\n interactionType: string\n title: string | null\n body: string | null\n status: string\n scheduledAt: Date | null\n occurredAt: Date | null\n priority: number | null\n authorUserId: string | null\n ownerUserId: string | null\n appearanceIcon: string | null\n appearanceColor: string | null\n source: string | null\n durationMinutes: number | null\n location: string | null\n allDay: boolean | null\n recurrenceRule: string | null\n recurrenceEnd: Date | null\n participants: Array<{ userId: string; name?: string; email?: string; status?: string }> | null\n reminderMinutes: number | null\n visibility: string | null\n linkedEntities: Array<{ id: string; type: string; label: string }> | null\n guestPermissions: { canInviteOthers?: boolean; canModify?: boolean; canSeeList?: boolean } | null\n }\n custom?: Record<string, unknown>\n}\n\ntype InteractionUndoPayload = {\n before?: InteractionSnapshot | null\n after?: InteractionSnapshot | null\n}\n\nasync function loadInteractionSnapshot(em: EntityManager, id: string): Promise<InteractionSnapshot | null> {\n const interaction = await findOneWithDecryption(em, CustomerInteraction, { id }, { populate: ['entity'] })\n if (!interaction) return null\n const custom = await loadCustomFieldSnapshot(em, {\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n tenantId: interaction.tenantId,\n organizationId: interaction.organizationId,\n })\n const entityRef = interaction.entity\n const entityKind = (typeof entityRef === 'object' && entityRef !== null && 'kind' in entityRef)\n ? (entityRef as { kind: string }).kind\n : null\n return {\n interaction: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n entityId: typeof entityRef === 'string' ? entityRef : entityRef.id,\n entityKind,\n dealId: interaction.dealId ?? null,\n interactionType: interaction.interactionType,\n title: interaction.title ?? null,\n body: interaction.body ?? null,\n status: interaction.status,\n scheduledAt: interaction.scheduledAt ?? null,\n occurredAt: interaction.occurredAt ?? null,\n priority: interaction.priority ?? null,\n authorUserId: interaction.authorUserId ?? null,\n ownerUserId: interaction.ownerUserId ?? null,\n appearanceIcon: interaction.appearanceIcon ?? null,\n appearanceColor: interaction.appearanceColor ?? null,\n source: interaction.source ?? null,\n durationMinutes: interaction.durationMinutes ?? null,\n location: interaction.location ?? null,\n allDay: interaction.allDay ?? null,\n recurrenceRule: interaction.recurrenceRule ?? null,\n recurrenceEnd: interaction.recurrenceEnd ?? null,\n participants: interaction.participants ?? null,\n reminderMinutes: interaction.reminderMinutes ?? null,\n visibility: interaction.visibility ?? null,\n linkedEntities: interaction.linkedEntities ?? null,\n guestPermissions: interaction.guestPermissions ?? null,\n },\n custom,\n }\n}\n\nasync function setInteractionCustomFields(\n dataEngine: DataEngine,\n interactionId: string,\n organizationId: string,\n tenantId: string,\n values: Record<string, unknown>\n) {\n if (!values || !Object.keys(values).length) return\n await setCustomFieldsIfAny({\n dataEngine,\n entityId: INTERACTION_ENTITY_ID,\n recordId: interactionId,\n organizationId,\n tenantId,\n values,\n notify: false,\n })\n}\n\nasync function emitLifecycleEvent(\n ctx: CommandRuntimeContext,\n eventId: string,\n payload: Record<string, unknown>\n): Promise<void> {\n let bus: { emitEvent(event: string, payload: unknown, options?: unknown): Promise<void> } | null = null\n try {\n bus = ctx.container.resolve('eventBus')\n } catch (err) {\n console.warn('[customers.commands.interactions] eventBus resolve failed; skipping emit', eventId, err)\n bus = null\n }\n if (!bus) return\n await bus\n .emitEvent(eventId, payload, { persistent: true })\n .catch((err) => {\n console.warn('[customers.commands.interactions] emit failed', eventId, err)\n return undefined\n })\n}\n\nasync function emitInteractionRevertedEvent(\n ctx: CommandRuntimeContext,\n interaction: InteractionSnapshot['interaction'],\n): Promise<void> {\n await emitLifecycleEvent(ctx, 'customers.interaction.reverted', {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n entityId: interaction.entityId,\n interactionType: interaction.interactionType,\n source: interaction.source ?? null,\n status: interaction.status,\n occurredAt: interaction.occurredAt?.toISOString() ?? null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n })\n}\n\ntype InteractionIdentifiers = {\n id: string\n organizationId: string\n tenantId: string\n}\n\ntype InteractionProjectionMutation = {\n entityId: string\n nextInteractionId: string | null\n}\n\nfunction createTransactionalDataEngine(ctx: CommandRuntimeContext, em: EntityManager): DataEngine {\n const emWithConnection = em as EntityManager & { getConnection?: () => unknown }\n if (typeof emWithConnection.getConnection !== 'function') {\n return ctx.container.resolve('dataEngine') as DataEngine\n }\n return new DefaultDataEngine(em, ctx.container)\n}\n\nasync function runInTransaction<TResult>(\n em: EntityManager,\n operation: (trx: EntityManager) => Promise<TResult>,\n): Promise<TResult> {\n // Mirrors the SPEC-018 fix applied to withAtomicFlush: use explicit begin/commit/rollback\n // so the outer EntityManager stays bound to the transaction, and closures over `em` inside\n // `operation` participate in the same transaction. This avoids the em.transactional(cb)\n // hazard where the callback receives a child EM whose flushes can silently race against\n // subsequent queries on the original `em`.\n const supportsBegin =\n typeof (em as unknown as { begin?: () => Promise<void> }).begin === 'function' &&\n typeof (em as unknown as { commit?: () => Promise<void> }).commit === 'function' &&\n typeof (em as unknown as { rollback?: () => Promise<void> }).rollback === 'function'\n if (!supportsBegin) {\n return operation(em)\n }\n await em.begin()\n try {\n const result = await operation(em)\n await em.commit()\n return result\n } catch (err) {\n try {\n await em.rollback()\n } catch {\n // rollback failure should not mask the original error; intentionally swallowed\n }\n throw err\n }\n}\n\nasync function emitNextInteractionUpdatedEvent(\n ctx: CommandRuntimeContext,\n projection: InteractionProjectionMutation,\n identifiers: InteractionIdentifiers,\n): Promise<void> {\n await emitQueryIndexUpsertEvents(ctx, [{\n entityType: 'customers:customer_entity',\n recordId: projection.entityId,\n organizationId: identifiers.organizationId,\n tenantId: identifiers.tenantId,\n }])\n await emitLifecycleEvent(ctx, 'customers.next_interaction.updated', {\n id: projection.entityId,\n entityId: projection.entityId,\n nextInteractionId: projection.nextInteractionId,\n organizationId: identifiers.organizationId,\n tenantId: identifiers.tenantId,\n })\n}\n\n// \u2500\u2500\u2500 Create \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst createInteractionCommand: CommandHandler<InteractionCreateInput, { interactionId: string; entityId: string }> = {\n id: 'customers.interactions.create',\n async execute(rawInput, ctx) {\n const { parsed, custom } = parseWithCustomFields(interactionCreateSchema, rawInput)\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const normalizedAuthor = normalizeAuthorUserId(parsed.authorUserId ?? null, ctx.auth)\n const { interaction, entityId } = await runInTransaction(em, async (trx) => {\n const entity = await requireTimelineParentEntity(trx, parsed.entityId)\n ensureTenantScope(ctx, entity.tenantId)\n ensureOrganizationScope(ctx, entity.organizationId)\n\n if (parsed.dealId) {\n await requireDealInScope(trx, parsed.dealId, entity.tenantId, entity.organizationId)\n }\n\n const interaction = trx.create(CustomerInteraction, {\n ...(parsed.id ? { id: parsed.id } : {}),\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n entity,\n interactionType: parsed.interactionType,\n title: parsed.title ?? null,\n body: parsed.body ?? null,\n status: parsed.status ?? 'planned',\n scheduledAt: parsed.scheduledAt ?? null,\n occurredAt: parsed.occurredAt ?? null,\n priority: parsed.priority ?? null,\n authorUserId: normalizedAuthor,\n ownerUserId: parsed.ownerUserId ?? null,\n dealId: parsed.dealId ?? null,\n source: parsed.source ?? null,\n appearanceIcon: parsed.appearanceIcon ?? null,\n appearanceColor: parsed.appearanceColor ?? null,\n durationMinutes: parsed.durationMinutes ?? null,\n location: parsed.location ?? null,\n allDay: parsed.allDay ?? null,\n recurrenceRule: parsed.recurrenceRule ?? null,\n recurrenceEnd: parsed.recurrenceEnd ?? null,\n participants: parsed.participants ?? null,\n reminderMinutes: parsed.reminderMinutes ?? null,\n visibility: parsed.visibility ?? null,\n linkedEntities: parsed.linkedEntities ?? null,\n guestPermissions: parsed.guestPermissions ?? null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n trx.persist(interaction)\n await trx.flush()\n\n await setInteractionCustomFields(\n createTransactionalDataEngine(ctx, trx),\n interaction.id,\n entity.organizationId,\n entity.tenantId,\n custom,\n )\n\n return {\n interaction,\n entityId: entity.id,\n }\n })\n\n const projection = await recomputeNextInteraction(em, entityId)\n const nextInteractionId = projection.nextInteractionId\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'created',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n\n return { interactionId: interaction.id, entityId }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const snapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.create', 'Create interaction'),\n resourceKind: 'customers.interaction',\n resourceId: result.interactionId,\n parentResourceKind: resolveParentResourceKind(snapshot?.interaction?.entityKind),\n parentResourceId: snapshot?.interaction?.entityId ?? null,\n tenantId: snapshot?.interaction.tenantId ?? null,\n organizationId: snapshot?.interaction.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const interactionId = logEntry?.resourceId\n if (!interactionId) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const result = await runInTransaction(em, async (trx) => {\n const record = await findOneWithDecryption(trx, CustomerInteraction, { id: interactionId })\n if (!record) return null\n const entityId = typeof record.entity === 'string' ? record.entity : record.entity.id\n trx.remove(record)\n await trx.flush()\n return {\n entityId,\n identifiers: {\n id: record.id,\n organizationId: record.organizationId,\n tenantId: record.tenantId,\n },\n }\n })\n if (!result) return\n const projection = await recomputeNextInteraction(em, result.entityId)\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: result.entityId,\n nextInteractionId: projection.nextInteractionId,\n }, result.identifiers)\n },\n}\n\n// \u2500\u2500\u2500 Update \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst updateInteractionCommand: CommandHandler<InteractionUpdateInput, { interactionId: string }> = {\n id: 'customers.interactions.update',\n async prepare(rawInput, ctx) {\n const { parsed } = parseWithCustomFields(interactionUpdateSchema, rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const { parsed, custom } = parseWithCustomFields(interactionUpdateSchema, rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: parsed.id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n if (parsed.dealId !== undefined) {\n if (parsed.dealId) {\n await requireDealInScope(trx, parsed.dealId, interaction.tenantId, interaction.organizationId)\n }\n interaction.dealId = parsed.dealId ?? null\n }\n if (parsed.interactionType !== undefined) interaction.interactionType = parsed.interactionType\n if (parsed.title !== undefined) interaction.title = parsed.title ?? null\n if (parsed.body !== undefined) interaction.body = parsed.body ?? null\n if (parsed.status !== undefined) interaction.status = parsed.status\n if (parsed.scheduledAt !== undefined) interaction.scheduledAt = parsed.scheduledAt ?? null\n if (parsed.occurredAt !== undefined) interaction.occurredAt = parsed.occurredAt ?? null\n if (parsed.priority !== undefined) interaction.priority = parsed.priority ?? null\n if (parsed.authorUserId !== undefined) interaction.authorUserId = parsed.authorUserId ?? null\n if (parsed.ownerUserId !== undefined) interaction.ownerUserId = parsed.ownerUserId ?? null\n if (parsed.appearanceIcon !== undefined) interaction.appearanceIcon = parsed.appearanceIcon ?? null\n if (parsed.appearanceColor !== undefined) interaction.appearanceColor = parsed.appearanceColor ?? null\n if (parsed.pinned !== undefined) interaction.pinned = parsed.pinned\n if (parsed.durationMinutes !== undefined) interaction.durationMinutes = parsed.durationMinutes ?? null\n if (parsed.location !== undefined) interaction.location = parsed.location ?? null\n if (parsed.allDay !== undefined) interaction.allDay = parsed.allDay ?? null\n if (parsed.recurrenceRule !== undefined) interaction.recurrenceRule = parsed.recurrenceRule ?? null\n if (parsed.recurrenceEnd !== undefined) interaction.recurrenceEnd = parsed.recurrenceEnd ?? null\n if (parsed.participants !== undefined) interaction.participants = parsed.participants ?? null\n if (parsed.reminderMinutes !== undefined) interaction.reminderMinutes = parsed.reminderMinutes ?? null\n if (parsed.visibility !== undefined) interaction.visibility = parsed.visibility ?? null\n if (parsed.linkedEntities !== undefined) interaction.linkedEntities = parsed.linkedEntities ?? null\n if (parsed.guestPermissions !== undefined) interaction.guestPermissions = parsed.guestPermissions ?? null\n\n await trx.flush()\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n await setInteractionCustomFields(\n createTransactionalDataEngine(ctx, trx),\n interaction.id,\n interaction.organizationId,\n interaction.tenantId,\n custom,\n )\n\n return { interaction, entityId }\n })\n\n const projection = await recomputeNextInteraction(em, entityId)\n const nextInteractionId = projection.nextInteractionId\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n\n return { interactionId: interaction.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const afterSnapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.update', 'Update interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n snapshotAfter: afterSnapshot ?? null,\n payload: {\n undo: {\n before,\n after: afterSnapshot ?? null,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, nextInteractionId } = await runInTransaction(em, async (trx) => {\n let interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n const entity = await requireTimelineParentEntity(trx, before.interaction.entityId)\n\n if (!interaction) {\n interaction = trx.create(CustomerInteraction, {\n id: before.interaction.id,\n organizationId: before.interaction.organizationId,\n tenantId: before.interaction.tenantId,\n entity,\n interactionType: before.interaction.interactionType,\n title: before.interaction.title,\n body: before.interaction.body,\n status: before.interaction.status,\n scheduledAt: before.interaction.scheduledAt,\n occurredAt: before.interaction.occurredAt,\n priority: before.interaction.priority,\n authorUserId: before.interaction.authorUserId,\n ownerUserId: before.interaction.ownerUserId,\n dealId: before.interaction.dealId,\n source: before.interaction.source,\n appearanceIcon: before.interaction.appearanceIcon,\n appearanceColor: before.interaction.appearanceColor,\n durationMinutes: before.interaction.durationMinutes,\n location: before.interaction.location,\n allDay: before.interaction.allDay,\n recurrenceRule: before.interaction.recurrenceRule,\n recurrenceEnd: before.interaction.recurrenceEnd,\n participants: before.interaction.participants,\n reminderMinutes: before.interaction.reminderMinutes,\n visibility: before.interaction.visibility,\n linkedEntities: before.interaction.linkedEntities,\n guestPermissions: before.interaction.guestPermissions,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n trx.persist(interaction)\n } else {\n interaction.entity = entity\n interaction.interactionType = before.interaction.interactionType\n interaction.title = before.interaction.title\n interaction.body = before.interaction.body\n interaction.status = before.interaction.status\n interaction.scheduledAt = before.interaction.scheduledAt\n interaction.occurredAt = before.interaction.occurredAt\n interaction.priority = before.interaction.priority\n interaction.authorUserId = before.interaction.authorUserId\n interaction.ownerUserId = before.interaction.ownerUserId\n interaction.dealId = before.interaction.dealId\n interaction.source = before.interaction.source\n interaction.appearanceIcon = before.interaction.appearanceIcon\n interaction.appearanceColor = before.interaction.appearanceColor\n interaction.durationMinutes = before.interaction.durationMinutes\n interaction.location = before.interaction.location\n interaction.allDay = before.interaction.allDay\n interaction.recurrenceRule = before.interaction.recurrenceRule\n interaction.recurrenceEnd = before.interaction.recurrenceEnd\n interaction.participants = before.interaction.participants\n interaction.reminderMinutes = before.interaction.reminderMinutes\n interaction.visibility = before.interaction.visibility\n interaction.linkedEntities = before.interaction.linkedEntities\n interaction.guestPermissions = before.interaction.guestPermissions\n }\n\n await trx.flush()\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n\n const resetValues = buildCustomFieldResetMap(before.custom, payload?.after?.custom)\n if (Object.keys(resetValues).length) {\n await setCustomFieldsIfAny({\n dataEngine: createTransactionalDataEngine(ctx, trx),\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n values: resetValues,\n notify: false,\n })\n }\n\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId,\n }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n },\n}\n\n// \u2500\u2500\u2500 Complete \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst completeInteractionCommand: CommandHandler<InteractionCompleteInput, { interactionId: string }> = {\n id: 'customers.interactions.complete',\n async prepare(rawInput, ctx) {\n const parsed = interactionCompleteSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = interactionCompleteSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: parsed.id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n interaction.status = 'done'\n interaction.occurredAt = parsed.occurredAt ?? new Date()\n await trx.flush()\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n return { interaction, entityId }\n })\n\n const projection = await recomputeNextInteraction(em, entityId)\n const nextInteractionId = projection.nextInteractionId\n\n const identifiers = {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n }\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers,\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitLifecycleEvent(ctx, 'customers.interaction.completed', {\n ...identifiers,\n entityId,\n interactionType: interaction.interactionType,\n status: interaction.status,\n source: interaction.source ?? null,\n occurredAt: interaction.occurredAt?.toISOString() ?? null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, identifiers)\n\n return { interactionId: interaction.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const afterSnapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.complete', 'Complete interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n snapshotAfter: afterSnapshot ?? null,\n payload: {\n undo: {\n before,\n after: afterSnapshot ?? null,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const result = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n if (!interaction) return null\n\n interaction.status = before.interaction.status\n interaction.occurredAt = before.interaction.occurredAt\n await trx.flush()\n\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n if (!result) return\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: result.interaction,\n identifiers: {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitInteractionRevertedEvent(ctx, before.interaction)\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId: result.nextInteractionId,\n }, {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n })\n },\n}\n\n// \u2500\u2500\u2500 Cancel \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst cancelInteractionCommand: CommandHandler<InteractionCancelInput, { interactionId: string }> = {\n id: 'customers.interactions.cancel',\n async prepare(rawInput, ctx) {\n const parsed = interactionCancelSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = interactionCancelSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: parsed.id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n interaction.status = 'canceled'\n await trx.flush()\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n return { interaction, entityId }\n })\n\n const projection = await recomputeNextInteraction(em, entityId)\n const nextInteractionId = projection.nextInteractionId\n\n const identifiers = {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n }\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers,\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitLifecycleEvent(ctx, 'customers.interaction.canceled', {\n ...identifiers,\n entityId,\n interactionType: interaction.interactionType,\n status: interaction.status,\n source: interaction.source ?? null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, identifiers)\n\n return { interactionId: interaction.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const afterSnapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.cancel', 'Cancel interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n snapshotAfter: afterSnapshot ?? null,\n payload: {\n undo: {\n before,\n after: afterSnapshot ?? null,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const result = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n if (!interaction) return null\n\n interaction.status = before.interaction.status\n await trx.flush()\n\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n if (!result) return\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: result.interaction,\n identifiers: {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitInteractionRevertedEvent(ctx, before.interaction)\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId: result.nextInteractionId,\n }, {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n })\n },\n}\n\n// \u2500\u2500\u2500 Delete \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst deleteInteractionCommand: CommandHandler<{ body?: Record<string, unknown>; query?: Record<string, unknown> }, { interactionId: string }> =\n {\n id: 'customers.interactions.delete',\n async prepare(input, ctx) {\n const id = requireId(input, 'Interaction id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const id = requireId(input, 'Interaction id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n interaction.deletedAt = new Date()\n await trx.flush()\n\n return { interaction, entityId }\n })\n\n const projection = await recomputeNextInteraction(em, entityId)\n const nextInteractionId = projection.nextInteractionId\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'deleted',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n return { interactionId: interaction.id }\n },\n buildLog: async ({ snapshots }) => {\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('customers.audit.interactions.delete', 'Delete interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n payload: {\n undo: {\n before,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const entity = await requireTimelineParentEntity(trx, before.interaction.entityId)\n let interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n if (!interaction) {\n interaction = trx.create(CustomerInteraction, {\n id: before.interaction.id,\n organizationId: before.interaction.organizationId,\n tenantId: before.interaction.tenantId,\n entity,\n interactionType: before.interaction.interactionType,\n title: before.interaction.title,\n body: before.interaction.body,\n status: before.interaction.status,\n scheduledAt: before.interaction.scheduledAt,\n occurredAt: before.interaction.occurredAt,\n priority: before.interaction.priority,\n authorUserId: before.interaction.authorUserId,\n ownerUserId: before.interaction.ownerUserId,\n dealId: before.interaction.dealId,\n source: before.interaction.source,\n appearanceIcon: before.interaction.appearanceIcon,\n appearanceColor: before.interaction.appearanceColor,\n durationMinutes: before.interaction.durationMinutes,\n location: before.interaction.location,\n allDay: before.interaction.allDay,\n recurrenceRule: before.interaction.recurrenceRule,\n recurrenceEnd: before.interaction.recurrenceEnd,\n participants: before.interaction.participants,\n reminderMinutes: before.interaction.reminderMinutes,\n visibility: before.interaction.visibility,\n linkedEntities: before.interaction.linkedEntities,\n guestPermissions: before.interaction.guestPermissions,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n trx.persist(interaction)\n } else {\n interaction.deletedAt = null\n interaction.entity = entity\n interaction.interactionType = before.interaction.interactionType\n interaction.title = before.interaction.title\n interaction.body = before.interaction.body\n interaction.status = before.interaction.status\n interaction.scheduledAt = before.interaction.scheduledAt\n interaction.occurredAt = before.interaction.occurredAt\n interaction.priority = before.interaction.priority\n interaction.authorUserId = before.interaction.authorUserId\n interaction.ownerUserId = before.interaction.ownerUserId\n interaction.dealId = before.interaction.dealId\n interaction.source = before.interaction.source\n interaction.appearanceIcon = before.interaction.appearanceIcon\n interaction.appearanceColor = before.interaction.appearanceColor\n interaction.durationMinutes = before.interaction.durationMinutes\n interaction.location = before.interaction.location\n interaction.allDay = before.interaction.allDay\n interaction.recurrenceRule = before.interaction.recurrenceRule\n interaction.recurrenceEnd = before.interaction.recurrenceEnd\n interaction.participants = before.interaction.participants\n interaction.reminderMinutes = before.interaction.reminderMinutes\n interaction.visibility = before.interaction.visibility\n interaction.linkedEntities = before.interaction.linkedEntities\n interaction.guestPermissions = before.interaction.guestPermissions\n }\n await trx.flush()\n\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n\n const resetValues = buildCustomFieldResetMap(before.custom, undefined)\n if (Object.keys(resetValues).length) {\n await setCustomFieldsIfAny({\n dataEngine: createTransactionalDataEngine(ctx, trx),\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n values: resetValues,\n notify: false,\n })\n }\n\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'created',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId,\n }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n },\n }\n\n// \u2500\u2500\u2500 Recompute Next (internal repair) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst recomputeNextSchema = z.object({ entityId: z.string().min(1) })\n\nconst recomputeNextCommand: CommandHandler<{ entityId: string }, { entityId: string }> = {\n id: 'customers.interaction.recompute_next',\n async execute(rawInput, ctx) {\n const parsed = recomputeNextSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const projection = await recomputeNextInteraction(em, parsed.entityId)\n const entity = await requireTimelineParentEntity(em, parsed.entityId)\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: parsed.entityId,\n nextInteractionId: projection.nextInteractionId,\n }, {\n id: parsed.entityId,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n })\n return { entityId: parsed.entityId }\n },\n}\n\nregisterCommand(createInteractionCommand)\nregisterCommand(updateInteractionCommand)\nregisterCommand(completeInteractionCommand)\nregisterCommand(cancelInteractionCommand)\nregisterCommand(deleteInteractionCommand)\nregisterCommand(recomputeNextCommand)\n"],
5
- "mappings": "AAAA,SAAS,SAAS;AAClB,SAAS,uBAAuB;AAEh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Q,IAAI,EAAoB,KAAK;AAC/D,UAAM,aAAa,MAAM,yBAAyB,IAAI,OAAO,QAAQ;AACrE,UAAM,SAAS,MAAM,4BAA4B,IAAI,OAAO,QAAQ;AACpE,UAAM,gCAAgC,KAAK;AAAA,MACzC,UAAU,OAAO;AAAA,MACjB,mBAAmB,WAAW;AAAA,IAChC,GAAG;AAAA,MACD,IAAI,OAAO;AAAA,MACX,gBAAgB,OAAO;AAAA,MACvB,UAAU,OAAO;AAAA,IACnB,CAAC;AACD,WAAO,EAAE,UAAU,OAAO,SAAS;AAAA,EACrC;AACF;AAEA,gBAAgB,wBAAwB;AACxC,gBAAgB,wBAAwB;AACxC,gBAAgB,0BAA0B;AAC1C,gBAAgB,wBAAwB;AACxC,gBAAgB,wBAAwB;AACxC,gBAAgB,oBAAoB;",
4
+ "sourcesContent": ["import { z } from 'zod'\nimport { registerCommand } from '@open-mercato/shared/lib/commands'\nimport type { CommandHandler } from '@open-mercato/shared/lib/commands'\nimport {\n parseWithCustomFields,\n setCustomFieldsIfAny,\n emitCrudSideEffects,\n emitCrudUndoSideEffects,\n requireId,\n normalizeAuthorUserId,\n} from '@open-mercato/shared/lib/commands/helpers'\nimport { DefaultDataEngine, type DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { CommandRuntimeContext } from '@open-mercato/shared/lib/commands'\nimport { CustomerInteraction } from '../data/entities'\nimport {\n interactionCreateSchema,\n interactionUpdateSchema,\n interactionCompleteSchema,\n interactionCancelSchema,\n type InteractionCreateInput,\n type InteractionUpdateInput,\n type InteractionCompleteInput,\n type InteractionCancelInput,\n} from '../data/validators'\nimport {\n ensureOrganizationScope,\n ensureTenantScope,\n requireTimelineParentEntity,\n extractUndoPayload,\n emitQueryIndexUpsertEvents,\n requireDealInScope,\n resolveParentResourceKind,\n} from './shared'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport {\n loadCustomFieldSnapshot,\n buildCustomFieldResetMap,\n} from '@open-mercato/shared/lib/commands/customFieldSnapshots'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport type { CrudIndexerConfig, CrudEventsConfig } from '@open-mercato/shared/lib/crud/types'\nimport { recomputeNextInteraction } from '../lib/interactionProjection'\n\nconst INTERACTION_ENTITY_ID = 'customers:customer_interaction'\nconst interactionCrudIndexer: CrudIndexerConfig<CustomerInteraction> = {\n entityType: 'customers:customer_interaction' as const,\n}\n\nconst interactionCrudEvents: CrudEventsConfig = {\n module: 'customers',\n entity: 'interaction',\n persistent: true,\n buildPayload: (ctx) => ({\n id: ctx.identifiers.id,\n organizationId: ctx.identifiers.organizationId,\n tenantId: ctx.identifiers.tenantId,\n entityId:\n ctx.entity && typeof ctx.entity === 'object' && 'entity' in (ctx.entity as Record<string, unknown>)\n ? (() => {\n const entityRef = (ctx.entity as CustomerInteraction).entity\n return typeof entityRef === 'string' ? entityRef : entityRef?.id ?? null\n })()\n : null,\n interactionType:\n ctx.entity && typeof ctx.entity === 'object' && 'interactionType' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerInteraction).interactionType\n : null,\n status:\n ctx.entity && typeof ctx.entity === 'object' && 'status' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerInteraction).status\n : null,\n source:\n ctx.entity && typeof ctx.entity === 'object' && 'source' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerInteraction).source ?? null\n : null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n }),\n}\n\ntype InteractionSnapshot = {\n interaction: {\n id: string\n organizationId: string\n tenantId: string\n entityId: string\n entityKind: string | null\n dealId: string | null\n interactionType: string\n title: string | null\n body: string | null\n status: string\n scheduledAt: Date | null\n occurredAt: Date | null\n priority: number | null\n authorUserId: string | null\n ownerUserId: string | null\n appearanceIcon: string | null\n appearanceColor: string | null\n source: string | null\n durationMinutes: number | null\n location: string | null\n allDay: boolean | null\n recurrenceRule: string | null\n recurrenceEnd: Date | null\n participants: Array<{ userId: string; name?: string; email?: string; status?: string }> | null\n reminderMinutes: number | null\n visibility: string | null\n linkedEntities: Array<{ id: string; type: string; label: string }> | null\n guestPermissions: { canInviteOthers?: boolean; canModify?: boolean; canSeeList?: boolean } | null\n }\n custom?: Record<string, unknown>\n}\n\ntype InteractionUndoPayload = {\n before?: InteractionSnapshot | null\n after?: InteractionSnapshot | null\n}\n\nasync function loadInteractionSnapshot(em: EntityManager, id: string): Promise<InteractionSnapshot | null> {\n const interaction = await findOneWithDecryption(em, CustomerInteraction, { id }, { populate: ['entity'] })\n if (!interaction) return null\n const custom = await loadCustomFieldSnapshot(em, {\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n tenantId: interaction.tenantId,\n organizationId: interaction.organizationId,\n })\n const entityRef = interaction.entity\n const entityKind = (typeof entityRef === 'object' && entityRef !== null && 'kind' in entityRef)\n ? (entityRef as { kind: string }).kind\n : null\n return {\n interaction: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n entityId: typeof entityRef === 'string' ? entityRef : entityRef.id,\n entityKind,\n dealId: interaction.dealId ?? null,\n interactionType: interaction.interactionType,\n title: interaction.title ?? null,\n body: interaction.body ?? null,\n status: interaction.status,\n scheduledAt: interaction.scheduledAt ?? null,\n occurredAt: interaction.occurredAt ?? null,\n priority: interaction.priority ?? null,\n authorUserId: interaction.authorUserId ?? null,\n ownerUserId: interaction.ownerUserId ?? null,\n appearanceIcon: interaction.appearanceIcon ?? null,\n appearanceColor: interaction.appearanceColor ?? null,\n source: interaction.source ?? null,\n durationMinutes: interaction.durationMinutes ?? null,\n location: interaction.location ?? null,\n allDay: interaction.allDay ?? null,\n recurrenceRule: interaction.recurrenceRule ?? null,\n recurrenceEnd: interaction.recurrenceEnd ?? null,\n participants: interaction.participants ?? null,\n reminderMinutes: interaction.reminderMinutes ?? null,\n visibility: interaction.visibility ?? null,\n linkedEntities: interaction.linkedEntities ?? null,\n guestPermissions: interaction.guestPermissions ?? null,\n },\n custom,\n }\n}\n\nasync function setInteractionCustomFields(\n dataEngine: DataEngine,\n interactionId: string,\n organizationId: string,\n tenantId: string,\n values: Record<string, unknown>\n) {\n if (!values || !Object.keys(values).length) return\n await setCustomFieldsIfAny({\n dataEngine,\n entityId: INTERACTION_ENTITY_ID,\n recordId: interactionId,\n organizationId,\n tenantId,\n values,\n notify: false,\n })\n}\n\nasync function emitLifecycleEvent(\n ctx: CommandRuntimeContext,\n eventId: string,\n payload: Record<string, unknown>\n): Promise<void> {\n let bus: { emitEvent(event: string, payload: unknown, options?: unknown): Promise<void> } | null = null\n try {\n bus = ctx.container.resolve('eventBus')\n } catch (err) {\n console.warn('[customers.commands.interactions] eventBus resolve failed; skipping emit', eventId, err)\n bus = null\n }\n if (!bus) return\n await bus\n .emitEvent(eventId, payload, { persistent: true })\n .catch((err) => {\n console.warn('[customers.commands.interactions] emit failed', eventId, err)\n return undefined\n })\n}\n\nasync function emitInteractionRevertedEvent(\n ctx: CommandRuntimeContext,\n interaction: InteractionSnapshot['interaction'],\n): Promise<void> {\n await emitLifecycleEvent(ctx, 'customers.interaction.reverted', {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n entityId: interaction.entityId,\n interactionType: interaction.interactionType,\n source: interaction.source ?? null,\n status: interaction.status,\n occurredAt: interaction.occurredAt?.toISOString() ?? null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n })\n}\n\ntype InteractionIdentifiers = {\n id: string\n organizationId: string\n tenantId: string\n}\n\ntype InteractionProjectionMutation = {\n entityId: string\n nextInteractionId: string | null\n}\n\nfunction createTransactionalDataEngine(ctx: CommandRuntimeContext, em: EntityManager): DataEngine {\n const emWithConnection = em as EntityManager & { getConnection?: () => unknown }\n if (typeof emWithConnection.getConnection !== 'function') {\n return ctx.container.resolve('dataEngine') as DataEngine\n }\n return new DefaultDataEngine(em, ctx.container)\n}\n\nasync function runInTransaction<TResult>(\n em: EntityManager,\n operation: (trx: EntityManager) => Promise<TResult>,\n): Promise<TResult> {\n // Mirrors the SPEC-018 fix applied to withAtomicFlush: use explicit begin/commit/rollback\n // so the outer EntityManager stays bound to the transaction, and closures over `em` inside\n // `operation` participate in the same transaction. This avoids the em.transactional(cb)\n // hazard where the callback receives a child EM whose flushes can silently race against\n // subsequent queries on the original `em`.\n const supportsBegin =\n typeof (em as unknown as { begin?: () => Promise<void> }).begin === 'function' &&\n typeof (em as unknown as { commit?: () => Promise<void> }).commit === 'function' &&\n typeof (em as unknown as { rollback?: () => Promise<void> }).rollback === 'function'\n if (!supportsBegin) {\n return operation(em)\n }\n await em.begin()\n try {\n const result = await operation(em)\n await em.commit()\n return result\n } catch (err) {\n try {\n await em.rollback()\n } catch {\n // rollback failure should not mask the original error; intentionally swallowed\n }\n throw err\n }\n}\n\nasync function emitNextInteractionUpdatedEvent(\n ctx: CommandRuntimeContext,\n projection: InteractionProjectionMutation,\n identifiers: InteractionIdentifiers,\n): Promise<void> {\n await emitQueryIndexUpsertEvents(ctx, [{\n entityType: 'customers:customer_entity',\n recordId: projection.entityId,\n organizationId: identifiers.organizationId,\n tenantId: identifiers.tenantId,\n }])\n await emitLifecycleEvent(ctx, 'customers.next_interaction.updated', {\n id: projection.entityId,\n entityId: projection.entityId,\n nextInteractionId: projection.nextInteractionId,\n organizationId: identifiers.organizationId,\n tenantId: identifiers.tenantId,\n })\n}\n\n// \u2500\u2500\u2500 Create \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst createInteractionCommand: CommandHandler<InteractionCreateInput, { interactionId: string; entityId: string }> = {\n id: 'customers.interactions.create',\n async execute(rawInput, ctx) {\n const { parsed, custom } = parseWithCustomFields(interactionCreateSchema, rawInput)\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const normalizedAuthor = normalizeAuthorUserId(parsed.authorUserId ?? null, ctx.auth)\n const { interaction, entityId, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const entity = await requireTimelineParentEntity(trx, parsed.entityId)\n ensureTenantScope(ctx, entity.tenantId)\n ensureOrganizationScope(ctx, entity.organizationId)\n\n if (parsed.dealId) {\n await requireDealInScope(trx, parsed.dealId, entity.tenantId, entity.organizationId)\n }\n\n const interaction = trx.create(CustomerInteraction, {\n ...(parsed.id ? { id: parsed.id } : {}),\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n entity,\n interactionType: parsed.interactionType,\n title: parsed.title ?? null,\n body: parsed.body ?? null,\n status: parsed.status ?? 'planned',\n scheduledAt: parsed.scheduledAt ?? null,\n occurredAt: parsed.occurredAt ?? null,\n priority: parsed.priority ?? null,\n authorUserId: normalizedAuthor,\n ownerUserId: parsed.ownerUserId ?? null,\n dealId: parsed.dealId ?? null,\n source: parsed.source ?? null,\n appearanceIcon: parsed.appearanceIcon ?? null,\n appearanceColor: parsed.appearanceColor ?? null,\n durationMinutes: parsed.durationMinutes ?? null,\n location: parsed.location ?? null,\n allDay: parsed.allDay ?? null,\n recurrenceRule: parsed.recurrenceRule ?? null,\n recurrenceEnd: parsed.recurrenceEnd ?? null,\n participants: parsed.participants ?? null,\n reminderMinutes: parsed.reminderMinutes ?? null,\n visibility: parsed.visibility ?? null,\n linkedEntities: parsed.linkedEntities ?? null,\n guestPermissions: parsed.guestPermissions ?? null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n trx.persist(interaction)\n await trx.flush()\n\n await setInteractionCustomFields(\n createTransactionalDataEngine(ctx, trx),\n interaction.id,\n entity.organizationId,\n entity.tenantId,\n custom,\n )\n\n const projection = await recomputeNextInteraction(trx, entity.id)\n\n return {\n interaction,\n entityId: entity.id,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'created',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n\n return { interactionId: interaction.id, entityId }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const snapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.create', 'Create interaction'),\n resourceKind: 'customers.interaction',\n resourceId: result.interactionId,\n parentResourceKind: resolveParentResourceKind(snapshot?.interaction?.entityKind),\n parentResourceId: snapshot?.interaction?.entityId ?? null,\n tenantId: snapshot?.interaction.tenantId ?? null,\n organizationId: snapshot?.interaction.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const interactionId = logEntry?.resourceId\n if (!interactionId) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const result = await runInTransaction(em, async (trx) => {\n const record = await findOneWithDecryption(trx, CustomerInteraction, { id: interactionId })\n if (!record) return null\n const entityId = typeof record.entity === 'string' ? record.entity : record.entity.id\n trx.remove(record)\n await trx.flush()\n const projection = await recomputeNextInteraction(trx, entityId)\n return {\n entityId,\n nextInteractionId: projection.nextInteractionId,\n identifiers: {\n id: record.id,\n organizationId: record.organizationId,\n tenantId: record.tenantId,\n },\n }\n })\n if (!result) return\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: result.entityId,\n nextInteractionId: result.nextInteractionId,\n }, result.identifiers)\n },\n}\n\n// \u2500\u2500\u2500 Update \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst updateInteractionCommand: CommandHandler<InteractionUpdateInput, { interactionId: string }> = {\n id: 'customers.interactions.update',\n async prepare(rawInput, ctx) {\n const { parsed } = parseWithCustomFields(interactionUpdateSchema, rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const { parsed, custom } = parseWithCustomFields(interactionUpdateSchema, rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: parsed.id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n if (parsed.dealId !== undefined) {\n if (parsed.dealId) {\n await requireDealInScope(trx, parsed.dealId, interaction.tenantId, interaction.organizationId)\n }\n interaction.dealId = parsed.dealId ?? null\n }\n if (parsed.interactionType !== undefined) interaction.interactionType = parsed.interactionType\n if (parsed.title !== undefined) interaction.title = parsed.title ?? null\n if (parsed.body !== undefined) interaction.body = parsed.body ?? null\n if (parsed.status !== undefined) interaction.status = parsed.status\n if (parsed.scheduledAt !== undefined) interaction.scheduledAt = parsed.scheduledAt ?? null\n if (parsed.occurredAt !== undefined) interaction.occurredAt = parsed.occurredAt ?? null\n if (parsed.priority !== undefined) interaction.priority = parsed.priority ?? null\n if (parsed.authorUserId !== undefined) interaction.authorUserId = parsed.authorUserId ?? null\n if (parsed.ownerUserId !== undefined) interaction.ownerUserId = parsed.ownerUserId ?? null\n if (parsed.appearanceIcon !== undefined) interaction.appearanceIcon = parsed.appearanceIcon ?? null\n if (parsed.appearanceColor !== undefined) interaction.appearanceColor = parsed.appearanceColor ?? null\n if (parsed.pinned !== undefined) interaction.pinned = parsed.pinned\n if (parsed.durationMinutes !== undefined) interaction.durationMinutes = parsed.durationMinutes ?? null\n if (parsed.location !== undefined) interaction.location = parsed.location ?? null\n if (parsed.allDay !== undefined) interaction.allDay = parsed.allDay ?? null\n if (parsed.recurrenceRule !== undefined) interaction.recurrenceRule = parsed.recurrenceRule ?? null\n if (parsed.recurrenceEnd !== undefined) interaction.recurrenceEnd = parsed.recurrenceEnd ?? null\n if (parsed.participants !== undefined) interaction.participants = parsed.participants ?? null\n if (parsed.reminderMinutes !== undefined) interaction.reminderMinutes = parsed.reminderMinutes ?? null\n if (parsed.visibility !== undefined) interaction.visibility = parsed.visibility ?? null\n if (parsed.linkedEntities !== undefined) interaction.linkedEntities = parsed.linkedEntities ?? null\n if (parsed.guestPermissions !== undefined) interaction.guestPermissions = parsed.guestPermissions ?? null\n\n await trx.flush()\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n await setInteractionCustomFields(\n createTransactionalDataEngine(ctx, trx),\n interaction.id,\n interaction.organizationId,\n interaction.tenantId,\n custom,\n )\n\n const projection = await recomputeNextInteraction(trx, entityId)\n\n return { interaction, entityId, nextInteractionId: projection.nextInteractionId }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n\n return { interactionId: interaction.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const afterSnapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.update', 'Update interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n snapshotAfter: afterSnapshot ?? null,\n payload: {\n undo: {\n before,\n after: afterSnapshot ?? null,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, nextInteractionId } = await runInTransaction(em, async (trx) => {\n let interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n const entity = await requireTimelineParentEntity(trx, before.interaction.entityId)\n\n if (!interaction) {\n interaction = trx.create(CustomerInteraction, {\n id: before.interaction.id,\n organizationId: before.interaction.organizationId,\n tenantId: before.interaction.tenantId,\n entity,\n interactionType: before.interaction.interactionType,\n title: before.interaction.title,\n body: before.interaction.body,\n status: before.interaction.status,\n scheduledAt: before.interaction.scheduledAt,\n occurredAt: before.interaction.occurredAt,\n priority: before.interaction.priority,\n authorUserId: before.interaction.authorUserId,\n ownerUserId: before.interaction.ownerUserId,\n dealId: before.interaction.dealId,\n source: before.interaction.source,\n appearanceIcon: before.interaction.appearanceIcon,\n appearanceColor: before.interaction.appearanceColor,\n durationMinutes: before.interaction.durationMinutes,\n location: before.interaction.location,\n allDay: before.interaction.allDay,\n recurrenceRule: before.interaction.recurrenceRule,\n recurrenceEnd: before.interaction.recurrenceEnd,\n participants: before.interaction.participants,\n reminderMinutes: before.interaction.reminderMinutes,\n visibility: before.interaction.visibility,\n linkedEntities: before.interaction.linkedEntities,\n guestPermissions: before.interaction.guestPermissions,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n trx.persist(interaction)\n } else {\n interaction.entity = entity\n interaction.interactionType = before.interaction.interactionType\n interaction.title = before.interaction.title\n interaction.body = before.interaction.body\n interaction.status = before.interaction.status\n interaction.scheduledAt = before.interaction.scheduledAt\n interaction.occurredAt = before.interaction.occurredAt\n interaction.priority = before.interaction.priority\n interaction.authorUserId = before.interaction.authorUserId\n interaction.ownerUserId = before.interaction.ownerUserId\n interaction.dealId = before.interaction.dealId\n interaction.source = before.interaction.source\n interaction.appearanceIcon = before.interaction.appearanceIcon\n interaction.appearanceColor = before.interaction.appearanceColor\n interaction.durationMinutes = before.interaction.durationMinutes\n interaction.location = before.interaction.location\n interaction.allDay = before.interaction.allDay\n interaction.recurrenceRule = before.interaction.recurrenceRule\n interaction.recurrenceEnd = before.interaction.recurrenceEnd\n interaction.participants = before.interaction.participants\n interaction.reminderMinutes = before.interaction.reminderMinutes\n interaction.visibility = before.interaction.visibility\n interaction.linkedEntities = before.interaction.linkedEntities\n interaction.guestPermissions = before.interaction.guestPermissions\n }\n\n await trx.flush()\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n\n const resetValues = buildCustomFieldResetMap(before.custom, payload?.after?.custom)\n if (Object.keys(resetValues).length) {\n await setCustomFieldsIfAny({\n dataEngine: createTransactionalDataEngine(ctx, trx),\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n values: resetValues,\n notify: false,\n })\n }\n\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId,\n }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n },\n}\n\n// \u2500\u2500\u2500 Complete \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst completeInteractionCommand: CommandHandler<InteractionCompleteInput, { interactionId: string }> = {\n id: 'customers.interactions.complete',\n async prepare(rawInput, ctx) {\n const parsed = interactionCompleteSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = interactionCompleteSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: parsed.id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n interaction.status = 'done'\n interaction.occurredAt = parsed.occurredAt ?? new Date()\n await trx.flush()\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n const projection = await recomputeNextInteraction(trx, entityId)\n return { interaction, entityId, nextInteractionId: projection.nextInteractionId }\n })\n\n const identifiers = {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n }\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers,\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitLifecycleEvent(ctx, 'customers.interaction.completed', {\n ...identifiers,\n entityId,\n interactionType: interaction.interactionType,\n status: interaction.status,\n source: interaction.source ?? null,\n occurredAt: interaction.occurredAt?.toISOString() ?? null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, identifiers)\n\n return { interactionId: interaction.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const afterSnapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.complete', 'Complete interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n snapshotAfter: afterSnapshot ?? null,\n payload: {\n undo: {\n before,\n after: afterSnapshot ?? null,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const result = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n if (!interaction) return null\n\n interaction.status = before.interaction.status\n interaction.occurredAt = before.interaction.occurredAt\n await trx.flush()\n\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n if (!result) return\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: result.interaction,\n identifiers: {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitInteractionRevertedEvent(ctx, before.interaction)\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId: result.nextInteractionId,\n }, {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n })\n },\n}\n\n// \u2500\u2500\u2500 Cancel \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst cancelInteractionCommand: CommandHandler<InteractionCancelInput, { interactionId: string }> = {\n id: 'customers.interactions.cancel',\n async prepare(rawInput, ctx) {\n const parsed = interactionCancelSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = interactionCancelSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: parsed.id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n interaction.status = 'canceled'\n await trx.flush()\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n const projection = await recomputeNextInteraction(trx, entityId)\n return { interaction, entityId, nextInteractionId: projection.nextInteractionId }\n })\n\n const identifiers = {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n }\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers,\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitLifecycleEvent(ctx, 'customers.interaction.canceled', {\n ...identifiers,\n entityId,\n interactionType: interaction.interactionType,\n status: interaction.status,\n source: interaction.source ?? null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, identifiers)\n\n return { interactionId: interaction.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const afterSnapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.cancel', 'Cancel interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n snapshotAfter: afterSnapshot ?? null,\n payload: {\n undo: {\n before,\n after: afterSnapshot ?? null,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const result = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n if (!interaction) return null\n\n interaction.status = before.interaction.status\n await trx.flush()\n\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n if (!result) return\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: result.interaction,\n identifiers: {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitInteractionRevertedEvent(ctx, before.interaction)\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId: result.nextInteractionId,\n }, {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n })\n },\n}\n\n// \u2500\u2500\u2500 Delete \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst deleteInteractionCommand: CommandHandler<{ body?: Record<string, unknown>; query?: Record<string, unknown> }, { interactionId: string }> =\n {\n id: 'customers.interactions.delete',\n async prepare(input, ctx) {\n const id = requireId(input, 'Interaction id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const id = requireId(input, 'Interaction id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n interaction.deletedAt = new Date()\n await trx.flush()\n\n const projection = await recomputeNextInteraction(trx, entityId)\n return { interaction, entityId, nextInteractionId: projection.nextInteractionId }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'deleted',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n return { interactionId: interaction.id }\n },\n buildLog: async ({ snapshots }) => {\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('customers.audit.interactions.delete', 'Delete interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n payload: {\n undo: {\n before,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const entity = await requireTimelineParentEntity(trx, before.interaction.entityId)\n let interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n if (!interaction) {\n interaction = trx.create(CustomerInteraction, {\n id: before.interaction.id,\n organizationId: before.interaction.organizationId,\n tenantId: before.interaction.tenantId,\n entity,\n interactionType: before.interaction.interactionType,\n title: before.interaction.title,\n body: before.interaction.body,\n status: before.interaction.status,\n scheduledAt: before.interaction.scheduledAt,\n occurredAt: before.interaction.occurredAt,\n priority: before.interaction.priority,\n authorUserId: before.interaction.authorUserId,\n ownerUserId: before.interaction.ownerUserId,\n dealId: before.interaction.dealId,\n source: before.interaction.source,\n appearanceIcon: before.interaction.appearanceIcon,\n appearanceColor: before.interaction.appearanceColor,\n durationMinutes: before.interaction.durationMinutes,\n location: before.interaction.location,\n allDay: before.interaction.allDay,\n recurrenceRule: before.interaction.recurrenceRule,\n recurrenceEnd: before.interaction.recurrenceEnd,\n participants: before.interaction.participants,\n reminderMinutes: before.interaction.reminderMinutes,\n visibility: before.interaction.visibility,\n linkedEntities: before.interaction.linkedEntities,\n guestPermissions: before.interaction.guestPermissions,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n trx.persist(interaction)\n } else {\n interaction.deletedAt = null\n interaction.entity = entity\n interaction.interactionType = before.interaction.interactionType\n interaction.title = before.interaction.title\n interaction.body = before.interaction.body\n interaction.status = before.interaction.status\n interaction.scheduledAt = before.interaction.scheduledAt\n interaction.occurredAt = before.interaction.occurredAt\n interaction.priority = before.interaction.priority\n interaction.authorUserId = before.interaction.authorUserId\n interaction.ownerUserId = before.interaction.ownerUserId\n interaction.dealId = before.interaction.dealId\n interaction.source = before.interaction.source\n interaction.appearanceIcon = before.interaction.appearanceIcon\n interaction.appearanceColor = before.interaction.appearanceColor\n interaction.durationMinutes = before.interaction.durationMinutes\n interaction.location = before.interaction.location\n interaction.allDay = before.interaction.allDay\n interaction.recurrenceRule = before.interaction.recurrenceRule\n interaction.recurrenceEnd = before.interaction.recurrenceEnd\n interaction.participants = before.interaction.participants\n interaction.reminderMinutes = before.interaction.reminderMinutes\n interaction.visibility = before.interaction.visibility\n interaction.linkedEntities = before.interaction.linkedEntities\n interaction.guestPermissions = before.interaction.guestPermissions\n }\n await trx.flush()\n\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n\n const resetValues = buildCustomFieldResetMap(before.custom, undefined)\n if (Object.keys(resetValues).length) {\n await setCustomFieldsIfAny({\n dataEngine: createTransactionalDataEngine(ctx, trx),\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n values: resetValues,\n notify: false,\n })\n }\n\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'created',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId,\n }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n },\n }\n\n// \u2500\u2500\u2500 Recompute Next (internal repair) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst recomputeNextSchema = z.object({ entityId: z.string().min(1) })\n\nconst recomputeNextCommand: CommandHandler<{ entityId: string }, { entityId: string }> = {\n id: 'customers.interaction.recompute_next',\n async execute(rawInput, ctx) {\n const parsed = recomputeNextSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const projection = await recomputeNextInteraction(em, parsed.entityId)\n const entity = await requireTimelineParentEntity(em, parsed.entityId)\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: parsed.entityId,\n nextInteractionId: projection.nextInteractionId,\n }, {\n id: parsed.entityId,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n })\n return { entityId: parsed.entityId }\n },\n}\n\nregisterCommand(createInteractionCommand)\nregisterCommand(updateInteractionCommand)\nregisterCommand(completeInteractionCommand)\nregisterCommand(cancelInteractionCommand)\nregisterCommand(deleteInteractionCommand)\nregisterCommand(recomputeNextCommand)\n"],
5
+ "mappings": "AAAA,SAAS,SAAS;AAClB,SAAS,uBAAuB;AAEhC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAA0C;AAGnD,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAEtC,SAAS,gCAAgC;AAEzC,MAAM,wBAAwB;AAC9B,MAAM,yBAAiE;AAAA,EACrE,YAAY;AACd;AAEA,MAAM,wBAA0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,gBAAgB,0BAA0B;AAC1C,gBAAgB,wBAAwB;AACxC,gBAAgB,wBAAwB;AACxC,gBAAgB,oBAAoB;",
6
6
  "names": ["interaction", "entityId"]
7
7
  }
@@ -823,21 +823,24 @@ const deletePersonCommand = {
823
823
  throw buildPersonHasDependentsError(translate, { dealLinks });
824
824
  }
825
825
  const profile = await em.findOne(CustomerPersonProfile, { entity: record });
826
- if (profile) em.remove(profile);
827
- await em.nativeDelete(CustomerAddress, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId });
828
- await em.nativeDelete(CustomerComment, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId });
829
- await em.nativeDelete(CustomerActivity, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId });
830
- await em.nativeDelete(CustomerInteraction, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId });
831
- await em.nativeDelete(CustomerTodoLink, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId });
832
- await em.nativeDelete(CustomerTagAssignment, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId });
833
- await em.nativeDelete(CustomerDealPersonLink, { person: record });
834
- await em.nativeDelete(CustomerPersonCompanyLink, { person: record });
835
- if (profile) {
836
- await em.nativeDelete(CustomFieldValue, { entityId: PERSON_ENTITY_ID, recordId: profile.id });
837
- }
838
- await em.nativeDelete(CustomFieldValue, { entityId: CUSTOMER_ENTITY_ID, recordId: record.id });
839
- em.remove(record);
840
- await em.flush();
826
+ await withAtomicFlush(em, [
827
+ async () => {
828
+ if (profile) em.remove(profile);
829
+ await em.nativeDelete(CustomerAddress, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId });
830
+ await em.nativeDelete(CustomerComment, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId });
831
+ await em.nativeDelete(CustomerActivity, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId });
832
+ await em.nativeDelete(CustomerInteraction, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId });
833
+ await em.nativeDelete(CustomerTodoLink, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId });
834
+ await em.nativeDelete(CustomerTagAssignment, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId });
835
+ await em.nativeDelete(CustomerDealPersonLink, { person: record });
836
+ await em.nativeDelete(CustomerPersonCompanyLink, { person: record });
837
+ if (profile) {
838
+ await em.nativeDelete(CustomFieldValue, { entityId: PERSON_ENTITY_ID, recordId: profile.id });
839
+ }
840
+ await em.nativeDelete(CustomFieldValue, { entityId: CUSTOMER_ENTITY_ID, recordId: record.id });
841
+ em.remove(record);
842
+ }
843
+ ], { transaction: true });
841
844
  const indexDeletes = [];
842
845
  const dealUpserts = [];
843
846
  if (snapshot) {