@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
@@ -3,6 +3,7 @@ import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
3
3
  import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
4
4
  import { getEntityIds } from '@open-mercato/shared/lib/encryption/entityIds'
5
5
  import type { EntityManager } from '@mikro-orm/postgresql'
6
+ import { sql } from 'kysely'
6
7
  import { readCoverageSnapshot, refreshCoverageSnapshot } from '../lib/coverage'
7
8
  import type { FullTextSearchStrategy } from '@open-mercato/search/strategies'
8
9
  import type { SearchModuleConfig } from '@open-mercato/shared/modules/search'
@@ -21,7 +22,7 @@ export async function GET(req: Request) {
21
22
 
22
23
  const container = await createRequestContainer()
23
24
  const em = container.resolve('em') as EntityManager
24
- const knex = (em as any).getConnection().getKnex()
25
+ const db = (em as any).getKysely()
25
26
  const scope = await resolveOrganizationScopeForRequest({ container, auth, request: req })
26
27
 
27
28
  const organizationId = scope.selectedId ?? auth.orgId ?? null
@@ -119,23 +120,27 @@ export async function GET(req: Request) {
119
120
 
120
121
  // Limit to entities that have active custom field definitions in current scope
121
122
  try {
122
- const cfRows = await knex('custom_field_defs')
123
- .distinct('entity_id')
124
- .where({ is_active: true })
125
- .modify((qb: any) => {
126
- if (tenantId != null) {
127
- qb.andWhere((b: any) => b.where({ tenant_id: tenantId }).orWhereNull('tenant_id'))
128
- } else {
129
- qb.andWhere((b: any) => b.whereNull('tenant_id'))
130
- }
131
- if (Array.isArray(organizationScopeIds)) {
132
- qb.andWhere((b: any) => {
133
- b.whereIn('organization_id', organizationScopeIds)
134
- b.orWhereNull('organization_id')
135
- })
136
- }
137
- })
138
- const enabled = new Set<string>((cfRows || []).map((r: any) => String(r.entity_id)))
123
+ let cfQuery = db
124
+ .selectFrom('custom_field_defs' as any)
125
+ .select(['entity_id' as any])
126
+ .distinct()
127
+ .where('is_active' as any, '=', true)
128
+ if (tenantId != null) {
129
+ cfQuery = cfQuery.where((eb: any) => eb.or([
130
+ eb('tenant_id' as any, '=', tenantId),
131
+ eb('tenant_id' as any, 'is', null),
132
+ ]))
133
+ } else {
134
+ cfQuery = cfQuery.where('tenant_id' as any, 'is', null as any)
135
+ }
136
+ if (Array.isArray(organizationScopeIds)) {
137
+ cfQuery = cfQuery.where((eb: any) => eb.or([
138
+ eb('organization_id' as any, 'in', organizationScopeIds),
139
+ eb('organization_id' as any, 'is', null),
140
+ ]))
141
+ }
142
+ const cfRows = await cfQuery.execute() as Array<{ entity_id: string }>
143
+ const enabled = new Set<string>((cfRows || []).map((r) => String(r.entity_id)))
139
144
  entityIds = entityIds.filter((id) => enabled.has(id))
140
145
  } catch {}
141
146
 
@@ -144,23 +149,22 @@ export async function GET(req: Request) {
144
149
 
145
150
  async function fetchJobSummary(entityType: string, tenantIdParam: string | null, organizationIdParam: string | null) {
146
151
  try {
147
- const rows = await knex('entity_index_jobs')
148
- .where({ entity_type: entityType })
149
- .andWhere((qb: any) => {
150
- if (tenantIdParam != null) {
151
- qb.whereRaw('tenant_id is not distinct from ?', [tenantIdParam])
152
- } else {
153
- qb.whereRaw('tenant_id is not distinct from ?', [null])
154
- }
155
- })
156
- .andWhere((qb: any) => {
157
- if (organizationIdParam != null) {
158
- qb.whereRaw('organization_id is not distinct from ?', [organizationIdParam]).orWhereNull('organization_id')
159
- } else {
160
- qb.whereRaw('organization_id is not distinct from ?', [null])
161
- }
162
- })
163
- .orderBy('started_at', 'desc')
152
+ let jobQuery = db
153
+ .selectFrom('entity_index_jobs' as any)
154
+ .selectAll()
155
+ .where('entity_type' as any, '=', entityType)
156
+ .where(sql<boolean>`tenant_id is not distinct from ${tenantIdParam ?? null}`)
157
+ if (organizationIdParam != null) {
158
+ jobQuery = jobQuery.where((eb: any) => eb.or([
159
+ eb('organization_id' as any, '=', organizationIdParam),
160
+ eb('organization_id' as any, 'is', null),
161
+ ]))
162
+ } else {
163
+ jobQuery = jobQuery.where(sql<boolean>`organization_id is not distinct from ${null}`)
164
+ }
165
+ const rows = await jobQuery
166
+ .orderBy('started_at' as any, 'desc')
167
+ .execute() as Array<Record<string, any>>
164
168
 
165
169
  if (!rows.length) {
166
170
  return { status: 'idle' as const, partitions: [] as any[] }
@@ -294,7 +298,7 @@ export async function GET(req: Request) {
294
298
  withDeleted: false,
295
299
  } as const
296
300
  const ensureSnapshot = async () => {
297
- let snapshot = await readCoverageSnapshot(knex, scope)
301
+ let snapshot = await readCoverageSnapshot(db, scope)
298
302
  const refreshedAt = snapshot?.refreshed_at instanceof Date
299
303
  ? snapshot.refreshed_at
300
304
  : snapshot?.refreshed_at
@@ -303,7 +307,7 @@ export async function GET(req: Request) {
303
307
  const stale = !snapshot || !refreshedAt || (Date.now() - refreshedAt.getTime() > COVERAGE_STALE_MS)
304
308
  if (forceRefresh || stale) {
305
309
  await refreshCoverageSnapshot(em, scope).catch(() => undefined)
306
- snapshot = await readCoverageSnapshot(knex, scope)
310
+ snapshot = await readCoverageSnapshot(db, scope)
307
311
  }
308
312
  const finalRefreshed = snapshot?.refreshed_at instanceof Date
309
313
  ? snapshot.refreshed_at
@@ -378,24 +382,29 @@ export async function GET(req: Request) {
378
382
  } catch {}
379
383
  }
380
384
 
381
- const errorRows = await knex('indexer_error_logs')
382
- .modify((qb: any) => {
383
- if (tenantId != null) {
384
- qb.where((inner: any) => {
385
- inner.where('tenant_id', tenantId).orWhereNull('tenant_id')
386
- })
387
- } else {
388
- qb.whereNull('tenant_id')
389
- }
390
- })
391
- .andWhere((qb: any) => {
392
- qb.whereNull('organization_id')
393
- if (Array.isArray(organizationScopeIds) && organizationScopeIds.length) {
394
- qb.orWhereIn('organization_id', organizationScopeIds)
395
- }
396
- })
397
- .orderBy('occurred_at', 'desc')
385
+ let errorQuery = db
386
+ .selectFrom('indexer_error_logs' as any)
387
+ .selectAll()
388
+ if (tenantId != null) {
389
+ errorQuery = errorQuery.where((eb: any) => eb.or([
390
+ eb('tenant_id' as any, '=', tenantId),
391
+ eb('tenant_id' as any, 'is', null),
392
+ ]))
393
+ } else {
394
+ errorQuery = errorQuery.where('tenant_id' as any, 'is', null as any)
395
+ }
396
+ if (Array.isArray(organizationScopeIds) && organizationScopeIds.length) {
397
+ errorQuery = errorQuery.where((eb: any) => eb.or([
398
+ eb('organization_id' as any, 'is', null),
399
+ eb('organization_id' as any, 'in', organizationScopeIds),
400
+ ]))
401
+ } else {
402
+ errorQuery = errorQuery.where('organization_id' as any, 'is', null as any)
403
+ }
404
+ const errorRows = await errorQuery
405
+ .orderBy('occurred_at' as any, 'desc')
398
406
  .limit(100)
407
+ .execute() as Array<Record<string, any>>
399
408
 
400
409
  const errors = errorRows.map((row: any) => {
401
410
  const occurredAt = row.occurred_at instanceof Date ? row.occurred_at : row.occurred_at ? new Date(row.occurred_at) : null
@@ -414,24 +423,29 @@ export async function GET(req: Request) {
414
423
  }
415
424
  })
416
425
 
417
- const logRows = await knex('indexer_status_logs')
418
- .modify((qb: any) => {
419
- if (tenantId != null) {
420
- qb.where((inner: any) => {
421
- inner.where('tenant_id', tenantId).orWhereNull('tenant_id')
422
- })
423
- } else {
424
- qb.whereNull('tenant_id')
425
- }
426
- })
427
- .andWhere((qb: any) => {
428
- qb.whereNull('organization_id')
429
- if (Array.isArray(organizationScopeIds) && organizationScopeIds.length) {
430
- qb.orWhereIn('organization_id', organizationScopeIds)
431
- }
432
- })
433
- .orderBy('occurred_at', 'desc')
426
+ let logsQuery = db
427
+ .selectFrom('indexer_status_logs' as any)
428
+ .selectAll()
429
+ if (tenantId != null) {
430
+ logsQuery = logsQuery.where((eb: any) => eb.or([
431
+ eb('tenant_id' as any, '=', tenantId),
432
+ eb('tenant_id' as any, 'is', null),
433
+ ]))
434
+ } else {
435
+ logsQuery = logsQuery.where('tenant_id' as any, 'is', null as any)
436
+ }
437
+ if (Array.isArray(organizationScopeIds) && organizationScopeIds.length) {
438
+ logsQuery = logsQuery.where((eb: any) => eb.or([
439
+ eb('organization_id' as any, 'is', null),
440
+ eb('organization_id' as any, 'in', organizationScopeIds),
441
+ ]))
442
+ } else {
443
+ logsQuery = logsQuery.where('organization_id' as any, 'is', null as any)
444
+ }
445
+ const logRows = await logsQuery
446
+ .orderBy('occurred_at' as any, 'desc')
434
447
  .limit(100)
448
+ .execute() as Array<Record<string, any>>
435
449
 
436
450
  const logs = logRows.map((row: any) => {
437
451
  const occurredAt = row.occurred_at instanceof Date ? row.occurred_at : row.occurred_at ? new Date(row.occurred_at) : null
@@ -1,7 +1,7 @@
1
1
  import type { ModuleCli } from '@open-mercato/shared/modules/registry'
2
2
  import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
3
3
  import type { EntityManager } from '@mikro-orm/postgresql'
4
- import type { Knex } from 'knex'
4
+ import { type Kysely, sql } from 'kysely'
5
5
  import { createProgressBar } from '@open-mercato/shared/lib/cli/progress'
6
6
  import { resolveTenantEncryptionService } from '@open-mercato/shared/lib/encryption/customFieldValues'
7
7
  import { decryptIndexDocForSearch, encryptIndexDocForStorage } from '@open-mercato/shared/lib/encryption/indexDoc'
@@ -141,7 +141,7 @@ const DEFAULT_BATCH_SIZE = 200
141
141
 
142
142
  type RebuildExecutionOptions = {
143
143
  em: EntityManager
144
- knex: Knex
144
+ db: Kysely<any>
145
145
  entityType: string
146
146
  tableName: string
147
147
  orgOverride?: string
@@ -165,7 +165,7 @@ type RebuildResult = {
165
165
  async function rebuildEntityIndexes(options: RebuildExecutionOptions): Promise<RebuildResult> {
166
166
  const {
167
167
  em,
168
- knex,
168
+ db,
169
169
  entityType,
170
170
  tableName,
171
171
  orgOverride,
@@ -220,28 +220,41 @@ async function rebuildEntityIndexes(options: RebuildExecutionOptions): Promise<R
220
220
  }
221
221
  }
222
222
 
223
- const filters: Record<string, unknown> = {}
224
- if (!global) {
225
- if (orgOverride !== undefined && supportsOrgFilter) filters.organization_id = orgOverride
226
- if (tenantOverride !== undefined && supportsTenantFilter) filters.tenant_id = tenantOverride
223
+ const applyFilters = <QB extends { where: (...args: any[]) => QB }>(q: QB): QB => {
224
+ let chain = q
225
+ if (!global) {
226
+ if (orgOverride !== undefined && supportsOrgFilter) {
227
+ chain = chain.where('organization_id' as any, '=', orgOverride)
228
+ }
229
+ if (tenantOverride !== undefined && supportsTenantFilter) {
230
+ chain = chain.where('tenant_id' as any, '=', tenantOverride)
231
+ }
232
+ }
233
+ if (!includeDeleted && supportsDeletedFilter) {
234
+ chain = chain.where('deleted_at' as any, 'is', null as any)
235
+ }
236
+ return chain
227
237
  }
228
- if (!includeDeleted && supportsDeletedFilter) filters.deleted_at = null
229
-
230
- const baseQuery = knex(tableName).where(filters)
231
238
 
232
239
  if (recordId) {
233
- const row = await baseQuery.clone().where({ id: recordId }).first<AnyRow>()
240
+ const row = await applyFilters(
241
+ db.selectFrom(tableName as any).selectAll() as any,
242
+ )
243
+ .where('id' as any, '=', recordId)
244
+ .executeTakeFirst() as AnyRow | undefined
234
245
  if (!row) return { processed: 0, matched: 0 }
235
246
  const bar = createProgressBar(progressLabel ?? `Rebuilding ${entityType}`, 1)
236
- await upsertIndexBatch(knex, entityType, [row], { orgId: orgOverride, tenantId: tenantOverride }, { encryptDoc, decryptDoc })
247
+ await upsertIndexBatch(db, entityType, [row], { orgId: orgOverride, tenantId: tenantOverride }, { encryptDoc, decryptDoc })
237
248
  bar.update(1)
238
249
  bar.complete()
239
250
  return { processed: 1, matched: 1 }
240
251
  }
241
252
 
242
- const countRow = await baseQuery.clone().count<{ count: string }>({ count: '*' }).first()
243
- const totalRaw = countRow?.count ?? (countRow as any)?.['count(*)']
244
- const total = totalRaw ? Number(totalRaw) : 0
253
+ const countRow = await applyFilters(
254
+ db.selectFrom(tableName as any).select(sql<string>`count(*)`.as('count')) as any,
255
+ ).executeTakeFirst() as { count: string | number } | undefined
256
+ const totalRaw = countRow?.count
257
+ const total = totalRaw != null ? Number(totalRaw) : 0
245
258
  const effectiveOffset = Math.max(0, offset)
246
259
  const matchedWithoutLimit = Math.max(0, total - effectiveOffset)
247
260
  const limitValue = toPositiveInt(limit)
@@ -257,15 +270,17 @@ async function rebuildEntityIndexes(options: RebuildExecutionOptions): Promise<R
257
270
 
258
271
  while (processed < intended) {
259
272
  const chunkLimit = remaining !== undefined ? Math.min(batchSize, remaining) : batchSize
260
- const chunk = await baseQuery
261
- .clone()
262
- .select('*')
263
- .orderBy('id')
264
- .limit(chunkLimit)
265
- .offset(cursorOffset)
273
+ const chunk = await applyFilters(
274
+ db
275
+ .selectFrom(tableName as any)
276
+ .selectAll()
277
+ .orderBy('id' as any)
278
+ .limit(chunkLimit)
279
+ .offset(cursorOffset) as any,
280
+ ).execute() as AnyRow[]
266
281
  if (!chunk.length) break
267
282
 
268
- await upsertIndexBatch(knex, entityType, chunk as AnyRow[], {
283
+ await upsertIndexBatch(db, entityType, chunk as AnyRow[], {
269
284
  orgId: orgOverride,
270
285
  tenantId: tenantOverride,
271
286
  }, { encryptDoc, decryptDoc })
@@ -284,10 +299,15 @@ async function rebuildEntityIndexes(options: RebuildExecutionOptions): Promise<R
284
299
  return { processed, matched: intended }
285
300
  }
286
301
 
287
- async function getColumnSet(knex: Knex, tableName: string): Promise<Set<string>> {
302
+ async function getColumnSet(db: Kysely<any>, tableName: string): Promise<Set<string>> {
288
303
  try {
289
- const info = await knex(tableName).columnInfo()
290
- return new Set(Object.keys(info).map((key) => key.toLowerCase()))
304
+ const rows = await db
305
+ .selectFrom('information_schema.columns' as any)
306
+ .select(['column_name' as any])
307
+ .where(sql<boolean>`table_schema = current_schema()`)
308
+ .where('table_name' as any, '=', tableName)
309
+ .execute() as Array<{ column_name: string }>
310
+ return new Set(rows.map((row) => String(row.column_name).toLowerCase()))
291
311
  } catch {
292
312
  return new Set<string>()
293
313
  }
@@ -336,9 +356,9 @@ const rebuild: ModuleCli = {
336
356
  const container = await createRequestContainer()
337
357
  const em = (container.resolve('em') as EntityManager)
338
358
  try {
339
- const knex = em.getConnection().getKnex()
359
+ const db = em.getKysely<any>()
340
360
  const tableName = resolveEntityTableName(em, entity)
341
- const columns = await getColumnSet(knex, tableName)
361
+ const columns = await getColumnSet(db, tableName)
342
362
  const supportsOrg = columns.has('organization_id')
343
363
  const supportsTenant = columns.has('tenant_id')
344
364
  const supportsDeleted = columns.has('deleted_at')
@@ -355,7 +375,7 @@ const rebuild: ModuleCli = {
355
375
 
356
376
  const result = await rebuildEntityIndexes({
357
377
  em,
358
- knex,
378
+ db,
359
379
  entityType: entity,
360
380
  tableName,
361
381
  orgOverride: orgId,
@@ -440,7 +460,7 @@ const rebuildAll: ModuleCli = {
440
460
  const container = await createRequestContainer()
441
461
  const em = (container.resolve('em') as EntityManager)
442
462
  try {
443
- const knex = em.getConnection().getKnex()
463
+ const db = em.getKysely<any>()
444
464
 
445
465
  const { getEntityIds } = await import('@open-mercato/shared/lib/encryption/entityIds')
446
466
  const entityIds = flattenSystemEntityIds(getEntityIds() as Record<string, Record<string, string>>)
@@ -453,7 +473,7 @@ const rebuildAll: ModuleCli = {
453
473
  for (let idx = 0; idx < entityIds.length; idx += 1) {
454
474
  const entity = entityIds[idx]!
455
475
  const tableName = resolveEntityTableName(em, entity)
456
- const columns = await getColumnSet(knex, tableName)
476
+ const columns = await getColumnSet(db, tableName)
457
477
  const supportsOrg = columns.has('organization_id')
458
478
  const supportsTenant = columns.has('tenant_id')
459
479
  const supportsDeleted = columns.has('deleted_at')
@@ -481,7 +501,7 @@ const rebuildAll: ModuleCli = {
481
501
  console.log(`[${idx + 1}/${entityIds.length}] Rebuilding ${entity}${scopeLabel}`)
482
502
  const result = await rebuildEntityIndexes({
483
503
  em,
484
- knex,
504
+ db,
485
505
  entityType: entity,
486
506
  tableName,
487
507
  orgOverride: orgId,
@@ -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
  // Generic JSONB-backed index rows for any entity ('<module>:<entity>')
4
4
  @Entity({ tableName: 'entity_indexes' })
@@ -72,25 +72,42 @@ export function register(container: AppContainer) {
72
72
  if (!id) return
73
73
  if (!orgId || !tenantId) {
74
74
  try {
75
- const knex = (em as any).getConnection().getKnex()
75
+ const db = (em as any).getKysely()
76
76
  const table = resolveEntityTableName(em, entityType)
77
- const row = await knex(table).select(['organization_id', 'tenant_id']).where({ id }).first()
77
+ const row = await db
78
+ .selectFrom(table as any)
79
+ .select(['organization_id' as any, 'tenant_id' as any])
80
+ .where('id' as any, '=', id)
81
+ .executeTakeFirst() as { organization_id: string | null; tenant_id: string | null } | undefined
78
82
  orgId = row?.organization_id ?? orgId
79
83
  tenantId = row?.tenant_id ?? tenantId
80
84
  } catch {}
81
85
  }
82
86
  // Optional: only index when custom field definitions exist for this entity (org/global)
83
87
  try {
84
- const knex = (em as any).getConnection().getKnex()
85
- const hasCf = await knex('custom_field_defs')
86
- .where({ entity_id: entityType, is_active: true })
87
- .modify((qb: any) => {
88
- if (orgId != null) qb.andWhere((b: any) => b.where({ organization_id: orgId }).orWhereNull('organization_id'))
89
- else qb.whereNull('organization_id')
90
- if (tenantId != null) qb.andWhere((b: any) => b.where({ tenant_id: tenantId }).orWhereNull('tenant_id'))
91
- else qb.whereNull('tenant_id')
92
- })
93
- .first()
88
+ const db = (em as any).getKysely()
89
+ let cfQuery = db
90
+ .selectFrom('custom_field_defs' as any)
91
+ .select(['id' as any])
92
+ .where('entity_id' as any, '=', entityType)
93
+ .where('is_active' as any, '=', true)
94
+ if (orgId != null) {
95
+ cfQuery = cfQuery.where((eb: any) => eb.or([
96
+ eb('organization_id' as any, '=', orgId),
97
+ eb('organization_id' as any, 'is', null),
98
+ ]))
99
+ } else {
100
+ cfQuery = cfQuery.where('organization_id' as any, 'is', null as any)
101
+ }
102
+ if (tenantId != null) {
103
+ cfQuery = cfQuery.where((eb: any) => eb.or([
104
+ eb('tenant_id' as any, '=', tenantId),
105
+ eb('tenant_id' as any, 'is', null),
106
+ ]))
107
+ } else {
108
+ cfQuery = cfQuery.where('tenant_id' as any, 'is', null as any)
109
+ }
110
+ const hasCf = await cfQuery.executeTakeFirst()
94
111
  if (!hasCf) return
95
112
  } catch {}
96
113
  try {
@@ -107,9 +124,13 @@ export function register(container: AppContainer) {
107
124
  if (!id) return
108
125
  if (!orgId) {
109
126
  try {
110
- const knex = (em as any).getConnection().getKnex()
127
+ const db = (em as any).getKysely()
111
128
  const table = resolveEntityTableName(em, entityType)
112
- const row = await knex(table).select(['organization_id']).where({ id }).first()
129
+ const row = await db
130
+ .selectFrom(table as any)
131
+ .select(['organization_id' as any])
132
+ .where('id' as any, '=', id)
133
+ .executeTakeFirst() as { organization_id: string | null } | undefined
113
134
  orgId = row?.organization_id ?? orgId
114
135
  } catch {}
115
136
  }
@@ -123,9 +144,13 @@ export function register(container: AppContainer) {
123
144
  // Build list of entity ids to subscribe to
124
145
  try {
125
146
  const em = (container.resolve('em') as any)
126
- const knex = (em as any).getConnection().getKnex()
147
+ const db = (em as any).getKysely()
127
148
  const cfEntityIds: string[] = []
128
- knex('custom_field_defs').distinct('entity_id')
149
+ db
150
+ .selectFrom('custom_field_defs' as any)
151
+ .select(['entity_id' as any])
152
+ .distinct()
153
+ .execute()
129
154
  .then((rows: any[]) => {
130
155
  for (const r of rows || []) cfEntityIds.push(String(r.entity_id))
131
156
  })