@open-mercato/core 0.5.1-develop.2691.d8a0934b37 → 0.5.1-develop.2694.732417c5ec

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 (414) hide show
  1. package/dist/modules/api_keys/data/entities.js +1 -1
  2. package/dist/modules/api_keys/data/entities.js.map +1 -1
  3. package/dist/modules/api_keys/services/apiKeyService.js +5 -5
  4. package/dist/modules/api_keys/services/apiKeyService.js.map +2 -2
  5. package/dist/modules/attachments/api/library/[id]/route.js +1 -1
  6. package/dist/modules/attachments/api/library/[id]/route.js.map +2 -2
  7. package/dist/modules/attachments/api/library/route.js +7 -9
  8. package/dist/modules/attachments/api/library/route.js.map +2 -2
  9. package/dist/modules/attachments/api/partitions/route.js +3 -3
  10. package/dist/modules/attachments/api/partitions/route.js.map +2 -2
  11. package/dist/modules/attachments/api/route.js +6 -5
  12. package/dist/modules/attachments/api/route.js.map +2 -2
  13. package/dist/modules/attachments/api/transfer/route.js +1 -1
  14. package/dist/modules/attachments/api/transfer/route.js.map +2 -2
  15. package/dist/modules/attachments/data/entities.js +2 -1
  16. package/dist/modules/attachments/data/entities.js.map +2 -2
  17. package/dist/modules/attachments/lib/ocrQueue.js +1 -1
  18. package/dist/modules/attachments/lib/ocrQueue.js.map +2 -2
  19. package/dist/modules/audit_logs/api/audit-logs/actions/export/route.js.map +2 -2
  20. package/dist/modules/audit_logs/api/audit-logs/actions/route.js.map +2 -2
  21. package/dist/modules/audit_logs/data/entities.js +1 -1
  22. package/dist/modules/audit_logs/data/entities.js.map +1 -1
  23. package/dist/modules/audit_logs/services/actionLogService.js +77 -70
  24. package/dist/modules/audit_logs/services/actionLogService.js.map +2 -2
  25. package/dist/modules/auth/api/roles/acl/route.js +1 -1
  26. package/dist/modules/auth/api/roles/acl/route.js.map +2 -2
  27. package/dist/modules/auth/api/users/acl/route.js +2 -2
  28. package/dist/modules/auth/api/users/acl/route.js.map +2 -2
  29. package/dist/modules/auth/api/users/resend-invite/route.js +1 -1
  30. package/dist/modules/auth/api/users/resend-invite/route.js.map +2 -2
  31. package/dist/modules/auth/cli.js +12 -6
  32. package/dist/modules/auth/cli.js.map +2 -2
  33. package/dist/modules/auth/commands/users.js +1 -1
  34. package/dist/modules/auth/commands/users.js.map +2 -2
  35. package/dist/modules/auth/data/entities.js +1 -1
  36. package/dist/modules/auth/data/entities.js.map +2 -2
  37. package/dist/modules/auth/lib/setup-app.js +3 -3
  38. package/dist/modules/auth/lib/setup-app.js.map +2 -2
  39. package/dist/modules/auth/services/authService.js +2 -2
  40. package/dist/modules/auth/services/authService.js.map +2 -2
  41. package/dist/modules/business_rules/api/rules/route.js +3 -3
  42. package/dist/modules/business_rules/api/rules/route.js.map +2 -2
  43. package/dist/modules/business_rules/api/sets/[id]/members/route.js +7 -4
  44. package/dist/modules/business_rules/api/sets/[id]/members/route.js.map +2 -2
  45. package/dist/modules/business_rules/api/sets/route.js +3 -3
  46. package/dist/modules/business_rules/api/sets/route.js.map +2 -2
  47. package/dist/modules/business_rules/cli.js +1 -1
  48. package/dist/modules/business_rules/cli.js.map +2 -2
  49. package/dist/modules/business_rules/data/entities.js +2 -9
  50. package/dist/modules/business_rules/data/entities.js.map +2 -2
  51. package/dist/modules/business_rules/lib/rule-engine.js +1 -1
  52. package/dist/modules/business_rules/lib/rule-engine.js.map +2 -2
  53. package/dist/modules/catalog/api/option-schemas/route.js +0 -1
  54. package/dist/modules/catalog/api/option-schemas/route.js.map +2 -2
  55. package/dist/modules/catalog/data/entities.js +2 -11
  56. package/dist/modules/catalog/data/entities.js.map +2 -2
  57. package/dist/modules/configs/data/entities.js +2 -1
  58. package/dist/modules/configs/data/entities.js.map +2 -2
  59. package/dist/modules/currencies/commands/fetch-configs.js +3 -3
  60. package/dist/modules/currencies/commands/fetch-configs.js.map +2 -2
  61. package/dist/modules/currencies/data/entities.js +1 -1
  62. package/dist/modules/currencies/data/entities.js.map +2 -2
  63. package/dist/modules/customer_accounts/api/signup.js +1 -1
  64. package/dist/modules/customer_accounts/api/signup.js.map +2 -2
  65. package/dist/modules/customer_accounts/data/entities.js +1 -1
  66. package/dist/modules/customer_accounts/data/entities.js.map +2 -2
  67. package/dist/modules/customer_accounts/services/customerInvitationService.js +1 -1
  68. package/dist/modules/customer_accounts/services/customerInvitationService.js.map +2 -2
  69. package/dist/modules/customer_accounts/services/customerSessionService.js +1 -1
  70. package/dist/modules/customer_accounts/services/customerSessionService.js.map +2 -2
  71. package/dist/modules/customer_accounts/services/customerTokenService.js +12 -7
  72. package/dist/modules/customer_accounts/services/customerTokenService.js.map +2 -2
  73. package/dist/modules/customers/api/interactions/conflicts/route.js +19 -17
  74. package/dist/modules/customers/api/interactions/conflicts/route.js.map +2 -2
  75. package/dist/modules/customers/api/interactions/counts/route.js +7 -6
  76. package/dist/modules/customers/api/interactions/counts/route.js.map +2 -2
  77. package/dist/modules/customers/api/interactions/route.js +28 -42
  78. package/dist/modules/customers/api/interactions/route.js.map +2 -2
  79. package/dist/modules/customers/api/utils.js +29 -24
  80. package/dist/modules/customers/api/utils.js.map +2 -2
  81. package/dist/modules/customers/cli.js +45 -40
  82. package/dist/modules/customers/cli.js.map +2 -2
  83. package/dist/modules/customers/commands/dictionaries.js +1 -1
  84. package/dist/modules/customers/commands/dictionaries.js.map +2 -2
  85. package/dist/modules/customers/commands/tags.js +1 -1
  86. package/dist/modules/customers/commands/tags.js.map +2 -2
  87. package/dist/modules/customers/data/entities.js +2 -12
  88. package/dist/modules/customers/data/entities.js.map +2 -2
  89. package/dist/modules/customers/lib/interactionProjection.js +18 -15
  90. package/dist/modules/customers/lib/interactionProjection.js.map +2 -2
  91. package/dist/modules/customers/lib/personCompanyLinkTable.js +6 -8
  92. package/dist/modules/customers/lib/personCompanyLinkTable.js.map +2 -2
  93. package/dist/modules/dashboards/api/roles/widgets/route.js +1 -1
  94. package/dist/modules/dashboards/api/roles/widgets/route.js.map +2 -2
  95. package/dist/modules/dashboards/api/users/widgets/route.js +1 -1
  96. package/dist/modules/dashboards/api/users/widgets/route.js.map +2 -2
  97. package/dist/modules/dashboards/data/entities.js +1 -1
  98. package/dist/modules/dashboards/data/entities.js.map +1 -1
  99. package/dist/modules/data_sync/api/mappings/route.js +1 -1
  100. package/dist/modules/data_sync/api/mappings/route.js.map +2 -2
  101. package/dist/modules/data_sync/data/entities.js +2 -1
  102. package/dist/modules/data_sync/data/entities.js.map +2 -2
  103. package/dist/modules/data_sync/lib/id-mapping.js +1 -1
  104. package/dist/modules/data_sync/lib/id-mapping.js.map +2 -2
  105. package/dist/modules/data_sync/lib/sync-run-service.js +1 -1
  106. package/dist/modules/data_sync/lib/sync-run-service.js.map +2 -2
  107. package/dist/modules/dictionaries/commands/factory.js +1 -1
  108. package/dist/modules/dictionaries/commands/factory.js.map +2 -2
  109. package/dist/modules/dictionaries/data/entities.js +2 -9
  110. package/dist/modules/dictionaries/data/entities.js.map +2 -2
  111. package/dist/modules/directory/commands/organizations.js +4 -4
  112. package/dist/modules/directory/commands/organizations.js.map +2 -2
  113. package/dist/modules/directory/data/entities.js +2 -1
  114. package/dist/modules/directory/data/entities.js.map +2 -2
  115. package/dist/modules/entities/api/definitions.js +2 -2
  116. package/dist/modules/entities/api/definitions.js.map +2 -2
  117. package/dist/modules/entities/api/encryption.js +2 -2
  118. package/dist/modules/entities/api/encryption.js.map +2 -2
  119. package/dist/modules/entities/api/relations/options.js +2 -2
  120. package/dist/modules/entities/api/relations/options.js.map +2 -2
  121. package/dist/modules/entities/cli.js +4 -4
  122. package/dist/modules/entities/cli.js.map +2 -2
  123. package/dist/modules/entities/data/entities.js +1 -1
  124. package/dist/modules/entities/data/entities.js.map +2 -2
  125. package/dist/modules/entities/lib/field-definitions.js +2 -2
  126. package/dist/modules/entities/lib/field-definitions.js.map +2 -2
  127. package/dist/modules/entities/lib/register.js +1 -1
  128. package/dist/modules/entities/lib/register.js.map +2 -2
  129. package/dist/modules/feature_toggles/data/entities.js +2 -9
  130. package/dist/modules/feature_toggles/data/entities.js.map +2 -2
  131. package/dist/modules/inbox_ops/api/proposals/counts/route.js +3 -6
  132. package/dist/modules/inbox_ops/api/proposals/counts/route.js.map +2 -2
  133. package/dist/modules/inbox_ops/data/entities.js +2 -8
  134. package/dist/modules/inbox_ops/data/entities.js.map +2 -2
  135. package/dist/modules/inbox_ops/lib/messagesIntegration.js +6 -6
  136. package/dist/modules/inbox_ops/lib/messagesIntegration.js.map +2 -2
  137. package/dist/modules/integrations/data/entities.js +2 -1
  138. package/dist/modules/integrations/data/entities.js.map +2 -2
  139. package/dist/modules/integrations/lib/credentials-service.js +1 -1
  140. package/dist/modules/integrations/lib/credentials-service.js.map +2 -2
  141. package/dist/modules/integrations/lib/log-service.js +1 -1
  142. package/dist/modules/integrations/lib/log-service.js.map +2 -2
  143. package/dist/modules/integrations/lib/state-service.js +1 -1
  144. package/dist/modules/integrations/lib/state-service.js.map +2 -2
  145. package/dist/modules/messages/api/route.js +90 -93
  146. package/dist/modules/messages/api/route.js.map +2 -2
  147. package/dist/modules/messages/api/unread-count/route.js +8 -7
  148. package/dist/modules/messages/api/unread-count/route.js.map +2 -2
  149. package/dist/modules/messages/commands/confirmations.js +1 -1
  150. package/dist/modules/messages/commands/confirmations.js.map +2 -2
  151. package/dist/modules/messages/commands/messages.js +3 -3
  152. package/dist/modules/messages/commands/messages.js.map +2 -2
  153. package/dist/modules/messages/data/entities.js +2 -1
  154. package/dist/modules/messages/data/entities.js.map +2 -2
  155. package/dist/modules/messages/lib/email-sender.js +1 -1
  156. package/dist/modules/messages/lib/email-sender.js.map +2 -2
  157. package/dist/modules/messages/lib/searchLookup.js +8 -8
  158. package/dist/modules/messages/lib/searchLookup.js.map +2 -2
  159. package/dist/modules/messages/lib/tokenConsumption.js +9 -4
  160. package/dist/modules/messages/lib/tokenConsumption.js.map +2 -2
  161. package/dist/modules/notifications/data/entities.js +2 -1
  162. package/dist/modules/notifications/data/entities.js.map +2 -2
  163. package/dist/modules/notifications/lib/notificationRecipients.js +15 -5
  164. package/dist/modules/notifications/lib/notificationRecipients.js.map +2 -2
  165. package/dist/modules/notifications/lib/notificationService.js +39 -34
  166. package/dist/modules/notifications/lib/notificationService.js.map +2 -2
  167. package/dist/modules/notifications/workers/create-notification.worker.js +14 -13
  168. package/dist/modules/notifications/workers/create-notification.worker.js.map +2 -2
  169. package/dist/modules/payment_gateways/api/transactions/route.js +2 -2
  170. package/dist/modules/payment_gateways/api/transactions/route.js.map +2 -2
  171. package/dist/modules/payment_gateways/data/entities.js +2 -1
  172. package/dist/modules/payment_gateways/data/entities.js.map +2 -2
  173. package/dist/modules/payment_gateways/lib/gateway-service.js +1 -1
  174. package/dist/modules/payment_gateways/lib/gateway-service.js.map +2 -2
  175. package/dist/modules/payment_gateways/lib/webhook-utils.js +2 -2
  176. package/dist/modules/payment_gateways/lib/webhook-utils.js.map +2 -2
  177. package/dist/modules/perspectives/data/entities.js +1 -1
  178. package/dist/modules/perspectives/data/entities.js.map +2 -2
  179. package/dist/modules/planner/data/entities.js +1 -1
  180. package/dist/modules/planner/data/entities.js.map +2 -2
  181. package/dist/modules/progress/data/entities.js +2 -1
  182. package/dist/modules/progress/data/entities.js.map +2 -2
  183. package/dist/modules/progress/lib/progressServiceImpl.js +1 -1
  184. package/dist/modules/progress/lib/progressServiceImpl.js.map +2 -2
  185. package/dist/modules/query_index/api/status.js +66 -57
  186. package/dist/modules/query_index/api/status.js.map +2 -2
  187. package/dist/modules/query_index/cli.js +39 -24
  188. package/dist/modules/query_index/cli.js.map +2 -2
  189. package/dist/modules/query_index/data/entities.js +1 -1
  190. package/dist/modules/query_index/data/entities.js.map +2 -2
  191. package/dist/modules/query_index/di.js +25 -13
  192. package/dist/modules/query_index/di.js.map +2 -2
  193. package/dist/modules/query_index/lib/batch.js +31 -33
  194. package/dist/modules/query_index/lib/batch.js.map +2 -2
  195. package/dist/modules/query_index/lib/coverage.js +63 -50
  196. package/dist/modules/query_index/lib/coverage.js.map +2 -2
  197. package/dist/modules/query_index/lib/engine.js +592 -588
  198. package/dist/modules/query_index/lib/engine.js.map +2 -2
  199. package/dist/modules/query_index/lib/indexer.js +74 -47
  200. package/dist/modules/query_index/lib/indexer.js.map +2 -2
  201. package/dist/modules/query_index/lib/jobs.js +37 -24
  202. package/dist/modules/query_index/lib/jobs.js.map +2 -2
  203. package/dist/modules/query_index/lib/purge.js +19 -11
  204. package/dist/modules/query_index/lib/purge.js.map +2 -2
  205. package/dist/modules/query_index/lib/reindexer.js +47 -44
  206. package/dist/modules/query_index/lib/reindexer.js.map +2 -2
  207. package/dist/modules/query_index/lib/search-tokens.js +47 -25
  208. package/dist/modules/query_index/lib/search-tokens.js.map +2 -2
  209. package/dist/modules/query_index/lib/stale.js +14 -12
  210. package/dist/modules/query_index/lib/stale.js.map +2 -2
  211. package/dist/modules/query_index/lib/subscriber-scope.js +2 -2
  212. package/dist/modules/query_index/lib/subscriber-scope.js.map +2 -2
  213. package/dist/modules/query_index/subscribers/delete_one.js +3 -2
  214. package/dist/modules/query_index/subscribers/delete_one.js.map +2 -2
  215. package/dist/modules/resources/commands/tag-assignments.js +1 -1
  216. package/dist/modules/resources/commands/tag-assignments.js.map +2 -2
  217. package/dist/modules/resources/commands/tags.js +1 -1
  218. package/dist/modules/resources/commands/tags.js.map +2 -2
  219. package/dist/modules/resources/data/entities.js +2 -1
  220. package/dist/modules/resources/data/entities.js.map +2 -2
  221. package/dist/modules/sales/commands/documentAddresses.js +2 -2
  222. package/dist/modules/sales/commands/documentAddresses.js.map +2 -2
  223. package/dist/modules/sales/commands/notes.js.map +2 -2
  224. package/dist/modules/sales/commands/tags.js +1 -1
  225. package/dist/modules/sales/commands/tags.js.map +2 -2
  226. package/dist/modules/sales/data/enrichers.js +9 -8
  227. package/dist/modules/sales/data/enrichers.js.map +2 -2
  228. package/dist/modules/sales/data/entities.js +2 -11
  229. package/dist/modules/sales/data/entities.js.map +2 -2
  230. package/dist/modules/shipping_carriers/data/entities.js +2 -1
  231. package/dist/modules/shipping_carriers/data/entities.js.map +2 -2
  232. package/dist/modules/shipping_carriers/lib/shipping-service.js +1 -1
  233. package/dist/modules/shipping_carriers/lib/shipping-service.js.map +2 -2
  234. package/dist/modules/shipping_carriers/lib/webhook-utils.js +2 -2
  235. package/dist/modules/shipping_carriers/lib/webhook-utils.js.map +2 -2
  236. package/dist/modules/staff/data/entities.js +1 -1
  237. package/dist/modules/staff/data/entities.js.map +2 -2
  238. package/dist/modules/translations/api/[entityType]/[entityId]/route.js +3 -5
  239. package/dist/modules/translations/api/[entityType]/[entityId]/route.js.map +2 -2
  240. package/dist/modules/translations/api/context.js +2 -2
  241. package/dist/modules/translations/api/context.js.map +2 -2
  242. package/dist/modules/translations/commands/translations.js +46 -39
  243. package/dist/modules/translations/commands/translations.js.map +2 -2
  244. package/dist/modules/translations/components/TranslationManager.js +19 -10
  245. package/dist/modules/translations/components/TranslationManager.js.map +2 -2
  246. package/dist/modules/translations/data/entities.js +1 -1
  247. package/dist/modules/translations/data/entities.js.map +2 -2
  248. package/dist/modules/translations/lib/apply.js +4 -4
  249. package/dist/modules/translations/lib/apply.js.map +2 -2
  250. package/dist/modules/translations/lib/batch.js +3 -2
  251. package/dist/modules/translations/lib/batch.js.map +2 -2
  252. package/dist/modules/translations/subscribers/cleanup.js +3 -5
  253. package/dist/modules/translations/subscribers/cleanup.js.map +2 -2
  254. package/dist/modules/workflows/api/definitions/route.js +1 -1
  255. package/dist/modules/workflows/api/definitions/route.js.map +2 -2
  256. package/dist/modules/workflows/cli.js +5 -5
  257. package/dist/modules/workflows/cli.js.map +2 -2
  258. package/dist/modules/workflows/data/entities.js +2 -1
  259. package/dist/modules/workflows/data/entities.js.map +2 -2
  260. package/dist/modules/workflows/lib/event-logger.js +2 -2
  261. package/dist/modules/workflows/lib/event-logger.js.map +2 -2
  262. package/dist/modules/workflows/lib/seeds.js +16 -1
  263. package/dist/modules/workflows/lib/seeds.js.map +2 -2
  264. package/dist/modules/workflows/lib/step-handler.js +3 -3
  265. package/dist/modules/workflows/lib/step-handler.js.map +2 -2
  266. package/dist/modules/workflows/lib/task-handler.js +1 -1
  267. package/dist/modules/workflows/lib/task-handler.js.map +2 -2
  268. package/dist/modules/workflows/lib/transition-handler.js +1 -1
  269. package/dist/modules/workflows/lib/transition-handler.js.map +2 -2
  270. package/dist/modules/workflows/lib/workflow-executor.js +2 -2
  271. package/dist/modules/workflows/lib/workflow-executor.js.map +2 -2
  272. package/jest.config.cjs +4 -2
  273. package/package.json +3 -3
  274. package/src/modules/api_keys/data/entities.ts +1 -1
  275. package/src/modules/api_keys/services/apiKeyService.ts +5 -5
  276. package/src/modules/attachments/api/library/[id]/route.ts +1 -1
  277. package/src/modules/attachments/api/library/route.ts +10 -12
  278. package/src/modules/attachments/api/partitions/route.ts +3 -3
  279. package/src/modules/attachments/api/route.ts +10 -8
  280. package/src/modules/attachments/api/transfer/route.ts +1 -1
  281. package/src/modules/attachments/data/entities.ts +2 -1
  282. package/src/modules/attachments/lib/ocrQueue.ts +1 -1
  283. package/src/modules/audit_logs/api/audit-logs/actions/export/route.ts +4 -4
  284. package/src/modules/audit_logs/api/audit-logs/actions/route.ts +4 -4
  285. package/src/modules/audit_logs/data/entities.ts +1 -1
  286. package/src/modules/audit_logs/services/actionLogService.ts +96 -87
  287. package/src/modules/auth/api/roles/acl/route.ts +1 -1
  288. package/src/modules/auth/api/users/acl/route.ts +2 -2
  289. package/src/modules/auth/api/users/resend-invite/route.ts +1 -1
  290. package/src/modules/auth/cli.ts +46 -40
  291. package/src/modules/auth/commands/users.ts +1 -1
  292. package/src/modules/auth/data/entities.ts +1 -1
  293. package/src/modules/auth/lib/setup-app.ts +3 -3
  294. package/src/modules/auth/services/authService.ts +2 -2
  295. package/src/modules/business_rules/api/rules/route.ts +3 -3
  296. package/src/modules/business_rules/api/sets/[id]/members/route.ts +7 -4
  297. package/src/modules/business_rules/api/sets/route.ts +3 -3
  298. package/src/modules/business_rules/cli.ts +1 -1
  299. package/src/modules/business_rules/data/entities.ts +2 -9
  300. package/src/modules/business_rules/lib/rule-engine.ts +1 -1
  301. package/src/modules/catalog/api/option-schemas/route.ts +0 -1
  302. package/src/modules/catalog/data/entities.ts +2 -11
  303. package/src/modules/configs/data/entities.ts +2 -1
  304. package/src/modules/currencies/commands/fetch-configs.ts +3 -3
  305. package/src/modules/currencies/data/entities.ts +1 -1
  306. package/src/modules/customer_accounts/api/signup.ts +1 -1
  307. package/src/modules/customer_accounts/data/entities.ts +1 -1
  308. package/src/modules/customer_accounts/services/customerInvitationService.ts +1 -1
  309. package/src/modules/customer_accounts/services/customerSessionService.ts +1 -1
  310. package/src/modules/customer_accounts/services/customerTokenService.ts +26 -15
  311. package/src/modules/customers/api/interactions/conflicts/route.ts +26 -23
  312. package/src/modules/customers/api/interactions/counts/route.ts +13 -11
  313. package/src/modules/customers/api/interactions/route.ts +32 -44
  314. package/src/modules/customers/api/utils.ts +45 -37
  315. package/src/modules/customers/cli.ts +88 -67
  316. package/src/modules/customers/commands/dictionaries.ts +1 -1
  317. package/src/modules/customers/commands/tags.ts +1 -1
  318. package/src/modules/customers/data/entities.ts +2 -12
  319. package/src/modules/customers/lib/interactionProjection.ts +36 -25
  320. package/src/modules/customers/lib/personCompanyLinkTable.ts +13 -18
  321. package/src/modules/dashboards/api/roles/widgets/route.ts +1 -1
  322. package/src/modules/dashboards/api/users/widgets/route.ts +1 -1
  323. package/src/modules/dashboards/data/entities.ts +1 -1
  324. package/src/modules/data_sync/api/mappings/route.ts +1 -1
  325. package/src/modules/data_sync/data/entities.ts +2 -1
  326. package/src/modules/data_sync/lib/id-mapping.ts +1 -1
  327. package/src/modules/data_sync/lib/sync-run-service.ts +1 -1
  328. package/src/modules/dictionaries/commands/factory.ts +1 -1
  329. package/src/modules/dictionaries/data/entities.ts +2 -9
  330. package/src/modules/directory/commands/organizations.ts +4 -4
  331. package/src/modules/directory/data/entities.ts +2 -1
  332. package/src/modules/entities/api/definitions.ts +2 -2
  333. package/src/modules/entities/api/encryption.ts +2 -2
  334. package/src/modules/entities/api/relations/options.ts +8 -3
  335. package/src/modules/entities/cli.ts +4 -4
  336. package/src/modules/entities/data/entities.ts +1 -1
  337. package/src/modules/entities/lib/field-definitions.ts +2 -2
  338. package/src/modules/entities/lib/register.ts +1 -1
  339. package/src/modules/feature_toggles/data/entities.ts +2 -9
  340. package/src/modules/inbox_ops/api/proposals/counts/route.ts +10 -10
  341. package/src/modules/inbox_ops/data/entities.ts +2 -8
  342. package/src/modules/inbox_ops/lib/messagesIntegration.ts +12 -11
  343. package/src/modules/integrations/data/entities.ts +2 -1
  344. package/src/modules/integrations/lib/credentials-service.ts +1 -1
  345. package/src/modules/integrations/lib/log-service.ts +1 -1
  346. package/src/modules/integrations/lib/state-service.ts +1 -1
  347. package/src/modules/messages/api/route.ts +134 -123
  348. package/src/modules/messages/api/unread-count/route.ts +19 -16
  349. package/src/modules/messages/commands/confirmations.ts +1 -1
  350. package/src/modules/messages/commands/messages.ts +3 -3
  351. package/src/modules/messages/data/entities.ts +2 -1
  352. package/src/modules/messages/lib/email-sender.ts +1 -1
  353. package/src/modules/messages/lib/searchLookup.ts +16 -13
  354. package/src/modules/messages/lib/tokenConsumption.ts +16 -8
  355. package/src/modules/notifications/data/entities.ts +2 -1
  356. package/src/modules/notifications/lib/notificationRecipients.ts +42 -26
  357. package/src/modules/notifications/lib/notificationService.ts +53 -42
  358. package/src/modules/notifications/workers/create-notification.worker.ts +20 -17
  359. package/src/modules/payment_gateways/api/transactions/route.ts +2 -2
  360. package/src/modules/payment_gateways/data/entities.ts +2 -1
  361. package/src/modules/payment_gateways/lib/gateway-service.ts +1 -1
  362. package/src/modules/payment_gateways/lib/webhook-utils.ts +2 -2
  363. package/src/modules/perspectives/data/entities.ts +1 -1
  364. package/src/modules/planner/data/entities.ts +1 -1
  365. package/src/modules/progress/data/entities.ts +2 -1
  366. package/src/modules/progress/lib/progressServiceImpl.ts +1 -1
  367. package/src/modules/query_index/api/status.ts +85 -71
  368. package/src/modules/query_index/cli.ts +51 -31
  369. package/src/modules/query_index/data/entities.ts +1 -1
  370. package/src/modules/query_index/di.ts +41 -16
  371. package/src/modules/query_index/lib/batch.ts +68 -55
  372. package/src/modules/query_index/lib/coverage.ts +115 -88
  373. package/src/modules/query_index/lib/engine.ts +1036 -1096
  374. package/src/modules/query_index/lib/indexer.ts +115 -79
  375. package/src/modules/query_index/lib/jobs.ts +51 -31
  376. package/src/modules/query_index/lib/purge.ts +25 -19
  377. package/src/modules/query_index/lib/reindexer.ts +97 -84
  378. package/src/modules/query_index/lib/search-tokens.ts +67 -36
  379. package/src/modules/query_index/lib/stale.ts +14 -17
  380. package/src/modules/query_index/lib/subscriber-scope.ts +6 -5
  381. package/src/modules/query_index/subscribers/delete_one.ts +9 -6
  382. package/src/modules/resources/commands/tag-assignments.ts +1 -1
  383. package/src/modules/resources/commands/tags.ts +1 -1
  384. package/src/modules/resources/data/entities.ts +2 -1
  385. package/src/modules/sales/commands/documentAddresses.ts +2 -2
  386. package/src/modules/sales/commands/notes.ts +1 -1
  387. package/src/modules/sales/commands/tags.ts +1 -1
  388. package/src/modules/sales/data/enrichers.ts +17 -13
  389. package/src/modules/sales/data/entities.ts +2 -11
  390. package/src/modules/shipping_carriers/data/entities.ts +2 -1
  391. package/src/modules/shipping_carriers/lib/shipping-service.ts +1 -1
  392. package/src/modules/shipping_carriers/lib/webhook-utils.ts +2 -2
  393. package/src/modules/staff/data/entities.ts +1 -1
  394. package/src/modules/translations/api/[entityType]/[entityId]/route.ts +14 -11
  395. package/src/modules/translations/api/context.ts +4 -4
  396. package/src/modules/translations/commands/translations.ts +116 -81
  397. package/src/modules/translations/components/TranslationManager.tsx +23 -14
  398. package/src/modules/translations/data/entities.ts +1 -1
  399. package/src/modules/translations/i18n/de.json +1 -0
  400. package/src/modules/translations/i18n/en.json +1 -0
  401. package/src/modules/translations/i18n/es.json +1 -0
  402. package/src/modules/translations/i18n/pl.json +1 -0
  403. package/src/modules/translations/lib/apply.ts +6 -6
  404. package/src/modules/translations/lib/batch.ts +9 -7
  405. package/src/modules/translations/subscribers/cleanup.ts +10 -11
  406. package/src/modules/workflows/api/definitions/route.ts +1 -1
  407. package/src/modules/workflows/cli.ts +5 -5
  408. package/src/modules/workflows/data/entities.ts +2 -1
  409. package/src/modules/workflows/lib/event-logger.ts +2 -2
  410. package/src/modules/workflows/lib/seeds.ts +16 -1
  411. package/src/modules/workflows/lib/step-handler.ts +3 -3
  412. package/src/modules/workflows/lib/task-handler.ts +1 -1
  413. package/src/modules/workflows/lib/transition-handler.ts +1 -1
  414. package/src/modules/workflows/lib/workflow-executor.ts +2 -2
@@ -2,6 +2,7 @@ import type { ModuleCli } from '@open-mercato/shared/modules/registry'
2
2
  import { createRequestContainer, type AppContainer } from '@open-mercato/shared/lib/di/container'
3
3
  import { randomUUID } from 'crypto'
4
4
  import type { EntityManager } from '@mikro-orm/postgresql'
5
+ import { type Kysely, sql } from 'kysely'
5
6
  import { Dictionary, DictionaryEntry, type DictionaryManagerVisibility } from '@open-mercato/core/modules/dictionaries/data/entities'
6
7
  import { installCustomEntitiesFromModules } from '@open-mercato/core/modules/entities/lib/install-from-ce'
7
8
  import type { CacheStrategy } from '@open-mercato/cache/types'
@@ -1855,12 +1856,18 @@ async function seedCustomerStressTest(
1855
1856
  const assignmentFlushThreshold = includeExtras ? 100 : 0
1856
1857
  const cfInsertBatchSize = 500
1857
1858
  const flushInterval = 100
1858
- const knex = em.getConnection().getKnex()
1859
- const entityIndexesColumns = await knex('entity_indexes')
1860
- .columnInfo()
1861
- .catch(() => ({} as Record<string, unknown>))
1862
- const hasColumn = (name: string) =>
1863
- Object.keys(entityIndexesColumns).some((col) => col.toLowerCase() === name.toLowerCase())
1859
+ const db = em.getKysely<any>() as any
1860
+ const entityIndexesColumnRows = await db
1861
+ .selectFrom('information_schema.columns')
1862
+ .select(['column_name'])
1863
+ .where(sql<boolean>`table_schema = current_schema()`)
1864
+ .where('table_name', '=', 'entity_indexes')
1865
+ .execute()
1866
+ .catch(() => [] as Array<{ column_name: string }>)
1867
+ const entityIndexesColumnSet = new Set<string>(
1868
+ entityIndexesColumnRows.map((row: any) => String(row.column_name).toLowerCase()),
1869
+ )
1870
+ const hasColumn = (name: string) => entityIndexesColumnSet.has(name.toLowerCase())
1864
1871
  const supportsOrgCoalesced = hasColumn('organization_id_coalesced')
1865
1872
 
1866
1873
  type PendingIndexDoc = {
@@ -1992,37 +1999,42 @@ async function seedCustomerStressTest(
1992
1999
  return
1993
2000
  }
1994
2001
  if (supportsOrgCoalesced) {
1995
- await trx('entity_indexes')
1996
- .insert(rows)
1997
- .onConflict(['entity_type', 'entity_id', 'organization_id_coalesced'])
1998
- .merge({
1999
- doc: trx.raw('excluded.doc'),
2000
- index_version: trx.raw('excluded.index_version'),
2001
- organization_id: trx.raw('excluded.organization_id'),
2002
- tenant_id: trx.raw('excluded.tenant_id'),
2003
- deleted_at: trx.raw('excluded.deleted_at'),
2004
- updated_at: trx.raw('excluded.updated_at'),
2005
- })
2002
+ await trx
2003
+ .insertInto('entity_indexes')
2004
+ .values(rows.map((row) => ({ ...row, doc: sql`${JSON.stringify(row.doc)}::jsonb` })))
2005
+ .onConflict((oc: any) => oc
2006
+ .columns(['entity_type', 'entity_id', 'organization_id_coalesced'])
2007
+ .doUpdateSet({
2008
+ doc: sql`excluded.doc`,
2009
+ index_version: sql`excluded.index_version`,
2010
+ organization_id: sql`excluded.organization_id`,
2011
+ tenant_id: sql`excluded.tenant_id`,
2012
+ deleted_at: sql`excluded.deleted_at`,
2013
+ updated_at: sql`excluded.updated_at`,
2014
+ }))
2015
+ .execute()
2006
2016
  } else {
2007
2017
  for (const row of rows) {
2008
- const updatePayload = {
2009
- doc: row.doc,
2010
- index_version: row.index_version,
2011
- organization_id: row.organization_id,
2012
- tenant_id: row.tenant_id,
2013
- updated_at: row.updated_at,
2014
- deleted_at: null as null,
2015
- }
2016
- const updated = await trx('entity_indexes')
2017
- .where({
2018
- entity_type: row.entity_type,
2019
- entity_id: row.entity_id,
2018
+ const updated = await trx
2019
+ .updateTable('entity_indexes')
2020
+ .set({
2021
+ doc: sql`${JSON.stringify(row.doc)}::jsonb`,
2022
+ index_version: row.index_version,
2020
2023
  organization_id: row.organization_id,
2021
- })
2022
- .update(updatePayload)
2023
- if (updated) continue
2024
+ tenant_id: row.tenant_id,
2025
+ updated_at: row.updated_at,
2026
+ deleted_at: null,
2027
+ } as any)
2028
+ .where('entity_type', '=', row.entity_type)
2029
+ .where('entity_id', '=', row.entity_id)
2030
+ .where('organization_id', row.organization_id === null ? 'is' : '=', row.organization_id as any)
2031
+ .executeTakeFirst() as { numUpdatedRows?: bigint | number } | undefined
2032
+ if (updated && Number(updated.numUpdatedRows ?? 0) > 0) continue
2024
2033
  try {
2025
- await trx('entity_indexes').insert(row)
2034
+ await trx.insertInto('entity_indexes').values({
2035
+ ...row,
2036
+ doc: sql`${JSON.stringify(row.doc)}::jsonb`,
2037
+ } as any).execute()
2026
2038
  } catch {
2027
2039
  // ignored: row inserted concurrently
2028
2040
  }
@@ -2129,7 +2141,7 @@ async function seedCustomerStressTest(
2129
2141
  created_at: timestamp,
2130
2142
  deleted_at: null,
2131
2143
  }))
2132
- await knex.insert(payload).into('custom_field_values')
2144
+ await db.insertInto('custom_field_values').values(payload).execute()
2133
2145
  }
2134
2146
  }
2135
2147
 
@@ -2292,11 +2304,14 @@ async function seedCustomerStressTest(
2292
2304
  const entityInsertBatchSize = 1000
2293
2305
  const contactsPerCompany = Math.max(1, Math.ceil(toCreate / companyCount))
2294
2306
 
2295
- await warnIfStressTestSchemaChanged(knex)
2307
+ await warnIfStressTestSchemaChanged(db)
2296
2308
 
2297
2309
  const insertRows = async (trx: any, table: string, rows: unknown[]) => {
2298
2310
  if (!rows.length) return
2299
- await trx.batchInsert(table, rows, entityInsertBatchSize)
2311
+ for (let i = 0; i < rows.length; i += entityInsertBatchSize) {
2312
+ const chunk = rows.slice(i, i + entityInsertBatchSize)
2313
+ await trx.insertInto(table).values(chunk as any).execute()
2314
+ }
2300
2315
  rows.length = 0
2301
2316
  }
2302
2317
 
@@ -2312,7 +2327,7 @@ async function seedCustomerStressTest(
2312
2327
  activityRows.length +
2313
2328
  commentRows.length
2314
2329
  if (pendingCount === 0) return
2315
- await knex.transaction(async (trx) => {
2330
+ await db.transaction().execute(async (trx: any) => {
2316
2331
  await insertRows(trx, 'customer_entities', customerEntityRows)
2317
2332
  await insertRows(trx, 'customer_companies', companyProfileRows)
2318
2333
  await insertRows(trx, 'customer_people', personProfileRows)
@@ -2751,15 +2766,17 @@ const STRESS_TEST_REQUIRED_COLUMNS: Record<string, readonly string[]> = {
2751
2766
  ],
2752
2767
  }
2753
2768
 
2754
- async function warnIfStressTestSchemaChanged(knex: any) {
2769
+ async function warnIfStressTestSchemaChanged(db: Kysely<any>) {
2755
2770
  try {
2756
2771
  const warnings: string[] = []
2757
2772
  for (const [table, requiredColumns] of Object.entries(STRESS_TEST_REQUIRED_COLUMNS)) {
2758
- const rows = await knex('information_schema.columns')
2773
+ const rows = await (db as any)
2774
+ .selectFrom('information_schema.columns')
2759
2775
  .select('column_name')
2760
- .whereRaw('table_schema = current_schema()')
2761
- .where({ table_name: table })
2762
- const existing = new Set(rows.map((row: { column_name: string }) => row.column_name))
2776
+ .where(sql<boolean>`table_schema = current_schema()`)
2777
+ .where('table_name', '=', table)
2778
+ .execute() as Array<{ column_name: string }>
2779
+ const existing = new Set(rows.map((row) => row.column_name))
2763
2780
  const missing = requiredColumns.filter((column) => !existing.has(column))
2764
2781
  if (missing.length) warnings.push(`${table}: missing ${missing.join(', ')}`)
2765
2782
  }
@@ -2969,7 +2986,7 @@ async function backfillInteractions(
2969
2986
  container: { resolve: (name: string) => unknown },
2970
2987
  args: SeedArgs,
2971
2988
  ): Promise<{ activitiesMigrated: number; todosMigrated: number; projectionsRecomputed: number; errors: number }> {
2972
- const knex = em.getKnex()
2989
+ const db = em.getKysely<any>() as any
2973
2990
  const { tenantId, organizationId } = args
2974
2991
 
2975
2992
  let activitiesMigrated = 0
@@ -2981,8 +2998,9 @@ async function backfillInteractions(
2981
2998
  // Step 1: Migrate activities → interactions
2982
2999
  console.log('[backfill] Migrating activities to interactions...')
2983
3000
  while (true) {
2984
- const activities = await knex('customer_activities')
2985
- .select(
3001
+ const activities = await db
3002
+ .selectFrom('customer_activities')
3003
+ .select([
2986
3004
  'customer_activities.id',
2987
3005
  'customer_activities.organization_id',
2988
3006
  'customer_activities.tenant_id',
@@ -2995,23 +3013,24 @@ async function backfillInteractions(
2995
3013
  'customer_activities.appearance_color',
2996
3014
  'customer_activities.entity_id',
2997
3015
  'customer_activities.deal_id',
2998
- )
2999
- .where('customer_activities.tenant_id', tenantId)
3000
- .andWhere('customer_activities.organization_id', organizationId)
3001
- .whereNotExists(
3002
- knex('customer_interactions')
3003
- .select(knex.raw('1'))
3004
- .whereRaw('customer_interactions.id = customer_activities.id')
3005
- )
3016
+ ])
3017
+ .where('customer_activities.tenant_id', '=', tenantId)
3018
+ .where('customer_activities.organization_id', '=', organizationId)
3019
+ .where((eb: any) => eb.not(eb.exists(
3020
+ eb.selectFrom('customer_interactions')
3021
+ .select(sql<number>`1`.as('one'))
3022
+ .whereRef('customer_interactions.id', '=', 'customer_activities.id')
3023
+ )))
3006
3024
  .orderBy('customer_activities.created_at', 'asc')
3007
3025
  .limit(BACKFILL_BATCH_SIZE)
3026
+ .execute() as any[]
3008
3027
 
3009
3028
  if (activities.length === 0) break
3010
3029
 
3011
3030
  for (const activity of activities) {
3012
3031
  try {
3013
3032
  const status = activity.occurred_at ? 'done' : 'planned'
3014
- await knex('customer_interactions').insert({
3033
+ await db.insertInto('customer_interactions').values({
3015
3034
  id: activity.id,
3016
3035
  organization_id: activity.organization_id,
3017
3036
  tenant_id: activity.tenant_id,
@@ -3029,7 +3048,7 @@ async function backfillInteractions(
3029
3048
  deal_id: activity.deal_id,
3030
3049
  created_at: new Date(),
3031
3050
  updated_at: new Date(),
3032
- })
3051
+ } as any).execute()
3033
3052
  activitiesMigrated++
3034
3053
  affectedEntityIds.add(activity.entity_id)
3035
3054
  } catch (err) {
@@ -3054,8 +3073,9 @@ async function backfillInteractions(
3054
3073
  }
3055
3074
 
3056
3075
  while (true) {
3057
- const todoLinks = await knex('customer_todo_links')
3058
- .select(
3076
+ const todoLinks = await db
3077
+ .selectFrom('customer_todo_links')
3078
+ .select([
3059
3079
  'customer_todo_links.id',
3060
3080
  'customer_todo_links.organization_id',
3061
3081
  'customer_todo_links.tenant_id',
@@ -3063,16 +3083,17 @@ async function backfillInteractions(
3063
3083
  'customer_todo_links.todo_source',
3064
3084
  'customer_todo_links.entity_id',
3065
3085
  'customer_todo_links.created_at',
3066
- )
3067
- .where('customer_todo_links.tenant_id', tenantId)
3068
- .andWhere('customer_todo_links.organization_id', organizationId)
3069
- .whereNotExists(
3070
- knex('customer_interactions')
3071
- .select(knex.raw('1'))
3072
- .whereRaw('customer_interactions.id = customer_todo_links.todo_id')
3073
- )
3086
+ ])
3087
+ .where('customer_todo_links.tenant_id', '=', tenantId)
3088
+ .where('customer_todo_links.organization_id', '=', organizationId)
3089
+ .where((eb: any) => eb.not(eb.exists(
3090
+ eb.selectFrom('customer_interactions')
3091
+ .select(sql<number>`1`.as('one'))
3092
+ .whereRef('customer_interactions.id', '=', 'customer_todo_links.todo_id')
3093
+ )))
3074
3094
  .orderBy('customer_todo_links.created_at', 'asc')
3075
3095
  .limit(BACKFILL_BATCH_SIZE)
3096
+ .execute() as any[]
3076
3097
 
3077
3098
  if (todoLinks.length === 0) break
3078
3099
 
@@ -3118,7 +3139,7 @@ async function backfillInteractions(
3118
3139
  const title = summary?.title ?? 'Migrated task'
3119
3140
  const status = summary?.isDone ? 'done' : 'planned'
3120
3141
 
3121
- await knex('customer_interactions').insert({
3142
+ await db.insertInto('customer_interactions').values({
3122
3143
  id: link.todo_id,
3123
3144
  organization_id: link.organization_id,
3124
3145
  tenant_id: link.tenant_id,
@@ -3136,7 +3157,7 @@ async function backfillInteractions(
3136
3157
  deal_id: null,
3137
3158
  created_at: new Date(),
3138
3159
  updated_at: new Date(),
3139
- })
3160
+ } as any).execute()
3140
3161
  todosMigrated++
3141
3162
  affectedEntityIds.add(link.entity_id)
3142
3163
  } catch (err) {
@@ -294,7 +294,7 @@ const createDictionaryEntryCommand: CommandHandler<CustomerDictionaryEntryCreate
294
294
  { tenantId: after.tenantId, organizationId: after.organizationId },
295
295
  )
296
296
  if (entry) {
297
- await em.removeAndFlush(entry)
297
+ await em.remove(entry).flush()
298
298
  await invalidateCache(ctx, after)
299
299
  return
300
300
  }
@@ -470,7 +470,7 @@ const unassignTagCommand: CommandHandler<TagAssignmentInput, { assignmentId: str
470
470
  organizationId: parsed.organizationId,
471
471
  })
472
472
  if (!existing) throw new CrudHttpError(404, { error: 'Tag assignment not found' })
473
- await em.remove(existing)
473
+ await em.remove(existing).flush()
474
474
  await em.flush()
475
475
 
476
476
  const de = (ctx.container.resolve('dataEngine') as DataEngine)
@@ -1,15 +1,5 @@
1
- import {
2
- Entity,
3
- PrimaryKey,
4
- Property,
5
- Index,
6
- Unique,
7
- OneToOne,
8
- OneToMany,
9
- ManyToOne,
10
- Collection,
11
- OptionalProps,
12
- } from '@mikro-orm/core'
1
+ import { Collection, OptionalProps } from '@mikro-orm/core'
2
+ import { Entity, Index, ManyToOne, OneToMany, OneToOne, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'
13
3
 
14
4
  export type CustomerEntityKind = 'person' | 'company'
15
5
  export type CustomerAddressFormat = 'line_first' | 'street_first'
@@ -1,4 +1,5 @@
1
1
  import type { EntityManager } from '@mikro-orm/postgresql'
2
+ import { sql } from 'kysely'
2
3
 
3
4
  export type NextInteractionProjectionResult = {
4
5
  nextInteractionId: string | null
@@ -18,54 +19,64 @@ export async function recomputeNextInteraction(
18
19
  entityId: string,
19
20
  organizationId?: string | null,
20
21
  ): Promise<NextInteractionProjectionResult> {
21
- const knex = em.getKnex()
22
+ const db = em.getKysely<any>() as any
22
23
 
23
- const query = knex('customer_interactions')
24
- .select('id', 'scheduled_at', 'title', 'interaction_type', 'appearance_icon', 'appearance_color')
25
- .where('entity_id', entityId)
26
- .andWhere('status', 'planned')
27
- .whereNotNull('scheduled_at')
28
- .whereNull('deleted_at')
24
+ let query = db
25
+ .selectFrom('customer_interactions')
26
+ .select([
27
+ 'id',
28
+ 'scheduled_at',
29
+ 'title',
30
+ 'interaction_type',
31
+ 'appearance_icon',
32
+ 'appearance_color',
33
+ ])
34
+ .where('entity_id', '=', entityId)
35
+ .where('status', '=', 'planned')
36
+ .where('scheduled_at', 'is not', null)
37
+ .where('deleted_at', 'is', null)
29
38
  if (organizationId) {
30
- query.andWhere('organization_id', organizationId)
39
+ query = query.where('organization_id', '=', organizationId)
31
40
  }
32
41
 
33
42
  const candidate = await query
34
- .orderBy([
35
- { column: 'scheduled_at', order: 'asc' },
36
- { column: 'priority', order: 'desc', nulls: 'last' },
37
- { column: 'created_at', order: 'asc' },
38
- { column: 'id', order: 'asc' },
39
- ])
40
- .first()
43
+ .orderBy('scheduled_at', 'asc')
44
+ .orderBy(sql`priority desc nulls last`)
45
+ .orderBy('created_at', 'asc')
46
+ .orderBy('id', 'asc')
47
+ .executeTakeFirst() as Record<string, any> | undefined
41
48
 
42
49
  if (candidate) {
43
50
  const interactionName = candidate.title && candidate.title.trim() !== ''
44
51
  ? candidate.title
45
52
  : candidate.interaction_type
46
53
 
47
- await knex('customer_entities')
48
- .where('id', entityId)
49
- .update({
54
+ await db
55
+ .updateTable('customer_entities')
56
+ .set({
50
57
  next_interaction_at: candidate.scheduled_at,
51
58
  next_interaction_name: interactionName,
52
59
  next_interaction_ref_id: candidate.id,
53
60
  next_interaction_icon: candidate.appearance_icon,
54
61
  next_interaction_color: candidate.appearance_color,
55
- updated_at: knex.fn.now(),
56
- })
62
+ updated_at: sql`now()`,
63
+ } as any)
64
+ .where('id', '=', entityId)
65
+ .execute()
57
66
  return { nextInteractionId: String(candidate.id) }
58
67
  } else {
59
- await knex('customer_entities')
60
- .where('id', entityId)
61
- .update({
68
+ await db
69
+ .updateTable('customer_entities')
70
+ .set({
62
71
  next_interaction_at: null,
63
72
  next_interaction_name: null,
64
73
  next_interaction_ref_id: null,
65
74
  next_interaction_icon: null,
66
75
  next_interaction_color: null,
67
- updated_at: knex.fn.now(),
68
- })
76
+ updated_at: sql`now()`,
77
+ } as any)
78
+ .where('id', '=', entityId)
79
+ .execute()
69
80
  return { nextInteractionId: null }
70
81
  }
71
82
  }
@@ -1,4 +1,5 @@
1
1
  import type { EntityManager } from '@mikro-orm/postgresql'
2
+ import { sql } from '@mikro-orm/postgresql'
2
3
 
3
4
  const PERSON_COMPANY_LINKS_TABLE = 'customer_person_company_links'
4
5
  const PERSON_COMPANY_LINKS_DELETED_AT_COLUMN = 'deleted_at'
@@ -6,29 +7,23 @@ const PERSON_COMPANY_LINKS_DELETED_AT_COLUMN = 'deleted_at'
6
7
  let supportsDeletedAtColumnPromise: Promise<boolean> | null = null
7
8
  let warnedAboutMissingDeletedAtColumn = false
8
9
 
9
- type KnexLike = (tableName: string) => {
10
- where: (filters: Record<string, unknown>) => {
11
- first: () => Promise<unknown>
12
- }
13
- }
14
-
15
- function getKnex(em: EntityManager): KnexLike {
16
- return (em.getConnection() as unknown as { getKnex: () => KnexLike }).getKnex()
17
- }
18
-
19
10
  export async function customerPersonCompanyLinksSupportDeletedAt(em: EntityManager): Promise<boolean> {
20
- if (typeof (em as { getConnection?: unknown }).getConnection !== 'function') {
11
+ if (typeof (em as { getKysely?: unknown }).getKysely !== 'function') {
21
12
  return true
22
13
  }
23
14
  if (!supportsDeletedAtColumnPromise) {
24
- supportsDeletedAtColumnPromise = getKnex(em)('information_schema.columns')
25
- .where({
26
- table_name: PERSON_COMPANY_LINKS_TABLE,
27
- column_name: PERSON_COMPANY_LINKS_DELETED_AT_COLUMN,
28
- })
29
- .first()
30
- .then((row) => !!row)
15
+ const db = em.getKysely<any>() as any
16
+ const probe: Promise<boolean> = db
17
+ .selectFrom('information_schema.columns')
18
+ .select(['column_name'])
19
+ .where(sql<boolean>`table_schema = current_schema()`)
20
+ .where('table_name', '=', PERSON_COMPANY_LINKS_TABLE)
21
+ .where('column_name', '=', PERSON_COMPANY_LINKS_DELETED_AT_COLUMN)
22
+ .executeTakeFirst()
23
+ .then((row: unknown) => !!row)
31
24
  .catch(() => false)
25
+ supportsDeletedAtColumnPromise = probe
26
+ return probe
32
27
  }
33
28
  return supportsDeletedAtColumnPromise
34
29
  }
@@ -128,7 +128,7 @@ export async function PUT(req: Request) {
128
128
 
129
129
  if (!widgetIds.length) {
130
130
  if (record) {
131
- await em.removeAndFlush(record)
131
+ await em.remove(record).flush()
132
132
  }
133
133
  return NextResponse.json({ ok: true, widgetIds: [] })
134
134
  }
@@ -128,7 +128,7 @@ export async function PUT(req: Request) {
128
128
 
129
129
  if (parsed.data.mode === 'inherit') {
130
130
  if (record) {
131
- await em.remove(record)
131
+ await em.remove(record).flush()
132
132
  await em.flush()
133
133
  }
134
134
  return NextResponse.json({ ok: true, mode: 'inherit', widgetIds: [] })
@@ -1,4 +1,4 @@
1
- import { Entity, PrimaryKey, Property, Unique } from '@mikro-orm/core'
1
+ import { Entity, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'
2
2
  import type { DashboardLayoutItem } from '@open-mercato/shared/modules/dashboard/widgets'
3
3
 
4
4
  @Entity({ tableName: 'dashboard_layouts' })
@@ -133,7 +133,7 @@ export async function POST(req: Request) {
133
133
  organizationId: scope.organizationId,
134
134
  tenantId: scope.tenantId,
135
135
  })
136
- await em.persistAndFlush(created)
136
+ await em.persist(created).flush()
137
137
 
138
138
  return NextResponse.json({
139
139
  id: created.id,
@@ -1,4 +1,5 @@
1
- import { Entity, Index, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'
1
+ import { OptionalProps } from '@mikro-orm/core'
2
+ import { Entity, Index, PrimaryKey, Property } from '@mikro-orm/decorators/legacy'
2
3
 
3
4
  @Entity({ tableName: 'sync_runs' })
4
5
  @Index({ properties: ['integrationId', 'entityType', 'status', 'organizationId', 'tenantId'] })
@@ -116,7 +116,7 @@ export function createExternalIdMappingService(em: EntityManager) {
116
116
  tenantId: scope.tenantId,
117
117
  })
118
118
 
119
- await em.persistAndFlush(created)
119
+ await em.persist(created).flush()
120
120
  return created
121
121
  },
122
122
  }
@@ -32,7 +32,7 @@ export function createSyncRunService(em: EntityManager) {
32
32
  tenantId: scope.tenantId,
33
33
  })
34
34
 
35
- await em.persistAndFlush(row)
35
+ await em.persist(row).flush()
36
36
  return row
37
37
  },
38
38
 
@@ -296,7 +296,7 @@ export function registerDictionaryEntryCommands<TCreate, TUpdate>(
296
296
  scopeEnsurer(ctx, { tenantId: after.tenantId, organizationId: after.organizationId })
297
297
  const entry = await em.findOne(DictionaryEntry, after.id)
298
298
  if (entry) {
299
- await em.removeAndFlush(entry)
299
+ await em.remove(entry).flush()
300
300
  return
301
301
  }
302
302
  await em.nativeDelete(DictionaryEntry, { id: after.id })
@@ -1,12 +1,5 @@
1
- import {
2
- Entity,
3
- PrimaryKey,
4
- Property,
5
- Unique,
6
- Index,
7
- ManyToOne,
8
- OptionalProps,
9
- } from '@mikro-orm/core'
1
+ import { Entity, Index, ManyToOne, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'
2
+ import { OptionalProps } from '@mikro-orm/core'
10
3
 
11
4
  export type DictionaryManagerVisibility = 'default' | 'hidden'
12
5
 
@@ -199,7 +199,7 @@ async function restoreChildParents(em: EntityManager, tenantId: string, snapshot
199
199
  toPersist.push(child)
200
200
  }
201
201
  }
202
- if (toPersist.length) await em.persistAndFlush(toPersist)
202
+ if (toPersist.length) await em.persist(toPersist).flush()
203
203
  }
204
204
 
205
205
  function normalizeChildIds(ids: readonly string[], exclude: string[]): string[] {
@@ -239,7 +239,7 @@ async function assignChildren(
239
239
  toPersist.push(child)
240
240
  }
241
241
  }
242
- if (toPersist.length) await em.persistAndFlush(toPersist)
242
+ if (toPersist.length) await em.persist(toPersist).flush()
243
243
  }
244
244
 
245
245
  async function clearRemovedChildren(em: EntityManager, tenantId: string, recordId: string, desiredChildIds: Set<string>): Promise<void> {
@@ -248,7 +248,7 @@ async function clearRemovedChildren(em: EntityManager, tenantId: string, recordI
248
248
  const toPersist = current.filter((child) => !desiredChildIds.has(String(child.id)))
249
249
  if (!toPersist.length) return
250
250
  for (const child of toPersist) child.parentId = null
251
- await em.persistAndFlush(toPersist)
251
+ await em.persist(toPersist).flush()
252
252
  }
253
253
 
254
254
  async function resolveUniqueSlug(em: EntityManager, tenantId: string, baseSlug: string, excludeId?: string): Promise<string> {
@@ -669,7 +669,7 @@ const deleteOrganizationCommand: CommandHandler<{ body: any; query: Record<strin
669
669
  toPersist.push(child)
670
670
  }
671
671
  toPersist.push(deleted)
672
- if (toPersist.length) await em.persistAndFlush(toPersist)
672
+ if (toPersist.length) await em.persist(toPersist).flush()
673
673
  setUndoMeta(deleted, { childParentsBefore: childSnapshotsBefore })
674
674
 
675
675
  await rebuildHierarchyForTenant(em, tenantId)
@@ -1,4 +1,5 @@
1
- import { Entity, PrimaryKey, Property, ManyToOne, OneToMany, Collection, Unique } from '@mikro-orm/core'
1
+ import { Collection } from '@mikro-orm/core'
2
+ import { Entity, ManyToOne, OneToMany, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'
2
3
 
3
4
  @Entity({ tableName: 'tenants' })
4
5
  export class Tenant {
@@ -4,7 +4,7 @@ import type { CacheStrategy } from '@open-mercato/cache'
4
4
  import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
5
5
  import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
6
6
  import type { RbacService } from '@open-mercato/core/modules/auth/services/rbacService'
7
- import { CustomFieldDef } from '@open-mercato/core/modules/entities/data/entities'
7
+ import { CustomEntity, CustomFieldDef } from '@open-mercato/core/modules/entities/data/entities'
8
8
  import { upsertCustomFieldDefSchema, fieldsetCodeRegex } from '@open-mercato/core/modules/entities/data/validators'
9
9
  import {
10
10
  createDefinitionsCacheKey,
@@ -157,7 +157,7 @@ function parseEntityIds(url: URL): string[] {
157
157
 
158
158
  async function resolveEntityDefaultEditor(em: any, entityId: string, tenantId: string | null | undefined): Promise<string | undefined> {
159
159
  try {
160
- const ent = await em.findOne('@open-mercato/core/modules/entities/data/entities:CustomEntity' as any, {
160
+ const ent = await em.findOne(CustomEntity, {
161
161
  entityId,
162
162
  $and: [
163
163
  { $or: [ { tenantId: tenantId ?? undefined as any }, { tenantId: null } ] },
@@ -75,7 +75,7 @@ export async function POST(req: Request) {
75
75
  existing.fieldsJson = payload.fields
76
76
  existing.isActive = payload.isActive ?? true
77
77
  existing.updatedAt = new Date()
78
- await em.persistAndFlush(existing)
78
+ await em.persist(existing).flush()
79
79
  } else {
80
80
  const map = repo.create({
81
81
  entityId: payload.entityId,
@@ -84,7 +84,7 @@ export async function POST(req: Request) {
84
84
  fieldsJson: payload.fields,
85
85
  isActive: payload.isActive ?? true,
86
86
  })
87
- await em.persistAndFlush(map)
87
+ await em.persist(map).flush()
88
88
  }
89
89
 
90
90
  try {