@open-mercato/core 0.7.1-develop.7178.1.ab93fbaf4e → 0.7.1-develop.7180.1.9717fbbb43

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 (808) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/dist/generated/entities/staff_time_entry/index.js +14 -0
  3. package/dist/generated/entities/staff_time_entry/index.js.map +2 -2
  4. package/dist/generated/entities/staff_time_entry_tag/index.js +15 -0
  5. package/dist/generated/entities/staff_time_entry_tag/index.js.map +7 -0
  6. package/dist/generated/entities/staff_time_project/index.js +16 -0
  7. package/dist/generated/entities/staff_time_project/index.js.map +2 -2
  8. package/dist/generated/entities/staff_time_report/index.js +57 -0
  9. package/dist/generated/entities/staff_time_report/index.js.map +7 -0
  10. package/dist/generated/entities/staff_time_report_entry/index.js +27 -0
  11. package/dist/generated/entities/staff_time_report_entry/index.js.map +7 -0
  12. package/dist/generated/entities/staff_time_report_event/index.js +21 -0
  13. package/dist/generated/entities/staff_time_report_event/index.js.map +7 -0
  14. package/dist/generated/entities/staff_time_report_project/index.js +15 -0
  15. package/dist/generated/entities/staff_time_report_project/index.js.map +7 -0
  16. package/dist/generated/entities/staff_time_tag/index.js +21 -0
  17. package/dist/generated/entities/staff_time_tag/index.js.map +7 -0
  18. package/dist/generated/entities/staff_time_task/index.js +37 -0
  19. package/dist/generated/entities/staff_time_task/index.js.map +7 -0
  20. package/dist/generated/entities/staff_time_task_comment/index.js +21 -0
  21. package/dist/generated/entities/staff_time_task_comment/index.js.map +7 -0
  22. package/dist/generated/entities/staff_time_task_status/index.js +29 -0
  23. package/dist/generated/entities/staff_time_task_status/index.js.map +7 -0
  24. package/dist/generated/entities/staff_time_task_tag/index.js +15 -0
  25. package/dist/generated/entities/staff_time_task_tag/index.js.map +7 -0
  26. package/dist/generated/entities.ids.generated.js +11 -1
  27. package/dist/generated/entities.ids.generated.js.map +2 -2
  28. package/dist/generated/entity-fields-registry.js +149 -0
  29. package/dist/generated/entity-fields-registry.js.map +2 -2
  30. package/dist/helpers/integration/timesheetFixtures.js +7 -0
  31. package/dist/helpers/integration/timesheetFixtures.js.map +2 -2
  32. package/dist/modules/auth/cli.js +16 -0
  33. package/dist/modules/auth/cli.js.map +2 -2
  34. package/dist/modules/auth/lib/backendChrome.js +1 -0
  35. package/dist/modules/auth/lib/backendChrome.js.map +2 -2
  36. package/dist/modules/customer_accounts/lib/customerRoleAcls.js +44 -0
  37. package/dist/modules/customer_accounts/lib/customerRoleAcls.js.map +7 -0
  38. package/dist/modules/customer_accounts/setup.js +1 -28
  39. package/dist/modules/customer_accounts/setup.js.map +2 -2
  40. package/dist/modules/data_sync/api/options.js +2 -0
  41. package/dist/modules/data_sync/api/options.js.map +2 -2
  42. package/dist/modules/data_sync/backend/data-sync/page.js +39 -17
  43. package/dist/modules/data_sync/backend/data-sync/page.js.map +2 -2
  44. package/dist/modules/data_sync/lib/start-controls.js +42 -0
  45. package/dist/modules/data_sync/lib/start-controls.js.map +7 -0
  46. package/dist/modules/staff/acl.js +9 -1
  47. package/dist/modules/staff/acl.js.map +2 -2
  48. package/dist/modules/staff/ai-agents.js +142 -0
  49. package/dist/modules/staff/ai-agents.js.map +7 -0
  50. package/dist/modules/staff/ai-tools/time-tracking-pack.js +348 -0
  51. package/dist/modules/staff/ai-tools/time-tracking-pack.js.map +7 -0
  52. package/dist/modules/staff/ai-tools/types.js +54 -0
  53. package/dist/modules/staff/ai-tools/types.js.map +7 -0
  54. package/dist/modules/staff/ai-tools.js +8 -0
  55. package/dist/modules/staff/ai-tools.js.map +7 -0
  56. package/dist/modules/staff/analytics.js +84 -1
  57. package/dist/modules/staff/analytics.js.map +2 -2
  58. package/dist/modules/staff/api/guards.js +37 -3
  59. package/dist/modules/staff/api/guards.js.map +2 -2
  60. package/dist/modules/staff/api/leave-requests/accept/route.js +1 -3
  61. package/dist/modules/staff/api/leave-requests/accept/route.js.map +2 -2
  62. package/dist/modules/staff/api/leave-requests/reject/route.js +1 -3
  63. package/dist/modules/staff/api/leave-requests/reject/route.js.map +2 -2
  64. package/dist/modules/staff/api/portal/time-reports/[id]/route.js +131 -0
  65. package/dist/modules/staff/api/portal/time-reports/[id]/route.js.map +7 -0
  66. package/dist/modules/staff/api/portal/time-reports/route.js +179 -0
  67. package/dist/modules/staff/api/portal/time-reports/route.js.map +7 -0
  68. package/dist/modules/staff/api/team-members/self/route.js +1 -3
  69. package/dist/modules/staff/api/team-members/self/route.js.map +2 -2
  70. package/dist/modules/staff/api/team-members/tags/assign/route.js +1 -3
  71. package/dist/modules/staff/api/team-members/tags/assign/route.js.map +2 -2
  72. package/dist/modules/staff/api/team-members/tags/unassign/route.js +1 -3
  73. package/dist/modules/staff/api/team-members/tags/unassign/route.js.map +2 -2
  74. package/dist/modules/staff/api/timesheets/_shared/withTimesheetInterceptors.js +174 -0
  75. package/dist/modules/staff/api/timesheets/_shared/withTimesheetInterceptors.js.map +7 -0
  76. package/dist/modules/staff/api/timesheets/access-requests/route.js +226 -0
  77. package/dist/modules/staff/api/timesheets/access-requests/route.js.map +7 -0
  78. package/dist/modules/staff/api/timesheets/my-projects/[projectId]/route.js +15 -8
  79. package/dist/modules/staff/api/timesheets/my-projects/[projectId]/route.js.map +2 -2
  80. package/dist/modules/staff/api/timesheets/my-projects/route.js +13 -1
  81. package/dist/modules/staff/api/timesheets/my-projects/route.js.map +2 -2
  82. package/dist/modules/staff/api/timesheets/my-work/myWorkAggregate.js +42 -0
  83. package/dist/modules/staff/api/timesheets/my-work/myWorkAggregate.js.map +7 -0
  84. package/dist/modules/staff/api/timesheets/my-work/route.js +383 -0
  85. package/dist/modules/staff/api/timesheets/my-work/route.js.map +7 -0
  86. package/dist/modules/staff/api/timesheets/projects/kpis/route.js +14 -2
  87. package/dist/modules/staff/api/timesheets/projects/kpis/route.js.map +2 -2
  88. package/dist/modules/staff/api/timesheets/reports/[id]/close/route.js +168 -0
  89. package/dist/modules/staff/api/timesheets/reports/[id]/close/route.js.map +7 -0
  90. package/dist/modules/staff/api/timesheets/reports/[id]/export/route.js +246 -0
  91. package/dist/modules/staff/api/timesheets/reports/[id]/export/route.js.map +7 -0
  92. package/dist/modules/staff/api/timesheets/reports/[id]/sheet/route.js +183 -0
  93. package/dist/modules/staff/api/timesheets/reports/[id]/sheet/route.js.map +7 -0
  94. package/dist/modules/staff/api/timesheets/reports/[id]/unlock/route.js +164 -0
  95. package/dist/modules/staff/api/timesheets/reports/[id]/unlock/route.js.map +7 -0
  96. package/dist/modules/staff/api/timesheets/reports/preview/route.js +360 -0
  97. package/dist/modules/staff/api/timesheets/reports/preview/route.js.map +7 -0
  98. package/dist/modules/staff/api/timesheets/reports/route.js +316 -0
  99. package/dist/modules/staff/api/timesheets/reports/route.js.map +7 -0
  100. package/dist/modules/staff/api/timesheets/reports/shared.js +63 -0
  101. package/dist/modules/staff/api/timesheets/reports/shared.js.map +7 -0
  102. package/dist/modules/staff/api/timesheets/settings/reapply-rounding/route.js +164 -0
  103. package/dist/modules/staff/api/timesheets/settings/reapply-rounding/route.js.map +7 -0
  104. package/dist/modules/staff/api/timesheets/settings/rounding-impact/route.js +168 -0
  105. package/dist/modules/staff/api/timesheets/settings/rounding-impact/route.js.map +7 -0
  106. package/dist/modules/staff/api/timesheets/settings/route.js +199 -0
  107. package/dist/modules/staff/api/timesheets/settings/route.js.map +7 -0
  108. package/dist/modules/staff/api/timesheets/tags/access.js +76 -0
  109. package/dist/modules/staff/api/timesheets/tags/access.js.map +7 -0
  110. package/dist/modules/staff/api/timesheets/tags/entry-assignments/route.js +235 -0
  111. package/dist/modules/staff/api/timesheets/tags/entry-assignments/route.js.map +7 -0
  112. package/dist/modules/staff/api/timesheets/tags/route.js +160 -0
  113. package/dist/modules/staff/api/timesheets/tags/route.js.map +7 -0
  114. package/dist/modules/staff/api/timesheets/tags/task-assignments/route.js +233 -0
  115. package/dist/modules/staff/api/timesheets/tags/task-assignments/route.js.map +7 -0
  116. package/dist/modules/staff/api/timesheets/task-statuses/route.js +188 -0
  117. package/dist/modules/staff/api/timesheets/task-statuses/route.js.map +7 -0
  118. package/dist/modules/staff/api/timesheets/tasks/[id]/comments/route.js +399 -0
  119. package/dist/modules/staff/api/timesheets/tasks/[id]/comments/route.js.map +7 -0
  120. package/dist/modules/staff/api/timesheets/tasks/[id]/status/route.js +210 -0
  121. package/dist/modules/staff/api/timesheets/tasks/[id]/status/route.js.map +7 -0
  122. package/dist/modules/staff/api/timesheets/tasks/route.js +333 -0
  123. package/dist/modules/staff/api/timesheets/tasks/route.js.map +7 -0
  124. package/dist/modules/staff/api/timesheets/time-entries/[id]/duplicate/route.js +228 -0
  125. package/dist/modules/staff/api/timesheets/time-entries/[id]/duplicate/route.js.map +7 -0
  126. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/[segmentId]/route.js +29 -10
  127. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/[segmentId]/route.js.map +2 -2
  128. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/route.js +31 -18
  129. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/route.js.map +2 -2
  130. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.js +21 -7
  131. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.js.map +2 -2
  132. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-stop/route.js +27 -7
  133. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-stop/route.js.map +2 -2
  134. package/dist/modules/staff/api/timesheets/time-entries/bulk/route.js +215 -32
  135. package/dist/modules/staff/api/timesheets/time-entries/bulk/route.js.map +2 -2
  136. package/dist/modules/staff/api/timesheets/time-entries/copy-day/route.js +378 -0
  137. package/dist/modules/staff/api/timesheets/time-entries/copy-day/route.js.map +7 -0
  138. package/dist/modules/staff/api/timesheets/time-entries/overlaps/route.js +340 -0
  139. package/dist/modules/staff/api/timesheets/time-entries/overlaps/route.js.map +7 -0
  140. package/dist/modules/staff/api/timesheets/time-entries/route.js +238 -26
  141. package/dist/modules/staff/api/timesheets/time-entries/route.js.map +2 -2
  142. package/dist/modules/staff/api/timesheets/time-entries/start-timer/route.js +23 -8
  143. package/dist/modules/staff/api/timesheets/time-entries/start-timer/route.js.map +2 -2
  144. package/dist/modules/staff/api/timesheets/time-projects/[id]/change-currency/route.js +209 -0
  145. package/dist/modules/staff/api/timesheets/time-projects/[id]/change-currency/route.js.map +7 -0
  146. package/dist/modules/staff/api/timesheets/time-projects/[id]/employees/route.js +59 -2
  147. package/dist/modules/staff/api/timesheets/time-projects/[id]/employees/route.js.map +2 -2
  148. package/dist/modules/staff/api/timesheets/time-projects/route.js +264 -22
  149. package/dist/modules/staff/api/timesheets/time-projects/route.js.map +2 -2
  150. package/dist/modules/staff/backend/staff/time-tracking/board/page.js +110 -0
  151. package/dist/modules/staff/backend/staff/time-tracking/board/page.js.map +7 -0
  152. package/dist/modules/staff/backend/staff/time-tracking/board/page.meta.js +18 -0
  153. package/dist/modules/staff/backend/staff/time-tracking/board/page.meta.js.map +7 -0
  154. package/dist/modules/staff/backend/staff/time-tracking/entries/page.js +981 -0
  155. package/dist/modules/staff/backend/staff/time-tracking/entries/page.js.map +7 -0
  156. package/dist/modules/staff/backend/staff/time-tracking/entries/page.meta.js +18 -0
  157. package/dist/modules/staff/backend/staff/time-tracking/entries/page.meta.js.map +7 -0
  158. package/dist/modules/staff/backend/staff/time-tracking/page.js +583 -0
  159. package/dist/modules/staff/backend/staff/time-tracking/page.js.map +7 -0
  160. package/dist/modules/staff/backend/staff/time-tracking/page.meta.js +15 -0
  161. package/dist/modules/staff/backend/staff/time-tracking/page.meta.js.map +7 -0
  162. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/board/page.js +65 -0
  163. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/board/page.js.map +7 -0
  164. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/board/page.meta.js +16 -0
  165. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/board/page.meta.js.map +7 -0
  166. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/edit/page.js +229 -0
  167. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/edit/page.js.map +7 -0
  168. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/edit/page.meta.js +16 -0
  169. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/edit/page.meta.js.map +7 -0
  170. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/page.js +1014 -0
  171. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/page.js.map +7 -0
  172. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/page.meta.js +16 -0
  173. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/page.meta.js.map +7 -0
  174. package/dist/modules/staff/backend/staff/time-tracking/projects/create/page.js +97 -0
  175. package/dist/modules/staff/backend/staff/time-tracking/projects/create/page.js.map +7 -0
  176. package/dist/modules/staff/backend/staff/time-tracking/projects/create/page.meta.js +16 -0
  177. package/dist/modules/staff/backend/staff/time-tracking/projects/create/page.meta.js.map +7 -0
  178. package/dist/modules/staff/backend/staff/time-tracking/projects/page.js +1040 -0
  179. package/dist/modules/staff/backend/staff/time-tracking/projects/page.js.map +7 -0
  180. package/dist/modules/staff/backend/staff/time-tracking/projects/page.meta.js +19 -0
  181. package/dist/modules/staff/backend/staff/time-tracking/projects/page.meta.js.map +7 -0
  182. package/dist/modules/staff/backend/staff/time-tracking/projects/projectFormConfig.js +353 -0
  183. package/dist/modules/staff/backend/staff/time-tracking/projects/projectFormConfig.js.map +7 -0
  184. package/dist/modules/staff/backend/staff/time-tracking/reports/[id]/page.js +457 -0
  185. package/dist/modules/staff/backend/staff/time-tracking/reports/[id]/page.js.map +7 -0
  186. package/dist/modules/staff/backend/staff/time-tracking/reports/[id]/page.meta.js +16 -0
  187. package/dist/modules/staff/backend/staff/time-tracking/reports/[id]/page.meta.js.map +7 -0
  188. package/dist/modules/staff/backend/staff/time-tracking/reports/create/page.js +697 -0
  189. package/dist/modules/staff/backend/staff/time-tracking/reports/create/page.js.map +7 -0
  190. package/dist/modules/staff/backend/staff/time-tracking/reports/create/page.meta.js +16 -0
  191. package/dist/modules/staff/backend/staff/time-tracking/reports/create/page.meta.js.map +7 -0
  192. package/dist/modules/staff/backend/staff/time-tracking/reports/page.js +174 -0
  193. package/dist/modules/staff/backend/staff/time-tracking/reports/page.js.map +7 -0
  194. package/dist/modules/staff/backend/staff/time-tracking/reports/page.meta.js +18 -0
  195. package/dist/modules/staff/backend/staff/time-tracking/reports/page.meta.js.map +7 -0
  196. package/dist/modules/staff/backend/staff/time-tracking/settings/page.js +546 -0
  197. package/dist/modules/staff/backend/staff/time-tracking/settings/page.js.map +7 -0
  198. package/dist/modules/staff/backend/staff/time-tracking/settings/page.meta.js +18 -0
  199. package/dist/modules/staff/backend/staff/time-tracking/settings/page.meta.js.map +7 -0
  200. package/dist/modules/staff/backend/staff/time-tracking/timesheet/GridView.js +710 -0
  201. package/dist/modules/staff/backend/staff/time-tracking/timesheet/GridView.js.map +7 -0
  202. package/dist/modules/staff/backend/staff/time-tracking/timesheet/page.js +646 -0
  203. package/dist/modules/staff/backend/staff/time-tracking/timesheet/page.js.map +7 -0
  204. package/dist/modules/staff/backend/staff/time-tracking/timesheet/page.meta.js +18 -0
  205. package/dist/modules/staff/backend/staff/time-tracking/timesheet/page.meta.js.map +7 -0
  206. package/dist/modules/staff/backend/staff/timesheets/page.js +4 -793
  207. package/dist/modules/staff/backend/staff/timesheets/page.js.map +2 -2
  208. package/dist/modules/staff/backend/staff/timesheets/page.meta.js +2 -7
  209. package/dist/modules/staff/backend/staff/timesheets/page.meta.js.map +2 -2
  210. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.js +5 -136
  211. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.js.map +2 -2
  212. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.meta.js +1 -7
  213. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.meta.js.map +2 -2
  214. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.js +5 -445
  215. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.js.map +3 -3
  216. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.meta.js +1 -7
  217. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.meta.js.map +2 -2
  218. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.js +4 -76
  219. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.js.map +2 -2
  220. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.meta.js +1 -7
  221. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.meta.js.map +2 -2
  222. package/dist/modules/staff/backend/staff/timesheets/projects/page.js +4 -613
  223. package/dist/modules/staff/backend/staff/timesheets/projects/page.js.map +2 -2
  224. package/dist/modules/staff/backend/staff/timesheets/projects/page.meta.js +2 -17
  225. package/dist/modules/staff/backend/staff/timesheets/projects/page.meta.js.map +2 -2
  226. package/dist/modules/staff/ce.js +40 -0
  227. package/dist/modules/staff/ce.js.map +2 -2
  228. package/dist/modules/staff/cli.js +166 -1
  229. package/dist/modules/staff/cli.js.map +2 -2
  230. package/dist/modules/staff/commands/index.js +5 -0
  231. package/dist/modules/staff/commands/index.js.map +2 -2
  232. package/dist/modules/staff/commands/timesheets-entries.js +569 -21
  233. package/dist/modules/staff/commands/timesheets-entries.js.map +3 -3
  234. package/dist/modules/staff/commands/timesheets-projects.js +450 -7
  235. package/dist/modules/staff/commands/timesheets-projects.js.map +2 -2
  236. package/dist/modules/staff/commands/timesheets-reports.js +1036 -0
  237. package/dist/modules/staff/commands/timesheets-reports.js.map +7 -0
  238. package/dist/modules/staff/commands/timesheets-tags.js +1015 -0
  239. package/dist/modules/staff/commands/timesheets-tags.js.map +7 -0
  240. package/dist/modules/staff/commands/timesheets-task-comments.js +438 -0
  241. package/dist/modules/staff/commands/timesheets-task-comments.js.map +7 -0
  242. package/dist/modules/staff/commands/timesheets-task-statuses.js +723 -0
  243. package/dist/modules/staff/commands/timesheets-task-statuses.js.map +7 -0
  244. package/dist/modules/staff/commands/timesheets-tasks.js +834 -0
  245. package/dist/modules/staff/commands/timesheets-tasks.js.map +7 -0
  246. package/dist/modules/staff/data/enrichers.js +426 -12
  247. package/dist/modules/staff/data/enrichers.js.map +2 -2
  248. package/dist/modules/staff/data/entities.js +552 -3
  249. package/dist/modules/staff/data/entities.js.map +2 -2
  250. package/dist/modules/staff/data/extensions.js +41 -0
  251. package/dist/modules/staff/data/extensions.js.map +7 -0
  252. package/dist/modules/staff/data/validators.js +254 -9
  253. package/dist/modules/staff/data/validators.js.map +2 -2
  254. package/dist/modules/staff/di.js +42 -1
  255. package/dist/modules/staff/di.js.map +2 -2
  256. package/dist/modules/staff/events.js +84 -6
  257. package/dist/modules/staff/events.js.map +2 -2
  258. package/dist/modules/staff/events.payloads.js +158 -0
  259. package/dist/modules/staff/events.payloads.js.map +7 -0
  260. package/dist/modules/staff/extension-points.js +261 -0
  261. package/dist/modules/staff/extension-points.js.map +7 -0
  262. package/dist/modules/staff/frontend/[orgSlug]/portal/time-reports/[id]/page.js +138 -0
  263. package/dist/modules/staff/frontend/[orgSlug]/portal/time-reports/[id]/page.js.map +7 -0
  264. package/dist/modules/staff/frontend/[orgSlug]/portal/time-reports/[id]/page.meta.js +12 -0
  265. package/dist/modules/staff/frontend/[orgSlug]/portal/time-reports/[id]/page.meta.js.map +7 -0
  266. package/dist/modules/staff/frontend/[orgSlug]/portal/time-reports/page.js +133 -0
  267. package/dist/modules/staff/frontend/[orgSlug]/portal/time-reports/page.js.map +7 -0
  268. package/dist/modules/staff/frontend/[orgSlug]/portal/time-reports/page.meta.js +19 -0
  269. package/dist/modules/staff/frontend/[orgSlug]/portal/time-reports/page.meta.js.map +7 -0
  270. package/dist/modules/staff/lib/crud.js +11 -1
  271. package/dist/modules/staff/lib/crud.js.map +2 -2
  272. package/dist/modules/staff/lib/time-tracking/access.js +92 -0
  273. package/dist/modules/staff/lib/time-tracking/access.js.map +7 -0
  274. package/dist/modules/staff/lib/time-tracking/billability.js +39 -0
  275. package/dist/modules/staff/lib/time-tracking/billability.js.map +7 -0
  276. package/dist/modules/staff/lib/time-tracking/capacity.js +68 -0
  277. package/dist/modules/staff/lib/time-tracking/capacity.js.map +7 -0
  278. package/dist/modules/staff/lib/time-tracking/componentContracts.js +15 -0
  279. package/dist/modules/staff/lib/time-tracking/componentContracts.js.map +7 -0
  280. package/dist/modules/staff/lib/time-tracking/cost.js +82 -0
  281. package/dist/modules/staff/lib/time-tracking/cost.js.map +7 -0
  282. package/dist/modules/staff/lib/time-tracking/duration.js +55 -0
  283. package/dist/modules/staff/lib/time-tracking/duration.js.map +7 -0
  284. package/dist/modules/staff/lib/time-tracking/featureAccess.js +41 -0
  285. package/dist/modules/staff/lib/time-tracking/featureAccess.js.map +7 -0
  286. package/dist/modules/staff/lib/time-tracking/interval.js +72 -0
  287. package/dist/modules/staff/lib/time-tracking/interval.js.map +7 -0
  288. package/dist/modules/staff/lib/time-tracking/migrateProjectCodes.js +88 -0
  289. package/dist/modules/staff/lib/time-tracking/migrateProjectCodes.js.map +7 -0
  290. package/dist/modules/staff/lib/time-tracking/moneyVisibility.js +10 -0
  291. package/dist/modules/staff/lib/time-tracking/moneyVisibility.js.map +7 -0
  292. package/dist/modules/staff/lib/time-tracking/overlap.js +87 -0
  293. package/dist/modules/staff/lib/time-tracking/overlap.js.map +7 -0
  294. package/dist/modules/staff/lib/time-tracking/portalRecipients.js +27 -0
  295. package/dist/modules/staff/lib/time-tracking/portalRecipients.js.map +7 -0
  296. package/dist/modules/staff/lib/time-tracking/portalReports.js +16 -0
  297. package/dist/modules/staff/lib/time-tracking/portalReports.js.map +7 -0
  298. package/dist/modules/staff/lib/time-tracking/projectCode.js +135 -0
  299. package/dist/modules/staff/lib/time-tracking/projectCode.js.map +7 -0
  300. package/dist/modules/staff/lib/time-tracking/reapplyRounding.js +187 -0
  301. package/dist/modules/staff/lib/time-tracking/reapplyRounding.js.map +7 -0
  302. package/dist/modules/staff/lib/time-tracking/recalculationRunner.js +80 -0
  303. package/dist/modules/staff/lib/time-tracking/recalculationRunner.js.map +7 -0
  304. package/dist/modules/staff/lib/time-tracking/recalculations.js +56 -0
  305. package/dist/modules/staff/lib/time-tracking/recalculations.js.map +7 -0
  306. package/dist/modules/staff/lib/time-tracking/registries/invoke.js +63 -0
  307. package/dist/modules/staff/lib/time-tracking/registries/invoke.js.map +7 -0
  308. package/dist/modules/staff/lib/time-tracking/registries/registry.js +62 -0
  309. package/dist/modules/staff/lib/time-tracking/registries/registry.js.map +7 -0
  310. package/dist/modules/staff/lib/time-tracking/registries/scope.js +21 -0
  311. package/dist/modules/staff/lib/time-tracking/registries/scope.js.map +7 -0
  312. package/dist/modules/staff/lib/time-tracking/rollup.js +34 -0
  313. package/dist/modules/staff/lib/time-tracking/rollup.js.map +7 -0
  314. package/dist/modules/staff/lib/time-tracking/rounding.js +66 -0
  315. package/dist/modules/staff/lib/time-tracking/rounding.js.map +7 -0
  316. package/dist/modules/staff/lib/time-tracking/roundingImpact.js +39 -0
  317. package/dist/modules/staff/lib/time-tracking/roundingImpact.js.map +7 -0
  318. package/dist/modules/staff/lib/time-tracking/settingKeys.js +214 -0
  319. package/dist/modules/staff/lib/time-tracking/settingKeys.js.map +7 -0
  320. package/dist/modules/staff/lib/time-tracking/settings.js +87 -0
  321. package/dist/modules/staff/lib/time-tracking/settings.js.map +7 -0
  322. package/dist/modules/staff/lib/time-tracking/sqlInClause.js +9 -0
  323. package/dist/modules/staff/lib/time-tracking/sqlInClause.js.map +7 -0
  324. package/dist/modules/staff/lib/time-tracking/timeEntrySources.js +48 -0
  325. package/dist/modules/staff/lib/time-tracking/timeEntrySources.js.map +7 -0
  326. package/dist/modules/staff/lib/time-tracking-ui/BoardFilterChips.js +283 -0
  327. package/dist/modules/staff/lib/time-tracking-ui/BoardFilterChips.js.map +7 -0
  328. package/dist/modules/staff/lib/time-tracking-ui/CustomerPicker.js +324 -0
  329. package/dist/modules/staff/lib/time-tracking-ui/CustomerPicker.js.map +7 -0
  330. package/dist/modules/staff/lib/time-tracking-ui/DurationInput.js +121 -0
  331. package/dist/modules/staff/lib/time-tracking-ui/DurationInput.js.map +7 -0
  332. package/dist/modules/staff/lib/time-tracking-ui/EntryDetailsFields.js +188 -0
  333. package/dist/modules/staff/lib/time-tracking-ui/EntryDetailsFields.js.map +7 -0
  334. package/dist/modules/staff/lib/time-tracking-ui/EntryFilterBar.js +89 -0
  335. package/dist/modules/staff/lib/time-tracking-ui/EntryFilterBar.js.map +7 -0
  336. package/dist/modules/staff/lib/time-tracking-ui/KanbanBoard.js +855 -0
  337. package/dist/modules/staff/lib/time-tracking-ui/KanbanBoard.js.map +7 -0
  338. package/dist/modules/staff/lib/time-tracking-ui/KanbanCard.js +360 -0
  339. package/dist/modules/staff/lib/time-tracking-ui/KanbanCard.js.map +7 -0
  340. package/dist/modules/staff/lib/time-tracking-ui/KanbanColumn.js +259 -0
  341. package/dist/modules/staff/lib/time-tracking-ui/KanbanColumn.js.map +7 -0
  342. package/dist/modules/staff/lib/time-tracking-ui/NewTaskDialog.js +238 -0
  343. package/dist/modules/staff/lib/time-tracking-ui/NewTaskDialog.js.map +7 -0
  344. package/dist/modules/staff/lib/time-tracking-ui/NoProjectAccess.js +130 -0
  345. package/dist/modules/staff/lib/time-tracking-ui/NoProjectAccess.js.map +7 -0
  346. package/dist/modules/staff/lib/time-tracking-ui/PeriodSelector.js +98 -0
  347. package/dist/modules/staff/lib/time-tracking-ui/PeriodSelector.js.map +7 -0
  348. package/dist/modules/staff/lib/time-tracking-ui/PhasePlaceholder.js +27 -0
  349. package/dist/modules/staff/lib/time-tracking-ui/PhasePlaceholder.js.map +7 -0
  350. package/dist/modules/staff/lib/time-tracking-ui/ProjectCodeField.js +166 -0
  351. package/dist/modules/staff/lib/time-tracking-ui/ProjectCodeField.js.map +7 -0
  352. package/dist/modules/staff/lib/time-tracking-ui/ProjectCurrencyField.js +295 -0
  353. package/dist/modules/staff/lib/time-tracking-ui/ProjectCurrencyField.js.map +7 -0
  354. package/dist/modules/staff/lib/time-tracking-ui/ProjectFormSections.js +212 -0
  355. package/dist/modules/staff/lib/time-tracking-ui/ProjectFormSections.js.map +7 -0
  356. package/dist/modules/staff/lib/time-tracking-ui/ProjectTeamDrawer.js +729 -0
  357. package/dist/modules/staff/lib/time-tracking-ui/ProjectTeamDrawer.js.map +7 -0
  358. package/dist/modules/staff/lib/time-tracking-ui/ReportSheet.js +217 -0
  359. package/dist/modules/staff/lib/time-tracking-ui/ReportSheet.js.map +7 -0
  360. package/dist/modules/staff/lib/time-tracking-ui/TagPicker.js +158 -0
  361. package/dist/modules/staff/lib/time-tracking-ui/TagPicker.js.map +7 -0
  362. package/dist/modules/staff/lib/time-tracking-ui/TaskBoardScreen.js +224 -0
  363. package/dist/modules/staff/lib/time-tracking-ui/TaskBoardScreen.js.map +7 -0
  364. package/dist/modules/staff/lib/time-tracking-ui/TaskCommentThread.js +93 -0
  365. package/dist/modules/staff/lib/time-tracking-ui/TaskCommentThread.js.map +7 -0
  366. package/dist/modules/staff/lib/time-tracking-ui/TaskDrawer.js +1196 -0
  367. package/dist/modules/staff/lib/time-tracking-ui/TaskDrawer.js.map +7 -0
  368. package/dist/modules/staff/lib/time-tracking-ui/TaskListView.js +176 -0
  369. package/dist/modules/staff/lib/time-tracking-ui/TaskListView.js.map +7 -0
  370. package/dist/modules/staff/lib/time-tracking-ui/TaskPicker.js +307 -0
  371. package/dist/modules/staff/lib/time-tracking-ui/TaskPicker.js.map +7 -0
  372. package/dist/modules/staff/lib/time-tracking-ui/TaskQuickLog.js +284 -0
  373. package/dist/modules/staff/lib/time-tracking-ui/TaskQuickLog.js.map +7 -0
  374. package/dist/modules/staff/lib/time-tracking-ui/TimeEntriesSummaryFooter.js +73 -0
  375. package/dist/modules/staff/lib/time-tracking-ui/TimeEntriesSummaryFooter.js.map +7 -0
  376. package/dist/modules/staff/lib/time-tracking-ui/TimeEntryDialog.js +1499 -0
  377. package/dist/modules/staff/lib/time-tracking-ui/TimeEntryDialog.js.map +7 -0
  378. package/dist/modules/staff/lib/time-tracking-ui/TimeEntryDurationCell.js +95 -0
  379. package/dist/modules/staff/lib/time-tracking-ui/TimeEntryDurationCell.js.map +7 -0
  380. package/dist/modules/staff/lib/time-tracking-ui/TimesheetCalendar.js +188 -0
  381. package/dist/modules/staff/lib/time-tracking-ui/TimesheetCalendar.js.map +7 -0
  382. package/dist/modules/staff/lib/time-tracking-ui/TimesheetPeriodFooter.js +61 -0
  383. package/dist/modules/staff/lib/time-tracking-ui/TimesheetPeriodFooter.js.map +7 -0
  384. package/dist/modules/staff/lib/time-tracking-ui/TimesheetViewSwitch.js +45 -0
  385. package/dist/modules/staff/lib/time-tracking-ui/TimesheetViewSwitch.js.map +7 -0
  386. package/dist/modules/staff/lib/time-tracking-ui/boardDirectory.js +176 -0
  387. package/dist/modules/staff/lib/time-tracking-ui/boardDirectory.js.map +7 -0
  388. package/dist/modules/staff/lib/time-tracking-ui/boardFilters.js +82 -0
  389. package/dist/modules/staff/lib/time-tracking-ui/boardFilters.js.map +7 -0
  390. package/dist/modules/staff/lib/time-tracking-ui/boardSummary.js +5 -0
  391. package/dist/modules/staff/lib/time-tracking-ui/boardSummary.js.map +7 -0
  392. package/dist/modules/staff/lib/time-tracking-ui/kanbanBoardData.js +152 -0
  393. package/dist/modules/staff/lib/time-tracking-ui/kanbanBoardData.js.map +7 -0
  394. package/dist/modules/staff/lib/time-tracking-ui/projectTeamAssignment.js +92 -0
  395. package/dist/modules/staff/lib/time-tracking-ui/projectTeamAssignment.js.map +7 -0
  396. package/dist/modules/staff/lib/time-tracking-ui/taskDrawerData.js +111 -0
  397. package/dist/modules/staff/lib/time-tracking-ui/taskDrawerData.js.map +7 -0
  398. package/dist/modules/staff/lib/time-tracking-ui/timeEntryDialogState.js +243 -0
  399. package/dist/modules/staff/lib/time-tracking-ui/timeEntryDialogState.js.map +7 -0
  400. package/dist/modules/staff/lib/time-tracking-ui/timeEntryListData.js +151 -0
  401. package/dist/modules/staff/lib/time-tracking-ui/timeEntryListData.js.map +7 -0
  402. package/dist/modules/staff/lib/time-tracking-ui/timeTrackingSettingsForm.js +105 -0
  403. package/dist/modules/staff/lib/time-tracking-ui/timeTrackingSettingsForm.js.map +7 -0
  404. package/dist/modules/staff/lib/time-tracking-ui/timesheetData.js +132 -0
  405. package/dist/modules/staff/lib/time-tracking-ui/timesheetData.js.map +7 -0
  406. package/dist/modules/staff/lib/time-tracking-ui/timesheetPeriod.js +205 -0
  407. package/dist/modules/staff/lib/time-tracking-ui/timesheetPeriod.js.map +7 -0
  408. package/dist/modules/staff/lib/time-tracking-ui/timesheetTargets.js +53 -0
  409. package/dist/modules/staff/lib/time-tracking-ui/timesheetTargets.js.map +7 -0
  410. package/dist/modules/staff/lib/time-tracking-ui/useBoardFilters.js +77 -0
  411. package/dist/modules/staff/lib/time-tracking-ui/useBoardFilters.js.map +7 -0
  412. package/dist/modules/staff/lib/time-tracking-ui/useTimesheetPreferences.js +151 -0
  413. package/dist/modules/staff/lib/time-tracking-ui/useTimesheetPreferences.js.map +7 -0
  414. package/dist/modules/staff/lib/timeTrackingSeeds.js +809 -0
  415. package/dist/modules/staff/lib/timeTrackingSeeds.js.map +7 -0
  416. package/dist/modules/staff/lib/timesheets/timeEntryCacheInvalidation.js +2 -3
  417. package/dist/modules/staff/lib/timesheets/timeEntryCacheInvalidation.js.map +2 -2
  418. package/dist/modules/staff/lib/timesheets/timeEntryDecoration.js +152 -0
  419. package/dist/modules/staff/lib/timesheets/timeEntryDecoration.js.map +7 -0
  420. package/dist/modules/staff/lib/timesheets-projects/budgetBurn.js +36 -0
  421. package/dist/modules/staff/lib/timesheets-projects/budgetBurn.js.map +7 -0
  422. package/dist/modules/staff/lib/timesheets-projects/budgetThreshold.js +66 -0
  423. package/dist/modules/staff/lib/timesheets-projects/budgetThreshold.js.map +7 -0
  424. package/dist/modules/staff/lib/timesheets-projects/budgetThresholdState.js +78 -0
  425. package/dist/modules/staff/lib/timesheets-projects/budgetThresholdState.js.map +7 -0
  426. package/dist/modules/staff/lib/timesheets-projects/computeProjectFinancials.js +81 -0
  427. package/dist/modules/staff/lib/timesheets-projects/computeProjectFinancials.js.map +7 -0
  428. package/dist/modules/staff/lib/timesheets-projects/reportSelection.js +44 -0
  429. package/dist/modules/staff/lib/timesheets-projects/reportSelection.js.map +7 -0
  430. package/dist/modules/staff/lib/timesheets-projects-ui/AssignMembersDialog.js +169 -0
  431. package/dist/modules/staff/lib/timesheets-projects-ui/AssignMembersDialog.js.map +7 -0
  432. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectBudgetCell.js +22 -0
  433. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectBudgetCell.js.map +7 -0
  434. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectCard.js +51 -1
  435. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectCard.js.map +2 -2
  436. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectsBulkActionsBar.js +70 -0
  437. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectsBulkActionsBar.js.map +7 -0
  438. package/dist/modules/staff/lib/timesheets-reports/buildReportSheet.js +63 -0
  439. package/dist/modules/staff/lib/timesheets-reports/buildReportSheet.js.map +7 -0
  440. package/dist/modules/staff/lib/timesheets-reports/loadReportData.js +170 -0
  441. package/dist/modules/staff/lib/timesheets-reports/loadReportData.js.map +7 -0
  442. package/dist/modules/staff/lib/timesheets-reports/pdf.js +205 -0
  443. package/dist/modules/staff/lib/timesheets-reports/pdf.js.map +7 -0
  444. package/dist/modules/staff/lib/timesheets-reports/reportApprovalPolicies.js +68 -0
  445. package/dist/modules/staff/lib/timesheets-reports/reportApprovalPolicies.js.map +7 -0
  446. package/dist/modules/staff/lib/timesheets-reports/reportConfigData.js +135 -0
  447. package/dist/modules/staff/lib/timesheets-reports/reportConfigData.js.map +7 -0
  448. package/dist/modules/staff/lib/timesheets-reports/reportConfigState.js +48 -0
  449. package/dist/modules/staff/lib/timesheets-reports/reportConfigState.js.map +7 -0
  450. package/dist/modules/staff/lib/timesheets-reports/reportExport.js +262 -0
  451. package/dist/modules/staff/lib/timesheets-reports/reportExport.js.map +7 -0
  452. package/dist/modules/staff/lib/timesheets-reports/reportExportFormats.js +34 -0
  453. package/dist/modules/staff/lib/timesheets-reports/reportExportFormats.js.map +7 -0
  454. package/dist/modules/staff/lib/timesheets-reports/reportGroupings.js +79 -0
  455. package/dist/modules/staff/lib/timesheets-reports/reportGroupings.js.map +7 -0
  456. package/dist/modules/staff/lib/timesheets-reports/reportLabels.js +11 -0
  457. package/dist/modules/staff/lib/timesheets-reports/reportLabels.js.map +7 -0
  458. package/dist/modules/staff/lib/timesheets-reports/reportReference.js +83 -0
  459. package/dist/modules/staff/lib/timesheets-reports/reportReference.js.map +7 -0
  460. package/dist/modules/staff/lib/timesheets-reports/reportRows.js +42 -0
  461. package/dist/modules/staff/lib/timesheets-reports/reportRows.js.map +7 -0
  462. package/dist/modules/staff/lib/timesheets-reports/reportSheetData.js +107 -0
  463. package/dist/modules/staff/lib/timesheets-reports/reportSheetData.js.map +7 -0
  464. package/dist/modules/staff/lib/timesheets-reports/reportTotals.js +289 -0
  465. package/dist/modules/staff/lib/timesheets-reports/reportTotals.js.map +7 -0
  466. package/dist/modules/staff/lib/timesheets-reports/xlsx.js +145 -0
  467. package/dist/modules/staff/lib/timesheets-reports/xlsx.js.map +7 -0
  468. package/dist/modules/staff/lib/timesheets-tasks/computeTaskRollups.js +116 -0
  469. package/dist/modules/staff/lib/timesheets-tasks/computeTaskRollups.js.map +7 -0
  470. package/dist/modules/staff/lib/timesheets-tasks/defaultStatusTemplate.js +50 -0
  471. package/dist/modules/staff/lib/timesheets-tasks/defaultStatusTemplate.js.map +7 -0
  472. package/dist/modules/staff/lib/timesheets-tasks/seedProjectStatuses.js +27 -0
  473. package/dist/modules/staff/lib/timesheets-tasks/seedProjectStatuses.js.map +7 -0
  474. package/dist/modules/staff/lib/timesheets-tasks/statusPositions.js +65 -0
  475. package/dist/modules/staff/lib/timesheets-tasks/statusPositions.js.map +7 -0
  476. package/dist/modules/staff/lib/timesheets-tasks/statusSlug.js +31 -0
  477. package/dist/modules/staff/lib/timesheets-tasks/statusSlug.js.map +7 -0
  478. package/dist/modules/staff/lib/timesheets-tasks/taskHierarchy.js +31 -0
  479. package/dist/modules/staff/lib/timesheets-tasks/taskHierarchy.js.map +7 -0
  480. package/dist/modules/staff/lib/timesheets-tasks/taskHoursTotals.js +17 -0
  481. package/dist/modules/staff/lib/timesheets-tasks/taskHoursTotals.js.map +7 -0
  482. package/dist/modules/staff/lib/timesheets-tasks/taskReference.js +51 -0
  483. package/dist/modules/staff/lib/timesheets-tasks/taskReference.js.map +7 -0
  484. package/dist/modules/staff/lib/timesheets-ui/CreateProjectDialog.js +11 -4
  485. package/dist/modules/staff/lib/timesheets-ui/CreateProjectDialog.js.map +2 -2
  486. package/dist/modules/staff/lib/timesheets-ui/ListView.js +369 -111
  487. package/dist/modules/staff/lib/timesheets-ui/ListView.js.map +2 -2
  488. package/dist/modules/staff/lib/timesheets-ui/TimerBar.js +47 -2
  489. package/dist/modules/staff/lib/timesheets-ui/TimerBar.js.map +2 -2
  490. package/dist/modules/staff/migrations/Migration20260813073131_staff.js +79 -0
  491. package/dist/modules/staff/migrations/Migration20260813073131_staff.js.map +7 -0
  492. package/dist/modules/staff/migrations/Migration20260824143357_staff.js +15 -0
  493. package/dist/modules/staff/migrations/Migration20260824143357_staff.js.map +7 -0
  494. package/dist/modules/staff/notifications.client.js +16 -0
  495. package/dist/modules/staff/notifications.client.js.map +7 -0
  496. package/dist/modules/staff/notifications.handlers.js +80 -0
  497. package/dist/modules/staff/notifications.handlers.js.map +7 -0
  498. package/dist/modules/staff/notifications.js +168 -0
  499. package/dist/modules/staff/notifications.js.map +2 -2
  500. package/dist/modules/staff/search.js +159 -1
  501. package/dist/modules/staff/search.js.map +2 -2
  502. package/dist/modules/staff/setup.js +20 -1
  503. package/dist/modules/staff/setup.js.map +2 -2
  504. package/dist/modules/staff/subscribers/time-project-access-requested-notification.js +68 -0
  505. package/dist/modules/staff/subscribers/time-project-access-requested-notification.js.map +7 -0
  506. package/dist/modules/staff/subscribers/time-project-budget-threshold-notification.js +149 -0
  507. package/dist/modules/staff/subscribers/time-project-budget-threshold-notification.js.map +7 -0
  508. package/dist/modules/staff/subscribers/time-report-approved-notification.js +78 -0
  509. package/dist/modules/staff/subscribers/time-report-approved-notification.js.map +7 -0
  510. package/dist/modules/staff/subscribers/time-report-portal-broadcast.js +78 -0
  511. package/dist/modules/staff/subscribers/time-report-portal-broadcast.js.map +7 -0
  512. package/dist/modules/staff/translations.js +4 -1
  513. package/dist/modules/staff/translations.js.map +2 -2
  514. package/dist/modules/staff/widgets/components.js +7 -0
  515. package/dist/modules/staff/widgets/components.js.map +7 -0
  516. package/dist/modules/staff/widgets/injection/timer-sidebar-indicator/widget.js +5 -4
  517. package/dist/modules/staff/widgets/injection/timer-sidebar-indicator/widget.js.map +2 -2
  518. package/dist/modules/staff/widgets/notifications/TimeProjectAccessRequestedRenderer.js +135 -0
  519. package/dist/modules/staff/widgets/notifications/TimeProjectAccessRequestedRenderer.js.map +7 -0
  520. package/dist/modules/staff/widgets/notifications/index.js +5 -0
  521. package/dist/modules/staff/widgets/notifications/index.js.map +7 -0
  522. package/dist/modules/staff/workers/timesheets-reapply-rounding.js +43 -0
  523. package/dist/modules/staff/workers/timesheets-reapply-rounding.js.map +7 -0
  524. package/generated/entities/staff_time_entry/index.ts +7 -0
  525. package/generated/entities/staff_time_entry_tag/index.ts +6 -0
  526. package/generated/entities/staff_time_project/index.ts +8 -0
  527. package/generated/entities/staff_time_report/index.ts +27 -0
  528. package/generated/entities/staff_time_report_entry/index.ts +12 -0
  529. package/generated/entities/staff_time_report_event/index.ts +9 -0
  530. package/generated/entities/staff_time_report_project/index.ts +6 -0
  531. package/generated/entities/staff_time_tag/index.ts +9 -0
  532. package/generated/entities/staff_time_task/index.ts +17 -0
  533. package/generated/entities/staff_time_task_comment/index.ts +9 -0
  534. package/generated/entities/staff_time_task_status/index.ts +13 -0
  535. package/generated/entities/staff_time_task_tag/index.ts +6 -0
  536. package/generated/entities.ids.generated.ts +11 -1
  537. package/generated/entity-fields-registry.ts +149 -0
  538. package/package.json +7 -7
  539. package/src/helpers/integration/timesheetFixtures.ts +31 -1
  540. package/src/modules/auth/README.md +1 -1
  541. package/src/modules/auth/cli.ts +35 -1
  542. package/src/modules/auth/i18n/de.json +7 -0
  543. package/src/modules/auth/i18n/en.json +7 -0
  544. package/src/modules/auth/i18n/es.json +7 -0
  545. package/src/modules/auth/i18n/ko.json +7 -0
  546. package/src/modules/auth/i18n/pl.json +7 -0
  547. package/src/modules/auth/lib/backendChrome.tsx +1 -0
  548. package/src/modules/customer_accounts/lib/customerRoleAcls.ts +79 -0
  549. package/src/modules/customer_accounts/setup.ts +1 -45
  550. package/src/modules/data_sync/AGENTS.md +34 -0
  551. package/src/modules/data_sync/api/options.ts +2 -0
  552. package/src/modules/data_sync/backend/data-sync/page.tsx +82 -33
  553. package/src/modules/data_sync/i18n/de.json +1 -0
  554. package/src/modules/data_sync/i18n/en.json +1 -0
  555. package/src/modules/data_sync/i18n/es.json +1 -0
  556. package/src/modules/data_sync/i18n/ko.json +1 -0
  557. package/src/modules/data_sync/i18n/pl.json +1 -0
  558. package/src/modules/data_sync/lib/adapter.ts +45 -0
  559. package/src/modules/data_sync/lib/start-controls.ts +89 -0
  560. package/src/modules/staff/AGENTS.md +769 -1
  561. package/src/modules/staff/acl.ts +9 -0
  562. package/src/modules/staff/ai-agents.ts +189 -0
  563. package/src/modules/staff/ai-tools/time-tracking-pack.ts +494 -0
  564. package/src/modules/staff/ai-tools/types.ts +82 -0
  565. package/src/modules/staff/ai-tools.ts +13 -0
  566. package/src/modules/staff/analytics.ts +113 -0
  567. package/src/modules/staff/api/guards.ts +85 -3
  568. package/src/modules/staff/api/leave-requests/accept/route.ts +0 -2
  569. package/src/modules/staff/api/leave-requests/reject/route.ts +0 -2
  570. package/src/modules/staff/api/portal/time-reports/[id]/route.ts +182 -0
  571. package/src/modules/staff/api/portal/time-reports/route.ts +270 -0
  572. package/src/modules/staff/api/team-members/self/route.ts +0 -2
  573. package/src/modules/staff/api/team-members/tags/assign/route.ts +0 -2
  574. package/src/modules/staff/api/team-members/tags/unassign/route.ts +0 -2
  575. package/src/modules/staff/api/timesheets/_shared/withTimesheetInterceptors.ts +292 -0
  576. package/src/modules/staff/api/timesheets/access-requests/route.ts +299 -0
  577. package/src/modules/staff/api/timesheets/my-projects/[projectId]/route.ts +15 -7
  578. package/src/modules/staff/api/timesheets/my-projects/route.ts +14 -1
  579. package/src/modules/staff/api/timesheets/my-work/myWorkAggregate.ts +90 -0
  580. package/src/modules/staff/api/timesheets/my-work/route.ts +475 -0
  581. package/src/modules/staff/api/timesheets/projects/kpis/route.ts +15 -2
  582. package/src/modules/staff/api/timesheets/reports/[id]/close/route.ts +203 -0
  583. package/src/modules/staff/api/timesheets/reports/[id]/export/route.ts +315 -0
  584. package/src/modules/staff/api/timesheets/reports/[id]/sheet/route.ts +220 -0
  585. package/src/modules/staff/api/timesheets/reports/[id]/unlock/route.ts +208 -0
  586. package/src/modules/staff/api/timesheets/reports/preview/route.ts +449 -0
  587. package/src/modules/staff/api/timesheets/reports/route.ts +386 -0
  588. package/src/modules/staff/api/timesheets/reports/shared.ts +121 -0
  589. package/src/modules/staff/api/timesheets/settings/reapply-rounding/route.ts +205 -0
  590. package/src/modules/staff/api/timesheets/settings/rounding-impact/route.ts +226 -0
  591. package/src/modules/staff/api/timesheets/settings/route.ts +242 -0
  592. package/src/modules/staff/api/timesheets/tags/access.ts +134 -0
  593. package/src/modules/staff/api/timesheets/tags/entry-assignments/route.ts +290 -0
  594. package/src/modules/staff/api/timesheets/tags/route.ts +177 -0
  595. package/src/modules/staff/api/timesheets/tags/task-assignments/route.ts +294 -0
  596. package/src/modules/staff/api/timesheets/task-statuses/route.ts +232 -0
  597. package/src/modules/staff/api/timesheets/tasks/[id]/comments/route.ts +532 -0
  598. package/src/modules/staff/api/timesheets/tasks/[id]/status/route.ts +271 -0
  599. package/src/modules/staff/api/timesheets/tasks/route.ts +443 -0
  600. package/src/modules/staff/api/timesheets/time-entries/[id]/duplicate/route.ts +306 -0
  601. package/src/modules/staff/api/timesheets/time-entries/[id]/segments/[segmentId]/route.ts +32 -10
  602. package/src/modules/staff/api/timesheets/time-entries/[id]/segments/route.ts +32 -17
  603. package/src/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.ts +27 -6
  604. package/src/modules/staff/api/timesheets/time-entries/[id]/timer-stop/route.ts +36 -6
  605. package/src/modules/staff/api/timesheets/time-entries/bulk/route.ts +331 -34
  606. package/src/modules/staff/api/timesheets/time-entries/copy-day/route.ts +533 -0
  607. package/src/modules/staff/api/timesheets/time-entries/overlaps/route.ts +457 -0
  608. package/src/modules/staff/api/timesheets/time-entries/route.ts +378 -24
  609. package/src/modules/staff/api/timesheets/time-entries/start-timer/route.ts +31 -9
  610. package/src/modules/staff/api/timesheets/time-projects/[id]/change-currency/route.ts +246 -0
  611. package/src/modules/staff/api/timesheets/time-projects/[id]/employees/route.ts +62 -2
  612. package/src/modules/staff/api/timesheets/time-projects/route.ts +397 -22
  613. package/src/modules/staff/backend/staff/time-tracking/board/page.meta.ts +14 -0
  614. package/src/modules/staff/backend/staff/time-tracking/board/page.tsx +151 -0
  615. package/src/modules/staff/backend/staff/time-tracking/entries/page.meta.ts +14 -0
  616. package/src/modules/staff/backend/staff/time-tracking/entries/page.tsx +1229 -0
  617. package/src/modules/staff/backend/staff/time-tracking/page.meta.ts +11 -0
  618. package/src/modules/staff/backend/staff/time-tracking/page.tsx +823 -0
  619. package/src/modules/staff/backend/staff/time-tracking/projects/[id]/board/page.meta.ts +12 -0
  620. package/src/modules/staff/backend/staff/time-tracking/projects/[id]/board/page.tsx +81 -0
  621. package/src/modules/staff/backend/staff/time-tracking/projects/[id]/edit/page.meta.ts +12 -0
  622. package/src/modules/staff/backend/staff/time-tracking/projects/[id]/edit/page.tsx +275 -0
  623. package/src/modules/staff/backend/staff/time-tracking/projects/[id]/page.meta.ts +12 -0
  624. package/src/modules/staff/backend/staff/time-tracking/projects/[id]/page.tsx +1420 -0
  625. package/src/modules/staff/backend/staff/time-tracking/projects/create/page.meta.ts +12 -0
  626. package/src/modules/staff/backend/staff/time-tracking/projects/create/page.tsx +109 -0
  627. package/src/modules/staff/backend/staff/time-tracking/projects/page.meta.ts +15 -0
  628. package/src/modules/staff/backend/staff/time-tracking/projects/page.tsx +1254 -0
  629. package/src/modules/staff/backend/staff/time-tracking/projects/projectFormConfig.ts +466 -0
  630. package/src/modules/staff/backend/staff/time-tracking/reports/[id]/page.meta.ts +12 -0
  631. package/src/modules/staff/backend/staff/time-tracking/reports/[id]/page.tsx +632 -0
  632. package/src/modules/staff/backend/staff/time-tracking/reports/create/page.meta.ts +12 -0
  633. package/src/modules/staff/backend/staff/time-tracking/reports/create/page.tsx +867 -0
  634. package/src/modules/staff/backend/staff/time-tracking/reports/page.meta.ts +14 -0
  635. package/src/modules/staff/backend/staff/time-tracking/reports/page.tsx +246 -0
  636. package/src/modules/staff/backend/staff/time-tracking/settings/page.meta.ts +14 -0
  637. package/src/modules/staff/backend/staff/time-tracking/settings/page.tsx +701 -0
  638. package/src/modules/staff/backend/staff/time-tracking/timesheet/GridView.tsx +953 -0
  639. package/src/modules/staff/backend/staff/time-tracking/timesheet/page.meta.ts +14 -0
  640. package/src/modules/staff/backend/staff/time-tracking/timesheet/page.tsx +800 -0
  641. package/src/modules/staff/backend/staff/timesheets/page.meta.ts +6 -6
  642. package/src/modules/staff/backend/staff/timesheets/page.tsx +12 -1010
  643. package/src/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.meta.ts +0 -6
  644. package/src/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.tsx +4 -158
  645. package/src/modules/staff/backend/staff/timesheets/projects/[id]/page.meta.ts +0 -6
  646. package/src/modules/staff/backend/staff/timesheets/projects/[id]/page.tsx +4 -609
  647. package/src/modules/staff/backend/staff/timesheets/projects/create/page.meta.ts +0 -6
  648. package/src/modules/staff/backend/staff/timesheets/projects/create/page.tsx +3 -89
  649. package/src/modules/staff/backend/staff/timesheets/projects/page.meta.ts +2 -19
  650. package/src/modules/staff/backend/staff/timesheets/projects/page.tsx +3 -778
  651. package/src/modules/staff/ce.ts +63 -0
  652. package/src/modules/staff/cli.ts +207 -1
  653. package/src/modules/staff/commands/index.ts +5 -0
  654. package/src/modules/staff/commands/timesheets-entries.ts +1006 -28
  655. package/src/modules/staff/commands/timesheets-projects.ts +593 -7
  656. package/src/modules/staff/commands/timesheets-reports.ts +1329 -0
  657. package/src/modules/staff/commands/timesheets-tags.ts +1315 -0
  658. package/src/modules/staff/commands/timesheets-task-comments.ts +583 -0
  659. package/src/modules/staff/commands/timesheets-task-statuses.ts +889 -0
  660. package/src/modules/staff/commands/timesheets-tasks.ts +1121 -0
  661. package/src/modules/staff/data/enrichers.ts +675 -10
  662. package/src/modules/staff/data/entities.ts +494 -2
  663. package/src/modules/staff/data/extensions.ts +68 -0
  664. package/src/modules/staff/data/validators.ts +348 -3
  665. package/src/modules/staff/di.ts +96 -0
  666. package/src/modules/staff/events.payloads.ts +268 -0
  667. package/src/modules/staff/events.ts +87 -5
  668. package/src/modules/staff/extension-points.ts +308 -0
  669. package/src/modules/staff/frontend/[orgSlug]/portal/time-reports/[id]/page.meta.ts +10 -0
  670. package/src/modules/staff/frontend/[orgSlug]/portal/time-reports/[id]/page.tsx +225 -0
  671. package/src/modules/staff/frontend/[orgSlug]/portal/time-reports/page.meta.ts +17 -0
  672. package/src/modules/staff/frontend/[orgSlug]/portal/time-reports/page.tsx +182 -0
  673. package/src/modules/staff/i18n/de.json +899 -0
  674. package/src/modules/staff/i18n/en.json +899 -0
  675. package/src/modules/staff/i18n/es.json +899 -0
  676. package/src/modules/staff/i18n/ko.json +899 -0
  677. package/src/modules/staff/i18n/pl.json +899 -0
  678. package/src/modules/staff/lib/crud.ts +14 -3
  679. package/src/modules/staff/lib/time-tracking/access.ts +155 -0
  680. package/src/modules/staff/lib/time-tracking/billability.ts +68 -0
  681. package/src/modules/staff/lib/time-tracking/capacity.ts +124 -0
  682. package/src/modules/staff/lib/time-tracking/componentContracts.ts +26 -0
  683. package/src/modules/staff/lib/time-tracking/cost.ts +144 -0
  684. package/src/modules/staff/lib/time-tracking/duration.ts +68 -0
  685. package/src/modules/staff/lib/time-tracking/featureAccess.ts +115 -0
  686. package/src/modules/staff/lib/time-tracking/interval.ts +90 -0
  687. package/src/modules/staff/lib/time-tracking/migrateProjectCodes.ts +161 -0
  688. package/src/modules/staff/lib/time-tracking/moneyVisibility.ts +37 -0
  689. package/src/modules/staff/lib/time-tracking/overlap.ts +159 -0
  690. package/src/modules/staff/lib/time-tracking/portalRecipients.ts +76 -0
  691. package/src/modules/staff/lib/time-tracking/portalReports.ts +31 -0
  692. package/src/modules/staff/lib/time-tracking/projectCode.ts +221 -0
  693. package/src/modules/staff/lib/time-tracking/reapplyRounding.ts +313 -0
  694. package/src/modules/staff/lib/time-tracking/recalculationRunner.ts +118 -0
  695. package/src/modules/staff/lib/time-tracking/recalculations.ts +135 -0
  696. package/src/modules/staff/lib/time-tracking/registries/invoke.ts +122 -0
  697. package/src/modules/staff/lib/time-tracking/registries/registry.ts +124 -0
  698. package/src/modules/staff/lib/time-tracking/registries/scope.ts +56 -0
  699. package/src/modules/staff/lib/time-tracking/rollup.ts +59 -0
  700. package/src/modules/staff/lib/time-tracking/rounding.ts +126 -0
  701. package/src/modules/staff/lib/time-tracking/roundingImpact.ts +75 -0
  702. package/src/modules/staff/lib/time-tracking/settingKeys.ts +274 -0
  703. package/src/modules/staff/lib/time-tracking/settings.ts +168 -0
  704. package/src/modules/staff/lib/time-tracking/sqlInClause.ts +22 -0
  705. package/src/modules/staff/lib/time-tracking/timeEntrySources.ts +85 -0
  706. package/src/modules/staff/lib/time-tracking-ui/BoardFilterChips.tsx +360 -0
  707. package/src/modules/staff/lib/time-tracking-ui/CustomerPicker.tsx +427 -0
  708. package/src/modules/staff/lib/time-tracking-ui/DurationInput.tsx +192 -0
  709. package/src/modules/staff/lib/time-tracking-ui/EntryDetailsFields.tsx +224 -0
  710. package/src/modules/staff/lib/time-tracking-ui/EntryFilterBar.tsx +144 -0
  711. package/src/modules/staff/lib/time-tracking-ui/KanbanBoard.tsx +1065 -0
  712. package/src/modules/staff/lib/time-tracking-ui/KanbanCard.tsx +435 -0
  713. package/src/modules/staff/lib/time-tracking-ui/KanbanColumn.tsx +316 -0
  714. package/src/modules/staff/lib/time-tracking-ui/NewTaskDialog.tsx +291 -0
  715. package/src/modules/staff/lib/time-tracking-ui/NoProjectAccess.tsx +162 -0
  716. package/src/modules/staff/lib/time-tracking-ui/PeriodSelector.tsx +149 -0
  717. package/src/modules/staff/lib/time-tracking-ui/PhasePlaceholder.tsx +31 -0
  718. package/src/modules/staff/lib/time-tracking-ui/ProjectCodeField.tsx +230 -0
  719. package/src/modules/staff/lib/time-tracking-ui/ProjectCurrencyField.tsx +432 -0
  720. package/src/modules/staff/lib/time-tracking-ui/ProjectFormSections.tsx +323 -0
  721. package/src/modules/staff/lib/time-tracking-ui/ProjectTeamDrawer.tsx +930 -0
  722. package/src/modules/staff/lib/time-tracking-ui/ReportSheet.tsx +357 -0
  723. package/src/modules/staff/lib/time-tracking-ui/TagPicker.tsx +195 -0
  724. package/src/modules/staff/lib/time-tracking-ui/TaskBoardScreen.tsx +243 -0
  725. package/src/modules/staff/lib/time-tracking-ui/TaskCommentThread.tsx +137 -0
  726. package/src/modules/staff/lib/time-tracking-ui/TaskDrawer.tsx +1405 -0
  727. package/src/modules/staff/lib/time-tracking-ui/TaskListView.tsx +260 -0
  728. package/src/modules/staff/lib/time-tracking-ui/TaskPicker.tsx +435 -0
  729. package/src/modules/staff/lib/time-tracking-ui/TaskQuickLog.tsx +296 -0
  730. package/src/modules/staff/lib/time-tracking-ui/TimeEntriesSummaryFooter.tsx +97 -0
  731. package/src/modules/staff/lib/time-tracking-ui/TimeEntryDialog.tsx +1929 -0
  732. package/src/modules/staff/lib/time-tracking-ui/TimeEntryDurationCell.tsx +126 -0
  733. package/src/modules/staff/lib/time-tracking-ui/TimesheetCalendar.tsx +265 -0
  734. package/src/modules/staff/lib/time-tracking-ui/TimesheetPeriodFooter.tsx +78 -0
  735. package/src/modules/staff/lib/time-tracking-ui/TimesheetViewSwitch.tsx +70 -0
  736. package/src/modules/staff/lib/time-tracking-ui/boardDirectory.ts +231 -0
  737. package/src/modules/staff/lib/time-tracking-ui/boardFilters.ts +128 -0
  738. package/src/modules/staff/lib/time-tracking-ui/boardSummary.ts +20 -0
  739. package/src/modules/staff/lib/time-tracking-ui/kanbanBoardData.ts +228 -0
  740. package/src/modules/staff/lib/time-tracking-ui/projectTeamAssignment.ts +143 -0
  741. package/src/modules/staff/lib/time-tracking-ui/taskDrawerData.ts +194 -0
  742. package/src/modules/staff/lib/time-tracking-ui/timeEntryDialogState.ts +400 -0
  743. package/src/modules/staff/lib/time-tracking-ui/timeEntryListData.ts +271 -0
  744. package/src/modules/staff/lib/time-tracking-ui/timeTrackingSettingsForm.ts +168 -0
  745. package/src/modules/staff/lib/time-tracking-ui/timesheetData.ts +225 -0
  746. package/src/modules/staff/lib/time-tracking-ui/timesheetPeriod.ts +278 -0
  747. package/src/modules/staff/lib/time-tracking-ui/timesheetTargets.ts +93 -0
  748. package/src/modules/staff/lib/time-tracking-ui/useBoardFilters.ts +107 -0
  749. package/src/modules/staff/lib/time-tracking-ui/useTimesheetPreferences.ts +245 -0
  750. package/src/modules/staff/lib/timeTrackingSeeds.ts +1037 -0
  751. package/src/modules/staff/lib/timesheets/timeEntryCacheInvalidation.ts +11 -10
  752. package/src/modules/staff/lib/timesheets/timeEntryDecoration.ts +256 -0
  753. package/src/modules/staff/lib/timesheets-projects/budgetBurn.ts +60 -0
  754. package/src/modules/staff/lib/timesheets-projects/budgetThreshold.ts +135 -0
  755. package/src/modules/staff/lib/timesheets-projects/budgetThresholdState.ts +137 -0
  756. package/src/modules/staff/lib/timesheets-projects/computeProjectFinancials.ts +142 -0
  757. package/src/modules/staff/lib/timesheets-projects/reportSelection.ts +82 -0
  758. package/src/modules/staff/lib/timesheets-projects-ui/AssignMembersDialog.tsx +237 -0
  759. package/src/modules/staff/lib/timesheets-projects-ui/ProjectBudgetCell.tsx +33 -0
  760. package/src/modules/staff/lib/timesheets-projects-ui/ProjectCard.tsx +56 -1
  761. package/src/modules/staff/lib/timesheets-projects-ui/ProjectsBulkActionsBar.tsx +90 -0
  762. package/src/modules/staff/lib/timesheets-reports/buildReportSheet.ts +125 -0
  763. package/src/modules/staff/lib/timesheets-reports/loadReportData.ts +251 -0
  764. package/src/modules/staff/lib/timesheets-reports/pdf.ts +263 -0
  765. package/src/modules/staff/lib/timesheets-reports/reportApprovalPolicies.ts +137 -0
  766. package/src/modules/staff/lib/timesheets-reports/reportConfigData.ts +247 -0
  767. package/src/modules/staff/lib/timesheets-reports/reportConfigState.ts +89 -0
  768. package/src/modules/staff/lib/timesheets-reports/reportExport.ts +373 -0
  769. package/src/modules/staff/lib/timesheets-reports/reportExportFormats.ts +71 -0
  770. package/src/modules/staff/lib/timesheets-reports/reportGroupings.ts +153 -0
  771. package/src/modules/staff/lib/timesheets-reports/reportLabels.ts +23 -0
  772. package/src/modules/staff/lib/timesheets-reports/reportReference.ts +146 -0
  773. package/src/modules/staff/lib/timesheets-reports/reportRows.ts +89 -0
  774. package/src/modules/staff/lib/timesheets-reports/reportSheetData.ts +196 -0
  775. package/src/modules/staff/lib/timesheets-reports/reportTotals.ts +544 -0
  776. package/src/modules/staff/lib/timesheets-reports/xlsx.ts +207 -0
  777. package/src/modules/staff/lib/timesheets-tasks/computeTaskRollups.ts +238 -0
  778. package/src/modules/staff/lib/timesheets-tasks/defaultStatusTemplate.ts +90 -0
  779. package/src/modules/staff/lib/timesheets-tasks/seedProjectStatuses.ts +43 -0
  780. package/src/modules/staff/lib/timesheets-tasks/statusPositions.ts +132 -0
  781. package/src/modules/staff/lib/timesheets-tasks/statusSlug.ts +43 -0
  782. package/src/modules/staff/lib/timesheets-tasks/taskHierarchy.ts +99 -0
  783. package/src/modules/staff/lib/timesheets-tasks/taskHoursTotals.ts +42 -0
  784. package/src/modules/staff/lib/timesheets-tasks/taskReference.ts +108 -0
  785. package/src/modules/staff/lib/timesheets-ui/CreateProjectDialog.tsx +18 -4
  786. package/src/modules/staff/lib/timesheets-ui/ListView.tsx +504 -149
  787. package/src/modules/staff/lib/timesheets-ui/TimerBar.tsx +50 -2
  788. package/src/modules/staff/migrations/.snapshot-open-mercato.json +3244 -228
  789. package/src/modules/staff/migrations/Migration20260813073131_staff.ts +94 -0
  790. package/src/modules/staff/migrations/Migration20260824143357_staff.ts +17 -0
  791. package/src/modules/staff/notifications.client.ts +16 -0
  792. package/src/modules/staff/notifications.handlers.ts +88 -0
  793. package/src/modules/staff/notifications.ts +163 -0
  794. package/src/modules/staff/search.ts +191 -1
  795. package/src/modules/staff/setup.ts +22 -0
  796. package/src/modules/staff/subscribers/time-project-access-requested-notification.ts +95 -0
  797. package/src/modules/staff/subscribers/time-project-budget-threshold-notification.ts +226 -0
  798. package/src/modules/staff/subscribers/time-report-approved-notification.ts +116 -0
  799. package/src/modules/staff/subscribers/time-report-portal-broadcast.ts +120 -0
  800. package/src/modules/staff/translations.ts +17 -0
  801. package/src/modules/staff/widgets/components.ts +34 -0
  802. package/src/modules/staff/widgets/injection/timer-sidebar-indicator/widget.tsx +6 -5
  803. package/src/modules/staff/widgets/notifications/TimeProjectAccessRequestedRenderer.tsx +138 -0
  804. package/src/modules/staff/widgets/notifications/index.ts +1 -0
  805. package/src/modules/staff/workers/timesheets-reapply-rounding.ts +59 -0
  806. package/dist/modules/staff/backend/staff/timesheets/projects/projectFormConfig.js +0 -123
  807. package/dist/modules/staff/backend/staff/timesheets/projects/projectFormConfig.js.map +0 -7
  808. package/src/modules/staff/backend/staff/timesheets/projects/projectFormConfig.ts +0 -138
@@ -0,0 +1,1315 @@
1
+ /**
2
+ * Tag commands for the consulting suite (T3.4).
3
+ *
4
+ * A tag is org-wide vocabulary — screen 6 renders it as a card badge, screen 7 as
5
+ * a chip in the task drawer, screens 8 and 10 on the time entry. The tag itself is
6
+ * therefore project-agnostic; only its *assignments* touch project-scoped rows,
7
+ * which is why the access filtering lives on the assignment routes rather than
8
+ * here.
9
+ *
10
+ * Three decisions the callers depend on:
11
+ *
12
+ * 1. `slug` is unique per organization+tenant (partial unique index, live rows
13
+ * only). A collision comes back as a 409 carrying `fieldErrors.slug` so the
14
+ * form marks the field instead of showing a dead 500.
15
+ * 2. **Deleting a tag cascades to its assignments and reports the count.** The
16
+ * alternatives are worse: silently orphaning 200 entry badges hides the blast
17
+ * radius, and refusing until the caller hand-unpicks 200 rows gives them no
18
+ * way forward. The tag is soft-deleted, the junction rows are removed, the
19
+ * response carries `removedTaskAssignments` / `removedEntryAssignments`, and
20
+ * undo puts both the tag and every removed assignment back.
21
+ * 3. **Assignment is idempotent.** Both junctions carry a unique index, so
22
+ * re-sending a tag the target already has is a no-op success, never a unique
23
+ * violation. The already-present ids come back in `alreadyAssignedTagIds` so
24
+ * the UI can tell "added" from "was already there". Unassigning a tag that is
25
+ * not assigned is the same kind of no-op.
26
+ */
27
+
28
+ import { z } from 'zod'
29
+ import type { EntityManager } from '@mikro-orm/postgresql'
30
+ import type { CommandHandler } from '@open-mercato/shared/lib/commands'
31
+ import { registerCommand } from '@open-mercato/shared/lib/commands'
32
+ import { CrudHttpError, isUniqueViolation } from '@open-mercato/shared/lib/crud/errors'
33
+ import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
34
+ import { buildChanges, emitCrudSideEffects, emitCrudUndoSideEffects } from '@open-mercato/shared/lib/commands/helpers'
35
+ import { withAtomicFlush } from '@open-mercato/shared/lib/commands/flush'
36
+ import type { CrudIndexerConfig } from '@open-mercato/shared/lib/crud/types'
37
+ import type { DataEngine } from '@open-mercato/shared/lib/data/engine'
38
+ import {
39
+ StaffTimeEntry,
40
+ StaffTimeEntryTag,
41
+ StaffTimeTag,
42
+ StaffTimeTask,
43
+ StaffTimeTaskTag,
44
+ } from '../data/entities'
45
+ import {
46
+ staffTimeTagCreateSchema,
47
+ staffTimeEntryTagAssignmentSchema,
48
+ staffTimeTaskTagAssignmentSchema,
49
+ type StaffTimeTagCreateInput,
50
+ type StaffTimeEntryTagAssignmentInput,
51
+ type StaffTimeTaskTagAssignmentInput,
52
+ } from '../data/validators'
53
+ import {
54
+ applyScopeToWhere,
55
+ commandActorScope,
56
+ commandInputScope,
57
+ ensureOrganizationScope,
58
+ ensureTenantScope,
59
+ extractUndoPayload,
60
+ scopedStaffSnapshotWhere,
61
+ staffSnapshotScopeFromContext,
62
+ staffSnapshotScopeFromSnapshot,
63
+ type StaffCommandScope,
64
+ type StaffSnapshotScope,
65
+ } from './shared'
66
+
67
+ export const staffTimeTagCommandIds = {
68
+ create: 'staff.timesheets.tags.create',
69
+ update: 'staff.timesheets.tags.update',
70
+ delete: 'staff.timesheets.tags.delete',
71
+ assignTask: 'staff.timesheets.tags.assign_task',
72
+ unassignTask: 'staff.timesheets.tags.unassign_task',
73
+ assignEntry: 'staff.timesheets.tags.assign_entry',
74
+ unassignEntry: 'staff.timesheets.tags.unassign_entry',
75
+ } as const
76
+
77
+ export const TAG_SLUG_DUPLICATE_CODE = 'time_tag_slug_duplicate'
78
+ export const TAG_UNKNOWN_IDS_CODE = 'time_tag_unknown_ids'
79
+ export const TAG_TARGET_LOCKED_CODE = 'time_entry_locked'
80
+
81
+ /**
82
+ * An assignment snapshot is written into the audit payload so undo can put the
83
+ * junction rows back. A tag used across thousands of rows would bloat the log, so
84
+ * the snapshot stops here and says so; undo then restores what it captured.
85
+ */
86
+ export const TAG_ASSIGNMENT_SNAPSHOT_LIMIT = 500
87
+
88
+ const tagCrudIndexer: CrudIndexerConfig<StaffTimeTag> = {
89
+ entityType: 'staff:staff_time_tag',
90
+ }
91
+
92
+ const taskCrudIndexer: CrudIndexerConfig<StaffTimeTask> = {
93
+ entityType: 'staff:staff_time_task',
94
+ }
95
+
96
+ const timeEntryCrudIndexer: CrudIndexerConfig<StaffTimeEntry> = {
97
+ entityType: 'staff:staff_time_entry',
98
+ }
99
+
100
+ // No CRUD event ids are declared for tags in `events.ts`: a tag write is
101
+ // vocabulary maintenance the screens re-read, so these commands queue index and
102
+ // cache side effects only.
103
+
104
+ type Translate = (key: string, fallback: string) => string
105
+
106
+ /**
107
+ * `data/validators.ts` ships the create shape only. The update schema is derived
108
+ * from it rather than restated so the slug/label/color rules cannot drift apart.
109
+ */
110
+ export const staffTimeTagUpdateSchema = z.object({
111
+ id: z.string().uuid(),
112
+ slug: staffTimeTagCreateSchema.shape.slug.optional(),
113
+ label: staffTimeTagCreateSchema.shape.label.optional(),
114
+ color: staffTimeTagCreateSchema.shape.color,
115
+ })
116
+
117
+ export type StaffTimeTagUpdateInput = z.infer<typeof staffTimeTagUpdateSchema>
118
+
119
+ type TagSnapshot = {
120
+ id: string
121
+ tenantId: string
122
+ organizationId: string
123
+ slug: string
124
+ label: string
125
+ color: string | null
126
+ deletedAt: string | null
127
+ }
128
+
129
+ type TagAssignmentSnapshot = {
130
+ id: string
131
+ tenantId: string
132
+ organizationId: string
133
+ tagId: string
134
+ targetId: string
135
+ }
136
+
137
+ type TagUndoPayload = {
138
+ before?: TagSnapshot | null
139
+ after?: TagSnapshot | null
140
+ taskAssignments?: TagAssignmentSnapshot[] | null
141
+ entryAssignments?: TagAssignmentSnapshot[] | null
142
+ assignmentsTruncated?: boolean
143
+ }
144
+
145
+ type AssignmentUndoPayload = {
146
+ target: 'task' | 'time_entry'
147
+ targetId: string
148
+ tenantId: string
149
+ organizationId: string
150
+ tagIdsBefore: string[]
151
+ tagIdsAfter: string[]
152
+ added: string[]
153
+ removed: TagAssignmentSnapshot[]
154
+ }
155
+
156
+ function toTagSnapshot(tag: StaffTimeTag): TagSnapshot {
157
+ return {
158
+ id: tag.id,
159
+ tenantId: tag.tenantId,
160
+ organizationId: tag.organizationId,
161
+ slug: tag.slug,
162
+ label: tag.label,
163
+ color: tag.color ?? null,
164
+ deletedAt: tag.deletedAt ? tag.deletedAt.toISOString() : null,
165
+ }
166
+ }
167
+
168
+ async function loadTagSnapshot(
169
+ em: EntityManager,
170
+ id: string,
171
+ scope?: StaffSnapshotScope | null,
172
+ ): Promise<TagSnapshot | null> {
173
+ const tag = await em.findOne(StaffTimeTag, scopedStaffSnapshotWhere(id, scope))
174
+ return tag ? toTagSnapshot(tag) : null
175
+ }
176
+
177
+ function slugDuplicateError(translate: Translate, slug: string): CrudHttpError {
178
+ const message = translate(
179
+ 'staff.time_tracking.tags.errors.slugDuplicate',
180
+ 'A tag with this slug already exists.',
181
+ )
182
+ return new CrudHttpError(409, {
183
+ code: TAG_SLUG_DUPLICATE_CODE,
184
+ error: message,
185
+ slug,
186
+ fieldErrors: { slug: message },
187
+ })
188
+ }
189
+
190
+ function tagNotFoundError(translate: Translate): CrudHttpError {
191
+ return new CrudHttpError(404, {
192
+ error: translate('staff.time_tracking.tags.errors.notFound', 'Tag not found or not accessible.'),
193
+ })
194
+ }
195
+
196
+ function unknownTagIdsError(translate: Translate, unknownIds: string[]): CrudHttpError {
197
+ const message = translate(
198
+ 'staff.time_tracking.tags.errors.unknownIds',
199
+ 'Some tags do not exist in this organization.',
200
+ )
201
+ return new CrudHttpError(422, {
202
+ code: TAG_UNKNOWN_IDS_CODE,
203
+ error: message,
204
+ unknownIds,
205
+ fieldErrors: { tagIds: message },
206
+ })
207
+ }
208
+
209
+ function targetNotFoundError(translate: Translate, target: 'task' | 'time_entry'): CrudHttpError {
210
+ // Deliberately the same 404 for "does not exist" and "not yours": tagging must
211
+ // not become a way to probe which task or entry ids exist (screen 17 note 1).
212
+ const message =
213
+ target === 'task'
214
+ ? translate('staff.time_tracking.tags.errors.taskNotFound', 'Task not found or not accessible.')
215
+ : translate('staff.time_tracking.tags.errors.entryNotFound', 'Time entry not found or not accessible.')
216
+ return new CrudHttpError(404, { error: message })
217
+ }
218
+
219
+ /**
220
+ * Persistence for one junction table. The command bodies below are shared; only
221
+ * these closures know which table and which target column they address, so each
222
+ * ORM call stays fully typed against its own entity.
223
+ */
224
+ type TagJunctionOps = {
225
+ target: 'task' | 'time_entry'
226
+ resourceKind: string
227
+ loadAssignments: (
228
+ em: EntityManager,
229
+ targetId: string,
230
+ scope: StaffCommandScope,
231
+ ) => Promise<TagAssignmentSnapshot[]>
232
+ loadAssignmentsForSnapshot: (
233
+ em: EntityManager,
234
+ targetId: string,
235
+ scope: StaffSnapshotScope | null,
236
+ ) => Promise<TagAssignmentSnapshot[]>
237
+ loadAssignmentsByTag: (
238
+ em: EntityManager,
239
+ tagId: string,
240
+ scope: StaffCommandScope,
241
+ ) => Promise<TagAssignmentSnapshot[]>
242
+ createAssignment: (em: EntityManager, row: Omit<TagAssignmentSnapshot, 'id'>) => void
243
+ deleteAssignments: (em: EntityManager, ids: string[], scope: StaffCommandScope) => Promise<number>
244
+ deleteAssignmentsByTag: (em: EntityManager, tagId: string, scope: StaffCommandScope) => Promise<number>
245
+ restoreAssignments: (em: EntityManager, rows: TagAssignmentSnapshot[]) => Promise<void>
246
+ }
247
+
248
+ function snapshotScopeWhere(scope?: StaffSnapshotScope | null): { tenantId?: string; organizationId?: string } {
249
+ const where: { tenantId?: string; organizationId?: string } = {}
250
+ if (scope?.tenantId) where.tenantId = scope.tenantId
251
+ if (scope?.organizationId) where.organizationId = scope.organizationId
252
+ return where
253
+ }
254
+
255
+ const taskJunctionOps: TagJunctionOps = {
256
+ target: 'task',
257
+ resourceKind: 'staff.timesheets.task_tag',
258
+ loadAssignments: async (em, targetId, scope) => {
259
+ const rows = await em.find(StaffTimeTaskTag, applyScopeToWhere<StaffTimeTaskTag>({ taskId: targetId }, scope))
260
+ return rows.map((row) => ({
261
+ id: row.id,
262
+ tenantId: row.tenantId,
263
+ organizationId: row.organizationId,
264
+ tagId: row.tagId,
265
+ targetId: row.taskId,
266
+ }))
267
+ },
268
+ loadAssignmentsForSnapshot: async (em, targetId, scope) => {
269
+ const rows = await em.find(StaffTimeTaskTag, { taskId: targetId, ...snapshotScopeWhere(scope) })
270
+ return rows.map((row) => ({
271
+ id: row.id,
272
+ tenantId: row.tenantId,
273
+ organizationId: row.organizationId,
274
+ tagId: row.tagId,
275
+ targetId: row.taskId,
276
+ }))
277
+ },
278
+ loadAssignmentsByTag: async (em, tagId, scope) => {
279
+ const rows = await em.find(StaffTimeTaskTag, applyScopeToWhere<StaffTimeTaskTag>({ tagId }, scope), {
280
+ limit: TAG_ASSIGNMENT_SNAPSHOT_LIMIT + 1,
281
+ })
282
+ return rows.map((row) => ({
283
+ id: row.id,
284
+ tenantId: row.tenantId,
285
+ organizationId: row.organizationId,
286
+ tagId: row.tagId,
287
+ targetId: row.taskId,
288
+ }))
289
+ },
290
+ createAssignment: (em, row) => {
291
+ em.persist(
292
+ em.create(StaffTimeTaskTag, {
293
+ tenantId: row.tenantId,
294
+ organizationId: row.organizationId,
295
+ tagId: row.tagId,
296
+ taskId: row.targetId,
297
+ createdAt: new Date(),
298
+ }),
299
+ )
300
+ },
301
+ deleteAssignments: async (em, ids, scope) =>
302
+ em.nativeDelete(StaffTimeTaskTag, applyScopeToWhere<StaffTimeTaskTag>({ id: { $in: ids } }, scope)),
303
+ deleteAssignmentsByTag: async (em, tagId, scope) =>
304
+ em.nativeDelete(StaffTimeTaskTag, applyScopeToWhere<StaffTimeTaskTag>({ tagId }, scope)),
305
+ restoreAssignments: async (em, rows) => {
306
+ for (const row of rows) {
307
+ const existing = await em.findOne(StaffTimeTaskTag, {
308
+ tagId: row.tagId,
309
+ taskId: row.targetId,
310
+ tenantId: row.tenantId,
311
+ organizationId: row.organizationId,
312
+ })
313
+ if (existing) continue
314
+ em.persist(
315
+ em.create(StaffTimeTaskTag, {
316
+ id: row.id,
317
+ tenantId: row.tenantId,
318
+ organizationId: row.organizationId,
319
+ tagId: row.tagId,
320
+ taskId: row.targetId,
321
+ createdAt: new Date(),
322
+ }),
323
+ )
324
+ }
325
+ },
326
+ }
327
+
328
+ const entryJunctionOps: TagJunctionOps = {
329
+ target: 'time_entry',
330
+ resourceKind: 'staff.timesheets.entry_tag',
331
+ loadAssignments: async (em, targetId, scope) => {
332
+ const rows = await em.find(
333
+ StaffTimeEntryTag,
334
+ applyScopeToWhere<StaffTimeEntryTag>({ timeEntryId: targetId }, scope),
335
+ )
336
+ return rows.map((row) => ({
337
+ id: row.id,
338
+ tenantId: row.tenantId,
339
+ organizationId: row.organizationId,
340
+ tagId: row.tagId,
341
+ targetId: row.timeEntryId,
342
+ }))
343
+ },
344
+ loadAssignmentsForSnapshot: async (em, targetId, scope) => {
345
+ const rows = await em.find(StaffTimeEntryTag, { timeEntryId: targetId, ...snapshotScopeWhere(scope) })
346
+ return rows.map((row) => ({
347
+ id: row.id,
348
+ tenantId: row.tenantId,
349
+ organizationId: row.organizationId,
350
+ tagId: row.tagId,
351
+ targetId: row.timeEntryId,
352
+ }))
353
+ },
354
+ loadAssignmentsByTag: async (em, tagId, scope) => {
355
+ const rows = await em.find(StaffTimeEntryTag, applyScopeToWhere<StaffTimeEntryTag>({ tagId }, scope), {
356
+ limit: TAG_ASSIGNMENT_SNAPSHOT_LIMIT + 1,
357
+ })
358
+ return rows.map((row) => ({
359
+ id: row.id,
360
+ tenantId: row.tenantId,
361
+ organizationId: row.organizationId,
362
+ tagId: row.tagId,
363
+ targetId: row.timeEntryId,
364
+ }))
365
+ },
366
+ createAssignment: (em, row) => {
367
+ em.persist(
368
+ em.create(StaffTimeEntryTag, {
369
+ tenantId: row.tenantId,
370
+ organizationId: row.organizationId,
371
+ tagId: row.tagId,
372
+ timeEntryId: row.targetId,
373
+ createdAt: new Date(),
374
+ }),
375
+ )
376
+ },
377
+ deleteAssignments: async (em, ids, scope) =>
378
+ em.nativeDelete(StaffTimeEntryTag, applyScopeToWhere<StaffTimeEntryTag>({ id: { $in: ids } }, scope)),
379
+ deleteAssignmentsByTag: async (em, tagId, scope) =>
380
+ em.nativeDelete(StaffTimeEntryTag, applyScopeToWhere<StaffTimeEntryTag>({ tagId }, scope)),
381
+ restoreAssignments: async (em, rows) => {
382
+ for (const row of rows) {
383
+ const existing = await em.findOne(StaffTimeEntryTag, {
384
+ tagId: row.tagId,
385
+ timeEntryId: row.targetId,
386
+ tenantId: row.tenantId,
387
+ organizationId: row.organizationId,
388
+ })
389
+ if (existing) continue
390
+ em.persist(
391
+ em.create(StaffTimeEntryTag, {
392
+ id: row.id,
393
+ tenantId: row.tenantId,
394
+ organizationId: row.organizationId,
395
+ tagId: row.tagId,
396
+ timeEntryId: row.targetId,
397
+ createdAt: new Date(),
398
+ }),
399
+ )
400
+ }
401
+ },
402
+ }
403
+
404
+ async function requireKnownTags(
405
+ em: EntityManager,
406
+ tagIds: string[],
407
+ scope: StaffCommandScope,
408
+ translate: Translate,
409
+ ): Promise<void> {
410
+ const unique = Array.from(new Set(tagIds))
411
+ if (unique.length === 0) return
412
+ const tags = await em.find(
413
+ StaffTimeTag,
414
+ applyScopeToWhere<StaffTimeTag>({ id: { $in: unique }, deletedAt: null }, scope),
415
+ { fields: ['id'] },
416
+ )
417
+ const known = new Set(tags.map((tag) => tag.id))
418
+ const unknownIds = unique.filter((id) => !known.has(id))
419
+ if (unknownIds.length > 0) throw unknownTagIdsError(translate, unknownIds)
420
+ }
421
+
422
+ const createTagCommand: CommandHandler<StaffTimeTagCreateInput, { tagId: string }> = {
423
+ id: staffTimeTagCommandIds.create,
424
+ async prepare(rawInput, ctx) {
425
+ const parsed = staffTimeTagCreateSchema.safeParse(rawInput)
426
+ if (!parsed.success) return {}
427
+ const em = ctx.container.resolve('em') as EntityManager
428
+ const existing = await em.findOne(StaffTimeTag, {
429
+ slug: parsed.data.slug,
430
+ tenantId: parsed.data.tenantId,
431
+ organizationId: parsed.data.organizationId,
432
+ deletedAt: null,
433
+ })
434
+ return { before: { slugTaken: existing != null } }
435
+ },
436
+ async execute(rawInput, ctx) {
437
+ const parsed = staffTimeTagCreateSchema.parse(rawInput)
438
+ ensureTenantScope(ctx, parsed.tenantId)
439
+ ensureOrganizationScope(ctx, parsed.organizationId)
440
+ const scope = commandInputScope(ctx, parsed.tenantId, parsed.organizationId)
441
+ const { translate } = await resolveTranslations()
442
+
443
+ const em = (ctx.container.resolve('em') as EntityManager).fork()
444
+ let created: StaffTimeTag | null = null
445
+
446
+ try {
447
+ await withAtomicFlush(
448
+ em,
449
+ [
450
+ async () => {
451
+ // The read lives in the same transaction as the insert, so a
452
+ // concurrent create cannot slip a second row past this check; the
453
+ // partial unique index is the backstop and is translated below.
454
+ const duplicate = await em.findOne(
455
+ StaffTimeTag,
456
+ applyScopeToWhere<StaffTimeTag>({ slug: parsed.slug, deletedAt: null }, scope),
457
+ { fields: ['id'] },
458
+ )
459
+ if (duplicate) throw slugDuplicateError(translate, parsed.slug)
460
+ },
461
+ () => {
462
+ created = em.create(StaffTimeTag, {
463
+ tenantId: parsed.tenantId,
464
+ organizationId: parsed.organizationId,
465
+ slug: parsed.slug,
466
+ label: parsed.label,
467
+ color: parsed.color ?? null,
468
+ createdAt: new Date(),
469
+ updatedAt: new Date(),
470
+ deletedAt: null,
471
+ })
472
+ em.persist(created)
473
+ },
474
+ ],
475
+ { transaction: true, label: staffTimeTagCommandIds.create },
476
+ )
477
+ } catch (err) {
478
+ if (isUniqueViolation(err)) throw slugDuplicateError(translate, parsed.slug)
479
+ throw err
480
+ }
481
+
482
+ const record = created as StaffTimeTag | null
483
+ if (!record) throw tagNotFoundError(translate)
484
+
485
+ await emitCrudSideEffects({
486
+ dataEngine: ctx.container.resolve('dataEngine'),
487
+ action: 'created',
488
+ entity: record,
489
+ identifiers: { id: record.id, organizationId: record.organizationId, tenantId: record.tenantId },
490
+ indexer: tagCrudIndexer,
491
+ })
492
+
493
+ return { tagId: record.id }
494
+ },
495
+ captureAfter: async (_input, result, ctx) => {
496
+ const em = (ctx.container.resolve('em') as EntityManager).fork()
497
+ const snapshot = await loadTagSnapshot(em, result.tagId, staffSnapshotScopeFromContext(ctx))
498
+ if (!snapshot) return null
499
+ return { snapshot }
500
+ },
501
+ buildLog: async ({ result, ctx }) => {
502
+ const em = (ctx.container.resolve('em') as EntityManager).fork()
503
+ const snapshot = await loadTagSnapshot(em, result.tagId, staffSnapshotScopeFromContext(ctx))
504
+ if (!snapshot) return null
505
+ const { translate } = await resolveTranslations()
506
+ return {
507
+ actionLabel: translate('staff.audit.timesheets.tags.create', 'Create tag'),
508
+ resourceKind: 'staff.timesheets.tag',
509
+ resourceId: snapshot.id,
510
+ tenantId: snapshot.tenantId,
511
+ organizationId: snapshot.organizationId,
512
+ snapshotAfter: snapshot,
513
+ payload: {
514
+ undo: { after: snapshot } satisfies TagUndoPayload,
515
+ },
516
+ }
517
+ },
518
+ undo: async ({ logEntry, ctx }) => {
519
+ const payload = extractUndoPayload<TagUndoPayload>(logEntry)
520
+ const after = payload?.after
521
+ if (!after) return
522
+ const snapshotScope = staffSnapshotScopeFromSnapshot(after)
523
+ const em = (ctx.container.resolve('em') as EntityManager).fork()
524
+ const tag = await em.findOne(StaffTimeTag, scopedStaffSnapshotWhere(after.id, snapshotScope))
525
+ if (!tag) return
526
+
527
+ await withAtomicFlush(
528
+ em,
529
+ [
530
+ () => {
531
+ tag.deletedAt = new Date()
532
+ tag.updatedAt = new Date()
533
+ },
534
+ ],
535
+ { transaction: true, label: `${staffTimeTagCommandIds.create}.undo` },
536
+ )
537
+
538
+ await emitCrudUndoSideEffects({
539
+ dataEngine: ctx.container.resolve('dataEngine'),
540
+ action: 'deleted',
541
+ entity: tag,
542
+ identifiers: { id: tag.id, organizationId: tag.organizationId, tenantId: tag.tenantId },
543
+ indexer: tagCrudIndexer,
544
+ })
545
+ },
546
+ }
547
+
548
+ const updateTagCommand: CommandHandler<StaffTimeTagUpdateInput, { tagId: string }> = {
549
+ id: staffTimeTagCommandIds.update,
550
+ async prepare(rawInput, ctx) {
551
+ const parsed = staffTimeTagUpdateSchema.safeParse(rawInput)
552
+ if (!parsed.success) return {}
553
+ const em = ctx.container.resolve('em') as EntityManager
554
+ const before = await loadTagSnapshot(em, parsed.data.id, staffSnapshotScopeFromContext(ctx))
555
+ if (!before) return {}
556
+ return { before: { snapshot: before } }
557
+ },
558
+ async execute(rawInput, ctx) {
559
+ const parsed = staffTimeTagUpdateSchema.parse(rawInput)
560
+ const { translate } = await resolveTranslations()
561
+ const em = (ctx.container.resolve('em') as EntityManager).fork()
562
+ const scope = commandActorScope(ctx)
563
+
564
+ const tag = await em.findOne(StaffTimeTag, applyScopeToWhere<StaffTimeTag>({ id: parsed.id, deletedAt: null }, scope))
565
+ if (!tag) throw tagNotFoundError(translate)
566
+ ensureTenantScope(ctx, tag.tenantId)
567
+ ensureOrganizationScope(ctx, tag.organizationId)
568
+
569
+ try {
570
+ await withAtomicFlush(
571
+ em,
572
+ [
573
+ async () => {
574
+ if (parsed.slug === undefined || parsed.slug === tag.slug) return
575
+ const duplicate = await em.findOne(
576
+ StaffTimeTag,
577
+ applyScopeToWhere<StaffTimeTag>({ slug: parsed.slug, deletedAt: null, id: { $ne: tag.id } }, scope),
578
+ { fields: ['id'] },
579
+ )
580
+ if (duplicate) throw slugDuplicateError(translate, parsed.slug)
581
+ },
582
+ () => {
583
+ if (parsed.slug !== undefined) tag.slug = parsed.slug
584
+ if (parsed.label !== undefined) tag.label = parsed.label
585
+ if (parsed.color !== undefined) tag.color = parsed.color ?? null
586
+ tag.updatedAt = new Date()
587
+ },
588
+ ],
589
+ { transaction: true, label: staffTimeTagCommandIds.update },
590
+ )
591
+ } catch (err) {
592
+ if (isUniqueViolation(err)) throw slugDuplicateError(translate, parsed.slug ?? tag.slug)
593
+ throw err
594
+ }
595
+
596
+ await emitCrudSideEffects({
597
+ dataEngine: ctx.container.resolve('dataEngine'),
598
+ action: 'updated',
599
+ entity: tag,
600
+ identifiers: { id: tag.id, organizationId: tag.organizationId, tenantId: tag.tenantId },
601
+ indexer: tagCrudIndexer,
602
+ })
603
+
604
+ return { tagId: tag.id }
605
+ },
606
+ buildLog: async ({ snapshots, ctx }) => {
607
+ const before = (snapshots.before as { snapshot?: TagSnapshot } | undefined)?.snapshot
608
+ if (!before) return null
609
+ const em = (ctx.container.resolve('em') as EntityManager).fork()
610
+ const after = await loadTagSnapshot(em, before.id, staffSnapshotScopeFromSnapshot(before))
611
+ if (!after) return null
612
+ const changes = buildChanges(
613
+ before as unknown as Record<string, unknown>,
614
+ after as unknown as Record<string, unknown>,
615
+ ['slug', 'label', 'color'],
616
+ )
617
+ const { translate } = await resolveTranslations()
618
+ return {
619
+ actionLabel: translate('staff.audit.timesheets.tags.update', 'Update tag'),
620
+ resourceKind: 'staff.timesheets.tag',
621
+ resourceId: before.id,
622
+ tenantId: before.tenantId,
623
+ organizationId: before.organizationId,
624
+ snapshotBefore: before,
625
+ snapshotAfter: after,
626
+ changes,
627
+ payload: {
628
+ undo: { before, after } satisfies TagUndoPayload,
629
+ },
630
+ }
631
+ },
632
+ undo: async ({ logEntry, ctx }) => {
633
+ const payload = extractUndoPayload<TagUndoPayload>(logEntry)
634
+ const before = payload?.before
635
+ if (!before) return
636
+ const snapshotScope = staffSnapshotScopeFromSnapshot(before)
637
+ const em = (ctx.container.resolve('em') as EntityManager).fork()
638
+ const tag = await em.findOne(StaffTimeTag, scopedStaffSnapshotWhere(before.id, snapshotScope))
639
+ if (!tag) return
640
+
641
+ await withAtomicFlush(
642
+ em,
643
+ [
644
+ () => {
645
+ tag.slug = before.slug
646
+ tag.label = before.label
647
+ tag.color = before.color ?? null
648
+ tag.updatedAt = new Date()
649
+ },
650
+ ],
651
+ { transaction: true, label: `${staffTimeTagCommandIds.update}.undo` },
652
+ )
653
+
654
+ await emitCrudUndoSideEffects({
655
+ dataEngine: ctx.container.resolve('dataEngine'),
656
+ action: 'updated',
657
+ entity: tag,
658
+ identifiers: { id: tag.id, organizationId: tag.organizationId, tenantId: tag.tenantId },
659
+ indexer: tagCrudIndexer,
660
+ })
661
+ },
662
+ }
663
+
664
+ type DeleteTagResult = {
665
+ tagId: string
666
+ removedTaskAssignments: number
667
+ removedEntryAssignments: number
668
+ }
669
+
670
+ const deleteTagCommand: CommandHandler<{ id?: string }, DeleteTagResult> = {
671
+ id: staffTimeTagCommandIds.delete,
672
+ async prepare(input, ctx) {
673
+ const id = input?.id
674
+ if (!id) return {}
675
+ const em = ctx.container.resolve('em') as EntityManager
676
+ const scope = staffSnapshotScopeFromContext(ctx)
677
+ const before = await loadTagSnapshot(em, id, scope)
678
+ if (!before) return {}
679
+ const readScope: StaffCommandScope = {
680
+ tenantId: before.tenantId,
681
+ organizationId: before.organizationId,
682
+ requireTenant: true,
683
+ requireOrganization: true,
684
+ }
685
+ const taskAssignments = await taskJunctionOps.loadAssignmentsByTag(em, id, readScope)
686
+ const entryAssignments = await entryJunctionOps.loadAssignmentsByTag(em, id, readScope)
687
+ const truncated =
688
+ taskAssignments.length > TAG_ASSIGNMENT_SNAPSHOT_LIMIT || entryAssignments.length > TAG_ASSIGNMENT_SNAPSHOT_LIMIT
689
+ return {
690
+ before: {
691
+ snapshot: before,
692
+ taskAssignments: taskAssignments.slice(0, TAG_ASSIGNMENT_SNAPSHOT_LIMIT),
693
+ entryAssignments: entryAssignments.slice(0, TAG_ASSIGNMENT_SNAPSHOT_LIMIT),
694
+ assignmentsTruncated: truncated,
695
+ },
696
+ }
697
+ },
698
+ async execute(input, ctx) {
699
+ const { translate } = await resolveTranslations()
700
+ const id = input?.id
701
+ if (!id) {
702
+ throw new CrudHttpError(400, {
703
+ error: translate('staff.time_tracking.tags.errors.idRequired', 'Tag id is required.'),
704
+ })
705
+ }
706
+ const em = (ctx.container.resolve('em') as EntityManager).fork()
707
+ const scope = commandActorScope(ctx)
708
+ const tag = await em.findOne(StaffTimeTag, applyScopeToWhere<StaffTimeTag>({ id, deletedAt: null }, scope))
709
+ if (!tag) throw tagNotFoundError(translate)
710
+ ensureTenantScope(ctx, tag.tenantId)
711
+ ensureOrganizationScope(ctx, tag.organizationId)
712
+
713
+ let removedTaskAssignments = 0
714
+ let removedEntryAssignments = 0
715
+
716
+ await withAtomicFlush(
717
+ em,
718
+ [
719
+ async () => {
720
+ // The cascade is deliberate: the badge disappears everywhere it was
721
+ // used, and the counts travel back so the caller sees the reach.
722
+ removedTaskAssignments = await taskJunctionOps.deleteAssignmentsByTag(em, tag.id, scope)
723
+ removedEntryAssignments = await entryJunctionOps.deleteAssignmentsByTag(em, tag.id, scope)
724
+ },
725
+ () => {
726
+ tag.deletedAt = new Date()
727
+ tag.updatedAt = new Date()
728
+ },
729
+ ],
730
+ { transaction: true, label: staffTimeTagCommandIds.delete },
731
+ )
732
+
733
+ await emitCrudSideEffects({
734
+ dataEngine: ctx.container.resolve('dataEngine'),
735
+ action: 'deleted',
736
+ entity: tag,
737
+ identifiers: { id: tag.id, organizationId: tag.organizationId, tenantId: tag.tenantId },
738
+ indexer: tagCrudIndexer,
739
+ })
740
+
741
+ return { tagId: tag.id, removedTaskAssignments, removedEntryAssignments }
742
+ },
743
+ buildLog: async ({ result, snapshots }) => {
744
+ const prepared = snapshots.before as
745
+ | {
746
+ snapshot?: TagSnapshot
747
+ taskAssignments?: TagAssignmentSnapshot[]
748
+ entryAssignments?: TagAssignmentSnapshot[]
749
+ assignmentsTruncated?: boolean
750
+ }
751
+ | undefined
752
+ const before = prepared?.snapshot
753
+ if (!before) return null
754
+ const { translate } = await resolveTranslations()
755
+ return {
756
+ actionLabel: translate('staff.audit.timesheets.tags.delete', 'Delete tag'),
757
+ resourceKind: 'staff.timesheets.tag',
758
+ resourceId: before.id,
759
+ tenantId: before.tenantId,
760
+ organizationId: before.organizationId,
761
+ snapshotBefore: before,
762
+ changes: {
763
+ removedTaskAssignments: { from: result.removedTaskAssignments, to: 0 },
764
+ removedEntryAssignments: { from: result.removedEntryAssignments, to: 0 },
765
+ },
766
+ payload: {
767
+ undo: {
768
+ before,
769
+ taskAssignments: prepared?.taskAssignments ?? null,
770
+ entryAssignments: prepared?.entryAssignments ?? null,
771
+ assignmentsTruncated: prepared?.assignmentsTruncated ?? false,
772
+ } satisfies TagUndoPayload,
773
+ },
774
+ }
775
+ },
776
+ undo: async ({ logEntry, ctx }) => {
777
+ const payload = extractUndoPayload<TagUndoPayload>(logEntry)
778
+ const before = payload?.before
779
+ if (!before) return
780
+ const snapshotScope = staffSnapshotScopeFromSnapshot(before)
781
+ const em = (ctx.container.resolve('em') as EntityManager).fork()
782
+ let tag = await em.findOne(StaffTimeTag, scopedStaffSnapshotWhere(before.id, snapshotScope))
783
+
784
+ await withAtomicFlush(
785
+ em,
786
+ [
787
+ () => {
788
+ if (!tag) {
789
+ tag = em.create(StaffTimeTag, {
790
+ id: before.id,
791
+ tenantId: before.tenantId,
792
+ organizationId: before.organizationId,
793
+ slug: before.slug,
794
+ label: before.label,
795
+ color: before.color ?? null,
796
+ createdAt: new Date(),
797
+ updatedAt: new Date(),
798
+ deletedAt: null,
799
+ })
800
+ em.persist(tag)
801
+ return
802
+ }
803
+ tag.slug = before.slug
804
+ tag.label = before.label
805
+ tag.color = before.color ?? null
806
+ tag.deletedAt = null
807
+ tag.updatedAt = new Date()
808
+ },
809
+ // Restoring assignments re-reads the junction rows, so it is its own phase.
810
+ () => taskJunctionOps.restoreAssignments(em, payload?.taskAssignments ?? []),
811
+ () => entryJunctionOps.restoreAssignments(em, payload?.entryAssignments ?? []),
812
+ ],
813
+ { transaction: true, label: `${staffTimeTagCommandIds.delete}.undo` },
814
+ )
815
+
816
+ await emitCrudUndoSideEffects({
817
+ dataEngine: ctx.container.resolve('dataEngine'),
818
+ action: 'created',
819
+ entity: tag,
820
+ identifiers: { id: before.id, organizationId: before.organizationId, tenantId: before.tenantId },
821
+ indexer: tagCrudIndexer,
822
+ })
823
+ },
824
+ }
825
+
826
+ type AssignmentResult = {
827
+ targetId: string
828
+ assignedTagIds: string[]
829
+ alreadyAssignedTagIds: string[]
830
+ tagIds: string[]
831
+ }
832
+
833
+ type UnassignmentResult = {
834
+ targetId: string
835
+ removedTagIds: string[]
836
+ notAssignedTagIds: string[]
837
+ tagIds: string[]
838
+ }
839
+
840
+ type AssignmentTarget = {
841
+ id: string
842
+ tenantId: string
843
+ organizationId: string
844
+ }
845
+
846
+ async function requireTaskTarget(
847
+ em: EntityManager,
848
+ taskId: string,
849
+ scope: StaffCommandScope,
850
+ translate: Translate,
851
+ ): Promise<AssignmentTarget> {
852
+ const task = await em.findOne(StaffTimeTask, applyScopeToWhere<StaffTimeTask>({ id: taskId, deletedAt: null }, scope))
853
+ if (!task) throw targetNotFoundError(translate, 'task')
854
+ return { id: task.id, tenantId: task.tenantId, organizationId: task.organizationId }
855
+ }
856
+
857
+ async function requireEntryTarget(
858
+ em: EntityManager,
859
+ timeEntryId: string,
860
+ scope: StaffCommandScope,
861
+ translate: Translate,
862
+ ): Promise<AssignmentTarget> {
863
+ const entry = await em.findOne(
864
+ StaffTimeEntry,
865
+ applyScopeToWhere<StaffTimeEntry>({ id: timeEntryId, deletedAt: null }, scope),
866
+ )
867
+ if (!entry) throw targetNotFoundError(translate, 'time_entry')
868
+ if (entry.lockedReportId) {
869
+ // An entry frozen in a closed report is read-only, and its tags are part of
870
+ // what the report renders.
871
+ throw new CrudHttpError(409, {
872
+ code: TAG_TARGET_LOCKED_CODE,
873
+ error: translate(
874
+ 'staff.time_tracking.tags.errors.entryLocked',
875
+ 'This time entry is locked in a closed report and its tags cannot be changed.',
876
+ ),
877
+ lockedReportId: entry.lockedReportId,
878
+ })
879
+ }
880
+ return { id: entry.id, tenantId: entry.tenantId, organizationId: entry.organizationId }
881
+ }
882
+
883
+ type AssignmentCommandInput = {
884
+ tenantId: string
885
+ organizationId: string
886
+ targetId: string
887
+ tagIds: string[]
888
+ }
889
+
890
+ function refreshTargetSideEffects(ops: TagJunctionOps) {
891
+ return async (ctx: { container: { resolve: (name: string) => unknown } }, target: AssignmentTarget) => {
892
+ const dataEngine = ctx.container.resolve('dataEngine') as DataEngine
893
+ // The target's own index document and cached lists carry its tags, so they
894
+ // are refreshed even though no column on the target row changed.
895
+ await emitCrudSideEffects({
896
+ dataEngine,
897
+ action: 'updated',
898
+ entity: target,
899
+ identifiers: { id: target.id, organizationId: target.organizationId, tenantId: target.tenantId },
900
+ indexer: ops.target === 'task' ? taskCrudIndexer : timeEntryCrudIndexer,
901
+ })
902
+ }
903
+ }
904
+
905
+ async function runAssignment(
906
+ ops: TagJunctionOps,
907
+ requireTarget: (
908
+ em: EntityManager,
909
+ targetId: string,
910
+ scope: StaffCommandScope,
911
+ translate: Translate,
912
+ ) => Promise<AssignmentTarget>,
913
+ parsed: AssignmentCommandInput,
914
+ ctx: Parameters<CommandHandler<AssignmentCommandInput, AssignmentResult>['execute']>[1],
915
+ ): Promise<AssignmentResult> {
916
+ ensureTenantScope(ctx, parsed.tenantId)
917
+ ensureOrganizationScope(ctx, parsed.organizationId)
918
+ const scope = commandInputScope(ctx, parsed.tenantId, parsed.organizationId)
919
+ const { translate } = await resolveTranslations()
920
+
921
+ const requestedTagIds = Array.from(new Set(parsed.tagIds))
922
+
923
+ let target: AssignmentTarget | null = null
924
+ let assignedTagIds: string[] = []
925
+ let alreadyAssignedTagIds: string[] = []
926
+ let tagIdsAfter: string[] = []
927
+
928
+ // Each attempt gets its own fork: a rolled-back unit of work must not carry
929
+ // its persisted-but-uncommitted rows into the retry.
930
+ const attempt = async (): Promise<void> => {
931
+ const em = (ctx.container.resolve('em') as EntityManager).fork()
932
+ await withAtomicFlush(
933
+ em,
934
+ [
935
+ async () => {
936
+ target = await requireTarget(em, parsed.targetId, scope, translate)
937
+ await requireKnownTags(em, requestedTagIds, scope, translate)
938
+ const existing = await ops.loadAssignments(em, parsed.targetId, scope)
939
+ const existingTagIds = new Set(existing.map((row) => row.tagId))
940
+ alreadyAssignedTagIds = requestedTagIds.filter((tagId) => existingTagIds.has(tagId))
941
+ assignedTagIds = requestedTagIds.filter((tagId) => !existingTagIds.has(tagId))
942
+ tagIdsAfter = Array.from(new Set([...existingTagIds, ...requestedTagIds]))
943
+ },
944
+ () => {
945
+ for (const tagId of assignedTagIds) {
946
+ ops.createAssignment(em, {
947
+ tenantId: parsed.tenantId,
948
+ organizationId: parsed.organizationId,
949
+ tagId,
950
+ targetId: parsed.targetId,
951
+ })
952
+ }
953
+ },
954
+ ],
955
+ { transaction: true, label: `${ops.target}.tags.assign` },
956
+ )
957
+ }
958
+
959
+ try {
960
+ await attempt()
961
+ } catch (err) {
962
+ if (!isUniqueViolation(err)) throw err
963
+ // A concurrent assign won the race. Re-reading turns the collision into the
964
+ // no-op success the second caller asked for; a second violation would mean
965
+ // the row is there either way, which is the requested end state.
966
+ try {
967
+ await attempt()
968
+ } catch (retryErr) {
969
+ if (!isUniqueViolation(retryErr)) throw retryErr
970
+ assignedTagIds = []
971
+ alreadyAssignedTagIds = requestedTagIds
972
+ tagIdsAfter = requestedTagIds
973
+ }
974
+ }
975
+
976
+ const resolvedTarget = target as AssignmentTarget | null
977
+ if (!resolvedTarget) throw targetNotFoundError(translate, ops.target)
978
+
979
+ if (assignedTagIds.length > 0) {
980
+ await refreshTargetSideEffects(ops)(ctx, resolvedTarget)
981
+ }
982
+
983
+ return {
984
+ targetId: parsed.targetId,
985
+ assignedTagIds,
986
+ alreadyAssignedTagIds,
987
+ tagIds: tagIdsAfter,
988
+ }
989
+ }
990
+
991
+ async function runUnassignment(
992
+ ops: TagJunctionOps,
993
+ requireTarget: (
994
+ em: EntityManager,
995
+ targetId: string,
996
+ scope: StaffCommandScope,
997
+ translate: Translate,
998
+ ) => Promise<AssignmentTarget>,
999
+ parsed: AssignmentCommandInput,
1000
+ ctx: Parameters<CommandHandler<AssignmentCommandInput, UnassignmentResult>['execute']>[1],
1001
+ ): Promise<UnassignmentResult> {
1002
+ ensureTenantScope(ctx, parsed.tenantId)
1003
+ ensureOrganizationScope(ctx, parsed.organizationId)
1004
+ const scope = commandInputScope(ctx, parsed.tenantId, parsed.organizationId)
1005
+ const { translate } = await resolveTranslations()
1006
+
1007
+ const em = (ctx.container.resolve('em') as EntityManager).fork()
1008
+ const requestedTagIds = Array.from(new Set(parsed.tagIds))
1009
+
1010
+ let target: AssignmentTarget | null = null
1011
+ let removedTagIds: string[] = []
1012
+ let notAssignedTagIds: string[] = []
1013
+ let tagIdsAfter: string[] = []
1014
+
1015
+ await withAtomicFlush(
1016
+ em,
1017
+ [
1018
+ async () => {
1019
+ target = await requireTarget(em, parsed.targetId, scope, translate)
1020
+ const existing = await ops.loadAssignments(em, parsed.targetId, scope)
1021
+ const byTagId = new Map(existing.map((row) => [row.tagId, row]))
1022
+ removedTagIds = requestedTagIds.filter((tagId) => byTagId.has(tagId))
1023
+ notAssignedTagIds = requestedTagIds.filter((tagId) => !byTagId.has(tagId))
1024
+ tagIdsAfter = existing.map((row) => row.tagId).filter((tagId) => !removedTagIds.includes(tagId))
1025
+ const removableIds = removedTagIds
1026
+ .map((tagId) => byTagId.get(tagId)?.id)
1027
+ .filter((value): value is string => typeof value === 'string')
1028
+ // Removing a tag that is not assigned is a no-op, not a 404: the caller
1029
+ // asked for an end state that already holds.
1030
+ if (removableIds.length > 0) await ops.deleteAssignments(em, removableIds, scope)
1031
+ },
1032
+ ],
1033
+ { transaction: true, label: `${ops.target}.tags.unassign` },
1034
+ )
1035
+
1036
+ const resolvedTarget = target as AssignmentTarget | null
1037
+ if (!resolvedTarget) throw targetNotFoundError(translate, ops.target)
1038
+
1039
+ if (removedTagIds.length > 0) {
1040
+ await refreshTargetSideEffects(ops)(ctx, resolvedTarget)
1041
+ }
1042
+
1043
+ return {
1044
+ targetId: parsed.targetId,
1045
+ removedTagIds,
1046
+ notAssignedTagIds,
1047
+ tagIds: tagIdsAfter,
1048
+ }
1049
+ }
1050
+
1051
+ async function restoreAssignmentState(
1052
+ ops: TagJunctionOps,
1053
+ payload: AssignmentUndoPayload,
1054
+ ctx: { container: { resolve: (name: string) => unknown } },
1055
+ ): Promise<void> {
1056
+ const em = (ctx.container.resolve('em') as EntityManager).fork()
1057
+ const scope: StaffCommandScope = {
1058
+ tenantId: payload.tenantId,
1059
+ organizationId: payload.organizationId,
1060
+ requireTenant: true,
1061
+ requireOrganization: true,
1062
+ }
1063
+
1064
+ await withAtomicFlush(
1065
+ em,
1066
+ [
1067
+ async () => {
1068
+ if (payload.added.length > 0) {
1069
+ const current = await ops.loadAssignments(em, payload.targetId, scope)
1070
+ const removableIds = current
1071
+ .filter((row) => payload.added.includes(row.tagId))
1072
+ .map((row) => row.id)
1073
+ if (removableIds.length > 0) await ops.deleteAssignments(em, removableIds, scope)
1074
+ }
1075
+ },
1076
+ () => ops.restoreAssignments(em, payload.removed),
1077
+ ],
1078
+ { transaction: true, label: `${ops.target}.tags.undo` },
1079
+ )
1080
+ }
1081
+
1082
+ function assignmentLogPayload(
1083
+ ops: TagJunctionOps,
1084
+ parsed: AssignmentCommandInput,
1085
+ result: AssignmentResult,
1086
+ ): AssignmentUndoPayload {
1087
+ return {
1088
+ target: ops.target,
1089
+ targetId: parsed.targetId,
1090
+ tenantId: parsed.tenantId,
1091
+ organizationId: parsed.organizationId,
1092
+ tagIdsBefore: result.tagIds.filter((tagId) => !result.assignedTagIds.includes(tagId)),
1093
+ tagIdsAfter: result.tagIds,
1094
+ added: result.assignedTagIds,
1095
+ removed: [],
1096
+ }
1097
+ }
1098
+
1099
+ function unassignmentLogPayload(
1100
+ ops: TagJunctionOps,
1101
+ parsed: AssignmentCommandInput,
1102
+ result: UnassignmentResult,
1103
+ removedRows: TagAssignmentSnapshot[],
1104
+ ): AssignmentUndoPayload {
1105
+ return {
1106
+ target: ops.target,
1107
+ targetId: parsed.targetId,
1108
+ tenantId: parsed.tenantId,
1109
+ organizationId: parsed.organizationId,
1110
+ tagIdsBefore: [...result.tagIds, ...result.removedTagIds],
1111
+ tagIdsAfter: result.tagIds,
1112
+ added: [],
1113
+ removed: removedRows,
1114
+ }
1115
+ }
1116
+
1117
+ function toTaskCommandInput(parsed: StaffTimeTaskTagAssignmentInput): AssignmentCommandInput {
1118
+ return {
1119
+ tenantId: parsed.tenantId,
1120
+ organizationId: parsed.organizationId,
1121
+ targetId: parsed.taskId,
1122
+ tagIds: parsed.tagIds,
1123
+ }
1124
+ }
1125
+
1126
+ function toEntryCommandInput(parsed: StaffTimeEntryTagAssignmentInput): AssignmentCommandInput {
1127
+ return {
1128
+ tenantId: parsed.tenantId,
1129
+ organizationId: parsed.organizationId,
1130
+ targetId: parsed.timeEntryId,
1131
+ tagIds: parsed.tagIds,
1132
+ }
1133
+ }
1134
+
1135
+ const assignTaskTagsCommand: CommandHandler<StaffTimeTaskTagAssignmentInput, AssignmentResult> = {
1136
+ id: staffTimeTagCommandIds.assignTask,
1137
+ async prepare(rawInput, ctx) {
1138
+ const parsed = staffTimeTaskTagAssignmentSchema.safeParse(rawInput)
1139
+ if (!parsed.success) return {}
1140
+ const em = ctx.container.resolve('em') as EntityManager
1141
+ const rows = await taskJunctionOps.loadAssignmentsForSnapshot(
1142
+ em,
1143
+ parsed.data.taskId,
1144
+ staffSnapshotScopeFromContext(ctx),
1145
+ )
1146
+ return { before: { tagIds: rows.map((row) => row.tagId) } }
1147
+ },
1148
+ execute: async (rawInput, ctx) => {
1149
+ const parsed = staffTimeTaskTagAssignmentSchema.parse(rawInput)
1150
+ return runAssignment(taskJunctionOps, requireTaskTarget, toTaskCommandInput(parsed), ctx)
1151
+ },
1152
+ buildLog: async ({ input, result, snapshots }) => {
1153
+ const parsed = staffTimeTaskTagAssignmentSchema.parse(input)
1154
+ const commandInput = toTaskCommandInput(parsed)
1155
+ const before = (snapshots.before as { tagIds?: string[] } | undefined)?.tagIds ?? []
1156
+ const { translate } = await resolveTranslations()
1157
+ return {
1158
+ actionLabel: translate('staff.audit.timesheets.tags.assign_task', 'Assign task tags'),
1159
+ resourceKind: taskJunctionOps.resourceKind,
1160
+ resourceId: commandInput.targetId,
1161
+ tenantId: commandInput.tenantId,
1162
+ organizationId: commandInput.organizationId,
1163
+ snapshotBefore: { tagIds: before },
1164
+ snapshotAfter: { tagIds: result.tagIds },
1165
+ changes: { tagIds: { from: before, to: result.tagIds } },
1166
+ payload: {
1167
+ undo: assignmentLogPayload(taskJunctionOps, commandInput, result),
1168
+ },
1169
+ }
1170
+ },
1171
+ undo: async ({ logEntry, ctx }) => {
1172
+ const payload = extractUndoPayload<AssignmentUndoPayload>(logEntry)
1173
+ if (!payload) return
1174
+ await restoreAssignmentState(taskJunctionOps, payload, ctx)
1175
+ },
1176
+ }
1177
+
1178
+ const unassignTaskTagsCommand: CommandHandler<StaffTimeTaskTagAssignmentInput, UnassignmentResult> = {
1179
+ id: staffTimeTagCommandIds.unassignTask,
1180
+ async prepare(rawInput, ctx) {
1181
+ const parsed = staffTimeTaskTagAssignmentSchema.safeParse(rawInput)
1182
+ if (!parsed.success) return {}
1183
+ const em = ctx.container.resolve('em') as EntityManager
1184
+ const rows = await taskJunctionOps.loadAssignmentsForSnapshot(
1185
+ em,
1186
+ parsed.data.taskId,
1187
+ staffSnapshotScopeFromContext(ctx),
1188
+ )
1189
+ return { before: { rows } }
1190
+ },
1191
+ execute: async (rawInput, ctx) => {
1192
+ const parsed = staffTimeTaskTagAssignmentSchema.parse(rawInput)
1193
+ return runUnassignment(taskJunctionOps, requireTaskTarget, toTaskCommandInput(parsed), ctx)
1194
+ },
1195
+ buildLog: async ({ input, result, snapshots }) => {
1196
+ const parsed = staffTimeTaskTagAssignmentSchema.parse(input)
1197
+ const commandInput = toTaskCommandInput(parsed)
1198
+ const rows = (snapshots.before as { rows?: TagAssignmentSnapshot[] } | undefined)?.rows ?? []
1199
+ const removedRows = rows.filter((row) => result.removedTagIds.includes(row.tagId))
1200
+ const { translate } = await resolveTranslations()
1201
+ return {
1202
+ actionLabel: translate('staff.audit.timesheets.tags.unassign_task', 'Unassign task tags'),
1203
+ resourceKind: taskJunctionOps.resourceKind,
1204
+ resourceId: commandInput.targetId,
1205
+ tenantId: commandInput.tenantId,
1206
+ organizationId: commandInput.organizationId,
1207
+ snapshotBefore: { tagIds: rows.map((row) => row.tagId) },
1208
+ snapshotAfter: { tagIds: result.tagIds },
1209
+ changes: { tagIds: { from: rows.map((row) => row.tagId), to: result.tagIds } },
1210
+ payload: {
1211
+ undo: unassignmentLogPayload(taskJunctionOps, commandInput, result, removedRows),
1212
+ },
1213
+ }
1214
+ },
1215
+ undo: async ({ logEntry, ctx }) => {
1216
+ const payload = extractUndoPayload<AssignmentUndoPayload>(logEntry)
1217
+ if (!payload) return
1218
+ await restoreAssignmentState(taskJunctionOps, payload, ctx)
1219
+ },
1220
+ }
1221
+
1222
+ const assignEntryTagsCommand: CommandHandler<StaffTimeEntryTagAssignmentInput, AssignmentResult> = {
1223
+ id: staffTimeTagCommandIds.assignEntry,
1224
+ async prepare(rawInput, ctx) {
1225
+ const parsed = staffTimeEntryTagAssignmentSchema.safeParse(rawInput)
1226
+ if (!parsed.success) return {}
1227
+ const em = ctx.container.resolve('em') as EntityManager
1228
+ const rows = await entryJunctionOps.loadAssignmentsForSnapshot(
1229
+ em,
1230
+ parsed.data.timeEntryId,
1231
+ staffSnapshotScopeFromContext(ctx),
1232
+ )
1233
+ return { before: { tagIds: rows.map((row) => row.tagId) } }
1234
+ },
1235
+ execute: async (rawInput, ctx) => {
1236
+ const parsed = staffTimeEntryTagAssignmentSchema.parse(rawInput)
1237
+ return runAssignment(entryJunctionOps, requireEntryTarget, toEntryCommandInput(parsed), ctx)
1238
+ },
1239
+ buildLog: async ({ input, result, snapshots }) => {
1240
+ const parsed = staffTimeEntryTagAssignmentSchema.parse(input)
1241
+ const commandInput = toEntryCommandInput(parsed)
1242
+ const before = (snapshots.before as { tagIds?: string[] } | undefined)?.tagIds ?? []
1243
+ const { translate } = await resolveTranslations()
1244
+ return {
1245
+ actionLabel: translate('staff.audit.timesheets.tags.assign_entry', 'Assign time entry tags'),
1246
+ resourceKind: entryJunctionOps.resourceKind,
1247
+ resourceId: commandInput.targetId,
1248
+ tenantId: commandInput.tenantId,
1249
+ organizationId: commandInput.organizationId,
1250
+ snapshotBefore: { tagIds: before },
1251
+ snapshotAfter: { tagIds: result.tagIds },
1252
+ changes: { tagIds: { from: before, to: result.tagIds } },
1253
+ payload: {
1254
+ undo: assignmentLogPayload(entryJunctionOps, commandInput, result),
1255
+ },
1256
+ }
1257
+ },
1258
+ undo: async ({ logEntry, ctx }) => {
1259
+ const payload = extractUndoPayload<AssignmentUndoPayload>(logEntry)
1260
+ if (!payload) return
1261
+ await restoreAssignmentState(entryJunctionOps, payload, ctx)
1262
+ },
1263
+ }
1264
+
1265
+ const unassignEntryTagsCommand: CommandHandler<StaffTimeEntryTagAssignmentInput, UnassignmentResult> = {
1266
+ id: staffTimeTagCommandIds.unassignEntry,
1267
+ async prepare(rawInput, ctx) {
1268
+ const parsed = staffTimeEntryTagAssignmentSchema.safeParse(rawInput)
1269
+ if (!parsed.success) return {}
1270
+ const em = ctx.container.resolve('em') as EntityManager
1271
+ const rows = await entryJunctionOps.loadAssignmentsForSnapshot(
1272
+ em,
1273
+ parsed.data.timeEntryId,
1274
+ staffSnapshotScopeFromContext(ctx),
1275
+ )
1276
+ return { before: { rows } }
1277
+ },
1278
+ execute: async (rawInput, ctx) => {
1279
+ const parsed = staffTimeEntryTagAssignmentSchema.parse(rawInput)
1280
+ return runUnassignment(entryJunctionOps, requireEntryTarget, toEntryCommandInput(parsed), ctx)
1281
+ },
1282
+ buildLog: async ({ input, result, snapshots }) => {
1283
+ const parsed = staffTimeEntryTagAssignmentSchema.parse(input)
1284
+ const commandInput = toEntryCommandInput(parsed)
1285
+ const rows = (snapshots.before as { rows?: TagAssignmentSnapshot[] } | undefined)?.rows ?? []
1286
+ const removedRows = rows.filter((row) => result.removedTagIds.includes(row.tagId))
1287
+ const { translate } = await resolveTranslations()
1288
+ return {
1289
+ actionLabel: translate('staff.audit.timesheets.tags.unassign_entry', 'Unassign time entry tags'),
1290
+ resourceKind: entryJunctionOps.resourceKind,
1291
+ resourceId: commandInput.targetId,
1292
+ tenantId: commandInput.tenantId,
1293
+ organizationId: commandInput.organizationId,
1294
+ snapshotBefore: { tagIds: rows.map((row) => row.tagId) },
1295
+ snapshotAfter: { tagIds: result.tagIds },
1296
+ changes: { tagIds: { from: rows.map((row) => row.tagId), to: result.tagIds } },
1297
+ payload: {
1298
+ undo: unassignmentLogPayload(entryJunctionOps, commandInput, result, removedRows),
1299
+ },
1300
+ }
1301
+ },
1302
+ undo: async ({ logEntry, ctx }) => {
1303
+ const payload = extractUndoPayload<AssignmentUndoPayload>(logEntry)
1304
+ if (!payload) return
1305
+ await restoreAssignmentState(entryJunctionOps, payload, ctx)
1306
+ },
1307
+ }
1308
+
1309
+ registerCommand(createTagCommand)
1310
+ registerCommand(updateTagCommand)
1311
+ registerCommand(deleteTagCommand)
1312
+ registerCommand(assignTaskTagsCommand)
1313
+ registerCommand(unassignTaskTagsCommand)
1314
+ registerCommand(assignEntryTagsCommand)
1315
+ registerCommand(unassignEntryTagsCommand)