@open-mercato/core 0.5.1-develop.2691.d8a0934b37 → 0.5.1-develop.2699.f8b50c8046

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
@@ -235,7 +235,7 @@ const composeMessageCommand: CommandHandler<unknown, { id: string; threadId: str
235
235
  organizationId: input.organizationId,
236
236
  })
237
237
 
238
- await trx.persistAndFlush(message)
238
+ await trx.persist(message).flush()
239
239
  if (!threadId && !input.isDraft && !message.threadId) {
240
240
  message.threadId = message.id
241
241
  await trx.flush()
@@ -567,7 +567,7 @@ const replyMessageCommand: CommandHandler<unknown, { id: string; externalEmail:
567
567
  tenantId: input.tenantId,
568
568
  organizationId: input.organizationId,
569
569
  })
570
- await trx.persistAndFlush(message)
570
+ await trx.persist(message).flush()
571
571
  for (const recipientUserId of recipientIds) {
572
572
  trx.persist(trx.create(MessageRecipient, {
573
573
  messageId: message.id,
@@ -709,7 +709,7 @@ const forwardMessageCommand: CommandHandler<unknown, { id: string; externalEmail
709
709
  tenantId: input.tenantId,
710
710
  organizationId: input.organizationId,
711
711
  })
712
- await trx.persistAndFlush(newMessage)
712
+ await trx.persist(newMessage).flush()
713
713
  for (const recipient of input.recipients) {
714
714
  trx.persist(trx.create(MessageRecipient, {
715
715
  messageId: newMessage.id,
@@ -1,4 +1,5 @@
1
- import { Entity, PrimaryKey, Property, Index, OptionalProps, Unique } from '@mikro-orm/core'
1
+ import { OptionalProps } from '@mikro-orm/core'
2
+ import { Entity, Index, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'
2
3
 
3
4
  export type MessageStatus = 'draft' | 'sent'
4
5
  export type MessagePriority = 'low' | 'normal' | 'high' | 'urgent'
@@ -154,7 +154,7 @@ export async function createMessageAccessToken(
154
154
  expiresAt,
155
155
  useCount: 0,
156
156
  })
157
- await em.persistAndFlush(record)
157
+ await em.persist(record).flush()
158
158
  logDebug('Created access token', {
159
159
  messageId,
160
160
  recipientUserId,
@@ -1,10 +1,10 @@
1
1
  import type { EntityManager } from '@mikro-orm/postgresql'
2
- import type { Knex } from 'knex'
2
+ import { type Kysely, sql } from 'kysely'
3
3
  import { resolveSearchConfig } from '@open-mercato/shared/lib/search/config'
4
4
  import { tokenizeText } from '@open-mercato/shared/lib/search/tokenize'
5
5
 
6
- function getKnex(em: EntityManager): Knex {
7
- return (em.getConnection() as unknown as { getKnex: () => Knex }).getKnex()
6
+ function getDb(em: EntityManager): Kysely<any> {
7
+ return em.getKysely<any>()
8
8
  }
9
9
 
10
10
  export async function findMessageIdsBySearchTokens({
@@ -26,23 +26,26 @@ export async function findMessageIdsBySearchTokens({
26
26
  const tokens = tokenizeText(trimmed, resolveSearchConfig())
27
27
  if (!tokens.hashes.length) return []
28
28
 
29
- const knex = getKnex(em)
30
- let searchQuery = knex('search_tokens')
29
+ const db = getDb(em) as any
30
+ let searchQuery = db
31
+ .selectFrom('search_tokens')
31
32
  .select('entity_id')
32
- .where('entity_type', 'messages:message')
33
- .whereIn('field', fields)
34
- .whereIn('token_hash', tokens.hashes)
35
- .groupBy('entity_id')
36
- .havingRaw('count(distinct token_hash) >= ?', [tokens.hashes.length])
33
+ .where('entity_type', '=', 'messages:message')
34
+ .where('field', 'in', fields)
35
+ .where('token_hash', 'in', tokens.hashes)
36
+ .where(sql<boolean>`tenant_id is not distinct from ${tenantId}`)
37
37
 
38
- searchQuery = searchQuery.whereRaw('tenant_id is not distinct from ?', [tenantId])
39
38
  if (organizationId) {
40
- searchQuery = searchQuery.where('organization_id', organizationId)
39
+ searchQuery = searchQuery.where('organization_id', '=', organizationId)
41
40
  } else {
42
- searchQuery = searchQuery.whereRaw('organization_id is not distinct from ?', [null])
41
+ searchQuery = searchQuery.where(sql<boolean>`organization_id is not distinct from ${null}`)
43
42
  }
44
43
 
45
44
  const rows = await searchQuery
45
+ .groupBy('entity_id')
46
+ .having(sql<boolean>`count(distinct token_hash) >= ${tokens.hashes.length}`)
47
+ .execute()
48
+
46
49
  return rows
47
50
  .map((row: { entity_id?: unknown }) => (typeof row.entity_id === 'string' ? row.entity_id : null))
48
51
  .filter((id: string | null): id is string => typeof id === 'string' && id.length > 0)
@@ -1,4 +1,5 @@
1
1
  import type { EntityManager } from '@mikro-orm/postgresql'
2
+ import { type Kysely, sql } from 'kysely'
2
3
  import { MessageAccessToken } from '../data/entities'
3
4
 
4
5
  export const MAX_TOKEN_USE_COUNT = 25
@@ -9,20 +10,27 @@ export type TokenConsumptionResult =
9
10
  | { ok: true }
10
11
  | { ok: false; reason: TokenConsumptionFailureReason }
11
12
 
13
+ function getKysely(em: EntityManager): Kysely<any> {
14
+ return (em as unknown as { getKysely: () => Kysely<any> }).getKysely()
15
+ }
16
+
12
17
  export async function consumeMessageAccessToken(
13
18
  em: EntityManager,
14
19
  tokenId: string,
15
20
  ): Promise<TokenConsumptionResult> {
16
- const knex = em.getKnex()
21
+ const db = getKysely(em)
17
22
  const now = new Date()
18
- const consumed = await knex('message_access_tokens')
19
- .where('id', tokenId)
20
- .where('use_count', '<', MAX_TOKEN_USE_COUNT)
21
- .where('expires_at', '>', now)
22
- .update({
23
- use_count: knex.raw('use_count + 1'),
23
+ const updateResult = await db
24
+ .updateTable('message_access_tokens' as any)
25
+ .set({
26
+ use_count: sql`use_count + 1`,
24
27
  used_at: now,
25
- })
28
+ } as any)
29
+ .where('id' as any, '=', tokenId)
30
+ .where('use_count' as any, '<', MAX_TOKEN_USE_COUNT)
31
+ .where('expires_at' as any, '>', now)
32
+ .executeTakeFirst()
33
+ const consumed = Number(updateResult?.numUpdatedRows ?? 0n)
26
34
  if (consumed > 0) return { ok: true }
27
35
 
28
36
  em.clear()
@@ -1,4 +1,5 @@
1
- import { Entity, PrimaryKey, Property, Index, OptionalProps } from '@mikro-orm/core'
1
+ import { OptionalProps } from '@mikro-orm/core'
2
+ import { Entity, Index, PrimaryKey, Property } from '@mikro-orm/decorators/legacy'
2
3
  import type { NotificationActionData } from '@open-mercato/shared/modules/notifications/types'
3
4
 
4
5
  export type NotificationStatus = 'unread' | 'read' | 'actioned' | 'dismissed'
@@ -1,4 +1,4 @@
1
- import type { Knex } from 'knex'
1
+ import type { Kysely } from 'kysely'
2
2
  import { hasFeature } from '@open-mercato/shared/security/features'
3
3
 
4
4
  interface AclRow {
@@ -35,47 +35,63 @@ function collectUsersWithFeature(
35
35
  }
36
36
 
37
37
  export async function getRecipientUserIdsForRole(
38
- knex: Knex,
38
+ db: Kysely<any>,
39
39
  tenantId: string,
40
40
  roleId: string
41
41
  ): Promise<string[]> {
42
- const userRoles = await knex('user_roles')
43
- .join('users', 'user_roles.user_id', 'users.id')
44
- .where('user_roles.role_id', roleId)
45
- .whereNull('user_roles.deleted_at')
46
- .whereNull('users.deleted_at')
47
- .where('users.tenant_id', tenantId)
42
+ const builder: any = db
43
+ const userRoles = await builder
44
+ .selectFrom('user_roles')
45
+ .innerJoin('users', 'user_roles.user_id', 'users.id')
46
+ .where('user_roles.role_id', '=', roleId)
47
+ .where('user_roles.deleted_at', 'is', null)
48
+ .where('users.deleted_at', 'is', null)
49
+ .where('users.tenant_id', '=', tenantId)
48
50
  .select('users.id as user_id')
51
+ .execute() as Array<{ user_id: string }>
49
52
 
50
- return userRoles.map((row: { user_id: string }) => row.user_id)
53
+ return userRoles.map((row) => row.user_id)
51
54
  }
52
55
 
53
56
  export async function getRecipientUserIdsForFeature(
54
- knex: Knex,
57
+ db: Kysely<any>,
55
58
  tenantId: string,
56
59
  requiredFeature: string
57
60
  ): Promise<string[]> {
58
61
  const userIdsSet = new Set<string>()
62
+ const builder: any = db
59
63
 
60
- const userAcls = await knex('user_acls')
61
- .join('users', 'user_acls.user_id', 'users.id')
62
- .where('user_acls.tenant_id', tenantId)
63
- .whereNull('user_acls.deleted_at')
64
- .whereNull('users.deleted_at')
65
- .where('users.tenant_id', tenantId)
66
- .select('users.id as user_id', 'user_acls.features_json', 'user_acls.is_super_admin')
64
+ const userAcls = await builder
65
+ .selectFrom('user_acls')
66
+ .innerJoin('users', 'user_acls.user_id', 'users.id')
67
+ .where('user_acls.tenant_id', '=', tenantId)
68
+ .where('user_acls.deleted_at', 'is', null)
69
+ .where('users.deleted_at', 'is', null)
70
+ .where('users.tenant_id', '=', tenantId)
71
+ .select([
72
+ 'users.id as user_id',
73
+ 'user_acls.features_json',
74
+ 'user_acls.is_super_admin',
75
+ ])
76
+ .execute() as AclRow[]
67
77
 
68
78
  collectUsersWithFeature(userIdsSet, userAcls, requiredFeature)
69
79
 
70
- const roleAcls = await knex('role_acls')
71
- .join('user_roles', 'role_acls.role_id', 'user_roles.role_id')
72
- .join('users', 'user_roles.user_id', 'users.id')
73
- .where('role_acls.tenant_id', tenantId)
74
- .whereNull('role_acls.deleted_at')
75
- .whereNull('user_roles.deleted_at')
76
- .whereNull('users.deleted_at')
77
- .where('users.tenant_id', tenantId)
78
- .select('users.id as user_id', 'role_acls.features_json', 'role_acls.is_super_admin')
80
+ const roleAcls = await builder
81
+ .selectFrom('role_acls')
82
+ .innerJoin('user_roles', 'role_acls.role_id', 'user_roles.role_id')
83
+ .innerJoin('users', 'user_roles.user_id', 'users.id')
84
+ .where('role_acls.tenant_id', '=', tenantId)
85
+ .where('role_acls.deleted_at', 'is', null)
86
+ .where('user_roles.deleted_at', 'is', null)
87
+ .where('users.deleted_at', 'is', null)
88
+ .where('users.tenant_id', '=', tenantId)
89
+ .select([
90
+ 'users.id as user_id',
91
+ 'role_acls.features_json',
92
+ 'role_acls.is_super_admin',
93
+ ])
94
+ .execute() as AclRow[]
79
95
 
80
96
  collectUsersWithFeature(userIdsSet, roleAcls, requiredFeature)
81
97
 
@@ -1,5 +1,5 @@
1
1
  import type { EntityManager } from '@mikro-orm/postgresql'
2
- import type { Knex } from 'knex'
2
+ import { type Kysely, sql } from 'kysely'
3
3
  import { Notification, type NotificationStatus } from '../data/entities'
4
4
  import type { CreateNotificationInput, CreateBatchNotificationInput, CreateRoleNotificationInput, CreateFeatureNotificationInput, ExecuteActionInput } from '../data/validators'
5
5
  import type { NotificationPollData } from '@open-mercato/shared/modules/notifications/types'
@@ -24,8 +24,8 @@ function debug(...args: unknown[]): void {
24
24
  }
25
25
  }
26
26
 
27
- function getKnex(em: EntityManager): Knex {
28
- return (em.getConnection() as unknown as { getKnex: () => Knex }).getKnex()
27
+ function getDb(em: EntityManager): Kysely<any> {
28
+ return em.getKysely<any>()
29
29
  }
30
30
 
31
31
  const UNIQUE_NOTIFICATION_ACTIVE_STATUSES: NotificationStatus[] = ['unread', 'read', 'actioned']
@@ -109,8 +109,8 @@ async function createOrRefreshNotification(
109
109
  const orgScope = normalizeOrgScope(ctx.organizationId) ?? 'global'
110
110
  const lockKey = `notifications:${ctx.tenantId}:${orgScope}:${recipientUserId}:${input.type}:${input.groupKey}`
111
111
  try {
112
- const knex = getKnex(em)
113
- await knex.raw('select pg_advisory_xact_lock(hashtext(?))', [lockKey])
112
+ const db = getDb(em)
113
+ await sql`select pg_advisory_xact_lock(hashtext(${lockKey}))`.execute(db)
114
114
  } catch {
115
115
  // If advisory locks are unavailable, continue with best-effort dedupe.
116
116
  }
@@ -228,8 +228,8 @@ export function createNotificationService(deps: NotificationServiceDeps): Notifi
228
228
  async createForRole(input, ctx) {
229
229
  const em = rootEm.fork()
230
230
 
231
- const knex = getKnex(em)
232
- const recipientUserIds = await getRecipientUserIdsForRole(knex, ctx.tenantId, input.roleId)
231
+ const db = getDb(em)
232
+ const recipientUserIds = await getRecipientUserIdsForRole(db, ctx.tenantId, input.roleId)
233
233
  if (recipientUserIds.length === 0) {
234
234
  return []
235
235
  }
@@ -255,8 +255,8 @@ export function createNotificationService(deps: NotificationServiceDeps): Notifi
255
255
 
256
256
  async createForFeature(input, ctx) {
257
257
  const em = rootEm.fork()
258
- const knex = getKnex(em)
259
- const recipientUserIds = await getRecipientUserIdsForFeature(knex, ctx.tenantId, input.requiredFeature)
258
+ const db = getDb(em)
259
+ const recipientUserIds = await getRecipientUserIdsForFeature(db, ctx.tenantId, input.requiredFeature)
260
260
 
261
261
  if (recipientUserIds.length === 0) {
262
262
  debug('No users found with feature:', input.requiredFeature, 'in tenant:', ctx.tenantId)
@@ -309,29 +309,39 @@ export function createNotificationService(deps: NotificationServiceDeps): Notifi
309
309
 
310
310
  async markAllAsRead(ctx) {
311
311
  const em = rootEm.fork()
312
- const knex = getKnex(em)
313
- const baseQuery = knex('notifications')
314
- .where({
315
- recipient_user_id: ctx.userId,
316
- tenant_id: ctx.tenantId,
317
- status: 'unread',
318
- })
319
-
320
- if (ctx.organizationId) {
321
- baseQuery.where('organization_id', ctx.organizationId)
312
+ const db = getDb(em)
313
+ const applyScope = <QB extends { where: (...args: any[]) => QB }>(q: QB): QB => {
314
+ let chain = q
315
+ .where('recipient_user_id' as any, '=', ctx.userId as any)
316
+ .where('tenant_id' as any, '=', ctx.tenantId)
317
+ .where('status' as any, '=', 'unread')
318
+ if (ctx.organizationId) {
319
+ chain = chain.where('organization_id' as any, '=', ctx.organizationId)
320
+ }
321
+ return chain
322
322
  }
323
323
 
324
- const targetRows = await baseQuery.clone()
325
- .select('id', 'organization_id', 'recipient_user_id')
324
+ const targetRows = await applyScope(
325
+ db
326
+ .selectFrom('notifications' as any)
327
+ .select([
328
+ 'id' as any,
329
+ 'organization_id' as any,
330
+ 'recipient_user_id' as any,
331
+ ]),
332
+ ).execute() as Array<{ id: string }>
326
333
 
327
334
  if (!targetRows.length) {
328
335
  return 0
329
336
  }
330
337
 
331
- const result = await baseQuery.clone().update({
332
- status: 'read',
333
- read_at: knex.fn.now(),
334
- })
338
+ const updateResult = await applyScope(
339
+ db.updateTable('notifications' as any).set({
340
+ status: 'read',
341
+ read_at: sql`now()`,
342
+ } as any) as any,
343
+ ).executeTakeFirst() as { numUpdatedRows?: bigint | number } | undefined
344
+ const result = Number(updateResult?.numUpdatedRows ?? targetRows.length)
335
345
 
336
346
  const notifications = await findWithDecryption(em, Notification, {
337
347
  id: { $in: targetRows.map((row) => row.id) },
@@ -528,32 +538,33 @@ export function createNotificationService(deps: NotificationServiceDeps): Notifi
528
538
 
529
539
  async cleanupExpired() {
530
540
  const em = rootEm.fork()
531
- const knex = getKnex(em)
541
+ const db = getDb(em)
532
542
 
533
- const result = await knex('notifications')
534
- .where('expires_at', '<', knex.fn.now())
535
- .whereNotIn('status', ['actioned', 'dismissed'])
536
- .update({
543
+ const updateResult = await db
544
+ .updateTable('notifications' as any)
545
+ .set({
537
546
  status: 'dismissed',
538
- dismissed_at: knex.fn.now(),
539
- })
547
+ dismissed_at: sql`now()`,
548
+ } as any)
549
+ .where('expires_at' as any, '<', sql`now()`)
550
+ .where('status' as any, 'not in', ['actioned', 'dismissed'])
551
+ .executeTakeFirst() as { numUpdatedRows?: bigint | number } | undefined
540
552
 
541
- return result
553
+ return Number(updateResult?.numUpdatedRows ?? 0)
542
554
  },
543
555
 
544
556
  async deleteBySource(sourceEntityType, sourceEntityId, ctx) {
545
557
  const em = rootEm.fork()
546
- const knex = getKnex(em)
558
+ const db = getDb(em)
547
559
 
548
- const result = await knex('notifications')
549
- .where({
550
- source_entity_type: sourceEntityType,
551
- source_entity_id: sourceEntityId,
552
- tenant_id: ctx.tenantId,
553
- })
554
- .delete()
560
+ const deleteResult = await db
561
+ .deleteFrom('notifications' as any)
562
+ .where('source_entity_type' as any, '=', sourceEntityType)
563
+ .where('source_entity_id' as any, '=', sourceEntityId)
564
+ .where('tenant_id' as any, '=', ctx.tenantId)
565
+ .executeTakeFirst() as { numDeletedRows?: bigint | number } | undefined
555
566
 
556
- return result
567
+ return Number(deleteResult?.numDeletedRows ?? 0)
557
568
  },
558
569
  }
559
570
  }
@@ -1,12 +1,13 @@
1
1
  import type { EntityManager } from '@mikro-orm/core'
2
- import type { Knex } from 'knex'
2
+ import type { EntityManager as PgEntityManager } from '@mikro-orm/postgresql'
3
+ import { type Kysely, sql } from 'kysely'
3
4
  import { Notification } from '../data/entities'
4
5
  import type { CreateNotificationInput, CreateRoleNotificationInput, CreateFeatureNotificationInput } from '../data/validators'
5
6
  import { buildNotificationEntity, emitNotificationCreated, emitNotificationCreatedBatch } from '../lib/notificationFactory'
6
7
  import { getRecipientUserIdsForFeature, getRecipientUserIdsForRole } from '../lib/notificationRecipients'
7
8
 
8
- function getKnex(em: EntityManager): Knex {
9
- return (em.getConnection() as unknown as { getKnex: () => Knex }).getKnex()
9
+ function getDb(em: EntityManager): Kysely<any> {
10
+ return (em as unknown as PgEntityManager).getKysely<any>()
10
11
  }
11
12
 
12
13
  export const NOTIFICATIONS_QUEUE_NAME = 'notifications'
@@ -61,7 +62,7 @@ export default async function handle(
61
62
  const { recipientUserId, ...content } = input
62
63
  const notification = buildNotificationEntity(em, content, recipientUserId, { tenantId, organizationId })
63
64
 
64
- await em.persistAndFlush(notification)
65
+ await em.persist(notification).flush()
65
66
 
66
67
  await emitNotificationCreated(eventBus, notification, { tenantId, organizationId })
67
68
  } else if (payload.type === 'create-role') {
@@ -69,8 +70,8 @@ export default async function handle(
69
70
  const eventBus = ctx.resolve('eventBus') as { emit: (event: string, payload: unknown) => Promise<void> }
70
71
  const { input, tenantId, organizationId } = payload
71
72
 
72
- const knex = getKnex(em)
73
- const recipientUserIds = await getRecipientUserIdsForRole(knex, tenantId, input.roleId)
73
+ const db = getDb(em)
74
+ const recipientUserIds = await getRecipientUserIdsForRole(db, tenantId, input.roleId)
74
75
  if (recipientUserIds.length === 0) {
75
76
  return
76
77
  }
@@ -82,7 +83,7 @@ export default async function handle(
82
83
  notifications.push(notification)
83
84
  }
84
85
 
85
- await em.persistAndFlush(notifications)
86
+ await em.persist(notifications).flush()
86
87
 
87
88
  await emitNotificationCreatedBatch(eventBus, notifications, { tenantId, organizationId })
88
89
  } else if (payload.type === 'create-feature') {
@@ -90,8 +91,8 @@ export default async function handle(
90
91
  const eventBus = ctx.resolve('eventBus') as { emit: (event: string, payload: unknown) => Promise<void> }
91
92
  const { input, tenantId, organizationId } = payload
92
93
 
93
- const knex = getKnex(em)
94
- const recipientUserIds = await getRecipientUserIdsForFeature(knex, tenantId, input.requiredFeature)
94
+ const db = getDb(em)
95
+ const recipientUserIds = await getRecipientUserIdsForFeature(db, tenantId, input.requiredFeature)
95
96
 
96
97
  if (recipientUserIds.length === 0) {
97
98
  return
@@ -104,19 +105,21 @@ export default async function handle(
104
105
  notifications.push(notification)
105
106
  }
106
107
 
107
- await em.persistAndFlush(notifications)
108
+ await em.persist(notifications).flush()
108
109
 
109
110
  await emitNotificationCreatedBatch(eventBus, notifications, { tenantId, organizationId })
110
111
  } else if (payload.type === 'cleanup-expired') {
111
112
  const em = (ctx.resolve('em') as EntityManager).fork()
112
- const knex = getKnex(em)
113
+ const db = getDb(em)
113
114
 
114
- await knex('notifications')
115
- .where('expires_at', '<', knex.fn.now())
116
- .whereNotIn('status', ['actioned', 'dismissed'])
117
- .update({
115
+ await db
116
+ .updateTable('notifications' as any)
117
+ .set({
118
118
  status: 'dismissed',
119
- dismissed_at: knex.fn.now(),
120
- })
119
+ dismissed_at: sql`now()`,
120
+ } as any)
121
+ .where('expires_at' as any, '<', sql`now()`)
122
+ .where('status' as any, 'not in', ['actioned', 'dismissed'])
123
+ .execute()
121
124
  }
122
125
  }
@@ -75,7 +75,7 @@ export async function GET(req: Request) {
75
75
 
76
76
  const [items, total] = await Promise.all([
77
77
  qb.getResultList(),
78
- countQb.count('gt.id', true),
78
+ countQb.getCount('gt.id', true),
79
79
  ])
80
80
 
81
81
  return NextResponse.json({
@@ -99,7 +99,7 @@ export async function GET(req: Request) {
99
99
  total,
100
100
  page,
101
101
  pageSize,
102
- totalPages: Math.max(1, Math.ceil(total / pageSize)),
102
+ totalPages: Math.max(1, Math.ceil(Number(total) / pageSize)),
103
103
  })
104
104
  }
105
105
 
@@ -1,4 +1,5 @@
1
- import { Entity, Index, OptionalProps, PrimaryKey, Property, Unique } from '@mikro-orm/core'
1
+ import { OptionalProps } from '@mikro-orm/core'
2
+ import { Entity, Index, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'
2
3
 
3
4
  @Entity({ tableName: 'gateway_transactions' })
4
5
  @Index({ properties: ['paymentId', 'organizationId', 'tenantId'] })
@@ -168,7 +168,7 @@ export function createPaymentGatewayService(deps: PaymentGatewayServiceDeps) {
168
168
  organizationId: input.organizationId,
169
169
  tenantId: input.tenantId,
170
170
  })
171
- await em.persistAndFlush(transaction)
171
+ await em.persist(transaction).flush()
172
172
  await emitPaymentGatewayEvent('payment_gateways.session.created', {
173
173
  transactionId: transaction.id,
174
174
  paymentId: transaction.paymentId,
@@ -19,7 +19,7 @@ export async function claimWebhookProcessing(
19
19
  })
20
20
 
21
21
  try {
22
- await em.persistAndFlush(record)
22
+ await em.persist(record).flush()
23
23
  return true
24
24
  } catch (error: unknown) {
25
25
  if (error instanceof UniqueConstraintViolationException) {
@@ -48,5 +48,5 @@ export async function releaseWebhookClaim(
48
48
  scope,
49
49
  )
50
50
  if (!existing) return
51
- await em.removeAndFlush(existing)
51
+ await em.remove(existing).flush()
52
52
  }
@@ -1,4 +1,4 @@
1
- import { Entity, PrimaryKey, Property, Index, Unique } from '@mikro-orm/core'
1
+ import { Entity, Index, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'
2
2
 
3
3
  @Entity({ tableName: 'perspectives' })
4
4
  @Index({ name: 'perspectives_user_scope_idx', properties: ['userId', 'tenantId', 'organizationId', 'tableId'] })
@@ -1,4 +1,4 @@
1
- import { Entity, PrimaryKey, Property, Index, Enum } from '@mikro-orm/core'
1
+ import { Entity, Enum, Index, PrimaryKey, Property } from '@mikro-orm/decorators/legacy'
2
2
 
3
3
  export type PlannerAvailabilitySubjectType = 'member' | 'resource' | 'ruleset'
4
4
  export type PlannerAvailabilityKind = 'availability' | 'unavailability'
@@ -1,4 +1,5 @@
1
- import { Entity, PrimaryKey, Property, Index, OptionalProps } 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
  export type ProgressJobStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled'
4
5
 
@@ -42,7 +42,7 @@ export function createProgressService(em: EntityManager, eventBus: { emit: (even
42
42
  status: 'pending',
43
43
  })
44
44
 
45
- await em.persistAndFlush(job)
45
+ await em.persist(job).flush()
46
46
 
47
47
  await eventBus.emit(PROGRESS_EVENTS.JOB_CREATED, {
48
48
  ...buildJobPayload(job),