@open-mercato/core 0.6.5-develop.4384.1.ce2ec6eaaa → 0.6.5-develop.4393.1.de282b5dfd

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 (533) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/dist/generated/entities/channel_ingest_dead_letter/index.js +25 -0
  3. package/dist/generated/entities/channel_ingest_dead_letter/index.js.map +7 -0
  4. package/dist/generated/entities/channel_thread_mapping/index.js +25 -0
  5. package/dist/generated/entities/channel_thread_mapping/index.js.map +7 -0
  6. package/dist/generated/entities/channel_thread_token/index.js +17 -0
  7. package/dist/generated/entities/channel_thread_token/index.js.map +7 -0
  8. package/dist/generated/entities/communication_channel/index.js +43 -0
  9. package/dist/generated/entities/communication_channel/index.js.map +7 -0
  10. package/dist/generated/entities/customer_interaction/index.js +4 -0
  11. package/dist/generated/entities/customer_interaction/index.js.map +2 -2
  12. package/dist/generated/entities/external_conversation/index.js +25 -0
  13. package/dist/generated/entities/external_conversation/index.js.map +7 -0
  14. package/dist/generated/entities/external_message/index.js +25 -0
  15. package/dist/generated/entities/external_message/index.js.map +7 -0
  16. package/dist/generated/entities/integration_credentials/index.js +3 -1
  17. package/dist/generated/entities/integration_credentials/index.js.map +2 -2
  18. package/dist/generated/entities/message/index.js +2 -0
  19. package/dist/generated/entities/message/index.js.map +2 -2
  20. package/dist/generated/entities/message_channel_link/index.js +33 -0
  21. package/dist/generated/entities/message_channel_link/index.js.map +7 -0
  22. package/dist/generated/entities/message_reaction/index.js +25 -0
  23. package/dist/generated/entities/message_reaction/index.js.map +7 -0
  24. package/dist/generated/entities.ids.generated.js +11 -0
  25. package/dist/generated/entities.ids.generated.js.map +2 -2
  26. package/dist/generated/entity-fields-registry.js +117 -0
  27. package/dist/generated/entity-fields-registry.js.map +2 -2
  28. package/dist/helpers/integration/authFixtures.js +2 -1
  29. package/dist/helpers/integration/authFixtures.js.map +2 -2
  30. package/dist/helpers/integration/communicationChannelsFixtures.js +58 -0
  31. package/dist/helpers/integration/communicationChannelsFixtures.js.map +7 -0
  32. package/dist/modules/communication_channels/acl.js +47 -0
  33. package/dist/modules/communication_channels/acl.js.map +7 -0
  34. package/dist/modules/communication_channels/api/delete/channels/[id]/route.js +133 -0
  35. package/dist/modules/communication_channels/api/delete/channels/[id]/route.js.map +7 -0
  36. package/dist/modules/communication_channels/api/delete/messages/[messageId]/reactions/[reactionId]/route.js +113 -0
  37. package/dist/modules/communication_channels/api/delete/messages/[messageId]/reactions/[reactionId]/route.js.map +7 -0
  38. package/dist/modules/communication_channels/api/get/channels/[id]/health/route.js +138 -0
  39. package/dist/modules/communication_channels/api/get/channels/[id]/health/route.js.map +7 -0
  40. package/dist/modules/communication_channels/api/get/channels/[id]/route.js +93 -0
  41. package/dist/modules/communication_channels/api/get/channels/[id]/route.js.map +7 -0
  42. package/dist/modules/communication_channels/api/get/channels/route.js +96 -0
  43. package/dist/modules/communication_channels/api/get/channels/route.js.map +7 -0
  44. package/dist/modules/communication_channels/api/get/me/channels/route.js +82 -0
  45. package/dist/modules/communication_channels/api/get/me/channels/route.js.map +7 -0
  46. package/dist/modules/communication_channels/api/get/oauth/[provider]/callback/route.js +274 -0
  47. package/dist/modules/communication_channels/api/get/oauth/[provider]/callback/route.js.map +7 -0
  48. package/dist/modules/communication_channels/api/post/channels/[id]/import-history/route.js +168 -0
  49. package/dist/modules/communication_channels/api/post/channels/[id]/import-history/route.js.map +7 -0
  50. package/dist/modules/communication_channels/api/post/channels/[id]/poll-now/route.js +143 -0
  51. package/dist/modules/communication_channels/api/post/channels/[id]/poll-now/route.js.map +7 -0
  52. package/dist/modules/communication_channels/api/post/channels/[id]/push/register/route.js +127 -0
  53. package/dist/modules/communication_channels/api/post/channels/[id]/push/register/route.js.map +7 -0
  54. package/dist/modules/communication_channels/api/post/channels/[id]/set-primary/route.js +99 -0
  55. package/dist/modules/communication_channels/api/post/channels/[id]/set-primary/route.js.map +7 -0
  56. package/dist/modules/communication_channels/api/post/channels/[id]/test-send/route.js +197 -0
  57. package/dist/modules/communication_channels/api/post/channels/[id]/test-send/route.js.map +7 -0
  58. package/dist/modules/communication_channels/api/post/channels/connect/credentials/route.js +124 -0
  59. package/dist/modules/communication_channels/api/post/channels/connect/credentials/route.js.map +7 -0
  60. package/dist/modules/communication_channels/api/post/messages/[messageId]/reactions/route.js +120 -0
  61. package/dist/modules/communication_channels/api/post/messages/[messageId]/reactions/route.js.map +7 -0
  62. package/dist/modules/communication_channels/api/post/oauth/[provider]/initiate/route.js +157 -0
  63. package/dist/modules/communication_channels/api/post/oauth/[provider]/initiate/route.js.map +7 -0
  64. package/dist/modules/communication_channels/api/post/send-as-user/route.js +115 -0
  65. package/dist/modules/communication_channels/api/post/send-as-user/route.js.map +7 -0
  66. package/dist/modules/communication_channels/api/post/test-seed/route.js +217 -0
  67. package/dist/modules/communication_channels/api/post/test-seed/route.js.map +7 -0
  68. package/dist/modules/communication_channels/api/post/webhook/[provider]/route.js +175 -0
  69. package/dist/modules/communication_channels/api/post/webhook/[provider]/route.js.map +7 -0
  70. package/dist/modules/communication_channels/api/post/webhooks/gmail/route.js +123 -0
  71. package/dist/modules/communication_channels/api/post/webhooks/gmail/route.js.map +7 -0
  72. package/dist/modules/communication_channels/api/put/threads/[threadId]/assign/route.js +117 -0
  73. package/dist/modules/communication_channels/api/put/threads/[threadId]/assign/route.js.map +7 -0
  74. package/dist/modules/communication_channels/backend/communication_channels/channels/[id]/page.js +180 -0
  75. package/dist/modules/communication_channels/backend/communication_channels/channels/[id]/page.js.map +7 -0
  76. package/dist/modules/communication_channels/backend/communication_channels/channels/[id]/page.meta.js +36 -0
  77. package/dist/modules/communication_channels/backend/communication_channels/channels/[id]/page.meta.js.map +7 -0
  78. package/dist/modules/communication_channels/backend/communication_channels/channels/page.js +107 -0
  79. package/dist/modules/communication_channels/backend/communication_channels/channels/page.js.map +7 -0
  80. package/dist/modules/communication_channels/backend/communication_channels/channels/page.meta.js +38 -0
  81. package/dist/modules/communication_channels/backend/communication_channels/channels/page.meta.js.map +7 -0
  82. package/dist/modules/communication_channels/backend/profile/communication-channels/page.js +727 -0
  83. package/dist/modules/communication_channels/backend/profile/communication-channels/page.js.map +7 -0
  84. package/dist/modules/communication_channels/backend/profile/communication-channels/page.meta.js +38 -0
  85. package/dist/modules/communication_channels/backend/profile/communication-channels/page.meta.js.map +7 -0
  86. package/dist/modules/communication_channels/commands/connect-credential-channel.js +154 -0
  87. package/dist/modules/communication_channels/commands/connect-credential-channel.js.map +7 -0
  88. package/dist/modules/communication_channels/commands/delete-channel.js +137 -0
  89. package/dist/modules/communication_channels/commands/delete-channel.js.map +7 -0
  90. package/dist/modules/communication_channels/commands/deliver-outbound-message.js +400 -0
  91. package/dist/modules/communication_channels/commands/deliver-outbound-message.js.map +7 -0
  92. package/dist/modules/communication_channels/commands/disconnect-channel.js +163 -0
  93. package/dist/modules/communication_channels/commands/disconnect-channel.js.map +7 -0
  94. package/dist/modules/communication_channels/commands/ingest-inbound-message.js +413 -0
  95. package/dist/modules/communication_channels/commands/ingest-inbound-message.js.map +7 -0
  96. package/dist/modules/communication_channels/commands/interceptors.js +68 -0
  97. package/dist/modules/communication_channels/commands/interceptors.js.map +7 -0
  98. package/dist/modules/communication_channels/commands/process-inbound-reaction.js +198 -0
  99. package/dist/modules/communication_channels/commands/process-inbound-reaction.js.map +7 -0
  100. package/dist/modules/communication_channels/commands/push-register.js +146 -0
  101. package/dist/modules/communication_channels/commands/push-register.js.map +7 -0
  102. package/dist/modules/communication_channels/commands/push-renew.js +23 -0
  103. package/dist/modules/communication_channels/commands/push-renew.js.map +7 -0
  104. package/dist/modules/communication_channels/commands/push-unregister.js +108 -0
  105. package/dist/modules/communication_channels/commands/push-unregister.js.map +7 -0
  106. package/dist/modules/communication_channels/commands/queue-import-history.js +113 -0
  107. package/dist/modules/communication_channels/commands/queue-import-history.js.map +7 -0
  108. package/dist/modules/communication_channels/commands/reassign-conversation.js +193 -0
  109. package/dist/modules/communication_channels/commands/reassign-conversation.js.map +7 -0
  110. package/dist/modules/communication_channels/commands/set-primary-channel.js +114 -0
  111. package/dist/modules/communication_channels/commands/set-primary-channel.js.map +7 -0
  112. package/dist/modules/communication_channels/commands/toggle-outbound-reaction.js +260 -0
  113. package/dist/modules/communication_channels/commands/toggle-outbound-reaction.js.map +7 -0
  114. package/dist/modules/communication_channels/data/enrichers.js +286 -0
  115. package/dist/modules/communication_channels/data/enrichers.js.map +7 -0
  116. package/dist/modules/communication_channels/data/entities.js +447 -0
  117. package/dist/modules/communication_channels/data/entities.js.map +7 -0
  118. package/dist/modules/communication_channels/data/extensions.js +67 -0
  119. package/dist/modules/communication_channels/data/extensions.js.map +7 -0
  120. package/dist/modules/communication_channels/data/validators.js +123 -0
  121. package/dist/modules/communication_channels/data/validators.js.map +7 -0
  122. package/dist/modules/communication_channels/di.js +35 -0
  123. package/dist/modules/communication_channels/di.js.map +7 -0
  124. package/dist/modules/communication_channels/encryption.js +12 -0
  125. package/dist/modules/communication_channels/encryption.js.map +7 -0
  126. package/dist/modules/communication_channels/events.js +124 -0
  127. package/dist/modules/communication_channels/events.js.map +7 -0
  128. package/dist/modules/communication_channels/index.js +20 -0
  129. package/dist/modules/communication_channels/index.js.map +7 -0
  130. package/dist/modules/communication_channels/lib/access-control.js +43 -0
  131. package/dist/modules/communication_channels/lib/access-control.js.map +7 -0
  132. package/dist/modules/communication_channels/lib/adapter-compat.js +36 -0
  133. package/dist/modules/communication_channels/lib/adapter-compat.js.map +7 -0
  134. package/dist/modules/communication_channels/lib/adapter-registry-singleton.js +22 -0
  135. package/dist/modules/communication_channels/lib/adapter-registry-singleton.js.map +7 -0
  136. package/dist/modules/communication_channels/lib/adapter.js +1 -0
  137. package/dist/modules/communication_channels/lib/adapter.js.map +7 -0
  138. package/dist/modules/communication_channels/lib/connect-channel.js +95 -0
  139. package/dist/modules/communication_channels/lib/connect-channel.js.map +7 -0
  140. package/dist/modules/communication_channels/lib/contact-resolver.js +79 -0
  141. package/dist/modules/communication_channels/lib/contact-resolver.js.map +7 -0
  142. package/dist/modules/communication_channels/lib/credential-refresh.js +97 -0
  143. package/dist/modules/communication_channels/lib/credential-refresh.js.map +7 -0
  144. package/dist/modules/communication_channels/lib/dead-letter.js +62 -0
  145. package/dist/modules/communication_channels/lib/dead-letter.js.map +7 -0
  146. package/dist/modules/communication_channels/lib/email-capabilities.js +47 -0
  147. package/dist/modules/communication_channels/lib/email-capabilities.js.map +7 -0
  148. package/dist/modules/communication_channels/lib/email-contact.js +14 -0
  149. package/dist/modules/communication_channels/lib/email-contact.js.map +7 -0
  150. package/dist/modules/communication_channels/lib/email-mime.js +259 -0
  151. package/dist/modules/communication_channels/lib/email-mime.js.map +7 -0
  152. package/dist/modules/communication_channels/lib/error-classification.js +101 -0
  153. package/dist/modules/communication_channels/lib/error-classification.js.map +7 -0
  154. package/dist/modules/communication_channels/lib/gmail-pubsub-jwt.js +185 -0
  155. package/dist/modules/communication_channels/lib/gmail-pubsub-jwt.js.map +7 -0
  156. package/dist/modules/communication_channels/lib/mutation-guards.js +114 -0
  157. package/dist/modules/communication_channels/lib/mutation-guards.js.map +7 -0
  158. package/dist/modules/communication_channels/lib/oauth-client-config.js +32 -0
  159. package/dist/modules/communication_channels/lib/oauth-client-config.js.map +7 -0
  160. package/dist/modules/communication_channels/lib/oauth-state.js +128 -0
  161. package/dist/modules/communication_channels/lib/oauth-state.js.map +7 -0
  162. package/dist/modules/communication_channels/lib/oauth-token.js +45 -0
  163. package/dist/modules/communication_channels/lib/oauth-token.js.map +7 -0
  164. package/dist/modules/communication_channels/lib/pg-errors.js +11 -0
  165. package/dist/modules/communication_channels/lib/pg-errors.js.map +7 -0
  166. package/dist/modules/communication_channels/lib/provider-health.js +24 -0
  167. package/dist/modules/communication_channels/lib/provider-health.js.map +7 -0
  168. package/dist/modules/communication_channels/lib/push-state.js +19 -0
  169. package/dist/modules/communication_channels/lib/push-state.js.map +7 -0
  170. package/dist/modules/communication_channels/lib/queue.js +54 -0
  171. package/dist/modules/communication_channels/lib/queue.js.map +7 -0
  172. package/dist/modules/communication_channels/lib/reaction-processor-types.js +5 -0
  173. package/dist/modules/communication_channels/lib/reaction-processor-types.js.map +7 -0
  174. package/dist/modules/communication_channels/lib/reaction-semantics.js +11 -0
  175. package/dist/modules/communication_channels/lib/reaction-semantics.js.map +7 -0
  176. package/dist/modules/communication_channels/lib/registry.js +67 -0
  177. package/dist/modules/communication_channels/lib/registry.js.map +7 -0
  178. package/dist/modules/communication_channels/lib/route-mutation-guard.js +43 -0
  179. package/dist/modules/communication_channels/lib/route-mutation-guard.js.map +7 -0
  180. package/dist/modules/communication_channels/lib/sanitize-channel-html.js +96 -0
  181. package/dist/modules/communication_channels/lib/sanitize-channel-html.js.map +7 -0
  182. package/dist/modules/communication_channels/lib/send-as-user.js +194 -0
  183. package/dist/modules/communication_channels/lib/send-as-user.js.map +7 -0
  184. package/dist/modules/communication_channels/lib/system-user.js +22 -0
  185. package/dist/modules/communication_channels/lib/system-user.js.map +7 -0
  186. package/dist/modules/communication_channels/lib/test-seed.js +68 -0
  187. package/dist/modules/communication_channels/lib/test-seed.js.map +7 -0
  188. package/dist/modules/communication_channels/lib/thread-matcher.js +263 -0
  189. package/dist/modules/communication_channels/lib/thread-matcher.js.map +7 -0
  190. package/dist/modules/communication_channels/lib/thread-token.js +219 -0
  191. package/dist/modules/communication_channels/lib/thread-token.js.map +7 -0
  192. package/dist/modules/communication_channels/lib/use-connect-channel.js +61 -0
  193. package/dist/modules/communication_channels/lib/use-connect-channel.js.map +7 -0
  194. package/dist/modules/communication_channels/migrations/Migration20260526134719_communication_channels.js +50 -0
  195. package/dist/modules/communication_channels/migrations/Migration20260526134719_communication_channels.js.map +7 -0
  196. package/dist/modules/communication_channels/migrations/Migration20260527195446_communication_channels.js +19 -0
  197. package/dist/modules/communication_channels/migrations/Migration20260527195446_communication_channels.js.map +7 -0
  198. package/dist/modules/communication_channels/migrations/Migration20260529231848_communication_channels.js +13 -0
  199. package/dist/modules/communication_channels/migrations/Migration20260529231848_communication_channels.js.map +7 -0
  200. package/dist/modules/communication_channels/migrations/Migration20260531120000_communication_channels.js +17 -0
  201. package/dist/modules/communication_channels/migrations/Migration20260531120000_communication_channels.js.map +7 -0
  202. package/dist/modules/communication_channels/notifications.client.js +51 -0
  203. package/dist/modules/communication_channels/notifications.client.js.map +7 -0
  204. package/dist/modules/communication_channels/notifications.handlers.js +53 -0
  205. package/dist/modules/communication_channels/notifications.handlers.js.map +7 -0
  206. package/dist/modules/communication_channels/notifications.js +56 -0
  207. package/dist/modules/communication_channels/notifications.js.map +7 -0
  208. package/dist/modules/communication_channels/setup.js +105 -0
  209. package/dist/modules/communication_channels/setup.js.map +7 -0
  210. package/dist/modules/communication_channels/subscribers/channel-requires-reauth-notification.js +71 -0
  211. package/dist/modules/communication_channels/subscribers/channel-requires-reauth-notification.js.map +7 -0
  212. package/dist/modules/communication_channels/subscribers/outbound-bridge.js +103 -0
  213. package/dist/modules/communication_channels/subscribers/outbound-bridge.js.map +7 -0
  214. package/dist/modules/communication_channels/subscribers/user-deleted-cascade.js +51 -0
  215. package/dist/modules/communication_channels/subscribers/user-deleted-cascade.js.map +7 -0
  216. package/dist/modules/communication_channels/widgets/components.js +7 -0
  217. package/dist/modules/communication_channels/widgets/components.js.map +7 -0
  218. package/dist/modules/communication_channels/widgets/injection/channel-badge/widget.client.js +18 -0
  219. package/dist/modules/communication_channels/widgets/injection/channel-badge/widget.client.js.map +7 -0
  220. package/dist/modules/communication_channels/widgets/injection/channel-badge/widget.js +30 -0
  221. package/dist/modules/communication_channels/widgets/injection/channel-badge/widget.js.map +7 -0
  222. package/dist/modules/communication_channels/widgets/injection/channel-info-panel/widget.client.js +185 -0
  223. package/dist/modules/communication_channels/widgets/injection/channel-info-panel/widget.client.js.map +7 -0
  224. package/dist/modules/communication_channels/widgets/injection/channel-info-panel/widget.js +17 -0
  225. package/dist/modules/communication_channels/widgets/injection/channel-info-panel/widget.js.map +7 -0
  226. package/dist/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.client.js +44 -0
  227. package/dist/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.client.js.map +7 -0
  228. package/dist/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.js +17 -0
  229. package/dist/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.js.map +7 -0
  230. package/dist/modules/communication_channels/widgets/injection/profile-channels-menu/widget.js +23 -0
  231. package/dist/modules/communication_channels/widgets/injection/profile-channels-menu/widget.js.map +7 -0
  232. package/dist/modules/communication_channels/widgets/injection/reaction-bar/widget.client.js +141 -0
  233. package/dist/modules/communication_channels/widgets/injection/reaction-bar/widget.client.js.map +7 -0
  234. package/dist/modules/communication_channels/widgets/injection/reaction-bar/widget.js +17 -0
  235. package/dist/modules/communication_channels/widgets/injection/reaction-bar/widget.js.map +7 -0
  236. package/dist/modules/communication_channels/widgets/injection-table.js +38 -0
  237. package/dist/modules/communication_channels/widgets/injection-table.js.map +7 -0
  238. package/dist/modules/communication_channels/widgets/notifications/ChannelRequiresReauthRenderer.js +25 -0
  239. package/dist/modules/communication_channels/widgets/notifications/ChannelRequiresReauthRenderer.js.map +7 -0
  240. package/dist/modules/communication_channels/widgets/notifications/MessageReceivedRenderer.js +19 -0
  241. package/dist/modules/communication_channels/widgets/notifications/MessageReceivedRenderer.js.map +7 -0
  242. package/dist/modules/communication_channels/widgets/notifications/index.js +7 -0
  243. package/dist/modules/communication_channels/widgets/notifications/index.js.map +7 -0
  244. package/dist/modules/communication_channels/workers/channel-import-history.js +185 -0
  245. package/dist/modules/communication_channels/workers/channel-import-history.js.map +7 -0
  246. package/dist/modules/communication_channels/workers/gmail-history-sync.js +154 -0
  247. package/dist/modules/communication_channels/workers/gmail-history-sync.js.map +7 -0
  248. package/dist/modules/communication_channels/workers/gmail-renew-watch.js +95 -0
  249. package/dist/modules/communication_channels/workers/gmail-renew-watch.js.map +7 -0
  250. package/dist/modules/communication_channels/workers/inbound-processor.js +56 -0
  251. package/dist/modules/communication_channels/workers/inbound-processor.js.map +7 -0
  252. package/dist/modules/communication_channels/workers/outbound-delivery.js +85 -0
  253. package/dist/modules/communication_channels/workers/outbound-delivery.js.map +7 -0
  254. package/dist/modules/communication_channels/workers/poll-channel.js +240 -0
  255. package/dist/modules/communication_channels/workers/poll-channel.js.map +7 -0
  256. package/dist/modules/communication_channels/workers/poll-tick.js +132 -0
  257. package/dist/modules/communication_channels/workers/poll-tick.js.map +7 -0
  258. package/dist/modules/communication_channels/workers/reaction-processor.js +192 -0
  259. package/dist/modules/communication_channels/workers/reaction-processor.js.map +7 -0
  260. package/dist/modules/customers/acl.js +18 -0
  261. package/dist/modules/customers/acl.js.map +2 -2
  262. package/dist/modules/customers/api/activities/route.js +9 -0
  263. package/dist/modules/customers/api/activities/route.js.map +2 -2
  264. package/dist/modules/customers/api/companies/[id]/route.js +18 -7
  265. package/dist/modules/customers/api/companies/[id]/route.js.map +2 -2
  266. package/dist/modules/customers/api/interactions/[id]/visibility/route.js +151 -0
  267. package/dist/modules/customers/api/interactions/[id]/visibility/route.js.map +7 -0
  268. package/dist/modules/customers/api/interactions/counts/route.js +6 -0
  269. package/dist/modules/customers/api/interactions/counts/route.js.map +2 -2
  270. package/dist/modules/customers/api/interactions/route.js +26 -7
  271. package/dist/modules/customers/api/interactions/route.js.map +2 -2
  272. package/dist/modules/customers/api/people/[id]/email-threads/route.js +82 -0
  273. package/dist/modules/customers/api/people/[id]/email-threads/route.js.map +7 -0
  274. package/dist/modules/customers/api/people/[id]/emails/route.js +157 -0
  275. package/dist/modules/customers/api/people/[id]/emails/route.js.map +7 -0
  276. package/dist/modules/customers/api/people/[id]/route.js +12 -4
  277. package/dist/modules/customers/api/people/[id]/route.js.map +2 -2
  278. package/dist/modules/customers/backend/customers/people-v2/[id]/page.js +10 -0
  279. package/dist/modules/customers/backend/customers/people-v2/[id]/page.js.map +2 -2
  280. package/dist/modules/customers/commands/deals.js +46 -5
  281. package/dist/modules/customers/commands/deals.js.map +2 -2
  282. package/dist/modules/customers/commands/interactions.js +16 -0
  283. package/dist/modules/customers/commands/interactions.js.map +2 -2
  284. package/dist/modules/customers/components/detail/ActivityCard.js +32 -0
  285. package/dist/modules/customers/components/detail/ActivityCard.js.map +2 -2
  286. package/dist/modules/customers/components/detail/ComposeEmailDialog.js +242 -0
  287. package/dist/modules/customers/components/detail/ComposeEmailDialog.js.map +7 -0
  288. package/dist/modules/customers/components/detail/DealForm.js +2 -1
  289. package/dist/modules/customers/components/detail/DealForm.js.map +2 -2
  290. package/dist/modules/customers/components/detail/DealsSection.js +10 -0
  291. package/dist/modules/customers/components/detail/DealsSection.js.map +2 -2
  292. package/dist/modules/customers/components/detail/EmailCardActions.js +179 -0
  293. package/dist/modules/customers/components/detail/EmailCardActions.js.map +7 -0
  294. package/dist/modules/customers/components/detail/EmailReplyForwardActions.js +52 -0
  295. package/dist/modules/customers/components/detail/EmailReplyForwardActions.js.map +7 -0
  296. package/dist/modules/customers/components/detail/PersonDetailTabs.js +7 -1
  297. package/dist/modules/customers/components/detail/PersonDetailTabs.js.map +2 -2
  298. package/dist/modules/customers/components/detail/PersonEmailThreadsTab.js +366 -0
  299. package/dist/modules/customers/components/detail/PersonEmailThreadsTab.js.map +7 -0
  300. package/dist/modules/customers/data/enrichers.js +133 -2
  301. package/dist/modules/customers/data/enrichers.js.map +2 -2
  302. package/dist/modules/customers/data/entities.js +18 -0
  303. package/dist/modules/customers/data/entities.js.map +2 -2
  304. package/dist/modules/customers/data/extensions.js +16 -0
  305. package/dist/modules/customers/data/extensions.js.map +7 -0
  306. package/dist/modules/customers/encryption.js +11 -0
  307. package/dist/modules/customers/encryption.js.map +2 -2
  308. package/dist/modules/customers/events.js +4 -1
  309. package/dist/modules/customers/events.js.map +2 -2
  310. package/dist/modules/customers/lib/findPeopleByAddresses.js +64 -0
  311. package/dist/modules/customers/lib/findPeopleByAddresses.js.map +7 -0
  312. package/dist/modules/customers/lib/kysely.js.map +2 -2
  313. package/dist/modules/customers/lib/link-channel-message-handler.js +303 -0
  314. package/dist/modules/customers/lib/link-channel-message-handler.js.map +7 -0
  315. package/dist/modules/customers/lib/personEmailThreads.js +205 -0
  316. package/dist/modules/customers/lib/personEmailThreads.js.map +7 -0
  317. package/dist/modules/customers/lib/visibilityFilter.js +51 -0
  318. package/dist/modules/customers/lib/visibilityFilter.js.map +7 -0
  319. package/dist/modules/customers/migrations/Migration20260527012240_customers.js +20 -0
  320. package/dist/modules/customers/migrations/Migration20260527012240_customers.js.map +7 -0
  321. package/dist/modules/customers/setup.js +2 -1
  322. package/dist/modules/customers/setup.js.map +2 -2
  323. package/dist/modules/customers/subscribers/link-channel-message-received.js +12 -0
  324. package/dist/modules/customers/subscribers/link-channel-message-received.js.map +7 -0
  325. package/dist/modules/customers/subscribers/link-channel-message-sent.js +12 -0
  326. package/dist/modules/customers/subscribers/link-channel-message-sent.js.map +7 -0
  327. package/dist/modules/integrations/data/entities.js +8 -1
  328. package/dist/modules/integrations/data/entities.js.map +2 -2
  329. package/dist/modules/integrations/lib/credentials-service.js +29 -14
  330. package/dist/modules/integrations/lib/credentials-service.js.map +2 -2
  331. package/dist/modules/integrations/migrations/Migration20260526154136_integrations.js +15 -0
  332. package/dist/modules/integrations/migrations/Migration20260526154136_integrations.js.map +7 -0
  333. package/dist/modules/messages/commands/messages.js +70 -8
  334. package/dist/modules/messages/commands/messages.js.map +2 -2
  335. package/dist/modules/messages/components/ComposeMessagePageClient.js +24 -13
  336. package/dist/modules/messages/components/ComposeMessagePageClient.js.map +2 -2
  337. package/dist/modules/messages/components/MessageDetailPageClient.js +39 -2
  338. package/dist/modules/messages/components/MessageDetailPageClient.js.map +2 -2
  339. package/dist/modules/messages/components/MessagesInboxPageClient.js +1 -0
  340. package/dist/modules/messages/components/MessagesInboxPageClient.js.map +2 -2
  341. package/dist/modules/messages/data/entities.js +8 -1
  342. package/dist/modules/messages/data/entities.js.map +2 -2
  343. package/dist/modules/messages/migrations/Migration20260531130000.js +15 -0
  344. package/dist/modules/messages/migrations/Migration20260531130000.js.map +7 -0
  345. package/dist/modules/messages/widgets/injection-table.js +7 -0
  346. package/dist/modules/messages/widgets/injection-table.js.map +7 -0
  347. package/generated/entities/channel_ingest_dead_letter/index.ts +11 -0
  348. package/generated/entities/channel_thread_mapping/index.ts +11 -0
  349. package/generated/entities/channel_thread_token/index.ts +7 -0
  350. package/generated/entities/communication_channel/index.ts +20 -0
  351. package/generated/entities/customer_interaction/index.ts +2 -0
  352. package/generated/entities/external_conversation/index.ts +11 -0
  353. package/generated/entities/external_message/index.ts +11 -0
  354. package/generated/entities/integration_credentials/index.ts +1 -0
  355. package/generated/entities/message/index.ts +1 -0
  356. package/generated/entities/message_channel_link/index.ts +15 -0
  357. package/generated/entities/message_reaction/index.ts +11 -0
  358. package/generated/entities.ids.generated.ts +11 -0
  359. package/generated/entity-fields-registry.ts +117 -0
  360. package/package.json +9 -7
  361. package/src/helpers/integration/authFixtures.ts +4 -1
  362. package/src/helpers/integration/communicationChannelsFixtures.ts +124 -0
  363. package/src/modules/communication_channels/acl.ts +43 -0
  364. package/src/modules/communication_channels/api/delete/channels/[id]/route.ts +163 -0
  365. package/src/modules/communication_channels/api/delete/messages/[messageId]/reactions/[reactionId]/route.ts +143 -0
  366. package/src/modules/communication_channels/api/get/channels/[id]/health/route.ts +173 -0
  367. package/src/modules/communication_channels/api/get/channels/[id]/route.ts +111 -0
  368. package/src/modules/communication_channels/api/get/channels/route.ts +109 -0
  369. package/src/modules/communication_channels/api/get/me/channels/route.ts +100 -0
  370. package/src/modules/communication_channels/api/get/oauth/[provider]/callback/route.ts +355 -0
  371. package/src/modules/communication_channels/api/post/channels/[id]/import-history/route.ts +206 -0
  372. package/src/modules/communication_channels/api/post/channels/[id]/poll-now/route.ts +174 -0
  373. package/src/modules/communication_channels/api/post/channels/[id]/push/register/route.ts +158 -0
  374. package/src/modules/communication_channels/api/post/channels/[id]/set-primary/route.ts +114 -0
  375. package/src/modules/communication_channels/api/post/channels/[id]/test-send/route.ts +241 -0
  376. package/src/modules/communication_channels/api/post/channels/connect/credentials/route.ts +134 -0
  377. package/src/modules/communication_channels/api/post/messages/[messageId]/reactions/route.ts +143 -0
  378. package/src/modules/communication_channels/api/post/oauth/[provider]/initiate/route.ts +192 -0
  379. package/src/modules/communication_channels/api/post/send-as-user/route.ts +125 -0
  380. package/src/modules/communication_channels/api/post/test-seed/route.ts +267 -0
  381. package/src/modules/communication_channels/api/post/webhook/[provider]/route.ts +227 -0
  382. package/src/modules/communication_channels/api/post/webhooks/gmail/route.ts +161 -0
  383. package/src/modules/communication_channels/api/put/threads/[threadId]/assign/route.ts +132 -0
  384. package/src/modules/communication_channels/backend/communication_channels/channels/[id]/page.meta.ts +34 -0
  385. package/src/modules/communication_channels/backend/communication_channels/channels/[id]/page.tsx +250 -0
  386. package/src/modules/communication_channels/backend/communication_channels/channels/page.meta.ts +36 -0
  387. package/src/modules/communication_channels/backend/communication_channels/channels/page.tsx +137 -0
  388. package/src/modules/communication_channels/backend/profile/communication-channels/page.meta.ts +36 -0
  389. package/src/modules/communication_channels/backend/profile/communication-channels/page.tsx +907 -0
  390. package/src/modules/communication_channels/commands/connect-credential-channel.ts +243 -0
  391. package/src/modules/communication_channels/commands/delete-channel.ts +193 -0
  392. package/src/modules/communication_channels/commands/deliver-outbound-message.ts +579 -0
  393. package/src/modules/communication_channels/commands/disconnect-channel.ts +241 -0
  394. package/src/modules/communication_channels/commands/ingest-inbound-message.ts +602 -0
  395. package/src/modules/communication_channels/commands/interceptors.ts +104 -0
  396. package/src/modules/communication_channels/commands/process-inbound-reaction.ts +265 -0
  397. package/src/modules/communication_channels/commands/push-register.ts +203 -0
  398. package/src/modules/communication_channels/commands/push-renew.ts +49 -0
  399. package/src/modules/communication_channels/commands/push-unregister.ts +168 -0
  400. package/src/modules/communication_channels/commands/queue-import-history.ts +180 -0
  401. package/src/modules/communication_channels/commands/reassign-conversation.ts +273 -0
  402. package/src/modules/communication_channels/commands/set-primary-channel.ts +154 -0
  403. package/src/modules/communication_channels/commands/toggle-outbound-reaction.ts +347 -0
  404. package/src/modules/communication_channels/data/enrichers.ts +413 -0
  405. package/src/modules/communication_channels/data/entities.ts +546 -0
  406. package/src/modules/communication_channels/data/extensions.ts +76 -0
  407. package/src/modules/communication_channels/data/validators.ts +138 -0
  408. package/src/modules/communication_channels/di.ts +40 -0
  409. package/src/modules/communication_channels/encryption.ts +44 -0
  410. package/src/modules/communication_channels/events.ts +122 -0
  411. package/src/modules/communication_channels/i18n/de.json +138 -0
  412. package/src/modules/communication_channels/i18n/en.json +138 -0
  413. package/src/modules/communication_channels/i18n/es.json +138 -0
  414. package/src/modules/communication_channels/i18n/pl.json +138 -0
  415. package/src/modules/communication_channels/index.ts +19 -0
  416. package/src/modules/communication_channels/lib/access-control.ts +110 -0
  417. package/src/modules/communication_channels/lib/adapter-compat.ts +57 -0
  418. package/src/modules/communication_channels/lib/adapter-registry-singleton.ts +35 -0
  419. package/src/modules/communication_channels/lib/adapter.ts +605 -0
  420. package/src/modules/communication_channels/lib/connect-channel.ts +163 -0
  421. package/src/modules/communication_channels/lib/contact-resolver.ts +162 -0
  422. package/src/modules/communication_channels/lib/credential-refresh.ts +197 -0
  423. package/src/modules/communication_channels/lib/dead-letter.ts +87 -0
  424. package/src/modules/communication_channels/lib/email-capabilities.ts +60 -0
  425. package/src/modules/communication_channels/lib/email-contact.ts +17 -0
  426. package/src/modules/communication_channels/lib/email-mime.ts +425 -0
  427. package/src/modules/communication_channels/lib/error-classification.ts +144 -0
  428. package/src/modules/communication_channels/lib/gmail-pubsub-jwt.ts +278 -0
  429. package/src/modules/communication_channels/lib/mutation-guards.ts +215 -0
  430. package/src/modules/communication_channels/lib/oauth-client-config.ts +79 -0
  431. package/src/modules/communication_channels/lib/oauth-state.ts +228 -0
  432. package/src/modules/communication_channels/lib/oauth-token.ts +81 -0
  433. package/src/modules/communication_channels/lib/pg-errors.ts +12 -0
  434. package/src/modules/communication_channels/lib/provider-health.ts +47 -0
  435. package/src/modules/communication_channels/lib/push-state.ts +38 -0
  436. package/src/modules/communication_channels/lib/queue.ts +66 -0
  437. package/src/modules/communication_channels/lib/reaction-processor-types.ts +51 -0
  438. package/src/modules/communication_channels/lib/reaction-semantics.ts +48 -0
  439. package/src/modules/communication_channels/lib/registry.ts +99 -0
  440. package/src/modules/communication_channels/lib/route-mutation-guard.ts +68 -0
  441. package/src/modules/communication_channels/lib/sanitize-channel-html.ts +129 -0
  442. package/src/modules/communication_channels/lib/send-as-user.ts +284 -0
  443. package/src/modules/communication_channels/lib/system-user.ts +74 -0
  444. package/src/modules/communication_channels/lib/test-seed.ts +140 -0
  445. package/src/modules/communication_channels/lib/thread-matcher.ts +430 -0
  446. package/src/modules/communication_channels/lib/thread-token.ts +355 -0
  447. package/src/modules/communication_channels/lib/use-connect-channel.ts +73 -0
  448. package/src/modules/communication_channels/migrations/.snapshot-open-mercato.json +2142 -0
  449. package/src/modules/communication_channels/migrations/Migration20260526134719_communication_channels.ts +55 -0
  450. package/src/modules/communication_channels/migrations/Migration20260527195446_communication_channels.ts +20 -0
  451. package/src/modules/communication_channels/migrations/Migration20260529231848_communication_channels.ts +13 -0
  452. package/src/modules/communication_channels/migrations/Migration20260531120000_communication_channels.ts +24 -0
  453. package/src/modules/communication_channels/notifications.client.ts +50 -0
  454. package/src/modules/communication_channels/notifications.handlers.ts +86 -0
  455. package/src/modules/communication_channels/notifications.ts +52 -0
  456. package/src/modules/communication_channels/setup.ts +158 -0
  457. package/src/modules/communication_channels/subscribers/channel-requires-reauth-notification.ts +118 -0
  458. package/src/modules/communication_channels/subscribers/outbound-bridge.ts +175 -0
  459. package/src/modules/communication_channels/subscribers/user-deleted-cascade.ts +100 -0
  460. package/src/modules/communication_channels/widgets/components.ts +36 -0
  461. package/src/modules/communication_channels/widgets/injection/channel-badge/widget.client.tsx +38 -0
  462. package/src/modules/communication_channels/widgets/injection/channel-badge/widget.ts +51 -0
  463. package/src/modules/communication_channels/widgets/injection/channel-info-panel/widget.client.tsx +278 -0
  464. package/src/modules/communication_channels/widgets/injection/channel-info-panel/widget.ts +24 -0
  465. package/src/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.client.tsx +63 -0
  466. package/src/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.ts +29 -0
  467. package/src/modules/communication_channels/widgets/injection/profile-channels-menu/widget.ts +34 -0
  468. package/src/modules/communication_channels/widgets/injection/reaction-bar/widget.client.tsx +177 -0
  469. package/src/modules/communication_channels/widgets/injection/reaction-bar/widget.ts +26 -0
  470. package/src/modules/communication_channels/widgets/injection-table.ts +47 -0
  471. package/src/modules/communication_channels/widgets/notifications/ChannelRequiresReauthRenderer.tsx +48 -0
  472. package/src/modules/communication_channels/widgets/notifications/MessageReceivedRenderer.tsx +45 -0
  473. package/src/modules/communication_channels/widgets/notifications/index.ts +2 -0
  474. package/src/modules/communication_channels/workers/channel-import-history.ts +252 -0
  475. package/src/modules/communication_channels/workers/gmail-history-sync.ts +223 -0
  476. package/src/modules/communication_channels/workers/gmail-renew-watch.ts +141 -0
  477. package/src/modules/communication_channels/workers/inbound-processor.ts +114 -0
  478. package/src/modules/communication_channels/workers/outbound-delivery.ts +155 -0
  479. package/src/modules/communication_channels/workers/poll-channel.ts +391 -0
  480. package/src/modules/communication_channels/workers/poll-tick.ts +210 -0
  481. package/src/modules/communication_channels/workers/reaction-processor.ts +264 -0
  482. package/src/modules/customers/acl.ts +18 -0
  483. package/src/modules/customers/api/activities/route.ts +13 -0
  484. package/src/modules/customers/api/companies/[id]/route.ts +21 -1
  485. package/src/modules/customers/api/interactions/[id]/visibility/route.ts +179 -0
  486. package/src/modules/customers/api/interactions/counts/route.ts +10 -0
  487. package/src/modules/customers/api/interactions/route.ts +51 -5
  488. package/src/modules/customers/api/people/[id]/email-threads/route.ts +92 -0
  489. package/src/modules/customers/api/people/[id]/emails/route.ts +184 -0
  490. package/src/modules/customers/api/people/[id]/route.ts +17 -2
  491. package/src/modules/customers/backend/customers/people-v2/[id]/page.tsx +11 -1
  492. package/src/modules/customers/commands/deals.ts +65 -6
  493. package/src/modules/customers/commands/interactions.ts +30 -0
  494. package/src/modules/customers/components/detail/ActivityCard.tsx +48 -0
  495. package/src/modules/customers/components/detail/ComposeEmailDialog.tsx +329 -0
  496. package/src/modules/customers/components/detail/DealForm.tsx +2 -1
  497. package/src/modules/customers/components/detail/DealsSection.tsx +26 -0
  498. package/src/modules/customers/components/detail/EmailCardActions.tsx +258 -0
  499. package/src/modules/customers/components/detail/EmailReplyForwardActions.tsx +53 -0
  500. package/src/modules/customers/components/detail/PersonDetailTabs.tsx +8 -1
  501. package/src/modules/customers/components/detail/PersonEmailThreadsTab.tsx +448 -0
  502. package/src/modules/customers/data/enrichers.ts +252 -1
  503. package/src/modules/customers/data/entities.ts +46 -1
  504. package/src/modules/customers/data/extensions.ts +26 -0
  505. package/src/modules/customers/encryption.ts +11 -0
  506. package/src/modules/customers/events.ts +4 -0
  507. package/src/modules/customers/i18n/de.json +41 -0
  508. package/src/modules/customers/i18n/en.json +41 -0
  509. package/src/modules/customers/i18n/es.json +41 -0
  510. package/src/modules/customers/i18n/pl.json +41 -0
  511. package/src/modules/customers/lib/findPeopleByAddresses.ts +107 -0
  512. package/src/modules/customers/lib/kysely.ts +16 -0
  513. package/src/modules/customers/lib/link-channel-message-handler.ts +571 -0
  514. package/src/modules/customers/lib/personEmailThreads.ts +325 -0
  515. package/src/modules/customers/lib/visibilityFilter.ts +152 -0
  516. package/src/modules/customers/migrations/.snapshot-open-mercato.json +61 -0
  517. package/src/modules/customers/migrations/Migration20260527012240_customers.ts +23 -0
  518. package/src/modules/customers/setup.ts +1 -0
  519. package/src/modules/customers/subscribers/link-channel-message-received.ts +21 -0
  520. package/src/modules/customers/subscribers/link-channel-message-sent.ts +21 -0
  521. package/src/modules/integrations/AGENTS.md +9 -0
  522. package/src/modules/integrations/data/entities.ts +21 -1
  523. package/src/modules/integrations/lib/credentials-service.ts +49 -13
  524. package/src/modules/integrations/migrations/.snapshot-open-mercato.json +26 -1
  525. package/src/modules/integrations/migrations/Migration20260526154136_integrations.ts +15 -0
  526. package/src/modules/messages/commands/messages.ts +101 -8
  527. package/src/modules/messages/components/ComposeMessagePageClient.tsx +17 -0
  528. package/src/modules/messages/components/MessageDetailPageClient.tsx +43 -0
  529. package/src/modules/messages/components/MessagesInboxPageClient.tsx +4 -0
  530. package/src/modules/messages/data/entities.ts +11 -0
  531. package/src/modules/messages/migrations/.snapshot-open-mercato.json +18 -0
  532. package/src/modules/messages/migrations/Migration20260531130000.ts +15 -0
  533. package/src/modules/messages/widgets/injection-table.ts +29 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/modules/customers/commands/interactions.ts"],
4
- "sourcesContent": ["import { z } from 'zod'\nimport { registerCommand } from '@open-mercato/shared/lib/commands'\nimport type { CommandHandler } from '@open-mercato/shared/lib/commands'\nimport {\n parseWithCustomFields,\n setCustomFieldsIfAny,\n emitCrudSideEffects,\n emitCrudUndoSideEffects,\n requireId,\n normalizeAuthorUserId,\n} from '@open-mercato/shared/lib/commands/helpers'\nimport { DefaultDataEngine, type DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { CommandRuntimeContext } from '@open-mercato/shared/lib/commands'\nimport { CustomerInteraction } from '../data/entities'\nimport {\n interactionCreateSchema,\n interactionUpdateSchema,\n interactionCompleteSchema,\n interactionCancelSchema,\n type InteractionCreateInput,\n type InteractionUpdateInput,\n type InteractionCompleteInput,\n type InteractionCancelInput,\n} from '../data/validators'\nimport {\n ensureOrganizationScope,\n ensureTenantScope,\n requireTimelineParentEntity,\n extractUndoPayload,\n emitQueryIndexUpsertEvents,\n requireDealInScope,\n resolveParentResourceKind,\n} from './shared'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport {\n loadCustomFieldSnapshot,\n buildCustomFieldResetMap,\n} from '@open-mercato/shared/lib/commands/customFieldSnapshots'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport type { CrudIndexerConfig, CrudEventsConfig } from '@open-mercato/shared/lib/crud/types'\nimport { recomputeNextInteraction } from '../lib/interactionProjection'\n\nconst INTERACTION_ENTITY_ID = 'customers:customer_interaction'\nconst interactionCrudIndexer: CrudIndexerConfig<CustomerInteraction> = {\n entityType: 'customers:customer_interaction' as const,\n}\n\nconst interactionCrudEvents: CrudEventsConfig = {\n module: 'customers',\n entity: 'interaction',\n persistent: true,\n buildPayload: (ctx) => ({\n id: ctx.identifiers.id,\n organizationId: ctx.identifiers.organizationId,\n tenantId: ctx.identifiers.tenantId,\n entityId:\n ctx.entity && typeof ctx.entity === 'object' && 'entity' in (ctx.entity as Record<string, unknown>)\n ? (() => {\n const entityRef = (ctx.entity as CustomerInteraction).entity\n return typeof entityRef === 'string' ? entityRef : entityRef?.id ?? null\n })()\n : null,\n interactionType:\n ctx.entity && typeof ctx.entity === 'object' && 'interactionType' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerInteraction).interactionType\n : null,\n status:\n ctx.entity && typeof ctx.entity === 'object' && 'status' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerInteraction).status\n : null,\n source:\n ctx.entity && typeof ctx.entity === 'object' && 'source' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerInteraction).source ?? null\n : null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n }),\n}\n\ntype InteractionSnapshot = {\n interaction: {\n id: string\n organizationId: string\n tenantId: string\n entityId: string\n entityKind: string | null\n dealId: string | null\n interactionType: string\n title: string | null\n body: string | null\n status: string\n scheduledAt: Date | null\n occurredAt: Date | null\n priority: number | null\n authorUserId: string | null\n ownerUserId: string | null\n appearanceIcon: string | null\n appearanceColor: string | null\n source: string | null\n durationMinutes: number | null\n location: string | null\n allDay: boolean | null\n recurrenceRule: string | null\n recurrenceEnd: Date | null\n participants: Array<{ userId: string; name?: string; email?: string; status?: string }> | null\n reminderMinutes: number | null\n visibility: string | null\n linkedEntities: Array<{ id: string; type: string; label: string }> | null\n guestPermissions: { canInviteOthers?: boolean; canModify?: boolean; canSeeList?: boolean } | null\n }\n custom?: Record<string, unknown>\n}\n\ntype InteractionUndoPayload = {\n before?: InteractionSnapshot | null\n after?: InteractionSnapshot | null\n}\n\nasync function loadInteractionSnapshot(em: EntityManager, id: string): Promise<InteractionSnapshot | null> {\n const interaction = await findOneWithDecryption(em, CustomerInteraction, { id }, { populate: ['entity'] })\n if (!interaction) return null\n const custom = await loadCustomFieldSnapshot(em, {\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n tenantId: interaction.tenantId,\n organizationId: interaction.organizationId,\n })\n const entityRef = interaction.entity\n const entityKind = (typeof entityRef === 'object' && entityRef !== null && 'kind' in entityRef)\n ? (entityRef as { kind: string }).kind\n : null\n return {\n interaction: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n entityId: typeof entityRef === 'string' ? entityRef : entityRef.id,\n entityKind,\n dealId: interaction.dealId ?? null,\n interactionType: interaction.interactionType,\n title: interaction.title ?? null,\n body: interaction.body ?? null,\n status: interaction.status,\n scheduledAt: interaction.scheduledAt ?? null,\n occurredAt: interaction.occurredAt ?? null,\n priority: interaction.priority ?? null,\n authorUserId: interaction.authorUserId ?? null,\n ownerUserId: interaction.ownerUserId ?? null,\n appearanceIcon: interaction.appearanceIcon ?? null,\n appearanceColor: interaction.appearanceColor ?? null,\n source: interaction.source ?? null,\n durationMinutes: interaction.durationMinutes ?? null,\n location: interaction.location ?? null,\n allDay: interaction.allDay ?? null,\n recurrenceRule: interaction.recurrenceRule ?? null,\n recurrenceEnd: interaction.recurrenceEnd ?? null,\n participants: interaction.participants ?? null,\n reminderMinutes: interaction.reminderMinutes ?? null,\n visibility: interaction.visibility ?? null,\n linkedEntities: interaction.linkedEntities ?? null,\n guestPermissions: interaction.guestPermissions ?? null,\n },\n custom,\n }\n}\n\nasync function setInteractionCustomFields(\n dataEngine: DataEngine,\n interactionId: string,\n organizationId: string,\n tenantId: string,\n values: Record<string, unknown>\n) {\n if (!values || !Object.keys(values).length) return\n await setCustomFieldsIfAny({\n dataEngine,\n entityId: INTERACTION_ENTITY_ID,\n recordId: interactionId,\n organizationId,\n tenantId,\n values,\n notify: false,\n })\n}\n\nasync function emitLifecycleEvent(\n ctx: CommandRuntimeContext,\n eventId: string,\n payload: Record<string, unknown>\n): Promise<void> {\n let bus: { emitEvent(event: string, payload: unknown, options?: unknown): Promise<void> } | null = null\n try {\n bus = ctx.container.resolve('eventBus')\n } catch (err) {\n console.warn('[customers.commands.interactions] eventBus resolve failed; skipping emit', eventId, err)\n bus = null\n }\n if (!bus) return\n await bus\n .emitEvent(eventId, payload, { persistent: true })\n .catch((err) => {\n console.warn('[customers.commands.interactions] emit failed', eventId, err)\n return undefined\n })\n}\n\nasync function emitInteractionRevertedEvent(\n ctx: CommandRuntimeContext,\n interaction: InteractionSnapshot['interaction'],\n): Promise<void> {\n await emitLifecycleEvent(ctx, 'customers.interaction.reverted', {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n entityId: interaction.entityId,\n interactionType: interaction.interactionType,\n source: interaction.source ?? null,\n status: interaction.status,\n occurredAt: interaction.occurredAt?.toISOString() ?? null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n })\n}\n\ntype InteractionIdentifiers = {\n id: string\n organizationId: string\n tenantId: string\n}\n\ntype InteractionProjectionMutation = {\n entityId: string\n nextInteractionId: string | null\n}\n\nfunction createTransactionalDataEngine(ctx: CommandRuntimeContext, em: EntityManager): DataEngine {\n const emWithConnection = em as EntityManager & { getConnection?: () => unknown }\n if (typeof emWithConnection.getConnection !== 'function') {\n return ctx.container.resolve('dataEngine') as DataEngine\n }\n return new DefaultDataEngine(em, ctx.container)\n}\n\nasync function runInTransaction<TResult>(\n em: EntityManager,\n operation: (trx: EntityManager) => Promise<TResult>,\n): Promise<TResult> {\n // Mirrors the SPEC-018 fix applied to withAtomicFlush: use explicit begin/commit/rollback\n // so the outer EntityManager stays bound to the transaction, and closures over `em` inside\n // `operation` participate in the same transaction. This avoids the em.transactional(cb)\n // hazard where the callback receives a child EM whose flushes can silently race against\n // subsequent queries on the original `em`.\n const supportsBegin =\n typeof (em as unknown as { begin?: () => Promise<void> }).begin === 'function' &&\n typeof (em as unknown as { commit?: () => Promise<void> }).commit === 'function' &&\n typeof (em as unknown as { rollback?: () => Promise<void> }).rollback === 'function'\n if (!supportsBegin) {\n return operation(em)\n }\n await em.begin()\n try {\n const result = await operation(em)\n await em.commit()\n return result\n } catch (err) {\n try {\n await em.rollback()\n } catch {\n // rollback failure should not mask the original error; intentionally swallowed\n }\n throw err\n }\n}\n\nasync function emitNextInteractionUpdatedEvent(\n ctx: CommandRuntimeContext,\n projection: InteractionProjectionMutation,\n identifiers: InteractionIdentifiers,\n): Promise<void> {\n await emitQueryIndexUpsertEvents(ctx, [{\n entityType: 'customers:customer_entity',\n recordId: projection.entityId,\n organizationId: identifiers.organizationId,\n tenantId: identifiers.tenantId,\n }])\n await emitLifecycleEvent(ctx, 'customers.next_interaction.updated', {\n id: projection.entityId,\n entityId: projection.entityId,\n nextInteractionId: projection.nextInteractionId,\n organizationId: identifiers.organizationId,\n tenantId: identifiers.tenantId,\n })\n}\n\n// \u2500\u2500\u2500 Create \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst createInteractionCommand: CommandHandler<InteractionCreateInput, { interactionId: string; entityId: string }> = {\n id: 'customers.interactions.create',\n async execute(rawInput, ctx) {\n const { parsed, custom } = parseWithCustomFields(interactionCreateSchema, rawInput)\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const normalizedAuthor = normalizeAuthorUserId(parsed.authorUserId ?? null, ctx.auth)\n const { interaction, entityId, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const entity = await requireTimelineParentEntity(trx, parsed.entityId)\n ensureTenantScope(ctx, entity.tenantId)\n ensureOrganizationScope(ctx, entity.organizationId)\n\n if (parsed.dealId) {\n await requireDealInScope(trx, parsed.dealId, entity.tenantId, entity.organizationId)\n }\n\n const interaction = trx.create(CustomerInteraction, {\n ...(parsed.id ? { id: parsed.id } : {}),\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n entity,\n interactionType: parsed.interactionType,\n title: parsed.title ?? null,\n body: parsed.body ?? null,\n status: parsed.status ?? 'planned',\n scheduledAt: parsed.scheduledAt ?? null,\n occurredAt: parsed.occurredAt ?? null,\n priority: parsed.priority ?? null,\n authorUserId: normalizedAuthor,\n ownerUserId: parsed.ownerUserId ?? null,\n dealId: parsed.dealId ?? null,\n source: parsed.source ?? null,\n appearanceIcon: parsed.appearanceIcon ?? null,\n appearanceColor: parsed.appearanceColor ?? null,\n durationMinutes: parsed.durationMinutes ?? null,\n location: parsed.location ?? null,\n allDay: parsed.allDay ?? null,\n recurrenceRule: parsed.recurrenceRule ?? null,\n recurrenceEnd: parsed.recurrenceEnd ?? null,\n participants: parsed.participants ?? null,\n reminderMinutes: parsed.reminderMinutes ?? null,\n visibility: parsed.visibility ?? null,\n linkedEntities: parsed.linkedEntities ?? null,\n guestPermissions: parsed.guestPermissions ?? null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n trx.persist(interaction)\n await trx.flush()\n\n await setInteractionCustomFields(\n createTransactionalDataEngine(ctx, trx),\n interaction.id,\n entity.organizationId,\n entity.tenantId,\n custom,\n )\n\n const projection = await recomputeNextInteraction(trx, entity.id)\n\n return {\n interaction,\n entityId: entity.id,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'created',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n\n return { interactionId: interaction.id, entityId }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const snapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.create', 'Create interaction'),\n resourceKind: 'customers.interaction',\n resourceId: result.interactionId,\n parentResourceKind: resolveParentResourceKind(snapshot?.interaction?.entityKind),\n parentResourceId: snapshot?.interaction?.entityId ?? null,\n tenantId: snapshot?.interaction.tenantId ?? null,\n organizationId: snapshot?.interaction.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const interactionId = logEntry?.resourceId\n if (!interactionId) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const result = await runInTransaction(em, async (trx) => {\n const record = await findOneWithDecryption(trx, CustomerInteraction, { id: interactionId })\n if (!record) return null\n const entityId = typeof record.entity === 'string' ? record.entity : record.entity.id\n trx.remove(record)\n await trx.flush()\n const projection = await recomputeNextInteraction(trx, entityId)\n return {\n entityId,\n nextInteractionId: projection.nextInteractionId,\n identifiers: {\n id: record.id,\n organizationId: record.organizationId,\n tenantId: record.tenantId,\n },\n }\n })\n if (!result) return\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: result.entityId,\n nextInteractionId: result.nextInteractionId,\n }, result.identifiers)\n },\n}\n\n// \u2500\u2500\u2500 Update \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst updateInteractionCommand: CommandHandler<InteractionUpdateInput, { interactionId: string }> = {\n id: 'customers.interactions.update',\n async prepare(rawInput, ctx) {\n const { parsed } = parseWithCustomFields(interactionUpdateSchema, rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const { parsed, custom } = parseWithCustomFields(interactionUpdateSchema, rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: parsed.id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n if (parsed.dealId !== undefined) {\n if (parsed.dealId) {\n await requireDealInScope(trx, parsed.dealId, interaction.tenantId, interaction.organizationId)\n }\n interaction.dealId = parsed.dealId ?? null\n }\n if (parsed.interactionType !== undefined) interaction.interactionType = parsed.interactionType\n if (parsed.title !== undefined) interaction.title = parsed.title ?? null\n if (parsed.body !== undefined) interaction.body = parsed.body ?? null\n if (parsed.status !== undefined) interaction.status = parsed.status\n if (parsed.scheduledAt !== undefined) interaction.scheduledAt = parsed.scheduledAt ?? null\n if (parsed.occurredAt !== undefined) interaction.occurredAt = parsed.occurredAt ?? null\n if (parsed.priority !== undefined) interaction.priority = parsed.priority ?? null\n if (parsed.authorUserId !== undefined) interaction.authorUserId = parsed.authorUserId ?? null\n if (parsed.ownerUserId !== undefined) interaction.ownerUserId = parsed.ownerUserId ?? null\n if (parsed.appearanceIcon !== undefined) interaction.appearanceIcon = parsed.appearanceIcon ?? null\n if (parsed.appearanceColor !== undefined) interaction.appearanceColor = parsed.appearanceColor ?? null\n if (parsed.pinned !== undefined) interaction.pinned = parsed.pinned\n if (parsed.durationMinutes !== undefined) interaction.durationMinutes = parsed.durationMinutes ?? null\n if (parsed.location !== undefined) interaction.location = parsed.location ?? null\n if (parsed.allDay !== undefined) interaction.allDay = parsed.allDay ?? null\n if (parsed.recurrenceRule !== undefined) interaction.recurrenceRule = parsed.recurrenceRule ?? null\n if (parsed.recurrenceEnd !== undefined) interaction.recurrenceEnd = parsed.recurrenceEnd ?? null\n if (parsed.participants !== undefined) interaction.participants = parsed.participants ?? null\n if (parsed.reminderMinutes !== undefined) interaction.reminderMinutes = parsed.reminderMinutes ?? null\n if (parsed.visibility !== undefined) interaction.visibility = parsed.visibility ?? null\n if (parsed.linkedEntities !== undefined) interaction.linkedEntities = parsed.linkedEntities ?? null\n if (parsed.guestPermissions !== undefined) interaction.guestPermissions = parsed.guestPermissions ?? null\n\n await trx.flush()\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n await setInteractionCustomFields(\n createTransactionalDataEngine(ctx, trx),\n interaction.id,\n interaction.organizationId,\n interaction.tenantId,\n custom,\n )\n\n const projection = await recomputeNextInteraction(trx, entityId)\n\n return { interaction, entityId, nextInteractionId: projection.nextInteractionId }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n\n return { interactionId: interaction.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const afterSnapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.update', 'Update interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n snapshotAfter: afterSnapshot ?? null,\n payload: {\n undo: {\n before,\n after: afterSnapshot ?? null,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, nextInteractionId } = await runInTransaction(em, async (trx) => {\n let interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n const entity = await requireTimelineParentEntity(trx, before.interaction.entityId)\n\n if (!interaction) {\n interaction = trx.create(CustomerInteraction, {\n id: before.interaction.id,\n organizationId: before.interaction.organizationId,\n tenantId: before.interaction.tenantId,\n entity,\n interactionType: before.interaction.interactionType,\n title: before.interaction.title,\n body: before.interaction.body,\n status: before.interaction.status,\n scheduledAt: before.interaction.scheduledAt,\n occurredAt: before.interaction.occurredAt,\n priority: before.interaction.priority,\n authorUserId: before.interaction.authorUserId,\n ownerUserId: before.interaction.ownerUserId,\n dealId: before.interaction.dealId,\n source: before.interaction.source,\n appearanceIcon: before.interaction.appearanceIcon,\n appearanceColor: before.interaction.appearanceColor,\n durationMinutes: before.interaction.durationMinutes,\n location: before.interaction.location,\n allDay: before.interaction.allDay,\n recurrenceRule: before.interaction.recurrenceRule,\n recurrenceEnd: before.interaction.recurrenceEnd,\n participants: before.interaction.participants,\n reminderMinutes: before.interaction.reminderMinutes,\n visibility: before.interaction.visibility,\n linkedEntities: before.interaction.linkedEntities,\n guestPermissions: before.interaction.guestPermissions,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n trx.persist(interaction)\n } else {\n interaction.entity = entity\n interaction.interactionType = before.interaction.interactionType\n interaction.title = before.interaction.title\n interaction.body = before.interaction.body\n interaction.status = before.interaction.status\n interaction.scheduledAt = before.interaction.scheduledAt\n interaction.occurredAt = before.interaction.occurredAt\n interaction.priority = before.interaction.priority\n interaction.authorUserId = before.interaction.authorUserId\n interaction.ownerUserId = before.interaction.ownerUserId\n interaction.dealId = before.interaction.dealId\n interaction.source = before.interaction.source\n interaction.appearanceIcon = before.interaction.appearanceIcon\n interaction.appearanceColor = before.interaction.appearanceColor\n interaction.durationMinutes = before.interaction.durationMinutes\n interaction.location = before.interaction.location\n interaction.allDay = before.interaction.allDay\n interaction.recurrenceRule = before.interaction.recurrenceRule\n interaction.recurrenceEnd = before.interaction.recurrenceEnd\n interaction.participants = before.interaction.participants\n interaction.reminderMinutes = before.interaction.reminderMinutes\n interaction.visibility = before.interaction.visibility\n interaction.linkedEntities = before.interaction.linkedEntities\n interaction.guestPermissions = before.interaction.guestPermissions\n }\n\n await trx.flush()\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n\n const resetValues = buildCustomFieldResetMap(before.custom, payload?.after?.custom)\n if (Object.keys(resetValues).length) {\n await setCustomFieldsIfAny({\n dataEngine: createTransactionalDataEngine(ctx, trx),\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n values: resetValues,\n notify: false,\n })\n }\n\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId,\n }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n },\n}\n\n// \u2500\u2500\u2500 Complete \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst completeInteractionCommand: CommandHandler<InteractionCompleteInput, { interactionId: string }> = {\n id: 'customers.interactions.complete',\n async prepare(rawInput, ctx) {\n const parsed = interactionCompleteSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = interactionCompleteSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: parsed.id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n interaction.status = 'done'\n interaction.occurredAt = parsed.occurredAt ?? new Date()\n await trx.flush()\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n const projection = await recomputeNextInteraction(trx, entityId)\n return { interaction, entityId, nextInteractionId: projection.nextInteractionId }\n })\n\n const identifiers = {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n }\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers,\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitLifecycleEvent(ctx, 'customers.interaction.completed', {\n ...identifiers,\n entityId,\n interactionType: interaction.interactionType,\n status: interaction.status,\n source: interaction.source ?? null,\n occurredAt: interaction.occurredAt?.toISOString() ?? null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, identifiers)\n\n return { interactionId: interaction.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const afterSnapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.complete', 'Complete interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n snapshotAfter: afterSnapshot ?? null,\n payload: {\n undo: {\n before,\n after: afterSnapshot ?? null,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const result = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n if (!interaction) return null\n\n interaction.status = before.interaction.status\n interaction.occurredAt = before.interaction.occurredAt\n await trx.flush()\n\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n if (!result) return\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: result.interaction,\n identifiers: {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitInteractionRevertedEvent(ctx, before.interaction)\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId: result.nextInteractionId,\n }, {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n })\n },\n}\n\n// \u2500\u2500\u2500 Cancel \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst cancelInteractionCommand: CommandHandler<InteractionCancelInput, { interactionId: string }> = {\n id: 'customers.interactions.cancel',\n async prepare(rawInput, ctx) {\n const parsed = interactionCancelSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = interactionCancelSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: parsed.id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n interaction.status = 'canceled'\n await trx.flush()\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n const projection = await recomputeNextInteraction(trx, entityId)\n return { interaction, entityId, nextInteractionId: projection.nextInteractionId }\n })\n\n const identifiers = {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n }\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers,\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitLifecycleEvent(ctx, 'customers.interaction.canceled', {\n ...identifiers,\n entityId,\n interactionType: interaction.interactionType,\n status: interaction.status,\n source: interaction.source ?? null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, identifiers)\n\n return { interactionId: interaction.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const afterSnapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.cancel', 'Cancel interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n snapshotAfter: afterSnapshot ?? null,\n payload: {\n undo: {\n before,\n after: afterSnapshot ?? null,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const result = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n if (!interaction) return null\n\n interaction.status = before.interaction.status\n await trx.flush()\n\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n if (!result) return\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: result.interaction,\n identifiers: {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitInteractionRevertedEvent(ctx, before.interaction)\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId: result.nextInteractionId,\n }, {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n })\n },\n}\n\n// \u2500\u2500\u2500 Delete \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst deleteInteractionCommand: CommandHandler<{ body?: Record<string, unknown>; query?: Record<string, unknown> }, { interactionId: string }> =\n {\n id: 'customers.interactions.delete',\n async prepare(input, ctx) {\n const id = requireId(input, 'Interaction id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const id = requireId(input, 'Interaction id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n interaction.deletedAt = new Date()\n await trx.flush()\n\n const projection = await recomputeNextInteraction(trx, entityId)\n return { interaction, entityId, nextInteractionId: projection.nextInteractionId }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'deleted',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n return { interactionId: interaction.id }\n },\n buildLog: async ({ snapshots }) => {\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('customers.audit.interactions.delete', 'Delete interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n payload: {\n undo: {\n before,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const entity = await requireTimelineParentEntity(trx, before.interaction.entityId)\n let interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n if (!interaction) {\n interaction = trx.create(CustomerInteraction, {\n id: before.interaction.id,\n organizationId: before.interaction.organizationId,\n tenantId: before.interaction.tenantId,\n entity,\n interactionType: before.interaction.interactionType,\n title: before.interaction.title,\n body: before.interaction.body,\n status: before.interaction.status,\n scheduledAt: before.interaction.scheduledAt,\n occurredAt: before.interaction.occurredAt,\n priority: before.interaction.priority,\n authorUserId: before.interaction.authorUserId,\n ownerUserId: before.interaction.ownerUserId,\n dealId: before.interaction.dealId,\n source: before.interaction.source,\n appearanceIcon: before.interaction.appearanceIcon,\n appearanceColor: before.interaction.appearanceColor,\n durationMinutes: before.interaction.durationMinutes,\n location: before.interaction.location,\n allDay: before.interaction.allDay,\n recurrenceRule: before.interaction.recurrenceRule,\n recurrenceEnd: before.interaction.recurrenceEnd,\n participants: before.interaction.participants,\n reminderMinutes: before.interaction.reminderMinutes,\n visibility: before.interaction.visibility,\n linkedEntities: before.interaction.linkedEntities,\n guestPermissions: before.interaction.guestPermissions,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n trx.persist(interaction)\n } else {\n interaction.deletedAt = null\n interaction.entity = entity\n interaction.interactionType = before.interaction.interactionType\n interaction.title = before.interaction.title\n interaction.body = before.interaction.body\n interaction.status = before.interaction.status\n interaction.scheduledAt = before.interaction.scheduledAt\n interaction.occurredAt = before.interaction.occurredAt\n interaction.priority = before.interaction.priority\n interaction.authorUserId = before.interaction.authorUserId\n interaction.ownerUserId = before.interaction.ownerUserId\n interaction.dealId = before.interaction.dealId\n interaction.source = before.interaction.source\n interaction.appearanceIcon = before.interaction.appearanceIcon\n interaction.appearanceColor = before.interaction.appearanceColor\n interaction.durationMinutes = before.interaction.durationMinutes\n interaction.location = before.interaction.location\n interaction.allDay = before.interaction.allDay\n interaction.recurrenceRule = before.interaction.recurrenceRule\n interaction.recurrenceEnd = before.interaction.recurrenceEnd\n interaction.participants = before.interaction.participants\n interaction.reminderMinutes = before.interaction.reminderMinutes\n interaction.visibility = before.interaction.visibility\n interaction.linkedEntities = before.interaction.linkedEntities\n interaction.guestPermissions = before.interaction.guestPermissions\n }\n await trx.flush()\n\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n\n const resetValues = buildCustomFieldResetMap(before.custom, undefined)\n if (Object.keys(resetValues).length) {\n await setCustomFieldsIfAny({\n dataEngine: createTransactionalDataEngine(ctx, trx),\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n values: resetValues,\n notify: false,\n })\n }\n\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'created',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId,\n }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n },\n }\n\n// \u2500\u2500\u2500 Recompute Next (internal repair) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst recomputeNextSchema = z.object({ entityId: z.string().min(1) })\n\nconst recomputeNextCommand: CommandHandler<{ entityId: string }, { entityId: string }> = {\n id: 'customers.interaction.recompute_next',\n async execute(rawInput, ctx) {\n const parsed = recomputeNextSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const projection = await recomputeNextInteraction(em, parsed.entityId)\n const entity = await requireTimelineParentEntity(em, parsed.entityId)\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: parsed.entityId,\n nextInteractionId: projection.nextInteractionId,\n }, {\n id: parsed.entityId,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n })\n return { entityId: parsed.entityId }\n },\n}\n\nregisterCommand(createInteractionCommand)\nregisterCommand(updateInteractionCommand)\nregisterCommand(completeInteractionCommand)\nregisterCommand(cancelInteractionCommand)\nregisterCommand(deleteInteractionCommand)\nregisterCommand(recomputeNextCommand)\n"],
5
- "mappings": "AAAA,SAAS,SAAS;AAClB,SAAS,uBAAuB;AAEhC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAA0C;AAGnD,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAEtC,SAAS,gCAAgC;AAEzC,MAAM,wBAAwB;AAC9B,MAAM,yBAAiE;AAAA,EACrE,YAAY;AACd;AAEA,MAAM,wBAA0C;AAAA,EAC9C,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,YAAY;A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AAwB;AACxC,gBAAgB,oBAAoB;",
4
+ "sourcesContent": ["import { z } from 'zod'\nimport { registerCommand } from '@open-mercato/shared/lib/commands'\nimport type { CommandHandler } from '@open-mercato/shared/lib/commands'\nimport {\n parseWithCustomFields,\n setCustomFieldsIfAny,\n emitCrudSideEffects,\n emitCrudUndoSideEffects,\n requireId,\n normalizeAuthorUserId,\n} from '@open-mercato/shared/lib/commands/helpers'\nimport { DefaultDataEngine, type DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { CommandRuntimeContext } from '@open-mercato/shared/lib/commands'\nimport { CustomerInteraction } from '../data/entities'\nimport {\n interactionCreateSchema,\n interactionUpdateSchema,\n interactionCompleteSchema,\n interactionCancelSchema,\n type InteractionCreateInput,\n type InteractionUpdateInput,\n type InteractionCompleteInput,\n type InteractionCancelInput,\n} from '../data/validators'\nimport {\n ensureOrganizationScope,\n ensureTenantScope,\n requireTimelineParentEntity,\n extractUndoPayload,\n emitQueryIndexUpsertEvents,\n requireDealInScope,\n resolveParentResourceKind,\n} from './shared'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport {\n loadCustomFieldSnapshot,\n buildCustomFieldResetMap,\n} from '@open-mercato/shared/lib/commands/customFieldSnapshots'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport type { CrudIndexerConfig, CrudEventsConfig } from '@open-mercato/shared/lib/crud/types'\nimport { recomputeNextInteraction } from '../lib/interactionProjection'\nimport { canChangeEmailVisibility } from '../lib/visibilityFilter'\n\nconst INTERACTION_ENTITY_ID = 'customers:customer_interaction'\nconst interactionCrudIndexer: CrudIndexerConfig<CustomerInteraction> = {\n entityType: 'customers:customer_interaction' as const,\n}\n\nconst interactionCrudEvents: CrudEventsConfig = {\n module: 'customers',\n entity: 'interaction',\n persistent: true,\n buildPayload: (ctx) => ({\n id: ctx.identifiers.id,\n organizationId: ctx.identifiers.organizationId,\n tenantId: ctx.identifiers.tenantId,\n entityId:\n ctx.entity && typeof ctx.entity === 'object' && 'entity' in (ctx.entity as Record<string, unknown>)\n ? (() => {\n const entityRef = (ctx.entity as CustomerInteraction).entity\n return typeof entityRef === 'string' ? entityRef : entityRef?.id ?? null\n })()\n : null,\n interactionType:\n ctx.entity && typeof ctx.entity === 'object' && 'interactionType' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerInteraction).interactionType\n : null,\n status:\n ctx.entity && typeof ctx.entity === 'object' && 'status' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerInteraction).status\n : null,\n source:\n ctx.entity && typeof ctx.entity === 'object' && 'source' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerInteraction).source ?? null\n : null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n }),\n}\n\ntype InteractionSnapshot = {\n interaction: {\n id: string\n organizationId: string\n tenantId: string\n entityId: string\n entityKind: string | null\n dealId: string | null\n interactionType: string\n title: string | null\n body: string | null\n status: string\n scheduledAt: Date | null\n occurredAt: Date | null\n priority: number | null\n authorUserId: string | null\n ownerUserId: string | null\n appearanceIcon: string | null\n appearanceColor: string | null\n source: string | null\n durationMinutes: number | null\n location: string | null\n allDay: boolean | null\n recurrenceRule: string | null\n recurrenceEnd: Date | null\n participants: Array<{ userId: string; name?: string; email?: string; status?: string }> | null\n reminderMinutes: number | null\n visibility: string | null\n linkedEntities: Array<{ id: string; type: string; label: string }> | null\n guestPermissions: { canInviteOthers?: boolean; canModify?: boolean; canSeeList?: boolean } | null\n }\n custom?: Record<string, unknown>\n}\n\ntype InteractionUndoPayload = {\n before?: InteractionSnapshot | null\n after?: InteractionSnapshot | null\n}\n\nasync function loadInteractionSnapshot(em: EntityManager, id: string): Promise<InteractionSnapshot | null> {\n const interaction = await findOneWithDecryption(em, CustomerInteraction, { id }, { populate: ['entity'] })\n if (!interaction) return null\n const custom = await loadCustomFieldSnapshot(em, {\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n tenantId: interaction.tenantId,\n organizationId: interaction.organizationId,\n })\n const entityRef = interaction.entity\n const entityKind = (typeof entityRef === 'object' && entityRef !== null && 'kind' in entityRef)\n ? (entityRef as { kind: string }).kind\n : null\n return {\n interaction: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n entityId: typeof entityRef === 'string' ? entityRef : entityRef.id,\n entityKind,\n dealId: interaction.dealId ?? null,\n interactionType: interaction.interactionType,\n title: interaction.title ?? null,\n body: interaction.body ?? null,\n status: interaction.status,\n scheduledAt: interaction.scheduledAt ?? null,\n occurredAt: interaction.occurredAt ?? null,\n priority: interaction.priority ?? null,\n authorUserId: interaction.authorUserId ?? null,\n ownerUserId: interaction.ownerUserId ?? null,\n appearanceIcon: interaction.appearanceIcon ?? null,\n appearanceColor: interaction.appearanceColor ?? null,\n source: interaction.source ?? null,\n durationMinutes: interaction.durationMinutes ?? null,\n location: interaction.location ?? null,\n allDay: interaction.allDay ?? null,\n recurrenceRule: interaction.recurrenceRule ?? null,\n recurrenceEnd: interaction.recurrenceEnd ?? null,\n participants: interaction.participants ?? null,\n reminderMinutes: interaction.reminderMinutes ?? null,\n visibility: interaction.visibility ?? null,\n linkedEntities: interaction.linkedEntities ?? null,\n guestPermissions: interaction.guestPermissions ?? null,\n },\n custom,\n }\n}\n\nasync function setInteractionCustomFields(\n dataEngine: DataEngine,\n interactionId: string,\n organizationId: string,\n tenantId: string,\n values: Record<string, unknown>\n) {\n if (!values || !Object.keys(values).length) return\n await setCustomFieldsIfAny({\n dataEngine,\n entityId: INTERACTION_ENTITY_ID,\n recordId: interactionId,\n organizationId,\n tenantId,\n values,\n notify: false,\n })\n}\n\nasync function emitLifecycleEvent(\n ctx: CommandRuntimeContext,\n eventId: string,\n payload: Record<string, unknown>\n): Promise<void> {\n let bus: { emitEvent(event: string, payload: unknown, options?: unknown): Promise<void> } | null = null\n try {\n bus = ctx.container.resolve('eventBus')\n } catch (err) {\n console.warn('[customers.commands.interactions] eventBus resolve failed; skipping emit', eventId, err)\n bus = null\n }\n if (!bus) return\n await bus\n .emitEvent(eventId, payload, { persistent: true })\n .catch((err) => {\n console.warn('[customers.commands.interactions] emit failed', eventId, err)\n return undefined\n })\n}\n\nasync function emitInteractionRevertedEvent(\n ctx: CommandRuntimeContext,\n interaction: InteractionSnapshot['interaction'],\n): Promise<void> {\n await emitLifecycleEvent(ctx, 'customers.interaction.reverted', {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n entityId: interaction.entityId,\n interactionType: interaction.interactionType,\n source: interaction.source ?? null,\n status: interaction.status,\n occurredAt: interaction.occurredAt?.toISOString() ?? null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n })\n}\n\ntype InteractionIdentifiers = {\n id: string\n organizationId: string\n tenantId: string\n}\n\ntype InteractionProjectionMutation = {\n entityId: string\n nextInteractionId: string | null\n}\n\nfunction createTransactionalDataEngine(ctx: CommandRuntimeContext, em: EntityManager): DataEngine {\n const emWithConnection = em as EntityManager & { getConnection?: () => unknown }\n if (typeof emWithConnection.getConnection !== 'function') {\n return ctx.container.resolve('dataEngine') as DataEngine\n }\n return new DefaultDataEngine(em, ctx.container)\n}\n\nasync function runInTransaction<TResult>(\n em: EntityManager,\n operation: (trx: EntityManager) => Promise<TResult>,\n): Promise<TResult> {\n // Mirrors the SPEC-018 fix applied to withAtomicFlush: use explicit begin/commit/rollback\n // so the outer EntityManager stays bound to the transaction, and closures over `em` inside\n // `operation` participate in the same transaction. This avoids the em.transactional(cb)\n // hazard where the callback receives a child EM whose flushes can silently race against\n // subsequent queries on the original `em`.\n const supportsBegin =\n typeof (em as unknown as { begin?: () => Promise<void> }).begin === 'function' &&\n typeof (em as unknown as { commit?: () => Promise<void> }).commit === 'function' &&\n typeof (em as unknown as { rollback?: () => Promise<void> }).rollback === 'function'\n if (!supportsBegin) {\n return operation(em)\n }\n await em.begin()\n try {\n const result = await operation(em)\n await em.commit()\n return result\n } catch (err) {\n try {\n await em.rollback()\n } catch {\n // rollback failure should not mask the original error; intentionally swallowed\n }\n throw err\n }\n}\n\nasync function emitNextInteractionUpdatedEvent(\n ctx: CommandRuntimeContext,\n projection: InteractionProjectionMutation,\n identifiers: InteractionIdentifiers,\n): Promise<void> {\n await emitQueryIndexUpsertEvents(ctx, [{\n entityType: 'customers:customer_entity',\n recordId: projection.entityId,\n organizationId: identifiers.organizationId,\n tenantId: identifiers.tenantId,\n }])\n await emitLifecycleEvent(ctx, 'customers.next_interaction.updated', {\n id: projection.entityId,\n entityId: projection.entityId,\n nextInteractionId: projection.nextInteractionId,\n organizationId: identifiers.organizationId,\n tenantId: identifiers.tenantId,\n })\n}\n\n// \u2500\u2500\u2500 Create \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst createInteractionCommand: CommandHandler<InteractionCreateInput, { interactionId: string; entityId: string }> = {\n id: 'customers.interactions.create',\n async execute(rawInput, ctx) {\n const { parsed, custom } = parseWithCustomFields(interactionCreateSchema, rawInput)\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const normalizedAuthor = normalizeAuthorUserId(parsed.authorUserId ?? null, ctx.auth)\n const { interaction, entityId, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const entity = await requireTimelineParentEntity(trx, parsed.entityId)\n ensureTenantScope(ctx, entity.tenantId)\n ensureOrganizationScope(ctx, entity.organizationId)\n\n if (parsed.dealId) {\n await requireDealInScope(trx, parsed.dealId, entity.tenantId, entity.organizationId)\n }\n\n const interaction = trx.create(CustomerInteraction, {\n ...(parsed.id ? { id: parsed.id } : {}),\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n entity,\n interactionType: parsed.interactionType,\n title: parsed.title ?? null,\n body: parsed.body ?? null,\n status: parsed.status ?? 'planned',\n scheduledAt: parsed.scheduledAt ?? null,\n occurredAt: parsed.occurredAt ?? null,\n priority: parsed.priority ?? null,\n authorUserId: normalizedAuthor,\n ownerUserId: parsed.ownerUserId ?? null,\n dealId: parsed.dealId ?? null,\n source: parsed.source ?? null,\n appearanceIcon: parsed.appearanceIcon ?? null,\n appearanceColor: parsed.appearanceColor ?? null,\n durationMinutes: parsed.durationMinutes ?? null,\n location: parsed.location ?? null,\n allDay: parsed.allDay ?? null,\n recurrenceRule: parsed.recurrenceRule ?? null,\n recurrenceEnd: parsed.recurrenceEnd ?? null,\n participants: parsed.participants ?? null,\n reminderMinutes: parsed.reminderMinutes ?? null,\n visibility: parsed.visibility ?? null,\n linkedEntities: parsed.linkedEntities ?? null,\n guestPermissions: parsed.guestPermissions ?? null,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n trx.persist(interaction)\n await trx.flush()\n\n await setInteractionCustomFields(\n createTransactionalDataEngine(ctx, trx),\n interaction.id,\n entity.organizationId,\n entity.tenantId,\n custom,\n )\n\n const projection = await recomputeNextInteraction(trx, entity.id)\n\n return {\n interaction,\n entityId: entity.id,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'created',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n\n return { interactionId: interaction.id, entityId }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const snapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.create', 'Create interaction'),\n resourceKind: 'customers.interaction',\n resourceId: result.interactionId,\n parentResourceKind: resolveParentResourceKind(snapshot?.interaction?.entityKind),\n parentResourceId: snapshot?.interaction?.entityId ?? null,\n tenantId: snapshot?.interaction.tenantId ?? null,\n organizationId: snapshot?.interaction.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const interactionId = logEntry?.resourceId\n if (!interactionId) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const result = await runInTransaction(em, async (trx) => {\n const record = await findOneWithDecryption(trx, CustomerInteraction, { id: interactionId })\n if (!record) return null\n const entityId = typeof record.entity === 'string' ? record.entity : record.entity.id\n trx.remove(record)\n await trx.flush()\n const projection = await recomputeNextInteraction(trx, entityId)\n return {\n entityId,\n nextInteractionId: projection.nextInteractionId,\n identifiers: {\n id: record.id,\n organizationId: record.organizationId,\n tenantId: record.tenantId,\n },\n }\n })\n if (!result) return\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: result.entityId,\n nextInteractionId: result.nextInteractionId,\n }, result.identifiers)\n },\n}\n\n// \u2500\u2500\u2500 Update \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst updateInteractionCommand: CommandHandler<InteractionUpdateInput, { interactionId: string }> = {\n id: 'customers.interactions.update',\n async prepare(rawInput, ctx) {\n const { parsed } = parseWithCustomFields(interactionUpdateSchema, rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const { parsed, custom } = parseWithCustomFields(interactionUpdateSchema, rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: parsed.id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n // Email visibility is an access-controlled field: only the interaction's\n // author may change a\n // private email's visibility (mirrors the dedicated PATCH .../visibility\n // route). Enforce it here \u2014 the single persistence path \u2014 so the generic\n // update route (PUT /api/interactions) cannot bypass the gate. Evaluated\n // against the row's pre-mutation author/type. 404 (not 403) keeps the\n // existence-masking consistent with the dedicated route.\n if (\n parsed.visibility !== undefined &&\n interaction.interactionType === 'email' &&\n (parsed.visibility ?? null) !== (interaction.visibility ?? null)\n ) {\n const actorUserId = (ctx.auth as { sub?: string | null } | null)?.sub ?? null\n if (\n !canChangeEmailVisibility({\n interactionType: interaction.interactionType,\n currentVisibility: interaction.visibility,\n nextVisibility: parsed.visibility,\n authorUserId: interaction.authorUserId,\n actorUserId,\n // v1 strict owner-only: only the author may flip visibility; no admin\n // bypass (canChangeEmailVisibility ignores caller features in v1).\n userFeatures: undefined,\n })\n ) {\n throw new CrudHttpError(404, { error: 'Email not found' })\n }\n }\n\n if (parsed.dealId !== undefined) {\n if (parsed.dealId) {\n await requireDealInScope(trx, parsed.dealId, interaction.tenantId, interaction.organizationId)\n }\n interaction.dealId = parsed.dealId ?? null\n }\n if (parsed.interactionType !== undefined) interaction.interactionType = parsed.interactionType\n if (parsed.title !== undefined) interaction.title = parsed.title ?? null\n if (parsed.body !== undefined) interaction.body = parsed.body ?? null\n if (parsed.status !== undefined) interaction.status = parsed.status\n if (parsed.scheduledAt !== undefined) interaction.scheduledAt = parsed.scheduledAt ?? null\n if (parsed.occurredAt !== undefined) interaction.occurredAt = parsed.occurredAt ?? null\n if (parsed.priority !== undefined) interaction.priority = parsed.priority ?? null\n if (parsed.authorUserId !== undefined) interaction.authorUserId = parsed.authorUserId ?? null\n if (parsed.ownerUserId !== undefined) interaction.ownerUserId = parsed.ownerUserId ?? null\n if (parsed.appearanceIcon !== undefined) interaction.appearanceIcon = parsed.appearanceIcon ?? null\n if (parsed.appearanceColor !== undefined) interaction.appearanceColor = parsed.appearanceColor ?? null\n if (parsed.pinned !== undefined) interaction.pinned = parsed.pinned\n if (parsed.durationMinutes !== undefined) interaction.durationMinutes = parsed.durationMinutes ?? null\n if (parsed.location !== undefined) interaction.location = parsed.location ?? null\n if (parsed.allDay !== undefined) interaction.allDay = parsed.allDay ?? null\n if (parsed.recurrenceRule !== undefined) interaction.recurrenceRule = parsed.recurrenceRule ?? null\n if (parsed.recurrenceEnd !== undefined) interaction.recurrenceEnd = parsed.recurrenceEnd ?? null\n if (parsed.participants !== undefined) interaction.participants = parsed.participants ?? null\n if (parsed.reminderMinutes !== undefined) interaction.reminderMinutes = parsed.reminderMinutes ?? null\n if (parsed.visibility !== undefined) interaction.visibility = parsed.visibility ?? null\n if (parsed.linkedEntities !== undefined) interaction.linkedEntities = parsed.linkedEntities ?? null\n if (parsed.guestPermissions !== undefined) interaction.guestPermissions = parsed.guestPermissions ?? null\n\n await trx.flush()\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n await setInteractionCustomFields(\n createTransactionalDataEngine(ctx, trx),\n interaction.id,\n interaction.organizationId,\n interaction.tenantId,\n custom,\n )\n\n const projection = await recomputeNextInteraction(trx, entityId)\n\n return { interaction, entityId, nextInteractionId: projection.nextInteractionId }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n\n return { interactionId: interaction.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const afterSnapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.update', 'Update interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n snapshotAfter: afterSnapshot ?? null,\n payload: {\n undo: {\n before,\n after: afterSnapshot ?? null,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, nextInteractionId } = await runInTransaction(em, async (trx) => {\n let interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n const entity = await requireTimelineParentEntity(trx, before.interaction.entityId)\n\n if (!interaction) {\n interaction = trx.create(CustomerInteraction, {\n id: before.interaction.id,\n organizationId: before.interaction.organizationId,\n tenantId: before.interaction.tenantId,\n entity,\n interactionType: before.interaction.interactionType,\n title: before.interaction.title,\n body: before.interaction.body,\n status: before.interaction.status,\n scheduledAt: before.interaction.scheduledAt,\n occurredAt: before.interaction.occurredAt,\n priority: before.interaction.priority,\n authorUserId: before.interaction.authorUserId,\n ownerUserId: before.interaction.ownerUserId,\n dealId: before.interaction.dealId,\n source: before.interaction.source,\n appearanceIcon: before.interaction.appearanceIcon,\n appearanceColor: before.interaction.appearanceColor,\n durationMinutes: before.interaction.durationMinutes,\n location: before.interaction.location,\n allDay: before.interaction.allDay,\n recurrenceRule: before.interaction.recurrenceRule,\n recurrenceEnd: before.interaction.recurrenceEnd,\n participants: before.interaction.participants,\n reminderMinutes: before.interaction.reminderMinutes,\n visibility: before.interaction.visibility,\n linkedEntities: before.interaction.linkedEntities,\n guestPermissions: before.interaction.guestPermissions,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n trx.persist(interaction)\n } else {\n interaction.entity = entity\n interaction.interactionType = before.interaction.interactionType\n interaction.title = before.interaction.title\n interaction.body = before.interaction.body\n interaction.status = before.interaction.status\n interaction.scheduledAt = before.interaction.scheduledAt\n interaction.occurredAt = before.interaction.occurredAt\n interaction.priority = before.interaction.priority\n interaction.authorUserId = before.interaction.authorUserId\n interaction.ownerUserId = before.interaction.ownerUserId\n interaction.dealId = before.interaction.dealId\n interaction.source = before.interaction.source\n interaction.appearanceIcon = before.interaction.appearanceIcon\n interaction.appearanceColor = before.interaction.appearanceColor\n interaction.durationMinutes = before.interaction.durationMinutes\n interaction.location = before.interaction.location\n interaction.allDay = before.interaction.allDay\n interaction.recurrenceRule = before.interaction.recurrenceRule\n interaction.recurrenceEnd = before.interaction.recurrenceEnd\n interaction.participants = before.interaction.participants\n interaction.reminderMinutes = before.interaction.reminderMinutes\n interaction.visibility = before.interaction.visibility\n interaction.linkedEntities = before.interaction.linkedEntities\n interaction.guestPermissions = before.interaction.guestPermissions\n }\n\n await trx.flush()\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n\n const resetValues = buildCustomFieldResetMap(before.custom, payload?.after?.custom)\n if (Object.keys(resetValues).length) {\n await setCustomFieldsIfAny({\n dataEngine: createTransactionalDataEngine(ctx, trx),\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n values: resetValues,\n notify: false,\n })\n }\n\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId,\n }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n },\n}\n\n// \u2500\u2500\u2500 Complete \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst completeInteractionCommand: CommandHandler<InteractionCompleteInput, { interactionId: string }> = {\n id: 'customers.interactions.complete',\n async prepare(rawInput, ctx) {\n const parsed = interactionCompleteSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = interactionCompleteSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: parsed.id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n interaction.status = 'done'\n interaction.occurredAt = parsed.occurredAt ?? new Date()\n await trx.flush()\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n const projection = await recomputeNextInteraction(trx, entityId)\n return { interaction, entityId, nextInteractionId: projection.nextInteractionId }\n })\n\n const identifiers = {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n }\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers,\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitLifecycleEvent(ctx, 'customers.interaction.completed', {\n ...identifiers,\n entityId,\n interactionType: interaction.interactionType,\n status: interaction.status,\n source: interaction.source ?? null,\n occurredAt: interaction.occurredAt?.toISOString() ?? null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, identifiers)\n\n return { interactionId: interaction.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const afterSnapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.complete', 'Complete interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n snapshotAfter: afterSnapshot ?? null,\n payload: {\n undo: {\n before,\n after: afterSnapshot ?? null,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const result = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n if (!interaction) return null\n\n interaction.status = before.interaction.status\n interaction.occurredAt = before.interaction.occurredAt\n await trx.flush()\n\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n if (!result) return\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: result.interaction,\n identifiers: {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitInteractionRevertedEvent(ctx, before.interaction)\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId: result.nextInteractionId,\n }, {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n })\n },\n}\n\n// \u2500\u2500\u2500 Cancel \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst cancelInteractionCommand: CommandHandler<InteractionCancelInput, { interactionId: string }> = {\n id: 'customers.interactions.cancel',\n async prepare(rawInput, ctx) {\n const parsed = interactionCancelSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = interactionCancelSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: parsed.id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n interaction.status = 'canceled'\n await trx.flush()\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n const projection = await recomputeNextInteraction(trx, entityId)\n return { interaction, entityId, nextInteractionId: projection.nextInteractionId }\n })\n\n const identifiers = {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n }\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: interaction,\n identifiers,\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitLifecycleEvent(ctx, 'customers.interaction.canceled', {\n ...identifiers,\n entityId,\n interactionType: interaction.interactionType,\n status: interaction.status,\n source: interaction.source ?? null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, identifiers)\n\n return { interactionId: interaction.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadInteractionSnapshot(em, result.interactionId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const afterSnapshot = snapshots.after as InteractionSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.interactions.cancel', 'Cancel interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n snapshotAfter: afterSnapshot ?? null,\n payload: {\n undo: {\n before,\n after: afterSnapshot ?? null,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const result = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n if (!interaction) return null\n\n interaction.status = before.interaction.status\n await trx.flush()\n\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n if (!result) return\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: result.interaction,\n identifiers: {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitInteractionRevertedEvent(ctx, before.interaction)\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId: result.nextInteractionId,\n }, {\n id: result.interaction.id,\n organizationId: result.interaction.organizationId,\n tenantId: result.interaction.tenantId,\n })\n },\n}\n\n// \u2500\u2500\u2500 Delete \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst deleteInteractionCommand: CommandHandler<{ body?: Record<string, unknown>; query?: Record<string, unknown> }, { interactionId: string }> =\n {\n id: 'customers.interactions.delete',\n async prepare(input, ctx) {\n const id = requireId(input, 'Interaction id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadInteractionSnapshot(em, id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const id = requireId(input, 'Interaction id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, entityId, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const interaction = await findOneWithDecryption(trx, CustomerInteraction, { id, deletedAt: null })\n if (!interaction) throw new CrudHttpError(404, { error: 'Interaction not found' })\n ensureTenantScope(ctx, interaction.tenantId)\n ensureOrganizationScope(ctx, interaction.organizationId)\n\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n interaction.deletedAt = new Date()\n await trx.flush()\n\n const projection = await recomputeNextInteraction(trx, entityId)\n return { interaction, entityId, nextInteractionId: projection.nextInteractionId }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'deleted',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, { entityId, nextInteractionId }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n return { interactionId: interaction.id }\n },\n buildLog: async ({ snapshots }) => {\n const before = snapshots.before as InteractionSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('customers.audit.interactions.delete', 'Delete interaction'),\n resourceKind: 'customers.interaction',\n resourceId: before.interaction.id,\n parentResourceKind: resolveParentResourceKind(before.interaction.entityKind),\n parentResourceId: before.interaction.entityId ?? null,\n tenantId: before.interaction.tenantId,\n organizationId: before.interaction.organizationId,\n snapshotBefore: before,\n payload: {\n undo: {\n before,\n } satisfies InteractionUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<InteractionUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const { interaction, nextInteractionId } = await runInTransaction(em, async (trx) => {\n const entity = await requireTimelineParentEntity(trx, before.interaction.entityId)\n let interaction = await findOneWithDecryption(trx, CustomerInteraction, { id: before.interaction.id })\n if (!interaction) {\n interaction = trx.create(CustomerInteraction, {\n id: before.interaction.id,\n organizationId: before.interaction.organizationId,\n tenantId: before.interaction.tenantId,\n entity,\n interactionType: before.interaction.interactionType,\n title: before.interaction.title,\n body: before.interaction.body,\n status: before.interaction.status,\n scheduledAt: before.interaction.scheduledAt,\n occurredAt: before.interaction.occurredAt,\n priority: before.interaction.priority,\n authorUserId: before.interaction.authorUserId,\n ownerUserId: before.interaction.ownerUserId,\n dealId: before.interaction.dealId,\n source: before.interaction.source,\n appearanceIcon: before.interaction.appearanceIcon,\n appearanceColor: before.interaction.appearanceColor,\n durationMinutes: before.interaction.durationMinutes,\n location: before.interaction.location,\n allDay: before.interaction.allDay,\n recurrenceRule: before.interaction.recurrenceRule,\n recurrenceEnd: before.interaction.recurrenceEnd,\n participants: before.interaction.participants,\n reminderMinutes: before.interaction.reminderMinutes,\n visibility: before.interaction.visibility,\n linkedEntities: before.interaction.linkedEntities,\n guestPermissions: before.interaction.guestPermissions,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n trx.persist(interaction)\n } else {\n interaction.deletedAt = null\n interaction.entity = entity\n interaction.interactionType = before.interaction.interactionType\n interaction.title = before.interaction.title\n interaction.body = before.interaction.body\n interaction.status = before.interaction.status\n interaction.scheduledAt = before.interaction.scheduledAt\n interaction.occurredAt = before.interaction.occurredAt\n interaction.priority = before.interaction.priority\n interaction.authorUserId = before.interaction.authorUserId\n interaction.ownerUserId = before.interaction.ownerUserId\n interaction.dealId = before.interaction.dealId\n interaction.source = before.interaction.source\n interaction.appearanceIcon = before.interaction.appearanceIcon\n interaction.appearanceColor = before.interaction.appearanceColor\n interaction.durationMinutes = before.interaction.durationMinutes\n interaction.location = before.interaction.location\n interaction.allDay = before.interaction.allDay\n interaction.recurrenceRule = before.interaction.recurrenceRule\n interaction.recurrenceEnd = before.interaction.recurrenceEnd\n interaction.participants = before.interaction.participants\n interaction.reminderMinutes = before.interaction.reminderMinutes\n interaction.visibility = before.interaction.visibility\n interaction.linkedEntities = before.interaction.linkedEntities\n interaction.guestPermissions = before.interaction.guestPermissions\n }\n await trx.flush()\n\n const projection = await recomputeNextInteraction(trx, before.interaction.entityId)\n\n const resetValues = buildCustomFieldResetMap(before.custom, undefined)\n if (Object.keys(resetValues).length) {\n await setCustomFieldsIfAny({\n dataEngine: createTransactionalDataEngine(ctx, trx),\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n values: resetValues,\n notify: false,\n })\n }\n\n return {\n interaction,\n nextInteractionId: projection.nextInteractionId,\n }\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'created',\n entity: interaction,\n identifiers: {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n },\n syncOrigin: ctx.syncOrigin,\n indexer: interactionCrudIndexer,\n events: interactionCrudEvents,\n })\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: before.interaction.entityId,\n nextInteractionId,\n }, {\n id: interaction.id,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n })\n },\n }\n\n// \u2500\u2500\u2500 Recompute Next (internal repair) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst recomputeNextSchema = z.object({ entityId: z.string().min(1) })\n\nconst recomputeNextCommand: CommandHandler<{ entityId: string }, { entityId: string }> = {\n id: 'customers.interaction.recompute_next',\n async execute(rawInput, ctx) {\n const parsed = recomputeNextSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const projection = await recomputeNextInteraction(em, parsed.entityId)\n const entity = await requireTimelineParentEntity(em, parsed.entityId)\n await emitNextInteractionUpdatedEvent(ctx, {\n entityId: parsed.entityId,\n nextInteractionId: projection.nextInteractionId,\n }, {\n id: parsed.entityId,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n })\n return { entityId: parsed.entityId }\n },\n}\n\nregisterCommand(createInteractionCommand)\nregisterCommand(updateInteractionCommand)\nregisterCommand(completeInteractionCommand)\nregisterCommand(cancelInteractionCommand)\nregisterCommand(deleteInteractionCommand)\nregisterCommand(recomputeNextCommand)\n"],
5
+ "mappings": "AAAA,SAAS,SAAS;AAClB,SAAS,uBAAuB;AAEhC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAA0C;AAGnD,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,S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;AAEpE,MAAM,uBAAmF;AAAA,EACvF,IAAI;AAAA,EACJ,MAAM,QAAQ,UAAU,KAAK;AAC3B,UAAM,SAAS,oBAAoB,MAAM,QAAQ;AACjD,UAAM,KAAM,IAAI,UAAU,QAAQ,IAAI,EAAoB,KAAK;AAC/D,UAAM,aAAa,MAAM,yBAAyB,IAAI,OAAO,QAAQ;AACrE,UAAM,SAAS,MAAM,4BAA4B,IAAI,OAAO,QAAQ;AACpE,UAAM,gCAAgC,KAAK;AAAA,MACzC,UAAU,OAAO;AAAA,MACjB,mBAAmB,WAAW;AAAA,IAChC,GAAG;AAAA,MACD,IAAI,OAAO;AAAA,MACX,gBAAgB,OAAO;AAAA,MACvB,UAAU,OAAO;AAAA,IACnB,CAAC;AACD,WAAO,EAAE,UAAU,OAAO,SAAS;AAAA,EACrC;AACF;AAEA,gBAAgB,wBAAwB;AACxC,gBAAgB,wBAAwB;AACxC,gBAAgB,0BAA0B;AAC1C,gBAAgB,wBAAwB;AACxC,gBAAgB,wBAAwB;AACxC,gBAAgB,oBAAoB;",
6
6
  "names": ["interaction", "entityId"]
7
7
  }
@@ -10,6 +10,7 @@ import { apiCallOrThrow } from "@open-mercato/ui/backend/utils/apiCall";
10
10
  import { useT } from "@open-mercato/shared/lib/i18n/context";
11
11
  import { cn } from "@open-mercato/shared/lib/utils";
12
12
  import { ActivityAiActions } from "./ActivityAiActions.js";
13
+ import { EmailCardActions } from "./EmailCardActions.js";
13
14
  const TYPE_ICONS = {
14
15
  call: Phone,
15
16
  email: Mail,
@@ -46,6 +47,27 @@ function resolveTarget(activity) {
46
47
  if (activity.customer?.displayName) return activity.customer.displayName;
47
48
  return null;
48
49
  }
50
+ function buildEmailCardWidgetData(activity) {
51
+ const integrations = activity._integrations;
52
+ const emailMeta = integrations?.email ?? {};
53
+ return {
54
+ interactionId: activity.id,
55
+ // The MessageChannelLink UUID stored on the interaction row.
56
+ externalMessageId: typeof emailMeta.externalMessageId === "string" ? emailMeta.externalMessageId : null,
57
+ // RFC2822 Message-ID (e.g. "<abc@mail.gmail.com>") for In-Reply-To / References headers.
58
+ rfcMessageId: typeof emailMeta.rfcMessageId === "string" ? emailMeta.rfcMessageId : null,
59
+ // entityId is the CustomerEntity id — on a person detail page this IS the personId.
60
+ personId: activity.entityId ?? null,
61
+ fromAddress: typeof emailMeta.fromAddress === "string" ? emailMeta.fromAddress : null,
62
+ toAddresses: Array.isArray(emailMeta.toAddresses) ? emailMeta.toAddresses : null,
63
+ ccAddresses: Array.isArray(emailMeta.ccAddresses) ? emailMeta.ccAddresses : null,
64
+ subject: activity.title ?? null,
65
+ inReplyTo: typeof emailMeta.inReplyTo === "string" ? emailMeta.inReplyTo : null,
66
+ references: Array.isArray(emailMeta.references) ? emailMeta.references : null,
67
+ currentVisibility: emailMeta.currentVisibility === "private" || emailMeta.currentVisibility === "shared" ? emailMeta.currentVisibility : null,
68
+ isAuthor: typeof emailMeta.isAuthor === "boolean" ? emailMeta.isAuthor : null
69
+ };
70
+ }
49
71
  function ActivityCard({ activity, onOpen, onChanged, runMutation }) {
50
72
  const t = useT();
51
73
  const timestamp = activity.occurredAt ?? activity.scheduledAt ?? activity.createdAt;
@@ -155,6 +177,16 @@ function ActivityCard({ activity, onOpen, onChanged, runMutation }) {
155
177
  ] })
156
178
  ] }),
157
179
  /* @__PURE__ */ jsx("div", { className: "mt-2", children: /* @__PURE__ */ jsx(ActivityAiActions, { activityType: activity.interactionType }) }),
180
+ activity.interactionType === "email" ? /* @__PURE__ */ jsx(
181
+ "div",
182
+ {
183
+ className: "mt-1",
184
+ onClick: (event) => event.stopPropagation(),
185
+ onKeyDown: (event) => event.stopPropagation(),
186
+ role: "presentation",
187
+ children: /* @__PURE__ */ jsx(EmailCardActions, { data: buildEmailCardWidgetData(activity) })
188
+ }
189
+ ) : null,
158
190
  snippet ? /* @__PURE__ */ jsx("p", { className: "mt-2 text-sm text-muted-foreground", children: snippet }) : null,
159
191
  /* @__PURE__ */ jsxs("div", { className: "mt-3 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground", children: [
160
192
  /* @__PURE__ */ jsx(Avatar, { label: actorLabel, size: "xs", variant: "monochrome" }),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/modules/customers/components/detail/ActivityCard.tsx"],
4
- "sourcesContent": ["'use client'\n\nimport * as React from 'react'\nimport { Calendar, Check, ExternalLink, ListTodo, Mail, MoreHorizontal, Phone, StickyNote, Users } from 'lucide-react'\nimport { Avatar } from '@open-mercato/ui/primitives/avatar'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { IconButton } from '@open-mercato/ui/primitives/icon-button'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { apiCallOrThrow } from '@open-mercato/ui/backend/utils/apiCall'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { cn } from '@open-mercato/shared/lib/utils'\nimport type { InteractionSummary } from './types'\nimport { ActivityAiActions } from './ActivityAiActions'\n\ntype GuardedMutationRunner = <T,>(\n operation: () => Promise<T>,\n mutationPayload?: Record<string, unknown>,\n) => Promise<T>\n\ntype ActivityCardProps = {\n activity: InteractionSummary\n onOpen?: (activity: InteractionSummary) => void\n /** Called after a successful mark-done so the parent can refresh the timeline. */\n onChanged?: () => void\n /**\n * Optional guarded-mutation runner. When provided, mutations route through the parent's\n * `useGuardedMutation` so retry-last-mutation and the global injection contract apply.\n * When omitted, mutations run directly via `apiCallOrThrow` (e.g. read-only contexts\n * or jest unit tests that don't supply a guarded runner).\n */\n runMutation?: GuardedMutationRunner\n}\n\nconst TYPE_ICONS: Record<string, React.ComponentType<{ className?: string }>> = {\n call: Phone,\n email: Mail,\n meeting: Users,\n note: StickyNote,\n task: ListTodo,\n}\n\nfunction formatDayLabel(value: string, t: ReturnType<typeof useT>): string {\n const date = new Date(value)\n if (Number.isNaN(date.getTime())) return ''\n const now = new Date()\n const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime()\n const day = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime()\n const diffDays = Math.round((today - day) / 86400000)\n if (diffDays === 0) return t('customers.timeline.date.today', 'today')\n if (diffDays === 1) return t('customers.timeline.date.yesterday', 'yesterday')\n return date.toLocaleDateString(undefined, { day: 'numeric', month: 'short' })\n}\n\nfunction formatTimeLabel(value: string): string {\n const date = new Date(value)\n if (Number.isNaN(date.getTime())) return ''\n return date.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' })\n}\n\nfunction trimSnippet(value: string | null | undefined): string | null {\n const normalized = value?.trim()\n if (!normalized) return null\n if (normalized.length <= 200) return normalized\n return `${normalized.slice(0, 197)}...`\n}\n\nfunction resolveTarget(activity: InteractionSummary): string | null {\n const participant = activity.participants?.find((item) => item.name || item.email)\n if (participant?.name) return participant.name\n if (participant?.email) return participant.email\n if (activity.customer?.displayName) return activity.customer.displayName\n return null\n}\n\nexport function ActivityCard({ activity, onOpen, onChanged, runMutation }: ActivityCardProps) {\n const t = useT()\n const timestamp = activity.occurredAt ?? activity.scheduledAt ?? activity.createdAt\n const TypeIcon = TYPE_ICONS[activity.interactionType] ?? StickyNote\n const titleBase = activity.title ?? activity.body ?? activity.interactionType\n const title = activity.duration ? `${titleBase} (${activity.duration} min)` : titleBase\n const snippet = trimSnippet(activity.body && activity.title ? activity.body : activity.body ?? null)\n const actorLabel = activity.authorName ?? activity.authorEmail ?? t('customers.changelog.user.system', 'System')\n const target = resolveTarget(activity)\n const direction = activity.interactionType === 'email'\n ? t('customers.activityLog.direction.to', 'to')\n : activity.interactionType === 'call' || activity.interactionType === 'meeting'\n ? t('customers.activityLog.direction.with', 'with')\n : ''\n const showExternalLink = Boolean(activity._integrations && Object.keys(activity._integrations).length > 0)\n const [markingDone, setMarkingDone] = React.useState(false)\n\n const handleMarkDone = React.useCallback(async () => {\n if (markingDone) return\n setMarkingDone(true)\n try {\n const operation = () =>\n apiCallOrThrow('/api/customers/interactions/complete', {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ id: activity.id, occurredAt: new Date().toISOString() }),\n })\n if (runMutation) {\n await runMutation(operation, {\n id: activity.id,\n status: 'done',\n operation: 'completeActivity',\n })\n } else {\n await operation()\n }\n flash(t('customers.activities.actions.markDoneSuccess', 'Activity marked done'), 'success')\n onChanged?.()\n } catch (err) {\n console.warn('[customers.activityCard] mark done failed', activity.id, err)\n flash(t('customers.activities.actions.markDoneError', 'Could not mark activity as done'), 'error')\n } finally {\n setMarkingDone(false)\n }\n }, [activity.id, markingDone, onChanged, runMutation, t])\n\n return (\n <div\n className={cn(\n 'grid gap-3',\n onOpen ? 'cursor-pointer' : '',\n )}\n style={{ gridTemplateColumns: '64px 36px minmax(0,1fr)' }}\n onClick={() => onOpen?.(activity)}\n role={onOpen ? 'button' : undefined}\n tabIndex={onOpen ? 0 : undefined}\n onKeyDown={onOpen ? (event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault()\n onOpen(activity)\n }\n } : undefined}\n >\n <div className=\"pt-1 text-xs text-muted-foreground\">\n <div className=\"font-semibold text-foreground\">{formatDayLabel(timestamp, t)}</div>\n <div>{formatTimeLabel(timestamp)}</div>\n </div>\n\n <div className=\"flex size-9 items-center justify-center rounded-lg bg-muted/80\">\n <TypeIcon className=\"size-4 text-muted-foreground\" />\n </div>\n\n <div className=\"rounded-xl border bg-card px-4 py-3 shadow-sm\">\n <div className=\"flex items-start justify-between gap-3\">\n <div className=\"min-w-0\">\n <div className=\"flex items-center gap-1.5\">\n <h4 className=\"truncate text-sm font-semibold text-foreground\">{title}</h4>\n {showExternalLink ? <ExternalLink className=\"size-3.5 text-muted-foreground\" /> : null}\n </div>\n {activity.location ? (\n <div className=\"mt-1 flex items-center gap-1 text-xs text-muted-foreground\">\n <Calendar className=\"size-3.5\" />\n <span className=\"truncate\">{activity.location}</span>\n </div>\n ) : null}\n </div>\n\n <div className=\"flex items-center gap-1.5\">\n {activity.status === 'planned' ? (\n <Button\n type=\"button\"\n variant=\"default\"\n size=\"sm\"\n disabled={markingDone}\n onClick={(event) => {\n event.stopPropagation()\n void handleMarkDone()\n }}\n >\n <Check className=\"size-3.5\" />\n {t('customers.activities.actions.markDone', 'Mark done')}\n </Button>\n ) : null}\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n aria-label={t('customers.timeline.more', 'More')}\n onClick={(event) => {\n event.stopPropagation()\n onOpen?.(activity)\n }}\n >\n <MoreHorizontal className=\"size-4\" />\n </IconButton>\n </div>\n </div>\n\n <div className=\"mt-2\">\n <ActivityAiActions activityType={activity.interactionType} />\n </div>\n\n {snippet ? (\n <p className=\"mt-2 text-sm text-muted-foreground\">{snippet}</p>\n ) : null}\n\n <div className=\"mt-3 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground\">\n <Avatar label={actorLabel} size=\"xs\" variant=\"monochrome\" />\n <span className=\"font-medium text-foreground\">{actorLabel}</span>\n {target && direction ? (\n <>\n <span>\u00B7</span>\n <span>{direction}</span>\n <span className=\"text-foreground\">{target}</span>\n </>\n ) : null}\n </div>\n </div>\n </div>\n )\n}\n\nexport default ActivityCard\n"],
5
- "mappings": ";AAyIM,SAmEM,UAlEJ,KADF;AAvIN,YAAY,WAAW;AACvB,SAAS,UAAU,OAAO,cAAc,UAAU,MAAM,gBAAgB,OAAO,YAAY,aAAa;AACxG,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AACrB,SAAS,UAAU;AAEnB,SAAS,yBAAyB;AAqBlC,MAAM,aAA0E;AAAA,EAC9E,MAAM;AAAA,EACN,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AACR;AAEA,SAAS,eAAe,OAAe,GAAoC;AACzE,QAAM,OAAO,IAAI,KAAK,KAAK;AAC3B,MAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,EAAG,QAAO;AACzC,QAAM,MAAM,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;AAAA,kBACR,MAAK;AAAA,kBACL,UAAU;AAAA,kBACV,SAAS,CAAC,UAAU;AAClB,0BAAM,gBAAgB;AACtB,yBAAK,eAAe;AAAA,kBACtB;AAAA,kBAEA;AAAA,wCAAC,SAAM,WAAU,YAAW;AAAA,oBAC3B,EAAE,yCAAyC,WAAW;AAAA;AAAA;AAAA,cACzD,IACE;AAAA,cACJ;AAAA,gBAAC;AAAA;AAAA,kBACC,MAAK;AAAA,kBACL,SAAQ;AAAA,kBACR,MAAK;AAAA,kBACL,cAAY,EAAE,2BAA2B,MAAM;AAAA,kBAC/C,SAAS,CAAC,UAAU;AAClB,0BAAM,gBAAgB;AACtB,6BAAS,QAAQ;AAAA,kBACnB;AAAA,kBAEA,8BAAC,kBAAe,WAAU,UAAS;AAAA;AAAA,cACrC;AAAA,eACF;AAAA,aACF;AAAA,UAEA,oBAAC,SAAI,WAAU,QACb,8BAAC,qBAAkB,cAAc,SAAS,iBAAiB,GAC7D;AAAA,UAEC,UACC,oBAAC,OAAE,WAAU,sCAAsC,mBAAQ,IACzD;AAAA,UAEJ,qBAAC,SAAI,WAAU,0EACb;AAAA,gCAAC,UAAO,OAAO,YAAY,MAAK,MAAK,SAAQ,cAAa;AAAA,YAC1D,oBAAC,UAAK,WAAU,+BAA+B,sBAAW;AAAA,YACzD,UAAU,YACT,iCACE;AAAA,kCAAC,UAAK,kBAAC;AAAA,cACP,oBAAC,UAAM,qBAAU;AAAA,cACjB,oBAAC,UAAK,WAAU,mBAAmB,kBAAO;AAAA,eAC5C,IACE;AAAA,aACN;AAAA,WACF;AAAA;AAAA;AAAA,EACF;AAEJ;AAEA,IAAO,uBAAQ;",
4
+ "sourcesContent": ["'use client'\n\nimport * as React from 'react'\nimport { Calendar, Check, ExternalLink, ListTodo, Mail, MoreHorizontal, Phone, StickyNote, Users } from 'lucide-react'\nimport { Avatar } from '@open-mercato/ui/primitives/avatar'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { IconButton } from '@open-mercato/ui/primitives/icon-button'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { apiCallOrThrow } from '@open-mercato/ui/backend/utils/apiCall'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { cn } from '@open-mercato/shared/lib/utils'\nimport type { InteractionSummary } from './types'\nimport { ActivityAiActions } from './ActivityAiActions'\nimport { EmailCardActions, type EmailCardWidgetData } from './EmailCardActions'\n\ntype GuardedMutationRunner = <T,>(\n operation: () => Promise<T>,\n mutationPayload?: Record<string, unknown>,\n) => Promise<T>\n\ntype ActivityCardProps = {\n activity: InteractionSummary\n onOpen?: (activity: InteractionSummary) => void\n /** Called after a successful mark-done so the parent can refresh the timeline. */\n onChanged?: () => void\n /**\n * Optional guarded-mutation runner. When provided, mutations route through the parent's\n * `useGuardedMutation` so retry-last-mutation and the global injection contract apply.\n * When omitted, mutations run directly via `apiCallOrThrow` (e.g. read-only contexts\n * or jest unit tests that don't supply a guarded runner).\n */\n runMutation?: GuardedMutationRunner\n}\n\nconst TYPE_ICONS: Record<string, React.ComponentType<{ className?: string }>> = {\n call: Phone,\n email: Mail,\n meeting: Users,\n note: StickyNote,\n task: ListTodo,\n}\n\nfunction formatDayLabel(value: string, t: ReturnType<typeof useT>): string {\n const date = new Date(value)\n if (Number.isNaN(date.getTime())) return ''\n const now = new Date()\n const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime()\n const day = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime()\n const diffDays = Math.round((today - day) / 86400000)\n if (diffDays === 0) return t('customers.timeline.date.today', 'today')\n if (diffDays === 1) return t('customers.timeline.date.yesterday', 'yesterday')\n return date.toLocaleDateString(undefined, { day: 'numeric', month: 'short' })\n}\n\nfunction formatTimeLabel(value: string): string {\n const date = new Date(value)\n if (Number.isNaN(date.getTime())) return ''\n return date.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' })\n}\n\nfunction trimSnippet(value: string | null | undefined): string | null {\n const normalized = value?.trim()\n if (!normalized) return null\n if (normalized.length <= 200) return normalized\n return `${normalized.slice(0, 197)}...`\n}\n\nfunction resolveTarget(activity: InteractionSummary): string | null {\n const participant = activity.participants?.find((item) => item.name || item.email)\n if (participant?.name) return participant.name\n if (participant?.email) return participant.email\n if (activity.customer?.displayName) return activity.customer.displayName\n return null\n}\n\n/**\n * Build the `EmailCardWidgetData` for the email-card-actions injection spot.\n * Email metadata (rfcMessageId, addresses, threading headers, current visibility,\n * and the author flag) is populated server-side by `interactionEmailCardEnricher`\n * and surfaced via the `_integrations.email` passthrough; missing values fall\n * back to null.\n */\nfunction buildEmailCardWidgetData(activity: InteractionSummary): EmailCardWidgetData {\n const integrations = activity._integrations as Record<string, unknown> | undefined\n const emailMeta = (integrations?.email ?? {}) as Record<string, unknown>\n return {\n interactionId: activity.id,\n // The MessageChannelLink UUID stored on the interaction row.\n externalMessageId:\n typeof emailMeta.externalMessageId === 'string' ? emailMeta.externalMessageId : null,\n // RFC2822 Message-ID (e.g. \"<abc@mail.gmail.com>\") for In-Reply-To / References headers.\n rfcMessageId:\n typeof emailMeta.rfcMessageId === 'string' ? emailMeta.rfcMessageId : null,\n // entityId is the CustomerEntity id \u2014 on a person detail page this IS the personId.\n personId: activity.entityId ?? null,\n fromAddress:\n typeof emailMeta.fromAddress === 'string' ? emailMeta.fromAddress : null,\n toAddresses: Array.isArray(emailMeta.toAddresses) ? (emailMeta.toAddresses as string[]) : null,\n ccAddresses: Array.isArray(emailMeta.ccAddresses) ? (emailMeta.ccAddresses as string[]) : null,\n subject: activity.title ?? null,\n inReplyTo:\n typeof emailMeta.inReplyTo === 'string' ? emailMeta.inReplyTo : null,\n references: Array.isArray(emailMeta.references) ? (emailMeta.references as string[]) : null,\n currentVisibility:\n emailMeta.currentVisibility === 'private' || emailMeta.currentVisibility === 'shared'\n ? emailMeta.currentVisibility\n : null,\n isAuthor: typeof emailMeta.isAuthor === 'boolean' ? emailMeta.isAuthor : null,\n }\n}\n\nexport function ActivityCard({ activity, onOpen, onChanged, runMutation }: ActivityCardProps) {\n const t = useT()\n const timestamp = activity.occurredAt ?? activity.scheduledAt ?? activity.createdAt\n const TypeIcon = TYPE_ICONS[activity.interactionType] ?? StickyNote\n const titleBase = activity.title ?? activity.body ?? activity.interactionType\n const title = activity.duration ? `${titleBase} (${activity.duration} min)` : titleBase\n const snippet = trimSnippet(activity.body && activity.title ? activity.body : activity.body ?? null)\n const actorLabel = activity.authorName ?? activity.authorEmail ?? t('customers.changelog.user.system', 'System')\n const target = resolveTarget(activity)\n const direction = activity.interactionType === 'email'\n ? t('customers.activityLog.direction.to', 'to')\n : activity.interactionType === 'call' || activity.interactionType === 'meeting'\n ? t('customers.activityLog.direction.with', 'with')\n : ''\n const showExternalLink = Boolean(activity._integrations && Object.keys(activity._integrations).length > 0)\n const [markingDone, setMarkingDone] = React.useState(false)\n\n const handleMarkDone = React.useCallback(async () => {\n if (markingDone) return\n setMarkingDone(true)\n try {\n const operation = () =>\n apiCallOrThrow('/api/customers/interactions/complete', {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ id: activity.id, occurredAt: new Date().toISOString() }),\n })\n if (runMutation) {\n await runMutation(operation, {\n id: activity.id,\n status: 'done',\n operation: 'completeActivity',\n })\n } else {\n await operation()\n }\n flash(t('customers.activities.actions.markDoneSuccess', 'Activity marked done'), 'success')\n onChanged?.()\n } catch (err) {\n console.warn('[customers.activityCard] mark done failed', activity.id, err)\n flash(t('customers.activities.actions.markDoneError', 'Could not mark activity as done'), 'error')\n } finally {\n setMarkingDone(false)\n }\n }, [activity.id, markingDone, onChanged, runMutation, t])\n\n return (\n <div\n className={cn(\n 'grid gap-3',\n onOpen ? 'cursor-pointer' : '',\n )}\n style={{ gridTemplateColumns: '64px 36px minmax(0,1fr)' }}\n onClick={() => onOpen?.(activity)}\n role={onOpen ? 'button' : undefined}\n tabIndex={onOpen ? 0 : undefined}\n onKeyDown={onOpen ? (event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault()\n onOpen(activity)\n }\n } : undefined}\n >\n <div className=\"pt-1 text-xs text-muted-foreground\">\n <div className=\"font-semibold text-foreground\">{formatDayLabel(timestamp, t)}</div>\n <div>{formatTimeLabel(timestamp)}</div>\n </div>\n\n <div className=\"flex size-9 items-center justify-center rounded-lg bg-muted/80\">\n <TypeIcon className=\"size-4 text-muted-foreground\" />\n </div>\n\n <div className=\"rounded-xl border bg-card px-4 py-3 shadow-sm\">\n <div className=\"flex items-start justify-between gap-3\">\n <div className=\"min-w-0\">\n <div className=\"flex items-center gap-1.5\">\n <h4 className=\"truncate text-sm font-semibold text-foreground\">{title}</h4>\n {showExternalLink ? <ExternalLink className=\"size-3.5 text-muted-foreground\" /> : null}\n </div>\n {activity.location ? (\n <div className=\"mt-1 flex items-center gap-1 text-xs text-muted-foreground\">\n <Calendar className=\"size-3.5\" />\n <span className=\"truncate\">{activity.location}</span>\n </div>\n ) : null}\n </div>\n\n <div className=\"flex items-center gap-1.5\">\n {activity.status === 'planned' ? (\n <Button\n type=\"button\"\n variant=\"default\"\n size=\"sm\"\n disabled={markingDone}\n onClick={(event) => {\n event.stopPropagation()\n void handleMarkDone()\n }}\n >\n <Check className=\"size-3.5\" />\n {t('customers.activities.actions.markDone', 'Mark done')}\n </Button>\n ) : null}\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n aria-label={t('customers.timeline.more', 'More')}\n onClick={(event) => {\n event.stopPropagation()\n onOpen?.(activity)\n }}\n >\n <MoreHorizontal className=\"size-4\" />\n </IconButton>\n </div>\n </div>\n\n <div className=\"mt-2\">\n <ActivityAiActions activityType={activity.interactionType} />\n </div>\n\n {activity.interactionType === 'email' ? (\n <div\n className=\"mt-1\"\n onClick={(event) => event.stopPropagation()}\n onKeyDown={(event) => event.stopPropagation()}\n role=\"presentation\"\n >\n <EmailCardActions data={buildEmailCardWidgetData(activity)} />\n </div>\n ) : null}\n\n {snippet ? (\n <p className=\"mt-2 text-sm text-muted-foreground\">{snippet}</p>\n ) : null}\n\n <div className=\"mt-3 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground\">\n <Avatar label={actorLabel} size=\"xs\" variant=\"monochrome\" />\n <span className=\"font-medium text-foreground\">{actorLabel}</span>\n {target && direction ? (\n <>\n <span>\u00B7</span>\n <span>{direction}</span>\n <span className=\"text-foreground\">{target}</span>\n </>\n ) : null}\n </div>\n </div>\n </div>\n )\n}\n\nexport default ActivityCard\n"],
5
+ "mappings": ";AA8KM,SA8EM,UA7EJ,KADF;AA5KN,YAAY,WAAW;AACvB,SAAS,UAAU,OAAO,cAAc,UAAU,MAAM,gBAAgB,OAAO,YAAY,aAAa;AACxG,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AACrB,SAAS,UAAU;AAEnB,SAAS,yBAAyB;AAClC,SAAS,wBAAkD;AAqB3D,MAAM,aAA0E;AAAA,EAC9E,MAAM;AAAA,EACN,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AACR;AAEA,SAAS,eAAe,OAAe,GAAoC;AACzE,QAAM,OAAO,IAAI,KAAK,KAAK;AAC3B,MAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,EAAG,QAAO;AACzC,QAAM,MAAM,oBAAI,KAAK;AACrB,QAAM,QAAQ,IAAI,KAAK,IAAI,YAAY,GAAG,IAAI,SAAS,GAAG,IAAI,QAAQ,CAAC,EAAE,QAAQ;AACjF,QAAM,MAAM,IAAI,KAAK,KAAK,YAAY,GAAG,KAAK,SAAS,GAAG,KAAK,QAAQ,CAAC,EAAE,QAAQ;AAClF,QAAM,WAAW,KAAK,OAAO,QAAQ,OAAO,KAAQ;AACpD,MAAI,aAAa,EAAG,QAAO,EAAE,iCAAiC,OAAO;AACrE,MAAI,aAAa,EAAG,QAAO,EAAE,qCAAqC,WAAW;AAC7E,SAAO,KAAK,mBAAmB,QA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